{ /*Dan Neufeldt 2-09-04 This is a script to create a swirling sphere of instanced or duplicated geometry, particle emitters, or geometry emitting particles. this proc calls the sphereGroups proc which creates however many groups are specified. it then uses the specified creation method to create the multiple objects and parents them randomly to one of the groups int $many is how many objects to create, how many pieces int $numGroups is how many spinning groups to create float $radius is the general radius of the sphere float $rI is the amount of random variation allowed for the radius to decrease per object float $rO is the amount of random variation allowed for the radius to increase per object int $create is the creation type, 1 is instanced geometry, 2 is duplicated geometry, 3 is particle emitters, 4 is objects emitting particles int $particleAmt is how many different particle nodes to create int $controlEmitter tells the script whether the emitters create should have control emitters if that option if on then for each particle node an emitter will be created that does not actually emit particles, but simply has all its attributes driving the attributes of every emitter connected to that particular particle node. int $objectEmissionType the choice is given whether the object should emit particles from the geometry, or if an emitter should be created and parented to the geometry if the user wished to have instanced geometry with particles the second choice should be used as instanced geometry cannot emit particles */ proc makeSwirlyFields (string $createRadio, string $piecesField, string $numGroupsField, string $radiusField, string $randRadiusFields, string $numberOfParticlesField, string $controlEmitterCheck, string $objectEmitRadio, string $instanceCheck, string $swirlNameField, string $aimAxisFields, string $scaleOptionsRadio, string $randScaleMinFields, string $randScaleMaxFields) { int $create = `radioButtonGrp -q -sl $createRadio`; int $numPieces = `intFieldGrp -q -v1 $piecesField`; float $numGroups = `intFieldGrp -q -v1 $numGroupsField`; float $radius = `floatFieldGrp -q -v1 $radiusField`; float $innerRand = `floatFieldGrp -q -v1 $randRadiusFields`; float $outerRand = `floatFieldGrp -q -v2 $randRadiusFields`; int $particleAmt = `intFieldGrp -q -v1 $numberOfParticlesField`; int $controlEmitter = `checkBox -q -v $controlEmitterCheck`; int $objectEmissionType = (`radioButtonGrp -q -sl $objectEmitRadio` - 1); int $instanceObject = `checkBox -q -v $instanceCheck`; string $mainName = `textFieldGrp -q -tx $swirlNameField`; float $aimAxis[]; $aimAxis[0] = `floatFieldGrp -q -v1 $aimAxisFields`; $aimAxis[1] = `floatFieldGrp -q -v2 $aimAxisFields`; $aimAxis[2] = `floatFieldGrp -q -v3 $aimAxisFields`; int $randScaleOptions = `radioButtonGrp -q -sl $scaleOptionsRadio`; float $randScale[]; $randScale[0] = `floatFieldGrp -q -v1 $randScaleMinFields`; $randScale[1] = `floatFieldGrp -q -v2 $randScaleMinFields`; $randScale[2] = `floatFieldGrp -q -v3 $randScaleMinFields`; $randScale[3] = `floatFieldGrp -q -v1 $randScaleMaxFields`; $randScale[4] = `floatFieldGrp -q -v2 $randScaleMaxFields`; $randScale[5] = `floatFieldGrp -q -v3 $randScaleMaxFields`; spherePlanes $mainName $numPieces $numGroups $radius $innerRand $outerRand $create $particleAmt $controlEmitter $objectEmissionType $instanceObject $aimAxis $randScaleOptions $randScale; } proc spherePlanes (string $mainName, int $many, int $numGroups, float $radius, float $rI, float $rO, int $create, int $particleAmt, int $controlEmitter, int $objectEmissionType, int $instForEmit, float $aimAxis[], int $randScaleOptions, float $randScale[]) { progressWindow -t "Progress of the Thing" -st "Yes its doing something"; int $progressStep = (100 / $many); int $marchOfProgress; string $sel[] = `ls -sl`; string $loc[] = `spaceLocator`; string $overParent = `group -w -em -n ($mainName + "SuperGroup")`; string $renameLoc = `rename $loc[0] $mainName`; string $parented[] = `parent -r $renameLoc $overParent`; string $center = $parented[0]; addingManyAttrs $numGroups $center; string $groups[] = `sphereGroups $numGroups $center`; string $particles[0]; if ($create > 2){ $particles = `djnParticleNodes $particleAmt $center`; } string $ctrlEmitters[]; if ($controlEmitter){ $ctrlEmitters = `djnCreateControlEmitters $particleAmt $center`; } string $dummyAim = `group -w -em`; aimConstraint -aim $aimAxis[0] $aimAxis[1] $aimAxis[2] $center $dummyAim; int $i; for ($i = 0; $i < $many; $i ++) { progressWindow -e -pr $marchOfProgress; $marchOfProgress = $marchOfProgress + $progressStep; int $randGroup = (rand($numGroups)); string $groupName = $groups[$randGroup]; float $rnd = (rand($rI, $rO)); vector $points = (unit(sphrand (1)) * ($radius + $rnd)); if (1 == $create) { string $object[] = `instance $sel`; if (1 != $randScaleOptions){ djnSwirlRandScale $object $randScaleOptions $randScale; } move ($points.x) ($points.y) ($points.z) $object; move ($points.x) ($points.y) ($points.z) $dummyAim; float $rot[] = `getAttr ($dummyAim + ".rotate")`; rotate -r -os $rot[0] $rot[1] $rot[2] $object; parent -r $object $groupName; } if (2 == $create) { string $object[] = `duplicate -rc $sel`; if (1 != $randScaleOptions){ djnSwirlRandScale $object $randScaleOptions $randScale; } move ($points.x) ($points.y) ($points.z) $object; move ($points.x) ($points.y) ($points.z) $dummyAim; float $rot[] = `getAttr ($dummyAim + ".rotate")`; rotate -r -os $rot[0] $rot[1] $rot[2] $object; parent -r $object $groupName; } if (3 == $create) { select -cl; int $rndPart = (rand($particleAmt)); string $emitter[] = `emitter -n ($center + "Emit" + $i)`; move ($points.x) ($points.y) ($points.z) $emitter[0]; if (!$controlEmitter){ move ($points.x) ($points.y) ($points.z) $dummyAim; float $rot[] = `getAttr ($dummyAim + ".rotate")`; rotate -r -os $rot[0] $rot[1] $rot[2] $emitter[0]; }else{ djnConnectControlEmitter $ctrlEmitters[$rndPart] $emitter[0]; } connectDynamic -em $emitter[0] $particles[$rndPart]; if ($controlEmitter){ } parent -r $emitter[0] $groupName; } if (4 == $create) { int $rndPart = (rand($particleAmt)); string $particle = $particles[$rndPart]; string $object[]; if (!$objectEmissionType){ $object = `duplicate -rc $sel[0]`; move ($points.x) ($points.y) ($points.z) $object[0]; djnEmitFromObject $object[0] $particle $controlEmitter $ctrlEmitters[$rndPart]; move ($points.x) ($points.y) ($points.z) $dummyAim; float $rot[] = `getAttr ($dummyAim + ".rotate")`; rotate -r -os $rot[0] $rot[1] $rot[2] $object[0]; parent -r $object[0] $groupName; }else{ if ($instForEmit){ $object = `instance $sel`; }else{ $object = `duplicate -rc $sel[0]`; } djnEmitWithInstance $object[0] $particle $controlEmitter $ctrlEmitters[$rndPart]; move ($points.x) ($points.y) ($points.z) $object; move ($points.x) ($points.y) ($points.z) $dummyAim; float $rot[] = `getAttr ($dummyAim + ".rotate")`; rotate -r -os $rot[0] $rot[1] $rot[2] $object; parent -r $object $groupName; } } } delete $dummyAim; select -cl; progressWindow -endProgress; } //this portion takes the inputs from the UI and feeds them to the actual procedure proc djnSwirlRandScale (string $objects[], int $which, float $sc[]) { string $object; if (2 == $which){ for ($object in $objects) { vector $scr = rand (<< $sc[0], $sc[1], $sc[2]>>, <<$sc[3], $sc[4], $sc[5]>>); scale ($scr.x) ($scr.y) ($scr.z) $object; } }else{ for ($object in $objects) { float $scr = rand($sc[0], $sc[3]); scale $scr $scr $scr $object; } } } // this proc creates the randomly spinning groups of objects. it accompishes this by setting random SDK keyframes, one at 0 rotation, // one at 360 frames with a random rotation value for each rotation channel. // the SDK curves are driven by the rotation attributes on the ctrl object. the object has a channel for each group proc string[] sphereGroups (int $number, string $ctrl) { string $bigGroup = `group -w -em`; string $overGroup[] = `parent -r $bigGroup $ctrl`; string $masterGroup = `rename $overGroup[0] ($ctrl + "MasterGrp")`; int $i; string $return[]; string $tangent = "spline"; for ($i = 0; $i < $number; $i++) { string $fullCtrl = ($ctrl + ".rotation" + $i); string $name = `group -w -em`; string $group[] = `parent -r $name $masterGroup`; string $newName = `rename $group[0] ($ctrl + "Swrl" + $i)`; $return[$i] = $newName; vector $rotate = `rand <<1, 1, 1>> <<360, 360, 360>>`; setDrivenKeyframe -at "rotateX" -v 0 -cd $fullCtrl -dv 0 -itt $tangent -ott $tangent $newName; setDrivenKeyframe -at "rotateX" -v ($rotate.x) -cd $fullCtrl -dv 360 -itt $tangent -ott $tangent $newName; setDrivenKeyframe -at "rotateY" -v 0 -cd $fullCtrl -dv 0 -itt $tangent -ott $tangent $newName; setDrivenKeyframe -at "rotateY" -v ($rotate.y) -cd $fullCtrl -dv 360 -itt $tangent -ott $tangent $newName; setDrivenKeyframe -at "rotateZ" -v 0 -cd $fullCtrl -dv 0 -itt $tangent -ott $tangent $newName; setDrivenKeyframe -at "rotateZ" -v ($rotate.z) -cd $fullCtrl -dv 360 -itt $tangent -ott $tangent $newName; string $curves[] = `listConnections -d 0 -s 1 $newName`; for ($curve in $curves) { setAttr ($curve + ".pre") 1; setAttr ($curve + ".pst") 1; } } return $return; } // this proc adds attributes to the control locator to vary the speed of the group rotations. it adds an attribute for each group. proc addingManyAttrs (int $number, string $object) { int $i; for ($i = 0; $i <= $number; $i++) { float $default = (1 + (.1 * $i)); string $rotation = ("rotation" + $i); string $speed = ("rotateSpeed" + $i); addAttr -at "float" -ln $rotation $object; addAttr -at "float" -ln $speed -dv $default $object; string $multNode = `createNode multDoubleLinear`; string $mult = `rename $multNode ($object + "Mult" + $i)`; connectAttr ("time1.outTime") ($mult + ".input1"); connectAttr ($object + "." + $speed) ($mult + ".input2"); setAttr -k 1 ($object + "." + $speed); connectAttr ($mult + ".output") ($object + "." + $rotation); } } proc string[] djnParticleNodes (int $number, string $ctrl) { string $particles[]; int $i; for ($i = 0; $i < $number; $i++) { string $particle[] = `particle`; string $newName = `rename $particle[0] ($ctrl + "Particle" + $i)`; string $parent[] = `listRelatives -p $ctrl`; string $parented[] = `parent -r $newName $parent[0]`; $particles[$i] = $parented[0]; } return $particles; } proc string[] djnCreateControlEmitters (int $number, string $ctrl) { int $i; string $group = `group -w -em -n ($ctrl + "CtrlEmitters")`; string $ctrlParent[] = `parent -r $group $ctrl`; string $emitters[]; for ($i = 0; $i < $number; $i++) { select -cl; string $oldName[] = `emitter`; move ($i * 2) 0 0 $oldName[0]; string $newName = `rename $oldName[0] ($ctrl + "CtrlEmitter" + $i)`; string $parented[] = `parent -r $newName $ctrlParent[0]`; $emitters[$i] = $parented[0]; } return $emitters; } // this procedure connects most attributes of one emitter to the same attributes of another emitter, // thus creating a control emitter. // this is for controling the emission stylings of many emitters at once. proc djnConnectControlEmitter (string $master, string $slave) { string $emitterAttrs[] = { "rotateX", "rotateY", "rotateZ", "scaleX", "scaleY", "scaleZ", "emitterType", "rate", "cycleEmission", "cycleInterval", "maxDistance", "minDistance", "directionX", "directionY", "directionZ", "spread", "speed", "speedRandom", "tangentSpeed", "normalSpeed", "particleColor", "particleColorR", "particleColorG", "particleColorB", "volumeShape", "volumeOffsetX", "volumeOffsetY", "volumeOffsetZ", "volumeSweep", "sectionRadius", "awayFromCenter", "awayFromAxis", "alongAxis", "aroundAxis", "randomDirection", "directionalSpeed", "scaleSpeedBySize", "displaySpeed" }; string $attr; for ($attr in $emitterAttrs) { connectAttr ($master + "." + $attr) ($slave + "." + $attr); } } proc djnEmitFromObject (string $object, string $particle, int $controlEmitter, string $ctrlEmitter) { string $children[] = `listRelatives -ad $object`; string $child; for ($child in $children) { string $type = `nodeType $child`; if (("mesh" == $type) || ("nurbsCurve" == $type) || ("nurbsSurface" == $type)){ string $emitter[] = `emitter -n ($child + "Emit") $child`; if ($controlEmitter){ djnConnectControlEmitter $ctrlEmitter $emitter[1]; } connectDynamic -em $emitter[1] $particle; } } } proc djnEmitWithInstance (string $object, string $particle, int $controlEmitter, string $ctrlEmitter) { select -cl; float $piv[] = `xform -q -rp $object`; string $emitter[] = `emitter -n ($object + "Emit")`; if ($controlEmitter){ djnConnectControlEmitter $ctrlEmitter $emitter[0]; } connectDynamic -em $emitter[0] $particle; parent -r $emitter[0] $object; } proc djnSwirlScaleFieldEnabling (int $which, string $minField, string $maxField) { if (1 == $which){ floatFieldGrp -e -en1 0 -en2 0 -en3 0 $minField; floatFieldGrp -e -en1 0 -en2 0 -en3 0 $maxField; } if (2 == $which){ floatFieldGrp -e -en1 1 -en2 0 -en3 0 $minField; floatFieldGrp -e -en1 1 -en2 0 -en3 0 $maxField; } if (3 == $which){ floatFieldGrp -e -en1 1 -en2 1 -en3 1 $minField; floatFieldGrp -e -en1 1 -en2 1 -en3 1 $maxField; } } string $windowName = "swirlySpheresWindow"; if (`window -exists $windowName`) deleteUI $windowName; int $w = 350; int $h = 400; window -t "Swirling Spheres of Madness" $windowName; scrollLayout; columnLayout; text -l "Creation Options"; string $createRadio = `radioButtonGrp -nrb 4 -la4 "Instance" "Duplicate" "Emitters" "Emitting Object" -sl 1 -cw4 70 70 70 90 createRadio`; separator -w 350 -h 12; string $swirlNameField = `textFieldGrp -l "Name" -tx "sphereGrp" -w 280 swirlNameField`; string $piecesField = `intFieldGrp -l "Number of Pieces" -v1 10 piecesField`; string $numGroupsField = `intFieldGrp -l "Number of Groups" -v1 5 numberGroupsField`; string $radiusField = `floatFieldGrp -l "Radius" -v1 10 radiusField`; string $randRadiusFields = `floatFieldGrp -l "Random Radius Min/Max" -nf 2 -v1 -1 -v2 1 randRadiusFields`; frameLayout -l "Positional Options" -cll 1 -cl 1 -w ($w - 50) positionalOptionsFrame; columnLayout; string $aimAxisFields = `floatFieldGrp -nf 3 -l "Aim Axis" -v1 0 -v2 1 -v3 0 -cw4 90 50 50 50 -cat 1 "left" 0 aimAxisFields`; string $scaleOptionsRadio = `radioButtonGrp -nrb 3 -la3 "None" "Uniform" "Total Control" -sl 1 -cw 1 80 -cw 2 80 -cw 3 80 scaleOptionsRadio`; string $randScaleMinFields = `floatFieldGrp -nf 3 -l "Rand Scale Min" -v1 0 -v2 0 -v3 0 -cw4 90 50 50 50 -cat 1 "left" 0 -en1 0 -en2 0 -en3 0 randScaleMinFields`; string $randScaleMaxFields = `floatFieldGrp -nf 3 -l "Rand Scale Max" -v1 1 -v2 1 -v3 1 -cw4 90 50 50 50 -cat 1 "left" 0 -en1 0 -en2 0 -en3 0 randScaleMaxFields`; radioButtonGrp -e -on1 ("djnSwirlScaleFieldEnabling 1 " + $randScaleMinFields + " " + $randScaleMaxFields) -on2 ("djnSwirlScaleFieldEnabling 2 " + $randScaleMinFields + " " + $randScaleMaxFields) -on3 ("djnSwirlScaleFieldEnabling 3 " + $randScaleMinFields + " " + $randScaleMaxFields) $scaleOptionsRadio; setParent..; setParent..; frameLayout -l "Emission Options" -cll 1 -cl 0 -w ($w - 50) emissionOptionsFrame; columnLayout; string $numberOfParticlesField = `intFieldGrp -l "Number Of Particle Nodes" -nf 1 -v1 1 numberOfParticlesField`; string $controlEmitterCheck = `checkBox -l "Create Control Emitters" -v 1 controlEmitterCheck`; string $objectEmitRadio = `radioButtonGrp -nrb 2 -la2 "Emit From Object" "Emit With Object" -sl 1 objectEmitRadio`; string $instanceCheck = `checkBox -l "Instance Object" -v 1 -en 0 instanceCheck`; setParent..; setParent..; separator -w 350 -h 20; rowColumnLayout -nc 3 -cw 1 110 -cw 2 100 -cw 3 100; text -l " "; button -l "Create" -c ("makeSwirlyFields " + $createRadio + " " +$piecesField + " " + $numGroupsField + " " + $radiusField + " " + $randRadiusFields + " " + $numberOfParticlesField + " " + $controlEmitterCheck + " " + $objectEmitRadio + " " + $instanceCheck + " " + $swirlNameField + " " + $aimAxisFields + " " + $scaleOptionsRadio + " " + $randScaleMinFields + " " + $randScaleMaxFields); text -l " "; setParent..; setParent..; setParent $windowName; window -e -wh $w $h $windowName; showWindow $windowName; }