记一次FbxSdk导出四边面的问题 · 语雀 (yuque.com)
1、使用FbxSdk,导出四边面的代码如下:
static FbxMesh* CreateMeshAndWriteVertices(FbxScene* mScene, const tFBX_MESH_VERTEX* vertices, int verticesCount)
{
FbxMesh* mesh = FbxMesh::Create(mScene, "mesh");
mesh->InitControlPoints(verticesCount);
FbxVector4* lControlPoints = mesh->GetControlPoints();
for (int i = 0; i < mesh->GetControlPointsCount(); ++i)
{
const tFBX_MESH_VERTEX& inVtx = vertices[i];
FbxVector4 cp(inVtx.pos[0], inVtx.pos[1], inVtx.pos[2]);
lControlPoints[i] = cp;
}
// 此处省略若干设置法线和colors的代码
return mesh;
}
void ExportCore::WriteQuadMesh(const char* nodePath, const tFBX_MESH_VERTEX* vertices,
int verticesCount, const tFBX_MESH_QUAD* quads, int quadsCount)
{
FbxMesh* mesh = CreateMeshAndWriteVertices(mScene, vertices, verticesCount, vertexFlag);
// Create the quad's polygon
for (int i = 0; i < quadsCount; ++i)
{
mesh->BeginPolygon();
mesh->AddPolygon(quads[i].i0); // Control point 0
mesh->AddPolygon(quads[i].i1); // Control point 1
mesh->AddPolygon(quads[i].i2); // Control point 2
mesh->AddPolygon(quads[i].i3); // Control point 3
mesh->EndPolygon();
}
FbxNode* node = _GetOrCreateNodeByPath(nodePath);
node->SetNodeAttribute(mesh);
}
2、然后意外地发现,当第一个四边面退化成三角形时,fbx在3DMax里面打开,会发现缺面
3、用FbxSdk导入fbx,并打印这些顶点和索引,发现数据是正确的。因为FbxSDK没有源码,只能猜测是它的bug,或者设计如此。
4、解决方法:
直接把第一个四边面的索引设置重复2次,可以解决