Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset focal offsets on input start and setLookAt #507

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/CameraControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,8 @@ export class CameraControls extends EventDispatcher {
if ( ! this._domElement ) return;
if ( ! this._enabled || this.mouseButtons.wheel === ACTION.NONE ) return;

this._resetFocalOffsets();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about moving this line to the beginning of _zoomInternal() and _dollyInternal() with if ( this.dollyToCursor )?
Then wheel zoom/dolly will reset focalOffsets.

eg

protected _dollyInternal = ( delta: number, x: number, y : number ): void => {

  if ( this.dollyToCursor ) this._resetFocalOffsets();


if (
this._interactiveArea.left !== 0 ||
this._interactiveArea.top !== 0 ||
Expand Down Expand Up @@ -843,6 +845,8 @@ export class CameraControls extends EventDispatcher {

if ( ! this._enabled ) return;

this._resetFocalOffsets();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think mouse drag movement does not affect focalOffset. so, can we remove this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to call this whenever any input starts. Otherwise, we may interrupt transitions or animations. Is there a better place to put this?


extractClientCoordFromEvent( this._activePointers, _v2 );

this._getClientRect( this._elementRect );
Expand Down Expand Up @@ -2034,6 +2038,8 @@ export class CameraControls extends EventDispatcher {
enableTransition: boolean = false,
): Promise<void> {

this._resetFocalOffsets();

this._isUserControllingRotate = false;
this._isUserControllingDolly = false;
this._isUserControllingTruck = false;
Expand Down Expand Up @@ -3214,6 +3220,19 @@ export class CameraControls extends EventDispatcher {

protected _removeAllEventListeners(): void {}

// Applies and resets focal offsets to play nice with lookAt and zoom-to-cursor
// https://github.com/yomotsu/camera-controls/issues/491
_resetFocalOffsets() {
CodyJasonBennett marked this conversation as resolved.
Show resolved Hide resolved

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we check the focalOffset value first?
If the value is 0, 0, 0, let's just return and do nothing.

_v3A.set( 0, 0, -1 ).applyQuaternion( this._camera.quaternion );
_v3A.multiplyScalar( this._spherical.radius );
_v3A.add( this._camera.position );

this.setFocalOffset( 0, 0, 0, false );
this.moveTo( _v3A.x, _v3A.y, _v3A.z, false );

}

/**
* backward compatible
* @deprecated use smoothTime (in seconds) instead
Expand Down