//////////////////////////////// // // // srElasticKey, Smith Roberts 2007 // // // //////////////////////////////// // Overview: This script creates a "wind-up" curve leading into a set of animation curves or an "overshoot" upon // exiting a set of animation curves. The script creates a baseline key which acts as an anchor, then changes // the value of the selected key or keys in inverse proportion to the value change of the original curve. Users // can choose the placement of the baseline key either in proportion to the duration of the curve, or in an // absolute number of keyframes. Value displacement of the selected keyframe can be modified by percentage // of the original curve's value change over that duration. Works on multiple curves simultaneously. // Sounds much more complicated than it is. Try it! : ) // Install: copy script into local scripts folder, source the script ( or restart maya ), type "srElasticKey" to launch the script. // Written by Smith Roberts : urbanprimate@gmail.com // Tested with Maya 8.5 // -------------------------------------------------------------------------------------------------------------------------------------------- // proc to create the UI // global proc srElasticKey() { if (`window -exists srElasticKeyWin`) deleteUI -window srElasticKeyWin; window -t "srElasticKey" -w 562 -h 350 srElasticKeyWin; formLayout srEtopForm; rowColumnLayout -nc 3 -cw 1 65 -cw 2 150 -cw 3 100 srErow1; text -l "Placement"; radioCollection srEradio1; $srEradio1_1 = `radioButton -label "Into Curve"`; $srEradio1_2 = `radioButton -label "Exiting Curve"`; radioCollection -e -select $srEradio1_1 srEradio1; setParent srEtopForm; rowColumnLayout -nc 3 -cw 1 65 -cw 2 150 -cw 3 100 srErow2; text -l "Baseline displacement"; radioCollection srEradio2; $srEradio2_1 = `radioButton -label "Absolute"`; $srEradio2_2 = `radioButton -label "Percentage"`; radioCollection -e -select $srEradio2_2 srEradio2; setParent srEtopForm; frameLayout -bs "out" -h 2 srESep1; setParent srEtopForm; floatSliderGrp -pre 2 -label "Percentage Time Displacement" -field true -minValue 1 -maxValue 100 -v 30 srEslide; intSliderGrp -label "Absolute Time Displacement" -field true -minValue 1 -maxValue 100 -v 3 srEslide2; floatSliderGrp -pre 2 -label "Percentage Value Displacement" -field true -minValue 1 -maxValue 100 -v 30 srEslide3; checkBox -l " Preserve curve value for baseline key" -v 0 srEbox; checkBox -l " Snap to integer frame number" -v 1 srEbox2; rowColumnLayout -nc 3 -cw 1 180 -cw 2 180 -cw 3 180 srEbutrow; button -l "Create Elastic Keys" -c "getsrEPrefs 1" -h 27 ; button -l "Apply" -c "getsrEPrefs 0"; button -l "Close" -c "deleteUI srElasticKeyWin"; setParent srEtopForm; formLayout -e -attachForm srErow1 "left" 100 -attachForm srErow1 "top" 3 -attachForm srErow2 "left" 100 -attachForm srErow2 "top" 25 -attachForm srESep1 "left" 0 -attachForm srESep1 "right" 0 -attachForm srESep1 "top" 70 -attachForm srEslide "left" 25 -attachForm srEslide "top" 78 -attachForm srEslide2 "left" 25 -attachForm srEslide2 "top" 110 -attachForm srEslide2 "right" 140 -attachForm srEslide3 "left" 25 -attachForm srEslide3 "top" 142 -attachForm srEbox "left" 164 -attachForm srEbox "top" 169 -attachForm srEbox2 "left" 164 -attachForm srEbox2 "top" 187 -attachForm srEbutrow "left" 5 -attachForm srEbutrow "bottom" 5 srEtopForm; showWindow; window -e -h 290 srElasticKeyWin; } // proc to calculate and insert new keys // global proc getsrEPrefs( int $closeWindow ) { string $orientation; float $sourceFrame; float $timeDifference; string $selectedNames[]; // float $valueDifference; float $slidePercent; float $baseDisplace; float $absDisplace; float$valuePercent; int $displaceMod; string $time; float $newValue; int $i; if ( $closeWindow == 1) { deleteUI srElasticKeyWin; } if ( `radioCollection -q -sl srEradio1` == "radioButton1" ) { $orientation = "next"; $displaceMod = 1; } else { $orientation = "previous"; $displaceMod = -1; } string $selectedNames [] = `keyframe -selected -name -query` ; float $selectedTime [] = `keyframe -selected -q` ; for ($i = 0; $i < size($selectedNames); $i++) { string $currentName = $selectedNames[$i] ; float $currentTime = $selectedTime[$i] ; $sourceFrame = `findKeyframe -time $currentTime -which $orientation $currentName` ; float $timeDifference = $sourceFrame - $currentTime ; if ( `radioCollection -q -sl srEradio1` == "radioButton1" ) { $time = $currentTime + ":" + $sourceFrame; } else { $time = $sourceFrame + ":" + $currentTime; } float $values[] = `keyframe -time $time -query -valueChange $currentName` ; float $valueDifference = $values[0] - $values[1]; selectKey -remove; string $button = `radioCollection -q -sl srEradio2`; if ( `radioCollection -q -sl srEradio2` == "radioButton3" ) { $baseDisplace = `intSliderGrp -q -v srEslide2`* $displaceMod; } else { $slidePercent = `floatSliderGrp -q -v srEslide` ; $baseDisplace = $slidePercent * .01 * $timeDifference ; } if ( `checkBox -q -v srEbox` == 0) { $absDisplace = $currentTime - $baseDisplace; copyKey -time $currentTime $currentName; pasteKey -time $absDisplace -option merge $currentName; } else { $absDisplace = $currentTime - $baseDisplace; copyKey -time $currentTime $currentName; setKeyframe -time $absDisplace $currentName; } $valuePercent = `floatSliderGrp -q -v srEslide3`; float $valueDisplace = $valuePercent * .01 * $valueDifference; if ( `radioCollection -q -sl srEradio1` == "radioButton1" ) { $newValue = $values[0] + $valueDisplace; } else { $newValue = $values[1] - $valueDisplace; } keyframe -time $currentTime -valueChange $newValue $currentName; if ( `checkBox -q -v srEbox2` == 1) { snapKey -t $currentTime -tm 1.0 $currentName; snapKey -t $absDisplace -tm 1.0 $currentName; } } }