From 85bedf77013717a56c2f189dfd725cb7a797932f Mon Sep 17 00:00:00 2001 From: Andrea Gargaro Date: Thu, 2 Mar 2023 15:09:57 +0100 Subject: [PATCH] Trackball zoom limit --- examples/jsm/controls/TrackballControls.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/examples/jsm/controls/TrackballControls.js b/examples/jsm/controls/TrackballControls.js index 77ef51c48e03ee..038b0c93d3975f 100644 --- a/examples/jsm/controls/TrackballControls.js +++ b/examples/jsm/controls/TrackballControls.js @@ -1,5 +1,6 @@ import { EventDispatcher, + MathUtils, MOUSE, Quaternion, Vector2, @@ -205,8 +206,13 @@ class TrackballControls extends EventDispatcher { } else if ( scope.object.isOrthographicCamera ) { - scope.object.zoom /= factor; - scope.object.updateProjectionMatrix(); + scope.object.zoom = MathUtils.clamp(scope.object.zoom / factor, scope.minDistance, scope.maxDistance); + + if (lastZoom != scope.object.zoom) { + + scope.object.updateProjectionMatrix(); + + } } else { @@ -226,8 +232,13 @@ class TrackballControls extends EventDispatcher { } else if ( scope.object.isOrthographicCamera ) { - scope.object.zoom /= factor; - scope.object.updateProjectionMatrix(); + scope.object.zoom = MathUtils.clamp(scope.object.zoom / factor, scope.minDistance, scope.maxDistance); + + if (lastZoom != scope.object.zoom) { + + scope.object.updateProjectionMatrix(); + + } } else {