@d5techs/3dgs-lib 1.4.36 → 1.4.38

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.cjs CHANGED
@@ -630,6 +630,10 @@ const _OrbitControls = class _OrbitControls {
630
630
  // 移动端触摸灵敏度
631
631
  __publicField(this, "touchZoomSpeed", 0.01);
632
632
  __publicField(this, "touchPanSpeed", 3e-3);
633
+ // 缩放步长上限:取 min(distance, cameraToCenterDist, zoomDistanceCap),
634
+ // 使缩放速度始终与相机到模型的真实距离匹配,而非 target 位置。
635
+ __publicField(this, "zoomDistanceCap", Infinity);
636
+ __publicField(this, "_modelCenter", [0, 0, 0]);
633
637
  // 阻尼:每帧应用全量 delta,然后 delta *= (1 - dampingFactor) 实现惯性
634
638
  __publicField(this, "enableDamping", true);
635
639
  __publicField(this, "dampingFactor", 0.1);
@@ -793,7 +797,9 @@ const _OrbitControls = class _OrbitControls {
793
797
  const maxAccum = 120 * this.zoomSpeed * this.dampingFactor * 3;
794
798
  this.deltaDistance = Math.sign(this.deltaDistance) * Math.min(Math.abs(this.deltaDistance), maxAccum);
795
799
  } else {
796
- this.distance *= Math.exp(zoomDelta);
800
+ const factor = Math.exp(zoomDelta);
801
+ const effectiveDist = this.getEffectiveZoomDist();
802
+ this.distance -= effectiveDist * (1 - factor);
797
803
  this.distance = Math.max(
798
804
  this.minDistance,
799
805
  Math.min(this.maxDistance, this.distance)
@@ -942,7 +948,9 @@ const _OrbitControls = class _OrbitControls {
942
948
  if (this.enableDamping) {
943
949
  this.deltaDistance += -Math.log(ratio) * this.dampingFactor;
944
950
  } else {
945
- this.distance /= ratio;
951
+ const factor = 1 / ratio;
952
+ const effectiveDist = this.getEffectiveZoomDist();
953
+ this.distance -= effectiveDist * (1 - factor);
946
954
  this.distance = Math.max(
947
955
  this.minDistance,
948
956
  Math.min(this.maxDistance, this.distance)
@@ -1005,6 +1013,17 @@ const _OrbitControls = class _OrbitControls {
1005
1013
  this.camera.position[2] = this.camera.target[2] + this.distance * sinPhi * cosTheta;
1006
1014
  this.camera.updateMatrix();
1007
1015
  }
1016
+ /**
1017
+ * 缩放有效距离:取 distance、相机到模型中心距离、zoomDistanceCap 三者最小值。
1018
+ * 保证缩放步长始终与相机到模型的真实接近程度匹配。
1019
+ */
1020
+ getEffectiveZoomDist() {
1021
+ const cp = this.camera.position;
1022
+ const mc = this._modelCenter;
1023
+ const dx = cp[0] - mc[0], dy = cp[1] - mc[1], dz = cp[2] - mc[2];
1024
+ const camToCenter = Math.sqrt(dx * dx + dy * dy + dz * dz);
1025
+ return Math.min(this.distance, camToCenter, this.zoomDistanceCap);
1026
+ }
1008
1027
  /**
1009
1028
  * 每帧调用:应用阻尼衰减并更新相机
1010
1029
  * 在渲染循环中调用此方法以获得平滑惯性效果
@@ -1022,7 +1041,9 @@ const _OrbitControls = class _OrbitControls {
1022
1041
  if (Math.abs(this.deltaTheta) < EPS) this.deltaTheta = 0;
1023
1042
  if (Math.abs(this.deltaPhi) < EPS) this.deltaPhi = 0;
1024
1043
  if (Math.abs(this.deltaDistance) > EPS) {
1025
- this.distance *= Math.exp(this.deltaDistance);
1044
+ const factor = Math.exp(this.deltaDistance);
1045
+ const effectiveDist = this.getEffectiveZoomDist();
1046
+ this.distance -= effectiveDist * (1 - factor);
1026
1047
  this.distance = Math.max(
1027
1048
  this.minDistance,
1028
1049
  Math.min(this.maxDistance, this.distance)
@@ -1122,6 +1143,8 @@ const _OrbitControls = class _OrbitControls {
1122
1143
  }
1123
1144
  frameModel(center, radius, animate = true) {
1124
1145
  this.clearVelocity();
1146
+ this.zoomDistanceCap = radius;
1147
+ this._modelCenter = [center[0], center[1], center[2]];
1125
1148
  const fovRad = this.camera.fov;
1126
1149
  const halfFov = fovRad / 2;
1127
1150
  const marginFactor = 1.5;