// =========================================================================== // 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: // texCalculateTexelDensity // // Description: // UV workflow function used for calculating the texel density value of // input faces // // Input Arguments // faces - String[] - Names of face components. // mapSize - Int - The texture size to scale against. // progressBar - Int - Update the progressBar // // Return Values: // Float - The calculated texel density value. // // 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 float texCalculateTexelDensity(string $faces[], int $mapSize, int $progressBar) { float $area3DSum = 0.0; float $area2DSum = 0.0; $faces = `filterExpand -ex false -sm 34 $faces`; // Begin progressBar global string $gMainProgressBar; if ($progressBar) progressBar -e -bp -max (size($faces)) $gMainProgressBar; float $area3D[] = `polyEvaluate -worldFaceArea $faces`; float $area2D[] = `polyEvaluate -uvFaceArea $faces`; for ($i = 0; $i < size($area3D); $i++){ // Break if cancelled by user if ($progressBar && `progressBar -q -isCancelled $gMainProgressBar`) { warning((uiRes("m_texCalculateTexelDensity.kUvEditorGetTexelDensityInteruptMsg"))); break; } $area3DSum += $area3D[$i]; $area2DSum += $area2D[$i]; // Update the progress window if ($progressBar) progressBar -e -s 1 $gMainProgressBar; } // End progressBar if ($progressBar) progressBar -e -endProgress $gMainProgressBar; return (`sqrt $area2DSum` / `sqrt $area3DSum`) * $mapSize; }