Inverse quaternion with cannon-es physical body

Hi everyone. I’m trying to implement trimesh support for cannon-es debugger. Like it was implemented in cannon-es debugger for Three.js.
When I copy position and quaternion from mesh to physical body - the quaternion is inverted. The parent of the mesh is null. So quaternion shouldn’t be inherited.
I update mesh position and quats in the render loop like this:

mesh.position.set(
                  body.position.x,
                  body.position.y,
                  body.position.z
          )
          mesh.rotationQuaternion?.set(
                  body.quaternion.x,
                  body.quaternion.y,
                  body.quaternion.z,
                  body.quaternion.w
          )

1 Like

Hi @Kostiantyn_Balanchuk and welcome to the forum

is the mesh imported from a .gltf? can you share a PG?

Yes, mesh is imported from a .gltf. Sorry, I can’t share PG because there is no support for cannon-es lib so far.
I’m loading the model using code below.

tconst assetsManager = new BABYLON.AssetsManager(scene)
      const path = 'public/scenes/'
      const name = 'suzanne.glb'
      const meshTask = assetsManager.addMeshTask('load task', '', path, name);

      meshTask.onSuccess = (task) => {
        task.loadedMeshes.forEach((mesh) => {
          mesh.setEnabled(false)
        })
        addModel({ mass: 1, position: { x: -3, y: 5, z: 3 } });
      }

when importing .gltf, because of different space, when scene is left handed (default), a -1 scale and a rotation is applied to the model.
Can you try with right handed scene?
add scene.useRightHandedSystem = true;

3 Likes

Yes sir! Thank you so much!

1 Like