/********************************************************************************************************** Alien Replacer 1.1 ******what does this script do? This script, like maya's instancer, make a particles replacement, but use object's copies instead of instances. This allows users to edit every single object and change its animation manually or delete some of them, generally fit the animation to your desires. This way of instancing also avoid maya's instancing bugs (for example no blur with instances). Objects are animated by keyframe at a desire frame step and with desire tangents. ******what do I have to do to use it? to use this script you have to copy this file "alienReplacer.mel" in your script directory and the file "alienReplacer.bmp" into your icons directory. Restart maya or source the script and then execute the string "alienReplacer();" ******how can I use it? (optional)Select object, then shift-select particles(/optional), run the "alienReplacer();" procedure to get the interface with the following options: Copy with input connections: Duplicate source object with input connections Apply transformations to a null group: Preserve object input connections by creating a group over it Start Time: Start frame animation End Time: End frame animation Use Time Slider: Get the simulation time from the time slider Step Time: Step time in frame between a keyframe and the next one Random Scale: Values to randomize copies' scale Equal scale values: Apply the same random values to X, Y and Z Apply to all: Copy X min and X max to other values Random Rotate: Values to randomize copies' rotate Aim Geometry: Aim object to its path along selected axis Delete Particles: Delete particles after simulation Replace: Start the simulation to replace particles Reset: Reset options Info: Open a info window Exit: Quit the script with no operations /********************************************************************************************************** Alien Replacer 1.1 created by Nicola Danese *** n.danese@ubik.it *** based on the jms_pr script Purpose: This script, like maya's instancer, make a particles replacement, but use object's copies instead of instances. this allows users to edit every single object and change its animation or delete some of them. Objects are animated by keyframe. Instructions: Select object, then shift-select particles, run the alienReplacer procedure to get the interface with the following options: Copy with input connections: Duplicate source object with input connections Apply transformations to a null group: Preserve object input connections by creating a group over it Start Time: Start frame animation End Time: End frame animation Use Time Slider: Get the simulation time from the time slider Step Time: Step time in frame between a keyframe and the next one Random Scale: Values to randomize copies' scale Equal scale values: Apply the same random values to X, Y and Z Apply to all: Copy X min and X max to other values Random Rotate: Values to randomize copies' rotate Aim Geometry: Aim object to its path along selected axis Delete Particles: Delete particles after simulation Replace: Start the simulation to replace particles Reset: Reset options Info: Open a info window Exit: Quit the script with no operations Bugs: - If a particle die, at the last frame object's aim doesn't work properly. If you need that option you can correct it manually. - particles death sometimes cause error on random scale and rotate when switching objects. use it at your own risk!! To do: - Improve aim options - Correct scale and rotate to fit that bug (try to create an array with scale quantity, and match the object to that value, so the scale is still costant) History: 1.1 - Add the multiple objects selection to replace it randomly - Add the "equal scale values" check to uniform the random scale - Add the "Apply to all" button to copy the X settings to Y and Z, both for scale and rotate Contacts: www.ubik.it n.danese@ubik.it -#H####HM- %#######$%X@####@/ ./##MX :X##/ /###/. -###: X##, ##+ X##; -##% %#M ##/ /#X. =##= .##- /## +# .#= $## ##; ##- +#X #M -## #. /# .M -# /# ####H% #/ +# -H#;-;+#%, #/ $# =#@, =@#: #% $# ,#$ +#- #+ X# M%:#M:H#H: X#; #/ +# -@#;H# X- ,X+ +# #, :# @/ MH/% .@ .# # .#/ @ ##=X. #- #/ :# #% # @#;;% ,% X: @H +# ##: #=## /#,=@ #/ /#X /## ;#X ;##- ++ X X# @M. @# =@ %. .+@ ;# #+ /#; .# /X#@%. .#- ;#. #M- :# #% .M@ X##% ## ##/##: /## ,#+ H##M- X##@#: M##; ####- X##, .$##/ :$#X#; H#@####H%;;:;M$MM##X#H;##@ /#M ,/##########X/ X-=M. M$M,##H.-/+#///-.%#@, #@##; $##,$ X= =#@+ :$ H; ,##; :## M#X. M#XM. -X#% .;####@ X#M;, H/. .:###=,M#= #H:##X/: -;@##M#/- :#@ -#=/##%H###X@@XX###M+-##; ,##= %#. X@ ,#- H##H. $##$:## .M#- ##X### -#% .M-#%;- -$#: M, %#, ##@ @##=+#H####@##MM### ## /###= #=H/ .@# :#:/ :#, #MX#H ,# ,M -# %#. X+ #--## -## XX@ ##MH. :+##-. #, H# $#/ HM@ H%#/$#M#$%++XH###: $ :#- /#M. #/@@$ :#/ ,-M+X$%+//,#/- -# -#X X####. =#= $X @$ # ;@ $$ #$ X#% H#X; #%-,#@ ,H-- %X #, #, -##; ##/.#$, =######@X%XH@#####.. @# # ## +#@### ##HX.-%:@#,##% ,;;////=- #,, @:.# ,#+ M, ;/#$ /#@,MM-$##X ###: @#HH@,/X ##.X# X ###. .M#@M:##/#H =### ##M+X #=;X $= .#$ ###-#M####: /##MMM@X+:;...--=######H#-#MM= ,+X%@##/ :##$+#@##$ %##= ./$@#########:-M#####:##; :## $##+ @X/#; X##X ;;#%$$X#H =+###;-+#, XX$#/ ##M#/#-##- ########H%/:=-/:/#/ @#X-/XX:%###:X##M ##.%####= ##+ #=:/X#@MM####% M#++,%HX=-@#+ X:# ##M##@#@ ###/ #@.,## ..,,.@#: @#X-####X@-X=X# # ;@##. #%=#, $+;M. :#% ,@#=#%@#-;%#X @M# . #: ;@#/#@# ::/X## .##M -##M =#@##= .#% ,/##- -#M###### %#X .M#@ .##H: .XX#X$;:==/H# $#.+#+ %#####+/;@/ /# #M##, /H####H .#. . /+M#######MM###/ $##########: -++%$%$$%+/ ***************************************************************************************************************/ //code begin here //procedura per gestire le input connection nella duplicazione //handle the input connection option global proc checkCopyIC() { if (`checkBox -q -v chk6`) { checkBox -e -v true chk7; } } //procedure's end //procedura per gestire la scrollbar del tempo di animazione //handle the scrollbar of animation's time global proc checkTimeS() { global int $laststartTime; global int $lastEndTime; global int $startTime; global int $endTime; if (`checkBox -q -v chk1`) { $laststartTime = $startTime; $lastEndTime = $endTime; $startTime = `playbackOptions -q -min`; $endTime = `playbackOptions -q -max`; intSliderGrp -e -en false -v $startTime startTimeSlider; intSliderGrp -e -en false -v $endTime endTimeSlider; } else { $startTime = $laststartTime; $endTime = $lastEndTime; intSliderGrp -e -en true -v $startTime startTimeSlider; intSliderGrp -e -en true -v $endTime endTimeSlider; } } //procedure's end //procedura per recuperare il tempo di inizio animazione //get animation's start time global proc fldTimeS() { global int $startTime; $startTime = `intSliderGrp -q -v startTimeSlider`; } //procedure's end //procedura per recuperare il tempo di fine animazione //get animation's end time global proc fldTimeE() { global int $endTime; $endTime = `intSliderGrp -q -v endTimeSlider`; } //procedure's end //procedure per recuperare lo step time //get the step time global proc fldStepTime() { global int $stepTime; $stepTime= `intSliderGrp -q -v stepTimeSlider`; } //procedura per gestire il lock della scala //apply X scale to all scale global proc checkScaleLock() { if (`checkBox -q -v chk2X`) { checkBox -e -v false chkEqualScale; float $copyScaleMin = `floatSliderGrp -q -v scaleSliderMinX`; float $copyScaleMax = `floatSliderGrp -q -v scaleSliderMaxX`; checkBox -e -v true chk2Y; floatSliderGrp -e -en true -v $copyScaleMin scaleSliderMinY; floatSliderGrp -e -en true -v $copyScaleMax scaleSliderMaxY; fldScaleVY(); checkBox -e -v true chk2Z; floatSliderGrp -e -en true -v $copyScaleMin scaleSliderMinZ; floatSliderGrp -e -en true -v $copyScaleMax scaleSliderMaxZ; fldScaleVZ(); } } //procedure's end //procedura per gestire il lock della rotazione //apply X scale to all rotate global proc checkRotateLock() { if (`checkBox -q -v chk3X`) { float $copyRotateMin = `intSliderGrp -q -v twistSliderMinX`; float $copyRotateMax = `intSliderGrp -q -v twistSliderMaxX`; checkBox -e -v true chk3Y; intSliderGrp -e -en true -v $copyRotateMin twistSliderMinY; intSliderGrp -e -en true -v $copyRotateMax twistSliderMaxY; fldtwistVY(); checkBox -e -v true chk3Z; intSliderGrp -e -en true -v $copyRotateMin twistSliderMinZ; intSliderGrp -e -en true -v $copyRotateMax twistSliderMaxZ; fldtwistVZ(); } } //procedure's end //procedura per gestire l'equal delle scala //handle the equal scale option global proc checkEqualScale() { if (`checkBox -q -v chkEqualScale`) { checkBox -e -l "Random Scale" chk2X; checkBox -e -en false -v false chk2Y; checkBox -e -en false -v false chk2Z; floatSliderGrp -e -l "min value: " scaleSliderMinX; floatSliderGrp -e -l "max value: " scaleSliderMaxX; floatSliderGrp -e -en false -v 1 scaleSliderMinY; floatSliderGrp -e -en false -v 1 scaleSliderMaxY; floatSliderGrp -e -en false -v 1 scaleSliderMinZ; floatSliderGrp -e -en false -v 1 scaleSliderMaxZ; } else { checkBox -e -l "Random Scale X" chk2X; checkBox -e -en true -v false chk2Y; checkBox -e -en true -v false chk2Z; floatSliderGrp -e -l "X min value: " scaleSliderMinX; floatSliderGrp -e -l "X max value: " scaleSliderMaxX; floatSliderGrp -e -en true -v 1 scaleSliderMinY; floatSliderGrp -e -en true -v 1 scaleSliderMaxY; floatSliderGrp -e -en true -v 1 scaleSliderMinZ; floatSliderGrp -e -en true -v 1 scaleSliderMaxZ; } } //procedure's end //procedura che gestisce il fattore di scala X //handle the X scale factor global proc checkRandomSX() { global float $scaleVMinX; global float $scaleVMaxX; if (`checkBox -q -v chk2X`) { floatSliderGrp -e -en true -v $scaleVMinX scaleSliderMinX; floatSliderGrp -e -en true -v $scaleVMaxX scaleSliderMaxX; checkBox -e -en true chkEqualScale; } else { $scaleVMinX = 1.0; $scaleVMaxX = 1.0; floatSliderGrp -e -en false -v $scaleVMinX scaleSliderMinX; floatSliderGrp -e -en false -v $scaleVMaxX scaleSliderMaxX; checkBox -e -en false -v false chkEqualScale; } } //procedure's end //procedura che recupera il fattore random di scala X //get the X scale factor global proc fldScaleVX() { global float $scaleVMinX; global float $scaleVMaxX; $scaleVMinX = `floatSliderGrp -q -v scaleSliderMinX`; $scaleVMaxX = `floatSliderGrp -q -v scaleSliderMaxX`; } //procedure's end //procedura che gestisce il fattore di scala Y //handle the Y scale factor global proc checkRandomSY() { global float $scaleVMinY; global float $scaleVMaxY; if (`checkBox -q -v chk2Y`) { floatSliderGrp -e -en true -v $scaleVMinY scaleSliderMinY; floatSliderGrp -e -en true -v $scaleVMaxY scaleSliderMaxY; } else { $scaleVMinY = 1.0; $scaleVMaxY = 1.0; floatSliderGrp -e -en false -v $scaleVMinY scaleSliderMinY; floatSliderGrp -e -en false -v $scaleVMaxY scaleSliderMaxY; } } //procedure's end //procedura che recupera il fattore random di scala Y //get the Y scale factor global proc fldScaleVY() { global float $scaleVMinY; global float $scaleVMaxY; $scaleVMinY = `floatSliderGrp -q -v scaleSliderMinY`; $scaleVMaxY = `floatSliderGrp -q -v scaleSliderMaxY`; } //procedure's end //procedura che gestisce il fattore di scala Z //handle the Z scale factor global proc checkRandomSZ() { global float $scaleVMinZ; global float $scaleVMaxZ; if (`checkBox -q -v chk2Z`) { floatSliderGrp -e -en true -v $scaleVMinZ scaleSliderMinZ; floatSliderGrp -e -en true -v $scaleVMaxZ scaleSliderMaxZ; } else { $scaleVMinZ = 1.0; $scaleVMaxZ = 1.0; floatSliderGrp -e -en false -v $scaleVMinZ scaleSliderMinZ; floatSliderGrp -e -en false -v $scaleVMaxZ scaleSliderMaxZ; } } //procedure's end //procedura che recupera il fattore random di scala Z //get the Z scale factor global proc fldScaleVZ() { global float $scaleVMinZ; global float $scaleVMaxZ; $scaleVMinZ = `floatSliderGrp -q -v scaleSliderMinZ`; $scaleVMaxZ = `floatSliderGrp -q -v scaleSliderMaxZ`; } //procedure's end //procedura che gestisce il fattore random di rotazione X //handle the X twist factor global proc checkRandomTX() { global int $twistVMinX; global int $twistVMaxX; if (`checkBox -q -v chk3X`) { $twistVMaxX = 360; intSliderGrp -e -en true -v $twistVMinX twistSliderMinX; intSliderGrp -e -en true -v $twistVMaxX twistSliderMaxX; } else { $twistVMinX = 0; $twistVMaxX = 0; intSliderGrp -e -en false -v $twistVMinX twistSliderMinX; intSliderGrp -e -en false -v $twistVMaxX twistSliderMaxX; } } //procedure's end //procedura che recupera il fattore random di rotazione X //get the X twist factor global proc fldtwistVX() { global int $twistVMinX; global int $twistVMaxX; $twistVMinX = `intSliderGrp -q -v twistSliderMinX`; $twistVMaxX = `intSliderGrp -q -v twistSliderMaxX`; } //procedure's end //procedura che gestisce il fattore random di rotazione Y //handle the Y twist factor global proc checkRandomTY() { global int $twistVMinY; global int $twistVMaxY; if (`checkBox -q -v chk3Y`) { $twistVMaxY = 360; intSliderGrp -e -en true -v $twistVMinY twistSliderMinY; intSliderGrp -e -en true -v $twistVMaxY twistSliderMaxY; } else { $twistVMinY = 0; $twistVMaxY = 0; intSliderGrp -e -en false -v $twistVMinY twistSliderMinY; intSliderGrp -e -en false -v $twistVMaxY twistSliderMaxY; } } //procedure's end //procedura che recupera il fattore random di rotazione Y //get the Y twist factor global proc fldtwistVY() { global int $twistVMinY; global int $twistVMaxY; $twistVMinY = `intSliderGrp -q -v twistSliderMinY`; $twistVMaxY = `intSliderGrp -q -v twistSliderMaxY`; } //procedure's end //procedura che gestisce il fattore random di rotazione Z //handle the Z twist factor global proc checkRandomTZ() { global int $twistVMinZ; global int $twistVMaxZ; if (`checkBox -q -v chk3Z`) { $twistVMaxZ = 360; intSliderGrp -e -en true -v $twistVMinZ twistSliderMinZ; intSliderGrp -e -en true -v $twistVMaxZ twistSliderMaxZ; } else { $twistVMinZ = 0; $twistVMaxZ = 0; intSliderGrp -e -en false -v $twistVMinZ twistSliderMinZ; intSliderGrp -e -en false -v $twistVMaxZ twistSliderMaxZ; } } //procedure's end //procedura che recupera il fattore random di rotazione Z //get the Z twist factor global proc fldtwistVZ() { global int $twistVMinZ; global int $twistVMaxZ; $twistVMinZ = `intSliderGrp -q -v twistSliderMinZ`; $twistVMaxZ = `intSliderGrp -q -v twistSliderMaxZ`; } //procedure's end //procedura che gestisce l'aim e disabilita le rotazioni random... //handle the aim options and disable twist if necessary global proc checkAlign() { if (`checkBox -q -v chk4`) { radioButtonGrp -e -en true rbg; checkBox -e -v false -en false chk3X; checkBox -e -v false -en false chk3Y; checkBox -e -v false -en false chk3Z; checkRandomTX; checkRandomTY; checkRandomTZ; } else { radioButtonGrp -e -en false rbg; checkBox -e -en true chk3X; checkBox -e -en true chk3Y; checkBox -e -en true chk3Z; } } //procedure's end //procedura principale ******************************************************************************** //main procedure global proc replace() { //inizializzo variabili //set vars global int $startTime; global int $endTime; global int $stepTime; global int $aniScale = 1; global float $scaleVMinX; global float $scaleVMaxX; global float $scaleVMinY; global float $scaleVMaxY; global float $scaleVMinZ; global float $scaleVMaxZ; global int $aniTwist = 1; global int $twistVMinX; global int $twistVMaxX; global int $twistVMinY; global int $twistVMaxY; global int $twistVMinZ; global int $twistVMaxZ; global string $part; global string $objectList[]; global int $numberOfObject; global string $geom; global string $copyName; global string $padName; global string $grpName; global string $grpNameLoc; global string $transformObj; global string $keyObj; global string $keyLoc; int $particleCheCiSono; //recupero il nome delle nuove copie //get the copy name $copyName = `textFieldGrp -q -tx copyName`; if ($copyName == "") { $copyName = "copy"; } //creo il vettore di oggetti da copiare $objectList = `textScrollList -q -ai chosenGeometry`; $numberOfObject = size($objectList); //controlli vari su selezioni //check for correct selections if (($part == "") || ($numberOfObject == 0)) { print "please select particles and at least one object"; return; } //creo il gruppo superiore //create a group over the copies $grpName = $copyName + "Grp"; group -em -name $grpName; //creo il gruppo dei locator se necessario //locator group if necessary if (`checkBox -q -v chk4`) { $grpNameLoc = $grpName + "Loc"; group -em -name $grpNameLoc; } //calcolo quante particelle ho per ogni frame, e tengo il numero maggiore per calcolare il //numero di oggetti necessari ma prima le invisibilizzo per velocizzare l'operazione //hide the particles and get their number at every frame so I can duplicate the exact number of objects setAttr ($part + ".visibility") 0; int $numberOfParticles = 0; int $numberOfParticlesNow; for ($j=$startTime;$j<=$endTime;$j++) { currentTime $j; $numberOfParticlesNow = `getAttr ($part + ".count")`; if ($numberOfParticlesNow > $numberOfParticles) { $numberOfParticles = $numberOfParticlesNow; } } //duplico il numero giusto di oggetti //duplicate the needed amount of objects for ($k=0;$k<$numberOfParticles;$k++) { $name = ($copyName + $k); //ATTENZIONE!!! tolgo autokeyframe che da problemi nell'input connections! //WARNING!!! disable the autokeyframe option, no good with this script! autoKeyframe -state false; //se e' selezionata l'opzione duplico con input connections //if needed, duplicate with input connections if (`checkBox -q -v chk6`) { int $whichObject = floor(rand(0,$numberOfObject)); duplicate -ic -name $name $objectList[$whichObject]; } //altrimenti niente input connections //otherwise, no input in the copies else { int $whichObject = floor(rand(0,$numberOfObject)); duplicate -name $name $objectList[$whichObject]; } //se opzione aim creo il locator associato e faccio l'aimConstraint con l'opzione desiderata //if the copies are aimed, create the locator and do an aimConstraint between copies and locators if (`checkBox -q -v chk4`) { spaceLocator; $nomeLocator = $name + "Loc"; rename "locator1" $nomeLocator; parent $nomeLocator $grpNameLoc; int $aimOption = `radioButtonGrp -q -sl rbg`; string $aim = ""; string $aimCommand; switch($aimOption) { case 1: // X Axis $aim = " -aimVector 1 0 0 "; break; case 2: // Y Axis $aim = " -aimVector 0 1 0 "; break; case 3: // Z Axis $aim = " -aimVector 0 0 1 "; break; } $aimCommand = ("aimConstraint -offset 0 0 0 -weight 1 "+ $aim +" -worldUpType \"vector\" " + $nomeLocator + " " + $name); eval $aimCommand; } //se e' selezionata l'opzione del pad lo creo e metto il pad nel gruppone principale //do you want a group over every copy?let's do it...create the group if (`checkBox -q -v chk7`) { $padName = $name + "Pad"; group -n $padName $name; //metto la copia dentro il gruppo //and put the copy into its group parent $padName $grpName; } //altrimenti metto tutto nel gruppone senza pad //otherwise put the copies in the main group else { parent $name $grpName; } //se c'e' un pad applico le trasformazioni al pad altrimenti all'oggetto //if there's a single group transformations are applied to it, otherwise transformation are applied to the copy if (`checkBox -q -v chk7`) { $transformObj = $padName; } else { $transformObj = $name; } //setto la visibilita' della copia su off //object visibility off until particle born setKeyframe -attribute "visibility" -v off -t 1 $transformObj; //randomizzo la scala secondo il fattore indicato //create a random scale factor if ($aniScale == 1) { float $scaleValueX = rand($scaleVMinX,$scaleVMaxX); float $scaleValueY = rand($scaleVMinY,$scaleVMaxY); float $scaleValueZ = rand($scaleVMinZ,$scaleVMaxZ); //se c'e' equal scale la scala random e' unica per tutti gli assi //if equal scale is on, the random value is the same for X, Y, and Z if (`checkBox -q -v chkEqualScale`) { $scaleValueY = $scaleValueZ = $scaleValueX; } setAttr ($transformObj + ".scaleX") $scaleValueX; setAttr ($transformObj + ".scaleY") $scaleValueY; setAttr ($transformObj + ".scaleZ") $scaleValueZ; } //randomizzo la rotazione secondo il fattore indicato //create a random twist factor if ($aniTwist == 1) { float $rotateValueX = rand($twistVMinX,$twistVMaxX); float $rotateValueY = rand($twistVMinY,$twistVMaxY); float $rotateValueZ = rand($twistVMinZ,$twistVMaxZ); setAttr ($transformObj + ".rotateX") $rotateValueX; setAttr ($transformObj + ".rotateY") $rotateValueY; setAttr ($transformObj + ".rotateZ") $rotateValueZ; } } //animo le copie dell'oggetto settando dei keyframe //set a lot of keyframes for ($i = $startTime;$i<=$endTime;$i++) { currentTime $i; if (($i%$stepTime == 0) || ($i == $startTime) || ($i == $endTime)) { $particleCheCiSono = `getAttr ($part + ".count")`; for ($l=0;$l<$numberOfParticles;$l++) { float $v[]; if (`checkBox -q -v chk7`) { $keyObj = ($copyName + $l + "Pad"); } else { $keyObj = $copyName + $l; } $keyLoc = $copyName + $l + "Loc"; //visibilita' on quando l'oggetto e' animato //visibility on when object is animated setKeyframe -attribute "visibility" -v on -t $i $keyObj; //chiavo l'oggetto //set keys $v = `getParticleAttr -at position ($part + ".pt[" + $l + "]")`; setKeyframe -attribute "translateX" -v $v[0] -t $i $keyObj; setKeyframe -attribute "translateY" -v $v[1] -t $i $keyObj; setKeyframe -attribute "translateZ" -v $v[2] -t $i $keyObj; //chiavo i locator se ci sono //set keys on locators if needed if (`checkBox -q -v chk4`) { setKeyframe -attribute "translateX" -v $v[0] -t ($i -1) $keyLoc; setKeyframe -attribute "translateY" -v $v[1] -t ($i -1) $keyLoc; setKeyframe -attribute "translateZ" -v $v[2] -t ($i -1) $keyLoc; //all'ultimo frame dell'animazione l'aim sbaglia //the aim at the last frame is wrong if ($i == $endTime) { setKeyframe -attribute "visibility" -v off -t $i $keyObj; } } //se l'oggetto e' legato ad una particella morta lo invisibilizzo //if object is related to a dead particle let's set its visibility to false if ($l >= $particleCheCiSono) { setKeyframe -attribute "visibility" -v off -t $i $keyObj; } } } } //invisibilizzo il gruppo dei locator //hide locators' group if (`checkBox -q -v chk4`) { setAttr ($grpNameLoc + ".visibility") 0; } //cancello le particelle se opzionato //delete particle option is checked if (`checkBox -q -v chk5`) { string $delCommand = ("delete " + $part); eval $delCommand; } //torno al frame iniziale dell'animazione e rivisibilizzo le particelle //get back to first frame of animation currentTime $startTime; setAttr ($part + ".visibility") 1; } //procedure's end ************************************************************************************************** //procedura che resetta l'interfaccia //reset the UI global proc doReset() { global int $startTime; global int $endTime; global int $laststartTime; global int $lastEndTime; global int $stepTime; global float $scaleVMinX; global float $scaleVMaxX; global float $scaleVMinY; global float $scaleVMaxY; global float $scaleVMinZ; global float $scaleVMaxZ; global int $twistVMinX; global int $twistVMaxX; global int $twistVMinY; global int $twistVMaxY; global int $twistVMinZ; global int $twistVMaxZ; $startTime = $laststartTime = 1; $endTime = $lastEndTime = 100; $stepTime = 1; $scaleVMinX = 1.0; $scaleVMaxX = 1.0; $scaleVMinY = 1.0; $scaleVMaxY = 1.0; $scaleVMinZ = 1.0; $scaleVMaxZ = 1.0; $twistVMinX = 0; $twistVMaxX = 0; $twistVMinY = 0; $twistVMaxY = 0; $twistVMinZ = 0; $twistVMaxZ = 0; checkBox -e -v false chk1; checkBox -e -v false chk2X; checkBox -e -v false -en false chkEqualScale; checkEqualScale(); checkBox -e -v false chk2Y; checkBox -e -v false chk2Z; checkBox -e -v false chk3X; checkBox -e -v false chk3Y; checkBox -e -v false chk3Z; checkBox -e -v false chk4; checkBox -e -v false chk5; checkBox -e -v false chk6; checkBox -e -v false chk7; intSliderGrp -e -en true -v $stepTime stepTimeSlider; intSliderGrp -e -en true -v $startTime startTimeSlider; intSliderGrp -e -en true -v $endTime endTimeSlider; floatSliderGrp -e -en false -v $scaleVMinX scaleSliderMinX; floatSliderGrp -e -en false -v $scaleVMaxX scaleSliderMaxX; floatSliderGrp -e -en false -v $scaleVMinY scaleSliderMinY; floatSliderGrp -e -en false -v $scaleVMaxY scaleSliderMaxY; floatSliderGrp -e -en false -v $scaleVMinZ scaleSliderMinZ; floatSliderGrp -e -en false -v $scaleVMaxZ scaleSliderMaxZ; checkBox -e -en true chk3X; checkBox -e -en true chk3Y; checkBox -e -en true chk3Z; intSliderGrp -e -en false -v $twistVMinX twistSliderMinX; intSliderGrp -e -en false -v $twistVMaxX twistSliderMaxX; intSliderGrp -e -en false -v $twistVMinY twistSliderMinY; intSliderGrp -e -en false -v $twistVMaxY twistSliderMaxY; intSliderGrp -e -en false -v $twistVMinZ twistSliderMinZ; intSliderGrp -e -en false -v $twistVMaxZ twistSliderMaxZ; radioButtonGrp -e -en false -sl 2 rbg; } //procedure's end //procedura di richiamo selezione particelle //select the particles global proc pickPart() { global string $part; string $sel[] = ` ls -sl `; $part = $sel[0]; textFieldButtonGrp -edit -text $part chosenParticle; } //procedure's end //procedura di richiamo selezione oggetto //select the object global proc pickGeom() { $nodeList = `ls -o -sl`; for ( $cnt = 0; $cnt < size ( $nodeList ); $cnt++ ) textScrollList -e -append ( $nodeList[$cnt] ) chosenGeometry; } //procedure's end //procedura di eliminazione selezione oggetto //delete the objects global proc delGeom() { int $toDelete[] = `textScrollList -q -sii chosenGeometry`; if (size($toDelete) == 1) textScrollList -e -rii $toDelete[0] chosenGeometry; } //procedure's end //procedura che crea la finestra di aiuto //create the info window global proc showInfo() { if (`window -ex AlienReplacerInfo`) deleteUI AlienReplacerInfo; window -title "alien replacer Info" -widthHeight 400 500 AlienReplacerInfo; formLayout -bgc 1 1 1 info; picture -image "alienReplacer.bmp" img; text -en false -bgc 0.137 0.141 0.145 -label "Alien Replacer v 1.1" txt1; text -en false -bgc 1 1 1 -label "Created by Nicola Danese *** n.danese@ubik.it ***" txt2; text -en false -bgc 0.137 0.141 0.145 -label "Purpose:" txt3; text -en false -bgc 1 1 1 -label "This script, like maya's instancer replacement, make a particle replacement, but use object's" txt4; text -en false -bgc 1 1 1 -label "copies instead of instances. this allow users to edit every single object and change" txt5; text -en false -bgc 1 1 1 -label "its animation or delete some of them. Objects are animated by keyframe every selected step time." txt6; text -en false -bgc 0.137 0.141 0.145 -label "Instructions:" txt7; text -en false -bgc 1 1 1 -label "Select object, then shift-select particles, run the alienReplacer procedure to get the interface" txt8; text -en false -bgc 1 1 1 -label "you can also call the alienReplacer procedure and then select object and particles." txt9; text -en false -bgc 1 1 1 -label "the UI offers the following options:" txt10; text -en false -bgc 1 1 1 -label "Copy with input connections: Duplicate source object with input connections" txt11; text -en false -bgc 1 1 1 -label "Apply transformations to a null group: Preserve object input connections by creating a group over it" txt12; text -en false -bgc 1 1 1 -label "Start Time: Start frame animation" txt13; text -en false -bgc 1 1 1 -label "End Time: End frame animation" txt14; text -en false -bgc 1 1 1 -label "Use Time Slider: Get the simulation time from the time slider" txt15; text -en false -bgc 1 1 1 -label "Step Time: Step time in frame between a keyframe and the next one" txt16; text -en false -bgc 1 1 1 -label "Random Scale: Values to randomize copies' scale" txt17; text -en false -bgc 1 1 1 -label "Equal Scale Values: Apply the same random values to X, Y and Z" txt18; text -en false -bgc 1 1 1 -label "Apply to All: Copy X min and X max to other values" txt19; text -en false -bgc 1 1 1 -label "Random Rotate: Values to randomize copies' rotate" txt20; text -en false -bgc 1 1 1 -label "Aim Geometry: Aim object to its path along selected axis" txt21; text -en false -bgc 1 1 1 -label "Delete Particles: Delete particles after simulation" txt22; text -en false -bgc 1 1 1 -label "Replace: Start the simulation to replace particles" txt23; text -en false -bgc 1 1 1 -label "Reset: Reset options" txt24; text -en false -bgc 1 1 1 -label "Exit: Quit the script with no operations" txt25; text -en false -bgc 0.137 0.141 0.145 -label "Bugs:" txt26; text -en false -bgc 1 1 1 -label "- If a particle die, at the last frame object's aim doesn't work properly" txt27; text -en false -bgc 1 1 1 -label " If you need that option you can correct it manually" txt28; text -en false -bgc 1 1 1 -label "- particles death sometimes cause error on random scale and rotate when switching objects" txt29; text -en false -bgc 1 1 1 -label " use it at your own risk!" txt30; text -en false -bgc 0.137 0.141 0.145 -label "Contacts:" txt31; text -en false -bgc 1 1 1 -label "www.ubik.it" txt32; text -en false -bgc 1 1 1 -label "n.danese@ubik.it" txt33; formLayout -e -af img "top" 0 -ac txt1 "top" 10 img -ac txt2 "top" 10 txt1 -ac txt3 "top" 10 txt2 -ac txt4 "top" 0 txt3 -ac txt5 "top" 0 txt4 -ac txt6 "top" 0 txt5 -ac txt7 "top" 10 txt6 -ac txt8 "top" 0 txt7 -ac txt9 "top" 0 txt8 -ac txt10 "top" 0 txt9 -ac txt11 "top" 0 txt10 -ac txt12 "top" 0 txt11 -ac txt13 "top" 0 txt12 -ac txt14 "top" 0 txt13 -ac txt15 "top" 0 txt14 -ac txt16 "top" 0 txt15 -ac txt17 "top" 0 txt16 -ac txt18 "top" 0 txt17 -ac txt18 "top" 0 txt17 -ac txt19 "top" 0 txt18 -ac txt20 "top" 0 txt19 -ac txt21 "top" 0 txt20 -ac txt22 "top" 0 txt21 -ac txt22 "top" 0 txt21 -ac txt23 "top" 0 txt22 -ac txt24 "top" 0 txt23 -ac txt25 "top" 0 txt24 -ac txt26 "top" 10 txt25 -ac txt27 "top" 0 txt26 -ac txt28 "top" 0 txt27 -ac txt29 "top" 0 txt28 -ac txt30 "top" 0 txt29 -ac txt31 "top" 10 txt30 -ac txt32 "top" 0 txt31 -ac txt33 "top" 0 txt32 info; showWindow AlienReplacerInfo; } ////procedure's end //procedura di creazione interfaccia - RICHIAMARE QUESTA! //create the interface - CALL THIS! global proc alienReplacer() { if (`window -ex AlienReplacer`) deleteUI AlienReplacer; window -title "Alien Replacer v 1.1" AlienReplacer; formLayout rcl1; //recupero i dati della selezione //get objects from selection string $sel[] = `ls -sl`;; global string $geom; global string $part; if (size($sel) != 0) { $part = $sel[(size($sel)-1)]; } else { $geom = ""; $part = ""; } //fine recupero dati //end of getting objects from selection //interfaccia //UI //selezione oggetti //objects selection separator -style "in" sep9; textFieldButtonGrp -l "particle" -cw 1 120 -text $part -buttonLabel "Pick" -bc "pickPart()" chosenParticle; text -en true -label "objects" textObj; textScrollList -numberOfRows 5 -w 238 -ams false chosenGeometry; //put object from previous selection for ( $cnt = 0; $cnt < (size($sel)-1); $cnt++ ) textScrollList -e -append ( $sel[$cnt] ) chosenGeometry; button -l "Pick" -c pickGeom btnObj; button -l "Del" -w 31 -c delGeom delObj; textFieldGrp -l "copy name" - cw 1 120 copyName; separator -style "single" sep6; //opzioni di copia //copy options checkBox -l "copy with Input Connection" -cc checkCopyIC -v false chk6; checkBox -l "apply tranformations to a null group" -v false chk7; separator -style "single" sep7; //opzioni del tempo di animazione //time option intSliderGrp -l "Start Time: " -cc fldTimeS -f true -min -10000 -max 10000 startTimeSlider; intSliderGrp -l "End Time: " -cc fldTimeE -f true -min -10000 -max 10000 endTimeSlider; checkBox -l "Use Time Slider" -cc checkTimeS -v false chk1; separator -style "single" sep1; //opzioni dello step time //step time option intSliderGrp -l "Step Time: " -min 1 -max 10 -cc fldStepTime -f true stepTimeSlider; separator -style "single" sep8; //X scale option checkBox -l "Random Scale X" -cc checkRandomSX -v false chk2X; button -l "Apply to all" -c checkScaleLock scaleLock; checkBox -l "Equal scale values" -cc checkEqualScale -v false -en false chkEqualScale; floatSliderGrp -l "X min value: " -cc fldScaleVX -f true -min -100 -max 100 scaleSliderMinX; floatSliderGrp -l "X max value: " -cc fldScaleVX -f true -min -100 -max 100 scaleSliderMaxX; //Y scale option checkBox -l "Random Scale Y" -cc checkRandomSY -v false chk2Y; floatSliderGrp -l "Y min value: " -cc fldScaleVY -f true -min -100 -max 100 scaleSliderMinY; floatSliderGrp -l "Y max value: " -cc fldScaleVY -f true -min -100 -max 100 scaleSliderMaxY; //Z scale option checkBox -l "Random Scale Z" -cc checkRandomSZ -v false chk2Z; floatSliderGrp -l "Z min value: " -cc fldScaleVZ -f true -min -100 -max 100 scaleSliderMinZ; floatSliderGrp -l "Z max value: " -cc fldScaleVZ -f true -min -100 -max 100 scaleSliderMaxZ; separator -style "single" sep2; //X rotate option checkBox -l "Random Rotate X" -cc checkRandomTX -v false chk3X; button -l "Apply to all" -c checkRotateLock rotateLock; intSliderGrp -l "X min value: " -min 0 -max 360 -cc fldtwistVX -f true twistSliderMinX; intSliderGrp -l "X max value: " -min 0 -max 360 -cc fldtwistVX -f true twistSliderMaxX; //Y rotate option checkBox -l "Random Rotate Y" -cc checkRandomTY -v false chk3Y; intSliderGrp -l "Y min value: " -min 0 -max 360 -cc fldtwistVY -f true twistSliderMinY; intSliderGrp -l "Y max value: " -min 0 -max 360 -cc fldtwistVY -f true twistSliderMaxY; //Z rotate option checkBox -l "Random Rotate Z" -cc checkRandomTZ -v false chk3Z; intSliderGrp -l "Z min value: " -min 0 -max 360 -cc fldtwistVZ -f true twistSliderMinZ; intSliderGrp -l "Z max value: " -min 0 -max 360 -cc fldtwistVZ -f true twistSliderMaxZ; separator -style "single" sep3; //aim option checkBox -l "Aim Geometry" -cc checkAlign -v false chk4; radioButtonGrp -l "Up Vector: " -nrb 3 -la3 "X" "Y" "Z" -sl 2 rbg; separator -style "single" sep4; //particles option checkBox -l "Delete Particles" -v false chk5; separator -style "in" sep5; //buttons rowLayout -nc 4 rl1; button -l "Replace" -align "center" -c replace -w 60 but1; button -l "Reset" -align "center" -c doReset -w 60 but2; button -l "Info" -align "center" -c showInfo -w 60 but4; button -l "Exit" -align "center" -c "evalDeferred \"deleteUI AlienReplacer\";" -w 60 but3; setParent..; separator -style "in" sep10; //layout formLayout -e //layout object selection -af sep9 "top" 0 -af sep9 "left" 0 -af sep9 "right" 0 -af chosenParticle "left" 0 -ac chosenParticle "top" 4 sep9 -af textObj "left" 75 -ac textObj "top" 4 chosenParticle -ac chosenGeometry "left" 10 textObj -ac chosenGeometry "top" 4 chosenParticle -ac btnObj "left" 2 chosenGeometry -ac btnObj "top" 4 chosenParticle -ac delObj "left" 2 chosenGeometry -ac delObj "top" 4 btnObj -af copyName "left" 0 -ac copyName "top" 4 chosenGeometry //layout copy options -af sep6 "left" 0 -ac sep6 "top" 4 copyName -af sep6 "right" 0 -af chk6 "left" 0 -ac chk6 "top" 4 sep6 -ac chk7 "left" 0 chk6 -ac chk7 "top" 4 sep6 -af sep7 "left" 0 -ac sep7 "top" 4 chk6 -af sep7 "right" 0 //layout time options -af startTimeSlider "left" 0 -ac startTimeSlider "top" 4 sep7 -af endTimeSlider "left" 0 -ac endTimeSlider "top" 4 startTimeSlider -af chk1 "left" 0 -ac chk1 "top" 4 endTimeSlider -af sep1 "left" 0 -ac sep1 "top" 4 chk1 -af sep1 "right" 0 //layout step time option -af stepTimeSlider "left" 0 -ac stepTimeSlider "top" 4 sep1 -af sep8 "left" 0 -ac sep8 "top" 4 stepTimeSlider -af sep8 "right" 0 //layout scale options -af chk2X "left" 0 -ac chk2X "top" 8 sep8 -ac chkEqualScale "left" 10 chk2X -ac chkEqualScale "top" 8 sep8 -ac scaleLock "left" 10 chkEqualScale -ac scaleLock "top" 4 sep8 -af scaleSliderMinX "left" 0 -ac scaleSliderMinX "top" 4 chk2X -af scaleSliderMaxX "left" 0 -ac scaleSliderMaxX "top" 4 scaleSliderMinX -af chk2Y "left" 0 -ac chk2Y "top" 4 scaleSliderMaxX -af scaleSliderMinY "left" 0 -ac scaleSliderMinY "top" 4 chk2Y -af scaleSliderMaxY "left" 0 -ac scaleSliderMaxY "top" 4 scaleSliderMinY -af chk2Z "left" 0 -ac chk2Z "top" 4 scaleSliderMaxY -af scaleSliderMinZ "left" 0 -ac scaleSliderMinZ "top" 4 chk2Z -af scaleSliderMaxZ "left" 0 -ac scaleSliderMaxZ "top" 4 scaleSliderMinZ -af sep2 "left" 0 -ac sep2 "top" 4 scaleSliderMaxZ -af sep2 "right" 0 //layout rotate options -af chk3X "left" 0 -ac chk3X "top" 8 sep2 -ac rotateLock "left" 10 chk3X -ac rotateLock "top" 4 sep2 -af twistSliderMinX "left" 0 -ac twistSliderMinX "top" 4 chk3X -af twistSliderMaxX "left" 0 -ac twistSliderMaxX "top" 4 twistSliderMinX -af chk3Y "left" 0 -ac chk3Y "top" 4 twistSliderMaxX -af twistSliderMinY "left" 0 -ac twistSliderMinY "top" 4 chk3Y -af twistSliderMaxY "left" 0 -ac twistSliderMaxY "top" 4 twistSliderMinY -af chk3Z "left" 0 -ac chk3Z "top" 4 twistSliderMaxY -af twistSliderMinZ "left" 0 -ac twistSliderMinZ "top" 4 chk3Z -af twistSliderMaxZ "left" 0 -ac twistSliderMaxZ "top" 4 twistSliderMinZ -af sep3 "left" 0 -ac sep3 "top" 4 twistSliderMaxZ -af sep3 "right" 0 //layout aim options -af chk4 "left" 0 -ac chk4 "top" 4 sep3 -af rbg "left" 0 -ac rbg "top" 4 chk4 -af sep4 "left" 0 -ac sep4 "top" 4 rbg -af sep4 "right" 0 //layout particles option -af chk5 "left" 0 -ac chk5 "top" 4 sep4 -af sep5 "left" 0 -ac sep5 "top" 4 chk5 -af sep5 "right" 0 -af rl1 "left" 20 -ac rl1 "top" 10 sep5 -af rl1 "right" 0 -ac sep10 "top" 10 rl1 -af sep10 "left" 0 -af sep10 "right" 0 rcl1; doReset(); showWindow AlienReplacer; } //procedure's end