Physics impostors for imported gltf are wrong

I’m sorry for creating all these threads on physics related questions/bugs in the last days. It’s just that for the first time I’m intensively working with the physics system and I’m stumbling on some issues here and there… That said here is another one:

I created a simple model in Blender, consisting of three cubes, which should be used as physics impostors later on:

I export everything as gltf and import it to babylon where I create the physics impostors. Pretty straightforward. The problem comes to the negative z-scaling of the gltf root mesh. This directly causes the actual physics impostors to be aligned the wrong way. I’m using Cannon and wrote some code to visualize the actual cannon shapes:

The white meshes is the actual geometry (I also enabled the physics viewer on the inspector, hence the wireframes). The magenta meshes are the cannon shapes.

As soon as I reset the z-scaling of the gltf root, everything is aligned as it should, but of course my model is flipped as a consequence:

Another workaround is to use scene.useRightHandedSystem = true this way the imported gtlf as no negative scaling on the z-axis and also it is not flipped.

I found some issues related to this, and there also is a merged PR which should have fixed this problem:

I’m attaching the original .blend as well as the exported .gltf and I’ll try to create a playground for reproduction of this issue. (108.2 KB)

1 Like

Oh great, I created a playground and there everything is working perfectly fine! I love when this happens…

I’m going to investigate if the problem is within my project and report back!

Allright, I figured out what’s causing the issue in my project: The imported gltf has a rotation on the y-axis of 180° applied, I’m resetting this first thing after the import is completed (and before creating the physics impostors) by doing physicsRoot.rotationQuaternion = new BABYLON.Quaternion(). I updated the playground accordingly:

That means, the issues is not as severe as I first suspected, could still be worth investigating?

Ok it’s me again, I found more weirdness… Please look at the following example:

I added gravity and a ground to the playground. I dont do any resets of scaling or rotationQuaternion. The object tips to the wrong side, as if the leg was attached to the other side:


When enabling scene.useRightHandedSystem = true the problem goes away:


I’m not sure if there’s anything that can be done except useRightHandedSystem :\ @Cedric

I’m very busy this week. But I’ll take a look next week (hopefully)

1 Like

@carolhmj I’m good using useRightHandedSystem, but since it took me at least a couple of hours to notice something is wrong and figure out what it was, I want other to potentially have a smoother experience :slight_smile:

1 Like

Coordinate systems are different between Blender and engines. Moreover, .gltf are right handed and, by default, babylonjs is left handed.
To do the conversion between right hand gltf and babylon left hand, a rotation and a scale is applied. This works fine for rendering but once physic is in the picture, it can become difficult.
IMHO, the best is to limit the number of system conversion. If using a right hand is not a problem for you, then it might be best to stay rght hand.
Other wise, another approach can be to use left hand babylon and bake transforms in the geometry. But it can also be challenging with rotations. If all your geometry is aligned on unit axis (hence, without rotations), it can also be a solution.