-
-
Save SEVEZ/1211839e06fdee1746d197594fbc010a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mirror transform | |
from maya import cmds | |
def mirror_transforms(nodes): | |
"""Mirror transforms `nodes` across the YZ axis | |
Arguments: | |
nodes (list): Transforms to be mirrored | |
""" | |
for node in nodes: | |
temp_joint = cmds.createNode('joint') | |
temp_ctl = cmds.duplicate(node, | |
inputConnections=True, | |
returnRootsOnly=True) | |
cmds.parent(temp_joint, node) | |
cmds.parent(temp_joint, world=True) | |
cmds.parent(temp_ctl, temp_joint) | |
mirrored = cmds.mirrorJoint(temp_joint, | |
mirrorBehavior=True, | |
mirrorYZ=True) | |
mirrored_joint = mirrored.pop(0) | |
mirrored_ctl = mirrored.pop(0) | |
cmds.parent(mirrored_ctl, world=True) | |
cmds.delete([temp_joint, temp_joint, mirrored_joint]) | |
yield node, mirrored_ctl | |
def mirror_shapes(nodes): | |
"""In addition to mirroring transforms, also mirror shapes | |
Arguments: | |
nodes (list): Transforms with shapes to mirror | |
""" | |
for original, mirrored in mirror_transforms(nodes): | |
mirrored_original = cmds.duplicate(original, | |
name=original + "_duplicate") | |
mirrored_group = cmds.createNode('transform', | |
name=original + "_transform") | |
cmds.parent(mirrored_original[0], mirrored_group) | |
cmds.setAttr(mirrored_group + ".sx", -1) | |
blendshape = cmds.blendShape((mirrored_original[0], mirrored), | |
origin='world') | |
cmds.setAttr(blendshape[0] + "." + mirrored_original[0], 1) | |
mirrored_with_shape = cmds.duplicate(mirrored) | |
cmds.delete([mirrored, mirrored_group]) | |
cmds.select(mirrored_with_shape, replace=True) | |
def mirror_selected_transforms(): | |
"""Interactively mirror transforms""" | |
nodes = cmds.ls(sl=1, | |
objectsOnly=True, | |
type='transform', | |
long=True) | |
for node in mirror_transforms(nodes): | |
pass | |
def mirror_selected_shapes(): | |
"""Interactively mirror shapes""" | |
nodes = cmds.ls(sl=1, | |
objectsOnly=True, | |
type='transform', | |
long=True) | |
return mirror_shapes(nodes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment