@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.cjs CHANGED
@@ -637,9 +637,10 @@ const _OrbitControls = class _OrbitControls {
637
637
  __publicField(this, "isDragging", false);
638
638
  __publicField(this, "lastX", 0);
639
639
  __publicField(this, "lastY", 0);
640
- // 待应用的增量(每帧全量应用后衰减,实现旋转/平移惯性)
640
+ // 待应用的增量(每帧全量应用后衰减,实现惯性)
641
641
  __publicField(this, "deltaTheta", 0);
642
642
  __publicField(this, "deltaPhi", 0);
643
+ __publicField(this, "deltaDistance", 0);
643
644
  __publicField(this, "deltaPanX", 0);
644
645
  __publicField(this, "deltaPanY", 0);
645
646
  __publicField(this, "deltaPanZ", 0);
@@ -787,11 +788,16 @@ const _OrbitControls = class _OrbitControls {
787
788
  else if (e.deltaMode === 2) delta *= 800;
788
789
  const normalizedDelta = Math.sign(delta) * Math.min(Math.abs(delta), 120);
789
790
  const zoomDelta = normalizedDelta * this.zoomSpeed;
790
- this.distance *= Math.exp(zoomDelta);
791
- this.distance = Math.max(
792
- this.minDistance,
793
- Math.min(this.maxDistance, this.distance)
794
- );
791
+ if (this.enableDamping) {
792
+ this.deltaDistance += zoomDelta * this.dampingFactor;
793
+ } else {
794
+ this.distance *= Math.exp(zoomDelta);
795
+ this.distance = Math.max(
796
+ this.minDistance,
797
+ Math.min(this.maxDistance, this.distance)
798
+ );
799
+ this.applySpherical();
800
+ }
795
801
  }
796
802
  onKeyDown(e) {
797
803
  var _a2;
@@ -931,11 +937,15 @@ const _OrbitControls = class _OrbitControls {
931
937
  const currentCenter = this.getTouchCenter(e.touches);
932
938
  if (this.lastTouchDistance > 0) {
933
939
  const ratio = currentDistance / this.lastTouchDistance;
934
- this.distance /= ratio;
935
- this.distance = Math.max(
936
- this.minDistance,
937
- Math.min(this.maxDistance, this.distance)
938
- );
940
+ if (this.enableDamping) {
941
+ this.deltaDistance += -Math.log(ratio) * this.dampingFactor;
942
+ } else {
943
+ this.distance /= ratio;
944
+ this.distance = Math.max(
945
+ this.minDistance,
946
+ Math.min(this.maxDistance, this.distance)
947
+ );
948
+ }
939
949
  }
940
950
  const deltaX = currentCenter.x - this.lastTouchCenter.x;
941
951
  const deltaY = currentCenter.y - this.lastTouchCenter.y;
@@ -1009,6 +1019,15 @@ const _OrbitControls = class _OrbitControls {
1009
1019
  this.deltaPhi *= decay;
1010
1020
  if (Math.abs(this.deltaTheta) < EPS) this.deltaTheta = 0;
1011
1021
  if (Math.abs(this.deltaPhi) < EPS) this.deltaPhi = 0;
1022
+ if (Math.abs(this.deltaDistance) > EPS) {
1023
+ this.distance *= Math.exp(this.deltaDistance);
1024
+ this.distance = Math.max(
1025
+ this.minDistance,
1026
+ Math.min(this.maxDistance, this.distance)
1027
+ );
1028
+ this.deltaDistance *= decay;
1029
+ if (Math.abs(this.deltaDistance) < EPS) this.deltaDistance = 0;
1030
+ }
1012
1031
  this.camera.target[0] += this.deltaPanX;
1013
1032
  this.camera.target[1] += this.deltaPanY;
1014
1033
  this.camera.target[2] += this.deltaPanZ;
@@ -1086,15 +1105,28 @@ const _OrbitControls = class _OrbitControls {
1086
1105
  const fovRad = this.camera.fov;
1087
1106
  const halfFov = fovRad / 2;
1088
1107
  const marginFactor = 1.5;
1089
- const targetDistance = radius / Math.tan(halfFov) * marginFactor;
1090
- const clampedDistance = Math.max(this.minDistance, targetDistance);
1108
+ const totalDistance = radius / Math.tan(halfFov) * marginFactor;
1109
+ const surfaceOffset = radius * 0.85;
1110
+ const sinPhi = Math.sin(this.phi);
1111
+ const cosPhi = Math.cos(this.phi);
1112
+ const sinTheta = Math.sin(this.theta);
1113
+ const cosTheta = Math.cos(this.theta);
1114
+ const offsetTarget = [
1115
+ center[0] + sinPhi * sinTheta * surfaceOffset,
1116
+ center[1] + cosPhi * surfaceOffset,
1117
+ center[2] + sinPhi * cosTheta * surfaceOffset
1118
+ ];
1119
+ const adjustedDistance = Math.max(
1120
+ this.minDistance,
1121
+ totalDistance - surfaceOffset
1122
+ );
1091
1123
  if (animate) {
1092
- this.animateToFrame(center, clampedDistance);
1124
+ this.animateToFrame(offsetTarget, adjustedDistance);
1093
1125
  } else {
1094
- this.camera.target[0] = center[0];
1095
- this.camera.target[1] = center[1];
1096
- this.camera.target[2] = center[2];
1097
- this.distance = clampedDistance;
1126
+ this.camera.target[0] = offsetTarget[0];
1127
+ this.camera.target[1] = offsetTarget[1];
1128
+ this.camera.target[2] = offsetTarget[2];
1129
+ this.distance = adjustedDistance;
1098
1130
  this.applySpherical();
1099
1131
  }
1100
1132
  }
@@ -1125,6 +1157,7 @@ const _OrbitControls = class _OrbitControls {
1125
1157
  clearVelocity() {
1126
1158
  this.deltaTheta = 0;
1127
1159
  this.deltaPhi = 0;
1160
+ this.deltaDistance = 0;
1128
1161
  this.deltaPanX = 0;
1129
1162
  this.deltaPanY = 0;
1130
1163
  this.deltaPanZ = 0;