@ridp/threejs 1.4.1 → 1.4.3
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/{readme.md → README.md} +228 -26
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.js +12 -9
- package/dist/packages/threejs/package.json.cjs +1 -0
- package/dist/packages/threejs/package.json.js +4 -0
- package/dist/packages/threejs/src/hooks/useBatchGLTFLoader.cjs +1 -0
- package/dist/packages/threejs/src/hooks/useBatchGLTFLoader.js +83 -0
- package/dist/packages/threejs/src/hooks/useGLTFLoader.cjs +1 -0
- package/dist/packages/threejs/src/hooks/useGLTFLoader.js +292 -0
- package/dist/packages/threejs/src/hooks/useObb.cjs +1 -0
- package/dist/packages/threejs/src/hooks/useObb.js +41 -0
- package/dist/packages/threejs/src/hooks/useRaycaster.cjs +1 -0
- package/dist/packages/threejs/src/hooks/useRaycaster.js +35 -0
- package/dist/packages/threejs/src/hooks/useThreeJs.cjs +5 -0
- package/dist/packages/threejs/src/hooks/useThreeJs.js +153 -0
- package/dist/packages/threejs/src/instance/IDBCache.cjs +1 -0
- package/dist/packages/threejs/src/instance/IDBCache.js +142 -0
- package/dist/packages/threejs/src/instance/threeIns.cjs +3 -0
- package/dist/packages/threejs/src/instance/threeIns.js +393 -0
- package/dist/packages/threejs/src/utils/CacheMonitor.cjs +1 -0
- package/dist/packages/threejs/src/utils/CacheMonitor.js +125 -0
- package/dist/packages/threejs/src/utils/ImageLoader.cjs +1 -0
- package/dist/packages/threejs/src/utils/ImageLoader.js +33 -0
- package/dist/packages/threejs/src/utils/PredictiveLoader.cjs +1 -0
- package/dist/packages/threejs/src/utils/PredictiveLoader.js +155 -0
- package/dist/packages/threejs/src/utils/RetryHelper.cjs +1 -0
- package/dist/packages/threejs/src/utils/RetryHelper.js +108 -0
- package/dist/packages/threejs/src/utils/common.cjs +1 -0
- package/dist/packages/threejs/src/utils/common.js +15 -0
- package/dist/packages/threejs/src/utils/css3dHelper.cjs +15 -0
- package/dist/packages/threejs/src/utils/css3dHelper.js +42 -0
- package/dist/packages/threejs/src/utils/disposeObject.cjs +1 -0
- package/dist/packages/threejs/src/utils/disposeObject.js +13 -0
- package/dist/packages/threejs/src/utils/helper.cjs +1 -0
- package/dist/packages/threejs/src/utils/helper.js +47 -0
- package/dist/packages/threejs/src/utils/modelSerialize.cjs +1 -0
- package/dist/packages/threejs/src/utils/modelSerialize.js +225 -0
- package/dist/packages/threejs/src/utils/sceneRebuilder.cjs +1 -0
- package/dist/packages/threejs/src/utils/sceneRebuilder.js +138 -0
- package/dist/packages/threejs/src/workers/gltfParser.worker.cjs +1 -0
- package/dist/packages/threejs/src/workers/gltfParser.worker.js +11 -0
- package/dist/packages/threejs/src/workers/gltfParserOptimized.worker.cjs +1 -0
- package/dist/packages/threejs/src/workers/gltfParserOptimized.worker.js +11 -0
- package/dist/threejs.cjs +1 -3
- package/dist/threejs.js +58 -404
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +40 -32
- package/package.json +1 -1
- package/dist/ImageLoader-Br_nvMOg.js +0 -1444
- package/dist/ImageLoader-DL32KyTh.cjs +0 -24
- package/dist/PredictiveLoader-CZfMSjv-.js +0 -3731
- package/dist/PredictiveLoader-DDxh7dDg.cjs +0 -2
- package/dist/useBatchGLTFLoader-B5EUagWI.js +0 -493
- package/dist/useBatchGLTFLoader-BjAvIpyB.cjs +0 -5
- /package/dist/{modelOptimizer-A0Cs6f9e.cjs → packages/threejs/src/utils/modelOptimizer.cjs} +0 -0
- /package/dist/{modelOptimizer-BRPnM2RH.js → packages/threejs/src/utils/modelOptimizer.js} +0 -0
|
@@ -1,493 +0,0 @@
|
|
|
1
|
-
import { Vector3 as b, Matrix3 as re, MathUtils as q, Box3 as J, Matrix4 as ae, Ray as de, WebGLRenderer as me, Scene as pe, PerspectiveCamera as ye, Raycaster as be, Vector2 as ze, Color as xe } from "three";
|
|
2
|
-
import { ref as H, shallowRef as Se, onMounted as we, onUnmounted as ge, nextTick as K } from "vue";
|
|
3
|
-
import { d as ve, j as Me, S as Oe, s as Re, u as Ae } from "./PredictiveLoader-CZfMSjv-.js";
|
|
4
|
-
const l = {
|
|
5
|
-
c: null,
|
|
6
|
-
// center
|
|
7
|
-
u: [new b(), new b(), new b()],
|
|
8
|
-
// basis vectors
|
|
9
|
-
e: []
|
|
10
|
-
// half width
|
|
11
|
-
}, u = {
|
|
12
|
-
c: null,
|
|
13
|
-
// center
|
|
14
|
-
u: [new b(), new b(), new b()],
|
|
15
|
-
// basis vectors
|
|
16
|
-
e: []
|
|
17
|
-
// half width
|
|
18
|
-
}, y = [[], [], []], a = [[], [], []], p = [], T = new b(), B = new b(), j = new b(), z = new b(), ee = new b(), te = new b(), v = new re(), ne = new J(), Y = new ae(), se = new ae(), oe = new de();
|
|
19
|
-
class G {
|
|
20
|
-
/**
|
|
21
|
-
* Constructs a new OBB.
|
|
22
|
-
*
|
|
23
|
-
* @param {Vector3} [center] - The center of the OBB.
|
|
24
|
-
* @param {Vector3} [halfSize] - Positive halfwidth extents of the OBB along each axis.
|
|
25
|
-
* @param {Matrix3} [rotation] - The rotation of the OBB.
|
|
26
|
-
*/
|
|
27
|
-
constructor(e = new b(), r = new b(), s = new re()) {
|
|
28
|
-
this.center = e, this.halfSize = r, this.rotation = s;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Sets the OBBs components to the given values.
|
|
32
|
-
*
|
|
33
|
-
* @param {Vector3} [center] - The center of the OBB.
|
|
34
|
-
* @param {Vector3} [halfSize] - Positive halfwidth extents of the OBB along each axis.
|
|
35
|
-
* @param {Matrix3} [rotation] - The rotation of the OBB.
|
|
36
|
-
* @return {OBB} A reference to this OBB.
|
|
37
|
-
*/
|
|
38
|
-
set(e, r, s) {
|
|
39
|
-
return this.center = e, this.halfSize = r, this.rotation = s, this;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Copies the values of the given OBB to this instance.
|
|
43
|
-
*
|
|
44
|
-
* @param {OBB} obb - The OBB to copy.
|
|
45
|
-
* @return {OBB} A reference to this OBB.
|
|
46
|
-
*/
|
|
47
|
-
copy(e) {
|
|
48
|
-
return this.center.copy(e.center), this.halfSize.copy(e.halfSize), this.rotation.copy(e.rotation), this;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Returns a new OBB with copied values from this instance.
|
|
52
|
-
*
|
|
53
|
-
* @return {OBB} A clone of this instance.
|
|
54
|
-
*/
|
|
55
|
-
clone() {
|
|
56
|
-
return new this.constructor().copy(this);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Returns the size of this OBB.
|
|
60
|
-
*
|
|
61
|
-
* @param {Vector3} target - The target vector that is used to store the method's result.
|
|
62
|
-
* @return {Vector3} The size.
|
|
63
|
-
*/
|
|
64
|
-
getSize(e) {
|
|
65
|
-
return e.copy(this.halfSize).multiplyScalar(2);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Clamps the given point within the bounds of this OBB.
|
|
69
|
-
*
|
|
70
|
-
* @param {Vector3} point - The point that should be clamped within the bounds of this OBB.
|
|
71
|
-
* @param {Vector3} target - The target vector that is used to store the method's result.
|
|
72
|
-
* @returns {Vector3} - The clamped point.
|
|
73
|
-
*/
|
|
74
|
-
clampPoint(e, r) {
|
|
75
|
-
const s = this.halfSize;
|
|
76
|
-
z.subVectors(e, this.center), this.rotation.extractBasis(T, B, j), r.copy(this.center);
|
|
77
|
-
const o = q.clamp(z.dot(T), -s.x, s.x);
|
|
78
|
-
r.add(T.multiplyScalar(o));
|
|
79
|
-
const t = q.clamp(z.dot(B), -s.y, s.y);
|
|
80
|
-
r.add(B.multiplyScalar(t));
|
|
81
|
-
const h = q.clamp(z.dot(j), -s.z, s.z);
|
|
82
|
-
return r.add(j.multiplyScalar(h)), r;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Returns `true` if the given point lies within this OBB.
|
|
86
|
-
*
|
|
87
|
-
* @param {Vector3} point - The point to test.
|
|
88
|
-
* @returns {boolean} - Whether the given point lies within this OBB or not.
|
|
89
|
-
*/
|
|
90
|
-
containsPoint(e) {
|
|
91
|
-
return z.subVectors(e, this.center), this.rotation.extractBasis(T, B, j), Math.abs(z.dot(T)) <= this.halfSize.x && Math.abs(z.dot(B)) <= this.halfSize.y && Math.abs(z.dot(j)) <= this.halfSize.z;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Returns `true` if the given AABB intersects this OBB.
|
|
95
|
-
*
|
|
96
|
-
* @param {Box3} box3 - The AABB to test.
|
|
97
|
-
* @returns {boolean} - Whether the given AABB intersects this OBB or not.
|
|
98
|
-
*/
|
|
99
|
-
intersectsBox3(e) {
|
|
100
|
-
return this.intersectsOBB(Fe.fromBox3(e));
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Returns `true` if the given bounding sphere intersects this OBB.
|
|
104
|
-
*
|
|
105
|
-
* @param {Sphere} sphere - The bounding sphere to test.
|
|
106
|
-
* @returns {boolean} - Whether the given bounding sphere intersects this OBB or not.
|
|
107
|
-
*/
|
|
108
|
-
intersectsSphere(e) {
|
|
109
|
-
return this.clampPoint(e.center, te), te.distanceToSquared(e.center) <= e.radius * e.radius;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Returns `true` if the given OBB intersects this OBB.
|
|
113
|
-
*
|
|
114
|
-
* @param {OBB} obb - The OBB to test.
|
|
115
|
-
* @param {number} [epsilon=Number.EPSILON] - A small value to prevent arithmetic errors.
|
|
116
|
-
* @returns {boolean} - Whether the given OBB intersects this OBB or not.
|
|
117
|
-
*/
|
|
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]), u.c = e.center, u.e[0] = e.halfSize.x, u.e[1] = e.halfSize.y, u.e[2] = e.halfSize.z, e.rotation.extractBasis(u.u[0], u.u[1], u.u[2]);
|
|
120
|
-
for (let t = 0; t < 3; t++)
|
|
121
|
-
for (let h = 0; h < 3; h++)
|
|
122
|
-
y[t][h] = l.u[t].dot(u.u[h]);
|
|
123
|
-
z.subVectors(u.c, l.c), p[0] = z.dot(l.u[0]), p[1] = z.dot(l.u[1]), p[2] = z.dot(l.u[2]);
|
|
124
|
-
for (let t = 0; t < 3; t++)
|
|
125
|
-
for (let h = 0; h < 3; h++)
|
|
126
|
-
a[t][h] = Math.abs(y[t][h]) + r;
|
|
127
|
-
let s, o;
|
|
128
|
-
for (let t = 0; t < 3; t++)
|
|
129
|
-
if (s = l.e[t], o = u.e[0] * a[t][0] + u.e[1] * a[t][1] + u.e[2] * a[t][2], Math.abs(p[t]) > s + o) return !1;
|
|
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 = u.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 = u.e[1] * a[0][2] + u.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 = u.e[0] * a[0][2] + u.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 = u.e[0] * a[0][1] + u.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 = u.e[1] * a[1][2] + u.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 = u.e[0] * a[1][2] + u.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 = u.e[0] * a[1][1] + u.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 = u.e[1] * a[2][2] + u.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 = u.e[0] * a[2][2] + u.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 = u.e[0] * a[2][1] + u.e[1] * a[2][0], Math.abs(p[1] * y[0][2] - p[0] * y[1][2]) > s + o));
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Returns `true` if the given plane intersects this OBB.
|
|
136
|
-
*
|
|
137
|
-
* @param {Plane} plane - The plane to test.
|
|
138
|
-
* @returns {boolean} Whether the given plane intersects this OBB or not.
|
|
139
|
-
*/
|
|
140
|
-
intersectsPlane(e) {
|
|
141
|
-
this.rotation.extractBasis(T, B, j);
|
|
142
|
-
const r = this.halfSize.x * Math.abs(e.normal.dot(T)) + 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
|
-
return Math.abs(s) <= r;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Performs a ray/OBB intersection test and stores the intersection point
|
|
147
|
-
* in the given 3D vector.
|
|
148
|
-
*
|
|
149
|
-
* @param {Ray} ray - The ray to test.
|
|
150
|
-
* @param {Vector3} target - The target vector that is used to store the method's result.
|
|
151
|
-
* @return {?Vector3} The intersection point. If no intersection is detected, `null` is returned.
|
|
152
|
-
*/
|
|
153
|
-
intersectRay(e, r) {
|
|
154
|
-
return this.getSize(ee), ne.setFromCenterAndSize(z.set(0, 0, 0), ee), Y.setFromMatrix3(this.rotation), Y.setPosition(this.center), se.copy(Y).invert(), oe.copy(e).applyMatrix4(se), oe.intersectBox(ne, r) ? r.applyMatrix4(Y) : null;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Returns `true` if the given ray intersects this OBB.
|
|
158
|
-
*
|
|
159
|
-
* @param {Ray} ray - The ray to test.
|
|
160
|
-
* @returns {boolean} Whether the given ray intersects this OBB or not.
|
|
161
|
-
*/
|
|
162
|
-
intersectsRay(e) {
|
|
163
|
-
return this.intersectRay(e, z) !== null;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Defines an OBB based on the given AABB.
|
|
167
|
-
*
|
|
168
|
-
* @param {Box3} box3 - The AABB to setup the OBB from.
|
|
169
|
-
* @return {OBB} A reference of this OBB.
|
|
170
|
-
*/
|
|
171
|
-
fromBox3(e) {
|
|
172
|
-
return e.getCenter(this.center), e.getSize(this.halfSize).multiplyScalar(0.5), this.rotation.identity(), this;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Returns `true` if the given OBB is equal to this OBB.
|
|
176
|
-
*
|
|
177
|
-
* @param {OBB} obb - The OBB to test.
|
|
178
|
-
* @returns {boolean} Whether the given OBB is equal to this OBB or not.
|
|
179
|
-
*/
|
|
180
|
-
equals(e) {
|
|
181
|
-
return e.center.equals(this.center) && e.halfSize.equals(this.halfSize) && e.rotation.equals(this.rotation);
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Applies the given transformation matrix to this OBB. This method can be
|
|
185
|
-
* used to transform the bounding volume with the world matrix of a 3D object
|
|
186
|
-
* in order to keep both entities in sync.
|
|
187
|
-
*
|
|
188
|
-
* @param {Matrix4} matrix - The matrix to apply.
|
|
189
|
-
* @return {OBB} A reference of this OBB.
|
|
190
|
-
*/
|
|
191
|
-
applyMatrix4(e) {
|
|
192
|
-
const r = e.elements;
|
|
193
|
-
let s = z.set(r[0], r[1], r[2]).length();
|
|
194
|
-
const o = z.set(r[4], r[5], r[6]).length(), t = z.set(r[8], r[9], r[10]).length();
|
|
195
|
-
e.determinant() < 0 && (s = -s), v.setFromMatrix4(e);
|
|
196
|
-
const c = 1 / s, n = 1 / o, i = 1 / t;
|
|
197
|
-
return v.elements[0] *= c, v.elements[1] *= c, v.elements[2] *= c, v.elements[3] *= n, v.elements[4] *= n, v.elements[5] *= n, v.elements[6] *= i, v.elements[7] *= i, v.elements[8] *= i, this.rotation.multiply(v), this.halfSize.x *= s, this.halfSize.y *= o, this.halfSize.z *= t, z.setFromMatrixPosition(e), this.center.add(z), this;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
const Fe = new G(), Pe = {
|
|
201
|
-
enableDamping: !0,
|
|
202
|
-
dampingFactor: 0.25,
|
|
203
|
-
screenSpacePanning: !1,
|
|
204
|
-
minDistance: 0.1,
|
|
205
|
-
maxDistance: 1e3,
|
|
206
|
-
maxPolarAngle: q.degToRad(60)
|
|
207
|
-
};
|
|
208
|
-
function Le(F, e) {
|
|
209
|
-
typeof console < "u" && console.warn && console.warn(
|
|
210
|
-
`[ThreeIns] useThreeJs() Hook 已弃用,建议使用 ThreeIns 类代替。
|
|
211
|
-
旧用法: const { scene, camera } = useThreeJs(selector, options)
|
|
212
|
-
新用法: const threeIns = new ThreeIns(selector, options)
|
|
213
|
-
|
|
214
|
-
ThreeIns 类提供更完整的 API 和更好的性能。`
|
|
215
|
-
);
|
|
216
|
-
const r = Object.assign(
|
|
217
|
-
{
|
|
218
|
-
css3d: !1,
|
|
219
|
-
stats: !1,
|
|
220
|
-
renderType: "change",
|
|
221
|
-
control: {
|
|
222
|
-
init: !0,
|
|
223
|
-
options: {}
|
|
224
|
-
}
|
|
225
|
-
},
|
|
226
|
-
e || {}
|
|
227
|
-
);
|
|
228
|
-
let s, o, t, h = [];
|
|
229
|
-
const c = H(!1), n = Se(), i = H(0), f = H(0), d = new me({
|
|
230
|
-
antialias: !0,
|
|
231
|
-
alpha: !0,
|
|
232
|
-
precision: "mediump",
|
|
233
|
-
logarithmicDepthBuffer: !0
|
|
234
|
-
}), x = new pe({}), m = new ye(50, 1, 0.1, 2e3), M = Math.tan(Math.PI / 180 * m.fov / 2);
|
|
235
|
-
let O = !1;
|
|
236
|
-
d.setPixelRatio(window.devicePixelRatio);
|
|
237
|
-
function L() {
|
|
238
|
-
c.value = !1;
|
|
239
|
-
const S = V();
|
|
240
|
-
i.value = S[0], f.value = S[1], m.aspect = i.value / f.value, m.position.set(47, 39, 100), m.fov = 360 / Math.PI * Math.atan(M * (f.value / i.value)), m.lookAt(0, 0, 0), m.updateProjectionMatrix(), d.setSize(i.value, f.value), s.appendChild(d.domElement), r.stats && W(), r.css3d && ce();
|
|
241
|
-
let P;
|
|
242
|
-
if (r.control && r.control.init) {
|
|
243
|
-
P = ve(m, d.domElement);
|
|
244
|
-
const C = Object.assign(
|
|
245
|
-
Pe,
|
|
246
|
-
r.control.options || {}
|
|
247
|
-
);
|
|
248
|
-
Object.keys(C).forEach((k) => {
|
|
249
|
-
P[k] = C[k];
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
return K(() => c.value = !0), P;
|
|
253
|
-
}
|
|
254
|
-
function I(S) {
|
|
255
|
-
S.preventDefault(), cancelAnimationFrame(R);
|
|
256
|
-
}
|
|
257
|
-
function U(S) {
|
|
258
|
-
S.preventDefault(), L(), R();
|
|
259
|
-
}
|
|
260
|
-
function $(S) {
|
|
261
|
-
h.push(S);
|
|
262
|
-
}
|
|
263
|
-
function R(S) {
|
|
264
|
-
h && h.length && h.forEach((P) => {
|
|
265
|
-
typeof P == "function" && P();
|
|
266
|
-
}), r.renderType === "loop" && w(), requestAnimationFrame(R);
|
|
267
|
-
}
|
|
268
|
-
function w() {
|
|
269
|
-
O = !1, o && o.update(), n.value && n.value.update(), d.render(x, m), t && t.render(x, m);
|
|
270
|
-
}
|
|
271
|
-
function _() {
|
|
272
|
-
O || (O = !0, requestAnimationFrame(w));
|
|
273
|
-
}
|
|
274
|
-
function g() {
|
|
275
|
-
K(() => {
|
|
276
|
-
const S = V();
|
|
277
|
-
i.value = S[0], f.value = S[1], m.aspect = i.value / f.value, m.fov = 360 / Math.PI * Math.atan(M * (f.value / i.value)), m.updateProjectionMatrix(), m.lookAt(x.position), d.setSize(i.value, f.value), t && t.setSize(i.value, f.value), w();
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
function V() {
|
|
281
|
-
return s = document.querySelector(F), s ? [s.clientWidth, s.clientHeight] : [0, 0];
|
|
282
|
-
}
|
|
283
|
-
function W() {
|
|
284
|
-
o = new Oe(), o.dom.style.cssText = "position:absolute;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000", s.appendChild(o.dom);
|
|
285
|
-
}
|
|
286
|
-
function ie(S, P, C, k, N) {
|
|
287
|
-
const Q = new J().setFromObject(S), Z = Q.getSize(new b()).length(), E = Q.getCenter(new b());
|
|
288
|
-
N && E.add(N);
|
|
289
|
-
const ue = Z * P * 0.5, he = q.degToRad(C.fov * 0.5), fe = ue / Math.tan(he), X = new b().subVectors(C.position, E).multiply(new b(1, 1, 1)).normalize().multiplyScalar(fe).add(E), D = {
|
|
290
|
-
x: X.x,
|
|
291
|
-
y: X.y,
|
|
292
|
-
z: X.z,
|
|
293
|
-
lookAt_x: E.x,
|
|
294
|
-
lookAt_y: E.y,
|
|
295
|
-
lookAt_z: E.z
|
|
296
|
-
};
|
|
297
|
-
return C.position.set(D.x, D.y, D.z), C.lookAt(
|
|
298
|
-
D.lookAt_x,
|
|
299
|
-
D.lookAt_y,
|
|
300
|
-
D.lookAt_z
|
|
301
|
-
), C.updateProjectionMatrix(), k.target.copy(E), k.update(), Z;
|
|
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);
|
|
305
|
-
}
|
|
306
|
-
function le() {
|
|
307
|
-
Me(x);
|
|
308
|
-
}
|
|
309
|
-
return we(() => {
|
|
310
|
-
n.value = L(), window.addEventListener("resize", g, !1), d.domElement.addEventListener(
|
|
311
|
-
"webglcontextlost",
|
|
312
|
-
I,
|
|
313
|
-
!1
|
|
314
|
-
), d.domElement.addEventListener(
|
|
315
|
-
"webglcontextrestored",
|
|
316
|
-
U,
|
|
317
|
-
!1
|
|
318
|
-
), r.renderType === "loop" ? requestAnimationFrame(R) : r.renderType === "change" && n.value && n.value.addEventListener("change", _);
|
|
319
|
-
}), ge(() => {
|
|
320
|
-
cancelAnimationFrame(R), d.domElement.removeEventListener("resize", g, !1), d.domElement.removeEventListener(
|
|
321
|
-
"webglcontextlost",
|
|
322
|
-
I,
|
|
323
|
-
!1
|
|
324
|
-
), d.domElement.removeEventListener(
|
|
325
|
-
"webglcontextrestored",
|
|
326
|
-
U,
|
|
327
|
-
!1
|
|
328
|
-
), le();
|
|
329
|
-
}), {
|
|
330
|
-
addAnimate: $,
|
|
331
|
-
frameArea: ie,
|
|
332
|
-
onRender: w,
|
|
333
|
-
css3dRenderer: t,
|
|
334
|
-
scene: x,
|
|
335
|
-
camera: m,
|
|
336
|
-
control: n,
|
|
337
|
-
renderer: d,
|
|
338
|
-
domWidth: i,
|
|
339
|
-
domHeight: f,
|
|
340
|
-
isReady: c
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
const De = (F = "app") => {
|
|
344
|
-
const e = new be();
|
|
345
|
-
e.params.Line.threshold = 8;
|
|
346
|
-
const r = new ze(), s = document.getElementById(F);
|
|
347
|
-
function o(c, n) {
|
|
348
|
-
const { scaleX: i, scaleY: f } = h(s), { clientWidth: d, clientHeight: x } = n, m = n.getBoundingClientRect(), M = d * i, O = x * f, L = c.clientX - m.left, I = c.clientY - m.top;
|
|
349
|
-
return r.x = (c.clientX - m.left) / M * 2 - 1, r.y = -((c.clientY - m.top) / O) * 2 + 1, { pointer: r, x: L, y: I };
|
|
350
|
-
}
|
|
351
|
-
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 };
|
|
354
|
-
}
|
|
355
|
-
function h(c) {
|
|
356
|
-
const n = window.getComputedStyle(c), i = n.transform || n.webkitTransform || n.mozTransform;
|
|
357
|
-
if (i && i !== "none") {
|
|
358
|
-
const f = i.match(/^matrix\((.+)\)$/);
|
|
359
|
-
if (f) {
|
|
360
|
-
const d = f[1].split(", "), x = parseFloat(d[0]), m = parseFloat(d[3]);
|
|
361
|
-
return { scaleX: x, scaleY: m };
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
return { scaleX: 1, scaleY: 1 };
|
|
365
|
-
}
|
|
366
|
-
return {
|
|
367
|
-
raycaster: e,
|
|
368
|
-
pointer: r,
|
|
369
|
-
getPointer: o,
|
|
370
|
-
getScale: h,
|
|
371
|
-
getIntersects: t
|
|
372
|
-
};
|
|
373
|
-
}, A = [], Ie = new xe(16711680), ke = () => {
|
|
374
|
-
const F = () => {
|
|
375
|
-
A.splice(0);
|
|
376
|
-
}, e = (c, n) => {
|
|
377
|
-
n.traverse((i) => {
|
|
378
|
-
i && r(c, i);
|
|
379
|
-
});
|
|
380
|
-
}, r = (c, n) => {
|
|
381
|
-
if (n.userData.needCheck && (n.autoUpdateMatrix = !1, n.updateMatrix(), n.updateMatrixWorld(), n.isMesh)) {
|
|
382
|
-
const i = new J(new b()).setFromObject(n);
|
|
383
|
-
n.geometry.userData.obb = new G(), n.geometry.userData.obb.halfSize.copy(i.getSize(new b())).multiplyScalar(0.5).multiplyScalar(0.88), n.userData.obb = new G(), n.userData.originColor = n.material.color.clone(), n.userData.parentUid = c, A.push({
|
|
384
|
-
object: n,
|
|
385
|
-
parentUid: c
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
return {
|
|
390
|
-
resetObbs: F,
|
|
391
|
-
initObb: e,
|
|
392
|
-
getObbObjectByParentUid: (c) => A.filter((n) => n.parentUid === c),
|
|
393
|
-
addObbFromArray: (c, n) => {
|
|
394
|
-
for (let i = 0, f = n.length; i < f; i++)
|
|
395
|
-
r(c, n[i]);
|
|
396
|
-
},
|
|
397
|
-
removeObbFromArray: (c) => {
|
|
398
|
-
const n = A.filter((i) => !c.includes(i.object));
|
|
399
|
-
A.splice(0, A.length, ...n);
|
|
400
|
-
},
|
|
401
|
-
removeUidObb: (c) => {
|
|
402
|
-
for (let n = A.length - 1; n >= 0; n--)
|
|
403
|
-
A[n].parentUid === c && A.splice(n, 1);
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
-
};
|
|
407
|
-
function qe() {
|
|
408
|
-
const { asyncFetch: F } = Ae();
|
|
409
|
-
async function e(o, t = {}) {
|
|
410
|
-
const {
|
|
411
|
-
maxConcurrent: h = 3,
|
|
412
|
-
maxRetries: c = 3,
|
|
413
|
-
onProgress: n,
|
|
414
|
-
onModelLoad: i,
|
|
415
|
-
onModelError: f
|
|
416
|
-
} = t, d = /* @__PURE__ */ new Map(), x = /* @__PURE__ */ new Map(), m = [...o];
|
|
417
|
-
let M = 0, O = 0;
|
|
418
|
-
return new Promise((L, I) => {
|
|
419
|
-
const U = async (R) => {
|
|
420
|
-
const { path: w, version: _ } = R;
|
|
421
|
-
O++;
|
|
422
|
-
try {
|
|
423
|
-
const g = await F(
|
|
424
|
-
w,
|
|
425
|
-
_,
|
|
426
|
-
(V) => {
|
|
427
|
-
const W = M / o.length * 100 + V / o.length;
|
|
428
|
-
n == null || n(Math.round(W));
|
|
429
|
-
},
|
|
430
|
-
{ maxRetries: c }
|
|
431
|
-
);
|
|
432
|
-
if (g)
|
|
433
|
-
d.set(w, g), i == null || i(w, g);
|
|
434
|
-
else
|
|
435
|
-
throw new Error(`模型加载返回空结果: ${w}`);
|
|
436
|
-
} catch (g) {
|
|
437
|
-
console.error(`[ 批量加载 ] 加载失败: ${w}`, g), x.set(w, g), f == null || f(w, g);
|
|
438
|
-
} finally {
|
|
439
|
-
O--, M++;
|
|
440
|
-
const g = M / o.length * 100;
|
|
441
|
-
n == null || n(Math.round(g)), $();
|
|
442
|
-
}
|
|
443
|
-
}, $ = () => {
|
|
444
|
-
if (M >= o.length) {
|
|
445
|
-
x.size > 0 && console.warn(`[ 批量加载 ] 完成,但有 ${x.size} 个模型加载失败`), L(d);
|
|
446
|
-
return;
|
|
447
|
-
}
|
|
448
|
-
for (; m.length > 0 && O < h; ) {
|
|
449
|
-
const R = m.shift();
|
|
450
|
-
U(R);
|
|
451
|
-
}
|
|
452
|
-
};
|
|
453
|
-
$();
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
async function r(o, t = {}) {
|
|
457
|
-
console.log(`[ 批量预加载 ] 开始预加载 ${o.length} 个模型`);
|
|
458
|
-
const h = await e(o, {
|
|
459
|
-
...t,
|
|
460
|
-
maxConcurrent: t.maxConcurrent || 2
|
|
461
|
-
// 预加载使用较低的并发数
|
|
462
|
-
});
|
|
463
|
-
return console.log(`[ 批量预加载 ] 完成,成功加载 ${h.size} 个模型`), h;
|
|
464
|
-
}
|
|
465
|
-
async function s(o, t = {}) {
|
|
466
|
-
const h = /* @__PURE__ */ new Map();
|
|
467
|
-
for (let c = 0; c < o.length; c++)
|
|
468
|
-
console.log(`[ 分组批量加载 ] 加载第 ${c + 1}/${o.length} 组`), (await e(o[c], {
|
|
469
|
-
...t,
|
|
470
|
-
onProgress: (i) => {
|
|
471
|
-
var d;
|
|
472
|
-
const f = c / o.length * 100 + i / o.length;
|
|
473
|
-
(d = t.onProgress) == null || d.call(t, Math.round(f));
|
|
474
|
-
}
|
|
475
|
-
})).forEach((i, f) => {
|
|
476
|
-
h.set(f, i);
|
|
477
|
-
});
|
|
478
|
-
return h;
|
|
479
|
-
}
|
|
480
|
-
return {
|
|
481
|
-
batchLoad: e,
|
|
482
|
-
preload: r,
|
|
483
|
-
batchLoadGroups: s
|
|
484
|
-
};
|
|
485
|
-
}
|
|
486
|
-
export {
|
|
487
|
-
De as a,
|
|
488
|
-
ke as b,
|
|
489
|
-
qe as c,
|
|
490
|
-
Ie as i,
|
|
491
|
-
A as o,
|
|
492
|
-
Le as u
|
|
493
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";const c=require("three"),C=require("vue"),I=require("./PredictiveLoader-DDxh7dDg.cjs"),u={c:null,u:[new c.Vector3,new c.Vector3,new c.Vector3],e:[]},h={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,x=new c.Vector3,Z=new c.Vector3,K=new c.Vector3,v=new c.Matrix3,ee=new c.Box3,_=new c.Matrix4,te=new c.Matrix4,ne=new c.Ray;class G{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;x.subVectors(e,this.center),this.rotation.extractBasis(V,B,j),r.copy(this.center);const o=c.MathUtils.clamp(x.dot(V),-s.x,s.x);r.add(V.multiplyScalar(o));const t=c.MathUtils.clamp(x.dot(B),-s.y,s.y);r.add(B.multiplyScalar(t));const f=c.MathUtils.clamp(x.dot(j),-s.z,s.z);return r.add(j.multiplyScalar(f)),r}containsPoint(e){return x.subVectors(e,this.center),this.rotation.extractBasis(V,B,j),Math.abs(x.dot(V))<=this.halfSize.x&&Math.abs(x.dot(B))<=this.halfSize.y&&Math.abs(x.dot(j))<=this.halfSize.z}intersectsBox3(e){return this.intersectsOBB(le.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]),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]);for(let t=0;t<3;t++)for(let f=0;f<3;f++)b[t][f]=u.u[t].dot(h.u[f]);x.subVectors(h.c,u.c),y[0]=x.dot(u.u[0]),y[1]=x.dot(u.u[1]),y[2]=x.dot(u.u[2]);for(let t=0;t<3;t++)for(let f=0;f<3;f++)a[t][f]=Math.abs(b[t][f])+r;let s,o;for(let t=0;t<3;t++)if(s=u.e[t],o=h.e[0]*a[t][0]+h.e[1]*a[t][1]+h.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=h.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=h.e[1]*a[0][2]+h.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=h.e[0]*a[0][2]+h.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=h.e[0]*a[0][1]+h.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=h.e[1]*a[1][2]+h.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=h.e[0]*a[1][2]+h.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=h.e[0]*a[1][1]+h.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=h.e[1]*a[2][2]+h.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=h.e[0]*a[2][2]+h.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=h.e[0]*a[2][1]+h.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(x.set(0,0,0),Z),_.setFromMatrix3(this.rotation),_.setPosition(this.center),te.copy(_).invert(),ne.copy(e).applyMatrix4(te),ne.intersectBox(ee,r)?r.applyMatrix4(_):null}intersectsRay(e){return this.intersectRay(e,x)!==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=x.set(r[0],r[1],r[2]).length();const o=x.set(r[4],r[5],r[6]).length(),t=x.set(r[8],r[9],r[10]).length();e.determinant()<0&&(s=-s),v.setFromMatrix4(e);const l=1/s,n=1/o,i=1/t;return v.elements[0]*=l,v.elements[1]*=l,v.elements[2]*=l,v.elements[3]*=n,v.elements[4]*=n,v.elements[5]*=n,v.elements[6]*=i,v.elements[7]*=i,v.elements[8]*=i,this.rotation.multiply(v),this.halfSize.x*=s,this.halfSize.y*=o,this.halfSize.z*=t,x.setFromMatrixPosition(e),this.center.add(x),this}}const le=new G,ue={enableDamping:!0,dampingFactor:.25,screenSpacePanning:!1,minDistance:.1,maxDistance:1e3,maxPolarAngle:c.MathUtils.degToRad(60)};function he(F,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,f=[];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),M=Math.tan(Math.PI/180*p.fov/2);let R=!1;m.setPixelRatio(window.devicePixelRatio);function L(){l.value=!1;const w=Y();i.value=w[0],d.value=w[1],p.aspect=i.value/d.value,p.position.set(47,39,100),p.fov=360/Math.PI*Math.atan(M*(d.value/i.value)),p.lookAt(0,0,0),p.updateProjectionMatrix(),m.setSize(i.value,d.value),s.appendChild(m.domElement),r.stats&&W(),r.css3d&&oe();let P;if(r.control&&r.control.init){P=I.createOrbitControl(p,m.domElement);const A=Object.assign(ue,r.control.options||{});Object.keys(A).forEach(k=>{P[k]=A[k]})}return C.nextTick(()=>l.value=!0),P}function D(w){w.preventDefault(),cancelAnimationFrame(T)}function U(w){w.preventDefault(),L(),T()}function $(w){f.push(w)}function T(w){f&&f.length&&f.forEach(P=>{typeof P=="function"&&P()}),r.renderType==="loop"&&S(),requestAnimationFrame(T)}function S(){R=!1,o&&o.update(),n.value&&n.value.update(),m.render(z,p),t&&t.render(z,p)}function H(){R||(R=!0,requestAnimationFrame(S))}function g(){C.nextTick(()=>{const w=Y();i.value=w[0],d.value=w[1],p.aspect=i.value/d.value,p.fov=360/Math.PI*Math.atan(M*(d.value/i.value)),p.updateProjectionMatrix(),p.lookAt(z.position),m.setSize(i.value,d.value),t&&t.setSize(i.value,d.value),S()})}function Y(){return s=document.querySelector(F),s?[s.clientWidth,s.clientHeight]:[0,0]}function W(){o=new I.Stats,o.dom.style.cssText="position:absolute;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000",s.appendChild(o.dom)}function se(w,P,A,k,J){const N=new c.Box3().setFromObject(w),Q=N.getSize(new c.Vector3).length(),E=N.getCenter(new c.Vector3);J&&E.add(J);const ae=Q*P*.5,ie=c.MathUtils.degToRad(A.fov*.5),ce=ae/Math.tan(ie),X=new c.Vector3().subVectors(A.position,E).multiply(new c.Vector3(1,1,1)).normalize().multiplyScalar(ce).add(E),q={x:X.x,y:X.y,z:X.z,lookAt_x:E.x,lookAt_y:E.y,lookAt_z:E.z};return A.position.set(q.x,q.y,q.z),A.lookAt(q.lookAt_x,q.lookAt_y,q.lookAt_z),A.updateProjectionMatrix(),k.target.copy(E),k.update(),Q}function oe(){t=new I.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 re(){I.disposeThreeObject(z)}return C.onMounted(()=>{n.value=L(),window.addEventListener("resize",g,!1),m.domElement.addEventListener("webglcontextlost",D,!1),m.domElement.addEventListener("webglcontextrestored",U,!1),r.renderType==="loop"?requestAnimationFrame(T):r.renderType==="change"&&n.value&&n.value.addEventListener("change",H)}),C.onUnmounted(()=>{cancelAnimationFrame(T),m.domElement.removeEventListener("resize",g,!1),m.domElement.removeEventListener("webglcontextlost",D,!1),m.domElement.removeEventListener("webglcontextrestored",U,!1),re()}),{addAnimate:$,frameArea:se,onRender:S,css3dRenderer:t,scene:z,camera:p,control:n,renderer:m,domWidth:i,domHeight:d,isReady:l}}const fe=(F="app")=>{const e=new c.Raycaster;e.params.Line.threshold=8;const r=new c.Vector2,s=document.getElementById(F);function o(l,n){const{scaleX:i,scaleY:d}=f(s),{clientWidth:m,clientHeight:z}=n,p=n.getBoundingClientRect(),M=m*i,R=z*d,L=l.clientX-p.left,D=l.clientY-p.top;return r.x=(l.clientX-p.left)/M*2-1,r.y=-((l.clientY-p.top)/R)*2+1,{pointer:r,x:L,y:D}}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 f(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:f,getIntersects:t}},O=[],de=new c.Color(16711680),me=()=>{const F=()=>{O.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 G,n.geometry.userData.obb.halfSize.copy(i.getSize(new c.Vector3)).multiplyScalar(.5).multiplyScalar(.88),n.userData.obb=new G,n.userData.originColor=n.material.color.clone(),n.userData.parentUid=l,O.push({object:n,parentUid:l})}};return{resetObbs:F,initObb:e,getObbObjectByParentUid:l=>O.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=O.filter(i=>!l.includes(i.object));O.splice(0,O.length,...n)},removeUidObb:l=>{for(let n=O.length-1;n>=0;n--)O[n].parentUid===l&&O.splice(n,1)}}};function pe(){const{asyncFetch:F}=I.useGLTFLoader();async function e(o,t={}){const{maxConcurrent:f=3,maxRetries:l=3,onProgress:n,onModelLoad:i,onModelError:d}=t,m=new Map,z=new Map,p=[...o];let M=0,R=0;return new Promise((L,D)=>{const U=async T=>{const{path:S,version:H}=T;R++;try{const g=await F(S,H,Y=>{const W=M/o.length*100+Y/o.length;n==null||n(Math.round(W))},{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{R--,M++;const g=M/o.length*100;n==null||n(Math.round(g)),$()}},$=()=>{if(M>=o.length){z.size>0&&console.warn(`[ 批量加载 ] 完成,但有 ${z.size} 个模型加载失败`),L(m);return}for(;p.length>0&&R<f;){const T=p.shift();U(T)}};$()})}async function r(o,t={}){console.log(`[ 批量预加载 ] 开始预加载 ${o.length} 个模型`);const f=await e(o,{...t,maxConcurrent:t.maxConcurrent||2});return console.log(`[ 批量预加载 ] 完成,成功加载 ${f.size} 个模型`),f}async function s(o,t={}){const f=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)=>{f.set(d,i)});return f}return{batchLoad:e,preload:r,batchLoadGroups:s}}exports.intersectColor=de;exports.obbObjects=O;exports.useBatchGLTFLoader=pe;exports.useObb=me;exports.useRaycaster=fe;exports.useThreeJs=he;
|
|
File without changes
|
|
File without changes
|