// =========================================================================== // 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: 20 February 2008 // // Description: // This is a helper script to perform the "cacheFile -replace" command // using the corresponding option box values. // // // Procedure Name: // setOptionVars // // Description: // Initialize the option values. // // Input Arguments: // Whether to set the options to default values. // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { // Time range // if( $forceFactorySettings || !`optionVar -exists replaceFluidCacheFramesTimeRange`) { optionVar -intValue replaceFluidCacheFramesTimeRange 1; } // startTime // if ($forceFactorySettings || !`optionVar -exists replaceFluidCacheFramesStartTime`) { optionVar -floatValue replaceFluidCacheFramesStartTime 1.0; } // endTime // if ($forceFactorySettings || !`optionVar -exists replaceFluidCacheFramesEndTime`) { optionVar -floatValue replaceFluidCacheFramesEndTime 10.0; } // Interpolation type // if( $forceFactorySettings || !`optionVar -exists replaceFluidCacheFramesInterpType`) { optionVar -intValue replaceFluidCacheFramesInterpType 1; } // interpolation startTime // if ($forceFactorySettings || !`optionVar -exists replaceFluidCacheFramesInterpStartTime`) { optionVar -floatValue replaceFluidCacheFramesInterpStartTime 1.0; } // Interpolation endTime // if ($forceFactorySettings || !`optionVar -exists replaceFluidCacheFramesInterpEndTime`) { optionVar -floatValue replaceFluidCacheFramesInterpEndTime 10.0; } // Interpolated frames rename string // if ($forceFactorySettings || !`optionVar -exists replaceFluidCacheFramesInterpRename`) { optionVar -stringValue replaceFluidCacheFramesInterpRename "backup"; } // In Tangent // if ($forceFactorySettings || !`optionVar -exists repFluidCacheFramesInTan`) { // 1 == linear optionVar -intValue repFluidCacheFramesInTan 1; } // Out Tangent // if ($forceFactorySettings || !`optionVar -exists repFluidCacheFramesOutTan`) { // 1 == linear optionVar -intValue repFluidCacheFramesOutTan 1; } // delete old unused string prefs if they are lingering around // if (`optionVar -exists replaceFluidCacheFramesInTangent`) { optionVar -rm replaceFluidCacheFramesInTangent; } if (`optionVar -exists replaceFluidCacheFramesOutTangent`) { optionVar -rm replaceFluidCacheFramesOutTangent; } // simulation rate // if ($forceFactorySettings || !`optionVar -exists replaceFluidCacheFramesSimulationRate`) { optionVar -floatValue replaceFluidCacheFramesSimulationRate 1; } // sampling rate // if( $forceFactorySettings || !`optionVar -exists replaceFluidCacheFramesSampleMultiplier` ) { optionVar -intValue replaceFluidCacheFramesSampleMultiplier 1; } // Delete backup files // if( $forceFactorySettings || !`optionVar -exists replaceFluidCacheFramesNoBackups` ) { optionVar -intValue replaceFluidCacheFramesNoBackups 0; } // Replace with simulation data // if( $forceFactorySettings || !`optionVar -exists replaceFluidCacheFramesWithoutSimulating` ) { optionVar -intValue replaceFluidCacheFramesWithoutSimulating 1; } } // // Procedure Name: // replaceFluidCacheFramesEnabling // // Description: // Set the enable state of start and end time fields. // // Input Arguments: // parent - Top level parent layout of the option box UI. // Required so that object names of the fields can be // successfully resolved. // // state - Enable state of the fields. // // Return Value: // None. // global proc replaceFluidCacheFramesEnabling() { int $startEnd = ( `radioButtonGrp -q -sl replaceFluidCacheFramesTimeRange2` == 1 ); floatFieldGrp -edit -enable $startEnd replaceFluidCacheFramesReplaceStart; floatFieldGrp -edit -enable $startEnd replaceFluidCacheFramesReplaceEnd; floatFieldGrp -edit -enable $startEnd replaceFluidCacheFramesSimulationRate; intFieldGrp -edit -enable $startEnd replaceFluidCacheFramesSampleMultiplier; checkBoxGrp -edit -enable (1-$startEnd) replaceFluidCacheFramesWithSimulation; int $interp = ( `radioButtonGrp -q -sl replaceFluidCacheFramesInterpType1` == 0 ); floatFieldGrp -edit -enable $interp replaceFluidCacheFramesInterpStart; floatFieldGrp -edit -enable $interp replaceFluidCacheFramesInterpEnd; optionMenuGrp -edit -enable $interp replaceFluidCacheFramesInTangent; optionMenuGrp -edit -enable $interp replaceFluidCacheFramesOutTangent; int $rename = ( `radioButtonGrp -q -sl replaceFluidCacheFramesInterpType3` == 1 ); textFieldGrp -edit -enable $rename replaceFluidCacheFramesInterpFilename; } // // Procedure Name: // replaceFluidCacheFramesSetup // // Description: // Update the state of the option box UI to reflect the option values. // // Input Arguments: // parent - Top level parent layout of the option box UI. // Required so that UI object names can be // successfully resolved. // // forceFactorySettings - Whether the option values should be set to // default values. // // Return Value: // None. // global proc replaceFluidCacheFramesSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; float $currentTime = `currentTime -q`; floatFieldGrp -edit -value1 $currentTime replaceFluidCacheFramesCurrentTime; // Range start // int $rangeStart = `optionVar -query replaceFluidCacheFramesTimeRange`; eval( "radioButtonGrp -e -select 1 replaceFluidCacheFramesTimeRange"+$rangeStart); // Start/End // float $startTime = `optionVar -query replaceFluidCacheFramesStartTime`; float $endTime = `optionVar -query replaceFluidCacheFramesEndTime`; floatFieldGrp -edit -value1 $startTime replaceFluidCacheFramesReplaceStart; floatFieldGrp -edit -value1 $endTime replaceFluidCacheFramesReplaceEnd; // Interpolation // int $interpType = `optionVar -q replaceFluidCacheFramesInterpType`; eval( "radioButtonGrp -e -sl 1 replaceFluidCacheFramesInterpType" + $interpType); float $interpStart = `optionVar -query replaceFluidCacheFramesInterpStartTime`; float $interpEnd = `optionVar -query replaceFluidCacheFramesInterpEndTime`; floatFieldGrp -edit -value1 $interpStart replaceFluidCacheFramesInterpStart; floatFieldGrp -edit -value1 $interpEnd replaceFluidCacheFramesInterpEnd; int $inTangent = `optionVar -query repFluidCacheFramesInTan`; int $outTangent = `optionVar -query repFluidCacheFramesOutTan`; optionMenuGrp -edit -sl $inTangent replaceFluidCacheFramesInTangent; optionMenuGrp -edit -sl $outTangent replaceFluidCacheFramesOutTangent; string $rename = `optionVar -query replaceFluidCacheFramesInterpRename`; textFieldGrp -edit -text $rename replaceFluidCacheFramesInterpFilename; // Sampling information // float $simulation = `optionVar -q replaceFluidCacheFramesSimulationRate` ; floatFieldGrp -e -v1 $simulation replaceFluidCacheFramesSimulationRate ; int $samplingRate = `optionVar -q replaceFluidCacheFramesSampleMultiplier` ; intFieldGrp -edit -v1 $samplingRate replaceFluidCacheFramesSampleMultiplier ; int $noBackups = `optionVar -query replaceFluidCacheFramesNoBackups`; checkBoxGrp -e -v1 $noBackups replaceFluidCacheFramesDeleteBackups; int $withSimulation = !`optionVar -query replaceFluidCacheFramesWithoutSimulating`; checkBoxGrp -e -v1 $withSimulation replaceFluidCacheFramesWithSimulation; replaceFluidCacheFramesEnabling(); } // // Procedure Name: // replaceFluidCacheFramesCallback // // Description: // Update the option values with the current state of the option box UI. // // Input Arguments: // parent - Top level parent layout of the option box UI. Required so // that UI object names can be successfully resolved. // // doIt - Whether the command should execute. // // Return Value: // None. // global proc replaceFluidCacheFramesCallback(string $parent, int $doIt) { setParent $parent; // start/end range // int $timeRangeMode = 1; if( `radioButtonGrp -q -sl replaceFluidCacheFramesTimeRange1` ) { $timeRangeMode = 1; } else if( `radioButtonGrp -q -sl replaceFluidCacheFramesTimeRange2` ) { $timeRangeMode = 2; } optionVar -intValue replaceFluidCacheFramesTimeRange $timeRangeMode; // start/end Time // optionVar -floatValue replaceFluidCacheFramesStartTime `floatFieldGrp -query -value1 replaceFluidCacheFramesReplaceStart`; optionVar -floatValue replaceFluidCacheFramesEndTime `floatFieldGrp -query -value1 replaceFluidCacheFramesReplaceEnd`; // Interpolation type // int $interpType; if( `radioButtonGrp -q -sl replaceFluidCacheFramesInterpType1` ) { $interpType = 1; } else if( `radioButtonGrp -q -sl replaceFluidCacheFramesInterpType2` ) { $interpType = 2; } else if( `radioButtonGrp -q -sl replaceFluidCacheFramesInterpType3` ) { $interpType = 3; } optionVar -intValue replaceFluidCacheFramesInterpType $interpType; // Interpolation start/end // optionVar -floatValue replaceFluidCacheFramesInterpStartTime `floatFieldGrp -q -v1 replaceFluidCacheFramesInterpStart`; optionVar -floatValue replaceFluidCacheFramesInterpEndTime `floatFieldGrp -q -v1 replaceFluidCacheFramesInterpEnd`; // In/out tangents optionVar -intValue repFluidCacheFramesInTan `optionMenuGrp -q -sl replaceFluidCacheFramesInTangent`; optionVar -intValue repFluidCacheFramesOutTan `optionMenuGrp -q -sl replaceFluidCacheFramesOutTangent`; // Interpolated frames rename string // string $name = `textFieldGrp -q -text replaceFluidCacheFramesInterpFilename`; if( size($name) == 0 ) { $name = "backup"; } optionVar -stringValue replaceFluidCacheFramesInterpRename $name; // simulation rate // optionVar -floatValue replaceFluidCacheFramesSimulationRate `floatFieldGrp -query -v1 replaceFluidCacheFramesSimulationRate`; // sampling rate // optionVar -intValue replaceFluidCacheFramesSampleMultiplier `intFieldGrp -query -v1 replaceFluidCacheFramesSampleMultiplier`; int $noBackups = `checkBoxGrp -q -v1 replaceFluidCacheFramesDeleteBackups`; optionVar -intValue replaceFluidCacheFramesNoBackups $noBackups; int $withSimulation = !`checkBoxGrp -q -v1 replaceFluidCacheFramesWithSimulation`; optionVar -intValue replaceFluidCacheFramesWithoutSimulating $withSimulation; if( $doIt ) { performReplaceFluidCacheFrames 0; } } // // Procedure Name: // replaceFluidCacheFramesOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc replaceFluidCacheFramesOptions() { // Name of the command for this option box. // string $commandName = "replaceFluidCacheFrames"; // Build the option box actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); string $layout = getOptionBox(); setParent $layout; setUITemplate -pushTemplate DefaultTemplate; tabLayout -tv false -scr true; string $parent = `columnLayout -adjustableColumn 1`; string $currentTime = (uiRes("m_performReplaceFluidCacheFrames.kFluidCurrentTime")); floatFieldGrp -label $currentTime -enable false replaceFluidCacheFramesCurrentTime; radioButtonGrp -label (uiRes("m_performReplaceFluidCacheFrames.kFluidReplaceTimeRange")) -nrb 1 -l1 $currentTime -cc "replaceFluidCacheFramesEnabling" replaceFluidCacheFramesTimeRange1; radioButtonGrp -label "" -l1 (uiRes("m_performReplaceFluidCacheFrames.kFluidStartEnd")) -scl replaceFluidCacheFramesTimeRange1 -cc "replaceFluidCacheFramesEnabling" replaceFluidCacheFramesTimeRange2; floatFieldGrp -nf 1 -cc "replaceFluidCacheFramesEnabling" -label (uiRes("m_performReplaceFluidCacheFrames.kFluidReplaceStart")) replaceFluidCacheFramesReplaceStart; floatFieldGrp -nf 1 -cc "replaceFluidCacheFramesEnabling" -label (uiRes("m_performReplaceFluidCacheFrames.kFluidReplaceEnd")) replaceFluidCacheFramesReplaceEnd; floatFieldGrp -label (uiRes("m_performReplaceFluidCacheFrames.kFluidSimulationRate")) -extraLabel (uiRes("m_performReplaceFluidCacheFrames.kFluidSimulationRateEnd")) -nf 1 -cc "replaceFluidCacheFramesEnabling" replaceFluidCacheFramesSimulationRate; intFieldGrp -label (uiRes("m_performReplaceFluidCacheFrames.kFluidSampleMultiplier")) -extraLabel (uiRes("m_performReplaceFluidCacheFrames.kFluidSampleMultiplierEnd")) -nf 1 -cc "replaceFluidCacheFramesEnabling" replaceFluidCacheFramesSampleMultiplier; separator -h 5 -style "none"; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performReplaceFluidCacheFrames.kFluidWithSimulation")) -v1 0 replaceFluidCacheFramesWithSimulation; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performReplaceFluidCacheFrames.kFluidDeleteBackups")) -v1 0 replaceFluidCacheFramesDeleteBackups; separator -h 10; radioButtonGrp -label "" -label1 (uiRes("m_performReplaceFluidCacheFrames.kFluidNoInterpolation")) -cc "replaceFluidCacheFramesEnabling" replaceFluidCacheFramesInterpType1; radioButtonGrp -label "" -nrb 1 -scl replaceFluidCacheFramesInterpType1 -label1 (uiRes("m_performReplaceFluidCacheFrames.kFluidInterpolateFrames")) -cc "replaceFluidCacheFramesEnabling" replaceFluidCacheFramesInterpType2; radioButtonGrp -label "" -nrb 1 -scl replaceFluidCacheFramesInterpType1 -label1 (uiRes("m_performReplaceFluidCacheFrames.kFluidRenameInterpolateFrames")) -cc "replaceFluidCacheFramesEnabling" replaceFluidCacheFramesInterpType3; separator -h 5 -style "none"; textFieldGrp -label "" -cc "replaceFluidCacheFramesEnabling" replaceFluidCacheFramesInterpFilename; separator -h 5 -style "none"; string $linear = (uiRes("m_performReplaceFluidCacheFrames.kFluidLinear")); string $smooth = (uiRes("m_performReplaceFluidCacheFrames.kFluidSmooth")); string $step = (uiRes("m_performReplaceFluidCacheFrames.kFluidStep")); optionMenuGrp -cc "replaceFluidCacheFramesEnabling" -label (uiRes("m_performReplaceFluidCacheFrames.kFluidInTangent")) replaceFluidCacheFramesInTangent; menuItem -label $linear linearIn; menuItem -label $smooth smoothIn; menuItem -label $step stepIn; floatFieldGrp -nf 1 -cc "replaceFluidCacheFramesEnabling" -label (uiRes("m_performReplaceFluidCacheFrames.kFluidInterpStart")) replaceFluidCacheFramesInterpStart; floatFieldGrp -nf 1 -cc "replaceFluidCacheFramesEnabling" -label (uiRes("m_performReplaceFluidCacheFrames.kFluidInterpEnd")) replaceFluidCacheFramesInterpEnd; optionMenuGrp -cc "replaceFluidCacheFramesEnabling" -label (uiRes("m_performReplaceFluidCacheFrames.kFluidOutTangent")) replaceFluidCacheFramesOutTangent; menuItem -label $linear linearOut; menuItem -label $smooth smoothOut; menuItem -label $step stepOut; separator -h 10 -style "none"; string $warning = ( (uiRes("m_performReplaceFluidCacheFrames.kFluidMultiCacheWarning1")) + (uiRes("m_performReplaceFluidCacheFrames.kFluidMultiCacheWarning2")) + (uiRes("m_performReplaceFluidCacheFrames.kFluidMultiCacheWarning3")) ); text -label $warning; setUITemplate -popTemplate; // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performReplaceFluidCacheFrames.kFluidReplace")) -command ($callback + " " + $parent + " " + 1) $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " " + 1) $resetBtn; // Set the option box title. // setOptionBoxTitle( (uiRes("m_performReplaceFluidCacheFrames.kFluidReplaceOptions")) ); setOptionBoxCommandName($commandName); setOptionBoxHelpTag( "ReplaceFluidCacheFrames" ); // Set the current values of the option box. // eval( $setup + " " + $parent + " " + 0 ); // 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() { setOptionVars(false); string $obj; float $startTime, $endTime; string $cmd = "cacheFile -refresh -replaceCachedFrame -runupFrames 0"; string $objects[]; $objects = getFluidObjectsToCache(0); for( $obj in $objects ) { $cmd += (" -cacheableNode " + $obj); } if( `optionVar -q replaceFluidCacheFramesWithoutSimulating` && `checkBoxGrp -query -enable replaceFluidCacheFramesWithSimulation`) { $cmd += " -replaceWithoutSimulating"; } int $timeMode = `optionVar -query replaceFluidCacheFramesTimeRange`; switch( $timeMode ) { case 1: $startTime = `currentTime -q`; $endTime = `currentTime -q`; break; case 2: default: $startTime = `optionVar -query replaceFluidCacheFramesStartTime`; $endTime = `optionVar -query replaceFluidCacheFramesEndTime`; if ($startTime == $endTime) $cmd += " -replaceWithSimulation"; break; } int $interpType = `optionVar -q replaceFluidCacheFramesInterpType`; if( $interpType != 1 ) { float $interpStart = `optionVar -q replaceFluidCacheFramesInterpStartTime`; float $interpEnd = `optionVar -q replaceFluidCacheFramesInterpEndTime`; $cmd += (" -interpStartTime " + $interpStart ); $cmd += (" -interpEndTime " + $interpEnd ); int $inTangentVal = `optionVar -q repFluidCacheFramesInTan`; int $outTangentVal = `optionVar -q repFluidCacheFramesOutTan`; string $inTangent = "linear"; string $outTangent = "linear"; if ($inTangentVal == 2) { $inTangent = "smooth"; } else if ($inTangentVal == 3) { $inTangent = "step"; } if ($outTangentVal == 2) { $outTangent = "smooth"; } else if ($outTangentVal == 3) { $outTangent = "step"; } $cmd += (" -inTangent " + $inTangent); $cmd += (" -outTangent " + $outTangent ); } if( $interpType == 3 ) { string $rename = `optionVar -q replaceFluidCacheFramesInterpRename`; if( size($rename) == 0 ) { $rename = "backup"; } $cmd += (" -fileName \"" + $rename + "\""); } float $simRate = `optionVar -query replaceFluidCacheFramesSimulationRate`; int $sampleMult = `optionVar -query replaceFluidCacheFramesSampleMultiplier`; $cmd += (" -startTime " + $startTime ); $cmd += (" -endTime " + $endTime ); $cmd += (" -simulationRate " + $simRate ); $cmd += (" -sampleMultiplier " + $sampleMult ); int $noBackups = `optionVar -q replaceFluidCacheFramesNoBackups`; if( $noBackups ) { $cmd += " -noBackup"; } string $cacheFiles[] = `ls -sl -type cacheFile`; if( size($cacheFiles) == 1 ) { $cmd += (" -cacheFileNode " + $cacheFiles[0] ); } return $cmd; } // // Procedure Name: // performReplaceFluidCacheFrames // // Description: // Perform the command using the corresponding // option values. This procedure will also show the option box // window if necessary as well as construct the command string // that will invoke the command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // // Return Value: // None. // global proc string performReplaceFluidCacheFrames(int $action) { string $cmd = ""; switch ($action) { // Execute the command from option settings. // case 0: setOptionVars(false); $cmd = `assembleCmd`; evalEcho($cmd); break; // Show the option box. // case 1: replaceFluidCacheFramesOptions(); break; // Return the command string. // case 2: setOptionVars (false); $cmd = `assembleCmd`; break; } return $cmd; }