// =========================================================================== // 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: 23 Mar, 2010 // // Procedure Name: // performTransferShadingSets // // Description: // Dialog and commands to setup a transfer shading sets command. // // Input Arguments: // bool 0 - sets up shading sets transfer // 1 - display options // Return Value: // None. // proc transferShadingSetsCreateOrResetOptionVars( int $forceFactorySettings ) // // Description: // Make sure all optionVars exist, and optionally force // them to the default settings // { if ( $forceFactorySettings || !`optionVar -exists transferShadingSetsSpaceOption` ) optionVar -intValue transferShadingSetsSpaceOption 1; if ( $forceFactorySettings || !`optionVar -exists transferShadingSetsSearchMethodOption` ) optionVar -intValue transferShadingSetsSearchMethodOption 2; } global proc transferShadingSetsSetUIFromOptionVars( string $parent, int $forceFactorySettings ) // // Description: // Set the UI values to match the current optionVars // { transferShadingSetsCreateOrResetOptionVars ( $forceFactorySettings ); int $value = `optionVar -q transferShadingSetsSpaceOption`; radioButtonGrp -e -select $value transferShadingSetsSpaceMenu; radioButtonGrp -e -select `optionVar -q transferShadingSetsSearchMethodOption` transferShadingSetsSearchMethodMenu; setParent $parent; } global proc transferShadingSetsSetOptionVarsFromUI( string $parent) // // Description: // Set the OptionVars from the UI values. // { int $value; $value = `radioButtonGrp -q -select transferShadingSetsSpaceMenu`; optionVar -intValue transferShadingSetsSpaceOption $value; $value = `radioButtonGrp -q -select transferShadingSetsSearchMethodMenu`; optionVar -intValue transferShadingSetsSearchMethodOption $value; setParent $parent; } global proc string transferShadingSetsGenerateCmd() { string $selection[] = `ls -sl -o`; int $numSelected = size( $selection ); string $cmd = "transferShadingSets"; if( !`exists $cmd`) { dynamicLoad libModifiers.so; } $cmd = $cmd + " "; if( $numSelected == 0) { error (uiRes("m_performTransferShadingSets.kErrorSelectAtLeastOneSurface")); return ""; } int $space = `optionVar -q transferShadingSetsSpaceOption`; if( $space >= 3) $space += 1; // Skip over the ignore translation attribute enum we don't expose $cmd += "-sampleSpace " + ($space - 1) + " "; int $searchMethod = `optionVar -q transferShadingSetsSearchMethodOption`; if( $searchMethod == 1) $cmd += "-searchMethod 0"; else $cmd += "-searchMethod 3"; return $cmd; } proc transferShadingSetsOptionWindow() { // Global template variables for form spacing global int $gOptionBoxTemplateFrameSpacing; // Name of the command for this option box. string $commandName = "transferShadingSets"; // Build the option box actions. string $callback = ( $commandName + "Callback" ); string $setup = ( "transferShadingSetsSetUIFromOptionVars" ); string $save = ( "transferShadingSetsSetOptionVarsFromUI" ); // Reset our counters $surfaceSamplingTargetListSize = 0; $surfaceSamplingSourceListSize = 0; // STEP 1: Get the option box string $layout = getOptionBox(); setParent $layout; // STEP 2: Pass the command name to the option box. setOptionBoxCommandName( "TransferShadingSets" ); // STEP 3: Activate the option box template setUITemplate -pushTemplate OptionBoxTemplate; // STEP 4: Create option box contents. // Form layout string $parent = `formLayout polyUnmirrorOptions`; // Attribute Settings frame string $attributeSettingsFrame = `frameLayout -label (uiRes("m_performTransferShadingSets.kAttributeSettingsFrame"))`; columnLayout; radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_performTransferShadingSets.kSampleSpace")) -labelArray2 (uiRes("m_performTransferShadingSets.kWorldSpace")) (uiRes("m_performTransferShadingSets.kObjectSpace")) transferShadingSetsSpaceMenu; radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_performTransferShadingSets.kSearchMethod")) -labelArray2 (uiRes("m_performTransferShadingSets.kClosestAlongNormal")) (uiRes("m_performTransferShadingSets.kClosestToPoint")) transferShadingSetsSearchMethodMenu; setParent $parent; // frameLayout setParent ..; // formLayout // Attach frames to form layout formLayout -edit -attachForm $attributeSettingsFrame "top" $gOptionBoxTemplateFrameSpacing -attachForm $attributeSettingsFrame "left" $gOptionBoxTemplateFrameSpacing -attachForm $attributeSettingsFrame "right" $gOptionBoxTemplateFrameSpacing -attachNone $attributeSettingsFrame "bottom" $parent; // Step 5: Deactivate the default UI template. setUITemplate -popTemplate; // Step 6: Customize the buttons. // 'Go' button. string $applyAndCloseBtn = getOptionBoxApplyAndCloseBtn(); button -edit -label (uiRes("m_performTransferShadingSets.kApplyandClose")) -command ( $callback + " " + $parent + " " + 1 + "; hideOptionBox" ) $applyAndCloseBtn; // 'Apply' button. string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performTransferShadingSets.kBake")) -command ( $callback + " " + $parent + " " + 1 ) $applyBtn; // 'Close' button. string $closeBtn = getOptionBoxCloseBtn(); button -edit -command ( $callback + " " + $parent + " " + 0 + "; hideOptionBox" ) $closeBtn; // 'Reset' menu item string $resetBtn = getOptionBoxResetBtn(); button -edit -command ( $setup + " " + $parent + " " + 1 ) $resetBtn; // 'Save' menu item string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ( $save + " " + $parent ) $saveBtn; // Step 7: Set the option box title setOptionBoxTitle (uiRes("m_performTransferShadingSets.kTransferShadingSetsOptions")); setOptionBoxHelpTag("TransferShadingSets"); // Step 9: Set the current values of the option box. eval ( ( $setup + " " + $parent + " " + 0 ) ); // Step 10: Show the option box. showOptionBox(); } global proc performTransferShadingSets( int $action ) { switch ( $action ) { case 0: transferShadingSetsCreateOrResetOptionVars( 0 ); string $cmd = transferShadingSetsGenerateCmd(); if( size( $cmd) ) evalEcho( $cmd ); // A secondary refresh routine is available transferShadingSetsRefresh(); break; case 1: transferShadingSetsOptionWindow(); break; } } global proc transferShadingSetsRefresh() // // Description: // Refreshes the viewport with the updated transfer attributes changes // on the destination mesh // To be called after a transfer attributes operation completes // { } global proc transferShadingSetsCallback( string $parent, int $doIt ) // // Description: // Handle the user clicking "Sample" etc // { // Set all our controlling option vars from the current UI // transferShadingSetsSetOptionVarsFromUI( $parent); // Execute the command if we've been told to // if ($doIt) { performTransferShadingSets 0; addToRecentCommandQueue "performTransferShadingSets 0" "Shading Sets Sampling"; } }