@d5techs/3dgs-lib 1.4.43 → 1.4.45

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
@@ -624,7 +624,7 @@ const _OrbitControls = class _OrbitControls {
624
624
  __publicField(this, "minPhi", 0.01);
625
625
  __publicField(this, "maxPhi", Math.PI - 0.01);
626
626
  // 灵敏度
627
- __publicField(this, "rotateSpeed", 3e-3);
627
+ __publicField(this, "rotateSpeed", 5e-3);
628
628
  __publicField(this, "zoomSpeed", 1e-3);
629
629
  __publicField(this, "panSpeed", 5e-3);
630
630
  // 移动端触摸灵敏度
@@ -739,7 +739,7 @@ const _OrbitControls = class _OrbitControls {
739
739
  */
740
740
  panByScreenDelta(deltaX, deltaY) {
741
741
  const { right, up } = this.getCameraAxes();
742
- const scale = this.panSpeed * this.distance;
742
+ const scale = this.panSpeed * this.getEffectiveZoomDist();
743
743
  const dx = -deltaX * scale;
744
744
  const dy = deltaY * scale;
745
745
  if (this.enableDamping) {
@@ -766,12 +766,13 @@ const _OrbitControls = class _OrbitControls {
766
766
  this.lastX = e.clientX;
767
767
  this.lastY = e.clientY;
768
768
  if (e.buttons === 1) {
769
+ const rs = this.rotateSpeed * this.getRotateScale();
769
770
  if (this.enableDamping) {
770
- this.deltaTheta += -deltaX * this.rotateSpeed * this.dampingFactor;
771
- this.deltaPhi += -deltaY * this.rotateSpeed * this.dampingFactor;
771
+ this.deltaTheta += -deltaX * rs * this.dampingFactor;
772
+ this.deltaPhi += -deltaY * rs * this.dampingFactor;
772
773
  } else {
773
- this.theta -= deltaX * this.rotateSpeed;
774
- this.phi -= deltaY * this.rotateSpeed;
774
+ this.theta -= deltaX * rs;
775
+ this.phi -= deltaY * rs;
775
776
  this.phi = Math.max(this.minPhi, Math.min(this.maxPhi, this.phi));
776
777
  }
777
778
  } else if (e.buttons === 2 || e.buttons === 4) {
@@ -826,7 +827,7 @@ const _OrbitControls = class _OrbitControls {
826
827
  const m = this.camera.viewMatrix;
827
828
  const right = [m[0], m[4], m[8]];
828
829
  const forward = [-m[2], -m[6], -m[10]];
829
- const speed = this.moveSpeed * this.distance;
830
+ const speed = this.moveSpeed * this.getEffectiveZoomDist();
830
831
  let dx = 0, dy = 0, dz = 0;
831
832
  if (this.pressedKeys.has("w") || this.pressedKeys.has("arrowup")) {
832
833
  dx += forward[0] * speed;
@@ -931,12 +932,13 @@ const _OrbitControls = class _OrbitControls {
931
932
  const deltaY = e.touches[0].clientY - this.lastY;
932
933
  this.lastX = e.touches[0].clientX;
933
934
  this.lastY = e.touches[0].clientY;
935
+ const rs = this.rotateSpeed * this.getRotateScale();
934
936
  if (this.enableDamping) {
935
- this.deltaTheta += -deltaX * this.rotateSpeed * this.dampingFactor;
936
- this.deltaPhi += -deltaY * this.rotateSpeed * this.dampingFactor;
937
+ this.deltaTheta += -deltaX * rs * this.dampingFactor;
938
+ this.deltaPhi += -deltaY * rs * this.dampingFactor;
937
939
  } else {
938
- this.theta -= deltaX * this.rotateSpeed;
939
- this.phi -= deltaY * this.rotateSpeed;
940
+ this.theta -= deltaX * rs;
941
+ this.phi -= deltaY * rs;
940
942
  this.phi = Math.max(this.minPhi, Math.min(this.maxPhi, this.phi));
941
943
  this.applySpherical();
942
944
  }
@@ -960,7 +962,7 @@ const _OrbitControls = class _OrbitControls {
960
962
  const deltaX = currentCenter.x - this.lastTouchCenter.x;
961
963
  const deltaY = currentCenter.y - this.lastTouchCenter.y;
962
964
  const { right, up } = this.getCameraAxes();
963
- const scale = this.touchPanSpeed * this.distance;
965
+ const scale = this.touchPanSpeed * this.getEffectiveZoomDist();
964
966
  const dx = -deltaX * scale;
965
967
  const dy = deltaY * scale;
966
968
  if (this.enableDamping) {
@@ -1013,6 +1015,18 @@ const _OrbitControls = class _OrbitControls {
1013
1015
  this.camera.position[2] = this.camera.target[2] + this.distance * sinPhi * cosTheta;
1014
1016
  this.camera.updateMatrix();
1015
1017
  }
1018
+ /**
1019
+ * 旋转速度缩放:当 target 远离模型时降低旋转灵敏度,
1020
+ * 使模型在屏幕上的视觉运动速度保持一致。
1021
+ */
1022
+ getRotateScale() {
1023
+ if (this.zoomDistanceCap === Infinity || this.distance < 1e-6) return 1;
1024
+ const cp = this.camera.position;
1025
+ const mc = this._modelCenter;
1026
+ const dx = cp[0] - mc[0], dy = cp[1] - mc[1], dz = cp[2] - mc[2];
1027
+ const camToCenter = Math.sqrt(dx * dx + dy * dy + dz * dz);
1028
+ return Math.min(1, camToCenter / this.distance);
1029
+ }
1016
1030
  /**
1017
1031
  * 缩放有效距离:取 distance、相机到模型中心距离、zoomDistanceCap 三者最小值。
1018
1032
  * 保证缩放步长始终与相机到模型的真实接近程度匹配。