Setting the position and rotation of a mesh with a matrix


I am working on with an AR library and using Babylonjs as the 3D renderer with great success. The AR framework returns a matrix to orient the 3D model globally, which is an excellent way to communicate. Searching the Babylon documentation and the web, I found a solution to setting the model’s position in space. I was wondering if there was a better way.

let matrix : BABYLON.Matrix // from AR framework

// set rotation
let rotMatrix : BABYLON.Matrix = matrix.getRotationMatrix();
let rotation : BABYLON.Quaternion = new BABYLON.Quaternion().fromRotationMatrix(rotMatrix);
this.root.rotation = rotation.toEulerAngles();

// set position
let pos = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(0, 0, 0), matrix);

This seems like a lot of work. Most libraries have a mesh.setMatrix(matrix).

Thanks Eddie

like this? :slight_smile:
(un-comment line #26 & click run)