// =========================================================================== // 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. // =========================================================================== proc buildPsdConvertSolidTxWindowMenu () // // Procedure Name: // buildPsdConvertSolidTxWindowMenu // // Description: // Creates the menus for the ConvertSolidTx Window // // Input Arguments: // None. // // Return Value: // None. // { global string $psdConvSolidTxWindow; menu -label (uiRes("m_psdConvertSolidTxPanel.kEdit")) -tearOff true -postMenuCommandOnce true; menuItem -label (uiRes("m_psdConvertSolidTxPanel.kResetSettings")) -command ("psdConvertSolidTxResetSettingsCmd"); menuItem -label (uiRes("m_psdConvertSolidTxPanel.kSaveSettings")) -command ("psdConvertSolidTxSaveSettingsCmd"); setParent -menu ..; } global proc psdConvertSolidTxResetSettingsCmd() { global string $psdChannelControl; psdConvSolidTxOptions -e -resetAll; psdChannelSelectCmd(); } global proc psdConvertSolidTxSaveSettingsCmd() { } global proc psdControlChangeCallback(string $controlName) { global string $psdconvertSolidTxAntiAlias, $psdConvertSolidBckMode, $psdConvertSolidTxFillTextureSeams, $psdConvertSolidTxSamplePlane, $psdConvertSolidBckColor, $psdConvertSolidTxBakeAlpha, $psdChannelControl; string $selectedItem[] = `psdChannelOutliner -q -selectItem $psdChannelControl`; int $value = 0, $index; for($index = 0; $index < size($selectedItem); $index++) { switch($controlName) { case "psdconvertSolidTxAntiAlias": $value = `checkBoxGrp -q -value1 $psdconvertSolidTxAntiAlias`; psdConvSolidTxOptions -e -channelString $selectedItem[$index] -antiAlias $value; break; case "psdConvertSolidTxFillTextureSeams": $value = `checkBoxGrp -q -value1 $psdConvertSolidTxFillTextureSeams`; psdConvSolidTxOptions -e -channelString $selectedItem[$index] -fillTextureSeams $value; break; case "psdConvertSolidTxSamplePlane": $value = `checkBoxGrp -q -value1 $psdConvertSolidTxSamplePlane`; psdConvSolidTxOptions -e -channelString $selectedItem[$index] -bakeUsingVirtualPlane $value; break; case "psdConvertSolidTxBakeAlpha": $value = `checkBoxGrp -q -value1 $psdConvertSolidTxBakeAlpha`; psdConvSolidTxOptions -e -channelString $selectedItem[$index] -bakeTransparency $value; break; case "psdConvertSolidBckMode": string $bgMode = `optionMenuGrp -q -value $psdConvertSolidBckMode`; performPsdConvertSolidBackModeCB(); psdConvSolidTxOptions -e -channelString $selectedItem[$index] -backgroundMode $bgMode; break; case "psdConvertSolidBckColor": float $bgColor[] = `colorSliderGrp -q -rgbValue $psdConvertSolidBckColor`; psdConvSolidTxOptions -e -channelString $selectedItem[$index] -backgroundColor $bgColor[0] $bgColor[1] $bgColor[2]; break; } } psdConvSolidTxOptions -e -saveAll; } proc string psdBgMode_melToUI( string $mel ) { string $ui = $mel; string $default = (uiRes("m_psdConvertSolidTxPanel.kShaderDefault")); string $custom = (uiRes("m_psdConvertSolidTxPanel.kCustomColor")); string $extend = (uiRes("m_psdConvertSolidTxPanel.kExtendEdgeColor")); if( $mel == "Shader default" ) { $ui = $default; } else if( $mel == "Custom color" ) { $ui = $custom; } else if( $mel == "Extend Edge Color" ) { $ui = $extend; } else { uiToMelMsg( "psdBgMode_melToUI", $mel, 1 ); } return $ui; } proc psdInitializeConvSolidTxValues(string $channelAttribute) { global string $psdconvertSolidTxAntiAlias, $psdConvertSolidBckMode, $psdConvertSolidTxFillTextureSeams, $psdConvertSolidTxSamplePlane, $psdConvertSolidBckColor, $psdConvertSolidTxBakeAlpha; psdConvSolidTxOptions -e -channelString $channelAttribute -antiAlias false -backgroundMode "Shader default" -backgroundColor 0 0 0 -fillTextureSeams true -bakeUsingVirtualPlane true -bakeTransparency false; checkBoxGrp -e -value1 off $psdconvertSolidTxAntiAlias; optionMenuGrp -e -value (psdBgMode_melToUI("Shader default")) $psdConvertSolidBckMode; colorSliderGrp -e -rgb 0 0 0 $psdConvertSolidBckColor; checkBoxGrp -e -value1 on $psdConvertSolidTxFillTextureSeams; checkBoxGrp -e -value1 off $psdConvertSolidTxSamplePlane; checkBoxGrp -e -value1 off $psdConvertSolidTxBakeAlpha; } proc psdDisplaySwatchImage(string $connectedAttribute) { global string $psdSwatchPort, $psdTextureName; string $tokens[]; tokenize $connectedAttribute "." $tokens; // Replace bump with normalCamera for getting the connections. string $connections[] ; if($tokens[size($tokens)-1] == "bump"){ $connectedAttribute = $tokens[0] + "." + "normalCamera"; $connections = `listConnections $connectedAttribute`; $connectedAttribute = $connections[0] + ".bumpValue"; } if ($tokens[size($tokens)-1] == "displacement"){ $connectedChannel = $tokens[0] + ".outColor" ; $connections = `listConnections -destination on -source off $connectedChannel`; // The default lambert material's outColor is connected to both initialShadingGroup and // initialParticleSE. We need to take the displacement attribute of initialShadingGroup // only. if(size($connections) > 1){ int $index; for($index = 0; $index < size($connections); $index++) { if(`nodeType $connections[$index]` == "shadingEngine"){ $connections[0] = $connections[$index]; } } } $connectedAttribute = $connections[0] + ".displacementShader" ; } string $connectedTextures = `connectionInfo -sourceFromDestination $connectedAttribute`; if(size($connectedTextures) > 0) { tokenize $connectedTextures "." $tokens; swatchDisplayPort -e -shadingNode $tokens[0] $psdSwatchPort; text -e -label $tokens[0] $psdTextureName; } } proc psdAddChannelAttributes(string $channelAttributes[]) { global string $psdChannelControl, $psdSwatchPort ; int $index, $numTokens; string $tokens[]; psdChannelOutliner -e -removeAll $psdChannelControl ; psdConvSolidTxOptions -e -deleteAll; string $imageFileName; for($index < 0; $index < size($channelAttributes); $index++) { $numTokens = `tokenize $channelAttributes[$index] "." $tokens`; $imageFileName = psdCheckConnectionsForChannel($channelAttributes[$index]); psdInitializeConvSolidTxValues($channelAttributes[$index]); // Add the items for the channelOutliner control. psdChannelOutliner -e -psdParent $tokens[0] -addChild $tokens[$numTokens -1] $imageFileName $psdChannelControl ; } // Keep the first one selected and assgn the attributes to them. psdChannelOutliner -e -select $channelAttributes[0] $psdChannelControl; psdDisplaySwatchImage($channelAttributes[0]); } global proc performPsdConvertSolidBackModeCB() { int $isBackColor = `optionMenuGrp -q -sl psdConvertSolidBckMode`; disable -v ($isBackColor != 2) psdConvertSolidBckColor; } global proc psdChannelSelectCmd() { global string $psdChannelControl; global string $psdconvertSolidTxAntiAlias, $psdConvertSolidBckMode, $psdConvertSolidTxFillTextureSeams, $psdConvertSolidTxSamplePlane, $psdConvertSolidBckColor, $psdConvertSolidTxBakeAlpha; string $selectedItem[] = `psdChannelOutliner -q -selectItem $psdChannelControl`; int $antiAliasFlag = `psdConvSolidTxOptions -channelString $selectedItem[0] -q -antiAlias`; int $fillTxFlag = `psdConvSolidTxOptions -channelString $selectedItem[0] -q -fillTextureSeams`; int $bakeVirtualPlane = `psdConvSolidTxOptions -channelString $selectedItem[0] -q -bakeUsingVirtualPlane`; int $transFlag = `psdConvSolidTxOptions -channelString $selectedItem[0] -q -bakeTransparency`; string $bgMode = `psdConvSolidTxOptions -channelString $selectedItem[0] -q -backgroundMode`; float $bgColor[] = `psdConvSolidTxOptions -channelString $selectedItem[0] -q -backgroundColor`; checkBoxGrp -e -value1 $antiAliasFlag $psdconvertSolidTxAntiAlias; optionMenuGrp -e -value (psdBgMode_melToUI($bgMode)) $psdConvertSolidBckMode; colorSliderGrp -e -rgb $bgColor[0] $bgColor[1] $bgColor[2] $psdConvertSolidBckColor; checkBoxGrp -e -value1 $fillTxFlag $psdConvertSolidTxFillTextureSeams; checkBoxGrp -e -value1 $bakeVirtualPlane $psdConvertSolidTxSamplePlane; checkBoxGrp -e -value1 $transFlag $psdConvertSolidTxBakeAlpha; psdDisplaySwatchImage( $selectedItem[0]); } global proc psdConvertSolidTxCloseCmd() { global string $psdConvSolidTxWindow ; window -e -visible false $psdConvSolidTxWindow; } global proc psdConvertSolidTxApplyCmd() { global string $psdConvSolidTxWindow ; psdConvSolidTxOptions -e -saveAll; window -e -visible false $psdConvSolidTxWindow; } global proc psdConvertSolidTxPanel(string $channelAttributes[]) { global string $psdConvSolidTxWindow, $psdSwatchPort, $psdTextureName ; global string $psdChannelControl, $psdApplyButton, $psdCloseButton ; global string $psdconvertSolidTxAntiAlias, $psdConvertSolidBckMode, $psdConvertSolidTxFillTextureSeams, $psdConvertSolidTxSamplePlane, $psdConvertSolidBckColor, $psdConvertSolidTxBakeAlpha; if(`window -exists "psdConvSolidTxWindow"`) { showWindow $psdConvSolidTxWindow; window -e -visible true $psdConvSolidTxWindow; }else{ $psdConvSolidTxWindow = `window -ret -h 300 -w 550 -title (uiRes("m_psdConvertSolidTxPanel.kPSDConvertSolidTextures")) psdConvSolidTxWindow`; string $texMenubar = `menuBarLayout texMenubarLayout`; string $topForm = `formLayout -p $texMenubar -numberOfDivisions 100 topForm`; $psdApplyButton = `button -p $topForm -label (uiRes("m_psdConvertSolidTxPanel.kApply")) -command "psdConvertSolidTxApplyCmd" psdApplyButton`; $psdCloseButton = `button -p $topForm -label (uiRes("m_psdConvertSolidTxPanel.kClose")) -command "psdConvertSolidTxCloseCmd" psdCloseButton`; string $leftForm = `formLayout -numberOfDivisions 100 leftForm`; $psdChannelControlLabel = `text -label (uiRes("m_psdConvertSolidTxPanel.kConnectedAttributes")) psdChannelControlLabel`; $psdChannelControl = `psdChannelOutliner -height 125 -selectCommand "psdChannelSelectCmd" psdChannelControl`; formLayout -e -attachForm $psdChannelControlLabel "left" 5 -attachForm $psdChannelControlLabel "right" 5 -attachForm $psdChannelControlLabel "top" 2 -attachForm $psdChannelControl "left" 5 -attachForm $psdChannelControl "right" 5 -attachControl $psdChannelControl "top" 2 $psdChannelControlLabel -attachForm $psdChannelControl "bottom" 5 $leftForm; setParent .. ; string $swatchPortForm = `formLayout -numberOfDivisions 100 swatchPortForm`; text -label (uiRes("m_psdConvertSolidTxPanel.kTextureSample")) psdTextureSampleLabel; $psdSwatchPort = `swatchDisplayPort -wh 64 64 swatchPort`; $psdTextureName = `text -label "" -font "boldLabelFont" psdTextureName`; separator -height 15 swatchSeparator; formLayout -e -attachForm psdTextureSampleLabel "left" 60 -attachForm psdTextureSampleLabel "top" 35 -attachForm psdTextureSampleLabel "bottom" 20 -attachForm swatchPort "left" 140 -attachForm swatchPort "top" 10 -attachForm swatchPort "bottom" 20 -attachControl psdTextureName "left" 5 swatchPort -attachForm psdTextureName "top" 35 -attachForm psdTextureName "bottom" 40 -attachForm swatchSeparator "left" 0 -attachForm swatchSeparator "right" 0 -attachControl swatchSeparator "top" 3 swatchPort $swatchPortForm ; setParent ..; string $rightColumn =`columnLayout -adjustableColumn 1`; $psdconvertSolidTxAntiAlias = `checkBoxGrp -label "" -label1 (uiRes("m_psdConvertSolidTxPanel.kAntialias")) -numberOfCheckBoxes 1 -value1 off -changeCommand ("psdControlChangeCallback psdconvertSolidTxAntiAlias" ) psdconvertSolidTxAntiAlias`; $psdConvertSolidBckMode = `optionMenuGrp -label (uiRes("m_psdConvertSolidTxPanel.kBackgroundMode")) -cal 1 "right" -changeCommand ("psdControlChangeCallback psdConvertSolidBckMode") psdConvertSolidBckMode`; menuItem -label (psdBgMode_melToUI("Shader default")); menuItem -label (psdBgMode_melToUI("Custom color")); menuItem -label (psdBgMode_melToUI("Extend Edge Color")); $psdConvertSolidBckColor = `colorSliderGrp -label (uiRes("m_psdConvertSolidTxPanel.kBackgroundColor")) -rgb 0 0 0 -changeCommand ("psdControlChangeCallback psdConvertSolidBckColor") psdConvertSolidBckColor`; disable -v true psdConvertSolidBckColor; separator -height 15; $psdConvertSolidTxFillTextureSeams = `checkBoxGrp -label "" -label1 (uiRes("m_psdConvertSolidTxPanel.kFillTextureSeams")) -cw 2 180 -numberOfCheckBoxes 1 -value1 on -changeCommand ("psdControlChangeCallback psdConvertSolidTxFillTextureSeams") psdConvertSolidTxFillTextureSeams`; $psdConvertSolidTxSamplePlane = `checkBoxGrp -label "" -label1 (uiRes("m_psdConvertSolidTxPanel.kBakeUsingVirtualPlane")) -cw 2 180 -numberOfCheckBoxes 1 -value1 off -changeCommand ("psdControlChangeCallback psdConvertSolidTxSamplePlane") psdConvertSolidTxSamplePlane`; $psdConvertSolidTxBakeAlpha = `checkBoxGrp -label "" -label1 (uiRes("m_psdConvertSolidTxPanel.kBakeTransparency")) -cw 2 180 -numberOfCheckBoxes 1 -value1 off -changeCommand ("psdControlChangeCallback psdConvertSolidTxBakeAlpha") psdConvertSolidTxBakeAlpha`; setParent .. ; formLayout -e -attachForm $leftForm "left" 5 -attachForm $leftForm "top" 5 -attachPosition $leftForm "right" 2 30 -attachForm $leftForm "bottom" 34 -attachForm $swatchPortForm "top" 0 -attachForm $swatchPortForm "right" 0 -attachControl $swatchPortForm "left" 0 $leftForm -attachForm $rightColumn "right" 0 -attachControl $rightColumn "top" 0 $swatchPortForm -attachControl $rightColumn "left" 0 $leftForm -attachForm $psdApplyButton "left" 5 -attachPosition $psdApplyButton "right" 2 50 -attachForm $psdApplyButton "bottom" 5 -attachControl $psdApplyButton "top" 2 $leftForm -attachControl $psdCloseButton "left" 2 $psdApplyButton -attachPosition $psdCloseButton "right" 2 99 -attachForm $psdCloseButton "bottom" 5 -attachControl $psdCloseButton "top" 2 $leftForm $topForm; setParent ..; buildPsdConvertSolidTxWindowMenu; showWindow $psdConvSolidTxWindow; window -e -visible true $psdConvSolidTxWindow; } psdAddChannelAttributes($channelAttributes); }