thinInstanceAdd - incorrect z-position on imported models vs Babylon primitives

When using thinInstanceAdd, it appears that the z position is flipped for imported models, as demonstrated in the playground:

Thin Instance bug | Babylon.js Playground (babylonjs.com)

const position1 = new BABYLON.Vector3(-0.2, 0.1, 0);
Both objects appear at the same location

const position2 = new BABYLON.Vector3(0.2, 0.1, 0.25);
x and y positions are correct, but z appears mirrored for the imported mesh.

Could this be related to how babylon imports glb files?

gltf is right-handed and babylon is per default left-handed. so yes, it is probably because of the way we import the mesh. The root mesh (the first mesh provided by the loader) is setting the mesh’s orientation to be compatible with left-handed system, so in this case applying a reversed matrix on the z will work -

Thin Instance bug | Babylon.js Playground (babylonjs.com)

Babylon does support right-handed system, but it seems that in this case something is different in the way we are loading the mesh. In this case you will first need to reset the roation of the loaded mesh:

Thin Instance bug | Babylon.js Playground (babylonjs.com)

I will let @bghgary comment on the 180 degrees rotation when using RHS - is this something we apply? is it needed when using RHS?
(just a note - he is away right now and will be back next week, sorry about any delay…)

3 Likes

Yes, but it is not a flip in Z. It’s technically a flip in X. I didn’t realize in the beginning that a flip in Z and a 180 rotation is equivalent to a flip in X. That’s why there is a Z flip and an additional 180 rotation. I can’t change it to a flip in X without breaking some scenarios and thus it is stuck this way.

Whether a transform is right-handed or left-handed just requires a flip in one axis. It can be X, Y, or Z.

glTF spec: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#coordinate-system-and-units

2 Likes

Thanks for your reply @bghgary, it’s good to know what’s happening behind the scenes

2 Likes