Skip to content

Commit

Permalink
Gizmo hover disabled with no selection on mouse down (#7092)
Browse files Browse the repository at this point in the history
* Disable hover when moving mouse with no selection

* Skip hover entirely without having to set value
  • Loading branch information
kpal81xd authored Nov 5, 2024
1 parent a8cebda commit 34fdda2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/extras/gizmo/gizmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

/**
Expand Down
18 changes: 16 additions & 2 deletions src/extras/gizmo/transform-gizmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -278,6 +286,7 @@ class TransformGizmo extends Gizmo {
}

if (!meshInstance) {
this._noSelection = true;
return;
}

Expand All @@ -298,7 +307,9 @@ class TransformGizmo extends Gizmo {
return;
}

this._hover(meshInstance);
if (!this._noSelection) {
this._hover(meshInstance);
}

if (!this._dragging) {
return;
Expand All @@ -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;
}
Expand Down

0 comments on commit 34fdda2

Please sign in to comment.