Assimp not properly loading indices

♀尐吖头ヾ 提交于 2019-12-11 22:16:50

问题


I'm trying to load simple 3d model cube.3ds, but next error occurs: when I read indices to my vector, vector contains: [0, 1, 2, 3, ...]. It's not properly. I found almost the same topic: Assimp and D3D model loading: Mesh not being displayed in D3D, but I don't found the answer. Can anyone describe in detail properly algorithm for loading indices from meshes. Thank's a lot!


回答1:


Here is a example pulled from the assimp sample code on accessing the mesh indices.

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();
    }
}


来源:https://stackoverflow.com/questions/17785943/assimp-not-properly-loading-indices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!