Feel free to test out the zoom functionality in the scene.
function customZoom(center, size) {
// Obtain the current lookAt vector of OrthographicCamera camera
var vectorLookAt = new THREE.Vector3(0, 0, -1);
vectorLookAt.applyQuaternion(camera.quaternion);
vectorLookAt.normalize();
// Adjust position of camera based on lookat vector
vectorLookAt.multiplyScalar(-size);
camera.position = new THREE.Vector3().addVectors(center, vectorLookAt);
// Retrieve the current size of the camera
var viewSize = 2 * camera.top;
var aspectRatio = 2 * camera.right / viewSize; // Calculate aspect ratio of camera
// Update camera with new size and aspect ratio
viewSize = size;
camera.left = -aspectRatio * viewSize / 2;
camera.right = aspectRatio * viewSize / 2;
camera.top = viewSize / 2;
camera.bottom = -viewSize / 2;
camera.near = 0.1;
camera.far = 2 * size;
camera.updateProjectionMatrix();
// Set light to follow camera position
spotLight.position.set(camera.position.x, camera.position.y, camera.position.z);
// Set center point for orbit control
orbitControls.center.set(center.x, center.y, center.z);
orbitControls.target.set(center.x, center.y, center.z);
}