// =========================================================================== // 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. // =========================================================================== /* * Includes */ /* * globals */ // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- // UI Procs // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- /* * cMuscleMirrorWeights() - Main Entry */ global proc cMuscleMirrorWeights() { global int $gCMusclePaint_wtCnt ; global string $gCMusclePaint_wtLabels[] ; if (`window -q -ex cMuscleMirrorWeightsWin`) { showWindow cMuscleMirrorWeightsWin ; return ; } window -w 350 -h 280 -t (uiRes("m_cMuscleMirrorWeights.kWindowTitleMirrorWeights")) cMuscleMirrorWeightsWin ; scrollLayout mainMirrorWeightsScrollLayout; columnLayout -parent mainMirrorWeightsScrollLayout -adj 1 mainCol ; // Top FORM // ///////////////////////////// formLayout -p mainCol topForm ; text -l (uiRes("m_cMuscleMirrorWeights.kNode")) txSysMirror ; textField -tx "" tfSysMirror ; button -l "<<<" -w 30 -c ("cMMW_loadSys();") -ann (uiRes("m_cMuscleMirrorWeights.kNodeAnnot")) btnSysMirror ; popupMenu -p tfSysMirror -pmc ("cMMW_buildSysMenu();") pmSysMirror ; // MIRROR FRAME // ///////////////////////////// frameLayout -l (uiRes("m_cMuscleMirrorWeights.kMirrorFrame")) -cl false -cll true -p mainCol cMMW_MirrorFrame ; formLayout -p cMMW_MirrorFrame mainMirrorForm ; text -l (uiRes("m_cMuscleMirrorWeights.kWeights")) -w 50 -al "left" txWtsMirror ; optionMenu optWtsMirror ; int $i ; for ($i=0; $i < $gCMusclePaint_wtCnt; ++$i) menuItem -l ($gCMusclePaint_wtLabels[ $i ]) ; optionMenu -e -sl 1 optWtsMirror ; radioButtonGrp -l (uiRes("m_cMuscleMirrorWeights.kMirrorFrameMirrorBy")) -nrb 2 -la2 (uiRes("m_cMuscleMirrorWeights.kMirrorFrameWorldPos")) (uiRes("m_cMuscleMirrorWeights.kMirrorFrameLocalPos")) -sl 1 -cw3 101 80 80 -ann (uiRes("m_cMuscleMirrorWeights.kMirrorFrameMirrorByAnnot")) rbgMirrorSpace ; text -l (uiRes("m_cMuscleMirrorWeights.kMirrorFrameTolerance")) txTol ; floatField -w 150 -v -1.0 -min -1.0 -pre 6 -en true tfTol ; popupMenu -p tfTol ; menuItem -l "0.0001" -c ("floatField -e -v 0.0001 tfTol ;") ; menuItem -l "0.001" -c ("floatField -e -v 0.001 tfTol ;") ; menuItem -l "0.01" -c ("floatField -e -v 0.01 tfTol ;") ; menuItem -l "0.1" -c ("floatField -e -v 0.1 tfTol ;") ; menuItem -divider true ; menuItem -l (uiRes("m_cMuscleMirrorWeights.kMirrorFrameToleranceDisabled")) -c ("floatField -e -v -1.0 tfTol ;") ; //radioButtonGrp -l "Mirror Dir.:" -nrb 6 -la6 "+X to -X" "+Y to -Y" "+Z to -Z" "-X to +X" "-Y to +Y" "-Z to +Z" -sl 1 -en true -cw6 63 60 60 60 60 60 60 rbgMirror ; text -l (uiRes("m_cMuscleMirrorWeights.kMirrorFrameDirection")) txMirrorDir ; radioCollection rbgMirror ; radioButton -l (uiRes("m_cMuscleMirrorWeights.kMirrorFrameX")) rbXtox ; radioButton -l (uiRes("m_cMuscleMirrorWeights.kMirrorFrameY")) rbYtoy ; radioButton -l (uiRes("m_cMuscleMirrorWeights.kMirrorFrameZ")) rbZtoz ; radioButton -l (uiRes("m_cMuscleMirrorWeights.kMirrorFrameXNeg")) rbxtoX ; radioButton -l (uiRes("m_cMuscleMirrorWeights.kMirrorFrameYNeg")) rbytoY ; radioButton -l (uiRes("m_cMuscleMirrorWeights.kMirrorFrameZNeg")) rbztoZ ; radioCollection -e -sl "rbXtox" rbgMirror ; text -l (uiRes("m_cMuscleMirrorWeights.kMirrorFrameSearch")) txSearch ; textField -tx "" tfSearch ; text -l (uiRes("m_cMuscleMirrorWeights.kMirrorFrameReplace")) txReplace ; textField -tx "" tfReplace ; popupMenu -p tfSearch ; menuItem -l (uiRes("m_cMuscleMirrorWeights.kSearchNone")) -c ("textField -e -tx \"\" tfSearch; textField -e -tx \"\" tfReplace; ") ; menuItem -l "Lf" -c ("textField -e -tx \"Lf\" tfSearch; textField -e -tx \"Rt\" tfReplace; ") ; menuItem -l "Rt" -c ("textField -e -tx \"Rt\" tfSearch; textField -e -tx \"Lf\" tfReplace; ") ; menuItem -l "Lt" -c ("textField -e -tx \"Lt\" tfSearch; textField -e -tx \"Rt\" tfReplace; ") ; menuItem -l "Rt" -c ("textField -e -tx \"Rt\" tfSearch; textField -e -tx \"Lt\" tfReplace; ") ; menuItem -l "_L" -c ("textField -e -tx \"_L\" tfSearch; textField -e -tx \"_R\" tfReplace; ") ; menuItem -l "_R" -c ("textField -e -tx \"_R\" tfSearch; textField -e -tx \"_L\" tfReplace; ") ; menuItem -l "Left" -c ("textField -e -tx \"Left\" tfSearch; textField -e -tx \"Right\" tfReplace; ") ; menuItem -l "Right" -c ("textField -e -tx \"Right\" tfSearch; textField -e -tx \"Left\" tfReplace; ") ; button -l (uiRes("m_cMuscleMirrorWeights.kMirrorFrameMirrorWeights")) -c ("cMMW_mirrorUI();") -ann (uiRes("m_cMuscleMirrorWeights.kMirrorFrameMirrorWeightsAnnot")) btnMirror ; formLayout -e -af txSysMirror "top" 8 -an txSysMirror "bottom" -af txSysMirror "left" 5 -an txSysMirror "right" -af tfSysMirror "top" 5 -an tfSysMirror "bottom" -ac tfSysMirror "left" 5 txSysMirror -ac tfSysMirror "right" 5 btnSysMirror -af btnSysMirror "top" 5 -af btnSysMirror "bottom" 2 -an btnSysMirror "left" -af btnSysMirror "right" 5 topForm ; formLayout -e -af txWtsMirror "top" 5 -an txWtsMirror "bottom" -af txWtsMirror "left" 5 -an txWtsMirror "right" -af optWtsMirror "top" 2 -an optWtsMirror "bottom" -ac optWtsMirror "left" 0 txWtsMirror -an optWtsMirror "right" -ac rbgMirrorSpace "top" 5 optWtsMirror -an rbgMirrorSpace "bottom" -af rbgMirrorSpace "left" 5 -an rbgMirrorSpace "right" -ac txTol "top" 8 rbgMirrorSpace -an txTol "bottom" -af txTol "left" 5 -an txTol "right" -ac tfTol "top" 5 rbgMirrorSpace -an tfTol "bottom" -ac tfTol "left" 5 txTol -af tfTol "right" 5 -ac txMirrorDir "top" 5 tfTol -an txMirrorDir "bottom" -af txMirrorDir "left" 5 -an txMirrorDir "right" -ac rbXtox "top" 5 tfTol -an rbXtox "bottom" -ac rbXtox "left" 5 txMirrorDir -an rbXtox "right" -ac rbYtoy "top" 5 tfTol -an rbYtoy "bottom" -ac rbYtoy "left" 5 rbXtox -an rbYtoy "right" -ac rbZtoz "top" 5 tfTol -an rbZtoz "bottom" -ac rbZtoz "left" 5 rbYtoy -an rbZtoz "right" -ac rbxtoX "top" 5 txMirrorDir -an rbxtoX "bottom" -ac rbxtoX "left" 5 txMirrorDir -an rbxtoX "right" -ac rbytoY "top" 5 txMirrorDir -an rbytoY "bottom" -ac rbytoY "left" 5 rbxtoX -an rbytoY "right" -ac rbztoZ "top" 5 txMirrorDir -an rbztoZ "bottom" -ac rbztoZ "left" 5 rbytoY -an rbztoZ "right" -ac txSearch "top" 8 rbxtoX -an txSearch "bottom" -af txSearch "left" 5 -an txSearch "right" -ac tfSearch "top" 5 rbxtoX -an tfSearch "bottom" -ac tfSearch "left" 5 txSearch -ap tfSearch "right" 0 49 -ac txReplace "top" 8 rbxtoX -an txReplace "bottom" -ap txReplace "left" 0 51 -an txReplace "right" -ac tfReplace "top" 5 rbxtoX -an tfReplace "bottom" -ac tfReplace "left" 5 txReplace -af tfReplace "right" 5 -ac btnMirror "top" 5 tfSearch -af btnMirror "bottom" 5 -af btnMirror "left" 5 -af btnMirror "right" 5 mainMirrorForm ; showWindow cMuscleMirrorWeightsWin ; } // -------------------------------------------------------------------------- /* * cMMW_loadSys() - Mirrors the cMuscleSystem node up into field */ global proc cMMW_loadSys() { string $objs[] = `ls -sl` ; if (size($objs) <= 0) return ; string $mSs[] = cMMW_getSysFromGeo($objs) ; string $mS ; if (nodeType($objs[0]) == "cMuscleSystem") { $mS = $objs[0] ; } else $mS = $mSs[0] ; textField -e -tx $mS tfSysMirror ; } // -------------------------------------------------------------------------- /* * cMMW_getSysGeosInScene() - Returns list of all system def'd geo in scene */ global proc string[] cMMW_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 ; } // -------------------------------------------------------------------------- /* * cMMW_buildSysMenu() - Makes popup menu for the geo list */ global proc cMMW_buildSysMenu() { menu -e -dai pmSysMirror ; setParent -menu pmSysMirror ; string $geos[] = cMMW_getSysGeosInScene() ; string $g; $geos = `sort $geos` ; for ($g in $geos) { string $mSs[] = cMMW_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+"\"; cMMW_loadSys(); ") ; } } } // -------------------------------------------------------------------------- /* * cMMW_mirrorUI() - Wrapper for mirror from ui call */ global proc cMMW_mirrorUI() { global int $gCMusclePaint_wtCnt ; global string $gCMusclePaint_wtNames[] ; global string $gCMusclePaint_wtLabels[] ; global int $gCMusclePaint_wtNormalize[] ; string $sys = `textField -q -tx tfSysMirror`; int $nWtName = `optionMenu -q -sl optWtsMirror` - 1 ; string $wtName = $gCMusclePaint_wtNames[$nWtName] ; int $space = `radioButtonGrp -q -sl rbgMirrorSpace` ; // world or local float $tol = `floatField -q -v tfTol` ; string $search = `textField -q -tx tfSearch` ; string $replace = `textField -q -tx tfReplace` ; int $mirrorAxis = 0 ; if (`radioButton -q -sl rbXtox`) $mirrorAxis = 0 ; else if (`radioButton -q -sl rbYtoy`) $mirrorAxis = 1 ; else if (`radioButton -q -sl rbZtoz`) $mirrorAxis = 2 ; else if (`radioButton -q -sl rbxtoX`) $mirrorAxis = 3 ; else if (`radioButton -q -sl rbytoY`) $mirrorAxis = 4 ; else if (`radioButton -q -sl rbztoZ`) $mirrorAxis = 5 ; string $comps[] = cMuscle_getSelComps($sys, true) ; cMMW_mirror($sys, $comps, $wtName, $space, $tol, $mirrorAxis, $search, $replace) ; } // -------------------------------------------------------------------------- /* * cMMW_mirror() - Real mirror proc */ global proc cMMW_mirror(string $sys, string $comps[], string $wtName, int $space, float $tol, int $mirrorAxis, string $search, string $replace ) { if (size($comps) <= 0) { error -sl 0 (uiRes("m_cMuscleMirrorWeights.kMustSelectPointToLoad")) ; } string $spaceStr = "" ; if ($space == 1) $spaceStr = "world" ; else $spaceStr = "object" ; // Call plugin to do actual save. setAttr ($sys+".envelope") 0.0 ; //select -r $comps ; cMuscleWeightMirror -sys $sys -wt $wtName -space $spaceStr -axis $mirrorAxis -tolerance $tol -src $search -rep $replace ; setAttr ($sys+".envelope") 1.0 ; } // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- // Helper System Procs // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- global proc string[] cMMW_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` ; $mSs = stringArrayRemoveDuplicates($mSs) ; return $mSs ; } // --------------------------------------------------------------------------