From 72d4643ff930dd468e313524ebd892cfd5da3876 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Mon, 27 Apr 2026 00:55:12 +0200 Subject: [PATCH] Refactor camera zoom to use smooth, stepped transitions for perspective and orthographic views --- src/viewport-three/viewport-host.ts | 38 +++++++++++++++++++---------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/viewport-three/viewport-host.ts b/src/viewport-three/viewport-host.ts index c3cf3585..ae2539fe 100644 --- a/src/viewport-three/viewport-host.ts +++ b/src/viewport-three/viewport-host.ts @@ -9619,26 +9619,38 @@ export class ViewportHost { event.preventDefault(); if (this.viewMode === "perspective") { - this.cameraSpherical.radius = Math.min( - MAX_CAMERA_DISTANCE, - Math.max( - MIN_CAMERA_DISTANCE, - this.cameraSpherical.radius * Math.exp(event.deltaY * ZOOM_SPEED) - ) + this.targetPerspectiveCameraRadius = this.clampPerspectiveCameraRadius( + (this.targetPerspectiveCameraRadius ?? this.cameraSpherical.radius) * + Math.exp(event.deltaY * ZOOM_SPEED) ); + const nextRadius = this.stepSmoothZoomValue( + this.cameraSpherical.radius, + this.targetPerspectiveCameraRadius, + SMOOTH_ZOOM_IMMEDIATE_RESPONSE + ); + this.cameraSpherical.radius = nextRadius.value; + if (nextRadius.done) { + this.targetPerspectiveCameraRadius = null; + } this.applyPerspectiveCameraPose(); this.emitCameraStateChange(); return; } - this.orthographicCamera.zoom = Math.min( - MAX_ORTHOGRAPHIC_ZOOM, - Math.max( - MIN_ORTHOGRAPHIC_ZOOM, - this.orthographicCamera.zoom * Math.exp(-event.deltaY * ZOOM_SPEED) - ) + this.targetOrthographicCameraZoom = this.clampOrthographicCameraZoom( + (this.targetOrthographicCameraZoom ?? this.orthographicCamera.zoom) * + Math.exp(-event.deltaY * ZOOM_SPEED) ); - this.orthographicCamera.updateProjectionMatrix(); + const nextZoom = this.stepSmoothZoomValue( + this.orthographicCamera.zoom, + this.targetOrthographicCameraZoom, + SMOOTH_ZOOM_IMMEDIATE_RESPONSE + ); + this.orthographicCamera.zoom = nextZoom.value; + if (nextZoom.done) { + this.targetOrthographicCameraZoom = null; + } + this.applyOrthographicCameraPose(); this.emitCameraStateChange(); };