//parisKeyJitter //created by Paris Mavroidis 2008 global proc string[] parisKJGetSelectedObjAttrs() { string $attrs[] = `channelBox -q -sma mainChannelBox`; string $objs[] = `ls -sl`; string $objAttrs[]; int $count = 0; for ($o in $objs) for ($a in $attrs) if (`attributeQuery -exists -node $o $a`) { $objAttrs[$count] = ($o+" "+$a); $count++; } return $objAttrs; } global proc parisKJUI() { if (`window -q -exists parisKJWindow`) deleteUI parisKJWindow; window -wh 500 500 parisKJWindow; columnLayout -columnOffset "both" 15; separator -h 15 -w 400 -style "none"; rowLayout -nc 2 -cw2 120 200; text -l "KEYFRAME JITTER" -font "boldLabelFont" -w 300 -al "left"; text -l " by Paris Mavroidis (www.parismav.com)" -w 300 -al "left"; setParent..; separator -h 2 -w 400 -style "single"; separator -h 15 -w 400 -style "none"; text -l "Instructions" -al "left" -w 350 -font "boldLabelFont"; text -l "1) Set the desired options." -al "left" -w 350; text -l "2) Select the objects and attributes (from the channel box) to apply the jitter to." -al "left" -w 400; text -l "3) Click on the 'Apply Jitter' button" -al "left" -w 350; separator -h 15 -w 400 -style "none"; text -l "Frame Range" -font "boldLabelFont" -w 300 -al "left"; rowLayout -nc 4 -cw4 150 75 30 65; radioButtonGrp -sl 1 -cw2 70 70 -numberOfRadioButtons 2 -labelArray2 "time slider" "start/end:" -on1 "parisKJSetFrameRangeMode 1" -on2 "parisKJSetFrameRangeMode 2" pkjFrameRangeGrp; intField -v 0 -w 65 -en 0 -s 1 pkjFrameField1; text -l "to" -al "center" -w 20; intField -v 100 -w 65 -en 0 -s 1 pkjFrameField2; setParent..; separator -h 15 -w 400 -style "none"; text -l "Keyframe Interval" -font "boldLabelFont" -w 300 -al "left"; rowLayout -nc 4 -cw4 150 75 30 65; text -l "random # of frames between:"; intField -v 1 -w 65 -s 1 -min 1 pkjIntervalField1; text -l "and" -w 20 -al "center"; intField -v 1 -w 65 -s 1 -min 1 pkjIntervalField2; setParent..; separator -h 15 -w 400 -style "none"; text -l "Value Range" -font "boldLabelFont" -w 300 -al "left"; rowLayout -nc 4 -cw4 150 75 30 65; text -l "random value between:"; floatField -v 0 -w 65 -s 0.5 pkjValueField1; text -l "and" -w 20; floatField -v 0 -w 65 -s 0.5 pkjValueField2; setParent..; separator -h 5 -w 400 -style "none"; radioButtonGrp -sl 1 -cw2 140 200 -numberOfRadioButtons 2 -labelArray2 "values are absolute" "values are offsets from current value" pkjValueTypeGrp; separator -h 15 -w 400 -style "none"; rowLayout -nc 2 -cw2 90 180; text -l "Tangent Types " -font "boldLabelFont" -w 90 -al "left"; text -l "(selected at random for each key)"-w 180 -al "left"; setParent..; rowLayout -nc 4 -cw4 80 80 80 80; checkBox -l "spline" -v 1 pkjSplineBox; checkBox -l "linear" -v 1 pkjLinearBox; checkBox -l "flat" -v 1 pkjFlatBox; checkBox -l "clamped" -v 1 pkjClampedBox; setParent..; rowLayout -nc 4 -cw4 80 80 80 80; checkBox -l "step" -v 0 pkjStepBox; checkBox -l "fast" -v 0 pkjFastBox; checkBox -l "slow" -v 0 pkjSlowBox; setParent..; separator -h 15 -w 400 -style "none"; text -l "Other Options" -w 300 -font "boldLabelFont" -align "left"; checkBox -l "delete existing keys in range" -v 1 pkjDeleteExistingBox; checkBox -l "same keys for all objects/attributes" -v 0 pkjSameKeysBox; //checkBox -l "same keys for all objects/attributes" -v 0 pkjSameKeysBox; separator -h 15 -w 400 -style "none"; rowLayout -nc 2 -cw2 200 200 -cl2 "center" "center"; button -l "Apply Jitter" -w 200 -al "center" -c "parisKJApplyJitter"; button -l "Close" -w 200 -al "center" -c "deleteUI parisKJWindow"; setParent..; setParent..; window -e -wh 435 495 -title "Keyframe Jitter" parisKJWindow; showWindow parisKJWindow; } global proc parisKJApplyJitter() { int $startFrame; int $endFrame; string $tangentTypes[]; string $attrs[] = parisKJGetSelectedObjAttrs(); if (size($attrs)) { int $frameRangeMode = `radioButtonGrp -q -sl pkjFrameRangeGrp`; if ($frameRangeMode==1) { $startFrame = `playbackOptions -q -min`; $endFrame = `playbackOptions -q -max`; } else { $startFrame = `intField -q -v pkjFrameField1`; $endFrame = `intField -q -v pkjFrameField2`; if ($endFrame<$startFrame) { int $temp = $startFrame; $startFrame = $endFrame; $endFrame = $temp; } } int $valueMode = `radioButtonGrp -q -sl pkjValueTypeGrp`; int $interval1 = `intField -q -v pkjIntervalField1`; int $interval2 = `intField -q -v pkjIntervalField2`; float $value1 = `floatField -q -v pkjValueField1`; float $value2 = `floatField -q -v pkjValueField2`; int $index = 0; if (`checkBox -q -v pkjSplineBox`) { $tangentTypes[$index] = "spline"; $index++; } if (`checkBox -q -v pkjLinearBox`) { $tangentTypes[$index] = "linear"; $index++; } if (`checkBox -q -v pkjFlatBox`) { $tangentTypes[$index] = "flat"; $index++; } if (`checkBox -q -v pkjClampedBox`) { $tangentTypes[$index] = "clamped"; $index++; } if (`checkBox -q -v pkjStepBox`) { $tangentTypes[$index] = "step"; $index++; } if (`checkBox -q -v pkjFastBox`) { $tangentTypes[$index] = "fast"; $index++; } if (`checkBox -q -v pkjSlowBox`) { $tangentTypes[$index] = "slow"; $index++; } int $deleteExisting = `checkBox -q -v pkjDeleteExistingBox`; int $sameKeys = `checkBox -q -v pkjSameKeysBox`; if ($deleteExisting) { for ($a in $attrs) { //delete existing keys in range string $splitAttr[]; tokenize $a $splitAttr; string $range = $startFrame+":"+$endFrame; cutKey -t $range -at $splitAttr[1] $splitAttr[0]; } } if ($sameKeys) { float $startVals[]; for ($i = 0; $i