// =========================================================================== // 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. // =========================================================================== // // hikCustomRigUI.mel // // Description: // Methods for creating and updating the custom rig UI // /////////////////////////////////////////////////////////////////// // Local Methods... /////////////////////////////////////////////////////////////////// // Change the min/max range limits on a float slider, such that min <= $val <= max proc updateFloatSliderGrpRange( string $slider, float $val, float $mn, float $mx, float $lim ) { floatSliderGrp -e -minValue ( ( $val >= $mn ) ? $mn : $val ) -maxValue ( ( $val <= $mx ) ? $mx : $val ) -fieldMinValue ( -1.0 * $lim ) -fieldMaxValue ( $lim ) -value $val $slider ; } proc enableCustomRigMapMode( string $type, int $val ) { if ( $type == "T" ) { iconTextCheckBox -e -enable $val -v false hikCustomRigTranslateButton; checkBox -e -enable $val -v false hikCustomRigCheckBoxTrans; } else if ( $type == "R" ) { iconTextCheckBox -e -enable $val -v false hikCustomRigRotateButton; checkBox -e -enable $val -v false hikCustomRigCheckBoxRot; } } proc setCustomRigSliderValues( string $type, float $val[] ) { if ( $type == "T" ) { updateFloatSliderGrpRange( "hikCustomRigSliderTransX", $val[0], -10.0, 10.0, 1000. ); updateFloatSliderGrpRange( "hikCustomRigSliderTransY", $val[1], -10.0, 10.0, 1000. ); updateFloatSliderGrpRange( "hikCustomRigSliderTransZ", $val[2], -10.0, 10.0, 1000. ); } else if ( $type == "R" ) { updateFloatSliderGrpRange( "hikCustomRigSliderRotX", $val[0], -360.0, 360.0, 360.0 ); updateFloatSliderGrpRange( "hikCustomRigSliderRotY", $val[1], -360.0, 360.0, 360.0 ); updateFloatSliderGrpRange( "hikCustomRigSliderRotZ", $val[2], -360.0, 360.0, 360.0 ); } } proc customRigWidgetFatalError( string $filename ) { string $err = `format -s $filename (uiRes("m_hikCustomRigUI.kWidgetFatalErr"))`; catch( `error $err` ); } proc enableCustomRigMapping( string $type, int $show ) { enableCustomRigMapMode( $type, $show ); hikEnableCustomRigSliders( $type, $show ); } proc enableCustomRigMappingOptions( int $show ) { enableCustomRigMapping( "T", $show ); enableCustomRigMapping( "R", $show ); } proc updateCustomRigButtonState() { int $exists = RetargeterExists( RetargeterGetName( hikGetCurrentCharacter() ) ); iconTextButton -e -enable ( $exists == true ) hikCustomRigDeleteButton; iconTextButton -e -enable ( $exists == true ) hikCustomRigOpenButton; iconTextButton -e -enable ( $exists == true ) hikCustomRigSaveButton; } proc updateCustomRigSliders() { // Disable all sliders and checkboxes enableCustomRigMappingOptions( false ); hikSetCustomRigMapMode( "T", false ); hikSetCustomRigMapMode( "R", false ); // If there is nothing selected in the CustomRigToolWidget bail int $inx = `hikCustomRigToolWidget -q -sl`; if ( $inx == -1 ) return; // Make sure the selected id corresponds to a valid name string $body = hikCustomRigElementNameFromId( hikGetCurrentCharacter(), $inx ); if ( size( $body ) == 0 ) { print ( uiRes( "m_hikCustomRigOperations.kInvalidIndex" ) ); return; } // Bail if the selected item is not assigned or if there // is no retargeter for the selected body string $name = RetargeterGetName( hikGetCurrentCharacter() ); if( RetargeterHasMapping( $name, $body ) == false ) return; // Re-enable specific portions of the UI. string $types[] = { "T", "R" }; int $i; for ( $i=0; $i $maxDockWidth ) { $dockWidth = $maxDockWidth; optionVar -iv hikCustomRigTabWidth $dockWidth; } else if ( $dockWidth < $gHIKDockMinWidth ) { $dockWidth = $gHIKDockMinWidth; optionVar -iv hikCustomRigTabWidth $dockWidth; } HIKUiControl -edit -maxWidth $maxDockWidth -minWidth $gHIKDockMinWidth -ctrlName "hikCharacterControlsDock"; } global proc hikUpdateCustomRigAssignedMappings( string $character ) { string $name = RetargeterGetName( $character ); int $indices[] = RetargeterAssignedElementIndices( $name ); if ( size( $indices ) == 0 ) $indices = { -1 }; string $cmd = intArrayToString( $indices, " -assigned " ); eval( `format -s $cmd "hikCustomRigToolWidget -e -assigned ^1s"` ); } global proc hikUpdateEditCustomRigMenu() { } global proc hikSetCustomRigMapMode( string $type, int $val ) { if ( $type == "T" ) { iconTextCheckBox -e -v $val hikCustomRigTranslateButton; checkBox -e -v $val hikCustomRigCheckBoxTrans; } else if ( $type == "R" ) { iconTextCheckBox -e -v $val hikCustomRigRotateButton; checkBox -e -v $val hikCustomRigCheckBoxRot; } } global proc hikEnableCustomRigSliders( string $type, int $show ) { if ( $type == "T" ) { if ( `floatSliderGrp -q -exists hikCustomRigSliderTransX` ) floatSliderGrp -e -enable $show hikCustomRigSliderTransX; if ( `floatSliderGrp -q -exists hikCustomRigSliderTransY` ) floatSliderGrp -e -enable $show hikCustomRigSliderTransY; if ( `floatSliderGrp -q -exists hikCustomRigSliderTransZ` ) floatSliderGrp -e -enable $show hikCustomRigSliderTransZ; } else if ( $type == "R" ) { if ( `floatSliderGrp -q -exists hikCustomRigSliderRotX` ) floatSliderGrp -e -enable $show hikCustomRigSliderRotX; if ( `floatSliderGrp -q -exists hikCustomRigSliderRotY` ) floatSliderGrp -e -enable $show hikCustomRigSliderRotY; if ( `floatSliderGrp -q -exists hikCustomRigSliderRotZ` ) floatSliderGrp -e -enable $show hikCustomRigSliderRotZ; } if ( $show == false ) setCustomRigSliderValues( $type, { 0., 0., 0. } ); } global proc hikCustomRigSetDefaultUIConfig() { string $defConfigFilename = hikGetDefaultResourcesDir(); $defConfigFilename = $defConfigFilename + "CharacterControlsConfig.xml"; string $customConfigFilename = `optionVar -q hikCustomRigUIPath`; warning `format -s $customConfigFilename (uiRes("m_hikCustomRigUI.kUIConfFileError"))`; optionVar -stringValue hikCustomRigUIPath $defConfigFilename; if( catch( `hikCustomRigToolWidget -e -configFilename $defConfigFilename` ) ) customRigWidgetFatalError( $defConfigFilename ); } global proc hikUpdateCustomRigConfigFromFile( string $configFilename ) { if( catch( `hikCustomRigToolWidget -edit -configFilename $configFilename` ) ) hikCustomRigSetDefaultUIConfig( ); hikOnSwitchCustomRig; hikUpdateContextualUI; hikCustomRigToolWidget -e -refreshScale; } /////////////////////////////////////////////////////////////////// // Script jobs... /////////////////////////////////////////////////////////////////// global int $gCustomRigUndoId = -1; if ( $gCustomRigUndoId == -1 ) $gCustomRigUndoId = `scriptJob -e "Undo" "eval( \"hikCustomRigUndoRedo\" );"`; global int $gCustomRigRedoId = -1; if ( $gCustomRigRedoId == -1 ) $gCustomRigRedoId = `scriptJob -e "Redo" "eval( \"hikCustomRigUndoRedo\" );"`; global proc hikCustomRigUndoRedo() { // If no character controls window exists, there is nothing to do. if ( hikCharacterControlsWindowExists() == false ) return; // If a custom rig was deleted and the undo function restores it, // the (custom rig) suffix will not appear next to the character name. // To make sure this happens, we update the drop down containing the // list of character names. hikUpdateCharacterList; // Update the list of possible source too. If a source (eg. control rig) has // been deleted, we want to make sure we aren't displaying an invalid source. hikUpdateSourceList; string $character = hikGetCurrentCharacter(); // Next we temporarily disable maya's undo mechanism ... int $undo = hikTurnOffUndo(); // ... force a UI refresh hikUpdateContextualUI; // ... update the custom rig window (if necessary) int $hasRig = hikHasCustomRig( $character ); if ( $hasRig ) hikUpdateCustomRigUI; // ... and restore undo (if it was orignally active) hikRestoreUndo( $undo ); // Lastly we push the custom rig tab to the top of the // tab stack if a custom rig exists if ( $hasRig ) hikSelectCustomRigTab; }