// =========================================================================== // 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. // =========================================================================== source "blendShapeTurnOnParentsVisibility.mel"; global proc blendShapeToggleSoloState(string $bsdName, string $id, string $ibIndex) // // Description: // If the clicked item is invisible, or some of the items other // than the clicked item are visible, turn the clicked item on and // all others off. Other wise, return all other items to their // last-known visibility states. // { string $clickedAttr; int $isBlendShapeOrBlendShapeGroup = 0; if (endsWith($bsdName, "shapeEditorManager")) { // blendShape group $clickedAttr = $bsdName + ".blendShapeDirectory[" + stringRemovePrefix($id, "-") + "].directoryVisibility"; $isBlendShapeOrBlendShapeGroup = 1; } else if ($id == "") { // blendShape $clickedAttr = $bsdName + ".targetDirectory[0].directoryVisibility"; $isBlendShapeOrBlendShapeGroup = 1; } else if (startsWith($id, "-")) { // target group $clickedAttr = $bsdName + ".targetDirectory[" + stringRemovePrefix($id, "-") + "].directoryVisibility"; } else if ($ibIndex == "") { // target $clickedAttr = $bsdName + ".targetVisibility[" + $id + "]"; } else { // inbetween target $clickedAttr = $bsdName + ".inbetweenInfoGroup[" + $id + "].inbetweenInfo[" + $ibIndex + "].inbetweenVisibility"; } turnOnParentsForSingleAttr($clickedAttr); int $visible = `getAttr $clickedAttr`; // Get all the visible items other than the clicked item and its parents and children string $otherVisibleAttrs[] = getOtherVisibleAttrs($bsdName, $id, $ibIndex, $isBlendShapeOrBlendShapeGroup); string $soloNodeName; if ($isBlendShapeOrBlendShapeGroup) $soloNodeName = "shapeEditorManager"; else if ($ibIndex == "") $soloNodeName = $bsdName; else $soloNodeName = $bsdName + "." + $id; string $visibilityStateOption = "blendShapeVisibilityStatesBeforeSolo" + $soloNodeName; string $nodeNameOption = "blendShapeSoloNodeNames"; if (!$visible || size($otherVisibleAttrs) > 0) { // Start soloing: remembering the original states of other items, and turn them off if (`optionVar -exists $nodeNameOption`) { string $soloNodeNames[] = `optionVar -q $nodeNameOption`; if (!stringArrayContains($soloNodeName, $soloNodeNames)) optionVar -sva $nodeNameOption $soloNodeName; } else optionVar -sva $nodeNameOption $soloNodeName; if (`optionVar -exists $visibilityStateOption`) optionVar -ca $visibilityStateOption; for ($attr in $otherVisibleAttrs) { optionVar -sva $visibilityStateOption $attr; setAttr $attr 0; } if (!$visible) setAttr $clickedAttr 1; } else { // Stop soloing: return other items to their last-known visibility states if (`optionVar -exists $visibilityStateOption`) { string $oldVisibleAttrs[] = `optionVar -q $visibilityStateOption`; for ($attr in $oldVisibleAttrs) setAttr $attr 1; optionVar -ca $visibilityStateOption; } } } global proc string[] getOtherVisibleAttrs(string $bsdName, string $id, string $ibIndex, int $isBlendShapeOrBlendShapeGroup) { string $excludedItems[], $visibleAttrs[]; if ($isBlendShapeOrBlendShapeGroup) { string $manager; // blendShape or blendShape group if (endsWith($bsdName, "shapeEditorManager")) { if ($id == "0") { // referenced root $manager = "shapeEditorManager"; string $managerPlug[] = `listConnections -s 1 -d 0 -p 1 ($bsdName + ".blendShapeDirectory[0].directoryParentVisibility")`; if (size($managerPlug) && startsWith($managerPlug[0], "shapeEditorManager.outBlendShapeVisibility[") && endsWith($managerPlug[0], "]")) $id = substring($managerPlug[0], 44, size($managerPlug[0]) - 1); } else // blendShape group $manager = $bsdName; } else { // blendShape node string $managers[] = `listConnections -s 0 -d 1 ($bsdName + ".midLayerParent")`; $manager = $managers[0]; $id = `getAttr ($bsdName + ".midLayerId")`; } $excludedItems[size($excludedItems)] = $id; $excludedItems = stringArrayCatenate($excludedItems, getBlendShapeParentItems($manager, $id)); $excludedItems = stringArrayCatenate($excludedItems, getBlendShapeGroupChildItems($manager, $id)); int $allBlendShapes[] = `getAttr -multiIndices ($manager + ".blendShapeParent")`; int $allGroups[] = `getAttr -multiIndices ($manager + ".blendShapeDirectory")`; for ($bsd in $allBlendShapes) { if (!stringArrayContains($bsd, $excludedItems)) { string $visibilityAttr; string $name = blendShapeGetNodeNameById($manager, $bsd); if (endsWith($name, "shapeEditorManager")) $visibilityAttr = $name + ".blendShapeDirectory[0].directoryVisibility"; else $visibilityAttr = $name + ".targetDirectory[0].directoryVisibility"; if (`getAttr $visibilityAttr`) $visibleAttrs[size($visibleAttrs)] = $visibilityAttr; } } for ($bsdG in $allGroups) { string $groupId = stringAddPrefix($bsdG, "-"); if (!stringArrayContains($groupId, $excludedItems)) { string $visibilityAttr = $manager + ".blendShapeDirectory[" + $bsdG + "].directoryVisibility"; if (`getAttr $visibilityAttr`) $visibleAttrs[size($visibleAttrs)] = $visibilityAttr; } } if ($manager != "shapeEditorManager") $visibleAttrs = stringArrayCatenate($visibleAttrs, getOtherVisibleAttrs($manager, 0, "", 1)); } else if ($ibIndex == "") { // target or target group $excludedItems[size($excludedItems)] = $id; $excludedItems = stringArrayCatenate($excludedItems, getTargetParentItems($bsdName, $id)); $excludedItems = stringArrayCatenate($excludedItems, getTargetGroupChildItems($bsdName, $id)); int $allTargets[] = `getAttr -multiIndices ($bsdName + ".weight")`; int $allGroups[] = `getAttr -multiIndices ($bsdName + ".targetDirectory")`; for ($tgt in $allTargets) { if (!stringArrayContains($tgt, $excludedItems)) { string $visibilityAttr = $bsdName + ".targetVisibility[" + $tgt + "]"; if (`getAttr $visibilityAttr`) $visibleAttrs[size($visibleAttrs)] = $visibilityAttr; } } for ($tgtG in $allGroups) { string $groupId = stringAddPrefix($tgtG, "-"); if (!stringArrayContains($groupId, $excludedItems)) { string $visibilityAttr = $bsdName + ".targetDirectory[" + $tgtG + "].directoryVisibility"; if (`getAttr $visibilityAttr`) $visibleAttrs[size($visibleAttrs)] = $visibilityAttr; } } } else { // in-between target int $allIbTargets[] = `getAttr -multiIndices ($bsdName + ".inbetweenInfoGroup[" + $id + "].inbetweenInfo")`; for ($iBtgt in $allIbTargets) { if ($iBtgt != $ibIndex && $iBtgt != 6000) { string $visibilityAttr = $bsdName + ".inbetweenInfoGroup[" + $id + "].inbetweenInfo[" + $iBtgt + "].inbetweenVisibility"; if (`getAttr $visibilityAttr`) $visibleAttrs[size($visibleAttrs)] = $visibilityAttr; } } } return $visibleAttrs; } global proc string[] getBlendShapeParentItems(string $manager, string $id) { string $parentItems[]; string $parentIndexAttr; if (startsWith($id, "-")) // blendShape group $parentIndexAttr = $manager + ".blendShapeDirectory[" + stringRemovePrefix($id, "-") + "].parentIndex"; else // blendShape $parentIndexAttr = $manager + ".blendShapeParent[" + $id + "]"; int $parentIndex = `getAttr $parentIndexAttr`; string $groupId = stringAddPrefix($parentIndex, "-"); $parentItems[size($parentItems)] = $groupId; if ($parentIndex > 0) $parentItems = stringArrayCatenate($parentItems, getBlendShapeParentItems($manager, $groupId)); return $parentItems; } global proc string[] getTargetParentItems(string $bsdName, string $id) { string $parentItems[]; string $parentIndexAttr; if (startsWith($id, "-")) // target group $parentIndexAttr = $bsdName + ".targetDirectory[" + stringRemovePrefix($id, "-") + "].parentIndex"; else // target $parentIndexAttr = $bsdName + ".parentDirectory[" + $id + "]"; int $parentIndex = `getAttr $parentIndexAttr`; string $groupId = stringAddPrefix($parentIndex, "-"); $parentItems[size($parentItems)] = $groupId; if ($parentIndex > 0) $parentItems = stringArrayCatenate($parentItems, getTargetParentItems($bsdName, $groupId)); return $parentItems; } global proc string[] getBlendShapeGroupChildItems(string $manager, string $id) { string $childItems[]; if (startsWith($id, "-")) { string $childAttr = $manager + ".blendShapeDirectory[" + stringRemovePrefix($id, "-") + "].childIndices"; int $childIndices[] = `getAttr $childAttr`; for ($child in $childIndices) { $childItems[size($childItems)] = $child; $childItems = stringArrayCatenate($childItems, getBlendShapeGroupChildItems($manager, $child)); } } return $childItems; } global proc string[] getTargetGroupChildItems(string $bsdName, string $id) { string $childItems[]; if (startsWith($id, "-")) { string $childAttr = $bsdName + ".targetDirectory[" + stringRemovePrefix($id, "-") + "].childIndices"; int $childIndices[] = `getAttr $childAttr`; for ($child in $childIndices) { $childItems[size($childItems)] = $child; $childItems = stringArrayCatenate($childItems, getTargetGroupChildItems($bsdName, $child)); } } return $childItems; }