// Generative Cheese Script// // Author: Yu Ping Hsieh // 02/11/2008 //compatible: Maya 5 and up //instruction:Must start a new Maya file with no history /////////////////////////////////////////// //1st loop: Random PolySphere Loop //What it does: generate random polyspheres in space //Command: int $YCounter = 1; polySphere -r 3 -n "SphereObject"; do { float $XVal = rand (-7, 7); float $YVal = rand (-10,10); float $ZVal = rand (-7,7); float $SVal = rand (0.85, 0.15); move -a $XVal $YVal $ZVal; scale -a $SVal $SVal $SVal; rotate -a $YVal $YVal $YVal; duplicate -rr; currentTime $YCounter; $YCounter ++; } while ($YCounter < 75); /////////////////////////////////////////////// //2nd loop: Bounding Box Loop: //What it does: creates a polycube, deletes all spheres not intersecting the cube polyCube -w 5 -d 5 -h 15 -n BooleanBox; // can change attribute or shape, but name of shape must be BooleanBox //polySphere -r 7 -n BooleanBox; //polyCone -r 5 -h 20 -n BooleanBox; //polyTorus -r 4 -sr 2 -n BooleanBox; //polyPipe -r 5 -t 1.5 -h 20 -n BooleanBox; string $bBox [] = `ls-sl`; float $minValue[] = `getAttr ($bBox[0]).boundingBoxMin`; //define max and min values of bounding box float $maxValue[] = `getAttr ($bBox[0]).boundingBoxMax`; string $sphereX [] = `ls-tr "SphereObject*"`; //list all sphere names in a string array int $YCounter = 0; //checks if the bounding boxes of spheres and cube intersect do { select -r $sphereX [$YCounter]; float $sphereXMax []= `getAttr ($sphereX [$YCounter] + ".boundingBoxMax")`; //define max and min values of each sphere float $sphereXMin []= `getAttr ($sphereX [$YCounter] + ".boundingBoxMin")`; if ($sphereXMax [0] > $maxValue [0] && $sphereXMin [0] > $maxValue [0]) { delete; } if ($sphereXMax [1] > $maxValue [1] && $sphereXMin [1] > $maxValue [1]) { delete; } if ($sphereXMax [2] > $maxValue [2] && $sphereXMin [2] > $maxValue [2]) { delete; } if ($sphereXMax [0] < $minValue [0] && $sphereXMin [0] < $minValue [0]) { delete; } if ($sphereXMax [1] < $minValue [1] && $sphereXMin [1] < $minValue [1]) { delete; } if ($sphereXMax [2] < $minValue [2] && $sphereXMin [2] < $minValue [2]) { delete; } currentTime $YCounter; $YCounter ++; } while ($YCounter < size($sphereX)); ///////////////////////////////////////////////////////////////////////////// //3rd loop: Boolean operation loop //what it does: removes the area of intersection between the spheres and bounding box string $sphereZ [] = `ls-tr "SphereObject*"`; //list all sphere names in a string array polyBoolOp -op 2 BooleanBox $sphereZ[0]; //boolean the first sphere with the bounding box int $XCounter = 1; //the rest of boolean operations are in a loop do { string $polySurfX [] = `ls-sl "polySurface*"`; //name of the bounding box is changed to polysurface after first boolean operation polyBoolOp -op 2 $polySurfX[0] $sphereZ [$XCounter]; currentTime $XCounter; $XCounter ++; } while ($XCounter < size($sphereZ)); //Fin. ////////////////////////////////////////////////////////////////// string $renderObj [] = `ls-tr "polySurface*"`; int $Xval = size($renderObj); //create an ambient light; string $ambLight = `ambientLight -i .5`; move -r 0 0 20 $ambLight; // Create a spot light string $spotLight = `spotLight -ca 90 -d 1 -i 1 -p 100`; move -r 5 5 11 $spotLight; rotate -r -70 45 -30 $spotLight; // Make it Sciarc red!!! sets -name redMaterialGroup -renderable true -empty; shadingNode -name SciarcRed -asShader phong; setAttr -type double3 SciarcRed.color 1 0 0; surfaceShaderList -add redMaterialGroup SciarcRed; sets -e -forceElement redMaterialGroup $renderObj[$Xval-1]; //render image string $RenderImage = "Ping's Image"; setAttr defaultRenderGlobals.imageFilePrefix -type "string" $RenderImage; setAttr "defaultRenderGlobals.enableDefaultLight" 0; render -x 1912 -y 1080 persp; render -x 1912 -y 1080 top;