用于 openGL 显示的 FBX 解析

FBX parse for openGL Display

我想解析 FBX file 并通过 openGL 在 iPhone 上显示它。 目前尝试使用 FBX SDK from Autodesk.

解析 *.fbx 格式

也发现这个 link 有用,但仍然有一些误解 - 我猜我收到的索引不正确。我在搅拌机中创建简单的立方体并将该文件导出到 *.fbx。如果我通过 FBX Review 应用程序打开这个文件 - 一切都显示完美,但是当我尝试绘制这个立方体时 - 看起来我解析的一些数据是 incorrect/or 部分。

要获取索引,我使用下一个代码

int numIndices = pMesh->GetPolygonVertexCount();
int *indices = new int [numIndices];
indices = pMesh->GetPolygonVertices();

int polygonCount = pMesh->GetPolygonCount();
int totalObjSize = 0;
for (int i = 0; i < polygonCount; ++i) {
    totalObjSize += pMesh->GetPolygonSize(i);
}

结果:

----Indices----24---: 0 1 2 3 4 7 6 5 0 4 5 1 1 5 6 2 2 6 7 3 4 0 3 7

----Coordinates(Vertises)----72
1 1 -1 
1 -1 -1 
-1 -1 -1 
-1 1 -1  
1 0.999999 1 
-1 1 1 
-1 -1 1 
0.999999 -1 1 
1 1 -1  
1 0.999999 1 
0.999999 -1 1 
1 -1 -1 
1 -1 -1 
0.999999 -1 1 
-1 -1 1 
-1 -1 -1 
-1 -1 -1 
-1 -1 1 
-1 1 1 
-1 1 -1  
 1 0.999999 1 
 1 1 -1 
-1 1 -1 
-1 1 1 

----Texture UV----48
0.499999 9.7692e-05
0.499999 0.333364
0.250049 0.333364
0.250049 9.78112e-05
0.250049 0.666633
0.499999 0.666633
0.499999 0.9999
0.250049 0.9999
0.74995 0.333366
0.74995 0.666633
0.5 0.666633
0.5 0.333367
0.499998 0.333366
0.499998 0.666632
0.250048 0.666633
0.250048 0.333366
0.25005 0.333367
0.25005 0.666633
0.000100091 0.666633
0.000100024 0.333367
0.749953 0.666639
0.749953 0.333373
0.999903 0.333373
0.999903 0.666639

----Normal----72
0 0 -1 
0 0 -1 
0 0 -1 
0 0 -1 
0 0 1 
0 0 1 
0 0 1 
0 0 1 
1 0 0 
1 0 0 
1 0 0 
1 0 0 
0 -1 0 
0 -1 0 
0 -1 0 
0 -1 0 
-1 0 0 
-1 0 0 
-1 0 0 
-1 0 0 
0 1 0 
0 1 0 
0 1 0 
0 1 0 

我还能够解析顶点(坐标)和纹理 UV 和法线 - 所有看起来都是正确的(我将我获得的值与可以通过示例应用程序 ImportScene 获得的值进行比较,可通过 link.

所以当我尝试使用 openGL 中的所有数据时,我得到了一些意想不到的对象。

问题是 - 我是否正确解析了 FBX 文件中的索引?

另外 关于在 openGL 中绘制对象。

---更新---

我还发现这个索引不正确(未排序且不完整),所以问题是如何从 FBX 文件生成正确的索引顺序?

如果有人遇到同样的问题,我 post 有自己的解决方案(也许有另一种方法可以做到这一点,这比真正的解决方案更可能是解决方法,所以如果有人找到另一种方法 - 那就太好了)

    int indicessCount = index;
    int *testIndices = new int [indicessCount]; 
        index = 0;
    pairCounter = 0;
    int indexElement = 0;
    for (int i = 0; i < polygonCount; i++) {
        int lPolygonSize = pMesh->GetPolygonSize(i);
        for (int j = 0; j< lPolygonSize; j++) {
            _displayModel.indises[index++] = indexElement + j;
            if (j==2) {
                if ((pairCounter % 1)) {
                    int firstIndex = index-3;
                    int secondIndex = index-1;
                    _displayModel.indises[index++] = _displayModel.indises[secondIndex];
                    _displayModel.indises[index++] = _displayModel.indises[firstIndex];
                    pairCounter = 0;
                }
                pairCounter++;
            }
        }
    indexElement += lPolygonSize;
}

同时对您的场景进行三角测量

FbxGeometryConverter converter(_fbxManager);
converter.Triangulate(_fbxScene, true);