View Full Version : MEL: position of an object over the last 3 frames
Any idea how i can access the position of an object over the last 3 frames in a MEL runtime expression evaluated perframe.
04-28-2003, 05:55 PM
Use the time flag on getAttr to evaluate the object translation at a previous frame:
float $pos = `getAttr -time ( time - 1) myObject.t`;
04-28-2003, 08:48 PM
Your use of "runtime expression" makes me wonder if you're doing this in a particle expression? But then you said "per frame," so I'm confused.
Doing a getAttr like this in an expression can be very dicey, because Maya won't necessarily execute the expression if the actual input attributes (the ones you access without a getAttr) haven't changed. This will give you funky behavior whenever you have two identical input states in a row, because the results of the getAttr will be changing but the inputs will not and the expression will not execute.
Also, if you're doing this in a particle expression, you may want to think of another approach because it will be verrrry slow. (Another approach might be to use userVectors to cache old positions.)
04-28-2003, 10:21 PM
When using "getAttr -time" to get values in an expression you can still get good updates by simply assigning the attributes to a dummy variable, i.e..
float $pos = `getAttr -time (frame - 10 ) myObject.t`;
float $dummyX = myObject.tx;
float $dummyY = myObject.ty;
float $dummyZ = myObject.tz;
This creates connections from the object translate to your expression, which insures that the expression updates when the object's translate changes.
04-28-2003, 11:21 PM
i also saw a solution on the 'fast animation rigs' dvd
it uses a frameCache node. it gives you access to specefic values in an animation curve. on the dvd jason created it using MEL. i don't remember the specifics on how to create the node, but maybe you can find it in the MEL reference.
Yea im using a rigid body with some particles in the same scene, the particles are colored depending upon the position of the rigid body of the last few frames. So i prolly got a bit confised with my terminology.
04-28-2003, 11:56 PM
Duncan's point is excellent, but I think I wasn't perfectly clear:
In the event where tx, ty, and tz do not change for a couple of frames in a row but there has been recent change (within the window of past frames being examined by getAttr) you still won't get proper updates with that solution, because the results of the getAttrs will be different but the values of the actual input connections will not themselves be changing.
As for frameCache, I played around with that for a while and got very inconsistent results -- I wonder if there's some magic dance one has to do to make it work properly?
04-29-2003, 01:13 AM
Mark, I think it should update every frame if alwaysEvaluate is turned on for the expression( the default setting ).
04-29-2003, 03:24 AM
hehe oops! Is that the default setting? :D
Anyway, as long as that works and you are careful not to getAttr on something that requires massive amounts of calculation (attrs fed by animation curves may be OK, attrs fed by a mess of IK-driven deformers acting on geometry may not be) it should be fine, I agree.
04-29-2003, 11:05 AM
hmm.. does that work at all?
does maya really evaluate the current position of a rigid body/particle system when you query it?
it would need to do a runup for each queried frame which would make that expression terribly slow.
to get it work you can either create a cache for the particles and/or bake the dynamics simulation for the rigid body.
another thing would be creating 3 new per particle attributes which you fill with the position values from the frames in a runtime expression.. but i think what you needed is for the rigid body
04-29-2003, 11:12 AM
oops again, I didn't read carefully enough to note that he was trying to get the values of dynamics data as opposed to object attribute values.
04-29-2003, 05:06 PM
Yes. Rebo if you need to get the value of rigid body positions at different points in time, then you should first bake the rigid body solution before attempting to use "getAttr -time".
Thanx guys, i have this clearer in my head now.
01-15-2006, 01:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.