首页 > 代码库 > Get skincluster data with maya’s python API

Get skincluster data with maya’s python API

The code below demonstrates, via maya’s python api, how to retrieve:
– mObject from a mesh, and its skincluster
– MFnSkinCluster for the skincluster on that mesh
– the influences in that skin cluster and their names
– the influence weights for every vert in that mesh
Enjoy!

 

# Imports first! # Don‘t mind the short names, I have a habit of using mc, om, oma for maya‘s modulesimport maya.OpenMaya as omimport maya.OpenMayaAnim as oma

Next, we’ll get the MObject & MDagPath for our mesh’s shapenode

# The shape node for some meshmesh = pSphereShape1mSel = om.MSelectionList()mSel.add(mesh)meshMObject = om.MObject()meshDagPath  = om.MDagPath()mSel.getDependNode(0, meshMObject)mSel.getDagPath(0, meshDagPath)

Next, an MDagPathArray of the influences and the influence count.
Also, the node names for those influences, for convenience.

 

# Influences & Influence countinfluences= om.MDagPathArray()infCount = skinFn.influenceObjects(influences)# Get node names for influencesinfluenceNames = [influences[i].partialPathName() for i in range(infCount)]

Finally, get all of the weight data, organized as a dictionary of dictionaries.
The first level will use vert indices for keys, the next will be a dict of influence name : weight.

 

weightData = http://www.mamicode.com/{} # Ordered by vertIter 0-numVertsvertIter = om.MItGeometry(meshMObject)while not vertIter.isDone():    vertInfCount = om.MScriptUtil()    vertInfCountPtr = vertInfCount.asUintPtr()    om.MScriptUtil.setUint(vertInfCountPtr, 0)    weights = om.MDoubleArray()    skinFn.getWeights(meshDagPath,                       vertIter.currentItem(),                       weights,                       vertInfCountPtr)    # Create a dictionary for each vert index in the mesh    # All influences will be returned for each vert, but may have 0 influence    weightData[vertIter.index()] = dict(zip(influenceNames, weights))    vertIter.next()

Get skincluster data with maya’s python API