@ericchen1990/pano-view 3.6.2 → 3.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -3769,12 +3769,18 @@ var PointerDragAnchor = class {
3769
3769
  this.projection = projection;
3770
3770
  this.local = new import_three2.Vector3();
3771
3771
  this.rotation = new import_three2.Euler(0, 0, 0, "YXZ");
3772
- this.anchor = this.ray(start).clone().applyEuler(this.rotation.set(
3772
+ const startRay = this.ray(start).clone();
3773
+ this.baseAzimuth = Math.atan2(startRay.x, -startRay.z);
3774
+ this.baseElevation = Math.atan2(startRay.y, -startRay.z);
3775
+ this.anchor = startRay.clone().applyEuler(this.rotation.set(
3773
3776
  import_three2.MathUtils.degToRad(origin.pitch),
3774
3777
  import_three2.MathUtils.degToRad(-origin.yaw),
3775
3778
  0,
3776
3779
  "YXZ"
3777
3780
  ));
3781
+ const originPitch = import_three2.MathUtils.degToRad(origin.pitch);
3782
+ const roots = this.pitchRoots(startRay, originPitch);
3783
+ this.useSupplementary = Math.abs(roots.supplementary - originPitch) + 1e-6 < Math.abs(roots.principal - originPitch);
3778
3784
  }
3779
3785
  ray(point) {
3780
3786
  return this.local.set(
@@ -3783,6 +3789,21 @@ var PointerDragAnchor = class {
3783
3789
  0.5
3784
3790
  ).applyMatrix4(this.projection.projectionMatrixInverse).normalize();
3785
3791
  }
3792
+ /** Pitch roots of the level-camera constraint. The supplementary root is unwrapped toward the press. */
3793
+ pitchRoots(ray, originPitch) {
3794
+ const latitude = Math.asin(import_three2.MathUtils.clamp(
3795
+ this.anchor.y / Math.max(Math.hypot(ray.y, ray.z), 1e-12),
3796
+ -1,
3797
+ 1
3798
+ ));
3799
+ const offset = Math.atan2(ray.y, -ray.z);
3800
+ const principal = latitude - offset;
3801
+ const turned = Math.PI - latitude - offset;
3802
+ return {
3803
+ principal,
3804
+ supplementary: originPitch + Math.atan2(Math.sin(turned - originPitch), Math.cos(turned - originPitch))
3805
+ };
3806
+ }
3786
3807
  solve(point, speed = DEFAULT_POINTER_DRAG_SPEED, invert = false) {
3787
3808
  const multiplier = (Number.isFinite(speed) && speed >= 0 ? speed : DEFAULT_POINTER_DRAG_SPEED) / DEFAULT_POINTER_DRAG_SPEED * (invert ? -1 : 1);
3788
3809
  if (multiplier === 0) return { yaw: 0, pitch: 0 };
@@ -3790,22 +3811,27 @@ var PointerDragAnchor = class {
3790
3811
  x: this.start.x + (point.x - this.start.x) * multiplier,
3791
3812
  y: this.start.y + (point.y - this.start.y) * multiplier
3792
3813
  });
3793
- const latitude = Math.asin(import_three2.MathUtils.clamp(this.anchor.y / Math.max(Math.hypot(ray.y, ray.z), 1e-12), -1, 1));
3794
- const offset = Math.atan2(ray.y, -ray.z);
3795
3814
  const originPitch = import_three2.MathUtils.degToRad(this.origin.pitch);
3796
- const candidates = [latitude - offset, Math.PI - latitude - offset, -Math.PI - latitude - offset];
3797
- let pitch = candidates[0];
3798
- let distance = Infinity;
3799
- for (const candidate of candidates) {
3800
- const bounded = import_three2.MathUtils.clamp(candidate, -Math.PI / 2, Math.PI / 2);
3801
- const nextDistance = Math.abs(candidate - bounded) * 10 + Math.abs(bounded - originPitch);
3802
- if (nextDistance < distance) {
3803
- pitch = bounded;
3804
- distance = nextDistance;
3805
- }
3806
- }
3807
- const z = Math.sin(pitch) * ray.y + Math.cos(pitch) * ray.z;
3808
- const yaw = import_three2.MathUtils.radToDeg(Math.atan2(this.anchor.x, -this.anchor.z) - Math.atan2(ray.x, -z));
3815
+ const roots = this.pitchRoots(ray, originPitch);
3816
+ const exactPitch = import_three2.MathUtils.clamp(
3817
+ this.useSupplementary ? roots.supplementary : roots.principal,
3818
+ -Math.PI / 2,
3819
+ Math.PI / 2
3820
+ );
3821
+ const stablePitch = originPitch - (Math.atan2(ray.y, -ray.z) - this.baseElevation);
3822
+ const fromPole = Math.asin(Math.min(1, Math.hypot(this.anchor.x, this.anchor.z)));
3823
+ const pointerLock = import_three2.MathUtils.smoothstep(fromPole, import_three2.MathUtils.degToRad(8), import_three2.MathUtils.degToRad(18));
3824
+ const pitchTurn = Math.atan2(Math.sin(exactPitch - stablePitch), Math.cos(exactPitch - stablePitch));
3825
+ const pitch = import_three2.MathUtils.clamp(
3826
+ pointerLock >= 1 ? exactPitch : stablePitch + pointerLock * pitchTurn,
3827
+ -Math.PI / 2,
3828
+ Math.PI / 2
3829
+ );
3830
+ const pitchedZ = Math.sin(exactPitch) * ray.y + Math.cos(exactPitch) * ray.z;
3831
+ const exactYaw = Math.atan2(this.anchor.x, -this.anchor.z) - Math.atan2(ray.x, -pitchedZ);
3832
+ const stableYaw = import_three2.MathUtils.degToRad(this.origin.yaw) + Math.atan2(ray.x, -ray.z) - this.baseAzimuth;
3833
+ const yawTurn = Math.atan2(Math.sin(exactYaw - stableYaw), Math.cos(exactYaw - stableYaw));
3834
+ const yaw = import_three2.MathUtils.radToDeg(stableYaw + pointerLock * yawTurn);
3809
3835
  return { yaw: normalizeViewYaw(yaw - this.origin.yaw), pitch: import_three2.MathUtils.radToDeg(pitch) - this.origin.pitch };
3810
3836
  }
3811
3837
  };