@ridp/threejs 1.5.1 → 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/threejs.js CHANGED
@@ -1,13 +1,13 @@
1
1
  var H = Object.defineProperty;
2
- var A = (g, t, e) => t in g ? H(g, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : g[t] = e;
3
- var n = (g, t, e) => A(g, typeof t != "symbol" ? t + "" : t, e);
4
- import { i as se, o as oe, c as ie, b as ne, a as re, u as ae } from "./useBatchGLTFLoader-C1C8R5Ss.js";
5
- import { d as P, S as j, s as X, j as Y } from "./PredictiveLoader-C9zJlZEQ.js";
6
- import { C as ce, E as de, I as he, M as me, P as xe, q as fe, R as ge, n as ue, h as pe, g as Fe, b as Re, c as Me, a as ze, e as be, f as Ee, i as Le, l as Oe, m as we, o as Ce, k as ye, p as Te, r as Se, u as De } from "./PredictiveLoader-C9zJlZEQ.js";
7
- import { I as Ie, c as He, a as Ae, g as Pe, b as je, d as Xe, i as Ye } from "./objectQuery-BfHUGPET.js";
8
- import { ModelOptimizer as Ze, modelOptimizer as qe } from "./modelOptimizer-D6fRg-DF.js";
9
- import { MathUtils as R, Scene as V, PerspectiveCamera as Z, WebGLRenderer as q, Box3 as B, Vector3 as l, Box3Helper as _ } from "three";
10
- const G = "1.5.0", N = 50, W = 20, $ = 20, T = {
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",
@@ -16,15 +16,15 @@ const G = "1.5.0", N = 50, W = 20, $ = 20, T = {
16
16
  // 左侧视
17
17
  ISO: "iso"
18
18
  // 正斜视(等轴测视角)
19
- }, k = {
19
+ }, $ = {
20
20
  enableDamping: !0,
21
21
  dampingFactor: 0.25,
22
22
  screenSpacePanning: !1,
23
23
  minDistance: 0.1,
24
24
  maxDistance: 1e3,
25
- maxPolarAngle: R.degToRad(60)
25
+ maxPolarAngle: F.degToRad(60)
26
26
  };
27
- class U {
27
+ class J {
28
28
  /**
29
29
  * 构造函数
30
30
  * @param {string} selector - DOM 容器选择器
@@ -38,22 +38,22 @@ class U {
38
38
  * @param {boolean} [option.control.init=true] - 是否初始化控制器
39
39
  * @param {Object} [option.control.options={}] - 控制器选项
40
40
  */
41
- constructor(t, e) {
42
- n(this, "isReady", !1);
43
- n(this, "scene", null);
44
- n(this, "camera", null);
45
- n(this, "renderer", null);
46
- n(this, "control", null);
47
- n(this, "css3dRenderer", null);
48
- n(this, "el", null);
49
- n(this, "renderRequested", !1);
50
- n(this, "selector", null);
51
- n(this, "eventsListener", {});
52
- n(this, "stats", null);
53
- n(this, "isDispose", !1);
54
- n(this, "version", "0.0.0");
55
- n(this, "boxHelper", null);
56
- n(this, "initOpt", {
41
+ constructor(e, t) {
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,25 +70,25 @@ class U {
70
70
  * 初始化场景
71
71
  * @param {string} selector - DOM 容器选择器
72
72
  */
73
- n(this, "setup", (t) => {
74
- if (this.isDispose = !1, this.selector = t, this.el = document.querySelector(t), !this.el) {
75
- console.error(`ThreeIns: 找不到元素 ${t}`);
73
+ o(this, "setup", (e) => {
74
+ if (this.isDispose = !1, this.selector = e, this.el = document.querySelector(e), !this.el) {
75
+ console.error(`ThreeIns: 找不到元素 ${e}`);
76
76
  return;
77
77
  }
78
- const [e, h] = this.getTargetSize();
79
- if (this.updateCameraFOV(e, h), this.camera.position.set(0, 0, 0), this.camera.lookAt(0, 0, 0), this.camera.updateProjectionMatrix(), this.renderer.setPixelRatio(window.devicePixelRatio), this.renderer.setSize(e, h), this.el.appendChild(this.renderer.domElement), this.initOpt.control && this.initOpt.control.init) {
80
- this.control = P(this.camera, this.renderer.domElement);
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
+ this.control = j(this.camera, this.renderer.domElement);
81
81
  const s = Object.assign(
82
- k,
82
+ $,
83
83
  this.initOpt.control.options || {}
84
84
  );
85
- Object.keys(s).forEach((u) => {
86
- this.control[u] = s[u];
85
+ Object.keys(s).forEach((f) => {
86
+ this.control[f] = s[f];
87
87
  });
88
88
  }
89
89
  setTimeout(() => {
90
90
  this.isReady = !0;
91
- }, W), this.initOpt.stats && this.initStats(), this.initOpt.css3d && this.initCss3dRenderer(), this.initOpt.renderType === "loop" ? this.animate() : this.initOpt.renderType === "change" && this.control && this.control.addEventListener(
91
+ }, k), this.initOpt.stats && this.initStats(), this.initOpt.css3d && this.initCss3dRenderer(), this.initOpt.renderType === "loop" ? this.animate() : this.initOpt.renderType === "change" && this.control && this.control.addEventListener(
92
92
  "change",
93
93
  this.requestRenderIfNotRequested
94
94
  ), this.initListener();
@@ -97,22 +97,22 @@ class U {
97
97
  * WebGL 上下文丢失处理
98
98
  * @param {Event} e - 事件对象
99
99
  */
100
- n(this, "onContextLost", (t) => {
101
- t.preventDefault(), this.animationFrameId && cancelAnimationFrame(this.animationFrameId);
100
+ o(this, "onContextLost", (e) => {
101
+ e.preventDefault(), this.animationFrameId && cancelAnimationFrame(this.animationFrameId);
102
102
  });
103
103
  /**
104
104
  * WebGL 上下文恢复处理
105
105
  * @param {Event} e - 事件对象
106
106
  */
107
- n(this, "onContextRestored", (t) => {
108
- t.preventDefault(), this.dispose(), setTimeout(() => {
107
+ o(this, "onContextRestored", (e) => {
108
+ e.preventDefault(), this.dispose(), setTimeout(() => {
109
109
  this.setup(this.selector);
110
- }, $);
110
+ }, U);
111
111
  });
112
112
  /**
113
113
  * 初始化事件监听器
114
114
  */
115
- n(this, "initListener", () => {
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 U {
126
126
  /**
127
127
  * 移除事件监听器
128
128
  */
129
- n(this, "removeListener", () => {
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 U {
140
140
  /**
141
141
  * 渲染循环(loop 模式)
142
142
  */
143
- n(this, "animate", () => {
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
- n(this, "onRender", () => {
150
- this.isDispose || (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), this.eventsListener.onRender && this.eventsListener.onRender.length && this.eventsListener.onRender.forEach((t) => t()));
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
- n(this, "requestRenderIfNotRequested", () => {
171
+ o(this, "requestRenderIfNotRequested", () => {
156
172
  this.renderRequested || (this.renderRequested = !0, requestAnimationFrame(() => {
157
173
  this.onRender();
158
174
  }));
@@ -160,10 +176,10 @@ class U {
160
176
  /**
161
177
  * 处理窗口大小变化(带防抖)
162
178
  */
163
- n(this, "onResize", () => {
179
+ o(this, "onResize", () => {
164
180
  this.resizeTimer && clearTimeout(this.resizeTimer), this.resizeTimer = setTimeout(() => {
165
- const [t, e] = this.getTargetSize();
166
- this.updateCameraFOV(t, e), this.camera.lookAt(this.scene.position), this.renderer.setSize(t, e), this.css3dRenderer && this.css3dRenderer.setSize(t, e), this.onRender();
181
+ const [e, t] = this.getTargetSize();
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
  /**
@@ -181,25 +197,21 @@ class U {
181
197
  * @param {number} [scale=0.8] - 缩放比例,1=占满画布,0.5=50%,2.0=200%
182
198
  * @returns {Object} 返回 setView 的结果
183
199
  */
184
- n(this, "frameArea", (t, e) => (console.warn(
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 })`
188
- ), this.setView(t, T.ISO, { scale: e, animate: !1, showBox: !1 })));
204
+ ), this.setView(e, v.ISO, { scale: t, animate: !1, showBox: !1 })));
189
205
  /**
190
206
  * 切换到指定视角
191
207
  * 根据视角类型自动调整相机位置和朝向,支持缩放比例控制
192
208
  *
193
209
  * @param {Object3D} model - 3D 物体对象
194
- * @param {string|Vector3} viewType - 视角类型,可以使用 ViewType 枚举或自定义 Vector3 方向向量
195
- * - ViewType 枚举:
196
- * - 'top': 俯视(从上往下看 Y 轴正方向)
197
- * - 'right': 侧视(从右往左看 X 轴正方向)
198
- * - 'left': 左侧视(从左往右看 X 轴负方向)
199
- * - 'iso': 正斜视(等轴测视角,45°角)
200
- * - Vector3 自定义方向:
201
- * - 任意方向向量,如 Vector3(1, 1, 1)、Vector3(2, 0, 1)
202
- * - 向量会被自动归一化,相对模型中心的任意角度
210
+ * @param {string} viewType - 视角类型,使用 ViewType 枚举
211
+ * - 'top': 俯视(从上往下看 Y 轴正方向)
212
+ * - 'right': 侧视(从右往左看 X 轴正方向)
213
+ * - 'left': 左侧视(从左往右看 X 轴负方向)
214
+ * - 'iso': 正斜视(等轴测视角,45°角)
203
215
  * @param {Object} [options] - 可选配置
204
216
  * @param {number} [options.scale=1] - 缩放比例,控制模型在画布中的占比
205
217
  * @param {string|Vector3} [options.position='center'] - 模型在画布中的位置
@@ -219,8 +231,6 @@ class U {
219
231
  * // 导入 ViewType 枚举
220
232
  * import { ThreeIns, ViewType } from 'threejs';
221
233
  *
222
- * // ============ 使用预设 ViewType ============
223
- *
224
234
  * // 切换到俯视,模型占满画布,居中显示
225
235
  * threeIns.setView(model, ViewType.TOP);
226
236
  *
@@ -250,114 +260,77 @@ class U {
250
260
  * scale: 0.8
251
261
  * });
252
262
  *
253
- * // ============ 使用自定义 Vector3 方向 ============
254
- *
255
- * // 从对角线方向查看模型(类似等轴测)
256
- * threeIns.setView(model, new THREE.Vector3(1, 1, 1));
257
- *
258
- * // 从右前方查看模型
259
- * threeIns.setView(model, new THREE.Vector3(2, 1, 1));
260
- *
261
- * // 从左侧平视模型
262
- * threeIns.setView(model, new THREE.Vector3(0, 0, 1));
263
- *
264
- * // 从下方仰视模型
265
- * threeIns.setView(model, new THREE.Vector3(0, -1, 1));
266
- *
267
- * // 自定义方向 + 其他选项
268
- * threeIns.setView(model, new THREE.Vector3(1, 2, 1), {
269
- * scale: 0.6,
270
- * position: 'center',
271
- * showBox: true,
272
- * animate: true,
273
- * duration: 1500
274
- * });
275
- *
276
263
  * // 或者使用类静态属性(向后兼容)
277
264
  * threeIns.setView(model, ThreeIns.ViewType.TOP);
278
265
  */
279
- n(this, "setView", (t, e, h = {}) => {
280
- let s = h.scale || 0.8, u = h.offset || null, M = h.position || "center", z = h.showBox || !1, S = h.boxColor || 16776960, E = h.animate !== void 0 ? h.animate : !0, L = h.duration || 1e3;
281
- const p = new B().setFromObject(t);
282
- let d = p.getCenter(new l());
283
- if (typeof M == "string") {
284
- const i = p.getSize(new l()), r = {
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());
270
+ if (typeof R == "string") {
271
+ const i = g.getSize(new l()), a = {
285
272
  center: new l(0, 0, 0),
286
273
  "top-left": new l(-i.x * 0.3, i.y * 0.3, i.z * 0.3),
287
274
  "top-right": new l(i.x * 0.3, i.y * 0.3, i.z * 0.3),
288
275
  "bottom-left": new l(-i.x * 0.3, -i.y * 0.3, i.z * 0.3),
289
276
  "bottom-right": new l(i.x * 0.3, -i.y * 0.3, i.z * 0.3)
290
- }, c = r[M] || r.center;
291
- typeof e == "string" ? e === "top" ? d.add(new l(c.x, 0, c.z)) : e === "right" || e === "left" ? d.add(new l(c.x, c.y, c.z)) : d.add(c) : d.add(c);
292
- } else M instanceof l && d.add(M);
293
- u && d.add(u);
294
- const o = p.getSize(new l());
295
- let F;
296
- if (e instanceof l)
297
- F = e.clone().normalize();
298
- else {
299
- const i = {
300
- top: new l(0, 1, 0),
301
- // 从上往下:Y 轴正方向
302
- right: new l(1, 1, 1).normalize(),
303
- // 从右往左:X 轴正方向
304
- left: new l(-1, 1, 1).normalize(),
305
- // 从左往右:X 轴负方向
306
- iso: new l(0, 1, 1).normalize()
307
- // 等轴测:从对角线上方俯视
308
- };
309
- F = i[e] || i.iso;
310
- }
311
- const O = this.camera.aspect, a = R.degToRad(this.camera.fov * 0.5), D = R.degToRad(80), m = Math.min(Math.atan(Math.tan(a) * O), D);
312
- let x;
313
- if (e instanceof l) {
314
- const i = o.x * 0.5 / (Math.tan(m) * s), r = o.y * 0.5 / (Math.tan(a) * s), c = o.z * 0.5 / (Math.tan(a) * s);
315
- x = Math.max(i, r, c);
316
- } else if (e === "top") {
317
- const i = o.x * 0.5 / (Math.tan(m) * s), r = o.z * 0.5 / (Math.tan(a) * s);
318
- x = Math.max(i, r);
319
- } else if (e === "right" || e === "left") {
320
- const i = o.y * 0.5 / (Math.tan(a) * s), r = o.z * 0.5 / (Math.tan(a) * s);
321
- x = Math.max(i, r);
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),
283
+ // 从上往下:Y 轴正方向
284
+ right: new l(1, 1, 1).normalize(),
285
+ // 从右往左:X 轴正方向
286
+ left: new l(-1, 1, 1).normalize(),
287
+ // 从左往右:X 轴负方向
288
+ iso: new l(0, 1, 1).normalize()
289
+ // 等轴测:从对角线上方俯视
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;
292
+ if (t === "top") {
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);
295
+ } else if (t === "right" || t === "left") {
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);
322
298
  } else {
323
- const i = o.x * 0.5 / (Math.tan(m) * s), r = o.y * 0.5 / (Math.tan(a) * s), c = o.z * 0.5 / (Math.tan(a) * s);
324
- x = Math.max(i, r, c);
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);
325
301
  }
326
- const f = F.clone().multiplyScalar(x).add(d);
327
- if (z && (console.log("📍 相机位置验证:"), console.log(" - 方向向量:", F), console.log(" - 距离:", x.toFixed(2)), console.log(" - 包围盒中心:", d), console.log(" - 计算公式: direction * distance + boxCenter"), console.log(" - 目标位置:", f), console.log(" - 实际相机与中心的距离:", f.clone().sub(d).length().toFixed(2))), z ? (this.boxHelper && (this.scene.remove(this.boxHelper), this.boxHelper = null), this.boxHelper = new _(p, S), this.scene.add(this.boxHelper)) : this.boxHelper && (this.scene.remove(this.boxHelper), this.boxHelper = null), E) {
328
- const i = this.camera.position.clone(), r = this.control ? this.control.target.clone() : new l(0, 0, 0), c = d, v = Date.now(), w = () => {
329
- const I = Date.now() - v, C = Math.min(I / L, 1), y = 1 - Math.pow(1 - C, 3);
330
- if (this.camera.position.lerpVectors(i, f, y), this.control) {
331
- const b = new l();
332
- b.lerpVectors(r, c, y), this.control.target.copy(b), this.camera.lookAt(b);
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);
333
309
  } else
334
- this.camera.lookAt(d);
335
- this.camera.updateProjectionMatrix(), C < 1 ? requestAnimationFrame(w) : (this.camera.position.copy(f), this.camera.lookAt(d), this.camera.updateProjectionMatrix(), this.control && (this.control.target.copy(d), this.control.update()), this.onRender());
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());
336
312
  };
337
- w();
313
+ O();
338
314
  } else
339
- this.camera.position.copy(f), this.camera.lookAt(d), this.camera.updateProjectionMatrix(), this.control && (this.control.target.copy(d), this.control.update()), this.onRender();
340
- if (z) {
341
- if (console.log("🎥 视角切换信息:"), console.log(" - 视角类型:", e instanceof l ? `自定义 Vector3(${e.x.toFixed(2)}, ${e.y.toFixed(2)}, ${e.z.toFixed(2)})` : e), console.log(" - 相机位置:", f), console.log(" - 观察目标:", d), console.log(" - 方向向量:", F), console.log(" - 包围盒尺寸:", o), console.log(" - 包围盒中心:", p.getCenter(new l())), console.log(" - 水平 FOV:", R.radToDeg(m * 2).toFixed(2) + "°"), console.log(" - 垂直 FOV:", R.radToDeg(a * 2).toFixed(2) + "°"), console.log(" - 宽高比:", O.toFixed(4)), console.log(" - 模型宽度:", o.x.toFixed(2)), console.log(" - 模型高度:", o.y.toFixed(2)), console.log(" - 模型深度:", o.z.toFixed(2)), console.log(" - 传入的 scale 参数:", s), e instanceof l) {
342
- const i = o.x * 0.5 / (Math.tan(m) * s), r = o.y * 0.5 / (Math.tan(a) * s), c = o.z * 0.5 / (Math.tan(a) * s);
343
- console.log(" - 模型 X 尺寸 (宽度):", o.x.toFixed(2)), console.log(" - 模型 Y 尺寸 (高度):", o.y.toFixed(2)), console.log(" - 模型 Z 尺寸 (深度):", o.z.toFixed(2)), console.log(" - tan(halfFovX):", Math.tan(m).toFixed(4)), console.log(" - tan(halfFovY):", Math.tan(a).toFixed(4)), console.log(" - X方向距离计算: (", (o.x * 0.5).toFixed(2), ") / (", Math.tan(m).toFixed(4), " *", s, ") =", i.toFixed(2)), console.log(" - Y方向距离计算: (", (o.y * 0.5).toFixed(2), ") / (", Math.tan(a).toFixed(4), " *", s, ") =", r.toFixed(2)), console.log(" - Z方向距离计算: (", (o.z * 0.5).toFixed(2), ") / (", Math.tan(a).toFixed(4), " *", s, ") =", c.toFixed(2)), console.log(" - X方向距离 (scale=" + s + "):", i.toFixed(2)), console.log(" - Y方向距离 (scale=" + s + "):", r.toFixed(2)), console.log(" - Z方向距离 (scale=" + s + "):", c.toFixed(2)), console.log(" - 最大距离 (Max):", Math.max(i, r, c).toFixed(2));
344
- } else if (e === "top") {
345
- const i = o.x * 0.5 / (Math.tan(m) * s), r = o.z * 0.5 / (Math.tan(a) * s);
346
- console.log(" - 模型 X 尺寸 (宽度):", o.x.toFixed(2)), console.log(" - 模型 Z 尺寸 (深度):", o.z.toFixed(2)), console.log(" - tan(halfFovX):", Math.tan(m).toFixed(4)), console.log(" - tan(halfFovY):", Math.tan(a).toFixed(4)), console.log(" - X方向距离计算: (", (o.x * 0.5).toFixed(2), ") / (", Math.tan(m).toFixed(4), " *", s, ") =", i.toFixed(2)), console.log(" - Z方向距离计算: (", (o.z * 0.5).toFixed(2), ") / (", Math.tan(a).toFixed(4), " *", s, ") =", r.toFixed(2)), console.log(" - X方向距离 (scale=" + s + "):", i.toFixed(2)), console.log(" - Z方向距离 (scale=" + s + "):", r.toFixed(2));
347
- } else if (e === "right" || e === "left") {
348
- const i = o.y * 0.5 / (Math.tan(a) * s), r = o.z * 0.5 / (Math.tan(a) * s);
349
- console.log(" - Y方向距离 (scale=" + s + "):", i.toFixed(2)), console.log(" - Z方向距离 (scale=" + s + "):", r.toFixed(2));
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));
320
+ } else if (t === "right" || t === "left") {
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));
350
323
  } else {
351
- const i = o.x * 0.5 / (Math.tan(m) * s), r = o.y * 0.5 / (Math.tan(a) * s), c = o.z * 0.5 / (Math.tan(a) * s);
352
- console.log(" - 模型 X 尺寸 (宽度):", o.x.toFixed(2)), console.log(" - 模型 Y 尺寸 (高度):", o.y.toFixed(2)), console.log(" - 模型 Z 尺寸 (深度):", o.z.toFixed(2)), console.log(" - tan(halfFovX):", Math.tan(m).toFixed(4)), console.log(" - tan(halfFovY):", Math.tan(a).toFixed(4)), console.log(" - X方向距离计算: (", (o.x * 0.5).toFixed(2), ") / (", Math.tan(m).toFixed(4), " *", s, ") =", i.toFixed(2)), console.log(" - Y方向距离计算: (", (o.y * 0.5).toFixed(2), ") / (", Math.tan(a).toFixed(4), " *", s, ") =", r.toFixed(2)), console.log(" - Z方向距离计算: (", (o.z * 0.5).toFixed(2), ") / (", Math.tan(a).toFixed(4), " *", s, ") =", c.toFixed(2)), console.log(" - X方向距离 (scale=" + s + "):", i.toFixed(2)), console.log(" - Y方向距离 (scale=" + s + "):", r.toFixed(2)), console.log(" - Z方向距离 (scale=" + s + "):", c.toFixed(2)), console.log(" - 最大距离 (Max):", Math.max(i, r, c).toFixed(2));
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));
353
326
  }
354
- console.log(" - 最终距离:", x.toFixed(2)), console.log(" - 缩放比例:", s), console.log(" - 动画:", E ? "是 (" + L + "ms)" : "否");
327
+ console.log(" - 最终距离:", u.toFixed(2)), console.log(" - 缩放比例:", s), console.log(" - 动画:", M ? "是 (" + T + "ms)" : "否");
355
328
  }
356
329
  return {
357
- position: f,
358
- target: d,
359
- distance: x,
360
- viewType: e
330
+ position: p,
331
+ target: h,
332
+ distance: u,
333
+ viewType: t
361
334
  };
362
335
  });
363
336
  /**
@@ -366,14 +339,32 @@ class U {
366
339
  * @param {Function} callback - 回调函数
367
340
  * @returns {Function} 返回取消监听的函数
368
341
  */
369
- n(this, "on", (t, e) => !t || !e || typeof e != "function" ? (console.warn("ThreeIns.on: 无效的参数"), () => {
370
- }) : (this.eventsListener[t] || (this.eventsListener[t] = []), this.eventsListener[t].push(e), () => this.off(t, e)));
371
- this.isReady = !1, this.scene = new V({}), this.camera = new Z(50, 1, 0.1, 2e3), this.renderer = new q({
342
+ o(this, "on", (e, t) => !e || !t || typeof t != "function" ? (console.warn("ThreeIns.on: 无效的参数"), () => {
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
+ });
362
+ this.isReady = !1, this.scene = new Y({}), this.camera = new B(50, 1, 0.1, 2e3), this.renderer = new Z({
372
363
  antialias: !0,
373
364
  alpha: !0,
374
365
  precision: "mediump",
375
366
  logarithmicDepthBuffer: !0
376
- }), this.version = G, 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, e && (this.initOpt = Object.assign(this.initOpt, e)), t && this.setup(t);
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);
377
368
  }
378
369
  /**
379
370
  * 更新相机 FOV 以适应容器尺寸
@@ -381,23 +372,23 @@ class U {
381
372
  * @param {number} domW - 容器宽度
382
373
  * @param {number} domH - 容器高度
383
374
  */
384
- updateCameraFOV(t, e) {
385
- const h = this.initOpt.initialFov || 50, s = Math.tan(Math.PI / 180 * h / 2);
386
- this.camera.aspect = t / e, this.camera.fov = 360 / Math.PI * Math.atan(s * (e / t)), this.camera.updateProjectionMatrix();
375
+ updateCameraFOV(e, t) {
376
+ const r = this.initOpt.initialFov || 50, s = Math.tan(Math.PI / 180 * r / 2);
377
+ this.camera.aspect = e / t, this.camera.fov = 360 / Math.PI * Math.atan(s * (t / e)), this.camera.updateProjectionMatrix();
387
378
  }
388
379
  /**
389
380
  * 初始化性能统计
390
381
  */
391
382
  initStats() {
392
- this.stats = new j(), this.stats.dom.style.cssText = "position:absolute;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000", this.el.appendChild(this.stats.dom);
383
+ this.stats = new V(), this.stats.dom.style.cssText = "position:absolute;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000", this.el.appendChild(this.stats.dom);
393
384
  }
394
385
  /**
395
386
  * 初始化 CSS3D 渲染器
396
387
  */
397
388
  initCss3dRenderer() {
398
- this.css3dRenderer = new X();
399
- const [t, e] = this.getTargetSize();
400
- this.css3dRenderer.setSize(t, e), this.css3dRenderer.domElement.style.position = "absolute", this.css3dRenderer.domElement.style.pointerEvents = "none", this.css3dRenderer.domElement.style.top = 0, this.css3dRenderer.domElement.style.left = 0, this.el.appendChild(this.css3dRenderer.domElement);
389
+ this.css3dRenderer = new q();
390
+ const [e, t] = this.getTargetSize();
391
+ this.css3dRenderer.setSize(e, t), this.css3dRenderer.domElement.style.position = "absolute", this.css3dRenderer.domElement.style.pointerEvents = "none", this.css3dRenderer.domElement.style.top = 0, this.css3dRenderer.domElement.style.left = 0, this.el.appendChild(this.css3dRenderer.domElement);
401
392
  }
402
393
  /**
403
394
  * 获取目标容器尺寸
@@ -412,64 +403,73 @@ class U {
412
403
  * @param {string} event - 事件名称
413
404
  * @param {Function} [callback] - 可选的回调函数,如果不提供则移除该事件的所有监听器
414
405
  */
415
- off(t, e) {
416
- if (!t) {
406
+ off(e, t) {
407
+ if (!e) {
417
408
  this.eventsListener = {};
418
409
  return;
419
410
  }
420
- this.eventsListener[t] && (e ? this.eventsListener[t] = this.eventsListener[t].filter((h) => h !== e) : this.eventsListener[t] = []);
411
+ this.eventsListener[e] && (t ? this.eventsListener[e] = this.eventsListener[e].filter((r) => r !== t) : this.eventsListener[e] = []);
421
412
  }
422
413
  /**
423
414
  * 清理所有资源
424
415
  */
425
416
  dispose() {
426
- this.isDispose || (this.isDispose = !0, this.animationFrameId && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = null), this.resizeTimer && (clearTimeout(this.resizeTimer), this.resizeTimer = null), this.removeListener(), this.eventsListener = {}, this.stats && this.stats.dom && (this.stats.dom.remove(), this.stats = null), this.css3dRenderer && (this.css3dRenderer.domElement.remove(), this.css3dRenderer = null), this.boxHelper && (this.scene.remove(this.boxHelper), this.boxHelper = null), this.scene && (Y(this.scene), this.scene = null), this.renderer && (this.renderer.dispose(), this.renderer.domElement && this.renderer.domElement.remove(), this.renderer = null), this.control && (this.control.dispose(), this.control = null), this.camera = null, this.el = null, this.selector = null, console.log("ThreeIns: 资源已清理完成"));
417
+ this.isDispose || (this.isDispose = !0, this.animationFrameId && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = null), this.resizeTimer && (clearTimeout(this.resizeTimer), this.resizeTimer = null), this.removeListener(), this.eventsListener = {}, this.stats && this.stats.dom && (this.stats.dom.remove(), this.stats = null), this.css3dRenderer && (this.css3dRenderer.domElement.remove(), this.css3dRenderer = null), this.boxHelper && (this.scene.remove(this.boxHelper), this.boxHelper = null), this.scene && (X(this.scene), this.scene = null), this.renderer && (this.renderer.dispose(), this.renderer.domElement && this.renderer.domElement.remove(), this.renderer = null), this.control && (this.control.dispose(), this.control = null), this.camera = null, this.el = null, this.selector = null, console.log("ThreeIns: 资源已清理完成"));
427
418
  }
428
419
  }
429
420
  // 存储包围盒辅助器
430
421
  // 视角类型枚举(作为类静态属性引用,保持向后兼容)
431
- n(U, "ViewType", T);
422
+ o(J, "ViewType", v);
432
423
  export {
433
- ce as CacheMonitor,
424
+ he as CacheMonitor,
434
425
  de as ErrorType,
435
- he as IDBCache,
436
- Ie as ImageLoader,
437
- me as ModelLoadError,
438
- Ze as ModelOptimizer,
439
- xe as PredictiveLoader,
440
- fe as ProgressiveSceneBuilder,
441
- ge as RetryHelper,
442
- U as ThreeIns,
443
- T as ViewType,
444
- ue as cacheMonitor,
445
- pe as createArrowHelper,
446
- Fe as createAxesHelper,
447
- Re as createBox3Helper,
426
+ me as IDBCache,
427
+ qe as ImageLoader,
428
+ fe as ModelLoadError,
429
+ Je as ModelOptimizer,
430
+ ue as PredictiveLoader,
431
+ pe as ProgressiveSceneBuilder,
432
+ xe as RetryHelper,
433
+ J as ThreeIns,
434
+ v as ViewType,
435
+ ge as cacheMonitor,
436
+ Xe as cancelIdleTask,
437
+ Fe as clearGeometryCache,
438
+ Re as clearMaterialCache,
439
+ we as createArrowHelper,
440
+ be as createAxesHelper,
441
+ ze as createBox3Helper,
448
442
  Me as createCameraHelper,
449
- ze as createGridHelper,
450
- He as createInfoPlane,
451
- be as createMapControls,
452
- P as createOrbitControl,
453
- Ee as createRaycaster,
454
- Le as createStats,
455
- Ae as createTagPlane,
456
- Oe as dataToObject3D,
457
- we as dataToObject3DSync,
458
- Y as disposeThreeObject,
459
- Pe as getCommonParent,
460
- je as getObjectByUserData,
461
- Xe as getRootObj,
462
- Ye as initEnvImage,
463
- se as intersectColor,
464
- qe as modelOptimizer,
465
- oe as obbObjects,
466
- Ce as object3DToData,
467
- ye as object3DToDataSync,
468
- Te as predictiveLoader,
469
- Se as rebuildScene,
470
- ie as useBatchGLTFLoader,
471
- De as useGLTFLoader,
472
- ne as useObb,
473
- re as useRaycaster,
474
- ae as useThreeJs
443
+ Te as createGridHelper,
444
+ Ye as createInfoPlane,
445
+ Ee as createMapControls,
446
+ j as createOrbitControl,
447
+ Le as createRaycaster,
448
+ Oe as createStats,
449
+ Be as createTagPlane,
450
+ Ce as dataToObject3D,
451
+ ye as dataToObject3DSync,
452
+ X as disposeThreeObject,
453
+ Ze as getCommonParent,
454
+ ve as getGeometryCacheStats,
455
+ Ie as getMaterialCacheStats,
456
+ Ge as getObjectByUserData,
457
+ We as getRootObj,
458
+ _e as initEnvImage,
459
+ oe as intersectColor,
460
+ Ke as modelOptimizer,
461
+ ie as obbObjects,
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,
470
+ ne as useBatchGLTFLoader,
471
+ je as useGLTFLoader,
472
+ re as useObb,
473
+ ae as useRaycaster,
474
+ le as useThreeJs
475
475
  };