Create physics body with imported model (Havok)

Is this the correct way to add collider to an imported mesh?

  BABYLON.SceneLoader.ImportMeshAsync("", "./public/", "jengaPiece.glb", scene).then((result) => {
    const jengaPiece = result.meshes[0];
    jengaPiece.position = new BABYLON.Vector3(0, 5, 0);
    new BABYLON.PhysicsAggregate(jengaPiece, BABYLON.PhysicsShapeType.BOX, { mass: 1, restitution: 0.5, friction: 0.2 }, scene);
  });

I am asking because it falls down (the physics work) but collider behaves weird, it sinks into ground and rotates and bounces around.

image

result.meshes[0]

Is probably the root TransformNode. Try .meshes[1] or otherwise find the actual mesh in the hierarchy.

Also, after that you might need before physics setup:

const mesh = getActualMesh();
mesh.refreshBoundingInfo(true);
//and/or
mesh.computeWorldMatrix(true);
1 Like

Thanks!