// =========================================================================== // 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: October 27, 2016 // // Procedure Name: // texSetTexelDensity // // Description: // UV workflow function used for scaling shells so that they match a // specific texel density value. // // Input Arguments // density - Float - Density to scale // mapSize - Int - The texture size to scale against. // // Return Values: // None. // // Notes: // This script is part of the implementation of Nightshade UV Editor into // Autodesk Maya. // // =========================================================================== global proc texSetTexelDensity(float $density, int $mapSize) { // Validate selection and store it texCheckSelection("any"); string $originalSel[] = `ls -sl`; select `polyListComponentConversion -toUV`; string $shellList[] = texGetShells(); // Begin progressBar global string $gMainProgressBar; progressBar -e -bp -max (size($shellList)*2) $gMainProgressBar; for ($shell in $shellList) { // Update the progress window progressBar -e -s 1 $gMainProgressBar; // Break if cancelled by user if (`progressBar -q -isCancelled $gMainProgressBar`) { warning((uiRes("m_texSetTexelDensity.kUvEditorSetTexelDensityInteruptMsg"))); break; } string $uvs[] = stringToStringArray($shell, " "); string $selectionFaces[] = `polyListComponentConversion -toFace $uvs`; $selectionFaces = `filterExpand -ex false -sm 34 $selectionFaces`; float $currentDensity = texCalculateTexelDensity($selectionFaces, $mapSize, false); float $scale = ($density/$currentDensity); float $bc[] = `polyEvaluate -bc2 $uvs`; float $pU = ($bc[0] + $bc[1])/2; float $pV = ($bc[2] + $bc[3])/2; polyEditUV -pu $pU -pv $pV -su $scale -sv $scale $uvs; // Update the progress window progressBar -e -s 1 $gMainProgressBar; } // End progressBar progressBar -e -endProgress $gMainProgressBar; select $originalSel; }