global proc palmerUI () { string $myWindow; $myWindow = `window -mnb true -in "Palm Generator" -title "Palm Generator 1.0" -rtf true`; columnLayout; frameLayout -collapsable true - label "Detail Properties"; columnLayout; intSliderGrp -min 3 -max 10 -v 3 -field true -label "Number Points" numPts; intSliderGrp -min 3 -max 50 -v 3 -field true -label "Number Leaves" numLvs ; floatSliderGrp -min 0 -max 1 -v 0 -pre 3 -field true -label "Leaf Randomness" lfRnd; floatSliderGrp -min 0 -max .5 -v 0.05 -pre 3 -field true -label "Depth Spread" dpSpr; setParent ..; setParent ..; frameLayout -collapsable true - label "Leaf Properties"; columnLayout; floatSliderGrp -min .5 -max 10 -v .5 -pre 3 -field true -label "Leaf Length" lfLngth; floatSliderGrp -min 0 -max 1 -v 0 -pre 3 -field true -label "Length Rand" lngthRnd; floatSliderGrp -min 0.001 -max 0.1 -v .005 -pre 5 -field true -label "Leaf Thickness" lfThk; floatSliderGrp -min 0 -max 10 -pre 3 -v 1 -field true -label "Branch Length" brLngth; floatSliderGrp -min 0.002 -max .2 -pre 5 -v .01 -field true -label "Branch Thickness" brThk; floatSliderGrp -min 0 -max 1 -pre 3 -v 0 -field true -label "Thickness Rand" thkRnd; setParent ..; setParent ..; frameLayout -collapsable true - label "Construction Properties"; columnLayout; checkBox -label "Uniform Spacing" uniSpc; floatSliderGrp -min 5 -max 180 -v 90 -pre 3 -field true -label "Leaf Angle" lfAng; floatSliderGrp -min 0 -max 1 -pre 3 -v 0 -field true -label "Angle Rand" angRnd; setParent ..; setParent ..; frameLayout -collapsable true -label "Gravity and Wind"; columnLayout; floatSliderGrp -min 0 -max 5 -pre 3 -v 2 -field true -label "Gravity Magnitude" grvMag; floatSliderGrp -min 0 -max 1 -pre 3 -v 0 -field true -label "Gravity Variance" grvRnd; floatSliderGrp -min 1 -max 5 -pre 3 -v 2 -field true -label "Stiffness" grvExp; floatSliderGrp -min 0 -max 5 -pre 3 -v 1 -field true -label "Wind Magnitude" wndMag; floatSliderGrp -min 0 -max 1 -pre 3 -v 0 -field true -label "Wind Variance" wndRnd; floatSliderGrp -min 1 -max 5 -pre 3 -v 2 -field true -label "Stiffness" wndExp; setParent ..; setParent ..; frameLayout -collapsable true - label "Multiplicity Properties"; columnLayout; intSliderGrp -min 1 -max 200 -v 1 -field true -label "Number Copies" numCpy ; checkBox -label "Use Nurbs Surface(s)" -onCommand "confirmDialog -title \"WARNING\" -message \"Please have at least one valid Nurbs surface selected when you press the Create Palms button\" -button \"OK\"" useNurb; checkBox -label "Use Color Texture" -onCommand "confirmDialog -title \"WARNING\" -message \"Please have at least one valid Nurbs surface selected with texture information when you press the Create Palms button\" -button \"OK\"" useCol; floatSliderGrp -min 0 -max 1 -pre 3 -v 0 -field true -label "Scale Randomness" sclRnd; floatSliderGrp -min 0 -max 1 -pre 3 -v 0 -field true -label "Rotation Randomness" rotRnd; intSliderGrp -min 1 -max 20 -v 3 -field true -label "Number Palms per Cluster" numPpc ; setParent ..; setParent ..; setParent ..; rowColumnLayout -nc 4; button -label "Make Palm(s)" -align "center" -command "palmer(`intSliderGrp -q -v numPts`, `intSliderGrp -q -v numLvs`,`floatSliderGrp -q -v lfRnd`, `floatSliderGrp -q -v dpSpr`,`floatSliderGrp -q -v lfLngth`,`floatSliderGrp -q -v lngthRnd`,`floatSliderGrp -q -v lfThk`,`floatSliderGrp -q -v brLngth`,`floatSliderGrp -q -v brThk`,`floatSliderGrp -q -v thkRnd`, `checkBox -q -v uniSpc`, `floatSliderGrp -q -v lfAng`,`floatSliderGrp -q -v angRnd`,`floatSliderGrp -q -v grvMag`, `floatSliderGrp -q -v grvRnd`, `floatSliderGrp -q -v grvExp`,`floatSliderGrp -q -v wndMag`,`floatSliderGrp -q -v wndRnd`,`floatSliderGrp -q -v wndExp`,`intSliderGrp -q -v numCpy`,`checkBox -q -v useNurb`, `checkBox -q -v useCol`, `floatSliderGrp -q -v sclRnd`, `floatSliderGrp -q -v rotRnd`,`intSliderGrp -q -v numPpc`)"; button -label "Undo Palm(s)" -align "center" -command "undo"; button -label "Delete All" -align "center" -command "select -all \; delete"; button -label "Close" -align "center" -command ("deleteUI -window " + $myWindow); showWindow $myWindow; } //___________________________________________________________________________________________ global proc string drawCurve (vector $pnts[], int $degree) { //begin making our command string string $cmdStr = "curve -d "+ $degree + " "; //Concatenate data onto it int $n; for($n = 0; $n < size($pnts); $n++) $cmdStr += " -p " + $pnts[$n]; //finally, use the eval() function to pass the //command string into the MEL interpreter string $name = eval($cmdStr); return $name; } global proc vector[] gravitizer (vector $pnts[], float $mag, float $magrand, float $exp) { vector $out[]; int $n; int $length = size($pnts); // float $magnitude=$mag*$magrand; // float $exponent= $exp*$exprand; float $exprand = rand($exp-1, $exp+1); for($n = 0; $n < $length; $n++){ float $angle = dot($pnts[$n], <<1, 0, 0>>); $angle=abs($angle); vector $temp = $pnts[$n]; float $u = (float) $n/$length; float $ygrav = $temp.y -($mag*pow($u, ($exp*$exprand))*$angle)+rand(-.5,.5)*$magrand*$u*$angle; $temp= << $temp.x, $ygrav, $temp.z >>; $out[$n]= $temp; } return $out; } global proc vector[] wind (vector $pnts[], float $mag, float $magrand, float $exp) { vector $out[]; int $n; int $length = size($pnts); // float $magnitude=$mag*$magrand; // float $exponent= $exp*$exprand; float $exprand = rand($exp-1, $exp+1); for($n = 0; $n < $length; $n++){ float $angle = dot($pnts[$n], <<1, 0, 0>>); $angle= 1 - abs($angle); vector $temp = $pnts[$n]; float $u = (float) $n/$length; float $zmag = $temp.z -($mag*pow($u, $exp*$exprand)*$angle)+rand(-.5,.5)*$magrand*$u*$angle; float $xmag = $temp.x -($mag*pow($u, $exp*$exprand)*$angle)+rand(-.5,.5)*$magrand*$u*$angle; $temp= << $xmag, $temp.y, $zmag >>; $out[$n]= $temp; } return $out; } global proc vector[] branchwind (vector $pnts[], float $mag, float $magrand, float $exp) { vector $out[]; int $n; int $length = size($pnts); // float $magnitude=$mag*$magrand; // float $exponent= $exp*$exprand; float $exprand = rand($exp-1, $exp+1); for($n = 0; $n < ($length-1); $n++){ // float $angle = dot($pnts[$n], <<1, 0, 0>>); // $angle=abs($angle); vector $temp = $pnts[$n]; float $u = (float) $n/$length; float $zmag = $temp.z -$mag*$u+rand(-.5,.5)*$magrand*$u; float $xmag = $temp.x -$mag*$u+rand(-.5,.5)*$magrand*$u; $temp= << $xmag, $temp.y, $zmag >>; $out[$n]= $temp; } $out[($length-1)]=$pnts[($length-1)]; return $out; } //____________________________________________________________________________________________ //____________________________________________________ global proc vector rotatePnt(float $alpha, vector $p) { return rot($p, <<0,0,1>>, deg_to_rad($alpha)); } //____________________________________________________ global proc vector[] fan(float $angle, float $len, int $num) { vector $out[]; // find the angle between each leaf float $a = $angle/($num - 1); // find the first leaf position vector $axial_leaf = <<0,$len,0>>; $out[0] = rotatePnt($angle/2, $axial_leaf); // loop around to find the other leaf positions for($n = 1; $n < $num; $n++) $out[$n] = rotatePnt(-$a * $n, $out[0]); return $out; } //____________________________________________________ global proc vector[] palmgen(float $leaflength, int $numleaves, float $depth) { vector $out[]; for($n = 0; $n < $numleaves; $n++) { vector $e = sphrand($leaflength); float $yFix = abs($e.y); float $zFix = $e.z*$depth; $e = << $e.x, $yFix, $zFix>>; $e = unit($e)*$leaflength; $out[$n] = $e; } return $out; } //____________________________________________________ global proc vector[] subdivide(int $div, vector $B, vector $E ) { vector $end = $E - $B; vector $pnt[]; float $u; int $n; for($n = 0; $n < $div + 1; $n++) { // Find the parametric distance along the vector // Note the cast, or promotion, to a float $u = (float) $n/$div; // find the xyz at the parametric location and // offset by $B so that we have the xyz relative // to the true beginning of the line defined by // locations $B and $E. $pnt[$n] = $u * $end + $B; //print ("$pnt = " + $pnt[$n] + "\n"); } return $pnt; } global proc string[] SlmPaletteUtils_GetPaletteHandles() { string $palettes[]; string $handles = `slimcmd slim GetPalettes`; tokenize($handles, $palettes); return $palettes; } global proc string SlmPaletteUtils_GetPaletteLabel(string $handle) { return `slimcmd $handle GetLabel`; } global proc SlmPaletteUtils_ShowPalette(string $name) { slimcmd slim WindowCmd Show palettes; } global proc string SlmPaletteUtils_AddShaderToPalette(string $shadername, string $pltHandle) { $path = `slimcmd workspace ResolvePath shaders "plastic slo"`; $path += ("/" + $shadername + ".slo"); $path = "$RMANTREE/lib/shaders/" + $shadername + ".slo"; slimcmd $pltHandle CreateInstance -file $path; $shadername += "*"; return `slimcmd $pltHandle GetAppearances -name $shadername`; } global proc string SlmPaletteUtils_CreatePalette(string $name) { string $handle = `slimcmd slim FindPalette $name`; if($handle != "") return $handle; $handle = `slimcmd slim CreatePalette -edit -new`; slimcmd $handle SetLabel $name; return $handle; } global proc string[] SlmParamUtils_GetPropertyHandles(string $appHandle) { string $all = `slimcmd $appHandle GetProperties`; string $out[]; tokenize($all, $out); return $out; } global proc string[] SlmParamUtils_GetParamNames(string $appHandle) { string $handles[] = getPropertyHandles($appHandle); string $names[]; for($n = 0; $n < size($handles); $n++) $names[$n] = `slimcmd $handles[$n] GetLabel`; return $names; } global proc string SlmParamUtils_GetPropertyNamed(string $appHandle, string $name) { string $handles[] = SlmParamUtils_GetPropertyHandles($appHandle); string $names[]; for($n = 0; $n < size($handles); $n++) { $names[$n] = `slimcmd $handles[$n] GetLabel`; if($names[$n] == $name) return $handles[$n]; } return ""; } global proc string[] SlmParamUtils_GetPropertyTypes(string $appHandle) { string $handles[] = SlmParamUtils_GetPropertyHandles($appHandle); string $types[]; for($n = 0; $n < size($handles); $n++) $types[$n] = `slimcmd $handles[$n] GetType`; return $types; } //___________________________________________________________________________________________ global proc palmer (int $numpoints, int $numleaves, float $leavesrand, float $depthspread, float $leaflength, float $lengthrand, float $leafthickness, float $branchlength, float $branchthickness, float $thicknessrand, int $uniformspacing, float $leafangle, float $anglerand, float $gravity, float $gravityrand, float $gravityexp, float $wind, float $windrand, float $windexp, int $numcopies, int $usenurbs, int $usecolor, float $scalerand, float $rotrand, int $palmspergroup) { // Trial cluster of "spikes" int $palmgroupcounter = $palmspergroup ; int $i,$n; string $dagnodes[]; float $randmoveX=0; float $randmoveZ=0; float $randmoveY=0; $dagnodes = `selectedNodes -dagObjects`; string $palH= SlmPaletteUtils_CreatePalette("mine_all_mine"); string $appH= SlmPaletteUtils_AddShaderToPalette("plastic",$palH); string $kdH= SlmParamUtils_GetPropertyNamed($appH,"Kd"); string $csH= SlmParamUtils_GetPropertyNamed($appH,"Cs"); //We'll use the apporpriate slim commands directly ourselves slimcmd $kdH SetValue "1.0"; slimcmd $csH SetValue "{0.0 0.6 0.0}"; slimcmd $appH PreviewRender; for ($i=0; $i<$numcopies; $i++) { vector $origin = <<0,0,0>>; vector $leaf[]; vector $branch[]; $branch = subdivide($numpoints, $origin, << 0,(-1*$branchlength), 0 >> ); $branch = branchwind($branch, $wind, $windrand, $windexp); string $original = drawCurve($branch, 3); //mtor control attach surface `slimcmd apph GetID`; string $shape[] = `listRelatives -s`; addAttr -ln mtorCurveWidth -dv $branchthickness -k true $shape[0]; int $leafrandomizer = rand((-$numleaves/2),($numleaves/2))*$leavesrand; float $anglerandomizer= rand((-$leafangle/2),($leafangle/2))*$anglerand; float $combinedAngle = $leafangle + $anglerandomizer; int $combinedNumber= $numleaves + $leafrandomizer; vector $ends[]; if ($uniformspacing){ $ends= fan($combinedAngle, $leaflength,$combinedNumber); } else{ $ends= palmgen($leaflength, $combinedNumber, $depthspread); } for($n = 0; $n < $numleaves; $n++) { $leaf = subdivide($numpoints, $origin, $ends[$n]); $leaf = gravitizer($leaf, $gravity, $gravityrand, $gravityexp); $leaf = wind($leaf, $wind, $windrand, $windexp); string $current = drawCurve($leaf, 3); parent $current $original; // RenderMan stuff... // mtor control attach surface `slimcmd apph GetID`; string $shape[] = `listRelatives -s`; float $thickrandomizer=rand((-$leafthickness/2),($leafthickness/2))*$thicknessrand; $thickrandomizer += $leafthickness; addAttr -ln mtorCurveWidth -dv $branchthickness -k true $shape[0]; } pickWalk -d up; // pickWalk -d up; //hilite -r; float $randu, $randv; int $whichsurface = rand (0,size($dagnodes)-1); if ($usenurbs && !$usecolor && $i==0) { //set initial values if using NURBS surface float $m[] = `pointOnSurface -u $randu -v $randv $dagnodes[$whichsurface]`; $randmoveX=$m[0]; $randmoveZ=$m[2]; $randmoveY=$m[1]; } else if ($usecolor && $i==0) //set initial values if using Colored surface { float $c[] = `colorAtPoint -o RGB -u .5 -v .5 "ramp1"`; int $elements; for($elements in $c) print ("\nYou are reading element "+ $elements+" of Vals."); while ($c[1] ==0 || $c[0] > .2 || $c[2] >.2 || $c[2] > $c[1] || $c[0] >$c[1]) { $randu=rand(0,1); $randv=rand(0,1); $whichsurface = rand (0,size($dagnodes)-1); $c = `colorAtPoint -o RGB -u $randu -v $randv "ramp1"`; } $randmoveX=$c[0]; $randmoveZ=$c[2]; $randmoveY=$c[1]; } if ($palmgroupcounter == 0) {//break from current grouping to create a position for new group $palmgroupcounter = $palmspergroup; if ($usenurbs && !$usecolor) { $randu=rand(0,1); $randv=rand(0,1); int $whichsurface = rand (0,size($dagnodes)-1); float $m[] = `pointOnSurface -u $randu -v $randv $dagnodes[$whichsurface]`; $randmoveX=$m[0]; $randmoveZ=$m[2]; $randmoveY=$m[1]; } else if ($usecolor) { int $whichsurface = rand (0,size($dagnodes)-1); // float $c[] = `colorAtPoint -o RGB -u .5 -v .5 $dagnodes[$whichsurface]`; // createNode checker; float $c[] = `colorAtPoint -o RGB -u .5 -v .5 "ramp1"`; while ($c[1] ==0 || $c[0] > .2 || $c[2] >.2 || $c[2] > $c[1] || $c[0] >$c[1]) { $randu=rand(0,1); $randv=rand(0,1); $whichsurface = rand (0,size($dagnodes)-1); $c = `colorAtPoint -o RGB -u $randu -v $randv "ramp1"`; } $randmoveX=$c[0]; $randmoveZ=$c[2]; $randmoveY=$c[1]; } else{ $randmoveX = rand(-12,12); $randmoveZ = rand(-12,12); // $randmoveY = rand(-2,2); } } $palmgroupcounter=$palmgroupcounter-1; float $randroty = rand (-180,180)*$rotrand; float $randrotxz = rand (-60,60)*$rotrand; float $randscale= 1+(rand (-.75,3)*$scalerand); select $original; xform -os -piv 0 (-$branchlength) 0; move -r 0 $branchlength 0 $original; move -r $randmoveX $randmoveY $randmoveZ; rotate $randrotxz $randroty $randrotxz; if ($randscale>0) scale $randscale $randscale $randscale; slimcmd slim Clear; select $original; mtor control attach surface `slimcmd $appH GetID`; //mtor RenderSpool; } defaultDirectionalLight(1,1,1,1,"0",0,0,0); rotate -45 0 0; move 0 1 0; } //_______________________________________________________________________________________ palmerUI(); //That's it...putting all of this code into the script editor (make sure mtor_maya5.mll has been loaded) should execute and run the UI. //Cheers! -Sean