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