@d5techs/3dgs-lib 1.4.31 → 1.4.32

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
@@ -635,9 +635,10 @@ const _OrbitControls = class _OrbitControls {
635
635
  __publicField(this, "isDragging", false);
636
636
  __publicField(this, "lastX", 0);
637
637
  __publicField(this, "lastY", 0);
638
- // 待应用的增量(每帧全量应用后衰减,实现旋转/平移惯性)
638
+ // 待应用的增量(每帧全量应用后衰减,实现惯性)
639
639
  __publicField(this, "deltaTheta", 0);
640
640
  __publicField(this, "deltaPhi", 0);
641
+ __publicField(this, "deltaDistance", 0);
641
642
  __publicField(this, "deltaPanX", 0);
642
643
  __publicField(this, "deltaPanY", 0);
643
644
  __publicField(this, "deltaPanZ", 0);
@@ -785,11 +786,16 @@ const _OrbitControls = class _OrbitControls {
785
786
  else if (e.deltaMode === 2) delta *= 800;
786
787
  const normalizedDelta = Math.sign(delta) * Math.min(Math.abs(delta), 120);
787
788
  const zoomDelta = normalizedDelta * this.zoomSpeed;
788
- this.distance *= Math.exp(zoomDelta);
789
- this.distance = Math.max(
790
- this.minDistance,
791
- Math.min(this.maxDistance, this.distance)
792
- );
789
+ if (this.enableDamping) {
790
+ this.deltaDistance += zoomDelta * this.dampingFactor;
791
+ } else {
792
+ this.distance *= Math.exp(zoomDelta);
793
+ this.distance = Math.max(
794
+ this.minDistance,
795
+ Math.min(this.maxDistance, this.distance)
796
+ );
797
+ this.applySpherical();
798
+ }
793
799
  }
794
800
  onKeyDown(e) {
795
801
  var _a2;
@@ -929,11 +935,15 @@ const _OrbitControls = class _OrbitControls {
929
935
  const currentCenter = this.getTouchCenter(e.touches);
930
936
  if (this.lastTouchDistance > 0) {
931
937
  const ratio = currentDistance / this.lastTouchDistance;
932
- this.distance /= ratio;
933
- this.distance = Math.max(
934
- this.minDistance,
935
- Math.min(this.maxDistance, this.distance)
936
- );
938
+ if (this.enableDamping) {
939
+ this.deltaDistance += -Math.log(ratio) * this.dampingFactor;
940
+ } else {
941
+ this.distance /= ratio;
942
+ this.distance = Math.max(
943
+ this.minDistance,
944
+ Math.min(this.maxDistance, this.distance)
945
+ );
946
+ }
937
947
  }
938
948
  const deltaX = currentCenter.x - this.lastTouchCenter.x;
939
949
  const deltaY = currentCenter.y - this.lastTouchCenter.y;
@@ -1007,6 +1017,15 @@ const _OrbitControls = class _OrbitControls {
1007
1017
  this.deltaPhi *= decay;
1008
1018
  if (Math.abs(this.deltaTheta) < EPS) this.deltaTheta = 0;
1009
1019
  if (Math.abs(this.deltaPhi) < EPS) this.deltaPhi = 0;
1020
+ if (Math.abs(this.deltaDistance) > EPS) {
1021
+ this.distance *= Math.exp(this.deltaDistance);
1022
+ this.distance = Math.max(
1023
+ this.minDistance,
1024
+ Math.min(this.maxDistance, this.distance)
1025
+ );
1026
+ this.deltaDistance *= decay;
1027
+ if (Math.abs(this.deltaDistance) < EPS) this.deltaDistance = 0;
1028
+ }
1010
1029
  this.camera.target[0] += this.deltaPanX;
1011
1030
  this.camera.target[1] += this.deltaPanY;
1012
1031
  this.camera.target[2] += this.deltaPanZ;
@@ -1084,15 +1103,28 @@ const _OrbitControls = class _OrbitControls {
1084
1103
  const fovRad = this.camera.fov;
1085
1104
  const halfFov = fovRad / 2;
1086
1105
  const marginFactor = 1.5;
1087
- const targetDistance = radius / Math.tan(halfFov) * marginFactor;
1088
- const clampedDistance = Math.max(this.minDistance, targetDistance);
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
+ );
1089
1121
  if (animate) {
1090
- this.animateToFrame(center, clampedDistance);
1122
+ this.animateToFrame(offsetTarget, adjustedDistance);
1091
1123
  } else {
1092
- this.camera.target[0] = center[0];
1093
- this.camera.target[1] = center[1];
1094
- this.camera.target[2] = center[2];
1095
- this.distance = clampedDistance;
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;
1096
1128
  this.applySpherical();
1097
1129
  }
1098
1130
  }
@@ -1123,6 +1155,7 @@ const _OrbitControls = class _OrbitControls {
1123
1155
  clearVelocity() {
1124
1156
  this.deltaTheta = 0;
1125
1157
  this.deltaPhi = 0;
1158
+ this.deltaDistance = 0;
1126
1159
  this.deltaPanX = 0;
1127
1160
  this.deltaPanY = 0;
1128
1161
  this.deltaPanZ = 0;