proc createGroups() { //create empty group nodes group -em -name Trees; group -em -name Decals; group -em -name Lamps; group -em -name GroundPlanes; group -em -name Roads_Sidewalks; group -em -name Structures; group -em -name Filler; } proc startProgram() { //declare variables int $treeCount = 0; int $decalCount = 0; int $lampCount = 0; //select all meshes string $type[] = `lsType("mesh")`; //loop through each object and select all of its verts for($i = 0; $i < size($type); $i++) { //declare vaiable for storing the verts in an array int $vertC[]; if($type[$i] != "") { select -cl; select -r $type[$i]; //print($type[$i] + "\n"); int $tempVert[] = `polyEvaluate -v $type[$i]`; //print($tempVert[0] + "\n"); //if the vert count is 1662 then it is a tree if($tempVert[0] == 1662 || $tempVert[0] == 3180) { $treeCount++; select -cl; select -r $type[$i]; string $parentNam[] = `listRelatives -p $type[$i]`; string $treeNam = `rename $parentNam[0] ("Tree00" + $treeCount)`; select -cl; select -r $treeNam; select -add Trees; parent; } else if($tempVert[0] == 6 || $tempVert[0] == 4) { $decalCount++; select -cl; select -r $type[$i]; string $parentNam[] = `listRelatives -p $type[$i]`; string $decalNam = `rename $parentNam[0] ("Decal00" + $decalCount)`; select -cl; select -r $decalNam; select -add Decals; parent; } else if($tempVert[0] == 1044) { $lampCount++; select -cl; select -r $type[$i]; string $parentNam[] = `listRelatives -p $type[$i]`; string $lampNam = `rename $parentNam[0] ("Lamp00" + $lampCount)`; select -cl; select -r $lampNam; select -add Lamps; parent; } else { //subtract 1 from the number of verts to get the array index $vertC[$i] = $tempVert[0]; int $vertNum = $tempVert[0] - 1; //select all the verts select -r ( $type[$i] + ".vtx[0:" + $vertNum + "]" ); //call the position proc and give the vertex number to the proc getHeight($type[$i], $vertNum); } } } } proc selection() { string $sel[] = `ls -sl`; int $vert[] = `polyEvaluate -v $sel[0]`; int $vertN = $vert[0] - 1; getHeight($sel[0], $vertN); } //create the vert positions here in this procedure proc getHeight(string $nam, int $vert) { //print($vert + "\n"); print("Now working on:" + $nam + "\n"); //declare variables float $x[]; float $y[]; float $z[]; int $planeCount = 0; int $groundCount = 0; int $StructureCount = 0; int $fillerCount = 0; //begin loop for($i = 0; $i < $vert; $i++) { //use the vert number to iterate throught the verts int $curVert = $vert; //run the xform command on the vert in the loop order vector $vertPos = `xform -q -t -ws ($nam + ".vtx[" + $curVert + "]")`; int $curFaces[] = `polyEvaluate -f $nam`; //store the individual values into floats $x[$i] = $vertPos.x; $y[$i] = $vertPos.y; $z[$i] = $vertPos.z; //print($x[$i] + " " + $y[$i] + " " + $z[$i] + "\n"); //subract one from the vert number $vert--; } //sort the vlaues in the floats to get a list from smallest to largest //$x = `sort $x`; $y = `sort $y`; //$z = `sort $z`; //print(size($y) + "\n"); int $ySize = `size($y)`; //print($ySize - 1 + "\n"); //print($y[0] + " " + $y[$ySize - 1] + "\n"); //compare the first and last values in the y array float $heightSub = ($y[0] - $y[$ySize - 1]); float $heightAdd = ($y[0] + $y[$ySize - 1]); //print($heightSub + "\n"); //print($heightAdd + "\n"); //find the area of the object selectd to use as a rule int $area = `polyFaceArea($nam)`; //grp the object selected based off of its height value and its total area if($heightSub == 0 && $heightAdd < 0) { if($area < 1000) { //print("I am a ground plane!!" + "\n"); $planeCount++; select -cl; select -r $nam; string $parentNam[] = `listRelatives -p $nam`; string $planeNam = `rename $parentNam[0] ("Plane00" + $planeCount)`; select -cl; select -r $planeNam; select -add GroundPlanes; parent; } else if($area > 1000) { //print("I am a ground plane!!" + "\n"); $fillerCount++; select -cl; select -r $nam; string $parentNam[] = `listRelatives -p $nam`; string $fillerNam = `rename $parentNam[0] ("filler00" + $fillerCount)`; select -cl; select -r $fillerNam; select -add Filler; parent; } } else if($heightSub < 0 && $heightAdd < 0) { //print("I am the ground!!" + "\n"); $groundCount++; select -cl; select -r $nam; string $parentNam[] = `listRelatives -p $nam`; string $groundNam = `rename $parentNam[0] ("Ground00" + $groundCount)`; select -cl; select -r $groundNam; select -add Roads_Sidewalks; parent; } else if($heightAdd > 0) { //print("I am a structure!!" + "\n"); $StructureCount++; select -cl; select -r $nam; string $parentNam[] = `listRelatives -p $nam`; string $structureNam = `rename $parentNam[0] ("Structure00" + $StructureCount)`; select -cl; select -r $structureNam; select -add Structures; parent; } else { print("I don't know what I am!!" + "\n"); } //print($vert + "\n"); } global proc float polyFaceArea(string $name) { select -r $name; string $list[] = `ls -sl`; float $totalArea = 0; for ($origFace in $list) { string $sel = $origFace; string $tokens[]; int $num = `tokenize $sel "." $tokens`; string $object = $tokens[0]; polyTriangulate -ch 1 $sel; string $listOfFaces[] =`ls -sl -flatten`; for ($face in $listOfFaces) { if ( size(`match "\.f\[[0-9]+\]$" $face`) > 0 ) { string $listOfVertsToToke[] = `polyInfo -fv $face`; tokenize $listOfVertsToToke[0] " " $tokens; float $x[],$y[],$z[]; for ($i = 2; $i<5;$i++) { string $vertName = ($object+".vtx["+$tokens[$i]+"]"); float $loc[] = `xform -q -ws -t $vertName`; $x[$i-2] = $loc[0]; $y[$i-2] = $loc[1]; $z[$i-2] = $loc[2]; } float $a = `distanceBetween {$x[0],$y[0],$z[0]} {$x[1],$y[1],$z[1]}`; float $b = `distanceBetween {$x[1],$y[1],$z[1]} {$x[2],$y[2],$z[2]}`; float $c = `distanceBetween {$x[2],$y[2],$z[2]} {$x[0],$y[0],$z[0]}`; float $area = .25* sqrt ( ($a+$b+$c) * ($b+$c-$a) *($c+$a-$b)*($a+$b-$c) ); $totalArea += $area; } } undo; } //select -cl; //print ("\nTotal Area = "+$totalArea+"\n"); return $totalArea; } global proc float distanceBetween(float $loc1[], float $loc2[]) { float $a = `pow ($loc2[0] - $loc1[0]) 2`; float $b = `pow ($loc2[1] - $loc1[1]) 2`; float $c = `pow ($loc2[2] - $loc1[2]) 2`; float $distance = `sqrt ( $a+$b+$c )`; return $distance; } //create a proc to merge the selected meshes and clean up the geo proc combine() { string $selA[] = `ls -sl`; //combine all the meshes string $polyCombineMesh = `polyPerformAction polyUnite o 0`; //Delete the history from the combine string $selB[] = `ls -sl`; select -cl; select -r $selB[0]; DeleteHistory; find out how many verts are in the new mesh int $meshVerts[] = `polyEvaluate -v`; int $meshFace[] = `polyEvaluate -f`; int $vertCount = $meshVerts[0] - 1; int $faceCount = $meshFace[0] - 1; //concatenate the name of the mesh with the amoutn of verts string $curMeshVert = ($selB[0] + ".vtx[0:" + $vertCount + "]"); select -cl; select -r $curMeshVert; //merge all the verts within the tolerance string $pMerge[] = `polyMergeVertex -d 0.01 -am 1 -ch 1 $curMeshVert`; select -r $selB[0]; DeleteHistory; UvProj($selB[0], $faceCount ); } proc UvProj(string $obj, int $faces) { string $curObj = ($obj + ".f[0:" + $faces + "]"); polyAutoProjection -lm 0 -pb 0 -ibd 1 -cm 0 -l 2 -sc 1 -o 1 -p 3 -ps 0.2 -ws 1 $curObj; select -cl; select -r $obj; unfold -i 5000 -ss 0 -gb 0 -gmb 0.6694 -pub 0 -ps 0 -oa 0 -us off; } proc manRename() { $sel = `ls -sl`; string $menu = `promptDialog -message "Enter new name:" -button "Ok" -button "Cancel" -defaultButton "Ok" -cancelButton "Cancel" -dismissString "Cancel"`; if (`size $sel` < 0 || $menu == "Ok" ) { $newName = `promptDialog -q`; for ($obj in $sel) { rename $obj $newName; } } } if(`window -exists myTestWin`) { deleteUI myTestWin; } string $win = `window -wh 200 200 myTestWin`; columnLayout -adj 1; button -l "Run Code" -c "startProgram" testBut; button -l "Create Groups" -c "createGroups" groupBut; button -l "Find Area" -c "polyFaceArea" areaBut; button -l "Merge and Clean" -c "combine" mergeBut; button -l "Manual Rename" -c "manRename" renameBut; showWindow $win;