Skip to content

Commit

Permalink
Gizmo fixes (#6997)
Browse files Browse the repository at this point in the history
  • Loading branch information
slimbuck authored Sep 30, 2024
1 parent 21693b0 commit 800aa6c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
20 changes: 15 additions & 5 deletions src/extras/gizmo/gizmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ class Gizmo extends EventHandler {
this._onPointerMove = this._onPointerMove.bind(this);
this._onPointerUp = this._onPointerUp.bind(this);

this._device.canvas.addEventListener('pointerdown', this._onPointerDown, true);
this._device.canvas.addEventListener('pointermove', this._onPointerMove, true);
this._device.canvas.addEventListener('pointerdown', this._onPointerDown);
this._device.canvas.addEventListener('pointermove', this._onPointerMove);
this._device.canvas.addEventListener('pointerup', this._onPointerUp);

this._app.on('update', () => {
Expand Down Expand Up @@ -357,6 +357,11 @@ class Gizmo extends EventHandler {
e.preventDefault();
e.stopPropagation();
}

// capture the pointer during drag
const { canvas } = this._device;
canvas.setPointerCapture(e.pointerId);

this.fire(Gizmo.EVENT_POINTERDOWN, e.offsetX, e.offsetY, selection[0]);
}

Expand All @@ -377,12 +382,17 @@ class Gizmo extends EventHandler {
}

/**
* @param {PointerEvent} e - The pointer event.
* @private
*/
_onPointerUp() {
_onPointerUp(e) {
if (!this.root.enabled || document.pointerLockElement) {
return;
}

const { canvas } = this._device;
canvas.releasePointerCapture(e.pointerId);

this.fire(Gizmo.EVENT_POINTERUP);
}

Expand Down Expand Up @@ -552,8 +562,8 @@ class Gizmo extends EventHandler {
destroy() {
this.detach();

this._device.canvas.removeEventListener('pointerdown', this._onPointerDown, true);
this._device.canvas.removeEventListener('pointermove', this._onPointerMove, true);
this._device.canvas.removeEventListener('pointerdown', this._onPointerDown);
this._device.canvas.removeEventListener('pointermove', this._onPointerMove);
this._device.canvas.removeEventListener('pointerup', this._onPointerUp);

this.root.destroy();
Expand Down
2 changes: 1 addition & 1 deletion src/extras/gizmo/rotate-gizmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class RotateGizmo extends TransformGizmo {
this._nodeOffsets.clear();
});

this._app.on('update', () => {
this._app.on('prerender', () => {
this._faceAxisLookAtCamera();
this._xyzAxisLookAtCamera();

Expand Down
2 changes: 1 addition & 1 deletion src/extras/gizmo/transform-gizmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class TransformGizmo extends Gizmo {
constructor(camera, layer) {
super(camera, layer);

this._app.on('update', () => {
this._app.on('prerender', () => {
if (!this.root.enabled) {
return;
}
Expand Down

0 comments on commit 800aa6c

Please sign in to comment.