From 49a15b26a584f94d2f04a15b9027e8f5e5102ca7 Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Sun, 13 Jun 2021 21:32:18 +0200 Subject: [PATCH] Add option to zoom in viewport using mouse cursor --- js/interface/actions.js | 4 ++++ js/preview/OrbitControls.js | 17 +++++++++++++---- js/preview/canvas.js | 4 ++-- js/preview/preview.js | 2 +- lang/en.json | 1 + 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/js/interface/actions.js b/js/interface/actions.js index a08c6aa..28654f1 100644 --- a/js/interface/actions.js +++ b/js/interface/actions.js @@ -1270,6 +1270,10 @@ const BARS = { category: 'navigate', keybind: new Keybind({key: 3}) }) + new KeybindItem('preview_zoom', { + category: 'navigate', + keybind: new Keybind({key: 1, shift: true}) + }) new KeybindItem('confirm', { category: 'navigate', diff --git a/js/preview/OrbitControls.js b/js/preview/OrbitControls.js index 3ff9f6f..523cd2c 100644 --- a/js/preview/OrbitControls.js +++ b/js/preview/OrbitControls.js @@ -248,8 +248,8 @@ THREE.OrbitControls = function ( object, preview ) { } - function getZoomScale() { - return Math.pow( 0.95, scope.zoomSpeed ); + function getZoomScale(modifier = 1) { + return Math.pow( 0.95, scope.zoomSpeed * modifier); } @@ -418,9 +418,9 @@ THREE.OrbitControls = function ( object, preview ) { dollyDelta.subVectors( dollyEnd, dollyStart ); if ( dollyDelta.y > 0 ) { - dollyIn( getZoomScale() ); + dollyIn( getZoomScale(0.12 * dollyDelta.y) ); } else if ( dollyDelta.y < 0 ) { - dollyOut( getZoomScale() ); + dollyOut( getZoomScale(0.12 * -dollyDelta.y) ); } dollyStart.copy( dollyEnd ); @@ -617,6 +617,15 @@ THREE.OrbitControls = function ( object, preview ) { } handleMouseDownPan( event ); state = STATE.PAN; + + } else if ( Keybinds.extra.preview_zoom.keybind.isTriggered(event) ) { + + if ( scope.enableZoom === false ) return; + if (event.which === 1 && Canvas.raycast(event) && display_mode === false) { + return; + } + handleMouseDownDolly( event ); + state = STATE.DOLLY; } if ( state !== STATE.NONE ) { diff --git a/js/preview/canvas.js b/js/preview/canvas.js index 14ab8fb..636f617 100644 --- a/js/preview/canvas.js +++ b/js/preview/canvas.js @@ -67,8 +67,8 @@ const Canvas = { varying float lift; float AMBIENT = 0.1; - float XFAC = -0.25; - float ZFAC = 0.2; + float XFAC = -0.05; + float ZFAC = 0.05; void main() { diff --git a/js/preview/preview.js b/js/preview/preview.js index ba6a586..087e66f 100644 --- a/js/preview/preview.js +++ b/js/preview/preview.js @@ -18,7 +18,7 @@ var gizmo_colors = { b: new THREE.Color(0x2d5ee8), grid: new THREE.Color(0x495061), wire: new THREE.Color(0x576f82), - solid: new THREE.Color(0xcecece), + solid: new THREE.Color(0xc1c1c1), outline: new THREE.Color(0x3e90ff) } const DefaultCameraPresets = [ diff --git a/lang/en.json b/lang/en.json index ab0f445..fb38207 100644 --- a/lang/en.json +++ b/lang/en.json @@ -655,6 +655,7 @@ "keybind.preview_select": "Select", "keybind.preview_rotate": "Rotate View", "keybind.preview_drag": "Drag View", + "keybind.preview_zoom": "Zoom View", "keybind.confirm": "Confirm", "keybind.cancel": "Cancel",