// =========================================================================== // 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: Nov, 12, 1998 // // Procedure Name: // performApplyColor // // Description: // Perform a color assignment on selected components // // Input Arguments: // $option : Whether to set the options to default values. // Return Value: // command string iff $option==2 // proc setOptionVars (int $forceFactorySettings) // // Description: // Setup option variables to store UI state. // Arguments: // forceFactorySettings : set option vars to default // Returns: // none // { if ($forceFactorySettings || !`optionVar -exists polyApplyColorRed`) optionVar -intValue polyApplyColorRed 1; if ($forceFactorySettings || !`optionVar -exists polyApplyColorRedValue`) optionVar -floatValue polyApplyColorRedValue 0.5; if ($forceFactorySettings || !`optionVar -exists polyApplyColorGreen`) optionVar -intValue polyApplyColorGreen 1; if ($forceFactorySettings || !`optionVar -exists polyApplyColorGreenValue`) optionVar -floatValue polyApplyColorGreenValue 0.5; if ($forceFactorySettings || !`optionVar -exists polyApplyColorBlue`) optionVar -intValue polyApplyColorBlue 1; if ($forceFactorySettings || !`optionVar -exists polyApplyColorBlueValue`) optionVar -floatValue polyApplyColorBlueValue 0.5; if ($forceFactorySettings || !`optionVar -exists polyApplyColorAlpha`) optionVar -intValue polyApplyColorAlpha 1; if ($forceFactorySettings || !`optionVar -exists polyApplyColorAlphaValue`) optionVar -floatValue polyApplyColorAlphaValue 1.0; if ($forceFactorySettings || !`optionVar -exists polyAutoColorPerVertex`) optionVar -intValue polyAutoColorPerVertex 1; // Color operation. Default is "replace" color. // 1 = repalce, 2 = add, 3 = subtract, 4 = remove if ($forceFactorySettings || !`optionVar -exists polyApplyColorOperation`) optionVar -intValue polyApplyColorOperation 1; if ($forceFactorySettings || !`optionVar -exists polyApplyColorIndivChannels`) optionVar -intValue polyApplyColorIndivChannels 0; } global proc toggleColorWidgets() // // Description: // Toggle color widgets (R,G,B,A RGB, relative etc) on // and off. // Arguments: // none // Returns: // none // { // Check current operation $cbval = `radioButtonGrp -query -select polyApplyColorOperation`; if ($cbval == 4) $remove = 1; else $remove = 0; // If operation is "remove". disable everything if ($remove) { disable -value true polyApplyColorIndivChannels; disable -value true colorValueFrame; frameLayout -edit -collapse true colorChannelValuesFrame; disable -value true polyApplyColorRed; disable -value true polyApplyColorGreen; disable -value true polyApplyColorBlue; disable -value true polyApplyColorRedValue; disable -value true polyApplyColorGreenValue; disable -value true polyApplyColorBlueValue; disable -value true polyApplyColorAlpha; disable -value true polyApplyColorAlphaValue1; } else { disable -value false polyApplyColorIndivChannels; int $individ = `radioButtonGrp -query -select polyApplyColorIndivChannels` - 1; // Disable all individual color widgets. Enable other widgets // if (!$individ) { disable -value false colorValueFrame; frameLayout -edit -collapse true colorChannelValuesFrame; disable -value true polyApplyColorRed; disable -value true polyApplyColorGreen; disable -value true polyApplyColorBlue; disable -value true polyApplyColorRedValue; disable -value true polyApplyColorGreenValue; disable -value true polyApplyColorBlueValue; disable -value true polyApplyColorAlpha; disable -value true polyApplyColorAlphaValue1; } // Disable individual ones as needed else { disable -value true colorValueFrame; frameLayout -edit -collapse false colorChannelValuesFrame; disable -value false polyApplyColorRed; disable -value false polyApplyColorGreen; disable -value false polyApplyColorBlue; disable -value false polyApplyColorAlpha; $ival = `optionVar -query polyApplyColorRed`; if ($ival) disable -value false polyApplyColorRedValue; else disable -value true polyApplyColorRedValue; $ival = `optionVar -query polyApplyColorGreen`; if ($ival) disable -value false polyApplyColorGreenValue; else disable -value true polyApplyColorGreenValue; $ival = `optionVar -query polyApplyColorBlue`; if ($ival) disable -value false polyApplyColorBlueValue; else disable -value true polyApplyColorBlueValue; $ival = `optionVar -query polyApplyColorAlpha`; if ($ival) disable -value false polyApplyColorAlphaValue1; else disable -value true polyApplyColorAlphaValue1; } } } global proc updatePolyColorSwatch(int $fromColorSlider) // // Description: // Update real color to apply's swatch // Arguments: // none // Returns: // none // { float $rval = 0.0; float $gval = 0.0; float $bval = 0.0; float $aval = 1.0; int $rset, $gset, $bset, $aset; float $rgb[3]; $cbval = `radioButtonGrp -query -select polyApplyColorOperation`; if ($cbval == 4) $remval = 1; else $remval = 0; //int $remval = `checkBoxGrp -query -value1 polyApplyColorRemove`; if ($remval) { canvas -edit -rgbValue 0 0 0 polyColorSwatch; return; } // If not setting individual colors, then // grab the color from the RGB color slider int $individual = `radioButtonGrp -query -select polyApplyColorIndivChannels` - 1; if ($individual == 0) { $aval = `floatSliderGrp -query -value polyApplyColorAlphaValue1`; if ($fromColorSlider == 0) { $rval = `floatSliderGrp -query -value polyApplyColorRedValue`; $gval = `floatSliderGrp -query -value polyApplyColorGreenValue`; $bval = `floatSliderGrp -query -value polyApplyColorBlueValue`; colorSliderGrp -edit -rgb $rval $gval $bval polyApplyColorRGBValue; } else { $rgb = `colorSliderGrp -query -rgb polyApplyColorRGBValue`; $rval = $rgb[0]; $gval = $rgb[1]; $bval = $rgb[2]; // Update the color float sliders also if individual not set floatSliderGrp -edit -value $rval polyApplyColorRedValue; floatSliderGrp -edit -value $gval polyApplyColorGreenValue; floatSliderGrp -edit -value $bval polyApplyColorBlueValue; } $bset = $rset = $gset = 1; } // else grab the colors from each individual color slider // also update the RGB slider // else { $rset = `checkBoxGrp -query -value1 polyApplyColorRed`; if ($rset) $rval = `floatSliderGrp -query -value polyApplyColorRedValue`; else $rval = 0.0; $gset = `checkBoxGrp -query -value1 polyApplyColorGreen`; if ($gset) $gval = `floatSliderGrp -query -value polyApplyColorGreenValue`; else $gbal = 0.0; $bset = `checkBoxGrp -query -value1 polyApplyColorBlue`; if ($bset) $bval = `floatSliderGrp -query -value polyApplyColorBlueValue`; else $bval = 0.0; $aset = `checkBoxGrp -query -value1 polyApplyColorAlpha`; if ($aset) $aval = `floatSliderGrp -query -value polyApplyColorAlphaValue1`; else $aval = 1.0; if ($fromColorSlider == 0) { colorSliderGrp -edit -rgb $rval $gval $bval polyApplyColorRGBValue; } } if ($gset || $bset || $rset) { $rval = $rval * $aval; $gval = $gval * $aval; $bval = $bval * $aval; } else { if ($aset) $rval = $gval = $bval = $aval; else $rval = $gval = $bval = 0.0; } canvas -edit -rgbValue $rval $gval $bval polyColorSwatch; } global proc performApplyColorSetup (string $parent, int $forceFactorySettings) // // Description: // Do setup of widget states. // Arguments: // parent : parent widget // forceFactorySettings : set to defaults. // Returns: // none // { setOptionVars($forceFactorySettings); setParent $parent; int $ival; float $fval; float $rval, $gval, $bval; // R $ival = `optionVar -query polyApplyColorRed`; checkBoxGrp -edit -value1 $ival polyApplyColorRed; $fval = `optionVar -query polyApplyColorRedValue`; $rval = $fval; floatSliderGrp -edit -value $fval polyApplyColorRedValue; // G $ival = `optionVar -query polyApplyColorGreen`; $gval = $fval; checkBoxGrp -edit -value1 $ival polyApplyColorGreen; $fval = `optionVar -query polyApplyColorGreenValue`; floatSliderGrp -edit -value $fval polyApplyColorGreenValue; // B $ival = `optionVar -query polyApplyColorBlue`; $bval = $fval; checkBoxGrp -edit -value1 $ival polyApplyColorBlue; $fval = `optionVar -query polyApplyColorBlueValue`; floatSliderGrp -edit -value $fval polyApplyColorBlueValue; // Alpha $ival = `optionVar -query polyApplyColorAlpha`; checkBoxGrp -edit -value1 $ival polyApplyColorAlpha; $fval = `optionVar -query polyApplyColorAlphaValue`; floatSliderGrp -edit -value $fval polyApplyColorAlphaValue; floatSliderGrp -edit -value $fval polyApplyColorAlphaValue1; $ival = `optionVar -query polyApplyColorOperation`; radioButtonGrp -edit -sl $ival polyApplyColorOperation; // Individual int $idval = `optionVar -query polyApplyColorIndivChannels`; radioButtonGrp -edit -select ($idval + 1) polyApplyColorIndivChannels; // RGB Color slider colorSliderGrp -edit -rgb $rval $gval $bval polyApplyColorRGBValue; updatePolyColorSwatch 0; toggleColorWidgets(); } global proc performApplyColorCallback (string $parent, int $doIt) // // Description: // Save option variables before application or save. // Arguments: // parent : parent widget // doIt : perform action // Returns: // none // { setParent $parent; // R optionVar -intValue polyApplyColorRed `checkBoxGrp -query -value1 polyApplyColorRed`; optionVar -floatValue polyApplyColorRedValue `floatSliderGrp -query -value polyApplyColorRedValue`; // G optionVar -intValue polyApplyColorGreen `checkBoxGrp -query -value1 polyApplyColorGreen`; optionVar -floatValue polyApplyColorGreenValue `floatSliderGrp -query -value polyApplyColorGreenValue`; // B optionVar -intValue polyApplyColorBlue `checkBoxGrp -query -value1 polyApplyColorBlue`; optionVar -floatValue polyApplyColorBlueValue `floatSliderGrp -query -value polyApplyColorBlueValue`; // Alpha optionVar -intValue polyApplyColorAlpha `checkBoxGrp -query -value1 polyApplyColorAlpha`; optionVar -floatValue polyApplyColorAlphaValue `floatSliderGrp -query -value polyApplyColorAlphaValue`; // Individual int $ival = `radioButtonGrp -query -select polyApplyColorIndivChannels` - 1; optionVar -intValue polyApplyColorIndivChannels $ival; // Operation int $rval = `radioButtonGrp -query -sl polyApplyColorOperation`; optionVar -intValue polyApplyColorOperation $rval; toggleColorWidgets(); updatePolyColorSwatch 0; if ($doIt) { performApplyColor 0; addToRecentCommandQueue "performApplyColor 0" "ApplyColor"; } } global proc polyApplyColorMatchAlphaValues(int $which) { float $fval; // Set the 1st to the 2nd's value if ($which == 0) { $fval = `floatSliderGrp -query -value polyApplyColorAlphaValue1`; floatSliderGrp -edit -value $fval polyApplyColorAlphaValue; } // Set the 2nd to the 1st's value else { $fval = `floatSliderGrp -query -value polyApplyColorAlphaValue`; floatSliderGrp -edit -value $fval polyApplyColorAlphaValue1; } } global proc grabAColor() { float $rgb[]; float $r, $g, $b; $rgb = `grabColor`; //print( $rgb ); $r = $rgb[0]; $g = $rgb[1]; $b = $rgb[2]; floatSliderGrp -edit -value $r polyApplyColorRedValue; floatSliderGrp -edit -value $g polyApplyColorGreenValue; floatSliderGrp -edit -value $b polyApplyColorBlueValue; updatePolyColorSwatch 0; } global proc grabSelectedColor() { float $rgb[]; float $a[]; int $foundColor = 0; // Check for vertex faces first string $selectedVertexFaces[] = `filterExpand -sm 70`; if (size($selectedVertexFaces) != 0) { $rgb = `polyColorPerVertex -q -rgb $selectedVertexFaces[0]`; $a = `polyColorPerVertex -q -a $selectedVertexFaces[0]`; $foundColor = 1; } // Check for vertices else { string $selectedVertices[] = `filterExpand -sm 31`; if (size($selectedVertices) != 0) { $rgb = `polyColorPerVertex -q -rgb $selectedVertices[0]`; $a = `polyColorPerVertex -q -a $selectedVertices[0]`; $foundColor = 1; } } if ($foundColor) { floatSliderGrp -edit -value $rgb[0] polyApplyColorRedValue; floatSliderGrp -edit -value $rgb[1] polyApplyColorGreenValue; floatSliderGrp -edit -value $rgb[2] polyApplyColorBlueValue; floatSliderGrp -edit -value $a[0] polyApplyColorAlphaValue; floatSliderGrp -edit -value $a[0] polyApplyColorAlphaValue1; updatePolyColorSwatch 0; } } proc polyApplyColorOptions() // // Description: // Options for apply color // Arguments: // none // Returns: // none // { // Global template variables for form spacing global int $gOptionBoxTemplateFrameSpacing; global int $gOptionBoxTemplateTextColumnWidth; string $commandName = "performApplyColor"; string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); string $layout = getOptionBox(); setParent $layout; setUITemplate -pushTemplate OptionBoxTemplate; waitCursor -state 1; // Form layout scrollLayout; string $parent = `formLayout polyUnmirrorOptions`; // Settings frame string $settingsFrame = `frameLayout -label (uiRes("m_performApplyColor.kSettingsFrame"))`; columnLayout; radioButtonGrp -numberOfRadioButtons 4 -vertical -label (uiRes("m_performApplyColor.kOperation")) -labelArray4 (uiRes("m_performApplyColor.kReplaceColor")) (uiRes("m_performApplyColor.kAddColor")) (uiRes("m_performApplyColor.kSubtractColor")) (uiRes("m_performApplyColor.kRemoveColor")) -onCommand4 ("toggleColorWidgets; updatePolyColorSwatch 0") -offCommand4 ("toggleColorWidgets; updatePolyColorSwatch 0") polyApplyColorOperation; radioButtonGrp -numberOfRadioButtons 2 -vertical -label (uiRes("m_performApplyColor.kEffect")) -labelArray2 (uiRes("m_performApplyColor.kAllChannels")) (uiRes("m_performApplyColor.kIndividualChannels")) -onCommand1 ("toggleColorWidgets; updatePolyColorSwatch 0;") -onCommand2 ("toggleColorWidgets; updatePolyColorSwatch 0;") polyApplyColorIndivChannels; setParent $parent; // frameLayout // Color Value frame string $colorValueFrame = `frameLayout -label (uiRes("m_performApplyColor.kColorValueFrame")) colorValueFrame`; columnLayout; // All colors, except alpha. Will update the color // color sliders colorSliderGrp -label (uiRes("m_performApplyColor.kColor")) -rgbValue 0.5 0.5 0.5 -changeCommand ("updatePolyColorSwatch 1") -dragCommand ("updatePolyColorSwatch 1") polyApplyColorRGBValue; //button rowLayout -numberOfColumns 3 -columnWidth3 $gOptionBoxTemplateTextColumnWidth 20 170; text -label (uiRes("m_performApplyColor.kGrabColor")) polyApplyColorGrabLabel; symbolButton -image "eyeDropper.png" -width 20 -height 20 -command ("grabAColor") polyApplyColorGrab; button -label (uiRes("m_performApplyColor.kSelectedVertexColor")) -command "grabSelectedColor" polyApplyColorVtxGrab; setParent ..; floatSliderGrp -label (uiRes("m_performApplyColor.kAlpha")) -minValue 0.0 -maxValue 1.0 -fieldMinValue -10000000000000000000000000000000000000000.0 -fieldMaxValue 10000000000000000000000000000000000000000.0 -changeCommand ("polyApplyColorMatchAlphaValues 1; updatePolyColorSwatch 0") -dragCommand ("polyApplyColorMatchAlphaValues 1; updatePolyColorSwatch 0") polyApplyColorAlphaValue; rowLayout -numberOfColumns 2 -columnWidth2 $gOptionBoxTemplateTextColumnWidth 76 polyColorSwatchLayout; text -label (uiRes("m_performApplyColor.kColorWithAlpha")) polyColorSwatchLabel; canvas -width 76 -height 22 polyColorSwatch; setParent ..; setParent $parent; // frameLayout // Color Channel Values frame string $colorChannelValuesFrame = `frameLayout -label (uiRes("m_performApplyColor.kColorChannelValuesFrame")) -collapsable true colorChannelValuesFrame`; columnLayout; //---------------------------------------------------------------------- // Seperate or all color setting // Red checkBoxGrp -label1 (uiRes("m_performApplyColor.kSetRed")) -onCommand1 ("disable -value false polyApplyColorRedValue; updatePolyColorSwatch 0") -offCommand1 ("disable polyApplyColorRedValue; updatePolyColorSwatch 0") polyApplyColorRed; floatSliderGrp -label (uiRes("m_performApplyColor.kRed")) -minValue 0.0 -maxValue 1.0 -fieldMinValue -10000000000000000000000000000000000000000.0 -fieldMaxValue 10000000000000000000000000000000000000000.0 -changeCommand ("updatePolyColorSwatch 0") -dragCommand ("updatePolyColorSwatch 0") polyApplyColorRedValue; // Green checkBoxGrp -label1 (uiRes("m_performApplyColor.kSetGreen")) -onCommand1 ("disable -value false polyApplyColorGreenValue; updatePolyColorSwatch 0") -offCommand1 ("disable polyApplyColorGreenValue; updatePolyColorSwatch 0") polyApplyColorGreen; floatSliderGrp -label (uiRes("m_performApplyColor.kGreen")) -minValue 0.0 -maxValue 1.0 -fieldMinValue -10000000000000000000000000000000000000000.0 -fieldMaxValue 10000000000000000000000000000000000000000.0 -changeCommand ("updatePolyColorSwatch 0") -dragCommand ("updatePolyColorSwatch 0") polyApplyColorGreenValue; // Blue checkBoxGrp -label1 (uiRes("m_performApplyColor.kSetBlue")) -onCommand1 ("disable -value false polyApplyColorBlueValue; updatePolyColorSwatch 0") -offCommand1 ("disable polyApplyColorBlueValue; updatePolyColorSwatch 0") polyApplyColorBlue; floatSliderGrp -label (uiRes("m_performApplyColor.kBlue")) -minValue 0.0 -maxValue 1.0 -fieldMinValue -10000000000000000000000000000000000000000.0 -fieldMaxValue 10000000000000000000000000000000000000000.0 -changeCommand ("updatePolyColorSwatch 0") -dragCommand ("updatePolyColorSwatch 0") polyApplyColorBlueValue; // Alpha checkBoxGrp -label1 (uiRes("m_performApplyColor.kSetAlpha")) -onCommand1 ("disable -v false polyApplyColorAlphaValue1; updatePolyColorSwatch 0") -offCommand1 ("disable polyApplyColorAlphaValue1; updatePolyColorSwatch 0") polyApplyColorAlpha; floatSliderGrp -label (uiRes("m_performApplyColor.kAlphaIndiv")) -minValue 0.0 -maxValue 1.0 -fieldMinValue -10000000000000000000000000000000000000000.0 -fieldMaxValue 10000000000000000000000000000000000000000.0 -changeCommand ("polyApplyColorMatchAlphaValues 0; updatePolyColorSwatch 0") -dragCommand ("polyApplyColorMatchAlphaValues 0; updatePolyColorSwatch 0") polyApplyColorAlphaValue1; setParent $parent; // frameLayout setParent ..; // formLayout // Attach Description/Settings frames to form layout formLayout -edit -attachForm $settingsFrame "top" $gOptionBoxTemplateFrameSpacing -attachForm $settingsFrame "left" $gOptionBoxTemplateFrameSpacing -attachForm $settingsFrame "right" $gOptionBoxTemplateFrameSpacing -attachNone $settingsFrame "bottom" -attachControl $colorValueFrame "top" $gOptionBoxTemplateFrameSpacing $settingsFrame -attachForm $colorValueFrame "left" $gOptionBoxTemplateFrameSpacing -attachForm $colorValueFrame "right" $gOptionBoxTemplateFrameSpacing -attachNone $colorValueFrame "bottom" -attachControl $colorChannelValuesFrame "top" $gOptionBoxTemplateFrameSpacing $colorValueFrame -attachForm $colorChannelValuesFrame "left" $gOptionBoxTemplateFrameSpacing -attachForm $colorChannelValuesFrame "right" $gOptionBoxTemplateFrameSpacing -attachNone $colorChannelValuesFrame "bottom" $parent; //---------------------------------------------------------------------- updatePolyColorSwatch 0; waitCursor -state 0; setUITemplate -popTemplate; string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performApplyColor.kApplyColorButton")) -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_performApplyColor.kApplyColorOptions")) ); // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "ApplyColor" ); eval (($setup + " " + $parent + " " + 0)); showOptionBox(); } proc string assembleCmd() { string $cmd = "polyColorPerVertex"; int $Red = 1; int $Green = 1; int $Blue = 1; int $Alpha = 1; float $RedValue, $GreenValue, $BlueValue, $AlphaValue; int $individual = `optionVar -query polyApplyColorIndivChannels`; if ($individual == 1) { $Red = `optionVar -query polyApplyColorRed`; $Green = `optionVar -query polyApplyColorGreen`; $Blue = `optionVar -query polyApplyColorBlue`; $Alpha = `optionVar -query polyApplyColorAlpha`; $RedValue = `optionVar -query polyApplyColorRedValue`; $GreenValue = `optionVar -query polyApplyColorGreenValue`; $BlueValue = `optionVar -query polyApplyColorBlueValue`; $AlphaValue = `optionVar -query polyApplyColorAlphaValue`; } else { $Red = 1; $Green = 1; $Blue = 1; $Alpha = 1; $RedValue = `optionVar -query polyApplyColorRedValue`; $GreenValue = `optionVar -query polyApplyColorGreenValue`; $BlueValue = `optionVar -query polyApplyColorBlueValue`; $AlphaValue = `optionVar -query polyApplyColorAlphaValue`; } int $Operation = `optionVar -query polyApplyColorOperation`; int $Relative = 0; if ($Operation == 4) $Remove = 1; else { $Remove = 0; // Add relative if ($Operation == 2) $Relative = 1; // Subtract relative else if ($Operation == 3) $Relative = 2; // Replace else { $Relative = 0; } } // If remove, don't worry about the rest // if ($Remove) { $cmd = ($cmd + " -rem "); } else { if (($Red + $Green + $Blue + $Alpha) == 0) { warning ((uiRes("m_performApplyColor.kNoColorChannels"))); $cmd = ""; } else { // Handle case of subtracting color // if ($Relative == 2) { $RedValue = -$RedValue; $GreenValue = -$GreenValue; $BlueValue = -$BlueValue; $AlphaValue = -$AlphaValue; } if ($Red) $cmd = ($cmd + " -r " + $RedValue); if ($Green) $cmd = ($cmd + " -g " + $GreenValue); if ($Blue) $cmd = ($cmd + " -b " + $BlueValue); if ($Alpha) $cmd = ($cmd + " -a " + $AlphaValue); if ($Relative) $cmd = ($cmd + " -rel"); if (`optionVar -q polyAutoShowColorPerVertex`) { $cmd = ($cmd + " -cdo"); } } } $cmd = ($cmd + ";"); return $cmd; } global proc string performApplyColor (int $option) { string $cmd=""; switch ($option) { case 1: // Just the option box polyApplyColorOptions; break; default: setOptionVars(false); $cmd = assembleCmd(); if ($option == 2) return $cmd; if (`optionVar -q polyAutoShowColorPerVertex`) { optionVar -intValue colorShadedDisplay 1 -intValueAppend colorShadedDisplay 1; DisplaySmoothShaded; } evalEcho $cmd; break; } return $cmd; }