@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/{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 +212 -212
- 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} +11 -378
- 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
1
|
var H = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { i as
|
|
5
|
-
import { d as
|
|
6
|
-
import { C as
|
|
7
|
-
import { I as
|
|
8
|
-
import { ModelOptimizer as
|
|
9
|
-
import { MathUtils as
|
|
10
|
-
const
|
|
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
|
-
},
|
|
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:
|
|
25
|
+
maxPolarAngle: F.degToRad(60)
|
|
26
26
|
};
|
|
27
|
-
class
|
|
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(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
74
|
-
if (this.isDispose = !1, this.selector =
|
|
75
|
-
console.error(`ThreeIns: 找不到元素 ${
|
|
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 [
|
|
79
|
-
if (this.updateCameraFOV(
|
|
80
|
-
this.control =
|
|
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
|
-
|
|
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(() => {
|
|
90
90
|
this.isReady = !0;
|
|
91
|
-
},
|
|
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
|
-
|
|
101
|
-
|
|
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
|
-
|
|
108
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,10 +176,10 @@ class U {
|
|
|
160
176
|
/**
|
|
161
177
|
* 处理窗口大小变化(带防抖)
|
|
162
178
|
*/
|
|
163
|
-
|
|
179
|
+
o(this, "onResize", () => {
|
|
164
180
|
this.resizeTimer && clearTimeout(this.resizeTimer), this.resizeTimer = setTimeout(() => {
|
|
165
|
-
const [
|
|
166
|
-
this.updateCameraFOV(
|
|
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
|
-
|
|
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(
|
|
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
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
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
|
-
|
|
280
|
-
let s =
|
|
281
|
-
const
|
|
282
|
-
let
|
|
283
|
-
if (typeof
|
|
284
|
-
const i =
|
|
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
|
-
},
|
|
291
|
-
|
|
292
|
-
} else
|
|
293
|
-
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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 =
|
|
324
|
-
|
|
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
|
|
327
|
-
if (
|
|
328
|
-
const i = this.camera.position.clone(),
|
|
329
|
-
const
|
|
330
|
-
if (this.camera.position.lerpVectors(i,
|
|
331
|
-
const
|
|
332
|
-
|
|
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(
|
|
335
|
-
this.camera.updateProjectionMatrix(), C < 1 ? requestAnimationFrame(
|
|
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
|
-
|
|
313
|
+
O();
|
|
338
314
|
} else
|
|
339
|
-
this.camera.position.copy(
|
|
340
|
-
if (
|
|
341
|
-
if (console.log("🎥 视角切换信息:"), console.log(" - 视角类型:",
|
|
342
|
-
const i =
|
|
343
|
-
console.log(" - 模型 X 尺寸 (宽度):",
|
|
344
|
-
} else if (
|
|
345
|
-
const i =
|
|
346
|
-
console.log(" -
|
|
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 =
|
|
352
|
-
console.log(" - 模型 X 尺寸 (宽度):",
|
|
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(" - 最终距离:",
|
|
327
|
+
console.log(" - 最终距离:", u.toFixed(2)), console.log(" - 缩放比例:", s), console.log(" - 动画:", M ? "是 (" + T + "ms)" : "否");
|
|
355
328
|
}
|
|
356
329
|
return {
|
|
357
|
-
position:
|
|
358
|
-
target:
|
|
359
|
-
distance:
|
|
360
|
-
viewType:
|
|
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
|
-
|
|
370
|
-
}) : (this.eventsListener[
|
|
371
|
-
|
|
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 =
|
|
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(
|
|
385
|
-
const
|
|
386
|
-
this.camera.aspect =
|
|
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
|
|
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
|
|
399
|
-
const [
|
|
400
|
-
this.css3dRenderer.setSize(
|
|
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(
|
|
416
|
-
if (!
|
|
406
|
+
off(e, t) {
|
|
407
|
+
if (!e) {
|
|
417
408
|
this.eventsListener = {};
|
|
418
409
|
return;
|
|
419
410
|
}
|
|
420
|
-
this.eventsListener[
|
|
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 && (
|
|
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
|
-
|
|
422
|
+
o(J, "ViewType", v);
|
|
432
423
|
export {
|
|
433
|
-
|
|
424
|
+
he as CacheMonitor,
|
|
434
425
|
de as ErrorType,
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
Fe as
|
|
447
|
-
Re as
|
|
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
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
oe as
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
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
|
};
|