将 Unity 变换转换为 THREE.js 旋转 [英] Convert Unity transforms to THREE.js rotations

查看:57
本文介绍了将 Unity 变换转换为 THREE.js 旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 THREE.js 相机或对象的旋转与 Unity 游戏对象的变换相匹配?

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

Unity 使用具有 ZXY 欧拉阶数的左手系统.THREE.js 使用具有 XYZ euler 阶数的右手系统.

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:

假设您从 Unity 的四元数中获得 qxqyqzqw,我们应用以下转换在 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

这篇关于将 Unity 变换转换为 THREE.js 旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆