// Shaker 1.2 - Maya 2.5 // Changes in 1.2 // // you dont have to input the name, just pre-select // the objects you want to animate and hit enter.... // // tanx to Alexandre PIT ! // // Created by: // Luiz Fernando Valente // e-motion digital studios inc. // lfvsouza@zipmail.com.br // This script allows you "shake" an object creating // automatic keyframe with random animation over time // usage: // // just type: // // shaker; // // // enjoy. // ------- Program ------------ global proc shaker () { // choose select tool global string $gSelect; setToolTo $gSelect; if (`window -exists ui_shaker` == true) deleteUI ui_shaker; window -maximizeButton false -resizeToFitChildren true -title "Shaker 1.2" -iconName "Shaker" ui_shaker; columnLayout -adjustableColumn true -cal "left"; floatSliderGrp -label "Translate X" -field true -precision 1 -value 1 -minValue 0 -maxValue 50 -sliderStep .1 trax; floatSliderGrp -label "Translate Y" -field true -precision 1 -value 1 -minValue 0 -maxValue 50 -sliderStep .1 tray; floatSliderGrp -label "Translate Z" -field true -precision 1 -value 1 -minValue 0 -maxValue 50 -sliderStep .1 traz; floatSliderGrp -label "Rotate X" -field true -precision 0 -value 20 -minValue 0 -maxValue 360 -sliderStep 1 rotx; floatSliderGrp -label "Rotate Y" -field true -precision 0 -value 20 -minValue 0 -maxValue 360 -sliderStep 1 roty; floatSliderGrp -label "Rotate Z" -field true -precision 0 -value 20 -minValue 0 -maxValue 360 -sliderStep 1 rotz; intSliderGrp -label "Anim Start" -field true -value 0 -minValue 0 -maxValue 300 -sliderStep 1 anistart; intSliderGrp -label "Anim End" -field true -value 50 -minValue 0 -maxValue 300 -sliderStep 1 aniend; intSliderGrp -label "Anim Step" -field true -value 10 -minValue 0 -maxValue 300 -sliderStep 1 anistep; button -label "Execute Shaker" -align "center" -command "v_shaker"; button -label "Close Shaker" -align "center" -command "c_shaker"; showWindow ui_shaker; } global proc v_shaker () { // Criando Variaveis entradas pelo usuario string $nomes[] = `ls -sl`; int $quant = `size($nomes)`; float $trax = `floatSliderGrp -q -value trax`; float $tray = `floatSliderGrp -q -value tray`; float $traz = `floatSliderGrp -q -value traz`; float $rotx = `floatSliderGrp -q -value rotx`; float $roty = `floatSliderGrp -q -value roty`; float $rotz = `floatSliderGrp -q -value rotz`; int $anistart = `intSliderGrp -q -value anistart`; int $aniend = `intSliderGrp -q -value aniend`; int $anistep = `intSliderGrp -q -value anistep`; // Criando Variaveis auxiliares int $conta, $lope; float $antigo; float $atual; float $randomico; float $teste; float $itrax,$itray,$itraz,$irotx,$iroty,$irotz; string $nome; // Criando LOOP para todos os elementos // selecionados para Shaker. for($lope=0;$lope<$quant;$lope++) { $nome = $nomes[$lope]; // Setup inicial da animacao select $nome; currentTime -e $anistart; setKeyframe -at translateX; setKeyframe -at translateY; setKeyframe -at translateZ; setKeyframe -at rotateX; setKeyframe -at rotateY; setKeyframe -at rotateZ; // Pegando os parametros iniciais $itrax = eval ("getAttr " + $nome + ".translateX"); $itray = eval ("getAttr " + $nome + ".translateY"); $itraz = eval ("getAttr " + $nome + ".translateZ"); $irotx = eval ("getAttr " + $nome + ".rotateX"); $iroty = eval ("getAttr " + $nome + ".rotateY"); $irotz = eval ("getAttr " + $nome + ".rotateZ"); // Animando agora nos tempos pedidos for ($conta= $anistart+$anistep; $conta<= $aniend; $conta=$conta + $anistep) { currentTime -e $conta; // TRANSLATE X $randomico=eval("rand(-" + $trax + "," + $trax + ")" ); $antigo= eval("getAttr " + $nome + ".translateX" ); $wait = $antigo + $randomico ; if ($wait>$itrax + $trax) $wait=$itrax + $trax; if ($wait<$itrax - $trax) $wait=$itrax - $trax; eval("setAttr " + $nome + ".translateX " + $wait); setKeyframe -at translateX; // TRANSLATE Y $randomico=eval("rand(-" + $tray + "," + $tray + ")" ); $antigo= eval("getAttr " + $nome + ".translateY" ); $wait = $antigo + $randomico ; if ($wait>$itray + $tray) $wait=$itray + $tray; if ($wait<$itray - $tray) $wait=$itray - $tray; eval("setAttr " + $nome + ".translateY " + $wait); setKeyframe -at translateY; // TRANSLATE Z $randomico=eval("rand(-" + $traz + "," + $traz + ")" ); $antigo= eval("getAttr " + $nome + ".translateZ" ); $wait = $antigo + $randomico ; if ($wait>$itraz + $traz) $wait=$itraz + $traz; if ($wait<$itraz - $traz) $wait=$itraz - $traz; eval("setAttr " + $nome + ".translateZ " + $wait); setKeyframe -at translateZ; // ROTATE X $randomico=eval("rand(-" + $rotx + "," + $rotx + ")" ); $antigo= eval("getAttr " + $nome + ".rotateX" ); $wait = $antigo + $randomico ; if ($wait>$irotx + $rotx) $wait=$irotx + $rotx; if ($wait<$irotx - $rotx) $wait=$irotx - $rotx; eval("setAttr " + $nome + ".rotateX " + $wait); setKeyframe -at rotateX; // ROTATE Y $randomico=eval("rand(-" + $roty + "," + $roty + ")" ); $antigo= eval("getAttr " + $nome + ".rotateY" ); $wait = $antigo + $randomico ; if ($wait>$iroty + $roty) $wait=$iroty + $roty; if ($wait<$iroty - $roty) $wait=$iroty - $roty; eval("setAttr " + $nome + ".rotateY " + $wait); setKeyframe -at rotateY; // ROTATE Z $randomico=eval("rand(-" + $rotz + "," + $rotz + ")" ); $antigo= eval("getAttr " + $nome + ".rotateZ" ); $wait = $antigo + $randomico ; if ($wait>$irotz + $rotz) $wait=$irotz + $rotz; if ($wait<$irotz - $rotz) $wait=$irotz - $rotz; eval("setAttr " + $nome + ".rotateZ " + $wait); setKeyframe -at rotateZ; } // FINAL DO FOR DE ANIMACAO } // FINAL DO FOR DE REPETICAO PARA CADA ELEMENTO } // FINAL DO PROCEDIMENTO global proc c_shaker () { deleteUI ui_shaker; }