Hello, Is there any way to animate camera movement when camera.lookAt(mesh) function is called.
I have a case where I need to focus on the mesh and defocus with click on the button.
Advance thank you)
You might want to use Quaternion.rotateTowards() for this. Check out its usage here:
Inspired by Unity’s Quaternion.RotateTowards function.
1 Like
thank you very much for your response
I have this code but could you guide me what I did wrong
FocusModel: function() {
var rotationMatrix = new THREE.Matrix4();
var targetQuaternion = new THREE.Quaternion();
rotationMatrix.lookAt(
this.picked_asset.position,
this.camera.position,
this.camera.up
);
targetQuaternion.setFromRotationMatrix(rotationMatrix);
//Number of animation frames
var animFrames = 200;
//Pause between two consecutive animation frames
var deltaT = 1;
const goSlerping = acc => {
if (acc >= 1) return;
if (
!this.camera.quaternion.equals(this.picked_asset.quaternion)
) {
var step = 2 * acc;
this.camera.quaternion.rotateTowards(
targetQuaternion,
step
);
}
setTimeout(function() {
goSlerping(acc + 1 / animFrames);
}, deltaT);
};
goSlerping(1 / animFrames);
}