@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.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", 1e-3);
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,9 @@ 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
+ this.deltaPanX += dx * right[0] + dy * up[0];
741
+ this.deltaPanY += dx * right[1] + dy * up[1];
742
+ this.deltaPanZ += dx * right[2] + dy * up[2];
740
743
  } else {
741
744
  this.camera.target[0] += dx * right[0] + dy * up[0];
742
745
  this.camera.target[1] += dx * right[1] + dy * up[1];
@@ -756,15 +759,19 @@ const _OrbitControls = class _OrbitControls {
756
759
  this.lastX = e.clientX;
757
760
  this.lastY = e.clientY;
758
761
  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();
762
+ if (this.enableDamping) {
763
+ this.deltaTheta += -deltaX * this.rotateSpeed;
764
+ this.deltaPhi += -deltaY * this.rotateSpeed;
765
+ } else {
766
+ this.theta -= deltaX * this.rotateSpeed;
767
+ this.phi -= deltaY * this.rotateSpeed;
768
+ this.phi = Math.max(this.minPhi, Math.min(this.maxPhi, this.phi));
769
+ }
763
770
  } else if (e.buttons === 2 || e.buttons === 4) {
764
771
  this.panByScreenDelta(deltaX, deltaY);
765
- if (!this.enableDamping) {
766
- this.applySpherical();
767
- }
772
+ }
773
+ if (!this.enableDamping) {
774
+ this.applySpherical();
768
775
  }
769
776
  }
770
777
  onMouseUp() {
@@ -777,13 +784,17 @@ const _OrbitControls = class _OrbitControls {
777
784
  if (e.deltaMode === 1) delta *= 40;
778
785
  else if (e.deltaMode === 2) delta *= 800;
779
786
  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();
787
+ const zoomDelta = normalizedDelta * this.zoomSpeed;
788
+ if (this.enableDamping) {
789
+ this.deltaDistance += zoomDelta;
790
+ } else {
791
+ this.distance *= Math.exp(zoomDelta);
792
+ this.distance = Math.max(
793
+ this.minDistance,
794
+ Math.min(this.maxDistance, this.distance)
795
+ );
796
+ this.applySpherical();
797
+ }
787
798
  }
788
799
  onKeyDown(e) {
789
800
  var _a2;
@@ -909,20 +920,29 @@ const _OrbitControls = class _OrbitControls {
909
920
  const deltaY = e.touches[0].clientY - this.lastY;
910
921
  this.lastX = e.touches[0].clientX;
911
922
  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();
923
+ if (this.enableDamping) {
924
+ this.deltaTheta += -deltaX * this.rotateSpeed;
925
+ this.deltaPhi += -deltaY * this.rotateSpeed;
926
+ } else {
927
+ this.theta -= deltaX * this.rotateSpeed;
928
+ this.phi -= deltaY * this.rotateSpeed;
929
+ this.phi = Math.max(this.minPhi, Math.min(this.maxPhi, this.phi));
930
+ this.applySpherical();
931
+ }
916
932
  } else if (e.touches.length === 2) {
917
933
  const currentDistance = this.getTouchDistance(e.touches);
918
934
  const currentCenter = this.getTouchCenter(e.touches);
919
935
  if (this.lastTouchDistance > 0) {
920
936
  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
- );
937
+ if (this.enableDamping) {
938
+ this.deltaDistance += -Math.log(ratio);
939
+ } else {
940
+ this.distance /= ratio;
941
+ this.distance = Math.max(
942
+ this.minDistance,
943
+ Math.min(this.maxDistance, this.distance)
944
+ );
945
+ }
926
946
  }
927
947
  const deltaX = currentCenter.x - this.lastTouchCenter.x;
928
948
  const deltaY = currentCenter.y - this.lastTouchCenter.y;
@@ -931,9 +951,9 @@ const _OrbitControls = class _OrbitControls {
931
951
  const dx = -deltaX * scale;
932
952
  const dy = deltaY * scale;
933
953
  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];
954
+ this.deltaPanX += dx * right[0] + dy * up[0];
955
+ this.deltaPanY += dx * right[1] + dy * up[1];
956
+ this.deltaPanZ += dx * right[2] + dy * up[2];
937
957
  } else {
938
958
  this.camera.target[0] += dx * right[0] + dy * up[0];
939
959
  this.camera.target[1] += dx * right[1] + dy * up[1];
@@ -941,7 +961,7 @@ const _OrbitControls = class _OrbitControls {
941
961
  }
942
962
  this.lastTouchDistance = currentDistance;
943
963
  this.lastTouchCenter = currentCenter;
944
- this.applySpherical();
964
+ if (!this.enableDamping) this.applySpherical();
945
965
  }
946
966
  }
947
967
  onTouchEnd(e) {
@@ -987,17 +1007,32 @@ const _OrbitControls = class _OrbitControls {
987
1007
  this.applyKeyboardMovement();
988
1008
  if (this.enableDamping) {
989
1009
  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;
1010
+ const decay = 1 - this.dampingFactor;
1011
+ this.theta += this.deltaTheta;
1012
+ this.phi += this.deltaPhi;
1013
+ this.phi = Math.max(this.minPhi, Math.min(this.maxPhi, this.phi));
1014
+ this.deltaTheta *= decay;
1015
+ this.deltaPhi *= decay;
1016
+ if (Math.abs(this.deltaTheta) < EPS) this.deltaTheta = 0;
1017
+ if (Math.abs(this.deltaPhi) < EPS) this.deltaPhi = 0;
1018
+ if (Math.abs(this.deltaDistance) > EPS) {
1019
+ this.distance *= Math.exp(this.deltaDistance);
1020
+ this.distance = Math.max(
1021
+ this.minDistance,
1022
+ Math.min(this.maxDistance, this.distance)
1023
+ );
1024
+ this.deltaDistance *= decay;
1025
+ if (Math.abs(this.deltaDistance) < EPS) this.deltaDistance = 0;
1026
+ }
1027
+ this.camera.target[0] += this.deltaPanX;
1028
+ this.camera.target[1] += this.deltaPanY;
1029
+ this.camera.target[2] += this.deltaPanZ;
1030
+ this.deltaPanX *= decay;
1031
+ this.deltaPanY *= decay;
1032
+ this.deltaPanZ *= decay;
1033
+ if (Math.abs(this.deltaPanX) < EPS) this.deltaPanX = 0;
1034
+ if (Math.abs(this.deltaPanY) < EPS) this.deltaPanY = 0;
1035
+ if (Math.abs(this.deltaPanZ) < EPS) this.deltaPanZ = 0;
1001
1036
  }
1002
1037
  this.applySpherical();
1003
1038
  }
@@ -1103,9 +1138,12 @@ const _OrbitControls = class _OrbitControls {
1103
1138
  requestAnimationFrame(animate);
1104
1139
  }
1105
1140
  clearVelocity() {
1106
- this.velocityPanX = 0;
1107
- this.velocityPanY = 0;
1108
- this.velocityPanZ = 0;
1141
+ this.deltaTheta = 0;
1142
+ this.deltaPhi = 0;
1143
+ this.deltaDistance = 0;
1144
+ this.deltaPanX = 0;
1145
+ this.deltaPanY = 0;
1146
+ this.deltaPanZ = 0;
1109
1147
  }
1110
1148
  };
1111
1149
  /** 移动键 */