@ridp/threejs 1.5.0 → 1.5.2
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/{PredictiveLoader-C9zJlZEQ.js → PredictiveLoader-Ce8DXwbW.js} +1332 -1237
- package/dist/PredictiveLoader-c5o_CMyI.cjs +2 -0
- package/dist/assets/{gltfParser.worker-D2lwod50.js → gltfParser.worker-BJvxfZUb.js} +2 -2
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.js +2 -2
- package/dist/{modelOptimizer-D6fRg-DF.js → modelOptimizer-B7zPcU53.js} +55 -51
- package/dist/{modelOptimizer-A0Cs6f9e.cjs → modelOptimizer-_7Yr0hPn.cjs} +2 -1
- package/dist/objectQuery-BcL0iGx1.js +1473 -0
- package/dist/objectQuery-DFqBNl0a.cjs +24 -0
- package/dist/threejs.cjs +2 -2
- package/dist/threejs.js +162 -119
- package/dist/{useBatchGLTFLoader-C1C8R5Ss.js → useBatchGLTFLoader-BtuzDyHn.js} +187 -168
- package/dist/useBatchGLTFLoader-wNkKD723.cjs +5 -0
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +40 -31
- package/package.json +1 -1
- package/{README.md → readme.md} +9 -277
- package/dist/PredictiveLoader-Xy5S4HBr.cjs +0 -2
- package/dist/objectQuery-BfHUGPET.js +0 -1453
- package/dist/objectQuery-DNtwsgY8.cjs +0 -24
- package/dist/useBatchGLTFLoader-DHJyQcpJ.cjs +0 -5
package/dist/threejs.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var
|
|
2
|
-
var P = (
|
|
3
|
-
var
|
|
4
|
-
import { i as oe, o as ie, c as ne, b as re, a as ae, u as le } from "./useBatchGLTFLoader-
|
|
5
|
-
import { d as j, S as V,
|
|
6
|
-
import { C as he, E as de, I as me, M as fe, P as
|
|
7
|
-
import { I as
|
|
8
|
-
import { ModelOptimizer as
|
|
9
|
-
import { MathUtils as F, Scene as Y, PerspectiveCamera as B, WebGLRenderer as Z, Box3 as
|
|
10
|
-
const
|
|
1
|
+
var H = Object.defineProperty;
|
|
2
|
+
var P = (x, e, t) => e in x ? H(x, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : x[e] = t;
|
|
3
|
+
var o = (x, e, t) => P(x, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { i as oe, o as ie, c as ne, b as re, a as ae, u as le } from "./useBatchGLTFLoader-BtuzDyHn.js";
|
|
5
|
+
import { d as j, S as V, y as q, j as X } from "./PredictiveLoader-Ce8DXwbW.js";
|
|
6
|
+
import { C as he, E as de, I as me, M as fe, P as ue, x as pe, R as xe, t as ge, q as Fe, n as Re, h as we, g as be, b as ze, c as Me, a as Te, e as Ee, f as Le, i as Oe, l as Ce, m as ye, r as ve, p as Ie, o as Se, k as De, s as Ae, v as He, w as Pe, u as je } from "./PredictiveLoader-Ce8DXwbW.js";
|
|
7
|
+
import { I as qe, b as Xe, c as Ye, a as Be, g as Ze, d as Ge, e as We, i as _e, p as Ne, r as ke, t as Ue } from "./objectQuery-BcL0iGx1.js";
|
|
8
|
+
import { ModelOptimizer as Je, modelOptimizer as Ke } from "./modelOptimizer-B7zPcU53.js";
|
|
9
|
+
import { MathUtils as F, Scene as Y, PerspectiveCamera as B, WebGLRenderer as Z, Box3 as G, Vector3 as l, Box3Helper as W } from "three";
|
|
10
|
+
const _ = "1.5.2", N = 50, k = 20, U = 20, v = {
|
|
11
11
|
TOP: "top",
|
|
12
12
|
// 俯视(从上往下)
|
|
13
13
|
RIGHT: "right",
|
|
@@ -39,21 +39,21 @@ class J {
|
|
|
39
39
|
* @param {Object} [option.control.options={}] - 控制器选项
|
|
40
40
|
*/
|
|
41
41
|
constructor(e, t) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
42
|
+
o(this, "isReady", !1);
|
|
43
|
+
o(this, "scene", null);
|
|
44
|
+
o(this, "camera", null);
|
|
45
|
+
o(this, "renderer", null);
|
|
46
|
+
o(this, "control", null);
|
|
47
|
+
o(this, "css3dRenderer", null);
|
|
48
|
+
o(this, "el", null);
|
|
49
|
+
o(this, "renderRequested", !1);
|
|
50
|
+
o(this, "selector", null);
|
|
51
|
+
o(this, "eventsListener", {});
|
|
52
|
+
o(this, "stats", null);
|
|
53
|
+
o(this, "isDispose", !1);
|
|
54
|
+
o(this, "version", "0.0.0");
|
|
55
|
+
o(this, "boxHelper", null);
|
|
56
|
+
o(this, "initOpt", {
|
|
57
57
|
css3d: !1,
|
|
58
58
|
stats: !1,
|
|
59
59
|
renderType: "change",
|
|
@@ -70,20 +70,20 @@ class J {
|
|
|
70
70
|
* 初始化场景
|
|
71
71
|
* @param {string} selector - DOM 容器选择器
|
|
72
72
|
*/
|
|
73
|
-
|
|
73
|
+
o(this, "setup", (e) => {
|
|
74
74
|
if (this.isDispose = !1, this.selector = e, this.el = document.querySelector(e), !this.el) {
|
|
75
75
|
console.error(`ThreeIns: 找不到元素 ${e}`);
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
|
-
const [t,
|
|
79
|
-
if (this.updateCameraFOV(t,
|
|
78
|
+
const [t, r] = this.getTargetSize();
|
|
79
|
+
if (this.updateCameraFOV(t, r), this.camera.position.set(0, 0, 0), this.camera.lookAt(0, 0, 0), this.camera.updateProjectionMatrix(), this.renderer.setPixelRatio(window.devicePixelRatio), this.renderer.setSize(t, r), this.el.appendChild(this.renderer.domElement), this.initOpt.control && this.initOpt.control.init) {
|
|
80
80
|
this.control = j(this.camera, this.renderer.domElement);
|
|
81
81
|
const s = Object.assign(
|
|
82
82
|
$,
|
|
83
83
|
this.initOpt.control.options || {}
|
|
84
84
|
);
|
|
85
|
-
Object.keys(s).forEach((
|
|
86
|
-
this.control[
|
|
85
|
+
Object.keys(s).forEach((f) => {
|
|
86
|
+
this.control[f] = s[f];
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
setTimeout(() => {
|
|
@@ -97,14 +97,14 @@ class J {
|
|
|
97
97
|
* WebGL 上下文丢失处理
|
|
98
98
|
* @param {Event} e - 事件对象
|
|
99
99
|
*/
|
|
100
|
-
|
|
100
|
+
o(this, "onContextLost", (e) => {
|
|
101
101
|
e.preventDefault(), this.animationFrameId && cancelAnimationFrame(this.animationFrameId);
|
|
102
102
|
});
|
|
103
103
|
/**
|
|
104
104
|
* WebGL 上下文恢复处理
|
|
105
105
|
* @param {Event} e - 事件对象
|
|
106
106
|
*/
|
|
107
|
-
|
|
107
|
+
o(this, "onContextRestored", (e) => {
|
|
108
108
|
e.preventDefault(), this.dispose(), setTimeout(() => {
|
|
109
109
|
this.setup(this.selector);
|
|
110
110
|
}, U);
|
|
@@ -112,7 +112,7 @@ class J {
|
|
|
112
112
|
/**
|
|
113
113
|
* 初始化事件监听器
|
|
114
114
|
*/
|
|
115
|
-
|
|
115
|
+
o(this, "initListener", () => {
|
|
116
116
|
this.initOpt.initListener && window && window.addEventListener("resize", this.onResize, !1), this.renderer.domElement.addEventListener(
|
|
117
117
|
"webglcontextlost",
|
|
118
118
|
this.onContextLost,
|
|
@@ -126,7 +126,7 @@ class J {
|
|
|
126
126
|
/**
|
|
127
127
|
* 移除事件监听器
|
|
128
128
|
*/
|
|
129
|
-
|
|
129
|
+
o(this, "removeListener", () => {
|
|
130
130
|
window && window.removeEventListener("resize", this.onResize, !1), this.renderer && this.renderer.domElement && (this.renderer.domElement.removeEventListener(
|
|
131
131
|
"webglcontextlost",
|
|
132
132
|
this.onContextLost,
|
|
@@ -140,19 +140,35 @@ class J {
|
|
|
140
140
|
/**
|
|
141
141
|
* 渲染循环(loop 模式)
|
|
142
142
|
*/
|
|
143
|
-
|
|
143
|
+
o(this, "animate", () => {
|
|
144
144
|
this.isDispose || (this.initOpt.renderType === "loop" && this.onRender(), this.animationFrameId = requestAnimationFrame(this.animate));
|
|
145
145
|
});
|
|
146
146
|
/**
|
|
147
147
|
* 执行渲染
|
|
148
148
|
*/
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
o(this, "onRender", () => {
|
|
150
|
+
if (this.isDispose) return;
|
|
151
|
+
const e = this.debug ? performance.now() : 0;
|
|
152
|
+
this.renderRequested = !1, this.stats && this.stats.update(), this.control && this.control.update(), this.renderer.render(this.scene, this.camera), this.css3dRenderer && this.css3dRenderer.render(this.scene, this.camera);
|
|
153
|
+
const t = this.eventsListener.onRender;
|
|
154
|
+
if (t && t.length) {
|
|
155
|
+
const r = t.length;
|
|
156
|
+
for (let s = 0; s < r; s++)
|
|
157
|
+
try {
|
|
158
|
+
t[s]();
|
|
159
|
+
} catch (f) {
|
|
160
|
+
console.error("[ThreeIns] 渲染回调执行错误:", f);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (this.debug) {
|
|
164
|
+
const r = performance.now() - e;
|
|
165
|
+
r > 50 && console.warn(`[ThreeIns] 帧耗时 ${r.toFixed(1)}ms,可能存在性能问题`);
|
|
166
|
+
}
|
|
151
167
|
});
|
|
152
168
|
/**
|
|
153
169
|
* 请求渲染(如果尚未请求)
|
|
154
170
|
*/
|
|
155
|
-
|
|
171
|
+
o(this, "requestRenderIfNotRequested", () => {
|
|
156
172
|
this.renderRequested || (this.renderRequested = !0, requestAnimationFrame(() => {
|
|
157
173
|
this.onRender();
|
|
158
174
|
}));
|
|
@@ -160,11 +176,11 @@ class J {
|
|
|
160
176
|
/**
|
|
161
177
|
* 处理窗口大小变化(带防抖)
|
|
162
178
|
*/
|
|
163
|
-
|
|
179
|
+
o(this, "onResize", () => {
|
|
164
180
|
this.resizeTimer && clearTimeout(this.resizeTimer), this.resizeTimer = setTimeout(() => {
|
|
165
181
|
const [e, t] = this.getTargetSize();
|
|
166
182
|
this.updateCameraFOV(e, t), this.camera.lookAt(this.scene.position), this.renderer.setSize(e, t), this.css3dRenderer && this.css3dRenderer.setSize(e, t), this.onRender();
|
|
167
|
-
},
|
|
183
|
+
}, N);
|
|
168
184
|
});
|
|
169
185
|
/**
|
|
170
186
|
* @deprecated 此方法已弃用,请使用 setView() 方法代替
|
|
@@ -181,7 +197,7 @@ class J {
|
|
|
181
197
|
* @param {number} [scale=0.8] - 缩放比例,1=占满画布,0.5=50%,2.0=200%
|
|
182
198
|
* @returns {Object} 返回 setView 的结果
|
|
183
199
|
*/
|
|
184
|
-
|
|
200
|
+
o(this, "frameArea", (e, t) => (console.warn(
|
|
185
201
|
`[ThreeIns] frameArea() 已弃用,建议使用 setView() 方法。
|
|
186
202
|
旧用法: threeIns.frameArea(model, scale)
|
|
187
203
|
新用法: threeIns.setView(model, ViewType.ISO, { scale })`
|
|
@@ -247,73 +263,73 @@ class J {
|
|
|
247
263
|
* // 或者使用类静态属性(向后兼容)
|
|
248
264
|
* threeIns.setView(model, ThreeIns.ViewType.TOP);
|
|
249
265
|
*/
|
|
250
|
-
|
|
251
|
-
let s =
|
|
252
|
-
const g = new
|
|
253
|
-
let
|
|
266
|
+
o(this, "setView", (e, t, r = {}) => {
|
|
267
|
+
let s = r.scale || 0.8, f = r.offset || null, R = r.position || "center", w = r.showBox || !1, I = r.boxColor || 16776960, M = r.animate !== void 0 ? r.animate : !0, T = r.duration || 1e3;
|
|
268
|
+
const g = new G().setFromObject(e);
|
|
269
|
+
let h = g.getCenter(new l());
|
|
254
270
|
if (typeof R == "string") {
|
|
255
|
-
const
|
|
256
|
-
center: new
|
|
257
|
-
"top-left": new
|
|
258
|
-
"top-right": new
|
|
259
|
-
"bottom-left": new
|
|
260
|
-
"bottom-right": new
|
|
261
|
-
}, d =
|
|
262
|
-
t === "top" ?
|
|
263
|
-
} else R instanceof
|
|
264
|
-
|
|
265
|
-
const n = g.getSize(new
|
|
266
|
-
top: new
|
|
271
|
+
const i = g.getSize(new l()), a = {
|
|
272
|
+
center: new l(0, 0, 0),
|
|
273
|
+
"top-left": new l(-i.x * 0.3, i.y * 0.3, i.z * 0.3),
|
|
274
|
+
"top-right": new l(i.x * 0.3, i.y * 0.3, i.z * 0.3),
|
|
275
|
+
"bottom-left": new l(-i.x * 0.3, -i.y * 0.3, i.z * 0.3),
|
|
276
|
+
"bottom-right": new l(i.x * 0.3, -i.y * 0.3, i.z * 0.3)
|
|
277
|
+
}, d = a[R] || a.center;
|
|
278
|
+
t === "top" ? h.add(new l(d.x, 0, d.z)) : t === "right" || t === "left" ? h.add(new l(0, d.y, d.z)) : h.add(d);
|
|
279
|
+
} else R instanceof l && h.add(R);
|
|
280
|
+
f && h.add(f);
|
|
281
|
+
const n = g.getSize(new l()), E = {
|
|
282
|
+
top: new l(0, 1, 0),
|
|
267
283
|
// 从上往下:Y 轴正方向
|
|
268
|
-
right: new
|
|
284
|
+
right: new l(1, 1, 1).normalize(),
|
|
269
285
|
// 从右往左:X 轴正方向
|
|
270
|
-
left: new
|
|
286
|
+
left: new l(-1, 1, 1).normalize(),
|
|
271
287
|
// 从左往右:X 轴负方向
|
|
272
|
-
iso: new
|
|
288
|
+
iso: new l(0, 1, 1).normalize()
|
|
273
289
|
// 等轴测:从对角线上方俯视
|
|
274
|
-
}, b =
|
|
275
|
-
let
|
|
290
|
+
}, b = E[t] || E.iso, L = this.camera.aspect, c = F.degToRad(this.camera.fov * 0.5), S = F.degToRad(80), m = Math.min(Math.atan(Math.tan(c) * L), S);
|
|
291
|
+
let u;
|
|
276
292
|
if (t === "top") {
|
|
277
|
-
const
|
|
278
|
-
|
|
293
|
+
const i = n.x * 0.5 / (Math.tan(m) * s), a = n.z * 0.5 / (Math.tan(c) * s);
|
|
294
|
+
u = Math.max(i, a);
|
|
279
295
|
} else if (t === "right" || t === "left") {
|
|
280
|
-
const
|
|
281
|
-
|
|
296
|
+
const i = n.y * 0.5 / (Math.tan(c) * s), a = n.z * 0.5 / (Math.tan(c) * s);
|
|
297
|
+
u = Math.max(i, a);
|
|
282
298
|
} else {
|
|
283
|
-
const
|
|
284
|
-
|
|
299
|
+
const i = n.x * 0.5 / (Math.tan(m) * s), a = n.y * 0.5 / (Math.tan(c) * s), d = n.z * 0.5 / (Math.tan(c) * s);
|
|
300
|
+
u = Math.max(i, a, d);
|
|
285
301
|
}
|
|
286
|
-
const p = b.clone().multiplyScalar(
|
|
287
|
-
if (
|
|
288
|
-
const
|
|
289
|
-
const
|
|
290
|
-
if (this.camera.position.lerpVectors(
|
|
291
|
-
const
|
|
292
|
-
|
|
302
|
+
const p = b.clone().multiplyScalar(u).add(h);
|
|
303
|
+
if (w && (console.log("📍 相机位置验证:"), console.log(" - 方向向量:", b), console.log(" - 距离:", u.toFixed(2)), console.log(" - 包围盒中心:", h), console.log(" - 计算公式: direction * distance + boxCenter"), console.log(" - 目标位置:", p), console.log(" - 实际相机与中心的距离:", p.clone().sub(h).length().toFixed(2))), w ? (this.boxHelper && (this.scene.remove(this.boxHelper), this.boxHelper = null), this.boxHelper = new W(g, I), this.scene.add(this.boxHelper)) : this.boxHelper && (this.scene.remove(this.boxHelper), this.boxHelper = null), M) {
|
|
304
|
+
const i = this.camera.position.clone(), a = this.control ? this.control.target.clone() : new l(0, 0, 0), d = h, D = Date.now(), O = () => {
|
|
305
|
+
const A = Date.now() - D, C = Math.min(A / T, 1), y = 1 - Math.pow(1 - C, 3);
|
|
306
|
+
if (this.camera.position.lerpVectors(i, p, y), this.control) {
|
|
307
|
+
const z = new l();
|
|
308
|
+
z.lerpVectors(a, d, y), this.control.target.copy(z), this.camera.lookAt(z);
|
|
293
309
|
} else
|
|
294
|
-
this.camera.lookAt(
|
|
295
|
-
this.camera.updateProjectionMatrix(), C < 1 ? requestAnimationFrame(O) : (this.camera.position.copy(p), this.camera.lookAt(
|
|
310
|
+
this.camera.lookAt(h);
|
|
311
|
+
this.camera.updateProjectionMatrix(), C < 1 ? requestAnimationFrame(O) : (this.camera.position.copy(p), this.camera.lookAt(h), this.camera.updateProjectionMatrix(), this.control && (this.control.target.copy(h), this.control.update()), this.onRender());
|
|
296
312
|
};
|
|
297
313
|
O();
|
|
298
314
|
} else
|
|
299
|
-
this.camera.position.copy(p), this.camera.lookAt(
|
|
300
|
-
if (
|
|
301
|
-
if (console.log("🎥 视角切换信息:"), console.log(" - 视角类型:", t), console.log(" - 相机位置:", p), console.log(" - 观察目标:",
|
|
302
|
-
const
|
|
303
|
-
console.log(" - 模型 X 尺寸 (宽度):", n.x.toFixed(2)), console.log(" - 模型 Z 尺寸 (深度):", n.z.toFixed(2)), console.log(" - tan(halfFovX):", Math.tan(m).toFixed(4)), console.log(" - tan(halfFovY):", Math.tan(
|
|
315
|
+
this.camera.position.copy(p), this.camera.lookAt(h), this.camera.updateProjectionMatrix(), this.control && (this.control.target.copy(h), this.control.update()), this.onRender();
|
|
316
|
+
if (w) {
|
|
317
|
+
if (console.log("🎥 视角切换信息:"), console.log(" - 视角类型:", t), console.log(" - 相机位置:", p), console.log(" - 观察目标:", h), console.log(" - 方向向量:", b), console.log(" - 包围盒尺寸:", n), console.log(" - 包围盒中心:", g.getCenter(new l())), console.log(" - 水平 FOV:", F.radToDeg(m * 2).toFixed(2) + "°"), console.log(" - 垂直 FOV:", F.radToDeg(c * 2).toFixed(2) + "°"), console.log(" - 宽高比:", L.toFixed(4)), console.log(" - 模型宽度:", n.x.toFixed(2)), console.log(" - 模型高度:", n.y.toFixed(2)), console.log(" - 模型深度:", n.z.toFixed(2)), console.log(" - 传入的 scale 参数:", s), t === "top") {
|
|
318
|
+
const i = n.x * 0.5 / (Math.tan(m) * s), a = n.z * 0.5 / (Math.tan(c) * s);
|
|
319
|
+
console.log(" - 模型 X 尺寸 (宽度):", n.x.toFixed(2)), console.log(" - 模型 Z 尺寸 (深度):", n.z.toFixed(2)), console.log(" - tan(halfFovX):", Math.tan(m).toFixed(4)), console.log(" - tan(halfFovY):", Math.tan(c).toFixed(4)), console.log(" - X方向距离计算: (", (n.x * 0.5).toFixed(2), ") / (", Math.tan(m).toFixed(4), " *", s, ") =", i.toFixed(2)), console.log(" - Z方向距离计算: (", (n.z * 0.5).toFixed(2), ") / (", Math.tan(c).toFixed(4), " *", s, ") =", a.toFixed(2)), console.log(" - X方向距离 (scale=" + s + "):", i.toFixed(2)), console.log(" - Z方向距离 (scale=" + s + "):", a.toFixed(2));
|
|
304
320
|
} else if (t === "right" || t === "left") {
|
|
305
|
-
const
|
|
306
|
-
console.log(" - Y方向距离 (scale=" + s + "):",
|
|
321
|
+
const i = n.y * 0.5 / (Math.tan(c) * s), a = n.z * 0.5 / (Math.tan(c) * s);
|
|
322
|
+
console.log(" - Y方向距离 (scale=" + s + "):", i.toFixed(2)), console.log(" - Z方向距离 (scale=" + s + "):", a.toFixed(2));
|
|
307
323
|
} else {
|
|
308
|
-
const
|
|
309
|
-
console.log(" - 模型 X 尺寸 (宽度):", n.x.toFixed(2)), console.log(" - 模型 Y 尺寸 (高度):", n.y.toFixed(2)), console.log(" - 模型 Z 尺寸 (深度):", n.z.toFixed(2)), console.log(" - tan(halfFovX):", Math.tan(m).toFixed(4)), console.log(" - tan(halfFovY):", Math.tan(
|
|
324
|
+
const i = n.x * 0.5 / (Math.tan(m) * s), a = n.y * 0.5 / (Math.tan(c) * s), d = n.z * 0.5 / (Math.tan(c) * s);
|
|
325
|
+
console.log(" - 模型 X 尺寸 (宽度):", n.x.toFixed(2)), console.log(" - 模型 Y 尺寸 (高度):", n.y.toFixed(2)), console.log(" - 模型 Z 尺寸 (深度):", n.z.toFixed(2)), console.log(" - tan(halfFovX):", Math.tan(m).toFixed(4)), console.log(" - tan(halfFovY):", Math.tan(c).toFixed(4)), console.log(" - X方向距离计算: (", (n.x * 0.5).toFixed(2), ") / (", Math.tan(m).toFixed(4), " *", s, ") =", i.toFixed(2)), console.log(" - Y方向距离计算: (", (n.y * 0.5).toFixed(2), ") / (", Math.tan(c).toFixed(4), " *", s, ") =", a.toFixed(2)), console.log(" - Z方向距离计算: (", (n.z * 0.5).toFixed(2), ") / (", Math.tan(c).toFixed(4), " *", s, ") =", d.toFixed(2)), console.log(" - X方向距离 (scale=" + s + "):", i.toFixed(2)), console.log(" - Y方向距离 (scale=" + s + "):", a.toFixed(2)), console.log(" - Z方向距离 (scale=" + s + "):", d.toFixed(2)), console.log(" - 最大距离 (Max):", Math.max(i, a, d).toFixed(2));
|
|
310
326
|
}
|
|
311
|
-
console.log(" - 最终距离:",
|
|
327
|
+
console.log(" - 最终距离:", u.toFixed(2)), console.log(" - 缩放比例:", s), console.log(" - 动画:", M ? "是 (" + T + "ms)" : "否");
|
|
312
328
|
}
|
|
313
329
|
return {
|
|
314
330
|
position: p,
|
|
315
|
-
target:
|
|
316
|
-
distance:
|
|
331
|
+
target: h,
|
|
332
|
+
distance: u,
|
|
317
333
|
viewType: t
|
|
318
334
|
};
|
|
319
335
|
});
|
|
@@ -323,14 +339,32 @@ class J {
|
|
|
323
339
|
* @param {Function} callback - 回调函数
|
|
324
340
|
* @returns {Function} 返回取消监听的函数
|
|
325
341
|
*/
|
|
326
|
-
|
|
342
|
+
o(this, "on", (e, t) => !e || !t || typeof t != "function" ? (console.warn("ThreeIns.on: 无效的参数"), () => {
|
|
327
343
|
}) : (this.eventsListener[e] || (this.eventsListener[e] = []), this.eventsListener[e].push(t), () => this.off(e, t)));
|
|
344
|
+
/**
|
|
345
|
+
* 添加动画回调(推荐使用此方法注册动画回调)
|
|
346
|
+
* @param {Function} callback - 回调函数
|
|
347
|
+
* @returns {Function} 返回移除回调的函数
|
|
348
|
+
*/
|
|
349
|
+
o(this, "addAnimate", (e) => !e || typeof e != "function" ? (console.warn("ThreeIns.addAnimate: 无效的回调函数"), () => {
|
|
350
|
+
}) : (this.eventsListener.onRender || (this.eventsListener.onRender = []), this.eventsListener.onRender.push(e), () => this.removeAnimate(e)));
|
|
351
|
+
/**
|
|
352
|
+
* 移除动画回调
|
|
353
|
+
* @param {Function} callback - 要移除的回调函数
|
|
354
|
+
*/
|
|
355
|
+
o(this, "removeAnimate", (e) => {
|
|
356
|
+
if (!e) return;
|
|
357
|
+
const t = this.eventsListener.onRender;
|
|
358
|
+
if (!t) return;
|
|
359
|
+
const r = t.indexOf(e);
|
|
360
|
+
r > -1 && t.splice(r, 1);
|
|
361
|
+
});
|
|
328
362
|
this.isReady = !1, this.scene = new Y({}), this.camera = new B(50, 1, 0.1, 2e3), this.renderer = new Z({
|
|
329
363
|
antialias: !0,
|
|
330
364
|
alpha: !0,
|
|
331
365
|
precision: "mediump",
|
|
332
366
|
logarithmicDepthBuffer: !0
|
|
333
|
-
}), this.version =
|
|
367
|
+
}), this.version = _, this.onContextLost = this.onContextLost.bind(this), this.onContextRestored = this.onContextRestored.bind(this), this.onResize = this.onResize.bind(this), this.animate = this.animate.bind(this), this.resizeTimer = null, this.animationFrameId = null, t && (this.initOpt = Object.assign(this.initOpt, t)), e && this.setup(e);
|
|
334
368
|
}
|
|
335
369
|
/**
|
|
336
370
|
* 更新相机 FOV 以适应容器尺寸
|
|
@@ -339,7 +373,7 @@ class J {
|
|
|
339
373
|
* @param {number} domH - 容器高度
|
|
340
374
|
*/
|
|
341
375
|
updateCameraFOV(e, t) {
|
|
342
|
-
const
|
|
376
|
+
const r = this.initOpt.initialFov || 50, s = Math.tan(Math.PI / 180 * r / 2);
|
|
343
377
|
this.camera.aspect = e / t, this.camera.fov = 360 / Math.PI * Math.atan(s * (t / e)), this.camera.updateProjectionMatrix();
|
|
344
378
|
}
|
|
345
379
|
/**
|
|
@@ -374,7 +408,7 @@ class J {
|
|
|
374
408
|
this.eventsListener = {};
|
|
375
409
|
return;
|
|
376
410
|
}
|
|
377
|
-
this.eventsListener[e] && (t ? this.eventsListener[e] = this.eventsListener[e].filter((
|
|
411
|
+
this.eventsListener[e] && (t ? this.eventsListener[e] = this.eventsListener[e].filter((r) => r !== t) : this.eventsListener[e] = []);
|
|
378
412
|
}
|
|
379
413
|
/**
|
|
380
414
|
* 清理所有资源
|
|
@@ -385,47 +419,56 @@ class J {
|
|
|
385
419
|
}
|
|
386
420
|
// 存储包围盒辅助器
|
|
387
421
|
// 视角类型枚举(作为类静态属性引用,保持向后兼容)
|
|
388
|
-
|
|
422
|
+
o(J, "ViewType", v);
|
|
389
423
|
export {
|
|
390
424
|
he as CacheMonitor,
|
|
391
425
|
de as ErrorType,
|
|
392
426
|
me as IDBCache,
|
|
393
|
-
|
|
427
|
+
qe as ImageLoader,
|
|
394
428
|
fe as ModelLoadError,
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
429
|
+
Je as ModelOptimizer,
|
|
430
|
+
ue as PredictiveLoader,
|
|
431
|
+
pe as ProgressiveSceneBuilder,
|
|
398
432
|
xe as RetryHelper,
|
|
399
433
|
J as ThreeIns,
|
|
400
434
|
v as ViewType,
|
|
401
435
|
ge as cacheMonitor,
|
|
402
|
-
|
|
403
|
-
|
|
436
|
+
Xe as cancelIdleTask,
|
|
437
|
+
Fe as clearGeometryCache,
|
|
438
|
+
Re as clearMaterialCache,
|
|
439
|
+
we as createArrowHelper,
|
|
440
|
+
be as createAxesHelper,
|
|
404
441
|
ze as createBox3Helper,
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
442
|
+
Me as createCameraHelper,
|
|
443
|
+
Te as createGridHelper,
|
|
444
|
+
Ye as createInfoPlane,
|
|
445
|
+
Ee as createMapControls,
|
|
409
446
|
j as createOrbitControl,
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
447
|
+
Le as createRaycaster,
|
|
448
|
+
Oe as createStats,
|
|
449
|
+
Be as createTagPlane,
|
|
450
|
+
Ce as dataToObject3D,
|
|
451
|
+
ye as dataToObject3DSync,
|
|
415
452
|
X as disposeThreeObject,
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
453
|
+
Ze as getCommonParent,
|
|
454
|
+
ve as getGeometryCacheStats,
|
|
455
|
+
Ie as getMaterialCacheStats,
|
|
456
|
+
Ge as getObjectByUserData,
|
|
457
|
+
We as getRootObj,
|
|
458
|
+
_e as initEnvImage,
|
|
420
459
|
oe as intersectColor,
|
|
421
|
-
|
|
460
|
+
Ke as modelOptimizer,
|
|
422
461
|
ie as obbObjects,
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
462
|
+
Se as object3DToData,
|
|
463
|
+
De as object3DToDataSync,
|
|
464
|
+
Ae as object3DToTransferable,
|
|
465
|
+
He as predictiveLoader,
|
|
466
|
+
Ne as processInChunks,
|
|
467
|
+
Pe as rebuildScene,
|
|
468
|
+
ke as runWhenIdle,
|
|
469
|
+
Ue as throttle,
|
|
427
470
|
ne as useBatchGLTFLoader,
|
|
428
|
-
|
|
471
|
+
je as useGLTFLoader,
|
|
429
472
|
re as useObb,
|
|
430
473
|
ae as useRaycaster,
|
|
431
474
|
le as useThreeJs
|