@d5techs/3dgs-lib 1.4.32 → 1.4.34

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/3dgs-lib.js CHANGED
@@ -623,7 +623,7 @@ const _OrbitControls = class _OrbitControls {
623
623
  __publicField(this, "maxPhi", Math.PI - 0.01);
624
624
  // 灵敏度
625
625
  __publicField(this, "rotateSpeed", 5e-3);
626
- __publicField(this, "zoomSpeed", 15e-4);
626
+ __publicField(this, "zoomSpeed", 1e-3);
627
627
  __publicField(this, "panSpeed", 5e-3);
628
628
  // 移动端触摸灵敏度
629
629
  __publicField(this, "touchZoomSpeed", 0.01);
@@ -788,6 +788,8 @@ const _OrbitControls = class _OrbitControls {
788
788
  const zoomDelta = normalizedDelta * this.zoomSpeed;
789
789
  if (this.enableDamping) {
790
790
  this.deltaDistance += zoomDelta * this.dampingFactor;
791
+ const maxAccum = 120 * this.zoomSpeed * this.dampingFactor * 3;
792
+ this.deltaDistance = Math.sign(this.deltaDistance) * Math.min(Math.abs(this.deltaDistance), maxAccum);
791
793
  } else {
792
794
  this.distance *= Math.exp(zoomDelta);
793
795
  this.distance = Math.max(
@@ -1091,6 +1093,24 @@ const _OrbitControls = class _OrbitControls {
1091
1093
  this.camera.target[2] = z;
1092
1094
  this.applySpherical();
1093
1095
  }
1096
+ /**
1097
+ * 将 target 移到新位置,但保持相机世界坐标不变(重算 distance/theta/phi)
1098
+ */
1099
+ setTargetKeepPosition(x, y, z) {
1100
+ this.clearVelocity();
1101
+ const dx = this.camera.position[0] - x;
1102
+ const dy = this.camera.position[1] - y;
1103
+ const dz = this.camera.position[2] - z;
1104
+ const newDist = Math.sqrt(dx * dx + dy * dy + dz * dz);
1105
+ if (newDist < this.minDistance) return;
1106
+ this.camera.target[0] = x;
1107
+ this.camera.target[1] = y;
1108
+ this.camera.target[2] = z;
1109
+ this.distance = newDist;
1110
+ this.theta = Math.atan2(dx, dz);
1111
+ this.phi = Math.acos(Math.min(1, Math.max(-1, dy / newDist)));
1112
+ this.applySpherical();
1113
+ }
1094
1114
  getTarget() {
1095
1115
  return [
1096
1116
  this.camera.target[0],
@@ -1103,28 +1123,15 @@ const _OrbitControls = class _OrbitControls {
1103
1123
  const fovRad = this.camera.fov;
1104
1124
  const halfFov = fovRad / 2;
1105
1125
  const marginFactor = 1.5;
1106
- const totalDistance = radius / Math.tan(halfFov) * marginFactor;
1107
- const surfaceOffset = radius * 0.85;
1108
- const sinPhi = Math.sin(this.phi);
1109
- const cosPhi = Math.cos(this.phi);
1110
- const sinTheta = Math.sin(this.theta);
1111
- const cosTheta = Math.cos(this.theta);
1112
- const offsetTarget = [
1113
- center[0] + sinPhi * sinTheta * surfaceOffset,
1114
- center[1] + cosPhi * surfaceOffset,
1115
- center[2] + sinPhi * cosTheta * surfaceOffset
1116
- ];
1117
- const adjustedDistance = Math.max(
1118
- this.minDistance,
1119
- totalDistance - surfaceOffset
1120
- );
1126
+ const targetDistance = radius / Math.tan(halfFov) * marginFactor;
1127
+ const clampedDistance = Math.max(this.minDistance, targetDistance);
1121
1128
  if (animate) {
1122
- this.animateToFrame(offsetTarget, adjustedDistance);
1129
+ this.animateToFrame(center, clampedDistance);
1123
1130
  } else {
1124
- this.camera.target[0] = offsetTarget[0];
1125
- this.camera.target[1] = offsetTarget[1];
1126
- this.camera.target[2] = offsetTarget[2];
1127
- this.distance = adjustedDistance;
1131
+ this.camera.target[0] = center[0];
1132
+ this.camera.target[1] = center[1];
1133
+ this.camera.target[2] = center[2];
1134
+ this.distance = clampedDistance;
1128
1135
  this.applySpherical();
1129
1136
  }
1130
1137
  }
@@ -18796,6 +18803,16 @@ class App {
18796
18803
  return false;
18797
18804
  }
18798
18805
  this.controls.frameModel(bbox.center, bbox.radius, animate);
18806
+ if (!animate) {
18807
+ const rect = this.canvas.getBoundingClientRect();
18808
+ const hit = this.pickSplatPosition(
18809
+ rect.left + rect.width / 2,
18810
+ rect.top + rect.height / 2
18811
+ );
18812
+ if (hit) {
18813
+ this.controls.setTargetKeepPosition(hit[0], hit[1], hit[2]);
18814
+ }
18815
+ }
18799
18816
  return true;
18800
18817
  }
18801
18818
  // ============================================