@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.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", 15e-4);
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,10 @@ 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
+ const d = this.dampingFactor;
743
+ this.deltaPanX += (dx * right[0] + dy * up[0]) * d;
744
+ this.deltaPanY += (dx * right[1] + dy * up[1]) * d;
745
+ this.deltaPanZ += (dx * right[2] + dy * up[2]) * d;
742
746
  } else {
743
747
  this.camera.target[0] += dx * right[0] + dy * up[0];
744
748
  this.camera.target[1] += dx * right[1] + dy * up[1];
@@ -758,15 +762,19 @@ const _OrbitControls = class _OrbitControls {
758
762
  this.lastX = e.clientX;
759
763
  this.lastY = e.clientY;
760
764
  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();
765
+ if (this.enableDamping) {
766
+ this.deltaTheta += -deltaX * this.rotateSpeed * this.dampingFactor;
767
+ this.deltaPhi += -deltaY * this.rotateSpeed * this.dampingFactor;
768
+ } else {
769
+ this.theta -= deltaX * this.rotateSpeed;
770
+ this.phi -= deltaY * this.rotateSpeed;
771
+ this.phi = Math.max(this.minPhi, Math.min(this.maxPhi, this.phi));
772
+ }
765
773
  } else if (e.buttons === 2 || e.buttons === 4) {
766
774
  this.panByScreenDelta(deltaX, deltaY);
767
- if (!this.enableDamping) {
768
- this.applySpherical();
769
- }
775
+ }
776
+ if (!this.enableDamping) {
777
+ this.applySpherical();
770
778
  }
771
779
  }
772
780
  onMouseUp() {
@@ -779,13 +787,17 @@ const _OrbitControls = class _OrbitControls {
779
787
  if (e.deltaMode === 1) delta *= 40;
780
788
  else if (e.deltaMode === 2) delta *= 800;
781
789
  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();
790
+ const zoomDelta = normalizedDelta * this.zoomSpeed;
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
+ }
789
801
  }
790
802
  onKeyDown(e) {
791
803
  var _a2;
@@ -911,20 +923,29 @@ const _OrbitControls = class _OrbitControls {
911
923
  const deltaY = e.touches[0].clientY - this.lastY;
912
924
  this.lastX = e.touches[0].clientX;
913
925
  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();
926
+ if (this.enableDamping) {
927
+ this.deltaTheta += -deltaX * this.rotateSpeed * this.dampingFactor;
928
+ this.deltaPhi += -deltaY * this.rotateSpeed * this.dampingFactor;
929
+ } else {
930
+ this.theta -= deltaX * this.rotateSpeed;
931
+ this.phi -= deltaY * this.rotateSpeed;
932
+ this.phi = Math.max(this.minPhi, Math.min(this.maxPhi, this.phi));
933
+ this.applySpherical();
934
+ }
918
935
  } else if (e.touches.length === 2) {
919
936
  const currentDistance = this.getTouchDistance(e.touches);
920
937
  const currentCenter = this.getTouchCenter(e.touches);
921
938
  if (this.lastTouchDistance > 0) {
922
939
  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
- );
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
+ }
928
949
  }
929
950
  const deltaX = currentCenter.x - this.lastTouchCenter.x;
930
951
  const deltaY = currentCenter.y - this.lastTouchCenter.y;
@@ -933,9 +954,10 @@ const _OrbitControls = class _OrbitControls {
933
954
  const dx = -deltaX * scale;
934
955
  const dy = deltaY * scale;
935
956
  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];
957
+ const d = this.dampingFactor;
958
+ this.deltaPanX += (dx * right[0] + dy * up[0]) * d;
959
+ this.deltaPanY += (dx * right[1] + dy * up[1]) * d;
960
+ this.deltaPanZ += (dx * right[2] + dy * up[2]) * d;
939
961
  } else {
940
962
  this.camera.target[0] += dx * right[0] + dy * up[0];
941
963
  this.camera.target[1] += dx * right[1] + dy * up[1];
@@ -943,7 +965,7 @@ const _OrbitControls = class _OrbitControls {
943
965
  }
944
966
  this.lastTouchDistance = currentDistance;
945
967
  this.lastTouchCenter = currentCenter;
946
- this.applySpherical();
968
+ if (!this.enableDamping) this.applySpherical();
947
969
  }
948
970
  }
949
971
  onTouchEnd(e) {
@@ -989,17 +1011,32 @@ const _OrbitControls = class _OrbitControls {
989
1011
  this.applyKeyboardMovement();
990
1012
  if (this.enableDamping) {
991
1013
  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;
1014
+ const decay = 1 - this.dampingFactor;
1015
+ this.theta += this.deltaTheta;
1016
+ this.phi += this.deltaPhi;
1017
+ this.phi = Math.max(this.minPhi, Math.min(this.maxPhi, this.phi));
1018
+ this.deltaTheta *= decay;
1019
+ this.deltaPhi *= decay;
1020
+ if (Math.abs(this.deltaTheta) < EPS) this.deltaTheta = 0;
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
+ }
1031
+ this.camera.target[0] += this.deltaPanX;
1032
+ this.camera.target[1] += this.deltaPanY;
1033
+ this.camera.target[2] += this.deltaPanZ;
1034
+ this.deltaPanX *= decay;
1035
+ this.deltaPanY *= decay;
1036
+ this.deltaPanZ *= decay;
1037
+ if (Math.abs(this.deltaPanX) < EPS) this.deltaPanX = 0;
1038
+ if (Math.abs(this.deltaPanY) < EPS) this.deltaPanY = 0;
1039
+ if (Math.abs(this.deltaPanZ) < EPS) this.deltaPanZ = 0;
1003
1040
  }
1004
1041
  this.applySpherical();
1005
1042
  }
@@ -1105,9 +1142,12 @@ const _OrbitControls = class _OrbitControls {
1105
1142
  requestAnimationFrame(animate);
1106
1143
  }
1107
1144
  clearVelocity() {
1108
- this.velocityPanX = 0;
1109
- this.velocityPanY = 0;
1110
- this.velocityPanZ = 0;
1145
+ this.deltaTheta = 0;
1146
+ this.deltaPhi = 0;
1147
+ this.deltaDistance = 0;
1148
+ this.deltaPanX = 0;
1149
+ this.deltaPanY = 0;
1150
+ this.deltaPanZ = 0;
1111
1151
  }
1112
1152
  };
1113
1153
  /** 移动键 */