【问题标题】:Finding Blendshape from Target Maya Python API从 Target Maya Python API 中查找 Blendshape
【发布时间】:2014-05-07 02:21:41
【问题描述】:

我正在尝试从 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

很遗憾,我没有获得 blendshape 变形器。

与 maya.cmds 相同的示例:

import maya.cmds as cmds

targetMesh = "pSphere1"    

history = cmds.listHistory(targetMesh, future=True)
blndshape = cmds.ls(history, type="blendShape")

print blndshape

任何帮助将不胜感激!

【问题讨论】:

    标签: python api maya


    【解决方案1】:

    如果您正在使用可变形对象,您不想要未来标志:

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

    要获得实际形状,您需要添加

    source_shapes =  cmds.ls(*cmds.listHistory(*blendshapes) or [], type= 'mesh', ni=True)
    

    【讨论】:

      【解决方案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 的基础对象。

      【讨论】:

        猜你喜欢
        • 2019-05-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-08
        • 2013-10-06
        相关资源
        最近更新 更多