// =========================================================================== // 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: 4 April 1997 // // Procedure Name: // performSubdAutoProj // // Description: // // // Input Arguments: // $option : Whether to set the options to default values. // Return Value: // command string iff $option==2 // // // Initialize optionVars for subdAutoProj: // Color, Texture, Vertex // proc setOptionVars ( string $prefix, int $forceFactorySettings, string $vars[] ) { string $varName; // Must match $vars int $intValues[]= { 3, 1, 1, 2, 0 }; for ( $i = size($vars) ; $i-- ; ) { $varName = ($prefix + $vars[$i]); if ($forceFactorySettings || !`optionVar -exists $varName`) optionVar -intValue $varName $intValues[$i]; } $varName = ($prefix + "eg"); if ($forceFactorySettings || !`optionVar -exists $varName`) optionVar -floatValue $varName .2; /* // Also add the map name $varName = ($prefix + "uvSetName"); if ($forceFactorySettings || !`optionVar -exists $varName`) optionVar -stringValue $varName "uvSet1"; */ } global proc performSubdAutoProjSetup (string $parent, int $forceFactorySettings) { string $prefix = "subdAutoProj"; string $intVars[] ={"p", "o", "sc", "l", "lm"}; string $varName; float $presets[] = {.1, .2, .4, .8, 1.6, 3.2}; int $i; setOptionVars($prefix, $forceFactorySettings, $intVars); setParent $parent; $varName = ($prefix + $intVars[0]); optionMenuGrp -e -sl `optionVar -query $varName` $varName; $varName = ($prefix + $intVars[1]); radioButtonGrp -e -sl (`optionVar -query $varName`+1) $varName; $varName = ($prefix + $intVars[2]); radioButtonGrp -e -sl (`optionVar -query $varName`+1) $varName; $varName = ($prefix + $intVars[3]); optionMenuGrp -e -sl `optionVar -query $varName` $varName; $varName = ($prefix + $intVars[4]); radioButtonGrp -e -sl (`optionVar -query $varName`+1) $varName; $varName = ($prefix + "eg"); float $fval = `optionVar -q $varName`; floatSliderGrp -e -v $fval $varName; // See if the value corresponds to one of the presets. $varName = ($prefix + "egPresets"); optionMenuGrp -e -sl 1 $varName; for ($i = size($presets) ; $i-- ; ) { if ($fval == $presets[$i]) { optionMenuGrp -e -sl ($i+2) $varName; break; } } } global proc performSubdAutoProjCallback (string $parent, int $doIt) { string $prefix = "subdAutoProj"; string $intVars[] ={"p", "o", "sc", "l", "lm"}; string $varName; setParent $parent; $varName = ($prefix + $intVars[0]); optionVar -intValue $varName `optionMenuGrp -q -sl $varName`; $varName = ($prefix + $intVars[1]); optionVar -intValue $varName (`radioButtonGrp -q -sl $varName`-1); $varName = ($prefix + $intVars[2]); optionVar -intValue $varName (`radioButtonGrp -q -sl $varName`-1); $varName = ($prefix + $intVars[3]); optionVar -intValue $varName `optionMenuGrp -q -sl $varName`; $varName = ($prefix + $intVars[4]); optionVar -intValue $varName (`radioButtonGrp -q -sl $varName`-1); $varName = ($prefix + "eg"); optionVar -floatValue $varName `floatSliderGrp -q -v $varName`; if ($doIt) { performSubdAutoProj 0; addToRecentCommandQueue "performSubdAutoProj 0" "SubdAutoProj"; } } global proc subdAutoSpacingPresets() { int $item = `optionMenuGrp -q -sl "subdAutoProjegPresets"`-2; float $presets[] = {.1, .2, .4, .8, 1.6, 3.2}; if ($item>=0 && $item<6) floatSliderGrp -e -v $presets[$item] "subdAutoProjeg"; } proc subdAutoProjOptions (string $prefix, string $intVars[]) { // Global template variables for form spacing global int $gOptionBoxTemplateFrameSpacing; global int $gOptionBoxTemplateInnerFrameMarginHeight; global int $gOptionBoxTemplateInnerFrameMarginWidth; string $commandName = "performSubdAutoProj"; string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); string $varName; string $layout = getOptionBox(); setParent $layout; setUITemplate -pushTemplate OptionBoxTemplate; waitCursor -state 1; // Form layout scrollLayout; string $parent = `formLayout subdAutoProjectOptions`; // Mapping settings frame string $mappingFrame = `frameLayout -label (uiRes("m_performSubdAutoProj.kMappingFrame"))`; columnLayout; $varName = ($prefix + $intVars[0]); optionMenuGrp -label (uiRes("m_performSubdAutoProj.kPlanes")) $varName; menuItem -label (uiRes("m_performSubdAutoProj.kOption4")) ; menuItem -label (uiRes("m_performSubdAutoProj.kOption5")) ; menuItem -label (uiRes("m_performSubdAutoProj.kOption6")) ; menuItem -label (uiRes("m_performSubdAutoProj.kOption8")) ; menuItem -label (uiRes("m_performSubdAutoProj.kOption12")) ; setParent -menu ..; $varName = ($prefix + $intVars[1]); radioButtonGrp -label (uiRes("m_performSubdAutoProj.kOptimize")) -nrb 2 -label1 (uiRes("m_performSubdAutoProj.kLessDistortion")) -label2 (uiRes("m_performSubdAutoProj.kFewerPieces")) -vr $varName; setParent $parent; // Layout frame string $layoutFrame = `frameLayout -label (uiRes("m_performSubdAutoProj.kLayoutFrame"))`; columnLayout; $varName = ($prefix + $intVars[3]); $gapName = ($prefix + "eg"); $menuName = ($prefix + "egPresets"); string $grayCmd = "{ int $tmp = `optionMenuGrp -q -sl "+$varName + "` == 2;" + " floatSliderGrp -e -en $tmp "+$gapName+";" + " optionMenuGrp -e -en $tmp "+$menuName+";}"; optionMenuGrp -label (uiRes("m_performSubdAutoProj.kLayout")) -cc $grayCmd $varName; menuItem -label (uiRes("m_performSubdAutoProj.kAlongU")); menuItem -label (uiRes("m_performSubdAutoProj.kIntoSquare")); setParent -m ..; $varName = ($prefix + $intVars[2]); radioButtonGrp -label (uiRes("m_performSubdAutoProj.kScaleMode")) -nrb 3 -label1 (uiRes("m_performSubdAutoProj.kNone")) -label2 (uiRes("m_performSubdAutoProj.kUniform")) -label3 (uiRes("m_performSubdAutoProj.kStretchToSquare")) -vr $varName; $varName = ($prefix + $intVars[4]); radioButtonGrp -label (uiRes("m_performSubdAutoProj.kShellStacking")) -nrb 2 -label1 (uiRes("m_performSubdAutoProj.kBoundingBox")) -label2 (uiRes("m_performSubdAutoProj.kShape")) -vr $varName; // Shell spacing frame string $shellFrameSpacing = `formLayout polyAutoProjectOptionsShellSpacing`; string $shellFrame = `frameLayout -label (uiRes("m_performSubdAutoProj.kShellSpacingFrame"))`; columnLayout; optionMenuGrp -label (uiRes("m_performSubdAutoProj.kSpacingPresets")) -cc subdAutoSpacingPresets $menuName; menuItem -label (uiRes("m_performSubdAutoProj.kCustom")); menuItem -label (uiRes("m_performSubdAutoProj.kMap1024")); menuItem -label (uiRes("m_performSubdAutoProj.kMap512")); menuItem -label (uiRes("m_performSubdAutoProj.kMap256")); menuItem -label (uiRes("m_performSubdAutoProj.kMap128")); menuItem -label (uiRes("m_performSubdAutoProj.kMap64")); menuItem -label (uiRes("m_performSubdAutoProj.kMap32")); setParent -menu ..; string $cmd = ("optionMenuGrp -e -sl 1 " + $menuName); floatSliderGrp -label (uiRes("m_performSubdAutoProj.kPercentageSpace")) -min 0 -max 5 -cc $cmd $gapName; setParent $shellFrameSpacing; setParent ..; formLayout -e -af $shellFrame "top" $gOptionBoxTemplateFrameSpacing -af $shellFrame "left" $gOptionBoxTemplateInnerFrameMarginWidth -af $shellFrame "right" $gOptionBoxTemplateInnerFrameMarginWidth -af $shellFrame "bottom" $gOptionBoxTemplateInnerFrameMarginHeight $shellFrameSpacing; setParent $parent; setParent ..; // Attach frames to form layout formLayout -e -af $mappingFrame "top" $gOptionBoxTemplateFrameSpacing -af $mappingFrame "left" $gOptionBoxTemplateFrameSpacing -af $mappingFrame "right" $gOptionBoxTemplateFrameSpacing -an $mappingFrame "bottom" -ac $layoutFrame "top" $gOptionBoxTemplateFrameSpacing $mappingFrame -af $layoutFrame "left" $gOptionBoxTemplateFrameSpacing -af $layoutFrame "right" $gOptionBoxTemplateFrameSpacing -an $layoutFrame "bottom" $parent; waitCursor -state 0; setUITemplate -popTemplate; string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performSubdAutoProj.kProject")) -command ($callback + " " + $parent + " " + 1) $applyBtn; string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox") $saveBtn; string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " " + 1) $resetBtn; setOptionBoxTitle (uiRes("m_performSubdAutoProj.kSubdivMappingOptions")); setOptionBoxHelpTag( "SubdivAutomaticMapping" ); eval (($setup + " " + $parent + " " + 0)); showOptionBox(); } proc string getFacesToProject() { // Returns a string representing the currently applicable // selection items. ie. if a subdiv surface is selected, // then this returns a string containing its base faces. // All base faces can be projected onto. // // If subd faces are already selected, then return nothing. // If only subd objects are selected, then return string with all // base faces. string $result = ""; // There are already subd faces selected, just return // string $subdFaces[] = `filterExpand -sm 38`; // Find out if there are any subdivision surfaces selected // int $numSubdivs = 0; string $selectedSubdivs[]; string $allSubds[] = `filterExpand -ex 1 -sm 68`; // If there are subd faces AND subd objects, then // display warning // if( size($subdFaces) > 0 ) { if( size($allSubds) > 0 ) { warning (uiRes("m_performSubdAutoProj.kSelectedFaceWarning")); } return $result; } for ( $obj in $allSubds ) { $numSubdivs ++; $selectedSubdivs[$numSubdivs-1] = $obj; }; if( $numSubdivs > 0 ) { // create a string of subdiv faces from the selected subdivs for ( $subd in $selectedSubdivs) { string $tmp = "ls "; $tmp += $subd; $tmp += ".smf[\"*\"][\"*\"]" ; $tmp += " ;"; string $allFaces[] = eval( $tmp ); for( $face in $allFaces ) { $result += " "; $result += $face; } } } return $result; } global proc string performSubdAutoProj (int $option) { string $prefix = "subdAutoProj"; string $intVars[] ={"p", "o", "sc", "l", "lm"}; string $cmd=""; switch ($option) { case 0: // If nothing selected, then return // string $sel[] = `ls -sl`; if( size($sel) == 0 ) { warning (uiRes("m_performSubdAutoProj.kSubdivSurfaceWarn")); return $cmd; } string $varName; int $ival; setOptionVars($prefix, false, $intVars); $cmd = "subdAutoProjection"; $varName = ($prefix + $intVars[4]); $ival = `optionVar -query $varName`; $cmd = $cmd + " -" + $intVars[4] + " " + $ival; $varName = ($prefix + $intVars[3]); $ival = `optionVar -query $varName`; $cmd = $cmd + " -" + $intVars[3] + " " + ($ival-1); $varName = ($prefix + $intVars[2]); $ival = `optionVar -query $varName`; $cmd = $cmd + " -" + $intVars[2] + " " + $ival; $varName = ($prefix + $intVars[1]); $ival = `optionVar -query $varName`; $cmd = $cmd + " -" + $intVars[1] + " " + $ival; $varName = ($prefix + $intVars[0]); $ival = `optionVar -query $varName`; int $numVal[] = {4, 5, 6, 8, 12}; $cmd = $cmd + " -" + $intVars[0] + " " + $numVal[$ival-1]; $varName = ($prefix + "eg"); float $fval = `optionVar -query $varName`; $cmd = $cmd + " -ps " + $fval; // Convert everything to subd faces, if necessary // string $selectionToProject = getFacesToProject(); $cmd += $selectionToProject; // polyPerformAction $cmd "f" 0; string $result[] = `eval $cmd`; // Set selection break; case 1: subdAutoProjOptions($prefix, $intVars); break; case 2: $cmd="performSubdAutoProj 0"; break; } // Return the name of the new projection node // return $result[0]; }