PDA

View Full Version : Runtime expression evaluate every 'n' frame?


wizlon
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.

Ta.

NaughtyNathan
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?

:nathaN

ginodauri
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:

if (frame%25==0)
{
print (rand(0,1));
}

wizlon
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.

seed (1321353515+frame);

$randNum = rand (1, 10);

if ($randNum > 9.5)
{
print "yay!";
}

Attached is a Maya 2011 scene file if your interested.

Thanks again.

ginodauri
09-29-2010, 07:22 PM
If i fully understand problem this is solution:

int $rand1;
if (frame==1)
{
$rand1=1;
}
if(frame==$rand1)
{
$rand1+=rand(1,5);
print (frame);
}

wizlon
10-01-2010, 03:05 PM
Thanks all. This:

if (frame == 1)

volumeAxisField1.alongAxis = 1;

else

{

volumeAxisField1.alongAxis = (1 + sin(time)) * 1;

print(volumeAxisField1.alongAxis + "\n");

}

or this:

volumeAxisField1.alongAxis = (noise(time*.5)) *1;

gets me close to what I'm after.

Cheers.

CGTalk Moderation
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.