Skip to content

Commit

Permalink
fix: execute dragging once per frame (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillH0lt authored and yomotsu committed Oct 29, 2023
1 parent 58e4db3 commit 79a3537
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"serve": "^14.2.1",
"terser": "^5.19.3",
"three": "^0.155.0",
"tslib": "^2.6.2",
"typedoc": "^0.25.0",
"typescript": "^5.2.2"
},
Expand Down
8 changes: 7 additions & 1 deletion src/CameraControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ export class CameraControls extends EventDispatcher {
protected _elementRect = new DOMRect();

protected _isDragging = false;
protected _dragNeedsUpdate = true;
protected _activePointers: PointerInput[] = [];
protected _lockedPointer: PointerInput | null = null;
protected _interactiveArea = new DOMRect( 0, 0, 1, 1 );
Expand Down Expand Up @@ -1112,7 +1113,8 @@ export class CameraControls extends EventDispatcher {

const dragging = (): void => {

if ( ! this._enabled ) return;
if ( ! this._enabled || ! this._dragNeedsUpdate ) return;
this._dragNeedsUpdate = false;

extractClientCoordFromEvent( this._activePointers, _v2 );

Expand Down Expand Up @@ -1232,6 +1234,8 @@ export class CameraControls extends EventDispatcher {
extractClientCoordFromEvent( this._activePointers, _v2 );
lastDragPosition.copy( _v2 );

this._dragNeedsUpdate = false;

if (
this._activePointers.length === 0 ||
( this._activePointers.length === 1 && this._activePointers[ 0 ] === this._lockedPointer )
Expand Down Expand Up @@ -2810,6 +2814,8 @@ export class CameraControls extends EventDispatcher {

}

this._dragNeedsUpdate = true;

// collision detection
const maxDistance = this._collisionTest();
this._spherical.radius = Math.min( this._spherical.radius, maxDistance );
Expand Down

0 comments on commit 79a3537

Please sign in to comment.