Skip to content

Commit

Permalink
RBF manager fix mirror pose issue. Also more robust mirror pose with …
Browse files Browse the repository at this point in the history
…custom names
  • Loading branch information
miquelcampos committed Nov 7, 2024
1 parent 67f570e commit 0347758
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 50 deletions.
71 changes: 23 additions & 48 deletions release/scripts/mgear/core/anim_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,21 @@ def isSideElement(name):
Returns:
bool
Deleted Parameters:
node: str
"""
# try first wiht side labels if is a node. This will fail with attrs
try:
if isinstance(name, str):
node = pm.PyNode(name)
if node.hasAttr("side_label"):
side = node.side_label.get()
if side in "LR":
return True
except pm.MayaNodeError:
pass

# old logic for back compatibility
if "_L_" in name or "_R_" in name:
return True

nameParts = stripNamespace(name).split("|")[-1]

for part in nameParts.split("_"):
Expand Down Expand Up @@ -132,6 +140,8 @@ def swapSideLabelNode(node):
Returns:
str
"""
if isinstance(node, str):
node = pm.PyNode(node)

# first check default swapSideLabel. For defaul Shifter naming system
name = node.stripNamespace()
Expand Down Expand Up @@ -1257,7 +1267,7 @@ def spine_FKToIK(fkControls, ikControls, matchMatrix_dict=None):
##################################################


def getMirrorTarget(nameSpace, node):
def getMirrorTarget(nameSpace=None, node=None):
"""Find target control to apply mirroring.
Args:
Expand All @@ -1267,11 +1277,18 @@ def getMirrorTarget(nameSpace, node):
Returns:
PyNode: Mirror target
"""
if not node:
return
if isinstance(node, str):
node = pm.PyNode(node)

if isSideElement(node.name()):
nameParts = stripNamespace(node.name()).split("|")[-1]
nameParts = swapSideLabel(nameParts)
nameTarget = ":".join([nameSpace, nameParts])
nameParts = swapSideLabelNode(nameParts)
if nameSpace:
nameTarget = ":".join([nameSpace, nameParts])
else:
nameTarget = nameParts
return getNode(nameTarget)
else:
# Center controls mirror onto self
Expand Down Expand Up @@ -1409,48 +1426,6 @@ def calculateMirrorData(srcNode, targetNode, flip=False):
)
return results


def calculateMirrorDataRBF(srcNode, targetNode):
"""Calculate the mirror data
Args:
srcNode (str): The source Node
targetNode ([dict[str]]): Target node
flip (bool, optional): flip option
Returns:
[{"target": node, "attr": at, "val": flipVal}]
"""
results = []

# mirror attribute of source
for attrName in listAttrForMirror(srcNode):

# Apply "Invert Mirror" check boxes
invCheckName = getInvertCheckButtonAttrName(attrName)
if not pm.attributeQuery(
invCheckName, node=srcNode, shortName=True, exists=True
):
inv = -1
else:
inv = 1

# if attr name is side specified, record inverted attr name
if isSideElement(attrName):
invAttrName = swapSideLabel(attrName)
else:
invAttrName = attrName

results.append(
{
"target": targetNode,
"attr": invAttrName,
"val": srcNode.attr(attrName).get() * inv,
}
)
return results


def mirrorPoseOld(flip=False, nodes=False):
"""Deprecated: Mirror pose
Expand Down
8 changes: 7 additions & 1 deletion release/scripts/mgear/rigbits/rbf_manager2/rbf_manager_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
from mgear.core import pyqt
import mgear.core.string as mString
from mgear.core import anim_utils
from mgear.core import attribute
from mgear.vendor.Qt import QtWidgets, QtCore, QtCompat, QtGui
from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
from mgear.rigbits.six import PY2
Expand Down Expand Up @@ -208,6 +209,7 @@ def show(dockable=True, newSceneCallBack=True, *args):
# Create the UI
RBF_UI = RBFManagerUI(newSceneCallBack=newSceneCallBack)
RBF_UI.initializePoseControlWidgets()
RBF_UI.reevalluateAllNodes()

# Check if we've saved a size previously and set it
if mc.optionVar(exists='RBF_UI_width') and mc.optionVar(exists='RBF_UI_height'):
Expand Down Expand Up @@ -1543,9 +1545,11 @@ def mirrorSetup(self):
driverControl = aRbfNode.getDriverControlAttr()
driverControl = pm.PyNode(driverControl)
# Sanity check: make sure mirror attributes are set up properly
driven_ctl = []
for targetInfo in setupTargetInfo_dict.items():
driven = targetInfo[0]
ctrl = driven.name().replace("_driven", "_ctl")
driven_ctl.append(targetInfo[1][0])
for attr in ["invTx", "invTy", "invTz", "invRx", "invRy", "invRz"]:
pm.setAttr(driven + "." + attr, pm.getAttr(ctrl + "." + attr))
for index in range(poseIndices):
Expand All @@ -1554,7 +1558,7 @@ def mirrorSetup(self):
anim_utils.mirrorPose(flip=False, nodes=[driverControl])
mrData = []
for srcNode, dstValues in setupTargetInfo_dict.items():
mrData.extend(anim_utils.calculateMirrorDataRBF(srcNode,
mrData.extend(anim_utils.calculateMirrorData(srcNode,
dstValues[0]))
for entry in mrData:
anim_utils.applyMirror(nameSpace, entry)
Expand All @@ -1571,6 +1575,8 @@ def mirrorSetup(self):
for mrRbfNode in mrRbfNodes:
rbf_node.resetDrivenNodes(str(mrRbfNode))
pm.select(cl=True)
self.reevalluateAllNodes()
attribute.reset_SRT(driven_ctl)

def hideMenuBar(self, x, y):
"""rules to hide/show the menubar when hide is enabled
Expand Down
8 changes: 7 additions & 1 deletion release/scripts/mgear/rigbits/rbf_manager_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
from mgear.core import pyqt
import mgear.core.string as mString
from mgear.core import anim_utils
from mgear.core import attribute
from mgear.vendor.Qt import QtWidgets, QtCore, QtCompat
from maya.app.general.mayaMixin import MayaQWidgetDockableMixin

Expand Down Expand Up @@ -293,6 +294,7 @@ def show(dockable=True, newSceneCallBack=True, *args):
pass
RBF_UI = RBFManagerUI(parent=pyqt.maya_main_window(),
newSceneCallBack=newSceneCallBack)
RBF_UI.reevalluateAllNodes()
RBF_UI.show(dockable=True)
return RBF_UI

Expand Down Expand Up @@ -1624,9 +1626,11 @@ def mirrorSetup(self):
driverControl = aRbfNode.getDriverControlAttr()
driverControl = pm.PyNode(driverControl)
# Sanity check: make sure mirror attributes are set up properly
driven_ctl = []
for targetInfo in setupTargetInfo_dict.items():
driven = targetInfo[0]
ctrl = driven.name().replace("_driven", "_ctl")
driven_ctl.append(targetInfo[1][0])
for attr in ["invTx", "invTy", "invTz", "invRx", "invRy", "invRz"]:
pm.setAttr(driven + "." + attr, pm.getAttr(ctrl + "." + attr))
for index in range(poseIndices):
Expand All @@ -1635,7 +1639,7 @@ def mirrorSetup(self):
anim_utils.mirrorPose(flip=False, nodes=[driverControl])
mrData = []
for srcNode, dstValues in setupTargetInfo_dict.items():
mrData.extend(anim_utils.calculateMirrorDataRBF(srcNode,
mrData.extend(anim_utils.calculateMirrorData(srcNode,
dstValues[0]))
for entry in mrData:
anim_utils.applyMirror(nameSpace, entry)
Expand All @@ -1652,6 +1656,8 @@ def mirrorSetup(self):
for mrRbfNode in mrRbfNodes:
rbf_node.resetDrivenNodes(str(mrRbfNode))
pm.select(cl=True)
self.reevalluateAllNodes()
attribute.reset_SRT(driven_ctl)

def hideMenuBar(self, x, y):
"""rules to hide/show the menubar when hide is enabled
Expand Down

0 comments on commit 0347758

Please sign in to comment.