// =========================================================================== // 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. // =========================================================================== // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- // UI Procs // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- /* * cMuscleSetupMasterControl() - Main Entry */ global proc cMuscleSetupMasterControl() { if (`window -q -ex cMuscleSetupMasterControlWin`) { showWindow cMuscleSetupMasterControlWin ; return ; } window -w 350 -h 125 -t (uiRes("m_cMuscleSetupMasterControl.kWindowTitleSetupMasterMuscleControl")) cMuscleSetupMasterControlWin ; scrollLayout mainMuscleSetupMasterControlScrollLayout; formLayout -parent mainMuscleSetupMasterControlScrollLayout masterForm ; text -l (uiRes("m_cMuscleSetupMasterControl.kControls")) txControls ; textField -tx "" tfControls ; button -l "<<<" -w 30 -c ("cMSMC_loadObjs(\"tfControls\");") -ann (uiRes("m_cMuscleSetupMasterControl.kControlsAnnot")) btnControls ; text -l (uiRes("m_cMuscleSetupMasterControl.kMasterControl")) txMaster ; textField -tx "" tfMaster ; button -l "<<<" -w 30 -c ("cMSMC_loadObj(\"tfMaster\");") -ann (uiRes("m_cMuscleSetupMasterControl.kMasterControlAnnot")) btnMaster ; text -l (uiRes("m_cMuscleSetupMasterControl.kName")) txName ; textField -tx "" tfName ; popupMenu -p tfName pmName ; menuItem -l "ArmUpLf" -c ("textField -e -tx \"ArmUpLf\" tfName ; ") ; menuItem -l "ArmUpRt" -c ("textField -e -tx \"ArmUpRt\" tfName ; ") ; menuItem -l "ArmLoLf" -c ("textField -e -tx \"ArmLoLf\" tfName ; ") ; menuItem -l "ArmLoRt" -c ("textField -e -tx \"ArmLoRt\" tfName ; ") ; menuItem -divider true ; menuItem -l "LegUpLf" -c ("textField -e -tx \"LegUpLf\" tfName ; ") ; menuItem -l "LegUpRt" -c ("textField -e -tx \"LegUpRt\" tfName ; ") ; menuItem -l "LegLoLf" -c ("textField -e -tx \"LegLoLf\" tfName ; ") ; menuItem -l "LegLoRt" -c ("textField -e -tx \"LegLoRt\" tfName ; ") ; menuItem -divider true ; menuItem -l "Neck" -c ("textField -e -tx \"Neck\" tfName ; ") ; menuItem -l "Chest" -c ("textField -e -tx \"Neck\" tfName ; ") ; menuItem -l "Back" -c ("textField -e -tx \"Neck\" tfName ; ") ; menuItem -l "Belly" -c ("textField -e -tx \"Belly\" tfName ; ") ; menuItem -l "Butt" -c ("textField -e -tx \"Belly\" tfName ; ") ; button -l (uiRes("m_cMuscleSetupMasterControl.kSetupMasterMuscleControl")) -c ("cMSMC_setupMasterUI();") -ann (uiRes("m_cMuscleSetupMasterControl.kSetupMasterMuscleControlAnnot")) btnSetup ; formLayout -e -af txControls "top" 8 -an txControls "bottom" -af txControls "left" 5 -an txControls "right" -af tfControls "top" 5 -an tfControls "bottom" -ac tfControls "left" 5 txControls -ac tfControls "right" 5 btnControls -af btnControls "top" 5 -an btnControls "bottom" -an btnControls "left" -af btnControls "right" 5 -ac txMaster "top" 8 tfControls -an txMaster "bottom" -af txMaster "left" 5 -an txMaster "right" -ac tfMaster "top" 5 tfControls -an tfMaster "bottom" -ac tfMaster "left" 5 txMaster -ac tfMaster "right" 5 btnMaster -ac btnMaster "top" 5 tfControls -an btnMaster "bottom" -an btnMaster "left" -af btnMaster "right" 5 -ac txName "top" 8 tfMaster -an txName "bottom" -af txName "left" 5 -an txName "right" -ac tfName "top" 5 tfMaster -an tfName "bottom" -ac tfName "left" 5 txName -ac tfName "right" 5 btnMaster -ac btnSetup "top" 8 tfName -an btnSetup "bottom" -af btnSetup "left" 5 -af btnSetup "right" 5 masterForm ; showWindow cMuscleSetupMasterControlWin ; } // -------------------------------------------------------------------------- /* * cMSMC_loadObjs() */ global proc cMSMC_loadObjs(string $tf) { string $objs[] = `ls -sl` ; string $obj ; string $text = "" ; for ($obj in $objs) $text += ($obj+" ") ; textField -e -tx $text $tf ; } // -------------------------------------------------------------------------- /* * cMSMC_loadObj() */ global proc cMSMC_loadObj(string $tf) { string $objs[] = `ls -sl` ; textField -e -tx $objs[0] $tf ; } // -------------------------------------------------------------------------- /* * cMSMC_setupMasterUI() */ global proc cMSMC_setupMasterUI() { string $ctrlsStr = `textField -q -tx tfControls` ; string $ctrls[] ; clear $ctrls ; tokenize($ctrlsStr, " \t", $ctrls) ; string $master = `textField -q -tx tfMaster` ; string $name = `textField -q -tx tfName` ; cMSMC_setup( $ctrls, $master, $name) ; } // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- // Real Worker Procs // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- /* * cMSMC_setup() - Does real work of taking each muscle control and setting * up new custom attributes on the control for offset and new attrs * on a Master mover to control a bunch of muscles at once. */ global proc cMSMC_setup(string $ctrls[], string $master, string $name) { if (size($ctrls) <= 0 || $ctrls[0] == "") error -sl 0 (uiRes("m_cMuscleSetupMasterControl.kNoControlsProvided")) ; if ($master == "" || objExists($master) != true) error -sl 0 (uiRes("m_cMuscleSetupMasterControl.kInvalidMasterControl")) ; if ($name == "") error -sl 0 (uiRes("m_cMuscleSetupMasterControl.kNoBaseName")) ; string $attrs[] = {"jiggle", "cycle", "rest"} ; float $mins[] = {0.0, 1.0, 1.0} ; int $i; // Generate Expr string $expName = ("expMaster"+$name) ; if (objExists($expName)) delete $expName ; string $exp = "" ; string $msg = (uiRes("m_cMuscleSetupMasterControl.kMasterMuscleControlExpression")); $msg = `format -stringArg $expName $msg`; $exp += $msg; $exp += ("// \n") ; for ($i=0; $i < size($attrs); ++$i) { string $attr = $attrs[$i] ; string $msg = (uiRes("m_cMuscleSetupMasterControl.kMasterMuscleAttribute")); $msg = `format -stringArg $attr $msg`; $exp += $msg ; $exp += ("// --------------------- \n") ; float $largest = 0 ; string $ctrl ; for ($ctrl in $ctrls) { float $val = `getAttr ($ctrl+"."+$attr)` ; if ($val > $largest) $largest = $val ; if (objExists($ctrl+"."+(toupper($attr))) != true) addAttr -ln (toupper($attr)) -dv 0.0 -min 0.0 -k 1 $ctrl ; setAttr -k false ($ctrl+"."+$attr) ; } if (objExists($master+"."+$attr+$name) != true) addAttr -ln ($attr+$name) -dv 0.0 -min $mins[$i] -k 1 $master ; setAttr ($master+"."+$attr+$name) $largest ; for ($ctrl in $ctrls) { float $val = `getAttr ($ctrl+"."+$attr)` ; float $pct = 1.0 ; if ($largest != 0.0) $pct = $val / $largest ; $exp += ("float $val = ("+$pct+" * "+$master+"."+$attr+$name+") + ("+$ctrl+"."+(toupper($attr))+") ; \n") ; $exp += ("if ($val < "+$mins[$i]+") \n") ; $exp += (" $val = "+$mins[$i]+" ; \n") ; $exp += ($ctrl+"."+$attr+" = $val ; \n") ; $exp += ("// \n") ; } } expression -s $exp -n $expName ; select -r $master ; $msg = (uiRes("m_cMuscleSetupMasterControl.kSetupMasterMuscleControlMsg")); $msg = `format -stringArg $master $msg`; print $msg ; } // --------------------------------------------------------------------------