简体   繁体   中英

Assimp incorrectly imports OBJ indices?

I have created my own Model class to abstract the process of importing a model in Assimp, and make it easy to add a model. Currently, I haven't got this to work, and no model is shown. I believe this is due to the indices.

I noticed during debugging that the indices vector related to a mesh in the model always has the same number of elements as the vertices vector (although it should be more). eg:

vertices.size() == indices.size() //<--- true

Additionally, for some reason, all indices vectors simply contain consecutive integers. eg:

std::vector<GLuint> indices; //<--- After processing contains: {0, 1, 2, 3, ...}

Here is the code I use to extract the indices from Assimp:

//Process Indices
for (GLuint i = 0; i < mesh->mNumFaces; i++) {
    aiFace face = mesh->mFaces[i];
    for (GLuint j = 0; j < face.mNumIndices; j++) {
        GLuint index = face.mIndices[j];
        indices.push_back(index);
    }           
}

Also, here are my import flags (although I don't really know how these would affect indices):

const aiScene *scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals);

Turns out I had to add the flag:

aiProcess_JoinIdenticalVertices

This identifies and joins identical vertex data sets within all imported meshes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM