@d5techs/3dgs-lib 1.4.37 → 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.js CHANGED
@@ -628,9 +628,10 @@ const _OrbitControls = class _OrbitControls {
628
628
  // 移动端触摸灵敏度
629
629
  __publicField(this, "touchZoomSpeed", 0.01);
630
630
  __publicField(this, "touchPanSpeed", 3e-3);
631
- // 缩放步长上限:用 min(distance, zoomDistanceCap) 计算每步的绝对位移,
632
- // 使远距离时缩放速度由模型尺寸而非 target 位置决定。frameModel 会自动设置为 radius。
631
+ // 缩放步长上限:取 min(distance, cameraToCenterDist, zoomDistanceCap)
632
+ // 使缩放速度始终与相机到模型的真实距离匹配,而非 target 位置。
633
633
  __publicField(this, "zoomDistanceCap", Infinity);
634
+ __publicField(this, "_modelCenter", [0, 0, 0]);
634
635
  // 阻尼:每帧应用全量 delta,然后 delta *= (1 - dampingFactor) 实现惯性
635
636
  __publicField(this, "enableDamping", true);
636
637
  __publicField(this, "dampingFactor", 0.1);
@@ -795,7 +796,7 @@ const _OrbitControls = class _OrbitControls {
795
796
  this.deltaDistance = Math.sign(this.deltaDistance) * Math.min(Math.abs(this.deltaDistance), maxAccum);
796
797
  } else {
797
798
  const factor = Math.exp(zoomDelta);
798
- const effectiveDist = Math.min(this.distance, this.zoomDistanceCap);
799
+ const effectiveDist = this.getEffectiveZoomDist();
799
800
  this.distance -= effectiveDist * (1 - factor);
800
801
  this.distance = Math.max(
801
802
  this.minDistance,
@@ -946,7 +947,7 @@ const _OrbitControls = class _OrbitControls {
946
947
  this.deltaDistance += -Math.log(ratio) * this.dampingFactor;
947
948
  } else {
948
949
  const factor = 1 / ratio;
949
- const effectiveDist = Math.min(this.distance, this.zoomDistanceCap);
950
+ const effectiveDist = this.getEffectiveZoomDist();
950
951
  this.distance -= effectiveDist * (1 - factor);
951
952
  this.distance = Math.max(
952
953
  this.minDistance,
@@ -1010,6 +1011,17 @@ const _OrbitControls = class _OrbitControls {
1010
1011
  this.camera.position[2] = this.camera.target[2] + this.distance * sinPhi * cosTheta;
1011
1012
  this.camera.updateMatrix();
1012
1013
  }
1014
+ /**
1015
+ * 缩放有效距离:取 distance、相机到模型中心距离、zoomDistanceCap 三者最小值。
1016
+ * 保证缩放步长始终与相机到模型的真实接近程度匹配。
1017
+ */
1018
+ getEffectiveZoomDist() {
1019
+ const cp = this.camera.position;
1020
+ const mc = this._modelCenter;
1021
+ const dx = cp[0] - mc[0], dy = cp[1] - mc[1], dz = cp[2] - mc[2];
1022
+ const camToCenter = Math.sqrt(dx * dx + dy * dy + dz * dz);
1023
+ return Math.min(this.distance, camToCenter, this.zoomDistanceCap);
1024
+ }
1013
1025
  /**
1014
1026
  * 每帧调用:应用阻尼衰减并更新相机
1015
1027
  * 在渲染循环中调用此方法以获得平滑惯性效果
@@ -1028,7 +1040,7 @@ const _OrbitControls = class _OrbitControls {
1028
1040
  if (Math.abs(this.deltaPhi) < EPS) this.deltaPhi = 0;
1029
1041
  if (Math.abs(this.deltaDistance) > EPS) {
1030
1042
  const factor = Math.exp(this.deltaDistance);
1031
- const effectiveDist = Math.min(this.distance, this.zoomDistanceCap);
1043
+ const effectiveDist = this.getEffectiveZoomDist();
1032
1044
  this.distance -= effectiveDist * (1 - factor);
1033
1045
  this.distance = Math.max(
1034
1046
  this.minDistance,
@@ -1130,6 +1142,7 @@ const _OrbitControls = class _OrbitControls {
1130
1142
  frameModel(center, radius, animate = true) {
1131
1143
  this.clearVelocity();
1132
1144
  this.zoomDistanceCap = radius;
1145
+ this._modelCenter = [center[0], center[1], center[2]];
1133
1146
  const fovRad = this.camera.fov;
1134
1147
  const halfFov = fovRad / 2;
1135
1148
  const marginFactor = 1.5;