// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // =========================================================================== // // Procedure Name: // texSortShellsByBounds // // Description: // UV workflow function used for sorting UV shells by their bounding box // sizes. Sorted by either U or V size, in descending order. Used by the // function distributeShells for distributing towards a target shell. // // Input Arguments // shellList - String[] - Empty list or a list of UV shells // direction - String - "Up", "Down", "Left" or "Right" // // Return Value: // String[] - The sorted UV shell list. // // Notes: // This script is part of the implementation of Nightshade UV Editor into // Autodesk Maya. This script is sourced by other scripts. Do not run it // directly. // // =========================================================================== global proc string[] texSortShellsByBounds(string $shellList[], string $direction) { // MEL has no dictionaries so we will use the bounds size as a prefix to // the shell string in order to perform sorting. float $boundingSize; string $prefixList[]; for ($i = 0; $i < `size($shellList)`; $i++) { float $uvBox[] = eval("polyEvaluate -boundingBoxComponent2d " + $shellList[$i]); // Calculate bounding box if (($direction == "right") || ($direction == "left")){ $boundingSize = ($uvBox[1] - $uvBox[0]); // U } else if (($direction == "up") || ($direction == "down")){ $boundingSize = ($uvBox[2] - $uvBox[3]); // V } $prefixList[$i] = ($boundingSize + " " + $shellList[$i]); } // Sort the list and remove prefix string $sortedList[] = `sort($prefixList)`; for ($i = 0; $i < size($sortedList); $i++){ string $regex = "[^ ]+ *"; $sortedList[$i] = `substitute $regex $sortedList[$i] ""`; } // Reverse and return $sortedList = texReverseStringArray($sortedList); return $sortedList; }