// =========================================================================== // 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: // performPrelight // // Description: // Perform a prelight 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) { if ($forceFactorySettings || !`optionVar -exists polyPrelightByFace`) optionVar -intValue polyPrelightByFace 0; if ($forceFactorySettings || !`optionVar -exists polyPrelightFlat`) optionVar -intValue polyPrelightFlat 0; if ($forceFactorySettings || !`optionVar -exists polyPrelightShadows`) optionVar -intValue polyPrelightShadows 0; if ($forceFactorySettings || !`optionVar -exists polyPrelightForceShadows`) optionVar -intValue polyPrelightForceShadows 1; if ($forceFactorySettings || !`optionVar -exists polyPrelightReuseShadows`) optionVar -intValue polyPrelightReuseShadows 0; if ($forceFactorySettings || !`optionVar -exists polyPrelightLights`) optionVar -intValue polyPrelightLights 0; if ($forceFactorySettings || !`optionVar -exists polyPrelightGeometry`) optionVar -intValue polyPrelightGeometry 0; if ($forceFactorySettings || !`optionVar -exists polyPrelightIgnoreDoubleSided`) optionVar -intValue polyPrelightIgnoreDoubleSided 1; if ($forceFactorySettings || !`optionVar -exists polyPrelightScaleFactor`) optionVar -floatValue polyPrelightScaleFactor 1.0; if ($forceFactorySettings || !`optionVar -exists polyPrelightUnshareUV`) optionVar -intValue polyPrelightUnshareUV 0; if ($forceFactorySettings || !`optionVar -exists polyPrelightAvgColor`) optionVar -intValue polyPrelightAvgColor 0; if ($forceFactorySettings || !`optionVar -exists polyPrelightClampMin`) optionVar -intValue polyPrelightClampMin 0; if ($forceFactorySettings || !`optionVar -exists polyPrelightClampMinRGBA`) { optionVar -floatValue polyPrelightClampMinRGBA 0.0 -floatValueAppend polyPrelightClampMinRGBA 0.0 -floatValueAppend polyPrelightClampMinRGBA 0.0 -floatValueAppend polyPrelightClampMinRGBA 0.0; } if ($forceFactorySettings || !`optionVar -exists polyPrelightClampMax`) optionVar -intValue polyPrelightClampMax 0; if ($forceFactorySettings || !`optionVar -exists polyPrelightClampMaxRGBA`) { optionVar -floatValue polyPrelightClampMaxRGBA 1.0 -floatValueAppend polyPrelightClampMaxRGBA 1.0 -floatValueAppend polyPrelightClampMaxRGBA 1.0 -floatValueAppend polyPrelightClampMaxRGBA 1.0; } if ($forceFactorySettings || !`optionVar -exists polyPrelightDisableTex`) optionVar -intValue polyPrelightDisableTex 0; if ($forceFactorySettings || !`optionVar -exists polyPrelightColorBlend`) optionVar -intValue polyPrelightColorBlend 1; if ($forceFactorySettings || !`optionVar -exists polyPrelightAlphaBlend`) optionVar -intValue polyPrelightAlphaBlend 1; } global proc performPrelightSetup (string $parent, int $forceFactorySettings) { setOptionVars($forceFactorySettings); setParent $parent; int $ival; float $fval; float $vals[]; $ival = `optionVar -query polyPrelightByFace`; checkBoxGrp -edit -value1 $ival polyPrelightByFace; $ival = `optionVar -query polyPrelightFlat`; checkBoxGrp -edit -value1 $ival polyPrelightFlat; $ival = `optionVar -query polyPrelightShadows`; checkBoxGrp -edit -value1 $ival polyPrelightShadows; if ($ival) { disable -v false polyPrelightReuseShadows; disable -v false polyPrelightForceShadows; } else { disable polyPrelightReuseShadows; disable polyPrelightForceShadows; } $ival = `optionVar -query polyPrelightForceShadows`; checkBoxGrp -edit -value1 $ival polyPrelightForceShadows; $ival = `optionVar -query polyPrelightReuseShadows`; checkBoxGrp -edit -value1 $ival polyPrelightReuseShadows; $ival = `optionVar -query polyPrelightLights`; checkBoxGrp -edit -value1 $ival polyPrelightLights; if ($ival) disable -v true polyPrelightDisableTex; else disable -v false polyPrelightDisableTex; $ival = `optionVar -query polyPrelightGeometry`; checkBoxGrp -edit -value1 $ival polyPrelightGeometry; if ($ival) { disable polyPrelightByFace; disable polyPrelightColorBlend; disable polyPrelightAlphaBlend; } else { disable -v false polyPrelightByFace; disable -v false polyPrelightColorBlend; disable -v false polyPrelightAlphaBlend; } $ival = `optionVar -query polyPrelightIgnoreDoubleSided`; checkBoxGrp -edit -value1 $ival polyPrelightIgnoreDoubleSided; $fval = `optionVar -query polyPrelightScaleFactor`; floatFieldGrp -edit -value1 $fval polyPrelightScaleFactor; $ival = `optionVar -query polyPrelightClampMin`; checkBoxGrp -edit -value1 $ival polyPrelightClampMin; if ($ival) disable -v false polyPrelightClampMinRGBA; else disable -v true polyPrelightClampMinRGBA; $vals = `optionVar -query polyPrelightClampMinRGBA`; floatFieldGrp -edit -value1 $vals[0] -value2 $vals[1] -value3 $vals[2] -value4 $vals[3] polyPrelightClampMinRGBA; $ival = `optionVar -query polyPrelightClampMax`; checkBoxGrp -edit -value1 $ival polyPrelightClampMax; if ($ival) disable -v false polyPrelightClampMaxRGBA; else disable -v true polyPrelightClampMaxRGBA; $vals = `optionVar -query polyPrelightClampMaxRGBA`; floatFieldGrp -edit -value1 $vals[0] -value2 $vals[1] -value3 $vals[2] -value4 $vals[3] polyPrelightClampMaxRGBA; $ival = `optionVar -query polyPrelightAvgColor`; checkBoxGrp -edit -value1 $ival polyPrelightAvgColor; $ival = `optionVar -query polyPrelightUnshareUV`; //checkBoxGrp -edit -value1 $ival polyPrelightUnshareUV; $ival = `optionVar -query polyPrelightDisableTex`; checkBoxGrp -edit -value1 $ival polyPrelightDisableTex; $ival = `optionVar -query polyPrelightColorBlend`; optionMenuGrp -edit -sl $ival polyPrelightColorBlend; $ival = `optionVar -query polyPrelightAlphaBlend`; optionMenuGrp -edit -sl $ival polyPrelightAlphaBlend; } global proc performPrelightCallback (string $parent, int $doIt) { setParent $parent; optionVar -intValue polyPrelightGeometry `checkBoxGrp -query -value1 polyPrelightGeometry`; if (`checkBoxGrp -query -value1 polyPrelightGeometry`) { disable polyPrelightByFace; disable polyPrelightColorBlend; disable polyPrelightAlphaBlend; } else { disable -v false polyPrelightByFace; disable -v false polyPrelightColorBlend; disable -v false polyPrelightAlphaBlend; } optionVar -intValue polyPrelightIgnoreDoubleSided `checkBoxGrp -query -value1 polyPrelightIgnoreDoubleSided`; optionVar -intValue polyPrelightByFace `checkBoxGrp -query -value1 polyPrelightByFace`; optionVar -intValue polyPrelightFlat `checkBoxGrp -query -value1 polyPrelightFlat`; optionVar -intValue polyPrelightShadows `checkBoxGrp -query -value1 polyPrelightShadows`; if (`checkBoxGrp -query -value1 polyPrelightShadows`) { disable -v false polyPrelightReuseShadows; disable -v false polyPrelightForceShadows; } else { disable polyPrelightReuseShadows; disable polyPrelightForceShadows; } optionVar -intValue polyPrelightReuseShadows `checkBoxGrp -query -value1 polyPrelightReuseShadows`; optionVar -intValue polyPrelightForceShadows `checkBoxGrp -query -value1 polyPrelightForceShadows`; optionVar -intValue polyPrelightLights `checkBoxGrp -query -value1 polyPrelightLights`; optionVar -floatValue polyPrelightScaleFactor `floatFieldGrp -query -value1 polyPrelightScaleFactor`; optionVar -intValue polyPrelightClampMin `checkBoxGrp -query -value1 polyPrelightClampMin`; optionVar -floatValue polyPrelightClampMinRGBA `floatFieldGrp -query -value1 polyPrelightClampMinRGBA` -floatValueAppend polyPrelightClampMinRGBA `floatFieldGrp -query -value2 polyPrelightClampMinRGBA` -floatValueAppend polyPrelightClampMinRGBA `floatFieldGrp -query -value3 polyPrelightClampMinRGBA` -floatValueAppend polyPrelightClampMinRGBA `floatFieldGrp -query -value4 polyPrelightClampMinRGBA`; optionVar -intValue polyPrelightClampMax `checkBoxGrp -query -value1 polyPrelightClampMax`; optionVar -floatValue polyPrelightClampMaxRGBA `floatFieldGrp -query -value1 polyPrelightClampMaxRGBA` -floatValueAppend polyPrelightClampMaxRGBA `floatFieldGrp -query -value2 polyPrelightClampMaxRGBA` -floatValueAppend polyPrelightClampMaxRGBA `floatFieldGrp -query -value3 polyPrelightClampMaxRGBA` -floatValueAppend polyPrelightClampMaxRGBA `floatFieldGrp -query -value4 polyPrelightClampMaxRGBA`; optionVar -intValue polyPrelightAvgColor `checkBoxGrp -query -value1 polyPrelightAvgColor`; //optionVar -intValue polyPrelightUnshareUV // `checkBoxGrp -query -value1 polyPrelightUnshareUV`; optionVar -intValue polyPrelightIgnoreDoubleSided `checkBoxGrp -query -value1 polyPrelightIgnoreDoubleSided`; optionVar -intValue polyPrelightDisableTex `checkBoxGrp -query -value1 polyPrelightDisableTex`; optionVar -intValue polyPrelightColorBlend `optionMenuGrp -query -sl polyPrelightColorBlend`; optionVar -intValue polyPrelightAlphaBlend `optionMenuGrp -query -sl polyPrelightAlphaBlend`; if ($doIt) { performPrelight 0; addToRecentCommandQueue "performPrelight 0" "Prelight"; } } proc polyPrelightOptions() { // Global template variables for form spacing global int $gOptionBoxTemplateFrameSpacing; // Global from setDefaultTemplates.mel global int $gSingleWidgetWidthIndex; int $minMaxWidth = ($gSingleWidgetWidthIndex * 3) / 4; string $commandName = "performPrelight"; string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); string $layout = getOptionBox(); setParent $layout; setUITemplate -pushTemplate OptionBoxTemplate; waitCursor -state 1; scrollLayout; // Form layout string $parent = `formLayout prelightOptions`; // Sampling options frame string $samplingOptionsFrame = `frameLayout -label (uiRes("m_performPrelight.kSamplingOptionsFrame"))`; columnLayout; // Sample by face checkBoxGrp -label1 (uiRes("m_performPrelight.kSampleSelected")) polyPrelightByFace; // Store per face checkBoxGrp -label1 (uiRes("m_performPrelight.kSampleusingNormals")) polyPrelightFlat; // Compute shadows checkBoxGrp -label1 (uiRes("m_performPrelight.kComputeShadowMaps")) -on1 ("disable -v false polyPrelightReuseShadows; disable -v false polyPrelightForceShadows;") -of1 ("disable polyPrelightReuseShadows; disable polyPrelightForceShadows;") polyPrelightShadows; checkBoxGrp -label1 (uiRes("m_performPrelight.kForceShadowMapsOnLights")) polyPrelightForceShadows; checkBoxGrp -label1 (uiRes("m_performPrelight.kReuseComputedShadowMaps")) polyPrelightReuseShadows; // Disable textures checkBoxGrp -label1 (uiRes("m_performPrelight.kIgnoreMappedChannels")) polyPrelightDisableTex; // Lights only checkBoxGrp -label1 (uiRes("m_performPrelight.kSampleIncomingIllumination")) -on1 ("disable -v true polyPrelightDisableTex") -of1 ("disable -v false polyPrelightDisableTex") polyPrelightLights; // Displace geometry. Turn off flat shading checkBoxGrp -label1 (uiRes("m_performPrelight.kDisplaceGeom")) -on1 ("disable polyPrelightByFace; disable polyPrelightColorBlend; disable polyPrelightAlphaBlend;") -of1 ("disable -v false polyPrelightByFace; disable -v false polyPrelightColorBlend; disable -v false polyPrelightAlphaBlend;") polyPrelightGeometry; checkBoxGrp -label1 (uiRes("m_performPrelight.kIgnoreDoubleSided")) polyPrelightIgnoreDoubleSided; setParent ..; // columnLayout setParent $parent; // frameLayout // Storage options frame string $storageOptionsFrame = `frameLayout -label (uiRes("m_performPrelight.kStorageOptionsFrame"))`; columnLayout; // Average colors checkBoxGrp -label1 (uiRes("m_performPrelight.kStoreSharedValues")) polyPrelightAvgColor; // scale factor floatFieldGrp -label (uiRes("m_performPrelight.kSampleScaleFactor")) polyPrelightScaleFactor; // Clamping options checkBoxGrp -label1 (uiRes("m_performPrelight.kClampMinRGBA")) -on1 ("disable -v false polyPrelightClampMinRGBA") -of1 ("disable -v true polyPrelightClampMinRGBA") polyPrelightClampMin; floatFieldGrp -label (uiRes("m_performPrelight.kMin")) -numberOfFields 4 -precision 3 -columnWidth 2 $minMaxWidth -columnWidth 3 $minMaxWidth -columnWidth 4 $minMaxWidth -columnWidth 5 $minMaxWidth polyPrelightClampMinRGBA; checkBoxGrp -label1 (uiRes("m_performPrelight.kClampMaxRGBA")) -on1 ("disable -v false polyPrelightClampMaxRGBA") -of1 ("disable -v true polyPrelightClampMaxRGBA") polyPrelightClampMax; floatFieldGrp -label (uiRes("m_performPrelight.kMax")) -numberOfFields 4 -precision 3 -columnWidth 2 $minMaxWidth -columnWidth 3 $minMaxWidth -columnWidth 4 $minMaxWidth -columnWidth 5 $minMaxWidth polyPrelightClampMaxRGBA; // Color Blend options optionMenuGrp -label (uiRes("m_performPrelight.kColorBlending")) polyPrelightColorBlend; menuItem -label (uiRes("m_performPrelight.kColorOverwrite")); menuItem -label (uiRes("m_performPrelight.kColorAdd")); menuItem -label (uiRes("m_performPrelight.kColorSubtract")); menuItem -label (uiRes("m_performPrelight.kColorMultiply")); menuItem -label (uiRes("m_performPrelight.kColorDivide")); menuItem -label (uiRes("m_performPrelight.kColorAverage")); menuItem -label (uiRes("m_performPrelight.kColorDontOverwrite")); setParent -menu ..; optionMenuGrp -label (uiRes("m_performPrelight.kAlphaBlending")) polyPrelightAlphaBlend; menuItem -label (uiRes("m_performPrelight.kAlphaOverwrite")); menuItem -label (uiRes("m_performPrelight.kAlphaAdd")); menuItem -label (uiRes("m_performPrelight.kAlphaSubtract")); menuItem -label (uiRes("m_performPrelight.kAlphaMultiply")); menuItem -label (uiRes("m_performPrelight.kAlphaDivide")); menuItem -label (uiRes("m_performPrelight.kAlphaAverage")); menuItem -label (uiRes("m_performPrelight.kAlphaDontOverwrite")); setParent -menu ..; setParent ..; // columnLayout setParent $parent; // frameLayout setParent ..; // formLayout // Attach frames to form layout formLayout -e -af $samplingOptionsFrame "top" $gOptionBoxTemplateFrameSpacing -af $samplingOptionsFrame "left" $gOptionBoxTemplateFrameSpacing -af $samplingOptionsFrame "right" $gOptionBoxTemplateFrameSpacing -an $samplingOptionsFrame "bottom" -ac $storageOptionsFrame "top" $gOptionBoxTemplateFrameSpacing $samplingOptionsFrame -af $storageOptionsFrame "left" $gOptionBoxTemplateFrameSpacing -af $storageOptionsFrame "right" $gOptionBoxTemplateFrameSpacing -af $storageOptionsFrame "bottom" $gOptionBoxTemplateFrameSpacing $parent; waitCursor -state 0; setUITemplate -popTemplate; string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performPrelight.kPrelightButton")) -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_performPrelight.kPrelightOptions")) ); // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "Prelight" ); eval (($setup + " " + $parent + " " + 0)); showOptionBox(); } global proc string performPrelight (int $option) { string $cmd=""; string $sel[]; switch ($option) { case 1: polyPrelightOptions; // Just the option box break; default: setOptionVars(false); int $byFace = `optionVar -query polyPrelightByFace`; int $flat = `optionVar -query polyPrelightFlat`; int $shadows = `optionVar -query polyPrelightShadows`; int $fshadows = `optionVar -query polyPrelightForceShadows`; int $rshadows = `optionVar -query polyPrelightReuseShadows`; int $lights = `optionVar -query polyPrelightLights`; int $geom = `optionVar -query polyPrelightGeometry`; int $ignoreDoubleSided = `optionVar -query polyPrelightIgnoreDoubleSided`; float $scale = `optionVar -query polyPrelightScaleFactor`; int $clampMin = `optionVar -query polyPrelightClampMin`; int $clampMax = `optionVar -query polyPrelightClampMax`; float $minColor[], $maxColor[]; int $avgColor = `optionVar -query polyPrelightAvgColor`; int $disableTextures = `optionVar -query polyPrelightDisableTex`; int $colorBlend = `optionVar -query polyPrelightColorBlend`; int $alphaBlend = `optionVar -query polyPrelightAlphaBlend`; if ($clampMin) { $minColor = `optionVar -query polyPrelightClampMinRGBA`; } if ($clampMax) { $maxColor = `optionVar -query polyPrelightClampMaxRGBA`; } if ($disableTextures && ($lights == 0)) { $cmd = "toggleMaterialMapping(0);"; } else $cmd = ""; $cmd = ($cmd + "polyGeoSampler"); // If displace, no by face option // if ($geom) { $cmd = ($cmd + " -dg"); } else { if ($scale < 0.0) $scale = 1.0; if ($byFace) $cmd = ($cmd + " -bf"); } if ($ignoreDoubleSided) { $cmd = ($cmd + " -ids"); } // If shadows, then allow reuse, and force if ($shadows) { $cmd = ($cmd + " -cs"); if (!$fshadows) $cmd = ($cmd + " -ul"); if ($rshadows) $cmd = ($cmd + " -rs"); } // Check for lights only if ($lights) $cmd = ($cmd + " -lo"); // Check for flat if ($flat) $cmd = ($cmd + " -fs"); // Check scale $cmd = ($cmd + " -sf " + $scale); // Check clamp if ($clampMin) $cmd = ($cmd + " -cmn " + $minColor[0] + " " + $minColor[1] + " " + $minColor[2] + " -amn " + $minColor[3]); if ($clampMax) $cmd = ($cmd + " -cmx " + $maxColor[0] + " " + $maxColor[1] + " " + $maxColor[2] + " -amx " + $maxColor[3]); // Check shared storage if ($avgColor) $cmd = ($cmd + " -ac"); $cmd = ($cmd + " -su"); if (`optionVar -q polyAutoShowColorPerVertex`) { // set the display options on the mesh. $cmd = ($cmd + " -cdo"); } // Check for color blend, of not geometry // mapping. if (!$geom) { string $cblend = "\"overwrite\""; if ($colorBlend == 2) $cblend = "\"add\""; else if ($colorBlend == 3) $cblend = "\"subtract\""; else if ($colorBlend == 4) $cblend = "\"multiply\""; else if ($colorBlend == 5) $cblend = "\"divide\""; else if ($colorBlend == 6) $cblend = "\"average\""; else if ($colorBlend == 7) $cblend = "\"none\""; string $ablend = "\"overwrite\""; if ($alphaBlend == 2) $ablend = "\"add\""; else if ($alphaBlend == 3) $ablend = "\"subtract\""; else if ($alphaBlend == 4) $ablend = "\"multiply\""; else if ($alphaBlend == 5) $ablend = "\"divide\""; else if ($alphaBlend == 6) $ablend = "\"average\""; else if ($alphaBlend == 7) $ablend = "\"none\""; $cmd = ($cmd + " -colorBlend " + $cblend + " -alphaBlend " + $ablend); } $cmd = ($cmd + ";"); if ($disableTextures && ($lights == 0)) { $cmd = ($cmd + " toggleMaterialMapping(1);"); } if ($option == 0) { if (`optionVar -q polyAutoShowColorPerVertex`) { optionVar -intValue colorShadedDisplay 1 -intValueAppend colorShadedDisplay 1; DisplaySmoothShaded; } evalEcho $cmd; } break; } return $cmd; }