【问题标题】:FBX SDK Returns 4 Vertices When Expecting 3FBX SDK 在预期 3 时返回 4 个顶点
【发布时间】:2020-03-20 00:28:48
【问题描述】:

我正在尝试使用 AutoDesk FBX SDK 导入一些模型,如下所示。

void SearchNodes(fbxsdk::FbxNode* Node, std::vector<fbxsdk::FbxNode*>& Nodes) {
    for (int i = 0; i < Node->GetChildCount(); i++) {
        fbxsdk::FbxNode* Child = Node->GetChild(i);
        fbxsdk::FbxNodeAttribute* Attribute = Child->GetNodeAttribute();
        if (Attribute == NULL) {
            SearchNodes(Child, Nodes);
        }
        else {
            FbxNodeAttribute::EType AttributeType = Attribute->GetAttributeType();
            if (AttributeType != FbxNodeAttribute::eMesh) {
                SearchNodes(Child, Nodes);
            }
            else {
                Nodes.push_back(Child);
                SearchNodes(Child, Nodes);
            }
        }
    }
}

void Import(const char* File) {
    FbxImporter* Importer = FbxImporter::Create(_FbxManager, "");
    if (!Importer->Initialize(File, -1, _FbxManager->GetIOSettings())) {
        printf("FBX Import Initialize Failed: %s", Importer->GetStatus().GetErrorString());
        return;
    }

    FbxScene* Scene = FbxScene::Create(_FbxManager, "NewScene");
    Importer->Import(Scene);
    Importer->Destroy();

    FbxNode* RootNode = Scene->GetRootNode();
    if (RootNode) {
        std::vector<fbxsdk::FbxNode*> Nodes;
        SearchNodes(RootNode, Nodes);
        printf("Nodes Size: %i (%i)\n", RootNode->GetChildCount(true), Nodes.size());

        std::vector<Vertex> OutVertices = {};

        for (auto Node : Nodes) {
            FbxMesh* Mesh = (FbxMesh*)Node->GetNodeAttribute();

            FbxVector4* Vertices = Mesh->GetControlPoints();
            for (int j = 0; j < Mesh->GetPolygonCount(); j++) {
                int NumVerts = Mesh->GetPolygonSize(j);
                printf("NumVerts: %i\n", NumVerts);
                //if (NumVerts != 3 ) { continue; }
                for (int k = 0; k < NumVerts; k++) {
                    int VertID = Mesh->GetPolygonVertex(j, k);
                    Vertex NewVertex{};
                    NewVertex.pos.x = (float)Vertices[VertID].mData[0];
                    NewVertex.pos.y = (float)Vertices[VertID].mData[1];
                    NewVertex.pos.z = (float)Vertices[VertID].mData[2];
                    OutVertices.push_back(NewVertex);
                }
            }
        }
        printf("Out Vertex Count: %i\n", OutVertices.size());
    }
}

我抛出的每个 .fbx 文件都返回 4 个顶点而不是 3 个。

我试图弄清楚为什么我会得到 4 个顶点,以及我需要做什么来处理额外的顶点。是否提供了这条额外的信息,以便我可以处理索引?还是关于多边形的其他一些信息?

printf("NumVerts: %i\n", NumVerts); 显示为每个多边形找到了多少个顶点,90% 显示 4,偶尔我会在其中看到几个 3。

我的下一步是加载模型的索引以及顶点,所以如果这些多边形的额外顶点与索引有关,那就更好了。我只需要知道它为什么会发生以及如何处理它。

这些是经过测试的模型以供参考: Model1Model2Model3Model4

【问题讨论】:

    标签: c++ indices vertices fbx


    【解决方案1】:

    我没有看到你在任何地方对网格进行三角测量。您可以像这样对其进行三角测量:

    FbxGeometryConverter clsConverter( sdkManager );
    clsConverter.Triangulate( Scene, true );
    

    它应该可以解决您的问题。在Importer-&gt;Import(Scene);Importer-&gt;Destroy();之间添加

    【讨论】:

    • 完成了这项工作。我可以缓存FbxGeometryConverter 还是每次需要对不同的网格进行三角剖分时都需要创建/销毁一个?
    • @KKlouzal 我不确定,但我想它可以被缓存。
    猜你喜欢
    • 2016-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-04
    • 1970-01-01
    • 1970-01-01
    • 2019-08-08
    相关资源
    最近更新 更多