zoom = e => {
mouse.animating = true;
controls.enabled = false;
let requestId;
if (mouse.focus)
moveCamera(
true,
camera.position.x, 450, camera.position.z,
-(mouse.focus.position.x + mouse.focus.scale.x / 2) + camera.position.x,
dimensions.height / 2,
-(mouse.focus.position.z + mouse.focus.scale.z / 2) + camera.position.z);
else
moveCamera(
false,
0, 650, 0,
-dimensions.width / 2, dimensions.height / 2, -dimensions.depth / 2,
-1.57, 0, 0);
function moveCamera(dollyOut, x, y, z, sx, sy, sz, rx, ry, rz) {
animate();
if (dollyOut)
gsap.to(camera.position, {duration: 0.1, y: 600}).then(() => move());
else
move();
function move() {
const tweens = [];
if (requires(x, y, z)) tweens.push(gsap.to(camera.position, {duration: 0.25, x, y, z}));
if (requires(sx, sy, sz)) tweens.push(gsap.to(scene.position, {duration: 0.25, x: sx, y: sy, z: sz}));
if (requires(rx, ry, rz)) tweens.push(gsap.to(camera.rotation, {duration: 0.25, x: rx, y: ry, z: rz}));
Promise.all(tweens).then(() => {
cancelAnimationFrame(requestId);
if (!mouse.focus)
controls.reset();
else
controls.update();
mouse.animating = false;
controls.enabled = true;
});
}
}
function requires(a, b, c) {
return a || a === 0 || b || b === 0 || c || c === 0;
}
function animate() {
requestId = requestAnimationFrame(animate);
renderer.clear();
renderer.render(scene, camera);
}
}