/****************************************************************************** NintendoWare for CTR Maya Plugin File: NW4C_SetCombineGroup.mel Description: set combine group Date: 2010/07/01 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. ******************************************************************************/ // UpdateWindow DoSearch /****************************************************************************** is scene anim object ******************************************************************************/ proc int IsSceneAnimObject(string $node) { string $type = nodeType($node); string $childs[] = `listRelatives -pa -s $node`; if (size(`ls -cameras -lights -typ environmentFog $childs`) > 0 || $type == "lookAt") { return true; } return false; } /****************************************************************************** get selected transform (except camera & light) return node size ******************************************************************************/ proc int GetSelectedXform(string $xforms[]) { clear($xforms); string $nodes[] = `ls -sl -typ transform`; for ($node in $nodes) { if (!IsSceneAnimObject($node)) { $xforms[size($xforms)] = $node; } } return size($xforms); } /****************************************************************************** combine group ******************************************************************************/ global proc int nw4cSetCombineGroup_Get_UseCombineGroup(string $node) { return (`attributeQuery -n $node -ex "nw4cUseCombineGroup"`) ? `getAttr ($node + ".nw4cUseCombineGroup")` : 0; } global proc nw4cSetCombineGroup_Add_UseCombineGroup(string $node) { if (!`attributeQuery -n $node -ex "nw4cUseCombineGroup"`) { addAttr -ln "nw4cUseCombineGroup" -at "bool" -dv 0 -h 1 $node; } } global proc nw4cSetCombineGroup_Set_UseCombineGroup(string $node, int $val) { nw4cSetCombineGroup_Add_UseCombineGroup($node); setAttr ($node + ".nw4cUseCombineGroup") $val; } proc SetJob_UseCombineGroup(string $node) { if (!`attributeQuery -n $node -ex "nw4cUseCombineGroup"`) { return; } scriptJob -p nw4cSetCombineGroup_UseCombineGroup -rp -ac ($node + ".nw4cUseCombineGroup") ("if (`nw4cSetCombineGroup_Get_UseCombineGroup " + $node + "`) radioButtonGrp -e -sl 1 nw4cSetCombineGroup_UseCombineGroup;" + "else radioButtonGrp -e -sl 1 nw4cSetCombineGroup_DontCare;" + "control -e -en `nw4cSetCombineGroup_Get_UseCombineGroup " + $node + "` nw4cSetCombineGroup_CombineGroup;"); } global proc nw4cSetCombineGroup_UseCombineGroupCB(string $mainNode) { string $xforms[]; GetSelectedXform($xforms); int $val = `radioButtonGrp -q -sl nw4cSetCombineGroup_UseCombineGroup`; control -e -en $val nw4cSetCombineGroup_CombineGroup; control -e -en $val nw4cSetCombineGroup_SetSequentialBtn; for ($node in $xforms) { nw4cSetCombineGroup_Set_UseCombineGroup($node, $val); } SetJob_UseCombineGroup($mainNode); } /****************************************************************************** combine group number ******************************************************************************/ global proc int nw4cSetCombineGroup_Get_CombineGroup(string $node) { return (`attributeQuery -n $node -ex "nw4cCombineGroup"`) ? `getAttr ($node + ".nw4cCombineGroup")` : 0; } global proc nw4cSetCombineGroup_Add_CombineGroup(string $node) { if (!`attributeQuery -n $node -ex "nw4cCombineGroup"`) { addAttr -ln "nw4cCombineGroup" -at "short" -min 0 -max 255 -dv 0 -h 1 $node; } } global proc nw4cSetCombineGroup_Set_CombineGroup(string $node, int $val) { nw4cSetCombineGroup_Add_CombineGroup($node); setAttr ($node + ".nw4cCombineGroup") $val; } proc SetJob_CombineGroup(string $node) { if (!`attributeQuery -n $node -ex "nw4cCombineGroup"`) { return; } scriptJob -p nw4cSetCombineGroup_CombineGroup -rp -ac ($node + ".nw4cCombineGroup") ("intField -e -v (`nw4cSetCombineGroup_Get_CombineGroup " + $node + "`) nw4cSetCombineGroup_CombineGroup"); } global proc nw4cSetCombineGroup_CombineGroupCB(string $mainNode) { string $xforms[]; GetSelectedXform($xforms); int $val = `intField -q -v nw4cSetCombineGroup_CombineGroup`; if ($val < 0) { $val = 0; intField -e -v $val nw4cSetCombineGroup_CombineGroup; } else if ($val > 255) { $val = 255; intField -e -v $val nw4cSetCombineGroup_CombineGroup; } for ($node in $xforms) { nw4cSetCombineGroup_Set_CombineGroup($node, $val); } SetJob_CombineGroup($mainNode); } /****************************************************************************** update window ******************************************************************************/ global proc nw4cSetCombineGroup_UpdateWindow() { //----------------------------------------------------------------------------- // get selection string $xforms[]; GetSelectedXform($xforms); int $enableFlag = (size($xforms) > 0); //----------------------------------------------------------------------------- // set node name string $nodesName; if ($enableFlag) { $nodesName = $xforms[0]; int $nodeSize = size($xforms); for ($inode = 1; $inode < $nodeSize; ++$inode) { if ($inode == 3) { $nodesName += ", ... (" + $nodeSize + ")"; break; } $nodesName += ", " + $xforms[$inode]; } } else { $nodesName = "(None)"; } text -e -l $nodesName nw4cSetCombineGroup_NodeName; //----------------------------------------------------------------------------- // set current attr & change command int $useCombineGroup = 0; if ($enableFlag) { string $node = $xforms[0]; $useCombineGroup = `nw4cSetCombineGroup_Get_UseCombineGroup $node`; radioButtonGrp -e -sl (!$useCombineGroup) -on1 ("nw4cSetCombineGroup_UseCombineGroupCB " + $node) nw4cSetCombineGroup_DontCare; radioButtonGrp -e -sl $useCombineGroup -on1 ("nw4cSetCombineGroup_UseCombineGroupCB " + $node) nw4cSetCombineGroup_UseCombineGroup; intField -e -v `nw4cSetCombineGroup_Get_CombineGroup $node` -cc ("nw4cSetCombineGroup_CombineGroupCB " + $node) nw4cSetCombineGroup_CombineGroup; // setAttr などで変更された場合に、 // コントロールの値を更新するため SetJob_UseCombineGroup($node); SetJob_CombineGroup($node); } //----------------------------------------------------------------------------- // set enable state control -e -en $enableFlag nw4cSetCombineGroup_DontCare; control -e -en $enableFlag nw4cSetCombineGroup_UseCombineGroup; control -e -en ($enableFlag && $useCombineGroup) nw4cSetCombineGroup_CombineGroup; control -e -en $enableFlag nw4cSetCombineGroup_Description; control -e -en ($enableFlag && $useCombineGroup) nw4cSetCombineGroup_SetSequentialBtn; } /****************************************************************************** get hierarchy level ******************************************************************************/ proc int GetXformHierarchyLevel(string $node) { string $buffer[]; string $longName = `longNameOf($node)`; return `tokenize $longName "|" $buffer`; } /****************************************************************************** sort xforms ******************************************************************************/ proc SortXforms(string $xforms[], string $parents[], int $levels[]) { int $xfSize = size($xforms); for ($isg = 0; $isg < $xfSize - 1; ++$isg) { for ($jsg = $isg + 1; $jsg < $xfSize; ++$jsg) { string $xf0 = $xforms[$isg]; string $prnt0 = $parents[$isg]; int $lv0 = $levels[$isg]; string $xf1 = $xforms[$jsg]; string $prnt1 = $parents[$jsg]; int $lv1 = $levels[$jsg]; int $cond = 0; int $cmp; if ($lv0 == $lv1) { // レベルが同じなら次は親の名前でソートする $cmp = strcmp($prnt0, $prnt1); if ($cmp == 0) { // 親の名前が同じならノード名でソートする $cmp = strcmp($xf0, $xf1); } $cond = ($cmp > 0); } else { $cond = ($lv0 > $lv1); } if ($cond) { $xforms[$isg] = $xf1; $parents[$isg] = $prnt1; $levels[$isg] = $lv1; $xforms[$jsg] = $xf0; $parents[$jsg] = $prnt0; $levels[$jsg] = $lv0; } } } } /****************************************************************************** グループ番号を連続的に設定する ******************************************************************************/ global proc nw4cSetCombineGroup_SetSequential() { string $xforms[]; string $parents[]; int $hierarchyLevels[]; int $numXforms; int $i; GetSelectedXform($xforms); $numXforms = size($xforms); // グループ番号を取得する int $val = `intField -q -v nw4cSetCombineGroup_CombineGroup`; // 取得したグループ番号に xform の数を足して 255 を超えればエラーとする if (($val+$numXforms) <= 255) { // 各 xform の親ノードと階層構造のレベルを取得する for ($i=0; $i<$numXforms; $i++) { $parents[$i] = `firstParentOf $xforms[$i]`; $hierarchyLevels[$i] = `GetXformHierarchyLevel $xforms[$i]`; } // xform をソートする // 階層構造のレベル, 親ノードの名前, ノードの名前の順番でソートする SortXforms($xforms, $parents, $hierarchyLevels); print("NW4C_SetCombineGroup: Set sequaltial\n"); for ($i=0; $i<$numXforms; $i++) { print(" " + $xforms[$i] + ": combine group " + ($val + $i) + "\n"); nw4cSetCombineGroup_Set_CombineGroup($xforms[$i], ($val + $i)); } } else { error "The combine group number exceeds the limitation (255).\n"; } } /****************************************************************************** search mode callback ******************************************************************************/ global proc nw4cSetCombineGroup_SearchModeCB() { int $dontCare = (`radioButtonGrp -q -sl nw4cSetCombineGroup_SearchDontCare` == 1); int $useCombineGroup = (`radioButtonGrp -q -sl nw4cSetCombineGroup_SearchUseCombineGroup` == 1); control -e -en $useCombineGroup nw4cSetCombineGroup_SearchCompare; control -e -en $useCombineGroup nw4cSetCombineGroup_SearchCombineGroup; control -e -en ($dontCare || $useCombineGroup) nw4cSetCombineGroup_SearchBtn; } /****************************************************************************** search value callback ******************************************************************************/ global proc nw4cSetCombineGroup_SearchValueCB() { int $val = `intField -q -v nw4cSetCombineGroup_SearchCombineGroup`; if ($val < 0) { intField -e -v 0 nw4cSetCombineGroup_SearchCombineGroup; } else if ($val > 255) { intField -e -v 255 nw4cSetCombineGroup_SearchCombineGroup; } } /****************************************************************************** do search ******************************************************************************/ global proc nw4cSetCombineGroup_DoSearch() { int $searchUse = (`radioButtonGrp -q -sl nw4cSetCombineGroup_SearchUseCombineGroup` == 1); int $compare = `optionMenu -q -sl nw4cSetCombineGroup_SearchCompare` - 1; nw4cSetCombineGroup_SearchValueCB(); // clamp value int $searchVal = `intField -q -v nw4cSetCombineGroup_SearchCombineGroup`; int $nodeCount = 0; select -cl; string $xforms[] = `ls -typ transform`; for ($node in $xforms) { if (IsSceneAnimObject($node)) { continue; } int $useCombineGroup = nw4cSetCombineGroup_Get_UseCombineGroup($node); int $CombineGroup = nw4cSetCombineGroup_Get_CombineGroup($node); int $match = 0; if (!$searchUse) { $match = !$useCombineGroup; } else { if (!$useCombineGroup) { $match = 0; } else if ($compare == 0) { $match = ($CombineGroup < $searchVal); } else if ($compare == 1) { $match = ($CombineGroup <= $searchVal); } else if ($compare == 2) { $match = ($CombineGroup == $searchVal); } else if ($compare == 3) { $match = ($CombineGroup >= $searchVal); } else { $match = ($CombineGroup > $searchVal); } } if ($match) { select -add $node; ++$nodeCount; } } if ($nodeCount == 0) { print "Not found\n"; } else { string $msg = "Found: " + $nodeCount + " transform node"; if ($nodeCount >= 2) { $msg += "s"; } print ($msg + "\n"); } } /****************************************************************************** main ******************************************************************************/ global proc NW4C_SetCombineGroup() { int $afterMaya2011Adjust = 0; if (getApplicationVersionAsFloat() >= 2011) $afterMaya2011Adjust = 1; //----------------------------------------------------------------------------- // create window int $winW = 400; int $winH = 385; if (!`window -exists nw4cSetCombineGroup_Win`) { window -t "NW4C Set Combine Group" -wh $winW $winH -mxb 0 -mb 1 nw4cSetCombineGroup_Win; menu -l "Help"; menuItem -l ("Help on " + `window -q -t nw4cSetCombineGroup_Win` + "...") -c "NW4C_ShowHelp \"html/NW4C_SetCombineGroup.html\" \"\""; columnLayout -adj 1 -cat "both" 4 -cal "center" -rs 4; //----------------------------------------------------------------------------- // node name frameLayout -l "Selected Transform Node" -cll 0 -cl 0 -bv 1 -bs "etchedIn"; columnLayout -adj 1 -cal "center" -rs 8; text -l "" nw4cSetCombineGroup_NodeName; setParent ..; // columnLayout setParent ..; // formLayout //----------------------------------------------------------------------------- // set frameLayout -l "Set" -cll 0 -cl 0 -bv 1 -bs "etchedIn"; columnLayout -adj 1 -cal "center" -rs 0; string $form2 = `formLayout -nd 400`; radioButtonGrp -l "Combine Group" -nrb 1 -cw2 110 80 -l1 "Don't care" nw4cSetCombineGroup_DontCare; radioButtonGrp -l "" -nrb 1 -cw2 110 18 -l1 "" -scl nw4cSetCombineGroup_DontCare nw4cSetCombineGroup_UseCombineGroup; intField -w 50 -v 0 nw4cSetCombineGroup_CombineGroup; text -l "Setting range 0 - 255" nw4cSetCombineGroup_Description; setParent ..; // formLayout formLayout -e -af nw4cSetCombineGroup_DontCare "top" 8 -af nw4cSetCombineGroup_DontCare "left" 0 -an nw4cSetCombineGroup_DontCare "bottom" -an nw4cSetCombineGroup_DontCare "right" -ac nw4cSetCombineGroup_UseCombineGroup "top" 8 nw4cSetCombineGroup_DontCare -af nw4cSetCombineGroup_UseCombineGroup "left" 0 -an nw4cSetCombineGroup_UseCombineGroup "bottom" -an nw4cSetCombineGroup_UseCombineGroup "right" -ac nw4cSetCombineGroup_CombineGroup "top" 4 nw4cSetCombineGroup_DontCare -ac nw4cSetCombineGroup_CombineGroup "left" 0 nw4cSetCombineGroup_UseCombineGroup -an nw4cSetCombineGroup_CombineGroup "bottom" -an nw4cSetCombineGroup_CombineGroup "right" -ac nw4cSetCombineGroup_Description "top" 4 nw4cSetCombineGroup_CombineGroup -ac nw4cSetCombineGroup_Description "left" 4 nw4cSetCombineGroup_UseCombineGroup -af nw4cSetCombineGroup_Description "bottom" 8 -an nw4cSetCombineGroup_Description "right" $form2; rowColumnLayout -nc 2 -cw 1 200 -cw 2 150; text -l ""; // dummy button -l "Set Sequential" -c "nw4cSetCombineGroup_SetSequential" nw4cSetCombineGroup_SetSequentialBtn; setParent ..; // rowColumnLayout separator -h 8 -st "none"; setParent ..; // columnLayout setParent ..; // frameLayout //----------------------------------------------------------------------------- // search frameLayout -l "Search" -cll 0 -cl 0 -bv 1 -bs "etchedIn"; columnLayout -adj 1 -cal "center" -rs 0; string $form3 = `formLayout -nd 400`; radioButtonGrp -l "" -nrb 1 -cw2 110 80 -l1 "Don't care" -on1 "nw4cSetCombineGroup_SearchModeCB" nw4cSetCombineGroup_SearchDontCare; radioButtonGrp -l "" -nrb 1 -cw2 110 18 -l1 "" -scl nw4cSetCombineGroup_SearchDontCare -on1 "nw4cSetCombineGroup_SearchModeCB" nw4cSetCombineGroup_SearchUseCombineGroup; optionMenu -w 110 nw4cSetCombineGroup_SearchCompare; menuItem -l "< : ( under )"; menuItem -l "<= : ( below )"; menuItem -l "= : ( exactly )"; menuItem -l ">= : ( above )"; menuItem -l "> : ( over )"; intField -w 50 -h 26 -v 0 -cc "nw4cSetCombineGroup_SearchValueCB" nw4cSetCombineGroup_SearchCombineGroup; setParent ..; // formLayout formLayout -e -af nw4cSetCombineGroup_SearchDontCare "top" 8 -af nw4cSetCombineGroup_SearchDontCare "left" 0 -an nw4cSetCombineGroup_SearchDontCare "bottom" -an nw4cSetCombineGroup_SearchDontCare "right" -ac nw4cSetCombineGroup_SearchUseCombineGroup "top" 10 nw4cSetCombineGroup_SearchDontCare -af nw4cSetCombineGroup_SearchUseCombineGroup "left" 0 -an nw4cSetCombineGroup_SearchUseCombineGroup "bottom" -an nw4cSetCombineGroup_SearchUseCombineGroup "right" -ac nw4cSetCombineGroup_SearchCompare "top" (4 + $afterMaya2011Adjust * 3) nw4cSetCombineGroup_SearchDontCare -ac nw4cSetCombineGroup_SearchCompare "left" 0 nw4cSetCombineGroup_SearchUseCombineGroup -an nw4cSetCombineGroup_SearchCompare "bottom" -an nw4cSetCombineGroup_SearchCompare "right" -ac nw4cSetCombineGroup_SearchCombineGroup "top" 4 nw4cSetCombineGroup_SearchDontCare -ac nw4cSetCombineGroup_SearchCombineGroup "left" 4 nw4cSetCombineGroup_SearchCompare -af nw4cSetCombineGroup_SearchCombineGroup "bottom" 8 -an nw4cSetCombineGroup_SearchCombineGroup "right" $form3; rowColumnLayout -nc 2 -cw 1 200 -cw 2 150; text -l ""; // dummy button -l "Search" -c "nw4cSetCombineGroup_DoSearch" nw4cSetCombineGroup_SearchBtn; setParent ..; // rowColumnLayout separator -h 8 -st "none"; setParent ..; // columnLayout setParent ..; // formLayout optionMenu -e -sl 3 nw4cSetCombineGroup_SearchCompare; setParent ..; // columnLayout //----------------------------------------------------------------------------- // close button string $closeCmd = "deleteUI nw4cSetCombineGroup_Win"; string $form = `formLayout -nd 100`; string $closeBtn = `button -h 26 -l "Close" -c $closeCmd`; formLayout -e -af $closeBtn "top" 0 -af $closeBtn "left" 0 -af $closeBtn "bottom" 0 -af $closeBtn "right" 0 $form; setParent ..; // formLayout setParent ..; // columnLayout setFocus $closeBtn; //----------------------------------------------------------------------------- // set selection change job scriptJob -p nw4cSetCombineGroup_Win -e "SelectionChanged" "nw4cSetCombineGroup_UpdateWindow"; } if (`window -q -w nw4cSetCombineGroup_Win` < $winW) { window -e -w $winW nw4cSetCombineGroup_Win; } if (`window -q -h nw4cSetCombineGroup_Win` < $winH) { window -e -h $winH nw4cSetCombineGroup_Win; } //window -e -wh $winW $winH nw4cSetCombineGroup_Win; //----------------------------------------------------------------------------- // update window nw4cSetCombineGroup_UpdateWindow; nw4cSetCombineGroup_SearchModeCB; //----------------------------------------------------------------------------- // show window showWindow nw4cSetCombineGroup_Win; }