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
- <div>//derived from texSortShellsByBounds, uses same idea of combining the shellarea into the shelllist<br><br>global proc string[] sortShellsByUVArea(string $shellList[]){<br> global string $shellArea[];<br> string $prefixList[];<br><br> for ($i = 0; $i < `size($shellList)`; $i++)<br> {<br> string $temp[] = stringToStringArray($shellList[$i], " ");<br><br> string $faceList[] = `polyListComponentConversion -fromUV -toFace $temp`;<br> $faceAreas = `polyEvaluate -uvFaceArea $faceList`; // polyEvaluate returns a float[]<br> float $area;<br> for ($faceArea in $faceAreas)<br> $area += $faceArea;<br> $shellArea[$i] = $area;<br> $prefixList[$i] = ($shellArea[$i] + "%" + $shellList[$i]);<br> }<br><br>string $sortedShellList[];<br><br>$sortedShellList = `sort($prefixList)`;<br><br> return $sortedShellList;<br>}<br><br>global proc string[] uvShellCompare(){<br><br> float $lowNum;<br> float $midNum;<br> string $rawShellList[] = `texGetShells` ;<br> string $shellSmlList[];<br> string $shellMidList[];<br> string $shellLarList[];<br> //float $highNum; no need anymore<br> float $finalShellArea[];<br> string $finalShellList[];<br> string $combShellList[];<br> string $sortedShellList[] = sortShellsByUVArea($rawShellList); //call procedure<br> <br> for ($i = 0; $i < size($sortedShellList); $i++)<br> {<br> string $regex = "[^ ]+ *";<br> string $buffer[];<br> $finalShellList[$i] = `substitute $regex $sortedShellList[$i] ""`;<br> tokenize($sortedShellList[$i], "%", $buffer);<br> $finalShellArea[$i] = `float($buffer[0])`;<br> }<br> <br> $lowNum = $finalShellArea[(int(size($finalShellArea)* 1.0 / 3.0)];<br> $midNum = $finalShellArea[(int(size($finalShellArea)* 2.0 / 3.0)];<br> <br> for ($i = 0; $i < size($finalShellArea); $i++)<br> {<br> if ($finalShellArea <= lowNum){<br> $shellSmlList[size($shellSmlList)] = $finalShellList[$i];<br> }<br> if ($finalShellArea <= midNum){<br> $shellMidList[size($shellMidList)] = $finalShellList[$i];<br> }<br> else{<br> $shellLarList[size($shellLarList)] = $finalShellList[$i];<br> }<br> }<br> <br> $combShellList[0] = stringArrayToString($shellSmlList, " ");<br> $combShellList[1] = stringArrayToString($shellMidList, " ");<br> $combShellList[2] = stringArrayToString($shellLarList, " ");<br> return $combShellList;<br>}<br><br>uvShellCompare;<br><br></div><div><br></div>
having syntax error on this line- $finalShellArea[$i] = `float($buffer[0])`;
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.