// =========================================================================== // 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 string optionVarName(string $input, string $context) { return "gpuCache" + $input + "Option" + $context; } proc string uiItemName(string $input) { return "gpuCache" + $input + "UI"; } proc string getDefaultDirectory(string $context) { string $defaultDirectory; if ($context == "MR") { $defaultDirectory = composeRepresentationDirectory(); } else { if (size(`workspace -fileRuleEntry alembicCache`) == 0) { workspace -fileRule "alembicCache" "cache/alembic"; workspace -saveWorkspace; } $defaultDirectory = `workspace -fileRuleEntry alembicCache`; $defaultDirectory = `workspace -expandName $defaultDirectory`; } return $defaultDirectory; } global proc selectLocationForTextField(string $controlName, string $defaultLocation) { string $captionName = (uiRes("m_gpuCacheOptions.kCaptionName")); string $selectLabel = (uiRes("m_gpuCacheOptions.kSelectLabel")); string $locations[] = `fileDialog2 -caption $captionName -dir $defaultLocation -fileMode 3 -okCaption $selectLabel`; if (size($locations) > 0 && $locations[0] != "") { string $location = fromNativePath($locations[0]); textField -e -text $location $controlName; } } proc resetOptions(int $force, string $context) { if ($force || !`optionVar -exists (optionVarName("cacheDirectory", $context))`) { optionVar -stringValue (optionVarName("cacheDirectory", $context)) (getDefaultDirectory($context)); } string $selectedNodes[] = `ls -selection`; if ($force || !`optionVar -exists (optionVarName("cacheName", $context))`) { optionVar -stringValue (optionVarName("cacheName", $context)) (substituteAllString($selectedNodes[0], "|", "_")); } if ($force || !`optionVar -exists (optionVarName("fileDistribution", $context))`) optionVar -intValue (optionVarName("fileDistribution", $context)) 1; if ($force || !`optionVar -exists (optionVarName("consolidatedShapes", $context))`) optionVar -intValue (optionVarName("consolidatedShapes", $context)) 1; if ($force || !`optionVar -exists (optionVarName("consolidateUnder", $context))`) optionVar -intValue (optionVarName("consolidateUnder", $context)) 1; if ($force || !`optionVar -exists (optionVarName("consolidateUnderText", $context))`) { optionVar -stringValue (optionVarName("consolidateUnderText", $context)) $selectedNodes[0]; } if ($force || !`optionVar -exists (optionVarName("removeDuplicatedShading", $context))`) optionVar -intValue (optionVarName("removeDuplicatedShading", $context)) 0; if ($force || !`optionVar -exists (optionVarName("deleteOriginalGeometry", $context))`) optionVar -intValue (optionVarName("deleteOriginalGeometry", $context)) 1; } proc saveOptions(string $context) { optionVar -stringValue (optionVarName("cacheDirectory", $context)) `textField -q -text (uiItemName("cacheDirectory"))`; optionVar -stringValue (optionVarName("cacheName", $context)) `textFieldGrp -q -text (uiItemName("cacheName"))`; optionVar -intValue (optionVarName("fileDistribution", $context)) `radioButtonGrp -q -sl (uiItemName("fileDistribution"))`; optionVar -intValue (optionVarName("consolidatedShapes", $context)) `radioButtonGrp -q -sl (uiItemName("consolidatedShapes"))`; optionVar -intValue (optionVarName("consolidateUnder", $context)) `checkBoxGrp -q -value1 (uiItemName("consolidateUnder"))`; optionVar -stringValue (optionVarName("consolidateUnderText", $context)) `textFieldGrp -q -text (uiItemName("consolidateUnderText"))`; optionVar -intValue (optionVarName("removeDuplicatedShading", $context)) `checkBoxGrp -q -value1 (uiItemName("removeDuplicatedShading"))`; optionVar -intValue (optionVarName("deleteOriginalGeometry", $context)) `checkBoxGrp -q -value1 (uiItemName("deleteOriginalGeometry"))`; } proc loadOptions(string $context) { textField -e -text (getDefaultDirectory($context)) (uiItemName("cacheDirectory")); string $selectedNodes[] = `ls -selection`; textFieldGrp -e -text (substituteAllString($selectedNodes[0], "|", "_")) (uiItemName("cacheName")); radioButtonGrp -e -select `optionVar -q (optionVarName("fileDistribution", $context))` (uiItemName("fileDistribution")); int $consolidateShapes = `optionVar -q (optionVarName("consolidatedShapes", $context))`; int $consolidateUnder = `optionVar -q (optionVarName("consolidateUnder", $context))`; if ($consolidateShapes) radioButtonGrp -e -sl 1 (uiItemName("consolidatedShapes")); else radioButtonGrp -e -sl 1 (uiItemName("oneGPUCachePerShape")); checkBoxGrp -e -en $consolidateShapes (uiItemName("consolidateUnder")); checkBoxGrp -e -value1 $consolidateUnder (uiItemName("consolidateUnder")); textFieldGrp -e -en ($consolidateShapes && $consolidateUnder) (uiItemName("consolidateUnderText")); textFieldGrp -e -text $selectedNodes[0] (uiItemName("consolidateUnderText")); checkBoxGrp -e -en $consolidateShapes (uiItemName("removeDuplicatedShading")); checkBoxGrp -e -value1 `optionVar -q (optionVarName("removeDuplicatedShading", $context))` (uiItemName("removeDuplicatedShading")); checkBoxGrp -e -value1 `optionVar -q (optionVarName("deleteOriginalGeometry", $context))` (uiItemName("deleteOriginalGeometry")); } proc createUI(string $context) { rowLayout -numberOfColumns 3 -columnWidth 2 212 -columnWidth 3 25 cacheDirectoryLayout; text -label (uiRes("m_gpuCacheOptions.kCacheDirectory")) (uiItemName("cacheDirectoryLabel")); textField (uiItemName("cacheDirectory")); symbolButton -image "navButtonBrowse.png" -command ("selectLocationForTextField " + uiItemName("cacheDirectory") + " \"" + getDefaultDirectory($context) + "\"") (uiItemName("cacheDirectoryButton")); setParent ..; textFieldGrp -label (uiRes("m_gpuCacheOptions.kCacheName")) (uiItemName("cacheName")); radioButtonGrp -visible ($context != "MR") -label (uiRes("m_gpuCacheOptions.kFileDistribution")) -nrb 2 -vr -labelArray2 (uiRes("m_gpuCacheOptions.kOneFile")) (uiRes("m_gpuCacheOptions.kOneFilePerShape")) (uiItemName("fileDistribution")); radioButtonGrp -label (uiRes("m_gpuCacheOptions.kRepresentHierarchyAs")) -numberOfRadioButtons 1 -label1 (uiRes("m_gpuCacheOptions.kConsolidateShapes")) (uiItemName("consolidatedShapes")); checkBoxGrp -visible ($context != "MR") -numberOfCheckBoxes 1 -label1 (uiRes("m_gpuCacheOptions.kConsolidateUnder")) -columnAttach 1 "left" 200 (uiItemName("consolidateUnder")); textFieldGrp -visible ($context != "MR") -label "" -columnAttach 1 "left" 225 (uiItemName("consolidateUnderText")); checkBoxGrp -numberOfCheckBoxes 1 -label1 (uiRes("m_gpuCacheOptions.kRemoveDuplicatedShadingNetworks")) -columnAttach 1 "left" 200 (uiItemName("removeDuplicatedShading")); radioButtonGrp -label "" -numberOfRadioButtons 1 -label1 (uiRes("m_gpuCacheOptions.kOneGPUCachePerShape")) -shareCollection (uiItemName("consolidatedShapes")) (uiItemName("oneGPUCachePerShape")); radioButtonGrp -e -on1 ("checkBoxGrp -e -en true " + uiItemName("consolidateUnder") + "; checkBoxGrp -e -en true " + uiItemName("removeDuplicatedShading")) -of1 ("checkBoxGrp -e -en false " + uiItemName("consolidateUnder") + "; checkBoxGrp -e -en false " + uiItemName("removeDuplicatedShading")) (uiItemName("consolidatedShapes")); checkBoxGrp -e -onCommand ("textFieldGrp -e -en true " + uiItemName("consolidateUnderText")) -offCommand ("textFieldGrp -e -en false " + uiItemName("consolidateUnderText")) (uiItemName("consolidateUnder")); checkBoxGrp -visible ($context != "MR") -numberOfCheckBoxes 1 -label1 (uiRes("m_gpuCacheOptions.kDeleteOriginalGeometry")) (uiItemName("deleteOriginalGeometry")); } proc string assembleCommand(string $context) { // Initialze the options before access resetOptions(0, $context); string $cacheDirectory = `optionVar -q (optionVarName("cacheDirectory", $context))`; string $cacheName = `optionVar -q (optionVarName("cacheName", $context))`; int $fileDistribution = `optionVar -q (optionVarName("fileDistribution", $context))`; int $consolidatedShapes = `optionVar -q (optionVarName("consolidatedShapes", $context))`; int $consolidateUnder = `optionVar -q (optionVarName("consolidateUnder", $context))`; string $consolidateUnderText = `optionVar -q (optionVarName("consolidateUnderText", $context))`; int $removeDupShadingOption = `optionVar -q (optionVarName("removeDuplicatedShading", $context))`; int $deleteOriginalGeometry = `optionVar -q (optionVarName("deleteOriginalGeometry", $context))`; // MR has some restriction on some options if ($context == "MR") { if ($consolidatedShapes == 1) { $consolidateUnder = 1; // During current work process, we use multi-passes to process // multi-hierarchies. So before each pass, please select only the // top node of current hierarchy before calling this method. // TODO: if we switch to single-pass for multi-hierarchies, some changes // may need to be done here. string $selectedNodes[] = `ls -selection`; $consolidateUnderText = $selectedNodes[0]; $fileDistribution = 1; } $deleteOriginalGeometry = 1; } string $command = "gpuCache"; $command = $command + " -directory \"" + $cacheDirectory + "\" "; if ($consolidatedShapes == 1) { if ($consolidateUnder == 1) $command = $command + " -consolidateUnder " + $consolidateUnderText + " "; else $command = $command + " -consolidate "; if ($removeDupShadingOption) $command = "removeDuplicatedShadingNetworksForSelection; " + $command; } if ($deleteOriginalGeometry) $command += " -delete "; return $command; } // Global interface, working as message dispatcher. // UI module for initialize, save, load and access the gpuCache options. global proc string gpuCacheOptions(string $message, string $parameter) { string $result; if ($message == "initialize") resetOptions(0, $parameter); else if ($message == "reset") resetOptions(1, $parameter); else if ($message == "load") loadOptions($parameter); else if ($message == "save") saveOptions($parameter); else if ($message == "createUI") createUI($parameter); else if ($message == "assembleCommand") $result = assembleCommand($parameter); return $result; }