Skip to content

Commit

Permalink
ensure pan target appears and disappears correctly (#3354)
Browse files Browse the repository at this point in the history
  • Loading branch information
elalish authored Apr 7, 2022
1 parent 747695b commit a2c2c9a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/model-viewer/src/three-components/SmoothControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,15 +647,16 @@ export class SmoothControls extends EventDispatcher {
}

private recenter(pointer: Pointer) {
const {scene} = this;
(scene.element as any)[$panElement].style.opacity = 0;

if (!this.enablePan ||
Math.abs(pointer.clientX - this.startPointerPosition.clientX) >
TAP_DISTANCE ||
Math.abs(pointer.clientY - this.startPointerPosition.clientY) >
TAP_DISTANCE) {
return;
}
const {scene} = this;
(scene.element as any)[$panElement].style.opacity = 0;

const hit = scene.positionAndNormalFromPoint(
scene.getNDC(pointer.clientX, pointer.clientY));
Expand All @@ -673,15 +674,17 @@ export class SmoothControls extends EventDispatcher {
}

private resetRadius() {
const {scene} = this;
(scene.element as any)[$panElement].style.opacity = 0;

if (!this.enablePan || this.panPerPixel === 0) {
return;
}
const {scene} = this;
(scene.element as any)[$panElement].style.opacity = 0;

const hit = scene.positionAndNormalFromPoint(vector2.set(0, 0));
if (hit == null)
if (hit == null) {
return;
}

scene.target.worldToLocal(hit.position);
const goalTarget = scene.getTarget();
Expand Down Expand Up @@ -767,7 +770,7 @@ export class SmoothControls extends EventDispatcher {
null :
this.touchModeZoom;
this.touchDecided = true;
if (this.enablePan) {
if (this.enablePan && this.touchMode != null) {
this.initializePan();
const x = 0.5 * (targetTouches[0].clientX + targetTouches[1].clientX);
const y = 0.5 * (targetTouches[0].clientY + targetTouches[1].clientY);
Expand Down

0 comments on commit a2c2c9a

Please sign in to comment.