@needle-tools/engine 4.7.2-next.6f2cd71 → 4.7.2-next.d24ebbc

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 (32) hide show
  1. package/dist/gltf-progressive-CNdBjvz6.js +1145 -0
  2. package/dist/gltf-progressive-C_oN6wCA.umd.cjs +8 -0
  3. package/dist/gltf-progressive-MgWOszRl.min.js +8 -0
  4. package/dist/{needle-engine.bundle-B-NoV0t_.min.js → needle-engine.bundle-CGXifNgp.min.js} +101 -100
  5. package/dist/{needle-engine.bundle-CFi0ugBx.js → needle-engine.bundle-CHfSBXXT.js} +1966 -1918
  6. package/dist/{needle-engine.bundle-BMnlxDfi.umd.cjs → needle-engine.bundle-Dcn5L5IY.umd.cjs} +97 -96
  7. package/dist/needle-engine.js +3 -3
  8. package/dist/needle-engine.min.js +1 -1
  9. package/dist/needle-engine.umd.cjs +1 -1
  10. package/lib/engine/engine_context.js +1 -2
  11. package/lib/engine/engine_context.js.map +1 -1
  12. package/lib/engine/engine_lods.d.ts +1 -1
  13. package/lib/engine/engine_lods.js.map +1 -1
  14. package/lib/engine/engine_tonemapping.js +1 -0
  15. package/lib/engine/engine_tonemapping.js.map +1 -1
  16. package/lib/engine/webcomponents/needle-engine.d.ts +0 -1
  17. package/lib/engine/webcomponents/needle-engine.js +59 -3
  18. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  19. package/lib/engine-components/Skybox.js +24 -5
  20. package/lib/engine-components/Skybox.js.map +1 -1
  21. package/lib/engine-components/postprocessing/Effects/Tonemapping.js +1 -1
  22. package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -1
  23. package/package.json +2 -2
  24. package/src/engine/engine_context.ts +0 -2
  25. package/src/engine/engine_lods.ts +1 -2
  26. package/src/engine/engine_tonemapping.ts +1 -0
  27. package/src/engine/webcomponents/needle-engine.ts +68 -4
  28. package/src/engine-components/Skybox.ts +25 -7
  29. package/src/engine-components/postprocessing/Effects/Tonemapping.ts +1 -1
  30. package/dist/gltf-progressive-B9o1T8Vr.umd.cjs +0 -8
  31. package/dist/gltf-progressive-DO0SisAM.js +0 -1052
  32. package/dist/gltf-progressive-DQF10PJE.min.js +0 -8
@@ -1,1052 +0,0 @@
1
- var Ye = Object.defineProperty;
2
- var Ce = (i) => {
3
- throw TypeError(i);
4
- };
5
- var He = (i, t, e) => t in i ? Ye(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
6
- var d = (i, t, e) => He(i, typeof t != "symbol" ? t + "" : t, e), Ee = (i, t, e) => t.has(i) || Ce("Cannot " + e);
7
- var y = (i, t, e) => (Ee(i, t, "read from private field"), e ? e.call(i) : t.get(i)), j = (i, t, e) => t.has(i) ? Ce("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(i) : t.set(i, e), N = (i, t, e, s) => (Ee(i, t, "write to private field"), s ? s.call(i, e) : t.set(i, e), e);
8
- import { BufferGeometry as ye, Mesh as ee, Texture as oe, TextureLoader as je, Matrix4 as Be, Clock as Je, MeshStandardMaterial as Qe, Sphere as Ze, Box3 as Ie, Vector3 as q } from "./three-DrqIzZTH.js";
9
- import { DRACOLoader as et, KTX2Loader as tt, MeshoptDecoder as st, GLTFLoader as Pe } from "./three-examples-B50TT3Iu.js";
10
- const rt = "";
11
- globalThis.GLTF_PROGRESSIVE_VERSION = rt;
12
- console.debug("[gltf-progressive] version -");
13
- let V = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", te = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
14
- const nt = V, ot = te, $e = new URL(V + "draco_decoder.js");
15
- $e.searchParams.append("range", "true");
16
- fetch($e, {
17
- method: "GET",
18
- headers: {
19
- Range: "bytes=0-1"
20
- }
21
- }).catch((i) => {
22
- console.debug(`Failed to fetch remote Draco decoder from ${V} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), V === nt && it("./include/draco/"), te === ot && at("./include/ktx2/");
23
- }).finally(() => {
24
- Ue();
25
- });
26
- function it(i) {
27
- V = i, B && B[Se] != V ? (console.debug("Updating Draco decoder path to " + i), B[Se] = V, B.setDecoderPath(V), B.preload()) : console.debug("Setting Draco decoder path to " + i);
28
- }
29
- function at(i) {
30
- te = i, $ && $.transcoderPath != te ? (console.debug("Updating KTX2 transcoder path to " + i), $.setTranscoderPath(te), $.init()) : console.debug("Setting KTX2 transcoder path to " + i);
31
- }
32
- const Se = Symbol("dracoDecoderPath");
33
- let B, me, $;
34
- function Ue() {
35
- B || (B = new et(), B[Se] = V, B.setDecoderPath(V), B.setDecoderConfig({ type: "js" }), B.preload()), $ || ($ = new tt(), $.setTranscoderPath(te), $.init()), me || (me = st);
36
- }
37
- function Fe(i) {
38
- return Ue(), i ? $.detectSupport(i) : i !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: B, ktx2Loader: $, meshoptDecoder: me };
39
- }
40
- function Ne(i) {
41
- i.dracoLoader || i.setDRACOLoader(B), i.ktx2Loader || i.setKTX2Loader($), i.meshoptDecoder || i.setMeshoptDecoder(me);
42
- }
43
- const Te = /* @__PURE__ */ new WeakMap();
44
- function ze(i, t) {
45
- let e = Te.get(i);
46
- e ? e = Object.assign(e, t) : e = t, Te.set(i, e);
47
- }
48
- const we = Pe.prototype.load;
49
- function lt(...i) {
50
- const t = Te.get(this);
51
- let e = i[0];
52
- const s = new URL(e, window.location.href);
53
- if (s.hostname.endsWith("needle.tools")) {
54
- const n = (t == null ? void 0 : t.progressive) !== void 0 ? t.progressive : !0, r = t != null && t.usecase ? t.usecase : "default";
55
- n ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${r}` : this.requestHeader.Accept = `*/*;usecase=${r}`, e = s.toString();
56
- }
57
- return i[0] = e, we == null ? void 0 : we.call(this, ...i);
58
- }
59
- Pe.prototype.load = lt;
60
- ce("debugprogressive");
61
- function ce(i) {
62
- if (typeof window > "u") return !1;
63
- const e = new URL(window.location.href).searchParams.get(i);
64
- return e == null || e === "0" || e === "false" ? !1 : e === "" ? !0 : e;
65
- }
66
- function ct(i, t) {
67
- if (t === void 0 || t.startsWith("./") || t.startsWith("http") || i === void 0)
68
- return t;
69
- const e = i.lastIndexOf("/");
70
- if (e >= 0) {
71
- const s = i.substring(0, e + 1);
72
- for (; s.endsWith("/") && t.startsWith("/"); ) t = t.substring(1);
73
- return s + t;
74
- }
75
- return t;
76
- }
77
- let ie;
78
- function ut() {
79
- return ie !== void 0 || (ie = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), ce("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", ie)), ie;
80
- }
81
- const dt = typeof window > "u" && typeof document > "u", Ae = Symbol("needle:raycast-mesh");
82
- function ue(i) {
83
- return (i == null ? void 0 : i[Ae]) instanceof ye ? i[Ae] : null;
84
- }
85
- function ft(i, t) {
86
- if ((i.type === "Mesh" || i.type === "SkinnedMesh") && !ue(i)) {
87
- const s = gt(t);
88
- s.userData = { isRaycastMesh: !0 }, i[Ae] = s;
89
- }
90
- }
91
- function ht(i = !0) {
92
- if (i) {
93
- if (ae) return;
94
- const t = ae = ee.prototype.raycast;
95
- ee.prototype.raycast = function(e, s) {
96
- const o = this, n = ue(o);
97
- let r;
98
- n && o.isMesh && (r = o.geometry, o.geometry = n), t.call(this, e, s), r && (o.geometry = r);
99
- };
100
- } else {
101
- if (!ae) return;
102
- ee.prototype.raycast = ae, ae = null;
103
- }
104
- }
105
- let ae = null;
106
- function gt(i) {
107
- const t = new ye();
108
- for (const e in i.attributes)
109
- t.setAttribute(e, i.getAttribute(e));
110
- return t.setIndex(i.getIndex()), t;
111
- }
112
- const Q = new Array(), D = ce("debugprogressive");
113
- let pe, Z = -1;
114
- if (D) {
115
- let i = function() {
116
- Z += 1, Z >= t && (Z = -1), console.log(`Toggle LOD level [${Z}]`);
117
- }, t = 6;
118
- window.addEventListener("keyup", (e) => {
119
- e.key === "p" && i(), e.key === "w" && (pe = !pe, console.log(`Toggle wireframe [${pe}]`));
120
- const s = parseInt(e.key);
121
- !isNaN(s) && s >= 0 && (Z = s, console.log(`Set LOD level to [${Z}]`));
122
- });
123
- }
124
- function Ve(i) {
125
- if (D)
126
- if (Array.isArray(i))
127
- for (const t of i)
128
- Ve(t);
129
- else i && "wireframe" in i && (i.wireframe = pe === !0);
130
- }
131
- const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), x = class x {
132
- constructor(t, e) {
133
- d(this, "parser");
134
- d(this, "url");
135
- d(this, "_isLoadingMesh");
136
- d(this, "loadMesh", (t) => {
137
- var s, o;
138
- if (this._isLoadingMesh) return null;
139
- const e = (o = (s = this.parser.json.meshes[t]) == null ? void 0 : s.extensions) == null ? void 0 : o[K];
140
- return e ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", t).then((n) => {
141
- var r;
142
- return this._isLoadingMesh = !1, n && x.registerMesh(this.url, e.guid, n, (r = e.lods) == null ? void 0 : r.length, 0, e), n;
143
- })) : null;
144
- });
145
- D && console.log("Progressive extension registered for", e), this.parser = t, this.url = e;
146
- }
147
- /** The name of the extension */
148
- get name() {
149
- return K;
150
- }
151
- static getMeshLODExtension(t) {
152
- const e = this.getAssignedLODInformation(t);
153
- return e != null && e.key ? this.lodInfos.get(e.key) : null;
154
- }
155
- static getPrimitiveIndex(t) {
156
- var s;
157
- const e = (s = this.getAssignedLODInformation(t)) == null ? void 0 : s.index;
158
- return e ?? -1;
159
- }
160
- static getMaterialMinMaxLODsCount(t, e) {
161
- const s = this, o = "LODS:minmax", n = t[o];
162
- if (n != null) return n;
163
- if (e || (e = {
164
- min_count: 1 / 0,
165
- max_count: 0,
166
- lods: []
167
- }), Array.isArray(t)) {
168
- for (const a of t)
169
- this.getMaterialMinMaxLODsCount(a, e);
170
- return t[o] = e, e;
171
- }
172
- if (D === "verbose" && console.log("getMaterialMinMaxLODsCount", t), t.type === "ShaderMaterial" || t.type === "RawShaderMaterial") {
173
- const a = t;
174
- for (const l of Object.keys(a.uniforms)) {
175
- const u = a.uniforms[l].value;
176
- (u == null ? void 0 : u.isTexture) === !0 && r(u, e);
177
- }
178
- } else if (t.isMaterial)
179
- for (const a of Object.keys(t)) {
180
- const l = t[a];
181
- (l == null ? void 0 : l.isTexture) === !0 && r(l, e);
182
- }
183
- return t[o] = e, e;
184
- function r(a, l) {
185
- const u = s.getAssignedLODInformation(a);
186
- if (u) {
187
- const c = s.lodInfos.get(u.key);
188
- if (c && c.lods) {
189
- l.min_count = Math.min(l.min_count, c.lods.length), l.max_count = Math.max(l.max_count, c.lods.length);
190
- for (let h = 0; h < c.lods.length; h++) {
191
- const g = c.lods[h];
192
- g.width && (l.lods[h] = l.lods[h] || { min_height: 1 / 0, max_height: 0 }, l.lods[h].min_height = Math.min(l.lods[h].min_height, g.height), l.lods[h].max_height = Math.max(l.lods[h].max_height, g.height));
193
- }
194
- }
195
- }
196
- }
197
- }
198
- /** Check if a LOD level is available for a mesh or a texture
199
- * @param obj the mesh or texture to check
200
- * @param level the level of detail to check for (0 is the highest resolution). If undefined, the function checks if any LOD level is available
201
- * @returns true if the LOD level is available (or if any LOD level is available if level is undefined)
202
- */
203
- static hasLODLevelAvailable(t, e) {
204
- var n;
205
- if (Array.isArray(t)) {
206
- for (const r of t)
207
- if (this.hasLODLevelAvailable(r, e)) return !0;
208
- return !1;
209
- }
210
- if (t.isMaterial === !0) {
211
- for (const r of Object.keys(t)) {
212
- const a = t[r];
213
- if (a && a.isTexture && this.hasLODLevelAvailable(a, e))
214
- return !0;
215
- }
216
- return !1;
217
- } else if (t.isGroup === !0) {
218
- for (const r of t.children)
219
- if (r.isMesh === !0 && this.hasLODLevelAvailable(r, e))
220
- return !0;
221
- }
222
- let s, o;
223
- if (t.isMesh ? s = t.geometry : (t.isBufferGeometry || t.isTexture) && (s = t), s && (n = s == null ? void 0 : s.userData) != null && n.LODS) {
224
- const r = s.userData.LODS;
225
- if (o = this.lodInfos.get(r.key), e === void 0) return o != null;
226
- if (o)
227
- return Array.isArray(o.lods) ? e < o.lods.length : e === 0;
228
- }
229
- return !1;
230
- }
231
- /** Load a different resolution of a mesh (if available)
232
- * @param context the context
233
- * @param source the sourceid of the file from which the mesh is loaded (this is usually the component's sourceId)
234
- * @param mesh the mesh to load the LOD for
235
- * @param level the level of detail to load (0 is the highest resolution)
236
- * @returns a promise that resolves to the mesh with the requested LOD level
237
- * @example
238
- * ```javascript
239
- * const mesh = this.gameObject as Mesh;
240
- * NEEDLE_progressive.assignMeshLOD(context, sourceId, mesh, 1).then(mesh => {
241
- * console.log("Mesh with LOD level 1 loaded", mesh);
242
- * });
243
- * ```
244
- */
245
- static assignMeshLOD(t, e) {
246
- var s;
247
- if (!t) return Promise.resolve(null);
248
- if (t instanceof ee || t.isMesh === !0) {
249
- const o = t.geometry, n = this.getAssignedLODInformation(o);
250
- if (!n)
251
- return Promise.resolve(null);
252
- for (const r of Q)
253
- (s = r.onBeforeGetLODMesh) == null || s.call(r, t, e);
254
- return t["LOD:requested level"] = e, x.getOrLoadLOD(o, e).then((r) => {
255
- if (Array.isArray(r)) {
256
- const a = n.index || 0;
257
- r = r[a];
258
- }
259
- return t["LOD:requested level"] === e && (delete t["LOD:requested level"], r && o != r && ((r == null ? void 0 : r.isBufferGeometry) ? t.geometry = r : D && console.error("Invalid LOD geometry", r))), r;
260
- }).catch((r) => (console.error("Error loading mesh LOD", t, r), null));
261
- } else D && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", t);
262
- return Promise.resolve(null);
263
- }
264
- static assignTextureLOD(t, e = 0) {
265
- if (!t) return Promise.resolve(null);
266
- if (t.isMesh === !0) {
267
- const s = t;
268
- if (Array.isArray(s.material)) {
269
- const o = new Array();
270
- for (const n of s.material) {
271
- const r = this.assignTextureLOD(n, e);
272
- o.push(r);
273
- }
274
- return Promise.all(o).then((n) => {
275
- const r = new Array();
276
- for (const a of n)
277
- Array.isArray(a) && r.push(...a);
278
- return r;
279
- });
280
- } else
281
- return this.assignTextureLOD(s.material, e);
282
- }
283
- if (t.isMaterial === !0) {
284
- const s = t, o = [], n = new Array();
285
- if (s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
286
- const r = s;
287
- for (const a of Object.keys(r.uniforms)) {
288
- const l = r.uniforms[a].value;
289
- if ((l == null ? void 0 : l.isTexture) === !0) {
290
- const u = this.assignTextureLODForSlot(l, e, s, a).then((c) => (c && r.uniforms[a].value != c && (r.uniforms[a].value = c, r.uniformsNeedUpdate = !0), c));
291
- o.push(u), n.push(a);
292
- }
293
- }
294
- } else
295
- for (const r of Object.keys(s)) {
296
- const a = s[r];
297
- if ((a == null ? void 0 : a.isTexture) === !0) {
298
- const l = this.assignTextureLODForSlot(a, e, s, r);
299
- o.push(l), n.push(r);
300
- }
301
- }
302
- return Promise.all(o).then((r) => {
303
- const a = new Array();
304
- for (let l = 0; l < r.length; l++) {
305
- const u = r[l], c = n[l];
306
- u && u.isTexture === !0 ? a.push({ material: s, slot: c, texture: u, level: e }) : a.push({ material: s, slot: c, texture: null, level: e });
307
- }
308
- return a;
309
- });
310
- }
311
- if (t instanceof oe || t.isTexture === !0) {
312
- const s = t;
313
- return this.assignTextureLODForSlot(s, e, null, null);
314
- }
315
- return Promise.resolve(null);
316
- }
317
- static assignTextureLODForSlot(t, e, s, o) {
318
- return (t == null ? void 0 : t.isTexture) !== !0 ? Promise.resolve(null) : o === "glyphMap" ? Promise.resolve(t) : x.getOrLoadLOD(t, e).then((n) => {
319
- if (Array.isArray(n)) return null;
320
- if ((n == null ? void 0 : n.isTexture) === !0) {
321
- if (n != t && s && o) {
322
- const r = s[o];
323
- if (r && !D) {
324
- const a = this.getAssignedLODInformation(r);
325
- if (a && (a == null ? void 0 : a.level) < e)
326
- return D === "verbose" && console.warn("Assigned texture level is already higher: ", a.level, e, s, r, n), null;
327
- }
328
- s[o] = n;
329
- }
330
- return n;
331
- } else D == "verbose" && console.warn("No LOD found for", t, e);
332
- return null;
333
- }).catch((n) => (console.error("Error loading LOD", t, n), null));
334
- }
335
- afterRoot(t) {
336
- var e, s;
337
- return D && console.log("AFTER", this.url, t), (e = this.parser.json.textures) == null || e.forEach((o, n) => {
338
- var r;
339
- if (o != null && o.extensions) {
340
- const a = o == null ? void 0 : o.extensions[K];
341
- if (a) {
342
- if (!a.lods) {
343
- D && console.warn("Texture has no LODs", a);
344
- return;
345
- }
346
- let l = !1;
347
- for (const u of this.parser.associations.keys())
348
- if (u.isTexture === !0) {
349
- const c = this.parser.associations.get(u);
350
- (c == null ? void 0 : c.textures) === n && (l = !0, x.registerTexture(this.url, u, (r = a.lods) == null ? void 0 : r.length, n, a));
351
- }
352
- l || this.parser.getDependency("texture", n).then((u) => {
353
- var c;
354
- u && x.registerTexture(this.url, u, (c = a.lods) == null ? void 0 : c.length, n, a);
355
- });
356
- }
357
- }
358
- }), (s = this.parser.json.meshes) == null || s.forEach((o, n) => {
359
- if (o != null && o.extensions) {
360
- const r = o == null ? void 0 : o.extensions[K];
361
- if (r && r.lods) {
362
- for (const a of this.parser.associations.keys())
363
- if (a.isMesh) {
364
- const l = this.parser.associations.get(a);
365
- (l == null ? void 0 : l.meshes) === n && x.registerMesh(this.url, r.guid, a, r.lods.length, l.primitives, r);
366
- }
367
- }
368
- }
369
- }), null;
370
- }
371
- static async getOrLoadLOD(t, e) {
372
- var a, l, u, c;
373
- const s = D == "verbose", o = t.userData.LODS;
374
- if (!o)
375
- return null;
376
- const n = o == null ? void 0 : o.key;
377
- let r;
378
- if (t.isTexture === !0) {
379
- const h = t;
380
- h.source && h.source[Oe] && (r = h.source[Oe]);
381
- }
382
- if (r || (r = x.lodInfos.get(n)), r) {
383
- if (e > 0) {
384
- let v = !1;
385
- const b = Array.isArray(r.lods);
386
- if (b && e >= r.lods.length ? v = !0 : b || (v = !0), v)
387
- return this.lowresCache.get(n);
388
- }
389
- const h = Array.isArray(r.lods) ? (a = r.lods[e]) == null ? void 0 : a.path : r.lods;
390
- if (!h)
391
- return D && !r["missing:uri"] && (r["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, r)), null;
392
- const g = ct(o.url, h);
393
- if (g.endsWith(".glb") || g.endsWith(".gltf")) {
394
- if (!r.guid)
395
- return console.warn("missing pointer for glb/gltf texture", r), null;
396
- const v = g + "_" + r.guid, b = this.previouslyLoaded.get(v);
397
- if (b !== void 0) {
398
- s && console.log(`LOD ${e} was already loading/loaded: ${v}`);
399
- let w = await b.catch((p) => (console.error(`Error loading LOD ${e} from ${g}
400
- `, p), null)), _ = !1;
401
- if (w == null || (w instanceof oe && t instanceof oe ? (l = w.image) != null && l.data || (u = w.source) != null && u.data ? w = this.copySettings(t, w) : (_ = !0, this.previouslyLoaded.delete(v)) : w instanceof ye && t instanceof ye && ((c = w.attributes.position) != null && c.array || (_ = !0, this.previouslyLoaded.delete(v)))), !_)
402
- return w;
403
- }
404
- const M = r, U = new Promise(async (w, _) => {
405
- const p = new Pe();
406
- Ne(p), D && (await new Promise((S) => setTimeout(S, 1e3)), s && console.warn("Start loading (delayed) " + g, M.guid));
407
- let X = g;
408
- if (M && Array.isArray(M.lods)) {
409
- const S = M.lods[e];
410
- S.hash && (X += "?v=" + S.hash);
411
- }
412
- const A = await p.loadAsync(X).catch((S) => (console.error(`Error loading LOD ${e} from ${g}
413
- `, S), null));
414
- if (!A) return null;
415
- const R = A.parser;
416
- s && console.log("Loading finished " + g, M.guid);
417
- let I = 0;
418
- if (A.parser.json.textures) {
419
- let S = !1;
420
- for (const f of A.parser.json.textures) {
421
- if (f != null && f.extensions) {
422
- const T = f == null ? void 0 : f.extensions[K];
423
- if (T != null && T.guid && T.guid === M.guid) {
424
- S = !0;
425
- break;
426
- }
427
- }
428
- I++;
429
- }
430
- if (S) {
431
- let f = await R.getDependency("texture", I);
432
- return f && x.assignLODInformation(o.url, f, n, e, void 0), s && console.log('change "' + t.name + '" → "' + f.name + '"', g, I, f, v), t instanceof oe && (f = this.copySettings(t, f)), f && (f.guid = M.guid), w(f);
433
- } else D && console.warn("Could not find texture with guid", M.guid, A.parser.json);
434
- }
435
- if (I = 0, A.parser.json.meshes) {
436
- let S = !1;
437
- for (const f of A.parser.json.meshes) {
438
- if (f != null && f.extensions) {
439
- const T = f == null ? void 0 : f.extensions[K];
440
- if (T != null && T.guid && T.guid === M.guid) {
441
- S = !0;
442
- break;
443
- }
444
- }
445
- I++;
446
- }
447
- if (S) {
448
- const f = await R.getDependency("mesh", I);
449
- if (s && console.log(`Loaded Mesh "${f.name}"`, g, I, f, v), f.isMesh === !0) {
450
- const T = f.geometry;
451
- return x.assignLODInformation(o.url, T, n, e, 0), w(T);
452
- } else {
453
- const T = new Array();
454
- for (let L = 0; L < f.children.length; L++) {
455
- const O = f.children[L];
456
- if (O.isMesh === !0) {
457
- const P = O.geometry;
458
- x.assignLODInformation(o.url, P, n, e, L), T.push(P);
459
- }
460
- }
461
- return w(T);
462
- }
463
- } else D && console.warn("Could not find mesh with guid", M.guid, A.parser.json);
464
- }
465
- return w(null);
466
- });
467
- return this.previouslyLoaded.set(v, U), await U;
468
- } else if (t instanceof oe) {
469
- s && console.log("Load texture from uri: " + g);
470
- const b = await new je().loadAsync(g);
471
- return b ? (b.guid = r.guid, b.flipY = !1, b.needsUpdate = !0, b.colorSpace = t.colorSpace, s && console.log(r, b)) : D && console.warn("failed loading", g), b;
472
- }
473
- } else
474
- D && console.warn(`Can not load LOD ${e}: no LOD info found for "${n}" ${t.name}`, t.type);
475
- return null;
476
- }
477
- static assignLODInformation(t, e, s, o, n) {
478
- if (!e) return;
479
- e.userData || (e.userData = {});
480
- const r = new pt(t, s, o, n);
481
- e.userData.LODS = r;
482
- }
483
- static getAssignedLODInformation(t) {
484
- var e;
485
- return ((e = t == null ? void 0 : t.userData) == null ? void 0 : e.LODS) || null;
486
- }
487
- // private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
488
- static copySettings(t, e) {
489
- return e ? (D && console.warn(`Copy texture settings
490
- `, t.uuid, `
491
- `, e.uuid), e = e.clone(), e.offset = t.offset, e.repeat = t.repeat, e.colorSpace = t.colorSpace, e.magFilter = t.magFilter, e.minFilter = t.minFilter, e.wrapS = t.wrapS, e.wrapT = t.wrapT, e.flipY = t.flipY, e.anisotropy = t.anisotropy, e.mipmaps || (e.generateMipmaps = t.generateMipmaps), e) : t;
492
- }
493
- };
494
- /**
495
- * Register a texture with LOD information
496
- */
497
- d(x, "registerTexture", (t, e, s, o, n) => {
498
- if (D && console.log("> Progressive: register texture", o, e.name, e.uuid, e, n), !e) {
499
- D && console.error("gltf-progressive: Register texture without texture");
500
- return;
501
- }
502
- e.source && (e.source[Oe] = n);
503
- const r = n.guid;
504
- x.assignLODInformation(t, e, r, s, o), x.lodInfos.set(r, n), x.lowresCache.set(r, e);
505
- }), /**
506
- * Register a mesh with LOD information
507
- */
508
- d(x, "registerMesh", (t, e, s, o, n, r) => {
509
- var u;
510
- const a = s.geometry;
511
- if (!a) {
512
- D && console.warn("gltf-progressive: Register mesh without geometry");
513
- return;
514
- }
515
- a.userData || (a.userData = {}), D && console.log("> Progressive: register mesh " + s.name, { index: n, uuid: s.uuid }, r, s), x.assignLODInformation(t, a, e, o, n), x.lodInfos.set(e, r);
516
- let l = x.lowresCache.get(e);
517
- l ? l.push(s.geometry) : l = [s.geometry], x.lowresCache.set(e, l), o > 0 && !ue(s) && ft(s, a);
518
- for (const c of Q)
519
- (u = c.onRegisteredNewMesh) == null || u.call(c, s, r);
520
- }), /** A map of key = asset uuid and value = LOD information */
521
- d(x, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
522
- d(x, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
523
- d(x, "lowresCache", /* @__PURE__ */ new Map());
524
- let z = x;
525
- class pt {
526
- constructor(t, e, s, o) {
527
- d(this, "url");
528
- /** the key to lookup the LOD information */
529
- d(this, "key");
530
- d(this, "level");
531
- /** For multi objects (e.g. a group of meshes) this is the index of the object */
532
- d(this, "index");
533
- this.url = t, this.key = e, this.level = s, o != null && (this.index = o);
534
- }
535
- }
536
- const G = ce("debugprogressive"), yt = ce("noprogressive"), _e = Symbol("Needle:LODSManager"), be = Symbol("Needle:LODState"), J = Symbol("Needle:CurrentLOD"), C = { mesh_lod: -1, texture_lod: -1 };
537
- var m, E, Y, xe, se, re, De, H;
538
- let Le = (m = class {
539
- // readonly plugins: NEEDLE_progressive_plugin[] = [];
540
- constructor(t, e) {
541
- d(this, "context");
542
- d(this, "renderer");
543
- d(this, "projectionScreenMatrix", new Be());
544
- /**
545
- * The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
546
- * @default 200_000
547
- */
548
- d(this, "targetTriangleDensity", 2e5);
549
- /**
550
- * The interval in frames to automatically update the bounds of skinned meshes.
551
- * Set to 0 or a negative value to disable automatic bounds updates.
552
- * @default 30
553
- */
554
- d(this, "skinnedMeshAutoUpdateBoundsInterval", 30);
555
- /**
556
- * The update interval in frames. If set to 0, the LODs will be updated every frame. If set to 2, the LODs will be updated every second frame, etc.
557
- * @default "auto"
558
- */
559
- d(this, "updateInterval", "auto");
560
- j(this, E, 1);
561
- /**
562
- * If set to true, the LODsManager will not update the LODs.
563
- * @default false
564
- */
565
- d(this, "pause", !1);
566
- /**
567
- * When set to true the LODsManager will not update the LODs. This can be used to manually update the LODs using the `update` method.
568
- * Otherwise the LODs will be updated automatically when the renderer renders the scene.
569
- * @default false
570
- */
571
- d(this, "manual", !1);
572
- d(this, "_lodchangedlisteners", []);
573
- j(this, Y);
574
- j(this, xe, new Je());
575
- j(this, se, 0);
576
- j(this, re, 0);
577
- j(this, De, 0);
578
- j(this, H, 0);
579
- d(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
580
- // private testIfLODLevelsAreAvailable() {
581
- d(this, "_sphere", new Ze());
582
- d(this, "_tempBox", new Ie());
583
- d(this, "_tempBox2", new Ie());
584
- d(this, "tempMatrix", new Be());
585
- d(this, "_tempWorldPosition", new q());
586
- d(this, "_tempBoxSize", new q());
587
- d(this, "_tempBox2Size", new q());
588
- this.renderer = t, this.context = { ...e };
589
- }
590
- /** @internal */
591
- static getObjectLODState(t) {
592
- return t[be];
593
- }
594
- static addPlugin(t) {
595
- Q.push(t);
596
- }
597
- static removePlugin(t) {
598
- const e = Q.indexOf(t);
599
- e >= 0 && Q.splice(e, 1);
600
- }
601
- /**
602
- * Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
603
- * @param renderer The renderer to get the LODsManager for.
604
- * @returns The LODsManager instance.
605
- */
606
- static get(t, e) {
607
- if (t[_e])
608
- return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[_e];
609
- const s = new m(t, {
610
- engine: "unknown",
611
- ...e
612
- });
613
- return t[_e] = s, s;
614
- }
615
- /** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
616
- get plugins() {
617
- return Q;
618
- }
619
- addEventListener(t, e) {
620
- t === "changed" && this._lodchangedlisteners.push(e);
621
- }
622
- removeEventListener(t, e) {
623
- if (t === "changed") {
624
- const s = this._lodchangedlisteners.indexOf(e);
625
- s >= 0 && this._lodchangedlisteners.splice(s, 1);
626
- }
627
- }
628
- /**
629
- * Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
630
- */
631
- enable() {
632
- if (y(this, Y)) return;
633
- console.debug("[gltf-progressive] Enabling LODsManager for renderer");
634
- let t = 0;
635
- N(this, Y, this.renderer.render);
636
- const e = this;
637
- Fe(this.renderer), this.renderer.render = function(s, o) {
638
- const n = e.renderer.getRenderTarget();
639
- (n == null || "isXRRenderTarget" in n && n.isXRRenderTarget) && (t = 0, N(e, se, y(e, se) + 1), N(e, re, y(e, xe).getDelta()), N(e, De, y(e, De) + y(e, re)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / y(e, re)), N(e, H, e._fpsBuffer.reduce((a, l) => a + l) / e._fpsBuffer.length), G && y(e, se) % 200 === 0 && console.log("FPS", Math.round(y(e, H)), "Interval:", y(e, E)));
640
- const r = t++;
641
- y(e, Y).call(this, s, o), e.onAfterRender(s, o, r);
642
- };
643
- }
644
- disable() {
645
- y(this, Y) && (console.debug("[gltf-progressive] Disabling LODsManager for renderer"), this.renderer.render = y(this, Y), N(this, Y, void 0));
646
- }
647
- update(t, e) {
648
- this.internalUpdate(t, e);
649
- }
650
- onAfterRender(t, e, s) {
651
- if (this.pause) return;
652
- const n = this.renderer.renderLists.get(t, 0).opaque;
653
- let r = !0;
654
- if (n.length === 1) {
655
- const a = n[0].material;
656
- (a.name === "EffectMaterial" || a.name === "CopyShader") && (r = !1);
657
- }
658
- if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (r = !1), r) {
659
- if (yt || (this.updateInterval === "auto" ? y(this, H) < 40 && y(this, E) < 10 ? (N(this, E, y(this, E) + 1), G && console.warn("↓ Reducing LOD updates", y(this, E), y(this, H).toFixed(0))) : y(this, H) >= 60 && y(this, E) > 1 && (N(this, E, y(this, E) - 1), G && console.warn("↑ Increasing LOD updates", y(this, E), y(this, H).toFixed(0))) : N(this, E, this.updateInterval), y(this, E) > 0 && y(this, se) % y(this, E) != 0))
660
- return;
661
- this.internalUpdate(t, e);
662
- }
663
- }
664
- /**
665
- * Update LODs in a scene
666
- */
667
- internalUpdate(t, e) {
668
- var l, u;
669
- const s = this.renderer.renderLists.get(t, 0), o = s.opaque;
670
- this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix, e.matrixWorldInverse);
671
- const n = this.targetTriangleDensity;
672
- for (const c of o) {
673
- if (c.material && (((l = c.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((u = c.geometry) == null ? void 0 : u.type) === "BufferGeometry") && (c.material.name === "SphericalGaussianBlur" || c.material.name == "BackgroundCubeMaterial" || c.material.name === "CubemapFromEquirect" || c.material.name === "EquirectangularToCubeUV")) {
674
- G && (c.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (c.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", c, c.material.name, c.material.type)));
675
- continue;
676
- }
677
- switch (c.material.type) {
678
- case "LineBasicMaterial":
679
- case "LineDashedMaterial":
680
- case "PointsMaterial":
681
- case "ShadowMaterial":
682
- case "MeshDistanceMaterial":
683
- case "MeshDepthMaterial":
684
- continue;
685
- }
686
- if (G === "color" && c.material && !c.object.progressive_debug_color) {
687
- c.object.progressive_debug_color = !0;
688
- const g = Math.random() * 16777215, v = new Qe({ color: g });
689
- c.object.material = v;
690
- }
691
- const h = c.object;
692
- (h instanceof ee || h.isMesh) && this.updateLODs(t, e, h, n);
693
- }
694
- const r = s.transparent;
695
- for (const c of r) {
696
- const h = c.object;
697
- (h instanceof ee || h.isMesh) && this.updateLODs(t, e, h, n);
698
- }
699
- const a = s.transmissive;
700
- for (const c of a) {
701
- const h = c.object;
702
- (h instanceof ee || h.isMesh) && this.updateLODs(t, e, h, n);
703
- }
704
- }
705
- /** Update the LOD levels for the renderer. */
706
- updateLODs(t, e, s, o) {
707
- var a, l;
708
- s.userData || (s.userData = {});
709
- let n = s[be];
710
- if (n || (n = new mt(), s[be] = n), n.frames++ < 2)
711
- return;
712
- for (const u of Q)
713
- (a = u.onBeforeUpdateLOD) == null || a.call(u, this.renderer, t, e, s);
714
- const r = m.overrideGlobalLodLevel !== void 0 ? m.overrideGlobalLodLevel : Z;
715
- r >= 0 ? (C.mesh_lod = r, C.texture_lod = r) : (this.calculateLodLevel(e, s, n, o, C), C.mesh_lod = Math.round(C.mesh_lod), C.texture_lod = Math.round(C.texture_lod)), C.mesh_lod >= 0 && this.loadProgressiveMeshes(s, C.mesh_lod), s.material && C.texture_lod >= 0 && this.loadProgressiveTextures(s.material, C.texture_lod), D && s.material && !s.isGizmo && Ve(s.material);
716
- for (const u of Q)
717
- (l = u.onAfterUpdatedLOD) == null || l.call(u, this.renderer, t, e, s, C);
718
- n.lastLodLevel_Mesh = C.mesh_lod, n.lastLodLevel_Texture = C.texture_lod;
719
- }
720
- /** Load progressive textures for the given material
721
- * @param material the material to load the textures for
722
- * @param level the LOD level to load. Level 0 is the best quality, higher levels are lower quality
723
- * @returns Promise with true if the LOD was loaded, false if not
724
- */
725
- loadProgressiveTextures(t, e) {
726
- if (!t) return;
727
- if (Array.isArray(t)) {
728
- for (const n of t)
729
- this.loadProgressiveTextures(n, e);
730
- return;
731
- }
732
- let s = !1;
733
- (t[J] === void 0 || e < t[J]) && (s = !0);
734
- const o = t["DEBUG:LOD"];
735
- o != null && (s = t[J] != o, e = o), s && (t[J] = e, z.assignTextureLOD(t, e).then((n) => {
736
- this._lodchangedlisteners.forEach((r) => r({ type: "texture", level: e, object: t }));
737
- }));
738
- }
739
- /** Load progressive meshes for the given mesh
740
- * @param mesh the mesh to load the LOD for
741
- * @param index the index of the mesh if it's part of a group
742
- * @param level the LOD level to load. Level 0 is the best quality, higher levels are lower quality
743
- * @returns Promise with true if the LOD was loaded, false if not
744
- */
745
- loadProgressiveMeshes(t, e) {
746
- if (!t) return Promise.resolve(null);
747
- let s = t[J] !== e;
748
- const o = t["DEBUG:LOD"];
749
- if (o != null && (s = t[J] != o, e = o), s) {
750
- t[J] = e;
751
- const n = t.geometry;
752
- return z.assignMeshLOD(t, e).then((r) => (r && t[J] == e && n != t.geometry && this._lodchangedlisteners.forEach((a) => a({ type: "mesh", level: e, object: t })), r));
753
- }
754
- return Promise.resolve(null);
755
- }
756
- static isInside(t, e) {
757
- const s = t.min, o = t.max, n = (s.x + o.x) * 0.5, r = (s.y + o.y) * 0.5;
758
- return this._tempPtInside.set(n, r, s.z).applyMatrix4(e).z < 0;
759
- }
760
- calculateLodLevel(t, e, s, o, n) {
761
- var U, W, w;
762
- if (!e) {
763
- n.mesh_lod = -1, n.texture_lod = -1;
764
- return;
765
- }
766
- if (!t) {
767
- n.mesh_lod = -1, n.texture_lod = -1;
768
- return;
769
- }
770
- let a = 10 + 1, l = !1;
771
- if (G && e["DEBUG:LOD"] != null)
772
- return e["DEBUG:LOD"];
773
- const u = (U = z.getMeshLODExtension(e.geometry)) == null ? void 0 : U.lods, c = z.getPrimitiveIndex(e.geometry), h = u && u.length > 0, g = z.getMaterialMinMaxLODsCount(e.material), v = (g == null ? void 0 : g.min_count) != 1 / 0 && g.min_count > 0 && g.max_count > 0;
774
- if (!h && !v) {
775
- n.mesh_lod = 0, n.texture_lod = 0;
776
- return;
777
- }
778
- h || (l = !0, a = 0);
779
- const b = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
780
- let M = e.geometry.boundingBox;
781
- if (e.type === "SkinnedMesh") {
782
- const _ = e;
783
- if (!_.boundingBox)
784
- _.computeBoundingBox();
785
- else if (this.skinnedMeshAutoUpdateBoundsInterval > 0 && s.frames % this.skinnedMeshAutoUpdateBoundsInterval === 0) {
786
- const p = ue(_), X = _.geometry;
787
- p && (_.geometry = p), _.computeBoundingBox(), _.geometry = X;
788
- }
789
- M = _.boundingBox;
790
- }
791
- if (M) {
792
- const _ = t;
793
- if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
794
- this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
795
- const L = t.getWorldPosition(this._tempWorldPosition);
796
- if (this._sphere.containsPoint(L)) {
797
- n.mesh_lod = 0, n.texture_lod = 0;
798
- return;
799
- }
800
- }
801
- if (this._tempBox.copy(M), this._tempBox.applyMatrix4(e.matrixWorld), _.isPerspectiveCamera && m.isInside(this._tempBox, this.projectionScreenMatrix)) {
802
- n.mesh_lod = 0, n.texture_lod = 0;
803
- return;
804
- }
805
- if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && _.isPerspectiveCamera && _.fov > 70) {
806
- const L = this._tempBox.min, O = this._tempBox.max;
807
- let P = L.x, k = L.y, F = O.x, ne = O.y;
808
- const de = 2, Me = 1.5, fe = (L.x + O.x) * 0.5, he = (L.y + O.y) * 0.5;
809
- P = (P - fe) * de + fe, k = (k - he) * de + he, F = (F - fe) * de + fe, ne = (ne - he) * de + he;
810
- const qe = P < 0 && F > 0 ? 0 : Math.min(Math.abs(L.x), Math.abs(O.x)), Ke = k < 0 && ne > 0 ? 0 : Math.min(Math.abs(L.y), Math.abs(O.y)), ve = Math.max(qe, Ke);
811
- s.lastCentrality = (Me - ve) * (Me - ve) * (Me - ve);
812
- } else
813
- s.lastCentrality = 1;
814
- const p = this._tempBox.getSize(this._tempBoxSize);
815
- p.multiplyScalar(0.5), screen.availHeight > 0 && b > 0 && p.multiplyScalar(b / screen.availHeight), t.isPerspectiveCamera ? p.x *= t.aspect : t.isOrthographicCamera;
816
- const X = t.matrixWorldInverse, A = this._tempBox2;
817
- A.copy(M), A.applyMatrix4(e.matrixWorld), A.applyMatrix4(X);
818
- const R = A.getSize(this._tempBox2Size), I = Math.max(R.x, R.y);
819
- if (Math.max(p.x, p.y) != 0 && I != 0 && (p.z = R.z / Math.max(R.x, R.y) * Math.max(p.x, p.y)), s.lastScreenCoverage = Math.max(p.x, p.y, p.z), s.lastScreenspaceVolume.copy(p), s.lastScreenCoverage *= s.lastCentrality, G && m.debugDrawLine) {
820
- const L = this.tempMatrix.copy(this.projectionScreenMatrix);
821
- L.invert();
822
- const O = m.corner0, P = m.corner1, k = m.corner2, F = m.corner3;
823
- O.copy(this._tempBox.min), P.copy(this._tempBox.max), P.x = O.x, k.copy(this._tempBox.max), k.y = O.y, F.copy(this._tempBox.max);
824
- const ne = (O.z + F.z) * 0.5;
825
- O.z = P.z = k.z = F.z = ne, O.applyMatrix4(L), P.applyMatrix4(L), k.applyMatrix4(L), F.applyMatrix4(L), m.debugDrawLine(O, P, 255), m.debugDrawLine(O, k, 255), m.debugDrawLine(P, F, 255), m.debugDrawLine(k, F, 255);
826
- }
827
- let f = 999;
828
- if (u && s.lastScreenCoverage > 0)
829
- for (let L = 0; L < u.length; L++) {
830
- const O = u[L];
831
- if ((((W = O.densities) == null ? void 0 : W[c]) || O.density || 1e-5) / s.lastScreenCoverage < o) {
832
- f = L;
833
- break;
834
- }
835
- }
836
- f < a && (a = f, l = !0);
837
- }
838
- if (l ? n.mesh_lod = a : n.mesh_lod = s.lastLodLevel_Mesh, G && n.mesh_lod != s.lastLodLevel_Mesh) {
839
- const p = u == null ? void 0 : u[n.mesh_lod];
840
- p && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${n.mesh_lod} (${p.density.toFixed(0)}) - ${e.name}`);
841
- }
842
- if (v) {
843
- const _ = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
844
- if (s.lastLodLevel_Texture < 0) {
845
- if (n.texture_lod = g.max_count - 1, G) {
846
- const p = g.lods[g.max_count - 1];
847
- G && console.log(`First Texture LOD ${n.texture_lod} (${p.max_height}px) - ${e.name}`);
848
- }
849
- } else {
850
- const p = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
851
- let X = s.lastScreenCoverage * 4;
852
- ((w = this.context) == null ? void 0 : w.engine) === "model-viewer" && (X *= 1.5);
853
- const R = b / window.devicePixelRatio * X;
854
- let I = !1;
855
- for (let S = g.lods.length - 1; S >= 0; S--) {
856
- const f = g.lods[S];
857
- if (!(_ && f.max_height >= 2048) && !(ut() && f.max_height > 4096) && (f.max_height > R || !I && S === 0)) {
858
- if (I = !0, n.texture_lod = S, n.texture_lod < s.lastLodLevel_Texture) {
859
- const T = f.max_height;
860
- G && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${n.texture_lod} = ${T}px
861
- Screensize: ${R.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${p.toFixed(1)}
862
- ${e.name}`);
863
- }
864
- break;
865
- }
866
- }
867
- }
868
- } else
869
- n.texture_lod = 0;
870
- }
871
- }, E = new WeakMap(), Y = new WeakMap(), xe = new WeakMap(), se = new WeakMap(), re = new WeakMap(), De = new WeakMap(), H = new WeakMap(), /**
872
- * Assign a function to draw debug lines for the LODs. This function will be called with the start and end position of the line and the color of the line when the `debugprogressive` query parameter is set.
873
- */
874
- d(m, "debugDrawLine"), /**
875
- * Force override the LOD level for all objects in the scene
876
- */
877
- d(m, "overrideGlobalLodLevel"), d(m, "corner0", new q()), d(m, "corner1", new q()), d(m, "corner2", new q()), d(m, "corner3", new q()), d(m, "_tempPtInside", new q()), m);
878
- class mt {
879
- constructor() {
880
- d(this, "frames", 0);
881
- d(this, "lastLodLevel_Mesh", -1);
882
- d(this, "lastLodLevel_Texture", -1);
883
- d(this, "lastScreenCoverage", 0);
884
- d(this, "lastScreenspaceVolume", new q());
885
- d(this, "lastCentrality", 0);
886
- }
887
- }
888
- const Re = Symbol("NEEDLE_mesh_lod"), ge = Symbol("NEEDLE_texture_lod");
889
- let le = null;
890
- function We() {
891
- const i = Lt();
892
- i && (i.mapURLs(function(t) {
893
- return ke(), t;
894
- }), ke(), le == null || le.disconnect(), le = new MutationObserver((t) => {
895
- t.forEach((e) => {
896
- e.addedNodes.forEach((s) => {
897
- s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && Xe(s);
898
- });
899
- });
900
- }), le.observe(document, { childList: !0, subtree: !0 }));
901
- }
902
- function Lt() {
903
- if (typeof customElements > "u") return null;
904
- const i = customElements.get("model-viewer");
905
- return i || (customElements.whenDefined("model-viewer").then(() => {
906
- console.debug("[gltf-progressive] model-viewer defined"), We();
907
- }), null);
908
- }
909
- function ke() {
910
- if (typeof document > "u") return;
911
- document.querySelectorAll("model-viewer").forEach((t) => {
912
- Xe(t);
913
- });
914
- }
915
- const Ge = /* @__PURE__ */ new WeakSet();
916
- let xt = 0;
917
- function Xe(i) {
918
- if (!i || Ge.has(i))
919
- return null;
920
- Ge.add(i), console.debug("[gltf-progressive] found new model-viewer..." + ++xt + `
921
- `, i.getAttribute("src"));
922
- let t = null, e = null, s = null;
923
- for (let o = i; o != null; o = Object.getPrototypeOf(o)) {
924
- const n = Object.getOwnPropertySymbols(o), r = n.find((u) => u.toString() == "Symbol(renderer)"), a = n.find((u) => u.toString() == "Symbol(scene)"), l = n.find((u) => u.toString() == "Symbol(needsRender)");
925
- !t && r != null && (t = i[r].threeRenderer), !e && a != null && (e = i[a]), !s && l != null && (s = i[l]);
926
- }
927
- if (t && e) {
928
- let o = function() {
929
- if (s) {
930
- let r = 0, a = setInterval(() => {
931
- if (r++ > 5) {
932
- clearInterval(a);
933
- return;
934
- }
935
- s == null || s.call(i);
936
- }, 300);
937
- }
938
- };
939
- console.debug("[gltf-progressive] setup model-viewer");
940
- const n = Le.get(t, { engine: "model-viewer" });
941
- return Le.addPlugin(new Dt()), n.enable(), n.addEventListener("changed", () => {
942
- s == null || s.call(i);
943
- }), i.addEventListener("model-visibility", (r) => {
944
- r.detail.visible && (s == null || s.call(i));
945
- }), i.addEventListener("load", () => {
946
- o();
947
- }), () => {
948
- n.disable();
949
- };
950
- }
951
- return null;
952
- }
953
- class Dt {
954
- constructor() {
955
- d(this, "_didWarnAboutMissingUrl", !1);
956
- }
957
- onBeforeUpdateLOD(t, e, s, o) {
958
- this.tryParseMeshLOD(e, o), this.tryParseTextureLOD(e, o);
959
- }
960
- getUrl(t) {
961
- if (!t)
962
- return null;
963
- let e = t.getAttribute("src");
964
- return e || (e = t.src), e || (this._didWarnAboutMissingUrl || console.warn("No url found in modelviewer", t), this._didWarnAboutMissingUrl = !0), e;
965
- }
966
- tryGetCurrentGLTF(t) {
967
- return t._currentGLTF;
968
- }
969
- tryGetCurrentModelViewer(t) {
970
- return t.element;
971
- }
972
- tryParseTextureLOD(t, e) {
973
- if (e[ge] == !0) return;
974
- e[ge] = !0;
975
- const s = this.tryGetCurrentGLTF(t), o = this.tryGetCurrentModelViewer(t), n = this.getUrl(o);
976
- if (n && s && e.material) {
977
- let r = function(l) {
978
- var c, h, g;
979
- if (l[ge] == !0) return;
980
- l[ge] = !0, l.userData && (l.userData.LOD = -1);
981
- const u = Object.keys(l);
982
- for (let v = 0; v < u.length; v++) {
983
- const b = u[v], M = l[b];
984
- if ((M == null ? void 0 : M.isTexture) === !0) {
985
- const U = (h = (c = M.userData) == null ? void 0 : c.associations) == null ? void 0 : h.textures;
986
- if (U == null) continue;
987
- const W = s.parser.json.textures[U];
988
- if (!W) {
989
- console.warn("Texture data not found for texture index " + U);
990
- continue;
991
- }
992
- if ((g = W == null ? void 0 : W.extensions) != null && g[K]) {
993
- const w = W.extensions[K];
994
- w && n && z.registerTexture(n, M, w.lods.length, U, w);
995
- }
996
- }
997
- }
998
- };
999
- const a = e.material;
1000
- if (Array.isArray(a)) for (const l of a) r(l);
1001
- else r(a);
1002
- }
1003
- }
1004
- tryParseMeshLOD(t, e) {
1005
- var r, a;
1006
- if (e[Re] == !0) return;
1007
- e[Re] = !0;
1008
- const s = this.tryGetCurrentModelViewer(t), o = this.getUrl(s);
1009
- if (!o)
1010
- return;
1011
- const n = (a = (r = e.userData) == null ? void 0 : r.gltfExtensions) == null ? void 0 : a[K];
1012
- if (n && o) {
1013
- const l = e.uuid;
1014
- z.registerMesh(o, l, e, 0, n.lods.length, n);
1015
- }
1016
- }
1017
- }
1018
- function Mt(i, t, e, s) {
1019
- Fe(t), Ne(e), ze(e, {
1020
- progressive: !0,
1021
- ...s == null ? void 0 : s.hints
1022
- }), e.register((n) => new z(n, i));
1023
- const o = Le.get(t);
1024
- return (s == null ? void 0 : s.enableLODsManager) !== !1 && o.enable(), o;
1025
- }
1026
- We();
1027
- if (!dt) {
1028
- const i = {
1029
- gltfProgressive: {
1030
- useNeedleProgressive: Mt,
1031
- LODsManager: Le,
1032
- configureLoader: ze,
1033
- getRaycastMesh: ue,
1034
- useRaycastMeshes: ht
1035
- }
1036
- };
1037
- if (!globalThis.Needle)
1038
- globalThis.Needle = i;
1039
- else
1040
- for (const t in i)
1041
- globalThis.Needle[t] = i[t];
1042
- }
1043
- export {
1044
- Le as LODsManager,
1045
- z as NEEDLE_progressive,
1046
- Ne as addDracoAndKTX2Loaders,
1047
- ze as configureLoader,
1048
- Fe as createLoaders,
1049
- ue as getRaycastMesh,
1050
- it as setDracoDecoderLocation,
1051
- at as setKTX2TranscoderLocation
1052
- };