// =========================================================================== // 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: // texGetTargetShell // // Description: // UV workflow function used for determining the target shell when // distributing UV shells towards a target with distributeShells(). The // target is the shell at the maximum or minimum U or V position and it // is acquired by a proximity scan. // // Input Arguments // shellList - String[] - Empty list or a list of UV shells. // titleOverride - String - Progress window title. // // 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 string[] texGetTargetShell(string $shellList[]) { int $shellNum = size($shellList); if($shellNum < 3) return {}; // Calculate center point and dimensions for the entire selection float $minU = 999999; float $maxU = -999999; float $minV = 999999; float $maxV = -999999; float $centerUL[]; float $centerVL[]; for($i = 0; $i < $shellNum; $i++) { float $uvBox[] = eval("polyEvaluate -boundingBoxComponent2d " + $shellList[$i]); float $centerU = 0.5 * ( $uvBox[0] + $uvBox[1] ); float $centerV = 0.5 * ( $uvBox[2] + $uvBox[3] ); $centerUL[size($centerUL)] = $centerU; $centerVL[size($centerVL)] = $centerV; $minU = $centerU<$minU?$centerU:$minU; $maxU = $centerU>$maxU?$centerU:$maxU; $minV = $centerV<$minV?$centerV:$minV; $maxV = $centerV>$maxV?$centerV:$maxV; } float $centerU = 0.5 * ( $minU + $maxU ); float $centerV = 0.5 * ( $minV + $maxV ); // Get direction axis int $directionAxis; float $totalDistance; if (($maxU-$minU) >= ($maxV-$minV)){ $directionAxis = 0; $totalDistance = ($maxU-$minU); } else { $directionAxis = 1; $totalDistance = ($maxV-$minV); } int $listA[], $listB[]; // Sort shells into two lists. for($i = 0; $i < $shellNum; $i++) { // Add shell to list if ($directionAxis == 0) { if ($centerUL[$i] < $centerU) $listA[size($listA)] = $i; else $listB[size($listB)] = $i; } else { if ($centerVL[$i] < $centerV) $listA[size($listA)] = $i; else $listB[size($listB)] = $i; } } int $direction; string $targetShell; int $targetShellIndex; // Get direction and target shell if (`size($listA)` == 1 && `size($listB)` > 1){ $targetShellIndex = $listA[0]; $targetShell = $shellList[$targetShellIndex]; } else if (`size($listB)` == 1 && `size($listA)` > 1){ $targetShellIndex = $listB[0]; $targetShell = $shellList[$targetShellIndex]; } else return {}; // Add shell to list if ($directionAxis == 0) { float $center = $centerUL[$targetShellIndex]; if ($center < $centerU) $direction = 2; else $direction = 1; } else { float $center = $centerVL[$targetShellIndex]; if ($center < $centerV) $direction = 4; else $direction = 3; } float $distance = $totalDistance / ($shellNum - 1); // Invert dist if we are distributing towards bottom or the left if (($direction == 2) || ($direction == 4)) $distance = -$distance; // Place the $targetShell on position [0] string $temp[]; $temp[0] = $targetShell; $shellList = stringArrayRemove($temp, $shellList); // Doesn't work!!!! stringArrayInsertAtIndex(0, $shellList, $targetShell); // Construct return string array string $returnArray[]; stringArrayInsertAtIndex(0, $returnArray, $directionAxis); stringArrayInsertAtIndex(0, $returnArray, $distance); string $shellListString = stringArrayToString($shellList, "%"); stringArrayInsertAtIndex(0, $returnArray, $shellListString); stringArrayInsertAtIndex(0, $returnArray, $targetShell); return $returnArray; }