I am trying to transform a scene in Unity to the same in Three.js.
I tried several approaches and all the web articles I could find. One rotation is eluding me though.
Unity is Left Handed, ZXY order of rotation
Three is Right handed, XYZ
Those are my camera and objects:
this.camera = new THREE.PerspectiveCamera( 60, ratio, 512, 4096 ); //21.23931
this.camera.position.set( 1735, 1968.4, -1191) ;
const posR = new THREE.Vector3(1581, 1.0,551);
const posG = new THREE.Vector3(1415.26, 1.0, 666.77);
const posB = new THREE.Vector3(1540.04, 1.07, 846.82);
I am flipping the Y and Z axis
this.camera.position.set( this.camera.position.x, this.camera.position.z, this.camera.position.y) ;
mesh1.position.set( mesh1.position.x, mesh1.position.z, mesh1.position.y) ;
mesh2.position.set( mesh2.position.x, mesh2.position.z, mesh2.position.y) ;
mesh3.position.set( mesh3.position.x, mesh3.position.z, mesh3.position.y) ;
The rotation works well for X,Y axis.
Quaternion approach :
let angleX = 45;
let angleY = 0;
let angleZ = 0;
var unityQuat = new THREE.Quaternion();
var unityEuler = new THREE.Euler(THREE.MathUtils.degToRad(angleX), THREE.MathUtils.degToRad(angleY),THREE.MathUtils.degToRad(angleZ), 'ZXY' );
unityQuat.setFromEuler(unityEuler);
const UQuat = unityQuat;
var q = new THREE.Quaternion( UQuat.x, -UQuat.z, -UQuat.y, UQuat.w );
var v = new THREE.Euler();
v.setFromQuaternion( q );
unityEuler = v;
this.camera.setRotationFromEuler( unityEuler );
or Euler approach
let cameraRot = [THREE.MathUtils.degToRad(90 - angleX),THREE.MathUtils.degToRad(-angleZ), THREE.MathUtils.degToRad(-angleY)]
var unityEuler = new THREE.Euler( cameraRot[0], cameraRot[1], cameraRot[2], 'YZX' );