@needle-tools/engine 4.3.2-beta.3 → 4.3.2-beta.5

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.
@@ -1,19 +1,20 @@
1
- import { B as he, M as Q, T as ee, a as We, V as z, b as be, S as ze, c as Te, d as Ve, C as Ke } from "./three.light.js";
2
- import { D as Xe, K as qe, G as Se, M as Ye } from "./three-examples.light.js";
3
- const He = "";
4
- globalThis.GLTF_PROGRESSIVE_VERSION = He;
1
+ import { B as he, M as Q, T as ee, a as ze, V as z, b as be, S as Ve, c as Te, d as Ke, C as Xe } from "./three.light.js";
2
+ import { D as qe, K as Ye, G as Se, M as He } from "./three-examples.light.js";
3
+ const Je = "";
4
+ globalThis.GLTF_PROGRESSIVE_VERSION = Je;
5
5
  console.debug("[gltf-progressive] version -");
6
6
  let N = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", j = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
7
- const Je = N, Qe = j, Ze = new URL(N + "draco_decoder.js");
8
- fetch(Ze, {
7
+ const Qe = N, Ze = j, ke = new URL(N + "draco_decoder.js");
8
+ ke.searchParams.append("range", "true");
9
+ fetch(ke, {
9
10
  method: "GET",
10
11
  headers: {
11
12
  Range: "bytes=0-1"
12
13
  }
13
14
  }).catch((t) => {
14
- console.debug(`Failed to fetch remote Draco decoder from ${N} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), N === Je && je("./include/draco/"), j === Qe && et("./include/ktx2/");
15
+ console.debug(`Failed to fetch remote Draco decoder from ${N} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), N === Qe && je("./include/draco/"), j === Ze && et("./include/ktx2/");
15
16
  }).finally(() => {
16
- ke();
17
+ Be();
17
18
  });
18
19
  function je(t) {
19
20
  N = t, A && A[De] != N ? (console.debug("Updating Draco decoder path to " + t), A[De] = N, A.setDecoderPath(N), A.preload()) : console.debug("Setting Draco decoder path to " + t);
@@ -23,17 +24,17 @@ function et(t) {
23
24
  }
24
25
  const De = Symbol("dracoDecoderPath");
25
26
  let A, ge, G;
26
- function ke() {
27
- A || (A = new Xe(), A[De] = N, A.setDecoderPath(N), A.setDecoderConfig({ type: "js" }), A.preload()), G || (G = new qe(), G.setTranscoderPath(j), G.init()), ge || (ge = Ye);
28
- }
29
- function Be(t) {
30
- return ke(), t ? G.detectSupport(t) : t !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: A, ktx2Loader: G, meshoptDecoder: ge };
27
+ function Be() {
28
+ A || (A = new qe(), A[De] = N, A.setDecoderPath(N), A.setDecoderConfig({ type: "js" }), A.preload()), G || (G = new Ye(), G.setTranscoderPath(j), G.init()), ge || (ge = He);
31
29
  }
32
30
  function Re(t) {
31
+ return Be(), t ? G.detectSupport(t) : t !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: A, ktx2Loader: G, meshoptDecoder: ge };
32
+ }
33
+ function Ie(t) {
33
34
  t.dracoLoader || t.setDRACOLoader(A), t.ktx2Loader || t.setKTX2Loader(G), t.meshoptDecoder || t.setMeshoptDecoder(ge);
34
35
  }
35
36
  const Me = /* @__PURE__ */ new WeakMap();
36
- function Ie(t, e) {
37
+ function Ge(t, e) {
37
38
  let s = Me.get(t);
38
39
  s ? s = Object.assign(s, e) : s = e, Me.set(t, s);
39
40
  }
@@ -408,14 +409,14 @@ const M = class {
408
409
  const x = h + "_" + r.guid, L = this.previouslyLoaded.get(x);
409
410
  if (L !== void 0) {
410
411
  s && console.log(`LOD ${e} was already loading/loaded: ${x}`);
411
- let u = await L.catch(($) => (console.error(`Error loading LOD ${e} from ${h}
412
+ let f = await L.catch(($) => (console.error(`Error loading LOD ${e} from ${h}
412
413
  `, $), null)), w = !1;
413
- if (u == null || (u instanceof ee && t instanceof ee ? (a = u.image) != null && a.data || (c = u.source) != null && c.data ? u = this.copySettings(t, u) : (w = !0, this.previouslyLoaded.delete(x)) : u instanceof he && t instanceof he && ((l = u.attributes.position) != null && l.array || (w = !0, this.previouslyLoaded.delete(x)))), !w)
414
- return u;
414
+ if (f == null || (f instanceof ee && t instanceof ee ? (a = f.image) != null && a.data || (c = f.source) != null && c.data ? f = this.copySettings(t, f) : (w = !0, this.previouslyLoaded.delete(x)) : f instanceof he && t instanceof he && ((l = f.attributes.position) != null && l.array || (w = !0, this.previouslyLoaded.delete(x)))), !w)
415
+ return f;
415
416
  }
416
- const D = r, k = new Promise(async (u, w) => {
417
+ const D = r, k = new Promise(async (f, w) => {
417
418
  const $ = new Se();
418
- Re($), p && (await new Promise((O) => setTimeout(O, 1e3)), s && console.warn("Start loading (delayed) " + h, D.guid));
419
+ Ie($), p && (await new Promise((O) => setTimeout(O, 1e3)), s && console.warn("Start loading (delayed) " + h, D.guid));
419
420
  let B = h;
420
421
  if (D && Array.isArray(D.lods)) {
421
422
  const O = D.lods[e];
@@ -430,9 +431,9 @@ const M = class {
430
431
  let v = 0;
431
432
  if (T.parser.json.textures) {
432
433
  let O = !1;
433
- for (const f of T.parser.json.textures) {
434
- if (f != null && f.extensions) {
435
- const g = f == null ? void 0 : f.extensions[W];
434
+ for (const u of T.parser.json.textures) {
435
+ if (u != null && u.extensions) {
436
+ const g = u == null ? void 0 : u.extensions[W];
436
437
  if (g != null && g.guid && g.guid === D.guid) {
437
438
  O = !0;
438
439
  break;
@@ -441,16 +442,16 @@ const M = class {
441
442
  v++;
442
443
  }
443
444
  if (O) {
444
- let f = await U.getDependency("texture", v);
445
- return f && M.assignLODInformation(n.url, f, i, e, void 0, void 0), s && console.log('change "' + t.name + '" → "' + f.name + '"', h, v, f, x), t instanceof ee && (f = this.copySettings(t, f)), f && (f.guid = D.guid), u(f);
445
+ let u = await U.getDependency("texture", v);
446
+ return u && M.assignLODInformation(n.url, u, i, e, void 0, void 0), s && console.log('change "' + t.name + '" → "' + u.name + '"', h, v, u, x), t instanceof ee && (u = this.copySettings(t, u)), u && (u.guid = D.guid), f(u);
446
447
  } else
447
448
  p && console.warn("Could not find texture with guid", D.guid, T.parser.json);
448
449
  }
449
450
  if (v = 0, T.parser.json.meshes) {
450
451
  let O = !1;
451
- for (const f of T.parser.json.meshes) {
452
- if (f != null && f.extensions) {
453
- const g = f == null ? void 0 : f.extensions[W];
452
+ for (const u of T.parser.json.meshes) {
453
+ if (u != null && u.extensions) {
454
+ const g = u == null ? void 0 : u.extensions[W];
454
455
  if (g != null && g.guid && g.guid === D.guid) {
455
456
  O = !0;
456
457
  break;
@@ -459,30 +460,30 @@ const M = class {
459
460
  v++;
460
461
  }
461
462
  if (O) {
462
- const f = await U.getDependency("mesh", v), g = D;
463
- if (s && console.log(`Loaded Mesh "${f.name}"`, h, v, f, x), f.isMesh === !0) {
464
- const _ = f.geometry;
465
- return M.assignLODInformation(n.url, _, i, e, void 0, g.density), u(_);
463
+ const u = await U.getDependency("mesh", v), g = D;
464
+ if (s && console.log(`Loaded Mesh "${u.name}"`, h, v, u, x), u.isMesh === !0) {
465
+ const _ = u.geometry;
466
+ return M.assignLODInformation(n.url, _, i, e, void 0, g.density), f(_);
466
467
  } else {
467
468
  const _ = new Array();
468
- for (let S = 0; S < f.children.length; S++) {
469
- const E = f.children[S];
469
+ for (let S = 0; S < u.children.length; S++) {
470
+ const E = u.children[S];
470
471
  if (E.isMesh === !0) {
471
472
  const K = E.geometry;
472
473
  M.assignLODInformation(n.url, K, i, e, S, g.density), _.push(K);
473
474
  }
474
475
  }
475
- return u(_);
476
+ return f(_);
476
477
  }
477
478
  } else
478
479
  p && console.warn("Could not find mesh with guid", D.guid, T.parser.json);
479
480
  }
480
- return u(null);
481
+ return f(null);
481
482
  });
482
483
  return this.previouslyLoaded.set(x, k), await k;
483
484
  } else if (t instanceof ee) {
484
485
  s && console.log("Load texture from uri: " + h);
485
- const L = await new We().loadAsync(h);
486
+ const L = await new ze().loadAsync(h);
486
487
  return L ? (L.guid = r.guid, L.flipY = !1, L.needsUpdate = !0, L.colorSpace = t.colorSpace, s && console.log(r, L)) : p && console.warn("failed loading", h), L;
487
488
  }
488
489
  } else
@@ -539,18 +540,18 @@ class lt {
539
540
  this.url = e, this.key = s, this.level = n, i != null && (this.index = i), r != null && (this.density = r);
540
541
  }
541
542
  }
542
- var Ge = (t, e, s) => {
543
+ var $e = (t, e, s) => {
543
544
  if (!e.has(t))
544
545
  throw TypeError("Cannot " + s);
545
- }, y = (t, e, s) => (Ge(t, e, "read from private field"), s ? s.call(t) : e.get(t)), J = (t, e, s) => {
546
+ }, y = (t, e, s) => ($e(t, e, "read from private field"), s ? s.call(t) : e.get(t)), J = (t, e, s) => {
546
547
  if (e.has(t))
547
548
  throw TypeError("Cannot add the same private member more than once");
548
549
  e instanceof WeakSet ? e.add(t) : e.set(t, s);
549
- }, F = (t, e, s, n) => (Ge(t, e, "write to private field"), n ? n.call(t, s) : e.set(t, s), s), b, q, Oe, Z, ie, de, Y;
550
+ }, F = (t, e, s, n) => ($e(t, e, "write to private field"), n ? n.call(t, s) : e.set(t, s), s), b, q, Oe, Z, ie, de, Y;
550
551
  const R = oe("debugprogressive"), ct = oe("noprogressive"), me = Symbol("Needle:LODSManager"), xe = Symbol("Needle:LODState"), X = Symbol("Needle:CurrentLOD"), I = { mesh_lod: -1, texture_lod: -1 }, C = class {
551
552
  // readonly plugins: NEEDLE_progressive_plugin[] = [];
552
553
  constructor(t, e) {
553
- this.projectionScreenMatrix = new be(), this.targetTriangleDensity = 2e5, this.updateInterval = "auto", J(this, b, 1), this.pause = !1, this.manual = !1, this._lodchangedlisteners = [], J(this, q, void 0), J(this, Oe, new Ke()), J(this, Z, 0), J(this, ie, 0), J(this, de, 0), J(this, Y, 0), this._fpsBuffer = [60, 60, 60, 60, 60], this._sphere = new ze(), this._tempBox = new Te(), this._tempBox2 = new Te(), this.tempMatrix = new be(), this._tempWorldPosition = new z(), this._tempBoxSize = new z(), this._tempBox2Size = new z(), this.renderer = t, this.context = { ...e };
554
+ this.projectionScreenMatrix = new be(), this.targetTriangleDensity = 2e5, this.updateInterval = "auto", J(this, b, 1), this.pause = !1, this.manual = !1, this._lodchangedlisteners = [], J(this, q, void 0), J(this, Oe, new Xe()), J(this, Z, 0), J(this, ie, 0), J(this, de, 0), J(this, Y, 0), this._fpsBuffer = [60, 60, 60, 60, 60], this._sphere = new Ve(), this._tempBox = new Te(), this._tempBox2 = new Te(), this.tempMatrix = new be(), this._tempWorldPosition = new z(), this._tempBoxSize = new z(), this._tempBox2Size = new z(), this.renderer = t, this.context = { ...e };
554
555
  }
555
556
  /** @internal */
556
557
  static getObjectLODState(t) {
@@ -600,7 +601,7 @@ const R = oe("debugprogressive"), ct = oe("noprogressive"), me = Symbol("Needle:
600
601
  let t = 0;
601
602
  F(this, q, this.renderer.render);
602
603
  const e = this;
603
- Be(this.renderer), this.renderer.render = function(s, n) {
604
+ Re(this.renderer), this.renderer.render = function(s, n) {
604
605
  const i = e.renderer.getRenderTarget();
605
606
  (i == null || "isXRRenderTarget" in i && i.isXRRenderTarget) && (t = 0, F(e, Z, y(e, Z) + 1), F(e, ie, y(e, Oe).getDelta()), F(e, de, y(e, de) + y(e, ie)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / y(e, ie)), F(e, Y, e._fpsBuffer.reduce((o, a) => o + a) / e._fpsBuffer.length), R && y(e, Z) % 200 === 0 && console.log("FPS", Math.round(y(e, Y)), "Interval:", y(e, b)));
606
607
  const r = t++;
@@ -652,7 +653,7 @@ const R = oe("debugprogressive"), ct = oe("noprogressive"), me = Symbol("Needle:
652
653
  }
653
654
  if (R === "color" && l.material && !l.object.progressive_debug_color) {
654
655
  l.object.progressive_debug_color = !0;
655
- const h = Math.random() * 16777215, x = new Ve({ color: h });
656
+ const h = Math.random() * 16777215, x = new Ke({ color: h });
656
657
  l.object.material = x;
657
658
  }
658
659
  const d = l.object;
@@ -674,7 +675,7 @@ const R = oe("debugprogressive"), ct = oe("noprogressive"), me = Symbol("Needle:
674
675
  var o, a;
675
676
  s.userData || (s.userData = {});
676
677
  let i = s[xe];
677
- if (i || (i = new ft(), s[xe] = i), i.frames++ < 2)
678
+ if (i || (i = new ut(), s[xe] = i), i.frames++ < 2)
678
679
  return;
679
680
  for (const c of H)
680
681
  (o = c.onBeforeUpdateLOD) == null || o.call(c, this.renderer, t, e, s);
@@ -753,8 +754,8 @@ const R = oe("debugprogressive"), ct = oe("noprogressive"), me = Symbol("Needle:
753
754
  if (!m.boundingBox)
754
755
  m.computeBoundingBox();
755
756
  else if (s.frames % 30 === 0) {
756
- const u = ae(m), w = m.geometry;
757
- u && (m.geometry = u), m.computeBoundingBox(), m.geometry = w;
757
+ const f = ae(m), w = m.geometry;
758
+ f && (m.geometry = f), m.computeBoundingBox(), m.geometry = w;
758
759
  }
759
760
  D = m.boundingBox;
760
761
  }
@@ -762,8 +763,8 @@ const R = oe("debugprogressive"), ct = oe("noprogressive"), me = Symbol("Needle:
762
763
  const m = t;
763
764
  if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
764
765
  this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
765
- const f = t.getWorldPosition(this._tempWorldPosition);
766
- if (this._sphere.containsPoint(f)) {
766
+ const u = t.getWorldPosition(this._tempWorldPosition);
767
+ if (this._sphere.containsPoint(u)) {
767
768
  i.mesh_lod = 0, i.texture_lod = 0;
768
769
  return;
769
770
  }
@@ -773,50 +774,50 @@ const R = oe("debugprogressive"), ct = oe("noprogressive"), me = Symbol("Needle:
773
774
  return;
774
775
  }
775
776
  if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && m.isPerspectiveCamera && m.fov > 70) {
776
- const f = this._tempBox.min, g = this._tempBox.max;
777
- let _ = f.x, S = f.y, E = g.x, K = g.y;
778
- const le = 2, pe = 1.5, ce = (f.x + g.x) * 0.5, fe = (f.y + g.y) * 0.5;
779
- _ = (_ - ce) * le + ce, S = (S - fe) * le + fe, E = (E - ce) * le + ce, K = (K - fe) * le + fe;
780
- const Ue = _ < 0 && E > 0 ? 0 : Math.min(Math.abs(f.x), Math.abs(g.x)), Fe = S < 0 && K > 0 ? 0 : Math.min(Math.abs(f.y), Math.abs(g.y)), ye = Math.max(Ue, Fe);
777
+ const u = this._tempBox.min, g = this._tempBox.max;
778
+ let _ = u.x, S = u.y, E = g.x, K = g.y;
779
+ const le = 2, pe = 1.5, ce = (u.x + g.x) * 0.5, ue = (u.y + g.y) * 0.5;
780
+ _ = (_ - ce) * le + ce, S = (S - ue) * le + ue, E = (E - ce) * le + ce, K = (K - ue) * le + ue;
781
+ const Fe = _ < 0 && E > 0 ? 0 : Math.min(Math.abs(u.x), Math.abs(g.x)), We = S < 0 && K > 0 ? 0 : Math.min(Math.abs(u.y), Math.abs(g.y)), ye = Math.max(Fe, We);
781
782
  s.lastCentrality = (pe - ye) * (pe - ye) * (pe - ye);
782
783
  } else
783
784
  s.lastCentrality = 1;
784
- const u = this._tempBox.getSize(this._tempBoxSize);
785
- u.multiplyScalar(0.5), screen.availHeight > 0 && L > 0 && u.multiplyScalar(L / screen.availHeight), t.isPerspectiveCamera ? u.x *= t.aspect : t.isOrthographicCamera;
785
+ const f = this._tempBox.getSize(this._tempBoxSize);
786
+ f.multiplyScalar(0.5), screen.availHeight > 0 && L > 0 && f.multiplyScalar(L / screen.availHeight), t.isPerspectiveCamera ? f.x *= t.aspect : t.isOrthographicCamera;
786
787
  const w = t.matrixWorldInverse, $ = this._tempBox2;
787
788
  $.copy(D), $.applyMatrix4(e.matrixWorld), $.applyMatrix4(w);
788
789
  const B = $.getSize(this._tempBox2Size), T = Math.max(B.x, B.y);
789
- if (Math.max(u.x, u.y) != 0 && T != 0 && (u.z = B.z / Math.max(B.x, B.y) * Math.max(u.x, u.y)), s.lastScreenCoverage = Math.max(u.x, u.y, u.z), s.lastScreenspaceVolume.copy(u), s.lastScreenCoverage *= s.lastCentrality, R && C.debugDrawLine) {
790
- const f = this.tempMatrix.copy(this.projectionScreenMatrix);
791
- f.invert();
790
+ if (Math.max(f.x, f.y) != 0 && T != 0 && (f.z = B.z / Math.max(B.x, B.y) * Math.max(f.x, f.y)), s.lastScreenCoverage = Math.max(f.x, f.y, f.z), s.lastScreenspaceVolume.copy(f), s.lastScreenCoverage *= s.lastCentrality, R && C.debugDrawLine) {
791
+ const u = this.tempMatrix.copy(this.projectionScreenMatrix);
792
+ u.invert();
792
793
  const g = C.corner0, _ = C.corner1, S = C.corner2, E = C.corner3;
793
794
  g.copy(this._tempBox.min), _.copy(this._tempBox.max), _.x = g.x, S.copy(this._tempBox.max), S.y = g.y, E.copy(this._tempBox.max);
794
795
  const K = (g.z + E.z) * 0.5;
795
- g.z = _.z = S.z = E.z = K, g.applyMatrix4(f), _.applyMatrix4(f), S.applyMatrix4(f), E.applyMatrix4(f), C.debugDrawLine(g, _, 255), C.debugDrawLine(g, S, 255), C.debugDrawLine(_, E, 255), C.debugDrawLine(S, E, 255);
796
+ g.z = _.z = S.z = E.z = K, g.applyMatrix4(u), _.applyMatrix4(u), S.applyMatrix4(u), E.applyMatrix4(u), C.debugDrawLine(g, _, 255), C.debugDrawLine(g, S, 255), C.debugDrawLine(_, E, 255), C.debugDrawLine(S, E, 255);
796
797
  }
797
798
  let v = 999;
798
799
  if (l && s.lastScreenCoverage > 0) {
799
- for (let f = 0; f < l.length; f++)
800
- if (l[f].density / s.lastScreenCoverage < n) {
801
- v = f;
800
+ for (let u = 0; u < l.length; u++)
801
+ if (l[u].density / s.lastScreenCoverage < n) {
802
+ v = u;
802
803
  break;
803
804
  }
804
805
  }
805
806
  v < o && (o = v, a = !0);
806
807
  }
807
808
  if (a ? i.mesh_lod = o : i.mesh_lod = s.lastLodLevel_Mesh, R && i.mesh_lod != s.lastLodLevel_Mesh) {
808
- const u = l == null ? void 0 : l[i.mesh_lod];
809
- u && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${i.mesh_lod} (${u.density.toFixed(0)}) - ${e.name}`);
809
+ const f = l == null ? void 0 : l[i.mesh_lod];
810
+ f && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${i.mesh_lod} (${f.density.toFixed(0)}) - ${e.name}`);
810
811
  }
811
812
  if (x) {
812
813
  const m = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
813
814
  if (s.lastLodLevel_Texture < 0) {
814
815
  if (i.texture_lod = h.max_count - 1, R) {
815
- const u = h.lods[h.max_count - 1];
816
- R && console.log(`First Texture LOD ${i.texture_lod} (${u.max_height}px) - ${e.name}`);
816
+ const f = h.lods[h.max_count - 1];
817
+ R && console.log(`First Texture LOD ${i.texture_lod} (${f.max_height}px) - ${e.name}`);
817
818
  }
818
819
  } else {
819
- const u = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
820
+ const f = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
820
821
  let w = s.lastScreenCoverage * 4;
821
822
  ((k = this.context) == null ? void 0 : k.engine) === "model-viewer" && (w *= 1.5);
822
823
  const B = L / window.devicePixelRatio * w;
@@ -827,7 +828,7 @@ const R = oe("debugprogressive"), ct = oe("noprogressive"), me = Symbol("Needle:
827
828
  if (T = !0, i.texture_lod = U, i.texture_lod < s.lastLodLevel_Texture) {
828
829
  const O = v.max_height;
829
830
  R && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${i.texture_lod} = ${O}px
830
- Screensize: ${B.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${u.toFixed(1)}
831
+ Screensize: ${B.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${f.toFixed(1)}
831
832
  ${e.name}`);
832
833
  }
833
834
  break;
@@ -851,43 +852,43 @@ V.corner1 = new z();
851
852
  V.corner2 = new z();
852
853
  V.corner3 = new z();
853
854
  V._tempPtInside = new z();
854
- class ft {
855
+ class ut {
855
856
  constructor() {
856
857
  this.frames = 0, this.lastLodLevel_Mesh = -1, this.lastLodLevel_Texture = -1, this.lastScreenCoverage = 0, this.lastScreenspaceVolume = new z(), this.lastCentrality = 0;
857
858
  }
858
859
  }
859
- const Ae = Symbol("NEEDLE_mesh_lod"), ue = Symbol("NEEDLE_texture_lod");
860
+ const Ae = Symbol("NEEDLE_mesh_lod"), fe = Symbol("NEEDLE_texture_lod");
860
861
  let re = null;
861
- function $e() {
862
- const t = ut();
862
+ function Ne() {
863
+ const t = ft();
863
864
  t && (t.mapURLs(function(e) {
864
865
  return Pe(), e;
865
866
  }), Pe(), re == null || re.disconnect(), re = new MutationObserver((e) => {
866
867
  e.forEach((s) => {
867
868
  s.addedNodes.forEach((n) => {
868
- n instanceof HTMLElement && n.tagName.toLowerCase() === "model-viewer" && Ne(n);
869
+ n instanceof HTMLElement && n.tagName.toLowerCase() === "model-viewer" && Ue(n);
869
870
  });
870
871
  });
871
872
  }), re.observe(document, { childList: !0, subtree: !0 }));
872
873
  }
873
- function ut() {
874
+ function ft() {
874
875
  if (typeof customElements > "u")
875
876
  return null;
876
877
  const t = customElements.get("model-viewer");
877
878
  return t || (customElements.whenDefined("model-viewer").then(() => {
878
- console.debug("[gltf-progressive] model-viewer defined"), $e();
879
+ console.debug("[gltf-progressive] model-viewer defined"), Ne();
879
880
  }), null);
880
881
  }
881
882
  function Pe() {
882
883
  if (typeof document > "u")
883
884
  return;
884
885
  document.querySelectorAll("model-viewer").forEach((e) => {
885
- Ne(e);
886
+ Ue(e);
886
887
  });
887
888
  }
888
889
  const Ce = /* @__PURE__ */ new WeakSet();
889
890
  let dt = 0;
890
- function Ne(t) {
891
+ function Ue(t) {
891
892
  if (!t || Ce.has(t))
892
893
  return null;
893
894
  Ce.add(t), console.debug("[gltf-progressive] found new model-viewer..." + ++dt + `
@@ -943,16 +944,16 @@ class ht {
943
944
  return e.element;
944
945
  }
945
946
  tryParseTextureLOD(e, s) {
946
- if (s[ue] == !0)
947
+ if (s[fe] == !0)
947
948
  return;
948
- s[ue] = !0;
949
+ s[fe] = !0;
949
950
  const n = this.tryGetCurrentGLTF(e), i = this.tryGetCurrentModelViewer(e), r = this.getUrl(i);
950
951
  if (r && n && s.material) {
951
952
  let o = function(c) {
952
953
  var d, h, x;
953
- if (c[ue] == !0)
954
+ if (c[fe] == !0)
954
955
  return;
955
- c[ue] = !0, c.userData && (c.userData.LOD = -1);
956
+ c[fe] = !0, c.userData && (c.userData.LOD = -1);
956
957
  const l = Object.keys(c);
957
958
  for (let L = 0; L < l.length; L++) {
958
959
  const D = l[L], k = c[D];
@@ -960,13 +961,13 @@ class ht {
960
961
  const m = (h = (d = k.userData) == null ? void 0 : d.associations) == null ? void 0 : h.textures;
961
962
  if (m == null)
962
963
  continue;
963
- const u = n.parser.json.textures[m];
964
- if (!u) {
964
+ const f = n.parser.json.textures[m];
965
+ if (!f) {
965
966
  console.warn("Texture data not found for texture index " + m);
966
967
  continue;
967
968
  }
968
- if ((x = u == null ? void 0 : u.extensions) != null && x[W]) {
969
- const w = u.extensions[W];
969
+ if ((x = f == null ? void 0 : f.extensions) != null && x[W]) {
970
+ const w = f.extensions[W];
970
971
  w && r && P.registerTexture(r, k, w.lods.length, m, w);
971
972
  }
972
973
  }
@@ -996,20 +997,20 @@ class ht {
996
997
  }
997
998
  }
998
999
  function gt(t, e, s, n) {
999
- Be(e), Re(s), Ie(s, {
1000
+ Re(e), Ie(s), Ge(s, {
1000
1001
  progressive: !0,
1001
1002
  ...n == null ? void 0 : n.hints
1002
1003
  }), s.register((r) => new P(r, t));
1003
1004
  const i = V.get(e);
1004
1005
  return (n == null ? void 0 : n.enableLODsManager) !== !1 && i.enable(), i;
1005
1006
  }
1006
- $e();
1007
+ Ne();
1007
1008
  if (!it) {
1008
1009
  const t = {
1009
1010
  gltfProgressive: {
1010
1011
  useNeedleProgressive: gt,
1011
1012
  LODsManager: V,
1012
- configureLoader: Ie,
1013
+ configureLoader: Ge,
1013
1014
  getRaycastMesh: ae,
1014
1015
  useRaycastMeshes: ot
1015
1016
  }
@@ -1023,9 +1024,9 @@ if (!it) {
1023
1024
  export {
1024
1025
  V as L,
1025
1026
  P as N,
1026
- Re as a,
1027
- Ie as b,
1028
- Be as c,
1027
+ Ie as a,
1028
+ Ge as b,
1029
+ Re as c,
1029
1030
  et as d,
1030
1031
  ae as g,
1031
1032
  je as s
@@ -1,8 +1,8 @@
1
- import{B as le,M as H,T as ee,a as Ne,V as $,b as Oe,S as Ue,c as Se,d as Fe,C as ze}from"./three.light.min.js";import{D as Ve,K as qe,G as ge,M as Ke}from"./three-examples.light.min.js";const He="";globalThis.GLTF_PROGRESSIVE_VERSION=He,console.debug("[gltf-progressive] version -");let G="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",J="https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";const Xe=G,Ye=J,Je=new URL(G+"draco_decoder.js");fetch(Je,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(t=>{console.debug(`Failed to fetch remote Draco decoder from ${G} (offline: ${typeof navigator<"u"?navigator.onLine:"unknown"})`),G===Xe&&Te("./include/draco/"),J===Ye&&Ee("./include/ktx2/")}).finally(()=>{Ae()});function Te(t){G=t,A&&A[me]!=G?(console.debug("Updating Draco decoder path to "+t),A[me]=G,A.setDecoderPath(G),A.preload()):console.debug("Setting Draco decoder path to "+t)}function Ee(t){J=t,C&&C.transcoderPath!=J?(console.debug("Updating KTX2 transcoder path to "+t),C.setTranscoderPath(J),C.init()):console.debug("Setting KTX2 transcoder path to "+t)}const me=Symbol("dracoDecoderPath");let A,ae,C;function Ae(){A||(A=new Ve,A[me]=G,A.setDecoderPath(G),A.setDecoderConfig({type:"js"}),A.preload()),C||(C=new qe,C.setTranscoderPath(J),C.init()),ae||(ae=Ke)}function pe(t){return Ae(),t?C.detectSupport(t):t!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:A,ktx2Loader:C,meshoptDecoder:ae}}function ve(t){t.dracoLoader||t.setDRACOLoader(A),t.ktx2Loader||t.setKTX2Loader(C),t.meshoptDecoder||t.setMeshoptDecoder(ae)}const ye=new WeakMap;function xe(t,e){let r=ye.get(t);r?r=Object.assign(r,e):r=e,ye.set(t,r)}const Pe=ge.prototype.load;function Qe(...t){const e=ye.get(this);let r=t[0];const n=new URL(r,window.location.href);if(n.hostname.endsWith("needle.tools")){const s=e?.progressive!==void 0?e.progressive:!0,o=e!=null&&e.usecase?e.usecase:"default";s?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${o}`:this.requestHeader.Accept=`*/*;usecase=${o}`,r=n.toString()}return t[0]=r,Pe?.call(this,...t)}ge.prototype.load=Qe,te("debugprogressive");function te(t){if(typeof window>"u")return!1;const e=new URL(window.location.href).searchParams.get(t);return e==null||e==="0"||e==="false"?!1:e===""?!0:e}function Ze(t,e){if(e===void 0||e.startsWith("./")||e.startsWith("http")||t===void 0)return e;const r=t.lastIndexOf("/");if(r>=0){const n=t.substring(0,r+1);for(;n.endsWith("/")&&e.startsWith("/");)e=e.substring(1);return n+e}return e}let ue;function et(){return ue!==void 0||(ue=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),te("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",ue)),ue}const tt=typeof window>"u"&&typeof document>"u",Le=Symbol("needle:raycast-mesh");function Q(t){return t?.[Le]instanceof le?t[Le]:null}function rt(t,e){if((t.type==="Mesh"||t.type==="SkinnedMesh")&&!Q(t)){const r=ot(e);r.userData={isRaycastMesh:!0},t[Le]=r}}function st(t=!0){if(t){if(re)return;const e=re=H.prototype.raycast;H.prototype.raycast=function(r,n){const s=this,o=Q(s);let i;o&&s.isMesh&&(i=s.geometry,s.geometry=o),e.call(this,r,n),i&&(s.geometry=i)}}else{if(!re)return;H.prototype.raycast=re,re=null}}let re=null;function ot(t){const e=new le;for(const r in t.attributes)e.setAttribute(r,t.getAttribute(r));return e.setIndex(t.getIndex()),e}const F=new Array,N="NEEDLE_progressive",v=te("debugprogressive"),De=Symbol("needle-progressive-texture"),se=new Map,we=new Set;if(v){let t=function(){e+=1,console.log("Toggle LOD level",e,se),se.forEach((s,o)=>{for(const i of s.keys){const a=o[i];if(a!=null)if(a.isBufferGeometry===!0){const u=S.getMeshLODInformation(a),l=u?Math.min(e,u.lods.length):0;o["DEBUG:LOD"]=l,u&&(r=Math.max(r,u.lods.length-1))}else o.isMaterial===!0&&(o["DEBUG:LOD"]=e)}}),e>=r&&(e=-1)},e=-1,r=2,n=!1;window.addEventListener("keyup",s=>{s.key==="p"&&t(),s.key==="w"&&(n=!n,we&&we.forEach(o=>{o.name!="BackgroundCubeMaterial"&&o.glyphMap==null&&"wireframe"in o&&(o.wireframe=n)}))})}function Be(t,e,r){var n;if(!v)return;se.has(t)||se.set(t,{keys:[],sourceId:r});const s=se.get(t);((n=s?.keys)==null?void 0:n.includes(e))==!1&&s.keys.push(e)}const w=class{constructor(t,e){this.loadMesh=r=>{var n,s;if(this._isLoadingMesh)return null;const o=(s=(n=this.parser.json.meshes[r])==null?void 0:n.extensions)==null?void 0:s[N];return o?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",r).then(i=>{var a;return this._isLoadingMesh=!1,i&&w.registerMesh(this.url,o.guid,i,(a=o.lods)==null?void 0:a.length,void 0,o),i})):null},v&&console.log("Progressive extension registered for",e),this.parser=t,this.url=e}get name(){return N}static getMeshLODInformation(t){const e=this.getAssignedLODInformation(t);return e!=null&&e.key?this.lodInfos.get(e.key):null}static getMaterialMinMaxLODsCount(t,e){const r=this,n="LODS:minmax",s=t[n];if(s!=null)return s;if(e||(e={min_count:1/0,max_count:0,lods:[]}),Array.isArray(t)){for(const i of t)this.getMaterialMinMaxLODsCount(i,e);return t[n]=e,e}if(v==="verbose"&&console.log("getMaterialMinMaxLODsCount",t),t.type==="ShaderMaterial"||t.type==="RawShaderMaterial"){const i=t;for(const a of Object.keys(i.uniforms)){const u=i.uniforms[a].value;u?.isTexture===!0&&o(u,e)}}else if(t.isMaterial)for(const i of Object.keys(t)){const a=t[i];a?.isTexture===!0&&o(a,e)}return t[n]=e,e;function o(i,a){const u=r.getAssignedLODInformation(i);if(u){const l=r.lodInfos.get(u.key);if(l&&l.lods){a.min_count=Math.min(a.min_count,l.lods.length),a.max_count=Math.max(a.max_count,l.lods.length);for(let h=0;h<l.lods.length;h++){const f=l.lods[h];f.width&&(a.lods[h]=a.lods[h]||{min_height:1/0,max_height:0},a.lods[h].min_height=Math.min(a.lods[h].min_height,f.height),a.lods[h].max_height=Math.max(a.lods[h].max_height,f.height))}}}}}static hasLODLevelAvailable(t,e){var r;if(Array.isArray(t)){for(const o of t)if(this.hasLODLevelAvailable(o,e))return!0;return!1}if(t.isMaterial===!0){for(const o of Object.keys(t)){const i=t[o];if(i&&i.isTexture&&this.hasLODLevelAvailable(i,e))return!0}return!1}else if(t.isGroup===!0){for(const o of t.children)if(o.isMesh===!0&&this.hasLODLevelAvailable(o,e))return!0}let n,s;if(t.isMesh?n=t.geometry:(t.isBufferGeometry||t.isTexture)&&(n=t),n&&(r=n?.userData)!=null&&r.LODS){const o=n.userData.LODS;if(s=this.lodInfos.get(o.key),e===void 0)return s!=null;if(s)return Array.isArray(s.lods)?e<s.lods.length:e===0}return!1}static assignMeshLOD(t,e){var r;if(!t)return Promise.resolve(null);if(t instanceof H||t.isMesh===!0){const n=t.geometry,s=this.getAssignedLODInformation(n);if(!s)return Promise.resolve(null);for(const o of F)(r=o.onBeforeGetLODMesh)==null||r.call(o,t,e);return t["LOD:requested level"]=e,w.getOrLoadLOD(n,e).then(o=>{if(Array.isArray(o)){const i=s.index||0;o=o[i]}return t["LOD:requested level"]===e&&(delete t["LOD:requested level"],o&&n!=o&&(o?.isBufferGeometry?(t.geometry=o,v&&Be(t,"geometry",s.url)):v&&console.error("Invalid LOD geometry",o))),o}).catch(o=>(console.error("Error loading mesh LOD",t,o),null))}else v&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",t);return Promise.resolve(null)}static assignTextureLOD(t,e=0){if(!t)return Promise.resolve(null);if(t.isMesh===!0){const r=t;if(Array.isArray(r.material)){const n=new Array;for(const s of r.material){const o=this.assignTextureLOD(s,e);n.push(o)}return Promise.all(n).then(s=>{const o=new Array;for(const i of s)Array.isArray(i)&&o.push(...i);return o})}else return this.assignTextureLOD(r.material,e)}if(t.isMaterial===!0){const r=t,n=[],s=new Array;if(v&&we.add(r),r.uniforms&&(r.isRawShaderMaterial||r.isShaderMaterial===!0)){const o=r;for(const i of Object.keys(o.uniforms)){const a=o.uniforms[i].value;if(a?.isTexture===!0){const u=this.assignTextureLODForSlot(a,e,r,i).then(l=>(l&&o.uniforms[i].value!=l&&(o.uniforms[i].value=l,o.uniformsNeedUpdate=!0),l));n.push(u),s.push(i)}}}else for(const o of Object.keys(r)){const i=r[o];if(i?.isTexture===!0){const a=this.assignTextureLODForSlot(i,e,r,o);n.push(a),s.push(o)}}return Promise.all(n).then(o=>{const i=new Array;for(let a=0;a<o.length;a++){const u=o[a],l=s[a];u&&u.isTexture===!0?i.push({material:r,slot:l,texture:u,level:e}):i.push({material:r,slot:l,texture:null,level:e})}return i})}if(t instanceof ee||t.isTexture===!0){const r=t;return this.assignTextureLODForSlot(r,e,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(t,e,r,n){return t?.isTexture!==!0?Promise.resolve(null):n==="glyphMap"?Promise.resolve(t):w.getOrLoadLOD(t,e).then(s=>{if(Array.isArray(s))return null;if(s?.isTexture===!0){if(s!=t){if(r&&n){const o=r[n];if(o&&!v){const i=this.getAssignedLODInformation(o);if(i&&i?.level<e)return v==="verbose"&&console.warn("Assigned texture level is already higher: ",i.level,e,r,o,s),null}r[n]=s}if(v&&n&&r){const o=this.getAssignedLODInformation(t);o?Be(r,n,o.url):console.warn("No LOD info for texture",t)}}return s}else v=="verbose"&&console.warn("No LOD found for",t,e);return null}).catch(s=>(console.error("Error loading LOD",t,s),null))}afterRoot(t){var e,r;return v&&console.log("AFTER",this.url,t),(e=this.parser.json.textures)==null||e.forEach((n,s)=>{var o;if(n!=null&&n.extensions){const i=n?.extensions[N];if(i){if(!i.lods){v&&console.warn("Texture has no LODs",i);return}let a=!1;for(const u of this.parser.associations.keys())if(u.isTexture===!0){const l=this.parser.associations.get(u);l?.textures===s&&(a=!0,w.registerTexture(this.url,u,(o=i.lods)==null?void 0:o.length,s,i))}a||this.parser.getDependency("texture",s).then(u=>{var l;u&&w.registerTexture(this.url,u,(l=i.lods)==null?void 0:l.length,s,i)})}}}),(r=this.parser.json.meshes)==null||r.forEach((n,s)=>{if(n!=null&&n.extensions){const o=n?.extensions[N];if(o&&o.lods){for(const i of this.parser.associations.keys())if(i.isMesh){const a=this.parser.associations.get(i);a?.meshes===s&&w.registerMesh(this.url,o.guid,i,o.lods.length,a.primitives,o)}}}}),null}static async getOrLoadLOD(t,e){var r,n,s,o;const i=v=="verbose",a=t.userData.LODS;if(!a)return null;const u=a?.key;let l;if(t.isTexture===!0){const h=t;h.source&&h.source[De]&&(l=h.source[De])}if(l||(l=w.lodInfos.get(u)),l){if(e>0){let p=!1;const E=Array.isArray(l.lods);if(E&&e>=l.lods.length?p=!0:E||(p=!0),p)return this.lowresCache.get(u)}const h=Array.isArray(l.lods)?(r=l.lods[e])==null?void 0:r.path:l.lods;if(!h)return v&&!l["missing:uri"]&&(l["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+e,l)),null;const f=Ze(a.url,h);if(f.endsWith(".glb")||f.endsWith(".gltf")){if(!l.guid)return console.warn("missing pointer for glb/gltf texture",l),null;const p=f+"_"+l.guid,E=this.previouslyLoaded.get(p);if(E!==void 0){i&&console.log(`LOD ${e} was already loading/loaded: ${p}`);let c=await E.catch(b=>(console.error(`Error loading LOD ${e} from ${f}
2
- `,b),null)),M=!1;if(c==null||(c instanceof ee&&t instanceof ee?(n=c.image)!=null&&n.data||(s=c.source)!=null&&s.data?c=this.copySettings(t,c):(M=!0,this.previouslyLoaded.delete(p)):c instanceof le&&t instanceof le&&((o=c.attributes.position)!=null&&o.array||(M=!0,this.previouslyLoaded.delete(p)))),!M)return c}const D=l,y=new Promise(async(c,M)=>{const b=new ge;ve(b),v&&(await new Promise(m=>setTimeout(m,1e3)),i&&console.warn("Start loading (delayed) "+f,D.guid));let B=f;if(D&&Array.isArray(D.lods)){const m=D.lods[e];m.hash&&(B+="?v="+m.hash)}const _=await b.loadAsync(B).catch(m=>(console.error(`Error loading LOD ${e} from ${f}
3
- `,m),null));if(!_)return null;const I=_.parser;i&&console.log("Loading finished "+f,D.guid);let g=0;if(_.parser.json.textures){let m=!1;for(const d of _.parser.json.textures){if(d!=null&&d.extensions){const L=d?.extensions[N];if(L!=null&&L.guid&&L.guid===D.guid){m=!0;break}}g++}if(m){let d=await I.getDependency("texture",g);return d&&w.assignLODInformation(a.url,d,u,e,void 0,void 0),i&&console.log('change "'+t.name+'" \u2192 "'+d.name+'"',f,g,d,p),t instanceof ee&&(d=this.copySettings(t,d)),d&&(d.guid=D.guid),c(d)}else v&&console.warn("Could not find texture with guid",D.guid,_.parser.json)}if(g=0,_.parser.json.meshes){let m=!1;for(const d of _.parser.json.meshes){if(d!=null&&d.extensions){const L=d?.extensions[N];if(L!=null&&L.guid&&L.guid===D.guid){m=!0;break}}g++}if(m){const d=await I.getDependency("mesh",g),L=D;if(i&&console.log(`Loaded Mesh "${d.name}"`,f,g,d,p),d.isMesh===!0){const O=d.geometry;return w.assignLODInformation(a.url,O,u,e,void 0,L.density),c(O)}else{const O=new Array;for(let j=0;j<d.children.length;j++){const K=d.children[j];if(K.isMesh===!0){const Y=K.geometry;w.assignLODInformation(a.url,Y,u,e,j,L.density),O.push(Y)}}return c(O)}}else v&&console.warn("Could not find mesh with guid",D.guid,_.parser.json)}return c(null)});return this.previouslyLoaded.set(p,y),await y}else if(t instanceof ee){i&&console.log("Load texture from uri: "+f);const p=await new Ne().loadAsync(f);return p?(p.guid=l.guid,p.flipY=!1,p.needsUpdate=!0,p.colorSpace=t.colorSpace,i&&console.log(l,p)):v&&console.warn("failed loading",f),p}}else v&&console.warn(`Can not load LOD ${e}: no LOD info found for "${u}" ${t.name}`,t.type);return null}static assignLODInformation(t,e,r,n,s,o){if(!e)return;e.userData||(e.userData={});const i=new nt(t,r,n,s,o);e.userData.LODS=i}static getAssignedLODInformation(t){var e;return((e=t?.userData)==null?void 0:e.LODS)||null}static copySettings(t,e){return e?(v&&console.warn(`Copy texture settings
1
+ import{B as le,M as H,T as ee,a as Ue,V as $,b as Oe,S as Fe,c as Se,d as ze,C as Ve}from"./three.light.min.js";import{D as qe,K as Ke,G as fe,M as He}from"./three-examples.light.min.js";const Xe="";globalThis.GLTF_PROGRESSIVE_VERSION=Xe,console.debug("[gltf-progressive] version -");let G="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",J="https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";const Ye=G,Je=J,Te=new URL(G+"draco_decoder.js");Te.searchParams.append("range","true"),fetch(Te,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(t=>{console.debug(`Failed to fetch remote Draco decoder from ${G} (offline: ${typeof navigator<"u"?navigator.onLine:"unknown"})`),G===Ye&&Ee("./include/draco/"),J===Je&&Ae("./include/ktx2/")}).finally(()=>{Pe()});function Ee(t){G=t,A&&A[me]!=G?(console.debug("Updating Draco decoder path to "+t),A[me]=G,A.setDecoderPath(G),A.preload()):console.debug("Setting Draco decoder path to "+t)}function Ae(t){J=t,C&&C.transcoderPath!=J?(console.debug("Updating KTX2 transcoder path to "+t),C.setTranscoderPath(J),C.init()):console.debug("Setting KTX2 transcoder path to "+t)}const me=Symbol("dracoDecoderPath");let A,ae,C;function Pe(){A||(A=new qe,A[me]=G,A.setDecoderPath(G),A.setDecoderConfig({type:"js"}),A.preload()),C||(C=new Ke,C.setTranscoderPath(J),C.init()),ae||(ae=He)}function pe(t){return Pe(),t?C.detectSupport(t):t!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:A,ktx2Loader:C,meshoptDecoder:ae}}function ve(t){t.dracoLoader||t.setDRACOLoader(A),t.ktx2Loader||t.setKTX2Loader(C),t.meshoptDecoder||t.setMeshoptDecoder(ae)}const ye=new WeakMap;function xe(t,e){let r=ye.get(t);r?r=Object.assign(r,e):r=e,ye.set(t,r)}const Be=fe.prototype.load;function Qe(...t){const e=ye.get(this);let r=t[0];const n=new URL(r,window.location.href);if(n.hostname.endsWith("needle.tools")){const s=e?.progressive!==void 0?e.progressive:!0,o=e!=null&&e.usecase?e.usecase:"default";s?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${o}`:this.requestHeader.Accept=`*/*;usecase=${o}`,r=n.toString()}return t[0]=r,Be?.call(this,...t)}fe.prototype.load=Qe,te("debugprogressive");function te(t){if(typeof window>"u")return!1;const e=new URL(window.location.href).searchParams.get(t);return e==null||e==="0"||e==="false"?!1:e===""?!0:e}function Ze(t,e){if(e===void 0||e.startsWith("./")||e.startsWith("http")||t===void 0)return e;const r=t.lastIndexOf("/");if(r>=0){const n=t.substring(0,r+1);for(;n.endsWith("/")&&e.startsWith("/");)e=e.substring(1);return n+e}return e}let ue;function et(){return ue!==void 0||(ue=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),te("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",ue)),ue}const tt=typeof window>"u"&&typeof document>"u",Le=Symbol("needle:raycast-mesh");function Q(t){return t?.[Le]instanceof le?t[Le]:null}function rt(t,e){if((t.type==="Mesh"||t.type==="SkinnedMesh")&&!Q(t)){const r=ot(e);r.userData={isRaycastMesh:!0},t[Le]=r}}function st(t=!0){if(t){if(re)return;const e=re=H.prototype.raycast;H.prototype.raycast=function(r,n){const s=this,o=Q(s);let i;o&&s.isMesh&&(i=s.geometry,s.geometry=o),e.call(this,r,n),i&&(s.geometry=i)}}else{if(!re)return;H.prototype.raycast=re,re=null}}let re=null;function ot(t){const e=new le;for(const r in t.attributes)e.setAttribute(r,t.getAttribute(r));return e.setIndex(t.getIndex()),e}const F=new Array,N="NEEDLE_progressive",v=te("debugprogressive"),De=Symbol("needle-progressive-texture"),se=new Map,we=new Set;if(v){let t=function(){e+=1,console.log("Toggle LOD level",e,se),se.forEach((s,o)=>{for(const i of s.keys){const a=o[i];if(a!=null)if(a.isBufferGeometry===!0){const u=S.getMeshLODInformation(a),l=u?Math.min(e,u.lods.length):0;o["DEBUG:LOD"]=l,u&&(r=Math.max(r,u.lods.length-1))}else o.isMaterial===!0&&(o["DEBUG:LOD"]=e)}}),e>=r&&(e=-1)},e=-1,r=2,n=!1;window.addEventListener("keyup",s=>{s.key==="p"&&t(),s.key==="w"&&(n=!n,we&&we.forEach(o=>{o.name!="BackgroundCubeMaterial"&&o.glyphMap==null&&"wireframe"in o&&(o.wireframe=n)}))})}function Ie(t,e,r){var n;if(!v)return;se.has(t)||se.set(t,{keys:[],sourceId:r});const s=se.get(t);((n=s?.keys)==null?void 0:n.includes(e))==!1&&s.keys.push(e)}const w=class{constructor(t,e){this.loadMesh=r=>{var n,s;if(this._isLoadingMesh)return null;const o=(s=(n=this.parser.json.meshes[r])==null?void 0:n.extensions)==null?void 0:s[N];return o?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",r).then(i=>{var a;return this._isLoadingMesh=!1,i&&w.registerMesh(this.url,o.guid,i,(a=o.lods)==null?void 0:a.length,void 0,o),i})):null},v&&console.log("Progressive extension registered for",e),this.parser=t,this.url=e}get name(){return N}static getMeshLODInformation(t){const e=this.getAssignedLODInformation(t);return e!=null&&e.key?this.lodInfos.get(e.key):null}static getMaterialMinMaxLODsCount(t,e){const r=this,n="LODS:minmax",s=t[n];if(s!=null)return s;if(e||(e={min_count:1/0,max_count:0,lods:[]}),Array.isArray(t)){for(const i of t)this.getMaterialMinMaxLODsCount(i,e);return t[n]=e,e}if(v==="verbose"&&console.log("getMaterialMinMaxLODsCount",t),t.type==="ShaderMaterial"||t.type==="RawShaderMaterial"){const i=t;for(const a of Object.keys(i.uniforms)){const u=i.uniforms[a].value;u?.isTexture===!0&&o(u,e)}}else if(t.isMaterial)for(const i of Object.keys(t)){const a=t[i];a?.isTexture===!0&&o(a,e)}return t[n]=e,e;function o(i,a){const u=r.getAssignedLODInformation(i);if(u){const l=r.lodInfos.get(u.key);if(l&&l.lods){a.min_count=Math.min(a.min_count,l.lods.length),a.max_count=Math.max(a.max_count,l.lods.length);for(let h=0;h<l.lods.length;h++){const g=l.lods[h];g.width&&(a.lods[h]=a.lods[h]||{min_height:1/0,max_height:0},a.lods[h].min_height=Math.min(a.lods[h].min_height,g.height),a.lods[h].max_height=Math.max(a.lods[h].max_height,g.height))}}}}}static hasLODLevelAvailable(t,e){var r;if(Array.isArray(t)){for(const o of t)if(this.hasLODLevelAvailable(o,e))return!0;return!1}if(t.isMaterial===!0){for(const o of Object.keys(t)){const i=t[o];if(i&&i.isTexture&&this.hasLODLevelAvailable(i,e))return!0}return!1}else if(t.isGroup===!0){for(const o of t.children)if(o.isMesh===!0&&this.hasLODLevelAvailable(o,e))return!0}let n,s;if(t.isMesh?n=t.geometry:(t.isBufferGeometry||t.isTexture)&&(n=t),n&&(r=n?.userData)!=null&&r.LODS){const o=n.userData.LODS;if(s=this.lodInfos.get(o.key),e===void 0)return s!=null;if(s)return Array.isArray(s.lods)?e<s.lods.length:e===0}return!1}static assignMeshLOD(t,e){var r;if(!t)return Promise.resolve(null);if(t instanceof H||t.isMesh===!0){const n=t.geometry,s=this.getAssignedLODInformation(n);if(!s)return Promise.resolve(null);for(const o of F)(r=o.onBeforeGetLODMesh)==null||r.call(o,t,e);return t["LOD:requested level"]=e,w.getOrLoadLOD(n,e).then(o=>{if(Array.isArray(o)){const i=s.index||0;o=o[i]}return t["LOD:requested level"]===e&&(delete t["LOD:requested level"],o&&n!=o&&(o?.isBufferGeometry?(t.geometry=o,v&&Ie(t,"geometry",s.url)):v&&console.error("Invalid LOD geometry",o))),o}).catch(o=>(console.error("Error loading mesh LOD",t,o),null))}else v&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",t);return Promise.resolve(null)}static assignTextureLOD(t,e=0){if(!t)return Promise.resolve(null);if(t.isMesh===!0){const r=t;if(Array.isArray(r.material)){const n=new Array;for(const s of r.material){const o=this.assignTextureLOD(s,e);n.push(o)}return Promise.all(n).then(s=>{const o=new Array;for(const i of s)Array.isArray(i)&&o.push(...i);return o})}else return this.assignTextureLOD(r.material,e)}if(t.isMaterial===!0){const r=t,n=[],s=new Array;if(v&&we.add(r),r.uniforms&&(r.isRawShaderMaterial||r.isShaderMaterial===!0)){const o=r;for(const i of Object.keys(o.uniforms)){const a=o.uniforms[i].value;if(a?.isTexture===!0){const u=this.assignTextureLODForSlot(a,e,r,i).then(l=>(l&&o.uniforms[i].value!=l&&(o.uniforms[i].value=l,o.uniformsNeedUpdate=!0),l));n.push(u),s.push(i)}}}else for(const o of Object.keys(r)){const i=r[o];if(i?.isTexture===!0){const a=this.assignTextureLODForSlot(i,e,r,o);n.push(a),s.push(o)}}return Promise.all(n).then(o=>{const i=new Array;for(let a=0;a<o.length;a++){const u=o[a],l=s[a];u&&u.isTexture===!0?i.push({material:r,slot:l,texture:u,level:e}):i.push({material:r,slot:l,texture:null,level:e})}return i})}if(t instanceof ee||t.isTexture===!0){const r=t;return this.assignTextureLODForSlot(r,e,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(t,e,r,n){return t?.isTexture!==!0?Promise.resolve(null):n==="glyphMap"?Promise.resolve(t):w.getOrLoadLOD(t,e).then(s=>{if(Array.isArray(s))return null;if(s?.isTexture===!0){if(s!=t){if(r&&n){const o=r[n];if(o&&!v){const i=this.getAssignedLODInformation(o);if(i&&i?.level<e)return v==="verbose"&&console.warn("Assigned texture level is already higher: ",i.level,e,r,o,s),null}r[n]=s}if(v&&n&&r){const o=this.getAssignedLODInformation(t);o?Ie(r,n,o.url):console.warn("No LOD info for texture",t)}}return s}else v=="verbose"&&console.warn("No LOD found for",t,e);return null}).catch(s=>(console.error("Error loading LOD",t,s),null))}afterRoot(t){var e,r;return v&&console.log("AFTER",this.url,t),(e=this.parser.json.textures)==null||e.forEach((n,s)=>{var o;if(n!=null&&n.extensions){const i=n?.extensions[N];if(i){if(!i.lods){v&&console.warn("Texture has no LODs",i);return}let a=!1;for(const u of this.parser.associations.keys())if(u.isTexture===!0){const l=this.parser.associations.get(u);l?.textures===s&&(a=!0,w.registerTexture(this.url,u,(o=i.lods)==null?void 0:o.length,s,i))}a||this.parser.getDependency("texture",s).then(u=>{var l;u&&w.registerTexture(this.url,u,(l=i.lods)==null?void 0:l.length,s,i)})}}}),(r=this.parser.json.meshes)==null||r.forEach((n,s)=>{if(n!=null&&n.extensions){const o=n?.extensions[N];if(o&&o.lods){for(const i of this.parser.associations.keys())if(i.isMesh){const a=this.parser.associations.get(i);a?.meshes===s&&w.registerMesh(this.url,o.guid,i,o.lods.length,a.primitives,o)}}}}),null}static async getOrLoadLOD(t,e){var r,n,s,o;const i=v=="verbose",a=t.userData.LODS;if(!a)return null;const u=a?.key;let l;if(t.isTexture===!0){const h=t;h.source&&h.source[De]&&(l=h.source[De])}if(l||(l=w.lodInfos.get(u)),l){if(e>0){let p=!1;const E=Array.isArray(l.lods);if(E&&e>=l.lods.length?p=!0:E||(p=!0),p)return this.lowresCache.get(u)}const h=Array.isArray(l.lods)?(r=l.lods[e])==null?void 0:r.path:l.lods;if(!h)return v&&!l["missing:uri"]&&(l["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+e,l)),null;const g=Ze(a.url,h);if(g.endsWith(".glb")||g.endsWith(".gltf")){if(!l.guid)return console.warn("missing pointer for glb/gltf texture",l),null;const p=g+"_"+l.guid,E=this.previouslyLoaded.get(p);if(E!==void 0){i&&console.log(`LOD ${e} was already loading/loaded: ${p}`);let c=await E.catch(b=>(console.error(`Error loading LOD ${e} from ${g}
2
+ `,b),null)),M=!1;if(c==null||(c instanceof ee&&t instanceof ee?(n=c.image)!=null&&n.data||(s=c.source)!=null&&s.data?c=this.copySettings(t,c):(M=!0,this.previouslyLoaded.delete(p)):c instanceof le&&t instanceof le&&((o=c.attributes.position)!=null&&o.array||(M=!0,this.previouslyLoaded.delete(p)))),!M)return c}const D=l,y=new Promise(async(c,M)=>{const b=new fe;ve(b),v&&(await new Promise(m=>setTimeout(m,1e3)),i&&console.warn("Start loading (delayed) "+g,D.guid));let B=g;if(D&&Array.isArray(D.lods)){const m=D.lods[e];m.hash&&(B+="?v="+m.hash)}const _=await b.loadAsync(B).catch(m=>(console.error(`Error loading LOD ${e} from ${g}
3
+ `,m),null));if(!_)return null;const I=_.parser;i&&console.log("Loading finished "+g,D.guid);let f=0;if(_.parser.json.textures){let m=!1;for(const d of _.parser.json.textures){if(d!=null&&d.extensions){const L=d?.extensions[N];if(L!=null&&L.guid&&L.guid===D.guid){m=!0;break}}f++}if(m){let d=await I.getDependency("texture",f);return d&&w.assignLODInformation(a.url,d,u,e,void 0,void 0),i&&console.log('change "'+t.name+'" \u2192 "'+d.name+'"',g,f,d,p),t instanceof ee&&(d=this.copySettings(t,d)),d&&(d.guid=D.guid),c(d)}else v&&console.warn("Could not find texture with guid",D.guid,_.parser.json)}if(f=0,_.parser.json.meshes){let m=!1;for(const d of _.parser.json.meshes){if(d!=null&&d.extensions){const L=d?.extensions[N];if(L!=null&&L.guid&&L.guid===D.guid){m=!0;break}}f++}if(m){const d=await I.getDependency("mesh",f),L=D;if(i&&console.log(`Loaded Mesh "${d.name}"`,g,f,d,p),d.isMesh===!0){const O=d.geometry;return w.assignLODInformation(a.url,O,u,e,void 0,L.density),c(O)}else{const O=new Array;for(let j=0;j<d.children.length;j++){const K=d.children[j];if(K.isMesh===!0){const Y=K.geometry;w.assignLODInformation(a.url,Y,u,e,j,L.density),O.push(Y)}}return c(O)}}else v&&console.warn("Could not find mesh with guid",D.guid,_.parser.json)}return c(null)});return this.previouslyLoaded.set(p,y),await y}else if(t instanceof ee){i&&console.log("Load texture from uri: "+g);const p=await new Ue().loadAsync(g);return p?(p.guid=l.guid,p.flipY=!1,p.needsUpdate=!0,p.colorSpace=t.colorSpace,i&&console.log(l,p)):v&&console.warn("failed loading",g),p}}else v&&console.warn(`Can not load LOD ${e}: no LOD info found for "${u}" ${t.name}`,t.type);return null}static assignLODInformation(t,e,r,n,s,o){if(!e)return;e.userData||(e.userData={});const i=new nt(t,r,n,s,o);e.userData.LODS=i}static getAssignedLODInformation(t){var e;return((e=t?.userData)==null?void 0:e.LODS)||null}static copySettings(t,e){return e?(v&&console.warn(`Copy texture settings
4
4
  `,t.uuid,`
5
- `,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}};let S=w;S.registerTexture=(t,e,r,n,s)=>{if(v&&console.log("> Progressive: register texture",n,e.name,e.uuid,e,s),!e){v&&console.error("gltf-progressive: Register texture without texture");return}e.source&&(e.source[De]=s);const o=s.guid;w.assignLODInformation(t,e,o,r,n,void 0),w.lodInfos.set(o,s),w.lowresCache.set(o,e)},S.registerMesh=(t,e,r,n,s,o)=>{var i;v&&console.log("> Progressive: register mesh",s,r.name,o,r.uuid,r);const a=r.geometry;if(!a){v&&console.warn("gltf-progressive: Register mesh without geometry");return}a.userData||(a.userData={}),w.assignLODInformation(t,a,e,n,s,o.density),w.lodInfos.set(e,o);let u=w.lowresCache.get(e);u?u.push(r.geometry):u=[r.geometry],w.lowresCache.set(e,u),n>0&&!Q(r)&&rt(r,a);for(const l of F)(i=l.onRegisteredNewMesh)==null||i.call(l,r,o)},S.lodInfos=new Map,S.previouslyLoaded=new Map,S.lowresCache=new Map;class nt{constructor(e,r,n,s,o){this.url=e,this.key=r,this.level=n,s!=null&&(this.index=s),o!=null&&(this.density=o)}}var Ie=(t,e,r)=>{if(!e.has(t))throw TypeError("Cannot "+r)},x=(t,e,r)=>(Ie(t,e,"read from private field"),r?r.call(t):e.get(t)),X=(t,e,r)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,r)},U=(t,e,r,n)=>(Ie(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),T,z,Me,Z,oe,ce,V;const k=te("debugprogressive"),it=te("noprogressive"),be=Symbol("Needle:LODSManager"),_e=Symbol("Needle:LODState"),q=Symbol("Needle:CurrentLOD"),R={mesh_lod:-1,texture_lod:-1},P=class{constructor(t,e){this.projectionScreenMatrix=new Oe,this.targetTriangleDensity=2e5,this.updateInterval="auto",X(this,T,1),this.pause=!1,this.manual=!1,this._lodchangedlisteners=[],X(this,z,void 0),X(this,Me,new ze),X(this,Z,0),X(this,oe,0),X(this,ce,0),X(this,V,0),this._fpsBuffer=[60,60,60,60,60],this._sphere=new Ue,this._tempBox=new Se,this._tempBox2=new Se,this.tempMatrix=new Oe,this._tempWorldPosition=new $,this._tempBoxSize=new $,this._tempBox2Size=new $,this.renderer=t,this.context={...e}}static getObjectLODState(t){return t[_e]}static addPlugin(t){F.push(t)}static removePlugin(t){const e=F.indexOf(t);e>=0&&F.splice(e,1)}static get(t,e){if(t[be])return console.debug("[gltf-progressive] LODsManager already exists for this renderer"),t[be];const r=new P(t,{engine:"unknown",...e});return t[be]=r,r}get plugins(){return F}addEventListener(t,e){t==="changed"&&this._lodchangedlisteners.push(e)}removeEventListener(t,e){if(t==="changed"){const r=this._lodchangedlisteners.indexOf(e);r>=0&&this._lodchangedlisteners.splice(r,1)}}enable(){if(x(this,z))return;console.debug("[gltf-progressive] Enabling LODsManager for renderer");let t=0;U(this,z,this.renderer.render);const e=this;pe(this.renderer),this.renderer.render=function(r,n){const s=e.renderer.getRenderTarget();(s==null||"isXRRenderTarget"in s&&s.isXRRenderTarget)&&(t=0,U(e,Z,x(e,Z)+1),U(e,oe,x(e,Me).getDelta()),U(e,ce,x(e,ce)+x(e,oe)),e._fpsBuffer.shift(),e._fpsBuffer.push(1/x(e,oe)),U(e,V,e._fpsBuffer.reduce((i,a)=>i+a)/e._fpsBuffer.length),k&&x(e,Z)%200===0&&console.log("FPS",Math.round(x(e,V)),"Interval:",x(e,T)));const o=t++;x(e,z).call(this,r,n),e.onAfterRender(r,n,o)}}disable(){x(this,z)&&(console.debug("[gltf-progressive] Disabling LODsManager for renderer"),this.renderer.render=x(this,z),U(this,z,void 0))}update(t,e){this.internalUpdate(t,e)}onAfterRender(t,e,r){if(this.pause)return;const n=this.renderer.renderLists.get(t,0).opaque;let s=!0;if(n.length===1){const o=n[0].material;(o.name==="EffectMaterial"||o.name==="CopyShader")&&(s=!1)}if((e.parent&&e.parent.type==="CubeCamera"||r>=1&&e.type==="OrthographicCamera")&&(s=!1),s){if(it||(this.updateInterval==="auto"?x(this,V)<40&&x(this,T)<10?(U(this,T,x(this,T)+1),k&&console.warn("\u2193 Reducing LOD updates",x(this,T),x(this,V).toFixed(0))):x(this,V)>=60&&x(this,T)>1&&(U(this,T,x(this,T)-1),k&&console.warn("\u2191 Increasing LOD updates",x(this,T),x(this,V).toFixed(0))):U(this,T,this.updateInterval),x(this,T)>0&&x(this,Z)%x(this,T)!=0))return;this.internalUpdate(t,e)}}internalUpdate(t,e){var r,n;const s=this.renderer.renderLists.get(t,0),o=s.opaque;this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse);const i=this.targetTriangleDensity;for(const l of o){if(l.material&&(((r=l.geometry)==null?void 0:r.type)==="BoxGeometry"||((n=l.geometry)==null?void 0:n.type)==="BufferGeometry")&&(l.material.name==="SphericalGaussianBlur"||l.material.name=="BackgroundCubeMaterial"||l.material.name==="CubemapFromEquirect"||l.material.name==="EquirectangularToCubeUV")){k&&(l.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]||(l.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]=!0,console.warn("Ignoring skybox or BLIT object",l,l.material.name,l.material.type)));continue}switch(l.material.type){case"LineBasicMaterial":case"LineDashedMaterial":case"PointsMaterial":case"ShadowMaterial":case"MeshDistanceMaterial":case"MeshDepthMaterial":continue}if(k==="color"&&l.material&&!l.object.progressive_debug_color){l.object.progressive_debug_color=!0;const f=Math.random()*16777215,p=new Fe({color:f});l.object.material=p}const h=l.object;(h instanceof H||h.isMesh)&&this.updateLODs(t,e,h,i)}const a=s.transparent;for(const l of a){const h=l.object;(h instanceof H||h.isMesh)&&this.updateLODs(t,e,h,i)}const u=s.transmissive;for(const l of u){const h=l.object;(h instanceof H||h.isMesh)&&this.updateLODs(t,e,h,i)}}updateLODs(t,e,r,n){var s,o;r.userData||(r.userData={});let i=r[_e];if(i||(i=new lt,r[_e]=i),i.frames++<2)return;for(const u of F)(s=u.onBeforeUpdateLOD)==null||s.call(u,this.renderer,t,e,r);this.calculateLodLevel(e,r,i,n,R),R.mesh_lod=Math.round(R.mesh_lod),R.texture_lod=Math.round(R.texture_lod),R.mesh_lod>=0&&this.loadProgressiveMeshes(r,R.mesh_lod);let a=R.texture_lod;r.material&&a>=0&&this.loadProgressiveTextures(r.material,a);for(const u of F)(o=u.onAfterUpdatedLOD)==null||o.call(u,this.renderer,t,e,r,R);i.lastLodLevel_Mesh=R.mesh_lod,i.lastLodLevel_Texture=R.texture_lod}loadProgressiveTextures(t,e){if(!t)return;if(Array.isArray(t)){for(const s of t)this.loadProgressiveTextures(s,e);return}let r=!1;(t[q]===void 0||e<t[q])&&(r=!0);const n=t["DEBUG:LOD"];n!=null&&(r=t[q]!=n,e=n),r&&(t[q]=e,S.assignTextureLOD(t,e).then(s=>{this._lodchangedlisteners.forEach(o=>o({type:"texture",level:e,object:t}))}))}loadProgressiveMeshes(t,e){if(!t)return Promise.resolve(null);let r=t[q]!==e;const n=t["DEBUG:LOD"];if(n!=null&&(r=t[q]!=n,e=n),r){t[q]=e;const s=t.geometry;return S.assignMeshLOD(t,e).then(o=>(o&&t[q]==e&&s!=t.geometry&&this._lodchangedlisteners.forEach(i=>i({type:"mesh",level:e,object:t})),o))}return Promise.resolve(null)}static isInside(t,e){const r=t.min,n=t.max,s=(r.x+n.x)*.5,o=(r.y+n.y)*.5;return this._tempPtInside.set(s,o,r.z).applyMatrix4(e).z<0}calculateLodLevel(t,e,r,n,s){var o;if(!e){s.mesh_lod=-1,s.texture_lod=-1;return}if(!t){s.mesh_lod=-1,s.texture_lod=-1;return}let i=10+1,a=!1;if(k&&e["DEBUG:LOD"]!=null)return e["DEBUG:LOD"];const u=S.getMeshLODInformation(e.geometry),l=u?.lods,h=l&&l.length>0,f=S.getMaterialMinMaxLODsCount(e.material),p=f?.min_count!=1/0&&f.min_count>0&&f.max_count>0;if(!h&&!p){s.mesh_lod=0,s.texture_lod=0;return}h||(a=!0,i=0);const E=this.renderer.domElement.clientHeight||this.renderer.domElement.height;let D=e.geometry.boundingBox;if(e.type==="SkinnedMesh"){const y=e;if(!y.boundingBox)y.computeBoundingBox();else if(r.frames%30===0){const c=Q(y),M=y.geometry;c&&(y.geometry=c),y.computeBoundingBox(),y.geometry=M}D=y.boundingBox}if(D){const y=t;if(e.geometry.attributes.color&&e.geometry.attributes.color.count<100&&e.geometry.boundingSphere){this._sphere.copy(e.geometry.boundingSphere),this._sphere.applyMatrix4(e.matrixWorld);const g=t.getWorldPosition(this._tempWorldPosition);if(this._sphere.containsPoint(g)){s.mesh_lod=0,s.texture_lod=0;return}}if(this._tempBox.copy(D),this._tempBox.applyMatrix4(e.matrixWorld),y.isPerspectiveCamera&&P.isInside(this._tempBox,this.projectionScreenMatrix)){s.mesh_lod=0,s.texture_lod=0;return}if(this._tempBox.applyMatrix4(this.projectionScreenMatrix),this.renderer.xr.enabled&&y.isPerspectiveCamera&&y.fov>70){const g=this._tempBox.min,m=this._tempBox.max;let d=g.x,L=g.y,O=m.x,j=m.y;const K=2,Y=1.5,ne=(g.x+m.x)*.5,ie=(g.y+m.y)*.5;d=(d-ne)*K+ne,L=(L-ie)*K+ie,O=(O-ne)*K+ne,j=(j-ie)*K+ie;const We=d<0&&O>0?0:Math.min(Math.abs(g.x),Math.abs(m.x)),$e=L<0&&j>0?0:Math.min(Math.abs(g.y),Math.abs(m.y)),fe=Math.max(We,$e);r.lastCentrality=(Y-fe)*(Y-fe)*(Y-fe)}else r.lastCentrality=1;const c=this._tempBox.getSize(this._tempBoxSize);c.multiplyScalar(.5),screen.availHeight>0&&E>0&&c.multiplyScalar(E/screen.availHeight),t.isPerspectiveCamera?c.x*=t.aspect:t.isOrthographicCamera;const M=t.matrixWorldInverse,b=this._tempBox2;b.copy(D),b.applyMatrix4(e.matrixWorld),b.applyMatrix4(M);const B=b.getSize(this._tempBox2Size),_=Math.max(B.x,B.y);if(Math.max(c.x,c.y)!=0&&_!=0&&(c.z=B.z/Math.max(B.x,B.y)*Math.max(c.x,c.y)),r.lastScreenCoverage=Math.max(c.x,c.y,c.z),r.lastScreenspaceVolume.copy(c),r.lastScreenCoverage*=r.lastCentrality,k&&P.debugDrawLine){const g=this.tempMatrix.copy(this.projectionScreenMatrix);g.invert();const m=P.corner0,d=P.corner1,L=P.corner2,O=P.corner3;m.copy(this._tempBox.min),d.copy(this._tempBox.max),d.x=m.x,L.copy(this._tempBox.max),L.y=m.y,O.copy(this._tempBox.max);const j=(m.z+O.z)*.5;m.z=d.z=L.z=O.z=j,m.applyMatrix4(g),d.applyMatrix4(g),L.applyMatrix4(g),O.applyMatrix4(g),P.debugDrawLine(m,d,255),P.debugDrawLine(m,L,255),P.debugDrawLine(d,O,255),P.debugDrawLine(L,O,255)}let I=999;if(l&&r.lastScreenCoverage>0){for(let g=0;g<l.length;g++)if(l[g].density/r.lastScreenCoverage<n){I=g;break}}I<i&&(i=I,a=!0)}if(a?s.mesh_lod=i:s.mesh_lod=r.lastLodLevel_Mesh,k&&s.mesh_lod!=r.lastLodLevel_Mesh){const y=l?.[s.mesh_lod];y&&console.log(`Mesh LOD changed: ${r.lastLodLevel_Mesh} \u2192 ${s.mesh_lod} (${y.density.toFixed(0)}) - ${e.name}`)}if(p){const y="saveData"in globalThis.navigator&&globalThis.navigator.saveData===!0;if(r.lastLodLevel_Texture<0){if(s.texture_lod=f.max_count-1,k){const c=f.lods[f.max_count-1];k&&console.log(`First Texture LOD ${s.texture_lod} (${c.max_height}px) - ${e.name}`)}}else{const c=r.lastScreenspaceVolume.x+r.lastScreenspaceVolume.y+r.lastScreenspaceVolume.z;let M=r.lastScreenCoverage*4;((o=this.context)==null?void 0:o.engine)==="model-viewer"&&(M*=1.5);const b=E/window.devicePixelRatio*M;let B=!1;for(let _=f.lods.length-1;_>=0;_--){let I=f.lods[_];if(!(y&&I.max_height>=2048)&&!(et()&&I.max_height>4096)&&(I.max_height>b||!B&&_===0)){if(B=!0,s.texture_lod=_,s.texture_lod<r.lastLodLevel_Texture){const g=I.max_height;k&&console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} \u2192 ${s.texture_lod} = ${g}px
5
+ `,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}};let S=w;S.registerTexture=(t,e,r,n,s)=>{if(v&&console.log("> Progressive: register texture",n,e.name,e.uuid,e,s),!e){v&&console.error("gltf-progressive: Register texture without texture");return}e.source&&(e.source[De]=s);const o=s.guid;w.assignLODInformation(t,e,o,r,n,void 0),w.lodInfos.set(o,s),w.lowresCache.set(o,e)},S.registerMesh=(t,e,r,n,s,o)=>{var i;v&&console.log("> Progressive: register mesh",s,r.name,o,r.uuid,r);const a=r.geometry;if(!a){v&&console.warn("gltf-progressive: Register mesh without geometry");return}a.userData||(a.userData={}),w.assignLODInformation(t,a,e,n,s,o.density),w.lodInfos.set(e,o);let u=w.lowresCache.get(e);u?u.push(r.geometry):u=[r.geometry],w.lowresCache.set(e,u),n>0&&!Q(r)&&rt(r,a);for(const l of F)(i=l.onRegisteredNewMesh)==null||i.call(l,r,o)},S.lodInfos=new Map,S.previouslyLoaded=new Map,S.lowresCache=new Map;class nt{constructor(e,r,n,s,o){this.url=e,this.key=r,this.level=n,s!=null&&(this.index=s),o!=null&&(this.density=o)}}var Ce=(t,e,r)=>{if(!e.has(t))throw TypeError("Cannot "+r)},x=(t,e,r)=>(Ce(t,e,"read from private field"),r?r.call(t):e.get(t)),X=(t,e,r)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,r)},U=(t,e,r,n)=>(Ce(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),T,z,Me,Z,oe,ce,V;const k=te("debugprogressive"),it=te("noprogressive"),be=Symbol("Needle:LODSManager"),_e=Symbol("Needle:LODState"),q=Symbol("Needle:CurrentLOD"),R={mesh_lod:-1,texture_lod:-1},P=class{constructor(t,e){this.projectionScreenMatrix=new Oe,this.targetTriangleDensity=2e5,this.updateInterval="auto",X(this,T,1),this.pause=!1,this.manual=!1,this._lodchangedlisteners=[],X(this,z,void 0),X(this,Me,new Ve),X(this,Z,0),X(this,oe,0),X(this,ce,0),X(this,V,0),this._fpsBuffer=[60,60,60,60,60],this._sphere=new Fe,this._tempBox=new Se,this._tempBox2=new Se,this.tempMatrix=new Oe,this._tempWorldPosition=new $,this._tempBoxSize=new $,this._tempBox2Size=new $,this.renderer=t,this.context={...e}}static getObjectLODState(t){return t[_e]}static addPlugin(t){F.push(t)}static removePlugin(t){const e=F.indexOf(t);e>=0&&F.splice(e,1)}static get(t,e){if(t[be])return console.debug("[gltf-progressive] LODsManager already exists for this renderer"),t[be];const r=new P(t,{engine:"unknown",...e});return t[be]=r,r}get plugins(){return F}addEventListener(t,e){t==="changed"&&this._lodchangedlisteners.push(e)}removeEventListener(t,e){if(t==="changed"){const r=this._lodchangedlisteners.indexOf(e);r>=0&&this._lodchangedlisteners.splice(r,1)}}enable(){if(x(this,z))return;console.debug("[gltf-progressive] Enabling LODsManager for renderer");let t=0;U(this,z,this.renderer.render);const e=this;pe(this.renderer),this.renderer.render=function(r,n){const s=e.renderer.getRenderTarget();(s==null||"isXRRenderTarget"in s&&s.isXRRenderTarget)&&(t=0,U(e,Z,x(e,Z)+1),U(e,oe,x(e,Me).getDelta()),U(e,ce,x(e,ce)+x(e,oe)),e._fpsBuffer.shift(),e._fpsBuffer.push(1/x(e,oe)),U(e,V,e._fpsBuffer.reduce((i,a)=>i+a)/e._fpsBuffer.length),k&&x(e,Z)%200===0&&console.log("FPS",Math.round(x(e,V)),"Interval:",x(e,T)));const o=t++;x(e,z).call(this,r,n),e.onAfterRender(r,n,o)}}disable(){x(this,z)&&(console.debug("[gltf-progressive] Disabling LODsManager for renderer"),this.renderer.render=x(this,z),U(this,z,void 0))}update(t,e){this.internalUpdate(t,e)}onAfterRender(t,e,r){if(this.pause)return;const n=this.renderer.renderLists.get(t,0).opaque;let s=!0;if(n.length===1){const o=n[0].material;(o.name==="EffectMaterial"||o.name==="CopyShader")&&(s=!1)}if((e.parent&&e.parent.type==="CubeCamera"||r>=1&&e.type==="OrthographicCamera")&&(s=!1),s){if(it||(this.updateInterval==="auto"?x(this,V)<40&&x(this,T)<10?(U(this,T,x(this,T)+1),k&&console.warn("\u2193 Reducing LOD updates",x(this,T),x(this,V).toFixed(0))):x(this,V)>=60&&x(this,T)>1&&(U(this,T,x(this,T)-1),k&&console.warn("\u2191 Increasing LOD updates",x(this,T),x(this,V).toFixed(0))):U(this,T,this.updateInterval),x(this,T)>0&&x(this,Z)%x(this,T)!=0))return;this.internalUpdate(t,e)}}internalUpdate(t,e){var r,n;const s=this.renderer.renderLists.get(t,0),o=s.opaque;this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse);const i=this.targetTriangleDensity;for(const l of o){if(l.material&&(((r=l.geometry)==null?void 0:r.type)==="BoxGeometry"||((n=l.geometry)==null?void 0:n.type)==="BufferGeometry")&&(l.material.name==="SphericalGaussianBlur"||l.material.name=="BackgroundCubeMaterial"||l.material.name==="CubemapFromEquirect"||l.material.name==="EquirectangularToCubeUV")){k&&(l.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]||(l.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]=!0,console.warn("Ignoring skybox or BLIT object",l,l.material.name,l.material.type)));continue}switch(l.material.type){case"LineBasicMaterial":case"LineDashedMaterial":case"PointsMaterial":case"ShadowMaterial":case"MeshDistanceMaterial":case"MeshDepthMaterial":continue}if(k==="color"&&l.material&&!l.object.progressive_debug_color){l.object.progressive_debug_color=!0;const g=Math.random()*16777215,p=new ze({color:g});l.object.material=p}const h=l.object;(h instanceof H||h.isMesh)&&this.updateLODs(t,e,h,i)}const a=s.transparent;for(const l of a){const h=l.object;(h instanceof H||h.isMesh)&&this.updateLODs(t,e,h,i)}const u=s.transmissive;for(const l of u){const h=l.object;(h instanceof H||h.isMesh)&&this.updateLODs(t,e,h,i)}}updateLODs(t,e,r,n){var s,o;r.userData||(r.userData={});let i=r[_e];if(i||(i=new lt,r[_e]=i),i.frames++<2)return;for(const u of F)(s=u.onBeforeUpdateLOD)==null||s.call(u,this.renderer,t,e,r);this.calculateLodLevel(e,r,i,n,R),R.mesh_lod=Math.round(R.mesh_lod),R.texture_lod=Math.round(R.texture_lod),R.mesh_lod>=0&&this.loadProgressiveMeshes(r,R.mesh_lod);let a=R.texture_lod;r.material&&a>=0&&this.loadProgressiveTextures(r.material,a);for(const u of F)(o=u.onAfterUpdatedLOD)==null||o.call(u,this.renderer,t,e,r,R);i.lastLodLevel_Mesh=R.mesh_lod,i.lastLodLevel_Texture=R.texture_lod}loadProgressiveTextures(t,e){if(!t)return;if(Array.isArray(t)){for(const s of t)this.loadProgressiveTextures(s,e);return}let r=!1;(t[q]===void 0||e<t[q])&&(r=!0);const n=t["DEBUG:LOD"];n!=null&&(r=t[q]!=n,e=n),r&&(t[q]=e,S.assignTextureLOD(t,e).then(s=>{this._lodchangedlisteners.forEach(o=>o({type:"texture",level:e,object:t}))}))}loadProgressiveMeshes(t,e){if(!t)return Promise.resolve(null);let r=t[q]!==e;const n=t["DEBUG:LOD"];if(n!=null&&(r=t[q]!=n,e=n),r){t[q]=e;const s=t.geometry;return S.assignMeshLOD(t,e).then(o=>(o&&t[q]==e&&s!=t.geometry&&this._lodchangedlisteners.forEach(i=>i({type:"mesh",level:e,object:t})),o))}return Promise.resolve(null)}static isInside(t,e){const r=t.min,n=t.max,s=(r.x+n.x)*.5,o=(r.y+n.y)*.5;return this._tempPtInside.set(s,o,r.z).applyMatrix4(e).z<0}calculateLodLevel(t,e,r,n,s){var o;if(!e){s.mesh_lod=-1,s.texture_lod=-1;return}if(!t){s.mesh_lod=-1,s.texture_lod=-1;return}let i=10+1,a=!1;if(k&&e["DEBUG:LOD"]!=null)return e["DEBUG:LOD"];const u=S.getMeshLODInformation(e.geometry),l=u?.lods,h=l&&l.length>0,g=S.getMaterialMinMaxLODsCount(e.material),p=g?.min_count!=1/0&&g.min_count>0&&g.max_count>0;if(!h&&!p){s.mesh_lod=0,s.texture_lod=0;return}h||(a=!0,i=0);const E=this.renderer.domElement.clientHeight||this.renderer.domElement.height;let D=e.geometry.boundingBox;if(e.type==="SkinnedMesh"){const y=e;if(!y.boundingBox)y.computeBoundingBox();else if(r.frames%30===0){const c=Q(y),M=y.geometry;c&&(y.geometry=c),y.computeBoundingBox(),y.geometry=M}D=y.boundingBox}if(D){const y=t;if(e.geometry.attributes.color&&e.geometry.attributes.color.count<100&&e.geometry.boundingSphere){this._sphere.copy(e.geometry.boundingSphere),this._sphere.applyMatrix4(e.matrixWorld);const f=t.getWorldPosition(this._tempWorldPosition);if(this._sphere.containsPoint(f)){s.mesh_lod=0,s.texture_lod=0;return}}if(this._tempBox.copy(D),this._tempBox.applyMatrix4(e.matrixWorld),y.isPerspectiveCamera&&P.isInside(this._tempBox,this.projectionScreenMatrix)){s.mesh_lod=0,s.texture_lod=0;return}if(this._tempBox.applyMatrix4(this.projectionScreenMatrix),this.renderer.xr.enabled&&y.isPerspectiveCamera&&y.fov>70){const f=this._tempBox.min,m=this._tempBox.max;let d=f.x,L=f.y,O=m.x,j=m.y;const K=2,Y=1.5,ne=(f.x+m.x)*.5,ie=(f.y+m.y)*.5;d=(d-ne)*K+ne,L=(L-ie)*K+ie,O=(O-ne)*K+ne,j=(j-ie)*K+ie;const $e=d<0&&O>0?0:Math.min(Math.abs(f.x),Math.abs(m.x)),Ne=L<0&&j>0?0:Math.min(Math.abs(f.y),Math.abs(m.y)),ge=Math.max($e,Ne);r.lastCentrality=(Y-ge)*(Y-ge)*(Y-ge)}else r.lastCentrality=1;const c=this._tempBox.getSize(this._tempBoxSize);c.multiplyScalar(.5),screen.availHeight>0&&E>0&&c.multiplyScalar(E/screen.availHeight),t.isPerspectiveCamera?c.x*=t.aspect:t.isOrthographicCamera;const M=t.matrixWorldInverse,b=this._tempBox2;b.copy(D),b.applyMatrix4(e.matrixWorld),b.applyMatrix4(M);const B=b.getSize(this._tempBox2Size),_=Math.max(B.x,B.y);if(Math.max(c.x,c.y)!=0&&_!=0&&(c.z=B.z/Math.max(B.x,B.y)*Math.max(c.x,c.y)),r.lastScreenCoverage=Math.max(c.x,c.y,c.z),r.lastScreenspaceVolume.copy(c),r.lastScreenCoverage*=r.lastCentrality,k&&P.debugDrawLine){const f=this.tempMatrix.copy(this.projectionScreenMatrix);f.invert();const m=P.corner0,d=P.corner1,L=P.corner2,O=P.corner3;m.copy(this._tempBox.min),d.copy(this._tempBox.max),d.x=m.x,L.copy(this._tempBox.max),L.y=m.y,O.copy(this._tempBox.max);const j=(m.z+O.z)*.5;m.z=d.z=L.z=O.z=j,m.applyMatrix4(f),d.applyMatrix4(f),L.applyMatrix4(f),O.applyMatrix4(f),P.debugDrawLine(m,d,255),P.debugDrawLine(m,L,255),P.debugDrawLine(d,O,255),P.debugDrawLine(L,O,255)}let I=999;if(l&&r.lastScreenCoverage>0){for(let f=0;f<l.length;f++)if(l[f].density/r.lastScreenCoverage<n){I=f;break}}I<i&&(i=I,a=!0)}if(a?s.mesh_lod=i:s.mesh_lod=r.lastLodLevel_Mesh,k&&s.mesh_lod!=r.lastLodLevel_Mesh){const y=l?.[s.mesh_lod];y&&console.log(`Mesh LOD changed: ${r.lastLodLevel_Mesh} \u2192 ${s.mesh_lod} (${y.density.toFixed(0)}) - ${e.name}`)}if(p){const y="saveData"in globalThis.navigator&&globalThis.navigator.saveData===!0;if(r.lastLodLevel_Texture<0){if(s.texture_lod=g.max_count-1,k){const c=g.lods[g.max_count-1];k&&console.log(`First Texture LOD ${s.texture_lod} (${c.max_height}px) - ${e.name}`)}}else{const c=r.lastScreenspaceVolume.x+r.lastScreenspaceVolume.y+r.lastScreenspaceVolume.z;let M=r.lastScreenCoverage*4;((o=this.context)==null?void 0:o.engine)==="model-viewer"&&(M*=1.5);const b=E/window.devicePixelRatio*M;let B=!1;for(let _=g.lods.length-1;_>=0;_--){let I=g.lods[_];if(!(y&&I.max_height>=2048)&&!(et()&&I.max_height>4096)&&(I.max_height>b||!B&&_===0)){if(B=!0,s.texture_lod=_,s.texture_lod<r.lastLodLevel_Texture){const f=I.max_height;k&&console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} \u2192 ${s.texture_lod} = ${f}px
6
6
  Screensize: ${b.toFixed(0)}px, Coverage: ${(100*r.lastScreenCoverage).toFixed(2)}%, Volume ${c.toFixed(1)}
7
- ${e.name}`)}break}}}}else s.texture_lod=0}};let W=P;T=new WeakMap,z=new WeakMap,Me=new WeakMap,Z=new WeakMap,oe=new WeakMap,ce=new WeakMap,V=new WeakMap,W.corner0=new $,W.corner1=new $,W.corner2=new $,W.corner3=new $,W._tempPtInside=new $;class lt{constructor(){this.frames=0,this.lastLodLevel_Mesh=-1,this.lastLodLevel_Texture=-1,this.lastScreenCoverage=0,this.lastScreenspaceVolume=new $,this.lastCentrality=0}}const Ce=Symbol("NEEDLE_mesh_lod"),de=Symbol("NEEDLE_texture_lod");let he=null;function ke(){const t=at();t&&(t.mapURLs(function(e){return Re(),e}),Re(),he?.disconnect(),he=new MutationObserver(e=>{e.forEach(r=>{r.addedNodes.forEach(n=>{n instanceof HTMLElement&&n.tagName.toLowerCase()==="model-viewer"&&Ge(n)})})}),he.observe(document,{childList:!0,subtree:!0}))}function at(){return typeof customElements>"u"?null:customElements.get("model-viewer")||(customElements.whenDefined("model-viewer").then(()=>{console.debug("[gltf-progressive] model-viewer defined"),ke()}),null)}function Re(){typeof document>"u"||document.querySelectorAll("model-viewer").forEach(t=>{Ge(t)})}const je=new WeakSet;let ut=0;function Ge(t){if(!t||je.has(t))return null;je.add(t),console.debug("[gltf-progressive] found new model-viewer..."+ ++ut+`
8
- `,t.getAttribute("src"));let e=null,r=null,n=null;for(let s=t;s!=null;s=Object.getPrototypeOf(s)){const o=Object.getOwnPropertySymbols(s),i=o.find(l=>l.toString()=="Symbol(renderer)"),a=o.find(l=>l.toString()=="Symbol(scene)"),u=o.find(l=>l.toString()=="Symbol(needsRender)");!e&&i!=null&&(e=t[i].threeRenderer),!r&&a!=null&&(r=t[a]),!n&&u!=null&&(n=t[u])}if(e&&r){let s=function(){if(n){let i=0,a=setInterval(()=>{if(i++>5){clearInterval(a);return}n?.call(t)},300)}};console.debug("[gltf-progressive] setup model-viewer");const o=W.get(e,{engine:"model-viewer"});return W.addPlugin(new ct),o.enable(),o.addEventListener("changed",()=>{n?.call(t)}),t.addEventListener("model-visibility",i=>{i.detail.visible&&n?.call(t)}),t.addEventListener("load",()=>{s()}),()=>{o.disable()}}return null}class ct{constructor(){this._didWarnAboutMissingUrl=!1}onBeforeUpdateLOD(e,r,n,s){this.tryParseMeshLOD(r,s),this.tryParseTextureLOD(r,s)}getUrl(e){if(!e)return null;let r=e.getAttribute("src");return r||(r=e.src),r||(this._didWarnAboutMissingUrl||console.warn("No url found in modelviewer",e),this._didWarnAboutMissingUrl=!0),r}tryGetCurrentGLTF(e){return e._currentGLTF}tryGetCurrentModelViewer(e){return e.element}tryParseTextureLOD(e,r){if(r[de]==!0)return;r[de]=!0;const n=this.tryGetCurrentGLTF(e),s=this.tryGetCurrentModelViewer(e),o=this.getUrl(s);if(o&&n&&r.material){let i=function(u){var l,h,f;if(u[de]==!0)return;u[de]=!0,u.userData&&(u.userData.LOD=-1);const p=Object.keys(u);for(let E=0;E<p.length;E++){const D=p[E],y=u[D];if(y?.isTexture===!0){const c=(h=(l=y.userData)==null?void 0:l.associations)==null?void 0:h.textures;if(c==null)continue;const M=n.parser.json.textures[c];if(!M){console.warn("Texture data not found for texture index "+c);continue}if((f=M?.extensions)!=null&&f[N]){const b=M.extensions[N];b&&o&&S.registerTexture(o,y,b.lods.length,c,b)}}}};const a=r.material;if(Array.isArray(a))for(const u of a)i(u);else i(a)}}tryParseMeshLOD(e,r){var n,s;if(r[Ce]==!0)return;r[Ce]=!0;const o=this.tryGetCurrentModelViewer(e),i=this.getUrl(o);if(!i)return;const a=(s=(n=r.userData)==null?void 0:n.gltfExtensions)==null?void 0:s[N];if(a&&i){const u=r.uuid;S.registerMesh(i,u,r,0,a.lods.length,a)}}}function dt(t,e,r,n){pe(e),ve(r),xe(r,{progressive:!0,...n?.hints}),r.register(o=>new S(o,t));const s=W.get(e);return n?.enableLODsManager!==!1&&s.enable(),s}if(ke(),!tt){const t={gltfProgressive:{useNeedleProgressive:dt,LODsManager:W,configureLoader:xe,getRaycastMesh:Q,useRaycastMeshes:st}};if(!globalThis.Needle)globalThis.Needle=t;else for(const e in t)globalThis.Needle[e]=t[e]}export{W as L,S as N,ve as a,xe as b,pe as c,Ee as d,Q as g,Te as s};
7
+ ${e.name}`)}break}}}}else s.texture_lod=0}};let W=P;T=new WeakMap,z=new WeakMap,Me=new WeakMap,Z=new WeakMap,oe=new WeakMap,ce=new WeakMap,V=new WeakMap,W.corner0=new $,W.corner1=new $,W.corner2=new $,W.corner3=new $,W._tempPtInside=new $;class lt{constructor(){this.frames=0,this.lastLodLevel_Mesh=-1,this.lastLodLevel_Texture=-1,this.lastScreenCoverage=0,this.lastScreenspaceVolume=new $,this.lastCentrality=0}}const ke=Symbol("NEEDLE_mesh_lod"),de=Symbol("NEEDLE_texture_lod");let he=null;function Re(){const t=at();t&&(t.mapURLs(function(e){return je(),e}),je(),he?.disconnect(),he=new MutationObserver(e=>{e.forEach(r=>{r.addedNodes.forEach(n=>{n instanceof HTMLElement&&n.tagName.toLowerCase()==="model-viewer"&&We(n)})})}),he.observe(document,{childList:!0,subtree:!0}))}function at(){return typeof customElements>"u"?null:customElements.get("model-viewer")||(customElements.whenDefined("model-viewer").then(()=>{console.debug("[gltf-progressive] model-viewer defined"),Re()}),null)}function je(){typeof document>"u"||document.querySelectorAll("model-viewer").forEach(t=>{We(t)})}const Ge=new WeakSet;let ut=0;function We(t){if(!t||Ge.has(t))return null;Ge.add(t),console.debug("[gltf-progressive] found new model-viewer..."+ ++ut+`
8
+ `,t.getAttribute("src"));let e=null,r=null,n=null;for(let s=t;s!=null;s=Object.getPrototypeOf(s)){const o=Object.getOwnPropertySymbols(s),i=o.find(l=>l.toString()=="Symbol(renderer)"),a=o.find(l=>l.toString()=="Symbol(scene)"),u=o.find(l=>l.toString()=="Symbol(needsRender)");!e&&i!=null&&(e=t[i].threeRenderer),!r&&a!=null&&(r=t[a]),!n&&u!=null&&(n=t[u])}if(e&&r){let s=function(){if(n){let i=0,a=setInterval(()=>{if(i++>5){clearInterval(a);return}n?.call(t)},300)}};console.debug("[gltf-progressive] setup model-viewer");const o=W.get(e,{engine:"model-viewer"});return W.addPlugin(new ct),o.enable(),o.addEventListener("changed",()=>{n?.call(t)}),t.addEventListener("model-visibility",i=>{i.detail.visible&&n?.call(t)}),t.addEventListener("load",()=>{s()}),()=>{o.disable()}}return null}class ct{constructor(){this._didWarnAboutMissingUrl=!1}onBeforeUpdateLOD(e,r,n,s){this.tryParseMeshLOD(r,s),this.tryParseTextureLOD(r,s)}getUrl(e){if(!e)return null;let r=e.getAttribute("src");return r||(r=e.src),r||(this._didWarnAboutMissingUrl||console.warn("No url found in modelviewer",e),this._didWarnAboutMissingUrl=!0),r}tryGetCurrentGLTF(e){return e._currentGLTF}tryGetCurrentModelViewer(e){return e.element}tryParseTextureLOD(e,r){if(r[de]==!0)return;r[de]=!0;const n=this.tryGetCurrentGLTF(e),s=this.tryGetCurrentModelViewer(e),o=this.getUrl(s);if(o&&n&&r.material){let i=function(u){var l,h,g;if(u[de]==!0)return;u[de]=!0,u.userData&&(u.userData.LOD=-1);const p=Object.keys(u);for(let E=0;E<p.length;E++){const D=p[E],y=u[D];if(y?.isTexture===!0){const c=(h=(l=y.userData)==null?void 0:l.associations)==null?void 0:h.textures;if(c==null)continue;const M=n.parser.json.textures[c];if(!M){console.warn("Texture data not found for texture index "+c);continue}if((g=M?.extensions)!=null&&g[N]){const b=M.extensions[N];b&&o&&S.registerTexture(o,y,b.lods.length,c,b)}}}};const a=r.material;if(Array.isArray(a))for(const u of a)i(u);else i(a)}}tryParseMeshLOD(e,r){var n,s;if(r[ke]==!0)return;r[ke]=!0;const o=this.tryGetCurrentModelViewer(e),i=this.getUrl(o);if(!i)return;const a=(s=(n=r.userData)==null?void 0:n.gltfExtensions)==null?void 0:s[N];if(a&&i){const u=r.uuid;S.registerMesh(i,u,r,0,a.lods.length,a)}}}function dt(t,e,r,n){pe(e),ve(r),xe(r,{progressive:!0,...n?.hints}),r.register(o=>new S(o,t));const s=W.get(e);return n?.enableLODsManager!==!1&&s.enable(),s}if(Re(),!tt){const t={gltfProgressive:{useNeedleProgressive:dt,LODsManager:W,configureLoader:xe,getRaycastMesh:Q,useRaycastMeshes:st}};if(!globalThis.Needle)globalThis.Needle=t;else for(const e in t)globalThis.Needle[e]=t[e]}export{W as L,S as N,ve as a,xe as b,pe as c,Ae as d,Q as g,Ee as s};