@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
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { Vector3 as
|
|
2
|
-
import { ref as
|
|
3
|
-
import { d as
|
|
1
|
+
import { Vector3 as x, Matrix3 as re, MathUtils as $, Box3 as Q, Matrix4 as ae, Ray as me, WebGLRenderer as pe, Scene as ye, PerspectiveCamera as be, Raycaster as xe, Vector2 as we, Color as ze } from "three";
|
|
2
|
+
import { ref as G, shallowRef as Se, onMounted as ge, onUnmounted as ve, nextTick as K } from "vue";
|
|
3
|
+
import { d as Me, j as Oe, S as Re, y as Ae, u as Te } from "./PredictiveLoader-Ce8DXwbW.js";
|
|
4
4
|
const l = {
|
|
5
5
|
c: null,
|
|
6
6
|
// center
|
|
7
|
-
u: [new
|
|
7
|
+
u: [new x(), new x(), new x()],
|
|
8
8
|
// basis vectors
|
|
9
9
|
e: []
|
|
10
10
|
// half width
|
|
11
|
-
},
|
|
11
|
+
}, h = {
|
|
12
12
|
c: null,
|
|
13
13
|
// center
|
|
14
|
-
u: [new
|
|
14
|
+
u: [new x(), new x(), new x()],
|
|
15
15
|
// basis vectors
|
|
16
16
|
e: []
|
|
17
17
|
// half width
|
|
18
|
-
}, y = [[], [], []], a = [[], [], []], p = [],
|
|
19
|
-
class
|
|
18
|
+
}, y = [[], [], []], a = [[], [], []], p = [], E = new x(), B = new x(), j = new x(), w = new x(), ee = new x(), te = new x(), M = new re(), ne = new Q(), X = new ae(), se = new ae(), oe = new me();
|
|
19
|
+
class N {
|
|
20
20
|
/**
|
|
21
21
|
* Constructs a new OBB.
|
|
22
22
|
*
|
|
@@ -24,7 +24,7 @@ class G {
|
|
|
24
24
|
* @param {Vector3} [halfSize] - Positive halfwidth extents of the OBB along each axis.
|
|
25
25
|
* @param {Matrix3} [rotation] - The rotation of the OBB.
|
|
26
26
|
*/
|
|
27
|
-
constructor(e = new
|
|
27
|
+
constructor(e = new x(), r = new x(), s = new re()) {
|
|
28
28
|
this.center = e, this.halfSize = r, this.rotation = s;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
@@ -73,13 +73,13 @@ class G {
|
|
|
73
73
|
*/
|
|
74
74
|
clampPoint(e, r) {
|
|
75
75
|
const s = this.halfSize;
|
|
76
|
-
|
|
77
|
-
const o =
|
|
78
|
-
r.add(
|
|
79
|
-
const t =
|
|
76
|
+
w.subVectors(e, this.center), this.rotation.extractBasis(E, B, j), r.copy(this.center);
|
|
77
|
+
const o = $.clamp(w.dot(E), -s.x, s.x);
|
|
78
|
+
r.add(E.multiplyScalar(o));
|
|
79
|
+
const t = $.clamp(w.dot(B), -s.y, s.y);
|
|
80
80
|
r.add(B.multiplyScalar(t));
|
|
81
|
-
const
|
|
82
|
-
return r.add(j.multiplyScalar(
|
|
81
|
+
const u = $.clamp(w.dot(j), -s.z, s.z);
|
|
82
|
+
return r.add(j.multiplyScalar(u)), r;
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* Returns `true` if the given point lies within this OBB.
|
|
@@ -88,7 +88,7 @@ class G {
|
|
|
88
88
|
* @returns {boolean} - Whether the given point lies within this OBB or not.
|
|
89
89
|
*/
|
|
90
90
|
containsPoint(e) {
|
|
91
|
-
return
|
|
91
|
+
return w.subVectors(e, this.center), this.rotation.extractBasis(E, B, j), Math.abs(w.dot(E)) <= this.halfSize.x && Math.abs(w.dot(B)) <= this.halfSize.y && Math.abs(w.dot(j)) <= this.halfSize.z;
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
94
|
* Returns `true` if the given AABB intersects this OBB.
|
|
@@ -116,20 +116,20 @@ class G {
|
|
|
116
116
|
* @returns {boolean} - Whether the given OBB intersects this OBB or not.
|
|
117
117
|
*/
|
|
118
118
|
intersectsOBB(e, r = Number.EPSILON) {
|
|
119
|
-
l.c = this.center, l.e[0] = this.halfSize.x, l.e[1] = this.halfSize.y, l.e[2] = this.halfSize.z, this.rotation.extractBasis(l.u[0], l.u[1], l.u[2]),
|
|
119
|
+
l.c = this.center, l.e[0] = this.halfSize.x, l.e[1] = this.halfSize.y, l.e[2] = this.halfSize.z, this.rotation.extractBasis(l.u[0], l.u[1], l.u[2]), h.c = e.center, h.e[0] = e.halfSize.x, h.e[1] = e.halfSize.y, h.e[2] = e.halfSize.z, e.rotation.extractBasis(h.u[0], h.u[1], h.u[2]);
|
|
120
120
|
for (let t = 0; t < 3; t++)
|
|
121
|
-
for (let
|
|
122
|
-
y[t][
|
|
123
|
-
|
|
121
|
+
for (let u = 0; u < 3; u++)
|
|
122
|
+
y[t][u] = l.u[t].dot(h.u[u]);
|
|
123
|
+
w.subVectors(h.c, l.c), p[0] = w.dot(l.u[0]), p[1] = w.dot(l.u[1]), p[2] = w.dot(l.u[2]);
|
|
124
124
|
for (let t = 0; t < 3; t++)
|
|
125
|
-
for (let
|
|
126
|
-
a[t][
|
|
125
|
+
for (let u = 0; u < 3; u++)
|
|
126
|
+
a[t][u] = Math.abs(y[t][u]) + r;
|
|
127
127
|
let s, o;
|
|
128
128
|
for (let t = 0; t < 3; t++)
|
|
129
|
-
if (s = l.e[t], o =
|
|
129
|
+
if (s = l.e[t], o = h.e[0] * a[t][0] + h.e[1] * a[t][1] + h.e[2] * a[t][2], Math.abs(p[t]) > s + o) return !1;
|
|
130
130
|
for (let t = 0; t < 3; t++)
|
|
131
|
-
if (s = l.e[0] * a[0][t] + l.e[1] * a[1][t] + l.e[2] * a[2][t], o =
|
|
132
|
-
return s = l.e[1] * a[2][0] + l.e[2] * a[1][0], o =
|
|
131
|
+
if (s = l.e[0] * a[0][t] + l.e[1] * a[1][t] + l.e[2] * a[2][t], o = h.e[t], Math.abs(p[0] * y[0][t] + p[1] * y[1][t] + p[2] * y[2][t]) > s + o) return !1;
|
|
132
|
+
return s = l.e[1] * a[2][0] + l.e[2] * a[1][0], o = h.e[1] * a[0][2] + h.e[2] * a[0][1], !(Math.abs(p[2] * y[1][0] - p[1] * y[2][0]) > s + o || (s = l.e[1] * a[2][1] + l.e[2] * a[1][1], o = h.e[0] * a[0][2] + h.e[2] * a[0][0], Math.abs(p[2] * y[1][1] - p[1] * y[2][1]) > s + o) || (s = l.e[1] * a[2][2] + l.e[2] * a[1][2], o = h.e[0] * a[0][1] + h.e[1] * a[0][0], Math.abs(p[2] * y[1][2] - p[1] * y[2][2]) > s + o) || (s = l.e[0] * a[2][0] + l.e[2] * a[0][0], o = h.e[1] * a[1][2] + h.e[2] * a[1][1], Math.abs(p[0] * y[2][0] - p[2] * y[0][0]) > s + o) || (s = l.e[0] * a[2][1] + l.e[2] * a[0][1], o = h.e[0] * a[1][2] + h.e[2] * a[1][0], Math.abs(p[0] * y[2][1] - p[2] * y[0][1]) > s + o) || (s = l.e[0] * a[2][2] + l.e[2] * a[0][2], o = h.e[0] * a[1][1] + h.e[1] * a[1][0], Math.abs(p[0] * y[2][2] - p[2] * y[0][2]) > s + o) || (s = l.e[0] * a[1][0] + l.e[1] * a[0][0], o = h.e[1] * a[2][2] + h.e[2] * a[2][1], Math.abs(p[1] * y[0][0] - p[0] * y[1][0]) > s + o) || (s = l.e[0] * a[1][1] + l.e[1] * a[0][1], o = h.e[0] * a[2][2] + h.e[2] * a[2][0], Math.abs(p[1] * y[0][1] - p[0] * y[1][1]) > s + o) || (s = l.e[0] * a[1][2] + l.e[1] * a[0][2], o = h.e[0] * a[2][1] + h.e[1] * a[2][0], Math.abs(p[1] * y[0][2] - p[0] * y[1][2]) > s + o));
|
|
133
133
|
}
|
|
134
134
|
/**
|
|
135
135
|
* Returns `true` if the given plane intersects this OBB.
|
|
@@ -138,8 +138,8 @@ class G {
|
|
|
138
138
|
* @returns {boolean} Whether the given plane intersects this OBB or not.
|
|
139
139
|
*/
|
|
140
140
|
intersectsPlane(e) {
|
|
141
|
-
this.rotation.extractBasis(
|
|
142
|
-
const r = this.halfSize.x * Math.abs(e.normal.dot(
|
|
141
|
+
this.rotation.extractBasis(E, B, j);
|
|
142
|
+
const r = this.halfSize.x * Math.abs(e.normal.dot(E)) + this.halfSize.y * Math.abs(e.normal.dot(B)) + this.halfSize.z * Math.abs(e.normal.dot(j)), s = e.normal.dot(this.center) - e.constant;
|
|
143
143
|
return Math.abs(s) <= r;
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
@@ -151,7 +151,7 @@ class G {
|
|
|
151
151
|
* @return {?Vector3} The intersection point. If no intersection is detected, `null` is returned.
|
|
152
152
|
*/
|
|
153
153
|
intersectRay(e, r) {
|
|
154
|
-
return this.getSize(ee), ne.setFromCenterAndSize(
|
|
154
|
+
return this.getSize(ee), ne.setFromCenterAndSize(w.set(0, 0, 0), ee), X.setFromMatrix3(this.rotation), X.setPosition(this.center), se.copy(X).invert(), oe.copy(e).applyMatrix4(se), oe.intersectBox(ne, r) ? r.applyMatrix4(X) : null;
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
157
|
* Returns `true` if the given ray intersects this OBB.
|
|
@@ -160,7 +160,7 @@ class G {
|
|
|
160
160
|
* @returns {boolean} Whether the given ray intersects this OBB or not.
|
|
161
161
|
*/
|
|
162
162
|
intersectsRay(e) {
|
|
163
|
-
return this.intersectRay(e,
|
|
163
|
+
return this.intersectRay(e, w) !== null;
|
|
164
164
|
}
|
|
165
165
|
/**
|
|
166
166
|
* Defines an OBB based on the given AABB.
|
|
@@ -190,22 +190,22 @@ class G {
|
|
|
190
190
|
*/
|
|
191
191
|
applyMatrix4(e) {
|
|
192
192
|
const r = e.elements;
|
|
193
|
-
let s =
|
|
194
|
-
const o =
|
|
195
|
-
e.determinant() < 0 && (s = -s),
|
|
193
|
+
let s = w.set(r[0], r[1], r[2]).length();
|
|
194
|
+
const o = w.set(r[4], r[5], r[6]).length(), t = w.set(r[8], r[9], r[10]).length();
|
|
195
|
+
e.determinant() < 0 && (s = -s), M.setFromMatrix4(e);
|
|
196
196
|
const c = 1 / s, n = 1 / o, i = 1 / t;
|
|
197
|
-
return
|
|
197
|
+
return M.elements[0] *= c, M.elements[1] *= c, M.elements[2] *= c, M.elements[3] *= n, M.elements[4] *= n, M.elements[5] *= n, M.elements[6] *= i, M.elements[7] *= i, M.elements[8] *= i, this.rotation.multiply(M), this.halfSize.x *= s, this.halfSize.y *= o, this.halfSize.z *= t, w.setFromMatrixPosition(e), this.center.add(w), this;
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
|
-
const Fe = new
|
|
200
|
+
const Fe = new N(), Pe = {
|
|
201
201
|
enableDamping: !0,
|
|
202
202
|
dampingFactor: 0.25,
|
|
203
203
|
screenSpacePanning: !1,
|
|
204
204
|
minDistance: 0.1,
|
|
205
205
|
maxDistance: 1e3,
|
|
206
|
-
maxPolarAngle:
|
|
206
|
+
maxPolarAngle: $.degToRad(60)
|
|
207
207
|
};
|
|
208
|
-
function
|
|
208
|
+
function De(P, e) {
|
|
209
209
|
typeof console < "u" && console.warn && console.warn(
|
|
210
210
|
`[ThreeIns] useThreeJs() Hook 已弃用,建议使用 ThreeIns 类代替。
|
|
211
211
|
旧用法: const { scene, camera } = useThreeJs(selector, options)
|
|
@@ -225,113 +225,132 @@ ThreeIns 类提供更完整的 API 和更好的性能。`
|
|
|
225
225
|
},
|
|
226
226
|
e || {}
|
|
227
227
|
);
|
|
228
|
-
let s, o, t,
|
|
229
|
-
const c =
|
|
228
|
+
let s, o, t, u = [];
|
|
229
|
+
const c = G(!1), n = Se(), i = G(0), f = G(0), d = new pe({
|
|
230
230
|
antialias: !0,
|
|
231
231
|
alpha: !0,
|
|
232
232
|
precision: "mediump",
|
|
233
233
|
logarithmicDepthBuffer: !0
|
|
234
|
-
}),
|
|
235
|
-
let
|
|
234
|
+
}), z = new ye({}), m = new be(50, 1, 0.1, 2e3), O = Math.tan(Math.PI / 180 * m.fov / 2);
|
|
235
|
+
let A = !1;
|
|
236
236
|
d.setPixelRatio(window.devicePixelRatio);
|
|
237
237
|
function L() {
|
|
238
238
|
c.value = !1;
|
|
239
|
-
const
|
|
240
|
-
i.value =
|
|
241
|
-
let
|
|
239
|
+
const b = J();
|
|
240
|
+
i.value = b[0], f.value = b[1], m.aspect = i.value / f.value, m.position.set(47, 39, 100), m.fov = 360 / Math.PI * Math.atan(O * (f.value / i.value)), m.lookAt(0, 0, 0), m.updateProjectionMatrix(), d.setSize(i.value, f.value), s.appendChild(d.domElement), r.stats && ie(), r.css3d && le();
|
|
241
|
+
let v;
|
|
242
242
|
if (r.control && r.control.init) {
|
|
243
|
-
|
|
244
|
-
const
|
|
243
|
+
v = Me(m, d.domElement);
|
|
244
|
+
const R = Object.assign(
|
|
245
245
|
Pe,
|
|
246
246
|
r.control.options || {}
|
|
247
247
|
);
|
|
248
|
-
Object.keys(
|
|
249
|
-
|
|
248
|
+
Object.keys(R).forEach((T) => {
|
|
249
|
+
v[T] = R[T];
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
|
-
return K(() => c.value = !0),
|
|
253
|
-
}
|
|
254
|
-
function
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
function
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
function
|
|
261
|
-
|
|
252
|
+
return K(() => c.value = !0), v;
|
|
253
|
+
}
|
|
254
|
+
function k(b) {
|
|
255
|
+
b.preventDefault(), cancelAnimationFrame(S);
|
|
256
|
+
}
|
|
257
|
+
function V(b) {
|
|
258
|
+
b.preventDefault(), L(), S();
|
|
259
|
+
}
|
|
260
|
+
function Y(b) {
|
|
261
|
+
return !b || typeof b != "function" ? (console.warn("useThreeJs.addAnimate: 无效的回调函数"), () => {
|
|
262
|
+
}) : (u.push(b), () => q(b));
|
|
263
|
+
}
|
|
264
|
+
function q(b) {
|
|
265
|
+
if (!b) return;
|
|
266
|
+
const v = u.indexOf(b);
|
|
267
|
+
v > -1 && u.splice(v, 1);
|
|
268
|
+
}
|
|
269
|
+
function S() {
|
|
270
|
+
const b = performance.now();
|
|
271
|
+
if (u && u.length) {
|
|
272
|
+
const R = u.length;
|
|
273
|
+
for (let T = 0; T < R; T++) {
|
|
274
|
+
const U = u[T];
|
|
275
|
+
if (typeof U == "function")
|
|
276
|
+
try {
|
|
277
|
+
U();
|
|
278
|
+
} catch (W) {
|
|
279
|
+
console.error("[useThreeJs] 动画回调执行错误:", W);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
r.renderType === "loop" && D();
|
|
284
|
+
const v = performance.now() - b;
|
|
285
|
+
v > 50 && r.debug && console.warn(`[useThreeJs] 帧耗时 ${v.toFixed(1)}ms,可能存在性能问题`), requestAnimationFrame(S);
|
|
262
286
|
}
|
|
263
|
-
function
|
|
264
|
-
|
|
265
|
-
typeof P == "function" && P();
|
|
266
|
-
}), r.renderType === "loop" && w(), requestAnimationFrame(R);
|
|
287
|
+
function D() {
|
|
288
|
+
A = !1, o && o.update(), n.value && n.value.update(), d.render(z, m), t && t.render(z, m);
|
|
267
289
|
}
|
|
268
|
-
function
|
|
269
|
-
|
|
290
|
+
function g() {
|
|
291
|
+
A || (A = !0, requestAnimationFrame(D));
|
|
270
292
|
}
|
|
271
293
|
function _() {
|
|
272
|
-
O || (O = !0, requestAnimationFrame(w));
|
|
273
|
-
}
|
|
274
|
-
function g() {
|
|
275
294
|
K(() => {
|
|
276
|
-
const
|
|
277
|
-
i.value =
|
|
295
|
+
const b = J();
|
|
296
|
+
i.value = b[0], f.value = b[1], m.aspect = i.value / f.value, m.fov = 360 / Math.PI * Math.atan(O * (f.value / i.value)), m.updateProjectionMatrix(), m.lookAt(z.position), d.setSize(i.value, f.value), t && t.setSize(i.value, f.value), D();
|
|
278
297
|
});
|
|
279
298
|
}
|
|
280
|
-
function
|
|
281
|
-
return s = document.querySelector(
|
|
282
|
-
}
|
|
283
|
-
function
|
|
284
|
-
o = new
|
|
285
|
-
}
|
|
286
|
-
function
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
const
|
|
290
|
-
x:
|
|
291
|
-
y:
|
|
292
|
-
z:
|
|
293
|
-
lookAt_x:
|
|
294
|
-
lookAt_y:
|
|
295
|
-
lookAt_z:
|
|
299
|
+
function J() {
|
|
300
|
+
return s = document.querySelector(P), s ? [s.clientWidth, s.clientHeight] : [0, 0];
|
|
301
|
+
}
|
|
302
|
+
function ie() {
|
|
303
|
+
o = new Re(), o.dom.style.cssText = "position:absolute;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000", s.appendChild(o.dom);
|
|
304
|
+
}
|
|
305
|
+
function ce(b, v, R, T, U) {
|
|
306
|
+
const W = new Q().setFromObject(b), Z = W.getSize(new x()).length(), C = W.getCenter(new x());
|
|
307
|
+
U && C.add(U);
|
|
308
|
+
const he = Z * v * 0.5, fe = $.degToRad(R.fov * 0.5), de = he / Math.tan(fe), H = new x().subVectors(R.position, C).multiply(new x(1, 1, 1)).normalize().multiplyScalar(de).add(C), I = {
|
|
309
|
+
x: H.x,
|
|
310
|
+
y: H.y,
|
|
311
|
+
z: H.z,
|
|
312
|
+
lookAt_x: C.x,
|
|
313
|
+
lookAt_y: C.y,
|
|
314
|
+
lookAt_z: C.z
|
|
296
315
|
};
|
|
297
|
-
return
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
),
|
|
302
|
-
}
|
|
303
|
-
function ce() {
|
|
304
|
-
t = new Re(), t.setSize(i.value, f.value), t.domElement.style.position = "absolute", t.domElement.style.top = 0, t.domElement.style.left = 0, t.domElement.style.pointerEvents = "none", s.appendChild(t.domElement);
|
|
316
|
+
return R.position.set(I.x, I.y, I.z), R.lookAt(
|
|
317
|
+
I.lookAt_x,
|
|
318
|
+
I.lookAt_y,
|
|
319
|
+
I.lookAt_z
|
|
320
|
+
), R.updateProjectionMatrix(), T.target.copy(C), T.update(), Z;
|
|
305
321
|
}
|
|
306
322
|
function le() {
|
|
307
|
-
|
|
323
|
+
t = new Ae(), t.setSize(i.value, f.value), t.domElement.style.position = "absolute", t.domElement.style.top = 0, t.domElement.style.left = 0, t.domElement.style.pointerEvents = "none", s.appendChild(t.domElement);
|
|
324
|
+
}
|
|
325
|
+
function ue() {
|
|
326
|
+
Oe(z);
|
|
308
327
|
}
|
|
309
|
-
return
|
|
310
|
-
n.value = L(), window.addEventListener("resize",
|
|
328
|
+
return ge(() => {
|
|
329
|
+
n.value = L(), window.addEventListener("resize", _, !1), d.domElement.addEventListener(
|
|
311
330
|
"webglcontextlost",
|
|
312
|
-
|
|
331
|
+
k,
|
|
313
332
|
!1
|
|
314
333
|
), d.domElement.addEventListener(
|
|
315
334
|
"webglcontextrestored",
|
|
316
|
-
|
|
335
|
+
V,
|
|
317
336
|
!1
|
|
318
|
-
), r.renderType === "loop" ? requestAnimationFrame(
|
|
319
|
-
}),
|
|
320
|
-
cancelAnimationFrame(
|
|
337
|
+
), r.renderType === "loop" ? requestAnimationFrame(S) : r.renderType === "change" && n.value && n.value.addEventListener("change", g);
|
|
338
|
+
}), ve(() => {
|
|
339
|
+
cancelAnimationFrame(S), d.domElement.removeEventListener("resize", _, !1), d.domElement.removeEventListener(
|
|
321
340
|
"webglcontextlost",
|
|
322
|
-
|
|
341
|
+
k,
|
|
323
342
|
!1
|
|
324
343
|
), d.domElement.removeEventListener(
|
|
325
344
|
"webglcontextrestored",
|
|
326
|
-
|
|
345
|
+
V,
|
|
327
346
|
!1
|
|
328
|
-
),
|
|
347
|
+
), ue();
|
|
329
348
|
}), {
|
|
330
|
-
addAnimate:
|
|
331
|
-
frameArea:
|
|
332
|
-
onRender:
|
|
349
|
+
addAnimate: Y,
|
|
350
|
+
frameArea: ce,
|
|
351
|
+
onRender: D,
|
|
333
352
|
css3dRenderer: t,
|
|
334
|
-
scene:
|
|
353
|
+
scene: z,
|
|
335
354
|
camera: m,
|
|
336
355
|
control: n,
|
|
337
356
|
renderer: d,
|
|
@@ -340,25 +359,25 @@ ThreeIns 类提供更完整的 API 和更好的性能。`
|
|
|
340
359
|
isReady: c
|
|
341
360
|
};
|
|
342
361
|
}
|
|
343
|
-
const
|
|
344
|
-
const e = new
|
|
362
|
+
const Ie = (P = "app") => {
|
|
363
|
+
const e = new xe();
|
|
345
364
|
e.params.Line.threshold = 8;
|
|
346
|
-
const r = new
|
|
365
|
+
const r = new we(), s = document.getElementById(P);
|
|
347
366
|
function o(c, n) {
|
|
348
|
-
const { scaleX: i, scaleY: f } =
|
|
349
|
-
return r.x = (c.clientX - m.left) /
|
|
367
|
+
const { scaleX: i, scaleY: f } = u(s), { clientWidth: d, clientHeight: z } = n, m = n.getBoundingClientRect(), O = d * i, A = z * f, L = c.clientX - m.left, k = c.clientY - m.top;
|
|
368
|
+
return r.x = (c.clientX - m.left) / O * 2 - 1, r.y = -((c.clientY - m.top) / A) * 2 + 1, { pointer: r, x: L, y: k };
|
|
350
369
|
}
|
|
351
370
|
function t(c, n, i, f) {
|
|
352
|
-
const { pointer: d, x, y: m } = o(c, n);
|
|
353
|
-
return e.setFromCamera(d, i), { intersects: e.intersectObjects(f), pointer: d, x, y: m };
|
|
371
|
+
const { pointer: d, x: z, y: m } = o(c, n);
|
|
372
|
+
return e.setFromCamera(d, i), { intersects: e.intersectObjects(f), pointer: d, x: z, y: m };
|
|
354
373
|
}
|
|
355
|
-
function
|
|
374
|
+
function u(c) {
|
|
356
375
|
const n = window.getComputedStyle(c), i = n.transform || n.webkitTransform || n.mozTransform;
|
|
357
376
|
if (i && i !== "none") {
|
|
358
377
|
const f = i.match(/^matrix\((.+)\)$/);
|
|
359
378
|
if (f) {
|
|
360
|
-
const d = f[1].split(", "),
|
|
361
|
-
return { scaleX:
|
|
379
|
+
const d = f[1].split(", "), z = parseFloat(d[0]), m = parseFloat(d[3]);
|
|
380
|
+
return { scaleX: z, scaleY: m };
|
|
362
381
|
}
|
|
363
382
|
}
|
|
364
383
|
return { scaleX: 1, scaleY: 1 };
|
|
@@ -367,103 +386,103 @@ const De = (F = "app") => {
|
|
|
367
386
|
raycaster: e,
|
|
368
387
|
pointer: r,
|
|
369
388
|
getPointer: o,
|
|
370
|
-
getScale:
|
|
389
|
+
getScale: u,
|
|
371
390
|
getIntersects: t
|
|
372
391
|
};
|
|
373
|
-
},
|
|
374
|
-
const
|
|
375
|
-
|
|
392
|
+
}, F = [], ke = new ze(16711680), qe = () => {
|
|
393
|
+
const P = () => {
|
|
394
|
+
F.splice(0);
|
|
376
395
|
}, e = (c, n) => {
|
|
377
396
|
n.traverse((i) => {
|
|
378
397
|
i && r(c, i);
|
|
379
398
|
});
|
|
380
399
|
}, r = (c, n) => {
|
|
381
400
|
if (n.userData.needCheck && (n.autoUpdateMatrix = !1, n.updateMatrix(), n.updateMatrixWorld(), n.isMesh)) {
|
|
382
|
-
const i = new
|
|
383
|
-
n.geometry.userData.obb = new
|
|
401
|
+
const i = new Q(new x()).setFromObject(n);
|
|
402
|
+
n.geometry.userData.obb = new N(), n.geometry.userData.obb.halfSize.copy(i.getSize(new x())).multiplyScalar(0.5).multiplyScalar(0.88), n.userData.obb = new N(), n.userData.originColor = n.material.color.clone(), n.userData.parentUid = c, F.push({
|
|
384
403
|
object: n,
|
|
385
404
|
parentUid: c
|
|
386
405
|
});
|
|
387
406
|
}
|
|
388
407
|
};
|
|
389
408
|
return {
|
|
390
|
-
resetObbs:
|
|
409
|
+
resetObbs: P,
|
|
391
410
|
initObb: e,
|
|
392
|
-
getObbObjectByParentUid: (c) =>
|
|
411
|
+
getObbObjectByParentUid: (c) => F.filter((n) => n.parentUid === c),
|
|
393
412
|
addObbFromArray: (c, n) => {
|
|
394
413
|
for (let i = 0, f = n.length; i < f; i++)
|
|
395
414
|
r(c, n[i]);
|
|
396
415
|
},
|
|
397
416
|
removeObbFromArray: (c) => {
|
|
398
|
-
const n =
|
|
399
|
-
|
|
417
|
+
const n = F.filter((i) => !c.includes(i.object));
|
|
418
|
+
F.splice(0, F.length, ...n);
|
|
400
419
|
},
|
|
401
420
|
removeUidObb: (c) => {
|
|
402
|
-
for (let n =
|
|
403
|
-
|
|
421
|
+
for (let n = F.length - 1; n >= 0; n--)
|
|
422
|
+
F[n].parentUid === c && F.splice(n, 1);
|
|
404
423
|
}
|
|
405
424
|
};
|
|
406
425
|
};
|
|
407
|
-
function
|
|
408
|
-
const { asyncFetch:
|
|
426
|
+
function Ue() {
|
|
427
|
+
const { asyncFetch: P } = Te();
|
|
409
428
|
async function e(o, t = {}) {
|
|
410
429
|
const {
|
|
411
|
-
maxConcurrent:
|
|
430
|
+
maxConcurrent: u = 3,
|
|
412
431
|
maxRetries: c = 3,
|
|
413
432
|
onProgress: n,
|
|
414
433
|
onModelLoad: i,
|
|
415
434
|
onModelError: f
|
|
416
|
-
} = t, d = /* @__PURE__ */ new Map(),
|
|
417
|
-
let
|
|
418
|
-
return new Promise((L,
|
|
419
|
-
const
|
|
420
|
-
const { path:
|
|
421
|
-
|
|
435
|
+
} = t, d = /* @__PURE__ */ new Map(), z = /* @__PURE__ */ new Map(), m = [...o];
|
|
436
|
+
let O = 0, A = 0;
|
|
437
|
+
return new Promise((L, k) => {
|
|
438
|
+
const V = async (q) => {
|
|
439
|
+
const { path: S, version: D } = q;
|
|
440
|
+
A++;
|
|
422
441
|
try {
|
|
423
|
-
const g = await
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
(
|
|
427
|
-
const
|
|
428
|
-
n == null || n(Math.round(
|
|
442
|
+
const g = await P(
|
|
443
|
+
S,
|
|
444
|
+
D,
|
|
445
|
+
(_) => {
|
|
446
|
+
const J = O / o.length * 100 + _ / o.length;
|
|
447
|
+
n == null || n(Math.round(J));
|
|
429
448
|
},
|
|
430
449
|
{ maxRetries: c }
|
|
431
450
|
);
|
|
432
451
|
if (g)
|
|
433
|
-
d.set(
|
|
452
|
+
d.set(S, g), i == null || i(S, g);
|
|
434
453
|
else
|
|
435
|
-
throw new Error(`模型加载返回空结果: ${
|
|
454
|
+
throw new Error(`模型加载返回空结果: ${S}`);
|
|
436
455
|
} catch (g) {
|
|
437
|
-
console.error(`[ 批量加载 ] 加载失败: ${
|
|
456
|
+
console.error(`[ 批量加载 ] 加载失败: ${S}`, g), z.set(S, g), f == null || f(S, g);
|
|
438
457
|
} finally {
|
|
439
|
-
|
|
440
|
-
const g =
|
|
441
|
-
n == null || n(Math.round(g)),
|
|
458
|
+
A--, O++;
|
|
459
|
+
const g = O / o.length * 100;
|
|
460
|
+
n == null || n(Math.round(g)), Y();
|
|
442
461
|
}
|
|
443
|
-
},
|
|
444
|
-
if (
|
|
445
|
-
|
|
462
|
+
}, Y = () => {
|
|
463
|
+
if (O >= o.length) {
|
|
464
|
+
z.size > 0 && console.warn(`[ 批量加载 ] 完成,但有 ${z.size} 个模型加载失败`), L(d);
|
|
446
465
|
return;
|
|
447
466
|
}
|
|
448
|
-
for (; m.length > 0 &&
|
|
449
|
-
const
|
|
450
|
-
|
|
467
|
+
for (; m.length > 0 && A < u; ) {
|
|
468
|
+
const q = m.shift();
|
|
469
|
+
V(q);
|
|
451
470
|
}
|
|
452
471
|
};
|
|
453
|
-
|
|
472
|
+
Y();
|
|
454
473
|
});
|
|
455
474
|
}
|
|
456
475
|
async function r(o, t = {}) {
|
|
457
476
|
console.log(`[ 批量预加载 ] 开始预加载 ${o.length} 个模型`);
|
|
458
|
-
const
|
|
477
|
+
const u = await e(o, {
|
|
459
478
|
...t,
|
|
460
479
|
maxConcurrent: t.maxConcurrent || 2
|
|
461
480
|
// 预加载使用较低的并发数
|
|
462
481
|
});
|
|
463
|
-
return console.log(`[ 批量预加载 ] 完成,成功加载 ${
|
|
482
|
+
return console.log(`[ 批量预加载 ] 完成,成功加载 ${u.size} 个模型`), u;
|
|
464
483
|
}
|
|
465
484
|
async function s(o, t = {}) {
|
|
466
|
-
const
|
|
485
|
+
const u = /* @__PURE__ */ new Map();
|
|
467
486
|
for (let c = 0; c < o.length; c++)
|
|
468
487
|
console.log(`[ 分组批量加载 ] 加载第 ${c + 1}/${o.length} 组`), (await e(o[c], {
|
|
469
488
|
...t,
|
|
@@ -473,9 +492,9 @@ function qe() {
|
|
|
473
492
|
(d = t.onProgress) == null || d.call(t, Math.round(f));
|
|
474
493
|
}
|
|
475
494
|
})).forEach((i, f) => {
|
|
476
|
-
|
|
495
|
+
u.set(f, i);
|
|
477
496
|
});
|
|
478
|
-
return
|
|
497
|
+
return u;
|
|
479
498
|
}
|
|
480
499
|
return {
|
|
481
500
|
batchLoad: e,
|
|
@@ -484,10 +503,10 @@ function qe() {
|
|
|
484
503
|
};
|
|
485
504
|
}
|
|
486
505
|
export {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
506
|
+
Ie as a,
|
|
507
|
+
qe as b,
|
|
508
|
+
Ue as c,
|
|
509
|
+
ke as i,
|
|
510
|
+
F as o,
|
|
511
|
+
De as u
|
|
493
512
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";const c=require("three"),C=require("vue"),$=require("./PredictiveLoader-c5o_CMyI.cjs"),u={c:null,u:[new c.Vector3,new c.Vector3,new c.Vector3],e:[]},f={c:null,u:[new c.Vector3,new c.Vector3,new c.Vector3],e:[]},b=[[],[],[]],a=[[],[],[]],y=[],V=new c.Vector3,B=new c.Vector3,j=new c.Vector3,w=new c.Vector3,Z=new c.Vector3,K=new c.Vector3,M=new c.Matrix3,ee=new c.Box3,X=new c.Matrix4,te=new c.Matrix4,ne=new c.Ray;class N{constructor(e=new c.Vector3,r=new c.Vector3,s=new c.Matrix3){this.center=e,this.halfSize=r,this.rotation=s}set(e,r,s){return this.center=e,this.halfSize=r,this.rotation=s,this}copy(e){return this.center.copy(e.center),this.halfSize.copy(e.halfSize),this.rotation.copy(e.rotation),this}clone(){return new this.constructor().copy(this)}getSize(e){return e.copy(this.halfSize).multiplyScalar(2)}clampPoint(e,r){const s=this.halfSize;w.subVectors(e,this.center),this.rotation.extractBasis(V,B,j),r.copy(this.center);const o=c.MathUtils.clamp(w.dot(V),-s.x,s.x);r.add(V.multiplyScalar(o));const t=c.MathUtils.clamp(w.dot(B),-s.y,s.y);r.add(B.multiplyScalar(t));const h=c.MathUtils.clamp(w.dot(j),-s.z,s.z);return r.add(j.multiplyScalar(h)),r}containsPoint(e){return w.subVectors(e,this.center),this.rotation.extractBasis(V,B,j),Math.abs(w.dot(V))<=this.halfSize.x&&Math.abs(w.dot(B))<=this.halfSize.y&&Math.abs(w.dot(j))<=this.halfSize.z}intersectsBox3(e){return this.intersectsOBB(ue.fromBox3(e))}intersectsSphere(e){return this.clampPoint(e.center,K),K.distanceToSquared(e.center)<=e.radius*e.radius}intersectsOBB(e,r=Number.EPSILON){u.c=this.center,u.e[0]=this.halfSize.x,u.e[1]=this.halfSize.y,u.e[2]=this.halfSize.z,this.rotation.extractBasis(u.u[0],u.u[1],u.u[2]),f.c=e.center,f.e[0]=e.halfSize.x,f.e[1]=e.halfSize.y,f.e[2]=e.halfSize.z,e.rotation.extractBasis(f.u[0],f.u[1],f.u[2]);for(let t=0;t<3;t++)for(let h=0;h<3;h++)b[t][h]=u.u[t].dot(f.u[h]);w.subVectors(f.c,u.c),y[0]=w.dot(u.u[0]),y[1]=w.dot(u.u[1]),y[2]=w.dot(u.u[2]);for(let t=0;t<3;t++)for(let h=0;h<3;h++)a[t][h]=Math.abs(b[t][h])+r;let s,o;for(let t=0;t<3;t++)if(s=u.e[t],o=f.e[0]*a[t][0]+f.e[1]*a[t][1]+f.e[2]*a[t][2],Math.abs(y[t])>s+o)return!1;for(let t=0;t<3;t++)if(s=u.e[0]*a[0][t]+u.e[1]*a[1][t]+u.e[2]*a[2][t],o=f.e[t],Math.abs(y[0]*b[0][t]+y[1]*b[1][t]+y[2]*b[2][t])>s+o)return!1;return s=u.e[1]*a[2][0]+u.e[2]*a[1][0],o=f.e[1]*a[0][2]+f.e[2]*a[0][1],!(Math.abs(y[2]*b[1][0]-y[1]*b[2][0])>s+o||(s=u.e[1]*a[2][1]+u.e[2]*a[1][1],o=f.e[0]*a[0][2]+f.e[2]*a[0][0],Math.abs(y[2]*b[1][1]-y[1]*b[2][1])>s+o)||(s=u.e[1]*a[2][2]+u.e[2]*a[1][2],o=f.e[0]*a[0][1]+f.e[1]*a[0][0],Math.abs(y[2]*b[1][2]-y[1]*b[2][2])>s+o)||(s=u.e[0]*a[2][0]+u.e[2]*a[0][0],o=f.e[1]*a[1][2]+f.e[2]*a[1][1],Math.abs(y[0]*b[2][0]-y[2]*b[0][0])>s+o)||(s=u.e[0]*a[2][1]+u.e[2]*a[0][1],o=f.e[0]*a[1][2]+f.e[2]*a[1][0],Math.abs(y[0]*b[2][1]-y[2]*b[0][1])>s+o)||(s=u.e[0]*a[2][2]+u.e[2]*a[0][2],o=f.e[0]*a[1][1]+f.e[1]*a[1][0],Math.abs(y[0]*b[2][2]-y[2]*b[0][2])>s+o)||(s=u.e[0]*a[1][0]+u.e[1]*a[0][0],o=f.e[1]*a[2][2]+f.e[2]*a[2][1],Math.abs(y[1]*b[0][0]-y[0]*b[1][0])>s+o)||(s=u.e[0]*a[1][1]+u.e[1]*a[0][1],o=f.e[0]*a[2][2]+f.e[2]*a[2][0],Math.abs(y[1]*b[0][1]-y[0]*b[1][1])>s+o)||(s=u.e[0]*a[1][2]+u.e[1]*a[0][2],o=f.e[0]*a[2][1]+f.e[1]*a[2][0],Math.abs(y[1]*b[0][2]-y[0]*b[1][2])>s+o))}intersectsPlane(e){this.rotation.extractBasis(V,B,j);const r=this.halfSize.x*Math.abs(e.normal.dot(V))+this.halfSize.y*Math.abs(e.normal.dot(B))+this.halfSize.z*Math.abs(e.normal.dot(j)),s=e.normal.dot(this.center)-e.constant;return Math.abs(s)<=r}intersectRay(e,r){return this.getSize(Z),ee.setFromCenterAndSize(w.set(0,0,0),Z),X.setFromMatrix3(this.rotation),X.setPosition(this.center),te.copy(X).invert(),ne.copy(e).applyMatrix4(te),ne.intersectBox(ee,r)?r.applyMatrix4(X):null}intersectsRay(e){return this.intersectRay(e,w)!==null}fromBox3(e){return e.getCenter(this.center),e.getSize(this.halfSize).multiplyScalar(.5),this.rotation.identity(),this}equals(e){return e.center.equals(this.center)&&e.halfSize.equals(this.halfSize)&&e.rotation.equals(this.rotation)}applyMatrix4(e){const r=e.elements;let s=w.set(r[0],r[1],r[2]).length();const o=w.set(r[4],r[5],r[6]).length(),t=w.set(r[8],r[9],r[10]).length();e.determinant()<0&&(s=-s),M.setFromMatrix4(e);const l=1/s,n=1/o,i=1/t;return M.elements[0]*=l,M.elements[1]*=l,M.elements[2]*=l,M.elements[3]*=n,M.elements[4]*=n,M.elements[5]*=n,M.elements[6]*=i,M.elements[7]*=i,M.elements[8]*=i,this.rotation.multiply(M),this.halfSize.x*=s,this.halfSize.y*=o,this.halfSize.z*=t,w.setFromMatrixPosition(e),this.center.add(w),this}}const ue=new N,he={enableDamping:!0,dampingFactor:.25,screenSpacePanning:!1,minDistance:.1,maxDistance:1e3,maxPolarAngle:c.MathUtils.degToRad(60)};function fe(P,e){typeof console<"u"&&console.warn&&console.warn(`[ThreeIns] useThreeJs() Hook 已弃用,建议使用 ThreeIns 类代替。
|
|
2
|
+
旧用法: const { scene, camera } = useThreeJs(selector, options)
|
|
3
|
+
新用法: const threeIns = new ThreeIns(selector, options)
|
|
4
|
+
|
|
5
|
+
ThreeIns 类提供更完整的 API 和更好的性能。`);const r=Object.assign({css3d:!1,stats:!1,renderType:"change",control:{init:!0,options:{}}},e||{});let s,o,t,h=[];const l=C.ref(!1),n=C.shallowRef(),i=C.ref(0),d=C.ref(0),m=new c.WebGLRenderer({antialias:!0,alpha:!0,precision:"mediump",logarithmicDepthBuffer:!0}),z=new c.Scene({}),p=new c.PerspectiveCamera(50,1,.1,2e3),O=Math.tan(Math.PI/180*p.fov/2);let A=!1;m.setPixelRatio(window.devicePixelRatio);function L(){l.value=!1;const x=H();i.value=x[0],d.value=x[1],p.aspect=i.value/d.value,p.position.set(47,39,100),p.fov=360/Math.PI*Math.atan(O*(d.value/i.value)),p.lookAt(0,0,0),p.updateProjectionMatrix(),m.setSize(i.value,d.value),s.appendChild(m.domElement),r.stats&&se(),r.css3d&&re();let v;if(r.control&&r.control.init){v=$.createOrbitControl(p,m.domElement);const T=Object.assign(he,r.control.options||{});Object.keys(T).forEach(F=>{v[F]=T[F]})}return C.nextTick(()=>l.value=!0),v}function k(x){x.preventDefault(),cancelAnimationFrame(S)}function J(x){x.preventDefault(),L(),S()}function Y(x){return!x||typeof x!="function"?(console.warn("useThreeJs.addAnimate: 无效的回调函数"),()=>{}):(h.push(x),()=>I(x))}function I(x){if(!x)return;const v=h.indexOf(x);v>-1&&h.splice(v,1)}function S(){const x=performance.now();if(h&&h.length){const T=h.length;for(let F=0;F<T;F++){const U=h[F];if(typeof U=="function")try{U()}catch(W){console.error("[useThreeJs] 动画回调执行错误:",W)}}}r.renderType==="loop"&&q();const v=performance.now()-x;v>50&&r.debug&&console.warn(`[useThreeJs] 帧耗时 ${v.toFixed(1)}ms,可能存在性能问题`),requestAnimationFrame(S)}function q(){A=!1,o&&o.update(),n.value&&n.value.update(),m.render(z,p),t&&t.render(z,p)}function g(){A||(A=!0,requestAnimationFrame(q))}function _(){C.nextTick(()=>{const x=H();i.value=x[0],d.value=x[1],p.aspect=i.value/d.value,p.fov=360/Math.PI*Math.atan(O*(d.value/i.value)),p.updateProjectionMatrix(),p.lookAt(z.position),m.setSize(i.value,d.value),t&&t.setSize(i.value,d.value),q()})}function H(){return s=document.querySelector(P),s?[s.clientWidth,s.clientHeight]:[0,0]}function se(){o=new $.Stats,o.dom.style.cssText="position:absolute;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000",s.appendChild(o.dom)}function oe(x,v,T,F,U){const W=new c.Box3().setFromObject(x),Q=W.getSize(new c.Vector3).length(),E=W.getCenter(new c.Vector3);U&&E.add(U);const ie=Q*v*.5,ce=c.MathUtils.degToRad(T.fov*.5),le=ie/Math.tan(ce),G=new c.Vector3().subVectors(T.position,E).multiply(new c.Vector3(1,1,1)).normalize().multiplyScalar(le).add(E),D={x:G.x,y:G.y,z:G.z,lookAt_x:E.x,lookAt_y:E.y,lookAt_z:E.z};return T.position.set(D.x,D.y,D.z),T.lookAt(D.lookAt_x,D.lookAt_y,D.lookAt_z),T.updateProjectionMatrix(),F.target.copy(E),F.update(),Q}function re(){t=new $.CSS3DRenderer,t.setSize(i.value,d.value),t.domElement.style.position="absolute",t.domElement.style.top=0,t.domElement.style.left=0,t.domElement.style.pointerEvents="none",s.appendChild(t.domElement)}function ae(){$.disposeThreeObject(z)}return C.onMounted(()=>{n.value=L(),window.addEventListener("resize",_,!1),m.domElement.addEventListener("webglcontextlost",k,!1),m.domElement.addEventListener("webglcontextrestored",J,!1),r.renderType==="loop"?requestAnimationFrame(S):r.renderType==="change"&&n.value&&n.value.addEventListener("change",g)}),C.onUnmounted(()=>{cancelAnimationFrame(S),m.domElement.removeEventListener("resize",_,!1),m.domElement.removeEventListener("webglcontextlost",k,!1),m.domElement.removeEventListener("webglcontextrestored",J,!1),ae()}),{addAnimate:Y,frameArea:oe,onRender:q,css3dRenderer:t,scene:z,camera:p,control:n,renderer:m,domWidth:i,domHeight:d,isReady:l}}const de=(P="app")=>{const e=new c.Raycaster;e.params.Line.threshold=8;const r=new c.Vector2,s=document.getElementById(P);function o(l,n){const{scaleX:i,scaleY:d}=h(s),{clientWidth:m,clientHeight:z}=n,p=n.getBoundingClientRect(),O=m*i,A=z*d,L=l.clientX-p.left,k=l.clientY-p.top;return r.x=(l.clientX-p.left)/O*2-1,r.y=-((l.clientY-p.top)/A)*2+1,{pointer:r,x:L,y:k}}function t(l,n,i,d){const{pointer:m,x:z,y:p}=o(l,n);return e.setFromCamera(m,i),{intersects:e.intersectObjects(d),pointer:m,x:z,y:p}}function h(l){const n=window.getComputedStyle(l),i=n.transform||n.webkitTransform||n.mozTransform;if(i&&i!=="none"){const d=i.match(/^matrix\((.+)\)$/);if(d){const m=d[1].split(", "),z=parseFloat(m[0]),p=parseFloat(m[3]);return{scaleX:z,scaleY:p}}}return{scaleX:1,scaleY:1}}return{raycaster:e,pointer:r,getPointer:o,getScale:h,getIntersects:t}},R=[],me=new c.Color(16711680),pe=()=>{const P=()=>{R.splice(0)},e=(l,n)=>{n.traverse(i=>{i&&r(l,i)})},r=(l,n)=>{if(n.userData.needCheck&&(n.autoUpdateMatrix=!1,n.updateMatrix(),n.updateMatrixWorld(),n.isMesh)){const i=new c.Box3(new c.Vector3).setFromObject(n);n.geometry.userData.obb=new N,n.geometry.userData.obb.halfSize.copy(i.getSize(new c.Vector3)).multiplyScalar(.5).multiplyScalar(.88),n.userData.obb=new N,n.userData.originColor=n.material.color.clone(),n.userData.parentUid=l,R.push({object:n,parentUid:l})}};return{resetObbs:P,initObb:e,getObbObjectByParentUid:l=>R.filter(n=>n.parentUid===l),addObbFromArray:(l,n)=>{for(let i=0,d=n.length;i<d;i++)r(l,n[i])},removeObbFromArray:l=>{const n=R.filter(i=>!l.includes(i.object));R.splice(0,R.length,...n)},removeUidObb:l=>{for(let n=R.length-1;n>=0;n--)R[n].parentUid===l&&R.splice(n,1)}}};function ye(){const{asyncFetch:P}=$.useGLTFLoader();async function e(o,t={}){const{maxConcurrent:h=3,maxRetries:l=3,onProgress:n,onModelLoad:i,onModelError:d}=t,m=new Map,z=new Map,p=[...o];let O=0,A=0;return new Promise((L,k)=>{const J=async I=>{const{path:S,version:q}=I;A++;try{const g=await P(S,q,_=>{const H=O/o.length*100+_/o.length;n==null||n(Math.round(H))},{maxRetries:l});if(g)m.set(S,g),i==null||i(S,g);else throw new Error(`模型加载返回空结果: ${S}`)}catch(g){console.error(`[ 批量加载 ] 加载失败: ${S}`,g),z.set(S,g),d==null||d(S,g)}finally{A--,O++;const g=O/o.length*100;n==null||n(Math.round(g)),Y()}},Y=()=>{if(O>=o.length){z.size>0&&console.warn(`[ 批量加载 ] 完成,但有 ${z.size} 个模型加载失败`),L(m);return}for(;p.length>0&&A<h;){const I=p.shift();J(I)}};Y()})}async function r(o,t={}){console.log(`[ 批量预加载 ] 开始预加载 ${o.length} 个模型`);const h=await e(o,{...t,maxConcurrent:t.maxConcurrent||2});return console.log(`[ 批量预加载 ] 完成,成功加载 ${h.size} 个模型`),h}async function s(o,t={}){const h=new Map;for(let l=0;l<o.length;l++)console.log(`[ 分组批量加载 ] 加载第 ${l+1}/${o.length} 组`),(await e(o[l],{...t,onProgress:i=>{var m;const d=l/o.length*100+i/o.length;(m=t.onProgress)==null||m.call(t,Math.round(d))}})).forEach((i,d)=>{h.set(d,i)});return h}return{batchLoad:e,preload:r,batchLoadGroups:s}}exports.intersectColor=me;exports.obbObjects=R;exports.useBatchGLTFLoader=ye;exports.useObb=pe;exports.useRaycaster=de;exports.useThreeJs=fe;
|
package/dist/utils.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./PredictiveLoader-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./PredictiveLoader-c5o_CMyI.cjs"),r=require("./objectQuery-DFqBNl0a.cjs"),t=require("./modelOptimizer-_7Yr0hPn.cjs");exports.CacheMonitor=e.CacheMonitor;exports.ErrorType=e.ErrorType;exports.ModelLoadError=e.ModelLoadError;exports.PredictiveLoader=e.PredictiveLoader;exports.ProgressiveSceneBuilder=e.ProgressiveSceneBuilder;exports.RetryHelper=e.RetryHelper;exports.cacheMonitor=e.cacheMonitor;exports.clearGeometryCache=e.clearGeometryCache;exports.clearMaterialCache=e.clearMaterialCache;exports.createArrowHelper=e.createArrowHelper;exports.createAxesHelper=e.createAxesHelper;exports.createBox3Helper=e.createBox3Helper;exports.createCameraHelper=e.createCameraHelper;exports.createGridHelper=e.createGridHelper;exports.createMapControls=e.createMapControls;exports.createOrbitControl=e.createOrbitControl;exports.createRaycaster=e.createRaycaster;exports.createStats=e.createStats;exports.dataToObject3D=e.dataToObject3D;exports.dataToObject3DSync=e.dataToObject3DSync;exports.disposeThreeObject=e.disposeThreeObject;exports.getGeometryCacheStats=e.getGeometryCacheStats;exports.getMaterialCacheStats=e.getMaterialCacheStats;exports.object3DToData=e.object3DToData;exports.object3DToDataSync=e.object3DToDataSync;exports.object3DToTransferable=e.object3DToTransferable;exports.predictiveLoader=e.predictiveLoader;exports.rebuildScene=e.rebuildScene;exports.ImageLoader=r.ImageLoader;exports.cancelIdleTask=r.cancelIdleTask;exports.createInfoPlane=r.createInfoPlane;exports.createTagPlane=r.createTagPlane;exports.getCommonParent=r.getCommonParent;exports.getObjectByUserData=r.getObjectByUserData;exports.getRootObj=r.getRootObj;exports.initEnvImage=r.initEnvImage;exports.processInChunks=r.processInChunks;exports.runWhenIdle=r.runWhenIdle;exports.throttle=r.throttle;exports.ModelOptimizer=t.ModelOptimizer;exports.modelOptimizer=t.modelOptimizer;
|