@d5techs/3dgs-lib 1.4.37 → 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 +18 -5
- package/dist/3dgs-lib.cjs.map +1 -1
- package/dist/3dgs-lib.js +18 -5
- package/dist/3dgs-lib.js.map +1 -1
- package/dist/core/OrbitControls.d.ts +6 -0
- package/package.json +1 -1
package/dist/3dgs-lib.cjs
CHANGED
|
@@ -630,9 +630,10 @@ const _OrbitControls = class _OrbitControls {
|
|
|
630
630
|
// 移动端触摸灵敏度
|
|
631
631
|
__publicField(this, "touchZoomSpeed", 0.01);
|
|
632
632
|
__publicField(this, "touchPanSpeed", 3e-3);
|
|
633
|
-
//
|
|
634
|
-
//
|
|
633
|
+
// 缩放步长上限:取 min(distance, cameraToCenterDist, zoomDistanceCap),
|
|
634
|
+
// 使缩放速度始终与相机到模型的真实距离匹配,而非 target 位置。
|
|
635
635
|
__publicField(this, "zoomDistanceCap", Infinity);
|
|
636
|
+
__publicField(this, "_modelCenter", [0, 0, 0]);
|
|
636
637
|
// 阻尼:每帧应用全量 delta,然后 delta *= (1 - dampingFactor) 实现惯性
|
|
637
638
|
__publicField(this, "enableDamping", true);
|
|
638
639
|
__publicField(this, "dampingFactor", 0.1);
|
|
@@ -797,7 +798,7 @@ const _OrbitControls = class _OrbitControls {
|
|
|
797
798
|
this.deltaDistance = Math.sign(this.deltaDistance) * Math.min(Math.abs(this.deltaDistance), maxAccum);
|
|
798
799
|
} else {
|
|
799
800
|
const factor = Math.exp(zoomDelta);
|
|
800
|
-
const effectiveDist =
|
|
801
|
+
const effectiveDist = this.getEffectiveZoomDist();
|
|
801
802
|
this.distance -= effectiveDist * (1 - factor);
|
|
802
803
|
this.distance = Math.max(
|
|
803
804
|
this.minDistance,
|
|
@@ -948,7 +949,7 @@ const _OrbitControls = class _OrbitControls {
|
|
|
948
949
|
this.deltaDistance += -Math.log(ratio) * this.dampingFactor;
|
|
949
950
|
} else {
|
|
950
951
|
const factor = 1 / ratio;
|
|
951
|
-
const effectiveDist =
|
|
952
|
+
const effectiveDist = this.getEffectiveZoomDist();
|
|
952
953
|
this.distance -= effectiveDist * (1 - factor);
|
|
953
954
|
this.distance = Math.max(
|
|
954
955
|
this.minDistance,
|
|
@@ -1012,6 +1013,17 @@ const _OrbitControls = class _OrbitControls {
|
|
|
1012
1013
|
this.camera.position[2] = this.camera.target[2] + this.distance * sinPhi * cosTheta;
|
|
1013
1014
|
this.camera.updateMatrix();
|
|
1014
1015
|
}
|
|
1016
|
+
/**
|
|
1017
|
+
* 缩放有效距离:取 distance、相机到模型中心距离、zoomDistanceCap 三者最小值。
|
|
1018
|
+
* 保证缩放步长始终与相机到模型的真实接近程度匹配。
|
|
1019
|
+
*/
|
|
1020
|
+
getEffectiveZoomDist() {
|
|
1021
|
+
const cp = this.camera.position;
|
|
1022
|
+
const mc = this._modelCenter;
|
|
1023
|
+
const dx = cp[0] - mc[0], dy = cp[1] - mc[1], dz = cp[2] - mc[2];
|
|
1024
|
+
const camToCenter = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
1025
|
+
return Math.min(this.distance, camToCenter, this.zoomDistanceCap);
|
|
1026
|
+
}
|
|
1015
1027
|
/**
|
|
1016
1028
|
* 每帧调用:应用阻尼衰减并更新相机
|
|
1017
1029
|
* 在渲染循环中调用此方法以获得平滑惯性效果
|
|
@@ -1030,7 +1042,7 @@ const _OrbitControls = class _OrbitControls {
|
|
|
1030
1042
|
if (Math.abs(this.deltaPhi) < EPS) this.deltaPhi = 0;
|
|
1031
1043
|
if (Math.abs(this.deltaDistance) > EPS) {
|
|
1032
1044
|
const factor = Math.exp(this.deltaDistance);
|
|
1033
|
-
const effectiveDist =
|
|
1045
|
+
const effectiveDist = this.getEffectiveZoomDist();
|
|
1034
1046
|
this.distance -= effectiveDist * (1 - factor);
|
|
1035
1047
|
this.distance = Math.max(
|
|
1036
1048
|
this.minDistance,
|
|
@@ -1132,6 +1144,7 @@ const _OrbitControls = class _OrbitControls {
|
|
|
1132
1144
|
frameModel(center, radius, animate = true) {
|
|
1133
1145
|
this.clearVelocity();
|
|
1134
1146
|
this.zoomDistanceCap = radius;
|
|
1147
|
+
this._modelCenter = [center[0], center[1], center[2]];
|
|
1135
1148
|
const fovRad = this.camera.fov;
|
|
1136
1149
|
const halfFov = fovRad / 2;
|
|
1137
1150
|
const marginFactor = 1.5;
|