@d5techs/3dgs-lib 1.4.28 → 1.4.29

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