【发布时间】:2014-05-24 05:09:10
【问题描述】:
根据模型文件对象定义,新对象的放置由 location(空间中的一个点)和 X 轴、Y 轴和 Z 轴的标准化方向给出。
如何将其转换为 THREE.Euler,以便我可以在空间中正确旋转我的对象。
所以轴是关闭类型THREE.Vector3。
如果新对象与world 对齐,则值为:
xAxis = new THREE.Vector3( 1, 0, 0 );
yAxis = new THREE.Vector3( 0, 1, 0 );
zAxis = new THREE.Vector3( 0, 0, 1 );
但是,例如,如果对象的整个局部 UCS 围绕 zAxis 旋转 180 度(或 Math.PI),它们将如下所示:
xAxis = new THREE.Vector3( -1, 0, 0 );
yAxis = new THREE.Vector3( 0, -1, 0 );
zAxis = new THREE.Vector3( 0, 0, 1 );
所以我需要这样做:
var object3D = new THREE.Object3D();
object3D.position = location;
var euler = new THREE.Euler();
euler.setFromNormalizedAxes( xAxis, yAxis, zAxis );
object3D.rotation = euler;
或者从这些轴创建一个旋转矩阵:
var rotationMatrix = new THREE.Matrix4();
rotationMatrix.setFromNormalizedAxes( xAxis, yAxis, zAxis );
object3D.rotation.setFromRotationMatrix( rotationMatrix, "XYZ" );
我还不太擅长这些旋转矩阵和欧拉旋转...
【问题讨论】:
-
你太离谱了。请参阅lighthouse3d.com/tutorials/glsl-tutorial/the-normal-matrix 了解什么是法线矩阵以及它的用途。
-
@WestLangley 好吧,你是对的,我完全误解了
_normalMatrix的功能。我改变了问题。当我在挖掘并遇到 normalMatrix 时,它看起来像这样:1 0 0 0 1 0 0 0 1 这与 X、Y 和 Z 轴定义完全相同,这就是为什么我认为它与标准化 UCS 轴有关.
标签: matrix rotation three.js normals euler-angles