// =========================================================================== // 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. // =========================================================================== // Generate the bbox command with args proc string assembleCmd() { string $command = "geomToBBox"; string $name = `optionVar -q geometryToBoundingBoxName`; $command += $name != "" ? " -name " + $name : ""; string $nameSuffix = `optionVar -q geometryToBoundingBoxNameSuffix`; $command += $nameSuffix != "" ? " -nameSuffix " + $nameSuffix : ""; $command += `optionVar -query geometryToBoundingBoxRepresentHierarchyAs` == 1 ? " -single" : ""; $command += `optionVar -query geometryToBoundingBoxCombineMesh` == 1 ? " -combineMesh" : ""; float $rgb[3] = `optionVar -query geometryToBoundingBoxShaderColor`; $command += " -shaderColor " + $rgb[0] + " " + $rgb[1] + " " + $rgb[2] + ""; $command += `optionVar -query geometryToBoundingBoxKeepOriginal` == 1 ? " -keepOriginal" : ""; if(`optionVar -query geometryToBoundingBoxBakeAnimation` == 1 ) { $command += " -bakeAnimation"; if(`optionVar -query geometryToBoundingBoxBakeTimeRangeType` == 2) { $command += " -startTime " + `optionVar -query geometryToBoundingBoxBakeStartTime`; $command += " -endTime " + `optionVar -query geometryToBoundingBoxBakeEndTime`; } $command += " -sampleBy " + `optionVar -query geometryToBoundingBoxBakeSampleByTime`; } print($command + "\n"); return $command; } // Default option settings proc setOptionVars(int $forceFactorySettings) { // bbox name if ($forceFactorySettings || !`optionVar -exists geometryToBoundingBoxName`) { optionVar -stringValue geometryToBoundingBoxName ""; } // bbox name suffix if ($forceFactorySettings || !`optionVar -exists geometryToBoundingBoxNameSuffix`) { optionVar -stringValue geometryToBoundingBoxNameSuffix "_BBox"; } // bbox hierarchy representation if ($forceFactorySettings || !`optionVar -exists geometryToBoundingBoxRepresentHierarchyAs`) { optionVar -intValue geometryToBoundingBoxRepresentHierarchyAs 1; } // bbox combine mesh if ($forceFactorySettings || !`optionVar -exists geometryToBoundingBoxCombineMesh`) { optionVar -intValue geometryToBoundingBoxCombineMesh 0; } // bbox shader color if ($forceFactorySettings || !`optionVar -exists geometryToBoundingBoxShaderColor`) { optionVar -clearArray geometryToBoundingBoxShaderColor; optionVar -floatValue geometryToBoundingBoxShaderColor 0.5; optionVar -floatValueAppend geometryToBoundingBoxShaderColor 0.5; optionVar -floatValueAppend geometryToBoundingBoxShaderColor 0.5; } // bbox keep original if ($forceFactorySettings || !`optionVar -exists geometryToBoundingBoxKeepOriginal`) { optionVar -intValue geometryToBoundingBoxKeepOriginal 0; } // bake animation option if ($forceFactorySettings || !`optionVar -exists geometryToBoundingBoxBakeAnimation`) { optionVar -intValue geometryToBoundingBoxBakeAnimation 0; } // bake animation time range type if ($forceFactorySettings || !`optionVar -exists geometryToBoundingBoxBakeTimeRangeType`) { optionVar -intValue geometryToBoundingBoxBakeTimeRangeType 1; } // bake animation start time if ($forceFactorySettings || !`optionVar -exists geometryToBoundingBoxBakeStartTime`) { optionVar -floatValue geometryToBoundingBoxBakeStartTime `playbackOptions -q -min`; } // bake animation end time if ($forceFactorySettings || !`optionVar -exists geometryToBoundingBoxBakeEndTime`) { optionVar -floatValue geometryToBoundingBoxBakeEndTime `playbackOptions -q -max`; } // bake animation sample by (evaluation increment) if ($forceFactorySettings || !`optionVar -exists geometryToBoundingBoxBakeSampleByTime`) { optionVar -floatValue geometryToBoundingBoxBakeSampleByTime 1.0; } } // Update the state of the option box UI to reflect the option values. global proc boundingBoxOptionsSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. // bbox name textFieldGrp -edit -text `optionVar -query geometryToBoundingBoxName` bboxName; // bbox name suffix textFieldGrp -edit -text `optionVar -query geometryToBoundingBoxNameSuffix` bboxNameSuffix; int $convertionType = `optionVar -query geometryToBoundingBoxRepresentHierarchyAs`; int $bakeAnimation = `optionVar -query geometryToBoundingBoxBakeAnimation`; // bbox hierarchy representation radioButtonGrp -edit -select $convertionType representHierarchyAs; checkBox -edit -enable ($convertionType == 1 ? false : $bakeAnimation == 1 ? false : true) bboxCombineMesh; // bbox shader color float $rgb[3] = `optionVar -query geometryToBoundingBoxShaderColor`; colorSliderGrp -edit -rgb $rgb[0] $rgb[1] $rgb[2] bboxShaderColor; // bbox keep original checkBox -edit -value `optionVar -query geometryToBoundingBoxKeepOriginal` bboxKeepOriginal; // bbox combine mesh checkBox -edit -value ($convertionType == 1 ? 0 : `optionVar -query geometryToBoundingBoxCombineMesh`) bboxCombineMesh; // bake animation checkBox -edit -value $bakeAnimation bboxBakeAnimation; frameLayout -edit -enable ($bakeAnimation == 1 ? true : false) bboxBakeAnimLayout; int $TimeTangentType = `optionVar -query geometryToBoundingBoxBakeTimeRangeType`; // bake animation time range type radioButtonGrp -edit -select $TimeTangentType bboxTimeRange; // bake animation start time floatFieldGrp -edit -enable ($TimeTangentType == 1 ? false : true) -value1 `optionVar -query geometryToBoundingBoxBakeStartTime` bboxStartTime; // bake animation start time floatFieldGrp -edit -enable ($TimeTangentType == 1 ? false : true) -value1 `optionVar -query geometryToBoundingBoxBakeEndTime` bboxEndTime; // bake animation start time floatFieldGrp -edit -value1 `optionVar -query geometryToBoundingBoxBakeSampleByTime` bboxSampleByTime; } // Update the option values with the current state of the option box UI. global proc boundingBoxOptionsCallback(string $parent, int $doIt) { setParent $parent; // bbox name optionVar -stringValue geometryToBoundingBoxName `textFieldGrp -query -text bboxName`; // bbox name suffix optionVar -stringValue geometryToBoundingBoxNameSuffix `textFieldGrp -query -text bboxNameSuffix`; // bbox hierarchy representation. optionVar -intValue geometryToBoundingBoxRepresentHierarchyAs `radioButtonGrp -query -select representHierarchyAs`; // bbox combine mesh optionVar -intValue geometryToBoundingBoxCombineMesh `checkBox -query -value bboxCombineMesh`; // bbox shader color. float $rgb[3] = `colorSliderGrp -query -rgb bboxShaderColor`; optionVar -clearArray geometryToBoundingBoxShaderColor; optionVar -floatValue geometryToBoundingBoxShaderColor $rgb[0]; optionVar -floatValueAppend geometryToBoundingBoxShaderColor $rgb[1]; optionVar -floatValueAppend geometryToBoundingBoxShaderColor $rgb[2]; // bbox keep original optionVar -intValue geometryToBoundingBoxKeepOriginal `checkBox -query -value bboxKeepOriginal`; // bake animation optionVar -intValue geometryToBoundingBoxBakeAnimation `checkBox -query -value bboxBakeAnimation`; // bake animation time range type optionVar -intValue geometryToBoundingBoxBakeTimeRangeType `radioButtonGrp -query -select bboxTimeRange`; // bake animation start time optionVar -floatValue geometryToBoundingBoxBakeStartTime `floatFieldGrp -query -value1 bboxStartTime`; // bake animation start time optionVar -floatValue geometryToBoundingBoxBakeEndTime `floatFieldGrp -query -value1 bboxEndTime`; // bake animation start time optionVar -floatValue geometryToBoundingBoxBakeSampleByTime `floatFieldGrp -query -value1 bboxSampleByTime`; if ($doIt) { eval(assembleCmd()); } } // Construct the option box UI. // Involves accessing the standard option box and customizing the UI accordingly. global proc geomToBBoxOptions() { // Name of the command for this option box. string $commandName = "boundingBoxOptions"; // Build the option box actions. string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // STEP 1: Get the option box. // ============================ // string $layout = getOptionBox(); setParent $layout; // STEP 2: Pass the command name to the option box. // ================================================= // setOptionBoxCommandName($commandName); // STEP 3: Activate the default UI template. // ========================================== // setUITemplate -pushTemplate DefaultTemplate; // STEP 4: Create option box contents. // =================================== // // Turn on the wait cursor. waitCursor -state 1; tabLayout -tabsVisible 0 -scrollable 1; string $parent = `columnLayout -adjustableColumn 1`; textFieldGrp -label (uiRes("m_performGeomToBBox.kBBoxName")) bboxName; textFieldGrp -label (uiRes("m_performGeomToBBox.kBBoxNameSuffix")) bboxNameSuffix; radioButtonGrp -label (uiRes("m_performGeomToBBox.kBBoxRepresentHierarchyAs")) -numberOfRadioButtons 2 -vertical -labelArray2 (uiRes("m_performGeomToBBox.kOneBBox")) (uiRes("m_performGeomToBBox.kOneBBoxPerShape")) -onCommand1 ("checkBox -edit -enable false -value 0 bboxCombineMesh") -onCommand2 ("checkBox -edit -enable (`checkBox -query -value bboxBakeAnimation` == 1 ? false : true) bboxCombineMesh") representHierarchyAs; rowLayout -numberOfColumns 1 -columnAttach 1 "left" 173; checkBox -label (uiRes("m_performGeomToBBox.kBBoxCombineMesh")) bboxCombineMesh; setParent ..; colorSliderGrp -label (uiRes("m_performGeomToBBox.kBBoxShaderColor")) bboxShaderColor; text -label ""; rowLayout -numberOfColumns 1 -columnAttach 1 "left" 173; checkBox -label (uiRes("m_performGeomToBBox.kBBoxBakeAnimation")) -onCommand ("frameLayout -edit -enable true bboxBakeAnimLayout; checkBox -edit -enable false -value 0 bboxCombineMesh;") -offCommand ("frameLayout -edit -enable false bboxBakeAnimLayout; checkBox -edit -enable (`radioButtonGrp -query -select representHierarchyAs` == 1 ? false : true) bboxCombineMesh;") bboxBakeAnimation; setParent ..; columnLayout -adjustableColumn true; frameLayout -labelVisible false -collapsable false bboxBakeAnimLayout; columnLayout; radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_performGeomToBBox.kBBoxTimeRange")) -labelArray2 (uiRes("m_performGeomToBBox.kBBoxTimeSlider")) (uiRes("m_performGeomToBBox.kBBoxStartEnd")) -onCommand1 ("floatFieldGrp -edit -enable false bboxStartTime;floatFieldGrp -edit -enable false bboxEndTime;") -onCommand2 ("floatFieldGrp -edit -enable true bboxStartTime;floatFieldGrp -edit -enable true bboxEndTime;") bboxTimeRange; floatFieldGrp -label (uiRes("m_performGeomToBBox.kBBoxStartTime")) -columnWidth 2 85 bboxStartTime; floatFieldGrp -label (uiRes("m_performGeomToBBox.kBBoxEndTime")) -columnWidth 2 85 bboxEndTime; floatFieldGrp -label (uiRes("m_performGeomToBBox.kBBoxSampleByTime")) -columnWidth 2 85 bboxSampleByTime; setParent ..; setParent ..; setParent ..; rowLayout -numberOfColumns 1 -columnAttach 1 "left" 173; checkBox -label (uiRes("m_performGeomToBBox.kBBoxKeepOriginal")) bboxKeepOriginal; setParent ..; // Turn off the wait cursor. waitCursor -state 0; // Step 5: Deactivate the default UI template. // =========================================== // setUITemplate -popTemplate; // Step 6: Customize the buttons. // ============================== // // 'Apply' button. string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performGeomToBBox.kBBoxConvert")) -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; // Step 7: Set the option box title. // ================================= // setOptionBoxTitle (uiRes("m_performGeomToBBox.kConvertGeoToBBoxTitle")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "GeomToBBox" ); // Step 9: Set the current values of the option box. // ================================================= // eval(($setup + " " + $parent + " " + 0)); // Step 10: Show the option box. // ============================= // showOptionBox(); } global proc string performGeomToBBox( int $action ) { string $cmd = ""; switch( $action ) { case 0: setOptionVars(0); $cmd = assembleCmd(); eval($cmd); break; case 1: geomToBBoxOptions; break; } return $cmd; }