@needle-tools/engine 4.16.4-alpha → 4.16.4-beta

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 (27) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/dist/{gltf-progressive-LOFTyzy4.umd.cjs → gltf-progressive-BacJPTD6.umd.cjs} +8 -8
  3. package/dist/{gltf-progressive-DQa78GTA.min.js → gltf-progressive-BmXoz_HR.min.js} +8 -8
  4. package/dist/{gltf-progressive-_wvokUUu.js → gltf-progressive-CzxjNmG6.js} +116 -107
  5. package/dist/{needle-engine.bundle-LGUii273.js → needle-engine.bundle-5JsGk35A.js} +3113 -3074
  6. package/dist/{needle-engine.bundle-BQv3gp3d.umd.cjs → needle-engine.bundle-C8L0tAbe.umd.cjs} +114 -114
  7. package/dist/{needle-engine.bundle-C_iC-4wt.min.js → needle-engine.bundle-DISIqVWx.min.js} +125 -125
  8. package/dist/needle-engine.d.ts +15 -4
  9. package/dist/needle-engine.js +3 -3
  10. package/dist/needle-engine.min.js +1 -1
  11. package/dist/needle-engine.umd.cjs +1 -1
  12. package/dist/{postprocessing-C-WOZQC5.js → postprocessing-BUS23YkY.js} +2 -2
  13. package/dist/{postprocessing-CtXfLXvp.umd.cjs → postprocessing-C_736uMz.umd.cjs} +2 -2
  14. package/dist/{postprocessing-DXm8YKbQ.min.js → postprocessing-CaEfRjRY.min.js} +2 -2
  15. package/lib/engine/engine_lods.d.ts +9 -1
  16. package/lib/engine/engine_lods.js +9 -1
  17. package/lib/engine/engine_lods.js.map +1 -1
  18. package/lib/engine/engine_mainloop_utils.js +49 -60
  19. package/lib/engine/engine_mainloop_utils.js.map +1 -1
  20. package/lib/engine/webcomponents/needle-engine.d.ts +6 -2
  21. package/lib/engine/webcomponents/needle-engine.js +56 -41
  22. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  23. package/package.json +3 -2
  24. package/src/engine/engine_lods.ts +10 -2
  25. package/src/engine/engine_mainloop_utils.ts +54 -62
  26. package/src/engine/webcomponents/needle-engine.ts +62 -47
  27. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -1,4 +1,4 @@
1
- import { BufferGeometry as V, Mesh as X, Box3 as pe, Vector3 as A, Sphere as Se, CompressedTexture as Fe, Texture as F, Matrix3 as We, InterleavedBuffer as Ue, InterleavedBufferAttribute as ze, BufferAttribute as Ne, TextureLoader as qe, Matrix4 as Me, Clock as Ee, MeshStandardMaterial as Ve } from "./three.js";
1
+ import { BufferGeometry as V, Mesh as X, Box3 as pe, Vector3 as A, Sphere as Te, CompressedTexture as Fe, Texture as F, Matrix3 as We, InterleavedBuffer as Ue, InterleavedBufferAttribute as ze, BufferAttribute as qe, TextureLoader as Ne, Matrix4 as ve, Clock as Ee, MeshStandardMaterial as Ve } from "./three.js";
2
2
  import { DRACOLoader as Xe, KTX2Loader as je, MeshoptDecoder as Ke, GLTFLoader as we } from "./three-examples.js";
3
3
  const Ye = "";
4
4
  globalThis.GLTF_PROGRESSIVE_VERSION = Ye;
@@ -14,7 +14,7 @@ fetch(Pe, {
14
14
  }).catch((o) => {
15
15
  console.debug(`Failed to fetch remote Draco decoder from ${I} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), I === He && Ze("./include/draco/"), j === Qe && et("./include/ktx2/");
16
16
  }).finally(() => {
17
- Ce();
17
+ Ae();
18
18
  });
19
19
  const Je = () => ({
20
20
  dracoDecoderPath: I,
@@ -27,18 +27,18 @@ function et(o) {
27
27
  j = o, $ && $.transcoderPath != j ? (console.debug("Updating KTX2 transcoder path to " + o), $.setTranscoderPath(j), $.init()) : console.debug("Setting KTX2 transcoder path to " + o);
28
28
  }
29
29
  function Le(o) {
30
- return Ce(), o ? $.detectSupport(o) : o !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: C, ktx2Loader: $, meshoptDecoder: ne };
30
+ return Ae(), o ? $.detectSupport(o) : o !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: C, ktx2Loader: $, meshoptDecoder: ne };
31
31
  }
32
- function Te(o) {
32
+ function Ce(o) {
33
33
  o.dracoLoader || o.setDRACOLoader(C), o.ktx2Loader || o.setKTX2Loader($), o.meshoptDecoder || o.setMeshoptDecoder(ne);
34
34
  }
35
35
  const me = /* @__PURE__ */ Symbol("dracoDecoderPath");
36
36
  let C, ne, $;
37
- function Ce() {
37
+ function Ae() {
38
38
  C || (C = new Xe(), C[me] = I, C.setDecoderPath(I), C.setDecoderConfig({ type: "js" }), C.preload()), $ || ($ = new je(), $.setTranscoderPath(j), $.init()), ne || (ne = Ke);
39
39
  }
40
40
  const ye = /* @__PURE__ */ new WeakMap();
41
- function Ae(o, t) {
41
+ function ke(o, t) {
42
42
  let e = ye.get(o);
43
43
  e ? e = Object.assign(e, t) : e = t, ye.set(o, e);
44
44
  }
@@ -54,8 +54,8 @@ function st(...o) {
54
54
  return o[0] = e, tt?.call(this, ...o);
55
55
  }
56
56
  we.prototype.load = st;
57
- N("debugprogressive");
58
- function N(o) {
57
+ q("debugprogressive");
58
+ function q(o) {
59
59
  if (typeof window > "u") return !1;
60
60
  const e = new URL(window.location.href).searchParams.get(o);
61
61
  return e == null || e === "0" || e === "false" ? !1 : e === "" ? !0 : e;
@@ -71,17 +71,17 @@ function rt(o, t) {
71
71
  }
72
72
  return t;
73
73
  }
74
- function ke() {
75
- return H !== void 0 || (H = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), N("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", H)), H;
74
+ function _e() {
75
+ return H !== void 0 || (H = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), q("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", H)), H;
76
76
  }
77
77
  let H;
78
- function ve() {
78
+ function De() {
79
79
  if (typeof window > "u") return !1;
80
80
  const o = new URL(window.location.href), t = o.hostname === "localhost" || /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(o.hostname);
81
81
  return o.hostname === "127.0.0.1" || t;
82
82
  }
83
83
  class it {
84
- constructor(t = 100, e = {}) {
84
+ constructor(t, e = {}) {
85
85
  this.maxConcurrent = t, this.debug = e.debug ?? !1, window.requestAnimationFrame(this.tick);
86
86
  }
87
87
  _running = /* @__PURE__ */ new Map();
@@ -157,7 +157,7 @@ function ct(o) {
157
157
  t.setAttribute(e, o.getAttribute(e));
158
158
  return t.setIndex(o.getIndex()), t;
159
159
  }
160
- const z = new Array(), f = N("debugprogressive");
160
+ const z = new Array(), f = q("debugprogressive");
161
161
  let Z, E = -1;
162
162
  if (f) {
163
163
  let o = function() {
@@ -178,18 +178,18 @@ function Re(o) {
178
178
  }
179
179
  const J = new Array();
180
180
  let dt = 0;
181
- const ft = ke() ? 2 : 10;
181
+ const ft = _e() ? 2 : 10;
182
182
  function ht(o) {
183
183
  if (J.length < ft) {
184
184
  const s = J.length;
185
185
  f && console.warn(`[Worker] Creating new worker #${s}`);
186
- const r = _e.createWorker(o || {});
186
+ const r = Me.createWorker(o || {});
187
187
  return J.push(r), r;
188
188
  }
189
189
  const t = dt++ % J.length;
190
190
  return J[t];
191
191
  }
192
- class _e {
192
+ class Me {
193
193
  constructor(t, e) {
194
194
  this.worker = t, this._debug = e.debug ?? !1, t.onmessage = (s) => {
195
195
  const r = s.data;
@@ -212,7 +212,7 @@ class _e {
212
212
  const e = /* new-worker */ new Worker(URL.createObjectURL(new Blob(["import '" + `${new URL('./loader.worker-BqODMeeW.js', import.meta.url).toString()}` + "';"], { type: 'text/javascript' })), {
213
213
  type: "module"
214
214
  });
215
- return new _e(e, t);
215
+ return new Me(e, t);
216
216
  }
217
217
  _running = [];
218
218
  _webglRenderer = null;
@@ -265,7 +265,7 @@ function gt(o) {
265
265
  e.boundingBox?.max.x,
266
266
  e.boundingBox?.max.y,
267
267
  e.boundingBox?.max.z
268
- ), s.boundingSphere = new Se(
268
+ ), s.boundingSphere = new Te(
269
269
  new A(
270
270
  e.boundingSphere?.center.x,
271
271
  e.boundingSphere?.center.y,
@@ -322,13 +322,13 @@ function ue(o) {
322
322
  if ("isInterleavedBufferAttribute" in o && o.isInterleavedBufferAttribute) {
323
323
  const e = o.data, s = e.array, r = new Ue(s, e.stride);
324
324
  t = new ze(r, o.itemSize, s.byteOffset, o.normalized), t.offset = o.offset;
325
- } else "isBufferAttribute" in o && o.isBufferAttribute && (t = new Ne(o.array, o.itemSize, o.normalized), t.usage = o.usage, t.gpuType = o.gpuType, t.updateRanges = o.updateRanges);
325
+ } else "isBufferAttribute" in o && o.isBufferAttribute && (t = new qe(o.array, o.itemSize, o.normalized), t.usage = o.usage, t.gpuType = o.gpuType, t.updateRanges = o.updateRanges);
326
326
  return t;
327
327
  }
328
- const pt = N("gltf-progressive-worker");
329
- N("gltf-progressive-reduce-mipmaps");
330
- const K = N("gltf-progressive-gc"), ce = /* @__PURE__ */ Symbol("needle-progressive-texture"), W = "NEEDLE_progressive";
331
- class y {
328
+ const pt = q("gltf-progressive-worker");
329
+ q("gltf-progressive-reduce-mipmaps");
330
+ const K = q("gltf-progressive-gc"), ce = /* @__PURE__ */ Symbol("needle-progressive-texture"), W = "NEEDLE_progressive";
331
+ class m {
332
332
  /** The name of the extension */
333
333
  get name() {
334
334
  return W;
@@ -374,9 +374,9 @@ class y {
374
374
  const c = s.lodInfos.get(u.key);
375
375
  if (c && c.lods) {
376
376
  a.min_count = Math.min(a.min_count, c.lods.length), a.max_count = Math.max(a.max_count, c.lods.length);
377
- for (let m = 0; m < c.lods.length; m++) {
378
- const w = c.lods[m];
379
- w.width && (a.lods[m] = a.lods[m] || { min_height: 1 / 0, max_height: 0 }, a.lods[m].min_height = Math.min(a.lods[m].min_height, w.height), a.lods[m].max_height = Math.max(a.lods[m].max_height, w.height));
377
+ for (let y = 0; y < c.lods.length; y++) {
378
+ const w = c.lods[y];
379
+ w.width && (a.lods[y] = a.lods[y] || { min_height: 1 / 0, max_height: 0 }, a.lods[y].min_height = Math.min(a.lods[y].min_height, w.height), a.lods[y].max_height = Math.max(a.lods[y].max_height, w.height));
380
380
  }
381
381
  }
382
382
  }
@@ -436,7 +436,7 @@ class y {
436
436
  return Promise.resolve(null);
437
437
  for (const i of z)
438
438
  i.onBeforeGetLODMesh?.(t, e);
439
- return t["LOD:requested level"] = e, y.getOrLoadLOD(s, e).then((i) => {
439
+ return t["LOD:requested level"] = e, m.getOrLoadLOD(s, e).then((i) => {
440
440
  if (Array.isArray(i)) {
441
441
  const n = r.index || 0;
442
442
  i = i[n];
@@ -499,9 +499,19 @@ class y {
499
499
  }
500
500
  return Promise.resolve(null);
501
501
  }
502
+ /**
503
+ * Set the maximum number of concurrent loading tasks for LOD resources. This limits how many LOD resources (meshes or textures) can be loaded at the same time to prevent overloading the network or GPU. If the limit is reached, additional loading requests will be queued and processed as previous ones finish.
504
+ * @default 50 on desktop, 20 on mobile devices
505
+ */
506
+ static set maxConcurrentLoadingTasks(t) {
507
+ m.queue.maxConcurrent = t;
508
+ }
509
+ static get maxConcurrentLoadingTasks() {
510
+ return m.queue.maxConcurrent;
511
+ }
502
512
  // #region INTERNAL
503
513
  static assignTextureLODForSlot(t, e, s, r) {
504
- return t?.isTexture !== !0 ? Promise.resolve(null) : r === "glyphMap" ? Promise.resolve(t) : y.getOrLoadLOD(t, e).then((i) => {
514
+ return t?.isTexture !== !0 ? Promise.resolve(null) : r === "glyphMap" ? Promise.resolve(t) : m.getOrLoadLOD(t, e).then((i) => {
505
515
  if (Array.isArray(i))
506
516
  return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen..."), null;
507
517
  if (i?.isTexture === !0) {
@@ -533,7 +543,7 @@ class y {
533
543
  loadMesh = (t) => {
534
544
  if (this._isLoadingMesh) return null;
535
545
  const e = this.parser.json.meshes[t]?.extensions?.[W];
536
- return e ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", t).then((s) => (this._isLoadingMesh = !1, s && y.registerMesh(this.url, e.guid, s, e.lods?.length, 0, e), s))) : null;
546
+ return e ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", t).then((s) => (this._isLoadingMesh = !1, s && m.registerMesh(this.url, e.guid, s, e.lods?.length, 0, e), s))) : null;
537
547
  };
538
548
  // private _isLoadingTexture;
539
549
  // loadTexture = (textureIndex: number) => {
@@ -560,9 +570,9 @@ class y {
560
570
  }
561
571
  let i = !1;
562
572
  for (const n of this.parser.associations.keys())
563
- n.isTexture === !0 && this.parser.associations.get(n)?.textures === s && (i = !0, y.registerTexture(this.url, n, r.lods?.length, s, r));
573
+ n.isTexture === !0 && this.parser.associations.get(n)?.textures === s && (i = !0, m.registerTexture(this.url, n, r.lods?.length, s, r));
564
574
  i || this.parser.getDependency("texture", s).then((n) => {
565
- n && y.registerTexture(this.url, n, r.lods?.length, s, r);
575
+ n && m.registerTexture(this.url, n, r.lods?.length, s, r);
566
576
  });
567
577
  }
568
578
  }
@@ -573,7 +583,7 @@ class y {
573
583
  for (const i of this.parser.associations.keys())
574
584
  if (i.isMesh) {
575
585
  const n = this.parser.associations.get(i);
576
- n?.meshes === s && y.registerMesh(this.url, r.guid, i, r.lods.length, n.primitives, r);
586
+ n?.meshes === s && m.registerMesh(this.url, r.guid, i, r.lods.length, n.primitives, r);
577
587
  }
578
588
  }
579
589
  }
@@ -593,7 +603,7 @@ class y {
593
603
  }
594
604
  e.source && (e.source[ce] = i);
595
605
  const n = i.guid;
596
- y.assignLODInformation(t, e, n, s, r), y.lodInfos.set(n, i), y.lowresCache.set(n, new WeakRef(e));
606
+ m.assignLODInformation(t, e, n, s, r), m.lodInfos.set(n, i), m.lowresCache.set(n, new WeakRef(e));
597
607
  };
598
608
  /**
599
609
  * Register a mesh with LOD information
@@ -604,9 +614,9 @@ class y {
604
614
  f && console.warn("gltf-progressive: Register mesh without geometry");
605
615
  return;
606
616
  }
607
- l.userData || (l.userData = {}), f && console.log("> Progressive: register mesh " + s.name, { index: i, uuid: s.uuid }, n, s), y.assignLODInformation(t, l, e, r, i), y.lodInfos.set(e, n);
608
- let u = y.lowresCache.get(e)?.deref();
609
- u ? u.push(s.geometry) : u = [s.geometry], y.lowresCache.set(e, new WeakRef(u)), r > 0 && !ee(s) && lt(s, l);
617
+ l.userData || (l.userData = {}), f && console.log("> Progressive: register mesh " + s.name, { index: i, uuid: s.uuid }, n, s), m.assignLODInformation(t, l, e, r, i), m.lodInfos.set(e, n);
618
+ let u = m.lowresCache.get(e)?.deref();
619
+ u ? u.push(s.geometry) : u = [s.geometry], m.lowresCache.set(e, new WeakRef(u)), r > 0 && !ee(s) && lt(s, l);
610
620
  for (const c of z)
611
621
  c.onRegisteredNewMesh?.(s, n);
612
622
  };
@@ -681,9 +691,9 @@ class y {
681
691
  * The held value is the cache key string used in `previouslyLoaded`.
682
692
  */
683
693
  static _resourceRegistry = new FinalizationRegistry((t) => {
684
- const e = y.cache.get(t);
694
+ const e = m.cache.get(t);
685
695
  (f || K) && console.debug(`[gltf-progressive] Memory: Resource GC'd
686
- ${t}`), e instanceof WeakRef && (e.deref() || (y.cache.delete(t), (f || K) && console.log("[gltf-progressive] ↪ Cache entry deleted (GC)")));
696
+ ${t}`), e instanceof WeakRef && (e.deref() || (m.cache.delete(t), (f || K) && console.log("[gltf-progressive] ↪ Cache entry deleted (GC)")));
687
697
  });
688
698
  /**
689
699
  * Track texture usage by incrementing reference count
@@ -708,8 +718,8 @@ ${t}`), e instanceof WeakRef && (e.deref() || (y.cache.delete(t), (f || K) && co
708
718
  function i(n, l) {
709
719
  let a = t.image?.width || t.source?.data?.width || 0, u = t.image?.height || t.source?.data?.height || 0;
710
720
  const c = a && u ? `${a}x${u}` : "N/A";
711
- let m = "N/A";
712
- a && u && (m = `~${(nt(t) / (1024 * 1024)).toFixed(2)} MB`), console.log(`${n} — ${t.name} ${c} (${m}), refCount: ${s} → ${l}
721
+ let y = "N/A";
722
+ a && u && (y = `~${(nt(t) / (1024 * 1024)).toFixed(2)} MB`), console.log(`${n} — ${t.name} ${c} (${y}), refCount: ${s} → ${l}
713
723
  ${e}`);
714
724
  }
715
725
  }
@@ -725,13 +735,13 @@ ${e}`);
725
735
  const a = t;
726
736
  a.source && a.source[ce] && (n = a.source[ce]);
727
737
  }
728
- if (n || (n = y.lodInfos.get(i)), !n)
729
- f && console.warn(`Can not load LOD ${e}: no LOD info found for "${i}" ${t.name}`, t.type, y.lodInfos);
738
+ if (n || (n = m.lodInfos.get(i)), !n)
739
+ f && console.warn(`Can not load LOD ${e}: no LOD info found for "${i}" ${t.name}`, t.type, m.lodInfos);
730
740
  else {
731
741
  if (e > 0) {
732
742
  let c = !1;
733
- const m = Array.isArray(n.lods);
734
- if (m && e >= n.lods.length ? c = !0 : m || (c = !0), c) {
743
+ const y = Array.isArray(n.lods);
744
+ if (y && e >= n.lods.length ? c = !0 : y || (c = !0), c) {
735
745
  const w = this.lowresCache.get(i);
736
746
  if (w) {
737
747
  const L = w.deref();
@@ -748,7 +758,7 @@ ${e}`);
748
758
  if (u.endsWith(".glb") || u.endsWith(".gltf")) {
749
759
  if (!n.guid)
750
760
  return console.warn("missing pointer for glb/gltf texture", n), null;
751
- const c = u + "_" + n.guid, m = await this.queue.slot(u), w = this.cache.get(c);
761
+ const c = u + "_" + n.guid, y = await this.queue.slot(u), w = this.cache.get(c);
752
762
  if (w !== void 0)
753
763
  if (s && console.log(`LOD ${e} was already loading/loaded: ${c}`), w instanceof WeakRef) {
754
764
  const d = w.deref();
@@ -764,7 +774,7 @@ ${e}`);
764
774
  if (d == null || (d instanceof F && t instanceof F ? d.image?.data || d.source?.data ? d = this.copySettings(t, d) : (g = !0, this.cache.delete(c)) : d instanceof V && t instanceof V && (d.attributes.position?.array || (g = !0, this.cache.delete(c)))), !g)
765
775
  return d;
766
776
  }
767
- if (!m.use)
777
+ if (!y.use)
768
778
  return f && console.log(`LOD ${e} was aborted: ${u}`), null;
769
779
  const L = n, k = new Promise(async (d, g) => {
770
780
  if (pt) {
@@ -772,20 +782,20 @@ ${e}`);
772
782
  if (x.textures.length > 0)
773
783
  for (const h of x.textures) {
774
784
  let p = h.texture;
775
- return y.assignLODInformation(r.url, p, i, e, void 0), t instanceof F && (p = this.copySettings(t, p)), p && (p.guid = L.guid), d(p);
785
+ return m.assignLODInformation(r.url, p, i, e, void 0), t instanceof F && (p = this.copySettings(t, p)), p && (p.guid = L.guid), d(p);
776
786
  }
777
787
  if (x.geometries.length > 0) {
778
788
  const h = new Array();
779
789
  for (const p of x.geometries) {
780
790
  const b = p.geometry;
781
- y.assignLODInformation(r.url, b, i, e, p.primitiveIndex), h.push(b);
791
+ m.assignLODInformation(r.url, b, i, e, p.primitiveIndex), h.push(b);
782
792
  }
783
793
  return d(h);
784
794
  }
785
795
  return d(null);
786
796
  }
787
797
  const M = new we();
788
- Te(M), f && (await new Promise((_) => setTimeout(_, 1e3)), s && console.warn("Start loading (delayed) " + u, L.guid));
798
+ Ce(M), f && (await new Promise((_) => setTimeout(_, 1e3)), s && console.warn("Start loading (delayed) " + u, L.guid));
789
799
  let B = u;
790
800
  if (L && Array.isArray(L.lods)) {
791
801
  const _ = L.lods[e];
@@ -795,9 +805,9 @@ ${e}`);
795
805
  `, _), d(null)));
796
806
  if (!D)
797
807
  return d(null);
798
- const q = D.parser;
808
+ const N = D.parser;
799
809
  s && console.log("Loading finished " + u, L.guid);
800
- let P = 0;
810
+ let T = 0;
801
811
  if (D.parser.json.textures) {
802
812
  let _ = !1;
803
813
  for (const x of D.parser.json.textures) {
@@ -808,14 +818,14 @@ ${e}`);
808
818
  break;
809
819
  }
810
820
  }
811
- P++;
821
+ T++;
812
822
  }
813
823
  if (_) {
814
- let x = await q.getDependency("texture", P);
815
- return x && y.assignLODInformation(r.url, x, i, e, void 0), s && console.log('change "' + t.name + '" → "' + x.name + '"', u, P, x, c), t instanceof F && (x = this.copySettings(t, x)), x && (x.guid = L.guid), d(x);
824
+ let x = await N.getDependency("texture", T);
825
+ return x && m.assignLODInformation(r.url, x, i, e, void 0), s && console.log('change "' + t.name + '" → "' + x.name + '"', u, T, x, c), t instanceof F && (x = this.copySettings(t, x)), x && (x.guid = L.guid), d(x);
816
826
  } else f && console.warn("Could not find texture with guid", L.guid, D.parser.json);
817
827
  }
818
- if (P = 0, D.parser.json.meshes) {
828
+ if (T = 0, D.parser.json.meshes) {
819
829
  let _ = !1;
820
830
  for (const x of D.parser.json.meshes) {
821
831
  if (x?.extensions) {
@@ -825,20 +835,20 @@ ${e}`);
825
835
  break;
826
836
  }
827
837
  }
828
- P++;
838
+ T++;
829
839
  }
830
840
  if (_) {
831
- const x = await q.getDependency("mesh", P);
832
- if (s && console.log(`Loaded Mesh "${x.name}"`, u, P, x, c), x.isMesh === !0) {
841
+ const x = await N.getDependency("mesh", T);
842
+ if (s && console.log(`Loaded Mesh "${x.name}"`, u, T, x, c), x.isMesh === !0) {
833
843
  const h = x.geometry;
834
- return y.assignLODInformation(r.url, h, i, e, 0), d(h);
844
+ return m.assignLODInformation(r.url, h, i, e, 0), d(h);
835
845
  } else {
836
846
  const h = new Array();
837
847
  for (let p = 0; p < x.children.length; p++) {
838
848
  const b = x.children[p];
839
849
  if (b.isMesh === !0) {
840
850
  const S = b.geometry;
841
- y.assignLODInformation(r.url, S, i, e, p), h.push(S);
851
+ m.assignLODInformation(r.url, S, i, e, p), h.push(S);
842
852
  }
843
853
  }
844
854
  return d(h);
@@ -847,19 +857,18 @@ ${e}`);
847
857
  }
848
858
  return d(null);
849
859
  });
850
- this.cache.set(c, k), m.use(k);
860
+ this.cache.set(c, k), y.use(k);
851
861
  const v = await k;
852
- return v != null ? v instanceof F ? (this.cache.set(c, new WeakRef(v)), y._resourceRegistry.register(v, c)) : Array.isArray(v) ? this.cache.set(c, Promise.resolve(v)) : this.cache.set(c, Promise.resolve(v)) : this.cache.set(c, Promise.resolve(null)), v;
862
+ return v != null ? v instanceof F ? (this.cache.set(c, new WeakRef(v)), m._resourceRegistry.register(v, c)) : Array.isArray(v) ? this.cache.set(c, Promise.resolve(v)) : this.cache.set(c, Promise.resolve(v)) : this.cache.set(c, Promise.resolve(null)), v;
853
863
  } else if (t instanceof F) {
854
864
  s && console.log("Load texture from uri: " + u);
855
- const m = await new qe().loadAsync(u);
856
- return m ? (m.guid = n.guid, m.flipY = !1, m.needsUpdate = !0, m.colorSpace = t.colorSpace, s && console.log(n, m)) : f && console.warn("failed loading", u), m;
865
+ const y = await new Ne().loadAsync(u);
866
+ return y ? (y.guid = n.guid, y.flipY = !1, y.needsUpdate = !0, y.colorSpace = t.colorSpace, s && console.log(n, y)) : f && console.warn("failed loading", u), y;
857
867
  }
858
868
  }
859
869
  return null;
860
870
  }
861
- static maxConcurrent = 50;
862
- static queue = new it(y.maxConcurrent, { debug: f != !1 });
871
+ static queue = new it(_e() ? 20 : 50, { debug: f != !1 });
863
872
  static assignLODInformation(t, e, s, r, i) {
864
873
  if (!e) return;
865
874
  e.userData || (e.userData = {});
@@ -963,7 +972,7 @@ class de {
963
972
  });
964
973
  }
965
974
  }
966
- const R = N("debugprogressive"), yt = N("noprogressive"), fe = /* @__PURE__ */ Symbol("Needle:LODSManager"), he = /* @__PURE__ */ Symbol("Needle:LODState"), U = /* @__PURE__ */ Symbol("Needle:CurrentLOD"), T = { mesh_lod: -1, texture_lod: -1 };
975
+ const R = q("debugprogressive"), yt = q("noprogressive"), fe = /* @__PURE__ */ Symbol("Needle:LODSManager"), he = /* @__PURE__ */ Symbol("Needle:LODState"), U = /* @__PURE__ */ Symbol("Needle:CurrentLOD"), P = { mesh_lod: -1, texture_lod: -1 };
967
976
  let oe = class O {
968
977
  /**
969
978
  * 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.
@@ -996,7 +1005,7 @@ let oe = class O {
996
1005
  }
997
1006
  renderer;
998
1007
  context;
999
- projectionScreenMatrix = new Me();
1008
+ projectionScreenMatrix = new ve();
1000
1009
  /** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
1001
1010
  get plugins() {
1002
1011
  return z;
@@ -1045,7 +1054,7 @@ let oe = class O {
1045
1054
  const r = performance.now();
1046
1055
  return s.ready.finally(() => {
1047
1056
  const i = this._newPromiseGroups.indexOf(s);
1048
- i >= 0 && (this._newPromiseGroups.splice(i, 1), ve() && performance.measure("LODsManager:awaitLoading", {
1057
+ i >= 0 && (this._newPromiseGroups.splice(i, 1), De() && performance.measure("LODsManager:awaitLoading", {
1049
1058
  start: r,
1050
1059
  detail: { id: e, name: t?.name, awaited: s.awaitedCount, resolved: s.resolvedCount }
1051
1060
  }));
@@ -1136,8 +1145,8 @@ let oe = class O {
1136
1145
  }
1137
1146
  if (R === "color" && a.material && !a.object.progressive_debug_color) {
1138
1147
  a.object.progressive_debug_color = !0;
1139
- const c = Math.random() * 16777215, m = new Ve({ color: c });
1140
- a.object.material = m;
1148
+ const c = Math.random() * 16777215, y = new Ve({ color: c });
1149
+ a.object.material = y;
1141
1150
  }
1142
1151
  const u = a.object;
1143
1152
  (u instanceof X || u.isMesh) && this.updateLODs(t, e, u, i);
@@ -1162,10 +1171,10 @@ let oe = class O {
1162
1171
  for (const l of z)
1163
1172
  l.onBeforeUpdateLOD?.(this.renderer, t, e, s);
1164
1173
  const n = this.overrideLodLevel !== void 0 ? this.overrideLodLevel : E;
1165
- n >= 0 ? (T.mesh_lod = n, T.texture_lod = n) : (this.calculateLodLevel(e, s, i, r, T), T.mesh_lod = Math.round(T.mesh_lod), T.texture_lod = Math.round(T.texture_lod)), T.mesh_lod >= 0 && this.loadProgressiveMeshes(s, T.mesh_lod), s.material && T.texture_lod >= 0 && this.loadProgressiveTextures(s.material, T.texture_lod, n), f && s.material && !s.isGizmo && Re(s.material);
1174
+ n >= 0 ? (P.mesh_lod = n, P.texture_lod = n) : (this.calculateLodLevel(e, s, i, r, P), P.mesh_lod = Math.round(P.mesh_lod), P.texture_lod = Math.round(P.texture_lod)), P.mesh_lod >= 0 && this.loadProgressiveMeshes(s, P.mesh_lod), s.material && P.texture_lod >= 0 && this.loadProgressiveTextures(s.material, P.texture_lod, n), f && s.material && !s.isGizmo && Re(s.material);
1166
1175
  for (const l of z)
1167
- l.onAfterUpdatedLOD?.(this.renderer, t, e, s, T);
1168
- i.lastLodLevel_Mesh = T.mesh_lod, i.lastLodLevel_Texture = T.texture_lod;
1176
+ l.onAfterUpdatedLOD?.(this.renderer, t, e, s, P);
1177
+ i.lastLodLevel_Mesh = P.mesh_lod, i.lastLodLevel_Texture = P.texture_lod;
1169
1178
  }
1170
1179
  /** Load progressive textures for the given material
1171
1180
  * @param material the material to load the textures for
@@ -1182,7 +1191,7 @@ let oe = class O {
1182
1191
  let r = !1;
1183
1192
  if ((t[U] === void 0 || e < t[U]) && (r = !0), s !== void 0 && s >= 0 && (r = t[U] != s, e = s), r) {
1184
1193
  t[U] = e;
1185
- const i = y.assignTextureLOD(t, e).then((n) => {
1194
+ const i = m.assignTextureLOD(t, e).then((n) => {
1186
1195
  this._lodchangedlisteners.forEach((l) => l({ type: "texture", level: e, object: t }));
1187
1196
  });
1188
1197
  de.addPromise("texture", t, i, this._newPromiseGroups);
@@ -1200,16 +1209,16 @@ let oe = class O {
1200
1209
  const r = t["DEBUG:LOD"];
1201
1210
  if (r != null && (s = t[U] != r, e = r), s) {
1202
1211
  t[U] = e;
1203
- const i = t.geometry, n = y.assignMeshLOD(t, e).then((l) => (l && t[U] == e && i != t.geometry && this._lodchangedlisteners.forEach((a) => a({ type: "mesh", level: e, object: t })), l));
1212
+ const i = t.geometry, n = m.assignMeshLOD(t, e).then((l) => (l && t[U] == e && i != t.geometry && this._lodchangedlisteners.forEach((a) => a({ type: "mesh", level: e, object: t })), l));
1204
1213
  return de.addPromise("mesh", t, n, this._newPromiseGroups), n;
1205
1214
  }
1206
1215
  return Promise.resolve(null);
1207
1216
  }
1208
1217
  // private testIfLODLevelsAreAvailable() {
1209
- _sphere = new Se();
1218
+ _sphere = new Te();
1210
1219
  _tempBox = new pe();
1211
1220
  _tempBox2 = new pe();
1212
- tempMatrix = new Me();
1221
+ tempMatrix = new ve();
1213
1222
  _tempWorldPosition = new A();
1214
1223
  _tempBoxSize = new A();
1215
1224
  _tempBox2Size = new A();
@@ -1237,12 +1246,12 @@ let oe = class O {
1237
1246
  let l = 10 + 1, a = !1;
1238
1247
  if (R && e["DEBUG:LOD"] != null)
1239
1248
  return e["DEBUG:LOD"];
1240
- const u = y.getMeshLODExtension(e.geometry)?.lods, c = y.getPrimitiveIndex(e.geometry), m = u && u.length > 0, w = y.getMaterialMinMaxLODsCount(e.material), L = w.min_count !== 1 / 0 && w.min_count >= 0 && w.max_count >= 0;
1241
- if (!m && !L) {
1249
+ const u = m.getMeshLODExtension(e.geometry)?.lods, c = m.getPrimitiveIndex(e.geometry), y = u && u.length > 0, w = m.getMaterialMinMaxLODsCount(e.material), L = w.min_count !== 1 / 0 && w.min_count >= 0 && w.max_count >= 0;
1250
+ if (!y && !L) {
1242
1251
  i.mesh_lod = 0, i.texture_lod = 0;
1243
1252
  return;
1244
1253
  }
1245
- m || (a = !0, l = 0);
1254
+ y || (a = !0, l = 0);
1246
1255
  const k = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
1247
1256
  let v = e.geometry.boundingBox;
1248
1257
  if (e.type === "SkinnedMesh") {
@@ -1289,8 +1298,8 @@ let oe = class O {
1289
1298
  g.multiplyScalar(0.5), screen.availHeight > 0 && k > 0 && g.multiplyScalar(k / screen.availHeight), t.isPerspectiveCamera ? g.x *= t.aspect : t.isOrthographicCamera;
1290
1299
  const M = t.matrixWorldInverse, B = this._tempBox2;
1291
1300
  B.copy(v), B.applyMatrix4(e.matrixWorld), B.applyMatrix4(M);
1292
- const D = B.getSize(this._tempBox2Size), q = Math.max(D.x, D.y);
1293
- if (Math.max(g.x, g.y) != 0 && q != 0 && (g.z = D.z / Math.max(D.x, D.y) * Math.max(g.x, g.y)), s.lastScreenCoverage = Math.max(g.x, g.y, g.z), s.lastScreenspaceVolume.copy(g), s.lastScreenCoverage *= s.lastCentrality, R && O.debugDrawLine) {
1301
+ const D = B.getSize(this._tempBox2Size), N = Math.max(D.x, D.y);
1302
+ if (Math.max(g.x, g.y) != 0 && N != 0 && (g.z = D.z / Math.max(D.x, D.y) * Math.max(g.x, g.y)), s.lastScreenCoverage = Math.max(g.x, g.y, g.z), s.lastScreenspaceVolume.copy(g), s.lastScreenCoverage *= s.lastCentrality, R && O.debugDrawLine) {
1294
1303
  const h = this.tempMatrix.copy(this.projectionScreenMatrix);
1295
1304
  h.invert();
1296
1305
  const p = O.corner0, b = O.corner1, S = O.corner2, G = O.corner3;
@@ -1302,7 +1311,7 @@ let oe = class O {
1302
1311
  if (u && s.lastScreenCoverage > 0)
1303
1312
  for (let h = 0; h < u.length; h++) {
1304
1313
  const p = u[h], S = (p.densities?.[c] || p.density || 1e-5) / s.lastScreenCoverage;
1305
- if (c > 0 && ve() && !p.densities && !globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] && (window["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.")), S < r) {
1314
+ if (c > 0 && De() && !p.densities && !globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] && (window["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.")), S < r) {
1306
1315
  _ = h;
1307
1316
  break;
1308
1317
  }
@@ -1325,11 +1334,11 @@ let oe = class O {
1325
1334
  let M = s.lastScreenCoverage * 4;
1326
1335
  this.context?.engine === "model-viewer" && (M *= 1.5);
1327
1336
  const D = k / window.devicePixelRatio * M;
1328
- let q = !1;
1329
- for (let P = w.lods.length - 1; P >= 0; P--) {
1330
- const _ = w.lods[P];
1331
- if (!(d && _.max_height >= 2048) && !(ke() && _.max_height > 4096) && (_.max_height > D || !q && P === 0)) {
1332
- if (q = !0, i.texture_lod = P, R && i.texture_lod < s.lastLodLevel_Texture) {
1337
+ let N = !1;
1338
+ for (let T = w.lods.length - 1; T >= 0; T--) {
1339
+ const _ = w.lods[T];
1340
+ if (!(d && _.max_height >= 2048) && !(_e() && _.max_height > 4096) && (_.max_height > D || !N && T === 0)) {
1341
+ if (N = !0, i.texture_lod = T, R && i.texture_lod < s.lastLodLevel_Texture) {
1333
1342
  const x = _.max_height;
1334
1343
  console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${i.texture_lod} = ${x}px
1335
1344
  Screensize: ${D.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${g.toFixed(1)}
@@ -1351,13 +1360,13 @@ class xt {
1351
1360
  lastScreenspaceVolume = new A();
1352
1361
  lastCentrality = 0;
1353
1362
  }
1354
- const De = /* @__PURE__ */ Symbol("NEEDLE_mesh_lod"), ie = /* @__PURE__ */ Symbol("NEEDLE_texture_lod");
1363
+ const be = /* @__PURE__ */ Symbol("NEEDLE_mesh_lod"), ie = /* @__PURE__ */ Symbol("NEEDLE_texture_lod");
1355
1364
  let ge = null;
1356
1365
  function Ie() {
1357
1366
  const o = wt();
1358
1367
  o && (o.mapURLs(function(t) {
1359
- return be(), t;
1360
- }), be(), ge?.disconnect(), ge = new MutationObserver((t) => {
1368
+ return Oe(), t;
1369
+ }), Oe(), ge?.disconnect(), ge = new MutationObserver((t) => {
1361
1370
  t.forEach((e) => {
1362
1371
  e.addedNodes.forEach((s) => {
1363
1372
  s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && $e(s);
@@ -1372,18 +1381,18 @@ function wt() {
1372
1381
  console.debug("[gltf-progressive] model-viewer defined"), Ie();
1373
1382
  }), null);
1374
1383
  }
1375
- function be() {
1384
+ function Oe() {
1376
1385
  if (typeof document > "u") return;
1377
1386
  document.querySelectorAll("model-viewer").forEach((t) => {
1378
1387
  $e(t);
1379
1388
  });
1380
1389
  }
1381
- const Oe = /* @__PURE__ */ new WeakSet();
1390
+ const Se = /* @__PURE__ */ new WeakSet();
1382
1391
  let Lt = 0;
1383
1392
  function $e(o) {
1384
- if (!o || Oe.has(o))
1393
+ if (!o || Se.has(o))
1385
1394
  return null;
1386
- Oe.add(o), console.debug("[gltf-progressive] found new model-viewer..." + ++Lt + `
1395
+ Se.add(o), console.debug("[gltf-progressive] found new model-viewer..." + ++Lt + `
1387
1396
  `, o.getAttribute("src"));
1388
1397
  let t = null, e = null, s = null;
1389
1398
  for (let r = o; r != null; r = Object.getPrototypeOf(r)) {
@@ -1443,7 +1452,7 @@ class _t {
1443
1452
  a[ie] = !0, a.userData && (a.userData.LOD = -1);
1444
1453
  const u = Object.keys(a);
1445
1454
  for (let c = 0; c < u.length; c++) {
1446
- const m = u[c], w = a[m];
1455
+ const y = u[c], w = a[y];
1447
1456
  if (w?.isTexture === !0) {
1448
1457
  const L = w.userData?.associations?.textures;
1449
1458
  if (L == null) continue;
@@ -1454,7 +1463,7 @@ class _t {
1454
1463
  }
1455
1464
  if (k?.extensions?.[W]) {
1456
1465
  const v = k.extensions[W];
1457
- v && i && y.registerTexture(i, w, v.lods.length, L, v);
1466
+ v && i && m.registerTexture(i, w, v.lods.length, L, v);
1458
1467
  }
1459
1468
  }
1460
1469
  }
@@ -1465,15 +1474,15 @@ class _t {
1465
1474
  }
1466
1475
  }
1467
1476
  tryParseMeshLOD(t, e) {
1468
- if (e[De] == !0) return;
1469
- e[De] = !0;
1477
+ if (e[be] == !0) return;
1478
+ e[be] = !0;
1470
1479
  const s = this.tryGetCurrentModelViewer(t), r = this.getUrl(s);
1471
1480
  if (!r)
1472
1481
  return;
1473
1482
  const i = e.userData?.gltfExtensions?.[W];
1474
1483
  if (i && r) {
1475
1484
  const n = e.uuid;
1476
- y.registerMesh(r, n, e, 0, i.lods.length, i);
1485
+ m.registerMesh(r, n, e, 0, i.lods.length, i);
1477
1486
  }
1478
1487
  }
1479
1488
  }
@@ -1492,10 +1501,10 @@ function Mt(...o) {
1492
1501
  default:
1493
1502
  throw new Error("Invalid arguments");
1494
1503
  }
1495
- Le(e), Te(s), Ae(s, {
1504
+ Le(e), Ce(s), ke(s, {
1496
1505
  progressive: !0,
1497
1506
  ...r?.hints
1498
- }), s.register((n) => new y(n));
1507
+ }), s.register((n) => new m(n));
1499
1508
  const i = oe.get(e);
1500
1509
  return r?.enableLODsManager !== !1 && i.enable(), i;
1501
1510
  }
@@ -1505,7 +1514,7 @@ if (!at) {
1505
1514
  gltfProgressive: {
1506
1515
  useNeedleProgressive: Mt,
1507
1516
  LODsManager: oe,
1508
- configureLoader: Ae,
1517
+ configureLoader: ke,
1509
1518
  getRaycastMesh: ee,
1510
1519
  useRaycastMeshes: ut
1511
1520
  }
@@ -1518,9 +1527,9 @@ if (!at) {
1518
1527
  }
1519
1528
  export {
1520
1529
  oe as LODsManager,
1521
- y as NEEDLE_progressive,
1522
- Te as addDracoAndKTX2Loaders,
1523
- Ae as configureLoader,
1530
+ m as NEEDLE_progressive,
1531
+ Ce as addDracoAndKTX2Loaders,
1532
+ ke as configureLoader,
1524
1533
  Le as createLoaders,
1525
1534
  ee as getRaycastMesh,
1526
1535
  Ze as setDracoDecoderLocation,