andrewhake
09 September 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
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