How do I deal with parented objects and object rotation?

Discussion about scripting with Python
CMPXCHG8B
Posts: 4
Joined: Wed Mar 22, 2017 7:45 am

How do I deal with parented objects and object rotation?

Postby CMPXCHG8B » Sun Mar 26, 2017 3:49 am

I'm trying to set the initial velocity of some particles on an emitter.

The problem is that the emitter has been positioned, scaled, and rotated within the scene. It is also parented to a null that has been positioned and rotated (but not scaled). I want to set the velocity on the particles so that they fire down the Y axis of the emitter, which means I need to calculate a velocity vector that has been aligned as such.

How can I do this in Realflow?

In other applications like CINEMA 4D, I could grab the global matrix of an object and perform some simple operations to calculate the vector I need. However, it appears like Realflow doesn't expose any kind of "matrix" class through the Python scripting. The only thing I see is a fairly limited Vector class and nothing else. I suppose it might be possible to achieve what I want with only that, but I have no idea how- it seems rather complicated to have to deal with only vectors and walk up the chain of "Parented to" objects to calculate the correct velocity vector.

Is there any easier way to do this?

-CMPX


User avatar
tsn
Posts: 861
Joined: Fri Oct 27, 2006 10:36 am

Re: How do I deal with parented objects and object rotation?

Postby tsn » Thu Mar 30, 2017 7:02 am

Yes, there are ways to do that. One is to use the method from here: http://www.fundza.com/mel/axis_to_vector/index.html

If your emitter/null is static you only have to run such a script once and then you can store the vector as a global variable and transfer it to the particles' velocities. Another idea is to create a reference object/vector and calculate an Euler angle. This will make the particles point to a target, for example. Here's the concept:

Code: Select all

reference = Vector.new( 0.0, -1.0, 0.0 )
alignWith = Vector.new( 0.4, 0.9, -0.3 )
angles = reference.getEulerAngles( alignWith )
emitter = scene.get_DY_Emitter( "emitter_name" )
emitter.setParameter( "Rotation X", angles.x )
emitter.setParameter( "Rotation Y", angles.y )
emitter.setParameter( "Rotation Z", angles.z )


Cheers,
Thomas

User avatar
tsn
Posts: 861
Joined: Fri Oct 27, 2006 10:36 am

Re: How do I deal with parented objects and object rotation?

Postby tsn » Fri Mar 31, 2017 8:24 am

Sorry, this line was wrong:

Code: Select all

emitter = scene.get_DY_Emitter( "emitter_name" )


It has to be

Code: Select all

emitter = scene.get_DY_Domain( "domain_name" )

CMPXCHG8B
Posts: 4
Joined: Wed Mar 22, 2017 7:45 am

Re: How do I deal with parented objects and object rotation?

Postby CMPXCHG8B » Sat Apr 01, 2017 12:00 pm

Yeah, I saw that in the manual, though I was kinda hoping something exposed a Matrix interface somewhere I would work with instead.

In any case, thanks for your help! I've pretty much got it sorted using vectors and getEulerAngles() (it an't very pretty, but I guess it works).

-CMPX


Return to “Python-Scripting”

Who is online

Users browsing this forum: No registered users and 3 guests