Skip to content

Instantly share code, notes, and snippets.

@chris-lesage
Last active March 1, 2023 21:31
Show Gist options
  • Save chris-lesage/8c77edabf4f8ab81ea21f0c20703884e to your computer and use it in GitHub Desktop.
Save chris-lesage/8c77edabf4f8ab81ea21f0c20703884e to your computer and use it in GitHub Desktop.
A Maya script snippet to reset geometry to rest pose after joints have moved
import pymel.core as pm
### SNIPPET Reset Skin Cluster ###
# This script can be used to reset geometry to its neutral rest pose
# after joints have been moved. Use it when making adjustments to your rig/skeleton.
# USAGE: 1. Select the geo 2. Run this script.
# Limitation:
# Sometimes depending on your history, Maya may give an error and fail to reset the geo.
# Sometimes running it twice solves this... ¯\_( ツ )_/¯
# For more advanced cases, like resetting a single joint, see Cole O'Brien's script here:
# https://gist.github.com/obriencole11/cfb1545a61bbbaff23498f5f9042d0e3
oldSel = pm.selected()
for eachGeo in pm.selected():
skinInputs = eachGeo.listHistory(interestLevel=1, type='skinCluster')
# filters out a bug where if a geo has an FFD lattice which is skinned,
# it finds the lattice skinCluster instead of your geometry.
correctSkins = [
skin for skin in skinInputs
if eachGeo.name() in [sk.getTransform().name() for sk in skin.getGeometry()]
]
for oSkin in correctSkins:
skinJointList = pm.listConnections(oSkin.matrix, t='joint')
bindPose = pm.listConnections(skinJointList[0].name(), d=True, s=False, t='dagPose')
if bindPose:
if not (pm.referenceQuery(bindPose[0], inr=True)):
pm.delete(bindPose[0])
sourceGeo = pm.skinCluster(oSkin, q=True, g=True)[0]
pm.skinCluster(oSkin, e=True, ubk=True)
pm.skinCluster(skinJointList, sourceGeo, ibp=True, tsb=True)
pm.select(oldSel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment