@needle-tools/engine 5.1.14 → 5.1.15

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 (62) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/gltf-progressive-4EjGCbsd.umd.cjs +10 -0
  3. package/dist/{gltf-progressive-DaeP5KBr.js → gltf-progressive-BidVoP6g.js} +205 -198
  4. package/dist/gltf-progressive-JsCmImqa.min.js +10 -0
  5. package/dist/{needle-engine.bundle-y1_E7Ovt.umd.cjs → needle-engine.bundle-BivRq9Io.umd.cjs} +143 -143
  6. package/dist/{needle-engine.bundle-BEa7CABw.js → needle-engine.bundle-ByEd2JMt.js} +5658 -5645
  7. package/dist/{needle-engine.bundle-mkmiuKZB.min.js → needle-engine.bundle-DiobwRVT.min.js} +146 -146
  8. package/dist/needle-engine.d.ts +29 -27
  9. package/dist/needle-engine.js +233 -233
  10. package/dist/needle-engine.min.js +1 -1
  11. package/dist/needle-engine.umd.cjs +1 -1
  12. package/lib/engine/api.d.ts +1 -1
  13. package/lib/engine/api.js +1 -1
  14. package/lib/engine/api.js.map +1 -1
  15. package/lib/engine/engine_context.js +3 -0
  16. package/lib/engine/engine_context.js.map +1 -1
  17. package/lib/engine/engine_init.js +2 -2
  18. package/lib/engine/engine_init.js.map +1 -1
  19. package/lib/engine/engine_license.d.ts +7 -7
  20. package/lib/engine/engine_license.js +74 -74
  21. package/lib/engine/engine_license.js.map +1 -1
  22. package/lib/engine/engine_loaders.gltf.d.ts +3 -1
  23. package/lib/engine/engine_loaders.gltf.js +6 -1
  24. package/lib/engine/engine_loaders.gltf.js.map +1 -1
  25. package/lib/engine/engine_networking_blob.js +3 -3
  26. package/lib/engine/engine_networking_blob.js.map +1 -1
  27. package/lib/engine/engine_physics.d.ts +2 -0
  28. package/lib/engine/engine_physics.js +23 -1
  29. package/lib/engine/engine_physics.js.map +1 -1
  30. package/lib/engine/engine_utils_qrcode.js +2 -2
  31. package/lib/engine/engine_utils_qrcode.js.map +1 -1
  32. package/lib/engine/webcomponents/needle menu/needle-menu-spatial.js +2 -2
  33. package/lib/engine/webcomponents/needle menu/needle-menu-spatial.js.map +1 -1
  34. package/lib/engine/webcomponents/needle menu/needle-menu.js +5 -5
  35. package/lib/engine/webcomponents/needle menu/needle-menu.js.map +1 -1
  36. package/lib/engine/webcomponents/needle-engine.js +2 -2
  37. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  38. package/lib/engine/webcomponents/needle-engine.loading.js +2 -2
  39. package/lib/engine/webcomponents/needle-engine.loading.js.map +1 -1
  40. package/lib/engine/xr/TempXRContext.js +2 -2
  41. package/lib/engine/xr/TempXRContext.js.map +1 -1
  42. package/lib/engine-components/export/usdz/USDZExporter.js +4 -4
  43. package/lib/engine-components/export/usdz/USDZExporter.js.map +1 -1
  44. package/package.json +2 -2
  45. package/plugins/common/license.js +4 -4
  46. package/plugins/vite/license.js +4 -4
  47. package/src/engine/api.ts +1 -1
  48. package/src/engine/engine_context.ts +3 -0
  49. package/src/engine/engine_init.ts +2 -2
  50. package/src/engine/engine_license.ts +71 -71
  51. package/src/engine/engine_loaders.gltf.ts +8 -2
  52. package/src/engine/engine_networking_blob.ts +3 -3
  53. package/src/engine/engine_physics.ts +22 -1
  54. package/src/engine/engine_utils_qrcode.ts +2 -2
  55. package/src/engine/webcomponents/needle menu/needle-menu-spatial.ts +2 -2
  56. package/src/engine/webcomponents/needle menu/needle-menu.ts +5 -5
  57. package/src/engine/webcomponents/needle-engine.loading.ts +6 -6
  58. package/src/engine/webcomponents/needle-engine.ts +2 -2
  59. package/src/engine/xr/TempXRContext.ts +2 -2
  60. package/src/engine-components/export/usdz/USDZExporter.ts +4 -4
  61. package/dist/gltf-progressive-BnLTsXZw.umd.cjs +0 -10
  62. package/dist/gltf-progressive-D6RT9IkB.min.js +0 -10
@@ -1,60 +1,66 @@
1
- import { RedFormat as je, RedIntegerFormat as He, RGFormat as Ke, RGIntegerFormat as Ye, RGBFormat as Qe, RGBAFormat as Je, RGBAIntegerFormat as Ze, BufferGeometry as K, Mesh as Y, Box3 as de, Vector3 as A, Sphere as $e, CompressedTexture as et, Texture as q, Matrix3 as tt, InterleavedBuffer as st, InterleavedBufferAttribute as rt, BufferAttribute as nt, TextureLoader as it, Matrix4 as Ge, THREE as ot, Color as Be } from "./three-core.js";
2
- import { DRACOLoader as at, KTX2Loader as lt, MeshoptDecoder as ut, GLTFLoader as _e } from "./three-examples.js";
3
- const ct = "";
4
- globalThis.GLTF_PROGRESSIVE_VERSION = ct;
1
+ import { RedFormat as He, RedIntegerFormat as Ke, RGFormat as Ye, RGIntegerFormat as Qe, RGBFormat as Je, RGBAFormat as Ze, RGBAIntegerFormat as et, BufferGeometry as K, Mesh as Y, Box3 as de, Vector3 as A, Sphere as Be, CompressedTexture as tt, Texture as q, Matrix3 as st, InterleavedBuffer as rt, InterleavedBufferAttribute as nt, BufferAttribute as it, TextureLoader as ot, Matrix4 as qe, THREE as at, Color as We } from "./three-core.js";
2
+ import { DRACOLoader as lt, KTX2Loader as ut, MeshoptDecoder as ct, GLTFLoader as _e } from "./three-examples.js";
3
+ const dt = "";
4
+ globalThis.GLTF_PROGRESSIVE_VERSION = dt;
5
5
  console.debug("[gltf-progressive] version -");
6
- let G = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", Q = "https://cdn.needle.tools/static/three/0.179.1/basis2/";
7
- const ft = G, dt = Q, qe = new URL(G + "draco_decoder.js");
8
- qe.searchParams.append("range", "true");
9
- fetch(qe, {
6
+ let B = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", Q = "https://cdn.needle.tools/static/three/0.179.1/basis2/";
7
+ const ft = B, ht = Q, Fe = new URL(B + "draco_decoder.js");
8
+ Fe.searchParams.append("range", "true");
9
+ fetch(Fe, {
10
10
  method: "GET",
11
11
  headers: {
12
12
  Range: "bytes=0-1"
13
13
  }
14
14
  }).catch((i) => {
15
- console.debug(`Failed to fetch remote Draco decoder from ${G} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), G === ft && gt("./include/draco/"), Q === dt && pt("./include/ktx2/");
15
+ console.debug(`Failed to fetch remote Draco decoder from ${B} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), B === ft && pt("./include/draco/"), Q === ht && mt("./include/ktx2/");
16
16
  }).finally(() => {
17
- Fe();
17
+ Oe && Te();
18
18
  });
19
- const ht = () => ({
20
- dracoDecoderPath: G,
19
+ const gt = () => ({
20
+ dracoDecoderPath: B,
21
21
  ktx2TranscoderPath: Q
22
22
  });
23
- function gt(i) {
24
- G = i, P && P[Le] != G ? (console.debug("Updating Draco decoder path to " + i), P[Le] = G, P.setDecoderPath(G), P.preload()) : console.debug("Setting Draco decoder path to " + i);
25
- }
26
23
  function pt(i) {
27
- Q = i, B && B.transcoderPath != Q ? (console.debug("Updating KTX2 transcoder path to " + i), B.setTranscoderPath(Q), B.init()) : console.debug("Setting KTX2 transcoder path to " + i);
24
+ B = i, P && P[Le] != B ? (console.debug("Updating Draco decoder path to " + i), P[Le] = B, P.setDecoderPath(B), P.preload()) : console.debug("Setting Draco decoder path to " + i);
25
+ }
26
+ function mt(i) {
27
+ Q = i, G && G.transcoderPath != Q ? (console.debug("Updating KTX2 transcoder path to " + i), G.setTranscoderPath(Q), G.init()) : console.debug("Setting KTX2 transcoder path to " + i);
28
28
  }
29
29
  function be(i) {
30
- return Fe(), i ? B.detectSupport(i) : i !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: P, ktx2Loader: B, meshoptDecoder: ce };
30
+ Oe = !0;
31
+ const t = Te();
32
+ return i ? t.ktx2Loader.detectSupport(i) : i !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), t;
31
33
  }
32
- function We(i) {
33
- i.dracoLoader || i.setDRACOLoader(P), i.ktx2Loader || i.setKTX2Loader(B), i.meshoptDecoder || i.setMeshoptDecoder(ce);
34
+ function Jt() {
35
+ Oe = !1, P?.dispose(), G?.dispose(), P = void 0, G = void 0;
36
+ }
37
+ function Ue(i) {
38
+ const { dracoLoader: t, ktx2Loader: e, meshoptDecoder: s } = Te();
39
+ i.dracoLoader || i.setDRACOLoader(t), i.ktx2Loader || i.setKTX2Loader(e), i.meshoptDecoder || i.setMeshoptDecoder(s);
34
40
  }
35
41
  const Le = /* @__PURE__ */ Symbol("dracoDecoderPath");
36
- let P, ce, B;
37
- function Fe() {
38
- P || (P = new at(), P[Le] = G, P.setDecoderPath(G), P.setDecoderConfig({ type: "js" }), P.preload()), B || (B = new lt(), B.setTranscoderPath(Q), B.init()), ce || (ce = ut);
42
+ let Oe = !0, P, fe, G;
43
+ function Te() {
44
+ return P || (P = new lt(), P[Le] = B, P.setDecoderPath(B), P.setDecoderConfig({ type: "js" }), P.preload()), G || (G = new ut(), G.setTranscoderPath(Q), G.init()), fe || (fe = ct), { dracoLoader: P, ktx2Loader: G, meshoptDecoder: fe };
39
45
  }
40
46
  const we = /* @__PURE__ */ new WeakMap();
41
- function Ue(i, t) {
47
+ function ze(i, t) {
42
48
  let e = we.get(i);
43
49
  e ? e = Object.assign(e, t) : e = t, we.set(i, e);
44
50
  }
45
- const mt = _e.prototype.load;
46
- function yt(...i) {
51
+ const yt = _e.prototype.load;
52
+ function xt(...i) {
47
53
  const t = we.get(this);
48
54
  let e = i[0];
49
- const s = xt(e);
55
+ const s = Lt(e);
50
56
  if (s?.hostname.endsWith("needle.tools")) {
51
57
  const n = t?.progressive !== void 0 ? t.progressive : !0, o = t?.usecase ? t.usecase : "default";
52
58
  n ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${o}` : this.requestHeader.Accept = `*/*;usecase=${o}`, e = s.toString();
53
59
  }
54
- return i[0] = e, mt?.call(this, ...i);
60
+ return i[0] = e, yt?.call(this, ...i);
55
61
  }
56
- _e.prototype.load = yt;
57
- function xt(i) {
62
+ _e.prototype.load = xt;
63
+ function Lt(i) {
58
64
  try {
59
65
  if (i instanceof URL)
60
66
  return i;
@@ -64,19 +70,19 @@ function xt(i) {
64
70
  return null;
65
71
  }
66
72
  }
67
- function Se(i) {
73
+ function Pe(i) {
68
74
  return i != null && i.data != null;
69
75
  }
70
76
  function De(i) {
71
77
  const t = i.source?.data;
72
78
  return t != null && typeof t == "object" ? t : null;
73
79
  }
74
- function Lt(i) {
80
+ function wt(i) {
75
81
  const t = i.image;
76
82
  return t != null && typeof t == "object" ? t : null;
77
83
  }
78
84
  function ve(i) {
79
- const t = Lt(i), e = De(i);
85
+ const t = wt(i), e = De(i);
80
86
  return {
81
87
  width: t?.width || e?.width || 0,
82
88
  height: t?.height || e?.height || 0
@@ -89,7 +95,7 @@ function V(i) {
89
95
  const s = new URL(t).searchParams.get(i);
90
96
  return s == null || s === "0" || s === "false" ? !1 : s === "" ? !0 : s;
91
97
  }
92
- function wt(i, t) {
98
+ function Dt(i, t) {
93
99
  if (t === void 0 || i === void 0 || t.startsWith("./") || t.startsWith("http") || t.startsWith("data:") || t.startsWith("blob:"))
94
100
  return t;
95
101
  const e = i.lastIndexOf("/");
@@ -100,19 +106,19 @@ function wt(i, t) {
100
106
  }
101
107
  return t;
102
108
  }
103
- function Oe() {
109
+ function Se() {
104
110
  if (se !== void 0) return se;
105
111
  const i = globalThis.navigator?.userAgent || "";
106
112
  return se = /iPhone|iPad|iPod|Android|IEMobile/i.test(i), V("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", se), se;
107
113
  }
108
114
  let se;
109
- function ze() {
115
+ function Ee() {
110
116
  const i = globalThis.location?.href;
111
117
  if (!i) return !1;
112
118
  const t = new URL(i), e = t.hostname === "localhost" || /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(t.hostname);
113
119
  return t.hostname === "127.0.0.1" || e;
114
120
  }
115
- class Dt {
121
+ class vt {
116
122
  constructor(t, e = {}) {
117
123
  this.maxConcurrent = t, this.debug = e.debug ?? !1, typeof globalThis.requestAnimationFrame == "function" ? globalThis.requestAnimationFrame(this.tick) : setTimeout(this.tick, 0);
118
124
  }
@@ -146,29 +152,29 @@ class Dt {
146
152
  }
147
153
  }
148
154
  }
149
- function vt(i) {
150
- const t = i.image, e = t?.width ?? 0, s = t?.height ?? 0, r = t?.depth ?? 1, n = Math.floor(Math.log2(Math.max(e, s, r))) + 1, o = Mt(i);
155
+ function Mt(i) {
156
+ const t = i.image, e = t?.width ?? 0, s = t?.height ?? 0, r = t?.depth ?? 1, n = Math.floor(Math.log2(Math.max(e, s, r))) + 1, o = _t(i);
151
157
  return e * s * r * o * (1 - Math.pow(0.25, n)) / (1 - 0.25);
152
158
  }
153
- function Mt(i) {
159
+ function _t(i) {
154
160
  let t = 4;
155
161
  const e = i.format;
156
- e === je || e === He ? t = 1 : e === Ke || e === Ye ? t = 2 : e === Qe || e === 1029 ? t = 3 : (e === Je || e === Ze) && (t = 4);
162
+ e === He || e === Ke ? t = 1 : e === Ye || e === Qe ? t = 2 : e === Je || e === 1029 ? t = 3 : (e === Ze || e === et) && (t = 4);
157
163
  let s = 1;
158
164
  const r = i.type;
159
165
  return r === 1009 || r === 1010 ? s = 1 : r === 1011 || r === 1012 ? s = 2 : r === 1013 || r === 1014 || r === 1015 ? s = 4 : r === 1016 && (s = 2), t * s;
160
166
  }
161
- const _t = typeof window > "u" && typeof document > "u", Me = /* @__PURE__ */ Symbol("needle:raycast-mesh");
167
+ const bt = typeof window > "u" && typeof document > "u", Me = /* @__PURE__ */ Symbol("needle:raycast-mesh");
162
168
  function ae(i) {
163
169
  return i?.[Me] instanceof K ? i[Me] : null;
164
170
  }
165
- function bt(i, t) {
171
+ function Ot(i, t) {
166
172
  if ((i.type === "Mesh" || i.type === "SkinnedMesh") && !ae(i)) {
167
- const s = Tt(t);
173
+ const s = St(t);
168
174
  s.userData = { isRaycastMesh: !0 }, i[Me] = s;
169
175
  }
170
176
  }
171
- function Ot(i = !0) {
177
+ function Tt(i = !0) {
172
178
  if (i) {
173
179
  if (re) return;
174
180
  const t = re = Y.prototype.raycast;
@@ -183,7 +189,7 @@ function Ot(i = !0) {
183
189
  }
184
190
  }
185
191
  let re = null;
186
- function Tt(i) {
192
+ function St(i) {
187
193
  const t = new K();
188
194
  for (const e in i.attributes)
189
195
  t.setAttribute(e, i.getAttribute(e));
@@ -202,27 +208,27 @@ if (g && typeof window < "u") {
202
208
  !isNaN(s) && s >= 0 && (j = s, console.log(`Set LOD level to [${j}]`));
203
209
  });
204
210
  }
205
- function Ee(i) {
211
+ function Ne(i) {
206
212
  if (g && oe !== void 0)
207
213
  if (Array.isArray(i))
208
214
  for (const t of i)
209
- Ee(t);
215
+ Ne(t);
210
216
  else i && "wireframe" in i && (i.wireframe = oe === !0);
211
217
  }
212
218
  const ne = new Array();
213
- let St = 0;
214
- const Rt = Oe() ? 2 : 10;
215
- function Pt(i) {
216
- if (ne.length < Rt) {
219
+ let Rt = 0;
220
+ const Pt = Se() ? 2 : 10;
221
+ function Ct(i) {
222
+ if (ne.length < Pt) {
217
223
  const s = ne.length;
218
224
  g && console.warn(`[Worker] Creating new worker #${s}`);
219
- const r = Te.createWorker(i || {});
225
+ const r = Re.createWorker(i || {});
220
226
  return ne.push(r), r;
221
227
  }
222
- const t = St++ % ne.length;
228
+ const t = Rt++ % ne.length;
223
229
  return ne[t];
224
230
  }
225
- class Te {
231
+ class Re {
226
232
  constructor(t, e) {
227
233
  this.worker = t, this._debug = e.debug ?? !1, t.onmessage = (s) => {
228
234
  const r = s.data;
@@ -230,7 +236,7 @@ class Te {
230
236
  case "loaded-gltf":
231
237
  for (const n of this._running)
232
238
  if (n.url === r.result.url) {
233
- Ct(r.result), n.resolve(r.result);
239
+ kt(r.result), n.resolve(r.result);
234
240
  const o = n.url;
235
241
  o.startsWith("blob:") && URL.revokeObjectURL(o);
236
242
  }
@@ -245,15 +251,15 @@ class Te {
245
251
  const e = /* new-worker */ new Worker(URL.createObjectURL(new Blob(["import '" + `${new URL('./gltf-progressive.worker-BqODMeeW.js', import.meta.url).toString()}` + "';"], { type: 'text/javascript' })), {
246
252
  type: "module"
247
253
  });
248
- return new Te(e, t);
254
+ return new Re(e, t);
249
255
  }
250
256
  _running = [];
251
257
  _webglRenderer = null;
252
258
  async load(t, e) {
253
- const s = ht();
259
+ const s = gt();
254
260
  let r = e?.renderer;
255
261
  r || (this._webglRenderer ??= (async () => {
256
- const { WebGLRenderer: u } = await import("./three-core.js").then((d) => d.THREE);
262
+ const { WebGLRenderer: u } = await import("./three-core.js").then((f) => f.THREE);
257
263
  return new u();
258
264
  })(), r = await this._webglRenderer);
259
265
  const l = be(r).ktx2Loader.workerConfig;
@@ -281,7 +287,7 @@ class Te {
281
287
  }
282
288
  _debug = !1;
283
289
  }
284
- function Ct(i) {
290
+ function kt(i) {
285
291
  for (const t of i.geometries) {
286
292
  const e = t.geometry, s = new K();
287
293
  if (s.name = e.name || "", e.index) {
@@ -305,7 +311,7 @@ function Ct(i) {
305
311
  e.boundingBox?.max.x,
306
312
  e.boundingBox?.max.y,
307
313
  e.boundingBox?.max.z
308
- ), s.boundingSphere = new $e(
314
+ ), s.boundingSphere = new Be(
309
315
  new A(
310
316
  e.boundingSphere?.center.x,
311
317
  e.boundingSphere?.center.y,
@@ -322,7 +328,7 @@ function Ct(i) {
322
328
  let s = null;
323
329
  if (e.isCompressedTexture) {
324
330
  const r = e.mipmaps, { width: n, height: o } = ve(e);
325
- s = new et(
331
+ s = new tt(
326
332
  r,
327
333
  n,
328
334
  o,
@@ -348,7 +354,7 @@ function Ct(i) {
348
354
  e.type,
349
355
  e.anisotropy,
350
356
  e.colorSpace
351
- ), s.mipmaps = e.mipmaps, s.channel = e.channel, s.source.data = e.source.data, s.flipY = e.flipY, s.premultiplyAlpha = e.premultiplyAlpha, s.unpackAlignment = e.unpackAlignment, s.matrix = new tt(...e.matrix.elements);
357
+ ), s.mipmaps = e.mipmaps, s.channel = e.channel, s.source.data = e.source.data, s.flipY = e.flipY, s.premultiplyAlpha = e.premultiplyAlpha, s.unpackAlignment = e.unpackAlignment, s.matrix = new st(...e.matrix.elements);
352
358
  if (!s) {
353
359
  console.error("[Worker] Failed to create new texture from received data. Texture is not a CompressedTexture or Texture.");
354
360
  continue;
@@ -360,12 +366,12 @@ function Ct(i) {
360
366
  function he(i) {
361
367
  let t = i;
362
368
  if ("isInterleavedBufferAttribute" in i && i.isInterleavedBufferAttribute) {
363
- const e = i.data, s = e.array, r = new st(s, e.stride);
364
- t = new rt(r, i.itemSize, s.byteOffset, i.normalized), t.offset = i.offset;
365
- } else "isBufferAttribute" in i && i.isBufferAttribute && (t = new nt(i.array, i.itemSize, i.normalized), t.usage = i.usage, t.gpuType = i.gpuType, t.updateRanges = i.updateRanges);
369
+ const e = i.data, s = e.array, r = new rt(s, e.stride);
370
+ t = new nt(r, i.itemSize, s.byteOffset, i.normalized), t.offset = i.offset;
371
+ } else "isBufferAttribute" in i && i.isBufferAttribute && (t = new it(i.array, i.itemSize, i.normalized), t.usage = i.usage, t.gpuType = i.gpuType, t.updateRanges = i.updateRanges);
366
372
  return t;
367
373
  }
368
- const kt = V("gltf-progressive-worker");
374
+ const At = V("gltf-progressive-worker");
369
375
  V("gltf-progressive-reduce-mipmaps");
370
376
  const ie = V("gltf-progressive-gc"), ge = /* @__PURE__ */ Symbol("needle-progressive-texture"), U = "NEEDLE_progressive";
371
377
  class p {
@@ -434,12 +440,12 @@ class p {
434
440
  function o(l, a) {
435
441
  const u = s.getAssignedLODInformation(l);
436
442
  if (u) {
437
- const d = s.lodInfos.get(u.key);
438
- if (d && d.lods) {
439
- a.min_count = Math.min(a.min_count, d.lods.length), a.max_count = Math.max(a.max_count, d.lods.length);
440
- for (let c = 0; c < d.lods.length; c++) {
441
- const f = d.lods[c];
442
- f.width && (a.lods[c] = a.lods[c] || { min_height: 1 / 0, max_height: 0 }, a.lods[c].min_height = Math.min(a.lods[c].min_height, f.height), a.lods[c].max_height = Math.max(a.lods[c].max_height, f.height));
443
+ const f = s.lodInfos.get(u.key);
444
+ if (f && f.lods) {
445
+ a.min_count = Math.min(a.min_count, f.lods.length), a.max_count = Math.max(a.max_count, f.lods.length);
446
+ for (let c = 0; c < f.lods.length; c++) {
447
+ const d = f.lods[c];
448
+ d.width && (a.lods[c] = a.lods[c] || { min_height: 1 / 0, max_height: 0 }, a.lods[c].min_height = Math.min(a.lods[c].min_height, d.height), a.lods[c].max_height = Math.max(a.lods[c].max_height, d.height));
443
449
  }
444
450
  }
445
451
  }
@@ -539,9 +545,9 @@ class p {
539
545
  if (this.trackCurrentMaterialTextureSlots(n), n.uniforms && (n.isRawShaderMaterial || n.isShaderMaterial === !0)) {
540
546
  const a = n;
541
547
  for (const u of Object.keys(a.uniforms)) {
542
- const d = a.uniforms[u].value;
543
- if (d?.isTexture === !0) {
544
- const c = this.assignTextureLODForSlot(d, e, n, u, r).then((f) => (f && a.uniforms[u].value != f && (a.uniforms[u].value = f, a.uniformsNeedUpdate = !0), f));
548
+ const f = a.uniforms[u].value;
549
+ if (f?.isTexture === !0) {
550
+ const c = this.assignTextureLODForSlot(f, e, n, u, r).then((d) => (d && a.uniforms[u].value != d && (a.uniforms[u].value = d, a.uniformsNeedUpdate = !0), d));
545
551
  o.push(c), l.push(u);
546
552
  }
547
553
  }
@@ -549,15 +555,15 @@ class p {
549
555
  for (const a of Object.keys(n)) {
550
556
  const u = n[a];
551
557
  if (u?.isTexture === !0) {
552
- const d = this.assignTextureLODForSlot(u, e, n, a, r);
553
- o.push(d), l.push(a);
558
+ const f = this.assignTextureLODForSlot(u, e, n, a, r);
559
+ o.push(f), l.push(a);
554
560
  }
555
561
  }
556
562
  return Promise.all(o).then((a) => {
557
563
  const u = new Array();
558
- for (let d = 0; d < a.length; d++) {
559
- const c = a[d], f = l[d];
560
- c && c.isTexture === !0 ? u.push({ material: n, slot: f, texture: c, level: e }) : u.push({ material: n, slot: f, texture: null, level: e });
564
+ for (let f = 0; f < a.length; f++) {
565
+ const c = a[f], d = l[f];
566
+ c && c.isTexture === !0 ? u.push({ material: n, slot: d, texture: c, level: e }) : u.push({ material: n, slot: d, texture: null, level: e });
561
567
  }
562
568
  return u;
563
569
  });
@@ -592,7 +598,7 @@ class p {
592
598
  if (c && c.level === e && c.force === n)
593
599
  return c.promise;
594
600
  }
595
- const l = s && r ? this.nextTextureSlotRequestId(s, r, e, n) : 0, a = () => !s || !r || this.getLatestTextureSlotRequest(s, r)?.id === l, u = () => a() || this.shouldApplyStaleTextureSlotLOD(s, r, e, n), d = p.getOrLoadLOD(t, e, {
601
+ const l = s && r ? this.nextTextureSlotRequestId(s, r, e, n) : 0, a = () => !s || !r || this.getLatestTextureSlotRequest(s, r)?.id === l, u = () => a() || this.shouldApplyStaleTextureSlotLOD(s, r, e, n), f = p.getOrLoadLOD(t, e, {
596
602
  isCurrent: u
597
603
  }).then((c) => {
598
604
  if (!a() && !this.shouldApplyStaleTextureSlotLOD(s, r, e, n)) return null;
@@ -600,11 +606,11 @@ class p {
600
606
  return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen..."), null;
601
607
  if (c?.isTexture === !0) {
602
608
  if (c != t && s && r) {
603
- const f = this.getMaterialTextureSlot(s, r) ?? t;
604
- if (f && !n) {
605
- const h = this.getAssignedLODInformation(f);
609
+ const d = this.getMaterialTextureSlot(s, r) ?? t;
610
+ if (d && !n) {
611
+ const h = this.getAssignedLODInformation(d);
606
612
  if (h && h?.level < e)
607
- return g === "verbose" && console.warn("Assigned texture level is already higher: ", h.level, e, s, f, c), null;
613
+ return g === "verbose" && console.warn("Assigned texture level is already higher: ", h.level, e, s, d, c), null;
608
614
  }
609
615
  this.assignTrackedTextureSlot(s, r, c);
610
616
  }
@@ -612,7 +618,7 @@ class p {
612
618
  } else g == "verbose" && console.warn("No LOD found for", t, e);
613
619
  return null;
614
620
  }).catch((c) => (console.error("Error loading LOD", t, c), null));
615
- return s && r && this.setPendingTextureSlotRequest(s, r, e, n, l, d), d;
621
+ return s && r && this.setPendingTextureSlotRequest(s, r, e, n, l, f), f;
616
622
  }
617
623
  // Track material slots, not just texture objects. A shared fallback texture can be
618
624
  // referenced by many slots and should only be disposed after every slot moved away.
@@ -801,9 +807,9 @@ class p {
801
807
  }
802
808
  l.userData || (l.userData = {}), g && console.log("> Progressive: register mesh " + s.name, { index: n, uuid: s.uuid }, o, s), p.assignLODInformation(t, l, e, r, n), p.lodInfos.set(e, o);
803
809
  let u = p.lowresCache.get(e)?.deref();
804
- u ? u.push(s.geometry) : u = [s.geometry], p.lowresCache.set(e, new WeakRef(u)), r > 0 && !ae(s) && bt(s, l);
805
- for (const d of F)
806
- d.onRegisteredNewMesh?.(s, o);
810
+ u ? u.push(s.geometry) : u = [s.geometry], p.lowresCache.set(e, new WeakRef(u)), r > 0 && !ae(s) && Ot(s, l);
811
+ for (const f of F)
812
+ f.onRegisteredNewMesh?.(s, o);
807
813
  };
808
814
  /**
809
815
  * Dispose cached resources to free memory.
@@ -902,9 +908,9 @@ ${t}`), e instanceof WeakRef && (e.deref() || (p.cache.delete(t), (g || ie) && c
902
908
  return this.textureRefCounts.set(e, r), g === "verbose" && n("[gltf-progressive] Memory: Untrack texture", r), !1;
903
909
  function n(o, l) {
904
910
  let { width: a, height: u } = ve(t);
905
- const d = a && u ? `${a}x${u}` : "N/A";
911
+ const f = a && u ? `${a}x${u}` : "N/A";
906
912
  let c = "N/A";
907
- a && u && (c = `~${(vt(t) / (1024 * 1024)).toFixed(2)} MB`), console.log(`${o} — ${t.name} ${d} (${c}), refCount: ${s} → ${l}
913
+ a && u && (c = `~${(Mt(t) / (1024 * 1024)).toFixed(2)} MB`), console.log(`${o} — ${t.name} ${f} (${c}), refCount: ${s} → ${l}
908
914
  ${e}`);
909
915
  }
910
916
  }
@@ -919,16 +925,16 @@ ${e}`);
919
925
  const l = o?.key;
920
926
  let a;
921
927
  if (t.isTexture === !0) {
922
- const d = t;
923
- d.source && d.source[ge] && (a = d.source[ge]);
928
+ const f = t;
929
+ f.source && f.source[ge] && (a = f.source[ge]);
924
930
  }
925
931
  if (a || (a = p.lodInfos.get(l)), !a)
926
932
  g && console.warn(`Can not load LOD ${e}: no LOD info found for "${l}" ${t.name}`, t.type, p.lodInfos);
927
933
  else {
928
934
  if (e > 0) {
929
- let f = !1;
935
+ let d = !1;
930
936
  const h = Array.isArray(a.lods);
931
- if (h && e >= a.lods.length ? f = !0 : h || (f = !0), f) {
937
+ if (h && e >= a.lods.length ? d = !0 : h || (d = !0), d) {
932
938
  const v = this.lowresCache.get(l);
933
939
  if (v) {
934
940
  const L = v.deref();
@@ -938,14 +944,14 @@ ${e}`);
938
944
  return null;
939
945
  }
940
946
  }
941
- const d = Array.isArray(a.lods) ? a.lods[e]?.path : a.lods;
942
- if (!d)
947
+ const f = Array.isArray(a.lods) ? a.lods[e]?.path : a.lods;
948
+ if (!f)
943
949
  return g && !a["missing:uri"] && (a["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, a)), null;
944
- const c = wt(o.url, d);
950
+ const c = Dt(o.url, f);
945
951
  if (c.endsWith(".glb") || c.endsWith(".gltf")) {
946
952
  if (!a.guid)
947
953
  return console.warn("missing pointer for glb/gltf texture", a), null;
948
- const f = c + "_" + a.guid, h = await this.tryResolveLODCacheEntry(this.cache.get(f), f, c, t, e, n);
954
+ const d = c + "_" + a.guid, h = await this.tryResolveLODCacheEntry(this.cache.get(d), d, c, t, e, n);
949
955
  if (r !== this.cacheGeneration) return null;
950
956
  if (h.found) return h.value;
951
957
  if (s?.isCurrent?.() === !1)
@@ -954,20 +960,20 @@ ${e}`);
954
960
  if (r !== this.cacheGeneration) return null;
955
961
  if (s?.isCurrent?.() === !1)
956
962
  return n && console.log(`Skipping stale LOD ${e} request after queue: ${c}`), null;
957
- const L = await this.tryResolveLODCacheEntry(this.cache.get(f), f, c, t, e, n);
963
+ const L = await this.tryResolveLODCacheEntry(this.cache.get(d), d, c, t, e, n);
958
964
  if (r !== this.cacheGeneration) return null;
959
965
  if (L.found) return L.value;
960
- const x = this.cache.get(f);
966
+ const x = this.cache.get(d);
961
967
  if (x !== void 0) {
962
- const y = await this.tryResolveLODCacheEntry(x, f, c, t, e, n);
968
+ const y = await this.tryResolveLODCacheEntry(x, d, c, t, e, n);
963
969
  if (r !== this.cacheGeneration) return null;
964
970
  if (y.found) return y.value;
965
971
  }
966
972
  if (!v.use)
967
973
  return g && console.log(`LOD ${e} was aborted: ${c}`), null;
968
974
  const w = a, M = new Promise(async (y, T) => {
969
- if (kt) {
970
- const m = await (await Pt({})).load(c);
975
+ if (At) {
976
+ const m = await (await Ct({})).load(c);
971
977
  if (m.textures.length > 0)
972
978
  for (const D of m.textures) {
973
979
  let S = D.texture;
@@ -984,7 +990,7 @@ ${e}`);
984
990
  return y(null);
985
991
  }
986
992
  const I = new _e();
987
- We(I), g && (await new Promise((b) => setTimeout(b, 1e3)), n && console.warn("Start loading (delayed) " + c, w.guid));
993
+ Ue(I), g && (await new Promise((b) => setTimeout(b, 1e3)), n && console.warn("Start loading (delayed) " + c, w.guid));
988
994
  let C = c;
989
995
  if (w && Array.isArray(w.lods)) {
990
996
  const b = w.lods[e];
@@ -1011,7 +1017,7 @@ ${e}`);
1011
1017
  }
1012
1018
  if (b) {
1013
1019
  let m = await z.getDependency("texture", k);
1014
- return m && p.assignLODInformation(o.url, m, l, e, void 0), n && console.log('change "' + t.name + '" → "' + m.name + '"', c, k, m, f), t instanceof q && (m = this.copySettings(t, m)), m && (m.guid = w.guid), y(m);
1020
+ return m && p.assignLODInformation(o.url, m, l, e, void 0), n && console.log('change "' + t.name + '" → "' + m.name + '"', c, k, m, d), t instanceof q && (m = this.copySettings(t, m)), m && (m.guid = w.guid), y(m);
1015
1021
  } else g && console.warn("Could not find texture with guid", w.guid, _.parser.json);
1016
1022
  }
1017
1023
  if (k = 0, _.parser.json.meshes) {
@@ -1028,7 +1034,7 @@ ${e}`);
1028
1034
  }
1029
1035
  if (b) {
1030
1036
  const m = await z.getDependency("mesh", k);
1031
- if (n && console.log(`Loaded Mesh "${m.name}"`, c, k, m, f), m.isMesh === !0) {
1037
+ if (n && console.log(`Loaded Mesh "${m.name}"`, c, k, m, d), m.isMesh === !0) {
1032
1038
  const D = m.geometry;
1033
1039
  return p.assignLODInformation(o.url, D, l, e, 0), y(D);
1034
1040
  } else {
@@ -1046,14 +1052,14 @@ ${e}`);
1046
1052
  }
1047
1053
  return y(null);
1048
1054
  });
1049
- this.cache.set(f, M), v.use(M);
1055
+ this.cache.set(d, M), v.use(M);
1050
1056
  const O = await M;
1051
- return r !== this.cacheGeneration || this.cache.get(f) !== M ? null : (O != null ? O instanceof q ? (this.cache.set(f, new WeakRef(O)), p._resourceRegistry.register(O, f)) : Array.isArray(O) ? this.cache.set(f, Promise.resolve(O)) : this.cache.set(f, Promise.resolve(O)) : this.cache.set(f, Promise.resolve(null)), O);
1057
+ return r !== this.cacheGeneration || this.cache.get(d) !== M ? null : (O != null ? O instanceof q ? (this.cache.set(d, new WeakRef(O)), p._resourceRegistry.register(O, d)) : Array.isArray(O) ? this.cache.set(d, Promise.resolve(O)) : this.cache.set(d, Promise.resolve(O)) : this.cache.set(d, Promise.resolve(null)), O);
1052
1058
  } else if (t instanceof q) {
1053
1059
  if (s?.isCurrent?.() === !1)
1054
1060
  return n && console.log(`Skipping stale texture LOD ${e} request: ${c}`), null;
1055
1061
  n && console.log("Load texture from uri: " + c);
1056
- const h = await new it().loadAsync(c);
1062
+ const h = await new ot().loadAsync(c);
1057
1063
  return r !== this.cacheGeneration || s?.isCurrent?.() === !1 ? (h?.dispose(), null) : (h ? (h.guid = a.guid, h.flipY = !1, h.needsUpdate = !0, h.colorSpace = t.colorSpace, n && console.log(a, h)) : g && console.warn("failed loading", c), h);
1058
1064
  }
1059
1065
  }
@@ -1065,9 +1071,9 @@ ${e}`);
1065
1071
  if (o && console.log(`LOD ${n} was already loading/loaded: ${e}`), t instanceof WeakRef) {
1066
1072
  const u = t.deref();
1067
1073
  if (u) {
1068
- let d = u, c = !1;
1069
- if (d instanceof q && r instanceof q ? Se(d.image) || De(d) ? d = this.copySettings(r, d) : c = !0 : d instanceof K && r instanceof K && (d.attributes.position?.array || (c = !0)), !c)
1070
- return { found: !0, value: d };
1074
+ let f = u, c = !1;
1075
+ if (f instanceof q && r instanceof q ? Pe(f.image) || De(f) ? f = this.copySettings(r, f) : c = !0 : f instanceof K && r instanceof K && (f.attributes.position?.array || (c = !0)), !c)
1076
+ return { found: !0, value: f };
1071
1077
  }
1072
1078
  return this.cache.delete(e), g && console.log(`[gltf-progressive] Re-loading GC'd/disposed resource: ${e}`), { found: !1 };
1073
1079
  }
@@ -1075,16 +1081,16 @@ ${e}`);
1075
1081
  `, u), null));
1076
1082
  if (this.disposedRequests.has(t)) return { found: !0, value: null };
1077
1083
  let a = !1;
1078
- return l == null || (l instanceof q && r instanceof q ? Se(l.image) || De(l) ? l = this.copySettings(r, l) : (a = !0, this.cache.delete(e)) : l instanceof K && r instanceof K && (l.attributes.position?.array || (a = !0, this.cache.delete(e)))), a ? { found: !1 } : { found: !0, value: l };
1084
+ return l == null || (l instanceof q && r instanceof q ? Pe(l.image) || De(l) ? l = this.copySettings(r, l) : (a = !0, this.cache.delete(e)) : l instanceof K && r instanceof K && (l.attributes.position?.array || (a = !0, this.cache.delete(e)))), a ? { found: !1 } : { found: !0, value: l };
1079
1085
  }
1080
1086
  static _queue;
1081
1087
  static get queue() {
1082
- return this._queue ??= new Dt(Oe() ? 20 : 50, { debug: g != !1 });
1088
+ return this._queue ??= new vt(Se() ? 20 : 50, { debug: g != !1 });
1083
1089
  }
1084
1090
  static assignLODInformation(t, e, s, r, n) {
1085
1091
  if (!e) return;
1086
1092
  e.userData || (e.userData = {});
1087
- const o = new At(t, s, r, n);
1093
+ const o = new It(t, s, r, n);
1088
1094
  e.userData.LODS = o, "source" in e && typeof e.source == "object" && (e.source.LODS = o);
1089
1095
  }
1090
1096
  static getAssignedLODInformation(t) {
@@ -1097,7 +1103,7 @@ ${e}`);
1097
1103
  `, 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;
1098
1104
  }
1099
1105
  }
1100
- class At {
1106
+ class It {
1101
1107
  url;
1102
1108
  /** the key to lookup the LOD information */
1103
1109
  key;
@@ -1184,7 +1190,7 @@ class le {
1184
1190
  });
1185
1191
  }
1186
1192
  }
1187
- const $ = V("debugprogressive"), It = $ === "colors", $t = V("noprogressive"), pe = /* @__PURE__ */ Symbol("Needle:LODSManager"), me = /* @__PURE__ */ Symbol("Needle:LODState"), E = /* @__PURE__ */ Symbol("Needle:CurrentLOD"), Re = ot, R = { mesh_lod: -1, texture_lod: -1 }, Gt = new Be(), Pe = [
1193
+ const $ = V("debugprogressive"), $t = $ === "colors", Gt = V("noprogressive"), pe = /* @__PURE__ */ Symbol("Needle:LODSManager"), me = /* @__PURE__ */ Symbol("Needle:LODState"), E = /* @__PURE__ */ Symbol("Needle:CurrentLOD"), Ce = at, R = { mesh_lod: -1, texture_lod: -1 }, Bt = new We(), ke = [
1188
1194
  3526751,
1189
1195
  11065402,
1190
1196
  15978811,
@@ -1218,16 +1224,16 @@ const $ = V("debugprogressive"), It = $ === "colors", $t = V("noprogressive"), p
1218
1224
  5083278,
1219
1225
  5592405
1220
1226
  ];
1221
- function Bt() {
1222
- const i = Re.Timer || Re.Clock;
1227
+ function qt() {
1228
+ const i = Ce.Timer || Ce.Clock;
1223
1229
  return new i();
1224
1230
  }
1225
- const ye = new de(), N = new de(), Ce = new de(), qt = new A(), Wt = new A(), Ft = new Ge(), W = new A(), Z = new A(), ee = new A(), te = new A();
1226
- function Ut(i, t) {
1231
+ const ye = new de(), N = new de(), Ae = new de(), Wt = new A(), Ft = new A(), Ut = new qe(), W = new A(), Z = new A(), ee = new A(), te = new A();
1232
+ function zt(i, t) {
1227
1233
  const e = i.min, s = i.max, r = (e.x + s.x) * 0.5, n = (e.y + s.y) * 0.5;
1228
1234
  return W.set(r, n, e.z).applyMatrix4(t).z < 0;
1229
1235
  }
1230
- function zt(i) {
1236
+ function Et(i) {
1231
1237
  const {
1232
1238
  geometry: t,
1233
1239
  matrixWorld: e,
@@ -1238,18 +1244,18 @@ function zt(i) {
1238
1244
  currentLevel: l = -1,
1239
1245
  xrEnabled: a = !1,
1240
1246
  debugDrawLine: u,
1241
- warnMissingPrimitiveDensities: d = !1
1242
- } = i, c = p.getMeshLODExtension(t)?.lods, f = p.getPrimitiveIndex(t), h = i.target ?? {
1247
+ warnMissingPrimitiveDensities: f = !1
1248
+ } = i, c = p.getMeshLODExtension(t)?.lods, d = p.getPrimitiveIndex(t), h = i.target ?? {
1243
1249
  level: l,
1244
- primitiveIndex: f,
1250
+ primitiveIndex: d,
1245
1251
  screenCoverage: 0,
1246
1252
  screenspaceVolume: new A(),
1247
1253
  centrality: 1
1248
1254
  };
1249
- h.level = l, h.primitiveIndex = f, h.screenCoverage = 0, h.screenspaceVolume.set(0, 0, 0), h.centrality = 1;
1255
+ h.level = l, h.primitiveIndex = d, h.screenCoverage = 0, h.screenspaceVolume.set(0, 0, 0), h.centrality = 1;
1250
1256
  let v = i.boundingBox ?? t.boundingBox;
1251
1257
  if (v || (t.computeBoundingBox(), v = t.boundingBox), !v) return h;
1252
- if (ye.copy(v).applyMatrix4(e), s.isPerspectiveCamera && Ut(ye, r))
1258
+ if (ye.copy(v).applyMatrix4(e), s.isPerspectiveCamera && zt(ye, r))
1253
1259
  return h.level = 0, h.screenCoverage = 1 / 0, h.screenspaceVolume.set(1 / 0, 1 / 0, 1 / 0), h;
1254
1260
  if (N.copy(ye).applyMatrix4(r), a && s.isPerspectiveCamera && s.fov > 70) {
1255
1261
  const y = N.min, T = N.max;
@@ -1259,29 +1265,29 @@ function zt(i) {
1259
1265
  const S = I < 0 && _ > 0 ? 0 : Math.min(Math.abs(y.x), Math.abs(T.x)), X = C < 0 && z > 0 ? 0 : Math.min(Math.abs(y.y), Math.abs(T.y)), J = Math.max(S, X);
1260
1266
  h.centrality = (b - J) * (b - J) * (b - J);
1261
1267
  }
1262
- const L = N.getSize(qt);
1263
- L.multiplyScalar(0.5), globalThis.screen?.availHeight > 0 && o > 0 && L.multiplyScalar(o / globalThis.screen.availHeight), s.isPerspectiveCamera && (L.x *= s.aspect), Ce.copy(v).applyMatrix4(e).applyMatrix4(s.matrixWorldInverse);
1264
- const x = Ce.getSize(Wt), w = Math.max(L.x, L.y), M = Math.max(x.x, x.y);
1268
+ const L = N.getSize(Wt);
1269
+ L.multiplyScalar(0.5), globalThis.screen?.availHeight > 0 && o > 0 && L.multiplyScalar(o / globalThis.screen.availHeight), s.isPerspectiveCamera && (L.x *= s.aspect), Ae.copy(v).applyMatrix4(e).applyMatrix4(s.matrixWorldInverse);
1270
+ const x = Ae.getSize(Ft), w = Math.max(L.x, L.y), M = Math.max(x.x, x.y);
1265
1271
  w !== 0 && M !== 0 && (L.z = x.z / M * w);
1266
1272
  const O = Math.max(L.x, L.y, L.z) * h.centrality;
1267
1273
  if (h.screenCoverage = O, h.screenspaceVolume.copy(L), O <= 0) return h;
1268
1274
  if (u) {
1269
- const y = Ft.copy(r);
1275
+ const y = Ut.copy(r);
1270
1276
  y.invert(), W.copy(N.min), Z.copy(N.max), Z.x = W.x, ee.copy(N.max), ee.y = W.y, te.copy(N.max);
1271
1277
  const T = (W.z + te.z) * 0.5;
1272
1278
  W.z = Z.z = ee.z = te.z = T, W.applyMatrix4(y), Z.applyMatrix4(y), ee.applyMatrix4(y), te.applyMatrix4(y), u(W, Z, 255), u(W, ee, 255), u(Z, te, 255), u(ee, te, 255);
1273
1279
  }
1274
1280
  if (c?.length)
1275
1281
  for (let y = 0; y < c.length; y++) {
1276
- const T = c[y], I = T.densities?.[f] || T.density || 1e-5;
1277
- if (f > 0 && d && ze() && !T.densities && !globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] && (globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] = !0, console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")), I / O < n) {
1282
+ const T = c[y], I = T.densities?.[d] || T.density || 1e-5;
1283
+ if (d > 0 && f && Ee() && !T.densities && !globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] && (globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] = !0, console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")), I / O < n) {
1278
1284
  h.level = y;
1279
1285
  break;
1280
1286
  }
1281
1287
  }
1282
1288
  return h;
1283
1289
  }
1284
- let fe = class H {
1290
+ let ce = class H {
1285
1291
  /**
1286
1292
  * 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.
1287
1293
  */
@@ -1317,7 +1323,7 @@ let fe = class H {
1317
1323
  }
1318
1324
  renderer;
1319
1325
  context;
1320
- projectionScreenMatrix = new Ge();
1326
+ projectionScreenMatrix = new qe();
1321
1327
  /** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
1322
1328
  get plugins() {
1323
1329
  return F;
@@ -1390,7 +1396,7 @@ let fe = class H {
1390
1396
  const r = performance.now();
1391
1397
  return s.ready.finally(() => {
1392
1398
  const n = this._newPromiseGroups.indexOf(s);
1393
- n >= 0 && (this._newPromiseGroups.splice(n, 1), ze() && performance.measure("LODsManager:awaitLoading", {
1399
+ n >= 0 && (this._newPromiseGroups.splice(n, 1), Ee() && performance.measure("LODsManager:awaitLoading", {
1394
1400
  start: r,
1395
1401
  detail: { id: e, name: t?.name, awaited: s.awaitedCount, resolved: s.resolvedCount }
1396
1402
  }));
@@ -1450,7 +1456,7 @@ let fe = class H {
1450
1456
  #n = 0;
1451
1457
  #o = 0;
1452
1458
  #s = 0;
1453
- #i = Bt();
1459
+ #i = qt();
1454
1460
  _fpsBuffer = [60, 60, 60, 60, 60];
1455
1461
  /**
1456
1462
  * Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
@@ -1500,7 +1506,7 @@ let fe = class H {
1500
1506
  (l.name === "EffectMaterial" || l.name === "CopyShader") && (o = !1);
1501
1507
  }
1502
1508
  if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (o = !1), o) {
1503
- if ($t || (this.updateInterval === "auto" ? this.#s < 40 && this.#e < 10 ? (this.#e += 1, $ && console.warn("↓ Reducing LOD updates", this.#e, this.#s.toFixed(0))) : this.#s >= 60 && this.#e > 1 && (this.#e -= 1, $ && console.warn("↑ Increasing LOD updates", this.#e, this.#s.toFixed(0))) : this.#e = this.updateInterval, this.#e > 0 && this.#r % this.#e != 0))
1509
+ if (Gt || (this.updateInterval === "auto" ? this.#s < 40 && this.#e < 10 ? (this.#e += 1, $ && console.warn("↓ Reducing LOD updates", this.#e, this.#s.toFixed(0))) : this.#s >= 60 && this.#e > 1 && (this.#e -= 1, $ && console.warn("↑ Increasing LOD updates", this.#e, this.#s.toFixed(0))) : this.#e = this.updateInterval, this.#e > 0 && this.#r % this.#e != 0))
1504
1510
  return;
1505
1511
  this.internalUpdate(t, e), this._postprocessPromiseGroups();
1506
1512
  }
@@ -1565,12 +1571,12 @@ let fe = class H {
1565
1571
  updateLODs(t, e, s, r) {
1566
1572
  s.userData || (s.userData = {});
1567
1573
  let n = s[me];
1568
- if (n || (n = new Et(), s[me] = n), n.frames++ < 2)
1574
+ if (n || (n = new Nt(), s[me] = n), n.frames++ < 2)
1569
1575
  return;
1570
1576
  for (const l of F)
1571
1577
  l.onBeforeUpdateLOD?.(this.renderer, t, e, s);
1572
1578
  const o = this.overrideLodLevel !== void 0 ? this.overrideLodLevel : j;
1573
- o >= 0 ? (R.mesh_lod = o, R.texture_lod = o) : (this.calculateLodLevel(e, s, n, r, R), R.mesh_lod = Math.round(R.mesh_lod), R.texture_lod = Math.round(R.texture_lod)), R.mesh_lod >= 0 && this.loadProgressiveMeshes(s, R.mesh_lod), s.material && R.texture_lod >= 0 && this.loadProgressiveTextures(s.material, R.texture_lod, o), g && s.material && !s.isGizmo && Ee(s.material), It && s.material && !s.isGizmo && !s.isBatchedMesh && Ne(s.material, R.mesh_lod);
1579
+ o >= 0 ? (R.mesh_lod = o, R.texture_lod = o) : (this.calculateLodLevel(e, s, n, r, R), R.mesh_lod = Math.round(R.mesh_lod), R.texture_lod = Math.round(R.texture_lod)), R.mesh_lod >= 0 && this.loadProgressiveMeshes(s, R.mesh_lod), s.material && R.texture_lod >= 0 && this.loadProgressiveTextures(s.material, R.texture_lod, o), g && s.material && !s.isGizmo && Ne(s.material), $t && s.material && !s.isGizmo && !s.isBatchedMesh && Ve(s.material, R.mesh_lod);
1574
1580
  for (const l of F)
1575
1581
  l.onAfterUpdatedLOD?.(this.renderer, t, e, s, R);
1576
1582
  n.lastLodLevel_Mesh = R.mesh_lod, n.lastLodLevel_Texture = R.texture_lod;
@@ -1616,7 +1622,7 @@ let fe = class H {
1616
1622
  return Promise.resolve(null);
1617
1623
  }
1618
1624
  // private testIfLODLevelsAreAvailable() {
1619
- _sphere = new $e();
1625
+ _sphere = new Be();
1620
1626
  _tempWorldPosition = new A();
1621
1627
  static skinnedMeshBoundsFrameOffsetCounter = 0;
1622
1628
  static $skinnedMeshBoundsOffset = /* @__PURE__ */ Symbol("gltf-progressive-skinnedMeshBoundsOffset");
@@ -1633,7 +1639,7 @@ let fe = class H {
1633
1639
  let l = 10 + 1, a = !1;
1634
1640
  if ($ && e["DEBUG:LOD"] != null)
1635
1641
  return e["DEBUG:LOD"];
1636
- const u = p.getMeshLODExtension(e.geometry)?.lods, d = p.getPrimitiveIndex(e.geometry), c = u && u.length > 0, f = p.getMaterialMinMaxLODsCount(e.material), h = f.min_count !== 1 / 0 && f.min_count >= 0 && f.max_count >= 0;
1642
+ const u = p.getMeshLODExtension(e.geometry)?.lods, f = p.getPrimitiveIndex(e.geometry), c = u && u.length > 0, d = p.getMaterialMinMaxLODsCount(e.material), h = d.min_count !== 1 / 0 && d.min_count >= 0 && d.max_count >= 0;
1637
1643
  if (!c && !h) {
1638
1644
  n.mesh_lod = 0, n.texture_lod = 0;
1639
1645
  return;
@@ -1667,7 +1673,7 @@ let fe = class H {
1667
1673
  return;
1668
1674
  }
1669
1675
  }
1670
- const x = zt({
1676
+ const x = Et({
1671
1677
  geometry: e.geometry,
1672
1678
  matrixWorld: e.matrixWorld,
1673
1679
  camera: t,
@@ -1688,13 +1694,13 @@ let fe = class H {
1688
1694
  }
1689
1695
  if (a ? n.mesh_lod = l : n.mesh_lod = s.lastLodLevel_Mesh, $ && n.mesh_lod != s.lastLodLevel_Mesh) {
1690
1696
  const w = u?.[n.mesh_lod];
1691
- w && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${n.mesh_lod} (density: ${w.densities?.[d].toFixed(0)}) | ${e.name}`);
1697
+ w && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${n.mesh_lod} (density: ${w.densities?.[f].toFixed(0)}) | ${e.name}`);
1692
1698
  }
1693
1699
  if (h) {
1694
1700
  const x = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
1695
1701
  if (s.lastLodLevel_Texture < 0) {
1696
- if (n.texture_lod = f.max_count - 1, $) {
1697
- const w = f.lods[f.max_count - 1];
1702
+ if (n.texture_lod = d.max_count - 1, $) {
1703
+ const w = d.lods[d.max_count - 1];
1698
1704
  $ && console.log(`First Texture LOD ${n.texture_lod} (${w.max_height}px) - ${e.name}`);
1699
1705
  }
1700
1706
  } else {
@@ -1703,9 +1709,9 @@ let fe = class H {
1703
1709
  this.context?.engine === "model-viewer" && (M *= 1.5);
1704
1710
  const O = this.renderer.getPixelRatio?.() || globalThis.devicePixelRatio || 1, T = v / O * M;
1705
1711
  let I = !1;
1706
- for (let C = f.lods.length - 1; C >= 0; C--) {
1707
- const _ = f.lods[C];
1708
- if (!(x && _.max_height >= 2048) && !(Oe() && _.max_height > 4096) && (_.max_height > T || !I && C === 0)) {
1712
+ for (let C = d.lods.length - 1; C >= 0; C--) {
1713
+ const _ = d.lods[C];
1714
+ if (!(x && _.max_height >= 2048) && !(Se() && _.max_height > 4096) && (_.max_height > T || !I && C === 0)) {
1709
1715
  if (I = !0, n.texture_lod = C, $ && n.texture_lod < s.lastLodLevel_Texture) {
1710
1716
  const z = _.max_height;
1711
1717
  console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${n.texture_lod} = ${z}px
@@ -1720,7 +1726,7 @@ ${e.name}`);
1720
1726
  n.texture_lod = 0;
1721
1727
  }
1722
1728
  };
1723
- class Et {
1729
+ class Nt {
1724
1730
  frames = 0;
1725
1731
  lastLodLevel_Mesh = -1;
1726
1732
  lastLodLevel_Texture = -1;
@@ -1728,53 +1734,53 @@ class Et {
1728
1734
  lastScreenspaceVolume = new A();
1729
1735
  lastCentrality = 0;
1730
1736
  }
1731
- function Ne(i, t) {
1737
+ function Ve(i, t) {
1732
1738
  if (!(t < 0)) {
1733
1739
  if (Array.isArray(i)) {
1734
1740
  for (const e of i)
1735
- Ne(e, t);
1741
+ Ve(e, t);
1736
1742
  return;
1737
1743
  }
1738
- "color" in i && i.color instanceof Be && (i.color.copy(Nt(t, Gt)), i.needsUpdate = !0);
1744
+ "color" in i && i.color instanceof We && (i.color.copy(Vt(t, Bt)), i.needsUpdate = !0);
1739
1745
  }
1740
1746
  }
1741
- function Nt(i, t) {
1742
- const e = Math.max(0, Math.min(Pe.length - 1, Math.floor(i)));
1743
- return t.setHex(Pe[e]);
1747
+ function Vt(i, t) {
1748
+ const e = Math.max(0, Math.min(ke.length - 1, Math.floor(i)));
1749
+ return t.setHex(ke[e]);
1744
1750
  }
1745
- const ke = /* @__PURE__ */ Symbol("NEEDLE_mesh_lod"), ue = /* @__PURE__ */ Symbol("NEEDLE_texture_lod");
1751
+ const Ie = /* @__PURE__ */ Symbol("NEEDLE_mesh_lod"), ue = /* @__PURE__ */ Symbol("NEEDLE_texture_lod");
1746
1752
  let xe = null;
1747
- function Ve() {
1748
- const i = Vt();
1753
+ function Xe() {
1754
+ const i = Xt();
1749
1755
  i && (i.mapURLs(function(t) {
1750
- return Ae(), t;
1751
- }), Ae(), xe?.disconnect(), xe = new MutationObserver((t) => {
1756
+ return $e(), t;
1757
+ }), $e(), xe?.disconnect(), xe = new MutationObserver((t) => {
1752
1758
  t.forEach((e) => {
1753
1759
  e.addedNodes.forEach((s) => {
1754
- s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && Xe(s);
1760
+ s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && je(s);
1755
1761
  });
1756
1762
  });
1757
1763
  }), xe.observe(document, { childList: !0, subtree: !0 }));
1758
1764
  }
1759
- function Vt() {
1765
+ function Xt() {
1760
1766
  if (typeof customElements > "u") return null;
1761
1767
  const i = customElements.get("model-viewer");
1762
1768
  return i || (customElements.whenDefined("model-viewer").then(() => {
1763
- console.debug("[gltf-progressive] model-viewer defined"), Ve();
1769
+ console.debug("[gltf-progressive] model-viewer defined"), Xe();
1764
1770
  }), null);
1765
1771
  }
1766
- function Ae() {
1772
+ function $e() {
1767
1773
  if (typeof document > "u") return;
1768
1774
  document.querySelectorAll("model-viewer").forEach((t) => {
1769
- Xe(t);
1775
+ je(t);
1770
1776
  });
1771
1777
  }
1772
- const Ie = /* @__PURE__ */ new WeakSet();
1773
- let Xt = 0;
1774
- function Xe(i) {
1775
- if (!i || Ie.has(i))
1778
+ const Ge = /* @__PURE__ */ new WeakSet();
1779
+ let jt = 0;
1780
+ function je(i) {
1781
+ if (!i || Ge.has(i))
1776
1782
  return null;
1777
- Ie.add(i), console.debug("[gltf-progressive] found new model-viewer..." + ++Xt + `
1783
+ Ge.add(i), console.debug("[gltf-progressive] found new model-viewer..." + ++jt + `
1778
1784
  `, i.getAttribute("src"));
1779
1785
  let t = null, e = null, s = null;
1780
1786
  for (let r = i; r != null; r = Object.getPrototypeOf(r)) {
@@ -1795,8 +1801,8 @@ function Xe(i) {
1795
1801
  }
1796
1802
  };
1797
1803
  console.debug("[gltf-progressive] setup model-viewer");
1798
- const n = fe.get(t, { engine: "model-viewer" });
1799
- return fe.addPlugin(new jt()), n.enable(), n.addEventListener("changed", () => {
1804
+ const n = ce.get(t, { engine: "model-viewer" });
1805
+ return ce.addPlugin(new Ht()), n.enable(), n.addEventListener("changed", () => {
1800
1806
  s?.call(i);
1801
1807
  }), i.addEventListener("model-visibility", (o) => {
1802
1808
  o.detail.visible && s?.call(i);
@@ -1808,7 +1814,7 @@ function Xe(i) {
1808
1814
  }
1809
1815
  return null;
1810
1816
  }
1811
- class jt {
1817
+ class Ht {
1812
1818
  _didWarnAboutMissingUrl = !1;
1813
1819
  onBeforeUpdateLOD(t, e, s, r) {
1814
1820
  this.tryParseMeshLOD(e, r), this.tryParseTextureLOD(e, r);
@@ -1834,10 +1840,10 @@ class jt {
1834
1840
  if (a[ue] == !0) return;
1835
1841
  a[ue] = !0, a.userData && (a.userData.LOD = -1);
1836
1842
  const u = Object.keys(a);
1837
- for (let d = 0; d < u.length; d++) {
1838
- const c = u[d], f = a[c];
1839
- if (f?.isTexture === !0) {
1840
- const h = f.userData?.associations?.textures;
1843
+ for (let f = 0; f < u.length; f++) {
1844
+ const c = u[f], d = a[c];
1845
+ if (d?.isTexture === !0) {
1846
+ const h = d.userData?.associations?.textures;
1841
1847
  if (h == null) continue;
1842
1848
  const v = s.parser.json.textures[h];
1843
1849
  if (!v) {
@@ -1846,7 +1852,7 @@ class jt {
1846
1852
  }
1847
1853
  if (v?.extensions?.[U]) {
1848
1854
  const L = v.extensions[U];
1849
- L && n && p.registerTexture(n, f, L.lods.length, h, L);
1855
+ L && n && p.registerTexture(n, d, L.lods.length, h, L);
1850
1856
  }
1851
1857
  }
1852
1858
  }
@@ -1857,8 +1863,8 @@ class jt {
1857
1863
  }
1858
1864
  }
1859
1865
  tryParseMeshLOD(t, e) {
1860
- if (e[ke] == !0) return;
1861
- e[ke] = !0;
1866
+ if (e[Ie] == !0) return;
1867
+ e[Ie] = !0;
1862
1868
  const s = this.tryGetCurrentModelViewer(t), r = this.getUrl(s);
1863
1869
  if (!r)
1864
1870
  return;
@@ -1869,7 +1875,7 @@ class jt {
1869
1875
  }
1870
1876
  }
1871
1877
  }
1872
- function Ht(...i) {
1878
+ function Kt(...i) {
1873
1879
  let t, e, s, r;
1874
1880
  switch (i.length) {
1875
1881
  case 2:
@@ -1884,22 +1890,22 @@ function Ht(...i) {
1884
1890
  default:
1885
1891
  throw new Error("Invalid arguments");
1886
1892
  }
1887
- be(e), We(s), Ue(s, {
1893
+ be(e), Ue(s), ze(s, {
1888
1894
  progressive: !0,
1889
1895
  ...r?.hints
1890
1896
  }), s.register((o) => new p(o));
1891
- const n = fe.get(e);
1897
+ const n = ce.get(e);
1892
1898
  return r?.enableLODsManager !== !1 && n.enable(), n;
1893
1899
  }
1894
- Ve();
1895
- if (!_t) {
1900
+ Xe();
1901
+ if (!bt) {
1896
1902
  const i = {
1897
1903
  gltfProgressive: {
1898
- useNeedleProgressive: Ht,
1899
- LODsManager: fe,
1900
- configureLoader: Ue,
1904
+ useNeedleProgressive: Kt,
1905
+ LODsManager: ce,
1906
+ configureLoader: ze,
1901
1907
  getRaycastMesh: ae,
1902
- useRaycastMeshes: Ot
1908
+ useRaycastMeshes: Tt
1903
1909
  }
1904
1910
  };
1905
1911
  if (!globalThis.Needle)
@@ -1909,14 +1915,15 @@ if (!_t) {
1909
1915
  globalThis.Needle[t] = i[t];
1910
1916
  }
1911
1917
  export {
1912
- fe as LODsManager,
1918
+ ce as LODsManager,
1913
1919
  p as NEEDLE_progressive,
1914
- We as addDracoAndKTX2Loaders,
1915
- zt as calculateMeshLODLevel,
1916
- Ue as configureLoader,
1920
+ Ue as addDracoAndKTX2Loaders,
1921
+ Et as calculateMeshLODLevel,
1922
+ ze as configureLoader,
1917
1923
  be as createLoaders,
1918
- Nt as getLODColor,
1924
+ Jt as disposeLoaders,
1925
+ Vt as getLODColor,
1919
1926
  ae as getRaycastMesh,
1920
- gt as setDracoDecoderLocation,
1921
- pt as setKTX2TranscoderLocation
1927
+ pt as setDracoDecoderLocation,
1928
+ mt as setKTX2TranscoderLocation
1922
1929
  };