I get the wrong normals when reading normals from a FBX file

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I wrote a converter that converts model files into my own custom file format. For FBX files, I use the FBX SDK. So far, everything works perfectly fine, incl. loading mesh geometries, materials, texture information, animations, etc. I bought models from many artists for my video game and all work fine so far except for one. When loading these models, the geometry is fine, but the normals are wrong. I wrote a simple pixel shader that shows only the normals of a surface and this is the result:
The ground and the two containers in the center are fine. Their top normals are showing upwards (= green). However, you can see the other buildings have a red roof, which means the normal is something like (1.0f, 0.0f, 0.0f) - which points to the right. When I open these models in any modelling tool like blender or the new Microsoft 3D viewer, they are displayed correctly as you can see here:
It seems that I miss some information when reading normals from the FBX files. This is the code I am using:
FbxGeometryElementNormal* vertexNormal = pMesh->GetElementNormal(0); float normalX = 0.0f, normalY = 0.0f, normalZ = 0.0f; if(vertexNormal->GetMappingMode() == FbxGeometryElement::eByPolygonVertex && vertexNormal->GetReferenceMode() == FbxGeometryElement::eDirect) { int inVertexCounter = (int)geometry->GetNumberOfVertices(); normalX = static_cast<float>(vertexNormal->GetDirectArray().GetAt(inVertexCounter).mData[0]); normalY = static_cast<float>(vertexNormal->GetDirectArray().GetAt(inVertexCounter).mData[1]); normalZ = static_cast<float>(vertexNormal->GetDirectArray().GetAt(inVertexCounter).mData[2]); }
What did I do wrong? Or do I miss something?