javascript - 四元数旋转骨骼,直到与一个Vector3、三个js对齐

标签 javascript three.js

我想旋转骨骼,使其与 Vector3(directionToTarget)对齐,我有:

const directionToTarget = new THREE.Vector3(random, random, random); //pseudocode randoms
directionToTarget.normalize();

var Hand2worldQ = new THREE.Quaternion();
this._anchor['LeftHandIndex1'].getWorldQuaternion(Hand2worldQ); // gets Lefthand bone quaternion

this._mesh.skeleton.bones[ 0 ].quaternion.set( SomeFunctionThatMakesVecintoQuarternion(directionToTarget ); 
// this._mesh.skeleton.bones inherits Hand2worldQ/LeftHand rotation

SomeFunctionThatMakesVec3intoQuarternion(directionToTarget) 是我所需要的

最佳答案

Object3D 首先向下查看 0, 0, 1 轴。您可以use the Object3D.lookAt() method使该对象指向您的目标向量。然后您可以提取该旋转并将其用于您需要的任何其他用途:

// Initialize an abstract object looking towards 0, 0, 1
const object3D = new THREE.Object3D();

// Rotate it so it looks towards the target xyz coordinates
object3D.lookAt(randomX, randomY, randomZ);

// This will now have the final rotation
const myQuaternion = object3D.quaternion;
console.log(myQuaternion);

关于javascript - 四元数旋转骨骼,直到与一个Vector3、三个js对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71229209/

相关文章:

javascript - 为什么我需要在这里输入 var 的内容以及为什么它会给我一个数字作为答案? (Javascript)

javascript - 如何在 Three.js 中将 2d 路径转换为 ​​3d 形状?

javascript - 单击搜索按钮时如何隐藏 jQuery 中的导航栏切换?

javascript - meteor :如何导出类并在服务器上的另一个文件中使用

javascript - 如何调试 Mustache js 模板?

javascript - 错误: write EPIPE on Cloud Run while using html-pdf NPM

javascript - 使用 Three.js 的 mousedown 事件不起作用,除非我单击并稍微拖动

javascript - Three.js:逐步增加纹理分辨率的策略

javascript - 使用 VRControls 时无法更改相机位置

javascript - 固定地板立方体的动态高度