三JS-访问ArrowHelper方向



假设我创建了一个箭头助手,例如:

const arrowPosition = new THREE.Vector3(0, 0, 0);
const arrowPosition = new THREE.Vector3(2, -2, 0);
arrowDirection.subVectors( scene.position, new THREE.Vector3(1, 1, 1)).normalize();
arrow = new THREE.ArrowHelper( arrowDirection, arrowPosition, arrowLength, 0xffff00, arrowHeadLength, arrowHeadWidth);

创建它之后,我如何访问它的方向?

简而言之,我不确定是否有一种简单的方法可以访问方向,至少在vector3格式中是这样。ArrowHelper构造函数中使用的值dir(如文档中所述(从未直接分配给ArrowHelperObject3D父类的向量属性,而是用于设置从父类继承的ArrowHelper的四元数属性。

请参阅下面来自助手源代码的代码片段:

setDirection( dir ) {
// dir is assumed to be normalized
if ( dir.y > 0.99999 ) {
this.quaternion.set( 0, 0, 0, 1 );
} else if ( dir.y < - 0.99999 ) {
this.quaternion.set( 1, 0, 0, 0 );
} else {
_axis.set( dir.z, 0, - dir.x ).normalize();
const radians = Math.acos( dir.y );
this.quaternion.setFromAxisAngle( _axis, radians );
}
}

如Object3D文档中所列,quaternion描述辅助对象的旋转(四元数文档(。关于数学的更好讨论可能会在这个团结论坛上找到,但要获得矢量方向,您需要使用quaternion字段

希望这有帮助,如果有人能改进这个解释,请这样做,我对欧拉和四元数的经验是有限的

最新更新