Detect if normals are "correct" or need to be flipped?

Hi guys,

sometimes I import models into babylon, which have wrong normals (for example they are “black” when light is turned on). Is it possible to detect, when they are wrong and need to be flipped?

P.S.: I’m using a right handed system.

Best regards,

MrGroove

Hi,
I suppose you know about the ‘inspector’ debug section? ‘Display Normal’ and ‘Render Vertex Normals’ debugging options on mesh selection should help with that. I guess.

1 Like

I’m looking for an algorithmic way. Possibly detect the side orientation?

I’m not an expert on computational geometry, but as far as I know there’s no “perfect” solutions for the general case, only approximations and heuristics. If you can make some assumptions about the geometry then there might be a way; I’ve implemented one approach for terrain that could only consist of walls, simplistic slopes, and flat tiles, but it likely won’t work without these restrictions. One other basic idea would be defining the “center” of a model and then having the normals point “outwards”, which works in many simple cases but isn’t a general solution for complex meshes either.

If you need something more advanced, I’d google for “point cloud normal vector estimation” algorithms.

One paper I found this way describes some approaches worth looking into, if it does match your problem: ResearchGate overview

Hi @MrGroove just checking in, was your question answered? :smiley:

@MrGroove :

I have been dealing with this issue both with importing into BJS and exporting from BJS. I have had success with fixing up the normals in Fusion 360 before importing. There is an option to repair imported meshes by “wrapping” them.

I have also tried doing the same with algorithms and have found it to be some pretty heavy lifting! I tried shooting rays at my models to determine what the outside was and it worked until it didn’t. :melting_face:

What format are your models?

Hi.

I also have the same problem. I need a way to detect if the imported asset is based on left or right handed system.

Thanks.

What format are your assets in? If you aren’t using a format with a defined handedness (like GLTF, which is always right-handed), this is a difficult task :slight_smile: