我正在尝试使用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。我的下一步是将模型的索引与顶点一起加载,因此,如果这些多边形的多余顶点与索引有关,那就更好了。我只需要知道它为什么会发生以及如何处理它。
这些是经过测试以供参考的模型:
Model1 Model2 Model3 Model4
最佳答案
我看不到您在任何地方对网格进行三角剖分。您可以像这样对它进行三角测量:
FbxGeometryConverter clsConverter( sdkManager );
clsConverter.Triangulate( Scene, true );
它应该可以解决您的问题。将其添加到
Importer->Import(Scene);
和Importer->Destroy();
之间关于c++ - 当期望3时,FBX SDK返回4个顶点,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59019553/