@d5techs/3dgs-lib 1.4.28 → 1.4.30

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,22 +623,25 @@ 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", 8e-4);
626
+ __publicField(this, "zoomSpeed", 15e-4);
627
627
  __publicField(this, "panSpeed", 5e-3);
628
628
  // 移动端触摸灵敏度
629
629
  __publicField(this, "touchZoomSpeed", 0.01);
630
630
  __publicField(this, "touchPanSpeed", 3e-3);
631
- // 阻尼(值越大越灵敏,越小越丝滑;0.12 5 帧消化 50% 增量)
631
+ // 阻尼:每帧应用全量 delta,然后 delta *= (1 - dampingFactor) 实现惯性
632
632
  __publicField(this, "enableDamping", true);
633
- __publicField(this, "dampingFactor", 0.12);
633
+ __publicField(this, "dampingFactor", 0.1);
634
634
  // 状态
635
635
  __publicField(this, "isDragging", false);
636
636
  __publicField(this, "lastX", 0);
637
637
  __publicField(this, "lastY", 0);
638
- // 阻尼速度(仅平移使用)
639
- __publicField(this, "velocityPanX", 0);
640
- __publicField(this, "velocityPanY", 0);
641
- __publicField(this, "velocityPanZ", 0);
638
+ // 待应用的增量(每帧全量应用后衰减,实现惯性)
639
+ __publicField(this, "deltaTheta", 0);
640
+ __publicField(this, "deltaPhi", 0);
641
+ __publicField(this, "deltaDistance", 0);
642
+ __publicField(this, "deltaPanX", 0);
643
+ __publicField(this, "deltaPanY", 0);
644
+ __publicField(this, "deltaPanZ", 0);
642
645
  // 键盘移动
643
646
  __publicField(this, "moveSpeed", 0.015);
644
647
  __publicField(this, "pressedKeys", /* @__PURE__ */ new Set());
@@ -734,9 +737,10 @@ const _OrbitControls = class _OrbitControls {
734
737
  const dx = -deltaX * scale;
735
738
  const dy = deltaY * scale;
736
739
  if (this.enableDamping) {
737
- this.velocityPanX += dx * right[0] + dy * up[0];
738
- this.velocityPanY += dx * right[1] + dy * up[1];
739
- this.velocityPanZ += dx * right[2] + dy * up[2];
740
+ const d = this.dampingFactor;
741
+ this.deltaPanX += (dx * right[0] + dy * up[0]) * d;
742
+ this.deltaPanY += (dx * right[1] + dy * up[1]) * d;
743
+ this.deltaPanZ += (dx * right[2] + dy * up[2]) * d;
740
744
  } else {
741
745
  this.camera.target[0] += dx * right[0] + dy * up[0];
742
746
  this.camera.target[1] += dx * right[1] + dy * up[1];
@@ -756,15 +760,19 @@ const _OrbitControls = class _OrbitControls {
756
760
  this.lastX = e.clientX;
757
761
  this.lastY = e.clientY;
758
762
  if (e.buttons === 1) {
759
- this.theta -= deltaX * this.rotateSpeed;
760
- this.phi -= deltaY * this.rotateSpeed;
761
- this.phi = Math.max(this.minPhi, Math.min(this.maxPhi, this.phi));
762
- this.applySpherical();
763
+ if (this.enableDamping) {
764
+ this.deltaTheta += -deltaX * this.rotateSpeed * this.dampingFactor;
765
+ this.deltaPhi += -deltaY * this.rotateSpeed * this.dampingFactor;
766
+ } else {
767
+ this.theta -= deltaX * this.rotateSpeed;
768
+ this.phi -= deltaY * this.rotateSpeed;
769
+ this.phi = Math.max(this.minPhi, Math.min(this.maxPhi, this.phi));
770
+ }
763
771
  } else if (e.buttons === 2 || e.buttons === 4) {
764
772
  this.panByScreenDelta(deltaX, deltaY);
765
- if (!this.enableDamping) {
766
- this.applySpherical();
767
- }
773
+ }
774
+ if (!this.enableDamping) {
775
+ this.applySpherical();
768
776
  }
769
777
  }
770
778
  onMouseUp() {
@@ -777,13 +785,17 @@ const _OrbitControls = class _OrbitControls {
777
785
  if (e.deltaMode === 1) delta *= 40;
778
786
  else if (e.deltaMode === 2) delta *= 800;
779
787
  const normalizedDelta = Math.sign(delta) * Math.min(Math.abs(delta), 120);
780
- const factor = 1 + normalizedDelta * this.zoomSpeed;
781
- this.distance *= factor;
782
- this.distance = Math.max(
783
- this.minDistance,
784
- Math.min(this.maxDistance, this.distance)
785
- );
786
- this.applySpherical();
788
+ const zoomDelta = normalizedDelta * this.zoomSpeed;
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
+ }
787
799
  }
788
800
  onKeyDown(e) {
789
801
  var _a2;
@@ -909,20 +921,29 @@ const _OrbitControls = class _OrbitControls {
909
921
  const deltaY = e.touches[0].clientY - this.lastY;
910
922
  this.lastX = e.touches[0].clientX;
911
923
  this.lastY = e.touches[0].clientY;
912
- this.theta -= deltaX * this.rotateSpeed;
913
- this.phi -= deltaY * this.rotateSpeed;
914
- this.phi = Math.max(this.minPhi, Math.min(this.maxPhi, this.phi));
915
- this.applySpherical();
924
+ if (this.enableDamping) {
925
+ this.deltaTheta += -deltaX * this.rotateSpeed * this.dampingFactor;
926
+ this.deltaPhi += -deltaY * this.rotateSpeed * this.dampingFactor;
927
+ } else {
928
+ this.theta -= deltaX * this.rotateSpeed;
929
+ this.phi -= deltaY * this.rotateSpeed;
930
+ this.phi = Math.max(this.minPhi, Math.min(this.maxPhi, this.phi));
931
+ this.applySpherical();
932
+ }
916
933
  } else if (e.touches.length === 2) {
917
934
  const currentDistance = this.getTouchDistance(e.touches);
918
935
  const currentCenter = this.getTouchCenter(e.touches);
919
936
  if (this.lastTouchDistance > 0) {
920
937
  const ratio = currentDistance / this.lastTouchDistance;
921
- this.distance /= ratio;
922
- this.distance = Math.max(
923
- this.minDistance,
924
- Math.min(this.maxDistance, this.distance)
925
- );
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
+ }
926
947
  }
927
948
  const deltaX = currentCenter.x - this.lastTouchCenter.x;
928
949
  const deltaY = currentCenter.y - this.lastTouchCenter.y;
@@ -931,9 +952,10 @@ const _OrbitControls = class _OrbitControls {
931
952
  const dx = -deltaX * scale;
932
953
  const dy = deltaY * scale;
933
954
  if (this.enableDamping) {
934
- this.velocityPanX += dx * right[0] + dy * up[0];
935
- this.velocityPanY += dx * right[1] + dy * up[1];
936
- this.velocityPanZ += dx * right[2] + dy * up[2];
955
+ const d = this.dampingFactor;
956
+ this.deltaPanX += (dx * right[0] + dy * up[0]) * d;
957
+ this.deltaPanY += (dx * right[1] + dy * up[1]) * d;
958
+ this.deltaPanZ += (dx * right[2] + dy * up[2]) * d;
937
959
  } else {
938
960
  this.camera.target[0] += dx * right[0] + dy * up[0];
939
961
  this.camera.target[1] += dx * right[1] + dy * up[1];
@@ -941,7 +963,7 @@ const _OrbitControls = class _OrbitControls {
941
963
  }
942
964
  this.lastTouchDistance = currentDistance;
943
965
  this.lastTouchCenter = currentCenter;
944
- this.applySpherical();
966
+ if (!this.enableDamping) this.applySpherical();
945
967
  }
946
968
  }
947
969
  onTouchEnd(e) {
@@ -987,17 +1009,32 @@ const _OrbitControls = class _OrbitControls {
987
1009
  this.applyKeyboardMovement();
988
1010
  if (this.enableDamping) {
989
1011
  const EPS = 1e-6;
990
- const f = this.dampingFactor;
991
- this.camera.target[0] += this.velocityPanX * f;
992
- this.camera.target[1] += this.velocityPanY * f;
993
- this.camera.target[2] += this.velocityPanZ * f;
994
- const decay = 1 - f;
995
- this.velocityPanX *= decay;
996
- this.velocityPanY *= decay;
997
- this.velocityPanZ *= decay;
998
- if (Math.abs(this.velocityPanX) < EPS) this.velocityPanX = 0;
999
- if (Math.abs(this.velocityPanY) < EPS) this.velocityPanY = 0;
1000
- if (Math.abs(this.velocityPanZ) < EPS) this.velocityPanZ = 0;
1012
+ const decay = 1 - this.dampingFactor;
1013
+ this.theta += this.deltaTheta;
1014
+ this.phi += this.deltaPhi;
1015
+ this.phi = Math.max(this.minPhi, Math.min(this.maxPhi, this.phi));
1016
+ this.deltaTheta *= decay;
1017
+ this.deltaPhi *= decay;
1018
+ if (Math.abs(this.deltaTheta) < EPS) this.deltaTheta = 0;
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
+ }
1029
+ this.camera.target[0] += this.deltaPanX;
1030
+ this.camera.target[1] += this.deltaPanY;
1031
+ this.camera.target[2] += this.deltaPanZ;
1032
+ this.deltaPanX *= decay;
1033
+ this.deltaPanY *= decay;
1034
+ this.deltaPanZ *= decay;
1035
+ if (Math.abs(this.deltaPanX) < EPS) this.deltaPanX = 0;
1036
+ if (Math.abs(this.deltaPanY) < EPS) this.deltaPanY = 0;
1037
+ if (Math.abs(this.deltaPanZ) < EPS) this.deltaPanZ = 0;
1001
1038
  }
1002
1039
  this.applySpherical();
1003
1040
  }
@@ -1103,9 +1140,12 @@ const _OrbitControls = class _OrbitControls {
1103
1140
  requestAnimationFrame(animate);
1104
1141
  }
1105
1142
  clearVelocity() {
1106
- this.velocityPanX = 0;
1107
- this.velocityPanY = 0;
1108
- this.velocityPanZ = 0;
1143
+ this.deltaTheta = 0;
1144
+ this.deltaPhi = 0;
1145
+ this.deltaDistance = 0;
1146
+ this.deltaPanX = 0;
1147
+ this.deltaPanY = 0;
1148
+ this.deltaPanZ = 0;
1109
1149
  }
1110
1150
  };
1111
1151
  /** 移动键 */