softbox 4.16.1 → 4.18.0

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.
Files changed (49) hide show
  1. package/README.md +7 -6
  2. package/dist/{BrightnessContrastShader-BN6FBcLV.cjs → BrightnessContrastShader-C1jbh-NA.cjs} +2 -2
  3. package/dist/BrightnessContrastShader-CoM5EjqG.js +13 -0
  4. package/dist/ContactShadowBaker-MzqtJ-0h.js +2052 -0
  5. package/dist/ContactShadowBaker-lWQW97Cr.cjs +2 -0
  6. package/dist/CopyShader-C2Oc7n1P.js +12 -0
  7. package/dist/{CopyShader-DPSZNOxL.cjs → CopyShader-CM1OGKAp.cjs} +2 -2
  8. package/dist/EffectComposer-CMs4vldH.js +88 -0
  9. package/dist/EffectComposer-CdAQB6p0.cjs +1 -0
  10. package/dist/HueSaturationShader-BeHSjNY8.js +13 -0
  11. package/dist/{HueSaturationShader-BEp7jjxf.cjs → HueSaturationShader-bN5IWhh8.cjs} +2 -2
  12. package/dist/OutputPass-DicIJHut.cjs +72 -0
  13. package/dist/OutputPass-oQu4Xmeb.js +29 -0
  14. package/dist/Pass-CSHIrJrV.js +51 -0
  15. package/dist/Pass-D0vYi-gB.cjs +1 -0
  16. package/dist/RenderPass-DS8SYAhJ.js +16 -0
  17. package/dist/RenderPass-DlRq51Kq.cjs +1 -0
  18. package/dist/ShaderPass-DghZ7TAj.cjs +1 -0
  19. package/dist/ShaderPass-h4P0lBmc.js +22 -0
  20. package/dist/{ThreePathTracingService-VOgJGtMH.cjs → ThreePathTracingService-B1WEEKgQ.cjs} +96 -96
  21. package/dist/ThreePathTracingService-qV8I_V9u.js +2546 -0
  22. package/dist/UnrealBloomPass-BTHiW_Y8.js +123 -0
  23. package/dist/UnrealBloomPass-CQHHa-s_.cjs +115 -0
  24. package/dist/VignetteShader-CPF_iEkO.js +13 -0
  25. package/dist/{VignetteShader-Drpo9YxI.cjs → VignetteShader-CQmGrpns.cjs} +2 -2
  26. package/dist/index.d.cts +7 -0
  27. package/dist/index.d.ts +7 -0
  28. package/dist/simple-viewer.cjs +23 -1
  29. package/dist/simple-viewer.es.js +8473 -11
  30. package/package.json +26 -18
  31. package/dist/BrightnessContrastShader-B9tNAd_c.js +0 -49
  32. package/dist/CopyShader-DVL8Bcar.js +0 -41
  33. package/dist/EffectComposer-BdHnHszK.js +0 -188
  34. package/dist/EffectComposer-D2IQ0sek.cjs +0 -1
  35. package/dist/HueSaturationShader-B6tnz2ga.js +0 -60
  36. package/dist/OutputPass-Dy4KNHYF.cjs +0 -72
  37. package/dist/OutputPass-Tt8WbC_B.js +0 -125
  38. package/dist/Pass-C1mreNp8.cjs +0 -1
  39. package/dist/Pass-DOcH4lwV.js +0 -88
  40. package/dist/RenderPass-B57TYmjs.js +0 -37
  41. package/dist/RenderPass-BVzyKWsC.cjs +0 -1
  42. package/dist/ShaderPass-BQRqK8zp.cjs +0 -1
  43. package/dist/ShaderPass-C2HX8lsT.js +0 -45
  44. package/dist/ThreePathTracingService-CK3zD4Qj.js +0 -6383
  45. package/dist/UnrealBloomPass-Kx7djcld.cjs +0 -115
  46. package/dist/UnrealBloomPass-rjyQu37v.js +0 -281
  47. package/dist/VignetteShader-BG_QwoTp.js +0 -45
  48. package/dist/index-BWjJNKzq.js +0 -13030
  49. package/dist/index-BqbKpEQh.cjs +0 -29
@@ -0,0 +1,2052 @@
1
+ import * as e from "three";
2
+ import { BackSide as t, BatchedMesh as n, Box3 as r, BufferAttribute as i, DoubleSide as a, FrontSide as o, Line as s, Line3 as c, LineLoop as l, LineSegments as u, Matrix4 as d, Mesh as f, Plane as p, Points as m, REVISION as h, Ray as g, Sphere as _, Triangle as v, Vector2 as y, Vector3 as b } from "three";
3
+ //#region src/errors/ThreeViewerError.ts
4
+ var x = class e extends Error {
5
+ constructor(t, n, r) {
6
+ super(t), this.code = n, this.context = r, this.name = "ThreeViewerError", this.timestamp = /* @__PURE__ */ new Date(), Error.captureStackTrace && Error.captureStackTrace(this, e);
7
+ }
8
+ static fromError(t, n, r) {
9
+ if (t instanceof e) return t;
10
+ let i = t instanceof Error ? t.message : String(t), a = {
11
+ ...r,
12
+ originalError: t instanceof Error ? {
13
+ name: t.name,
14
+ message: t.message,
15
+ stack: t.stack
16
+ } : t
17
+ };
18
+ return new e(i, n, a);
19
+ }
20
+ }, S = /* @__PURE__ */ function(e) {
21
+ return e.SCENE_INIT_FAILED = "SCENE_INIT_FAILED", e.RENDERER_INIT_FAILED = "RENDERER_INIT_FAILED", e.RENDERER_NOT_INITIALIZED = "RENDERER_NOT_INITIALIZED", e.CAMERA_INIT_FAILED = "CAMERA_INIT_FAILED", e.WEBGL_NOT_SUPPORTED = "WEBGL_NOT_SUPPORTED", e.INITIALIZATION_FAILED = "INITIALIZATION_FAILED", e.PATH_TRACING_INIT_FAILED = "PATH_TRACING_INIT_FAILED", e.MODEL_LOAD_FAILED = "MODEL_LOAD_FAILED", e.TEXTURE_LOAD_FAILED = "TEXTURE_LOAD_FAILED", e.RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND", e.UNSUPPORTED_FORMAT = "UNSUPPORTED_FORMAT", e.INVALID_CONFIGURATION = "INVALID_CONFIGURATION", e.RENDER_ERROR = "RENDER_ERROR", e.RENDER_FAILED = "RENDER_FAILED", e.SCENE_OPERATION_FAILED = "SCENE_OPERATION_FAILED", e.COMPONENT_NOT_MOUNTED = "COMPONENT_NOT_MOUNTED", e.INVALID_STATE = "INVALID_STATE", e.INVALID_PARAMETER = "INVALID_PARAMETER", e.OPERATION_FAILED = "OPERATION_FAILED", e.UNKNOWN = "UNKNOWN", e;
22
+ }({}), C = {
23
+ ok(e) {
24
+ return {
25
+ ok: !0,
26
+ value: e
27
+ };
28
+ },
29
+ err(e) {
30
+ return {
31
+ ok: !1,
32
+ error: e
33
+ };
34
+ },
35
+ wrap(e) {
36
+ try {
37
+ return C.ok(e());
38
+ } catch (e) {
39
+ return C.err(e instanceof x ? e : new x(String(e), S.UNKNOWN, { originalError: e }));
40
+ }
41
+ }
42
+ }, w = class {
43
+ constructor() {
44
+ this.listeners = /* @__PURE__ */ new Map();
45
+ }
46
+ on(e, t) {
47
+ this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set());
48
+ let n = this.listeners.get(e);
49
+ return n && n.add(t), () => {
50
+ this.listeners.get(e)?.delete(t);
51
+ };
52
+ }
53
+ emit(e, t) {
54
+ this.listeners.get(e)?.forEach((n) => {
55
+ try {
56
+ n(t);
57
+ } catch (t) {
58
+ console.error(`Error in event listener for ${String(e)}:`, t);
59
+ }
60
+ });
61
+ }
62
+ once(e, t) {
63
+ let n = this.on(e, (e) => {
64
+ n(), t(e);
65
+ });
66
+ return n;
67
+ }
68
+ removeAllListeners(e) {
69
+ e ? this.listeners.delete(e) : this.listeners.clear();
70
+ }
71
+ listenerCount(e) {
72
+ return this.listeners.get(e)?.size || 0;
73
+ }
74
+ off(e, t) {
75
+ this.listeners.get(e)?.delete(t);
76
+ }
77
+ removeListener(e, t) {
78
+ this.off(e, t);
79
+ }
80
+ }, T = {
81
+ meters: 1,
82
+ centimeters: .01,
83
+ millimeters: .001,
84
+ feet: .3048,
85
+ inches: .0254
86
+ }, ee = "softbox-units-scale", te = 1.25, E = 65535, ne = E << 16, re = 2 ** -24, D = Symbol("SKIP_GENERATION"), ie = {
87
+ strategy: 0,
88
+ maxDepth: 40,
89
+ targetLeafSize: 10,
90
+ useSharedArrayBuffer: !1,
91
+ setBoundingBox: !0,
92
+ onProgress: null,
93
+ indirect: !1,
94
+ verbose: !0,
95
+ range: null,
96
+ [D]: !1
97
+ };
98
+ //#endregion
99
+ //#region node_modules/three-mesh-bvh/src/utils/ArrayBoxUtilities.js
100
+ function O(e, t, n) {
101
+ return n.min.x = t[e], n.min.y = t[e + 1], n.min.z = t[e + 2], n.max.x = t[e + 3], n.max.y = t[e + 4], n.max.z = t[e + 5], n;
102
+ }
103
+ function ae(e) {
104
+ let t = -1, n = -Infinity;
105
+ for (let r = 0; r < 3; r++) {
106
+ let i = e[r + 3] - e[r];
107
+ i > n && (n = i, t = r);
108
+ }
109
+ return t;
110
+ }
111
+ function oe(e, t) {
112
+ t.set(e);
113
+ }
114
+ function se(e, t, n) {
115
+ let r, i;
116
+ for (let a = 0; a < 3; a++) {
117
+ let o = a + 3;
118
+ r = e[a], i = t[a], n[a] = r < i ? r : i, r = e[o], i = t[o], n[o] = r > i ? r : i;
119
+ }
120
+ }
121
+ function ce(e, t, n) {
122
+ for (let r = 0; r < 3; r++) {
123
+ let i = t[e + 2 * r], a = t[e + 2 * r + 1], o = i - a, s = i + a;
124
+ o < n[r] && (n[r] = o), s > n[r + 3] && (n[r + 3] = s);
125
+ }
126
+ }
127
+ function le(e) {
128
+ let t = e[3] - e[0], n = e[4] - e[1], r = e[5] - e[2];
129
+ return 2 * (t * n + n * r + r * t);
130
+ }
131
+ //#endregion
132
+ //#region node_modules/three-mesh-bvh/src/core/utils/nodeBufferUtils.js
133
+ function k(e, t) {
134
+ return t[e + 15] === E;
135
+ }
136
+ function A(e, t) {
137
+ return t[e + 6];
138
+ }
139
+ function j(e, t) {
140
+ return t[e + 14];
141
+ }
142
+ function M(e) {
143
+ return e + 8;
144
+ }
145
+ function N(e, t) {
146
+ return e + t[e + 6] * 8;
147
+ }
148
+ function ue(e, t) {
149
+ return t[e + 7];
150
+ }
151
+ function P(e) {
152
+ return e;
153
+ }
154
+ //#endregion
155
+ //#region node_modules/three-mesh-bvh/src/core/build/computeBoundsUtils.js
156
+ function de(e, t, n, r, i) {
157
+ let a = Infinity, o = Infinity, s = Infinity, c = -Infinity, l = -Infinity, u = -Infinity, d = Infinity, f = Infinity, p = Infinity, m = -Infinity, h = -Infinity, g = -Infinity, _ = e.offset || 0;
158
+ for (let r = (t - _) * 6, i = (t + n - _) * 6; r < i; r += 6) {
159
+ let t = e[r + 0], n = e[r + 1], i = t - n, _ = t + n;
160
+ i < a && (a = i), _ > c && (c = _), t < d && (d = t), t > m && (m = t);
161
+ let v = e[r + 2], y = e[r + 3], b = v - y, x = v + y;
162
+ b < o && (o = b), x > l && (l = x), v < f && (f = v), v > h && (h = v);
163
+ let S = e[r + 4], C = e[r + 5], w = S - C, T = S + C;
164
+ w < s && (s = w), T > u && (u = T), S < p && (p = S), S > g && (g = S);
165
+ }
166
+ r[0] = a, r[1] = o, r[2] = s, r[3] = c, r[4] = l, r[5] = u, i[0] = d, i[1] = f, i[2] = p, i[3] = m, i[4] = h, i[5] = g;
167
+ }
168
+ //#endregion
169
+ //#region node_modules/three-mesh-bvh/src/core/build/splitUtils.js
170
+ var F = 32, fe = (e, t) => e.candidate - t.candidate, I = /* @__PURE__ */ Array(F).fill().map(() => ({
171
+ count: 0,
172
+ bounds: /* @__PURE__ */ new Float32Array(6),
173
+ rightCacheBounds: /* @__PURE__ */ new Float32Array(6),
174
+ leftCacheBounds: /* @__PURE__ */ new Float32Array(6),
175
+ candidate: 0
176
+ })), pe = /* @__PURE__ */ new Float32Array(6);
177
+ function me(e, t, n, r, i, a) {
178
+ let o = -1, s = 0;
179
+ if (a === 0) o = ae(t), o !== -1 && (s = (t[o] + t[o + 3]) / 2);
180
+ else if (a === 1) o = ae(e), o !== -1 && (s = he(n, r, i, o));
181
+ else if (a === 2) {
182
+ let a = le(e), c = te * i, l = n.offset || 0, u = (r - l) * 6, d = (r + i - l) * 6;
183
+ for (let e = 0; e < 3; e++) {
184
+ let r = t[e], l = (t[e + 3] - r) / F;
185
+ if (i < F / 4) {
186
+ let t = [...I];
187
+ t.length = i;
188
+ let r = 0;
189
+ for (let i = u; i < d; i += 6, r++) {
190
+ let a = t[r];
191
+ a.candidate = n[i + 2 * e], a.count = 0;
192
+ let { bounds: o, leftCacheBounds: s, rightCacheBounds: c } = a;
193
+ for (let e = 0; e < 3; e++) c[e] = Infinity, c[e + 3] = -Infinity, s[e] = Infinity, s[e + 3] = -Infinity, o[e] = Infinity, o[e + 3] = -Infinity;
194
+ ce(i, n, o);
195
+ }
196
+ t.sort(fe);
197
+ let l = i;
198
+ for (let e = 0; e < l; e++) {
199
+ let n = t[e];
200
+ for (; e + 1 < l && t[e + 1].candidate === n.candidate;) t.splice(e + 1, 1), l--;
201
+ }
202
+ for (let r = u; r < d; r += 6) {
203
+ let i = n[r + 2 * e];
204
+ for (let e = 0; e < l; e++) {
205
+ let a = t[e];
206
+ i >= a.candidate ? ce(r, n, a.rightCacheBounds) : (ce(r, n, a.leftCacheBounds), a.count++);
207
+ }
208
+ }
209
+ for (let n = 0; n < l; n++) {
210
+ let r = t[n], l = r.count, u = i - r.count, d = r.leftCacheBounds, f = r.rightCacheBounds, p = 0;
211
+ l !== 0 && (p = le(d) / a);
212
+ let m = 0;
213
+ u !== 0 && (m = le(f) / a);
214
+ let h = 1 + te * (p * l + m * u);
215
+ h < c && (o = e, c = h, s = r.candidate);
216
+ }
217
+ } else {
218
+ for (let e = 0; e < F; e++) {
219
+ let t = I[e];
220
+ t.count = 0, t.candidate = r + l + e * l;
221
+ let n = t.bounds;
222
+ for (let e = 0; e < 3; e++) n[e] = Infinity, n[e + 3] = -Infinity;
223
+ }
224
+ for (let t = u; t < d; t += 6) {
225
+ let i = ~~((n[t + 2 * e] - r) / l);
226
+ i >= F && (i = F - 1);
227
+ let a = I[i];
228
+ a.count++, ce(t, n, a.bounds);
229
+ }
230
+ let t = I[F - 1];
231
+ oe(t.bounds, t.rightCacheBounds);
232
+ for (let e = F - 2; e >= 0; e--) {
233
+ let t = I[e], n = I[e + 1];
234
+ se(t.bounds, n.rightCacheBounds, t.rightCacheBounds);
235
+ }
236
+ let f = 0;
237
+ for (let t = 0; t < F - 1; t++) {
238
+ let n = I[t], r = n.count, l = n.bounds, u = I[t + 1].rightCacheBounds;
239
+ r !== 0 && (f === 0 ? oe(l, pe) : se(l, pe, pe)), f += r;
240
+ let d = 0, p = 0;
241
+ f !== 0 && (d = le(pe) / a);
242
+ let m = i - f;
243
+ m !== 0 && (p = le(u) / a);
244
+ let h = 1 + te * (d * f + p * m);
245
+ h < c && (o = e, c = h, s = n.candidate);
246
+ }
247
+ }
248
+ }
249
+ } else console.warn(`BVH: Invalid build strategy value ${a} used.`);
250
+ return {
251
+ axis: o,
252
+ pos: s
253
+ };
254
+ }
255
+ function he(e, t, n, r) {
256
+ let i = 0, a = e.offset;
257
+ for (let o = t, s = t + n; o < s; o++) i += e[(o - a) * 6 + r * 2];
258
+ return i / n;
259
+ }
260
+ //#endregion
261
+ //#region node_modules/three-mesh-bvh/src/core/BVHNode.js
262
+ var ge = class {
263
+ constructor() {
264
+ this.boundingData = /* @__PURE__ */ new Float32Array(6);
265
+ }
266
+ };
267
+ //#endregion
268
+ //#region node_modules/three-mesh-bvh/src/core/build/sortUtils.js
269
+ function _e(e, t, n, r, i, a) {
270
+ let o = r, s = r + i - 1, c = a.pos, l = a.axis * 2, u = n.offset || 0;
271
+ for (;;) {
272
+ for (; o <= s && n[(o - u) * 6 + l] < c;) o++;
273
+ for (; o <= s && n[(s - u) * 6 + l] >= c;) s--;
274
+ if (o < s) {
275
+ for (let n = 0; n < t; n++) {
276
+ let r = e[o * t + n];
277
+ e[o * t + n] = e[s * t + n], e[s * t + n] = r;
278
+ }
279
+ for (let e = 0; e < 6; e++) {
280
+ let t = o - u, r = s - u, i = n[t * 6 + e];
281
+ n[t * 6 + e] = n[r * 6 + e], n[r * 6 + e] = i;
282
+ }
283
+ o++, s--;
284
+ } else return o;
285
+ }
286
+ }
287
+ //#endregion
288
+ //#region node_modules/three-mesh-bvh/src/core/build/buildUtils.js
289
+ var ve, ye, be, xe, Se = 2 ** 32;
290
+ function Ce(e) {
291
+ return "count" in e ? 1 : 1 + Ce(e.left) + Ce(e.right);
292
+ }
293
+ function we(e, t, n) {
294
+ return ve = new Float32Array(n), ye = new Uint32Array(n), be = new Uint16Array(n), xe = new Uint8Array(n), Te(e, t);
295
+ }
296
+ function Te(e, t) {
297
+ let n = e / 4, r = e / 2, i = "count" in t, a = t.boundingData;
298
+ for (let e = 0; e < 6; e++) ve[n + e] = a[e];
299
+ if (i) return t.buffer ? (xe.set(new Uint8Array(t.buffer), e), e + t.buffer.byteLength) : (ye[n + 6] = t.offset, be[r + 14] = t.count, be[r + 15] = E, e + 32);
300
+ {
301
+ let { left: r, right: i, splitAxis: a } = t, o = Te(e + 32, r), s = e / 32, c = o / 32 - s;
302
+ if (c > Se) throw Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");
303
+ return ye[n + 6] = c, ye[n + 7] = a, Te(o, i);
304
+ }
305
+ }
306
+ //#endregion
307
+ //#region node_modules/three-mesh-bvh/src/core/build/buildTree.js
308
+ function Ee(e, t, n, r, i, a) {
309
+ let { maxDepth: o, verbose: s, targetLeafSize: c, _strictLeafSize: l = Infinity, strategy: u, onProgress: d } = i, f = e.primitiveBuffer, p = e.primitiveBufferStride, m = /* @__PURE__ */ new Float32Array(6), h = !1, g = new ge();
310
+ return de(t, n, r, g.boundingData, m), v(g, n, r, m), g;
311
+ function _(e) {
312
+ d && d((e - a.offset) / a.count);
313
+ }
314
+ function v(e, n, r, i = null, a = 0) {
315
+ !h && a >= o && (h = !0, s && console.warn(`BVH: Max depth of ${o} reached when generating BVH. Consider increasing maxDepth.`));
316
+ let d = r > l;
317
+ if (r <= c && !d || a >= o) return _(n + r), e.offset = n, e.count = r, e;
318
+ let g = me(e.boundingData, i, t, n, r, u), y = g.axis === -1 ? -1 : _e(f, p, t, n, r, g);
319
+ if (g.axis === -1 || y === n || y === n + r) {
320
+ if (!d) return _(n + r), e.offset = n, e.count = r, e;
321
+ g.axis = Math.max(0, ae(e.boundingData)), y = n + Math.max(1, Math.floor(r / 2));
322
+ }
323
+ e.splitAxis = g.axis;
324
+ let b = new ge(), x = n, S = y - n;
325
+ e.left = b, de(t, x, S, b.boundingData, m), v(b, x, S, m, a + 1);
326
+ let C = new ge(), w = y, T = r - S;
327
+ return e.right = C, de(t, w, T, C.boundingData, m), v(C, w, T, m, a + 1), e;
328
+ }
329
+ }
330
+ function De(e, t) {
331
+ let n = t.useSharedArrayBuffer ? SharedArrayBuffer : ArrayBuffer, r = e.getRootRanges(t.range), i = r[0], a = r[r.length - 1], o = {
332
+ offset: i.offset,
333
+ count: a.offset + a.count - i.offset
334
+ }, s = new Float32Array(6 * o.count);
335
+ s.offset = o.offset, e.computePrimitiveBounds(o.offset, o.count, s), e._roots = r.map((r) => {
336
+ let i = Ee(e, s, r.offset, r.count, t, o), a = Ce(i), c = new n(32 * a);
337
+ return we(0, i, c), c;
338
+ });
339
+ }
340
+ //#endregion
341
+ //#region node_modules/three-mesh-bvh/src/utils/PrimitivePool.js
342
+ var Oe = class {
343
+ constructor(e) {
344
+ this._getNewPrimitive = e, this._primitives = [];
345
+ }
346
+ getPrimitive() {
347
+ let e = this._primitives;
348
+ return e.length === 0 ? this._getNewPrimitive() : e.pop();
349
+ }
350
+ releasePrimitive(e) {
351
+ this._primitives.push(e);
352
+ }
353
+ }, L = /* @__PURE__ */ new class {
354
+ constructor() {
355
+ this.float32Array = null, this.uint16Array = null, this.uint32Array = null;
356
+ let e = [], t = null;
357
+ this.setBuffer = (n) => {
358
+ t && e.push(t), t = n, this.float32Array = new Float32Array(n), this.uint16Array = new Uint16Array(n), this.uint32Array = new Uint32Array(n);
359
+ }, this.clearBuffer = () => {
360
+ t = null, this.float32Array = null, this.uint16Array = null, this.uint32Array = null, e.length !== 0 && this.setBuffer(e.pop());
361
+ };
362
+ }
363
+ }(), R, ke, Ae = [], je = /* @__PURE__ */ new Oe(() => new r());
364
+ function Me(e, t, n, r, i, a) {
365
+ R = je.getPrimitive(), ke = je.getPrimitive(), Ae.push(R, ke), L.setBuffer(e._roots[t]);
366
+ let o = Ne(0, e.geometry, n, r, i, a);
367
+ L.clearBuffer(), je.releasePrimitive(R), je.releasePrimitive(ke), Ae.pop(), Ae.pop();
368
+ let s = Ae.length;
369
+ return s > 0 && (ke = Ae[s - 1], R = Ae[s - 2]), o;
370
+ }
371
+ function Ne(e, t, n, r, i = null, a = 0, o = 0) {
372
+ let { float32Array: s, uint16Array: c, uint32Array: l } = L, u = e * 2;
373
+ if (k(u, c)) {
374
+ let t = A(e, l), n = j(u, c);
375
+ return O(P(e), s, R), r(t, n, !1, o, a + e / 8, R);
376
+ } else {
377
+ let u = M(e), d = N(e, l), f = u, p = d, m, h, g, _;
378
+ if (i && (g = R, _ = ke, O(P(f), s, g), O(P(p), s, _), m = i(g), h = i(_), h < m)) {
379
+ f = d, p = u;
380
+ let e = m;
381
+ m = h, h = e, g = _;
382
+ }
383
+ g || (g = R, O(P(f), s, g));
384
+ let v = k(f * 2, c), y = n(g, v, m, o + 1, a + f / 8), b;
385
+ if (y === 2) {
386
+ let e = w(f);
387
+ b = r(e, T(f) - e, !0, o + 1, a + f / 8, g);
388
+ } else b = y && Ne(f, t, n, r, i, a, o + 1);
389
+ if (b) return !0;
390
+ _ = ke, O(P(p), s, _);
391
+ let x = k(p * 2, c), S = n(_, x, h, o + 1, a + p / 8), C;
392
+ if (S === 2) {
393
+ let e = w(p);
394
+ C = r(e, T(p) - e, !0, o + 1, a + p / 8, _);
395
+ } else C = S && Ne(p, t, n, r, i, a, o + 1);
396
+ if (C) return !0;
397
+ return !1;
398
+ function w(e) {
399
+ let { uint16Array: t, uint32Array: n } = L, r = e * 2;
400
+ for (; !k(r, t);) e = M(e), r = e * 2;
401
+ return A(e, n);
402
+ }
403
+ function T(e) {
404
+ let { uint16Array: t, uint32Array: n } = L, r = e * 2;
405
+ for (; !k(r, t);) e = N(e, n), r = e * 2;
406
+ return A(e, n) + j(r, t);
407
+ }
408
+ }
409
+ }
410
+ //#endregion
411
+ //#region node_modules/three-mesh-bvh/src/core/cast/bvhcast.js
412
+ var Pe = /* @__PURE__ */ new L.constructor(), Fe = /* @__PURE__ */ new L.constructor(), z = /* @__PURE__ */ new Oe(() => new r()), B = /* @__PURE__ */ new r(), Ie = /* @__PURE__ */ new r(), Le = /* @__PURE__ */ new r(), Re = /* @__PURE__ */ new r(), ze = !1;
413
+ function Be(e, t, n, r) {
414
+ if (ze) throw Error("MeshBVH: Recursive calls to bvhcast not supported.");
415
+ ze = !0;
416
+ let i = e._roots, a = t._roots, o, s = 0, c = 0, l = new d().copy(n).invert();
417
+ for (let e = 0, t = i.length; e < t; e++) {
418
+ Pe.setBuffer(i[e]), c = 0;
419
+ let t = z.getPrimitive();
420
+ O(P(0), Pe.float32Array, t), t.applyMatrix4(l);
421
+ for (let e = 0, i = a.length; e < i && (Fe.setBuffer(a[e]), o = V(0, 0, n, l, r, s, c, 0, 0, t), Fe.clearBuffer(), c += a[e].byteLength / 32, !o); e++);
422
+ if (z.releasePrimitive(t), Pe.clearBuffer(), s += i[e].byteLength / 32, o) break;
423
+ }
424
+ return ze = !1, o;
425
+ }
426
+ function V(e, t, n, r, i, a = 0, o = 0, s = 0, c = 0, l = null, u = !1) {
427
+ let d, f;
428
+ u ? (d = Fe, f = Pe) : (d = Pe, f = Fe);
429
+ let p = d.float32Array, m = d.uint32Array, h = d.uint16Array, g = f.float32Array, _ = f.uint32Array, v = f.uint16Array, y = e * 2, b = t * 2, x = k(y, h), S = k(b, v), C = !1;
430
+ if (S && x) C = u ? i(A(t, _), j(t * 2, v), A(e, m), j(e * 2, h), c, o + t / 8, s, a + e / 8) : i(A(e, m), j(e * 2, h), A(t, _), j(t * 2, v), s, a + e / 8, c, o + t / 8);
431
+ else if (S) {
432
+ let l = z.getPrimitive();
433
+ O(P(t), g, l), l.applyMatrix4(n);
434
+ let d = M(e), f = N(e, m);
435
+ O(P(d), p, B), O(P(f), p, Ie);
436
+ let h = l.intersectsBox(B), _ = l.intersectsBox(Ie);
437
+ C = h && V(t, d, r, n, i, o, a, c, s + 1, l, !u) || _ && V(t, f, r, n, i, o, a, c, s + 1, l, !u), z.releasePrimitive(l);
438
+ } else {
439
+ let d = M(t), f = N(t, _);
440
+ O(P(d), g, Le), O(P(f), g, Re);
441
+ let h = l.intersectsBox(Le), v = l.intersectsBox(Re);
442
+ if (h && v) C = V(e, d, n, r, i, a, o, s, c + 1, l, u) || V(e, f, n, r, i, a, o, s, c + 1, l, u);
443
+ else if (h) if (x) C = V(e, d, n, r, i, a, o, s, c + 1, l, u);
444
+ else {
445
+ let t = z.getPrimitive();
446
+ t.copy(Le).applyMatrix4(n);
447
+ let l = M(e), f = N(e, m);
448
+ O(P(l), p, B), O(P(f), p, Ie);
449
+ let h = t.intersectsBox(B), g = t.intersectsBox(Ie);
450
+ C = h && V(d, l, r, n, i, o, a, c, s + 1, t, !u) || g && V(d, f, r, n, i, o, a, c, s + 1, t, !u), z.releasePrimitive(t);
451
+ }
452
+ else if (v) if (x) C = V(e, f, n, r, i, a, o, s, c + 1, l, u);
453
+ else {
454
+ let t = z.getPrimitive();
455
+ t.copy(Re).applyMatrix4(n);
456
+ let l = M(e), d = N(e, m);
457
+ O(P(l), p, B), O(P(d), p, Ie);
458
+ let h = t.intersectsBox(B), g = t.intersectsBox(Ie);
459
+ C = h && V(f, l, r, n, i, o, a, c, s + 1, t, !u) || g && V(f, d, r, n, i, o, a, c, s + 1, t, !u), z.releasePrimitive(t);
460
+ }
461
+ }
462
+ return C;
463
+ }
464
+ //#endregion
465
+ //#region node_modules/three-mesh-bvh/src/core/BVHTraversalHelper.js
466
+ var Ve = new class {
467
+ constructor() {
468
+ let e = null, t = null, n = null, r = !1;
469
+ this.root = null, this.buffer = null, this.uint32Array = null, this.uint16Array = null, this.setBVH = (i, a) => {
470
+ if (r) throw Error("BVHTraversalHelper: cannot call setBVH during an active traversal.");
471
+ this.root = a, this.buffer = e = i._roots[a], this.uint16Array = n = new Uint16Array(e), this.uint32Array = t = new Uint32Array(e);
472
+ }, this.reset = () => {
473
+ this.root = null, this.buffer = e = null, this.uint16Array = n = null, this.uint32Array = t = null;
474
+ }, this.getRangeStart = (e) => {
475
+ let r = e * 2;
476
+ for (; !k(r, n);) e = M(e), r = e * 2;
477
+ return A(e, t);
478
+ }, this.getRangeEnd = (e) => {
479
+ let r = e * 2;
480
+ for (; !k(r, n);) e = N(e, t), r = e * 2;
481
+ return A(e, t) + j(r, n);
482
+ };
483
+ let i = (e, r, a) => {
484
+ let o = k(r * 2, n);
485
+ if (!e(a, o, r) && !o) {
486
+ let n = M(r), o = N(r, t);
487
+ i(e, n, a + 1), i(e, o, a + 1);
488
+ }
489
+ };
490
+ this.traverseBuffer = (e) => {
491
+ if (r) throw Error("BVHTraversalHelper: cannot start a traversal during an active traversal.");
492
+ r = !0;
493
+ try {
494
+ i(e, 0, 0);
495
+ } finally {
496
+ r = !1;
497
+ }
498
+ }, this.traverse = (r) => {
499
+ this.traverseBuffer((i, a, o) => {
500
+ if (a) {
501
+ let s = o * 2, c = t[o + 6], l = n[s + 14];
502
+ return r(i, a, new Float32Array(e, o * 4, 6), c, l);
503
+ } else {
504
+ let n = ue(o, t);
505
+ return r(i, a, new Float32Array(e, o * 4, 6), n);
506
+ }
507
+ });
508
+ };
509
+ }
510
+ }(), He = /* @__PURE__ */ new r(), Ue = /* @__PURE__ */ new Float32Array(6), We = class {
511
+ constructor() {
512
+ this._roots = null, this.primitiveBuffer = null, this.primitiveBufferStride = null;
513
+ }
514
+ init(e) {
515
+ e = {
516
+ ...ie,
517
+ ...e
518
+ }, "maxLeafSize" in e && (console.warn("BVH: \"maxLeafSize\" option has been deprecated. Use \"targetLeafSize\", instead."), e = {
519
+ ...e,
520
+ targetLeafSize: e.maxLeafSize
521
+ }), De(this, e);
522
+ }
523
+ getRootRanges() {
524
+ throw Error("BVH: getRootRanges() not implemented");
525
+ }
526
+ writePrimitiveBounds() {
527
+ throw Error("BVH: writePrimitiveBounds() not implemented");
528
+ }
529
+ writePrimitiveRangeBounds(e, t, n, r) {
530
+ let i = Infinity, a = Infinity, o = Infinity, s = -Infinity, c = -Infinity, l = -Infinity;
531
+ for (let n = e, r = e + t; n < r; n++) {
532
+ this.writePrimitiveBounds(n, Ue, 0);
533
+ let [e, t, r, u, d, f] = Ue;
534
+ e < i && (i = e), u > s && (s = u), t < a && (a = t), d > c && (c = d), r < o && (o = r), f > l && (l = f);
535
+ }
536
+ return n[r + 0] = i, n[r + 1] = a, n[r + 2] = o, n[r + 3] = s, n[r + 4] = c, n[r + 5] = l, n;
537
+ }
538
+ computePrimitiveBounds(e, t, n) {
539
+ let r = n.offset || 0;
540
+ for (let i = e, a = e + t; i < a; i++) {
541
+ this.writePrimitiveBounds(i, Ue, 0);
542
+ let [e, t, a, o, s, c] = Ue, l = (e + o) / 2, u = (t + s) / 2, d = (a + c) / 2, f = (o - e) / 2, p = (s - t) / 2, m = (c - a) / 2, h = (i - r) * 6;
543
+ n[h + 0] = l, n[h + 1] = f + (Math.abs(l) + f) * re, n[h + 2] = u, n[h + 3] = p + (Math.abs(u) + p) * re, n[h + 4] = d, n[h + 5] = m + (Math.abs(d) + m) * re;
544
+ }
545
+ return n;
546
+ }
547
+ shiftPrimitiveOffsets(e) {
548
+ let t = this._indirectBuffer;
549
+ if (t) for (let n = 0, r = t.length; n < r; n++) t[n] += e;
550
+ else {
551
+ let t = this._roots;
552
+ for (let n = 0; n < t.length; n++) {
553
+ let r = t[n], i = new Uint32Array(r), a = new Uint16Array(r), o = r.byteLength / 32;
554
+ for (let t = 0; t < o; t++) {
555
+ let n = 8 * t;
556
+ k(2 * n, a) && (i[n + 6] += e);
557
+ }
558
+ }
559
+ }
560
+ }
561
+ traverse(e, t = 0) {
562
+ Ve.setBVH(this, t), Ve.traverse(e), Ve.reset();
563
+ }
564
+ refit() {
565
+ let e = this._roots;
566
+ for (let t = 0, n = e.length; t < n; t++) {
567
+ let n = e[t], r = new Uint32Array(n), i = new Uint16Array(n), a = new Float32Array(n), o = n.byteLength / 32;
568
+ for (let e = o - 1; e >= 0; e--) {
569
+ let t = e * 8, n = t * 2;
570
+ if (k(n, i)) {
571
+ let e = A(t, r), o = j(n, i);
572
+ this.writePrimitiveRangeBounds(e, o, Ue, 0), a.set(Ue, t);
573
+ } else {
574
+ let e = M(t), n = N(t, r);
575
+ for (let r = 0; r < 3; r++) {
576
+ let i = a[e + r], o = a[e + r + 3], s = a[n + r], c = a[n + r + 3];
577
+ a[t + r] = i < s ? i : s, a[t + r + 3] = o > c ? o : c;
578
+ }
579
+ }
580
+ }
581
+ }
582
+ }
583
+ getBoundingBox(e) {
584
+ return e.makeEmpty(), this._roots.forEach((t) => {
585
+ O(0, new Float32Array(t), He), e.union(He);
586
+ }), e;
587
+ }
588
+ shapecast(e) {
589
+ let { boundsTraverseOrder: t, intersectsBounds: n, intersectsRange: r, intersectsPrimitive: i, scratchPrimitive: a, iterate: o } = e;
590
+ if (r && i) {
591
+ let e = r;
592
+ r = (t, n, r, s, c) => e(t, n, r, s, c) ? !0 : o(t, n, this, i, r, s, a);
593
+ } else r ||= i ? (e, t, n, r) => o(e, t, this, i, n, r, a) : (e, t, n) => n;
594
+ let s = !1, c = 0, l = this._roots;
595
+ for (let e = 0, i = l.length; e < i; e++) {
596
+ let i = l[e];
597
+ if (s = Me(this, e, n, r, t, c), s) break;
598
+ c += i.byteLength / 32;
599
+ }
600
+ return s;
601
+ }
602
+ bvhcast(e, t, n) {
603
+ let { intersectsRanges: r } = n;
604
+ return Be(this, e, t, r);
605
+ }
606
+ };
607
+ //#endregion
608
+ //#region node_modules/three-mesh-bvh/src/utils/BufferUtils.js
609
+ function Ge() {
610
+ return typeof SharedArrayBuffer < "u";
611
+ }
612
+ //#endregion
613
+ //#region node_modules/three-mesh-bvh/src/core/build/geometryUtils.js
614
+ function Ke(e) {
615
+ return e.index ? e.index.count : e.attributes.position.count;
616
+ }
617
+ function qe(e) {
618
+ return Ke(e) / 3;
619
+ }
620
+ function Je(e, t = ArrayBuffer) {
621
+ return e > 65535 ? new Uint32Array(new t(4 * e)) : new Uint16Array(new t(2 * e));
622
+ }
623
+ function Ye(e, t) {
624
+ if (!e.index) {
625
+ let n = e.attributes.position.count, r = Je(n, t.useSharedArrayBuffer ? SharedArrayBuffer : ArrayBuffer);
626
+ e.setIndex(new i(r, 1));
627
+ for (let e = 0; e < n; e++) r[e] = e;
628
+ }
629
+ }
630
+ function Xe(e, t, n) {
631
+ let r = Ke(e) / n, i = t || e.drawRange, a = i.start / n, o = (i.start + i.count) / n, s = Math.max(0, a), c = Math.min(r, o) - s;
632
+ return {
633
+ offset: Math.floor(s),
634
+ count: Math.floor(c)
635
+ };
636
+ }
637
+ function Ze(e, t) {
638
+ return e.groups.map((e) => ({
639
+ offset: e.start / t,
640
+ count: e.count / t
641
+ }));
642
+ }
643
+ function Qe(e, t, n) {
644
+ let r = Xe(e, t, n), i = Ze(e, n);
645
+ if (!i.length) return [r];
646
+ let a = [], o = r.offset, s = r.offset + r.count, c = Ke(e) / n, l = [];
647
+ for (let e of i) {
648
+ let { offset: t, count: n } = e, r = t, i = t + (isFinite(n) ? n : c - t);
649
+ r < s && i > o && (l.push({
650
+ pos: Math.max(o, r),
651
+ isStart: !0
652
+ }), l.push({
653
+ pos: Math.min(s, i),
654
+ isStart: !1
655
+ }));
656
+ }
657
+ l.sort((e, t) => e.pos === t.pos ? e.type === "end" ? -1 : 1 : e.pos - t.pos);
658
+ let u = 0, d = null;
659
+ for (let e of l) {
660
+ let t = e.pos;
661
+ u !== 0 && t !== d && a.push({
662
+ offset: d,
663
+ count: t - d
664
+ }), u += e.isStart ? 1 : -1, d = t;
665
+ }
666
+ return a;
667
+ }
668
+ //#endregion
669
+ //#region node_modules/three-mesh-bvh/src/core/GeometryBVH.js
670
+ function $e(e, t) {
671
+ let n = e[e.length - 1], r = n.offset + n.count > 2 ** 16, i = e.reduce((e, t) => e + t.count, 0), a = r ? 4 : 2, o = t ? new SharedArrayBuffer(i * a) : new ArrayBuffer(i * a), s = r ? new Uint32Array(o) : new Uint16Array(o), c = 0;
672
+ for (let t = 0; t < e.length; t++) {
673
+ let { offset: n, count: r } = e[t];
674
+ for (let e = 0; e < r; e++) s[c + e] = n + e;
675
+ c += r;
676
+ }
677
+ return s;
678
+ }
679
+ var et = class extends We {
680
+ get indirect() {
681
+ return !!this._indirectBuffer;
682
+ }
683
+ get primitiveStride() {
684
+ return null;
685
+ }
686
+ get primitiveBufferStride() {
687
+ return this.indirect ? 1 : this.primitiveStride;
688
+ }
689
+ set primitiveBufferStride(e) {}
690
+ get primitiveBuffer() {
691
+ return this.indirect ? this._indirectBuffer : this.geometry.index.array;
692
+ }
693
+ set primitiveBuffer(e) {}
694
+ constructor(e, t = {}) {
695
+ if (!e.isBufferGeometry) throw Error("BVH: Only BufferGeometries are supported.");
696
+ if (e.index && e.index.isInterleavedBufferAttribute) throw Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.");
697
+ if (t.useSharedArrayBuffer && !Ge()) throw Error("BVH: SharedArrayBuffer is not available.");
698
+ super(), this.geometry = e, this.resolvePrimitiveIndex = t.indirect ? (e) => this._indirectBuffer[e] : (e) => e, this.primitiveBuffer = null, this.primitiveBufferStride = null, this._indirectBuffer = null, t = {
699
+ ...ie,
700
+ ...t
701
+ }, t[D] || this.init(t);
702
+ }
703
+ init(e) {
704
+ let { geometry: t, primitiveStride: n } = this;
705
+ if (e.indirect) {
706
+ let r = $e(Qe(t, e.range, n), e.useSharedArrayBuffer);
707
+ this._indirectBuffer = r;
708
+ } else Ye(t, e);
709
+ super.init(e), !t.boundingBox && e.setBoundingBox && (t.boundingBox = this.getBoundingBox(new r()));
710
+ }
711
+ getRootRanges(e) {
712
+ return this.indirect ? [{
713
+ offset: 0,
714
+ count: this._indirectBuffer.length
715
+ }] : Qe(this.geometry, e, this.primitiveStride);
716
+ }
717
+ raycastObject3D() {
718
+ throw Error("BVH: raycastObject3D() not implemented");
719
+ }
720
+ }, H = class {
721
+ constructor() {
722
+ this.min = Infinity, this.max = -Infinity;
723
+ }
724
+ setFromPointsField(e, t) {
725
+ let n = Infinity, r = -Infinity;
726
+ for (let i = 0, a = e.length; i < a; i++) {
727
+ let a = e[i][t];
728
+ n = a < n ? a : n, r = a > r ? a : r;
729
+ }
730
+ this.min = n, this.max = r;
731
+ }
732
+ setFromPoints(e, t) {
733
+ let n = Infinity, r = -Infinity;
734
+ for (let i = 0, a = t.length; i < a; i++) {
735
+ let a = t[i], o = e.dot(a);
736
+ n = o < n ? o : n, r = o > r ? o : r;
737
+ }
738
+ this.min = n, this.max = r;
739
+ }
740
+ isSeparated(e) {
741
+ return this.min > e.max || e.min > this.max;
742
+ }
743
+ };
744
+ H.prototype.setFromBox = (function() {
745
+ let e = /* @__PURE__ */ new b();
746
+ return function(t, n) {
747
+ let r = n.min, i = n.max, a = Infinity, o = -Infinity;
748
+ for (let n = 0; n <= 1; n++) for (let s = 0; s <= 1; s++) for (let c = 0; c <= 1; c++) {
749
+ e.x = r.x * n + i.x * (1 - n), e.y = r.y * s + i.y * (1 - s), e.z = r.z * c + i.z * (1 - c);
750
+ let l = t.dot(e);
751
+ a = Math.min(l, a), o = Math.max(l, o);
752
+ }
753
+ this.min = a, this.max = o;
754
+ };
755
+ })();
756
+ //#endregion
757
+ //#region node_modules/three-mesh-bvh/src/math/MathUtilities.js
758
+ var tt = (function() {
759
+ let e = /* @__PURE__ */ new b(), t = /* @__PURE__ */ new b(), n = /* @__PURE__ */ new b();
760
+ return function(r, i, a) {
761
+ let o = r.start, s = e, c = i.start, l = t;
762
+ n.subVectors(o, c), e.subVectors(r.end, r.start), t.subVectors(i.end, i.start);
763
+ let u = n.dot(l), d = l.dot(s), f = l.dot(l), p = n.dot(s), m = s.dot(s) * f - d * d, h, g;
764
+ h = m === 0 ? 0 : (u * d - p * f) / m, g = (u + h * d) / f, a.x = h, a.y = g;
765
+ };
766
+ })(), nt = (function() {
767
+ let e = /* @__PURE__ */ new y(), t = /* @__PURE__ */ new b(), n = /* @__PURE__ */ new b();
768
+ return function(r, i, a, o) {
769
+ tt(r, i, e);
770
+ let s = e.x, c = e.y;
771
+ if (s >= 0 && s <= 1 && c >= 0 && c <= 1) {
772
+ r.at(s, a), i.at(c, o);
773
+ return;
774
+ } else if (s >= 0 && s <= 1) {
775
+ c < 0 ? i.at(0, o) : i.at(1, o), r.closestPointToPoint(o, !0, a);
776
+ return;
777
+ } else if (c >= 0 && c <= 1) {
778
+ s < 0 ? r.at(0, a) : r.at(1, a), i.closestPointToPoint(a, !0, o);
779
+ return;
780
+ } else {
781
+ let e;
782
+ e = s < 0 ? r.start : r.end;
783
+ let l;
784
+ l = c < 0 ? i.start : i.end;
785
+ let u = t, d = n;
786
+ if (r.closestPointToPoint(l, !0, t), i.closestPointToPoint(e, !0, n), u.distanceToSquared(l) <= d.distanceToSquared(e)) {
787
+ a.copy(u), o.copy(l);
788
+ return;
789
+ } else {
790
+ a.copy(e), o.copy(d);
791
+ return;
792
+ }
793
+ }
794
+ };
795
+ })(), rt = (function() {
796
+ let e = /* @__PURE__ */ new b(), t = /* @__PURE__ */ new b(), n = /* @__PURE__ */ new p(), r = /* @__PURE__ */ new c();
797
+ return function(i, a) {
798
+ let { radius: o, center: s } = i, { a: c, b: l, c: u } = a;
799
+ if (r.start = c, r.end = l, r.closestPointToPoint(s, !0, e).distanceTo(s) <= o || (r.start = c, r.end = u, r.closestPointToPoint(s, !0, e).distanceTo(s) <= o) || (r.start = l, r.end = u, r.closestPointToPoint(s, !0, e).distanceTo(s) <= o)) return !0;
800
+ let d = a.getPlane(n);
801
+ if (Math.abs(d.distanceToPoint(s)) <= o) {
802
+ let e = d.projectPoint(s, t);
803
+ if (a.containsPoint(e)) return !0;
804
+ }
805
+ return !1;
806
+ };
807
+ })(), it = [
808
+ "x",
809
+ "y",
810
+ "z"
811
+ ], U = 1e-15, at = U * U;
812
+ function W(e) {
813
+ return Math.abs(e) < U;
814
+ }
815
+ var G = class extends v {
816
+ constructor(...e) {
817
+ super(...e), this.isExtendedTriangle = !0, this.satAxes = [
818
+ ,
819
+ ,
820
+ ,
821
+ ,
822
+ ].fill().map(() => new b()), this.satBounds = [
823
+ ,
824
+ ,
825
+ ,
826
+ ,
827
+ ].fill().map(() => new H()), this.points = [
828
+ this.a,
829
+ this.b,
830
+ this.c
831
+ ], this.plane = new p(), this.isDegenerateIntoSegment = !1, this.isDegenerateIntoPoint = !1, this.degenerateSegment = new c(), this.needsUpdate = !0;
832
+ }
833
+ intersectsSphere(e) {
834
+ return rt(e, this);
835
+ }
836
+ update() {
837
+ let e = this.a, t = this.b, n = this.c, r = this.points, i = this.satAxes, a = this.satBounds, o = i[0], s = a[0];
838
+ this.getNormal(o), s.setFromPoints(o, r);
839
+ let c = i[1], l = a[1];
840
+ c.subVectors(e, t), l.setFromPoints(c, r);
841
+ let u = i[2], d = a[2];
842
+ u.subVectors(t, n), d.setFromPoints(u, r);
843
+ let f = i[3], p = a[3];
844
+ f.subVectors(n, e), p.setFromPoints(f, r);
845
+ let m = c.length(), h = u.length(), g = f.length();
846
+ this.isDegenerateIntoPoint = !1, this.isDegenerateIntoSegment = !1, m < U ? h < U || g < U ? this.isDegenerateIntoPoint = !0 : (this.isDegenerateIntoSegment = !0, this.degenerateSegment.start.copy(e), this.degenerateSegment.end.copy(n)) : h < U ? g < U ? this.isDegenerateIntoPoint = !0 : (this.isDegenerateIntoSegment = !0, this.degenerateSegment.start.copy(t), this.degenerateSegment.end.copy(e)) : g < U && (this.isDegenerateIntoSegment = !0, this.degenerateSegment.start.copy(n), this.degenerateSegment.end.copy(t)), this.plane.setFromNormalAndCoplanarPoint(o, e), this.needsUpdate = !1;
847
+ }
848
+ };
849
+ G.prototype.closestPointToSegment = (function() {
850
+ let e = /* @__PURE__ */ new b(), t = /* @__PURE__ */ new b(), n = /* @__PURE__ */ new c();
851
+ return function(r, i = null, a = null) {
852
+ let { start: o, end: s } = r, c = this.points, l, u = Infinity;
853
+ for (let o = 0; o < 3; o++) {
854
+ let s = (o + 1) % 3;
855
+ n.start.copy(c[o]), n.end.copy(c[s]), nt(n, r, e, t), l = e.distanceToSquared(t), l < u && (u = l, i && i.copy(e), a && a.copy(t));
856
+ }
857
+ return this.closestPointToPoint(o, e), l = o.distanceToSquared(e), l < u && (u = l, i && i.copy(e), a && a.copy(o)), this.closestPointToPoint(s, e), l = s.distanceToSquared(e), l < u && (u = l, i && i.copy(e), a && a.copy(s)), Math.sqrt(u);
858
+ };
859
+ })(), G.prototype.intersectsTriangle = (function() {
860
+ let e = /* @__PURE__ */ new G(), t = /* @__PURE__ */ new H(), n = /* @__PURE__ */ new H(), r = /* @__PURE__ */ new b(), i = /* @__PURE__ */ new b(), a = /* @__PURE__ */ new b(), o = /* @__PURE__ */ new b(), s = /* @__PURE__ */ new c(), l = /* @__PURE__ */ new c(), u = /* @__PURE__ */ new b(), d = /* @__PURE__ */ new y(), f = /* @__PURE__ */ new y();
861
+ function p(e, i, a, s) {
862
+ let c = r;
863
+ !e.isDegenerateIntoPoint && !e.isDegenerateIntoSegment ? c.copy(e.plane.normal) : c.copy(i.plane.normal);
864
+ let l = e.satBounds, u = e.satAxes;
865
+ for (let r = 1; r < 4; r++) {
866
+ let a = l[r], s = u[r];
867
+ if (t.setFromPoints(s, i.points), a.isSeparated(t) || (o.copy(c).cross(s), t.setFromPoints(o, e.points), n.setFromPoints(o, i.points), t.isSeparated(n))) return !1;
868
+ }
869
+ let d = i.satBounds, f = i.satAxes;
870
+ for (let r = 1; r < 4; r++) {
871
+ let a = d[r], s = f[r];
872
+ if (t.setFromPoints(s, e.points), a.isSeparated(t) || (o.crossVectors(c, s), t.setFromPoints(o, e.points), n.setFromPoints(o, i.points), t.isSeparated(n))) return !1;
873
+ }
874
+ return a && (s || console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."), a.start.set(0, 0, 0), a.end.set(0, 0, 0)), !0;
875
+ }
876
+ function m(e, t, n, r, i, a, o, s, c, l, u) {
877
+ let d = o / (o - s);
878
+ l.x = r + (i - r) * d, u.start.subVectors(t, e).multiplyScalar(d).add(e), d = o / (o - c), l.y = r + (a - r) * d, u.end.subVectors(n, e).multiplyScalar(d).add(e);
879
+ }
880
+ function h(e, t, n, r, i, a, o, s, c, l, u) {
881
+ if (i > 0) m(e.c, e.a, e.b, r, t, n, c, o, s, l, u);
882
+ else if (a > 0) m(e.b, e.a, e.c, n, t, r, s, o, c, l, u);
883
+ else if (s * c > 0 || o != 0) m(e.a, e.b, e.c, t, n, r, o, s, c, l, u);
884
+ else if (s != 0) m(e.b, e.a, e.c, n, t, r, s, o, c, l, u);
885
+ else if (c != 0) m(e.c, e.a, e.b, r, t, n, c, o, s, l, u);
886
+ else return !0;
887
+ return !1;
888
+ }
889
+ function g(e, t, n, i) {
890
+ let a = t.degenerateSegment, o = e.plane.distanceToPoint(a.start), s = e.plane.distanceToPoint(a.end);
891
+ return W(o) ? W(s) ? p(e, t, n, i) : (n && (n.start.copy(a.start), n.end.copy(a.start)), e.containsPoint(a.start)) : W(s) ? (n && (n.start.copy(a.end), n.end.copy(a.end)), e.containsPoint(a.end)) : e.plane.intersectLine(a, r) == null ? !1 : (n && (n.start.copy(r), n.end.copy(r)), e.containsPoint(r));
892
+ }
893
+ function _(e, t, n) {
894
+ let r = t.a;
895
+ return W(e.plane.distanceToPoint(r)) && e.containsPoint(r) ? (n && (n.start.copy(r), n.end.copy(r)), !0) : !1;
896
+ }
897
+ function v(e, t, n) {
898
+ let i = e.degenerateSegment, a = t.a;
899
+ return i.closestPointToPoint(a, !0, r), a.distanceToSquared(r) < at ? (n && (n.start.copy(a), n.end.copy(a)), !0) : !1;
900
+ }
901
+ function x(e, t, n, o) {
902
+ if (e.isDegenerateIntoSegment) if (t.isDegenerateIntoSegment) {
903
+ let o = e.degenerateSegment, s = t.degenerateSegment, c = i, l = a;
904
+ o.delta(c), s.delta(l);
905
+ let u = r.subVectors(s.start, o.start), d = c.x * l.y - c.y * l.x;
906
+ if (W(d)) return !1;
907
+ let f = (u.x * l.y - u.y * l.x) / d, p = -(c.x * u.y - c.y * u.x) / d;
908
+ return f < 0 || f > 1 || p < 0 || p > 1 ? !1 : W(o.start.z + c.z * f - (s.start.z + l.z * p)) ? (n && (n.start.copy(o.start).addScaledVector(c, f), n.end.copy(o.start).addScaledVector(c, f)), !0) : !1;
909
+ } else if (t.isDegenerateIntoPoint) return v(e, t, n);
910
+ else return g(t, e, n, o);
911
+ else if (e.isDegenerateIntoPoint) return t.isDegenerateIntoPoint ? t.a.distanceToSquared(e.a) < at ? (n && (n.start.copy(e.a), n.end.copy(e.a)), !0) : !1 : t.isDegenerateIntoSegment ? v(t, e, n) : _(t, e, n);
912
+ else if (t.isDegenerateIntoPoint) return _(e, t, n);
913
+ else if (t.isDegenerateIntoSegment) return g(e, t, n, o);
914
+ }
915
+ return function(t, n = null, r = !1) {
916
+ this.needsUpdate && this.update(), t.isExtendedTriangle ? t.needsUpdate && t.update() : (e.copy(t), e.update(), t = e);
917
+ let o = x(this, t, n, r);
918
+ if (o !== void 0) return o;
919
+ let c = this.plane, m = t.plane, g = m.distanceToPoint(this.a), _ = m.distanceToPoint(this.b), v = m.distanceToPoint(this.c);
920
+ W(g) && (g = 0), W(_) && (_ = 0), W(v) && (v = 0);
921
+ let y = g * _, b = g * v;
922
+ if (y > 0 && b > 0) return !1;
923
+ let S = c.distanceToPoint(t.a), C = c.distanceToPoint(t.b), w = c.distanceToPoint(t.c);
924
+ W(S) && (S = 0), W(C) && (C = 0), W(w) && (w = 0);
925
+ let T = S * C, ee = S * w;
926
+ if (T > 0 && ee > 0) return !1;
927
+ i.copy(c.normal), a.copy(m.normal);
928
+ let te = i.cross(a), E = 0, ne = Math.abs(te.x), re = Math.abs(te.y);
929
+ re > ne && (ne = re, E = 1), Math.abs(te.z) > ne && (E = 2);
930
+ let D = it[E], ie = this.a[D], O = this.b[D], ae = this.c[D], oe = t.a[D], se = t.b[D], ce = t.c[D];
931
+ if (h(this, ie, O, ae, y, b, g, _, v, d, s) || h(t, oe, se, ce, T, ee, S, C, w, f, l)) return p(this, t, n, r);
932
+ if (d.y < d.x) {
933
+ let e = d.y;
934
+ d.y = d.x, d.x = e, u.copy(s.start), s.start.copy(s.end), s.end.copy(u);
935
+ }
936
+ if (f.y < f.x) {
937
+ let e = f.y;
938
+ f.y = f.x, f.x = e, u.copy(l.start), l.start.copy(l.end), l.end.copy(u);
939
+ }
940
+ return d.y < f.x || f.y < d.x ? !1 : (n && (f.x > d.x ? n.start.copy(l.start) : n.start.copy(s.start), f.y < d.y ? n.end.copy(l.end) : n.end.copy(s.end)), !0);
941
+ };
942
+ })(), G.prototype.distanceToPoint = (function() {
943
+ let e = /* @__PURE__ */ new b();
944
+ return function(t) {
945
+ return this.closestPointToPoint(t, e), t.distanceTo(e);
946
+ };
947
+ })(), G.prototype.distanceToTriangle = (function() {
948
+ let e = /* @__PURE__ */ new b(), t = /* @__PURE__ */ new b(), n = [
949
+ "a",
950
+ "b",
951
+ "c"
952
+ ], r = /* @__PURE__ */ new c(), i = /* @__PURE__ */ new c();
953
+ return function(a, o = null, s = null) {
954
+ let c = o || s ? r : null;
955
+ if (this.intersectsTriangle(a, c, !0)) return (o || s) && (o && c.getCenter(o), s && c.getCenter(s)), 0;
956
+ let l = Infinity;
957
+ for (let t = 0; t < 3; t++) {
958
+ let r, i = n[t], c = a[i];
959
+ this.closestPointToPoint(c, e), r = c.distanceToSquared(e), r < l && (l = r, o && o.copy(e), s && s.copy(c));
960
+ let u = this[i];
961
+ a.closestPointToPoint(u, e), r = u.distanceToSquared(e), r < l && (l = r, o && o.copy(u), s && s.copy(e));
962
+ }
963
+ for (let c = 0; c < 3; c++) {
964
+ let u = n[c], d = n[(c + 1) % 3];
965
+ r.set(this[u], this[d]);
966
+ for (let c = 0; c < 3; c++) {
967
+ let u = n[c], d = n[(c + 1) % 3];
968
+ i.set(a[u], a[d]), nt(r, i, e, t);
969
+ let f = e.distanceToSquared(t);
970
+ f < l && (l = f, o && o.copy(e), s && s.copy(t));
971
+ }
972
+ }
973
+ return Math.sqrt(l);
974
+ };
975
+ })();
976
+ //#endregion
977
+ //#region node_modules/three-mesh-bvh/src/math/OrientedBox.js
978
+ var K = class {
979
+ constructor(e, t, n) {
980
+ this.isOrientedBox = !0, this.min = new b(), this.max = new b(), this.matrix = new d(), this.invMatrix = new d(), this.points = Array(8).fill().map(() => new b()), this.satAxes = [
981
+ ,
982
+ ,
983
+ ,
984
+ ].fill().map(() => new b()), this.satBounds = [
985
+ ,
986
+ ,
987
+ ,
988
+ ].fill().map(() => new H()), this.alignedSatBounds = [
989
+ ,
990
+ ,
991
+ ,
992
+ ].fill().map(() => new H()), this.needsUpdate = !1, e && this.min.copy(e), t && this.max.copy(t), n && this.matrix.copy(n);
993
+ }
994
+ set(e, t, n) {
995
+ this.min.copy(e), this.max.copy(t), this.matrix.copy(n), this.needsUpdate = !0;
996
+ }
997
+ copy(e) {
998
+ this.min.copy(e.min), this.max.copy(e.max), this.matrix.copy(e.matrix), this.needsUpdate = !0;
999
+ }
1000
+ };
1001
+ K.prototype.update = (function() {
1002
+ return function() {
1003
+ let e = this.matrix, t = this.min, n = this.max, r = this.points;
1004
+ for (let i = 0; i <= 1; i++) for (let a = 0; a <= 1; a++) for (let o = 0; o <= 1; o++) {
1005
+ let s = r[1 * i | 2 * a | 4 * o];
1006
+ s.x = i ? n.x : t.x, s.y = a ? n.y : t.y, s.z = o ? n.z : t.z, s.applyMatrix4(e);
1007
+ }
1008
+ let i = this.satBounds, a = this.satAxes, o = r[0];
1009
+ for (let e = 0; e < 3; e++) {
1010
+ let t = a[e], n = i[e], s = r[1 << e];
1011
+ t.subVectors(o, s), n.setFromPoints(t, r);
1012
+ }
1013
+ let s = this.alignedSatBounds;
1014
+ s[0].setFromPointsField(r, "x"), s[1].setFromPointsField(r, "y"), s[2].setFromPointsField(r, "z"), this.invMatrix.copy(this.matrix).invert(), this.needsUpdate = !1;
1015
+ };
1016
+ })(), K.prototype.intersectsBox = (function() {
1017
+ let e = /* @__PURE__ */ new H();
1018
+ return function(t) {
1019
+ this.needsUpdate && this.update();
1020
+ let n = t.min, r = t.max, i = this.satBounds, a = this.satAxes, o = this.alignedSatBounds;
1021
+ if (e.min = n.x, e.max = r.x, o[0].isSeparated(e) || (e.min = n.y, e.max = r.y, o[1].isSeparated(e)) || (e.min = n.z, e.max = r.z, o[2].isSeparated(e))) return !1;
1022
+ for (let n = 0; n < 3; n++) {
1023
+ let r = a[n], o = i[n];
1024
+ if (e.setFromBox(r, t), o.isSeparated(e)) return !1;
1025
+ }
1026
+ return !0;
1027
+ };
1028
+ })(), K.prototype.intersectsTriangle = (function() {
1029
+ let e = /* @__PURE__ */ new G(), t = [
1030
+ ,
1031
+ ,
1032
+ ,
1033
+ ], n = /* @__PURE__ */ new H(), r = /* @__PURE__ */ new H(), i = /* @__PURE__ */ new b();
1034
+ return function(a) {
1035
+ this.needsUpdate && this.update(), a.isExtendedTriangle ? a.needsUpdate && a.update() : (e.copy(a), e.update(), a = e);
1036
+ let o = this.satBounds, s = this.satAxes;
1037
+ t[0] = a.a, t[1] = a.b, t[2] = a.c;
1038
+ for (let e = 0; e < 3; e++) {
1039
+ let r = o[e], i = s[e];
1040
+ if (n.setFromPoints(i, t), r.isSeparated(n)) return !1;
1041
+ }
1042
+ let c = a.satBounds, l = a.satAxes, u = this.points;
1043
+ for (let e = 0; e < 3; e++) {
1044
+ let t = c[e], r = l[e];
1045
+ if (n.setFromPoints(r, u), t.isSeparated(n)) return !1;
1046
+ }
1047
+ for (let e = 0; e < 3; e++) {
1048
+ let a = s[e];
1049
+ for (let e = 0; e < 4; e++) {
1050
+ let o = l[e];
1051
+ if (i.crossVectors(a, o), n.setFromPoints(i, t), r.setFromPoints(i, u), n.isSeparated(r)) return !1;
1052
+ }
1053
+ }
1054
+ return !0;
1055
+ };
1056
+ })(), K.prototype.closestPointToPoint = (function() {
1057
+ return function(e, t) {
1058
+ return this.needsUpdate && this.update(), t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min, this.max).applyMatrix4(this.matrix), t;
1059
+ };
1060
+ })(), K.prototype.distanceToPoint = (function() {
1061
+ let e = new b();
1062
+ return function(t) {
1063
+ return this.closestPointToPoint(t, e), t.distanceTo(e);
1064
+ };
1065
+ })(), K.prototype.distanceToBox = (function() {
1066
+ let e = [
1067
+ "x",
1068
+ "y",
1069
+ "z"
1070
+ ], t = /* @__PURE__ */ Array(12).fill().map(() => new c()), n = /* @__PURE__ */ Array(12).fill().map(() => new c()), r = /* @__PURE__ */ new b(), i = /* @__PURE__ */ new b();
1071
+ return function(a, o = 0, s = null, c = null) {
1072
+ if (this.needsUpdate && this.update(), this.intersectsBox(a)) return (s || c) && (a.getCenter(i), this.closestPointToPoint(i, r), a.closestPointToPoint(r, i), s && s.copy(r), c && c.copy(i)), 0;
1073
+ let l = o * o, u = a.min, d = a.max, f = this.points, p = Infinity;
1074
+ for (let e = 0; e < 8; e++) {
1075
+ let t = f[e];
1076
+ i.copy(t).clamp(u, d);
1077
+ let n = t.distanceToSquared(i);
1078
+ if (n < p && (p = n, s && s.copy(t), c && c.copy(i), n < l)) return Math.sqrt(n);
1079
+ }
1080
+ let m = 0;
1081
+ for (let r = 0; r < 3; r++) for (let i = 0; i <= 1; i++) for (let a = 0; a <= 1; a++) {
1082
+ let o = (r + 1) % 3, s = (r + 2) % 3, c = i << o | a << s, l = 1 << r | i << o | a << s, p = f[c], h = f[l];
1083
+ t[m].set(p, h);
1084
+ let g = e[r], _ = e[o], v = e[s], y = n[m], b = y.start, x = y.end;
1085
+ b[g] = u[g], b[_] = i ? u[_] : d[_], b[v] = a ? u[v] : d[_], x[g] = d[g], x[_] = i ? u[_] : d[_], x[v] = a ? u[v] : d[_], m++;
1086
+ }
1087
+ for (let e = 0; e <= 1; e++) for (let t = 0; t <= 1; t++) for (let n = 0; n <= 1; n++) {
1088
+ i.x = e ? d.x : u.x, i.y = t ? d.y : u.y, i.z = n ? d.z : u.z, this.closestPointToPoint(i, r);
1089
+ let a = i.distanceToSquared(r);
1090
+ if (a < p && (p = a, s && s.copy(r), c && c.copy(i), a < l)) return Math.sqrt(a);
1091
+ }
1092
+ for (let e = 0; e < 12; e++) {
1093
+ let a = t[e];
1094
+ for (let e = 0; e < 12; e++) {
1095
+ let t = n[e];
1096
+ nt(a, t, r, i);
1097
+ let o = r.distanceToSquared(i);
1098
+ if (o < p && (p = o, s && s.copy(r), c && c.copy(i), o < l)) return Math.sqrt(o);
1099
+ }
1100
+ }
1101
+ return Math.sqrt(p);
1102
+ };
1103
+ })();
1104
+ var q = /* @__PURE__ */ new class extends Oe {
1105
+ constructor() {
1106
+ super(() => new G());
1107
+ }
1108
+ }(), ot = /* @__PURE__ */ new b(), st = /* @__PURE__ */ new b();
1109
+ function ct(e, t, n = {}, r = 0, i = Infinity) {
1110
+ let a = r * r, o = i * i, s = Infinity, c = null;
1111
+ if (e.shapecast({
1112
+ boundsTraverseOrder: (e) => (ot.copy(t).clamp(e.min, e.max), ot.distanceToSquared(t)),
1113
+ intersectsBounds: (e, t, n) => n < s && n < o,
1114
+ intersectsTriangle: (e, n) => {
1115
+ e.closestPointToPoint(t, ot);
1116
+ let r = t.distanceToSquared(ot);
1117
+ return r < s && (st.copy(ot), s = r, c = n), r < a;
1118
+ }
1119
+ }), s === Infinity) return null;
1120
+ let l = Math.sqrt(s);
1121
+ return n.point ? n.point.copy(st) : n.point = st.clone(), n.distance = l, n.faceIndex = c, n;
1122
+ }
1123
+ //#endregion
1124
+ //#region node_modules/three-mesh-bvh/src/utils/ThreeRayIntersectUtilities.js
1125
+ var lt = parseInt(h) >= 169, ut = parseInt(h) <= 161, J = /* @__PURE__ */ new b(), Y = /* @__PURE__ */ new b(), X = /* @__PURE__ */ new b(), dt = /* @__PURE__ */ new y(), ft = /* @__PURE__ */ new y(), pt = /* @__PURE__ */ new y(), mt = /* @__PURE__ */ new b(), ht = /* @__PURE__ */ new b(), gt = /* @__PURE__ */ new b(), _t = /* @__PURE__ */ new b();
1126
+ function vt(e, n, r, i, o, s, c, l) {
1127
+ let u;
1128
+ if (u = s === t ? e.intersectTriangle(i, r, n, !0, o) : e.intersectTriangle(n, r, i, s !== a, o), u === null) return null;
1129
+ let d = e.origin.distanceTo(o);
1130
+ return d < c || d > l ? null : {
1131
+ distance: d,
1132
+ point: o.clone()
1133
+ };
1134
+ }
1135
+ function yt(e, t, n, r, i, a, o, s, c, l, u) {
1136
+ J.fromBufferAttribute(t, a), Y.fromBufferAttribute(t, o), X.fromBufferAttribute(t, s);
1137
+ let d = vt(e, J, Y, X, _t, c, l, u);
1138
+ if (d) {
1139
+ if (r) {
1140
+ dt.fromBufferAttribute(r, a), ft.fromBufferAttribute(r, o), pt.fromBufferAttribute(r, s), d.uv = new y();
1141
+ let e = v.getInterpolation(_t, J, Y, X, dt, ft, pt, d.uv);
1142
+ lt || (d.uv = e);
1143
+ }
1144
+ if (i) {
1145
+ dt.fromBufferAttribute(i, a), ft.fromBufferAttribute(i, o), pt.fromBufferAttribute(i, s), d.uv1 = new y();
1146
+ let e = v.getInterpolation(_t, J, Y, X, dt, ft, pt, d.uv1);
1147
+ lt || (d.uv1 = e), ut && (d.uv2 = d.uv1);
1148
+ }
1149
+ if (n) {
1150
+ mt.fromBufferAttribute(n, a), ht.fromBufferAttribute(n, o), gt.fromBufferAttribute(n, s), d.normal = new b();
1151
+ let t = v.getInterpolation(_t, J, Y, X, mt, ht, gt, d.normal);
1152
+ d.normal.dot(e.direction) > 0 && d.normal.multiplyScalar(-1), lt || (d.normal = t);
1153
+ }
1154
+ let t = {
1155
+ a,
1156
+ b: o,
1157
+ c: s,
1158
+ normal: new b(),
1159
+ materialIndex: 0
1160
+ };
1161
+ if (v.getNormal(J, Y, X, t.normal), d.face = t, d.faceIndex = a, lt) {
1162
+ let e = new b();
1163
+ v.getBarycoord(_t, J, Y, X, e), d.barycoord = e;
1164
+ }
1165
+ }
1166
+ return d;
1167
+ }
1168
+ function bt(e) {
1169
+ return e && e.isMaterial ? e.side : e;
1170
+ }
1171
+ function xt(e, t, n, r, i, a, o) {
1172
+ let s = r * 3, c = s + 0, l = s + 1, u = s + 2, { index: d, groups: f } = e;
1173
+ e.index && (c = d.getX(c), l = d.getX(l), u = d.getX(u));
1174
+ let { position: p, normal: m, uv: h, uv1: g } = e.attributes;
1175
+ if (Array.isArray(t)) {
1176
+ let e = r * 3;
1177
+ for (let s = 0, d = f.length; s < d; s++) {
1178
+ let { start: d, count: _, materialIndex: v } = f[s];
1179
+ if (e >= d && e < d + _) {
1180
+ let e = bt(t[v]), s = yt(n, p, m, h, g, c, l, u, e, a, o);
1181
+ if (s) if (s.faceIndex = r, s.face.materialIndex = v, i) i.push(s);
1182
+ else return s;
1183
+ }
1184
+ }
1185
+ } else {
1186
+ let e = bt(t), s = yt(n, p, m, h, g, c, l, u, e, a, o);
1187
+ if (s) if (s.faceIndex = r, s.face.materialIndex = 0, i) i.push(s);
1188
+ else return s;
1189
+ }
1190
+ return null;
1191
+ }
1192
+ //#endregion
1193
+ //#region node_modules/three-mesh-bvh/src/utils/TriangleUtilities.js
1194
+ function Z(e, t, n, r) {
1195
+ let i = e.a, a = e.b, o = e.c, s = t, c = t + 1, l = t + 2;
1196
+ n && (s = n.getX(s), c = n.getX(c), l = n.getX(l)), i.x = r.getX(s), i.y = r.getY(s), i.z = r.getZ(s), a.x = r.getX(c), a.y = r.getY(c), a.z = r.getZ(c), o.x = r.getX(l), o.y = r.getY(l), o.z = r.getZ(l);
1197
+ }
1198
+ //#endregion
1199
+ //#region node_modules/three-mesh-bvh/src/core/utils/iterationUtils.generated.js
1200
+ function St(e, t, n, r, i, a, o, s) {
1201
+ let { geometry: c, _indirectBuffer: l } = e;
1202
+ for (let e = r, l = r + i; e < l; e++) xt(c, t, n, e, a, o, s);
1203
+ }
1204
+ function Ct(e, t, n, r, i, a, o) {
1205
+ let { geometry: s, _indirectBuffer: c } = e, l = Infinity, u = null;
1206
+ for (let e = r, c = r + i; e < c; e++) {
1207
+ let r;
1208
+ r = xt(s, t, n, e, null, a, o), r && r.distance < l && (u = r, l = r.distance);
1209
+ }
1210
+ return u;
1211
+ }
1212
+ function wt(e, t, n, r, i, a, o) {
1213
+ let { geometry: s } = n, { index: c } = s, l = s.attributes.position;
1214
+ for (let n = e, s = t + e; n < s; n++) {
1215
+ let e;
1216
+ if (e = n, Z(o, e * 3, c, l), o.needsUpdate = !0, r(o, e, i, a)) return !0;
1217
+ }
1218
+ return !1;
1219
+ }
1220
+ //#endregion
1221
+ //#region node_modules/three-mesh-bvh/src/core/cast/refit.generated.js
1222
+ function Tt(e, t = null) {
1223
+ t && Array.isArray(t) && (t = new Set(t));
1224
+ let n = e.geometry, r = n.index ? n.index.array : null, i = n.attributes.position, a, o, s, c, l = 0, u = e._roots;
1225
+ for (let e = 0, t = u.length; e < t; e++) a = u[e], o = new Uint32Array(a), s = new Uint16Array(a), c = new Float32Array(a), d(0, l), l += a.byteLength;
1226
+ function d(e, n, a = !1) {
1227
+ let l = e * 2;
1228
+ if (k(l, s)) {
1229
+ let t = A(e, o), n = j(l, s), a = Infinity, u = Infinity, d = Infinity, f = -Infinity, p = -Infinity, m = -Infinity;
1230
+ for (let e = 3 * t, o = 3 * (t + n); e < o; e++) {
1231
+ let t = r[e], n = i.getX(t), o = i.getY(t), s = i.getZ(t);
1232
+ n < a && (a = n), n > f && (f = n), o < u && (u = o), o > p && (p = o), s < d && (d = s), s > m && (m = s);
1233
+ }
1234
+ return c[e + 0] !== a || c[e + 1] !== u || c[e + 2] !== d || c[e + 3] !== f || c[e + 4] !== p || c[e + 5] !== m ? (c[e + 0] = a, c[e + 1] = u, c[e + 2] = d, c[e + 3] = f, c[e + 4] = p, c[e + 5] = m, !0) : !1;
1235
+ } else {
1236
+ let r = M(e), i = N(e, o), s = a, l = !1, u = !1;
1237
+ if (t) {
1238
+ if (!s) {
1239
+ let e = r / 8 + n / 32, a = i / 8 + n / 32;
1240
+ l = t.has(e), u = t.has(a), s = !l && !u;
1241
+ }
1242
+ } else l = !0, u = !0;
1243
+ let f = s || l, p = s || u, m = !1;
1244
+ f && (m = d(r, n, s));
1245
+ let h = !1;
1246
+ p && (h = d(i, n, s));
1247
+ let g = m || h;
1248
+ if (g) for (let t = 0; t < 3; t++) {
1249
+ let n = r + t, a = i + t, o = c[n], s = c[n + 3], l = c[a], u = c[a + 3];
1250
+ c[e + t] = o < l ? o : l, c[e + t + 3] = s > u ? s : u;
1251
+ }
1252
+ return g;
1253
+ }
1254
+ }
1255
+ }
1256
+ //#endregion
1257
+ //#region node_modules/three-mesh-bvh/src/core/utils/intersectUtils.js
1258
+ function Q(e, t, n, r, i) {
1259
+ let a, o, s, c, l, u, d = 1 / n.direction.x, f = 1 / n.direction.y, p = 1 / n.direction.z, m = n.origin.x, h = n.origin.y, g = n.origin.z, _ = t[e], v = t[e + 3], y = t[e + 1], b = t[e + 3 + 1], x = t[e + 2], S = t[e + 3 + 2];
1260
+ return d >= 0 ? (a = (_ - m) * d, o = (v - m) * d) : (a = (v - m) * d, o = (_ - m) * d), f >= 0 ? (s = (y - h) * f, c = (b - h) * f) : (s = (b - h) * f, c = (y - h) * f), a > c || s > o || ((s > a || isNaN(a)) && (a = s), (c < o || isNaN(o)) && (o = c), p >= 0 ? (l = (x - g) * p, u = (S - g) * p) : (l = (S - g) * p, u = (x - g) * p), a > u || l > o) ? !1 : ((l > a || a !== a) && (a = l), (u < o || o !== o) && (o = u), a <= i && o >= r);
1261
+ }
1262
+ //#endregion
1263
+ //#region node_modules/three-mesh-bvh/src/core/utils/iterationUtils_indirect.generated.js
1264
+ function Et(e, t, n, r, i, a, o, s) {
1265
+ let { geometry: c, _indirectBuffer: l } = e;
1266
+ for (let e = r, u = r + i; e < u; e++) xt(c, t, n, l ? l[e] : e, a, o, s);
1267
+ }
1268
+ function Dt(e, t, n, r, i, a, o) {
1269
+ let { geometry: s, _indirectBuffer: c } = e, l = Infinity, u = null;
1270
+ for (let e = r, d = r + i; e < d; e++) {
1271
+ let r;
1272
+ r = xt(s, t, n, c ? c[e] : e, null, a, o), r && r.distance < l && (u = r, l = r.distance);
1273
+ }
1274
+ return u;
1275
+ }
1276
+ function Ot(e, t, n, r, i, a, o) {
1277
+ let { geometry: s } = n, { index: c } = s, l = s.attributes.position;
1278
+ for (let s = e, u = t + e; s < u; s++) {
1279
+ let e;
1280
+ if (e = n.resolveTriangleIndex(s), Z(o, e * 3, c, l), o.needsUpdate = !0, r(o, e, i, a)) return !0;
1281
+ }
1282
+ return !1;
1283
+ }
1284
+ //#endregion
1285
+ //#region node_modules/three-mesh-bvh/src/core/cast/raycast.generated.js
1286
+ function kt(e, t, n, r, i, a, o) {
1287
+ L.setBuffer(e._roots[t]), At(0, e, n, r, i, a, o), L.clearBuffer();
1288
+ }
1289
+ function At(e, t, n, r, i, a, o) {
1290
+ let { float32Array: s, uint16Array: c, uint32Array: l } = L, u = e * 2;
1291
+ if (k(u, c)) St(t, n, r, A(e, l), j(u, c), i, a, o);
1292
+ else {
1293
+ let c = M(e);
1294
+ Q(c, s, r, a, o) && At(c, t, n, r, i, a, o);
1295
+ let u = N(e, l);
1296
+ Q(u, s, r, a, o) && At(u, t, n, r, i, a, o);
1297
+ }
1298
+ }
1299
+ //#endregion
1300
+ //#region node_modules/three-mesh-bvh/src/core/cast/raycastFirst.generated.js
1301
+ var jt = [
1302
+ "x",
1303
+ "y",
1304
+ "z"
1305
+ ];
1306
+ function Mt(e, t, n, r, i, a) {
1307
+ L.setBuffer(e._roots[t]);
1308
+ let o = Nt(0, e, n, r, i, a);
1309
+ return L.clearBuffer(), o;
1310
+ }
1311
+ function Nt(e, t, n, r, i, a) {
1312
+ let { float32Array: o, uint16Array: s, uint32Array: c } = L, l = e * 2;
1313
+ if (k(l, s)) return Ct(t, n, r, A(e, c), j(l, s), i, a);
1314
+ {
1315
+ let s = ue(e, c), l = jt[s], u = r.direction[l] >= 0, d, f;
1316
+ u ? (d = M(e), f = N(e, c)) : (d = N(e, c), f = M(e));
1317
+ let p = Q(d, o, r, i, a) ? Nt(d, t, n, r, i, a) : null;
1318
+ if (p) {
1319
+ let e = p.point[l];
1320
+ if (u ? e <= o[f + s] : e >= o[f + s + 3]) return p;
1321
+ }
1322
+ let m = Q(f, o, r, i, a) ? Nt(f, t, n, r, i, a) : null;
1323
+ return p && m ? p.distance <= m.distance ? p : m : p || m || null;
1324
+ }
1325
+ }
1326
+ //#endregion
1327
+ //#region node_modules/three-mesh-bvh/src/core/cast/intersectsGeometry.generated.js
1328
+ var Pt = /* @__PURE__ */ new r(), Ft = /* @__PURE__ */ new G(), It = /* @__PURE__ */ new G(), Lt = /* @__PURE__ */ new d(), Rt = /* @__PURE__ */ new K(), zt = /* @__PURE__ */ new K();
1329
+ function Bt(e, t, n, r) {
1330
+ L.setBuffer(e._roots[t]);
1331
+ let i = Vt(0, e, n, r);
1332
+ return L.clearBuffer(), i;
1333
+ }
1334
+ function Vt(e, t, n, r, i = null) {
1335
+ let { float32Array: a, uint16Array: o, uint32Array: s } = L, c = e * 2;
1336
+ if (i === null && (n.boundingBox || n.computeBoundingBox(), Rt.set(n.boundingBox.min, n.boundingBox.max, r), i = Rt), k(c, o)) {
1337
+ let i = t.geometry, l = i.index, u = i.attributes.position, d = n.index, f = n.attributes.position, p = A(e, s), m = j(c, o);
1338
+ if (Lt.copy(r).invert(), n.boundsTree) return O(P(e), a, zt), zt.matrix.copy(Lt), zt.needsUpdate = !0, n.boundsTree.shapecast({
1339
+ intersectsBounds: (e) => zt.intersectsBox(e),
1340
+ intersectsTriangle: (e) => {
1341
+ e.a.applyMatrix4(r), e.b.applyMatrix4(r), e.c.applyMatrix4(r), e.needsUpdate = !0;
1342
+ for (let t = p * 3, n = (m + p) * 3; t < n; t += 3) if (Z(It, t, l, u), It.needsUpdate = !0, e.intersectsTriangle(It)) return !0;
1343
+ return !1;
1344
+ }
1345
+ });
1346
+ {
1347
+ let e = qe(n);
1348
+ for (let t = p * 3, n = (m + p) * 3; t < n; t += 3) {
1349
+ Z(Ft, t, l, u), Ft.a.applyMatrix4(Lt), Ft.b.applyMatrix4(Lt), Ft.c.applyMatrix4(Lt), Ft.needsUpdate = !0;
1350
+ for (let t = 0, n = e * 3; t < n; t += 3) if (Z(It, t, d, f), It.needsUpdate = !0, Ft.intersectsTriangle(It)) return !0;
1351
+ }
1352
+ }
1353
+ } else {
1354
+ let o = M(e), c = N(e, s);
1355
+ return O(P(o), a, Pt), !!(i.intersectsBox(Pt) && Vt(o, t, n, r, i) || (O(P(c), a, Pt), i.intersectsBox(Pt) && Vt(c, t, n, r, i)));
1356
+ }
1357
+ }
1358
+ //#endregion
1359
+ //#region node_modules/three-mesh-bvh/src/core/cast/closestPointToGeometry.generated.js
1360
+ var Ht = /* @__PURE__ */ new d(), Ut = /* @__PURE__ */ new K(), Wt = /* @__PURE__ */ new K(), Gt = /* @__PURE__ */ new b(), Kt = /* @__PURE__ */ new b(), qt = /* @__PURE__ */ new b(), Jt = /* @__PURE__ */ new b();
1361
+ function Yt(e, t, n, r = {}, i = {}, a = 0, o = Infinity) {
1362
+ t.boundingBox || t.computeBoundingBox(), Ut.set(t.boundingBox.min, t.boundingBox.max, n), Ut.needsUpdate = !0;
1363
+ let s = e.geometry, c = s.attributes.position, l = s.index, u = t.attributes.position, d = t.index, f = q.getPrimitive(), p = q.getPrimitive(), m = Gt, h = Kt, g = null, _ = null;
1364
+ i && (g = qt, _ = Jt);
1365
+ let v = Infinity, y = null, b = null;
1366
+ return Ht.copy(n).invert(), Wt.matrix.copy(Ht), e.shapecast({
1367
+ boundsTraverseOrder: (e) => Ut.distanceToBox(e),
1368
+ intersectsBounds: (e, t, n) => n < v && n < o ? (t && (Wt.min.copy(e.min), Wt.max.copy(e.max), Wt.needsUpdate = !0), !0) : !1,
1369
+ intersectsRange: (e, r) => {
1370
+ if (t.boundsTree) return t.boundsTree.shapecast({
1371
+ boundsTraverseOrder: (e) => Wt.distanceToBox(e),
1372
+ intersectsBounds: (e, t, n) => n < v && n < o,
1373
+ intersectsRange: (t, i) => {
1374
+ for (let o = t, s = t + i; o < s; o++) {
1375
+ Z(p, 3 * o, d, u), p.a.applyMatrix4(n), p.b.applyMatrix4(n), p.c.applyMatrix4(n), p.needsUpdate = !0;
1376
+ for (let t = e, n = e + r; t < n; t++) {
1377
+ Z(f, 3 * t, l, c), f.needsUpdate = !0;
1378
+ let e = f.distanceToTriangle(p, m, g);
1379
+ if (e < v && (h.copy(m), _ && _.copy(g), v = e, y = t, b = o), e < a) return !0;
1380
+ }
1381
+ }
1382
+ }
1383
+ });
1384
+ {
1385
+ let i = qe(t);
1386
+ for (let t = 0, o = i; t < o; t++) {
1387
+ Z(p, 3 * t, d, u), p.a.applyMatrix4(n), p.b.applyMatrix4(n), p.c.applyMatrix4(n), p.needsUpdate = !0;
1388
+ for (let n = e, i = e + r; n < i; n++) {
1389
+ Z(f, 3 * n, l, c), f.needsUpdate = !0;
1390
+ let e = f.distanceToTriangle(p, m, g);
1391
+ if (e < v && (h.copy(m), _ && _.copy(g), v = e, y = n, b = t), e < a) return !0;
1392
+ }
1393
+ }
1394
+ }
1395
+ }
1396
+ }), q.releasePrimitive(f), q.releasePrimitive(p), v === Infinity ? null : (r.point ? r.point.copy(h) : r.point = h.clone(), r.distance = v, r.faceIndex = y, i && (i.point ? i.point.copy(_) : i.point = _.clone(), i.point.applyMatrix4(Ht), h.applyMatrix4(Ht), i.distance = h.sub(i.point).length(), i.faceIndex = b), r);
1397
+ }
1398
+ //#endregion
1399
+ //#region node_modules/three-mesh-bvh/src/core/cast/refit_indirect.generated.js
1400
+ function Xt(e, t = null) {
1401
+ t && Array.isArray(t) && (t = new Set(t));
1402
+ let n = e.geometry, r = n.index ? n.index.array : null, i = n.attributes.position, a, o, s, c, l = 0, u = e._roots;
1403
+ for (let e = 0, t = u.length; e < t; e++) a = u[e], o = new Uint32Array(a), s = new Uint16Array(a), c = new Float32Array(a), d(0, l), l += a.byteLength;
1404
+ function d(n, a, l = !1) {
1405
+ let u = n * 2;
1406
+ if (k(u, s)) {
1407
+ let t = A(n, o), a = j(u, s), l = Infinity, d = Infinity, f = Infinity, p = -Infinity, m = -Infinity, h = -Infinity;
1408
+ for (let n = t, o = t + a; n < o; n++) {
1409
+ let t = 3 * e.resolveTriangleIndex(n);
1410
+ for (let e = 0; e < 3; e++) {
1411
+ let n = t + e;
1412
+ n = r ? r[n] : n;
1413
+ let a = i.getX(n), o = i.getY(n), s = i.getZ(n);
1414
+ a < l && (l = a), a > p && (p = a), o < d && (d = o), o > m && (m = o), s < f && (f = s), s > h && (h = s);
1415
+ }
1416
+ }
1417
+ return c[n + 0] !== l || c[n + 1] !== d || c[n + 2] !== f || c[n + 3] !== p || c[n + 4] !== m || c[n + 5] !== h ? (c[n + 0] = l, c[n + 1] = d, c[n + 2] = f, c[n + 3] = p, c[n + 4] = m, c[n + 5] = h, !0) : !1;
1418
+ } else {
1419
+ let e = M(n), r = N(n, o), i = l, s = !1, u = !1;
1420
+ if (t) {
1421
+ if (!i) {
1422
+ let n = e / 8 + a / 32, o = r / 8 + a / 32;
1423
+ s = t.has(n), u = t.has(o), i = !s && !u;
1424
+ }
1425
+ } else s = !0, u = !0;
1426
+ let f = i || s, p = i || u, m = !1;
1427
+ f && (m = d(e, a, i));
1428
+ let h = !1;
1429
+ p && (h = d(r, a, i));
1430
+ let g = m || h;
1431
+ if (g) for (let t = 0; t < 3; t++) {
1432
+ let i = e + t, a = r + t, o = c[i], s = c[i + 3], l = c[a], u = c[a + 3];
1433
+ c[n + t] = o < l ? o : l, c[n + t + 3] = s > u ? s : u;
1434
+ }
1435
+ return g;
1436
+ }
1437
+ }
1438
+ }
1439
+ //#endregion
1440
+ //#region node_modules/three-mesh-bvh/src/core/cast/raycast_indirect.generated.js
1441
+ function Zt(e, t, n, r, i, a, o) {
1442
+ L.setBuffer(e._roots[t]), Qt(0, e, n, r, i, a, o), L.clearBuffer();
1443
+ }
1444
+ function Qt(e, t, n, r, i, a, o) {
1445
+ let { float32Array: s, uint16Array: c, uint32Array: l } = L, u = e * 2;
1446
+ if (k(u, c)) Et(t, n, r, A(e, l), j(u, c), i, a, o);
1447
+ else {
1448
+ let c = M(e);
1449
+ Q(c, s, r, a, o) && Qt(c, t, n, r, i, a, o);
1450
+ let u = N(e, l);
1451
+ Q(u, s, r, a, o) && Qt(u, t, n, r, i, a, o);
1452
+ }
1453
+ }
1454
+ //#endregion
1455
+ //#region node_modules/three-mesh-bvh/src/core/cast/raycastFirst_indirect.generated.js
1456
+ var $t = [
1457
+ "x",
1458
+ "y",
1459
+ "z"
1460
+ ];
1461
+ function en(e, t, n, r, i, a) {
1462
+ L.setBuffer(e._roots[t]);
1463
+ let o = tn(0, e, n, r, i, a);
1464
+ return L.clearBuffer(), o;
1465
+ }
1466
+ function tn(e, t, n, r, i, a) {
1467
+ let { float32Array: o, uint16Array: s, uint32Array: c } = L, l = e * 2;
1468
+ if (k(l, s)) return Dt(t, n, r, A(e, c), j(l, s), i, a);
1469
+ {
1470
+ let s = ue(e, c), l = $t[s], u = r.direction[l] >= 0, d, f;
1471
+ u ? (d = M(e), f = N(e, c)) : (d = N(e, c), f = M(e));
1472
+ let p = Q(d, o, r, i, a) ? tn(d, t, n, r, i, a) : null;
1473
+ if (p) {
1474
+ let e = p.point[l];
1475
+ if (u ? e <= o[f + s] : e >= o[f + s + 3]) return p;
1476
+ }
1477
+ let m = Q(f, o, r, i, a) ? tn(f, t, n, r, i, a) : null;
1478
+ return p && m ? p.distance <= m.distance ? p : m : p || m || null;
1479
+ }
1480
+ }
1481
+ //#endregion
1482
+ //#region node_modules/three-mesh-bvh/src/core/cast/intersectsGeometry_indirect.generated.js
1483
+ var nn = /* @__PURE__ */ new r(), rn = /* @__PURE__ */ new G(), an = /* @__PURE__ */ new G(), on = /* @__PURE__ */ new d(), sn = /* @__PURE__ */ new K(), cn = /* @__PURE__ */ new K();
1484
+ function ln(e, t, n, r) {
1485
+ L.setBuffer(e._roots[t]);
1486
+ let i = un(0, e, n, r);
1487
+ return L.clearBuffer(), i;
1488
+ }
1489
+ function un(e, t, n, r, i = null) {
1490
+ let { float32Array: a, uint16Array: o, uint32Array: s } = L, c = e * 2;
1491
+ if (i === null && (n.boundingBox || n.computeBoundingBox(), sn.set(n.boundingBox.min, n.boundingBox.max, r), i = sn), k(c, o)) {
1492
+ let i = t.geometry, l = i.index, u = i.attributes.position, d = n.index, f = n.attributes.position, p = A(e, s), m = j(c, o);
1493
+ if (on.copy(r).invert(), n.boundsTree) return O(P(e), a, cn), cn.matrix.copy(on), cn.needsUpdate = !0, n.boundsTree.shapecast({
1494
+ intersectsBounds: (e) => cn.intersectsBox(e),
1495
+ intersectsTriangle: (e) => {
1496
+ e.a.applyMatrix4(r), e.b.applyMatrix4(r), e.c.applyMatrix4(r), e.needsUpdate = !0;
1497
+ for (let n = p, r = m + p; n < r; n++) if (Z(an, 3 * t.resolveTriangleIndex(n), l, u), an.needsUpdate = !0, e.intersectsTriangle(an)) return !0;
1498
+ return !1;
1499
+ }
1500
+ });
1501
+ {
1502
+ let e = qe(n);
1503
+ for (let n = p, r = m + p; n < r; n++) {
1504
+ Z(rn, 3 * t.resolveTriangleIndex(n), l, u), rn.a.applyMatrix4(on), rn.b.applyMatrix4(on), rn.c.applyMatrix4(on), rn.needsUpdate = !0;
1505
+ for (let t = 0, n = e * 3; t < n; t += 3) if (Z(an, t, d, f), an.needsUpdate = !0, rn.intersectsTriangle(an)) return !0;
1506
+ }
1507
+ }
1508
+ } else {
1509
+ let o = M(e), c = N(e, s);
1510
+ return O(P(o), a, nn), !!(i.intersectsBox(nn) && un(o, t, n, r, i) || (O(P(c), a, nn), i.intersectsBox(nn) && un(c, t, n, r, i)));
1511
+ }
1512
+ }
1513
+ //#endregion
1514
+ //#region node_modules/three-mesh-bvh/src/core/cast/closestPointToGeometry_indirect.generated.js
1515
+ var dn = /* @__PURE__ */ new d(), fn = /* @__PURE__ */ new K(), pn = /* @__PURE__ */ new K(), mn = /* @__PURE__ */ new b(), hn = /* @__PURE__ */ new b(), gn = /* @__PURE__ */ new b(), _n = /* @__PURE__ */ new b();
1516
+ function vn(e, t, n, r = {}, i = {}, a = 0, o = Infinity) {
1517
+ t.boundingBox || t.computeBoundingBox(), fn.set(t.boundingBox.min, t.boundingBox.max, n), fn.needsUpdate = !0;
1518
+ let s = e.geometry, c = s.attributes.position, l = s.index, u = t.attributes.position, d = t.index, f = q.getPrimitive(), p = q.getPrimitive(), m = mn, h = hn, g = null, _ = null;
1519
+ i && (g = gn, _ = _n);
1520
+ let v = Infinity, y = null, b = null;
1521
+ return dn.copy(n).invert(), pn.matrix.copy(dn), e.shapecast({
1522
+ boundsTraverseOrder: (e) => fn.distanceToBox(e),
1523
+ intersectsBounds: (e, t, n) => n < v && n < o ? (t && (pn.min.copy(e.min), pn.max.copy(e.max), pn.needsUpdate = !0), !0) : !1,
1524
+ intersectsRange: (r, i) => {
1525
+ if (t.boundsTree) {
1526
+ let s = t.boundsTree;
1527
+ return s.shapecast({
1528
+ boundsTraverseOrder: (e) => pn.distanceToBox(e),
1529
+ intersectsBounds: (e, t, n) => n < v && n < o,
1530
+ intersectsRange: (t, o) => {
1531
+ for (let x = t, S = t + o; x < S; x++) {
1532
+ let t = s.resolveTriangleIndex(x);
1533
+ Z(p, 3 * t, d, u), p.a.applyMatrix4(n), p.b.applyMatrix4(n), p.c.applyMatrix4(n), p.needsUpdate = !0;
1534
+ for (let t = r, n = r + i; t < n; t++) {
1535
+ let n = e.resolveTriangleIndex(t);
1536
+ Z(f, 3 * n, l, c), f.needsUpdate = !0;
1537
+ let r = f.distanceToTriangle(p, m, g);
1538
+ if (r < v && (h.copy(m), _ && _.copy(g), v = r, y = t, b = x), r < a) return !0;
1539
+ }
1540
+ }
1541
+ }
1542
+ });
1543
+ } else {
1544
+ let o = qe(t);
1545
+ for (let t = 0, s = o; t < s; t++) {
1546
+ Z(p, 3 * t, d, u), p.a.applyMatrix4(n), p.b.applyMatrix4(n), p.c.applyMatrix4(n), p.needsUpdate = !0;
1547
+ for (let n = r, o = r + i; n < o; n++) {
1548
+ let r = e.resolveTriangleIndex(n);
1549
+ Z(f, 3 * r, l, c), f.needsUpdate = !0;
1550
+ let i = f.distanceToTriangle(p, m, g);
1551
+ if (i < v && (h.copy(m), _ && _.copy(g), v = i, y = n, b = t), i < a) return !0;
1552
+ }
1553
+ }
1554
+ }
1555
+ }
1556
+ }), q.releasePrimitive(f), q.releasePrimitive(p), v === Infinity ? null : (r.point ? r.point.copy(h) : r.point = h.clone(), r.distance = v, r.faceIndex = y, i && (i.point ? i.point.copy(_) : i.point = _.clone(), i.point.applyMatrix4(dn), h.applyMatrix4(dn), i.distance = h.sub(i.point).length(), i.faceIndex = b), r);
1557
+ }
1558
+ //#endregion
1559
+ //#region node_modules/three-mesh-bvh/src/utils/GeometryRayIntersectUtilities.js
1560
+ function yn(e, t, n) {
1561
+ return e === null ? null : (e.point.applyMatrix4(t.matrixWorld), e.distance = e.point.distanceTo(n.ray.origin), e.object = t, e);
1562
+ }
1563
+ //#endregion
1564
+ //#region node_modules/three-mesh-bvh/src/core/MeshBVH.js
1565
+ var bn = /* @__PURE__ */ new K(), xn = /* @__PURE__ */ new g(), Sn = /* @__PURE__ */ new b(), Cn = /* @__PURE__ */ new d(), wn = /* @__PURE__ */ new b(), Tn = [
1566
+ "getX",
1567
+ "getY",
1568
+ "getZ"
1569
+ ], En = class e extends et {
1570
+ static serialize(e, t = {}) {
1571
+ t = {
1572
+ cloneBuffers: !0,
1573
+ ...t
1574
+ };
1575
+ let n = e.geometry, r = e._roots, i = e._indirectBuffer, a = n.getIndex(), o = {
1576
+ version: 1,
1577
+ roots: null,
1578
+ index: null,
1579
+ indirectBuffer: null
1580
+ };
1581
+ return t.cloneBuffers ? (o.roots = r.map((e) => e.slice()), o.index = a ? a.array.slice() : null, o.indirectBuffer = i ? i.slice() : null) : (o.roots = r, o.index = a ? a.array : null, o.indirectBuffer = i), o;
1582
+ }
1583
+ static deserialize(t, n, r = {}) {
1584
+ r = {
1585
+ setIndex: !0,
1586
+ indirect: !!t.indirectBuffer,
1587
+ ...r
1588
+ };
1589
+ let { index: a, roots: o, indirectBuffer: s } = t;
1590
+ t.version || (console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."), l(o));
1591
+ let c = new e(n, {
1592
+ ...r,
1593
+ [D]: !0
1594
+ });
1595
+ if (c._roots = o, c._indirectBuffer = s || null, r.setIndex) {
1596
+ let e = n.getIndex();
1597
+ if (e === null) {
1598
+ let e = new i(t.index, 1, !1);
1599
+ n.setIndex(e);
1600
+ } else e.array !== a && (e.array.set(a), e.needsUpdate = !0);
1601
+ }
1602
+ return c;
1603
+ function l(e) {
1604
+ for (let t = 0; t < e.length; t++) {
1605
+ let n = e[t], r = new Uint32Array(n), i = new Uint16Array(n);
1606
+ for (let e = 0, t = n.byteLength / 32; e < t; e++) {
1607
+ let t = 8 * e;
1608
+ k(2 * t, i) || (r[t + 6] = r[t + 6] / 8 - e);
1609
+ }
1610
+ }
1611
+ }
1612
+ }
1613
+ get primitiveStride() {
1614
+ return 3;
1615
+ }
1616
+ get resolveTriangleIndex() {
1617
+ return this.resolvePrimitiveIndex;
1618
+ }
1619
+ constructor(e, t = {}) {
1620
+ t.maxLeafTris && (console.warn("MeshBVH: \"maxLeafTris\" option has been deprecated. Use \"targetLeafSize\", instead."), t = {
1621
+ ...t,
1622
+ targetLeafSize: t.maxLeafTris
1623
+ }), super(e, t);
1624
+ }
1625
+ shiftTriangleOffsets(e) {
1626
+ return super.shiftPrimitiveOffsets(e);
1627
+ }
1628
+ writePrimitiveBounds(e, t, n) {
1629
+ let r = this.geometry, i = this._indirectBuffer, a = r.attributes.position, o = r.index ? r.index.array : null, s = (i ? i[e] : e) * 3, c = s + 0, l = s + 1, u = s + 2;
1630
+ o && (c = o[c], l = o[l], u = o[u]);
1631
+ for (let e = 0; e < 3; e++) {
1632
+ let r = a[Tn[e]](c), i = a[Tn[e]](l), o = a[Tn[e]](u), s = r;
1633
+ i < s && (s = i), o < s && (s = o);
1634
+ let d = r;
1635
+ i > d && (d = i), o > d && (d = o), t[n + e] = s, t[n + e + 3] = d;
1636
+ }
1637
+ return t;
1638
+ }
1639
+ computePrimitiveBounds(e, t, n) {
1640
+ let r = this.geometry, i = this._indirectBuffer, a = r.attributes.position, o = r.index ? r.index.array : null, s = a.normalized;
1641
+ if (e < 0 || t + e - n.offset > n.length / 6) throw Error("MeshBVH: compute triangle bounds range is invalid.");
1642
+ let c = a.array, l = a.offset || 0, u = 3;
1643
+ a.isInterleavedBufferAttribute && (u = a.data.stride);
1644
+ let d = [
1645
+ "getX",
1646
+ "getY",
1647
+ "getZ"
1648
+ ], f = n.offset;
1649
+ for (let r = e, p = e + t; r < p; r++) {
1650
+ let e = (i ? i[r] : r) * 3, t = (r - f) * 6, p = e + 0, m = e + 1, h = e + 2;
1651
+ o && (p = o[p], m = o[m], h = o[h]), s || (p = p * u + l, m = m * u + l, h = h * u + l);
1652
+ for (let e = 0; e < 3; e++) {
1653
+ let r, i, o;
1654
+ s ? (r = a[d[e]](p), i = a[d[e]](m), o = a[d[e]](h)) : (r = c[p + e], i = c[m + e], o = c[h + e]);
1655
+ let l = r;
1656
+ i < l && (l = i), o < l && (l = o);
1657
+ let u = r;
1658
+ i > u && (u = i), o > u && (u = o);
1659
+ let f = (u - l) / 2, g = e * 2;
1660
+ n[t + g + 0] = l + f, n[t + g + 1] = f + (Math.abs(l) + f) * re;
1661
+ }
1662
+ }
1663
+ return n;
1664
+ }
1665
+ raycastObject3D(e, t, n = []) {
1666
+ let { material: r } = e;
1667
+ if (r === void 0) return;
1668
+ Cn.copy(e.matrixWorld).invert(), xn.copy(t.ray).applyMatrix4(Cn), wn.setFromMatrixScale(e.matrixWorld), Sn.copy(xn.direction).multiply(wn);
1669
+ let i = Sn.length(), a = t.near / i, o = t.far / i;
1670
+ if (t.firstHitOnly === !0) {
1671
+ let i = this.raycastFirst(xn, r, a, o);
1672
+ i = yn(i, e, t), i && n.push(i);
1673
+ } else {
1674
+ let i = this.raycast(xn, r, a, o);
1675
+ for (let r = 0, a = i.length; r < a; r++) {
1676
+ let a = yn(i[r], e, t);
1677
+ a && n.push(a);
1678
+ }
1679
+ }
1680
+ return n;
1681
+ }
1682
+ refit(e = null) {
1683
+ return (this.indirect ? Xt : Tt)(this, e);
1684
+ }
1685
+ raycast(e, t = o, n = 0, r = Infinity) {
1686
+ let i = this._roots, a = [], s = this.indirect ? Zt : kt;
1687
+ for (let o = 0, c = i.length; o < c; o++) s(this, o, t, e, a, n, r);
1688
+ return a;
1689
+ }
1690
+ raycastFirst(e, t = o, n = 0, r = Infinity) {
1691
+ let i = this._roots, a = null, s = this.indirect ? en : Mt;
1692
+ for (let o = 0, c = i.length; o < c; o++) {
1693
+ let i = s(this, o, t, e, n, r);
1694
+ i != null && (a == null || i.distance < a.distance) && (a = i);
1695
+ }
1696
+ return a;
1697
+ }
1698
+ intersectsGeometry(e, t) {
1699
+ let n = !1, r = this._roots, i = this.indirect ? ln : Bt;
1700
+ for (let a = 0, o = r.length; a < o && (n = i(this, a, e, t), !n); a++);
1701
+ return n;
1702
+ }
1703
+ shapecast(e) {
1704
+ let t = q.getPrimitive(), n = super.shapecast({
1705
+ ...e,
1706
+ intersectsPrimitive: e.intersectsTriangle,
1707
+ scratchPrimitive: t,
1708
+ iterate: this.indirect ? Ot : wt
1709
+ });
1710
+ return q.releasePrimitive(t), n;
1711
+ }
1712
+ bvhcast(t, n, r) {
1713
+ let { intersectsRanges: i, intersectsTriangles: a } = r, o = q.getPrimitive(), s = this.geometry.index, c = this.geometry.attributes.position, l = this.indirect ? (e) => {
1714
+ let t = this.resolveTriangleIndex(e);
1715
+ Z(o, t * 3, s, c);
1716
+ } : (e) => {
1717
+ Z(o, e * 3, s, c);
1718
+ }, u = q.getPrimitive(), d = t.geometry.index, f = t.geometry.attributes.position, p = t.indirect ? (e) => {
1719
+ let n = t.resolveTriangleIndex(e);
1720
+ Z(u, n * 3, d, f);
1721
+ } : (e) => {
1722
+ Z(u, e * 3, d, f);
1723
+ };
1724
+ if (a) {
1725
+ if (!(t instanceof e)) throw Error("MeshBVH: \"intersectsTriangles\" callback can only be used with another MeshBVH.");
1726
+ let r = (e, t, r, i, s, c, d, f) => {
1727
+ for (let m = r, h = r + i; m < h; m++) {
1728
+ p(m), u.a.applyMatrix4(n), u.b.applyMatrix4(n), u.c.applyMatrix4(n), u.needsUpdate = !0;
1729
+ for (let n = e, r = e + t; n < r; n++) if (l(n), o.needsUpdate = !0, a(o, u, n, m, s, c, d, f)) return !0;
1730
+ }
1731
+ return !1;
1732
+ };
1733
+ if (i) {
1734
+ let e = i;
1735
+ i = function(t, n, i, a, o, s, c, l) {
1736
+ return e(t, n, i, a, o, s, c, l) ? !0 : r(t, n, i, a, o, s, c, l);
1737
+ };
1738
+ } else i = r;
1739
+ }
1740
+ return super.bvhcast(t, n, { intersectsRanges: i });
1741
+ }
1742
+ intersectsBox(e, t) {
1743
+ return bn.set(e.min, e.max, t), bn.needsUpdate = !0, this.shapecast({
1744
+ intersectsBounds: (e) => bn.intersectsBox(e),
1745
+ intersectsTriangle: (e) => bn.intersectsTriangle(e)
1746
+ });
1747
+ }
1748
+ intersectsSphere(e) {
1749
+ return this.shapecast({
1750
+ intersectsBounds: (t) => e.intersectsBox(t),
1751
+ intersectsTriangle: (t) => t.intersectsSphere(e)
1752
+ });
1753
+ }
1754
+ closestPointToGeometry(e, t, n = {}, r = {}, i = 0, a = Infinity) {
1755
+ return (this.indirect ? vn : Yt)(this, e, t, n, r, i, a);
1756
+ }
1757
+ closestPointToPoint(e, t = {}, n = 0, r = Infinity) {
1758
+ return ct(this, e, t, n, r);
1759
+ }
1760
+ }, Dn = {
1761
+ Mesh: f.prototype.raycast,
1762
+ Line: s.prototype.raycast,
1763
+ LineSegments: u.prototype.raycast,
1764
+ LineLoop: l.prototype.raycast,
1765
+ Points: m.prototype.raycast,
1766
+ BatchedMesh: n.prototype.raycast
1767
+ }, $ = /* @__PURE__ */ new f(), On = [];
1768
+ function kn(e, t) {
1769
+ if (this.isBatchedMesh) An.call(this, e, t);
1770
+ else {
1771
+ let { geometry: n } = this;
1772
+ if (n.boundsTree) n.boundsTree.raycastObject3D(this, e, t);
1773
+ else {
1774
+ let n;
1775
+ if (this instanceof f) n = Dn.Mesh;
1776
+ else if (this instanceof u) n = Dn.LineSegments;
1777
+ else if (this instanceof l) n = Dn.LineLoop;
1778
+ else if (this instanceof s) n = Dn.Line;
1779
+ else if (this instanceof m) n = Dn.Points;
1780
+ else throw Error("BVH: Fallback raycast function not found.");
1781
+ n.call(this, e, t);
1782
+ }
1783
+ }
1784
+ }
1785
+ function An(e, t) {
1786
+ if (this.boundsTrees) {
1787
+ let n = this.boundsTrees, r = this._drawInfo || this._instanceInfo, i = this._drawRanges || this._geometryInfo, a = this.matrixWorld;
1788
+ $.material = this.material, $.geometry = this.geometry;
1789
+ let o = $.geometry.boundsTree, s = $.geometry.drawRange;
1790
+ $.geometry.boundingSphere === null && ($.geometry.boundingSphere = new _());
1791
+ for (let o = 0, s = r.length; o < s; o++) {
1792
+ if (!this.getVisibleAt(o)) continue;
1793
+ let s = r[o].geometryIndex;
1794
+ if ($.geometry.boundsTree = n[s], this.getMatrixAt(o, $.matrixWorld).premultiply(a), !$.geometry.boundsTree) {
1795
+ this.getBoundingBoxAt(s, $.geometry.boundingBox), this.getBoundingSphereAt(s, $.geometry.boundingSphere);
1796
+ let e = i[s];
1797
+ $.geometry.setDrawRange(e.start, e.count);
1798
+ }
1799
+ $.raycast(e, On);
1800
+ for (let e = 0, n = On.length; e < n; e++) {
1801
+ let n = On[e];
1802
+ n.object = this, n.batchId = o, t.push(n);
1803
+ }
1804
+ On.length = 0;
1805
+ }
1806
+ $.geometry.boundsTree = o, $.geometry.drawRange = s, $.material = null, $.geometry = null;
1807
+ } else Dn.BatchedMesh.call(this, e, t);
1808
+ }
1809
+ //#endregion
1810
+ //#region src/infrastructure/three/bvh.ts
1811
+ function jn(e) {
1812
+ e.traverse((e) => {
1813
+ let t = e;
1814
+ if (!t.isMesh || t.isSkinnedMesh || t.isInstancedMesh || t.isBatchedMesh) return;
1815
+ let n = t.geometry;
1816
+ !n?.attributes?.position || n.morphAttributes?.position?.length || (n.boundsTree ||= new En(n), t.raycast = kn);
1817
+ });
1818
+ }
1819
+ function Mn(e) {
1820
+ e.boundsTree &&= void 0;
1821
+ }
1822
+ //#endregion
1823
+ //#region src/infrastructure/three/disposal.ts
1824
+ function Nn(t) {
1825
+ let n = t;
1826
+ for (let t of Object.keys(n)) {
1827
+ let r = n[t];
1828
+ r instanceof e.Texture && r.dispose();
1829
+ }
1830
+ let r = t;
1831
+ if (r.isShaderMaterial && r.uniforms) for (let t of Object.values(r.uniforms)) t?.value instanceof e.Texture && t.value.dispose();
1832
+ t.dispose();
1833
+ }
1834
+ function Pn(e) {
1835
+ e.traverse((e) => {
1836
+ let t = e;
1837
+ t.geometry && typeof t.geometry.dispose == "function" && (Mn(t.geometry), t.geometry.dispose());
1838
+ let n = t.material;
1839
+ Array.isArray(n) ? n.forEach(Nn) : n && Nn(n);
1840
+ let r = e;
1841
+ r.isLight && r.shadow?.dispose && r.shadow.dispose();
1842
+ });
1843
+ }
1844
+ function Fn(t, n) {
1845
+ if (!n?.keepBackgrounds) {
1846
+ t.background instanceof e.Texture && (t.background.dispose(), t.background = null), t.environment instanceof e.Texture && (t.environment.dispose(), t.environment = null);
1847
+ let n = t;
1848
+ n.__originalEnvironmentTexture &&= void 0;
1849
+ }
1850
+ for (let e of [...t.children]) Pn(e), t.remove(e);
1851
+ }
1852
+ //#endregion
1853
+ //#region src/infrastructure/three/ContactShadowBaker.ts
1854
+ var In = "contact-shadow-baked", Ln = "contact-shadow-live", Rn = "softboxContactShadowHelper", zn = "softboxPathTracingFloor", Bn = Math.PI * (3 - Math.sqrt(5));
1855
+ function Vn(e) {
1856
+ let t = e.getObjectByName(In);
1857
+ t && (e.remove(t), Pn(t));
1858
+ }
1859
+ function Hn(e) {
1860
+ Vn(e);
1861
+ let t = e.getObjectByName(Ln);
1862
+ t && (t.visible = !0);
1863
+ }
1864
+ var Un = class t {
1865
+ static {
1866
+ this.AMBIENT_RATIO = .62;
1867
+ }
1868
+ static {
1869
+ this.LIGHT_APERTURE_DEGREES = 13;
1870
+ }
1871
+ static {
1872
+ this.AMBIENT_MIN_ELEVATION_DEGREES = 55;
1873
+ }
1874
+ static {
1875
+ this.ACCUMULATION_TEXTURE_SIZE = 1024;
1876
+ }
1877
+ static {
1878
+ this.BAKE_SHADOW_MAP_SIZE = 1024;
1879
+ }
1880
+ static {
1881
+ this.SHADOW_STRENGTH = .55;
1882
+ }
1883
+ static {
1884
+ this.DISC_FOOTPRINT_MARGIN = 1.4;
1885
+ }
1886
+ static {
1887
+ this.DISC_HEIGHT_STRETCH = .45;
1888
+ }
1889
+ static {
1890
+ this.DISC_MIN_HALF_EXTENT = .05;
1891
+ }
1892
+ static {
1893
+ this.FLOOR_LIFT_PER_HEIGHT = .0025;
1894
+ }
1895
+ static {
1896
+ this.FLOOR_LIFT_MIN = 2e-4;
1897
+ }
1898
+ static {
1899
+ this.FLOOR_LIFT_MAX = .01;
1900
+ }
1901
+ static {
1902
+ this.BAKE_BUDGET_MS = 100;
1903
+ }
1904
+ static {
1905
+ this.MIN_PASSES = 24;
1906
+ }
1907
+ static {
1908
+ this.MAX_PASSES = 96;
1909
+ }
1910
+ constructor(e) {
1911
+ this.explicitPasses = e?.passes;
1912
+ }
1913
+ bake(n) {
1914
+ let { renderer: r, scene: i, object: a, light: o } = n;
1915
+ if (r.getContext().isContextLost()) {
1916
+ this.leaveLiveCatcherInCharge(i);
1917
+ return;
1918
+ }
1919
+ let s = this.measureBakeRegion(a);
1920
+ if (!s) return;
1921
+ let c = i.getObjectByName(Ln);
1922
+ c?.geometry instanceof e.CircleGeometry && (s.halfExtent = Math.min(s.halfExtent, c.geometry.parameters.radius));
1923
+ let l = new e.WebGLRenderTarget(t.ACCUMULATION_TEXTURE_SIZE, t.ACCUMULATION_TEXTURE_SIZE, {
1924
+ type: r.capabilities.isWebGL2 ? e.HalfFloatType : e.UnsignedByteType,
1925
+ depthBuffer: !1,
1926
+ stencilBuffer: !1
1927
+ }), u = new e.CircleGeometry(s.halfExtent, 64);
1928
+ if (this.accumulateShadowPasses(r, a, o, s, l, u), r.getContext().isContextLost()) {
1929
+ l.dispose(), u.dispose(), this.leaveLiveCatcherInCharge(i), console.warn("Contact-shadow bake aborted: WebGL context was lost mid-bake");
1930
+ return;
1931
+ }
1932
+ this.installBakedMesh(i, s, l, u);
1933
+ }
1934
+ leaveLiveCatcherInCharge(e) {
1935
+ Hn(e);
1936
+ }
1937
+ evictBakedMesh(e) {
1938
+ Vn(e);
1939
+ }
1940
+ measureBakeRegion(n) {
1941
+ let r = new e.Box3().setFromObject(n);
1942
+ if (r.isEmpty() || !Number.isFinite(r.min.x) || !Number.isFinite(r.max.x)) return null;
1943
+ let i = r.getSize(new e.Vector3()), a = r.getCenter(new e.Vector3()), o = Math.max(i.x, i.z);
1944
+ return {
1945
+ center: a,
1946
+ halfExtent: Math.max(o * t.DISC_FOOTPRINT_MARGIN + i.y * t.DISC_HEIGHT_STRETCH, t.DISC_MIN_HALF_EXTENT),
1947
+ objectHeight: i.y,
1948
+ boundingRadius: i.length() / 2
1949
+ };
1950
+ }
1951
+ accumulateShadowPasses(t, n, r, i, a, o) {
1952
+ let s = new e.Scene(), c = n.parent;
1953
+ s.add(n);
1954
+ let l = this.disableColorWrite(n), u = this.createBakeLight(r);
1955
+ s.add(u), s.add(u.target), u.target.position.copy(r.target.parent ? r.target.getWorldPosition(new e.Vector3()) : r.target.position);
1956
+ let d = new e.ShadowMaterial({
1957
+ transparent: !0,
1958
+ opacity: 0,
1959
+ depthWrite: !1
1960
+ });
1961
+ d.blending = e.CustomBlending, d.blendEquation = e.AddEquation, d.blendSrc = e.OneFactor, d.blendDst = e.OneFactor;
1962
+ let f = new e.Mesh(o, d);
1963
+ f.rotation.x = -Math.PI / 2, f.position.set(i.center.x, 0, i.center.z), f.receiveShadow = !0, s.add(f);
1964
+ let p = this.createBakeCamera(i);
1965
+ s.add(p);
1966
+ let m = t.getRenderTarget(), h = t.autoClear, g = t.getClearColor(new e.Color()), _ = t.getClearAlpha(), v = t.shadowMap.autoUpdate;
1967
+ try {
1968
+ t.shadowMap.autoUpdate = !0, t.setRenderTarget(a), t.setClearColor(0, 0), t.clear(!0, !1, !1), t.autoClear = !1;
1969
+ let e = this.explicitPasses ?? this.measureAffordablePasses(t, s, p, r, u, a);
1970
+ d.opacity = 1 / e;
1971
+ for (let n of this.sampleLightPositions(r, e)) u.position.copy(n), this.fitBakeDepthRange(u, i), t.render(s, p);
1972
+ } finally {
1973
+ t.autoClear = h, t.setClearColor(g, _), t.setRenderTarget(m), t.shadowMap.autoUpdate = v, this.restoreColorWrite(l), c ? c.add(n) : s.remove(n), u.dispose(), d.dispose();
1974
+ }
1975
+ }
1976
+ measureAffordablePasses(n, r, i, a, o, s) {
1977
+ o.position.copy(a.position), n.render(r, i), this.awaitGpuIdle(n, s);
1978
+ let c = performance.now();
1979
+ n.render(r, i), this.awaitGpuIdle(n, s);
1980
+ let l = Math.max(performance.now() - c, .01);
1981
+ return e.MathUtils.clamp(Math.round(t.BAKE_BUDGET_MS / l), t.MIN_PASSES, t.MAX_PASSES);
1982
+ }
1983
+ awaitGpuIdle(t, n) {
1984
+ if (!t.capabilities.textureTypeReadable(n.texture.type)) return;
1985
+ let r = n.texture.type === e.HalfFloatType ? /* @__PURE__ */ new Uint16Array(4) : /* @__PURE__ */ new Uint8Array(4);
1986
+ t.readRenderTargetPixels(n, 0, 0, 1, 1, r);
1987
+ }
1988
+ createBakeLight(n) {
1989
+ let r = new e.DirectionalLight(16777215, 1);
1990
+ r.castShadow = !0, r.shadow.mapSize.set(t.BAKE_SHADOW_MAP_SIZE, t.BAKE_SHADOW_MAP_SIZE), r.shadow.bias = 0, r.shadow.normalBias = 0, r.shadow.radius = 6;
1991
+ let i = n.shadow.camera, a = r.shadow.camera;
1992
+ return a.left = i.left, a.right = i.right, a.top = i.top, a.bottom = i.bottom, a.updateProjectionMatrix(), r;
1993
+ }
1994
+ fitBakeDepthRange(e, t) {
1995
+ let n = e.target.position.clone().sub(e.position).normalize(), r = t.center.clone().sub(e.position).dot(n), i = t.boundingRadius * 1.5 + t.halfExtent, a = e.shadow.camera;
1996
+ a.near = Math.max(r - i, r * .01), a.far = r + i, a.updateProjectionMatrix();
1997
+ }
1998
+ createBakeCamera(t) {
1999
+ let n = new e.OrthographicCamera(-t.halfExtent, t.halfExtent, t.halfExtent, -t.halfExtent, .1, Math.max(t.objectHeight, 1) * 4);
2000
+ return n.position.set(t.center.x, Math.max(t.objectHeight, 1) * 2, t.center.z), n.up.set(0, 0, -1), n.lookAt(t.center.x, 0, t.center.z), n.updateProjectionMatrix(), n.updateMatrixWorld(!0), n;
2001
+ }
2002
+ sampleLightPositions(n, r) {
2003
+ let i = n.position.clone(), a = n.target.parent ? n.target.getWorldPosition(new e.Vector3()) : n.target.position.clone(), o = a.clone().sub(i), s = o.length(), c = o.normalize(), l = new e.Vector3().crossVectors(c, new e.Vector3(0, 1, 0));
2004
+ l.lengthSq() < 1e-6 && l.set(1, 0, 0), l.normalize();
2005
+ let u = new e.Vector3().crossVectors(c, l), d = Math.round(r * t.AMBIENT_RATIO), f = r - d, p = e.MathUtils.degToRad(t.LIGHT_APERTURE_DEGREES), m = Math.tan(p / 2) * s, h = [];
2006
+ for (let e = 0; e < f; e++) {
2007
+ let t = m * Math.sqrt((e + .5) / f), n = e * Bn;
2008
+ h.push(i.clone().addScaledVector(l, t * Math.cos(n)).addScaledVector(u, t * Math.sin(n)));
2009
+ }
2010
+ let g = Math.sin(e.MathUtils.degToRad(t.AMBIENT_MIN_ELEVATION_DEGREES));
2011
+ for (let t = 0; t < d; t++) {
2012
+ let n = Math.sqrt((t + .5) / d), r = g + (.98 - g) * n, i = Math.sqrt(1 - r * r), o = t * Bn;
2013
+ h.push(new e.Vector3(i * Math.cos(o), r, i * Math.sin(o)).multiplyScalar(s).add(a));
2014
+ }
2015
+ return h;
2016
+ }
2017
+ installBakedMesh(n, r, i, a) {
2018
+ this.evictBakedMesh(n);
2019
+ let o = new e.MeshBasicMaterial({
2020
+ map: i.texture,
2021
+ transparent: !0,
2022
+ opacity: t.SHADOW_STRENGTH,
2023
+ depthWrite: !1,
2024
+ toneMapped: !1
2025
+ });
2026
+ o.onBeforeCompile = (e) => {
2027
+ e.fragmentShader = e.fragmentShader.replace("#include <map_fragment>", "#include <map_fragment>\n diffuseColor.a = pow(diffuseColor.a, 0.75);");
2028
+ }, o.customProgramCacheKey = () => "contact-shadow-alpha-gamma", o.addEventListener("dispose", () => i.dispose());
2029
+ let s = new e.Mesh(a, o);
2030
+ s.name = In, s.userData[Rn] = !0, s.rotation.x = -Math.PI / 2;
2031
+ let c = e.MathUtils.clamp(r.objectHeight * t.FLOOR_LIFT_PER_HEIGHT, t.FLOOR_LIFT_MIN, t.FLOOR_LIFT_MAX);
2032
+ s.position.set(r.center.x, c, r.center.z), s.userData.renderTarget = i, n.add(s);
2033
+ let l = n.getObjectByName(Ln);
2034
+ l && (l.visible = !1);
2035
+ }
2036
+ disableColorWrite(e) {
2037
+ let t = /* @__PURE__ */ new Map();
2038
+ return e.traverse((e) => {
2039
+ let n = e;
2040
+ if (!n.isMesh) return;
2041
+ let r = Array.isArray(n.material) ? n.material : [n.material];
2042
+ for (let e of r) e && !t.has(e) && (t.set(e, e.colorWrite), e.colorWrite = !1);
2043
+ }), t;
2044
+ }
2045
+ restoreColorWrite(e) {
2046
+ e.forEach((e, t) => {
2047
+ t.colorWrite = e;
2048
+ });
2049
+ }
2050
+ };
2051
+ //#endregion
2052
+ export { S as C, C as S, ue as _, zn as a, T as b, Fn as c, Je as d, Ke as f, A as g, k as h, Un as i, jn as l, j as m, Rn as n, Hn as o, P as p, Ln as r, Pn as s, In as t, En as u, ne as v, x as w, w as x, ee as y };