// =========================================================================== // 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. // =========================================================================== // // Creation Date: November 06, 2016 // // Procedure Name: // straightenUVEdges // // Description: // UV workflow function used for straightening a list of UV edge pairs // by grouping them into edge loops and aligning the UVs to the U/V axis. // // Input Arguments // axis - String - Straighten along axis... "U" or "V" // uvEdgeList - String[] - List of UV edges. The format for the // UV Edges is: "uvCoord1 uvCoord2" // // Return Value: // None. // // 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 texStraightenUVEdges(string $axis, string $uvEdgeList[]) { while (size($uvEdgeList) != 0) { // Clear lists and get coords from first edgeUV. Use as start for edge loop string $edgeLoop[], $removeList[], $scannedEdges[]; $stopLoop = false; string $uvEdgePair[] = stringToStringArray($uvEdgeList[0], " "); $edgeLoop[size($edgeLoop)] = $uvEdgePair[0]; $edgeLoop[size($edgeLoop)] = $uvEdgePair[1]; $removeList[size($removeList)] = $uvEdgeList[0]; // Find UV edges belonging to the same edge loop. // Keep running until no more components are added to the current loop ($edgeLoop) while ($stopLoop == false) { // Scan all uvEdges (tuples) and look for connections forming the $edgeLoop int $compAdded = false; for ($i = 0; $i < `size($uvEdgeList)`; $i++) { // Check if we've worked on the current tuple if (stringArrayContains($uvEdgeList[$i], $scannedEdges) == false) { // Check if the edgeUV exist in the $edgeLoop list string $singleEdgeUVs[] = stringToStringArray($uvEdgeList[$i], " "); if (stringArrayContains($singleEdgeUVs[0], $edgeLoop) || stringArrayContains($singleEdgeUVs[1], $edgeLoop)) { // Check every individual UV component of the current uvEdge for ($uv in $singleEdgeUVs) { if (stringArrayContains($uv, $edgeLoop) == false) { // Add components to lists $compAdded = true; $edgeLoop[size($edgeLoop)] = $uv; $scannedEdges[size($scannedEdges)] = $uvEdgeList[$i]; $removeList[size($removeList)] = $uvEdgeList[$i]; } } } } } // Entire $edgeLoop gathered. Stop the while-loop running the for-loop scanner if ($compAdded == false){ $stopLoop = true; } } // Remove processed edgeUVs (tuples) for ($item in $removeList){ if (stringArrayContains($item, $uvEdgeList)){ int $index = stringArrayFind($item, 0, $uvEdgeList); string $itemArray[] = stringToStringArray($item, " "); stringArrayRemoveAtIndex($index, $uvEdgeList); } } // Select the $edgeLoop and straighten it select $edgeLoop; if ($axis == "U"){ alignUV("avgV"); } else { alignUV("avgU"); } } }