// =========================================================================== // 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. // =========================================================================== // // Description: // This script provides a GUI for setting up blendShape normalization groups. // // Input Arguments: // None. // // Return Value: // None. // proc int[] getItgIndices( string $blendShape, int $multiIndex ) // // Description: // Return the used target indices for the inputTarget group. // { int $indices[]; string $aa[] = `listAttr -m -sn ( $blendShape + ".it[" + $multiIndex + "].itg" )`; for ( $a in $aa ) { string $tokens[]; tokenize $a "." $tokens; if ( size($tokens) != 3 ) continue; if ( $tokens[2] != "nid" ) continue; int $end = size($tokens[1]) - 1; string $index = `substring $tokens[1] 5 $end`; $indices[ size( $indices ) ] = $index; } return $indices; } proc int[] getGroups( string $blendShape, int $multiIndex, int $indices[] ) // // Description: // Return the used normalisation group IDs. // NB returns the IDs actually used by targets, not just all the multi indices of // the normalizationGroup attribute that happen to exist. // { int $groups[]; for ( $index in $indices ) { int $id = `getAttr ( $blendShape + ".it[" + $multiIndex + "].itg[" + $index + "].nid" )`; if ( $id == 0 ) continue; int $found = 0; for ( $group in $groups ) { if ( $group == $id ) { $found = 1; break; } } if ( $found == 0 ) $groups[ size( $groups ) ] = $id; } $groups = `sort $groups`; return $groups; } global proc editNormalizationGroupsEditId( string $blendShape, int $multiIndex, string $attr, string $ctrl ) // // Description: // Called when the user edits the normalisation group ID of a target. // { int $value = `intFieldGrp -q -v1 $ctrl`; if ( $value < 0 ) { // disallow values below zero // $value = 0; intFieldGrp -e -v1 $value $ctrl; } evalEcho( "setAttr " + $attr + " " + $value ); editNormalizationGroupsRefreshGroups( $blendShape, $multiIndex ); } global proc editNormalizationGroupsRefreshGroups( string $blendShape, int $multiIndex ) // // Description: // Rebuild the controls for the normalisation groups. // { global string $gEditNormalizationGroupsGroupsLayout; string $children[] = `layout -q -ca $gEditNormalizationGroupsGroupsLayout`; for ( $child in $children ) { deleteUI $child; } int $indices[] = getItgIndices( $blendShape, $multiIndex ); int $groups[] = getGroups( $blendShape, $multiIndex, $indices ); setParent $gEditNormalizationGroupsGroupsLayout; for ( $group in $groups ) { string $label = ( (uiRes("m_editNormalizationGroups.kGroup")) + $group ); string $attr = $blendShape + ".it[" + $multiIndex + "].ng[" + $group + "].nuw"; checkBoxGrp -label $label -l1 (uiRes("m_editNormalizationGroups.kUseWeights")) -v1 `getAttr $attr` -on1 ( "evalEcho( \"setAttr " + $attr + " 1\" )" ) -of1 ( "evalEcho( \"setAttr " + $attr + " 0\" )" ); } } global proc editNormalizationGroups() // // Description: // (Re)create the Edit Normalization Groups window. // { // we need two things: a blendShape node, and a geometry node so we can identify // the inputTarget index. // string $blendShape; int $multiIndex = -1; string $blendShapes[] = `ls -sl -typ blendShape`; if ( size( $blendShapes ) > 0 ) { // we allow a blendShape selection, provided it's unambiguous which // multiIndex is needed // string $ogs[] = `listAttr -m ( $blendShapes[0] + ".og" )`; if ( size( $ogs ) == 1 ) { $blendShape = $blendShapes[0]; $multiIndex = 0; } } if ( $blendShape == "" ) { $blendShapes = `ls -typ blendShape`; string $sels[] = `ls -sl`; for ( $sel in $sels ) { if ( nodeType( $sel ) == "transform" ) { string $children[] = `listRelatives -c -pa $sel`; if ( size( $children ) > 0 ) $sel = $children[0]; } for ( $bs in $blendShapes ) { string $geoms[] = `blendShape -q -g $bs`; int $i; for ( $i = 0; $i < size($geoms); $i++ ) { if ( $geoms[$i] == $sel ) { $blendShape = $bs; int $indices[] = `blendShape -q -gi $bs`; $multiIndex = $indices[$i]; break; } } if ( $blendShape != "" ) break; } } } if ( $blendShape == "" || $multiIndex < 0 ) { error (uiRes("m_editNormalizationGroups.kNoSelection")); return; } // get the indices // int $indices[] = getItgIndices( $blendShape, $multiIndex ); // delete the window if it already exists // if ( `window -ex editNormalizationGroupsWindow` == true ) { deleteUI editNormalizationGroupsWindow; } // create the window // window -title (uiRes("m_editNormalizationGroups.kEditNormalizationGroupsTitle")) -mxb true -mnb true -s true editNormalizationGroupsWindow; // create the controls // string $form = `formLayout`; // layout for targets // string $targetsLayout = `frameLayout -label (uiRes("m_editNormalizationGroups.kNormalizationGroupIds"))`; scrollLayout -childResizable true; columnLayout; for ( $index in $indices ) { string $label = `attributeName ( $blendShape + ".w[" + $index + "]" )`; string $attr = $blendShape + ".it[" + $multiIndex + "].itg[" + $index + "].nid"; int $value = `getAttr $attr`; string $ctrl = `intFieldGrp -label $label -v1 $value`; intFieldGrp -e -cc ( "editNormalizationGroupsEditId " + $blendShape + " " + $multiIndex + " " + $attr + " " + $ctrl ) $ctrl; } setParent ..; setParent ..; setParent ..; // layout for groups // global string $gEditNormalizationGroupsGroupsLayout; string $groupsLayout = `frameLayout -label (uiRes("m_editNormalizationGroups.kNormalizationGroups"))`; scrollLayout -childResizable true; string $col = `columnLayout`; $gEditNormalizationGroupsGroupsLayout = $col; setParent ..; setParent ..; setParent ..; // create the per-group controls // editNormalizationGroupsRefreshGroups( $blendShape, $multiIndex ); // lay out the form // formLayout -e -af $targetsLayout "top" 0 -ap $targetsLayout "bottom" 10 70 -af $targetsLayout "left" 0 -af $targetsLayout "right" 0 -ap $groupsLayout "top" 0 70 -af $groupsLayout "bottom" 0 -af $groupsLayout "left" 0 -af $groupsLayout "right" 0 $form; // finally show the window // showWindow editNormalizationGroupsWindow; }