C++ c++;OpenGL FBX模型未正确加载

C++ c++;OpenGL FBX模型未正确加载,c++,opengl,fbx,C++,Opengl,Fbx,我正在尝试使用OpenGL加载FBX模型,我让导入器工作并读取网格数据,以便绘制它 这是我用的 FbxMesh*mesh = pNode->GetMesh(); //================= Get Vertices ==================================== int numVerts = mesh->GetControlPointsCount(); for(int j = 0; j < numVerts; j+

我正在尝试使用OpenGL加载FBX模型,我让导入器工作并读取网格数据,以便绘制它

这是我用的

FbxMesh*mesh = pNode->GetMesh();
    //================= Get Vertices ====================================
    int numVerts = mesh->GetControlPointsCount();
    for(int j = 0; j < numVerts; j++)
    {
        FbxVector4 vert = mesh->GetControlPointAt(j);
        vertices[numVertices].x=(float)vert.mData[0];
        vertices[numVertices].y=(float)vert.mData[1];
        vertices[numVertices++].z=(float)vert.mData[2];
        printf("MeshVert: x: %f y: %f z: %f\n", vertices[numVertices-1].x, vertices[numVertices-1].y, vertices[numVertices-1].z);
    }
    //================= Get Indices ====================================
    numIndices = mesh->GetPolygonVertexCount();
    int triangleCount = numIndices / 3;
    indices = new int[numIndices];
    indices = mesh->GetPolygonVertices();
    printf("numIndices: %i\n", numIndices);
    printf("TriangleCount: %i\n", triangleCount);
    //================= Get Normals ====================================
    FbxGeometryElementNormal*normalEl = mesh->GetElementNormal();
    if(normalEl)
    {
        int numNormals = mesh->GetPolygonCount()*3;
        normals = new float[numNormals*3];
        int vertexCounter = 0;
        for(int polyCounter = 0 ; polyCounter<mesh->GetPolygonCount(); polyCounter++)
        {
            for(int k = 0; k < 3; k++)
            {
                FbxVector4 normal = normalEl->GetDirectArray().GetAt(vertexCounter);
                normals[vertexCounter*3+0] = (float)normal[0];
                normals[vertexCounter*3+1] = (float)normal[1];
                normals[vertexCounter*3+2] = (float)normal[2];
                //cout<<"\n"<<normals[vertexCounter*3+0]<<" "<<normals[vertexCounter*3+1]<<" "<<normals[vertexCounter*3+2];
                vertexCounter++;
            }
        }
    }
FbxMesh*mesh=pNode->GetMesh();
//======================获取顶点====================================
int numVerts=mesh->getcontrolpointscont();
对于(int j=0;jGetControlPointAt(j);
顶点[numVertices].x=(float)vert.mData[0];
顶点[numVertices].y=(float)vert.mData[1];
顶点[numVertices++].z=(float)vert.mData[2];
printf(“网格顶点:x:%f y:%f z:%f\n”,顶点[numVertices-1].x,顶点[numVertices-1].y,顶点[numVertices-1].z);
}
//=========================获取索引====================================
numIndices=mesh->GetPolygonVertexCount();
int TriangalCount=numIndices/3;
指数=新的整数[numIndices];
索引=网格->获取多边形顶点();
printf(“numIndices:%i\n”,numIndices);
printf(“三角形计数:%i\n”,三角形计数);
//======================获取法线====================================
FbxGeometryElementNormal*normalEl=mesh->GetElementNormal();
if(normalEl)
{
int numNormals=mesh->GetPolygonCount()*3;
法线=新浮点[numNormals*3];
int vertexCounter=0;
对于(int polyCounter=0;polyCounterGetPolygonCount();polyCounter++)
{
对于(int k=0;k<3;k++)
{
FbxVector4 normal=normalEl->GetDirectArray().GetAt(vertexCounter);
法线[vertexCounter*3+0]=(浮点)法线[0];
法线[vertexCounter*3+1]=(浮点)法线[1];
法线[vertexCounter*3+2]=(浮点)法线[2];
//现在能把它修好吗

for(int i = 0; i < numIndices - 3; i+=3)
{
    glBegin(GL_TRIANGLES);
    glNormal3f(normals[i*3+0], normals[i*3+1], normals[i*3+2]);
    for(int j = i; j <= i + 2; j++)
    {
        glVertex3f(vertices[indices[j]].x, vertices[indices[j]].y, vertices[indices[j]].z);
        glColor3f(1.0f, 1.0f, 1.0f);
    }
}
glEnd();
glFlush();
glutSwapBuffers();
for(int i=0;i对于(int j=i;j您的基本体绘制将顶点数据视为三角形条带。第一个三角形使用索引0、1和2。第二个三角形使用顶点1、2和3。依此类推。我怀疑您的外循环应该将“i”增加3,或者您的内循环应该将“i”乘以3,就像您对法线所做的那样。Th100万安克斯,我按照你的指示做了,在外环上增加了3个“I”,得到了我想要的。
for(int i = 0; i < numIndices - 3; i+=3)
{
    glBegin(GL_TRIANGLES);
    glNormal3f(normals[i*3+0], normals[i*3+1], normals[i*3+2]);
    for(int j = i; j <= i + 2; j++)
    {
        glVertex3f(vertices[indices[j]].x, vertices[indices[j]].y, vertices[indices[j]].z);
        glColor3f(1.0f, 1.0f, 1.0f);
    }
}
glEnd();
glFlush();
glutSwapBuffers();