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

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

Anonymous
Not applicable
1,699 Views
3 Replies
Message 1 of 4

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

Anonymous
Not applicable

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:

 

Normals.png

 

 

 

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:

 

Fine.png

 

 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?

 

0 Likes
1,700 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Not really, but they are a lot of unknown factors here (export, import, file data, etc...).

Why don't you start with a simple 6-sided box (with known vertex normals), and print out all the values from beginning to end.

0 Likes
Message 3 of 4

Anonymous
Not applicable

My implementations work fine for all other artists! I only have problems with the assets of this particular 3D artist. So, I know that the way I get the normals, convert FBX files to my file format and import my file format works fine - except for this case. Therefore, I assume that there is some kind of flag or property in the FBX files of this artist which I don't process.

0 Likes
Message 4 of 4

Anonymous
Not applicable

Well, if you're getting FBX files from different sources, then you should know there are at least 4 different ways to store vertex normals.  A good converter should cover them all.

eByControlPoint -> eDirect
eByControlPoint -> eIndexToDirect

eByPolygonVertex -> eDirect
eByPolygonVertex -> eIndexToDirect

0 Likes