apply random rotation animation to selected objects

apply random rotation animation to selected objects

Anonymous
Not applicable
4,817 Views
2 Replies
Message 1 of 3

apply random rotation animation to selected objects

Anonymous
Not applicable

disclaimer: total MEL / Expression newb.

 

i'm trying to develop a mel script that will automatically apply rotation animation expressions to selected objects. i found this script, which works for translation.

 

proc applyExpressionToSelection()
{
vector $rMx = << 10,2,10 >>;	// maximum x,y,z randomizations
vector $rMn = << -10,0,-10 >>;	// minimum x,y,z randomizations
string $mode = "move";	// "move", "rotate" or "scale"
for ($object in `ls -sl -tr`)
evalEcho($mode+" "+`rand ($rMn.x) ($rMx.x)`+" "+`rand ($rMn.y) ($rMx.y)`+" "+`rand ($rMn.z) ($rMx.z)`+" "+$object);
}
applyExpressionToSelection();

i cannot figure out how to convert this to rotation. also when i first execute this script my objects move around. i'd like everything to stay in place, then begin moving when i hit play.

 

any help is greatly appreciated.

 

thanks!

 

0 Likes
4,818 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

some progress just by trial and error. i'm now able to effect rotation, rotation distance and rotation speed.

 

proc applyExpressionToSelection()
{
string $sel[] = `ls -sl`;
int $id = 0;
for($object in $sel)
{
string $cmd = "vector $offset = noise(<<1,1,1>> * time*.5 + " + $id + ");\n";
$cmd += ($object + ".rotateX = $offset.x;\n");
$cmd += ($object + ".rotateY = $offset.y;\n");
$cmd += ($object + ".rotateZ = $offset.z*3;\n");
$id += 1;
expression -s $cmd -o $object -ae 1 -uc all;
}
}
applyExpressionToSelection();

but for some reason when i apply this script it changes the orientation of my objects. if anyone can help with that i'd appreciate it.

thanks!

0 Likes
Message 3 of 3

Anonymous
Not applicable

With that original code you posted, all you have to do is change the following line

 

string $mode = "move"; // "move", "rotate" or "scale"

to

 

string $mode = "rotate"; // "move", "rotate" or "scale"

 and it'll apply rotations instead of translations.

 

 

Also, what do you mean by "it changes the orientation of my objects"? What differentiation are you making between orientation and rotation in this case?

0 Likes