Can you invert the face normals of a figure?

So in my project I’ve been generating shapes via for loops, some of them generate the shape in a correct way and some doesn’t, so I want to know if there is any way to force Babylon.JS to calculate everytime the normals to the outside?

I wish I could give a playground but this time the shape is being generated from a json file and the playground didn’t let me put a tunnel to call that json.

This is the shape in question (ignore the lines), some of the shapes are with the correct normals but others are with inverted normals.

if is needed I can send code scripplets of the loop.

You could just copy and paste the json into the PG

2 Likes

https://playground.babylonjs.com/#GI8Z7K

You can check VertexData.ComputeNormals: Create Custom Meshes From Scratch | Babylon.js Documentation (babylonjs.com)

Keep in mind that, for the normals to be correctly computed, the faces should be specified in the correct orientation: Counterclockwise in a Left Handed System.

1 Like

https://playground.babylonjs.com/#GI8Z7K#1
Look at lines 392-410. I have used this previously to determine winding order when using 2D clipping libraries supporting holes etc.

3 Likes

Finally! thanks for the answer it really helped me a lot with the normals issue!

2 Likes