@d5techs/3dgs-lib 1.4.27 → 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
@@ -630,20 +630,20 @@ const _OrbitControls = class _OrbitControls {
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, "velocityTheta", 0);
642
- __publicField(this, "velocityPhi", 0);
643
- __publicField(this, "velocityDistance", 0);
644
- __publicField(this, "velocityPanX", 0);
645
- __publicField(this, "velocityPanY", 0);
646
- __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);
647
647
  // 键盘移动
648
648
  __publicField(this, "moveSpeed", 0.015);
649
649
  __publicField(this, "pressedKeys", /* @__PURE__ */ new Set());
@@ -739,9 +739,9 @@ const _OrbitControls = class _OrbitControls {
739
739
  const dx = -deltaX * scale;
740
740
  const dy = deltaY * scale;
741
741
  if (this.enableDamping) {
742
- this.velocityPanX += dx * right[0] + dy * up[0];
743
- this.velocityPanY += dx * right[1] + dy * up[1];
744
- 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];
745
745
  } else {
746
746
  this.camera.target[0] += dx * right[0] + dy * up[0];
747
747
  this.camera.target[1] += dx * right[1] + dy * up[1];
@@ -762,11 +762,8 @@ const _OrbitControls = class _OrbitControls {
762
762
  this.lastY = e.clientY;
763
763
  if (e.buttons === 1) {
764
764
  if (this.enableDamping) {
765
- this.velocityTheta += -deltaX * this.rotateSpeed;
766
- this.velocityPhi += -deltaY * this.rotateSpeed;
767
- const maxRotVel = 0.5;
768
- this.velocityTheta = Math.max(-maxRotVel, Math.min(maxRotVel, this.velocityTheta));
769
- this.velocityPhi = Math.max(-maxRotVel, Math.min(maxRotVel, this.velocityPhi));
765
+ this.deltaTheta += -deltaX * this.rotateSpeed;
766
+ this.deltaPhi += -deltaY * this.rotateSpeed;
770
767
  } else {
771
768
  this.theta -= deltaX * this.rotateSpeed;
772
769
  this.phi -= deltaY * this.rotateSpeed;
@@ -788,12 +785,10 @@ const _OrbitControls = class _OrbitControls {
788
785
  let delta = e.deltaY;
789
786
  if (e.deltaMode === 1) delta *= 40;
790
787
  else if (e.deltaMode === 2) delta *= 800;
791
- const normalizedDelta = Math.sign(delta) * Math.min(Math.abs(delta), 150);
788
+ const normalizedDelta = Math.sign(delta) * Math.min(Math.abs(delta), 120);
792
789
  const zoomDelta = normalizedDelta * this.zoomSpeed;
793
790
  if (this.enableDamping) {
794
- this.velocityDistance += zoomDelta;
795
- const maxVelocity = 2;
796
- this.velocityDistance = Math.max(-maxVelocity, Math.min(maxVelocity, this.velocityDistance));
791
+ this.deltaDistance += zoomDelta;
797
792
  } else {
798
793
  this.distance *= Math.exp(zoomDelta);
799
794
  this.distance = Math.max(
@@ -928,8 +923,8 @@ const _OrbitControls = class _OrbitControls {
928
923
  this.lastX = e.touches[0].clientX;
929
924
  this.lastY = e.touches[0].clientY;
930
925
  if (this.enableDamping) {
931
- this.velocityTheta += -deltaX * this.rotateSpeed;
932
- this.velocityPhi += -deltaY * this.rotateSpeed;
926
+ this.deltaTheta += -deltaX * this.rotateSpeed;
927
+ this.deltaPhi += -deltaY * this.rotateSpeed;
933
928
  } else {
934
929
  this.theta -= deltaX * this.rotateSpeed;
935
930
  this.phi -= deltaY * this.rotateSpeed;
@@ -941,11 +936,10 @@ const _OrbitControls = class _OrbitControls {
941
936
  const currentCenter = this.getTouchCenter(e.touches);
942
937
  if (this.lastTouchDistance > 0) {
943
938
  const ratio = currentDistance / this.lastTouchDistance;
944
- const zoomDelta = -Math.log(ratio) / (this.touchZoomSpeed * 100);
945
939
  if (this.enableDamping) {
946
- this.velocityDistance += zoomDelta;
940
+ this.deltaDistance += -Math.log(ratio);
947
941
  } else {
948
- this.distance *= Math.exp(zoomDelta);
942
+ this.distance /= ratio;
949
943
  this.distance = Math.max(
950
944
  this.minDistance,
951
945
  Math.min(this.maxDistance, this.distance)
@@ -959,9 +953,9 @@ const _OrbitControls = class _OrbitControls {
959
953
  const dx = -deltaX * scale;
960
954
  const dy = deltaY * scale;
961
955
  if (this.enableDamping) {
962
- this.velocityPanX += dx * right[0] + dy * up[0];
963
- this.velocityPanY += dx * right[1] + dy * up[1];
964
- 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];
965
959
  } else {
966
960
  this.camera.target[0] += dx * right[0] + dy * up[0];
967
961
  this.camera.target[1] += dx * right[1] + dy * up[1];
@@ -969,9 +963,7 @@ const _OrbitControls = class _OrbitControls {
969
963
  }
970
964
  this.lastTouchDistance = currentDistance;
971
965
  this.lastTouchCenter = currentCenter;
972
- if (!this.enableDamping) {
973
- this.applySpherical();
974
- }
966
+ if (!this.enableDamping) this.applySpherical();
975
967
  }
976
968
  }
977
969
  onTouchEnd(e) {
@@ -1017,31 +1009,32 @@ const _OrbitControls = class _OrbitControls {
1017
1009
  this.applyKeyboardMovement();
1018
1010
  if (this.enableDamping) {
1019
1011
  const EPS = 1e-6;
1020
- const f = this.dampingFactor;
1021
- this.theta += this.velocityTheta * f;
1022
- this.phi += this.velocityPhi * f;
1012
+ const decay = 1 - this.dampingFactor;
1013
+ this.theta += this.deltaTheta;
1014
+ this.phi += this.deltaPhi;
1023
1015
  this.phi = Math.max(this.minPhi, Math.min(this.maxPhi, this.phi));
1024
- this.distance *= Math.exp(this.velocityDistance * f);
1025
- this.distance = Math.max(
1026
- this.minDistance,
1027
- Math.min(this.maxDistance, this.distance)
1028
- );
1029
- this.camera.target[0] += this.velocityPanX * f;
1030
- this.camera.target[1] += this.velocityPanY * f;
1031
- this.camera.target[2] += this.velocityPanZ * f;
1032
- const decay = 1 - f;
1033
- this.velocityTheta *= decay;
1034
- this.velocityPhi *= decay;
1035
- this.velocityDistance *= decay;
1036
- this.velocityPanX *= decay;
1037
- this.velocityPanY *= decay;
1038
- this.velocityPanZ *= decay;
1039
- if (Math.abs(this.velocityTheta) < EPS) this.velocityTheta = 0;
1040
- if (Math.abs(this.velocityPhi) < EPS) this.velocityPhi = 0;
1041
- if (Math.abs(this.velocityDistance) < EPS) this.velocityDistance = 0;
1042
- if (Math.abs(this.velocityPanX) < EPS) this.velocityPanX = 0;
1043
- if (Math.abs(this.velocityPanY) < EPS) this.velocityPanY = 0;
1044
- if (Math.abs(this.velocityPanZ) < EPS) this.velocityPanZ = 0;
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;
1045
1038
  }
1046
1039
  this.applySpherical();
1047
1040
  }
@@ -1147,12 +1140,12 @@ const _OrbitControls = class _OrbitControls {
1147
1140
  requestAnimationFrame(animate);
1148
1141
  }
1149
1142
  clearVelocity() {
1150
- this.velocityTheta = 0;
1151
- this.velocityPhi = 0;
1152
- this.velocityDistance = 0;
1153
- this.velocityPanX = 0;
1154
- this.velocityPanY = 0;
1155
- 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;
1156
1149
  }
1157
1150
  };
1158
1151
  /** 移动键 */