// =========================================================================== // 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. // =========================================================================== // // Description: // Script to compute tessellation settings. // // Procedure Name: // tessellationSetup // // Description: // Procedure to setup the tessellation. // global proc tessellationSetup( int $surfacesOption, int $typeOption, int $framesOption, int $cameraOption, int $curvatureOption, float $uDivisionOption, float $vDivisionOption, int $uModeOption, int $uNumberOption, int $vModeOption, int $vNumberOption, int $useChordHeightOption, float $chordHeightOption, int $useChordHeightRatioOption, float $chordHeightRatioOption, int $useMinScreenOption, float $minScreenOption, int $useSmoothEdgeOption, float $smoothEdgeOption, int $edgeSwapOption) { string $surfaces[]; if ($surfacesOption == 0) { // Selected surfaces string $selection[] = `ls -selection`; for ($item in $selection) { // Get all the list of all descendents below the selected // item. The list doesn't include the root item, so we // append it. string $descendents[] = `listRelatives -allDescendents -path $item`; $descendents[size($descendents)] = $item; for ($path in $descendents) { if (`objectType -isType nurbsSurface $path`) { // Filter out intermediate objects if (! `getAttr ($path+".intermediateObject")`) { $surfaces[size($surfaces)] = $path; } } } } if (size($surfaces) == 0 ) { error (uiRes("m_tessellationSetup.kNoNURBSSelected")); } } else if ($surfacesOption == 1) { // All surfaces $lsSurfaces = `ls -type nurbsSurface`; for ($item in $lsSurfaces) { // Filter out the intermediate objects if (! `getAttr ($item + ".intermediateObject")`) { $surfaces[size($surfaces)] = $item; } } if (size($surfaces) == 0 ) { error (uiRes("m_tessellationSetup.kNoNURBS")); } } if ($typeOption == 0) { // Optimize float $start, $end, $by; if ($framesOption == 0) { // Render globals $start = `getAttr "defaultRenderGlobals.startFrame"`; $end = `getAttr "defaultRenderGlobals.endFrame"`; $by = `getAttr "defaultRenderGlobals.byFrameStep"`; } else if ($framesOption == 1) { // Time slider $start = `playbackOptions -q -animationStartTime`; $end = `playbackOptions -q -animationEndTime`; $by = `playbackOptions -q -by`; } else if ($framesOption == 2) { // Current time $start = `currentTime -q`; $end = $start; $by = `playbackOptions -q -by`; } string $camera = ""; if ($cameraOption == 0) { // All renderable cameras $camera = "-allCameras"; } else if ($cameraOption == 1) { // Active view string $panel = `getPanel -withFocus`; if (`modelPanel -exists $panel`) { $camera = `modelPanel -q -camera $panel`; } if ($camera == "") { error (uiRes("m_tessellationSetup.kActiveView")); } } for ($surface in $surfaces) { setAttr ($surface+".explicitTessellationAttributes") false; setAttr ($surface+".curvatureTolerance") $curvatureOption; setAttr ($surface+".uDivisionsFactor") $uDivisionOption; setAttr ($surface+".vDivisionsFactor") $vDivisionOption; setAttr ($surface+".smoothEdge") $useSmoothEdgeOption; setAttr ($surface+".smoothEdgeRatio") $smoothEdgeOption; setAttr ($surface+".edgeSwap") $edgeSwapOption; setAttr ($surface+".modeU") $uModeOption; // need to reset the feature based displacement mapping to // a nice default because of the auto-tessellation. int $initSamples = getAttr ($surface+".initialSampleRate"); if ($initSamples > 6) { setAttr ($surface+".initialSampleRate") 6; setAttr ($surface+".extraSampleRate") 5; } } runupTessellation $camera $start $end $by $surfaces; } else if ($typeOption == 1) { // Basic for ($surface in $surfaces) { setAttr ($surface+".explicitTessellationAttributes") false; setAttr ($surface+".curvatureTolerance") $curvatureOption; setAttr ($surface+".uDivisionsFactor") $uDivisionOption; setAttr ($surface+".vDivisionsFactor") $vDivisionOption; setAttr ($surface+".smoothEdge") $useSmoothEdgeOption; setAttr ($surface+".smoothEdgeRatio") $smoothEdgeOption; setAttr ($surface+".edgeSwap") $edgeSwapOption; setAttr ($surface+".modeU") $uModeOption; } } else if ($typeOption == 2) { // Advanced for ($surface in $surfaces) { setAttr ($surface+".explicitTessellationAttributes") true; setAttr ($surface+".modeU") $uModeOption; setAttr ($surface+".numberU") $uNumberOption; setAttr ($surface+".modeV") $vModeOption; setAttr ($surface+".numberV") $vNumberOption; setAttr ($surface+".useChordHeight") $useChordHeightOption; setAttr ($surface+".chordHeight") $chordHeightOption; setAttr ($surface+".useChordHeightRatio") $useChordHeightRatioOption; setAttr ($surface+".chordHeightRatio") $chordHeightRatioOption; setAttr ($surface+".useMinScreen") $useMinScreenOption; setAttr ($surface+".minScreen") $minScreenOption; setAttr ($surface+".smoothEdge") $useSmoothEdgeOption; setAttr ($surface+".smoothEdgeRatio") $smoothEdgeOption; setAttr ($surface+".edgeSwap") $edgeSwapOption; } } if (size($surfaces) == 1) { print((uiRes("m_tessellationSetup.kOneSurface"))); } else if (size($surfaces) > 1) { string $message = (uiRes("m_tessellationSetup.kSurfaces")); string $num = size($surfaces); $message = `format -stringArg $num $message`; print($message); } }