//////////////////////////////////////////////////////////////////////////////////////////////////
// //
// Rock Generator2.5 //
// //
//////////////////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 1998-1999 Alias|Wavefront,
// a division of Silicon Graphics Limited.
//
// The information in this file is provided for the exclusive use of the
// licensees of Alias|Wavefront. Such users have the right to use, modify,
// and incorporate this code into other products for purposes authorized
// by the Alias|Wavefront license agreement, without fee.
//
// ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
// INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
// EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
// DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
//
// Alias|Wavefront Script File
// MODIFY THIS AT YOUR OWN RISK
//
// Author: Terry Stoeger
//
// Creation Date: ( 10/05/99 )
// Last Update: ( 9/1/00 )
// Last Update: ( 2/01/2002 )
//
// Thank You:
// Alex Tang, Mike Aquino, Jeff Meeker and Ron Janzen:
// for you wisdom and input!!
//
// Description:
// This scripts generates different types of rock formations.
//
// Boulder: This is now used for many different rock shapes including My older "glacial" @ "slate" style
// Quartz: Crystal structure.
// Stalagmite: They look like aaaaa..... stalagmite's.
//
// Tips:
// To create one rock at World Origin set "Distribution Radius" too Zero.
// GlobalScale - Adjusts the over all size of the rock group.
//
// For "Quartz" - "Distribution Radius" has no effect.
// For "Stalagmite" - experiment with ScaleMin And ScaleMax.
//
//
//
// Input Arguments: NONE
//
//////////////////////////////////////////////////////////////////////////////////////////////////
// Version: Maya3.0 - 4.0 //
// ALERT: This script will work with Maya2.0 but "Quartz" will report an error and quit!!! //
// This is not a bug; some function calls have changed from 2.0 to 2.5!! //
// //
//////////////////////////////////////////////////////////////////////////////////////////////////
proc string rockRelatives ()
{
string $results[] = `listRelatives -p`;
string $results2[];
if (`nodeType ($results[0])` != "transform")
{
$results2 = `listRelatives -p $results[0]`;
}
else
{
$results2[0] = $results[0];
}
return $results2[0];
}
////////////////////////////////////
proc bolderGen()
{
waitCursor -state on;
//bolder generation proc:
int $bolderIndex;
//number of bolders in group:
int $bolderNumber = `intSliderGrp -q -value rockNum`;
//create group node:
string $bolderGroup = `createNode transform -n bolderGroup1`;
//generate bolder in for loop:
for($bolderIndex = 0; $bolderIndex < $bolderNumber; $bolderIndex++)
{
//generate base curve and 1st face:
int $bolderSect = rand (4,10);
float $bolderRadi = rand (1.5,3);
string $bolderBaseCurve[] = `circle -c 0 0 0 -sweep -360 -r $bolderRadi -nr 0 1 0 -d 1 -ut 0 -s $bolderSect -ch 0`;
string $bolderBasePoly[] = `planarSrf -ch 1 -d 3 -ko 0 -tol 0.01 -rn 0 -po 1 $bolderBaseCurve[0]`;
string $tesser[] = `listHistory $bolderBasePoly[0]`;
setAttr ($tesser[1] + ".polygonType") 1;
setAttr ($tesser[1] + ".format") 0;
setAttr ($tesser[1] + ".polygonCount") 1;
DeleteHistory $bolderBasePoly[0];
delete $bolderBaseCurve[0];
//get the shape node and the 1st face for later use:
string $bolderPoly[] = `listRelatives -s $bolderBasePoly[0]`;
select -r $bolderPoly.f["*"];
string $bolderPolyF[] = `filterExpand -sm 34`;
//extrude:
//float $bolderExtrudeY = rand (.5,3);
int $bolderExtrudeY = `intSliderGrp -q -value rockHeight`;
int $bolderDivisionsY = `intSliderGrp -q -value rockHeight`;
float $divHeight = ($bolderDivisionsY /2);
polyExtrudeFacet -ch 0 -kft 1 -ty $bolderExtrudeY -ran .25 -divisions $divHeight -off 0 $bolderPolyF[0];
//set up UV's .. kinda!!
select -r $bolderPolyF[0];
PolySelectConvert 4;
polyEditUV -pu 0.5 -pv 0.5 -su .6 -sv .6 ;
//make softbody and perturb:
select -r $bolderPoly[0];
float $bolderNoise = `floatSliderGrp -q -value rockNoise`;
select -r $bolderPoly[0];
polyTriangulate -ch 1 $bolderPoly[0];
DeleteHistory $bolderPoly[0];
string $bolderSoftBody[] =`soft -c $bolderPoly[0]`;
//string $bolderEX = "position = position + sphrand(<<.5,.5,.5>>);";
string $bolderEX = "position = position + sphrand(<<" + $bolderNoise + "," + $bolderNoise + ", " + $bolderNoise +">>);";
dynExpression -s $bolderEX -c $bolderSoftBody[0];
dynExpression -s $bolderEX -r $bolderSoftBody[0];
delete -ch $bolderPoly[0];
delete $bolderSoftBody[0];
//look at the lowRez/highRez flag, if on lowRez skip 2nd perturb:
int $rockRez = `radioButtonGrp -q -sl rezFlag`;
if($rockRez == 2)
{
//smooth poly:
polySmooth -dv 2 -c 0.8 -ch 1 $bolderPoly[0];
delete -ch $bolderPoly[0];
//repeat soft perturb:
select -r $bolderPoly[0];
string $bolderSoftBody[] =`soft -c $bolderPoly[0]`;
//string $bolderEX = "position = position + sphrand(<<.06,.08,.05>>);";
string $bolderEX = "position = position + sphrand(<<.1,.1,.1>>);";
dynExpression -s $bolderEX -c $bolderSoftBody[0];
dynExpression -s $bolderEX -r $bolderSoftBody[0];
delete -ch $bolderPoly[0];
delete $bolderSoftBody[0];
//smooth again:
polySmooth -dv 1 -c 0.5 -ch 1 $bolderPoly[0];
//polySmooth -dv 1 -c 1 -ch 1 $bolderPoly[0];
//delete -ch $bolderPoly[0];
}
else
{
//smooth poly:
polySmooth -dv 1 -c 1 -ch 1 $bolderPoly[0];
delete -ch $bolderPoly[0];
}
//call the prco to get the rock parent node
//This is done in a proc to make the script 2.5 and 3.0 compatable:
string $moveBolder = `rockRelatives`;
//random scale:
float $newBolderSmin = `floatSliderGrp -q -value rockScaleMin`;
float $newBolderSmax = `floatSliderGrp -q -value rockScaleMax`;
float $newBolderSheer = `floatSliderGrp -q -value rockSheer`;
float $newBolderSRand = rand($newBolderSmin,$newBolderSmax);
scale $newBolderSRand $newBolderSRand $newBolderSRand;
string $bolderShearXY = $moveBolder + ".shearXY";
setAttr $bolderShearXY $newBolderSheer;
// randomly distribute:
float $bolderDradius = `floatSliderGrp -q -value distRadius`;
float $bolderDradiusN = -$bolderDradius;
float $distX = rand ($bolderDradiusN,$bolderDradius);
float $distZ = rand ($bolderDradiusN,$bolderDradius);
string $distBolder[] = {(($moveBolder) + ".translateX"), ($moveBolder + ".ty"), ($moveBolder + ".tz")};
setAttr $distBolder[0] $distX;
//setAttr $distBolder[1] -.5;
setAttr $distBolder[2] $distZ;
float $randRotY = rand (0,360);
string $rotBolder = $moveBolder + ".ry";
setAttr $rotBolder $randRotY;
//parent to group node and rename:
parent $moveBolder $bolderGroup;
rename $moveBolder "bolder1";
}
//global scale and group:
float $bolderGRPscale = `floatSliderGrp -q -value globalRockScale`;
select $bolderGroup;
scale $bolderGRPscale $bolderGRPscale $bolderGRPscale;
makeIdentity -apply true;
waitCursor -state off;
}
//end of bolder proc:
/////////////////////////////////
proc crystalGen()
{
waitCursor -state on;
//crystal generation proc:
int $crystalIndex;
//number of crystal in group:
int $crystalNumber = `intSliderGrp -q -value rockNum`;
//create group node:
string $crystalGroup = `createNode transform -n quartzGroup1`;
//generate crystal in for loop:
for($crystalIndex = 0; $crystalIndex < $crystalNumber; $crystalIndex++)
{
//generate base curve and 1st face:
float $crystalRadi = rand (.4,1.2);
string $crystalCurve[] = `circle -c 0 0 0 -sweep -360 -r $crystalRadi -nr 0 1 0 -d 1 -ut 0 -s 6 -ch 0`;
string $crystalPoly[] = `planarSrf -ch 1 -d 3 -ko 0 -tol 0.01 -rn 0 -po 1 $crystalCurve[0]`;
string $tesser[] = `listHistory $crystalPoly[0]`;
setAttr ($tesser[1] + ".polygonType") 1;
setAttr ($tesser[1] + ".format") 0;
setAttr ($tesser[1] + ".polygonCount") 1;
DeleteHistory $crystalPoly[0];
delete $crystalCurve[0];
//list the verts and perturb:
string $vert[] = `polyListComponentConversion -tv $crystalPoly[0]`;
string $vertsExband[] = `filterExpand -sm 31 $vert`;
int $i;
int $vertNum = 5;
for($i = 0; $i < $vertNum; $i++)
{
select -r $vertsExband[$i];
float $vertAround = rand(-.4,.2);
move -r -moveXZ $vertAround;
}
//extrude:
string $crystalPolyF[] = `listRelatives -s $crystalPoly[0]`;
float $extrudeYmin = `floatSliderGrp -q -value rockScaleMin`;
float $extrudeYmax = `floatSliderGrp -q -value rockScaleMax` * 8;
float $extrudeY = rand ($extrudeYmin,$extrudeYmax);
polyExtrudeFacet -ch 0 -kft 1 -ty $extrudeY -off 0 $crystalPolyF[0];
string $crystalPolySF[] = `ls -sl`;
float $extrudeY2 = rand (.4,.8);
polyExtrudeFacet -ch 0 -kft 1 -ty $extrudeY2 -sx .01 -sz .01 -off 0 $crystalPolySF[0];
//perturb crystal points:
string $crystal[] = `listRelatives -p`;
string $crystVerts[] = `polyListComponentConversion -tv $crystal[0]`;
string $crystExband[] = `filterExpand -sm 31 $crystVerts`;
for ($i = 6; $i < 12; $i++)
{
select -r $crystExband[$i];
float $vertUp = rand(-.3,.3);
move -r -moveY $vertUp;
}
//set random angle:
string $oldCrystal[] = `listRelatives -p`;
select -r $oldCrystal[0];
string $newCrystal[] = `listRelatives -p`;
float $anglX = rand (-85,85);
float $anglZ = rand (-85,85);
string $RotateCrystal[] = {($newCrystal[0] + ".rx"), ($newCrystal[0] + ".rz")};
setAttr $RotateCrystal[0] $anglX;
setAttr $RotateCrystal[1] $anglZ;
//parent to group node and rename:
parent $newCrystal[0] $crystalGroup;
rename $newCrystal[0] "quartz1";
}
//global scale and group
float $crystGRPscale = `floatSliderGrp -q -value globalRockScale`;
select $crystalGroup;
scale $crystGRPscale $crystGRPscale $crystGRPscale;
makeIdentity -apply true;
waitCursor -state off;
}
//end of crystal proc:
////////////////////////////////////
proc stalagGen()
{
waitCursor -state on;
// stalagmite generation proc:
int $slagIndex;
//number of stalagmite's in group:
int $slagNumber = `intSliderGrp -q -value rockNum`;
//create group node:
string $tmpGroup = `createNode transform`;
//generate stalagmite in for loop:
for($slagIndex = 0; $slagIndex < $slagNumber; $slagIndex++)
{
//generate base curve and 1st face:
int $slagSect = rand(8,12);
float $slagRadi = rand(1,2);
string $slagBaseCurve[] = `circle -c 0 0 0 -sweep -360 -r $slagRadi -nr 0 1 0 -d 1 -ut 0 -s $slagSect -ch 0`;
string $slagBasePoly[] = `planarSrf -ch 1 -d 3 -ko 0 -tol 0.01 -rn 0 -po 1 $slagBaseCurve[0]`;
string $tesser[] = `listHistory $slagBasePoly[0]`;
setAttr ($tesser[1] + ".polygonType") 1;
setAttr ($tesser[1] + ".format") 0;
setAttr ($tesser[1] + ".polygonCount") 1;
DeleteHistory $slagBasePoly[0];
delete $slagBaseCurve[0];
//extrude:
string $slagPolyF[] = `listRelatives -s $slagBasePoly[0]`;
float $slagExtrudeY = rand (1,3);
polyExtrudeFacet -ch 0 -kft 1 -ty $slagExtrudeY -s 0.7 1 0.7 -off 0 $slagPolyF[0];
string $slagHigh[] = `ls -sl`;
int $slagUp;
for($slagUp = 0; $slagUp < 3; $slagUp++)
{
polyExtrudeFacet -ch 0 -kft 1 -ty 1.5 -s .7 1 .7 -off 0 $slagHigh[1];
}
polyExtrudeFacet -ch 0 -kft 1 -ty .9 -s .4 1 .4 -off 0 $slagHigh[1];
// randomly scale & distribute:
string $oldSlag[] = `listRelatives -p`;
select -r $oldSlag[0];
string $moveSlag[] = `listRelatives -p`;
//float $newSlagSmin = `floatSliderGrp -q -value rockScaleMin`;
//float $newslagSmax = `floatSliderGrp -q -value rockScaleMax` * 2;
float $slagHeight = rand (1,3);
//float $slagHeight = rand ($newSlagSmin,$newslagSmax);
scale 1 $slagHeight 1;
float $slagDradius = `floatSliderGrp -q -value distRadius` / 6;
float $slagDradiusN = -$slagDradius;
float $distX = rand ($slagDradiusN,$slagDradius);
float $distZ = rand ($slagDradiusN,$slagDradius);
string $distSlag[] = {($moveSlag[0] + ".tx"), ($moveSlag[0] + ".ty"), ($moveSlag[0] + ".tz")};
setAttr $distSlag[0] $distX;
setAttr $distSlag[1] -1;
setAttr $distSlag[2] $distZ;
//parent to group node :
parent $moveSlag[0] $tmpGroup;
}
//perform boolean op's & delete history:
string $bolSlagGrp = $tmpGroup;
string $boleSlag[] = `listRelatives -c $bolSlagGrp`;
select $boleSlag;
int $i;
for ($i=1; $i < size($boleSlag); ++$i)
{
string $firstBol[] = `ls -sl`;
if ( catch (`polyBoolOp -op 1 -ch 0 -n tmpSlag $firstBol[0] $boleSlag[$i]` ))
{
delete $firstBol;
delete $tmpGroup;
confirmDialog -t "Error" -m "Maya didn't like that one! Try again:" -b "OK" -db "OK" ;
}
string $firstBol[] = `ls -sl`;
}
string $slagPoly[] = `ls -sl`;
//maya2.5 iffy
//delete $tmpGroup;
//make softbody and perturb:
string $slagSoftBody[] =`soft -c $slagPoly[0]`;
string $slagEX = "position = position + sphrand(<<.2,.1,.2>>);";
dynExpression -s $slagEX -c $slagSoftBody[0];
dynExpression -s $slagEX -r $slagSoftBody[0];
delete -ch $slagPoly[0];
delete $slagSoftBody[0];
//smooth poly:
string $slagFaces[] = `listRelatives -s $slagPoly`;
polySmooth -dv 1 -c 1 -ch 1 $slagFaces[0];
delete -ch $slagPoly[0];
string $slagDone[] = `listRelatives -p `;
//string $scaleSlag[] = `select -r $slagDone[0]`;
//random scale:
float $newSlagSmin = `floatSliderGrp -q -value rockScaleMin`;
float $newslagSmax = `floatSliderGrp -q -value rockScaleMax`;
scale $newslagSmax $newSlagSmin $newslagSmax;
makeIdentity -apply true;
float $newSlagS = `floatSliderGrp -q -value globalRockScale`;
scale $newSlagS $newSlagS $newSlagS;
makeIdentity -apply true;
rename $slagDone[0] "stalagmite1";
waitCursor -state off;
}
//end of stalagmite rock generation proc:
///////////////////////////////////////
global proc genRock()
{
string $optionVal = `optionMenu -q -v rockType`;
switch ($optionVal)
{
case "Boulder":
bolderGen();
textField -edit -text "Boulders Generated !!" StatusLine;
break;
case "Quartz":
crystalGen();
textField -edit -text "Quartz Crystal Generated !!" StatusLine;
break;
case "Stalagmite":
stalagGen();
textField -edit -text "Stalagmite Generated !!" StatusLine;
break;
} // end switch
}
////////////////////////////////////
global proc changRockUI()
{
string $getV = `optionMenu -q -v rockType`;
switch($getV)
{
case "Boulder":
intSliderGrp -edit -value 5 -minValue 1 rockNum;
floatSliderGrp -edit -en true -value 10 distRadius;
intSliderGrp -edit -en true -value 2 rockHeight;
floatSliderGrp -edit -en true -value 0 rockSheer;
floatSliderGrp -edit -en true -value .5 rockNoise;
floatSliderGrp -edit -value 1.0 globalRockScale;
floatSliderGrp -edit -value .5 rockScaleMin;
floatSliderGrp -edit -value 1.0 rockScaleMax;
radioButtonGrp -edit -en true rezFlag;
textField -edit -text "RockGenerator 2.0" StatusLine;
break;
case "Quartz":
intSliderGrp -edit -value 20 -minValue 1 rockNum;
floatSliderGrp -edit -en false distRadius;
intSliderGrp -edit -en false -value 2 rockHeight;
floatSliderGrp -edit -en false -value 0 rockSheer;
floatSliderGrp -edit -en false -value .5 rockNoise;
floatSliderGrp -edit -value 1.0 globalRockScale;
floatSliderGrp -edit -value .5 rockScaleMin;
floatSliderGrp -edit -value 1.0 rockScaleMax;
radioButtonGrp -edit -en false rezFlag;
textField -edit -text "RockGenerator 2.0" StatusLine;
break;
case "Stalagmite":
intSliderGrp -edit -value 7 -minValue 2 rockNum;
floatSliderGrp -edit -en true -value 6 distRadius;
intSliderGrp -edit -en false -value 2 rockHeight;
floatSliderGrp -edit -en false -value 0 rockSheer;
floatSliderGrp -edit -en false -value .5 rockNoise;
floatSliderGrp -edit -value 1.0 globalRockScale;
floatSliderGrp -edit -value 1.0 rockScaleMin;
floatSliderGrp -edit -value 1.0 rockScaleMax;
radioButtonGrp -edit -en false rezFlag;
textField -edit -text "RockGenerator 2.0" StatusLine;
break;
}// end switch
}
////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
global proc rockGen()
{
string $win = "RockGenerator";
if (`window -exists $win`) deleteUI -window $win;
window -title "Rock Generator"
-minimizeButton true -maximizeButton false -rtf true
-wh 300 300 $win;
columnLayout -adjustableColumn true -cal "left" ColumnLayout;
frameLayout -labelVisible false -marginWidth 0 -marginHeight 0 rockFrame;
columnLayout;
optionMenu -label " Rock Type " rockType;
menuItem -label "Boulder";
menuItem -label "Quartz";
menuItem -label "Stalagmite";
separator -height 20 -st none;
intSliderGrp
-label "Number of Rocks" -field true
-value 5 -minValue 1 -maxValue 30 -sliderStep 1
rockNum;
floatSliderGrp
-label "Distribution Radius" -field true -precision 2
-value 10 -minValue 0 -maxValue 100 -step .1
distRadius;
separator -height 20 -st none;
intSliderGrp
-label "Height Ratio" -field true
-value 2 -minValue 0 -maxValue 10 -step 1
rockHeight;
floatSliderGrp
-label "Sheer" -field true -precision 2
-value 0 -minValue 0 -maxValue 5 -step .01
rockSheer;
floatSliderGrp
-label "3D Noise" -field true -precision 2
-value .5 -minValue 0 -maxValue 3 -step .01
rockNoise;
separator -height 20 -st none;
floatSliderGrp
-label "Global Rock Scale" -field true -precision 2
-value 1 -minValue .1 -maxValue 10 -step .1
globalRockScale;
floatSliderGrp
-label "Rock Scale Min" -field true -precision 2
-value .5 -minValue .01 -maxValue 2 -step .01
rockScaleMin;
floatSliderGrp
-label "Rock Scale Max" -field true -precision 2
-value 1 -minValue .01 -maxValue 2 -step .01
rockScaleMax;
separator -height 10 -st none;
radioButtonGrp
-numberOfRadioButtons 2
-label "Rock Resolution"
-labelArray2 "lowRez" "highRez"
-sl 1 rezFlag;
separator -height 10 -st none;
setParent RockGenerator|ColumnLayout;
textField -text "RockGenerator 2.0 - Requires Maya2.5 or Higher:" -editable false StatusLine;
rowColumnLayout -numberOfRows 1 -rowHeight 1 30;
button -label "Generate" -w 129 -c "genRock()";
button -label "Discard" -w 130 -c delete;
button -label "Close" -w 129 -c ("window -e -vis 0 "+$win) closeBtn;
setParent RockGenerator;
//alert callbacks:
optionMenu -edit -cc "changRockUI()" rockType;
intSliderGrp -edit -changeCommand "textField -edit -text \"ALERT: A Number > 5 May Take A Few Seconds:\"StatusLine" rockNum;
floatSliderGrp -edit -changeCommand "textField -edit -text \"Radius From Global Origin:\"StatusLine" distRadius;
intSliderGrp -edit -changeCommand "textField -edit -text \"Sets a Random Height Value:\"StatusLine" rockHeight;
floatSliderGrp -edit -changeCommand "textField -edit -text \"Sets The Sheer For An Angled Rock:\"StatusLine" rockSheer;
floatSliderGrp -edit -changeCommand "textField -edit -text \"Sets Amount Of Perturbation in The Rocks:\"StatusLine" rockNoise;
floatSliderGrp -edit -changeCommand "textField -edit -text \"Sets Over All Size Of Rock Group:\"StatusLine" globalRockScale;
floatSliderGrp -edit -changeCommand "textField -edit -text \"Sets Minimum Size Of Rock In Group:\"StatusLine" rockScaleMin;
floatSliderGrp -edit -changeCommand "textField -edit -text \"Sets Maximum Size Of Rock In Group:\"StatusLine" rockScaleMax;
showWindow $win;
}
rockGen;//RunIt
//////////////////////////////////////////////////////////////////////////////////////////////////
// End of Rock Gen //
//////////////////////////////////////////////////////////////////////////////////////////////////