// =========================================================================== // 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 nCloth cache. // // global string $gNclothCacheSceneNameForPrefs = ""; proc string[] pluginCacheFormats() { string $formats[] = {"mcx","mcc"}; // 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; } // 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 data directory. The file // works the same way, with the default being to use the name of the // selected object. // global string $gCacheCurrentProject = "CurrentProject"; global string $gNclothCacheAutomaticName = "Automatic"; global proc nclothCacheSetDirOptionVar() // // Set the optionVar based on the user's entry in the option box // { global string $gCacheCurrentProject; global string $gNclothCacheSceneNameForPrefs; 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 = $gCacheCurrentProject; } optionVar -sv nclothCacheDirName $value; $gNclothCacheSceneNameForPrefs = `file -q -loc`; } else { optionVar -sv nclothCacheDirName $gCacheCurrentProject; } } } global proc int cacheSetDirectory( string $dir, string $type ) { textFieldGrp -e -tx $dir cacheDir; nclothCacheSetDirOptionVar(); return 1; } global proc cacheBrowseForFolder() { string $cmd = "cacheSetDirectory "; string $action = (uiRes("m_performCreateNclothCache.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 disableNclothDiskCacheAttrs(string $parent) { setParent $parent; int $showStartEnd = `radioButtonGrp -query -sl nclothCacheTimeRange3`; if( $showStartEnd ) { floatFieldGrp -e -enable true nclothCacheStartEndTime; } else { floatFieldGrp -e -enable false nclothCacheStartEndTime; } } global proc nclothDistributionChanged() // // Enables/disables cacheName field depending on whether // OneFilePerFrame or OneFile is chosen and/or the number // of selected objects. // { int $numShapes = size( getNclothObjectsToCache(0) ); int $oneFilePerFrame = `radioButtonGrp -q -sl nclothCacheDist1`; int $perGeom = ($numShapes > 1) && `checkBoxGrp -q -value1 cachePerGeometry`; optionVar -intValue nclothCachePerGeometry $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; setNclothCacheName(); } global proc nclothCacheFormatChanged() // // Menu callback // { $value = `optionMenuGrp -q -v formatMenu`; optionVar -sv nclothCacheFormat $value; } global proc nclothCacheNameChanged() // // User has specified a cache name, so we no longer need to // update based on selected objects // { if( !`textFieldGrp -exists cacheName` ) return; // Make sure the cache name in option var can't be // cleared. It must remain set to gNclothCacheAutomaticName string $name = `textFieldGrp -query -text cacheName`; if( $name == "" ) return; // Since this is called on every Add, make sure the // cache name was actually modified. // global string $gNclothCacheAutomaticName; string $optName = `optionVar -q nclothCacheName`; if( $optName == $gNclothCacheAutomaticName ) { string $autoName = getAutomaticNclothCacheName(); if( $name == $autoName ) return; } global string $gNclothCacheSceneNameForPrefs; optionVar -sv nclothCacheName $name; $gNclothCacheSceneNameForPrefs = `file -q -loc`; } global proc setNclothCacheName() // // 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 $gNclothCacheAutomaticName; string $name = `optionVar -q nclothCacheName`; if ($name == $gNclothCacheAutomaticName) { $name = getAutomaticNclothCacheName(); } textFieldGrp -e -text $name cacheName; } proc setOptionVars(int $forceFactorySettings) { global string $gCacheCurrentProject; global string $gNclothCacheAutomaticName; global string $gNclothCacheSceneNameForPrefs; string $currSceneName = `file -q -loc`; if ($currSceneName != $gNclothCacheSceneNameForPrefs) { // 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 nclothCacheDirName; optionVar -rm nclothCacheName; } if( $forceFactorySettings || !`optionVar -exists nclothRefresh` ) optionVar -intValue nclothRefresh 1; if( $forceFactorySettings || !`optionVar -exists nclothCacheDistrib`) optionVar -intValue nclothCacheDistrib 1; if( $forceFactorySettings || !`optionVar -exists nclothCacheTimeRange`) optionVar -intValue nclothCacheTimeRange 2; if( $forceFactorySettings || !`optionVar -exists nclothCacheStartTime`) optionVar -floatValue nclothCacheStartTime 1; if( $forceFactorySettings || !`optionVar -exists nclothCacheEndTime`) optionVar -floatValue nclothCacheEndTime 10; if( $forceFactorySettings || !`optionVar -exists nclothCacheFormat`) optionVar -stringValue nclothCacheFormat "mcx"; if( $forceFactorySettings || !`optionVar -exists nclothCacheDirName`) { optionVar -sv nclothCacheDirName "CurrentProject"; } if( $forceFactorySettings || !`optionVar -exists nclothCacheName` ) { optionVar -stringValue nclothCacheName $gNclothCacheAutomaticName; } if( $forceFactorySettings || !`optionVar -exists nclothCachePerGeometry` ) optionVar -intValue nclothCachePerGeometry 1; if( $forceFactorySettings || !`optionVar -exists nclothCacheAsFloats` ) optionVar -intValue nclothCacheAsFloats 1; if( $forceFactorySettings || !`optionVar -exists nclothCacheSimulationRate`) optionVar -floatValue nclothCacheSimulationRate 1; if( $forceFactorySettings || !`optionVar -exists nclothCacheMergeDelete`) optionVar -intValue nclothCacheMergeDelete 0; if( $forceFactorySettings || !`optionVar -exists nclothCacheSampleMultiplier`) optionVar -intValue nclothCacheSampleMultiplier 1; if( $forceFactorySettings || !`optionVar -exists nclothCacheInheritModifications`) optionVar -intValue nclothCacheInheritModifications 0; if( $forceFactorySettings || !`optionVar -exists nclothCacheUsePrefix`) optionVar -intValue nclothCacheUsePrefix 0; } global proc nclothCacheSetup (string $parent, int $forceFactorySettings) { global string $gCacheCurrentProject; setOptionVars($forceFactorySettings); setParent $parent; // checkBoxGrp -e -v1 `optionVar -q nclothRefresh` nclothRefreshBox; string $cacheFormat = `optionVar -q nclothCacheFormat`; optionMenuGrp -e -v $cacheFormat formatMenu; int $distOpt = `optionVar -query nclothCacheDistrib`; if ($distOpt == 1) { radioButtonGrp -e -sl 1 nclothCacheDist1; } else if ($distOpt == 2) { radioButtonGrp -e -sl 1 nclothCacheDist2; } nclothDistributionChanged(); int $timeOpt = `optionVar -query nclothCacheTimeRange`; if ($timeOpt == 1) { radioButtonGrp -e -sl 1 nclothCacheTimeRange1; } else if ($timeOpt == 2) { radioButtonGrp -e -sl 1 nclothCacheTimeRange2; } else { radioButtonGrp -e -sl 1 nclothCacheTimeRange3; } // nclothCacheDirName int $import = 0; verifyWorkspaceFileRule( "fileCache", "cache/nCache" ); string $dirToUse = cacheGetCurrentDir("fileCache", "nclothCacheDirName", $gCacheCurrentProject, $import ); textFieldGrp -e -tx $dirToUse cacheDir; setNclothCacheName(); checkBoxGrp -edit -value1 `optionVar -query nclothCachePerGeometry` cachePerGeometry; floatFieldGrp -e -v1 `optionVar -query nclothCacheStartTime` -v2 `optionVar -query nclothCacheEndTime` nclothCacheStartEndTime; floatFieldGrp -e -v1 `optionVar -query nclothCacheSimulationRate` nclothCacheSimulationRate; intFieldGrp -e -v1 `optionVar -query nclothCacheSampleMultiplier` nclothCacheSampleMultiplier; if (`checkBoxGrp -exists mergeDeleteBox`) { checkBoxGrp -e -v1 `optionVar -query nclothCacheMergeDelete` mergeDeleteBox; } if( `checkBoxGrp -exists replaceInheritMods`) { checkBoxGrp -e -v1 `optionVar -query nclothCacheInheritModifications` replaceInheritMods; } if( `checkBoxGrp -exists useAsPrefix` ) { checkBoxGrp -e -value1 `optionVar -query nclothCacheUsePrefix` useAsPrefix; } /* if (`radioButtonGrp -exists nclothDoubleOrFloat`) { int $cacheFloats = `optionVar -q nclothCacheAsFloats`; int $selectRB = $cacheFloats ? 2 : 1; radioButtonGrp -e -sl $selectRB nclothDoubleOrFloat; } */ disableNclothDiskCacheAttrs $parent; } global proc nclothCacheCallback(string $parent, int $doIt, string $action) { int $timeMode = 1; int $distMode = 1; if ( `radioButtonGrp -q -sl nclothCacheDist1` ) { $distMode = 1; } else if ( `radioButtonGrp -q -sl nclothCacheDist2` ) { $distMode = 2; } optionVar -iv nclothCacheDistrib $distMode; if( `radioButtonGrp -q -sl nclothCacheTimeRange1` ) { $timeMode = 1; } else if( `radioButtonGrp -q -sl nclothCacheTimeRange2` ) { $timeMode = 2; } else if( `radioButtonGrp -q -sl nclothCacheTimeRange3` ) { $timeMode = 3; } optionVar -iv nclothCacheTimeRange $timeMode; // optionVar -iv nclothRefresh `checkBoxGrp -q -v1 nclothRefreshBox`; if (`checkBoxGrp -exists mergeDeleteBox`) { optionVar -iv nclothCacheMergeDelete `checkBoxGrp -q -v1 mergeDeleteBox`; } optionVar -fv nclothCacheStartTime `floatFieldGrp -q -v1 nclothCacheStartEndTime`; optionVar -fv nclothCacheEndTime `floatFieldGrp -q -v2 nclothCacheStartEndTime`; optionVar -fv nclothCacheSimulationRate `floatFieldGrp -q -v1 nclothCacheSimulationRate`; optionVar -iv nclothCacheSampleMultiplier `intFieldGrp -q -v1 nclothCacheSampleMultiplier`; if( `checkBoxGrp -exists replaceInheritMods`) { optionVar -iv nclothCacheInheritModifications `checkBoxGrp -q -v1 replaceInheritMods`; } if( `checkBoxGrp -exists useAsPrefix` ) { optionVar -iv nclothCacheUsePrefix `checkBoxGrp -q -value1 useAsPrefix`; } if ($doIt) { nclothCacheNameChanged(); hideOptionBox; string $cmd = ("performCreateNclothCache 0 "+$action); // use evalDeferred so that the option box will get hidden before // the cache is created evalDeferred $cmd; } } proc createNclothCacheOptions(string $action) { global string $gCacheCurrentProject; // Name of the command for this option box // string $commandName = "nclothCache"; // 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"; // nclothCacheDirName int $import = 0; verifyWorkspaceFileRule( "fileCache", "cache/nCache" ); string $dirToUse = cacheGetCurrentDir("fileCache", "nclothCacheDirName", $gCacheCurrentProject, $import ); textFieldGrp -label (uiRes("m_performCreateNclothCache.kCacheDirectory")) -tx $dirToUse -cc ( "nclothCacheSetDirOptionVar" ) -adjustableColumn 2 cacheDir; separator -w 5 -style "none"; symbolButton -image "navButtonBrowse.png" -c ( "cacheBrowseForFolder" ) cacheDirBrowser; setParent ..; // Cache Name // textFieldGrp -label (uiRes("m_performCreateNclothCache.kCacheName")) -enable true -cc ("nclothCacheNameChanged") cacheName; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performCreateNclothCache.kUsePrefix")) -value1 0 -enable true -cc ( "nclothDistributionChanged" ) useAsPrefix; // Initialize cache name setNclothCacheName(); // // Cache Format // string $cacheFormatList[] = `pluginCacheFormats`; int $selection = 1; // Corresponds to default entry of "mcx" if(!`optionVar -exists nclothCacheFormat` || !stringArrayContains(`optionVar -q nclothCacheFormat`, $cacheFormatList)) optionVar -stringValue nclothCacheFormat "mcx"; string $optionSelection = `optionVar -query nclothCacheFormat`; int $optionFound = false; string $tabForm = `columnLayout -adj true`; optionMenuGrp -l (uiRes("m_performCreateNclothCache.kNclothCacheFormat")) -cc ( "nclothCacheFormatChanged" ) 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 ) { warning( (uiRes("m_performCreateNclothCache.kNoFormatPlugin")) ); } optionMenuGrp -e -sl $selection formatMenu; // Distribution of cache files // radioButtonGrp -label (uiRes("m_performCreateNclothCache.kCacheFileDistribution")) -nrb 1 -l1 (uiRes("m_performCreateNclothCache.kOnePerFrame")) -cc ( "nclothDistributionChanged" ) nclothCacheDist1; radioButtonGrp -label "" -nrb 1 -scl nclothCacheDist1 -l1 (uiRes("m_performCreateNclothCache.kOneFile")) -cc ( "nclothDistributionChanged" ) nclothCacheDist2; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performCreateNclothCache.kCachePerGeometry")) -value1 `optionVar -query nclothCachePerGeometry` -enable true -cc ( "nclothDistributionChanged" ) cachePerGeometry; /* string $storeDouble = (uiRes("m_performCreateNclothCache.kNClothStoreDouble")); string $storeFloat = (uiRes("m_performCreateNclothCache.kNClothStoreFloat")); radioButtonGrp -label (uiRes("m_performCreateNclothCache.kStorePointsAs")) -nrb 2 -labelArray2 $storeDouble $storeFloat -on1 ("optionVar -iv nclothCacheAsFloats 0") -on2 ("optionVar -iv nclothCacheAsFloats 1") -select 1 nclothDoubleOrFloat; */ separator -h 5 -style "none"; // Time range to cache // radioButtonGrp -label (uiRes("m_performCreateNclothCache.kCacheTimeRange")) -nrb 1 -l1 (uiRes("m_performCreateNclothCache.kRenderSettings")) -cc ( "disableNclothDiskCacheAttrs " + $parent ) nclothCacheTimeRange1; radioButtonGrp -label "" -nrb 1 -scl nclothCacheTimeRange1 -cc ( "disableNclothDiskCacheAttrs " + $parent ) -l1 (localizedUIComponentLabel("Time Slider")) nclothCacheTimeRange2; radioButtonGrp -label "" -nrb 1 -scl nclothCacheTimeRange1 -l1 (uiRes("m_performCreateNclothCache.kStartEnd")) -cc ( "disableNclothDiskCacheAttrs " + $parent ) nclothCacheTimeRange3; floatFieldGrp -label (uiRes("m_performCreateNclothCache.kStartEndGrp")) -nf 2 nclothCacheStartEndTime; floatFieldGrp -label (uiRes("m_performCreateNclothCache.kSimulationRate")) -nf 1 -extraLabel (uiRes("m_performCreateNclothCache.kSimulationRateR")) nclothCacheSimulationRate; intFieldGrp -label (uiRes("m_performCreateNclothCache.kSampleMultiplierLeft")) -extraLabel (uiRes("m_performCreateNclothCache.kSampleMultiplierRight")) -nf 1 nclothCacheSampleMultiplier; separator -h 5 -style "none"; if ($action == "merge") { // refresh during caching // checkBoxGrp -numberOfCheckBoxes 1 -label (uiRes("m_performCreateNclothCache.kFileCleanup")) -label1 (uiRes("m_performCreateNclothCache.kDeleteExisting")) -v1 0 mergeDeleteBox; } if ($action == "replace") { // refresh during caching // checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performCreateNclothCache.kInheritModifications")) -v1 0 replaceInheritMods; } // refresh during caching // // checkBoxGrp // -numberOfCheckBoxes 1 // -label "" // -label1 _L10N( kRefresh, "Refresh screen while caching") // -v1 0 // nclothRefreshBox; // 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_performCreateNclothCache.kReplaceCache")); } else if ($action == "add") { $buttonName = (uiRes("m_performCreateNclothCache.kAddCache")); } else { $buttonName = (uiRes("m_performCreateNclothCache.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_performCreateNclothCache.kReplaceOptions")); } else if ($action == "add") { $optionTitle = (uiRes("m_performCreateNclothCache.kAddOptions")); } else { $optionTitle = (uiRes("m_performCreateNclothCache.kMergOptions")); } setOptionBoxTitle($optionTitle); // Step 8: Customize the 'Help' menu item text. // ============================================ // if ($action == "add") { setOptionBoxHelpTag( "CreateNclothCache" ); } else if ($action == "replace") { setOptionBoxHelpTag( "ReplaceNclothCache" ); } else { setOptionBoxHelpTag( "MergeNclothCache" ); } // 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" nclothDistributionChanged; // 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 $gCacheCurrentProject; global string $gNclothCacheAutomaticName; string $distrib = "OneFilePerFrame"; if (`optionVar -query nclothCacheDistrib` == 2) { $distrib = "OneFile"; } string $directory = `optionVar -query nclothCacheDirName`; if ($directory == $gCacheCurrentProject) { $directory = ""; } nclothCacheNameChanged(); // If the user doesn't hit enter after changing // cache name on windows, callback is not triggered. string $fileName = `optionVar -query nclothCacheName`; if ($fileName == $gNclothCacheAutomaticName) { $fileName = ""; } string $prefix = 0; if( `optionVar -exists nclothCacheUsePrefix`) { if ("" != $fileName) { $prefix = `optionVar -q nclothCacheUsePrefix`; } } if ($action == "merge") { if (`optionVar -query nclothCacheMergeDelete`) { $action = "mergeDelete"; } } int $inherit = 0; if( $action == "replace" ) { $inherit = `optionVar -q nclothCacheInheritModifications`; } return( "doCreateNclothCache 5 { \"" + `optionVar -query nclothCacheTimeRange` + "\", " + "\"" + `optionVar -query nclothCacheStartTime` + "\", " + "\"" + `optionVar -query nclothCacheEndTime` + "\", " + "\"" + $distrib + "\", " + "\"" + `optionVar -query nclothRefresh` + "\", " + "\"" + $directory + "\"," + "\"" + `optionVar -query nclothCachePerGeometry` + "\"," + "\"" + $fileName + "\"," + "\"" + $prefix + "\", " + "\"" + $action + "\", " + "\"0\", " + "\"" + `optionVar -query nclothCacheSimulationRate` + "\", " + "\"" + `optionVar -query nclothCacheSampleMultiplier` + "\"," + "\"" + $inherit + "\"," + "\"" + `optionVar -query nclothCacheAsFloats` + "\"," + "\"" + `optionVar -query nclothCacheFormat` + "\"" + " } " ); } global proc string performCreateNclothCache( int $action, string $createMode ) { string $cmd = ""; switch( $action ) { case 0: setOptionVars(false); $cmd = assembleCmd($createMode); evalEcho($cmd); break; case 1: createNclothCacheOptions($createMode); break; case 2: setOptionVars(false); $cmd = assembleCmd($createMode); break; } return $cmd; }