// =========================================================================== // 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. // =========================================================================== global proc polyGridUV(int $gridU, int $gridV, int $toCenters) { string $selection[] = `ls -sl`; string $compSelType = `getComponentMask`; string $selectedItems[]; $selectedItems = `filterExpand -ex true -sm 35`; if (size($selectedItems) == 0) { // If Convert Selection is ON, try to convert the current selection to uvs. int $val = `optionVar -q polyAutoConvertAction`; if ( 1 == $val ) { PolySelectConvert 4; $selectedItems = `filterExpand -ex true -sm 35`; } // Check if the set of uvs is still empty. if (size($selectedItems) == 0) { error((uiRes("m_polyGridUV.kNoUVsSelected"))); return; } } $gridU = `abs $gridU`; if ($gridU == 0) $gridU = 1; $gridV = `abs $gridV`; if ($gridV == 0) $gridV = 1; float $uv[2], $olduv[2]; float $igridU = 1.0 / (float)$gridU; float $igridV = 1.0 / (float)$gridV; string $uvStr; int $i=0; float $gridValue, $gridMin, $gridMax; while (size($selectedItems) > $i) { $uvStr = $selectedItems[$i]; $cmd = ("polyEditUV -q -u -v " + $uvStr + ";"); $uv = `eval $cmd`; $olduv = $uv; // Stretch to cell boundaries // $gridValue = $uv[0] / $igridU; $gridMin = `floor $gridValue`; $gridMin = $gridMin * $igridU; $gridMax = `ceil $gridValue`; $gridMax = $gridMax * $igridU; if (($uv[0]- $gridMin) < ($gridMax - $uv[0])) { $uv[0] = $gridMin; if ($toCenters != 0) $uv[0] = $uv[0] + ($igridU * 0.5); } else { $uv[0] = $gridMax; if ($toCenters != 0) $uv[0] = $uv[0] - ($igridU * 0.5); } $gridValue = $uv[1] / $igridV; $gridMin = `floor $gridValue`; $gridMin = $gridMin * $igridV; $gridMax = `ceil $gridValue`; $gridMax = $gridMax * $igridV; if (($uv[1]- $gridMin) == ($gridMax - $uv[1])) { $uv[1] = $gridMin; if ($toCenters != 0) $uv[1] = $uv[1] + ($igridV * 0.5); } else { if (($uv[1]- $gridMin) < ($gridMax - $uv[1])) { $uv[1] = $gridMin; if ($toCenters != 0) $uv[1] = $uv[1] + ($igridV * 0.5); } else { $uv[1] = $gridMax; if ($toCenters != 0) $uv[1] = $uv[1] - ($igridV * 0.5); } } //print ("old uv = " + $olduv[0] + " " + $olduv[1] + "\n"); //print ("new uv = " + $uv[0] + " " + $uv[1] + "\n"); polyEditUV -r off -u $uv[0] -v $uv[1] $uvStr; $i++; } //restore the original component mask setComponentMask($compSelType); //select the original selection select -replace $selection; }