PDA

View Full Version : Need help setting up a "random" script.


andytroz
02-04-2008, 11:23 PM
I'm looking for a way to animate the Phase of a turbulent field with random values between 15 and 30. The only problem I'm running in to is that the values must "tween" to eachother over a few frames instead of just "popping" to the value. I'd also like it so that the script would plant the values every 3 to 5 frames.

How would I go about this?
(I hope it's easy to understand the question)

tbaypaul
02-05-2008, 01:51 AM
a script that keys some values on it will give you greater flexibility on curve interp and cycle length by increasing $n to 10 or higher......but there are several ways to do what you want. This is a keyframe version of the basic logic that perlin noise uses to calculate it's function.

{
string $sel[] = `ls -sl`;//select your turb. field
int $n;
for($n = 0; $n < 5; ++$n){
float $v1 = rand(-5, 5);
float $v2 = rand(-5, 5);
float $v3 = rand(-5, 5);
setKeyframe -t (3*$n) -v $v1 -at phaseX $sel[0];
setKeyframe -t (3*$n) -v $v2 -at phaseY $sel[0];
setKeyframe -t (3*$n) -v $v3 -at phaseZ $sel[0];
setAttr ($sel[0] + "_phaseX.postInfinity") 3;
setAttr ($sel[0] + "_phaseX.preInfinity") 3;
setAttr ($sel[0] + "_phaseY.postInfinity") 3;
setAttr ($sel[0] + "_phaseY.preInfinity") 3;
setAttr ($sel[0] + "_phaseZ.postInfinity") 3;
setAttr ($sel[0] + "_phaseZ.preInfinity") 3;
}
}

axiomatic
02-05-2008, 04:44 AM
I like your script tbaypaul and i can think of a lot of uses for it. In this case I usually use noise as it's a lot simpler and i don't need to worry about keys. The MEL expression at runtime:

//
phaseX = noise(frame);
phaseZ = -1*phaseX;
//

noise returns a value between -1 and 1 in a progressive fashion. if you want values between 15 and 30 then you'd simply change the script:

//
phaseX = 23 + (7 * noise(frame));
phaseZ = -1*phaseX;
//

It's probably be better to use an absolute value, multiply it by you variance and add it to your offset with vars. You can change the evaluated number to speed up / slow down the noise. To do this just play with frame from the expression so (frame) might become (frame * 10) for example.


edit:
i used (frame) but you can use (time) for a smoother animation in some circumstance, i.e: noise(time)

CGTalk Moderation
02-05-2008, 04:44 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.