/* Title: crowdGen.mel Name: Dan McGrath Date: currentVersion(12/18/02) Version: 2.30 Description: This is a Mel script that will import multiple files and then randomly place them on the X and Z axis. For the sake of speed I have limited the import structure to only a ten(10) file maximum. Change it at your own risk. Input: The GUI created will need you to specify the amount of files to be imported. There are seperate check boxes for single and multiple file types, as well as a # box for a numerical value, up to Ten(10) Maximum. There will also need to be a designation of the folder that the script is going to be look for it's files to import. This can be any folder you want it to be, but you must only have objects that can be brought into your scene. I suggest ONLY *.mb files. This is the default I have set. Return: You should expect Maya to import and place up to ten(10) ".mb" files into your current scene. I recommend simple objects, for speed purposes (like rocks, buildings, and low-poly characters without complicated texturing). Extra Notes: Although I made this script using v4.02, it should work with most other versions of Maya without problem. Please understand that your use of this script will in no way make me liable for any problems or damages that occur to you in any way. USER ASSUMES ALL RESPONSIBILITY IN THE USE AND/OR MODIFICATION OF THIS SCRIPT. Any questions about this script can be directied towards me at: danmcgrath@spatiallight.net or try CGTalk.com, there is a great forum for Maya (and other) related questions. */ //You can type in crowdGenWin in the command line and this will //remake the following window. You only need to source it once. global proc crowdGenWin () { //I start with the making of the window itself. //All Global Procedures are listed at the end of //this script. To keep things as clean as possible. //------------------------------------------------------------------- if (`window -exists crowdGenWin`) { deleteUI crowdGenWin; } window -width 300 -height 200 -title "Crowd Generator ---------- V 2.30" -maximizeButton false crowdGenWin; //-------------------------------------------------------------------- //Layouts and Buttons scrollLayout scrollLayout1; columnLayout colSet1; separator -height 10 -style "none"; rowLayout -numberOfColumns 3 -columnWidth3 80 120 50 rowSet0; text " "; text -label "Choose the # to Import" -align "center"; text " "; setParent colSet1; columnLayout colSet0; separator -height 20 -style "none"; rowLayout -numberOfColumns 4 -columnWidth4 50 70 70 70 rowSet1; //Create a couple of check boxes text " "; checkBox -editable true -label "Single" -onCommand singleImpOn -offCommand singleImpOff checkBox1; text " "; checkBox -editable true -label "Group" -onCommand groupImpOn -offCommand groupImpOff checkBox2; setParent colSet1; //The script will query this int field if the group //box is checked rowLayout -numberOfColumns 3 -columnWidth3 140 65 40 rowSet2; text " "; text "# of Models "; intField -width 23 -minValue 1 -maxValue 10 -enable 0 -step 1 -v 1 importNum; setParent colSet1; rowColumnLayout -numberOfColumns 1 -columnWidth 1 300 rowColSet1; separator -height 10 -style "double"; setParent colSet1; rowLayout -numberOfColumns 1 -columnWidth1 100 rowSet5; text " "; setParent colSet1; rowLayout -numberOfColumns 3 -columnWidth3 50 130 30 -columnAttach3 "left" "left" "left" -columnOffset3 5 5 5 -adjustableColumn 2; text -label "Directory :"; textField -width 200 -ann "Directory of files." -en 1 -tx "Select the Folder to source from." textField_Directory; symbolButton -image "navButtonBrowse.xpm" -command ("srcFolder textField_Directory dir"); setParent colSet1; separator -height 20 -style "none"; rowLayout -numberOfColumns 3 -columnWidth3 45 200 60 textCol2; text " "; text -label "Set the maximum and minimum parameters" -align "center"; text " "; setParent colSet1; rowLayout -numberOfColumns 3 -columnWidth3 75 150 60 textCol3; text " "; text -label "that the randomizer will use." -align "center"; text " "; setParent colSet1; rowLayout -numberOfColumns 3 -columnWidth3 75 20 150 textCol4; text " "; text "Or"; checkBox -label " Skip the Parameters ?" -value 0 -onCommand skipAll -offCommand dontSkip checkBox3; setParent colSet1; columnLayout textCol5; text " Checking Box Will Max ALL Fields Below!"; setParent colSet1; separator -height 20 -style "none"; rowLayout -numberOfColumns 6 -columnWidth6 10 70 50 5 50 70 fieldLayouts; columnLayout emptyColSet1; text " "; text " "; text " "; text " "; text " "; text " "; text " "; text " "; setParent fieldLayouts; columnLayout textColSet1; text " "; separator -height 2 -style "none"; text "X Trans (25)"; separator -height 6 -style "none"; text "Z Trans (25)"; separator -height 22 -style "none"; text "Y Rotate(359)"; separator -height 22 -style "none"; text "X Scale (2)"; separator -height 6 -style "none"; text "Y Scale (2)"; separator -height 8 -style "none"; text "Z Scale (2)"; setParent fieldLayouts; columnLayout floatColSet1; text " Maximum"; floatField -minValue 0.00 -maxValue 25.00 -precision 2 -value 0 xTrans; floatField -minValue 0.00 -maxValue 25.00 -precision 2 -value 0 zTrans; text " "; floatField -minValue 0.00 -maxValue 359.00 -precision 2 -value 0 yRotate; text " "; floatField -minValue 1 -maxValue 2.00 -precision 2 -value 1 xScale; floatField -minValue 1 -maxValue 2.00 -precision 2 -value 1 yScale; floatField -minValue 1 -maxValue 2.00 -precision 2 -value 1 zScale; setParent fieldLayouts; columnLayout emptyColSet2; text " "; text " "; text " "; text " "; text " "; text " "; text " "; text " "; setParent fieldLayouts; columnLayout floatColSet2; text " Minimum"; floatField -minValue -25.00 -maxValue 0.00 -precision 2 -value 0 negxTrans; floatField -minValue -25.00 -maxValue 0.00 -precision 2 -value 0 negzTrans; text " "; floatField -minValue -359.00 -maxValue -0.00 -precision 2 -value 0 negyRotate; text " "; floatField -minValue .75 -maxValue 1.00 -precision 2 -value 1 negxScale; floatField -minValue .75 -maxValue 1.00 -precision 2 -value 1 negyScale; floatField -minValue .75 -maxValue 1.00 -precision 2 -value 1 negzScale; setParent fieldLayouts; columnLayout textColSet2; text " "; separator -height 2 -style "none"; text " X Trans (-25)"; separator -height 6 -style "none"; text " Z Trans (-25)"; separator -height 22 -style "none"; text " Y Rotate(-359)"; separator -height 22 -style "none"; text " X Scale (.75)"; separator -height 6 -style "none"; text " Y Scale (.75)"; separator -height 8 -style "none"; text " Z Scale (.75)"; setParent fieldLayouts; setParent colSet1; //Reset Values Button separator -h 3 -st "none"; rowLayout -numberOfColumns 3 -columnWidth3 95 80 50 resetRow; text " "; button -width 80 -height 20 -label "Reset Values?" -command resetValues resetButton; text " "; setParent colSet1; separator -height 10 -style "none"; //This is the button that actually sources all the above inputs //And then runs the Random Import Generator. rowLayout -numberOfColumns 3 -columnWidth3 60 150 50 rowSet15; text " "; button -width 150 -height 40 -label " Run Program" -command runGenerator runButton; text " "; setParent colSet1; setParent scrollLayout1; showWindow crowdGenWin; } //End of global proc crowdGenWin; //---------------- //All global procs //---------------- //This is the procedure for checking the "Single" check box global proc singleImpOn () { checkBox -edit -value 0 checkBox2; intField -edit -enable 0 -v 1 importNum; } global proc singleImpOff () { checkBox -edit -value 0 checkBox2; intField -edit -enable 0 importNum; } //this is the procedure for checking the "Group" check box global proc groupImpOn () { checkBox -edit -value 0 checkBox1; intField -edit -enable 1 importNum; } global proc groupImpOff () { checkBox -edit -value 0 checkBox1; intField -edit -enable 0 importNum; } //this is the procedure for checking the "Skip Parameters" check box global proc skipAll () { floatField -e -value 20 -enable false xTrans; floatField -e -value 20 -enable false zTrans; floatField -e -value 359 -enable false yRotate; floatField -e -value 2 -enable false xScale; floatField -e -value 2 -enable false yScale; floatField -e -value 2 -enable false zScale; //------------------------------------------- floatField -e -value -25 -enable false negxTrans; floatField -e -value -25 -enable false negzTrans; floatField -e -value -359 -enable false negyRotate; floatField -e -value .75 -enable false negxScale; floatField -e -value .75 -enable false negyScale; floatField -e -value .75 -enable false negzScale; } global proc dontSkip () { floatField -e -enable true xTrans; floatField -e -enable true zTrans; floatField -e -enable true yRotate; floatField -e -enable true xScale; floatField -e -enable true yScale; floatField -e -enable true zScale; //---------------------------------------- floatField -e -enable true negxTrans; floatField -e -enable true negzTrans; floatField -e -enable true negyRotate; floatField -e -enable true negxScale; floatField -e -enable true negyScale; floatField -e -enable true negzScale; } //the source folder procedure for "Directory" folder button global proc srcFolder (string $textField, string $type) { string $dirLoc = `fileBrowser ("loadNewPath \"" + $textField +"\" ") Directory txt 4`; } global proc string loadNewPath (string $textField, string $newPath, string $type) { textField -e -tx $newPath $textField; return $newPath; } //The Reset Values Button Procedure global proc resetValues () { floatField -e -value 0 xTrans; floatField -e -value 0 zTrans; floatField -e -value 0 yRotate; floatField -e -value 1 xScale; floatField -e -value 1 yScale; floatField -e -value 1 zScale; //------------------------------------------- floatField -e -value 0 negxTrans; floatField -e -value 0 negzTrans; floatField -e -value 0 negyRotate; floatField -e -value 1 negxScale; floatField -e -value 1 negyScale; floatField -e -value 1 negzScale; } global proc string readDirectory() { //get the text line from the GUI. string $dir = `textField -q -tx textField_Directory`; if (`substring $dir (size($dir)) (size($dir))` != "/") { $dir = ($dir + "/"); } string $contents[] = `getFileList -fld $dir`; string $allInDir[]; //clear($allInDir); int $howMany = 0; for ($i = 0; $i < size($contents); $i++) { if (`gmatch $contents[$i] "*.mb"`) { $allInDir[$howMany] = $contents[$i]; $howMany++; } } int $which = rand($howMany-1); return $allInDir[$which]; } //the "Run Program" procedure button global proc impAndRand () { string $file = `readDirectory`; file -i $file; } global proc runGenerator () { float $posTX = `floatField -q -v xTrans`; float $posTZ = `floatField -q -v zTrans`; float $negTX = `floatField -q -v negxTrans`; float $negTZ = `floatField -q -v negzTrans`; float $posRY = `floatField -q -v yRotate`; float $negRY = `floatField -q -v negyRotate`; float $posSX = `floatField -q -v xScale`; float $posSY = `floatField -q -v yScale`; float $posSZ = `floatField -q -v zScale`; float $negSX = `floatField -q -v negxScale`; float $negSY = `floatField -q -v negyScale`; float $negSZ = `floatField -q -v negzScale`; int $files; float $xPos, $zPos; float $xScale, $yScale, $zScale; float $yRot; for ($files = 1; $files <= `intField -q -v importNum`; $files ++) { $xPos = rand($posTX, $negTX); $zPos = rand($posTZ, $negTZ); $yRot = rand($posRY, $negRY); $xScale = rand($posSX, $negSX); $yScale = rand($posSY, $negSY); $zScale = rand($negSX, $negSZ); impAndRand; move $xPos 0 $zPos; rotate 0 $yRot 0; scale $xScale $yScale $zScale; } } //and launch the window crowdGenWin;