//geoBake.mel //By Christopher Evans - 11/27/04 //Thanks to JdC- in #maya for helping me when I hit a wall.. //www.ChrisEvans3D.com global proc geoBake() { //We will start by querying the range selected and tossing it into an array global string $gPlayBackSlider; float $rangeArray[2]; $rangeArray = `timeControl -q -rangeArray $gPlayBackSlider`; //Get the currently selected object string $obj[] = `ls -sl`; //Now we will get how many frames are inthe range float $numFrames = ($rangeArray[1] - $rangeArray[0]); //prompting user input promptDialog -message ("Create how many blendShapes? ["+$numFrames+" frames selected]") -button "Ok" -button "Cancel" -defaultButton "Ok" -cancelButton "Cancel" -dismissString "Cancel"; //How many blendshapes to generate? int $interval = `promptDialog -query`; float $frameSkip = ($numFrames / $interval); //Prompt user to name blendShape/deformation node promptDialog -message "Enter a name for this deformation:" -button "Ok" -button "Cancel" -defaultButton "Ok" -cancelButton "Cancel" -dismissString "Cancel"; string $name = `promptDialog -query`; //Start loop to name/create/set up blendShapes int $i; float $frame = 0; for($i = 0; $i < $interval; $i++) { currentTime -edit ($rangeArray[0] + $frame); duplicate -n ("morph_b"+$i) $obj[0]; delete -ch ("morph_b"+$i); $frame += $frameSkip; } currentTime -edit $rangeArray[0]; //Select the newly created objects, then the original, and create blendShapes string $ARR[]; $a = 0; while ($a < $interval) { $ARR[size($ARR)] = "morph_b"+$a ; $a++; } //print ($ARR); blendShape -n $name -parallel $ARR $obj[0]; //Select the morphs and hide them select -d $obj[0]; for($i = 0; $i < $interval; $i++) { select -add ("morph_b"+$i); hide; } //Adds an attr with the specified $name to the deformation object addAttr -ln $name -at double -min -1 -max $interval -dv 0 $obj[0]; setAttr -e -keyable true ($obj[0]+"."+$name); //Generate set drivens to allow new attr to fire all morphs for($i = 0; $i < $interval; $i++) { int $check = 0; $VAR = $i; // print ($i+"\n"); setAttr ($obj[0]+"."+$name) $i; setAttr ($name+".morph_b"+$VAR) 1; setDrivenKeyframe -cd ($obj[0]+"."+$name) ($name+".morph_b"+$VAR); $i++; if ($i == $interval) { $check = 1;} setAttr ($obj[0]+"."+$name) ($i); // print ($i+"\n"); setAttr ($obj[0]+"."+$name) $i; setAttr ($name+".morph_b"+$VAR) 0; setDrivenKeyframe -cd ($obj[0]+"."+$name) ($name+".morph_b"+$VAR); $i = $i - 2; // print ($i+"\n"); setAttr ($obj[0]+"."+$name) $i; setAttr ($name+".morph_b"+$VAR) 0; setDrivenKeyframe -cd ($obj[0]+"."+$name) ($name+".morph_b"+$VAR); $i++; if ($check == 1) { break; } } // change all keyframes for morph_b* to spline instead of clamped string $MM[]; $a = 0; while ($a < $interval) { $MM[size($MM)] = "morph_b"+$a ; $a++; } for ($morphs in $MM) { keyTangent -index 0 -inTangentType spline ($name+"_"+$morphs); keyTangent -index 0 -outTangentType spline ($name+"_"+$morphs); keyTangent -index 1 -inTangentType spline ($name+"_"+$morphs); keyTangent -index 1 -outTangentType spline ($name+"_"+$morphs); keyTangent -index 2 -inTangentType spline ($name+"_"+$morphs); keyTangent -index 2 -outTangentType spline ($name+"_"+$morphs); } //Opens a slider window that changes the $obj[].$name attr window -title ($name+" deformation") -width 400 -height 50; columnLayout; floatSliderGrp -label "blendShapes" -field true -minValue 0.00 -maxValue $interval bakeSlider; connectControl bakeSlider ($obj[0]+"."+$name); showWindow; }