Visual artifacts when loading OBJ model with Assimp

我只是一个虾纸丫 提交于 2019-12-10 21:06:07

问题


I am trying to integrate the Assimp loader to my framework. Everything is rendered fine, but in this spider model I'm rendering, its fangs are not being drawn as expected (see following picture).

Below is the relevant code snippet:

//Storing the Indices
for (unsigned int t = 0; t < mesh->mNumFaces; ++t) {
    aiFace* face = &mesh->mFaces[t];
    memcpy(&faceArray[index], face->mIndices, 3*sizeof(unsigned int));
    index += 3;
}

//Storing the Vertices
for (unsigned int t = 0; t < mesh->mNumVertices; ++t) {
    aiVector3D vertex ;
    if (mesh->HasPositions()) {
        vertex = mesh->mVertices[t];
        memcpy(&vertexArray[index], &vertex,3*sizeof(float));
    }
    index += 3;          
}

//Render module
void model::helperDraw(GLuint vertexBufferID, GLuint indexBufferID, GLuint textureID)
{
    GLint indexSize;
    glBindBuffer(GL_ARRAY_BUFFER,vertexBufferID);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,indexBufferID);
    glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &indexSize);
    glBindTexture( GL_TEXTURE_2D, textureID);
    glDrawElements(GL_TRIANGLES, indexSize/sizeof(GLuint), GL_UNSIGNED_INT, 0);
}

What could be wrong with my code?


回答1:


There is nothing obviously wrong with your code. One possible cause for these rendering artefacts is that the OBJ model you load has some faces that are triangles an some faces that are not. You are rendering everything as GL_TRIANGLES, but the OBJ format can specify faces as quads, triangle-strips, triangles and even other more exotic things like patches.

Assimp has a mesh triangulation facility that can make your life a lot easier when dealing with these multi-format mesh files, such as the OBJ. Try passing the flag aiProcess_Triangulate to the load method of the importer or even to the post-processing method if you do post-processing as a separate step. This is likely to fix the issue.



来源:https://stackoverflow.com/questions/24599637/visual-artifacts-when-loading-obj-model-with-assimp

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