【问题标题】:Assimp not properly loading indicesAssimp 没有正确加载索引
【发布时间】:2013-07-21 02:11:57
【问题描述】:

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

【问题讨论】:

    标签: parsing directx indices 3ds assimp


    【解决方案1】:

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

    【讨论】:

    • 感谢您提供此代码。但我的错误在其他地方。当我通过 assimp 读取场景时,我只传递了 aiProcess_Triangulate 标志,但是为了正确加载索引还需要传递 aiProcess_JoinIdenticalVertices。
    猜你喜欢
    • 2015-10-19
    • 2017-11-13
    • 2019-06-26
    • 2015-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    相关资源
    最近更新 更多