Some Havok shapes are flipped/rotated incorrectly

Hi everyone,

Playground that works: Babylon.js Playground

Playground that fails:

The tree in the second playground is either flipped or rotated incorrectly. I cannot figure out why.

I first thought it has something to do with the GLTF root node conversion and wasted a good hour trying to counter-act that. But then playground1 should fail as well, shouldnt it?

Best wishes

Making sure it really is flipped and not just the viewer being off:

What happens when you set?

scene.useRightHandedSystem = true

I think I figured out the why:

I use Blender. When I set the “origin to geometry” it works in Babylon. Figuring out what Blender’s “origin” maps to Babylon.

Latest playground nailing down the problem:

I cannot find an equivalent concept of Blender’s “origin”. Pivot (as in Mesh.getPivotPoint) seemed to fit but both are 0. But Babylon definitely knows the origin because if you try to rotate any of the cubes it is rotated around the origin. (i.e. 1st cube around the geometry center, 2nd cube around the bottom-center) Anyway, whatever this origin is in Babylon if it is not zero, it seems to throw off Havok.

Having said all that, if I do what @Takemura suggests it works (

But why??

Why does the first playground (Babylon.js Playground) work then?

It seems to me that vertices positions are different. Can you check it?

Also the physics engine I used (Cannon, Ammo) did cause problems with right handed roots of glb. This could also be the case for Havok (creating physics body with right handed mesh/vertices positions or parents y-rotation&z-scaling?). So I ended up using right handed system for my project.

If you check the truck from

the physics body is not perfectly aligned aswell:

so it is not just the tree. The issue occurs if origin is not centered and using right handed model.

The z-rotation of 180° (check glb root mesh), makes y being flipped. But i don’t know how physics body is created. Atleast it would make sense if it considers parent transform.

Ooh, nice spot. Didn’t see that! Only question now is why is the truck bounding box only slightly off and the tree box big times?

@Takemura Not sure what you mean by vertices positions?

From what I learned meshes are, if not empty like root, made of triangles/facets. Every triangle consists 3 edges. And every Edge consist two points/positions (start and end). Every vertex position is transformed by its mesh world matrix.
When you change origin i.e. to geometry center in blender, the mesh’s world matrix will change according to new position and the vertices positions will also change invertly, so that the mesh and its vertices stays at the same absolute/global world position.

A tutorial video for blender vertexes, edges and faces might help you, which shows how to view vertices position. In short:

  1. Select a mesh
  2. Switch to edit mode
  3. Check to be in vertex mode
  4. Select vertex
  5. Check its local position

Do check it before and after you changed origin.

How to get vertices data in BabylonJS:

1 Like