编程语言
首页 > 编程语言> > python – FBX SDK – 从角色的ENodeId获取FbxNode

python – FBX SDK – 从角色的ENodeId获取FbxNode

作者:互联网

是否可以从枚举ENodeId获取关联的FbxNode?
例如,如果我想从Character :: eLeftHand获取FbxNode

我试着使用Character :: GetCharacterLink(ENodeId,FbxCharacterLink)
然后只需调用FbxCharacterLink :: mNode从FbxCharacterLink中提取FbxNode

但是,此函数返回大多数ENodeIds False,因此不会创建FbxCharacterLink.

character = myScene.GetCharacter(0)
lefthand = character.eLeftHand
lefthand_node = FbxCharacterLink()
character.GetCharacterLink(lefthand, lefthand_node) # False
lefthand_node = lefthand_node.mNode

当我使用Python和Pyfbxsdk在Motionbuilder中编写脚本时,它非常简单,无论骨架对象如何命名,我都可以获得它的FBXObject

m = character.GetModel(self.BodyNodeObject[o])

和BodyNodeObject一起生成

def BodyNodes(self):
    for i in dir(FBBodyNodeId):
        if i[0] == 'k':
            try:
                self.BodyNodeObject[BodyNodesId[i]] = getattr(FBBodyNodeId, i)
            except:
                pass

BodyNodesId只是一个字典

BodyNodesId = OrderedDict({
        'kFBChestNodeId':'Spine1',
        'kFBHeadNodeId':'Head',
        'kFBHipsNodeId':'Hips',
        'kFBLeftAnkleNodeId':'LeftFoot',
        'kFBLeftCollarNodeId':'LeftShoulder',
        'kFBLeftElbowNodeId':'LeftForeArm',
        ...
})

解决方法:

这对我有用

from fbx import *

for i in range(myscene.GetCharacterCount()):
    character = myscene.GetCharacter(i)
    node = character.eHips
    link = FbxCharacterLink()
    while (character.GetCharacterLink(node, link)):
        print node, link.mNode.GetName()
        node = character.ENodeId(int(node+1))

标签:python,c-2,fbx,autodesk,motionbuilder
来源: https://codeday.me/bug/20190711/1433917.html