标签:style blog color io os ar for sp div
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 modules import maya.OpenMaya as om import maya.OpenMayaAnim as oma
Next, we’ll get the MObject & MDagPath for our mesh’s shapenode
# The shape node for some mesh mesh = ‘pSphereShape1‘ mSel = 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 count influences= om.MDagPathArray() infCount = skinFn.influenceObjects(influences) # Get node names for influences influenceNames = [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 = {} # Ordered by vertIter 0-numVerts vertIter = 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
标签:style blog color io os ar for sp div
原文地址:http://www.cnblogs.com/jonn/p/4023386.html