/* This file downloaded from Highend3d.com '' '' Highend3d.com File Information: '' '' Script Name: jhBakeGeo v1.5 '' Author: john homer '' Last Updated: February 18, 2004 '' Update/Change this file at: '' http://www.highend3d.com/maya/mel/?section=animation#2605 '' '' Please do not alter any information above this line '' it is generated dynamically by Highend3d.com and will '' be changed automatically on any updates. */ /*--------------------------------------------------------------------- / / bakes geometry into a blendshape. / It adds targets to the blendshape 1 at a time, / eliminating the need to have a shape per / frame existing untill belndshape creation, and therefore / saving a ton of RAM, / / USAGE: select some objects, run the script / / by john homer - john_homer@flashmail.com /---------------------------------------------------------------------*/ global proc jhBakeGeo() { string $sel[] = `ls -sl`; for ($origSurf in $sel) { float $startFrame = `playbackOptions -q -minTime`; float $endFrame = `playbackOptions -q -maxTime`; float $frameRange = $endFrame - $startFrame; float $weightInc = (1/$frameRange); float $currentWeight; int $stepSize = ($frameRange / 999) +1; // GET BASE SHAPE (FROM STARTFRAME) currentTime -e $startFrame; string $baseGeo[] = `duplicate $origSurf`; rename $baseGeo[0] ($origSurf + "_baked"); // GET LAST SHAPE (FROM ENDFRAME) currentTime -e $endFrame; string $endShape[] = `duplicate $origSurf`; select -r $endShape[0] ($origSurf + "_baked"); // CREATE THE COMMAND TO CREATE THE BLENDSHAPE string $blendOptions = ("blendShapeDeleteTarget " + "\"" + "blendShape -ib -name " + ($origSurf + "_bakeBlend") + "\""); eval $blendOptions; // CREATE THE BLENDSHAPE // ADD THE INBETWEEN TARGETS int $j = 1; for ($i=($startFrame+1); $i<$endFrame; $i+=$stepSize) { currentTime -e $i; // round to 2 decimal places $currentWeight = ($j*$weightInc); $currentWeight = ($currentWeight*1000); $currentWeight = trunc($currentWeight); $currentWeight = ($currentWeight/1000); $j+=$stepSize; string $tempShape[] = `duplicate $origSurf`; blendShape -e -ib -t ($origSurf + "_baked") 0 $tempShape[0] $currentWeight ($origSurf + "_bakeBlend"); delete $tempShape[0]; } currentTime -e $endFrame; setAttr ($origSurf + "_bakeBlend." + $endShape[0]) 1; // SET LAST KEYFRAME TO 1 setKeyframe ($origSurf + "_bakeBlend." + $endShape[0]); currentTime -e $startFrame; setAttr ($origSurf + "_bakeBlend." + $endShape[0]) 0; // SET FIRST KEYFRAME setKeyframe ($origSurf + "_bakeBlend." + $endShape[0]); hide $origSurf; rename $origSurf ($origSurf + "_original"); } print ("baked " + $origSurf +"\n"); }