Assimp没有正确加载指数

问题描述 投票:0回答:1

我正在尝试加载简单的3d模型cube.3ds,但是下一个错误发生:当我读取向量的索引时,向量包含:[0,1,2,3,...]。这不合适。我找到了几乎相同的主题:Assimp and D3D model loading: Mesh not being displayed in D3D,但我找不到答案。任何人都可以正确地描述从网格中加载索引的算法。非常感谢!

parsing directx indices 3ds assimp
1个回答
3
投票

以下是访问网格索引时从assimp示例代码中提取的示例。

for (; n < nd->mNumMeshes; ++n) 
{
    const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];

    apply_material(sc->mMaterials[mesh->mMaterialIndex]);

    if(mesh->mNormals == NULL) {
        glDisable(GL_LIGHTING);
    } else {
        glEnable(GL_LIGHTING);
    }

    for (t = 0; t < mesh->mNumFaces; ++t) {
        const struct aiFace* face = &mesh->mFaces[t];
        GLenum face_mode;

        switch(face->mNumIndices) {
            case 1: face_mode = GL_POINTS; break;
            case 2: face_mode = GL_LINES; break;
            case 3: face_mode = GL_TRIANGLES; break;
            default: face_mode = GL_POLYGON; break;
        }

        glBegin(face_mode);

        for(i = 0; i < face->mNumIndices; i++) {
            int index = face->mIndices[i];
            if(mesh->mColors[0] != NULL)
                glColor4fv((GLfloat*)&mesh->mColors[0][index]);
            if(mesh->mNormals != NULL) 
                glNormal3fv(&mesh->mNormals[index].x);
            glVertex3fv(&mesh->mVertices[index].x);
        }

        glEnd();
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.