[SOLVED] Fix normals

The cube in the blue circle has its shadow and lighted sides correct.
The objects in the red circle have their shadow and lighted sides inverted,
according to the direction of the light source.
How can I fix the normals so that the shadows are on the correct side ?

Blue circle: geometry created through com.jme3.scene.shape.Box
Rec circle: geometries created through GitHub - FennelFetish/jBMesh

1 Like

If they are indeed consistently exactly backwards then that’s weird that the library produces them that way.

To fix this in code the steps would be:

  1. grab the mesh
  2. get its Type.Normal VertexBuffer
  3. grab the FloatBuffer from it
  4. multiply all values in the FloatBuffer by -1 and set them back.
  5. send the VertexBuffer back to the mesh… (at least I think there is a way you need to tell the Mesh that the buffer has changed… you can look at some of the mesh subclass’s updateXXX() style methods to see).

…or maybe someone else has that handy.

1 Like

A utility to flip normals is Included in the MyMesh utility class in the Heart library.

Source code is here:

If the normals are flipped, you may also need to reverse the winding order, since incorrect winding order might be the cause. MyMesh also has a utility for that.


Winding order looks right or the objects would be rendered inside out.

Heart solved my problems :grinning:

Reversing the normals solved the issue depicted in the screenshot, light and shadow went to the right side.
And reversing the winding solved another problem that I hadn’t mentioned, namely that the objects didn’t ‘receive’ shadow.

Thank you @sgold and @pspeed for your work and time !!

1 Like