From 34fdda2feaa72c3f575b5478f1d602fa528173ee Mon Sep 17 00:00:00 2001 From: KPal <48248865+kpal81xd@users.noreply.github.com> Date: Tue, 5 Nov 2024 09:53:14 +0000 Subject: [PATCH] Gizmo hover disabled with no selection on mouse down (#7092) * Disable hover when moving mouse with no selection * Skip hover entirely without having to set value --- src/extras/gizmo/gizmo.js | 7 ++++++- src/extras/gizmo/transform-gizmo.js | 18 ++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/extras/gizmo/gizmo.js b/src/extras/gizmo/gizmo.js index 17808c4f406..76682053996 100644 --- a/src/extras/gizmo/gizmo.js +++ b/src/extras/gizmo/gizmo.js @@ -396,11 +396,16 @@ class Gizmo extends EventHandler { if (!this.root.enabled || document.pointerLockElement) { return; } + const selection = this._getSelection(e.offsetX, e.offsetY); + if (selection[0]) { + e.preventDefault(); + e.stopPropagation(); + } const { canvas } = this._device; canvas.releasePointerCapture(e.pointerId); - this.fire(Gizmo.EVENT_POINTERUP); + this.fire(Gizmo.EVENT_POINTERUP, e.offsetX, e.offsetY, selection[0]); } /** diff --git a/src/extras/gizmo/transform-gizmo.js b/src/extras/gizmo/transform-gizmo.js index 9323eba00a0..633b605a0b5 100644 --- a/src/extras/gizmo/transform-gizmo.js +++ b/src/extras/gizmo/transform-gizmo.js @@ -194,6 +194,14 @@ class TransformGizmo extends Gizmo { */ _hoverIsPlane = false; + /** + * Internal state of if there is no selection. + * + * @type {boolean} + * @private + */ + _noSelection = false; + /** * Internal currently selected axis. * @@ -278,6 +286,7 @@ class TransformGizmo extends Gizmo { } if (!meshInstance) { + this._noSelection = true; return; } @@ -298,7 +307,9 @@ class TransformGizmo extends Gizmo { return; } - this._hover(meshInstance); + if (!this._noSelection) { + this._hover(meshInstance); + } if (!this._dragging) { return; @@ -313,7 +324,10 @@ class TransformGizmo extends Gizmo { this._hoverIsPlane = false; }); - this.on(Gizmo.EVENT_POINTERUP, () => { + this.on(Gizmo.EVENT_POINTERUP, (x, y, meshInstance) => { + this._noSelection = false; + this._hover(meshInstance); + if (!this._dragging) { return; }