从目标Maya Python API查找Blendshape

2024-10-05 10:04:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从python maya api中的目标网格中找到blendshape变形器。我很确定我必须遍历依赖关系图来获得blendshape。在

这就是我要做的:

import maya.OpenMaya as OpenMaya
import maya.OpenMayaAnim as OpenMayaAnim

#Name of our targetmesh.
targetMesh = "pSphere1"

#Add selection.
mSel = OpenMaya.MSelectionList()
mSel.add(targetMesh, True)

#Get MObj
mObj = OpenMaya.MObject()
mSel.getDependNode(0, mObj)

#Make iterator.
itDG = OpenMaya.MItDependencyGraph(mObj,
                                   OpenMaya.MFn.kBlendShape, 
                                   OpenMaya.MItDependencyGraph.kUpstream)

while not itDG.isDone():
    oCurrentItem = itDG.currentItem()
    blndSkin = OpenMayaAnim.MFnBlendShapeDeformer(oCurrentItem)
    print blndSkin
    break

不幸的是我没有混合变形器。在

同样的例子玛雅.cmds公司名称:

^{pr2}$

任何帮助将不胜感激!在


Tags: importapias变形mayaopenmayamobjblendshape
2条回答

所以我找到的解决方案是:

def getBlendShape(shape):
    '''
    @param Shape: Name of the shape node.
    Returns MFnBlendShapeDeformer node or None.
    '''
    # Create an MDagPath for our shape node:
    selList = OpenMaya.MSelectionList()
    selList.add(shape)
    mDagPath = OpenMaya.MDagPath()
    selList.getDagPath(0, mDagPath)

    #Create iterator.
    mItDependencyGraph = OpenMaya.MItDependencyGraph(
        mDagPath.node(),
        OpenMaya.MItDependencyGraph.kPlugLevel)

    # Start walking through our shape node's dependency graph.
    while not mItDependencyGraph.isDone():
        # Get an MObject for the current item in the graph.
        mObject = mItDependencyGraph.currentItem()
        # It has a BlendShape.
        if mObject.hasFn(OpenMaya.MFn.kBlendShape):
            # return the MFnSkinCluster object for our MObject:
            return OpenMayaAnim.MFnBlendShapeDeformer(mObject)
        mItDependencyGraph.next()

if __name__ == '__main__':
    #TargetMesh
    targetMesh = "pSphereShape1"

    #Get Blendshape.
    blndShpNode = getBlendShape(targetMesh)

    if blndShpNode:
        #Get base objects.
        mObjArr = OpenMaya.MObjectArray()
        blndShpNode.getBaseObjects(mObjArr)
        mDagPath = OpenMaya.MDagPath()
        OpenMaya.MFnDagNode(mObjArr[0]).getPath(mDagPath)
        print(mDagPath.fullPathName())

    else:
        print("No Blendshape found.")

诀窍是我需要传递形状节点并且只使用OpenMaya.MItDependencyGraph.kPlugLevel). 在本例中,它查找blendshape的基对象。在

如果从可变形对象工作,则不需要“未来”标志:

targetMesh = "pSphere1"    
blendshapes = cmds.ls(*cmds.listHistory(targetMesh) or [], type= 'blendShape')

为了得到实际的形状,你需要添加

^{pr2}$

相关问题 更多 >

    热门问题