I'm attempting to use the AutoDesk FBX SDK to import some models as follows.
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());
}
}
Every .fbx file I throw at this returns 4 vertices instead of 3.
I'm trying to figure out why I'm getting 4 vertices and what I need to do to handle the extra vert. Is this extra piece of information provided so I can handle indices? Or is it some other piece of information about the polygon?
The printf("NumVerts: %i\n", NumVerts);
displays how many vertices are found for each polygon, 90% display 4 and occasionally I will see a few 3's in there.
My next step is to load indices for the model along with the vertices so if the extra vert for these polygons have something to do with indices then all the better. I just need to know why its happening and how to handle it.
These are the models that have been tested for reference: Model1 Model2 Model3 Model4
I don't see you triangulating the mesh anywhere. You can triangulate it like this:
FbxGeometryConverter clsConverter( sdkManager );
clsConverter.Triangulate( Scene, true );
It should fix your issue. Add it between Importer->Import(Scene);
and Importer->Destroy();