// =========================================================================== // 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: 26 June 1997 // // // Description: // This is a helper script to perform the 'Bake Simulation' operation // using the corresponding option box values. // // proc setOptionVars(int $forceFactorySettings) { keySetOptionBoxCommon( { "bakeSimulation", "unknown", "setOptionVars", $forceFactorySettings } ); // By Time // if ($forceFactorySettings || !`optionVar -exists bakeSimulationByTime`) { optionVar -floatValue bakeSimulationByTime 1.0; } // Oversampling Rate // if ($forceFactorySettings || !`optionVar -exists bakeSimulationOversamplingRate`) { optionVar -intValue bakeSimulationOversamplingRate 1; } // Disable implicit control // if ($forceFactorySettings || !`optionVar -exists bakeSimulationImpCon`) { optionVar -intValue bakeSimulationImpCon 1; } // Preserve keys outside the bake range // if ($forceFactorySettings || !`optionVar -exists bakeSimulationPreserveKeys`) { optionVar -intValue bakeSimulationPreserveKeys 1; } // Bake anim curves sparsely // if ($forceFactorySettings || !`optionVar -exists bakeSimulationSparseAnimCurve`) { optionVar -intValue bakeSimulationSparseAnimCurve 0; } // Bake on base layer // if ($forceFactorySettings || !`optionVar -exists bakeSimulationRemoveBakedAttributeFromLayer`) { optionVar -intValue bakeSimulationRemoveBakedAttributeFromLayer 0; } // Bake override layer // if ($forceFactorySettings || !`optionVar -exists bakeSimulationBakeOnOverrideLayer`) { optionVar -intValue bakeSimulationBakeOnOverrideLayer 0; } // Smart Bake // if ($forceFactorySettings || !`optionVar -exists bakeSimulationSmartBake`) { optionVar -intValue bakeSimulationSmartBake 0; } // if ($forceFactorySettings || !`optionVar -exists bakeSimulationSmartFidelity`) { optionVar -intValue bakeSimulationSmartFidelity 0.0; } if ($forceFactorySettings || !`optionVar -exists bakeSimulationSmartFidelityDelta`) { optionVar -floatValue bakeSimulationSmartFidelityDelta 5; } // Preserve keys outside the bake range // if ($forceFactorySettings || !`optionVar -exists minimizeRotation`) { optionVar -intValue minimizeRotation 1; } } // // Procedure Name: // bakeSimulationWidgetsEnable // // 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 bakeSimulationWidgetsEnable(string $selectionConnection) { keySetOptionBoxCommon( { "bakeSimulation", $selectionConnection, "enable" } ); bakeSimulationSmartWidgetsEnable(); } global proc bakeSimulationSmartWidgetsEnable() { int $lSmart = `checkBoxGrp -q -value1 bakeSimulationSmartBakeCB`; int $lAddKeys = `checkBoxGrp -q -value1 bakeSimulationIncreaseFedelityCB`; floatFieldGrp -e -enable (!$lSmart) byTime; rowLayout -e -enable (!$lSmart) oversamplingRateGrp; checkBoxGrp -e -enable $lSmart bakeSimulationIncreaseFedelityCB; floatFieldGrp -e -enable ($lSmart&&$lAddKeys) bakeSimulationFidelityDeltaF; } // // Procedure Name: // bakeSimulationSetup // // 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 bakeSimulationSetup(string $parent, string $selectionConnection, int $forceFactorySettings, string $startOverride, string $endOverride) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; keySetOptionBoxCommon( { "bakeSimulation", $selectionConnection, "setup", 0, $startOverride, $endOverride } ); // By time // floatFieldGrp -edit -value1 `optionVar -q bakeSimulationByTime` byTime; // Oversampling Rate // intField -edit -value `optionVar -q bakeSimulationOversamplingRate` oversamplingRate; // Disable implicit control // checkBoxGrp -edit -value1 `optionVar -q bakeSimulationImpCon` implicitControl; // Preserve keys outside bake range // checkBoxGrp -edit -value1 `optionVar -q bakeSimulationPreserveKeys` preserveKeys; // Bake anim curves sparsely // checkBoxGrp -edit -value1 `optionVar -q bakeSimulationSparseAnimCurve` sparseAnimCurves; //remove attribute from layer // int $removeBakedAttributeFromLayerOption = 1; if( `optionVar -q bakeSimulationRemoveBakedAttributeFromLayer` ) { $removeBakedAttributeFromLayerOption = 2; } else if( `optionVar -q bakeSimulationRemoveBakedAnimFromLayer` ) { $removeBakedAttributeFromLayerOption = 3; } optionMenuGrp -edit -select $removeBakedAttributeFromLayerOption removeBakedAttributeFromLayer; radioButtonGrp -edit -select (`optionVar -q bakeSimulationBakeOnOverrideLayer`+1) bakeOnOverrideLayer; // Smart Bake checkBoxGrp -edit -value1 ((`optionVar -query bakeSimulationSmartBake`)?1:0) bakeSimulationSmartBakeCB; checkBoxGrp -edit -value1 ((`optionVar -query bakeSimulationSmartFidelity`)?1:0) bakeSimulationIncreaseFedelityCB; floatFieldGrp -edit -value1 `optionVar -query bakeSimulationSmartFidelityDelta` bakeSimulationFidelityDeltaF; checkBoxGrp -edit -value1 `optionVar -q minimizeRotation` minimizeRotation; // Set the enable state of the start and end time fields // and the control points and shapes. // bakeSimulationWidgetsEnable ($selectionConnection); } // // Procedure Name: // bakeSimulationCallback // // 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. // // preBakeCmd - Optional command to perform before the execution of the bake operation // // postBakeCmd - Optional command to perform just after the execution of the bake operation // // Return Value: // None. // global proc bakeSimulationCallback(string $parent, int $doIt, string $selectionConnection, string $preBakeCmd, string $postBakeCmd ) { setParent $parent; keySetOptionBoxCommon( { "bakeSimulation", $selectionConnection, "callback" } ); // By time // optionVar -floatValue bakeSimulationByTime `floatFieldGrp -query -value1 byTime`; // Oversampling Rate // optionVar -intValue bakeSimulationOversamplingRate `intField -query -value oversamplingRate`; // Implicit control // optionVar -intValue bakeSimulationImpCon `checkBoxGrp -query -value1 implicitControl`; // Preserve keys outside bake range // optionVar -intValue bakeSimulationPreserveKeys `checkBoxGrp -query -value1 preserveKeys`; // Bake anim curves sparsely // optionVar -intValue bakeSimulationSparseAnimCurve `checkBoxGrp -query -value1 sparseAnimCurves`; optionVar -intValue bakeSimulationRemoveBakedAttributeFromLayer (`optionMenuGrp -query -select removeBakedAttributeFromLayer`==2); optionVar -intValue bakeSimulationRemoveBakedAnimFromLayer (`optionMenuGrp -query -select removeBakedAttributeFromLayer`==3); optionVar -intValue bakeSimulationBakeOnOverrideLayer (`radioButtonGrp -query -select bakeOnOverrideLayer`-1); // SmartBake optionVar -intValue bakeSimulationSmartBake `checkBoxGrp -q -value1 bakeSimulationSmartBakeCB`; optionVar -intValue bakeSimulationSmartFidelity `checkBoxGrp -q -value1 bakeSimulationIncreaseFedelityCB`; optionVar -floatValue bakeSimulationSmartFidelityDelta `floatFieldGrp -q -value1 bakeSimulationFidelityDeltaF`; optionVar -intValue minimizeRotation `checkBoxGrp -q -value1 minimizeRotation`; if ($doIt) { performBakeSimulationArgList 2 {"0", $selectionConnection, $preBakeCmd, $postBakeCmd }; string $tmpCmd = "performBakeSimulationArgList 2 {\"0\", \"" + $selectionConnection + "\",\""+$preBakeCmd+ "\",\""+$postBakeCmd+ "\"}"; addToRecentCommandQueue $tmpCmd "BakeSimulation"; } } proc string bakeSimulationWidgets (string $parent, string $selectionConnection) { setParent $parent; string $tabForm = `columnLayout -adjustableColumn true`; keySetOptionBoxCommon( { "bakeSimulation", $selectionConnection, "widgets", 0, 0, 1, 0 } ); // Layer Section radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_performBakeSimulationArgList.kBakeOnOverrideLayer")) -label1 (uiRes("m_performBakeSimulationArgList.kBakeOnOverrideLayerNo")) -label2 (uiRes("m_performBakeSimulationArgList.kBakeOnOverrideLayerYes")) bakeOnOverrideLayer; optionMenuGrp -label (uiRes("m_performBakeSimulationArgList.kBakeLayersFinality")) removeBakedAttributeFromLayer; menuItem -label (uiRes("m_performBakeSimulationArgList.kBakeLayersFinalityNo")); menuItem -label (uiRes("m_performBakeSimulationArgList.kBakeLayersFinalityRemoveAttr")); menuItem -label (uiRes("m_performBakeSimulationArgList.kBakeLayersFinalityRemoveAnim")); separator; floatFieldGrp -label (uiRes("m_performBakeSimulationArgList.kSampleBy")) byTime; rowLayout -nc 3 -adj 3 oversamplingRateGrp; text -label (uiRes("m_performBakeSimulationArgList.kOversamplingRate")); intField -v 1 -min 1 oversamplingRate; text -label ""; setParent ..; separator; // Smart Bake Section checkBoxGrp -label (uiRes("m_performBakeSimulationArgList.kSmartBake")) -enable true -onCommand "bakeSimulationSmartWidgetsEnable" -offCommand "bakeSimulationSmartWidgetsEnable" bakeSimulationSmartBakeCB; checkBoxGrp -label (uiRes("m_performBakeSimulationArgList.kSmartBakeIncreaseFidelity")) -visible true -onCommand "bakeSimulationSmartWidgetsEnable" -offCommand "bakeSimulationSmartWidgetsEnable" bakeSimulationIncreaseFedelityCB; floatFieldGrp -label (uiRes("m_performBakeSimulationArgList.kSmartBakeFidelityDelta")) -extraLabel (uiRes("m_performBakeSimulationArgList.kSmartBakeFidelityUnits")) -value1 0.250 -visible true bakeSimulationFidelityDeltaF; separator; // Remaining Options checkBoxGrp -label (uiRes("m_performBakeSimulationArgList.kKeepUnbakedKeys")) -label1 "" -ncb 1 preserveKeys; checkBoxGrp -label (uiRes("m_performBakeSimulationArgList.kSparseCurveBake")) -label1 "" -ncb 1 sparseAnimCurves; checkBoxGrp -label (uiRes("m_performBakeSimulationArgList.kDisableImplicitControl")) -label1 "" -ncb 1 implicitControl; checkBoxGrp -label (uiRes("m_performBakeSimulationArgList.kMinimizeRotation")) -label1 "" -ncb 1 minimizeRotation; return $tabForm; } // // Procedure Name: // bakeSimulationOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc bakeSimulationOptions (string $selectionConnection, string $preBakeCmd, string $postBakeCmd, string $startFrame, string $endFrame) { // Name of the command for this option box. // string $commandName = "bakeSimulation"; // Build the option box actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // 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; // Pass the command name to the option box. // // Any default option box behaviour based on the command name is set // up with this call. // setOptionBoxCommandName($commandName); // 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; // Turn on the wait cursor. // waitCursor -state 1; // RECOMMENDATION: Place the UI in a scroll layout. If the // option box window is ever resized such that it's entire // contents is not visible then the scroll bars provided by the // scroll layout will allow the user to access the hidden UI. // tabLayout -tv false -scr true; string $parent = `columnLayout -adjustableColumn 1`; // Create the option box widgets // bakeSimulationWidgets($parent, $selectionConnection); // Turn off the wait cursor. // waitCursor -state 0; // Deactivate the default UI template. // setUITemplate -popTemplate; // 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. $preBakeCmd = `encodeString $preBakeCmd`; $postBakeCmd = `encodeString $postBakeCmd`; // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performBakeSimulationArgList.kBake")) -command ($callback + " " + $parent + " " + 1 + " \"" + $selectionConnection + "\" (\""+$preBakeCmd+ "\") (\""+$postBakeCmd+"\") ") $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " " + 0 + " \"" + $selectionConnection + "\" (\""+$preBakeCmd+ "\") (\""+$postBakeCmd+"\") ; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " " + $selectionConnection + " " + 1 + " \"-1.0\" \"-1.0\"") $resetBtn; // Set the option box title. // setOptionBoxTitle (uiRes("m_performBakeSimulationArgList.kBakeAnimationOptions")); // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "KeysBakeSimulation" ); // Set the current values of the option box. // eval (($setup + " " + $parent + " " + $selectionConnection + " " + 0 + " " + $startFrame + " " + $endFrame)); // Show the option box. // showOptionBox(); } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // // Return Value: // The string to execute for this option box. // proc string assembleCmd(string $selectionConnection, string $preBakeCmd, string $postBakeCmd, string $startFrame, string $endFrame) { setOptionVars(false); float $start = (float)$startFrame; float $end = (float)$endFrame; int $whichRange = 3; // If the input is (-1,-1) ignore it and query the optionVar // if( $start == -1 && $end == -1 ) { // start/end times from the string optionVar // string $time = `optionVar -query bakeSimulationRange`; string $range[]; tokenize ($time, ":", $range); $start = float ($range[0]); $end = float ($range[1]); $whichRange = `optionVar -query bakeSimulationWhichRange`; } // doBakeSimulationArgList takes a string array // int $doBelow = `optionVar -query bakeSimulationHierarchy` == "below"; string $cmd = "doBakeSimulationArgList 8 { " + "\"" + $whichRange + "\"" + ",\"" + $start + "\"" + ",\"" + $end + "\"" + ",\"" + `optionVar -query bakeSimulationByTime` + "\"" + ",\"" + $doBelow + "\"" + ",\"" + `optionVar -query bakeSimulationControlPoints` + "\"" + ",\"" + `optionVar -query bakeSimulationShapes` + "\"" + ",\"" + `optionVar -query bakeSimulationImpCon` + "\"" + ",\"" + `optionVar -query bakeSimulationUseChannelBox` + "\"" + ",\"" + `optionVar -query bakeSimulationPreserveKeys` + "\"" + ",\"" + $selectionConnection + "\"" + ",\"" + `optionVar -query bakeSimulationSparseAnimCurve` + "\"" + ",\"" + `optionVar -query bakeSimulationRemoveBakedAttributeFromLayer` + "\"" + ",\"" + `optionVar -query bakeSimulationBakeOnOverrideLayer` + "\"" + ",\"" + `optionVar -query bakeSimulationSmartBake` + "\"" + ",\"" + ((`optionVar -query bakeSimulationSmartFidelity`)?( `optionVar -query bakeSimulationSmartFidelityDelta`):0.0) + "\"" + ",\"" + `optionVar -query minimizeRotation` + "\"" + ",\"" + `optionVar -query bakeSimulationRemoveBakedAnimFromLayer` + "\"" + ",\"" + `optionVar -query bakeSimulationOversamplingRate` + "\"" + " };"; if( $preBakeCmd != "" ) { $cmd = $preBakeCmd +";"+ $cmd; } if( $postBakeCmd != "" ) { $cmd += $postBakeCmd +";"; } return $cmd; } // // Procedure Name: // performBakeSimulationArgList // // Description: // Perform the 'bakeSimulation' operation 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 'bakeSimulation' operation with the current // option box values. // // Input Arguments: // $version: The version of this option box. Used to know how to // interpret the $args array. // "1" : $action, $selectionConnection // // $args // Version 1 // [0] $action 0 : Execute the command. // 1 : Show the option box dialog. // 2 : Return the command. // [1] $selectionConnection name of selection connection to use // // Version 2 // // [2] $preBakeCmd command string to be executed just before the simulation // baking gets performed. // // [3] $postBakeCmd command string to be executed just after the simulation // baking gets performed // // Return Value: // The string to execute for this option box. // global proc string performBakeSimulationArgList (string $version, string $args[]) { int $versionNum = $version; int $action = $args[0]; string $selectionConnection = $args[1]; string $preBakeCmd; string $postBakeCmd; string $startFrame = "-1"; string $endFrame = "-1"; if( $versionNum >= 2 ) { $preBakeCmd = $args[2]; $postBakeCmd = $args[3]; } if( $versionNum >= 3 ) { $startFrame = $args[4]; $endFrame = $args[5]; } string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Retrieve the option settings // setOptionVars(false); // Get the command. // $cmd = `assembleCmd $selectionConnection $preBakeCmd $postBakeCmd $startFrame $endFrame`; // Execute the command with the option settings. // eval($cmd); break; // Show the option box. // case 1: bakeSimulationOptions $selectionConnection $preBakeCmd $postBakeCmd $startFrame $endFrame; break; // Return the command string. // case 2: // Retrieve the option settings. // setOptionVars (false); // Get the command. // $cmd = `assembleCmd $selectionConnection $preBakeCmd $postBakeCmd $startFrame $endFrame`; break; } return $cmd; }