// =========================================================================== // 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: 2005 // // Description: // This script provides an option box dialog for the geometry cache. // // // This string is used as an optionVar value for the cache // directory when we want to indicate that the preference is to // use the current project's cache directory. The file // works the same way, with the default being to use the name of the // selected object. // global string $gGeomCacheCurrentProject = "CurrentProject"; global string $gGeomCacheAutomaticName = "Automatic"; global string $gGeomCacheSceneNameForPrefs = ""; proc string[] pluginCacheFormats() { string $formats[] = {"mcx","mcc"}; // This is the default, built in format string $plugins[] = `pluginInfo -q -ls`; // Get all loaded plugins for( $i = 0; $i < size($plugins); $i++ ) { string $pluginFormats[] = `pluginInfo -q -cacheFormat $plugins[$i]`; appendStringArray( $formats, $pluginFormats, size( $pluginFormats )); } return $formats; } global proc cacheSetDirOptionVar() // // Set the optionVar based on the user's entry in the option box // { global string $gGeomCacheCurrentProject; global string $gGeomCacheSceneNameForPrefs; if ( `textFieldGrp -q -en cacheDir` ) { string $value = `textFieldGrp -q -tx cacheDir`; if ( $value != "" ) { verifyWorkspaceFileRule( "fileCache", "cache/nCache" ); string $currentProj = (`workspace -q -fre "fileCache"` ); $currentProj = `workspace -en $currentProj`; $currentProj += "/"; if ($currentProj == $value) { $value = $gGeomCacheCurrentProject; } optionVar -sv geomCacheDirName $value; $gGeomCacheSceneNameForPrefs = `file -q -loc`; } else { optionVar -sv geomCacheDirName $gGeomCacheCurrentProject; } } } global proc int cacheSetDirectory( string $dir, string $type ) { textFieldGrp -e -tx $dir cacheDir; cacheSetDirOptionVar(); return 1; } global proc cacheBrowseForFolder() { string $cmd = "cacheSetDirectory "; string $action = (uiRes("m_performCreateGeometryCache.kSetDir")); string $startInDir; $startInDir = `textFieldGrp -q -tx cacheDir`; if ( size( $startInDir ) == 0 ) { $startInDir = `internalVar -uwd`; } if ( `file -q -ex $startInDir` ) { workspace -dir $startInDir; } fileBrowser( $cmd, $action, "", 4 ); } global proc disableGeomDiskCacheAttrs(string $parent) { setParent $parent; int $showStartEnd = `radioButtonGrp -query -sl geomCacheTimeRange3`; if( $showStartEnd ) { floatFieldGrp -e -enable true geomCacheStartEndTime; } else { floatFieldGrp -e -enable false geomCacheStartEndTime; } } global proc geomFormatChanged() // // Menu callback // { $value = `optionMenuGrp -q -v formatMenu`; optionVar -sv geomCacheFormat $value; string $optName = `optionVar -q geomCacheFormat`; } global proc geomDistributionChanged() // // Enables/disables cacheName field depending on whether // OneFilePerFrame or OneFile is chosen and/or the number // of selected objects. // { int $numShapes = size( getGeometriesToCache() ); int $oneFilePerFrame = `radioButtonGrp -q -sl geomCacheDist1`; int $perGeom = ($numShapes > 1) && `checkBoxGrp -q -value1 cachePerGeometry`; optionVar -intValue geomCachePerGeometry $perGeom; checkBoxGrp -e -enable ($numShapes > 1) cachePerGeometry; // disable the prefix box if there isn't a single object name // to prefix it to. (ie. OneFile, all geometry in one file) int $prefix = `checkBoxGrp -q -value1 useAsPrefix`; checkBoxGrp -e -enable ($oneFilePerFrame || $perGeom) useAsPrefix; // cache name field is disabled only if we are caching more // than one object per geometry and prefix is not going to be used. textFieldGrp -e -enable (!$perGeom || $prefix) cacheName; setCacheName(); } global proc geomCacheNameChanged() // // User has specified a cache name, so we no longer need to // update based on selected objects // { if( !`textFieldGrp -exists cacheName` ) return; // Make sure cache name in option var can't be cleared. // It must remain set to gGeomCacheAutomaticName string $name = `textFieldGrp -query -text cacheName`; if ( $name == "" ) return; // Since this is called on every add, make sure that // the cache name was actually set before changing the // option var. // global string $gGeomCacheAutomaticName; string $optName = `optionVar -q geomCacheName`; if( $optName == $gGeomCacheAutomaticName ) { string $autoName = getAutomaticCacheName(); if( $name == $autoName ) return; } global string $gGeomCacheSceneNameForPrefs; optionVar -sv geomCacheName $name; $gGeomCacheSceneNameForPrefs = `file -q -loc`; } global proc setCacheName() // // Sets the name of the cache based on the object name. If more than // one object selected, and user hasn't given us a prefix, // { global string $gGeomCacheAutomaticName; string $name = `optionVar -q geomCacheName`; if ($name == $gGeomCacheAutomaticName) { $name = getAutomaticCacheName(); } textFieldGrp -e -text $name cacheName; } proc setOptionVars(int $forceFactorySettings) { global string $gGeomCacheCurrentProject; global string $gGeomCacheAutomaticName; global string $gGeomCacheSceneNameForPrefs; string $currSceneName = `file -q -loc`; if ($currSceneName != $gGeomCacheSceneNameForPrefs) { // We only want the cache name and directory name prefs to exist // for the time that the scene is opened. We don't want them // to be saved for the next session or next scene. // optionVar -rm geomCacheDirName; optionVar -rm geomCacheName; } if( $forceFactorySettings || !`optionVar -exists geomRefresh` ) optionVar -intValue geomRefresh 1; if( $forceFactorySettings || !`optionVar -exists geomCacheDistrib`) optionVar -intValue geomCacheDistrib 1; if( $forceFactorySettings || !`optionVar -exists geomCacheTimeRange`) optionVar -intValue geomCacheTimeRange 2; if( $forceFactorySettings || !`optionVar -exists geomCacheStartTime`) optionVar -floatValue geomCacheStartTime 1; if( $forceFactorySettings || !`optionVar -exists geomCacheEndTime`) optionVar -floatValue geomCacheEndTime 10; if( $forceFactorySettings || !`optionVar -exists geomCacheFormat`) optionVar -stringValue geomCacheFormat "mcx"; if( $forceFactorySettings || !`optionVar -exists geomCacheDirName`) { optionVar -sv geomCacheDirName $gGeomCacheCurrentProject; } if( $forceFactorySettings || !`optionVar -exists geomCacheName` ) { optionVar -stringValue geomCacheName $gGeomCacheAutomaticName; } if( $forceFactorySettings || !`optionVar -exists geomCachePerGeometry` ) optionVar -intValue geomCachePerGeometry 1; if( $forceFactorySettings || !`optionVar -exists cacheAsFloats` ) optionVar -intValue cacheAsFloats 1; if( $forceFactorySettings || !`optionVar -exists cacheInWorld` ) optionVar -intValue cacheInWorld 0; if( $forceFactorySettings || !`optionVar -exists geomCacheSimulationRate`) optionVar -floatValue geomCacheSimulationRate 1; if( $forceFactorySettings || !`optionVar -exists geomCacheMergeDelete`) optionVar -intValue geomCacheMergeDelete 0; if( $forceFactorySettings || !`optionVar -exists geomCacheSampleMultiplier`) optionVar -intValue geomCacheSampleMultiplier 1; if( $forceFactorySettings || !`optionVar -exists geomCacheInheritModifications`) optionVar -intValue geomCacheInheritModifications 0; } global proc geomCacheSetup (string $parent, int $forceFactorySettings) { global string $gGeomCacheCurrentProject; setOptionVars($forceFactorySettings); setParent $parent; // checkBoxGrp -e -v1 `optionVar -q geomRefresh` geomRefreshBox; string $cacheFormat = `optionVar -q geomCacheFormat`; optionMenuGrp -e -v $cacheFormat formatMenu; int $distOpt = `optionVar -query geomCacheDistrib`; if ($distOpt == 1) { radioButtonGrp -e -sl 1 geomCacheDist1; } else if ($distOpt == 2) { radioButtonGrp -e -sl 1 geomCacheDist2; } geomDistributionChanged(); int $timeOpt = `optionVar -query geomCacheTimeRange`; if ($timeOpt == 1) { radioButtonGrp -e -sl 1 geomCacheTimeRange1; } else if ($timeOpt == 2) { radioButtonGrp -e -sl 1 geomCacheTimeRange2; } else { radioButtonGrp -e -sl 1 geomCacheTimeRange3; } // geomCacheDirName int $import = 0; verifyWorkspaceFileRule( "fileCache", "cache/nCache" ); string $dirToUse = cacheGetCurrentDir("fileCache", "geomCacheDirName", $gGeomCacheCurrentProject, $import ); textFieldGrp -e -tx $dirToUse cacheDir; setCacheName(); checkBoxGrp -edit -value1 `optionVar -query geomCachePerGeometry` cachePerGeometry; floatFieldGrp -e -v1 `optionVar -query geomCacheStartTime` -v2 `optionVar -query geomCacheEndTime` geomCacheStartEndTime; floatFieldGrp -e -v1 `optionVar -query geomCacheSimulationRate` geomCacheSimulationRate; intFieldGrp -e -v1 `optionVar -query geomCacheSampleMultiplier` geomCacheSampleMultiplier; if (`checkBoxGrp -exists mergeDeleteBox`) { checkBoxGrp -e -v1 `optionVar -query geomCacheMergeDelete` mergeDeleteBox; } if( `checkBoxGrp -exists replaceInheritMods`) { checkBoxGrp -e -v1 `optionVar -query geomCacheInheritModifications` replaceInheritMods; } if (`radioButtonGrp -exists doubleOrFloat`) { int $cacheFloats = `optionVar -q cacheAsFloats`; int $selectRB = $cacheFloats ? 2 : 1; radioButtonGrp -e -select $selectRB doubleOrFloat; } if (`radioButtonGrp -exists localOrWorld`) { int $cacheWorld = `optionVar -q cacheInWorld`; int $selectRB = $cacheWorld ? 2 : 1; radioButtonGrp -e -select $selectRB localOrWorld; } disableGeomDiskCacheAttrs $parent; } global proc geomCacheCallback(string $parent, int $doIt, string $action) { int $timeMode = 1; int $distMode = 1; if ( `radioButtonGrp -q -sl geomCacheDist1` ) { $distMode = 1; } else if ( `radioButtonGrp -q -sl geomCacheDist2` ) { $distMode = 2; } optionVar -iv geomCacheDistrib $distMode; if( `radioButtonGrp -q -sl geomCacheTimeRange1` ) { $timeMode = 1; } else if( `radioButtonGrp -q -sl geomCacheTimeRange2` ) { $timeMode = 2; } else if( `radioButtonGrp -q -sl geomCacheTimeRange3` ) { $timeMode = 3; } optionVar -iv geomCacheTimeRange $timeMode; // optionVar -iv geomRefresh `checkBoxGrp -q -v1 geomRefreshBox`; if (`checkBoxGrp -exists mergeDeleteBox`) { optionVar -iv geomCacheMergeDelete `checkBoxGrp -q -v1 mergeDeleteBox`; } if( `checkBoxGrp -exists replaceInheritMods`) { optionVar -iv geomCacheInheritModifications `checkBoxGrp -q -v1 replaceInheritMods`; } optionVar -fv geomCacheStartTime `floatFieldGrp -q -v1 geomCacheStartEndTime`; optionVar -fv geomCacheEndTime `floatFieldGrp -q -v2 geomCacheStartEndTime`; optionVar -fv geomCacheSimulationRate `floatFieldGrp -q -v1 geomCacheSimulationRate`; optionVar -fv geomCacheSampleMultiplier `intFieldGrp -q -v1 geomCacheSampleMultiplier`; if ($doIt) { performCreateGeometryCache 0 $action; } } proc createGeomCacheOptions(string $action) { global string $gGeomCacheCurrentProject; // Name of the command for this option box // string $commandName = "geomCache"; // Build the option box "methods" // string $callback = ($commandName + "Callback "); string $setup = ($commandName + "Setup"); // STEP 1: Get the option box. // ============================ // // The value returned is the name of the layout to be used as // the parent for the option box UI. // string $layout = getOptionBox(); setParent $layout; // STEP 2: Pass the command name to the option box. // ================================================= // // Any default option box behaviour based on the command name is set // up with this call. For example, updating the 'Help' menu item with // the name of the command. // setOptionBoxCommandName($commandName); // STEP 3: Activate the default UI template. // ========================================== // // Activate the default UI template so that the layout of this // option box is consistent with the layout of the rest of the // application. // setUITemplate -pushTemplate DefaultTemplate; // STEP 4: Create option box contents. // =================================== // // This, of course, will vary from option box to option box. // Turn on the wait cursor. // waitCursor -state 1; tabLayout -scr true -tv false; string $parent = `columnLayout -adjustableColumn 1`; // Create the widgets for this option box // // Directory name // rowLayout -nc 3 -cw3 400 5 50 -adjustableColumn 1 -cal 1 "both" -cal 2 "both" -cal 3 "left" -ct3 "both" "both" "left"; int $import = 0; verifyWorkspaceFileRule( "fileCache", "cache/nCache" ); string $dirToUse = cacheGetCurrentDir("fileCache", "geomCacheDirName", $gGeomCacheCurrentProject, $import ); textFieldGrp -label (uiRes("m_performCreateGeometryCache.kCacheDirectory")) -tx $dirToUse -cc ( "cacheSetDirOptionVar" ) -adjustableColumn 2 cacheDir; separator -w 5 -style "none"; symbolButton -image "navButtonBrowse.png" -c ( "cacheBrowseForFolder" ) cacheDirBrowser; setParent ..; // Cache Name // textFieldGrp -label (uiRes("m_performCreateGeometryCache.kCacheName")) -enable true -cc ("geomCacheNameChanged") cacheName; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performCreateGeometryCache.kUsePrefix")) -value1 0 -enable true -cc ( "geomDistributionChanged" ) useAsPrefix; // Initialize cache name setCacheName(); // // Cache Format // string $cacheFormatList[] = `pluginCacheFormats`; int $selection = 1; // Default entry of "mcx" if(!`optionVar -exists geomCacheFormat` || !stringArrayContains(`optionVar -q geomCacheFormat`, $cacheFormatList)) { optionVar -stringValue geomCacheFormat "mcx"; } string $optionSelection = `optionVar -query geomCacheFormat`; int $optionFound = false; string $tabForm = `columnLayout -adj true`; optionMenuGrp -l (uiRes("m_performCreateGeometryCache.kCacheFormat")) -cc ( "geomFormatChanged" ) formatMenu; for( $nth = 0; $nth < size($cacheFormatList); $nth++ ) { menuItem -l $cacheFormatList[$nth]; if( $cacheFormatList[$nth] == $optionSelection ) { $optionFound = true; $selection = $nth + 1; // Add 1 since menus are indexed 1-based } } if( $optionFound == false ) { // Warn that $optionSelection isn't supported warning( (uiRes("m_performCreateGeometryCache.kNoFormatPlugin")) ); } optionMenuGrp -e -sl $selection formatMenu; // Distribution of cache files // radioButtonGrp -label (uiRes("m_performCreateGeometryCache.kCacheFileDistribution")) -nrb 1 -l1 (uiRes("m_performCreateGeometryCache.kOnePerFrame")) -cc ( "geomDistributionChanged" ) geomCacheDist1; radioButtonGrp -label "" -nrb 1 -scl geomCacheDist1 -l1 (uiRes("m_performCreateGeometryCache.kOneFile")) -cc ( "geomDistributionChanged" ) geomCacheDist2; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performCreateGeometryCache.kCachePerGeometry")) -value1 `optionVar -query geomCachePerGeometry` -enable true -cc ( "geomDistributionChanged" ) cachePerGeometry; string $storeDouble = (uiRes("m_performCreateGeometryCache.kStoreDouble")); string $storeFloat = (uiRes("m_performCreateGeometryCache.kStoreFloat")); radioButtonGrp -label (uiRes("m_performCreateGeometryCache.kStorePointsAs")) -nrb 2 -labelArray2 $storeDouble $storeFloat -on1 ("optionVar -iv cacheAsFloats 0") -on2 ("optionVar -iv cacheAsFloats 1") -select 1 doubleOrFloat; if ($action == "export") { string $storeLocal = (uiRes("m_performCreateGeometryCache.kStoreLocal")); string $storeWorld = (uiRes("m_performCreateGeometryCache.kStoreWorld")); radioButtonGrp -label (uiRes("m_performCreateGeometryCache.kStorePointsIn")) -nrb 2 -labelArray2 $storeLocal $storeWorld -on1 ("optionVar -iv cacheInWorld 0") -on2 ("optionVar -iv cacheInWorld 1") -select 1 localOrWorld; } separator -h 5 -style "none"; // Time range to cache // radioButtonGrp -label (uiRes("m_performCreateGeometryCache.kCacheTimeRange")) -nrb 1 -l1 (uiRes("m_performCreateGeometryCache.kRenderSettings")) -cc ( "disableGeomDiskCacheAttrs " + $parent ) geomCacheTimeRange1; radioButtonGrp -label "" -nrb 1 -scl geomCacheTimeRange1 -cc ( "disableGeomDiskCacheAttrs " + $parent ) -l1 (localizedUIComponentLabel("Time Slider")) geomCacheTimeRange2; radioButtonGrp -label "" -nrb 1 -scl geomCacheTimeRange1 -l1 (uiRes("m_performCreateGeometryCache.kStartEnd")) -cc ( "disableGeomDiskCacheAttrs " + $parent ) geomCacheTimeRange3; floatFieldGrp -label (uiRes("m_performCreateGeometryCache.kStartEndGrp")) -nf 2 geomCacheStartEndTime; floatFieldGrp -label (uiRes("m_performCreateGeometryCache.kSimulationRate")) -nf 1 -extraLabel (uiRes("m_performCreateGeometryCache.kSimulationRateEnd")) geomCacheSimulationRate; intFieldGrp -label (uiRes("m_performCreateGeometryCache.kSampleMultiplier")) -nf 1 -extraLabel (uiRes("m_performCreateGeometryCache.kSampleMultiplierEnd")) geomCacheSampleMultiplier; separator -h 5 -style "none"; if ($action == "merge") { // refresh during caching // checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performCreateGeometryCache.kDeleteExisting")) -v1 0 mergeDeleteBox; } if ($action == "replace") { // refresh during caching // checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performCreateGeometryCache.kInheritModifications")) -v1 0 replaceInheritMods; } // refresh during caching // // checkBoxGrp // -numberOfCheckBoxes 1 // -label "" // -label1 _L10N( kRefresh, "Refresh screen while caching") // -v1 0 // geomRefreshBox; // Turn off the wait cursor. // waitCursor -state 0; // Step 5: Deactivate the default UI template. // =========================================== // setUITemplate -popTemplate; // Step 6: Customize the buttons. // ============================== // // Provide more descriptive labels for the buttons. This is not // necessary, but in some cases, for example, a button labelled // 'Create' may be more meaningful to the user than one labelled // 'Apply'. // // Disable those buttons that are not applicable to the option box. // // Attach actions to those buttons that are applicable to the option // box. Note that the 'Close' button has a default action attached // to it that will hide the window. If a a custom action is // attached to the 'Close' button then be sure to call the 'hide the // option box' procedure within the custom action so that the option // box is hidden properly. // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); string $buttonName; if ($action == "replace") { $buttonName = (uiRes("m_performCreateGeometryCache.kReplaceCache")); } else if ($action == "add") { $buttonName = (uiRes("m_performCreateGeometryCache.kAddCache")); } else if ($action == "export") { $buttonName = (uiRes("m_performCreateGeometryCache.kExportCache")); } else { $buttonName = (uiRes("m_performCreateGeometryCache.kMergeCache")); } button -edit -label $buttonName -command ($callback + " " + $parent + " " + 1 + " " + $action) $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " " + 0 + " " + $action +"; hideOptionBox") $saveBtn; // 'Reset' button string $resetBtn = getOptionBoxResetBtn(); int $resetToDefaults = 1; button -edit -command ($setup + " " + $parent + " " + $resetToDefaults) $resetBtn; // Step 7: Set the option box title. // ================================= // string $optionTitle; if ($action == "replace") { $optionTitle = (uiRes("m_performCreateGeometryCache.kReplaceOptions")); } else if ($action == "add") { $optionTitle = (uiRes("m_performCreateGeometryCache.kAddOptions")); } else if ($action == "merge") { $optionTitle = (uiRes("m_performCreateGeometryCache.kMergeOptions")); } else if ($action == "export") { $optionTitle = (uiRes("m_performCreateGeometryCache.kExportOptions")); } setOptionBoxTitle($optionTitle); // Step 8: Customize the 'Help' menu item text. // ============================================ // if ($action == "add") { setOptionBoxHelpTag( "CreateGeomCache" ); } else if ($action == "replace") { setOptionBoxHelpTag( "ReplaceGeomCache" ); } else if ($action == "merge") { setOptionBoxHelpTag( "MergeGeomCache" ); } else if ($action == "export") { setOptionBoxHelpTag( "ExportGeomCache" ); } // Step 9: Set the current values of the option box. // ================================================= // eval ($setup + " " + $parent + " " + 0); // update cacheName field if number of selected objects changes. Make sure it's // killed when we close this option box. // scriptJob -parent $parent -event "SelectionChanged" geomDistributionChanged; // Step 10: Show the option box. // ============================= // showOptionBox(); } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // // Return Value: // None. // proc string assembleCmd(string $action) { global string $gGeomCacheCurrentProject; global string $gGeomCacheAutomaticName; string $distrib = "OneFilePerFrame"; if (`optionVar -query geomCacheDistrib` == 2) { $distrib = "OneFile"; } string $directory = `optionVar -query geomCacheDirName`; if ($directory == $gGeomCacheCurrentProject) { $directory = ""; } geomCacheNameChanged(); // If the user doesn't hit enter after changing cache name on windows, // the command callback is not triggered. string $fileName = `optionVar -query geomCacheName`; if ($fileName == $gGeomCacheAutomaticName) { $fileName = ""; } string $prefix = 0; if( `checkBoxGrp -exists useAsPrefix` ) { $prefix = `checkBoxGrp -q -value1 useAsPrefix`; } if ($action == "merge") { if (`optionVar -query geomCacheMergeDelete`) { $action = "mergeDelete"; } } int $inherit = 0; if( $action == "replace" ) { $inherit = `optionVar -q geomCacheInheritModifications`; } $cmd = ( "doCreateGeometryCache 6 { \"" + `optionVar -query geomCacheTimeRange` + "\", " + "\"" + `optionVar -query geomCacheStartTime` + "\", " + "\"" + `optionVar -query geomCacheEndTime` + "\", " + "\"" + $distrib + "\", " + "\"" + `optionVar -query geomRefresh` + "\", " + "\"" + $directory + "\"," + "\"" + `optionVar -query geomCachePerGeometry` + "\"," + "\"" + $fileName + "\"," + "\"" + $prefix + "\", " + "\"" + $action + "\", " + "\"0\", " + "\"" + `optionVar -query geomCacheSimulationRate` + "\", " + "\"" + `optionVar -query geomCacheSampleMultiplier` + "\"," + "\"" + $inherit + "\"," + "\"" + `optionVar -query cacheAsFloats` + "\"," + "\"" + `optionVar -query geomCacheFormat` + "\"," + "\"" + `optionVar -query cacheInWorld` + "\"" + " } " ); return $cmd; } global proc string performCreateGeometryCache( int $action, string $createMode) { string $cmd = ""; switch( $action ) { case 0: setOptionVars(false); $cmd = assembleCmd($createMode); evalEcho($cmd); break; case 1: createGeomCacheOptions($createMode); break; case 2: setOptionVars(false); $cmd = assembleCmd($createMode); break; } return $cmd; }