@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.cjs +89 -51
- package/dist/3dgs-lib.cjs.map +1 -1
- package/dist/3dgs-lib.js +89 -51
- package/dist/3dgs-lib.js.map +1 -1
- package/dist/core/OrbitControls.d.ts +6 -3
- package/package.json +1 -1
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",
|
|
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
|
-
//
|
|
631
|
+
// 阻尼:每帧应用全量 delta,然后 delta *= (1 - dampingFactor) 实现惯性
|
|
632
632
|
__publicField(this, "enableDamping", true);
|
|
633
|
-
__publicField(this, "dampingFactor", 0.
|
|
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, "
|
|
640
|
-
__publicField(this, "
|
|
641
|
-
__publicField(this, "
|
|
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.
|
|
738
|
-
this.
|
|
739
|
-
this.
|
|
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.
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
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
|
-
|
|
766
|
-
|
|
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
|
|
781
|
-
this.
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
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.
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
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.
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
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.
|
|
935
|
-
this.
|
|
936
|
-
this.
|
|
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
|
|
991
|
-
this.
|
|
992
|
-
this.
|
|
993
|
-
this.
|
|
994
|
-
|
|
995
|
-
this.
|
|
996
|
-
this.
|
|
997
|
-
this.
|
|
998
|
-
if (Math.abs(this.
|
|
999
|
-
|
|
1000
|
-
|
|
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.
|
|
1107
|
-
this.
|
|
1108
|
-
this.
|
|
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
|
/** 移动键 */
|