// =========================================================================== // 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 // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- /* * cMuscleTransferWeights() - Main Entry */ global proc cMuscleTransferWeights() { if (`window -q -ex cMuscleTransferWeightsWin`) { showWindow cMuscleTransferWeightsWin ; return ; } window -w 350 -h 160 -t (uiRes("m_cMuscleTransferWeights.kWindowTitleMuscleTransferWeights")) cMuscleTransferWeightsWin ; scrollLayout mainMuscleTransferWeightsScrollLayout; formLayout -parent mainMuscleTransferWeightsScrollLayout xferForm ; text -l (uiRes("m_cMuscleTransferWeights.kMuscle")) txSysXfer ; textField -tx "" tfSysXfer ; button -l "<<<" -w 30 -c ("cMTW_loadSys();") -ann (uiRes("m_cMuscleTransferWeights.kMuscleAnnot")) btnSysXfer ; popupMenu -p tfSysXfer -pmc ("cMTW_buildSysMenu();") pmSysXfer ; text -l (uiRes("m_cMuscleTransferWeights.kTransferFrom")) txFromXfer ; textField -tx "" tfFromXfer ; button -l "<<<" -w 30 -c ("cMTW_loadObjs(\"tfFromXfer\");") -ann (uiRes("m_cMuscleTransferWeights.kTransferFromAnnot")) btnFromXfer ; text -l (uiRes("m_cMuscleTransferWeights.kTransferTo")) txToXfer ; textField -tx "" tfToXfer ; button -l "<<<" -w 30 -c ("cMTW_loadObj(\"tfToXfer\");") -ann (uiRes("m_cMuscleTransferWeights.kTransferToAnnot")) btnToXfer ; text -l (uiRes("m_cMuscleTransferWeights.kWeights")) -w 50 -al "left" txWtsXfer ; optionMenu optWtsXfer ; menuItem -l (uiRes("m_cMuscleTransferWeights.kWeightsSticky")) ; menuItem -l (uiRes("m_cMuscleTransferWeights.kWeightsStickyB")) ; menuItem -l (uiRes("m_cMuscleTransferWeights.kWeightsStickyC")) ; menuItem -l (uiRes("m_cMuscleTransferWeights.kWeightsSliding")) ; menuItem -l (uiRes("m_cMuscleTransferWeights.kWeightsDirection")) ; optionMenu -e -sl 1 optWtsXfer ; button -l (uiRes("m_cMuscleTransferWeights.kTransferWeightForSelected")) -c ("cMTW_transferUI();") -ann (uiRes("m_cMuscleTransferWeights.kTransferWeightForSelectedAnnot")) btnXfer ; formLayout -e -af txSysXfer "top" 8 -an txSysXfer "bottom" -af txSysXfer "left" 5 -an txSysXfer "right" -af tfSysXfer "top" 5 -an tfSysXfer "bottom" -ac tfSysXfer "left" 5 txSysXfer -ac tfSysXfer "right" 5 btnSysXfer -af btnSysXfer "top" 5 -an btnSysXfer "bottom" -an btnSysXfer "left" -af btnSysXfer "right" 5 -ac txFromXfer "top" 8 tfSysXfer -an txFromXfer "bottom" -af txFromXfer "left" 5 -an txFromXfer "right" -ac tfFromXfer "top" 5 tfSysXfer -an tfFromXfer "bottom" -ac tfFromXfer "left" 5 txFromXfer -ac tfFromXfer "right" 5 btnFromXfer -ac btnFromXfer "top" 5 tfSysXfer -an btnFromXfer "bottom" -an btnFromXfer "left" -af btnFromXfer "right" 5 -ac txToXfer "top" 8 tfFromXfer -an txToXfer "bottom" -af txToXfer "left" 5 -an txToXfer "right" -ac tfToXfer "top" 5 tfFromXfer -an tfToXfer "bottom" -ac tfToXfer "left" 5 txToXfer -ac tfToXfer "right" 5 btnToXfer -ac btnToXfer "top" 5 tfFromXfer -an btnToXfer "bottom" -an btnToXfer "left" -af btnToXfer "right" 5 -ac txWtsXfer "top" 8 tfToXfer -an txWtsXfer "bottom" -af txWtsXfer "left" 5 -an txWtsXfer "right" -ac optWtsXfer "top" 5 tfToXfer -an optWtsXfer "bottom" -ac optWtsXfer "left" 0 txWtsXfer -an optWtsXfer "right" -ac btnXfer "top" 5 optWtsXfer -an btnXfer "bottom" -af btnXfer "left" 5 -af btnXfer "right" 5 xferForm ; showWindow cMuscleTransferWeightsWin ; } // -------------------------------------------------------------------------- /* * cMTW_loadSys() - Loads the Maya Muscle node up into field */ global proc cMTW_loadSys() { string $objs[] = `ls -sl` ; if (size($objs) <= 0) return ; string $mSs[] = cMTW_getSysFromGeo($objs) ; string $mS ; if (nodeType($objs[0]) == "cMuscleSystem") { $mS = $objs[0] ; } else $mS = $mSs[0] ; textField -e -tx $mS tfSysXfer ; } // -------------------------------------------------------------------------- /* * cMTW_getSysGeosInScene() - Returns list of all system def'd geo in scene */ global proc string[] cMTW_getSysGeosInScene() { string $mSs[] = `ls -type "cMuscleSystem" "*"`; // Get ALL Sys in scene. string $mS ; string $geos[] ; clear $geos; int $nGeo = 0 ; for ($mS in $mSs) { string $thisGeos[] = `cMuscleQuery -geo -system $mS` ; string $parents[] = `listRelatives -parent $thisGeos` ; $geos[$nGeo] = $parents[0] ; ++$nGeo ; } $geos = stringArrayRemoveDuplicates($geos) ; return $geos ; } // -------------------------------------------------------------------------- /* * cMTW_buildSysMenu() - Makes popup menu for the geo list */ global proc cMTW_buildSysMenu() { menu -e -dai pmSysXfer ; setParent -menu pmSysXfer ; string $geos[] = cMTW_getSysGeosInScene() ; string $g; $geos = `sort $geos` ; for ($g in $geos) { string $mSs[] = cMTW_getSysFromGeo({$g}) ; // Go back and get all Systems from this geo... string $mS ; for ($mS in $mSs) { menuItem -l ($g+" - "+$mS) -c ("select -r \""+$mS+"\"; cMTW_loadSys(); ") ; } } } // -------------------------------------------------------------------------- /* * cMTW_loadObjs() */ global proc cMTW_loadObjs(string $tf) { string $objs[] = `ls -sl` ; string $obj ; string $text = "" ; for ($obj in $objs) $text += ($obj+" ") ; textField -e -tx $text $tf ; } // -------------------------------------------------------------------------- /* * cMTW_loadObj() */ global proc cMTW_loadObj(string $tf) { string $objs[] = `ls -sl` ; textField -e -tx $objs[0] $tf ; } // -------------------------------------------------------------------------- /* * cMTW_transferUI() - Wrapper */ global proc cMTW_transferUI() { string $mS = `textField -q -tx tfSysXfer` ; string $fromStr = `textField -q -tx tfFromXfer` ; string $from[] ; clear $from ; tokenize($fromStr, " \t", $from) ; string $to = `textField -q -tx tfToXfer` ; int $nWtName = `optionMenu -q -sl optWtsXfer` - 1 ; string $wtName = "sticky" ; if ($nWtName == 0) $wtName = "sticky" ; else if ($nWtName == 1) $wtName = "stickyb" ; else if ($nWtName == 2) $wtName = "stickyc" ; else if ($nWtName == 3) $wtName = "sliding" ; else if ($nWtName == 4) $wtName = "direction" ; cMuscle_fixDisconnected($mS) ; string $comps[] ; clear $comps ; $comps = cMuscle_getSelComps($mS, true) ; cMTW_transfer($mS, $from, $to, $wtName, $comps) ; } // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- // Worker Procs // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- /* * cMTW_transfer() - Main transfer proc * * $mS = cMuscleSystem node * $from = Array of objects to transfer weights off of * $to = Object to move weight onto * $wtName = Type of weights to transfer * $comps = Selected points to transfer for */ global proc cMTW_transfer(string $mS, string $from[], string $to, string $wtName, string $comps[]) { if ($mS == "") error -sl 0 (uiRes("m_cMuscleTransferWeights.kNoMuscleChosen")) ; if (size($from) <= 0 || $from[0] == "") error -sl 0 (uiRes("m_cMuscleTransferWeights.kNoTransferFrom")) ; if ($to == "") error -sl 0 (uiRes("m_cMuscleTransferWeights.kNoTransferTo")) ; if (size($comps) <= 0) error -sl 0 (uiRes("m_cMuscleTransferWeights.kNoPointsSelected")) ; int $nComp = size($comps) ; string $mOsFrom[] ; clear $mOsFrom ; string $mOsTos[] ; string $mOTo ; // Now get either muscles or muscleDirection nodes depending on the wt type... // if ($wtName == "sticky" || $wtName == "stickyb" || $wtName == "stickyc" || $wtName == "sliding") { $mOsFrom = `listRelatives -shapes -ni -type "cMuscleObject" $from`; if (size($mOsFrom) <= 0) error -sl 0 (uiRes("m_cMuscleTransferWeights.kMustSelectMuscleObject")) ; $mOsTos = `listRelatives -shapes -ni -type "cMuscleObject" $to`; $mOTo = $mOsTos[0] ; if ($mOTo == "") error -sl 0 (uiRes("m_cMuscleTransferWeights.kMustSelectMuscleObjectTransferTo")) ; } else if ($wtName == "direction") { $mOsFrom = `listRelatives -shapes -ni -type "cMuscleDirection" $from`; if (size($mOsFrom) <= 0) error -sl 0 (uiRes("m_cMuscleTransferWeights.kMustSelectMuscleDirection")) ; $mOsTos = `listRelatives -shapes -ni -type "cMuscleDirection" $to`; $mOTo = $mOsTos[0] ; if ($mOTo == "") error -sl 0 (uiRes("m_cMuscleTransferWeights.kMustSelectMuscleDirectionTransferTo")) ; } else error -sl 0 (uiRes("m_cMuscleTransferWeights.kUnknownWeightName")) ; // Auto unlock all weights first before loading... // if ($wtName == "sticky" || $wtName == "stickyb" || $wtName == "stickyc" || $wtName == "sliding") { string $nodes[] = `cMuscleQuery -system $mS -muscle` ; string $node ; for ($node in $nodes) cMuscleWeight -system $mS -muscle $node -wt $wtName -lock false ; // Edit lock } else if ($wtName == "direction") { string $nodes[] = `cMuscleQuery -system $mS -direction` ; string $node ; for ($node in $nodes) // Note flag here is always -muscle for all influence types regardless. cMuscleWeight -system $mS -muscle $node -wt $wtName -lock false ; // Edit lock } // Set up normalization int $bNormalize = true ; if ($wtName == "sliding" || $wtName == "direction") $bNormalize = false ; waitCursor -state on ; string $title = (uiRes("m_cMuscleTransferWeights.kProgressWindowTransferWeights")); $title = `format -stringArg $mOTo $title`; string $progress = (uiRes("m_cMuscleTransferWeights.kTransferWeightsInitialProgress")); $progress = `format -stringArg ($nComp-1) $progress`; progressWindow -title $title -progress 0 -status $progress -isInterruptable true ; // Go thru each point for ($i=0; $i < $nComp; ++$i) { if (`progressWindow -q -isCancelled`) { warning -sl 0 (uiRes("m_cMuscleTransferWeights.kTransferWeightsAborted")) ; break ; } int $nPct = 100.0 * $i / ($nComp) ; $progress = (uiRes("m_cMuscleTransferWeights.kTransferWeightsProgress")); $progress = `format -stringArg $i -stringArg ($nComp-1) -stringArg $nPct $progress`; progressWindow -e -progress $nPct -status $progress ; // Go thru each mO from for this pt string $mO ; for ($mO in $mOsFrom) { if ($i == 0) { string $msg = (uiRes("m_cMuscleTransferWeights.kTransferringWeightFromTo")); $msg = `format -stringArg $wtName -stringArg $mO -stringArg $mOTo $msg`; print ($msg) ; } // Get current sticky, sliding, or direction weight for the given FROM influence... float $curWts[] = `cMuscleWeight -system $mS -muscle $mO -wt $wtName -q -v $comps[$i]` ; if ($curWts[0] == 0.0) // If nothing on it, nothing to do! { //print ("// skip "+$mO+" for "+$comps[$i]+" //\n") ; continue ; } // Now get the weight we are about to assign onto... float $wtsTo[] = `cMuscleWeight -system $mS -muscle $mOTo -wt $wtName -q -v $comps[$i]` ; // Now set orig to 0...with no normalize! cMuscleWeight -muscle $mO -v 0.0 -normalize false -wt $wtName -system $mS $comps[$i] ; // And add wts to new one... cMuscleWeight -muscle $mOTo -v ($curWts[0]+$wtsTo[0]) -normalize $bNormalize -wt $wtName -system $mS $comps[$i] ; } } progressWindow -endProgress ; waitCursor -state off ; print (uiRes("m_cMuscleTransferWeights.kTransferWeightsComplete")) ; } // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- // Helper System Procs // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- global proc string[] cMTW_getSysFromGeo(string $objs[]) { string $mSs[] ; clear $mSs ; if (size($objs) <= 0 || $objs[0] == "") return $mSs ; string $hist[] = `listHistory -pdo true -il 1 $objs`; $mSs = `ls -type "cMuscleSystem" $hist` ; return $mSs ; } // --------------------------------------------------------------------------