Skip to content

Instantly share code, notes, and snippets.

@tokejepsen
Created October 29, 2021 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tokejepsen/ad9906e54381aad53828cd3d1e1707e2 to your computer and use it in GitHub Desktop.
Save tokejepsen/ad9906e54381aad53828cd3d1e1707e2 to your computer and use it in GitHub Desktop.
Maya: Batch Transfer Ngskintools Weights
"""
Select targets then source last.
"""
import pymel.core as pc
from ngSkinTools.mllInterface import MllInterface
selection = pc.ls(selection=True)
targets = selection[:-1]
source = selection[-1]
skin_cluster = source.getShape().listConnections(type="skinCluster")[0]
joints = skin_cluster.listConnections(type="joint")
source_mll = MllInterface()
source_mll.setCurrentMesh(str(source))
id_by_path = {}
for info in source_mll.listInfluenceInfo():
id_by_path[info.path] = info.logicalIndex
for target in targets:
args = joints + [target]
pc.skinCluster(*args)
influences_mapping = {}
target_mll = MllInterface()
target_mll.setCurrentMesh(str(target))
target_mll.initLayers()
for info in target_mll.listInfluenceInfo():
source_id = id_by_path[info.path]
influences_mapping[source_id] = info.logicalIndex
source_mll.transferWeights(str(target), influences_mapping, vertexTransferMode="closestPoint")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment