trying to write a procedure thats groups the uvs shells into 3 seperate categories (Small, Medium, Large). but running into an issue where small uv shells doesnt get cast to the correct array $uvShellSmlList
. Im been spending the whole day looking and testing to see why its doing that.
Note this code only works on maya 2017.4 + since texGetShell is a new procedure after uvToolkit was added.
global proc float[] getUVShellArea(){<br> global string $shellList[];<br> $shellList =`texGetShells`;<br> float $shellArea[];<br> //print $shellList;<br> //print (size($shellList));<br> for ($i = 0; $i < `size($shellList)`; $i++)<br> {<br> <br> string $tempList[] = stringToStringArray($shellList[$i], " ");<br><br> // Calculate shell UV area<br> string $faceList[] = `polyListComponentConversion -fromUV -toFace $tempList`;<br> $faceAreas = `polyEvaluate -uvFaceArea $faceList`; // polyEvaluate returns a float[]<br> float $totalArea;<br> for ($faceArea in $faceAreas)<br> $totalArea += $faceArea;<br> $shellArea[$i] = $totalArea;<br> }<br> //print $shellArea;<br> return $shellArea;<br>}<br><br>// sum of total Area of all shells then divided by TotalShells to get Average area. function to group shells according the area. Split into 3 categories (Small,Mid,Large)<br>global proc string[] uvShellCompare(){<br> global string $shellList[];<br> float $shellArea[] = `getUVShellArea`;<br> float $sortedShellAreaList[] = `sort $shellArea`;<br> float $shellAreaMin = $sortedShellAreaList[0]; //gets the smallest shell <br> float $shellAreaMax = $sortedShellAreaList[size($shellArea)]; //gets the largest shell<br> float $shellAreaAvg;<br> float $shellAreaTotalSum;<br> string $uvShellSmlList[];<br> string $uvShellMidList[];<br> string $uvShellLarList[];<br> string $combShellList[];<br> for ($tmpshellAreas in $shellArea)<br> $shellAreaTotalSum += $tmpshellAreas;<br> <br> print $shellAreaTotalSum;<br> <br> //$shellAreaAvg = $shellAreaTotalSum / (size($shellArea)); // may not use this method in cases where theres a large disparity between shell sizes<br> //(len - 1) / 2 and len / 2 even/odd<br> if ((size ($sortedShellAreaList)) % 2 == 0){ <br> //even<br> $shellAreaAvg = $sortedShellAreaList[((size ($sortedShellAreaList)) - 1)/ 2];<br> }<br> //odd<br> if ((size ($sortedShellAreaList)) % 2 != 0){<br> $shellAreaAvg = $sortedShellAreaList[(size ($sortedShellAreaList))/ 2];<br> }<br> <br> print ("\n" + $shellAreaAvg);<br> <br> for ($i = 0; $i <= `size($shellArea)`; $i++)<br> {<br> if ($shellArea[$i] < $shellAreaAvg && (equivalentTol($shellArea[$i],$shellAreaAvg,0.03) == 0))<br> {<br> $uvShellSmlList[size($uvShellSmlList)] = $shellList[$i];<br> }<br> <br> if ($shellArea[$i] == $shellAreaAvg || (equivalentTol($shellArea[$i],$shellAreaAvg,0.03) == 1))<br> {<br> $uvShellMidList[size($uvShellMidList)] = $shellList[$i];<br> }<br> <br> if ($shellArea[$i] > $shellAreaAvg && (equivalentTol($shellArea[$i],$shellAreaAvg,0.01) == 0))<br> {<br> $uvShellLarList[size($uvShellLarList)] = $shellList[$i];<br> }<br> }<br> $combShellList[0] = stringArrayToString($uvShellSmlList, " ");<br> $combShellList[1] = stringArrayToString($uvShellMidList, " ");<br> $combShellList[2] = stringArrayToString($uvShellLarList, " ");<br> return $combShellList;<br><br>}<br><br>{<br> string $testList[] = `uvShellCompare`;<br> print "\n";<br> print "Small ";<br> print $testList[0];<br> print "\n";<br> print "Medium ";<br> print $testList[1];<br> print "\n";<br> print "Large ";<br> print $testList[2];<br> }
Replies
Then of course the rest below fails.
somehow error says $testList hasn't been declared. If you run it without this portion it will work and print the list accordingly.