我想旋转骨骼,使其与 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/