// =========================================================================== // 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. // =========================================================================== global int $gSelChanged_cMuscleSelf ; // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- // UI Procs // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- /* * cMuscleSelfCollisionUI() - UI For self collision groupings */ global proc cMuscleSelfCollisionUI() { global int $gSelChanged_cMuscleSelf ; if (!`pluginInfo -q -loaded "MayaMuscle"`) error (uiRes("m_cMuscleSelfCollisionUI.kMustLoadMusclePlugin")); if (`window -q -ex cMuscleSelfCollisionUIWin`) { showWindow cMuscleSelfCollisionUIWin ; return ; } window -w 290 -h 400 -t (uiRes("m_cMuscleSelfCollisionUI.kWindowTitleSelfCollisionGrouping")) cMuscleSelfCollisionUIWin ; formLayout mainSelfForm ; text -l (uiRes("m_cMuscleSelfCollisionUI.kMuscleSystem")) txCMS ; textField -tx "" -ed 0 tfCMS ; button -l "<<<" -c ("cMuscleSelf_loadCMS();") -ann (uiRes("m_cMuscleSelfCollisionUI.kMuscleSystemAnnot")) btnCMS ; text -l (uiRes("m_cMuscleSelfCollisionUI.kName")) txName ; textField -tx "" tfName ; button -l (uiRes("m_cMuscleSelfCollisionUI.kPointA")) -c ("cMuscleSelf_select(\"tfA\");") txA ; textField -tx "" tfA ; button -l "<<<" -c ("cMuscleSelf_loadPts(\"tfA\");") -ann (uiRes("m_cMuscleSelfCollisionUI.kPointAAnnot")) btnA ; popupMenu -p tfA pmPtsA ; menuItem -l (uiRes("m_cMuscleSelfCollisionUI.kSelectPointsInA")) -c ("cMuscleSelf_select(\"tfA\");") ; menuItem -divider true ; menuItem -l (uiRes("m_cMuscleSelfCollisionUI.kLoadSelectedIntoPointsA")) -c ("cMuscleSelf_loadPts(\"tfA\");") ; menuItem -l (uiRes("m_cMuscleSelfCollisionUI.kAddSelectedIntoPointsA")) -c ("cMuscleSelf_addRemPts(\"tfA\", 1);") ; menuItem -l (uiRes("m_cMuscleSelfCollisionUI.kRemoveSelectedFromPointsA")) -c ("cMuscleSelf_addRemPts(\"tfA\", 0);") ; button -l (uiRes("m_cMuscleSelfCollisionUI.kPointsB")) -c ("cMuscleSelf_select(\"tfB\");") txB ; textField -tx "" tfB ; button -l "<<<" -c ("cMuscleSelf_loadPts(\"tfB\");") -ann (uiRes("m_cMuscleSelfCollisionUI.kPointsBAnnot")) btnB ; popupMenu -p tfB pmPtsB ; menuItem -l (uiRes("m_cMuscleSelfCollisionUI.kSelectPointsInB")) -c ("cMuscleSelf_select(\"tfB\");") ; menuItem -divider true ; menuItem -l (uiRes("m_cMuscleSelfCollisionUI.kLoadSelectedIntoPointsB")) -c ("cMuscleSelf_loadPts(\"tfB\");") ; menuItem -l (uiRes("m_cMuscleSelfCollisionUI.kAddSelectedIntoPointsB")) -c ("cMuscleSelf_addRemPts(\"tfB\", 1);") ; menuItem -l (uiRes("m_cMuscleSelfCollisionUI.kRemoveSelectedFromPointsB")) -c ("cMuscleSelf_addRemPts(\"tfB\", 0);") ; button -l (uiRes("m_cMuscleSelfCollisionUI.kCreateNewGrouping")) -c ("cMuscleSelf_createNew();") -ann (uiRes("m_cMuscleSelfCollisionUI.kCreateNewGroupingAnnot")) btnCreateNew ; text -l (uiRes("m_cMuscleSelfCollisionUI.kSelfCollisionGroups")) txGroups ; textScrollList -w 200 -ams false -nr 20 -sc ("cMuscleSelf_selectItemCB();") tslSelfGroups ; button -l (uiRes("m_cMuscleSelfCollisionUI.kEdit")) -w 300 -c ("cMuscleSelf_edit();") -ann (uiRes("m_cMuscleSelfCollisionUI.kEditAnnot")) btnEdit ; button -l (uiRes("m_cMuscleSelfCollisionUI.kDelete")) -w 300 -c ("cMuscleSelf_delete();") -ann (uiRes("m_cMuscleSelfCollisionUI.kDeleteAnnot")) btnDelete ; formLayout -e -attachForm txCMS "top" 8 -attachNone txCMS "bottom" -attachForm txCMS "left" 5 -attachNone txCMS "right" -attachForm tfCMS "top" 5 -attachNone tfCMS "bottom" -attachControl tfCMS "left" 5 txCMS -attachControl tfCMS "right" 5 btnCMS -attachForm btnCMS "top" 5 -attachNone btnCMS "bottom" -attachNone btnCMS "left" -attachForm btnCMS "right" 5 -attachControl txName "top" 8 tfCMS -attachNone txName "bottom" -attachForm txName "left" 5 -attachNone txName "right" -attachControl tfName "top" 5 tfCMS -attachNone tfName "bottom" -attachControl tfName "left" 5 txName -attachForm tfName "right" 5 -attachControl txA "top" 5 tfName -attachNone txA "bottom" -attachForm txA "left" 5 -attachNone txA "right" -attachControl tfA "top" 5 tfName -attachNone tfA "bottom" -attachControl tfA "left" 5 txA -attachControl tfA "right" 5 btnA -attachControl btnA "top" 5 tfName -attachNone btnA "bottom" -attachNone btnA "left" -attachForm btnA "right" 5 -attachControl txB "top" 5 tfA -attachNone txB "bottom" -attachForm txB "left" 5 -attachNone txB "right" -attachControl tfB "top" 5 tfA -attachNone tfB "bottom" -attachControl tfB "left" 5 txB -attachControl tfB "right" 5 btnB -attachControl btnB "top" 5 tfA -attachNone btnB "bottom" -attachNone btnB "left" -attachForm btnB "right" 5 -attachControl btnCreateNew "top" 5 tfB -attachNone btnCreateNew "bottom" -attachForm btnCreateNew "left" 5 -attachForm btnCreateNew "right" 5 -attachControl txGroups "top" 5 btnCreateNew -attachNone txGroups "bottom" -attachForm txGroups "left" 5 -attachNone txGroups "right" -attachControl tslSelfGroups "top" 5 txGroups -attachControl tslSelfGroups "bottom" 5 btnEdit -attachForm tslSelfGroups "left" 5 -attachForm tslSelfGroups "right" 5 -attachNone btnEdit "top" -attachForm btnEdit "bottom" 5 -attachForm btnEdit "left" 5 -attachPosition btnEdit "right" 0 49 -attachNone btnDelete "top" -attachForm btnDelete "bottom" 5 -attachPosition btnDelete "left" 0 50 -attachForm btnDelete "right" 5 mainSelfForm ; showWindow cMuscleSelfCollisionUIWin ; int $width = `text -q -w txCMS`; text -e -w $width -align right txName; button -e -w $width txA; button -e -w $width txB; cMuscleSelf_SelChangedCB() ; scriptJob -p cMuscleSelfCollisionUIWin -uiDeleted "cMuscleSelfCollisionUIWin" "cMuscleSelf_UIDeletedCB" ; $gSelChanged_cMuscleSelf = `scriptJob -p cMuscleSelfCollisionUIWin -event "SelectionChanged" "cMuscleSelf_SelChangedCB"` ; } // -------------------------------------------------------------------------- /* * cMuscleSelf_UIDeletedCB() - Quit proc callback */ global proc cMuscleSelf_UIDeletedCB() { } // -------------------------------------------------------------------------- /* * cMuscleSelf_SelChangedCB() - Selection changed callback */ global proc cMuscleSelf_SelChangedCB() { string $defOrig = `textField -q -tx tfCMS` ; cMuscleSelf_loadCMS() ; string $def = `textField -q -tx tfCMS` ; if ($def != $defOrig) cMuscleSelf_refresh() ; } // -------------------------------------------------------------------------- /* * cMuscleSelf_loadCMS() - load deformer to UI */ global proc cMuscleSelf_loadCMS() { // Get the list of cMuscleSystem Deformers from the selection... string $defs[] = cMuscle_getSelectedDeformers("cMuscleSystem") ; string $def = $defs[0] ; if ($def != "") textField -e -tx $def tfCMS ; } // -------------------------------------------------------------------------- /* * cMuscleSelf_refresh() - Refresh the UI */ global proc cMuscleSelf_refresh() { string $def = `textField -q -tx tfCMS` ; textScrollList -e -removeAll tslSelfGroups ; if ($def != "") { int $entries[] = `cMuscleQuery -system $def -selfcollide -index ` ; int $e ; for ($e = 0; $e < size($entries); ++$e) { int $g = $entries[$e] ; string $name = `getAttr ($def+".selfCollideData["+$g+"].selfName")` ; int $nA = `getAttr -size ($def+".selfCollideData["+$g+"].selfPtsA")` ; int $nB = `getAttr -size ($def+".selfCollideData["+$g+"].selfPtsB")` ; // The format of this string is important, because it'll be // parsed later on to retrieve the index $g. // string $item = ($g+1) + ". " + (uiRes("m_cMuscleSelfCollisionUI.kSelfCollisionItem")); $item = `format -stringArg $name -stringArg $nA -stringArg $nB $item`; textScrollList -e -a ($item) tslSelfGroups ; } } } // -------------------------------------------------------------------------- /* * cMuscleSelf_selectItemCB() - Callback for when item is selected. */ global proc cMuscleSelf_selectItemCB() { string $def = `textField -q -tx tfCMS` ; if ($def != "") { waitCursor -state on ; string $items[] = `textScrollList -q -si tslSelfGroups` ; string $item ; for ($item in $items) { string $parts[] ; tokenize($item, ".", $parts) ; if ($parts[0] != "") { int $g = (int)($parts[0]) - 1 ; string $name = `getAttr ($def+".selfCollideData["+$g+"].selfName")` ; int $nA = `getAttr -size ($def+".selfCollideData["+$g+"].selfPtsA")` ; int $nB = `getAttr -size ($def+".selfCollideData["+$g+"].selfPtsB")` ; textField -e -tx $name tfName ; float $ptsA[] = `getAttr ($def+".selfCollideData["+$g+"].selfPtsA")` ; float $ptsB[] = `getAttr ($def+".selfCollideData["+$g+"].selfPtsB")` ; string $strA="" ; string $strB="" ; float $pt ; for ($pt in $ptsA) $strA += (int)$pt + " " ; for ($pt in $ptsB) $strB += (int)$pt + " " ; textField -e -tx $strA tfA ; textField -e -tx $strB tfB ; } } waitCursor -state off ; } } // -------------------------------------------------------------------------- /* * cMuscleSelf_loadPts() - Load selected pts into ui... */ global proc cMuscleSelf_loadPts(string $tf) { string $def = `textField -q -tx tfCMS` ; textField -e -tx "" $tf ; if ($def != "") { string $pts[] = cMuscle_getSelComps($def, false) ; string $txPts ; string $pt ; // Also look at first one to assume shape... string $xforms[] = cMuscle_getGeoFromDeformer({$def}) ; string $shapes[] = `listRelatives -ni -shapes $xforms[0]` ; string $type = nodeType($shapes[0]) ; for ($pt in $pts) { int $idx = -1 ; if ($type == "nurbsSurface") { int $idxs[] = `cMuscleCompIndex $pt` ; // Convert nurbs double entry to single idx as deformer sees it in plugin $idx = $idxs[0] ; } else { // Parse out idx string $parts[] ; tokenize($pt, "[]", $parts) ; $idx = (int)($parts[1]) ; } $txPts += $idx + " " ; } textField -e -tx $txPts $tf ; } } // -------------------------------------------------------------------------- /* * cMuscleSelf_addRemPts() - Instead of replacing, adds or removes selected pts from the set */ global proc cMuscleSelf_addRemPts(string $tf, int $bAdd) { global int $gSelChanged_cMuscleSelf ; string $def = `textField -q -tx tfCMS` ; if ($def != "") { string $pts[] = cMuscle_getSelComps($def, false) ; string $txPts ; string $pt ; // Also look at first one to assume shape... string $xforms[] = cMuscle_getGeoFromDeformer({$def}) ; string $shapes[] = `listRelatives -ni -shapes $xforms[0]` ; string $type = nodeType($shapes[0]) ; // Now modify pts!!!! // we grab old and then add or subtract // cMuscleSelf_select($tf) ; string $ptsOrig[] = cMuscle_getSelComps($def, false) ; scriptJob -kill $gSelChanged_cMuscleSelf ; // Now add or deselect if ($bAdd == 1) select -add $pts ; else select -d $pts ; // Get final values... clear ($pts) ; $pts = cMuscle_getSelComps($def, false) ; $gSelChanged_cMuscleSelf = `scriptJob -p cMuscleSelfCollisionUIWin -event "SelectionChanged" "cMuscleSelf_SelChangedCB"` ; textField -e -tx "" $tf ; for ($pt in $pts) { int $idx = -1 ; if ($type == "nurbsSurface") { int $idxs[] = `cMuscleCompIndex $pt` ; // Convert nurbs double entry to single idx as deformer sees it in plugin $idx = $idxs[0] ; } else { // Parse out idx string $parts[] ; tokenize($pt, "[]", $parts) ; $idx = (int)($parts[1]) ; } $txPts += $idx + " " ; } textField -e -tx $txPts $tf ; } } // -------------------------------------------------------------------------- /* * cMuscleSelf_createNew() */ global proc cMuscleSelf_createNew() { string $def = `textField -q -tx tfCMS` ; if ($def != "") { string $txA = `textField -q -tx tfA` ; string $txB = `textField -q -tx tfB` ; string $ptsA[] ; string $ptsB[] ; tokenize($txA, " \t\r\n", $ptsA) ; tokenize($txB, " \t\r\n", $ptsB) ; string $name = `textField -q -tx tfName` ; if ($name == "" || strip($name) == "") error -sl 0 (uiRes("m_cMuscleSelfCollisionUI.kMustEnterValidCollisionGroup")) ; waitCursor -state on ; // Now we have to find an open entry...go thru until we find one with a name of "" int $g = 0 ; while (1) { string $nameTest = `getAttr ($def+".selfCollideData["+$g+"].selfName")` ; if ($nameTest == "") break ; // Got it...g looks empty... ++$g ; } // Now set the data setAttr -type "string" ($def+".selfCollideData["+$g+"].selfName") $name ; string $idx ; int $i ; for ($i=0; $i < size($ptsA); ++$i) { setAttr ($def+".selfCollideData["+$g+"].selfPtsA["+$i+"]") ((int)($ptsA[$i])) ; } for ($i=0; $i < size($ptsB); ++$i) { setAttr ($def+".selfCollideData["+$g+"].selfPtsB["+$i+"]") ((int)($ptsB[$i])) ; } } textField -e -tx "" tfName ; textField -e -tx "" tfA ; textField -e -tx "" tfB ; waitCursor -state off ; cMuscleSelf_refresh() ; } // -------------------------------------------------------------------------- /* * cMuscleSelf_delete() */ global proc cMuscleSelf_delete() { string $def = `textField -q -tx tfCMS` ; if ($def != "") { string $items[] = `textScrollList -q -si tslSelfGroups` ; string $item ; for ($item in $items) { string $parts[] ; tokenize($item, ".", $parts) ; if ($parts[0] != "") { int $g = (int)($parts[0]) - 1 ; removeMultiInstance -b true ($def+".selfCollideData["+$g+"]") ; } } } cMuscleSelf_refresh() ; } // -------------------------------------------------------------------------- /* * cMuscleSelf_edit() */ global proc cMuscleSelf_edit() { cMuscleSelf_delete() ; cMuscleSelf_createNew() ; } // -------------------------------------------------------------------------- /* * cMuscleSelf_select() - Select the pts again */ global proc cMuscleSelf_select(string $tf) { global int $gSelChanged_cMuscleSelf ; scriptJob -kill $gSelChanged_cMuscleSelf ; string $def = `textField -q -tx tfCMS` ; if ($def != "") { waitCursor -state on ; // Also look at first one to assume shape... string $xforms[] = cMuscle_getGeoFromDeformer({$def}) ; string $shapes[] = `listRelatives -ni -shapes $xforms[0]` ; string $type = nodeType($shapes[0]) ; string $strPts = `textField -q -tx $tf` ; string $pts[] ; tokenize($strPts, " \t\r\n", $pts) ; select -cl ; hilite $shapes[0] ; for ($pt in $pts) { if ($type == "nurbsSurface") { select -add ($shapes[0]+".cv["+$pt+"]") ; } else { select -add ($shapes[0]+".vtx["+$pt+"]") ; } } waitCursor -state off ; } $gSelChanged_cMuscleSelf = `scriptJob -p cMuscleSelfCollisionUIWin -event "SelectionChanged" "cMuscleSelf_SelChangedCB"` ; } // --------------------------------------------------------------------------