0

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

4

1 回答 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();
    }
}
于 2013-07-23T20:22:32.120 回答