// =========================================================================== // 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: 16 Nov, 2003 // // Procedure Name: // performTransferAttributes // // Description: // Dialog and commands to setup a transfer attributes node. // // Input Arguments: // bool 0 - sets up attribute transfer // 1 - display options // Return Value: // None. // proc transferAttributesCreateOrResetOptionVars( int $forceFactorySettings ) // // Description: // Make sure all optionVars exist, and optionally force // them to the default settings // { if ( $forceFactorySettings || !`optionVar -exists transferAttributesPositionsOption` ) optionVar -intValue transferAttributesPositionsOption 1; if ( $forceFactorySettings || !`optionVar -exists transferAttributesNormalsOption` ) optionVar -intValue transferAttributesNormalsOption 1; if ( $forceFactorySettings || !`optionVar -exists transferAttributesUVSetsOption` ) optionVar -intValue transferAttributesUVSetsOption 3; if ( $forceFactorySettings || !`optionVar -exists transferAttributesColorSetsOption` ) optionVar -intValue transferAttributesColorSetsOption 3; if ( $forceFactorySettings || !`optionVar -exists transferAttributesSpaceOption` ) optionVar -intValue transferAttributesSpaceOption 1; if ( $forceFactorySettings || !`optionVar -exists transferAttributesSearchMethodOption` ) optionVar -intValue transferAttributesSearchMethodOption 2; if ( $forceFactorySettings || !`optionVar -exists transferAttributesMirrorOption` ) optionVar -intValue transferAttributesMirrorOption 1; if ( $forceFactorySettings || !`optionVar -exists transferAttributesFlipUVsOption` ) optionVar -intValue transferAttributesFlipUVsOption 1; if ( $forceFactorySettings || !`optionVar -exists transferAttributesColorBordersOption` ) optionVar -intValue transferAttributesColorBordersOption 2; } global proc transferAttributesSetUIFromOptionVars( string $parent, int $forceFactorySettings ) // // Description: // Set the UI values to match the current optionVars // { transferAttributesCreateOrResetOptionVars ( $forceFactorySettings ); radioButtonGrp -e -select `optionVar -q transferAttributesPositionsOption` transferAttributesPositionsMenu; radioButtonGrp -e -select `optionVar -q transferAttributesNormalsOption` transferAttributesNormalsMenu; radioButtonGrp -e -select `optionVar -q transferAttributesUVSetsOption` transferAttributesUVSetMenu; radioButtonGrp -e -select `optionVar -q transferAttributesColorSetsOption` transferAttributesColorSetMenu; int $value = `optionVar -q transferAttributesSpaceOption`; if ( $value < 5 ) { radioButtonGrp -e -select $value transferAttributesSpaceMenu; } else { radioButtonGrp -e -select $value transferAttributesSpaceMenu2; } radioButtonGrp -e -select `optionVar -q transferAttributesSearchMethodOption` transferAttributesSearchMethodMenu; radioButtonGrp -e -select `optionVar -q transferAttributesMirrorOption` transferAttributesMirroringMenu; radioButtonGrp -e -select `optionVar -q transferAttributesFlipUVsOption` transferAttributesFlipUVsMenu; radioButtonGrp -e -select `optionVar -q transferAttributesColorBordersOption` transferAttributesColorBordersMenu; //dim controls based on selected values if (`radioButtonGrp -q -select transferAttributesUVSetMenu` == 1) radioButtonGrp -e -enable 0 transferAttributesFlipUVsMenu; if (`radioButtonGrp -q -select transferAttributesColorSetMenu` == 1) radioButtonGrp -e -enable 0 transferAttributesColorBordersMenu; setParent $parent; } global proc transferAttributesSetOptionVarsFromUI( string $parent) // // Description: // Set the OptionVars from the UI values. // { int $value; $value = `radioButtonGrp -q -select transferAttributesPositionsMenu`; optionVar -intValue transferAttributesPositionsOption $value; $value = `radioButtonGrp -q -select transferAttributesNormalsMenu`; optionVar -intValue transferAttributesNormalsOption $value; $value = `radioButtonGrp -q -select transferAttributesUVSetMenu`; optionVar -intValue transferAttributesUVSetsOption $value; $value = `radioButtonGrp -q -select transferAttributesColorSetMenu`; optionVar -intValue transferAttributesColorSetsOption $value; $value = `radioButtonGrp -q -select transferAttributesSpaceMenu`; if ( $value < 1 ) { $value = `radioButtonGrp -q -select transferAttributesSpaceMenu2`; $value += 4; } optionVar -intValue transferAttributesSpaceOption $value; $value = `radioButtonGrp -q -select transferAttributesSearchMethodMenu`; optionVar -intValue transferAttributesSearchMethodOption $value; $value = `radioButtonGrp -q -select transferAttributesMirroringMenu`; optionVar -intValue transferAttributesMirrorOption $value; $value = `radioButtonGrp -q -select transferAttributesFlipUVsMenu`; optionVar -intValue transferAttributesFlipUVsOption $value; $value = `radioButtonGrp -q -select transferAttributesColorBordersMenu`; optionVar -intValue transferAttributesColorBordersOption $value; setParent $parent; } proc string getActiveUVSet( string $path) { string $uvSet = ""; string $shapes[] = `listRelatives -path -shapes $path`; if ( `size $shapes` != 0 && `nodeType $shapes[0]` == "mesh" ) { string $currentUVSet[] = `polyUVSet -q -currentUVSet $shapes[0]`; $uvSet = $currentUVSet[0]; } return $uvSet; } proc string getActiveColorSet( string $path) { string $uvSet = ""; string $shapes[] = `listRelatives -path -shapes $path`; if ( `size $shapes` != 0 && `nodeType $shapes[0]` == "mesh" ) { string $currentColorSet[] = `polyColorSet -q -currentColorSet $shapes[0]`; $uvSet = $currentColorSet[0]; } return $uvSet; } global proc string transferAttributesGenerateCmd() { string $selection[] = `ls -sl -o`; int $numSelected = size( $selection ); string $cmd = "transferAttributes"; if( !`exists $cmd`) { dynamicLoad libModifiers.so; } $cmd = $cmd + " "; if( $numSelected == 0) { error (uiRes("m_performTransferAttributes.kErrorSelectAtLeastOneSurface")); return ""; } int $positions = `optionVar -q transferAttributesPositionsOption`; $cmd += "-transferPositions " + ($positions - 1) + " "; int $normals = `optionVar -q transferAttributesNormalsOption`; $cmd += "-transferNormals " + ($normals - 1) + " "; int $uvSets = `optionVar -q transferAttributesUVSetsOption`; $cmd += "-transferUVs " + ($uvSets - 1) + " "; if( $uvSets == 2) { if( $numSelected > 0) { string $src = getActiveUVSet( $selection[ 0]); if( size( $src ) > 0) { $cmd += "-sourceUvSet \"" + $src + "\" "; string $dst = getActiveUVSet( $selection[ $numSelected - 1]); if( size( $dst ) > 0) $cmd += "-targetUvSet \"" + $dst + "\" "; else $cmd += "-targetUvSet \"" + $src + "\" "; } } } int $colorSets = `optionVar -q transferAttributesColorSetsOption`; $cmd += "-transferColors " + ($colorSets - 1) + " "; if( $colorSets == 2) { if( $numSelected > 0) { string $src = getActiveColorSet( $selection[ 0]); if( size( $src ) > 0) { $cmd += "-sourceColorSet \"" + $src + "\" "; string $dst = getActiveColorSet( $selection[ $numSelected - 1]); if( size( $dst ) > 0) $cmd += "-targetColorSet \"" + $dst + "\" "; else $cmd += "-targetColorSet \"" + $src + "\" "; } } } int $space = `optionVar -q transferAttributesSpaceOption`; if( $space >= 3) $space += 1; // Skip over the ignore translation attribute enum we don't expose $cmd += "-sampleSpace " + ($space - 1) + " "; string $src = getActiveUVSet( $selection[ 0]); if( size( $src ) > 0) $cmd += "-sourceUvSpace \"" + $src + "\" "; string $dst = getActiveUVSet( $selection[ $numSelected - 1]); if( size( $dst ) > 0) $cmd += "-targetUvSpace \"" + $dst + "\" "; int $searchMethod = `optionVar -q transferAttributesSearchMethodOption`; if( $searchMethod == 1) $cmd += "-searchMethod 0"; else $cmd += "-searchMethod 3"; int $mirroring = `optionVar -q transferAttributesMirrorOption`; if( $mirroring == 2) $cmd += "-searchScaleX -1.0 "; else if( $mirroring == 3) $cmd += "-searchScaleY -1.0 "; else if( $mirroring == 4) $cmd += "-searchScaleZ -1.0 "; int $flipUVs = `optionVar -q transferAttributesFlipUVsOption`; $cmd += "-flipUVs " + ($flipUVs - 1) + " "; int $colourBorders = `optionVar -q transferAttributesColorBordersOption`; $cmd += "-colorBorders " + ($colourBorders - 1) + " "; return $cmd; } proc transferAttributesOptionWindow() { // Global template variables for form spacing global int $gOptionBoxTemplateFrameSpacing; // Name of the command for this option box. string $commandName = "transferAttributes"; // Build the option box actions. string $callback = ( $commandName + "Callback" ); string $setup = ( "transferAttributesSetUIFromOptionVars" ); string $save = ( "transferAttributesSetOptionVarsFromUI" ); // 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( "TransferAttributes" ); // STEP 3: Activate the option box template setUITemplate -pushTemplate OptionBoxTemplate; // STEP 4: Create option box contents. // Form layout string $parent = `formLayout polyUnmirrorOptions`; // Attributes To Transfer frame string $attributesToTransferFrame = `frameLayout -label (uiRes("m_performTransferAttributes.kAttributesToTransferFrame"))`; columnLayout; radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_performTransferAttributes.kPositionMenu")) -labelArray2 (uiRes("m_performTransferAttributes.kNoPositionSampling")) (uiRes("m_performTransferAttributes.kSnapVertex")) transferAttributesPositionsMenu; radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_performTransferAttributes.kNormalMenu")) -labelArray2 (uiRes("m_performTransferAttributes.kNoNormalSampling")) (uiRes("m_performTransferAttributes.kNormalSampling")) transferAttributesNormalsMenu; radioButtonGrp -numberOfRadioButtons 3 -label (uiRes("m_performTransferAttributes.kUVMenu")) -labelArray3 (uiRes("m_performTransferAttributes.kNoUVs")) (uiRes("m_performTransferAttributes.kActiveUVs")) (uiRes("m_performTransferAttributes.kAllUVs")) -onCommand1 "radioButtonGrp -e -enable 0 transferAttributesFlipUVsMenu" -onCommand2 "radioButtonGrp -e -enable 1 transferAttributesFlipUVsMenu" -onCommand3 "radioButtonGrp -e -enable 1 transferAttributesFlipUVsMenu" transferAttributesUVSetMenu; radioButtonGrp -numberOfRadioButtons 3 -label (uiRes("m_performTransferAttributes.kColorMenu")) -labelArray3 (uiRes("m_performTransferAttributes.kNoColors")) (uiRes("m_performTransferAttributes.kActiveColors")) (uiRes("m_performTransferAttributes.kAllColors")) -onCommand1 "radioButtonGrp -e -enable 0 transferAttributesColorBordersMenu" -onCommand2 "radioButtonGrp -e -enable 1 transferAttributesColorBordersMenu" -onCommand3 "radioButtonGrp -e -enable 1 transferAttributesColorBordersMenu" transferAttributesColorSetMenu; setParent $parent; // frameLayout // Attribute Settings frame string $attributeSettingsFrame = `frameLayout -label (uiRes("m_performTransferAttributes.kAttributeSettingsFrame"))`; columnLayout; radioButtonGrp -numberOfRadioButtons 4 -label (uiRes("m_performTransferAttributes.kSampleSpace")) -labelArray4 (uiRes("m_performTransferAttributes.kWorldSpace")) (uiRes("m_performTransferAttributes.kObjectSpace")) (uiRes("m_performTransferAttributes.kUVSpace")) (uiRes("m_performTransferAttributes.kComponentSpace")) transferAttributesSpaceMenu; radioButtonGrp -numberOfRadioButtons 1 -label1 (uiRes("m_performTransferAttributes.kTopologySpace")) -shareCollection transferAttributesSpaceMenu transferAttributesSpaceMenu2; radioButtonGrp -numberOfRadioButtons 4 -label (uiRes("m_performTransferAttributes.kMirroring")) -labelArray4 (uiRes("m_performTransferAttributes.kNoMirroring")) (uiRes("m_performTransferAttributes.kXMirroring")) (uiRes("m_performTransferAttributes.kYMirroring")) (uiRes("m_performTransferAttributes.kZMirroring")) transferAttributesMirroringMenu; radioButtonGrp -numberOfRadioButtons 3 -label (uiRes("m_performTransferAttributes.kFlipUVs")) -labelArray3 (uiRes("m_performTransferAttributes.kNoUVFlipping")) (uiRes("m_performTransferAttributes.kFlipU")) (uiRes("m_performTransferAttributes.kFlipV")) -enable 1 transferAttributesFlipUVsMenu; radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_performTransferAttributes.kColorBorders")) -labelArray2 (uiRes("m_performTransferAttributes.kIgnoreColorBorders")) (uiRes("m_performTransferAttributes.kPreserveColorBorders")) -enable 1 transferAttributesColorBordersMenu; radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_performTransferAttributes.kSearchMethod")) -labelArray2 (uiRes("m_performTransferAttributes.kClosestAlongNormal")) (uiRes("m_performTransferAttributes.kClosestToPoint")) transferAttributesSearchMethodMenu; setParent $parent; // frameLayout setParent ..; // formLayout // Attach frames to form layout formLayout -edit -attachForm $attributesToTransferFrame "top" $gOptionBoxTemplateFrameSpacing -attachForm $attributesToTransferFrame "left" $gOptionBoxTemplateFrameSpacing -attachForm $attributesToTransferFrame "right" $gOptionBoxTemplateFrameSpacing -attachNone $attributesToTransferFrame "bottom" -attachControl $attributeSettingsFrame "top" $gOptionBoxTemplateFrameSpacing $attributesToTransferFrame -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_performTransferAttributes.kApplyandClose")) -command ( $callback + " " + $parent + " " + 1 + "; hideOptionBox" ) $applyAndCloseBtn; // 'Apply' button. string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performTransferAttributes.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_performTransferAttributes.kTransferAttributesOptions")); setOptionBoxHelpTag("TransferAttributes"); // Step 9: Set the current values of the option box. eval ( ( $setup + " " + $parent + " " + 0 ) ); // Step 10: Show the option box. showOptionBox(); } global proc performTransferAttributes( int $action ) { switch ( $action ) { case 0: transferAttributesCreateOrResetOptionVars( 0 ); string $cmd = transferAttributesGenerateCmd(); if( size( $cmd) ) evalEcho( $cmd ); // A secondary refresh routine is available transferAttributesRefresh(); break; case 1: transferAttributesOptionWindow(); break; } } global proc transferAttributesRefresh() // // Description: // Refreshes the viewport with the updated transfer attributes changes // on the destination mesh // To be called after a transfer attributes operation completes // { // Were any color sets transferred? // int $colorSets = `optionVar -q transferAttributesColorSetsOption`; if( $colorSets>0 ) { // Determine the destination mesh node and its shape node // string $selection[] = `ls -sl -o`; int $numSelected = size( $selection ); if ($numSelected>0) { string $shapes[] = `listRelatives -path -shapes $selection[$numSelected-1]`; if ( `size $shapes` != 0 && `nodeType $shapes[0]` == "mesh" ) { // Update the display color attribute of the destination mesh node // This allows color sets to be displayed after they're transferred // string $objAndAttr=$shapes[0] + ".dcol"; setAttr $objAndAttr true; } } } } global proc transferAttributesCallback( string $parent, int $doIt ) // // Description: // Handle the user clicking "Sample" etc // { // Set all our controlling option vars from the current UI // transferAttributesSetOptionVarsFromUI( $parent); // Execute the command if we've been told to // if ($doIt) { performTransferAttributes 0; addToRecentCommandQueue "performTransferAttributes 0" "Attribute Sampling"; } }