Ammo.js Plugin Left Handed Coordinate Bug

(I can’t post all the playgrounds referenced here, since there’s a 2-link limit. They’re all here: babylon-test/ at master · Quadtree/babylon-test · GitHub )

I believe I’ve found a bug in the ammo.js plugin. Essentially, when the glTF loader loads a model and the scene is in the default left-handed mode, the glTF loader inverts the Z axis (since glTFs are right-handed). It does this by setting the root TransformNode to the scale (1,1,-1). Then when the ammo.js plugin loads it as a static trimesh, it only considers the local scale, rather than the parent’s scale, causing the Z inversion to be ignored. You can see the effect in this playground:

(See Playground 1)

One simple workaround is to switch the scene to right-handed mode:

(See Playground 2)

A more comprehensive solution is to patch the _addMeshVerts function so it takes the parent’s scale into account:

(See Playground 3)

If this looks like a good solution, I can clean it up a bit and submit it as a PR. There is a slight backwards compatibility break, since projects might be depending on the inverted behavior. Hopefully this will be rare, though.

Pinging @Cedric

Let me take a look…

Vertex transformation when creating a mesh impostor seems incomplete to me. I’m working on a fix.

PR MeshImpostor local position transform by CedricGuillemet · Pull Request #10031 · BabylonJS/Babylon.js · GitHub