Skip to content

Instantly share code, notes, and snippets.

@tokejepsen
Last active September 17, 2019 13:10
Show Gist options
  • Save tokejepsen/4ba7aadd260e857648b83738f78474ae to your computer and use it in GitHub Desktop.
Save tokejepsen/4ba7aadd260e857648b83738f78474ae to your computer and use it in GitHub Desktop.
Mirror Meshes
"""
Select all meshes that needs to be mirrored.
Script produces a mirror locator with a plane for visualizing.
"""
import pymel.core as pm
selection = pm.ls(selection=True)
# Create mirror locator/plane.
locator = pm.spaceLocator()
mirror_plane = pm.polyPlane()[0]
pm.parent(mirror_plane, locator)
mirror_plane.rotateZ.set(-90)
pm.rename(mirror_plane, "mirror_visualizer")
for node in selection:
# Duplicate mesh.
duplicate = pm.duplicate(node)
# Blendshape to original mesh in worldspace and zero out transforms.
blendshape = pm.blendShape(node, duplicate)[0]
pm.blendShape(blendshape, edit=True, weight=[(0, 1)])
blendshape.origin.set(0)
pm.makeIdentity(duplicate)
# Parent to mirror locator.
pm.parent(duplicate, locator)
# Duplicate blendshape as instance. Set x scale to -1.
instance = pm.instance(duplicate)[0]
instance.scaleX.set(-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment