@needle-tools/engine 4.7.2-next.37cf642 → 4.7.2-next.d24ebbc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,106 +1,106 @@
1
1
  var He = Object.defineProperty;
2
- var Ee = (o) => {
3
- throw TypeError(o);
2
+ var Ee = (n) => {
3
+ throw TypeError(n);
4
4
  };
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";
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
9
  import { DRACOLoader as tt, KTX2Loader as st, MeshoptDecoder as rt, GLTFLoader as Ce } from "./three-examples-B50TT3Iu.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 nt = V, ot = se, Fe = new URL(V + "draco_decoder.js");
14
+ const ot = V, nt = 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((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/");
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/");
23
23
  }).finally(() => {
24
24
  Ue();
25
25
  });
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);
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);
28
28
  }
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);
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);
31
31
  }
32
- const Pe = Symbol("dracoDecoderPath");
32
+ const Te = Symbol("dracoDecoderPath");
33
33
  let G, Le, $;
34
34
  function Ue() {
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);
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);
36
36
  }
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 };
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 };
39
39
  }
40
- function ze(o) {
41
- o.dracoLoader || o.setDRACOLoader(G), o.ktx2Loader || o.setKTX2Loader($), o.meshoptDecoder || o.setMeshoptDecoder(Le);
40
+ function ze(n) {
41
+ n.dracoLoader || n.setDRACOLoader(G), n.ktx2Loader || n.setKTX2Loader($), n.meshoptDecoder || n.setMeshoptDecoder(Le);
42
42
  }
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);
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);
47
47
  }
48
48
  const Me = Ce.prototype.load;
49
- function dt(...o) {
50
- const t = Te.get(this);
51
- let e = o[0];
49
+ function dt(...n) {
50
+ const t = Pe.get(this);
51
+ let e = n[0];
52
52
  const s = new URL(e, window.location.href);
53
53
  if (s.hostname.endsWith("needle.tools")) {
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();
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();
56
56
  }
57
- return o[0] = e, Me == null ? void 0 : Me.call(this, ...o);
57
+ return n[0] = e, Me == null ? void 0 : Me.call(this, ...n);
58
58
  }
59
59
  Ce.prototype.load = dt;
60
60
  de("debugprogressive");
61
- function de(o) {
61
+ function de(n) {
62
62
  if (typeof window > "u") return !1;
63
- const e = new URL(window.location.href).searchParams.get(o);
63
+ const e = new URL(window.location.href).searchParams.get(n);
64
64
  return e == null || e === "0" || e === "false" ? !1 : e === "" ? !0 : e;
65
65
  }
66
- function ut(o, t) {
67
- if (t === void 0 || t.startsWith("./") || t.startsWith("http") || o === void 0)
66
+ function ut(n, t) {
67
+ if (t === void 0 || t.startsWith("./") || t.startsWith("http") || n === void 0)
68
68
  return t;
69
- const e = o.lastIndexOf("/");
69
+ const e = n.lastIndexOf("/");
70
70
  if (e >= 0) {
71
- const s = o.substring(0, e + 1);
71
+ const s = n.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 oe;
77
+ let ne;
78
78
  function ct() {
79
- return oe !== void 0 || (oe = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), de("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", oe)), oe;
79
+ return ne !== void 0 || (ne = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), de("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", ne)), ne;
80
80
  }
81
81
  function ft() {
82
82
  if (typeof window > "u") return !1;
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;
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;
85
85
  }
86
86
  const ht = typeof window > "u" && typeof document > "u", Ae = Symbol("needle:raycast-mesh");
87
- function ue(o) {
88
- return (o == null ? void 0 : o[Ae]) instanceof ye ? o[Ae] : null;
87
+ function ue(n) {
88
+ return (n == null ? void 0 : n[Ae]) instanceof me ? n[Ae] : null;
89
89
  }
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;
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;
94
94
  }
95
95
  }
96
- function pt(o = !0) {
97
- if (o) {
96
+ function pt(n = !0) {
97
+ if (n) {
98
98
  if (ae) return;
99
99
  const t = ae = te.prototype.raycast;
100
100
  te.prototype.raycast = function(e, s) {
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);
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);
104
104
  };
105
105
  } else {
106
106
  if (!ae) return;
@@ -108,46 +108,46 @@ function pt(o = !0) {
108
108
  }
109
109
  }
110
110
  let ae = null;
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;
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;
116
116
  }
117
- const Q = new Array(), y = de("debugprogressive");
117
+ const Q = new Array(), w = de("debugprogressive");
118
118
  let pe, ee = -1;
119
- if (y) {
120
- let o = function() {
119
+ if (w) {
120
+ let n = 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" && o(), e.key === "w" && (pe = !pe, console.log(`Toggle wireframe [${pe}]`));
124
+ e.key === "p" && n(), 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(o) {
130
- if (y)
131
- if (Array.isArray(o))
132
- for (const t of o)
129
+ function We(n) {
130
+ if (w)
131
+ if (Array.isArray(n))
132
+ for (const t of n)
133
133
  We(t);
134
- else o && "wireframe" in o && (o.wireframe = pe === !0);
134
+ else n && "wireframe" in n && (n.wireframe = pe === !0);
135
135
  }
136
- const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = class w {
136
+ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), x = class x {
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, n;
142
+ var s, o;
143
143
  if (this._isLoadingMesh) return null;
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;
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;
148
148
  })) : null;
149
149
  });
150
- y && console.log("Progressive extension registered for", e), this.parser = t, this.url = e;
150
+ w && 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"), w = c
163
163
  return e ?? -1;
164
164
  }
165
165
  static getMaterialMinMaxLODsCount(t, e) {
166
- const s = this, n = "LODS:minmax", r = t[n];
167
- if (r != null) return r;
166
+ const s = this, o = "LODS:minmax", i = t[o];
167
+ if (i != null) return i;
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"), w = c
172
172
  }), Array.isArray(t)) {
173
173
  for (const a of t)
174
174
  this.getMaterialMinMaxLODsCount(a, e);
175
- return t[n] = e, e;
175
+ return t[o] = e, e;
176
176
  }
177
- if (y === "verbose" && console.log("getMaterialMinMaxLODsCount", t), t.type === "ShaderMaterial" || t.type === "RawShaderMaterial") {
177
+ if (w === "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 && i(c, e);
181
+ (c == null ? void 0 : c.isTexture) === !0 && r(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 && i(l, e);
186
+ (l == null ? void 0 : l.isTexture) === !0 && r(l, e);
187
187
  }
188
- return t[n] = e, e;
189
- function i(a, l) {
188
+ return t[o] = e, e;
189
+ function r(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"), w = 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 r;
209
+ var i;
210
210
  if (Array.isArray(t)) {
211
- for (const i of t)
212
- if (this.hasLODLevelAvailable(i, e)) return !0;
211
+ for (const r of t)
212
+ if (this.hasLODLevelAvailable(r, e)) return !0;
213
213
  return !1;
214
214
  }
215
215
  if (t.isMaterial === !0) {
216
- for (const i of Object.keys(t)) {
217
- const a = t[i];
216
+ for (const r of Object.keys(t)) {
217
+ const a = t[r];
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 i of t.children)
224
- if (i.isMesh === !0 && this.hasLODLevelAvailable(i, e))
223
+ for (const r of t.children)
224
+ if (r.isMesh === !0 && this.hasLODLevelAvailable(r, e))
225
225
  return !0;
226
226
  }
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;
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;
233
233
  }
234
234
  return !1;
235
235
  }
@@ -251,19 +251,19 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
251
251
  var s;
252
252
  if (!t) return Promise.resolve(null);
253
253
  if (t instanceof te || t.isMesh === !0) {
254
- const n = t.geometry, r = this.getAssignedLODInformation(n);
255
- if (!r)
254
+ const o = t.geometry, i = this.getAssignedLODInformation(o);
255
+ if (!i)
256
256
  return Promise.resolve(null);
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];
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];
263
263
  }
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);
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);
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"), w = c
271
271
  if (t.isMesh === !0) {
272
272
  const s = t;
273
273
  if (Array.isArray(s.material)) {
274
- const n = new Array();
275
- for (const r of s.material) {
276
- const i = this.assignTextureLOD(r, e);
277
- n.push(i);
274
+ const o = new Array();
275
+ for (const i of s.material) {
276
+ const r = this.assignTextureLOD(i, e);
277
+ o.push(r);
278
278
  }
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;
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;
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, n = [], r = new Array();
289
+ const s = t, o = [], i = new Array();
290
290
  if (s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
291
- const i = s;
292
- for (const a of Object.keys(i.uniforms)) {
293
- const l = i.uniforms[a].value;
291
+ const r = s;
292
+ for (const a of Object.keys(r.uniforms)) {
293
+ const l = r.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 && i.uniforms[a].value != u && (i.uniforms[a].value = u, i.uniformsNeedUpdate = !0), u));
296
- n.push(c), r.push(a);
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);
297
297
  }
298
298
  }
299
299
  } else
300
- for (const i of Object.keys(s)) {
301
- const a = s[i];
300
+ for (const r of Object.keys(s)) {
301
+ const a = s[r];
302
302
  if ((a == null ? void 0 : a.isTexture) === !0) {
303
- const l = this.assignTextureLODForSlot(a, e, s, i);
304
- n.push(l), r.push(i);
303
+ const l = this.assignTextureLODForSlot(a, e, s, r);
304
+ o.push(l), i.push(r);
305
305
  }
306
306
  }
307
- return Promise.all(n).then((i) => {
307
+ return Promise.all(o).then((r) => {
308
308
  const a = new Array();
309
- for (let l = 0; l < i.length; l++) {
310
- const c = i[l], u = r[l];
309
+ for (let l = 0; l < r.length; l++) {
310
+ const c = r[l], u = i[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 ne || t.isTexture === !0) {
316
+ if (t instanceof oe || 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, 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);
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);
330
330
  if (a && (a == null ? void 0 : a.level) < e)
331
- return y === "verbose" && console.warn("Assigned texture level is already higher: ", a.level, e, s, i, r), null;
331
+ return w === "verbose" && console.warn("Assigned texture level is already higher: ", a.level, e, s, r, i), null;
332
332
  }
333
- s[n] = r;
333
+ s[o] = i;
334
334
  }
335
- return r;
336
- } else y == "verbose" && console.warn("No LOD found for", t, e);
335
+ return i;
336
+ } else w == "verbose" && console.warn("No LOD found for", t, e);
337
337
  return null;
338
- }).catch((r) => (console.error("Error loading LOD", t, r), null));
338
+ }).catch((i) => (console.error("Error loading LOD", t, i), null));
339
339
  }
340
340
  afterRoot(t) {
341
341
  var e, s;
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];
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];
346
346
  if (a) {
347
347
  if (!a.lods) {
348
- y && console.warn("Texture has no LODs", a);
348
+ w && 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) === r && (l = !0, w.registerTexture(this.url, c, (i = a.lods) == null ? void 0 : i.length, r, a));
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));
356
356
  }
357
- l || this.parser.getDependency("texture", r).then((c) => {
357
+ l || this.parser.getDependency("texture", i).then((c) => {
358
358
  var u;
359
- c && w.registerTexture(this.url, c, (u = a.lods) == null ? void 0 : u.length, r, a);
359
+ c && x.registerTexture(this.url, c, (u = a.lods) == null ? void 0 : u.length, i, a);
360
360
  });
361
361
  }
362
362
  }
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) {
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) {
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) === r && w.registerMesh(this.url, i.guid, a, i.lods.length, l.primitives, i);
370
+ (l == null ? void 0 : l.meshes) === i && x.registerMesh(this.url, r.guid, a, r.lods.length, l.primitives, r);
371
371
  }
372
372
  }
373
373
  }
@@ -375,57 +375,57 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
375
375
  }
376
376
  static async getOrLoadLOD(t, e) {
377
377
  var a, l, c, u;
378
- const s = y == "verbose", n = t.userData.LODS;
379
- if (!n)
378
+ const s = w == "verbose", o = t.userData.LODS;
379
+ if (!o)
380
380
  return null;
381
- const r = n == null ? void 0 : n.key;
382
- let i;
381
+ const i = o == null ? void 0 : o.key;
382
+ let r;
383
383
  if (t.isTexture === !0) {
384
384
  const h = t;
385
- h.source && h.source[Oe] && (i = h.source[Oe]);
385
+ h.source && h.source[Oe] && (r = h.source[Oe]);
386
386
  }
387
- if (i || (i = w.lodInfos.get(r)), i) {
387
+ if (r || (r = x.lodInfos.get(i)), r) {
388
388
  if (e > 0) {
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);
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);
393
393
  }
394
- const h = Array.isArray(i.lods) ? (a = i.lods[e]) == null ? void 0 : a.path : i.lods;
394
+ const h = Array.isArray(r.lods) ? (a = r.lods[e]) == null ? void 0 : a.path : r.lods;
395
395
  if (!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);
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);
398
398
  if (g.endsWith(".glb") || g.endsWith(".gltf")) {
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);
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);
402
402
  if (b !== void 0) {
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;
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 _;
408
408
  }
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));
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));
412
412
  let X = g;
413
- if (_ && Array.isArray(_.lods)) {
414
- const S = _.lods[e];
413
+ if (v && Array.isArray(v.lods)) {
414
+ const S = v.lods[e];
415
415
  S.hash && (X += "?v=" + S.hash);
416
416
  }
417
- const T = await m.loadAsync(X).catch((S) => (console.error(`Error loading LOD ${e} from ${g}
417
+ const P = await y.loadAsync(X).catch((S) => (console.error(`Error loading LOD ${e} from ${g}
418
418
  `, S), null));
419
- if (!T) return null;
420
- const I = T.parser;
421
- s && console.log("Loading finished " + g, _.guid);
419
+ if (!P) return null;
420
+ const I = P.parser;
421
+ s && console.log("Loading finished " + g, v.guid);
422
422
  let B = 0;
423
- if (T.parser.json.textures) {
423
+ if (P.parser.json.textures) {
424
424
  let S = !1;
425
- for (const f of T.parser.json.textures) {
425
+ for (const f of P.parser.json.textures) {
426
426
  if (f != null && f.extensions) {
427
- const P = f == null ? void 0 : f.extensions[K];
428
- if (P != null && P.guid && P.guid === _.guid) {
427
+ const T = f == null ? void 0 : f.extensions[K];
428
+ if (T != null && T.guid && T.guid === v.guid) {
429
429
  S = !0;
430
430
  break;
431
431
  }
@@ -434,15 +434,15 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
434
434
  }
435
435
  if (S) {
436
436
  let f = await I.getDependency("texture", B);
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);
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);
439
439
  }
440
- if (B = 0, T.parser.json.meshes) {
440
+ if (B = 0, P.parser.json.meshes) {
441
441
  let S = !1;
442
- for (const f of T.parser.json.meshes) {
442
+ for (const f of P.parser.json.meshes) {
443
443
  if (f != null && f.extensions) {
444
- const P = f == null ? void 0 : f.extensions[K];
445
- if (P != null && P.guid && P.guid === _.guid) {
444
+ const T = f == null ? void 0 : f.extensions[K];
445
+ if (T != null && T.guid && T.guid === v.guid) {
446
446
  S = !0;
447
447
  break;
448
448
  }
@@ -451,39 +451,39 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = 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, v), f.isMesh === !0) {
455
- const P = f.geometry;
456
- return w.assignLODInformation(n.url, P, r, e, 0), D(P);
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);
457
457
  } else {
458
- const P = new Array();
459
- for (let x = 0; x < f.children.length; x++) {
460
- const M = f.children[x];
458
+ const T = new Array();
459
+ for (let L = 0; L < f.children.length; L++) {
460
+ const M = f.children[L];
461
461
  if (M.isMesh === !0) {
462
462
  const A = M.geometry;
463
- w.assignLODInformation(n.url, A, r, e, x), P.push(A);
463
+ x.assignLODInformation(o.url, A, i, e, L), T.push(A);
464
464
  }
465
465
  }
466
- return D(P);
466
+ return _(T);
467
467
  }
468
- } else y && console.warn("Could not find mesh with guid", _.guid, T.parser.json);
468
+ } else w && console.warn("Could not find mesh with guid", v.guid, P.parser.json);
469
469
  }
470
- return D(null);
470
+ return _(null);
471
471
  });
472
- return this.previouslyLoaded.set(v, F), await F;
473
- } else if (t instanceof ne) {
472
+ return this.previouslyLoaded.set(D, F), await F;
473
+ } else if (t instanceof oe) {
474
474
  s && console.log("Load texture from uri: " + g);
475
475
  const b = await new Je().loadAsync(g);
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;
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;
477
477
  }
478
478
  } else
479
- y && console.warn(`Can not load LOD ${e}: no LOD info found for "${r}" ${t.name}`, t.type);
479
+ w && console.warn(`Can not load LOD ${e}: no LOD info found for "${i}" ${t.name}`, t.type);
480
480
  return null;
481
481
  }
482
- static assignLODInformation(t, e, s, n, r) {
482
+ static assignLODInformation(t, e, s, o, i) {
483
483
  if (!e) return;
484
484
  e.userData || (e.userData = {});
485
- const i = new yt(t, s, n, r);
486
- e.userData.LODS = i;
485
+ const r = new mt(t, s, o, i);
486
+ e.userData.LODS = r;
487
487
  }
488
488
  static getAssignedLODInformation(t) {
489
489
  var e;
@@ -491,7 +491,7 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
491
491
  }
492
492
  // private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
493
493
  static copySettings(t, e) {
494
- return e ? (y && console.warn(`Copy texture settings
494
+ return e ? (w && 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"), w = c
499
499
  /**
500
500
  * Register a texture with LOD information
501
501
  */
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");
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");
505
505
  return;
506
506
  }
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);
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);
510
510
  }), /**
511
511
  * Register a mesh with LOD information
512
512
  */
513
- d(w, "registerMesh", (t, e, s, n, r, i) => {
513
+ d(x, "registerMesh", (t, e, s, o, i, r) => {
514
514
  var c;
515
515
  const a = s.geometry;
516
516
  if (!a) {
517
- y && console.warn("gltf-progressive: Register mesh without geometry");
517
+ w && console.warn("gltf-progressive: Register mesh without geometry");
518
518
  return;
519
519
  }
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);
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);
523
523
  for (const u of Q)
524
- (c = u.onRegisteredNewMesh) == null || c.call(u, s, i);
524
+ (c = u.onRegisteredNewMesh) == null || c.call(u, s, r);
525
525
  }), /** A map of key = asset uuid and value = LOD information */
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) {
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) {
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, n != null && (this.index = n);
538
+ this.url = t, this.key = e, this.level = s, o != null && (this.index = o);
539
539
  }
540
540
  }
541
- class me {
541
+ class ye {
542
542
  constructor(t, e) {
543
543
  d(this, "frame_start");
544
544
  d(this, "frame_capture_end");
@@ -550,18 +550,16 @@ class me {
550
550
  d(this, "_resolvedCount", 0);
551
551
  /** These promises are currently being awaited */
552
552
  d(this, "_awaiting", []);
553
- d(this, "_maxPromisesPerObject", 1);
554
553
  d(this, "_currentFrame", 0);
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;
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;
560
558
  }), this.ready.finally(() => {
561
559
  this._resolved = !0, this._awaiting.length = 0;
562
- }), this._signal = e.signal, (r = this._signal) == null || r.addEventListener("abort", () => {
560
+ }), this._signal = e.signal, (i = this._signal) == null || i.addEventListener("abort", () => {
563
561
  this.resolveNow();
564
- }), this._maxPromisesPerObject = Math.max(1, e.maxPromisesPerObject ?? 1);
562
+ });
565
563
  }
566
564
  /**
567
565
  * The number of promises that have been added to this group so far.
@@ -579,26 +577,14 @@ class me {
579
577
  var e;
580
578
  this._currentFrame = t, ((e = this._signal) != null && e.aborted || this._currentFrame > this.frame_capture_end && this._awaiting.length === 0) && this.resolveNow();
581
579
  }
582
- add(t, e, s) {
580
+ add(t, e) {
583
581
  if (this._resolved) {
584
- y && console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");
582
+ console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");
585
583
  return;
586
584
  }
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
- }
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
+ }));
602
588
  }
603
589
  resolveNow() {
604
590
  var t, e;
@@ -609,14 +595,14 @@ class me {
609
595
  });
610
596
  }
611
597
  }
612
- d(me, "addPromise", (t, e, s, n) => {
613
- n.forEach((r) => {
614
- r.add(t, e, s);
598
+ d(ye, "addPromise", (t, e, s) => {
599
+ s.forEach((o) => {
600
+ o.add(t, e);
615
601
  });
616
602
  });
617
603
  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 };
618
- var L, E, Y, we, Z, re, _e, H;
619
- let xe = (L = class {
604
+ var m, E, Y, we, Z, re, ve, H;
605
+ let xe = (m = class {
620
606
  // readonly plugins: NEEDLE_progressive_plugin[] = [];
621
607
  constructor(t, e) {
622
608
  d(this, "renderer");
@@ -657,7 +643,7 @@ let xe = (L = class {
657
643
  j(this, we, new Qe());
658
644
  j(this, Z, 0);
659
645
  j(this, re, 0);
660
- j(this, _e, 0);
646
+ j(this, ve, 0);
661
647
  j(this, H, 0);
662
648
  d(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
663
649
  // private testIfLODLevelsAreAvailable() {
@@ -689,7 +675,7 @@ let xe = (L = class {
689
675
  static get(t, e) {
690
676
  if (t[be])
691
677
  return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[be];
692
- const s = new L(t, {
678
+ const s = new m(t, {
693
679
  engine: "unknown",
694
680
  ...e
695
681
  });
@@ -703,13 +689,13 @@ let xe = (L = class {
703
689
  * Call to await LODs loading during the next render cycle.
704
690
  */
705
691
  awaitLoading(t) {
706
- const e = this._promiseGroupIds++, s = new me(p(this, Z), { ...t });
692
+ const e = this._promiseGroupIds++, s = new ye(p(this, Z), { ...t });
707
693
  this._newPromiseGroups.push(s);
708
- const n = performance.now();
694
+ const o = performance.now();
709
695
  return s.ready.finally(() => {
710
- const r = this._newPromiseGroups.indexOf(s);
711
- r >= 0 && (this._newPromiseGroups.splice(r, 1), ft() && performance.measure("LODsManager:awaitLoading", {
712
- start: n,
696
+ const i = this._newPromiseGroups.indexOf(s);
697
+ i >= 0 && (this._newPromiseGroups.splice(i, 1), ft() && performance.measure("LODsManager:awaitLoading", {
698
+ start: o,
713
699
  detail: { id: e, name: t == null ? void 0 : t.name, awaited: s.awaitedCount, resolved: s.resolvedCount }
714
700
  }));
715
701
  }), s.ready;
@@ -737,11 +723,11 @@ let xe = (L = class {
737
723
  let t = 0;
738
724
  N(this, Y, this.renderer.render);
739
725
  const e = this;
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);
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);
745
731
  };
746
732
  }
747
733
  disable() {
@@ -752,13 +738,13 @@ let xe = (L = class {
752
738
  }
753
739
  onAfterRender(t, e, s) {
754
740
  if (this.pause) return;
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);
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);
760
746
  }
761
- if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (i = !1), i) {
747
+ if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (r = !1), r) {
762
748
  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))
763
749
  return;
764
750
  this.internalUpdate(t, e), this._postprocessPromiseGroups();
@@ -769,10 +755,10 @@ let xe = (L = class {
769
755
  */
770
756
  internalUpdate(t, e) {
771
757
  var l, c;
772
- const s = this.renderer.renderLists.get(t, 0), n = s.opaque;
758
+ const s = this.renderer.renderLists.get(t, 0), o = s.opaque;
773
759
  this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix, e.matrixWorldInverse);
774
- const r = this.targetTriangleDensity;
775
- for (const u of n) {
760
+ const i = this.targetTriangleDensity;
761
+ for (const u of o) {
776
762
  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")) {
777
763
  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)));
778
764
  continue;
@@ -788,37 +774,37 @@ let xe = (L = class {
788
774
  }
789
775
  if (k === "color" && u.material && !u.object.progressive_debug_color) {
790
776
  u.object.progressive_debug_color = !0;
791
- const g = Math.random() * 16777215, v = new Ze({ color: g });
792
- u.object.material = v;
777
+ const g = Math.random() * 16777215, D = new Ze({ color: g });
778
+ u.object.material = D;
793
779
  }
794
780
  const h = u.object;
795
- (h instanceof te || h.isMesh) && this.updateLODs(t, e, h, r);
781
+ (h instanceof te || h.isMesh) && this.updateLODs(t, e, h, i);
796
782
  }
797
- const i = s.transparent;
798
- for (const u of i) {
783
+ const r = s.transparent;
784
+ for (const u of r) {
799
785
  const h = u.object;
800
- (h instanceof te || h.isMesh) && this.updateLODs(t, e, h, r);
786
+ (h instanceof te || h.isMesh) && this.updateLODs(t, e, h, i);
801
787
  }
802
788
  const a = s.transmissive;
803
789
  for (const u of a) {
804
790
  const h = u.object;
805
- (h instanceof te || h.isMesh) && this.updateLODs(t, e, h, r);
791
+ (h instanceof te || h.isMesh) && this.updateLODs(t, e, h, i);
806
792
  }
807
793
  }
808
794
  /** Update the LOD levels for the renderer. */
809
- updateLODs(t, e, s, n) {
795
+ updateLODs(t, e, s, o) {
810
796
  var a, l;
811
797
  s.userData || (s.userData = {});
812
- let r = s[Se];
813
- if (r || (r = new xt(), s[Se] = r), r.frames++ < 2)
798
+ let i = s[Se];
799
+ if (i || (i = new xt(), s[Se] = i), i.frames++ < 2)
814
800
  return;
815
801
  for (const c of Q)
816
802
  (a = c.onBeforeUpdateLOD) == null || a.call(c, this.renderer, t, e, s);
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);
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);
819
805
  for (const c of Q)
820
806
  (l = c.onAfterUpdatedLOD) == null || l.call(c, this.renderer, t, e, s, C);
821
- r.lastLodLevel_Mesh = C.mesh_lod, r.lastLodLevel_Texture = C.texture_lod;
807
+ i.lastLodLevel_Mesh = C.mesh_lod, i.lastLodLevel_Texture = C.texture_lod;
822
808
  }
823
809
  /** Load progressive textures for the given material
824
810
  * @param material the material to load the textures for
@@ -828,19 +814,19 @@ let xe = (L = class {
828
814
  loadProgressiveTextures(t, e) {
829
815
  if (!t) return;
830
816
  if (Array.isArray(t)) {
831
- for (const r of t)
832
- this.loadProgressiveTextures(r, e);
817
+ for (const i of t)
818
+ this.loadProgressiveTextures(i, e);
833
819
  return;
834
820
  }
835
821
  let s = !1;
836
822
  (t[J] === void 0 || e < t[J]) && (s = !0);
837
- const n = t["DEBUG:LOD"];
838
- if (n != null && (s = t[J] != n, e = n), s) {
823
+ const o = t["DEBUG:LOD"];
824
+ if (o != null && (s = t[J] != o, e = o), s) {
839
825
  t[J] = e;
840
- const r = z.assignTextureLOD(t, e).then((i) => {
826
+ const i = z.assignTextureLOD(t, e).then((r) => {
841
827
  this._lodchangedlisteners.forEach((a) => a({ type: "texture", level: e, object: t }));
842
828
  });
843
- me.addPromise("texture", t, r, this._newPromiseGroups);
829
+ ye.addPromise("texture", i, this._newPromiseGroups);
844
830
  }
845
831
  }
846
832
  /** Load progressive meshes for the given mesh
@@ -852,120 +838,120 @@ let xe = (L = class {
852
838
  loadProgressiveMeshes(t, e) {
853
839
  if (!t) return Promise.resolve(null);
854
840
  let s = t[J] !== e;
855
- const n = t["DEBUG:LOD"];
856
- if (n != null && (s = t[J] != n, e = n), s) {
841
+ const o = t["DEBUG:LOD"];
842
+ if (o != null && (s = t[J] != o, e = o), s) {
857
843
  t[J] = e;
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;
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;
860
846
  }
861
847
  return Promise.resolve(null);
862
848
  }
863
849
  static isInside(t, e) {
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;
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;
866
852
  }
867
- calculateLodLevel(t, e, s, n, r) {
868
- var F, W, D;
853
+ calculateLodLevel(t, e, s, o, i) {
854
+ var F, W, _;
869
855
  if (!e) {
870
- r.mesh_lod = -1, r.texture_lod = -1;
856
+ i.mesh_lod = -1, i.texture_lod = -1;
871
857
  return;
872
858
  }
873
859
  if (!t) {
874
- r.mesh_lod = -1, r.texture_lod = -1;
860
+ i.mesh_lod = -1, i.texture_lod = -1;
875
861
  return;
876
862
  }
877
863
  let a = 10 + 1, l = !1;
878
864
  if (k && e["DEBUG:LOD"] != null)
879
865
  return e["DEBUG:LOD"];
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;
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;
883
869
  return;
884
870
  }
885
871
  h || (l = !0, a = 0);
886
872
  const b = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
887
- let _ = e.geometry.boundingBox;
873
+ let v = e.geometry.boundingBox;
888
874
  if (e.type === "SkinnedMesh") {
889
875
  const O = e;
890
876
  if (!O.boundingBox)
891
877
  O.computeBoundingBox();
892
878
  else if (this.skinnedMeshAutoUpdateBoundsInterval > 0 && s.frames % this.skinnedMeshAutoUpdateBoundsInterval === 0) {
893
- const m = ue(O), X = O.geometry;
894
- m && (O.geometry = m), O.computeBoundingBox(), O.geometry = X;
879
+ const y = ue(O), X = O.geometry;
880
+ y && (O.geometry = y), O.computeBoundingBox(), O.geometry = X;
895
881
  }
896
- _ = O.boundingBox;
882
+ v = O.boundingBox;
897
883
  }
898
- if (_) {
884
+ if (v) {
899
885
  const O = t;
900
886
  if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
901
887
  this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
902
- const x = t.getWorldPosition(this._tempWorldPosition);
903
- if (this._sphere.containsPoint(x)) {
904
- r.mesh_lod = 0, r.texture_lod = 0;
888
+ const L = t.getWorldPosition(this._tempWorldPosition);
889
+ if (this._sphere.containsPoint(L)) {
890
+ i.mesh_lod = 0, i.texture_lod = 0;
905
891
  return;
906
892
  }
907
893
  }
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;
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;
910
896
  return;
911
897
  }
912
898
  if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && O.isPerspectiveCamera && O.fov > 70) {
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;
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;
916
902
  A = (A - fe) * ce + fe, R = (R - he) * ce + he, U = (U - fe) * ce + fe, ie = (ie - he) * ce + he;
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);
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);
919
905
  } else
920
906
  s.lastCentrality = 1;
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;
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;
930
916
  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);
931
917
  const ie = (M.z + U.z) * 0.5;
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);
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);
933
919
  }
934
920
  let f = 999;
935
921
  if (c && s.lastScreenCoverage > 0)
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;
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;
940
926
  break;
941
927
  }
942
928
  }
943
929
  f < a && (a = f, l = !0);
944
930
  }
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}`);
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}`);
948
934
  }
949
- if (v) {
935
+ if (D) {
950
936
  const O = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
951
937
  if (s.lastLodLevel_Texture < 0) {
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}`);
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}`);
955
941
  }
956
942
  } else {
957
- const m = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
943
+ const y = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
958
944
  let X = s.lastScreenCoverage * 4;
959
- ((D = this.context) == null ? void 0 : D.engine) === "model-viewer" && (X *= 1.5);
945
+ ((_ = this.context) == null ? void 0 : _.engine) === "model-viewer" && (X *= 1.5);
960
946
  const I = b / window.devicePixelRatio * X;
961
947
  let B = !1;
962
948
  for (let S = g.lods.length - 1; S >= 0; S--) {
963
949
  const f = g.lods[S];
964
950
  if (!(O && f.max_height >= 2048) && !(ct() && f.max_height > 4096) && (f.max_height > I || !B && S === 0)) {
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)}
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)}
969
955
  ${e.name}`);
970
956
  }
971
957
  break;
@@ -973,15 +959,15 @@ ${e.name}`);
973
959
  }
974
960
  }
975
961
  } else
976
- r.texture_lod = 0;
962
+ i.texture_lod = 0;
977
963
  }
978
- }, E = new WeakMap(), Y = new WeakMap(), we = new WeakMap(), Z = new WeakMap(), re = new WeakMap(), _e = new WeakMap(), H = new WeakMap(), /**
964
+ }, E = new WeakMap(), Y = new WeakMap(), we = new WeakMap(), Z = new WeakMap(), re = new WeakMap(), ve = new WeakMap(), H = new WeakMap(), /**
979
965
  * 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.
980
966
  */
981
- d(L, "debugDrawLine"), /**
967
+ d(m, "debugDrawLine"), /**
982
968
  * Force override the LOD level for all objects in the scene
983
969
  */
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);
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);
985
971
  class xt {
986
972
  constructor() {
987
973
  d(this, "frames", 0);
@@ -995,8 +981,8 @@ class xt {
995
981
  const Re = Symbol("NEEDLE_mesh_lod"), ge = Symbol("NEEDLE_texture_lod");
996
982
  let le = null;
997
983
  function Xe() {
998
- const o = wt();
999
- o && (o.mapURLs(function(t) {
984
+ const n = wt();
985
+ n && (n.mapURLs(function(t) {
1000
986
  return ke(), t;
1001
987
  }), ke(), le == null || le.disconnect(), le = new MutationObserver((t) => {
1002
988
  t.forEach((e) => {
@@ -1008,8 +994,8 @@ function Xe() {
1008
994
  }
1009
995
  function wt() {
1010
996
  if (typeof customElements > "u") return null;
1011
- const o = customElements.get("model-viewer");
1012
- return o || (customElements.whenDefined("model-viewer").then(() => {
997
+ const n = customElements.get("model-viewer");
998
+ return n || (customElements.whenDefined("model-viewer").then(() => {
1013
999
  console.debug("[gltf-progressive] model-viewer defined"), Xe();
1014
1000
  }), null);
1015
1001
  }
@@ -1020,49 +1006,49 @@ function ke() {
1020
1006
  });
1021
1007
  }
1022
1008
  const $e = /* @__PURE__ */ new WeakSet();
1023
- let _t = 0;
1024
- function qe(o) {
1025
- if (!o || $e.has(o))
1009
+ let vt = 0;
1010
+ function qe(n) {
1011
+ if (!n || $e.has(n))
1026
1012
  return null;
1027
- $e.add(o), console.debug("[gltf-progressive] found new model-viewer..." + ++_t + `
1028
- `, o.getAttribute("src"));
1013
+ $e.add(n), console.debug("[gltf-progressive] found new model-viewer..." + ++vt + `
1014
+ `, n.getAttribute("src"));
1029
1015
  let t = null, e = null, s = null;
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]);
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]);
1033
1019
  }
1034
1020
  if (t && e) {
1035
- let n = function() {
1021
+ let o = function() {
1036
1022
  if (s) {
1037
- let i = 0, a = setInterval(() => {
1038
- if (i++ > 5) {
1023
+ let r = 0, a = setInterval(() => {
1024
+ if (r++ > 5) {
1039
1025
  clearInterval(a);
1040
1026
  return;
1041
1027
  }
1042
- s == null || s.call(o);
1028
+ s == null || s.call(n);
1043
1029
  }, 300);
1044
1030
  }
1045
1031
  };
1046
1032
  console.debug("[gltf-progressive] setup model-viewer");
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();
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();
1054
1040
  }), () => {
1055
- r.disable();
1041
+ i.disable();
1056
1042
  };
1057
1043
  }
1058
1044
  return null;
1059
1045
  }
1060
- class vt {
1046
+ class Dt {
1061
1047
  constructor() {
1062
1048
  d(this, "_didWarnAboutMissingUrl", !1);
1063
1049
  }
1064
- onBeforeUpdateLOD(t, e, s, n) {
1065
- this.tryParseMeshLOD(e, n), this.tryParseTextureLOD(e, n);
1050
+ onBeforeUpdateLOD(t, e, s, o) {
1051
+ this.tryParseMeshLOD(e, o), this.tryParseTextureLOD(e, o);
1066
1052
  }
1067
1053
  getUrl(t) {
1068
1054
  if (!t)
@@ -1079,17 +1065,17 @@ class vt {
1079
1065
  tryParseTextureLOD(t, e) {
1080
1066
  if (e[ge] == !0) return;
1081
1067
  e[ge] = !0;
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) {
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) {
1085
1071
  var u, h, g;
1086
1072
  if (l[ge] == !0) return;
1087
1073
  l[ge] = !0, l.userData && (l.userData.LOD = -1);
1088
1074
  const c = Object.keys(l);
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;
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;
1093
1079
  if (F == null) continue;
1094
1080
  const W = s.parser.json.textures[F];
1095
1081
  if (!W) {
@@ -1097,44 +1083,44 @@ class vt {
1097
1083
  continue;
1098
1084
  }
1099
1085
  if ((g = W == null ? void 0 : W.extensions) != null && g[K]) {
1100
- const D = W.extensions[K];
1101
- D && r && z.registerTexture(r, _, D.lods.length, F, D);
1086
+ const _ = W.extensions[K];
1087
+ _ && i && z.registerTexture(i, v, _.lods.length, F, _);
1102
1088
  }
1103
1089
  }
1104
1090
  }
1105
1091
  };
1106
1092
  const a = e.material;
1107
- if (Array.isArray(a)) for (const l of a) i(l);
1108
- else i(a);
1093
+ if (Array.isArray(a)) for (const l of a) r(l);
1094
+ else r(a);
1109
1095
  }
1110
1096
  }
1111
1097
  tryParseMeshLOD(t, e) {
1112
- var i, a;
1098
+ var r, a;
1113
1099
  if (e[Re] == !0) return;
1114
1100
  e[Re] = !0;
1115
- const s = this.tryGetCurrentModelViewer(t), n = this.getUrl(s);
1116
- if (!n)
1101
+ const s = this.tryGetCurrentModelViewer(t), o = this.getUrl(s);
1102
+ if (!o)
1117
1103
  return;
1118
- const r = (a = (i = e.userData) == null ? void 0 : i.gltfExtensions) == null ? void 0 : a[K];
1119
- if (r && n) {
1104
+ const i = (a = (r = e.userData) == null ? void 0 : r.gltfExtensions) == null ? void 0 : a[K];
1105
+ if (i && o) {
1120
1106
  const l = e.uuid;
1121
- z.registerMesh(n, l, e, 0, r.lods.length, r);
1107
+ z.registerMesh(o, l, e, 0, i.lods.length, i);
1122
1108
  }
1123
1109
  }
1124
1110
  }
1125
- function Dt(o, t, e, s) {
1111
+ function _t(n, t, e, s) {
1126
1112
  Ne(t), ze(e), Ve(e, {
1127
1113
  progressive: !0,
1128
1114
  ...s == null ? void 0 : s.hints
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;
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;
1132
1118
  }
1133
1119
  Xe();
1134
1120
  if (!ht) {
1135
- const o = {
1121
+ const n = {
1136
1122
  gltfProgressive: {
1137
- useNeedleProgressive: Dt,
1123
+ useNeedleProgressive: _t,
1138
1124
  LODsManager: xe,
1139
1125
  configureLoader: Ve,
1140
1126
  getRaycastMesh: ue,
@@ -1142,10 +1128,10 @@ if (!ht) {
1142
1128
  }
1143
1129
  };
1144
1130
  if (!globalThis.Needle)
1145
- globalThis.Needle = o;
1131
+ globalThis.Needle = n;
1146
1132
  else
1147
- for (const t in o)
1148
- globalThis.Needle[t] = o[t];
1133
+ for (const t in n)
1134
+ globalThis.Needle[t] = n[t];
1149
1135
  }
1150
1136
  export {
1151
1137
  xe as LODsManager,