@d5techs/3dgs-lib 1.4.36 → 1.4.38
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 +26 -3
- package/dist/3dgs-lib.cjs.map +1 -1
- package/dist/3dgs-lib.js +26 -3
- package/dist/3dgs-lib.js.map +1 -1
- package/dist/core/OrbitControls.d.ts +7 -0
- package/package.json +1 -1
package/dist/3dgs-lib.js
CHANGED
|
@@ -628,6 +628,10 @@ const _OrbitControls = class _OrbitControls {
|
|
|
628
628
|
// 移动端触摸灵敏度
|
|
629
629
|
__publicField(this, "touchZoomSpeed", 0.01);
|
|
630
630
|
__publicField(this, "touchPanSpeed", 3e-3);
|
|
631
|
+
// 缩放步长上限:取 min(distance, cameraToCenterDist, zoomDistanceCap),
|
|
632
|
+
// 使缩放速度始终与相机到模型的真实距离匹配,而非 target 位置。
|
|
633
|
+
__publicField(this, "zoomDistanceCap", Infinity);
|
|
634
|
+
__publicField(this, "_modelCenter", [0, 0, 0]);
|
|
631
635
|
// 阻尼:每帧应用全量 delta,然后 delta *= (1 - dampingFactor) 实现惯性
|
|
632
636
|
__publicField(this, "enableDamping", true);
|
|
633
637
|
__publicField(this, "dampingFactor", 0.1);
|
|
@@ -791,7 +795,9 @@ const _OrbitControls = class _OrbitControls {
|
|
|
791
795
|
const maxAccum = 120 * this.zoomSpeed * this.dampingFactor * 3;
|
|
792
796
|
this.deltaDistance = Math.sign(this.deltaDistance) * Math.min(Math.abs(this.deltaDistance), maxAccum);
|
|
793
797
|
} else {
|
|
794
|
-
|
|
798
|
+
const factor = Math.exp(zoomDelta);
|
|
799
|
+
const effectiveDist = this.getEffectiveZoomDist();
|
|
800
|
+
this.distance -= effectiveDist * (1 - factor);
|
|
795
801
|
this.distance = Math.max(
|
|
796
802
|
this.minDistance,
|
|
797
803
|
Math.min(this.maxDistance, this.distance)
|
|
@@ -940,7 +946,9 @@ const _OrbitControls = class _OrbitControls {
|
|
|
940
946
|
if (this.enableDamping) {
|
|
941
947
|
this.deltaDistance += -Math.log(ratio) * this.dampingFactor;
|
|
942
948
|
} else {
|
|
943
|
-
|
|
949
|
+
const factor = 1 / ratio;
|
|
950
|
+
const effectiveDist = this.getEffectiveZoomDist();
|
|
951
|
+
this.distance -= effectiveDist * (1 - factor);
|
|
944
952
|
this.distance = Math.max(
|
|
945
953
|
this.minDistance,
|
|
946
954
|
Math.min(this.maxDistance, this.distance)
|
|
@@ -1003,6 +1011,17 @@ const _OrbitControls = class _OrbitControls {
|
|
|
1003
1011
|
this.camera.position[2] = this.camera.target[2] + this.distance * sinPhi * cosTheta;
|
|
1004
1012
|
this.camera.updateMatrix();
|
|
1005
1013
|
}
|
|
1014
|
+
/**
|
|
1015
|
+
* 缩放有效距离:取 distance、相机到模型中心距离、zoomDistanceCap 三者最小值。
|
|
1016
|
+
* 保证缩放步长始终与相机到模型的真实接近程度匹配。
|
|
1017
|
+
*/
|
|
1018
|
+
getEffectiveZoomDist() {
|
|
1019
|
+
const cp = this.camera.position;
|
|
1020
|
+
const mc = this._modelCenter;
|
|
1021
|
+
const dx = cp[0] - mc[0], dy = cp[1] - mc[1], dz = cp[2] - mc[2];
|
|
1022
|
+
const camToCenter = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
1023
|
+
return Math.min(this.distance, camToCenter, this.zoomDistanceCap);
|
|
1024
|
+
}
|
|
1006
1025
|
/**
|
|
1007
1026
|
* 每帧调用:应用阻尼衰减并更新相机
|
|
1008
1027
|
* 在渲染循环中调用此方法以获得平滑惯性效果
|
|
@@ -1020,7 +1039,9 @@ const _OrbitControls = class _OrbitControls {
|
|
|
1020
1039
|
if (Math.abs(this.deltaTheta) < EPS) this.deltaTheta = 0;
|
|
1021
1040
|
if (Math.abs(this.deltaPhi) < EPS) this.deltaPhi = 0;
|
|
1022
1041
|
if (Math.abs(this.deltaDistance) > EPS) {
|
|
1023
|
-
|
|
1042
|
+
const factor = Math.exp(this.deltaDistance);
|
|
1043
|
+
const effectiveDist = this.getEffectiveZoomDist();
|
|
1044
|
+
this.distance -= effectiveDist * (1 - factor);
|
|
1024
1045
|
this.distance = Math.max(
|
|
1025
1046
|
this.minDistance,
|
|
1026
1047
|
Math.min(this.maxDistance, this.distance)
|
|
@@ -1120,6 +1141,8 @@ const _OrbitControls = class _OrbitControls {
|
|
|
1120
1141
|
}
|
|
1121
1142
|
frameModel(center, radius, animate = true) {
|
|
1122
1143
|
this.clearVelocity();
|
|
1144
|
+
this.zoomDistanceCap = radius;
|
|
1145
|
+
this._modelCenter = [center[0], center[1], center[2]];
|
|
1123
1146
|
const fovRad = this.camera.fov;
|
|
1124
1147
|
const halfFov = fovRad / 2;
|
|
1125
1148
|
const marginFactor = 1.5;
|