I'm using Assimp to load in a model to render in OpenGL (the model is a .obj of the stanford bunny, with only vertex position information, no texture coordinates or normals). I set the postprocessing flags so that Assimp will generate smooth normals and calculate tangents/bitangents. However, while I can access the array of normals fine, I get a segfault when I try to access the array of tangents.
Here's the code I use to read the file, and all of my postprocess flags:
const aiScene* scene = importer.ReadFile(filename,
aiProcess_JoinIdenticalVertices |
aiProcess_Triangulate |
aiProcess_GenSmoothNormals |
aiProcess_CalcTangentSpace |
//aiProcess_RemoveComponent (remove colors) |
aiProcess_LimitBoneWeights |
aiProcess_ImproveCacheLocality |
aiProcess_RemoveRedundantMaterials |
aiProcess_GenUVCoords |
aiProcess_SortByPType |
aiProcess_FindDegenerates |
aiProcess_FindInvalidData |
aiProcess_FindInstances |
aiProcess_ValidateDataStructure |
aiProcess_OptimizeMeshes |
aiProcess_OptimizeGraph |
aiProcess_Debone |
0);
And here's where I crash:
vert.normal.x = mesh->mNormals[j].x; // This runs fine
vert.normal.y = mesh->mNormals[j].y;
vert.normal.z = mesh->mNormals[j].z;
vert.tangent.x = mesh->mTangents[j].x; // I crash here
vert.tangent.y = mesh->mTangents[j].y;
vert.tangent.z = mesh->mTangents[j].z;
Evidently, it's failing to create the tangents, even though I tell it to.
I tried to use importer.ApplyPostProcessing()
to calculate the tangents after the file is read and the other steps are complete, so that it has normals to calculate the tangents with, but I get the same result.