Convert Unity transforms to THREE.js rotations

后端 未结 3 1171
慢半拍i
慢半拍i 2021-02-10 01:57

How can I match the rotation of a THREE.js camera or object to a transform from a Unity GameObject?

Unity uses a left-handed system with a ZXY euler order. THREE.js uses

3条回答
  •  隐瞒了意图╮
    2021-02-10 02:38

    We ended up fixing this as follows:

    Assuming you get qx, qy, qz and qw from Unity's quaternion, we apply the conversion below in JavaScript / Three.JS:

    // convert Quaternion from Left-handed coordinate system to Right-handed
    
    var q = new THREE.Quaternion( -qx, qy, qz, -qw );
    
    var v = new THREE.Euler();  
    v.setFromQuaternion( q );
    
    v.y += Math.PI; // Y is 180 degrees off
    
    v.z *= -1; // flip Z
    
    object.rotation.copy( v );
    

    That worked correctly in all axis rotations and directions.

    three.js r.59

提交回复
热议问题