View Full Version : Runtime expression evaluate every 'n' frame?
09-29-2010, 10:02 AM
I'm using the simple runtime expression: volumeAxisField1.aroundAxis = rand (0,3);
How can I get this to evaluate something other than every frame. For example I would like the expression to evaluate every 'n' frames where 'n' is a random value between 1 and 75.
So instead of returning a value between 0 and 3 every frame I would like a value between 0 and 3 returned every - rand = (0,75); frames.
Hope this makes sense.
09-29-2010, 12:40 PM
afaik you can't stop an expression evaluating every frame (apart from manually disabling the node) but as you can reference time and frame directly in an expression you can keep the value the same for n frames, which I assume is fine for your needs? For example:
global float $gVar = 0;
if (fmod(frame,24)==0) $gVar = `rand 0 3`;
volumeAxisField1.aroundAxis = $gVar;
this works due to the fact that assigning a value to a global variable is ignored once the variable is initialised.
the 24 denotes the frame skip length you want (I guess you could make this another global variable?) do you want this to remain static throughout the animation? or do you want it to randomize itself during playback too?
09-29-2010, 01:25 PM
I don't know i understand your problem but it is not very "logical".
This is for every 25 frames value get changed:
09-29-2010, 02:34 PM
Thanks guys I'll look into those.
Here's what someone else posted:
'One way of doing this would be to have a random number determine the frequency of the script running...while this is not specifically "Frame" based...but should give you the same behavior.
$randNum = rand (1, 10);
if ($randNum > 9.5)
Attached is a Maya 2011 scene file if your interested.
09-29-2010, 07:22 PM
If i fully understand problem this is solution:
10-01-2010, 03:05 PM
Thanks all. This:
if (frame == 1)
volumeAxisField1.alongAxis = 1;
volumeAxisField1.alongAxis = (1 + sin(time)) * 1;
print(volumeAxisField1.alongAxis + "\n");
volumeAxisField1.alongAxis = (noise(time*.5)) *1;
gets me close to what I'm after.
10-01-2010, 03:05 PM
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.