So I hit a technical snag which I have been diligently avoiding for some time now, how was I to move all the leaves on my tree for my next short. Well I couldn’t put it off any longer and with some help from two of my co-workers Ken and Brian I got her figured out. It is a combination of a mel script and an expression.
The mel script is run to put custom attrs on each leaf to get information of the current rotation values and to attach a unique seed number to each leaf – most of the leaves are instances so I was unable to zero out their transforms.
Here is the script – feel free to use what you can – along with avery simple movie. Looks easy right? HA… for a mel novice this was quite a challenge, but hey with a little manual reading, some internet searching, and some good ole friend power she works!
Script and Expression -
//Mel script to set up custom attribute and store rotations in vector
for($i=21; $i<=198;$i++)
{
select (“appleLeaf”+$i);
$lf = (“appleLeaf” +$i);
addAttr -ln “OrgRot” -at double3 $lf;
addAttr -ln “OrgRotX” -at double -p OrgRot $lf;
addAttr -ln “OrgRotY” -at double -p OrgRot $lf;
addAttr -ln “OrgRotZ” -at double -p OrgRot $lf;
addAttr -ln “seed” -at double -min 0 -max 10 -dv 1 $lf;
float $rx = `getAttr ($lf + “.rotateX”)`;
float $ry = `getAttr ($lf + “.rotateY”)`;
float $rz = `getAttr ($lf + “.rotateZ”)`;
setAttr -type double3 ($lf+”.OrgRot”) $rx $ry $rz;
setAttr -e-keyable true ($lf+”.OrgRot”);
setAttr -e-keyable true ($lf+”.OrgRotX”);
setAttr -e-keyable true ($lf+”.OrgRotY”);
setAttr -e-keyable true ($lf+”.OrgRotZ”);
$rand = rand(0,10);
setAttr ($lf+”.seed”) $rand;
setAttr -e-keyable true ($lf+”.seed”);
}
//Expression for querying attr and rand noise
for($i=21; $i<=198;$i++)
{
select (“appleLeaf”+$i);
$lf = (“appleLeaf” +$i);
float $sd = `getAttr ($lf + “.OrgRotX”)` + `getAttr ($lf + “.OrgRotZ”)`/ 30;
float $rx = `getAttr ($lf + “.OrgRotX”)`;
float $ry = `getAttr ($lf + “.OrgRotY”)`;
float $rz = `getAttr ($lf + “.OrgRotZ”)`;
float $seed = `getAttr ($lf + “.seed”)`;
$x=noise(time +$seed)*4;
$y=noise(time+$seed)*4;
$z=noise(time+$seed)*4;
rotate ($rx + $x) ($ry+$y) ($rz+$z);
select -d;
}