//=========================== Spasim V 1.0========================================= // // Sprite Particle Animated Sequence Image Manipulator // // by Andrew Osiow Copyright 2005 // andrewosiow@gmail.com // // To be used freely with the aknowledgement that the author is not responsible // for any perceived damage this script may directly (or indirectly) cause. // Please contact the author if you plan to use this script in a commercial project. // // inspired by fxGen.mel by Alon Zaslavsky // My thanks to Alon for allowing me to expand upon his concept. // // Compatible with Maya 6 and up. (but not Maya 5). // // A useful tool for generating sprite particles effects. Please place // in your usual mel scripts directory, // (example - C:\Documents and Settings\name\My Documents\maya\6.0\scripts\). // Then type spasim in the command area. // // It builds the necessary ramps, shaders and equations to control color, size, // twist angle, and image sequence of sprite particles. It will also create the // emitter and particles (if necessary). Once done, Spasim does not act like an // editor, but it does create a series of particle attributes to manipulate twist // and sequence control after Spasim is done. The user is also free to change, // (at their own risk) any of the shaders, ramps, attributes, and equations // that Spasim has created. // // One Exception on manual changes after Spasim has run: Sequence Start, End and // Increment Attributes under the Interactive Sequence Caching Options of an imageFile // Node should not be changed after been set by Spasim because it could produce // undesirable results. This shouldn't be a problem because these values represent // the first and last frame of the entire sprite footage. If the footage length of // your material changes, you should run Spasim again. // // The script can run mulitple times. Each time it will generate a new // shader network. Sprite particles can be emitted from valid shapes by selecting // them before running the script. If multiple objects are selected the script // will generate a unique emitter and particle shape for each object. // If a particle shape is selected it will simply link the requested equations // and ramps for the desired sprite effects. This allows a user to convert a // particle shape created by 'Flow' or some other means into a sprite effect. // // version 0.1 Overhauled original fxGen interface // twist and image sequence controls added but not functional // version 0.2 Twist control working. Also works with color or sprite image // settings. Will correctly link emitter to selected surface geometry // version 0.3 Controls will enable and disable appropiately. // version 0.4 First completely working version // Sequence control now work correctly including // duration control. The particles startFrame // can also be changed. // version 0.5 Added interface equations and Attributes for more sophisticated // twist and sequence control. // version 0.6 Added code to allow for new loop starting point on random loops // after loop has ended. // version 0.7 Added code to handle curve geometry an emitter. // version 0.8 Added code to handle multiply shapes and disregard shapes that // can't be emitters. // version 0.9 added code for particles shapes. If a particle shape is selected // spasim will change it to a sprite partilce and add the desired ramps // and equations without creating an emitter. // version 1.0 Cleaned up ramp code - fixed minor bug - Start Color, Opacity and // scale values now correctly translated into ramps. // //======================================================================== global proc spasim () {// Interface Begins if (`window -ex spasimWindow`) deleteUI spasimWindow; string $spasimWin = `window -title "Spasim" -iconName "Spasim" -rtf 1 -s 0 spasimWindow`; string $spasimForm = `formLayout -numberOfDivisions 100`; // Create Controllers text -label "Particle Name" labelName; textField -text "particle" -width 100 txtParticleName; // scale controllers text -l "Sprite Size:" labelScale; checkBox -label "Scale During Lifetime" -value 1 -onc evalScaleCheck -ofc evalScaleCheck chkScale; text -label "Minimum Scale Value:" labelMin; floatField -min 0 -value 1 floatFieldMin; text -label "Maximum Scale Value:" labelMax; floatField -min 0 -value 5 floatFieldMax; // twist controllers text -label "Sprite Twist:" labelTwist; radioButtonGrp -numberOfRadioButtons 3 -label "Twist Type" -labelArray3 "none" "uniform" "alternate" //"random" -select 1 -onc evalTwistType twistType; text -label "Starting Angle:" -enable 0 labelStartAngle; intField -min -180 -max 180 -value 0 -enable 0 intFieldStartAngle; checkBox -label "Random Range" -value 0 -enable 0 checkStartAngle; text -label "Rotation per Frame:" -enable 0 labelRotate; intField -min -180 -max 180 -value 0 -enable 0 intFieldRotation; checkBox -label "Random Range" -value 0 -enable 0 checkRangeRotation; // display type controllers text -label "Sprite Display:" labelDisplay; radioButtonGrp -numberOfRadioButtons 3 -label "Color Type" -labelArray3 "color" "image" "sequence" -select 1 -onc evalDisplayType displayType; colorSliderGrp -label "Birth Color" -rgb 0.980 0.850 0.656 birthColorSlider; colorSliderGrp -label "Death Color" -rgb 0.576 0.348 0.160 deathColorSlider; text -label "Sprite Image File:" -enable 0 fileTextureText; textField -text "" -width 200 -enable 0 fileTexturePath; button -label "Browse" -width 70 -enable 0 -command browseForTexture fileTextureBrowse; text -label "Source Image Sequence:" -enable 0 labelImageSequence; text -label "Sequence Start:" -enable 0 labelSStart; intField -min 0 -value 1 -enable 0 intFieldSStart; text -label "Sequence End:" -enable 0 labelSEnd; intField -min 0 -value 1 -enable 0 intFieldSEnd; text -label "Frame Duration:" -enable 0 labelFDuration; intField -min 1 -value 1 -enable 0 intFieldDuration; text -label "Per Particle Loop:" -enable 0 labelPPSequence; text -label "Start Point:" -enable 0 labelPPSStart; intField -min 0 -value 1 -enable 0 intFieldPPSStart; radioButtonGrp -numberOfRadioButtons 3 -label "Loop Type" -labelArray3 "fixed" "sequential" "random" -enable 0 -select 1 -onc evalLoopType loopType; text -label "Loop Length:" -enable 0 labelPPSLength; intField -min 0 -value 1 -enable 0 intFieldPPSLength; checkBox -label "Random Range" -value 0 -enable 0 checkRRangePPLength; checkBox -label "New Start Point" -value 0 -enable 0 checkNewStartPoint; // opacity controlers text -l "Sprite Opacity:" labelOpacity; checkBox -label "Opacity Ramp" -value 1 -onc evalOpacityCheck -ofc evalOpacityCheck chkOpacity; colorSliderGrp -label "Birth Opacity" -rgb 0.667 0.667 0.667 birthOpacitySlider; colorSliderGrp -label "Death Opacity" -rgb 0.000 0.000 0.000 deathOpacitySlider; button -width 150 -height 26 -label "Create" -align "center" -command "spasimGen; deleteUI spasimWindow" createButton; // creates and closes button -width 150 -height 26 -label "Apply" -command "spasimGen" applyButton; // calls the create procedure button -width 150 -height 26 -label "Close" -command "deleteUI spasimWindow" closeButton; // closes interface // Layout Interface formLayout -e // arrange name field -af "txtParticleName" "left" 150 -af "txtParticleName" "top" 12 -ac "labelName" "right" 4 "txtParticleName" -af "labelName" "top" 12 $spasimForm; formLayout -e // arrange scale change controllers -af "labelScale" "left" 10 -ac "labelScale" "top" 12 "labelName" -af "chkScale" "left" 50 -ac "chkScale" "top" 4 "labelScale" $spasimForm; formLayout -e // arrange scale minimum maximam controller -aoc "labelMin" "left" 0 "chkScale" -ac "labelMin" "top" 8 "chkScale" -ac "floatFieldMin" "left" 4 "labelMin" -ac "floatFieldMin" "top" 6 "chkScale" -ac "labelMax" "left" 8 "floatFieldMin" -ac "labelMax" "top" 8 "chkScale" -ac "floatFieldMax" "left" 4 "labelMax" -ac "floatFieldMax" "top" 6 "chkScale" $spasimForm; formLayout -e // arrange twist controllers -af "labelTwist" "left" 10 -ac "labelTwist" "top" 12 "labelMin" -ac "twistType" top 4 "labelTwist" -af "labelStartAngle" "left" 50 -ac "labelStartAngle" "top" 10 "twistType" -ac "intFieldStartAngle" "left" 28 "labelStartAngle" -ac "intFieldStartAngle" "top" 6 "twistType" -ac "checkStartAngle" "left" 8 "intFieldRotation" -ac "checkStartAngle" "top" 10 "twistType" -af "labelRotate" "left" 50 -ac "labelRotate" "top" 10 "labelStartAngle" -ac "intFieldRotation" "left" 4 "labelRotate" -ac "intFieldRotation" "top" 6 "labelStartAngle" -ac "checkRangeRotation" "left" 8 "intFieldRotation" -ac "checkRangeRotation" "top" 10 "labelStartAngle" $spasimForm; formLayout -e // arrange display controllers -af "labelDisplay" "left" 10 -ac "labelDisplay" "top" 12 "labelRotate" -ac "displayType" "top" 4 "labelDisplay" -ac "birthColorSlider" "top" 4 "displayType" -ac "deathColorSlider" "top" 2 "birthColorSlider" $spasimForm; formLayout -e // arrange display controllers -af "fileTextureText" "left" 50 -ac "fileTextureText" "top" 10 "deathColorSlider" -ac "fileTexturePath" "left" 4 "fileTextureText" -ac "fileTexturePath" "top" 8 "deathColorSlider" -ac "fileTextureBrowse" "left" 4 "fileTexturePath" -ac "fileTextureBrowse" "top" 8 "deathColorSlider" $spasimForm; formLayout -e // arrange sequence controllers -aoc "labelImageSequence" "left" 0 "fileTextureText" -ac "labelImageSequence" "top" 6 "fileTexturePath" -aoc "intFieldSStart" "left" 0 "fileTexturePath" -ac "intFieldSStart" "top" 4 "labelImageSequence" -aoc "labelSStart" "left" 0 "fileTextureText" -ac "labelSStart" "top" 8 "labelImageSequence" -ac "labelSEnd" "left" 8 "intFieldSStart" -ac "labelSEnd" "top" 8 "labelImageSequence" -ac "intFieldSEnd" "left" 4 "labelSEnd" -ac "intFieldSEnd" "top" 4 "labelImageSequence" -aoc "labelPPSequence" "left" 0 "labelImageSequence" -ac "labelPPSequence" "top" 12 "labelSStart" -aoc "labelPPSStart" "left" 0 "fileTextureText" -ac "labelPPSStart" "top" 8 "labelPPSequence" -aoc "intFieldPPSStart" "left" 0 "intFieldSStart" -ac "intFieldPPSStart" "top" 4 "labelPPSequence" -ac "loopType" "top" 8 "labelPPSStart" -aoc "labelPPSLength" "left" 0 "fileTextureText" -ac "labelPPSLength" "top" 10 "loopType" -aoc "intFieldPPSLength" "left" 0 "intFieldPPSStart" -ac "intFieldPPSLength" "top" 6 "loopType" -ac "checkRRangePPLength" "left" 8 "intFieldPPSLength" -aoc "checkRRangePPLength" "top" 4 "intFieldPPSLength" -ac "checkNewStartPoint" "left" 4 "checkRRangePPLength" -aoc "checkNewStartPoint" "top" 4 "intFieldPPSLength" -aoc "labelFDuration" "left" 0 "fileTextureText" -ac "labelFDuration" "top" 12 "labelPPSLength" -aoc "intFieldDuration" "left" 0 "fileTexturePath" -ac "intFieldDuration" "top" 8 "labelPPSLength" $spasimForm; formLayout -e // arrange opacity controllers -af "labelOpacity" "left" 10 -ac "labelOpacity" "top" 12 "labelFDuration" -af "chkOpacity" "left" 50 -ac "chkOpacity" "top" 4 "labelOpacity" -ac "birthOpacitySlider" "top" 4 "chkOpacity" -ac "deathOpacitySlider" "top" 2 "birthOpacitySlider" $spasimForm; formLayout -e //arrange buttons -ac "createButton" "top" 12 "deathOpacitySlider" -af "createButton" "left" 4 -af "createButton" "bottom" 4 -ac "applyButton" "left" 4 "createButton" -af "applyButton" "bottom" 4 -ac "closeButton" "left" 4 "applyButton" -af "closeButton" "bottom" 4 -af "closeButton" "right" 4 $spasimForm; // Interface Ends showWindow $spasimWin; } global proc evalScaleCheck() {// Enable/disable scale controllers if (`checkBox -q -v chkScale` > 0) { floatField -e -en 1 floatFieldMin; floatField -e -en 1 floatFieldMax; } else { floatField -e -en 0 floatFieldMin; floatField -e -en 0 floatFieldMax; } } global proc evalTwistType() {// Enable/disable twist rotation controllers if (`radioButtonGrp -q -sl twistType` > 1) { text -e -en 1 labelStartAngle; intField -e -en 1 intFieldStartAngle; text -e -en 1 labelRotate; intField -e -en 1 intFieldRotation; checkBox -e -en 1 checkStartAngle; checkBox -e -en 1 checkRangeRotation; } else { text -e -en 0 labelStartAngle; intField -e -en 0 intFieldStartAngle; text -e -en 0 labelRotate; intField -e -en 0 intFieldRotation; checkBox -e -en 0 checkStartAngle; checkBox -e -en 0 checkRangeRotation; } } global proc evalDisplayType() {// Enable/disable display type controllers if (`radioButtonGrp -q -sl displayType` > 1) { colorSliderGrp -e -en 0 birthColorSlider; colorSliderGrp -e -en 0 deathColorSlider; text -e -en 1 fileTextureText; textField -e -en 1 fileTexturePath; button -e -en 1 fileTextureBrowse; if (`radioButtonGrp -q -sl displayType` > 2) { text -e -en 1 labelImageSequence; text -e -en 1 labelSStart; intField -e -en 1 intFieldSStart; text -e -en 1 labelSEnd; intField -e -en 1 intFieldSEnd; text -e -en 1 labelPPSequence; text -e -en 1 labelPPSStart; intField -e -en 1 intFieldPPSStart; radioButtonGrp -e -en 1 loopType; text -e -en 1 labelPPSLength; intField -e -en 1 intFieldPPSLength; checkBox -e -en 1 checkRRangePPLength; text -e -en 1 labelFDuration; intField -e -en 1 intFieldDuration; } else { text -e -en 0 labelImageSequence; text -e -en 0 labelSStart; intField -e -en 0 intFieldSStart; text -e -en 0 labelSEnd; intField -e -enable 0 intFieldSEnd; text -e -en 0 labelPPSequence; text -e -en 0 labelPPSStart; intField -e -en 0 intFieldPPSStart; radioButtonGrp -e -en 0 loopType; text -e -en 0 labelPPSLength; intField -e -en 0 intFieldPPSLength; checkBox -e -en 0 checkRRangePPLength; text -e -en 0 labelFDuration; intField -e -en 0 intFieldDuration; } } else { colorSliderGrp -e -en 1 birthColorSlider; colorSliderGrp -e -en 1 deathColorSlider; text -e -enable 0 fileTextureText; textField -e -en 0 fileTexturePath; button -e -en 0 fileTextureBrowse; text -e -en 0 labelImageSequence; text -e -en 0 labelSStart; intField -e -en 0 intFieldSStart; text -e -en 0 labelSEnd; intField -e -enable 0 intFieldSEnd; text -e -en 0 labelPPSequence; text -e -en 0 labelPPSStart; intField -e -en 0 intFieldPPSStart; radioButtonGrp -e -en 0 loopType; text -e -en 0 labelPPSLength; intField -e -en 0 intFieldPPSLength; checkBox -e -en 0 checkRRangePPLength; text -e -en 0 labelFDuration; intField -e -en 0 intFieldDuration; } evalLoopType; } global proc browseForTexture() {// Open file browser to current project string $currentProject = `workspace -q -dir`; string $fileName = `fileDialog -directoryMask $currentProject`; $fileName = `workspace -projectPath $fileName`; textField -e -tx $fileName fileTexturePath; } global proc evalLoopType() {// Enable/disable newStart based on Random Loop Type if (`radioButtonGrp -q -sl loopType` > 2) { checkBox -e -en 1 checkNewStartPoint; } else { checkBox -e -en 0 checkNewStartPoint; } } global proc evalOpacityCheck() {// Enable/disable twist rotation controllers if (`checkBox -q -v chkOpacity` > 0) { colorSliderGrp -e -en 1 birthOpacitySlider; colorSliderGrp -e -en 1 deathOpacitySlider; } else { colorSliderGrp -e -en 0 birthOpacitySlider; colorSliderGrp -e -en 0 deathOpacitySlider; } } global proc spasimGen () {// Main program loop for handling mulitply selected objects // varibles for particles and emitters string $pNew[]; string $pShape, $eName; string $currentShapeName[]; string $currentType; string $emitterType; string $pName = `textField -q -tx txtParticleName`; string $selectedShapes[] = `ls -sl`; if (size(`ls -sl`) == 0) { print ("No shape selected.\n"); if (`particleExists $pName`) { $pNew = `particle -n $pName`; warning ($pName + " already exists. Particle " + $pNew[0] + " was created instead."); $pName = $pNew[0]; delete $pNew[0]; } string $eName = ("emit_" + $pName); //use a directional emitter if nothing selected emitter -pos 0 0 0 -type direction -name $eName -r 100 -sro 0 -nuv 1 -cye none -cyi 1 -spd 10 -srn 1 -nsp 1.5 -tsp 0.1 -mxd 0 -mnd 0 -dx 0 -dy 1 -dz 0 -sp 0.2; $pShape = ($pName + "Shape"); particle -n $pName -sn $pShape; connectDynamic -em $eName $pName; spriteBuilder ($pName, $pShape); } else for ($currentShape in $selectedShapes) { $pName = `textField -q -tx txtParticleName`; $pShape = ""; // resetting - if $pShape receives a string then the shape will get processed // get current Shape Type $currentShapeName = `listRelatives -s $currentShape`; $currentType = `nodeType $currentShapeName[0]`; switch ($currentType) { // valid shape types case "nurbsCurve": $emitterType = "curve"; break; case "mesh": $emitterType = "surface"; break; case "nurbsSurface": $emitterType = "surface"; break; default: $emitterType = ""; break; } if ($emitterType !="") {// for emitting particles from shape $pName = $currentShape + $pName; $pShape = ($pName + "Shape"); string $eName = ("emit_" + $pName); select -r $currentShape; emitter -type $emitterType -name $eName -r 100 -sro 0 -nuv 0 -cye none -cyi 1 -spd 10 -srn 0 -nsp 1 -tsp 0 -mxd 0 -mnd 0 -dx 1 -dy 0 -dz 0 -sp 0; particle -n $pName -sn $pShape; connectDynamic -em $eName $pName; } if ($currentType == "particle") { $pName = $currentShape; $pShape = $currentShapeName[0]; } if ($pShape !="") { spriteBuilder ($pName, $pShape); print ("Generating Sprites for " + $currentShape + ".\n"); } else print ("Disregarding " + $currentShape + " - Invalid type: " + $currentType +".\n"); } } global proc spriteBuilder (string $pName, string $pShape) {// connects appropiate ramps and equations to $pShape // get values from interface float $spriteScaleMin = `floatField -q -v floatFieldMin`; float $spriteScaleMax = `floatField -q -v floatFieldMax`; int $startRotateValue = `intField -q -v intFieldStartAngle`; int $randomTwistStart = `checkBox -q -v checkStartAngle`; int $rotationValue = `intField -q -v intFieldRotation`; int $randomTwistChange = `checkBox -q -v checkRangeRotation`; int $scaleChecked = `checkBox -q -v chkScale`; int $spriteRotateType = `radioButtonGrp -q -sl twistType`; int $opacChecked = `checkBox -q -v chkOpacity`; int $colorType = `radioButtonGrp -q -sl displayType`; string $imageFileName; string $imageFileSource = `textField -q -tx fileTexturePath`; int $seqStartNumber = `intField -q -v intFieldSStart`; int $seqEndNumber = `intField -q -v intFieldSEnd`; int $ppStartNumber = `intField -q -v intFieldPPSStart`; int $spriteLoopType = `radioButtonGrp -q -sl loopType`; int $newStartPointCheck = `checkBox -q -v checkNewStartPoint`; int $ppLoopLength = `intField -q -v intFieldPPSLength`; int $randomLoopLength = `checkBox -q -v checkRRangePPLength`; int $loopFrameDuration = `intField -q -v intFieldDuration`; // variable for ramp construction string $newMap[]; string $retVal[]; string $scaleRamp; string $opacRamp; string $colorRamp; string $tmpMap; string $str; // adding particlePP attributes, linking ramp anding adding equations for // scale, twist, color, image sequence, and opacity if requested by interface // scale change if ($scaleChecked) { addAttr -ln spriteScaleXPP -dt doubleArray $pShape; addAttr -ln spriteScaleXPP0 -dt doubleArray $pShape; addAttr -ln spriteScaleYPP -dt doubleArray $pShape; addAttr -ln spriteScaleYPP0 -dt doubleArray $pShape; $newMap = `arrayMapper -target $pShape -destAttr spriteScaleYPP -inputV ageNormalized -type ramp`; $tmpMap = `rename $newMap ($pName + "_scaleYarrayMap")`; $str = ("listConnections -s 1 "+$tmpMap+".computeNodeColor;"); $mapRamp = `eval $str`; $scaleRamp = `rename $mapRamp ($pName + "_scaleRamp")`; $newMap = `arrayMapper -target $pShape -destAttr spriteScaleXPP -inputV ageNormalized -mapTo $scaleRamp`; rename $newMap ($pName + "_scaleXarrayMap"); //setting the scale values setAttr ($pName + "_scaleXarrayMap.minValue") $spriteScaleMin; setAttr ($pName + "_scaleYarrayMap.minValue") $spriteScaleMin; setAttr ($pName + "_scaleXarrayMap.maxValue") $spriteScaleMax; setAttr ($pName + "_scaleYarrayMap.maxValue") $spriteScaleMax; // building scale ramp // create ramp with a 3 point gradient float $deathScale[] = {1,1,1}; float $birthScale[] = {0,0,0}; int $scaleStep = 3; // equals how many gradient areas float $rampIncrement = 0.96/$scaleStep; // near top of the ramp position float $scaleIncrement = ($deathScale[0] - $birthScale[0])/$scaleStep; float $rampPosition = 0.0; // bottom of the ramp position int $pos = 0; for ( $pos = 0 ; $pos < $scaleStep+1 ; $pos++) { setAttr ($scaleRamp+".colorEntryList["+$pos+"].position") $rampPosition; setAttr ($scaleRamp+".colorEntryList["+$pos+"].color") -type double3 $birthScale[0] $birthScale[1] $birthScale[2]; $rampPosition += $rampIncrement; $birthScale[0] += $scaleIncrement; $birthScale[1] += $scaleIncrement; $birthScale[2] += $scaleIncrement; } $birthScale = {0,0,0}; } // building equations for twist change if ($spriteRotateType > 1) // uniform or alternate twist type {// adding atributes and expressions addAttr -ln spriteTwistPP -dt doubleArray $pShape; addAttr -ln spriteTwistPP0 -dt doubleArray $pShape; // adding control Attributes to the Particle Shape addAttr -ln twistType -at "enum" -en "None:Uniform:Alternate:" $pShape; setAttr -keyable true ($pShape+".twistType") ($spriteRotateType-1); addAttr -ln twistStart -at long -min 0 -max 180 -dv 0 $pShape; setAttr -keyable true ($pShape+".twistStart") $startRotateValue; addAttr -ln randStart -at bool $pShape; setAttr -keyable true ($pShape+".randStart") $randomTwistStart; addAttr -ln twistValue -at long -min 0 -max 180 -dv 0 $pShape; setAttr -keyable true ($pShape+".twistValue") $rotationValue; addAttr -ln randRot -at bool $pShape; setAttr -keyable true ($pShape+".randRot") $randomTwistChange; // build twist equations string $twistStartEquation = ($pShape+".twistStart - \r\n\t("+ $pShape+".randStart * " + "floor(rand(" + $pShape+".twistStart)))"); dynExpression -s ($pShape + ".spriteTwistPP = " + $twistStartEquation + ";") -c $pShape; string $twistChangeEquation = ("(" +$pShape + ".twistType>0)*" + $pShape +".twistValue - \r\n\t" + $pShape +".randRot * " + "floor(rand(" + $pShape+".twistValue))"); dynExpression -s ("$idMod = " + $pShape + ".id % 2;\r\n\r\n" + $pShape + ".spriteTwistPP = \r\n\t" + $pShape + ".spriteTwistPP + (" + $twistChangeEquation + ") *\r\n\t($idMod + ($idMod - 1)*(" + $pShape+".twistType*2-3));") -rbd $pShape; } // building opacity ramp if ($opacChecked) {// connecting Opacity Ramp addAttr -ln "opacityPP" -dt doubleArray $pShape; addAttr -ln "opacityPP0" -dt doubleArray $pShape; $newMap = `arrayMapper -target $pShape -destAttr opacityPP -inputV ageNormalized -type ramp`; $tmpMap = `rename $newMap ($pName + "_opacArrayMap")`; $str = ("listConnections -s 1 " + $tmpMap + ".computeNodeColor;"); $mapRamp = `eval $str`; $opacRamp = `rename $mapRamp ($pName + "_opacRamp")`; // create ramp with a 3 point gradient float $birthOpacity[] = `colorSliderGrp -q -rgb birthOpacitySlider`; float $deathOpacity[] = `colorSliderGrp -q -rgb deathOpacitySlider`; int $opacityStep = 3; // equals how many gradient areas float $rampIncrement = 0.96/$opacityStep; // near top of the ramp position float $opacityIncrement = ($deathOpacity[0] - $birthOpacity[0])/$opacityStep; float $rampPosition = 0.0; // bottom of the ramp position int $pos = 0; for ( $pos = 0 ; $pos < $opacityStep+1 ; $pos++) { setAttr ($opacRamp+".colorEntryList["+$pos+"].position") $rampPosition; setAttr ($opacRamp+".colorEntryList["+$pos+"].color") -type double3 $birthOpacity[0] $birthOpacity[1] $birthOpacity[2]; $rampPosition += $rampIncrement; $birthOpacity[0] += $opacityIncrement; $birthOpacity[1] += $opacityIncrement; $birthOpacity[2] += $opacityIncrement; } $birthOpacity = `colorSliderGrp -q -rgb birthOpacitySlider`; } // building color ramp if ($colorType == 1) // color {// connecting Color Ramp addAttr -ln "rgbPP" -dt vectorArray $pShape; addAttr -ln "rgbPP0" -dt vectorArray $pShape; $newMap = `arrayMapper -target $pShape -destAttr rgbPP -inputV ageNormalized -type ramp`; $tmpMap = `rename $newMap ($pName + "_RGBarrayMap")`; $str = ("listConnections -s 1 " + $tmpMap + ".computeNodeColor;"); $mapRamp = `eval $str`; $colorRamp = `rename $mapRamp ($pName + "_colorRamp")`; // create ramp with a 3 point gradient float $birthColor[] = `colorSliderGrp -q -rgb birthColorSlider`; float $deathColor[] = `colorSliderGrp -q -rgb deathColorSlider`; int $colorStep = 3; // equals how many gradient areas float $rampIncrement = 0.96/$colorStep; // near top of the ramp position float $redIncrement = ($deathColor[0] - $birthColor[0])/$colorStep; float $greenIncrement = ($deathColor[1] - $birthColor[1])/$colorStep; float $blueIncrement = ($deathColor[2] - $birthColor[2])/$colorStep; float $rampPosition = 0.0; // bottom of the ramp position int $pos = 0; for ( $pos = 0 ; $pos < $colorStep+1 ; $pos++) { setAttr ($colorRamp+".colorEntryList["+$pos+"].position") $rampPosition; setAttr ($colorRamp+".colorEntryList["+$pos+"].color") -type double3 $birthColor[0] $birthColor[1] $birthColor[2]; $rampPosition += $rampIncrement; $birthColor[0] += $redIncrement; $birthColor[1] += $greenIncrement; $birthColor[2] += $blueIncrement; } $birthColor = `colorSliderGrp -q -rgb birthColorSlider`; } // building shader nodes and equations for image or sequence display if ($colorType > 1) {// assign Lambert Shader string $shaderName = `shadingNode -asShader lambert -name ($pName+"Lambert")`; string $shaderGroup = $shaderName + "SG"; sets -renderable true -noSurfaceShader true -empty -name ($shaderGroup); connectAttr -f ($shaderName+".outColor") ($shaderGroup+".surfaceShader"); sets -e -forceElement $shaderGroup $pName; // link Image File Node to texture placement node $imageFileName = `shadingNode -asTexture file -name ($pName+"ImageFile")`; string $place2dName = `shadingNode -asUtility place2dTexture -name ($pName+"2dTexture")`; connectAttr -f ($place2dName+".coverage") ($imageFileName+".coverage"); connectAttr -f ($place2dName+".translateFrame") ($imageFileName+".translateFrame"); connectAttr -f ($place2dName+".rotateFrame") ($imageFileName+".rotateFrame"); connectAttr -f ($place2dName+".mirrorU") ($imageFileName+".mirrorU"); connectAttr -f ($place2dName+".mirrorV") ($imageFileName+".mirrorV"); connectAttr -f ($place2dName+".stagger") ($imageFileName+".stagger"); connectAttr -f ($place2dName+".wrapU") ($imageFileName+".wrapU"); connectAttr -f ($place2dName+".wrapV") ($imageFileName+".wrapV"); connectAttr -f ($place2dName+".repeatUV") ($imageFileName+".repeatUV"); connectAttr -f ($place2dName+".offset") ($imageFileName+".offset"); connectAttr -f ($place2dName+".rotateUV") ($imageFileName+".rotateUV"); connectAttr -f ($place2dName+".noiseUV") ($imageFileName+".noiseUV"); connectAttr -f ($place2dName+".vertexUvOne") ($imageFileName+".vertexUvOne"); connectAttr -f ($place2dName+".vertexUvTwo") ($imageFileName+".vertexUvTwo"); connectAttr -f ($place2dName+".vertexUvThree") ($imageFileName+".vertexUvThree"); connectAttr -f ($place2dName+".vertexCameraOne") ($imageFileName+".vertexCameraOne"); connectAttr ($place2dName+".outUV") ($imageFileName+".uv"); connectAttr ($place2dName+".outUvFilterSize") ($imageFileName+".uvFilterSize"); // link image file to surface shader connectAttr -force ($imageFileName+".outColor") ($shaderName+".color"); connectAttr -force ($imageFileName+".outTransparency") ($shaderName+".transparency"); // link image file name setAttr -type "string" ($imageFileName+".fileTextureName") $imageFileSource; } // adding attribute and equations for interactive sequence control if ($colorType == 3) {// add Control Attributes to the Particle Shape addAttr -ln startPoint -at long -min 1 -dv 1 $pShape; setAttr -keyable true ($pShape+".startPoint") $ppStartNumber; addAttr -ln currentStart -at long -min 1 $pShape; setAttr -keyable false ($pShape+".currentStart") $ppStartNumber; addAttr -ln currentLength -at long -min 1 $pShape; setAttr -keyable false ($pShape+".currentLength") $ppLoopLength; addAttr -ln loopType -at "enum" -en "Fixed:Sequential:Random:" $pShape; setAttr -keyable true ($pShape+".loopType") ($spriteLoopType-1); addAttr -ln loopLength -at long -min 1 -dv 1 $pShape; setAttr -keyable true ($pShape+".loopLength") $ppLoopLength; addAttr -ln randLength -at bool $pShape; setAttr -keyable true ($pShape+".randLength") $randomLoopLength; addAttr -ln newStart -at bool $pShape; setAttr -keyable true ($pShape+".newStart") $newStartPointCheck; addAttr -ln frameDuration -at long -min 1 -dv 1 $pShape; setAttr -keyable true ($pShape+".frameDuration") $loopFrameDuration; // add per particle attributes for per particle sprite image sequence control addAttr -ln spriteNumPP -dt doubleArray $pShape; addAttr -ln spriteNumPP0 -dt doubleArray $pShape; // add per particle attributes to allow individual squence control addAttr -ln startPointPP -dt doubleArray $pShape; addAttr -ln loopLengthPP -dt doubleArray $pShape; addAttr -ln loopPositionPP -dt doubleArray $pShape; addAttr -ln frameDurationPP -dt doubleArray $pShape; // set attributes for image sequence setAttr ($imageFileName+".useFrameExtension") 1; setAttr ($imageFileName+".useHardwareTextureCycling") 1; setAttr ($imageFileName+".startCycleExtension") 1; setAttr ($imageFileName+".endCycleExtension") $seqEndNumber; // generate equation for sequence control select $pShape; // creation equation for image sequence control string $creationExpresion = `dynExpression -q -c`; dynExpression -s ($creationExpresion + "\r\nif ( " + $pShape + ".loopType < 2)\r\n{\r\n " + $pShape + ".startPointPP = " + $pShape + ".startPoint;\r\n if (" + $pShape + ".loopType > 0)\r\n {\r\n if (" + $pShape + ".id > 0)\r\n " + $pShape + ".currentStart=\r\n (" + $pShape + ".currentStart+" + $pShape + ".currentLength)%" + $seqEndNumber + ";\r\n else " + $pShape + ".currentStart=" + $pShape + ".startPoint;\r\n " + $pShape + ".startPointPP=" + $pShape + ".currentStart;\r\n }\r\n else " + $pShape + ".startPointPP=" + $pShape +".startPoint;\r\n}\r\nelse " + $pShape + ".startPointPP=ceil(rand(" + $seqEndNumber + "));\r\n" + $pShape + ".spriteNumPP=" + $pShape + ".startPointPP;\r\n" + $pShape + ".loopLengthPP=" + $pShape + ".loopLength - \r\n" + $pShape + ".randLength * floor(rand(" + $pShape + ".loopLength));\r\n" + $pShape + ".currentLength=" + $pShape + ".loopLengthPP;\r\n" + $pShape + ".loopPositionPP=" + $pShape + ".loopLengthPP;\r\n" + $pShape + ".frameDurationPP=" + $pShape + ".frameDuration;\r\n") -c $pShape; // runtime (before Dynamics) equation for image sequence control string $runBeforeExpresion = `dynExpression -q -rbd`; dynExpression -s ($runBeforeExpresion + "\r\n" + $pShape + ".frameDurationPP--;\r\n" + "if (" + $pShape + ".frameDurationPP < 1)\r\n{\r\n " + $pShape + ".loopPositionPP--;\r\n " + "if (" + $pShape + ".loopPositionPP > 0)\r\n " + $pShape + ".spriteNumPP=("+ $pShape +".spriteNumPP)%" + $seqEndNumber + "+1;\r\n else\r\n {\r\n if (" + $pShape + ".newStart && " + $pShape + ".loopType > 1)\r\n " + $pShape + ".startPointPP=ceil(rand(50));\r\n " + $pShape + ".spriteNumPP=" + $pShape + ".startPointPP;\r\n " + $pShape + ".loopPositionPP=" + $pShape + ".loopLengthPP;\r\n };\r\n " + $pShape + ".frameDurationPP=" + $pShape + ".frameDuration;\r\n}") -rbd $pShape; } // Set sprite particle render type properties setAttr ($pShape + ".particleRenderType") 5; addAttr -is true -ln "spriteTwist" -at "float" -min -180 -max 180 -dv 0.0 $pShape; addAttr -is true -ln "spriteScaleX" -dv 1 $pShape; addAttr -is true -ln "spriteScaleY" -dv 1 $pShape; }