25 August 2019

fbxpysdk有个坑,就是必须要python3.3,官网最新的3.7是报错,找不到dll的。还需要复制lib里的文件放到python lib site package文件夹。还以为需要c++版本的dll,或者3dmax,然后发现并不是,只是版本不对。

安装步骤只需要安装py3.3,下载fbxsdk py版本即可。

等下试着导出一个动画

又遇到一个坑,我是官网下载的sdk。不知道为什么下载下来的是2019.0版本。然后导出贴图一直失效。找了半天bug,去官网逛了一下,发现是2019.5了。然后下载下来,试了试,好用的。 https://www.autodesk.com/developer-network/platform-technologies/fbx-sdk-2019-5

然后发现自己官方的fbxviewer显示贴图有问题!然后奇怪的发现win10自带的模型查看器可以显示贴图。然后研究了下fbx格式,发现fbx的贴图既可以存在于材质里,又可以存在语layerdtexture里,又可以存在于模型里,然后一般的查看器和u3d只支持存在于材质里的,而另2种方案是不支持的。所以现在就是想办法导出材质里的贴图。 然后发现第三个例子,c++版本导出的贴图正确,py的错误,估计py的写法有问题吧,等下研究下。

总结下来,这东西还是有点混乱的,例子做的也复杂,而且有bug,只有多方面各个版本测试,然后切换不同的语言才能正确找到答案。

找了半天破案了。

CreateTexture(pSdkManager, lMesh)
    
    lNode = FbxNode.Create(pSdkManager,pName)
    lNode.SetNodeAttribute(lMesh)
    lNode.SetShadingMode(FbxNode.eTextureShading)
FbxNode* lNode = FbxNode::Create(pScene,pName);

    lNode->SetNodeAttribute(lMesh);
    lNode->SetShadingMode(FbxNode::eTextureShading);

    CreateTexture(pScene, lMesh);

py的是先createtexture再创建节点 c++的是先创建节点,再createtexture 然后createtexture里用到了节点 。。感觉这个py版本就没人用过,多明显的bug

lLayer=pMesh.GetLayer(0)
            # Create a layer element material to handle proper mapping.
            lLayerElementMaterial=FbxLayerElementMaterial.Create(pMesh,lMaterial)

            # This allows us to control where the materials are mapped.  Using eAllSame
            # means that all faces/polygons of the mesh will be assigned the same material.
            lLayerElementMaterial.SetMappingMode(FbxLayerElement.eAllSame)
            lLayerElementMaterial.SetReferenceMode(FbxLayerElement.eIndexToDirect)
            
            # Save the material on the layer
            lLayer.SetMaterials(lLayerElementMaterial)

            # Add an index to the lLayerElementMaterial.  Since we have only one, and are using eAllSame mapping mode,
            # we only need to add one.
            lLayerElementMaterial.GetIndexArray().Add(0)

然后发现u3d和windows自带的显示不了贴图,但c++的可以。找到py少了这几行,虽然不知道干啥的,加上就好了。终于贴图可以正常显示了。下一步研究动画导出

研究了下矩阵,想把一个16个浮点数传给矩阵,py api有点难 有2个矩阵类FbxMatrix FbxAMatrix,一个提供了设置矩阵数字的方法,然后提供了Get旋转,位移,缩放。 另一个没有直接设置数字的方法,但可以根据旋转位移,缩放生成,所以有点绕,最终还是可以实现的效果的

最终终于搞出了一个smd转fbx的库

https://github.com/matrix3d/json2fbx