PDA

View Full Version : Apply noise to multiple objects


andrewhake
09-19-2010, 04:57 PM
I am sure there is a good way to do what I am after, just stuck.

I am using an expression:

string $cubes[] = `listRelatives grp_cubes`;

for ($cube in $cubes) {
setAttr ($cube + ".translateY") (((noise((rand(time)) * ctrl_cubeDynamics.Translate_Y_Frequency) + 1) * ctrl_cubeDynamics.Translate_Y_Amplitude) / 2);
}

to apply random translate Y movement to loads of cubes.

The problem is throwing rand into any part of the setAttr section seems to lose the smoother movement that the noise function generates. Removing rand will obviously just cause all the cubes to have the same value. I assume there must be a good way to do this but I am just running into a wall.

Any help is much appreciated.

EDIT: Got this resolved thanks to some great info in this post from trancor | http://forums.cgsociety.org/showpost.php?p=6143355&postcount=3

Here is my expression:

//Apply random noise to all pCubes
//Uses " ctrl_cubeDynamics.Translate_Y_Frequency" and "ctrl_cubeDynamics.Translate_Y_Amplitude" attributes on cube control object

//Get cube transforms (pCube1, pCube2, etc.)
string $cubes[]=`ls -type transform "pCube*"`;

float $value;

//Apply smooth random noise to each cube in translateY
for($thecube=0; $thecube<size($cubes); ++$thecube){
$value=noise($thecube*40+time * ctrl_cubeDynamics.Translate_Y_Frequency) * ctrl_cubeDynamics.Translate_Y_Amplitude;
setAttr ($cubes[$thecube]+".translateY") ($value * ctrl_cubeDynamics.Translate_Z_Switch);
}

//Apply controlled random noise to each cube in translateX and translateZ without intersection
for ($cube in $cubes) {
setAttr ($cube + ".translateX") (getAttr ($cube + ".origX") + (rand(-.5 * ctrl_cubeDynamics.Translate_X_Gap, .5 * ctrl_cubeDynamics.Translate_X_Gap)) * ctrl_cubeDynamics.Translate_X_Switch);
setAttr ($cube + ".translateZ") (getAttr ($cube + ".origZ") + (rand(-.25 * ctrl_cubeDynamics.Translate_Z_Gap, .25 * ctrl_cubeDynamics.Translate_Z_Gap)) * ctrl_cubeDynamics.Translate_Z_Switch);
}

The second part of the code is applying random controlled movement in X and Z based on the gap between the cubes so they don't intersect.

And a frame and .mov as an example:
http://andrewandoru.com/images/mkI_cubes.jpg

http://andrewandoru.com/sandbox/o_O_mkI_cubes_v1.3_1.mov

ewerybody
09-23-2010, 11:22 AM
looking nice. I would have just added randomly generated animation curves to the cubes. So all this does an expression now??!

andrewhake
09-23-2010, 02:07 PM
Yeah all the movement is just using the expression. It is pretty slow with 8400 cubes, but it is easy to setup a smaller preview region of cubes to test the movement. When I have it where I want, I just bake down the cubes and stop evaluating expressions.

It would be very easy to tie in rotation, scale, or other values in an expression like this. Just gets a bit slow.

CGTalk Moderation
09-23-2010, 02:07 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.