Quaternion-rotate bone until it aligned with a Vector3, 三个js
Quaterion-rotate bone untill it alignes with a Vector3, 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
SomeFunctionThatMakesVec3intoQuarterion(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);
我想旋转骨骼使其与 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
SomeFunctionThatMakesVec3intoQuarterion(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);