使用fbx sdk c ++从fbx读取纹理文件名

莫兹

我在尝试使用fbx sdk从fbx文件中获取信息时遇到了麻烦。我在Maya中创建了带有纹理的fbx模型。我要做的就是在代码中找到使用的纹理的完整文件名...

这是一些代码:

void Model::GetFbxInfo(FbxNode* Node)
{
int numKids = Node->GetChildCount();
FbxNode* childNode = 0;

for (int i = 0; i < numKids; i++)
{
    childNode = Node->GetChild(i);
    FbxMesh* mesh = childNode->GetMesh();

    if (mesh != NULL)
    {
        // get vertices, indices, uv, etc
        // some more code...
        // get vertices, indices, uv, etc

        //================= Texture ========================================

        int materialCount = childNode->GetSrcObjectCount<FbxSurfaceMaterial>();

        for (int index = 0; index < materialCount; index++)
        {
            FbxSurfaceMaterial* material = (FbxSurfaceMaterial*)childNode->GetSrcObject<FbxSurfaceMaterial>(index);

            if (material != NULL)
            {
                LOG(INFO) << "\nmaterial: " << material->GetName() << std::endl;
                // This only gets the material of type sDiffuse, you probably need to traverse all Standard Material Property by its name to get all possible textures.
                FbxProperty prop = material->FindProperty(FbxSurfaceMaterial::sDiffuse);

                // Check if it's layeredtextures
                int layeredTextureCount = prop.GetSrcObjectCount<FbxLayeredTexture>();

                if (layeredTextureCount > 0)
                {
                    for (int j = 0; j < layeredTextureCount; j++)
                    {
                        FbxLayeredTexture* layered_texture = FbxCast<FbxLayeredTexture>(prop.GetSrcObject<FbxLayeredTexture>(j));
                        int lcount = layered_texture->GetSrcObjectCount<FbxTexture>();

                        for (int k = 0; k < lcount; k++)
                        {
                            FbxTexture* texture = FbxCast<FbxTexture>(layered_texture->GetSrcObject<FbxTexture>(k));
                            // Then, you can get all the properties of the texture, include its name
                            const char* textureName = texture->GetName();
                            LOG(INFO) << textureName;
                        }
                    }
                }
                else 
                {
                    // Directly get textures
                    int textureCount = prop.GetSrcObjectCount<FbxTexture>();
                    for (int j = 0; j < textureCount; j++)
                    {
                        FbxTexture* texture = FbxCast<FbxTexture>(prop.GetSrcObject<FbxTexture>(j));
                        // Then, you can get all the properties of the texture, include its name
                        const char* textureName = texture->GetName();
                        LOG(INFO) << textureName;

                        FbxProperty p = texture->RootProperty.Find("Filename");
                        LOG(INFO) << p.Get<FbxString>() << std::endl;


                        HRESULT hr;
                        D3DX11CreateTextureFromFile(Game::GetInstance()->GetRenderer()->GetDevice(), textureName, 0, 0, &m_texture, &hr);
                        if(FAILED(hr))
                        {
                            std::string message;
                            message.append("Load Texture: ");
                            message.append(texture->GetName());
                            message.append(" failed");
                            SHOWMESSAGEBOX(hr, message.c_str());
                        }
                    }
                }
            }
        }

        this->GetFbxInfo(childNode);
    }
}

}

它是一个漫射的非分层纹理...因此else分支很重要... textureCount为1-因此找到了纹理,但文件名和纹理getname只返回“ file1”

这是我正在加载的ascii-fbx文件中的一条数据

Video: 900530112, "Video::file1", "Clip" {
    Type: "Clip"
    Properties70:  {
        P: "Path", "KString", "XRefUrl", "", "D:/Dropbox/Projects/MyModel/MyTexture.jpg"
    }
    UseMipMap: 0
    Filename: "D:/Dropbox/Projects/MyModel/MyTexture.jpg"
    RelativeFilename: "MyTexture.jpg"
}
Texture: 785759328, "Texture::file1", "" {
    Type: "TextureVideoClip"
    Version: 202
    TextureName: "Texture::file1"
    Properties70:  {
        P: "CurrentTextureBlendMode", "enum", "", "",0
        P: "UVSet", "KString", "", "", "map1"
        P: "UseMaterial", "bool", "", "",1
    }
    Media: "Video::file1"
    FileName: "D:/Dropbox/Projects/MyModel/MyTexture.jpg"
    RelativeFilename: "MyTexture.jpg"
    ModelUVTranslation: 0,0
    ModelUVScaling: 1,1
    Texture_Alpha_Source: "None"
    Cropping: 0,0,0,0
}

谁能帮助我了解我在做什么错?

谢谢!

尖刺

必须将fbxtexture转换为fbxfiletexture ...然后是getfilename

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用Python FBX SDK将* .obj转换为* .fbx

来自分类Dev

如何使用python fbx sdk导出二进制fbx文件

来自分类Dev

如何使用python fbx sdk导出二进制fbx文件

来自分类Dev

在Visual Studio / C ++中使用fbx SDK构建项目时编译错误

来自分类Dev

FBX SDK导出为较旧的fbx文件格式

来自分类Dev

在FBX SDK中创建点或顶点

来自分类Dev

当期望3时,FBX SDK返回4个顶点

来自分类Dev

Python FBX SDK –如何启用自动完成功能?

来自分类Dev

FBX SDK如何检索用户定义的对象属性

来自分类Dev

使用threeJS加载3D文件(fbx和obj)

来自分类Dev

我想使用opengl在ubuntu中查看FBX文件

来自分类Dev

导入 .FBX 文件

来自分类Dev

c ++ OpenGL FBX模型未正确加载

来自分类Dev

从文件名路径列表中仅提取maya文件中使用的纹理文件名

来自分类Dev

Python FBX SDK –如何缩放具有关键帧的模型?

来自分类Dev

为什么无法使用XML SDK 2.0 C#读取2013年之前的Excel文件版本

来自分类Dev

如何使用一些 Js 库在 html 页面中播放或查看 .FBX 文件

来自分类Dev

在C#中使用OpenXML SDK创建XLSX文件

来自分类Dev

使用Microsoft Graph C#SDK复制文件

来自分类Dev

使用Graph SDK获取文件夹内容-C#

来自分类Dev

传递绝对文件名以在C ++中读取文件

来自分类Dev

如何正确读取DirectX的FBX 2014索引?

来自分类Dev

使用Office 365 SDK for iOS读取文件

来自分类Dev

从C中的echo命令读取文件名

来自分类Dev

使用PowerShell读取下载文件的文件名

来自分类Dev

如何使用C ++从整个路径获取文件名

来自分类Dev

在C ++中使用sstream和fstream写入文件名

来自分类Dev

批量将bvh文件转换为fbx

来自分类Dev

从 URL 加载 .fbx 文件——这可能吗?

Related 相关文章

热门标签

归档