首页 > 代码库 > 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 = ‘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 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。