转换团结转变为THREE.js旋转转变为、团结、js、THREE

2023-09-08 01:03:31 作者:剧终人散尽

我如何匹配THREE.js相机或对象的一个​​旋转从统一游戏物体变换?

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

统一使用左手系带ZXY欧拉次序。 THREE.js使用右手系统的XYZ欧拉订单。

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

需要进行转换 GameObject.transform.rotation (四元),以 Object3D.rotation 什么转换( THREE.Vector3)?

What transformations need to be made to convert GameObject.transform.rotation (Quaternion) to Object3D.rotation (THREE.Vector3)?

推荐答案

我们结束了解决这个如下:

We ended up fixing this as follows:

假设你得到 QX QY QZ QW 从团结的四元数,我们应用下面的JavaScript / Three.JS转换:

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

three.js r.59