function animateCameraToPoint(point,camera_animation) {
// Compute the model's bounding box to determine size
const box = new THREE.Box3().setFromObject(model);
const size = new THREE.Vector3();
box.getSize(size);
// Calculate a distance factor based on model size
const distanceFactor = Math.max(size.x, size.y, size.z);
const zOffset = distanceFactor * 1.5; // Adjust multiplier for better framing
// Update OrbitControls target
orbitControls.target.set(point.x, point.y, point.z);
orbitControls.update(); // Apply changes to the controls
// Animate camera position
gsap.to(camera.position, {
x: point.x,
y: point.y + distanceFactor * 0.5, // Slightly above for better perspective
z: point.z + zOffset, // Offset for zoom
duration: 3,
ease: camera_animation || "power2.inOut", // Use a default easing function
});
// Continuously update camera to look at the target point
gsap.to(orbitControls.target, {
x: point.x,
y: point.y,
z: point.z,
duration: 3,
ease: camera_animation || "power2.inOut",
onUpdate: () => {
orbitControls.update();
}
});
}
Please help