3

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.

Haydn V. Harach
  • 1,265
  • 1
  • 18
  • 36
  • 2
    You generally need texture coordinates to generate tangent vectors. Why would you need a tangent space basis if you have no way of mapping a normal map onto the mesh? – Andon M. Coleman Mar 09 '14 at 00:32
  • That would explain it. Assimp's manual only said that it needed normals, not texture coordinates, so I was wondering why it didn't work. – Haydn V. Harach Mar 09 '14 at 01:21
  • To calculate tangent you need delta position and delta texture coordinate. – ChaoSXDemon Dec 03 '17 at 02:31

0 Answers0