LOD not working when instances have negative scaling

If an instanced object has a LOD and also is negatively scaled, the LOD levels fail to activate and the object gets stuck in initial high level of detail.

See playground reproduction: https://playground.babylonjs.com/#0720FC#93

What is strange is that inspecting the instance._currentLod property actually is returning the correct value, so the logic that chooses the LOD level is working, just for some reason the active mesh never updates.

I’m gonna start digging into the babylon codebase to try and figure this out, but any pointers greatly appreciated!

I have tracked the issue to this line of code in InstancedMesh.ts:

If true is returned here, everything works correctly. Now I just need to dig into what this code is supposed to be doing and why it isn’t working correctly for this case.

This is as far as I can go without more understanding of what this sign checking code is supposed to do. Hopefully someone else can take a look and figure out if this is the correct behavior, and if so why.

For now though, I can monkey patch my own babylon to hack around the issue.

Edit: Oh, now I see what this is for. It is to prevent the instanced meshes from getting turned inside out. Hmm, this could be tricky indeed.

Yes, having an odd number of negative scales will change the winding of a mesh, so we have to do extra annoying things to handle this case.

I’m afraid it’s a bit complicated (with a high probability of breaking something in the process) to try to handle the case where the source mesh and its LODs don’t have the same matrix determinant. So, for the time being, it’s a limitation of the LOD system that the source mesh and the LODs must have the same matrix determinant.

1 Like

Hmmm, just messing about in the playground and it appears I can create a second root mesh with a negative scale, and then instance any odds with this one instead.

Hopefully this will be a good enough solution (linking playground in case anyone else encounters this limitation in the future). Thanks for the pointers!

Playground with “fix”: https://playground.babylonjs.com/#0720FC#96