Skip to content

Instantly share code, notes, and snippets.

@viktorasm
Last active October 11, 2020 00:11
Show Gist options
  • Save viktorasm/ea273524337b01afa86941c835028472 to your computer and use it in GitHub Desktop.
Save viktorasm/ea273524337b01afa86941c835028472 to your computer and use it in GitHub Desktop.
# this is an example script how ngSkinTools can be automated
# to configure left-right influence mapping
# this example assumes that the scene has a skinned pPlane1
# which has ngSkinTools info already initialized. if not,
# see http://www.ngskintools.com/documentation/api/mll-interface.html
# for tips to how to do that programatically
# for this we use "manual mapping overrides" feature:
# the same where you can correct automatic associations by hand,
# only this time we choose to 'bake' the whole mapping using the
# internal knowledge of your rig script about what left joints
# correspond to your right joints and vice versa
from ngSkinTools.mllInterface import MllInterface
mll = MllInterface('pPlane1')
# to specify mirror pairs,
# we need to build a map of influence indexes, where
# key is a source index, and value is destination;
# for symmetrical relationship, we need two entries,
# {<left index>:<right index>, <right index>: <left index>}
# influence index it's logical plug number in skinCluster
# you can specify indexes straight away like this:
influenceMirrorMapping = {0:1, 1:0, 2:3, 3:2}
# .. or build a helper structure/methods to specify pairs by name.
# this part really depends on what tools you have at your disposal,
# I'll just use ngSkinTools helper methods that list full paths and indexes of influences in a skin cluster
influenceIndexMap = {name:value for name,value in zip(mll.listInfluencePaths(),mll.listInfluenceIndexes())}
import pymel.core as pm
def influenceIndex(partialName):
'''
really dumb way to conver short name into long one. hopefully you don't use short names in your automation scripts anymore
'''
return influenceIndexMap[pm.ls(partialName)[0].longName()]
def addOneWayMapping(source, destination):
'''
add influence mapping association by name
'''
influenceMirrorMapping[influenceIndex(source)] = influenceIndex(destination)
def addSymmetricalPair(influence1, influence2):
addOneWayMapping(influence1,influence2)
addOneWayMapping(influence2,influence1)
addSymmetricalPair('joint3','joint5')
addSymmetricalPair('joint6','joint7')
# this means that weights of joint10 will be mirrored on to joint11, but not vice versa
addOneWayMapping('joint10','joint11')
# this joint will be forced to act like a 'center' joint, where it's mirrored onto itself
addOneWayMapping('joint12','joint12')
# finally, set the values into ngSkinTools node. this overrides a previous setting,
# if we wanted to edit, instead of empty map we should call getManualMirrorInfluences() to get initial map
mll.setManualMirrorInfluences(influenceMirrorMapping)
# you can now preview the results in Mirror tab, "Edit influence associations".
# overrides will be visible with '[M]' prefix indicating that it's a manual rule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment