global proc keyframer(string $name) { select -r $name; currentTime 1; setKeyframe $name.translate; setKeyframe $name.rotate; timeSliderCopyKey; float $mover= `rand -5 5`; float $shaker = `rand -360 360`; currentTime 60; move -r $mover $mover $mover; rotate -r $shaker $shaker $shaker; setKeyframe $name.translate; setKeyframe $name.rotate; currentTime 120; $mover *= -1; $shaker *= -1; timeSliderPasteKey false; //move -r $mover $mover $mover; //rotate -r $shaker $shaker $shaker; setKeyframe $name.translate; setKeyframe $name.rotate; playbackOptions -min 1 -max 120; } global proc string molecule(float $srad, float $crad, int $sides) { string $sname[] = `sphere -r $srad`; float $compensationCylinder = .4 + .17*($sides - 4); float $compensationSphereX = $compensationCylinder*3.11/($sides - 2)-.9/$sides; if ($sides == 3) $compensationSphereX -= .02; move $compensationSphereX 0 $compensationCylinder; float $compensater = .8 + .008*($sides-3); if ($sides > 5 && $sides <26) $compensater += .04; if ($sides > 8 && $sides <19 ) $compensater += .02; if ( $sides == 26 || $sides == 27|| $sides == 5 || $sides == 19) $compensater += .01; if ($sides > 31) $compensater -= .0077*($sides-31); float $ratio = ($compensater)/($crad); string $cname[] = `cylinder -r $crad -hr $ratio`; move 0 0 $compensationCylinder; string $original = `group $cname[0] $sname[0]`; pickWalk -d up; string $d1[]; xform -os -piv 0 0 0; $d1 = `duplicate`; float $yrotation = 360.0/$sides; rotate 0 $yrotation 0; parent $d1[0] $original; int $counter; for($counter = 2; $counter<$sides; $counter++) { string $d2[]; $d2 = `duplicate`; float $duplicaterotation= $yrotation*$counter; rotate 0 $duplicaterotation 0; } pickWalk -d up; pickWalk -d up; pickWalk -d up; return $original; } global proc makeMolecule(float $srad, float $crad, int $sides, int $copies,float $tX, float $tY, float $tZ, float $rX, float $rY,float $rZ, float $sX, float $sY, float $sZ, int $offT,int $offR, int $offS, float $offH, int $animate) { int $n; //int $crazy; //for ($crazy=100; $crazy>2; $crazy--){ //$crazy can be put in place of the last number to create a //series of shapes, the first with sides = initial value of //$crazy, decrementing by one side until the final shape which //has 3 sides. float $localsrad=$srad; float $localcrad=$crad; int $localsides=$sides; float $localtX=$tX; float $localtY=$tY; float $localtZ=$tZ; float $localrX=$rX; float $localrY=$rY; float $localrZ=$rZ; float $localsX=$sX; float $localsY=$sY; float $localsZ=$sZ; //radius cannot be smaller than .01, sides no greater than 200. if ($sX==0 ||$sX==0. || $sX==0.0 ) { $localsX=1.0; warning "ScaleX entered as zero, subtituting 1.0"; } if ($sY==0 ||$sY==0. || $sY==0.0 ) { $localsY=1.0; warning "ScaleY entered as zero, subtituting 1.0"; } if ($sZ==0 ||$sZ==0. || $sZ==0.0 ) { $localsZ=1.0; warning "ScaleZ entered as zero, subtituting 1.0"; } if ($sides < 3) { $localsides = 3; warning "Number of Sides too small, Substituting 3"; } if ($sides > 200) { $localsides = 200; warning "Number of Sides too large, Substituting 200"; } if ($srad < .01) { $localsrad = .01; warning "Radius of Spheres too small, Substituting .01"; } if($crad > $srad){ $localcrad = $srad*.66; warning "Radii of Cylinders exceed Radii of Spheres, Substituting `print $crad`"; } if ($copies > 150) { string $returnVal=`confirmDialog -title "Warning! Creating more than 150 Copies." -message "This may compromise system stability. \nAre you sure?" -button "Proceed" -defaultButton "Proceed" -button "Cancel" -cancelButton "Cancel" -dismissString "Cancel"`; if ($returnVal=="Cancel") error "Operation Aborted by User."; } for($n = 0; $n<$copies; $n++) { float $up = $n * $offH; if ($offT){ $localtX=$tX; $localtY=$tY; $localtZ=$tZ; $localtX *= $n; $localtY *= $n; $localtZ *= $n; } if ($offR){ $localrX=$rX; $localrY=$rY; $localrZ=$rZ; $localrX *= $n; $localrY *= $n; $localrZ *= $n; } if ($offS){ int $i; $localsX=$sX; $localsY=$sY; $localsZ=$sZ; for($i=0;$i<$n;$i++){ $localsX *= $sX; $localsY *= $sY; $localsZ *= $sZ; } } string $name=molecule($localsrad, $localcrad,$localsides); pickWalk -d up; pickWalk -d up; pickWalk -d up; $up += $localtY; xform -t $localtX $up $localtZ; rotate $localrX $localrY $localrZ; scale $localsX $localsY $localsZ; if ($animate) { keyframer($name); } } } global proc inputValues(string $sphereRad, string $cylinderRad, string $numSides, string $numCopies, string $heightOffset,string $translationGroup, string $rotationGroup,string $scaleGroup, string $offTran, string $offRot, string $offScale, string $animate) { float $srad = `floatFieldGrp -q -value1 $sphereRad`; float $crad = `floatFieldGrp -q -value1 $cylinderRad`; int $sides = `intFieldGrp -q -value1 $numSides`; int $copies = `intFieldGrp -q -value1 $numCopies`; float $tX = `floatFieldGrp -q -value1 $translationGroup`; float $tY = `floatFieldGrp -q -value2 $translationGroup`; float $tZ = `floatFieldGrp -q -value3 $translationGroup`; float $rX = `floatFieldGrp -q -value1 $rotationGroup`; float $rY = `floatFieldGrp -q -value2 $rotationGroup`; float $rZ = `floatFieldGrp -q -value3 $rotationGroup`; float $sX = `floatFieldGrp -q -value1 $scaleGroup`; float $sY = `floatFieldGrp -q -value2 $scaleGroup`; float $sZ = `floatFieldGrp -q -value3 $scaleGroup`; int $offT = `checkBox -q -v $offTran`; int $offR = `checkBox -q -v $offRot`; int $offS = `checkBox -q -v $offScale`; int $animateTF=`checkBox -q -v $animate`; float $offH = `floatFieldGrp -q -value1 $heightOffset`; makeMolecule($srad,$crad,$sides,$copies,$tX,$tY,$tZ,$rX,$rY,$rZ,$sX,$sY,$sZ, $offT,$offR,$offS,$offH,$animateTF); } global proc moleculePlusPlusUI () { string $myWindow= `window -s false -mnb true -in "Molecule Generator"-title "Molecule Generator 1.0" -rtf true`; columnLayout; frameLayout -collapsable true - label "General"; columnLayout; floatFieldGrp -value1 0.2 -label "Sphere Radius" sphereRad; floatFieldGrp -value1 0.1 -label "Cylinder Radius" cylinderRad ; intFieldGrp -value1 4 -label "Number of Sides" numSides; intFieldGrp -value1 1 -label "Number of Copies" numCopies; floatFieldGrp -value1 .2 -label "Height Offset" heightOffset; rowLayout -ct1 "left" -co1 100; checkBox -label "Animate Molecules" animate; setParent ..; setParent ..; setParent ..; frameLayout -collapsable true - label "Transform Attributes"; columnLayout; floatFieldGrp -numberOfFields 3 -value1 0.0 -value2 0.0 -value3 0.0 -label "Translation X Y Z" transGroup; floatFieldGrp -numberOfFields 3 -value1 0.0 -value2 0.0 -value3 0.0 -label "Rotation X Y Z" rotGroup; floatFieldGrp -numberOfFields 3 -value1 1.0 -value2 1.0 -value3 1.0 -label "Scale X Y Z" scaleGroup; rowColumnLayout -nc 4 -cw 1 101 -cs 1 20 -cs 2 20 -cs 2 20; checkBox -label "Offset Translation " offTran; checkBox -label "Offset Rotation " offRot; checkBox -label "Offset Scale" offScale; setParent ..; setParent ..; setParent ..; rowColumnLayout -nc 3; button -label "Make Molecule(s)" -align "center" -command "inputValues(\"sphereRad\",\"cylinderRad\",\"numSides\",\"numCopies\",\"heightOffset\",\"transGroup\",\"rotGroup\",\"scaleGroup\",\"offTran\",\"offRot\",\"offScale\", \"animate\")"; button -label "Delete Molecule(s)" -align "center" -command "undo"; button -label "Close" -align "center" -command ("deleteUI -window " + $myWindow); showWindow $myWindow; }