I'm using Assimp to load in OBJ files to render in OpenGL using my own rendering pipeline.
But when I load in a file, every face has indices (0,1,2), rather than appropriate entries into the vertex array.
Every example I could find does something similar to this (which is what I'm doing):
for (size_t k = 0; k<mesh->mNumFaces; ++k)
{
if (mesh->mFaces->mNumIndices == 3)
{
out.index_list.push_back(mesh->mFaces->mIndices[0]);
out.index_list.push_back(mesh->mFaces->mIndices[1]);
out.index_list.push_back(mesh->mFaces->mIndices[2]);
}
else
{
std::cout << "wierd number of indices to a face: " << mesh->mFaces->mNumIndices << std::endl;
}
}
or this (which I've tried, and is very wrong):
for (size_t k = 0; k<mesh->mNumFaces; ++k)
{
if (mesh->mFaces->mNumIndices == 3)
{
out.index_list.push_back(mesh->mFaces->mIndices[0]+k*3);
out.index_list.push_back(mesh->mFaces->mIndices[1]+k*3);
out.index_list.push_back(mesh->mFaces->mIndices[2]+k*3);
}
else
{
std::cout << "wierd number of indices to a face: " << mesh->mFaces->mNumIndices << std::endl;
}
}
I've also tried some variations based on the relative number of vertexes and faces in a mesh, guessing that it should be a triangle strip, etc... and that also isn't working.
Example:
if (mesh->mNumFaces == mesh->mNumVertices-2)
for (size_t k = 0; k<mesh->mNumVertices-2; ++k)
{
if (k%2)
{
out.index_list.push_back(k+1);
out.index_list.push_back(k+0);
out.index_list.push_back(k+2);
}
else
{
out.index_list.push_back(k+0);
out.index_list.push_back(k+1);
out.index_list.push_back(k+2);
}
}
else if...
I'm obviously missing something very basic and obvious here, but I can't see what it is.