@needle-tools/engine 4.7.2-next.d24ebbc → 4.7.3-next.1603bb0

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 (54) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/gltf-progressive-BCZdu3Gc.min.js +8 -0
  3. package/dist/gltf-progressive-C6QbvrB4.umd.cjs +8 -0
  4. package/dist/{gltf-progressive-CNdBjvz6.js → gltf-progressive-CCddD-3B.js} +413 -399
  5. package/dist/{needle-engine.bundle-CGXifNgp.min.js → needle-engine.bundle-6bPQlS1q.min.js} +102 -102
  6. package/dist/{needle-engine.bundle-CHfSBXXT.js → needle-engine.bundle-CL5SiInU.js} +1962 -1889
  7. package/dist/{needle-engine.bundle-Dcn5L5IY.umd.cjs → needle-engine.bundle-Dm9L7JpU.umd.cjs} +70 -70
  8. package/dist/needle-engine.d.ts +21 -0
  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-xYQWCHFu.min.js → postprocessing-BzY0H7ry.min.js} +9 -9
  13. package/dist/{postprocessing-CjW23fio.umd.cjs → postprocessing-Dw2OCMp4.umd.cjs} +9 -9
  14. package/dist/{postprocessing-DYLNOL3W.js → postprocessing-vKBVFpSz.js} +10 -10
  15. package/dist/{three-examples-DaDLBuy6.min.js → three-examples-BMOhDaYR.min.js} +17 -17
  16. package/dist/{three-examples-X3OadjXB.umd.cjs → three-examples-DUcCNw9s.umd.cjs} +17 -17
  17. package/dist/{three-examples-B50TT3Iu.js → three-examples-tvuhV8Ne.js} +688 -688
  18. package/lib/engine/engine_create_objects.js +24 -1
  19. package/lib/engine/engine_create_objects.js.map +1 -1
  20. package/lib/engine/engine_input.js +3 -0
  21. package/lib/engine/engine_input.js.map +1 -1
  22. package/lib/engine/engine_physics.d.ts +13 -1
  23. package/lib/engine/engine_physics.js +15 -7
  24. package/lib/engine/engine_physics.js.map +1 -1
  25. package/lib/engine/webcomponents/needle-engine.js +14 -11
  26. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  27. package/lib/engine-components/OrbitControls.d.ts +57 -0
  28. package/lib/engine-components/OrbitControls.js +68 -9
  29. package/lib/engine-components/OrbitControls.js.map +1 -1
  30. package/lib/engine-components/Skybox.d.ts +1 -0
  31. package/lib/engine-components/Skybox.js +14 -18
  32. package/lib/engine-components/Skybox.js.map +1 -1
  33. package/lib/engine-components/postprocessing/PostProcessingHandler.js +1 -1
  34. package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
  35. package/lib/engine-components/postprocessing/Volume.d.ts +3 -1
  36. package/lib/engine-components/postprocessing/Volume.js +2 -0
  37. package/lib/engine-components/postprocessing/Volume.js.map +1 -1
  38. package/lib/engine-components/ui/EventSystem.js +9 -10
  39. package/lib/engine-components/ui/EventSystem.js.map +1 -1
  40. package/package.json +3 -3
  41. package/plugins/common/logger.js +34 -16
  42. package/plugins/vite/logger.client.js +123 -52
  43. package/plugins/vite/logger.js +5 -5
  44. package/src/engine/engine_create_objects.ts +24 -1
  45. package/src/engine/engine_input.ts +8 -1
  46. package/src/engine/engine_physics.ts +26 -8
  47. package/src/engine/webcomponents/needle-engine.ts +15 -13
  48. package/src/engine-components/OrbitControls.ts +94 -14
  49. package/src/engine-components/Skybox.ts +15 -21
  50. package/src/engine-components/postprocessing/PostProcessingHandler.ts +1 -1
  51. package/src/engine-components/postprocessing/Volume.ts +2 -1
  52. package/src/engine-components/ui/EventSystem.ts +8 -9
  53. package/dist/gltf-progressive-C_oN6wCA.umd.cjs +0 -8
  54. package/dist/gltf-progressive-MgWOszRl.min.js +0 -8
@@ -1,106 +1,106 @@
1
1
  var He = Object.defineProperty;
2
- var Ee = (n) => {
3
- throw TypeError(n);
2
+ var Ee = (o) => {
3
+ throw TypeError(o);
4
4
  };
5
- var je = (n, t, e) => t in n ? He(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
6
- var d = (n, t, e) => je(n, typeof t != "symbol" ? t + "" : t, e), Ge = (n, t, e) => t.has(n) || Ee("Cannot " + e);
7
- var p = (n, t, e) => (Ge(n, t, "read from private field"), e ? e.call(n) : t.get(n)), j = (n, t, e) => t.has(n) ? Ee("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(n) : t.set(n, e), N = (n, t, e, s) => (Ge(n, t, "write to private field"), s ? s.call(n, e) : t.set(n, e), e);
8
- import { BufferGeometry as me, Mesh as te, Texture as oe, TextureLoader as Je, Matrix4 as Be, Clock as Qe, MeshStandardMaterial as Ze, Sphere as et, Box3 as Ie, Vector3 as q } from "./three-DrqIzZTH.js";
9
- import { DRACOLoader as tt, KTX2Loader as st, MeshoptDecoder as rt, GLTFLoader as Ce } from "./three-examples-B50TT3Iu.js";
5
+ var je = (o, t, e) => t in o ? He(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
6
+ var d = (o, t, e) => je(o, typeof t != "symbol" ? t + "" : t, e), Ge = (o, t, e) => t.has(o) || Ee("Cannot " + e);
7
+ var p = (o, t, e) => (Ge(o, t, "read from private field"), e ? e.call(o) : t.get(o)), j = (o, t, e) => t.has(o) ? Ee("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(o) : t.set(o, e), N = (o, t, e, s) => (Ge(o, t, "write to private field"), s ? s.call(o, e) : t.set(o, e), e);
8
+ import { BufferGeometry as ye, Mesh as te, Texture as ne, TextureLoader as Je, Matrix4 as Be, Clock as Qe, MeshStandardMaterial as Ze, Sphere as et, Box3 as Ie, Vector3 as q } from "./three-DrqIzZTH.js";
9
+ import { DRACOLoader as tt, KTX2Loader as st, MeshoptDecoder as rt, GLTFLoader as Ce } from "./three-examples-tvuhV8Ne.js";
10
10
  const it = "";
11
11
  globalThis.GLTF_PROGRESSIVE_VERSION = it;
12
12
  console.debug("[gltf-progressive] version -");
13
13
  let V = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", se = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
14
- const ot = V, nt = se, Fe = new URL(V + "draco_decoder.js");
14
+ const nt = V, ot = se, Fe = new URL(V + "draco_decoder.js");
15
15
  Fe.searchParams.append("range", "true");
16
16
  fetch(Fe, {
17
17
  method: "GET",
18
18
  headers: {
19
19
  Range: "bytes=0-1"
20
20
  }
21
- }).catch((n) => {
22
- console.debug(`Failed to fetch remote Draco decoder from ${V} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), V === ot && at("./include/draco/"), se === nt && lt("./include/ktx2/");
21
+ }).catch((o) => {
22
+ console.debug(`Failed to fetch remote Draco decoder from ${V} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), V === nt && at("./include/draco/"), se === ot && lt("./include/ktx2/");
23
23
  }).finally(() => {
24
24
  Ue();
25
25
  });
26
- function at(n) {
27
- V = n, G && G[Te] != V ? (console.debug("Updating Draco decoder path to " + n), G[Te] = V, G.setDecoderPath(V), G.preload()) : console.debug("Setting Draco decoder path to " + n);
26
+ function at(o) {
27
+ V = o, G && G[Pe] != V ? (console.debug("Updating Draco decoder path to " + o), G[Pe] = V, G.setDecoderPath(V), G.preload()) : console.debug("Setting Draco decoder path to " + o);
28
28
  }
29
- function lt(n) {
30
- se = n, $ && $.transcoderPath != se ? (console.debug("Updating KTX2 transcoder path to " + n), $.setTranscoderPath(se), $.init()) : console.debug("Setting KTX2 transcoder path to " + n);
29
+ function lt(o) {
30
+ se = o, $ && $.transcoderPath != se ? (console.debug("Updating KTX2 transcoder path to " + o), $.setTranscoderPath(se), $.init()) : console.debug("Setting KTX2 transcoder path to " + o);
31
31
  }
32
- const Te = Symbol("dracoDecoderPath");
32
+ const Pe = Symbol("dracoDecoderPath");
33
33
  let G, Le, $;
34
34
  function Ue() {
35
- G || (G = new tt(), G[Te] = V, G.setDecoderPath(V), G.setDecoderConfig({ type: "js" }), G.preload()), $ || ($ = new st(), $.setTranscoderPath(se), $.init()), Le || (Le = rt);
35
+ G || (G = new tt(), G[Pe] = V, G.setDecoderPath(V), G.setDecoderConfig({ type: "js" }), G.preload()), $ || ($ = new st(), $.setTranscoderPath(se), $.init()), Le || (Le = rt);
36
36
  }
37
- function Ne(n) {
38
- return Ue(), n ? $.detectSupport(n) : n !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: G, ktx2Loader: $, meshoptDecoder: Le };
37
+ function Ne(o) {
38
+ return Ue(), o ? $.detectSupport(o) : o !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: G, ktx2Loader: $, meshoptDecoder: Le };
39
39
  }
40
- function ze(n) {
41
- n.dracoLoader || n.setDRACOLoader(G), n.ktx2Loader || n.setKTX2Loader($), n.meshoptDecoder || n.setMeshoptDecoder(Le);
40
+ function ze(o) {
41
+ o.dracoLoader || o.setDRACOLoader(G), o.ktx2Loader || o.setKTX2Loader($), o.meshoptDecoder || o.setMeshoptDecoder(Le);
42
42
  }
43
- const Pe = /* @__PURE__ */ new WeakMap();
44
- function Ve(n, t) {
45
- let e = Pe.get(n);
46
- e ? e = Object.assign(e, t) : e = t, Pe.set(n, e);
43
+ const Te = /* @__PURE__ */ new WeakMap();
44
+ function Ve(o, t) {
45
+ let e = Te.get(o);
46
+ e ? e = Object.assign(e, t) : e = t, Te.set(o, e);
47
47
  }
48
48
  const Me = Ce.prototype.load;
49
- function dt(...n) {
50
- const t = Pe.get(this);
51
- let e = n[0];
49
+ function dt(...o) {
50
+ const t = Te.get(this);
51
+ let e = o[0];
52
52
  const s = new URL(e, window.location.href);
53
53
  if (s.hostname.endsWith("needle.tools")) {
54
- const i = (t == null ? void 0 : t.progressive) !== void 0 ? t.progressive : !0, r = t != null && t.usecase ? t.usecase : "default";
55
- i ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${r}` : this.requestHeader.Accept = `*/*;usecase=${r}`, e = s.toString();
54
+ const r = (t == null ? void 0 : t.progressive) !== void 0 ? t.progressive : !0, i = t != null && t.usecase ? t.usecase : "default";
55
+ r ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${i}` : this.requestHeader.Accept = `*/*;usecase=${i}`, e = s.toString();
56
56
  }
57
- return n[0] = e, Me == null ? void 0 : Me.call(this, ...n);
57
+ return o[0] = e, Me == null ? void 0 : Me.call(this, ...o);
58
58
  }
59
59
  Ce.prototype.load = dt;
60
60
  de("debugprogressive");
61
- function de(n) {
61
+ function de(o) {
62
62
  if (typeof window > "u") return !1;
63
- const e = new URL(window.location.href).searchParams.get(n);
63
+ const e = new URL(window.location.href).searchParams.get(o);
64
64
  return e == null || e === "0" || e === "false" ? !1 : e === "" ? !0 : e;
65
65
  }
66
- function ut(n, t) {
67
- if (t === void 0 || t.startsWith("./") || t.startsWith("http") || n === void 0)
66
+ function ut(o, t) {
67
+ if (t === void 0 || t.startsWith("./") || t.startsWith("http") || o === void 0)
68
68
  return t;
69
- const e = n.lastIndexOf("/");
69
+ const e = o.lastIndexOf("/");
70
70
  if (e >= 0) {
71
- const s = n.substring(0, e + 1);
71
+ const s = o.substring(0, e + 1);
72
72
  for (; s.endsWith("/") && t.startsWith("/"); ) t = t.substring(1);
73
73
  return s + t;
74
74
  }
75
75
  return t;
76
76
  }
77
- let ne;
77
+ let oe;
78
78
  function ct() {
79
- return ne !== void 0 || (ne = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), de("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", ne)), ne;
79
+ return oe !== void 0 || (oe = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), de("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", oe)), oe;
80
80
  }
81
81
  function ft() {
82
82
  if (typeof window > "u") return !1;
83
- const n = new URL(window.location.href), t = n.hostname === "localhost" || /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(n.hostname);
84
- return n.hostname === "127.0.0.1" || t;
83
+ 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);
84
+ return o.hostname === "127.0.0.1" || t;
85
85
  }
86
86
  const ht = typeof window > "u" && typeof document > "u", Ae = Symbol("needle:raycast-mesh");
87
- function ue(n) {
88
- return (n == null ? void 0 : n[Ae]) instanceof me ? n[Ae] : null;
87
+ function ue(o) {
88
+ return (o == null ? void 0 : o[Ae]) instanceof ye ? o[Ae] : null;
89
89
  }
90
- function gt(n, t) {
91
- if ((n.type === "Mesh" || n.type === "SkinnedMesh") && !ue(n)) {
92
- const s = yt(t);
93
- s.userData = { isRaycastMesh: !0 }, n[Ae] = s;
90
+ function gt(o, t) {
91
+ if ((o.type === "Mesh" || o.type === "SkinnedMesh") && !ue(o)) {
92
+ const s = mt(t);
93
+ s.userData = { isRaycastMesh: !0 }, o[Ae] = s;
94
94
  }
95
95
  }
96
- function pt(n = !0) {
97
- if (n) {
96
+ function pt(o = !0) {
97
+ if (o) {
98
98
  if (ae) return;
99
99
  const t = ae = te.prototype.raycast;
100
100
  te.prototype.raycast = function(e, s) {
101
- const o = this, i = ue(o);
102
- let r;
103
- i && o.isMesh && (r = o.geometry, o.geometry = i), t.call(this, e, s), r && (o.geometry = r);
101
+ const n = this, r = ue(n);
102
+ let i;
103
+ r && n.isMesh && (i = n.geometry, n.geometry = r), t.call(this, e, s), i && (n.geometry = i);
104
104
  };
105
105
  } else {
106
106
  if (!ae) return;
@@ -108,46 +108,46 @@ function pt(n = !0) {
108
108
  }
109
109
  }
110
110
  let ae = null;
111
- function yt(n) {
112
- const t = new me();
113
- for (const e in n.attributes)
114
- t.setAttribute(e, n.getAttribute(e));
115
- return t.setIndex(n.getIndex()), t;
111
+ function mt(o) {
112
+ const t = new ye();
113
+ for (const e in o.attributes)
114
+ t.setAttribute(e, o.getAttribute(e));
115
+ return t.setIndex(o.getIndex()), t;
116
116
  }
117
- const Q = new Array(), w = de("debugprogressive");
117
+ const Q = new Array(), y = de("debugprogressive");
118
118
  let pe, ee = -1;
119
- if (w) {
120
- let n = function() {
119
+ if (y) {
120
+ let o = function() {
121
121
  ee += 1, ee >= t && (ee = -1), console.log(`Toggle LOD level [${ee}]`);
122
122
  }, t = 6;
123
123
  window.addEventListener("keyup", (e) => {
124
- e.key === "p" && n(), e.key === "w" && (pe = !pe, console.log(`Toggle wireframe [${pe}]`));
124
+ e.key === "p" && o(), e.key === "w" && (pe = !pe, console.log(`Toggle wireframe [${pe}]`));
125
125
  const s = parseInt(e.key);
126
126
  !isNaN(s) && s >= 0 && (ee = s, console.log(`Set LOD level to [${ee}]`));
127
127
  });
128
128
  }
129
- function We(n) {
130
- if (w)
131
- if (Array.isArray(n))
132
- for (const t of n)
129
+ function We(o) {
130
+ if (y)
131
+ if (Array.isArray(o))
132
+ for (const t of o)
133
133
  We(t);
134
- else n && "wireframe" in n && (n.wireframe = pe === !0);
134
+ else o && "wireframe" in o && (o.wireframe = pe === !0);
135
135
  }
136
- const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), x = class x {
136
+ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = class w {
137
137
  constructor(t, e) {
138
138
  d(this, "parser");
139
139
  d(this, "url");
140
140
  d(this, "_isLoadingMesh");
141
141
  d(this, "loadMesh", (t) => {
142
- var s, o;
142
+ var s, n;
143
143
  if (this._isLoadingMesh) return null;
144
- const e = (o = (s = this.parser.json.meshes[t]) == null ? void 0 : s.extensions) == null ? void 0 : o[K];
145
- return e ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", t).then((i) => {
146
- var r;
147
- return this._isLoadingMesh = !1, i && x.registerMesh(this.url, e.guid, i, (r = e.lods) == null ? void 0 : r.length, 0, e), i;
144
+ const e = (n = (s = this.parser.json.meshes[t]) == null ? void 0 : s.extensions) == null ? void 0 : n[K];
145
+ return e ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", t).then((r) => {
146
+ var i;
147
+ return this._isLoadingMesh = !1, r && w.registerMesh(this.url, e.guid, r, (i = e.lods) == null ? void 0 : i.length, 0, e), r;
148
148
  })) : null;
149
149
  });
150
- w && console.log("Progressive extension registered for", e), this.parser = t, this.url = e;
150
+ y && console.log("Progressive extension registered for", e), this.parser = t, this.url = e;
151
151
  }
152
152
  /** The name of the extension */
153
153
  get name() {
@@ -163,8 +163,8 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), x = c
163
163
  return e ?? -1;
164
164
  }
165
165
  static getMaterialMinMaxLODsCount(t, e) {
166
- const s = this, o = "LODS:minmax", i = t[o];
167
- if (i != null) return i;
166
+ const s = this, n = "LODS:minmax", r = t[n];
167
+ if (r != null) return r;
168
168
  if (e || (e = {
169
169
  min_count: 1 / 0,
170
170
  max_count: 0,
@@ -172,21 +172,21 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), x = c
172
172
  }), Array.isArray(t)) {
173
173
  for (const a of t)
174
174
  this.getMaterialMinMaxLODsCount(a, e);
175
- return t[o] = e, e;
175
+ return t[n] = e, e;
176
176
  }
177
- if (w === "verbose" && console.log("getMaterialMinMaxLODsCount", t), t.type === "ShaderMaterial" || t.type === "RawShaderMaterial") {
177
+ if (y === "verbose" && console.log("getMaterialMinMaxLODsCount", t), t.type === "ShaderMaterial" || t.type === "RawShaderMaterial") {
178
178
  const a = t;
179
179
  for (const l of Object.keys(a.uniforms)) {
180
180
  const c = a.uniforms[l].value;
181
- (c == null ? void 0 : c.isTexture) === !0 && r(c, e);
181
+ (c == null ? void 0 : c.isTexture) === !0 && i(c, e);
182
182
  }
183
183
  } else if (t.isMaterial)
184
184
  for (const a of Object.keys(t)) {
185
185
  const l = t[a];
186
- (l == null ? void 0 : l.isTexture) === !0 && r(l, e);
186
+ (l == null ? void 0 : l.isTexture) === !0 && i(l, e);
187
187
  }
188
- return t[o] = e, e;
189
- function r(a, l) {
188
+ return t[n] = e, e;
189
+ function i(a, l) {
190
190
  const c = s.getAssignedLODInformation(a);
191
191
  if (c) {
192
192
  const u = s.lodInfos.get(c.key);
@@ -206,30 +206,30 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), x = c
206
206
  * @returns true if the LOD level is available (or if any LOD level is available if level is undefined)
207
207
  */
208
208
  static hasLODLevelAvailable(t, e) {
209
- var i;
209
+ var r;
210
210
  if (Array.isArray(t)) {
211
- for (const r of t)
212
- if (this.hasLODLevelAvailable(r, e)) return !0;
211
+ for (const i of t)
212
+ if (this.hasLODLevelAvailable(i, e)) return !0;
213
213
  return !1;
214
214
  }
215
215
  if (t.isMaterial === !0) {
216
- for (const r of Object.keys(t)) {
217
- const a = t[r];
216
+ for (const i of Object.keys(t)) {
217
+ const a = t[i];
218
218
  if (a && a.isTexture && this.hasLODLevelAvailable(a, e))
219
219
  return !0;
220
220
  }
221
221
  return !1;
222
222
  } else if (t.isGroup === !0) {
223
- for (const r of t.children)
224
- if (r.isMesh === !0 && this.hasLODLevelAvailable(r, e))
223
+ for (const i of t.children)
224
+ if (i.isMesh === !0 && this.hasLODLevelAvailable(i, e))
225
225
  return !0;
226
226
  }
227
- let s, o;
228
- if (t.isMesh ? s = t.geometry : (t.isBufferGeometry || t.isTexture) && (s = t), s && (i = s == null ? void 0 : s.userData) != null && i.LODS) {
229
- const r = s.userData.LODS;
230
- if (o = this.lodInfos.get(r.key), e === void 0) return o != null;
231
- if (o)
232
- return Array.isArray(o.lods) ? e < o.lods.length : e === 0;
227
+ let s, n;
228
+ if (t.isMesh ? s = t.geometry : (t.isBufferGeometry || t.isTexture) && (s = t), s && (r = s == null ? void 0 : s.userData) != null && r.LODS) {
229
+ const i = s.userData.LODS;
230
+ if (n = this.lodInfos.get(i.key), e === void 0) return n != null;
231
+ if (n)
232
+ return Array.isArray(n.lods) ? e < n.lods.length : e === 0;
233
233
  }
234
234
  return !1;
235
235
  }
@@ -251,19 +251,19 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), x = c
251
251
  var s;
252
252
  if (!t) return Promise.resolve(null);
253
253
  if (t instanceof te || t.isMesh === !0) {
254
- const o = t.geometry, i = this.getAssignedLODInformation(o);
255
- if (!i)
254
+ const n = t.geometry, r = this.getAssignedLODInformation(n);
255
+ if (!r)
256
256
  return Promise.resolve(null);
257
- for (const r of Q)
258
- (s = r.onBeforeGetLODMesh) == null || s.call(r, t, e);
259
- return t["LOD:requested level"] = e, x.getOrLoadLOD(o, e).then((r) => {
260
- if (Array.isArray(r)) {
261
- const a = i.index || 0;
262
- r = r[a];
257
+ for (const i of Q)
258
+ (s = i.onBeforeGetLODMesh) == null || s.call(i, t, e);
259
+ return t["LOD:requested level"] = e, w.getOrLoadLOD(n, e).then((i) => {
260
+ if (Array.isArray(i)) {
261
+ const a = r.index || 0;
262
+ i = i[a];
263
263
  }
264
- return t["LOD:requested level"] === e && (delete t["LOD:requested level"], r && o != r && ((r == null ? void 0 : r.isBufferGeometry) ? t.geometry = r : w && console.error("Invalid LOD geometry", r))), r;
265
- }).catch((r) => (console.error("Error loading mesh LOD", t, r), null));
266
- } else w && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", t);
264
+ return t["LOD:requested level"] === e && (delete t["LOD:requested level"], i && n != i && ((i == null ? void 0 : i.isBufferGeometry) ? t.geometry = i : y && console.error("Invalid LOD geometry", i))), i;
265
+ }).catch((i) => (console.error("Error loading mesh LOD", t, i), null));
266
+ } else y && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", t);
267
267
  return Promise.resolve(null);
268
268
  }
269
269
  static assignTextureLOD(t, e = 0) {
@@ -271,103 +271,103 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), x = c
271
271
  if (t.isMesh === !0) {
272
272
  const s = t;
273
273
  if (Array.isArray(s.material)) {
274
- const o = new Array();
275
- for (const i of s.material) {
276
- const r = this.assignTextureLOD(i, e);
277
- o.push(r);
274
+ const n = new Array();
275
+ for (const r of s.material) {
276
+ const i = this.assignTextureLOD(r, e);
277
+ n.push(i);
278
278
  }
279
- return Promise.all(o).then((i) => {
280
- const r = new Array();
281
- for (const a of i)
282
- Array.isArray(a) && r.push(...a);
283
- return r;
279
+ return Promise.all(n).then((r) => {
280
+ const i = new Array();
281
+ for (const a of r)
282
+ Array.isArray(a) && i.push(...a);
283
+ return i;
284
284
  });
285
285
  } else
286
286
  return this.assignTextureLOD(s.material, e);
287
287
  }
288
288
  if (t.isMaterial === !0) {
289
- const s = t, o = [], i = new Array();
289
+ const s = t, n = [], r = new Array();
290
290
  if (s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
291
- const r = s;
292
- for (const a of Object.keys(r.uniforms)) {
293
- const l = r.uniforms[a].value;
291
+ const i = s;
292
+ for (const a of Object.keys(i.uniforms)) {
293
+ const l = i.uniforms[a].value;
294
294
  if ((l == null ? void 0 : l.isTexture) === !0) {
295
- const c = this.assignTextureLODForSlot(l, e, s, a).then((u) => (u && r.uniforms[a].value != u && (r.uniforms[a].value = u, r.uniformsNeedUpdate = !0), u));
296
- o.push(c), i.push(a);
295
+ const c = this.assignTextureLODForSlot(l, e, s, a).then((u) => (u && i.uniforms[a].value != u && (i.uniforms[a].value = u, i.uniformsNeedUpdate = !0), u));
296
+ n.push(c), r.push(a);
297
297
  }
298
298
  }
299
299
  } else
300
- for (const r of Object.keys(s)) {
301
- const a = s[r];
300
+ for (const i of Object.keys(s)) {
301
+ const a = s[i];
302
302
  if ((a == null ? void 0 : a.isTexture) === !0) {
303
- const l = this.assignTextureLODForSlot(a, e, s, r);
304
- o.push(l), i.push(r);
303
+ const l = this.assignTextureLODForSlot(a, e, s, i);
304
+ n.push(l), r.push(i);
305
305
  }
306
306
  }
307
- return Promise.all(o).then((r) => {
307
+ return Promise.all(n).then((i) => {
308
308
  const a = new Array();
309
- for (let l = 0; l < r.length; l++) {
310
- const c = r[l], u = i[l];
309
+ for (let l = 0; l < i.length; l++) {
310
+ const c = i[l], u = r[l];
311
311
  c && c.isTexture === !0 ? a.push({ material: s, slot: u, texture: c, level: e }) : a.push({ material: s, slot: u, texture: null, level: e });
312
312
  }
313
313
  return a;
314
314
  });
315
315
  }
316
- if (t instanceof oe || t.isTexture === !0) {
316
+ if (t instanceof ne || t.isTexture === !0) {
317
317
  const s = t;
318
318
  return this.assignTextureLODForSlot(s, e, null, null);
319
319
  }
320
320
  return Promise.resolve(null);
321
321
  }
322
- static assignTextureLODForSlot(t, e, s, o) {
323
- return (t == null ? void 0 : t.isTexture) !== !0 ? Promise.resolve(null) : o === "glyphMap" ? Promise.resolve(t) : x.getOrLoadLOD(t, e).then((i) => {
324
- if (Array.isArray(i)) return null;
325
- if ((i == null ? void 0 : i.isTexture) === !0) {
326
- if (i != t && s && o) {
327
- const r = s[o];
328
- if (r && !w) {
329
- const a = this.getAssignedLODInformation(r);
322
+ static assignTextureLODForSlot(t, e, s, n) {
323
+ return (t == null ? void 0 : t.isTexture) !== !0 ? Promise.resolve(null) : n === "glyphMap" ? Promise.resolve(t) : w.getOrLoadLOD(t, e).then((r) => {
324
+ if (Array.isArray(r)) return null;
325
+ if ((r == null ? void 0 : r.isTexture) === !0) {
326
+ if (r != t && s && n) {
327
+ const i = s[n];
328
+ if (i && !y) {
329
+ const a = this.getAssignedLODInformation(i);
330
330
  if (a && (a == null ? void 0 : a.level) < e)
331
- return w === "verbose" && console.warn("Assigned texture level is already higher: ", a.level, e, s, r, i), null;
331
+ return y === "verbose" && console.warn("Assigned texture level is already higher: ", a.level, e, s, i, r), null;
332
332
  }
333
- s[o] = i;
333
+ s[n] = r;
334
334
  }
335
- return i;
336
- } else w == "verbose" && console.warn("No LOD found for", t, e);
335
+ return r;
336
+ } else y == "verbose" && console.warn("No LOD found for", t, e);
337
337
  return null;
338
- }).catch((i) => (console.error("Error loading LOD", t, i), null));
338
+ }).catch((r) => (console.error("Error loading LOD", t, r), null));
339
339
  }
340
340
  afterRoot(t) {
341
341
  var e, s;
342
- return w && console.log("AFTER", this.url, t), (e = this.parser.json.textures) == null || e.forEach((o, i) => {
343
- var r;
344
- if (o != null && o.extensions) {
345
- const a = o == null ? void 0 : o.extensions[K];
342
+ return y && console.log("AFTER", this.url, t), (e = this.parser.json.textures) == null || e.forEach((n, r) => {
343
+ var i;
344
+ if (n != null && n.extensions) {
345
+ const a = n == null ? void 0 : n.extensions[K];
346
346
  if (a) {
347
347
  if (!a.lods) {
348
- w && console.warn("Texture has no LODs", a);
348
+ y && console.warn("Texture has no LODs", a);
349
349
  return;
350
350
  }
351
351
  let l = !1;
352
352
  for (const c of this.parser.associations.keys())
353
353
  if (c.isTexture === !0) {
354
354
  const u = this.parser.associations.get(c);
355
- (u == null ? void 0 : u.textures) === i && (l = !0, x.registerTexture(this.url, c, (r = a.lods) == null ? void 0 : r.length, i, a));
355
+ (u == null ? void 0 : u.textures) === r && (l = !0, w.registerTexture(this.url, c, (i = a.lods) == null ? void 0 : i.length, r, a));
356
356
  }
357
- l || this.parser.getDependency("texture", i).then((c) => {
357
+ l || this.parser.getDependency("texture", r).then((c) => {
358
358
  var u;
359
- c && x.registerTexture(this.url, c, (u = a.lods) == null ? void 0 : u.length, i, a);
359
+ c && w.registerTexture(this.url, c, (u = a.lods) == null ? void 0 : u.length, r, a);
360
360
  });
361
361
  }
362
362
  }
363
- }), (s = this.parser.json.meshes) == null || s.forEach((o, i) => {
364
- if (o != null && o.extensions) {
365
- const r = o == null ? void 0 : o.extensions[K];
366
- if (r && r.lods) {
363
+ }), (s = this.parser.json.meshes) == null || s.forEach((n, r) => {
364
+ if (n != null && n.extensions) {
365
+ const i = n == null ? void 0 : n.extensions[K];
366
+ if (i && i.lods) {
367
367
  for (const a of this.parser.associations.keys())
368
368
  if (a.isMesh) {
369
369
  const l = this.parser.associations.get(a);
370
- (l == null ? void 0 : l.meshes) === i && x.registerMesh(this.url, r.guid, a, r.lods.length, l.primitives, r);
370
+ (l == null ? void 0 : l.meshes) === r && w.registerMesh(this.url, i.guid, a, i.lods.length, l.primitives, i);
371
371
  }
372
372
  }
373
373
  }
@@ -375,57 +375,57 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), x = c
375
375
  }
376
376
  static async getOrLoadLOD(t, e) {
377
377
  var a, l, c, u;
378
- const s = w == "verbose", o = t.userData.LODS;
379
- if (!o)
378
+ const s = y == "verbose", n = t.userData.LODS;
379
+ if (!n)
380
380
  return null;
381
- const i = o == null ? void 0 : o.key;
382
- let r;
381
+ const r = n == null ? void 0 : n.key;
382
+ let i;
383
383
  if (t.isTexture === !0) {
384
384
  const h = t;
385
- h.source && h.source[Oe] && (r = h.source[Oe]);
385
+ h.source && h.source[Oe] && (i = h.source[Oe]);
386
386
  }
387
- if (r || (r = x.lodInfos.get(i)), r) {
387
+ if (i || (i = w.lodInfos.get(r)), i) {
388
388
  if (e > 0) {
389
- let D = !1;
390
- const b = Array.isArray(r.lods);
391
- if (b && e >= r.lods.length ? D = !0 : b || (D = !0), D)
392
- return this.lowresCache.get(i);
389
+ let v = !1;
390
+ const b = Array.isArray(i.lods);
391
+ if (b && e >= i.lods.length ? v = !0 : b || (v = !0), v)
392
+ return this.lowresCache.get(r);
393
393
  }
394
- const h = Array.isArray(r.lods) ? (a = r.lods[e]) == null ? void 0 : a.path : r.lods;
394
+ const h = Array.isArray(i.lods) ? (a = i.lods[e]) == null ? void 0 : a.path : i.lods;
395
395
  if (!h)
396
- return w && !r["missing:uri"] && (r["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, r)), null;
397
- const g = ut(o.url, h);
396
+ return y && !i["missing:uri"] && (i["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, i)), null;
397
+ const g = ut(n.url, h);
398
398
  if (g.endsWith(".glb") || g.endsWith(".gltf")) {
399
- if (!r.guid)
400
- return console.warn("missing pointer for glb/gltf texture", r), null;
401
- const D = g + "_" + r.guid, b = this.previouslyLoaded.get(D);
399
+ if (!i.guid)
400
+ return console.warn("missing pointer for glb/gltf texture", i), null;
401
+ const v = g + "_" + i.guid, b = this.previouslyLoaded.get(v);
402
402
  if (b !== void 0) {
403
- s && console.log(`LOD ${e} was already loading/loaded: ${D}`);
404
- let _ = await b.catch((y) => (console.error(`Error loading LOD ${e} from ${g}
405
- `, y), null)), O = !1;
406
- if (_ == null || (_ instanceof oe && t instanceof oe ? (l = _.image) != null && l.data || (c = _.source) != null && c.data ? _ = this.copySettings(t, _) : (O = !0, this.previouslyLoaded.delete(D)) : _ instanceof me && t instanceof me && ((u = _.attributes.position) != null && u.array || (O = !0, this.previouslyLoaded.delete(D)))), !O)
407
- return _;
403
+ s && console.log(`LOD ${e} was already loading/loaded: ${v}`);
404
+ let D = await b.catch((m) => (console.error(`Error loading LOD ${e} from ${g}
405
+ `, m), null)), O = !1;
406
+ if (D == null || (D instanceof ne && t instanceof ne ? (l = D.image) != null && l.data || (c = D.source) != null && c.data ? D = this.copySettings(t, D) : (O = !0, this.previouslyLoaded.delete(v)) : D instanceof ye && t instanceof ye && ((u = D.attributes.position) != null && u.array || (O = !0, this.previouslyLoaded.delete(v)))), !O)
407
+ return D;
408
408
  }
409
- const v = r, F = new Promise(async (_, O) => {
410
- const y = new Ce();
411
- ze(y), w && (await new Promise((S) => setTimeout(S, 1e3)), s && console.warn("Start loading (delayed) " + g, v.guid));
409
+ const _ = i, F = new Promise(async (D, O) => {
410
+ const m = new Ce();
411
+ ze(m), y && (await new Promise((S) => setTimeout(S, 1e3)), s && console.warn("Start loading (delayed) " + g, _.guid));
412
412
  let X = g;
413
- if (v && Array.isArray(v.lods)) {
414
- const S = v.lods[e];
413
+ if (_ && Array.isArray(_.lods)) {
414
+ const S = _.lods[e];
415
415
  S.hash && (X += "?v=" + S.hash);
416
416
  }
417
- const P = await y.loadAsync(X).catch((S) => (console.error(`Error loading LOD ${e} from ${g}
417
+ const T = await m.loadAsync(X).catch((S) => (console.error(`Error loading LOD ${e} from ${g}
418
418
  `, S), null));
419
- if (!P) return null;
420
- const I = P.parser;
421
- s && console.log("Loading finished " + g, v.guid);
419
+ if (!T) return null;
420
+ const I = T.parser;
421
+ s && console.log("Loading finished " + g, _.guid);
422
422
  let B = 0;
423
- if (P.parser.json.textures) {
423
+ if (T.parser.json.textures) {
424
424
  let S = !1;
425
- for (const f of P.parser.json.textures) {
425
+ for (const f of T.parser.json.textures) {
426
426
  if (f != null && f.extensions) {
427
- const T = f == null ? void 0 : f.extensions[K];
428
- if (T != null && T.guid && T.guid === v.guid) {
427
+ const P = f == null ? void 0 : f.extensions[K];
428
+ if (P != null && P.guid && P.guid === _.guid) {
429
429
  S = !0;
430
430
  break;
431
431
  }
@@ -434,15 +434,15 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), x = c
434
434
  }
435
435
  if (S) {
436
436
  let f = await I.getDependency("texture", B);
437
- return f && x.assignLODInformation(o.url, f, i, e, void 0), s && console.log('change "' + t.name + '" → "' + f.name + '"', g, B, f, D), t instanceof oe && (f = this.copySettings(t, f)), f && (f.guid = v.guid), _(f);
438
- } else w && console.warn("Could not find texture with guid", v.guid, P.parser.json);
437
+ return f && w.assignLODInformation(n.url, f, r, e, void 0), s && console.log('change "' + t.name + '" → "' + f.name + '"', g, B, f, v), t instanceof ne && (f = this.copySettings(t, f)), f && (f.guid = _.guid), D(f);
438
+ } else y && console.warn("Could not find texture with guid", _.guid, T.parser.json);
439
439
  }
440
- if (B = 0, P.parser.json.meshes) {
440
+ if (B = 0, T.parser.json.meshes) {
441
441
  let S = !1;
442
- for (const f of P.parser.json.meshes) {
442
+ for (const f of T.parser.json.meshes) {
443
443
  if (f != null && f.extensions) {
444
- const T = f == null ? void 0 : f.extensions[K];
445
- if (T != null && T.guid && T.guid === v.guid) {
444
+ const P = f == null ? void 0 : f.extensions[K];
445
+ if (P != null && P.guid && P.guid === _.guid) {
446
446
  S = !0;
447
447
  break;
448
448
  }
@@ -451,39 +451,39 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), x = c
451
451
  }
452
452
  if (S) {
453
453
  const f = await I.getDependency("mesh", B);
454
- if (s && console.log(`Loaded Mesh "${f.name}"`, g, B, f, D), f.isMesh === !0) {
455
- const T = f.geometry;
456
- return x.assignLODInformation(o.url, T, i, e, 0), _(T);
454
+ if (s && console.log(`Loaded Mesh "${f.name}"`, g, B, f, v), f.isMesh === !0) {
455
+ const P = f.geometry;
456
+ return w.assignLODInformation(n.url, P, r, e, 0), D(P);
457
457
  } else {
458
- const T = new Array();
459
- for (let L = 0; L < f.children.length; L++) {
460
- const M = f.children[L];
458
+ const P = new Array();
459
+ for (let x = 0; x < f.children.length; x++) {
460
+ const M = f.children[x];
461
461
  if (M.isMesh === !0) {
462
462
  const A = M.geometry;
463
- x.assignLODInformation(o.url, A, i, e, L), T.push(A);
463
+ w.assignLODInformation(n.url, A, r, e, x), P.push(A);
464
464
  }
465
465
  }
466
- return _(T);
466
+ return D(P);
467
467
  }
468
- } else w && console.warn("Could not find mesh with guid", v.guid, P.parser.json);
468
+ } else y && console.warn("Could not find mesh with guid", _.guid, T.parser.json);
469
469
  }
470
- return _(null);
470
+ return D(null);
471
471
  });
472
- return this.previouslyLoaded.set(D, F), await F;
473
- } else if (t instanceof oe) {
472
+ return this.previouslyLoaded.set(v, F), await F;
473
+ } else if (t instanceof ne) {
474
474
  s && console.log("Load texture from uri: " + g);
475
475
  const b = await new Je().loadAsync(g);
476
- return b ? (b.guid = r.guid, b.flipY = !1, b.needsUpdate = !0, b.colorSpace = t.colorSpace, s && console.log(r, b)) : w && console.warn("failed loading", g), b;
476
+ return b ? (b.guid = i.guid, b.flipY = !1, b.needsUpdate = !0, b.colorSpace = t.colorSpace, s && console.log(i, b)) : y && console.warn("failed loading", g), b;
477
477
  }
478
478
  } else
479
- w && console.warn(`Can not load LOD ${e}: no LOD info found for "${i}" ${t.name}`, t.type);
479
+ y && console.warn(`Can not load LOD ${e}: no LOD info found for "${r}" ${t.name}`, t.type);
480
480
  return null;
481
481
  }
482
- static assignLODInformation(t, e, s, o, i) {
482
+ static assignLODInformation(t, e, s, n, r) {
483
483
  if (!e) return;
484
484
  e.userData || (e.userData = {});
485
- const r = new mt(t, s, o, i);
486
- e.userData.LODS = r;
485
+ const i = new yt(t, s, n, r);
486
+ e.userData.LODS = i;
487
487
  }
488
488
  static getAssignedLODInformation(t) {
489
489
  var e;
@@ -491,7 +491,7 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), x = c
491
491
  }
492
492
  // private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
493
493
  static copySettings(t, e) {
494
- return e ? (w && console.warn(`Copy texture settings
494
+ return e ? (y && console.warn(`Copy texture settings
495
495
  `, t.uuid, `
496
496
  `, 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;
497
497
  }
@@ -499,46 +499,46 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), x = c
499
499
  /**
500
500
  * Register a texture with LOD information
501
501
  */
502
- d(x, "registerTexture", (t, e, s, o, i) => {
503
- if (w && console.log("> Progressive: register texture", o, e.name, e.uuid, e, i), !e) {
504
- w && console.error("gltf-progressive: Register texture without texture");
502
+ d(w, "registerTexture", (t, e, s, n, r) => {
503
+ if (y && console.log("> Progressive: register texture", n, e.name, e.uuid, e, r), !e) {
504
+ y && console.error("gltf-progressive: Register texture without texture");
505
505
  return;
506
506
  }
507
- e.source && (e.source[Oe] = i);
508
- const r = i.guid;
509
- x.assignLODInformation(t, e, r, s, o), x.lodInfos.set(r, i), x.lowresCache.set(r, e);
507
+ e.source && (e.source[Oe] = r);
508
+ const i = r.guid;
509
+ w.assignLODInformation(t, e, i, s, n), w.lodInfos.set(i, r), w.lowresCache.set(i, e);
510
510
  }), /**
511
511
  * Register a mesh with LOD information
512
512
  */
513
- d(x, "registerMesh", (t, e, s, o, i, r) => {
513
+ d(w, "registerMesh", (t, e, s, n, r, i) => {
514
514
  var c;
515
515
  const a = s.geometry;
516
516
  if (!a) {
517
- w && console.warn("gltf-progressive: Register mesh without geometry");
517
+ y && console.warn("gltf-progressive: Register mesh without geometry");
518
518
  return;
519
519
  }
520
- a.userData || (a.userData = {}), w && console.log("> Progressive: register mesh " + s.name, { index: i, uuid: s.uuid }, r, s), x.assignLODInformation(t, a, e, o, i), x.lodInfos.set(e, r);
521
- let l = x.lowresCache.get(e);
522
- l ? l.push(s.geometry) : l = [s.geometry], x.lowresCache.set(e, l), o > 0 && !ue(s) && gt(s, a);
520
+ a.userData || (a.userData = {}), y && console.log("> Progressive: register mesh " + s.name, { index: r, uuid: s.uuid }, i, s), w.assignLODInformation(t, a, e, n, r), w.lodInfos.set(e, i);
521
+ let l = w.lowresCache.get(e);
522
+ l ? l.push(s.geometry) : l = [s.geometry], w.lowresCache.set(e, l), n > 0 && !ue(s) && gt(s, a);
523
523
  for (const u of Q)
524
- (c = u.onRegisteredNewMesh) == null || c.call(u, s, r);
524
+ (c = u.onRegisteredNewMesh) == null || c.call(u, s, i);
525
525
  }), /** A map of key = asset uuid and value = LOD information */
526
- d(x, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
527
- d(x, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
528
- d(x, "lowresCache", /* @__PURE__ */ new Map());
529
- let z = x;
530
- class mt {
531
- constructor(t, e, s, o) {
526
+ d(w, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
527
+ d(w, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
528
+ d(w, "lowresCache", /* @__PURE__ */ new Map());
529
+ let z = w;
530
+ class yt {
531
+ constructor(t, e, s, n) {
532
532
  d(this, "url");
533
533
  /** the key to lookup the LOD information */
534
534
  d(this, "key");
535
535
  d(this, "level");
536
536
  /** For multi objects (e.g. a group of meshes) this is the index of the object */
537
537
  d(this, "index");
538
- this.url = t, this.key = e, this.level = s, o != null && (this.index = o);
538
+ this.url = t, this.key = e, this.level = s, n != null && (this.index = n);
539
539
  }
540
540
  }
541
- class ye {
541
+ class me {
542
542
  constructor(t, e) {
543
543
  d(this, "frame_start");
544
544
  d(this, "frame_capture_end");
@@ -550,16 +550,18 @@ class ye {
550
550
  d(this, "_resolvedCount", 0);
551
551
  /** These promises are currently being awaited */
552
552
  d(this, "_awaiting", []);
553
+ d(this, "_maxPromisesPerObject", 1);
553
554
  d(this, "_currentFrame", 0);
554
- var i;
555
- const s = t === 0 ? 2 : 1, o = Math.max(e.frames ?? s, s);
556
- this.frame_start = t, this.frame_capture_end = t + o, this.ready = new Promise((r) => {
557
- this._resolve = r;
555
+ d(this, "_seen", /* @__PURE__ */ new WeakMap());
556
+ var r;
557
+ const n = Math.max(e.frames ?? 2, 2);
558
+ this.frame_start = t, this.frame_capture_end = t + n, this.ready = new Promise((i) => {
559
+ this._resolve = i;
558
560
  }), this.ready.finally(() => {
559
561
  this._resolved = !0, this._awaiting.length = 0;
560
- }), this._signal = e.signal, (i = this._signal) == null || i.addEventListener("abort", () => {
562
+ }), this._signal = e.signal, (r = this._signal) == null || r.addEventListener("abort", () => {
561
563
  this.resolveNow();
562
- });
564
+ }), this._maxPromisesPerObject = Math.max(1, e.maxPromisesPerObject ?? 1);
563
565
  }
564
566
  /**
565
567
  * The number of promises that have been added to this group so far.
@@ -577,14 +579,26 @@ class ye {
577
579
  var e;
578
580
  this._currentFrame = t, ((e = this._signal) != null && e.aborted || this._currentFrame > this.frame_capture_end && this._awaiting.length === 0) && this.resolveNow();
579
581
  }
580
- add(t, e) {
582
+ add(t, e, s) {
581
583
  if (this._resolved) {
582
- console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");
584
+ y && console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");
583
585
  return;
584
586
  }
585
- this._currentFrame > this.frame_capture_end || (this._awaiting.push(e), this._addedCount++, e.finally(() => {
586
- this._resolvedCount++, this._awaiting.splice(this._awaiting.indexOf(e), 1);
587
- }));
587
+ if (!(this._currentFrame > this.frame_capture_end)) {
588
+ if (this._maxPromisesPerObject >= 1)
589
+ if (this._seen.has(e)) {
590
+ let n = this._seen.get(e);
591
+ if (n >= this._maxPromisesPerObject) {
592
+ y && console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");
593
+ return;
594
+ }
595
+ this._seen.set(e, n + 1);
596
+ } else
597
+ this._seen.set(e, 1);
598
+ this._awaiting.push(s), this._addedCount++, s.finally(() => {
599
+ this._resolvedCount++, this._awaiting.splice(this._awaiting.indexOf(s), 1);
600
+ });
601
+ }
588
602
  }
589
603
  resolveNow() {
590
604
  var t, e;
@@ -595,14 +609,14 @@ class ye {
595
609
  });
596
610
  }
597
611
  }
598
- d(ye, "addPromise", (t, e, s) => {
599
- s.forEach((o) => {
600
- o.add(t, e);
612
+ d(me, "addPromise", (t, e, s, n) => {
613
+ n.forEach((r) => {
614
+ r.add(t, e, s);
601
615
  });
602
616
  });
603
617
  const k = de("debugprogressive"), Lt = de("noprogressive"), be = Symbol("Needle:LODSManager"), Se = Symbol("Needle:LODState"), J = Symbol("Needle:CurrentLOD"), C = { mesh_lod: -1, texture_lod: -1 };
604
- var m, E, Y, we, Z, re, ve, H;
605
- let xe = (m = class {
618
+ var L, E, Y, we, Z, re, _e, H;
619
+ let xe = (L = class {
606
620
  // readonly plugins: NEEDLE_progressive_plugin[] = [];
607
621
  constructor(t, e) {
608
622
  d(this, "renderer");
@@ -643,7 +657,7 @@ let xe = (m = class {
643
657
  j(this, we, new Qe());
644
658
  j(this, Z, 0);
645
659
  j(this, re, 0);
646
- j(this, ve, 0);
660
+ j(this, _e, 0);
647
661
  j(this, H, 0);
648
662
  d(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
649
663
  // private testIfLODLevelsAreAvailable() {
@@ -675,7 +689,7 @@ let xe = (m = class {
675
689
  static get(t, e) {
676
690
  if (t[be])
677
691
  return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[be];
678
- const s = new m(t, {
692
+ const s = new L(t, {
679
693
  engine: "unknown",
680
694
  ...e
681
695
  });
@@ -689,13 +703,13 @@ let xe = (m = class {
689
703
  * Call to await LODs loading during the next render cycle.
690
704
  */
691
705
  awaitLoading(t) {
692
- const e = this._promiseGroupIds++, s = new ye(p(this, Z), { ...t });
706
+ const e = this._promiseGroupIds++, s = new me(p(this, Z), { ...t });
693
707
  this._newPromiseGroups.push(s);
694
- const o = performance.now();
708
+ const n = performance.now();
695
709
  return s.ready.finally(() => {
696
- const i = this._newPromiseGroups.indexOf(s);
697
- i >= 0 && (this._newPromiseGroups.splice(i, 1), ft() && performance.measure("LODsManager:awaitLoading", {
698
- start: o,
710
+ const r = this._newPromiseGroups.indexOf(s);
711
+ r >= 0 && (this._newPromiseGroups.splice(r, 1), ft() && performance.measure("LODsManager:awaitLoading", {
712
+ start: n,
699
713
  detail: { id: e, name: t == null ? void 0 : t.name, awaited: s.awaitedCount, resolved: s.resolvedCount }
700
714
  }));
701
715
  }), s.ready;
@@ -723,11 +737,11 @@ let xe = (m = class {
723
737
  let t = 0;
724
738
  N(this, Y, this.renderer.render);
725
739
  const e = this;
726
- Ne(this.renderer), this.renderer.render = function(s, o) {
727
- const i = e.renderer.getRenderTarget();
728
- (i == null || "isXRRenderTarget" in i && i.isXRRenderTarget) && (t = 0, N(e, Z, p(e, Z) + 1), N(e, re, p(e, we).getDelta()), N(e, ve, p(e, ve) + p(e, re)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / p(e, re)), N(e, H, e._fpsBuffer.reduce((a, l) => a + l) / e._fpsBuffer.length), k && p(e, Z) % 200 === 0 && console.log("FPS", Math.round(p(e, H)), "Interval:", p(e, E)));
729
- const r = t++;
730
- p(e, Y).call(this, s, o), e.onAfterRender(s, o, r);
740
+ Ne(this.renderer), this.renderer.render = function(s, n) {
741
+ const r = e.renderer.getRenderTarget();
742
+ (r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (t = 0, N(e, Z, p(e, Z) + 1), N(e, re, p(e, we).getDelta()), N(e, _e, p(e, _e) + p(e, re)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / p(e, re)), N(e, H, e._fpsBuffer.reduce((a, l) => a + l) / e._fpsBuffer.length), k && p(e, Z) % 200 === 0 && console.log("FPS", Math.round(p(e, H)), "Interval:", p(e, E)));
743
+ const i = t++;
744
+ p(e, Y).call(this, s, n), e.onAfterRender(s, n, i);
731
745
  };
732
746
  }
733
747
  disable() {
@@ -738,13 +752,13 @@ let xe = (m = class {
738
752
  }
739
753
  onAfterRender(t, e, s) {
740
754
  if (this.pause) return;
741
- const i = this.renderer.renderLists.get(t, 0).opaque;
742
- let r = !0;
743
- if (i.length === 1) {
744
- const a = i[0].material;
745
- (a.name === "EffectMaterial" || a.name === "CopyShader") && (r = !1);
755
+ const r = this.renderer.renderLists.get(t, 0).opaque;
756
+ let i = !0;
757
+ if (r.length === 1) {
758
+ const a = r[0].material;
759
+ (a.name === "EffectMaterial" || a.name === "CopyShader") && (i = !1);
746
760
  }
747
- if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (r = !1), r) {
761
+ if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (i = !1), i) {
748
762
  if (Lt || (this.updateInterval === "auto" ? p(this, H) < 40 && p(this, E) < 10 ? (N(this, E, p(this, E) + 1), k && console.warn("↓ Reducing LOD updates", p(this, E), p(this, H).toFixed(0))) : p(this, H) >= 60 && p(this, E) > 1 && (N(this, E, p(this, E) - 1), k && console.warn("↑ Increasing LOD updates", p(this, E), p(this, H).toFixed(0))) : N(this, E, this.updateInterval), p(this, E) > 0 && p(this, Z) % p(this, E) != 0))
749
763
  return;
750
764
  this.internalUpdate(t, e), this._postprocessPromiseGroups();
@@ -755,10 +769,10 @@ let xe = (m = class {
755
769
  */
756
770
  internalUpdate(t, e) {
757
771
  var l, c;
758
- const s = this.renderer.renderLists.get(t, 0), o = s.opaque;
772
+ const s = this.renderer.renderLists.get(t, 0), n = s.opaque;
759
773
  this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix, e.matrixWorldInverse);
760
- const i = this.targetTriangleDensity;
761
- for (const u of o) {
774
+ const r = this.targetTriangleDensity;
775
+ for (const u of n) {
762
776
  if (u.material && (((l = u.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((c = u.geometry) == null ? void 0 : c.type) === "BufferGeometry") && (u.material.name === "SphericalGaussianBlur" || u.material.name == "BackgroundCubeMaterial" || u.material.name === "CubemapFromEquirect" || u.material.name === "EquirectangularToCubeUV")) {
763
777
  k && (u.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (u.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", u, u.material.name, u.material.type)));
764
778
  continue;
@@ -774,37 +788,37 @@ let xe = (m = class {
774
788
  }
775
789
  if (k === "color" && u.material && !u.object.progressive_debug_color) {
776
790
  u.object.progressive_debug_color = !0;
777
- const g = Math.random() * 16777215, D = new Ze({ color: g });
778
- u.object.material = D;
791
+ const g = Math.random() * 16777215, v = new Ze({ color: g });
792
+ u.object.material = v;
779
793
  }
780
794
  const h = u.object;
781
- (h instanceof te || h.isMesh) && this.updateLODs(t, e, h, i);
795
+ (h instanceof te || h.isMesh) && this.updateLODs(t, e, h, r);
782
796
  }
783
- const r = s.transparent;
784
- for (const u of r) {
797
+ const i = s.transparent;
798
+ for (const u of i) {
785
799
  const h = u.object;
786
- (h instanceof te || h.isMesh) && this.updateLODs(t, e, h, i);
800
+ (h instanceof te || h.isMesh) && this.updateLODs(t, e, h, r);
787
801
  }
788
802
  const a = s.transmissive;
789
803
  for (const u of a) {
790
804
  const h = u.object;
791
- (h instanceof te || h.isMesh) && this.updateLODs(t, e, h, i);
805
+ (h instanceof te || h.isMesh) && this.updateLODs(t, e, h, r);
792
806
  }
793
807
  }
794
808
  /** Update the LOD levels for the renderer. */
795
- updateLODs(t, e, s, o) {
809
+ updateLODs(t, e, s, n) {
796
810
  var a, l;
797
811
  s.userData || (s.userData = {});
798
- let i = s[Se];
799
- if (i || (i = new xt(), s[Se] = i), i.frames++ < 2)
812
+ let r = s[Se];
813
+ if (r || (r = new xt(), s[Se] = r), r.frames++ < 2)
800
814
  return;
801
815
  for (const c of Q)
802
816
  (a = c.onBeforeUpdateLOD) == null || a.call(c, this.renderer, t, e, s);
803
- const r = m.overrideGlobalLodLevel !== void 0 ? m.overrideGlobalLodLevel : ee;
804
- r >= 0 ? (C.mesh_lod = r, C.texture_lod = r) : (this.calculateLodLevel(e, s, i, o, C), C.mesh_lod = Math.round(C.mesh_lod), C.texture_lod = Math.round(C.texture_lod)), C.mesh_lod >= 0 && this.loadProgressiveMeshes(s, C.mesh_lod), s.material && C.texture_lod >= 0 && this.loadProgressiveTextures(s.material, C.texture_lod), w && s.material && !s.isGizmo && We(s.material);
817
+ const i = L.overrideGlobalLodLevel !== void 0 ? L.overrideGlobalLodLevel : ee;
818
+ i >= 0 ? (C.mesh_lod = i, C.texture_lod = i) : (this.calculateLodLevel(e, s, r, n, C), C.mesh_lod = Math.round(C.mesh_lod), C.texture_lod = Math.round(C.texture_lod)), C.mesh_lod >= 0 && this.loadProgressiveMeshes(s, C.mesh_lod), s.material && C.texture_lod >= 0 && this.loadProgressiveTextures(s.material, C.texture_lod), y && s.material && !s.isGizmo && We(s.material);
805
819
  for (const c of Q)
806
820
  (l = c.onAfterUpdatedLOD) == null || l.call(c, this.renderer, t, e, s, C);
807
- i.lastLodLevel_Mesh = C.mesh_lod, i.lastLodLevel_Texture = C.texture_lod;
821
+ r.lastLodLevel_Mesh = C.mesh_lod, r.lastLodLevel_Texture = C.texture_lod;
808
822
  }
809
823
  /** Load progressive textures for the given material
810
824
  * @param material the material to load the textures for
@@ -814,19 +828,19 @@ let xe = (m = class {
814
828
  loadProgressiveTextures(t, e) {
815
829
  if (!t) return;
816
830
  if (Array.isArray(t)) {
817
- for (const i of t)
818
- this.loadProgressiveTextures(i, e);
831
+ for (const r of t)
832
+ this.loadProgressiveTextures(r, e);
819
833
  return;
820
834
  }
821
835
  let s = !1;
822
836
  (t[J] === void 0 || e < t[J]) && (s = !0);
823
- const o = t["DEBUG:LOD"];
824
- if (o != null && (s = t[J] != o, e = o), s) {
837
+ const n = t["DEBUG:LOD"];
838
+ if (n != null && (s = t[J] != n, e = n), s) {
825
839
  t[J] = e;
826
- const i = z.assignTextureLOD(t, e).then((r) => {
840
+ const r = z.assignTextureLOD(t, e).then((i) => {
827
841
  this._lodchangedlisteners.forEach((a) => a({ type: "texture", level: e, object: t }));
828
842
  });
829
- ye.addPromise("texture", i, this._newPromiseGroups);
843
+ me.addPromise("texture", t, r, this._newPromiseGroups);
830
844
  }
831
845
  }
832
846
  /** Load progressive meshes for the given mesh
@@ -838,120 +852,120 @@ let xe = (m = class {
838
852
  loadProgressiveMeshes(t, e) {
839
853
  if (!t) return Promise.resolve(null);
840
854
  let s = t[J] !== e;
841
- const o = t["DEBUG:LOD"];
842
- if (o != null && (s = t[J] != o, e = o), s) {
855
+ const n = t["DEBUG:LOD"];
856
+ if (n != null && (s = t[J] != n, e = n), s) {
843
857
  t[J] = e;
844
- const i = t.geometry, r = z.assignMeshLOD(t, e).then((a) => (a && t[J] == e && i != t.geometry && this._lodchangedlisteners.forEach((l) => l({ type: "mesh", level: e, object: t })), a));
845
- return ye.addPromise("mesh", r, this._newPromiseGroups), r;
858
+ const r = t.geometry, i = z.assignMeshLOD(t, e).then((a) => (a && t[J] == e && r != t.geometry && this._lodchangedlisteners.forEach((l) => l({ type: "mesh", level: e, object: t })), a));
859
+ return me.addPromise("mesh", t, i, this._newPromiseGroups), i;
846
860
  }
847
861
  return Promise.resolve(null);
848
862
  }
849
863
  static isInside(t, e) {
850
- const s = t.min, o = t.max, i = (s.x + o.x) * 0.5, r = (s.y + o.y) * 0.5;
851
- return this._tempPtInside.set(i, r, s.z).applyMatrix4(e).z < 0;
864
+ const s = t.min, n = t.max, r = (s.x + n.x) * 0.5, i = (s.y + n.y) * 0.5;
865
+ return this._tempPtInside.set(r, i, s.z).applyMatrix4(e).z < 0;
852
866
  }
853
- calculateLodLevel(t, e, s, o, i) {
854
- var F, W, _;
867
+ calculateLodLevel(t, e, s, n, r) {
868
+ var F, W, D;
855
869
  if (!e) {
856
- i.mesh_lod = -1, i.texture_lod = -1;
870
+ r.mesh_lod = -1, r.texture_lod = -1;
857
871
  return;
858
872
  }
859
873
  if (!t) {
860
- i.mesh_lod = -1, i.texture_lod = -1;
874
+ r.mesh_lod = -1, r.texture_lod = -1;
861
875
  return;
862
876
  }
863
877
  let a = 10 + 1, l = !1;
864
878
  if (k && e["DEBUG:LOD"] != null)
865
879
  return e["DEBUG:LOD"];
866
- const c = (F = z.getMeshLODExtension(e.geometry)) == null ? void 0 : F.lods, u = z.getPrimitiveIndex(e.geometry), h = c && c.length > 0, g = z.getMaterialMinMaxLODsCount(e.material), D = (g == null ? void 0 : g.min_count) != 1 / 0 && g.min_count > 0 && g.max_count > 0;
867
- if (!h && !D) {
868
- i.mesh_lod = 0, i.texture_lod = 0;
880
+ const c = (F = z.getMeshLODExtension(e.geometry)) == null ? void 0 : F.lods, u = z.getPrimitiveIndex(e.geometry), h = c && c.length > 0, g = z.getMaterialMinMaxLODsCount(e.material), v = (g == null ? void 0 : g.min_count) != 1 / 0 && g.min_count > 0 && g.max_count > 0;
881
+ if (!h && !v) {
882
+ r.mesh_lod = 0, r.texture_lod = 0;
869
883
  return;
870
884
  }
871
885
  h || (l = !0, a = 0);
872
886
  const b = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
873
- let v = e.geometry.boundingBox;
887
+ let _ = e.geometry.boundingBox;
874
888
  if (e.type === "SkinnedMesh") {
875
889
  const O = e;
876
890
  if (!O.boundingBox)
877
891
  O.computeBoundingBox();
878
892
  else if (this.skinnedMeshAutoUpdateBoundsInterval > 0 && s.frames % this.skinnedMeshAutoUpdateBoundsInterval === 0) {
879
- const y = ue(O), X = O.geometry;
880
- y && (O.geometry = y), O.computeBoundingBox(), O.geometry = X;
893
+ const m = ue(O), X = O.geometry;
894
+ m && (O.geometry = m), O.computeBoundingBox(), O.geometry = X;
881
895
  }
882
- v = O.boundingBox;
896
+ _ = O.boundingBox;
883
897
  }
884
- if (v) {
898
+ if (_) {
885
899
  const O = t;
886
900
  if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
887
901
  this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
888
- const L = t.getWorldPosition(this._tempWorldPosition);
889
- if (this._sphere.containsPoint(L)) {
890
- i.mesh_lod = 0, i.texture_lod = 0;
902
+ const x = t.getWorldPosition(this._tempWorldPosition);
903
+ if (this._sphere.containsPoint(x)) {
904
+ r.mesh_lod = 0, r.texture_lod = 0;
891
905
  return;
892
906
  }
893
907
  }
894
- if (this._tempBox.copy(v), this._tempBox.applyMatrix4(e.matrixWorld), O.isPerspectiveCamera && m.isInside(this._tempBox, this.projectionScreenMatrix)) {
895
- i.mesh_lod = 0, i.texture_lod = 0;
908
+ if (this._tempBox.copy(_), this._tempBox.applyMatrix4(e.matrixWorld), O.isPerspectiveCamera && L.isInside(this._tempBox, this.projectionScreenMatrix)) {
909
+ r.mesh_lod = 0, r.texture_lod = 0;
896
910
  return;
897
911
  }
898
912
  if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && O.isPerspectiveCamera && O.fov > 70) {
899
- const L = this._tempBox.min, M = this._tempBox.max;
900
- let A = L.x, R = L.y, U = M.x, ie = M.y;
901
- const ce = 2, De = 1.5, fe = (L.x + M.x) * 0.5, he = (L.y + M.y) * 0.5;
913
+ const x = this._tempBox.min, M = this._tempBox.max;
914
+ let A = x.x, R = x.y, U = M.x, ie = M.y;
915
+ const ce = 2, ve = 1.5, fe = (x.x + M.x) * 0.5, he = (x.y + M.y) * 0.5;
902
916
  A = (A - fe) * ce + fe, R = (R - he) * ce + he, U = (U - fe) * ce + fe, ie = (ie - he) * ce + he;
903
- const Ke = A < 0 && U > 0 ? 0 : Math.min(Math.abs(L.x), Math.abs(M.x)), Ye = R < 0 && ie > 0 ? 0 : Math.min(Math.abs(L.y), Math.abs(M.y)), _e = Math.max(Ke, Ye);
904
- s.lastCentrality = (De - _e) * (De - _e) * (De - _e);
917
+ const Ke = A < 0 && U > 0 ? 0 : Math.min(Math.abs(x.x), Math.abs(M.x)), Ye = R < 0 && ie > 0 ? 0 : Math.min(Math.abs(x.y), Math.abs(M.y)), De = Math.max(Ke, Ye);
918
+ s.lastCentrality = (ve - De) * (ve - De) * (ve - De);
905
919
  } else
906
920
  s.lastCentrality = 1;
907
- const y = this._tempBox.getSize(this._tempBoxSize);
908
- y.multiplyScalar(0.5), screen.availHeight > 0 && b > 0 && y.multiplyScalar(b / screen.availHeight), t.isPerspectiveCamera ? y.x *= t.aspect : t.isOrthographicCamera;
909
- const X = t.matrixWorldInverse, P = this._tempBox2;
910
- P.copy(v), P.applyMatrix4(e.matrixWorld), P.applyMatrix4(X);
911
- const I = P.getSize(this._tempBox2Size), B = Math.max(I.x, I.y);
912
- if (Math.max(y.x, y.y) != 0 && B != 0 && (y.z = I.z / Math.max(I.x, I.y) * Math.max(y.x, y.y)), s.lastScreenCoverage = Math.max(y.x, y.y, y.z), s.lastScreenspaceVolume.copy(y), s.lastScreenCoverage *= s.lastCentrality, k && m.debugDrawLine) {
913
- const L = this.tempMatrix.copy(this.projectionScreenMatrix);
914
- L.invert();
915
- const M = m.corner0, A = m.corner1, R = m.corner2, U = m.corner3;
921
+ const m = this._tempBox.getSize(this._tempBoxSize);
922
+ m.multiplyScalar(0.5), screen.availHeight > 0 && b > 0 && m.multiplyScalar(b / screen.availHeight), t.isPerspectiveCamera ? m.x *= t.aspect : t.isOrthographicCamera;
923
+ const X = t.matrixWorldInverse, T = this._tempBox2;
924
+ T.copy(_), T.applyMatrix4(e.matrixWorld), T.applyMatrix4(X);
925
+ const I = T.getSize(this._tempBox2Size), B = Math.max(I.x, I.y);
926
+ if (Math.max(m.x, m.y) != 0 && B != 0 && (m.z = I.z / Math.max(I.x, I.y) * Math.max(m.x, m.y)), s.lastScreenCoverage = Math.max(m.x, m.y, m.z), s.lastScreenspaceVolume.copy(m), s.lastScreenCoverage *= s.lastCentrality, k && L.debugDrawLine) {
927
+ const x = this.tempMatrix.copy(this.projectionScreenMatrix);
928
+ x.invert();
929
+ const M = L.corner0, A = L.corner1, R = L.corner2, U = L.corner3;
916
930
  M.copy(this._tempBox.min), A.copy(this._tempBox.max), A.x = M.x, R.copy(this._tempBox.max), R.y = M.y, U.copy(this._tempBox.max);
917
931
  const ie = (M.z + U.z) * 0.5;
918
- M.z = A.z = R.z = U.z = ie, M.applyMatrix4(L), A.applyMatrix4(L), R.applyMatrix4(L), U.applyMatrix4(L), m.debugDrawLine(M, A, 255), m.debugDrawLine(M, R, 255), m.debugDrawLine(A, U, 255), m.debugDrawLine(R, U, 255);
932
+ M.z = A.z = R.z = U.z = ie, M.applyMatrix4(x), A.applyMatrix4(x), R.applyMatrix4(x), U.applyMatrix4(x), L.debugDrawLine(M, A, 255), L.debugDrawLine(M, R, 255), L.debugDrawLine(A, U, 255), L.debugDrawLine(R, U, 255);
919
933
  }
920
934
  let f = 999;
921
935
  if (c && s.lastScreenCoverage > 0)
922
- for (let L = 0; L < c.length; L++) {
923
- const M = c[L];
924
- if ((((W = M.densities) == null ? void 0 : W[u]) || M.density || 1e-5) / s.lastScreenCoverage < o) {
925
- f = L;
936
+ for (let x = 0; x < c.length; x++) {
937
+ const M = c[x];
938
+ if ((((W = M.densities) == null ? void 0 : W[u]) || M.density || 1e-5) / s.lastScreenCoverage < n) {
939
+ f = x;
926
940
  break;
927
941
  }
928
942
  }
929
943
  f < a && (a = f, l = !0);
930
944
  }
931
- if (l ? i.mesh_lod = a : i.mesh_lod = s.lastLodLevel_Mesh, k && i.mesh_lod != s.lastLodLevel_Mesh) {
932
- const y = c == null ? void 0 : c[i.mesh_lod];
933
- y && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${i.mesh_lod} (${y.density.toFixed(0)}) - ${e.name}`);
945
+ if (l ? r.mesh_lod = a : r.mesh_lod = s.lastLodLevel_Mesh, k && r.mesh_lod != s.lastLodLevel_Mesh) {
946
+ const m = c == null ? void 0 : c[r.mesh_lod];
947
+ m && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${r.mesh_lod} (${m.density.toFixed(0)}) - ${e.name}`);
934
948
  }
935
- if (D) {
949
+ if (v) {
936
950
  const O = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
937
951
  if (s.lastLodLevel_Texture < 0) {
938
- if (i.texture_lod = g.max_count - 1, k) {
939
- const y = g.lods[g.max_count - 1];
940
- k && console.log(`First Texture LOD ${i.texture_lod} (${y.max_height}px) - ${e.name}`);
952
+ if (r.texture_lod = g.max_count - 1, k) {
953
+ const m = g.lods[g.max_count - 1];
954
+ k && console.log(`First Texture LOD ${r.texture_lod} (${m.max_height}px) - ${e.name}`);
941
955
  }
942
956
  } else {
943
- const y = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
957
+ const m = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
944
958
  let X = s.lastScreenCoverage * 4;
945
- ((_ = this.context) == null ? void 0 : _.engine) === "model-viewer" && (X *= 1.5);
959
+ ((D = this.context) == null ? void 0 : D.engine) === "model-viewer" && (X *= 1.5);
946
960
  const I = b / window.devicePixelRatio * X;
947
961
  let B = !1;
948
962
  for (let S = g.lods.length - 1; S >= 0; S--) {
949
963
  const f = g.lods[S];
950
964
  if (!(O && f.max_height >= 2048) && !(ct() && f.max_height > 4096) && (f.max_height > I || !B && S === 0)) {
951
- if (B = !0, i.texture_lod = S, i.texture_lod < s.lastLodLevel_Texture) {
952
- const T = f.max_height;
953
- k && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${i.texture_lod} = ${T}px
954
- Screensize: ${I.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${y.toFixed(1)}
965
+ if (B = !0, r.texture_lod = S, r.texture_lod < s.lastLodLevel_Texture) {
966
+ const P = f.max_height;
967
+ k && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${r.texture_lod} = ${P}px
968
+ Screensize: ${I.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${m.toFixed(1)}
955
969
  ${e.name}`);
956
970
  }
957
971
  break;
@@ -959,15 +973,15 @@ ${e.name}`);
959
973
  }
960
974
  }
961
975
  } else
962
- i.texture_lod = 0;
976
+ r.texture_lod = 0;
963
977
  }
964
- }, E = new WeakMap(), Y = new WeakMap(), we = new WeakMap(), Z = new WeakMap(), re = new WeakMap(), ve = new WeakMap(), H = new WeakMap(), /**
978
+ }, E = new WeakMap(), Y = new WeakMap(), we = new WeakMap(), Z = new WeakMap(), re = new WeakMap(), _e = new WeakMap(), H = new WeakMap(), /**
965
979
  * 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.
966
980
  */
967
- d(m, "debugDrawLine"), /**
981
+ d(L, "debugDrawLine"), /**
968
982
  * Force override the LOD level for all objects in the scene
969
983
  */
970
- d(m, "overrideGlobalLodLevel"), d(m, "corner0", new q()), d(m, "corner1", new q()), d(m, "corner2", new q()), d(m, "corner3", new q()), d(m, "_tempPtInside", new q()), m);
984
+ d(L, "overrideGlobalLodLevel"), d(L, "corner0", new q()), d(L, "corner1", new q()), d(L, "corner2", new q()), d(L, "corner3", new q()), d(L, "_tempPtInside", new q()), L);
971
985
  class xt {
972
986
  constructor() {
973
987
  d(this, "frames", 0);
@@ -981,8 +995,8 @@ class xt {
981
995
  const Re = Symbol("NEEDLE_mesh_lod"), ge = Symbol("NEEDLE_texture_lod");
982
996
  let le = null;
983
997
  function Xe() {
984
- const n = wt();
985
- n && (n.mapURLs(function(t) {
998
+ const o = wt();
999
+ o && (o.mapURLs(function(t) {
986
1000
  return ke(), t;
987
1001
  }), ke(), le == null || le.disconnect(), le = new MutationObserver((t) => {
988
1002
  t.forEach((e) => {
@@ -994,8 +1008,8 @@ function Xe() {
994
1008
  }
995
1009
  function wt() {
996
1010
  if (typeof customElements > "u") return null;
997
- const n = customElements.get("model-viewer");
998
- return n || (customElements.whenDefined("model-viewer").then(() => {
1011
+ const o = customElements.get("model-viewer");
1012
+ return o || (customElements.whenDefined("model-viewer").then(() => {
999
1013
  console.debug("[gltf-progressive] model-viewer defined"), Xe();
1000
1014
  }), null);
1001
1015
  }
@@ -1006,49 +1020,49 @@ function ke() {
1006
1020
  });
1007
1021
  }
1008
1022
  const $e = /* @__PURE__ */ new WeakSet();
1009
- let vt = 0;
1010
- function qe(n) {
1011
- if (!n || $e.has(n))
1023
+ let _t = 0;
1024
+ function qe(o) {
1025
+ if (!o || $e.has(o))
1012
1026
  return null;
1013
- $e.add(n), console.debug("[gltf-progressive] found new model-viewer..." + ++vt + `
1014
- `, n.getAttribute("src"));
1027
+ $e.add(o), console.debug("[gltf-progressive] found new model-viewer..." + ++_t + `
1028
+ `, o.getAttribute("src"));
1015
1029
  let t = null, e = null, s = null;
1016
- for (let o = n; o != null; o = Object.getPrototypeOf(o)) {
1017
- const i = Object.getOwnPropertySymbols(o), r = i.find((c) => c.toString() == "Symbol(renderer)"), a = i.find((c) => c.toString() == "Symbol(scene)"), l = i.find((c) => c.toString() == "Symbol(needsRender)");
1018
- !t && r != null && (t = n[r].threeRenderer), !e && a != null && (e = n[a]), !s && l != null && (s = n[l]);
1030
+ for (let n = o; n != null; n = Object.getPrototypeOf(n)) {
1031
+ const r = Object.getOwnPropertySymbols(n), i = r.find((c) => c.toString() == "Symbol(renderer)"), a = r.find((c) => c.toString() == "Symbol(scene)"), l = r.find((c) => c.toString() == "Symbol(needsRender)");
1032
+ !t && i != null && (t = o[i].threeRenderer), !e && a != null && (e = o[a]), !s && l != null && (s = o[l]);
1019
1033
  }
1020
1034
  if (t && e) {
1021
- let o = function() {
1035
+ let n = function() {
1022
1036
  if (s) {
1023
- let r = 0, a = setInterval(() => {
1024
- if (r++ > 5) {
1037
+ let i = 0, a = setInterval(() => {
1038
+ if (i++ > 5) {
1025
1039
  clearInterval(a);
1026
1040
  return;
1027
1041
  }
1028
- s == null || s.call(n);
1042
+ s == null || s.call(o);
1029
1043
  }, 300);
1030
1044
  }
1031
1045
  };
1032
1046
  console.debug("[gltf-progressive] setup model-viewer");
1033
- const i = xe.get(t, { engine: "model-viewer" });
1034
- return xe.addPlugin(new Dt()), i.enable(), i.addEventListener("changed", () => {
1035
- s == null || s.call(n);
1036
- }), n.addEventListener("model-visibility", (r) => {
1037
- r.detail.visible && (s == null || s.call(n));
1038
- }), n.addEventListener("load", () => {
1039
- o();
1047
+ const r = xe.get(t, { engine: "model-viewer" });
1048
+ return xe.addPlugin(new vt()), r.enable(), r.addEventListener("changed", () => {
1049
+ s == null || s.call(o);
1050
+ }), o.addEventListener("model-visibility", (i) => {
1051
+ i.detail.visible && (s == null || s.call(o));
1052
+ }), o.addEventListener("load", () => {
1053
+ n();
1040
1054
  }), () => {
1041
- i.disable();
1055
+ r.disable();
1042
1056
  };
1043
1057
  }
1044
1058
  return null;
1045
1059
  }
1046
- class Dt {
1060
+ class vt {
1047
1061
  constructor() {
1048
1062
  d(this, "_didWarnAboutMissingUrl", !1);
1049
1063
  }
1050
- onBeforeUpdateLOD(t, e, s, o) {
1051
- this.tryParseMeshLOD(e, o), this.tryParseTextureLOD(e, o);
1064
+ onBeforeUpdateLOD(t, e, s, n) {
1065
+ this.tryParseMeshLOD(e, n), this.tryParseTextureLOD(e, n);
1052
1066
  }
1053
1067
  getUrl(t) {
1054
1068
  if (!t)
@@ -1065,17 +1079,17 @@ class Dt {
1065
1079
  tryParseTextureLOD(t, e) {
1066
1080
  if (e[ge] == !0) return;
1067
1081
  e[ge] = !0;
1068
- const s = this.tryGetCurrentGLTF(t), o = this.tryGetCurrentModelViewer(t), i = this.getUrl(o);
1069
- if (i && s && e.material) {
1070
- let r = function(l) {
1082
+ const s = this.tryGetCurrentGLTF(t), n = this.tryGetCurrentModelViewer(t), r = this.getUrl(n);
1083
+ if (r && s && e.material) {
1084
+ let i = function(l) {
1071
1085
  var u, h, g;
1072
1086
  if (l[ge] == !0) return;
1073
1087
  l[ge] = !0, l.userData && (l.userData.LOD = -1);
1074
1088
  const c = Object.keys(l);
1075
- for (let D = 0; D < c.length; D++) {
1076
- const b = c[D], v = l[b];
1077
- if ((v == null ? void 0 : v.isTexture) === !0) {
1078
- const F = (h = (u = v.userData) == null ? void 0 : u.associations) == null ? void 0 : h.textures;
1089
+ for (let v = 0; v < c.length; v++) {
1090
+ const b = c[v], _ = l[b];
1091
+ if ((_ == null ? void 0 : _.isTexture) === !0) {
1092
+ const F = (h = (u = _.userData) == null ? void 0 : u.associations) == null ? void 0 : h.textures;
1079
1093
  if (F == null) continue;
1080
1094
  const W = s.parser.json.textures[F];
1081
1095
  if (!W) {
@@ -1083,44 +1097,44 @@ class Dt {
1083
1097
  continue;
1084
1098
  }
1085
1099
  if ((g = W == null ? void 0 : W.extensions) != null && g[K]) {
1086
- const _ = W.extensions[K];
1087
- _ && i && z.registerTexture(i, v, _.lods.length, F, _);
1100
+ const D = W.extensions[K];
1101
+ D && r && z.registerTexture(r, _, D.lods.length, F, D);
1088
1102
  }
1089
1103
  }
1090
1104
  }
1091
1105
  };
1092
1106
  const a = e.material;
1093
- if (Array.isArray(a)) for (const l of a) r(l);
1094
- else r(a);
1107
+ if (Array.isArray(a)) for (const l of a) i(l);
1108
+ else i(a);
1095
1109
  }
1096
1110
  }
1097
1111
  tryParseMeshLOD(t, e) {
1098
- var r, a;
1112
+ var i, a;
1099
1113
  if (e[Re] == !0) return;
1100
1114
  e[Re] = !0;
1101
- const s = this.tryGetCurrentModelViewer(t), o = this.getUrl(s);
1102
- if (!o)
1115
+ const s = this.tryGetCurrentModelViewer(t), n = this.getUrl(s);
1116
+ if (!n)
1103
1117
  return;
1104
- const i = (a = (r = e.userData) == null ? void 0 : r.gltfExtensions) == null ? void 0 : a[K];
1105
- if (i && o) {
1118
+ const r = (a = (i = e.userData) == null ? void 0 : i.gltfExtensions) == null ? void 0 : a[K];
1119
+ if (r && n) {
1106
1120
  const l = e.uuid;
1107
- z.registerMesh(o, l, e, 0, i.lods.length, i);
1121
+ z.registerMesh(n, l, e, 0, r.lods.length, r);
1108
1122
  }
1109
1123
  }
1110
1124
  }
1111
- function _t(n, t, e, s) {
1125
+ function Dt(o, t, e, s) {
1112
1126
  Ne(t), ze(e), Ve(e, {
1113
1127
  progressive: !0,
1114
1128
  ...s == null ? void 0 : s.hints
1115
- }), e.register((i) => new z(i, n));
1116
- const o = xe.get(t);
1117
- return (s == null ? void 0 : s.enableLODsManager) !== !1 && o.enable(), o;
1129
+ }), e.register((r) => new z(r, o));
1130
+ const n = xe.get(t);
1131
+ return (s == null ? void 0 : s.enableLODsManager) !== !1 && n.enable(), n;
1118
1132
  }
1119
1133
  Xe();
1120
1134
  if (!ht) {
1121
- const n = {
1135
+ const o = {
1122
1136
  gltfProgressive: {
1123
- useNeedleProgressive: _t,
1137
+ useNeedleProgressive: Dt,
1124
1138
  LODsManager: xe,
1125
1139
  configureLoader: Ve,
1126
1140
  getRaycastMesh: ue,
@@ -1128,10 +1142,10 @@ if (!ht) {
1128
1142
  }
1129
1143
  };
1130
1144
  if (!globalThis.Needle)
1131
- globalThis.Needle = n;
1145
+ globalThis.Needle = o;
1132
1146
  else
1133
- for (const t in n)
1134
- globalThis.Needle[t] = n[t];
1147
+ for (const t in o)
1148
+ globalThis.Needle[t] = o[t];
1135
1149
  }
1136
1150
  export {
1137
1151
  xe as LODsManager,