// =========================================================================== // 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: 2014/04/22 // // Description: // This script defines various HUD-related procedures // for evaluation manager state feedback. // global proc int isEvaluatorSupported( string $evaluatorName ) // // Description: // Checks whether a given custom evaluator is available or not. // // Arguments: // $evaluatorName - Name of the custom evaluator. // // Returns: // 1 if the custom evaluator is supported, 0 otherwise. // { $supportedModes = `evaluator -q`; $index = stringArrayFind( $evaluatorName , 0 , $supportedModes ); return ( $index >= 0 ); } global proc int isEvaluatorActive( string $evaluatorName ) // // Description: // Checks whether a given custom evaluator is active or not. // // Arguments: // $evaluatorName - Name of the custom evaluator. // // Returns: // 1 if the custom evaluator is active, 0 otherwise. // { if ( isEvaluatorSupported( $evaluatorName ) ) { return `evaluator -q -name $evaluatorName`; } else { // The mode is not in the supported modes. return 0; } } proc string[] GetEvaluationManagerHUD() // // Description: // Returns the names of HUD objects that display evaluation manager feedback. // // Returns: // The names of evaluation manager HUD objects, which are: // - HUDEvaluation // - HUDEMState // - HUDGPUOverride // { return { "HUDEvaluation" , "HUDEMState" , "HUDGPUOverride" }; } global proc SetEvaluationManagerHUDVisibility( int $newVisibleState ) // // Description: // Show or hide the HUD elements that display evaluation manager feedback. // // Arguments: // $newVisibleState - 0 to hide the elements, non-0 to show them. // { int $currentVisibility = `optionVar -query evaluationVisibility`; // if the visibility changes then update the optionVar and menu item if ($newVisibleState != $currentVisibility) { optionVar -iv evaluationVisibility $newVisibleState; if (`menuItem -q -exists evaluationItem`) { menuItem -e -checkBox $newVisibleState evaluationItem; } } // always call the headsUpDisplay command. This will refresh the HUD so // that things like changing from parallel mode to serial mode will be // immediately reflected in the HUD. for ( $element in GetEvaluationManagerHUD() ) { if ( `headsUpDisplay -exists $element` ) { headsUpDisplay -e -visible $newVisibleState $element; } } } global proc ToggleEvaluationManagerHUDVisibility() // // Description: // Toggle visibility state for evaluation manager HUD elements. // { int $currentVisibility = `optionVar -query evaluationVisibility`; int $newVisibility = !$currentVisibility; SetEvaluationManagerHUDVisibility($newVisibility); } global proc WarnAboutSerialExecutionFallback() { warning (uiRes("m_initHUDScriptsEvaluationManager.kWarningSerialFallback")); } // // Let's define various procedures to help setup // the evaluation manager shelf. // global proc ToggleEvaluator( string $evaluatorName ) // // Description: // Toggles the enabled/disabled state of a given a custom evaluator name. // // Arguments: // $evaluatorName - Name of the custom evaluator. // { if ( isEvaluatorActive( $evaluatorName ) ) { // Deactivate the deformer. evaluator -enable off -name $evaluatorName; } else { // Activate the deformer. string $pluginName = $evaluatorName + "Evaluator"; if ( !`pluginInfo -q -loaded $pluginName` ) { loadPlugin( $pluginName ); } evaluator -enable on -name $evaluatorName; evaluator -enable on -name $evaluatorName -nodeType "node" -nodeTypeChildren; } } // // Definitions of the callback for each button of the shelf. // // Using a function call per button allows us to change the code // associated with a button without changing the shelf itself // that might already be in user settings. // global proc setEvaluationManagerModeDefaultDG() // // Description: // Callback that sets the evaluation mode to regular Maya evaluation. // { catch ( `evaluationManager -mode "off"` ); SetEvaluationManagerHUDVisibility( 0 ); // Trigger an evaluation so that the graph is rebuilt after changing mode. currentTime `currentTime -q`; // Force refresh of HUD elements. refresh -force; } global proc setEvaluationManagerModeSerial() // // Description: // Callback that sets the evaluation mode to serial (cached) evaluation. // { catch ( `evaluationManager -mode "serial"` ); SetEvaluationManagerHUDVisibility( 1 ); // Trigger an evaluation so that the graph is rebuilt after changing mode. currentTime `currentTime -q`; // Force refresh of HUD elements. refresh -force; } global proc setEvaluationManagerModeParallel() // // Description: // Callback that sets the evaluation mode to parallel evaluation. // { catch ( `evaluationManager -mode "parallel"` ); SetEvaluationManagerHUDVisibility( 1 ); // Trigger an evaluation so that the graph is rebuilt after changing mode. currentTime `currentTime -q`; // Force refresh of HUD elements. refresh -force; } global proc turnOnOpenCLEvaluatorActive() // Description: // allback that turn on the OpenCL deformer evaluator active state. // { if(!isEvaluatorActive( "deformer" )) { toggleOpenCLEvaluator(); } } global proc turnOffOpenCLEvaluatorActive() // Description: // Callback that turn off the OpenCL deformer evaluator active state. // { if(isEvaluatorActive( "deformer" )) { toggleOpenCLEvaluator(); } } global proc toggleOpenCLEvaluator() // // Description: // Callback that toggles the OpenCL deformer evaluator active state. // { // This will only do something the first time the toggle is hit. // The plug-in is not unloaded when toggling off. if ( !`pluginInfo -q -loaded "GPUBuiltInDeformer"` ) { loadPlugin( "GPUBuiltInDeformer" ); } catch ( `ToggleEvaluator( "deformer" )` ); // Trigger an evaluation so that the graph is rebuilt after enabling/disabling evaluator. currentTime `currentTime -q`; // Force refresh of HUD elements. refresh -force; } global proc toggleEvaluationManagerManipulation() // // Description: // Callback that toggles the evaluation manager manipulation active state. // { if ( `evaluationManager -q -manipulation` ) { evaluationManager -manipulation off; warning (uiRes("m_initHUDScriptsEvaluationManager.kEMManipulationOff")); } else { evaluationManager -manipulation on; warning (uiRes("m_initHUDScriptsEvaluationManager.kEMManipulationOn")); } } //====================================================================== // // Toggle the visibility state of cache HUD elements. // global proc ToggleCacheHUDVisibility() { python( "from maya.plugin.evaluator.cache_optionvar_states import CachePreferenceHud" ); python( "CachePreferenceHud().set_value( not CachePreferenceHud().get_value() )" ); }