@needle-tools/gltf-progressive 4.0.0-alpha.4 → 4.0.0-alpha.6

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,66 +1,72 @@
1
- import * as Ve from "three";
2
- import { RedFormat as Xe, RedIntegerFormat as je, RGFormat as Ke, RGIntegerFormat as He, RGBFormat as Ye, RGBAFormat as Qe, RGBAIntegerFormat as Je, BufferGeometry as H, Mesh as Y, Box3 as fe, Vector3 as A, Sphere as Ie, CompressedTexture as Ze, Texture as W, Matrix3 as et, InterleavedBuffer as tt, InterleavedBufferAttribute as st, BufferAttribute as rt, TextureLoader as nt, Color as $e, Matrix4 as Ge } from "three";
1
+ import * as Xe from "three";
2
+ import { RedFormat as je, RedIntegerFormat as Ke, RGFormat as He, RGIntegerFormat as Ye, RGBFormat as Qe, RGBAFormat as Je, RGBAIntegerFormat as Ze, BufferGeometry as H, Mesh as Y, Box3 as ce, Vector3 as A, Sphere as Ge, CompressedTexture as et, Texture as W, Matrix3 as tt, InterleavedBuffer as st, InterleavedBufferAttribute as rt, BufferAttribute as nt, TextureLoader as it, Color as Be, Matrix4 as qe } from "three";
3
3
  import { GLTFLoader as Me } from "three/examples/jsm/loaders/GLTFLoader.js";
4
- import { MeshoptDecoder as it } from "three/examples/jsm/libs/meshopt_decoder.module.js";
5
- import { DRACOLoader as ot } from "three/examples/jsm/loaders/DRACOLoader.js";
6
- import { KTX2Loader as at } from "three/examples/jsm/loaders/KTX2Loader.js";
7
- const lt = "";
8
- globalThis.GLTF_PROGRESSIVE_VERSION = lt;
4
+ import { MeshoptDecoder as ot } from "three/examples/jsm/libs/meshopt_decoder.module.js";
5
+ import { DRACOLoader as at } from "three/examples/jsm/loaders/DRACOLoader.js";
6
+ import { KTX2Loader as lt } from "three/examples/jsm/loaders/KTX2Loader.js";
7
+ const ut = "";
8
+ globalThis.GLTF_PROGRESSIVE_VERSION = ut;
9
9
  console.debug("[gltf-progressive] version -");
10
- let B = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", Q = "https://cdn.needle.tools/static/three/0.179.1/basis2/";
11
- const ut = B, ct = Q;
10
+ let q = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", Q = "https://cdn.needle.tools/static/three/0.179.1/basis2/";
11
+ const ct = q, dt = Q;
12
12
  if (typeof window < "u") {
13
- const i = new URL(B + "draco_decoder.js");
13
+ const i = new URL(q + "draco_decoder.js");
14
14
  i.searchParams.append("range", "true"), fetch(i, {
15
15
  method: "GET",
16
16
  headers: {
17
17
  Range: "bytes=0-1"
18
18
  }
19
19
  }).catch((t) => {
20
- console.debug(`Failed to fetch remote Draco decoder from ${B} (offline: ${navigator.onLine})`), B === ut && dt("./include/draco/"), Q === ct && ht("./include/ktx2/");
20
+ console.debug(`Failed to fetch remote Draco decoder from ${q} (offline: ${navigator.onLine})`), q === ct && ht("./include/draco/"), Q === dt && gt("./include/ktx2/");
21
21
  }).finally(() => {
22
- qe();
22
+ be && Te();
23
23
  });
24
24
  }
25
25
  const ft = () => ({
26
- dracoDecoderPath: B,
26
+ dracoDecoderPath: q,
27
27
  ktx2TranscoderPath: Q
28
28
  });
29
- function dt(i) {
30
- B = i, k && k[xe] != B ? (console.debug("Updating Draco decoder path to " + i), k[xe] = B, k.setDecoderPath(B), k.preload()) : console.debug("Setting Draco decoder path to " + i);
31
- }
32
29
  function ht(i) {
33
- Q = i, q && q.transcoderPath != Q ? (console.debug("Updating KTX2 transcoder path to " + i), q.setTranscoderPath(Q), q.init()) : console.debug("Setting KTX2 transcoder path to " + i);
30
+ q = i, P && P[xe] != q ? (console.debug("Updating Draco decoder path to " + i), P[xe] = q, P.setDecoderPath(q), P.preload()) : console.debug("Setting Draco decoder path to " + i);
31
+ }
32
+ function gt(i) {
33
+ Q = i, B && B.transcoderPath != Q ? (console.debug("Updating KTX2 transcoder path to " + i), B.setTranscoderPath(Q), B.init()) : console.debug("Setting KTX2 transcoder path to " + i);
34
34
  }
35
35
  function _e(i) {
36
- return qe(), i ? q.detectSupport(i) : i !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: k, ktx2Loader: q, meshoptDecoder: ce };
36
+ be = !0;
37
+ const t = Te();
38
+ return i ? t.ktx2Loader.detectSupport(i) : i !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), t;
37
39
  }
38
- function Be(i) {
39
- i.dracoLoader || i.setDRACOLoader(k), i.ktx2Loader || i.setKTX2Loader(q), i.meshoptDecoder || i.setMeshoptDecoder(ce);
40
+ function Zt() {
41
+ be = !1, P?.dispose(), B?.dispose(), P = void 0, B = void 0;
42
+ }
43
+ function We(i) {
44
+ const { dracoLoader: t, ktx2Loader: e, meshoptDecoder: s } = Te();
45
+ i.dracoLoader || i.setDRACOLoader(t), i.ktx2Loader || i.setKTX2Loader(e), i.meshoptDecoder || i.setMeshoptDecoder(s);
40
46
  }
41
47
  const xe = /* @__PURE__ */ Symbol("dracoDecoderPath");
42
- let k, ce, q;
43
- function qe() {
44
- k || (k = new ot(), k[xe] = B, k.setDecoderPath(B), k.preload()), q || (q = new at(), q.setTranscoderPath(Q), q.init()), ce || (ce = it);
48
+ let be = !0, P, de, B;
49
+ function Te() {
50
+ return P || (P = new at(), P[xe] = q, P.setDecoderPath(q), P.preload()), B || (B = new lt(), B.setTranscoderPath(Q), B.init()), de || (de = ot), { dracoLoader: P, ktx2Loader: B, meshoptDecoder: de };
45
51
  }
46
- const we = /* @__PURE__ */ new WeakMap();
47
- function We(i, t) {
48
- let e = we.get(i);
49
- e ? e = Object.assign(e, t) : e = t, we.set(i, e);
52
+ const Le = /* @__PURE__ */ new WeakMap();
53
+ function Fe(i, t) {
54
+ let e = Le.get(i);
55
+ e ? e = Object.assign(e, t) : e = t, Le.set(i, e);
50
56
  }
51
- const gt = Me.prototype.load;
52
- function pt(...i) {
53
- const t = we.get(this);
57
+ const pt = Me.prototype.load;
58
+ function mt(...i) {
59
+ const t = Le.get(this);
54
60
  let e = i[0];
55
- const s = mt(e);
61
+ const s = yt(e);
56
62
  if (s?.hostname.endsWith("needle.tools")) {
57
63
  const n = t?.progressive !== void 0 ? t.progressive : !0, o = t?.usecase ? t.usecase : "default";
58
64
  n ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${o}` : this.requestHeader.Accept = `*/*;usecase=${o}`, e = s.toString();
59
65
  }
60
- return i[0] = e, gt?.call(this, ...i);
66
+ return i[0] = e, pt?.call(this, ...i);
61
67
  }
62
- Me.prototype.load = pt;
63
- function mt(i) {
68
+ Me.prototype.load = mt;
69
+ function yt(i) {
64
70
  try {
65
71
  if (i instanceof URL)
66
72
  return i;
@@ -70,19 +76,19 @@ function mt(i) {
70
76
  return null;
71
77
  }
72
78
  }
73
- function Oe(i) {
79
+ function Re(i) {
74
80
  return i != null && i.data != null;
75
81
  }
76
- function Le(i) {
82
+ function we(i) {
77
83
  const t = i.source?.data;
78
84
  return t != null && typeof t == "object" ? t : null;
79
85
  }
80
- function yt(i) {
86
+ function xt(i) {
81
87
  const t = i.image;
82
88
  return t != null && typeof t == "object" ? t : null;
83
89
  }
84
90
  function ve(i) {
85
- const t = yt(i), e = Le(i);
91
+ const t = xt(i), e = we(i);
86
92
  return {
87
93
  width: t?.width || e?.width || 0,
88
94
  height: t?.height || e?.height || 0
@@ -95,7 +101,7 @@ function X(i) {
95
101
  const s = new URL(t).searchParams.get(i);
96
102
  return s == null || s === "0" || s === "false" ? !1 : s === "" ? !0 : s;
97
103
  }
98
- function xt(i, t) {
104
+ function Lt(i, t) {
99
105
  if (t === void 0 || i === void 0 || t.startsWith("./") || t.startsWith("http") || t.startsWith("data:") || t.startsWith("blob:"))
100
106
  return t;
101
107
  const e = i.lastIndexOf("/");
@@ -106,13 +112,13 @@ function xt(i, t) {
106
112
  }
107
113
  return t;
108
114
  }
109
- function be() {
115
+ function Oe() {
110
116
  if (se !== void 0) return se;
111
117
  const i = globalThis.navigator?.userAgent || "";
112
118
  return se = /iPhone|iPad|iPod|Android|IEMobile/i.test(i), X("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", se), se;
113
119
  }
114
120
  let se;
115
- function Fe() {
121
+ function Ue() {
116
122
  const i = globalThis.location?.href;
117
123
  if (!i) return !1;
118
124
  const t = new URL(i), e = t.hostname === "localhost" || /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(t.hostname);
@@ -120,7 +126,7 @@ function Fe() {
120
126
  }
121
127
  class wt {
122
128
  constructor(t, e = {}) {
123
- this.maxConcurrent = t, this.debug = e.debug ?? !1, typeof globalThis.requestAnimationFrame == "function" ? globalThis.requestAnimationFrame(this.tick) : setTimeout(this.tick, 0);
129
+ this.maxConcurrent = t, this.debug = e.debug ?? !1, setTimeout(this.tick, 0);
124
130
  }
125
131
  _running = /* @__PURE__ */ new Map();
126
132
  _queue = [];
@@ -152,29 +158,29 @@ class wt {
152
158
  }
153
159
  }
154
160
  }
155
- function Lt(i) {
156
- const t = i.image, e = t?.width ?? 0, s = t?.height ?? 0, r = t?.depth ?? 1, n = Math.floor(Math.log2(Math.max(e, s, r))) + 1, o = vt(i);
161
+ function vt(i) {
162
+ const t = i.image, e = t?.width ?? 0, s = t?.height ?? 0, r = t?.depth ?? 1, n = Math.floor(Math.log2(Math.max(e, s, r))) + 1, o = Dt(i);
157
163
  return e * s * r * o * (1 - Math.pow(0.25, n)) / (1 - 0.25);
158
164
  }
159
- function vt(i) {
165
+ function Dt(i) {
160
166
  let t = 4;
161
167
  const e = i.format;
162
- e === Xe || e === je ? t = 1 : e === Ke || e === He ? t = 2 : e === Ye || e === 1029 ? t = 3 : (e === Qe || e === Je) && (t = 4);
168
+ e === je || e === Ke ? t = 1 : e === He || e === Ye ? t = 2 : e === Qe || e === 1029 ? t = 3 : (e === Je || e === Ze) && (t = 4);
163
169
  let s = 1;
164
170
  const r = i.type;
165
171
  return r === 1009 || r === 1010 ? s = 1 : r === 1011 || r === 1012 ? s = 2 : r === 1013 || r === 1014 || r === 1015 ? s = 4 : r === 1016 && (s = 2), t * s;
166
172
  }
167
- const Dt = typeof window > "u" && typeof document > "u", De = /* @__PURE__ */ Symbol("needle:raycast-mesh");
173
+ const Mt = typeof window > "u" && typeof document > "u", De = /* @__PURE__ */ Symbol("needle:raycast-mesh");
168
174
  function ae(i) {
169
175
  return i?.[De] instanceof H ? i[De] : null;
170
176
  }
171
- function Mt(i, t) {
177
+ function _t(i, t) {
172
178
  if ((i.type === "Mesh" || i.type === "SkinnedMesh") && !ae(i)) {
173
- const s = bt(t);
179
+ const s = Tt(t);
174
180
  s.userData = { isRaycastMesh: !0 }, i[De] = s;
175
181
  }
176
182
  }
177
- function _t(i = !0) {
183
+ function bt(i = !0) {
178
184
  if (i) {
179
185
  if (re) return;
180
186
  const t = re = Y.prototype.raycast;
@@ -189,7 +195,7 @@ function _t(i = !0) {
189
195
  }
190
196
  }
191
197
  let re = null;
192
- function bt(i) {
198
+ function Tt(i) {
193
199
  const t = new H();
194
200
  for (const e in i.attributes)
195
201
  t.setAttribute(e, i.getAttribute(e));
@@ -208,27 +214,27 @@ if (g && typeof window < "u") {
208
214
  !isNaN(s) && s >= 0 && (K = s, console.log(`Set LOD level to [${K}]`));
209
215
  });
210
216
  }
211
- function Ue(i) {
217
+ function ze(i) {
212
218
  if (g && oe !== void 0)
213
219
  if (Array.isArray(i))
214
220
  for (const t of i)
215
- Ue(t);
221
+ ze(t);
216
222
  else i && "wireframe" in i && (i.wireframe = oe === !0);
217
223
  }
218
224
  const ne = new Array();
219
- let Tt = 0;
220
- const Ot = be() ? 2 : 10;
221
- function St(i) {
222
- if (ne.length < Ot) {
225
+ let Ot = 0;
226
+ const St = Oe() ? 2 : 10;
227
+ function Rt(i) {
228
+ if (ne.length < St) {
223
229
  const s = ne.length;
224
230
  g && console.warn(`[Worker] Creating new worker #${s}`);
225
- const r = Te.createWorker(i || {});
231
+ const r = Se.createWorker(i || {});
226
232
  return ne.push(r), r;
227
233
  }
228
- const t = Tt++ % ne.length;
234
+ const t = Ot++ % ne.length;
229
235
  return ne[t];
230
236
  }
231
- class Te {
237
+ class Se {
232
238
  constructor(t, e) {
233
239
  this.worker = t, this._debug = e.debug ?? !1, t.onmessage = (s) => {
234
240
  const r = s.data;
@@ -236,7 +242,7 @@ class Te {
236
242
  case "loaded-gltf":
237
243
  for (const n of this._running)
238
244
  if (n.url === r.result.url) {
239
- Rt(r.result), n.resolve(r.result);
245
+ Pt(r.result), n.resolve(r.result);
240
246
  const o = n.url;
241
247
  o.startsWith("blob:") && URL.revokeObjectURL(o);
242
248
  }
@@ -255,7 +261,7 @@ class Te {
255
261
  ), {
256
262
  type: "module"
257
263
  });
258
- return new Te(e, t);
264
+ return new Se(e, t);
259
265
  }
260
266
  _running = [];
261
267
  _webglRenderer = null;
@@ -291,23 +297,23 @@ class Te {
291
297
  }
292
298
  _debug = !1;
293
299
  }
294
- function Rt(i) {
300
+ function Pt(i) {
295
301
  for (const t of i.geometries) {
296
302
  const e = t.geometry, s = new H();
297
303
  if (s.name = e.name || "", e.index) {
298
304
  const r = e.index;
299
- s.setIndex(de(r));
305
+ s.setIndex(fe(r));
300
306
  }
301
307
  for (const r in e.attributes) {
302
- const n = e.attributes[r], o = de(n);
308
+ const n = e.attributes[r], o = fe(n);
303
309
  s.setAttribute(r, o);
304
310
  }
305
311
  if (e.morphAttributes)
306
312
  for (const r in e.morphAttributes) {
307
- const o = e.morphAttributes[r].map((l) => de(l));
313
+ const o = e.morphAttributes[r].map((l) => fe(l));
308
314
  s.morphAttributes[r] = o;
309
315
  }
310
- if (s.morphTargetsRelative = e.morphTargetsRelative ?? !1, s.boundingBox = new fe(), s.boundingBox.min = new A(
316
+ if (s.morphTargetsRelative = e.morphTargetsRelative ?? !1, s.boundingBox = new ce(), s.boundingBox.min = new A(
311
317
  e.boundingBox?.min.x,
312
318
  e.boundingBox?.min.y,
313
319
  e.boundingBox?.min.z
@@ -315,7 +321,7 @@ function Rt(i) {
315
321
  e.boundingBox?.max.x,
316
322
  e.boundingBox?.max.y,
317
323
  e.boundingBox?.max.z
318
- ), s.boundingSphere = new Ie(
324
+ ), s.boundingSphere = new Ge(
319
325
  new A(
320
326
  e.boundingSphere?.center.x,
321
327
  e.boundingSphere?.center.y,
@@ -332,7 +338,7 @@ function Rt(i) {
332
338
  let s = null;
333
339
  if (e.isCompressedTexture) {
334
340
  const r = e.mipmaps, { width: n, height: o } = ve(e);
335
- s = new Ze(
341
+ s = new et(
336
342
  r,
337
343
  n,
338
344
  o,
@@ -358,7 +364,7 @@ function Rt(i) {
358
364
  e.type,
359
365
  e.anisotropy,
360
366
  e.colorSpace
361
- ), s.mipmaps = e.mipmaps, s.channel = e.channel, s.source.data = e.source.data, s.flipY = e.flipY, s.premultiplyAlpha = e.premultiplyAlpha, s.unpackAlignment = e.unpackAlignment, s.matrix = new et(...e.matrix.elements);
367
+ ), s.mipmaps = e.mipmaps, s.channel = e.channel, s.source.data = e.source.data, s.flipY = e.flipY, s.premultiplyAlpha = e.premultiplyAlpha, s.unpackAlignment = e.unpackAlignment, s.matrix = new tt(...e.matrix.elements);
362
368
  if (!s) {
363
369
  console.error("[Worker] Failed to create new texture from received data. Texture is not a CompressedTexture or Texture.");
364
370
  continue;
@@ -367,15 +373,15 @@ function Rt(i) {
367
373
  }
368
374
  return i;
369
375
  }
370
- function de(i) {
376
+ function fe(i) {
371
377
  let t = i;
372
378
  if ("isInterleavedBufferAttribute" in i && i.isInterleavedBufferAttribute) {
373
- const e = i.data, s = e.array, r = new tt(s, e.stride);
374
- t = new st(r, i.itemSize, s.byteOffset, i.normalized), t.offset = i.offset;
375
- } else "isBufferAttribute" in i && i.isBufferAttribute && (t = new rt(i.array, i.itemSize, i.normalized), t.usage = i.usage, t.gpuType = i.gpuType, t.updateRanges = i.updateRanges);
379
+ const e = i.data, s = e.array, r = new st(s, e.stride);
380
+ t = new rt(r, i.itemSize, s.byteOffset, i.normalized), t.offset = i.offset;
381
+ } else "isBufferAttribute" in i && i.isBufferAttribute && (t = new nt(i.array, i.itemSize, i.normalized), t.usage = i.usage, t.gpuType = i.gpuType, t.updateRanges = i.updateRanges);
376
382
  return t;
377
383
  }
378
- const Pt = X("gltf-progressive-worker");
384
+ const Ct = X("gltf-progressive-worker");
379
385
  X("gltf-progressive-reduce-mipmaps");
380
386
  const ie = X("gltf-progressive-gc"), he = /* @__PURE__ */ Symbol("needle-progressive-texture"), z = "NEEDLE_progressive";
381
387
  class p {
@@ -444,12 +450,12 @@ class p {
444
450
  function o(l, a) {
445
451
  const u = s.getAssignedLODInformation(l);
446
452
  if (u) {
447
- const d = s.lodInfos.get(u.key);
448
- if (d && d.lods) {
449
- a.min_count = Math.min(a.min_count, d.lods.length), a.max_count = Math.max(a.max_count, d.lods.length);
450
- for (let c = 0; c < d.lods.length; c++) {
451
- const f = d.lods[c];
452
- f.width && (a.lods[c] = a.lods[c] || { min_height: 1 / 0, max_height: 0 }, a.lods[c].min_height = Math.min(a.lods[c].min_height, f.height), a.lods[c].max_height = Math.max(a.lods[c].max_height, f.height));
453
+ const f = s.lodInfos.get(u.key);
454
+ if (f && f.lods) {
455
+ a.min_count = Math.min(a.min_count, f.lods.length), a.max_count = Math.max(a.max_count, f.lods.length);
456
+ for (let c = 0; c < f.lods.length; c++) {
457
+ const d = f.lods[c];
458
+ d.width && (a.lods[c] = a.lods[c] || { min_height: 1 / 0, max_height: 0 }, a.lods[c].min_height = Math.min(a.lods[c].min_height, d.height), a.lods[c].max_height = Math.max(a.lods[c].max_height, d.height));
453
459
  }
454
460
  }
455
461
  }
@@ -549,9 +555,9 @@ class p {
549
555
  if (this.trackCurrentMaterialTextureSlots(n), n.uniforms && (n.isRawShaderMaterial || n.isShaderMaterial === !0)) {
550
556
  const a = n;
551
557
  for (const u of Object.keys(a.uniforms)) {
552
- const d = a.uniforms[u].value;
553
- if (d?.isTexture === !0) {
554
- const c = this.assignTextureLODForSlot(d, e, n, u, r).then((f) => (f && a.uniforms[u].value != f && (a.uniforms[u].value = f, a.uniformsNeedUpdate = !0), f));
558
+ const f = a.uniforms[u].value;
559
+ if (f?.isTexture === !0) {
560
+ const c = this.assignTextureLODForSlot(f, e, n, u, r).then((d) => (d && a.uniforms[u].value != d && (a.uniforms[u].value = d, a.uniformsNeedUpdate = !0), d));
555
561
  o.push(c), l.push(u);
556
562
  }
557
563
  }
@@ -559,15 +565,15 @@ class p {
559
565
  for (const a of Object.keys(n)) {
560
566
  const u = n[a];
561
567
  if (u?.isTexture === !0) {
562
- const d = this.assignTextureLODForSlot(u, e, n, a, r);
563
- o.push(d), l.push(a);
568
+ const f = this.assignTextureLODForSlot(u, e, n, a, r);
569
+ o.push(f), l.push(a);
564
570
  }
565
571
  }
566
572
  return Promise.all(o).then((a) => {
567
573
  const u = new Array();
568
- for (let d = 0; d < a.length; d++) {
569
- const c = a[d], f = l[d];
570
- c && c.isTexture === !0 ? u.push({ material: n, slot: f, texture: c, level: e }) : u.push({ material: n, slot: f, texture: null, level: e });
574
+ for (let f = 0; f < a.length; f++) {
575
+ const c = a[f], d = l[f];
576
+ c && c.isTexture === !0 ? u.push({ material: n, slot: d, texture: c, level: e }) : u.push({ material: n, slot: d, texture: null, level: e });
571
577
  }
572
578
  return u;
573
579
  });
@@ -602,7 +608,7 @@ class p {
602
608
  if (c && c.level === e && c.force === n)
603
609
  return c.promise;
604
610
  }
605
- const l = s && r ? this.nextTextureSlotRequestId(s, r, e, n) : 0, a = () => !s || !r || this.getLatestTextureSlotRequest(s, r)?.id === l, u = () => a() || this.shouldApplyStaleTextureSlotLOD(s, r, e, n), d = p.getOrLoadLOD(t, e, {
611
+ const l = s && r ? this.nextTextureSlotRequestId(s, r, e, n) : 0, a = () => !s || !r || this.getLatestTextureSlotRequest(s, r)?.id === l, u = () => a() || this.shouldApplyStaleTextureSlotLOD(s, r, e, n), f = p.getOrLoadLOD(t, e, {
606
612
  isCurrent: u
607
613
  }).then((c) => {
608
614
  if (!a() && !this.shouldApplyStaleTextureSlotLOD(s, r, e, n)) return null;
@@ -610,11 +616,11 @@ class p {
610
616
  return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen..."), null;
611
617
  if (c?.isTexture === !0) {
612
618
  if (c != t && s && r) {
613
- const f = this.getMaterialTextureSlot(s, r) ?? t;
614
- if (f && !n) {
615
- const h = this.getAssignedLODInformation(f);
619
+ const d = this.getMaterialTextureSlot(s, r) ?? t;
620
+ if (d && !n) {
621
+ const h = this.getAssignedLODInformation(d);
616
622
  if (h && h?.level < e)
617
- return g === "verbose" && console.warn("Assigned texture level is already higher: ", h.level, e, s, f, c), null;
623
+ return g === "verbose" && console.warn("Assigned texture level is already higher: ", h.level, e, s, d, c), null;
618
624
  }
619
625
  this.assignTrackedTextureSlot(s, r, c);
620
626
  }
@@ -622,7 +628,7 @@ class p {
622
628
  } else g == "verbose" && console.warn("No LOD found for", t, e);
623
629
  return null;
624
630
  }).catch((c) => (console.error("Error loading LOD", t, c), null));
625
- return s && r && this.setPendingTextureSlotRequest(s, r, e, n, l, d), d;
631
+ return s && r && this.setPendingTextureSlotRequest(s, r, e, n, l, f), f;
626
632
  }
627
633
  // Track material slots, not just texture objects. A shared fallback texture can be
628
634
  // referenced by many slots and should only be disposed after every slot moved away.
@@ -811,9 +817,9 @@ class p {
811
817
  }
812
818
  l.userData || (l.userData = {}), g && console.log("> Progressive: register mesh " + s.name, { index: n, uuid: s.uuid }, o, s), p.assignLODInformation(t, l, e, r, n), p.lodInfos.set(e, o);
813
819
  let u = p.lowresCache.get(e)?.deref();
814
- u ? u.push(s.geometry) : u = [s.geometry], p.lowresCache.set(e, new WeakRef(u)), r > 0 && !ae(s) && Mt(s, l);
815
- for (const d of U)
816
- d.onRegisteredNewMesh?.(s, o);
820
+ u ? u.push(s.geometry) : u = [s.geometry], p.lowresCache.set(e, new WeakRef(u)), r > 0 && !ae(s) && _t(s, l);
821
+ for (const f of U)
822
+ f.onRegisteredNewMesh?.(s, o);
817
823
  };
818
824
  /**
819
825
  * Dispose cached resources to free memory.
@@ -911,10 +917,9 @@ ${t}`), e instanceof WeakRef && (e.deref() || (p.cache.delete(t), (g || ie) && c
911
917
  return this.textureRefCounts.delete(e), (g || ie) && n("[gltf-progressive] Memory: Dispose texture", r), t.dispose(), !0;
912
918
  return this.textureRefCounts.set(e, r), g === "verbose" && n("[gltf-progressive] Memory: Untrack texture", r), !1;
913
919
  function n(o, l) {
914
- let { width: a, height: u } = ve(t);
915
- const d = a && u ? `${a}x${u}` : "N/A";
920
+ const { width: a, height: u } = ve(t), f = a && u ? `${a}x${u}` : "N/A";
916
921
  let c = "N/A";
917
- a && u && (c = `~${(Lt(t) / (1024 * 1024)).toFixed(2)} MB`), console.log(`${o} — ${t.name} ${d} (${c}), refCount: ${s} → ${l}
922
+ a && u && (c = `~${(vt(t) / (1024 * 1024)).toFixed(2)} MB`), console.log(`${o} — ${t.name} ${f} (${c}), refCount: ${s} → ${l}
918
923
  ${e}`);
919
924
  }
920
925
  }
@@ -929,33 +934,33 @@ ${e}`);
929
934
  const l = o?.key;
930
935
  let a;
931
936
  if (t.isTexture === !0) {
932
- const d = t;
933
- d.source && d.source[he] && (a = d.source[he]);
937
+ const f = t;
938
+ f.source && f.source[he] && (a = f.source[he]);
934
939
  }
935
940
  if (a || (a = p.lodInfos.get(l)), !a)
936
941
  g && console.warn(`Can not load LOD ${e}: no LOD info found for "${l}" ${t.name}`, t.type, p.lodInfos);
937
942
  else {
938
943
  if (e > 0) {
939
- let f = !1;
944
+ let d = !1;
940
945
  const h = Array.isArray(a.lods);
941
- if (h && e >= a.lods.length ? f = !0 : h || (f = !0), f) {
946
+ if (h && e >= a.lods.length ? d = !0 : h || (d = !0), d) {
942
947
  const D = this.lowresCache.get(l);
943
948
  if (D) {
944
- const w = D.deref();
945
- if (w) return w;
949
+ const L = D.deref();
950
+ if (L) return L;
946
951
  this.lowresCache.delete(l), g && console.log(`[gltf-progressive] Lowres cache entry was GC'd: ${l}`);
947
952
  }
948
953
  return null;
949
954
  }
950
955
  }
951
- const d = Array.isArray(a.lods) ? a.lods[e]?.path : a.lods;
952
- if (!d)
956
+ const f = Array.isArray(a.lods) ? a.lods[e]?.path : a.lods;
957
+ if (!f)
953
958
  return g && !a["missing:uri"] && (a["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, a)), null;
954
- const c = xt(o.url, d);
959
+ const c = Lt(o.url, f);
955
960
  if (c.endsWith(".glb") || c.endsWith(".gltf")) {
956
961
  if (!a.guid)
957
962
  return console.warn("missing pointer for glb/gltf texture", a), null;
958
- const f = c + "_" + a.guid, h = await this.tryResolveLODCacheEntry(this.cache.get(f), f, c, t, e, n);
963
+ const d = c + "_" + a.guid, h = await this.tryResolveLODCacheEntry(this.cache.get(d), d, c, t, e, n);
959
964
  if (r !== this.cacheGeneration) return null;
960
965
  if (h.found) return h.value;
961
966
  if (s?.isCurrent?.() === !1)
@@ -964,24 +969,24 @@ ${e}`);
964
969
  if (r !== this.cacheGeneration) return null;
965
970
  if (s?.isCurrent?.() === !1)
966
971
  return n && console.log(`Skipping stale LOD ${e} request after queue: ${c}`), null;
967
- const w = await this.tryResolveLODCacheEntry(this.cache.get(f), f, c, t, e, n);
972
+ const L = await this.tryResolveLODCacheEntry(this.cache.get(d), d, c, t, e, n);
968
973
  if (r !== this.cacheGeneration) return null;
969
- if (w.found) return w.value;
970
- const x = this.cache.get(f);
974
+ if (L.found) return L.value;
975
+ const x = this.cache.get(d);
971
976
  if (x !== void 0) {
972
- const y = await this.tryResolveLODCacheEntry(x, f, c, t, e, n);
977
+ const y = await this.tryResolveLODCacheEntry(x, d, c, t, e, n);
973
978
  if (r !== this.cacheGeneration) return null;
974
979
  if (y.found) return y.value;
975
980
  }
976
981
  if (!D.use)
977
982
  return g && console.log(`LOD ${e} was aborted: ${c}`), null;
978
- const L = a, M = new Promise(async (y, O) => {
979
- if (Pt) {
980
- const m = await (await St({})).load(c);
983
+ const w = a, M = new Promise(async (y, O) => {
984
+ if (Ct) {
985
+ const m = await (await Rt({})).load(c);
981
986
  if (m.textures.length > 0)
982
987
  for (const v of m.textures) {
983
988
  let S = v.texture;
984
- return p.assignLODInformation(o.url, S, l, e, void 0), t instanceof W && (S = this.copySettings(t, S)), S && (S.guid = L.guid), y(S);
989
+ return p.assignLODInformation(o.url, S, l, e, void 0), t instanceof W && (S = this.copySettings(t, S)), S && (S.guid = w.guid), y(S);
985
990
  }
986
991
  if (m.geometries.length > 0) {
987
992
  const v = new Array();
@@ -994,51 +999,51 @@ ${e}`);
994
999
  return y(null);
995
1000
  }
996
1001
  const I = new Me();
997
- Be(I), g && (await new Promise((b) => setTimeout(b, 1e3)), n && console.warn("Start loading (delayed) " + c, L.guid));
998
- let P = c;
999
- if (L && Array.isArray(L.lods)) {
1000
- const b = L.lods[e];
1001
- b.hash && (P += "?v=" + b.hash);
1002
+ We(I), g && (await new Promise((b) => setTimeout(b, 1e3)), n && console.warn("Start loading (delayed) " + c, w.guid));
1003
+ let C = c;
1004
+ if (w && Array.isArray(w.lods)) {
1005
+ const b = w.lods[e];
1006
+ b.hash && (C += "?v=" + b.hash);
1002
1007
  }
1003
- const _ = await I.loadAsync(P).catch((b) => (console.error(`Error loading LOD ${e} from ${c}
1008
+ const _ = await I.loadAsync(C).catch((b) => (console.error(`Error loading LOD ${e} from ${c}
1004
1009
  `, b), y(null)));
1005
1010
  if (!_)
1006
1011
  return y(null);
1007
1012
  const E = _.parser;
1008
- n && console.log("Loading finished " + c, L.guid);
1009
- let C = 0;
1013
+ n && console.log("Loading finished " + c, w.guid);
1014
+ let k = 0;
1010
1015
  if (_.parser.json.textures) {
1011
1016
  let b = !1;
1012
1017
  for (const m of _.parser.json.textures) {
1013
1018
  if (m?.extensions) {
1014
1019
  const v = m?.extensions[z];
1015
- if (v?.guid && v.guid === L.guid) {
1020
+ if (v?.guid && v.guid === w.guid) {
1016
1021
  b = !0;
1017
1022
  break;
1018
1023
  }
1019
1024
  }
1020
- C++;
1025
+ k++;
1021
1026
  }
1022
1027
  if (b) {
1023
- let m = await E.getDependency("texture", C);
1024
- return m && p.assignLODInformation(o.url, m, l, e, void 0), n && console.log('change "' + t.name + '" → "' + m.name + '"', c, C, m, f), t instanceof W && (m = this.copySettings(t, m)), m && (m.guid = L.guid), y(m);
1025
- } else g && console.warn("Could not find texture with guid", L.guid, _.parser.json);
1028
+ let m = await E.getDependency("texture", k);
1029
+ return m && p.assignLODInformation(o.url, m, l, e, void 0), n && console.log('change "' + t.name + '" → "' + m.name + '"', c, k, m, d), t instanceof W && (m = this.copySettings(t, m)), m && (m.guid = w.guid), y(m);
1030
+ } else g && console.warn("Could not find texture with guid", w.guid, _.parser.json);
1026
1031
  }
1027
- if (C = 0, _.parser.json.meshes) {
1032
+ if (k = 0, _.parser.json.meshes) {
1028
1033
  let b = !1;
1029
1034
  for (const m of _.parser.json.meshes) {
1030
1035
  if (m?.extensions) {
1031
1036
  const v = m?.extensions[z];
1032
- if (v?.guid && v.guid === L.guid) {
1037
+ if (v?.guid && v.guid === w.guid) {
1033
1038
  b = !0;
1034
1039
  break;
1035
1040
  }
1036
1041
  }
1037
- C++;
1042
+ k++;
1038
1043
  }
1039
1044
  if (b) {
1040
- const m = await E.getDependency("mesh", C);
1041
- if (n && console.log(`Loaded Mesh "${m.name}"`, c, C, m, f), m.isMesh === !0) {
1045
+ const m = await E.getDependency("mesh", k);
1046
+ if (n && console.log(`Loaded Mesh "${m.name}"`, c, k, m, d), m.isMesh === !0) {
1042
1047
  const v = m.geometry;
1043
1048
  return p.assignLODInformation(o.url, v, l, e, 0), y(v);
1044
1049
  } else {
@@ -1052,18 +1057,18 @@ ${e}`);
1052
1057
  }
1053
1058
  return y(v);
1054
1059
  }
1055
- } else g && console.warn("Could not find mesh with guid", L.guid, _.parser.json);
1060
+ } else g && console.warn("Could not find mesh with guid", w.guid, _.parser.json);
1056
1061
  }
1057
1062
  return y(null);
1058
1063
  });
1059
- this.cache.set(f, M), D.use(M);
1064
+ this.cache.set(d, M), D.use(M);
1060
1065
  const T = await M;
1061
- return r !== this.cacheGeneration || this.cache.get(f) !== M ? null : (T != null ? T instanceof W ? (this.cache.set(f, new WeakRef(T)), p._resourceRegistry.register(T, f)) : Array.isArray(T) ? this.cache.set(f, Promise.resolve(T)) : this.cache.set(f, Promise.resolve(T)) : this.cache.set(f, Promise.resolve(null)), T);
1066
+ return r !== this.cacheGeneration || this.cache.get(d) !== M ? null : (T != null ? T instanceof W ? (this.cache.set(d, new WeakRef(T)), p._resourceRegistry.register(T, d)) : Array.isArray(T) ? this.cache.set(d, Promise.resolve(T)) : this.cache.set(d, Promise.resolve(T)) : this.cache.set(d, Promise.resolve(null)), T);
1062
1067
  } else if (t instanceof W) {
1063
1068
  if (s?.isCurrent?.() === !1)
1064
1069
  return n && console.log(`Skipping stale texture LOD ${e} request: ${c}`), null;
1065
1070
  n && console.log("Load texture from uri: " + c);
1066
- const h = await new nt().loadAsync(c);
1071
+ const h = await new it().loadAsync(c);
1067
1072
  return r !== this.cacheGeneration || s?.isCurrent?.() === !1 ? (h?.dispose(), null) : (h ? (h.guid = a.guid, h.flipY = !1, h.needsUpdate = !0, h.colorSpace = t.colorSpace, n && console.log(a, h)) : g && console.warn("failed loading", c), h);
1068
1073
  }
1069
1074
  }
@@ -1075,9 +1080,9 @@ ${e}`);
1075
1080
  if (o && console.log(`LOD ${n} was already loading/loaded: ${e}`), t instanceof WeakRef) {
1076
1081
  const u = t.deref();
1077
1082
  if (u) {
1078
- let d = u, c = !1;
1079
- if (d instanceof W && r instanceof W ? Oe(d.image) || Le(d) ? d = this.copySettings(r, d) : c = !0 : d instanceof H && r instanceof H && (d.attributes.position?.array || (c = !0)), !c)
1080
- return { found: !0, value: d };
1083
+ let f = u, c = !1;
1084
+ if (f instanceof W && r instanceof W ? Re(f.image) || we(f) ? f = this.copySettings(r, f) : c = !0 : f instanceof H && r instanceof H && (f.attributes.position?.array || (c = !0)), !c)
1085
+ return { found: !0, value: f };
1081
1086
  }
1082
1087
  return this.cache.delete(e), g && console.log(`[gltf-progressive] Re-loading GC'd/disposed resource: ${e}`), { found: !1 };
1083
1088
  }
@@ -1085,16 +1090,16 @@ ${e}`);
1085
1090
  `, u), null));
1086
1091
  if (this.disposedRequests.has(t)) return { found: !0, value: null };
1087
1092
  let a = !1;
1088
- return l == null || (l instanceof W && r instanceof W ? Oe(l.image) || Le(l) ? l = this.copySettings(r, l) : (a = !0, this.cache.delete(e)) : l instanceof H && r instanceof H && (l.attributes.position?.array || (a = !0, this.cache.delete(e)))), a ? { found: !1 } : { found: !0, value: l };
1093
+ return l == null || (l instanceof W && r instanceof W ? Re(l.image) || we(l) ? l = this.copySettings(r, l) : (a = !0, this.cache.delete(e)) : l instanceof H && r instanceof H && (l.attributes.position?.array || (a = !0, this.cache.delete(e)))), a ? { found: !1 } : { found: !0, value: l };
1089
1094
  }
1090
1095
  static _queue;
1091
1096
  static get queue() {
1092
- return this._queue ??= new wt(be() ? 20 : 50, { debug: g != !1 });
1097
+ return this._queue ??= new wt(Oe() ? 20 : 50, { debug: g != !1 });
1093
1098
  }
1094
1099
  static assignLODInformation(t, e, s, r, n) {
1095
1100
  if (!e) return;
1096
1101
  e.userData || (e.userData = {});
1097
- const o = new Ct(t, s, r, n);
1102
+ const o = new kt(t, s, r, n);
1098
1103
  e.userData.LODS = o, "source" in e && typeof e.source == "object" && (e.source.LODS = o);
1099
1104
  }
1100
1105
  static getAssignedLODInformation(t) {
@@ -1107,7 +1112,7 @@ ${e}`);
1107
1112
  `, 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;
1108
1113
  }
1109
1114
  }
1110
- class Ct {
1115
+ class kt {
1111
1116
  url;
1112
1117
  /** the key to lookup the LOD information */
1113
1118
  key;
@@ -1194,7 +1199,7 @@ class le {
1194
1199
  });
1195
1200
  }
1196
1201
  }
1197
- const $ = X("debugprogressive"), kt = $ === "colors", At = X("noprogressive"), ge = /* @__PURE__ */ Symbol("Needle:LODSManager"), pe = /* @__PURE__ */ Symbol("Needle:LODState"), N = /* @__PURE__ */ Symbol("Needle:CurrentLOD"), Se = Ve, R = { mesh_lod: -1, texture_lod: -1 }, It = new $e(), Re = [
1202
+ const $ = X("debugprogressive"), At = $ === "colors", It = X("noprogressive"), ge = /* @__PURE__ */ Symbol("Needle:LODSManager"), pe = /* @__PURE__ */ Symbol("Needle:LODState"), N = /* @__PURE__ */ Symbol("Needle:CurrentLOD"), Pe = Xe, R = { mesh_lod: -1, texture_lod: -1 }, $t = new Be(), Ce = [
1198
1203
  3526751,
1199
1204
  11065402,
1200
1205
  15978811,
@@ -1228,16 +1233,16 @@ const $ = X("debugprogressive"), kt = $ === "colors", At = X("noprogressive"), g
1228
1233
  5083278,
1229
1234
  5592405
1230
1235
  ];
1231
- function $t() {
1232
- const i = Se.Timer || Se.Clock;
1236
+ function Gt() {
1237
+ const i = Pe.Timer || Pe.Clock;
1233
1238
  return new i();
1234
1239
  }
1235
- const me = new fe(), V = new fe(), Pe = new fe(), Gt = new A(), Bt = new A(), qt = new Ge(), F = new A(), Z = new A(), ee = new A(), te = new A();
1236
- function Wt(i, t) {
1240
+ const me = new ce(), V = new ce(), ke = new ce(), Bt = new A(), qt = new A(), Wt = new qe(), F = new A(), Z = new A(), ee = new A(), te = new A();
1241
+ function Ft(i, t) {
1237
1242
  const e = i.min, s = i.max, r = (e.x + s.x) * 0.5, n = (e.y + s.y) * 0.5;
1238
1243
  return F.set(r, n, e.z).applyMatrix4(t).z < 0;
1239
1244
  }
1240
- function Ft(i) {
1245
+ function Ut(i) {
1241
1246
  const {
1242
1247
  geometry: t,
1243
1248
  matrixWorld: e,
@@ -1248,43 +1253,43 @@ function Ft(i) {
1248
1253
  currentLevel: l = -1,
1249
1254
  xrEnabled: a = !1,
1250
1255
  debugDrawLine: u,
1251
- warnMissingPrimitiveDensities: d = !1
1252
- } = i, c = p.getMeshLODExtension(t)?.lods, f = p.getPrimitiveIndex(t), h = i.target ?? {
1256
+ warnMissingPrimitiveDensities: f = !1
1257
+ } = i, c = p.getMeshLODExtension(t)?.lods, d = p.getPrimitiveIndex(t), h = i.target ?? {
1253
1258
  level: l,
1254
- primitiveIndex: f,
1259
+ primitiveIndex: d,
1255
1260
  screenCoverage: 0,
1256
1261
  screenspaceVolume: new A(),
1257
1262
  centrality: 1
1258
1263
  };
1259
- h.level = l, h.primitiveIndex = f, h.screenCoverage = 0, h.screenspaceVolume.set(0, 0, 0), h.centrality = 1;
1264
+ h.level = l, h.primitiveIndex = d, h.screenCoverage = 0, h.screenspaceVolume.set(0, 0, 0), h.centrality = 1;
1260
1265
  let D = i.boundingBox ?? t.boundingBox;
1261
1266
  if (D || (t.computeBoundingBox(), D = t.boundingBox), !D) return h;
1262
- if (me.copy(D).applyMatrix4(e), s.isPerspectiveCamera && Wt(me, r))
1267
+ if (me.copy(D).applyMatrix4(e), s.isPerspectiveCamera && Ft(me, r))
1263
1268
  return h.level = 0, h.screenCoverage = 1 / 0, h.screenspaceVolume.set(1 / 0, 1 / 0, 1 / 0), h;
1264
1269
  if (V.copy(me).applyMatrix4(r), a && s.isPerspectiveCamera && s.fov > 70) {
1265
1270
  const y = V.min, O = V.max;
1266
- let I = y.x, P = y.y, _ = O.x, E = O.y;
1267
- const C = 2, b = 1.5, m = (y.x + O.x) * 0.5, v = (y.y + O.y) * 0.5;
1268
- I = (I - m) * C + m, P = (P - v) * C + v, _ = (_ - m) * C + m, E = (E - v) * C + v;
1269
- const S = I < 0 && _ > 0 ? 0 : Math.min(Math.abs(y.x), Math.abs(O.x)), j = P < 0 && E > 0 ? 0 : Math.min(Math.abs(y.y), Math.abs(O.y)), J = Math.max(S, j);
1271
+ let I = y.x, C = y.y, _ = O.x, E = O.y;
1272
+ const k = 2, b = 1.5, m = (y.x + O.x) * 0.5, v = (y.y + O.y) * 0.5;
1273
+ I = (I - m) * k + m, C = (C - v) * k + v, _ = (_ - m) * k + m, E = (E - v) * k + v;
1274
+ const S = I < 0 && _ > 0 ? 0 : Math.min(Math.abs(y.x), Math.abs(O.x)), j = C < 0 && E > 0 ? 0 : Math.min(Math.abs(y.y), Math.abs(O.y)), J = Math.max(S, j);
1270
1275
  h.centrality = (b - J) * (b - J) * (b - J);
1271
1276
  }
1272
- const w = V.getSize(Gt);
1273
- w.multiplyScalar(0.5), globalThis.screen?.availHeight > 0 && o > 0 && w.multiplyScalar(o / globalThis.screen.availHeight), s.isPerspectiveCamera && (w.x *= s.aspect), Pe.copy(D).applyMatrix4(e).applyMatrix4(s.matrixWorldInverse);
1274
- const x = Pe.getSize(Bt), L = Math.max(w.x, w.y), M = Math.max(x.x, x.y);
1275
- L !== 0 && M !== 0 && (w.z = x.z / M * L);
1276
- const T = Math.max(w.x, w.y, w.z) * h.centrality;
1277
- if (h.screenCoverage = T, h.screenspaceVolume.copy(w), T <= 0) return h;
1277
+ const L = V.getSize(Bt);
1278
+ L.multiplyScalar(0.5), globalThis.screen?.availHeight > 0 && o > 0 && L.multiplyScalar(o / globalThis.screen.availHeight), s.isPerspectiveCamera && (L.x *= s.aspect), ke.copy(D).applyMatrix4(e).applyMatrix4(s.matrixWorldInverse);
1279
+ const x = ke.getSize(qt), w = Math.max(L.x, L.y), M = Math.max(x.x, x.y);
1280
+ w !== 0 && M !== 0 && (L.z = x.z / M * w);
1281
+ const T = Math.max(L.x, L.y, L.z) * h.centrality;
1282
+ if (h.screenCoverage = T, h.screenspaceVolume.copy(L), T <= 0) return h;
1278
1283
  if (u) {
1279
- const y = qt.copy(r);
1284
+ const y = Wt.copy(r);
1280
1285
  y.invert(), F.copy(V.min), Z.copy(V.max), Z.x = F.x, ee.copy(V.max), ee.y = F.y, te.copy(V.max);
1281
1286
  const O = (F.z + te.z) * 0.5;
1282
1287
  F.z = Z.z = ee.z = te.z = O, F.applyMatrix4(y), Z.applyMatrix4(y), ee.applyMatrix4(y), te.applyMatrix4(y), u(F, Z, 255), u(F, ee, 255), u(Z, te, 255), u(ee, te, 255);
1283
1288
  }
1284
1289
  if (c?.length)
1285
1290
  for (let y = 0; y < c.length; y++) {
1286
- const O = c[y], I = O.densities?.[f] || O.density || 1e-5;
1287
- if (f > 0 && d && Fe() && !O.densities && !globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] && (globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] = !0, console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")), I / T < n) {
1291
+ const O = c[y], I = O.densities?.[d] || O.density || 1e-5;
1292
+ if (d > 0 && f && Ue() && !O.densities && !globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] && (globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] = !0, console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")), I / T < n) {
1288
1293
  h.level = y;
1289
1294
  break;
1290
1295
  }
@@ -1327,7 +1332,7 @@ class G {
1327
1332
  }
1328
1333
  renderer;
1329
1334
  context;
1330
- projectionScreenMatrix = new Ge();
1335
+ projectionScreenMatrix = new qe();
1331
1336
  /** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
1332
1337
  get plugins() {
1333
1338
  return U;
@@ -1400,7 +1405,7 @@ class G {
1400
1405
  const r = performance.now();
1401
1406
  return s.ready.finally(() => {
1402
1407
  const n = this._newPromiseGroups.indexOf(s);
1403
- n >= 0 && (this._newPromiseGroups.splice(n, 1), Fe() && performance.measure("LODsManager:awaitLoading", {
1408
+ n >= 0 && (this._newPromiseGroups.splice(n, 1), Ue() && performance.measure("LODsManager:awaitLoading", {
1404
1409
  start: r,
1405
1410
  detail: { id: e, name: t?.name, awaited: s.awaitedCount, resolved: s.resolvedCount }
1406
1411
  }));
@@ -1460,7 +1465,7 @@ class G {
1460
1465
  #n = 0;
1461
1466
  #o = 0;
1462
1467
  #s = 0;
1463
- #i = $t();
1468
+ #i = Gt();
1464
1469
  _fpsBuffer = [60, 60, 60, 60, 60];
1465
1470
  /**
1466
1471
  * Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
@@ -1510,7 +1515,7 @@ class G {
1510
1515
  (l.name === "EffectMaterial" || l.name === "CopyShader") && (o = !1);
1511
1516
  }
1512
1517
  if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (o = !1), o) {
1513
- if (At || (this.updateInterval === "auto" ? this.#s < 40 && this.#e < 10 ? (this.#e += 1, $ && console.warn("↓ Reducing LOD updates", this.#e, this.#s.toFixed(0))) : this.#s >= 60 && this.#e > 1 && (this.#e -= 1, $ && console.warn("↑ Increasing LOD updates", this.#e, this.#s.toFixed(0))) : this.#e = this.updateInterval, this.#e > 0 && this.#r % this.#e != 0))
1518
+ if (It || (this.updateInterval === "auto" ? this.#s < 40 && this.#e < 10 ? (this.#e += 1, $ && console.warn("↓ Reducing LOD updates", this.#e, this.#s.toFixed(0))) : this.#s >= 60 && this.#e > 1 && (this.#e -= 1, $ && console.warn("↑ Increasing LOD updates", this.#e, this.#s.toFixed(0))) : this.#e = this.updateInterval, this.#e > 0 && this.#r % this.#e != 0))
1514
1519
  return;
1515
1520
  this.internalUpdate(t, e), this._postprocessPromiseGroups();
1516
1521
  }
@@ -1575,12 +1580,12 @@ class G {
1575
1580
  updateLODs(t, e, s, r) {
1576
1581
  s.userData || (s.userData = {});
1577
1582
  let n = s[pe];
1578
- if (n || (n = new Ut(), s[pe] = n), n.frames++ < 2)
1583
+ if (n || (n = new zt(), s[pe] = n), n.frames++ < 2)
1579
1584
  return;
1580
1585
  for (const l of U)
1581
1586
  l.onBeforeUpdateLOD?.(this.renderer, t, e, s);
1582
1587
  const o = this.overrideLodLevel !== void 0 ? this.overrideLodLevel : K;
1583
- o >= 0 ? (R.mesh_lod = o, R.texture_lod = o) : (this.calculateLodLevel(e, s, n, r, R), R.mesh_lod = Math.round(R.mesh_lod), R.texture_lod = Math.round(R.texture_lod)), R.mesh_lod >= 0 && this.loadProgressiveMeshes(s, R.mesh_lod), s.material && R.texture_lod >= 0 && this.loadProgressiveTextures(s.material, R.texture_lod, o), g && s.material && !s.isGizmo && Ue(s.material), kt && s.material && !s.isGizmo && !s.isBatchedMesh && ze(s.material, R.mesh_lod);
1588
+ o >= 0 ? (R.mesh_lod = o, R.texture_lod = o) : (this.calculateLodLevel(e, s, n, r, R), R.mesh_lod = Math.round(R.mesh_lod), R.texture_lod = Math.round(R.texture_lod)), R.mesh_lod >= 0 && this.loadProgressiveMeshes(s, R.mesh_lod), s.material && R.texture_lod >= 0 && this.loadProgressiveTextures(s.material, R.texture_lod, o), g && s.material && !s.isGizmo && ze(s.material), At && s.material && !s.isGizmo && !s.isBatchedMesh && Ee(s.material, R.mesh_lod);
1584
1589
  for (const l of U)
1585
1590
  l.onAfterUpdatedLOD?.(this.renderer, t, e, s, R);
1586
1591
  n.lastLodLevel_Mesh = R.mesh_lod, n.lastLodLevel_Texture = R.texture_lod;
@@ -1626,7 +1631,7 @@ class G {
1626
1631
  return Promise.resolve(null);
1627
1632
  }
1628
1633
  // private testIfLODLevelsAreAvailable() {
1629
- _sphere = new Ie();
1634
+ _sphere = new Ge();
1630
1635
  _tempWorldPosition = new A();
1631
1636
  static skinnedMeshBoundsFrameOffsetCounter = 0;
1632
1637
  static $skinnedMeshBoundsOffset = /* @__PURE__ */ Symbol("gltf-progressive-skinnedMeshBoundsOffset");
@@ -1643,14 +1648,14 @@ class G {
1643
1648
  let l = 10 + 1, a = !1;
1644
1649
  if ($ && e["DEBUG:LOD"] != null)
1645
1650
  return e["DEBUG:LOD"];
1646
- const u = p.getMeshLODExtension(e.geometry)?.lods, d = p.getPrimitiveIndex(e.geometry), c = u && u.length > 0, f = p.getMaterialMinMaxLODsCount(e.material), h = f.min_count !== 1 / 0 && f.min_count >= 0 && f.max_count >= 0;
1651
+ const u = p.getMeshLODExtension(e.geometry)?.lods, f = p.getPrimitiveIndex(e.geometry), c = u && u.length > 0, d = p.getMaterialMinMaxLODsCount(e.material), h = d.min_count !== 1 / 0 && d.min_count >= 0 && d.max_count >= 0;
1647
1652
  if (!c && !h) {
1648
1653
  n.mesh_lod = 0, n.texture_lod = 0;
1649
1654
  return;
1650
1655
  }
1651
1656
  c || (a = !0, l = 0);
1652
1657
  const D = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
1653
- let w = e.geometry.boundingBox;
1658
+ let L = e.geometry.boundingBox;
1654
1659
  if (e.type === "SkinnedMesh") {
1655
1660
  const x = e;
1656
1661
  if (!x.boundingBox)
@@ -1660,15 +1665,15 @@ class G {
1660
1665
  const M = G.skinnedMeshBoundsFrameOffsetCounter++;
1661
1666
  x[G.$skinnedMeshBoundsOffset] = M;
1662
1667
  }
1663
- const L = x[G.$skinnedMeshBoundsOffset];
1664
- if ((s.frames + L) % this.skinnedMeshAutoUpdateBoundsInterval === 0) {
1668
+ const w = x[G.$skinnedMeshBoundsOffset];
1669
+ if ((s.frames + w) % this.skinnedMeshAutoUpdateBoundsInterval === 0) {
1665
1670
  const M = ae(x), T = x.geometry;
1666
1671
  M && (x.geometry = M), x.computeBoundingBox(), x.geometry = T;
1667
1672
  }
1668
1673
  }
1669
- w = x.boundingBox;
1674
+ L = x.boundingBox;
1670
1675
  }
1671
- if (w) {
1676
+ if (L) {
1672
1677
  if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
1673
1678
  this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
1674
1679
  const M = t.getWorldPosition(this._tempWorldPosition);
@@ -1677,7 +1682,7 @@ class G {
1677
1682
  return;
1678
1683
  }
1679
1684
  }
1680
- const x = Ft({
1685
+ const x = Ut({
1681
1686
  geometry: e.geometry,
1682
1687
  matrixWorld: e.matrixWorld,
1683
1688
  camera: t,
@@ -1685,7 +1690,7 @@ class G {
1685
1690
  desiredDensity: r,
1686
1691
  canvasHeight: D,
1687
1692
  currentLevel: s.lastLodLevel_Mesh,
1688
- boundingBox: w,
1693
+ boundingBox: L,
1689
1694
  xrEnabled: this.renderer.xr.enabled,
1690
1695
  debugDrawLine: $ ? G.debugDrawLine : void 0,
1691
1696
  warnMissingPrimitiveDensities: !0
@@ -1697,29 +1702,29 @@ class G {
1697
1702
  x.level >= 0 && x.level < l && (l = x.level, a = !0);
1698
1703
  }
1699
1704
  if (a ? n.mesh_lod = l : n.mesh_lod = s.lastLodLevel_Mesh, $ && n.mesh_lod != s.lastLodLevel_Mesh) {
1700
- const L = u?.[n.mesh_lod];
1701
- L && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${n.mesh_lod} (density: ${L.densities?.[d].toFixed(0)}) | ${e.name}`);
1705
+ const w = u?.[n.mesh_lod];
1706
+ w && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${n.mesh_lod} (density: ${w.densities?.[f].toFixed(0)}) | ${e.name}`);
1702
1707
  }
1703
1708
  if (h) {
1704
1709
  const x = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
1705
1710
  if (s.lastLodLevel_Texture < 0) {
1706
- if (n.texture_lod = f.max_count - 1, $) {
1707
- const L = f.lods[f.max_count - 1];
1708
- $ && console.log(`First Texture LOD ${n.texture_lod} (${L.max_height}px) - ${e.name}`);
1711
+ if (n.texture_lod = d.max_count - 1, $) {
1712
+ const w = d.lods[d.max_count - 1];
1713
+ $ && console.log(`First Texture LOD ${n.texture_lod} (${w.max_height}px) - ${e.name}`);
1709
1714
  }
1710
1715
  } else {
1711
- const L = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
1716
+ const w = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
1712
1717
  let M = s.lastScreenCoverage * 4;
1713
1718
  this.context?.engine === "model-viewer" && (M *= 1.5);
1714
1719
  const T = this.renderer.getPixelRatio?.() || globalThis.devicePixelRatio || 1, O = D / T * M;
1715
1720
  let I = !1;
1716
- for (let P = f.lods.length - 1; P >= 0; P--) {
1717
- const _ = f.lods[P];
1718
- if (!(x && _.max_height >= 2048) && !(be() && _.max_height > 4096) && (_.max_height > O || !I && P === 0)) {
1719
- if (I = !0, n.texture_lod = P, $ && n.texture_lod < s.lastLodLevel_Texture) {
1721
+ for (let C = d.lods.length - 1; C >= 0; C--) {
1722
+ const _ = d.lods[C];
1723
+ if (!(x && _.max_height >= 2048) && !(Oe() && _.max_height > 4096) && (_.max_height > O || !I && C === 0)) {
1724
+ if (I = !0, n.texture_lod = C, $ && n.texture_lod < s.lastLodLevel_Texture) {
1720
1725
  const E = _.max_height;
1721
1726
  console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${n.texture_lod} = ${E}px
1722
- Screensize: ${O.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${L.toFixed(1)}
1727
+ Screensize: ${O.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${w.toFixed(1)}
1723
1728
  ${e.name}`);
1724
1729
  }
1725
1730
  break;
@@ -1730,7 +1735,7 @@ ${e.name}`);
1730
1735
  n.texture_lod = 0;
1731
1736
  }
1732
1737
  }
1733
- class Ut {
1738
+ class zt {
1734
1739
  frames = 0;
1735
1740
  lastLodLevel_Mesh = -1;
1736
1741
  lastLodLevel_Texture = -1;
@@ -1738,53 +1743,53 @@ class Ut {
1738
1743
  lastScreenspaceVolume = new A();
1739
1744
  lastCentrality = 0;
1740
1745
  }
1741
- function ze(i, t) {
1746
+ function Ee(i, t) {
1742
1747
  if (!(t < 0)) {
1743
1748
  if (Array.isArray(i)) {
1744
1749
  for (const e of i)
1745
- ze(e, t);
1750
+ Ee(e, t);
1746
1751
  return;
1747
1752
  }
1748
- "color" in i && i.color instanceof $e && (i.color.copy(zt(t, It)), i.needsUpdate = !0);
1753
+ "color" in i && i.color instanceof Be && (i.color.copy(Et(t, $t)), i.needsUpdate = !0);
1749
1754
  }
1750
1755
  }
1751
- function zt(i, t) {
1752
- const e = Math.max(0, Math.min(Re.length - 1, Math.floor(i)));
1753
- return t.setHex(Re[e]);
1756
+ function Et(i, t) {
1757
+ const e = Math.max(0, Math.min(Ce.length - 1, Math.floor(i)));
1758
+ return t.setHex(Ce[e]);
1754
1759
  }
1755
- const Ce = /* @__PURE__ */ Symbol("NEEDLE_mesh_lod"), ue = /* @__PURE__ */ Symbol("NEEDLE_texture_lod");
1760
+ const Ae = /* @__PURE__ */ Symbol("NEEDLE_mesh_lod"), ue = /* @__PURE__ */ Symbol("NEEDLE_texture_lod");
1756
1761
  let ye = null;
1757
- function Ee() {
1758
- const i = Et();
1762
+ function Ne() {
1763
+ const i = Nt();
1759
1764
  i && (i.mapURLs(function(t) {
1760
- return ke(), t;
1761
- }), ke(), ye?.disconnect(), ye = new MutationObserver((t) => {
1765
+ return Ie(), t;
1766
+ }), Ie(), ye?.disconnect(), ye = new MutationObserver((t) => {
1762
1767
  t.forEach((e) => {
1763
1768
  e.addedNodes.forEach((s) => {
1764
- s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && Ne(s);
1769
+ s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && Ve(s);
1765
1770
  });
1766
1771
  });
1767
1772
  }), ye.observe(document, { childList: !0, subtree: !0 }));
1768
1773
  }
1769
- function Et() {
1774
+ function Nt() {
1770
1775
  if (typeof customElements > "u") return null;
1771
1776
  const i = customElements.get("model-viewer");
1772
1777
  return i || (customElements.whenDefined("model-viewer").then(() => {
1773
- console.debug("[gltf-progressive] model-viewer defined"), Ee();
1778
+ console.debug("[gltf-progressive] model-viewer defined"), Ne();
1774
1779
  }), null);
1775
1780
  }
1776
- function ke() {
1781
+ function Ie() {
1777
1782
  if (typeof document > "u") return;
1778
1783
  document.querySelectorAll("model-viewer").forEach((t) => {
1779
- Ne(t);
1784
+ Ve(t);
1780
1785
  });
1781
1786
  }
1782
- const Ae = /* @__PURE__ */ new WeakSet();
1783
- let Nt = 0;
1784
- function Ne(i) {
1785
- if (!i || Ae.has(i))
1787
+ const $e = /* @__PURE__ */ new WeakSet();
1788
+ let Vt = 0;
1789
+ function Ve(i) {
1790
+ if (!i || $e.has(i))
1786
1791
  return null;
1787
- Ae.add(i), console.debug("[gltf-progressive] found new model-viewer..." + ++Nt + `
1792
+ $e.add(i), console.debug("[gltf-progressive] found new model-viewer..." + ++Vt + `
1788
1793
  `, i.getAttribute("src"));
1789
1794
  let t = null, e = null, s = null;
1790
1795
  for (let r = i; r != null; r = Object.getPrototypeOf(r)) {
@@ -1806,7 +1811,7 @@ function Ne(i) {
1806
1811
  };
1807
1812
  console.debug("[gltf-progressive] setup model-viewer");
1808
1813
  const n = G.get(t, { engine: "model-viewer" });
1809
- return G.addPlugin(new Vt()), n.enable(), n.addEventListener("changed", () => {
1814
+ return G.addPlugin(new Xt()), n.enable(), n.addEventListener("changed", () => {
1810
1815
  s?.call(i);
1811
1816
  }), i.addEventListener("model-visibility", (o) => {
1812
1817
  o.detail.visible && s?.call(i);
@@ -1818,7 +1823,7 @@ function Ne(i) {
1818
1823
  }
1819
1824
  return null;
1820
1825
  }
1821
- class Vt {
1826
+ class Xt {
1822
1827
  _didWarnAboutMissingUrl = !1;
1823
1828
  onBeforeUpdateLOD(t, e, s, r) {
1824
1829
  this.tryParseMeshLOD(e, r), this.tryParseTextureLOD(e, r);
@@ -1844,10 +1849,10 @@ class Vt {
1844
1849
  if (a[ue] == !0) return;
1845
1850
  a[ue] = !0, a.userData && (a.userData.LOD = -1);
1846
1851
  const u = Object.keys(a);
1847
- for (let d = 0; d < u.length; d++) {
1848
- const c = u[d], f = a[c];
1849
- if (f?.isTexture === !0) {
1850
- const h = f.userData?.associations?.textures;
1852
+ for (let f = 0; f < u.length; f++) {
1853
+ const c = u[f], d = a[c];
1854
+ if (d?.isTexture === !0) {
1855
+ const h = d.userData?.associations?.textures;
1851
1856
  if (h == null) continue;
1852
1857
  const D = s.parser.json.textures[h];
1853
1858
  if (!D) {
@@ -1855,8 +1860,8 @@ class Vt {
1855
1860
  continue;
1856
1861
  }
1857
1862
  if (D?.extensions?.[z]) {
1858
- const w = D.extensions[z];
1859
- w && n && p.registerTexture(n, f, w.lods.length, h, w);
1863
+ const L = D.extensions[z];
1864
+ L && n && p.registerTexture(n, d, L.lods.length, h, L);
1860
1865
  }
1861
1866
  }
1862
1867
  }
@@ -1867,8 +1872,8 @@ class Vt {
1867
1872
  }
1868
1873
  }
1869
1874
  tryParseMeshLOD(t, e) {
1870
- if (e[Ce] == !0) return;
1871
- e[Ce] = !0;
1875
+ if (e[Ae] == !0) return;
1876
+ e[Ae] = !0;
1872
1877
  const s = this.tryGetCurrentModelViewer(t), r = this.getUrl(s);
1873
1878
  if (!r)
1874
1879
  return;
@@ -1879,7 +1884,7 @@ class Vt {
1879
1884
  }
1880
1885
  }
1881
1886
  }
1882
- function Xt(...i) {
1887
+ function jt(...i) {
1883
1888
  let t, e, s, r;
1884
1889
  switch (i.length) {
1885
1890
  case 2:
@@ -1894,22 +1899,22 @@ function Xt(...i) {
1894
1899
  default:
1895
1900
  throw new Error("Invalid arguments");
1896
1901
  }
1897
- _e(e), Be(s), We(s, {
1902
+ _e(e), We(s), Fe(s, {
1898
1903
  progressive: !0,
1899
1904
  ...r?.hints
1900
1905
  }), s.register((o) => new p(o));
1901
1906
  const n = G.get(e);
1902
1907
  return r?.enableLODsManager !== !1 && n.enable(), n;
1903
1908
  }
1904
- Ee();
1905
- if (!Dt) {
1909
+ Ne();
1910
+ if (!Mt) {
1906
1911
  const i = {
1907
1912
  gltfProgressive: {
1908
- useNeedleProgressive: Xt,
1913
+ useNeedleProgressive: jt,
1909
1914
  LODsManager: G,
1910
- configureLoader: We,
1915
+ configureLoader: Fe,
1911
1916
  getRaycastMesh: ae,
1912
- useRaycastMeshes: _t
1917
+ useRaycastMeshes: bt
1913
1918
  }
1914
1919
  };
1915
1920
  if (!globalThis.Needle)
@@ -1922,18 +1927,19 @@ export {
1922
1927
  z as EXTENSION_NAME,
1923
1928
  G as LODsManager,
1924
1929
  p as NEEDLE_progressive,
1925
- lt as VERSION,
1926
- Be as addDracoAndKTX2Loaders,
1927
- Ft as calculateMeshLODLevel,
1928
- We as configureLoader,
1930
+ ut as VERSION,
1931
+ We as addDracoAndKTX2Loaders,
1932
+ Ut as calculateMeshLODLevel,
1933
+ Fe as configureLoader,
1929
1934
  _e as createLoaders,
1930
- zt as getLODColor,
1935
+ Zt as disposeLoaders,
1936
+ Et as getLODColor,
1931
1937
  ae as getRaycastMesh,
1932
- Re as lodDebugColors,
1933
- Ee as patchModelViewer,
1934
- Mt as registerRaycastMesh,
1935
- dt as setDracoDecoderLocation,
1936
- ht as setKTX2TranscoderLocation,
1937
- Xt as useNeedleProgressive,
1938
- _t as useRaycastMeshes
1938
+ Ce as lodDebugColors,
1939
+ Ne as patchModelViewer,
1940
+ _t as registerRaycastMesh,
1941
+ ht as setDracoDecoderLocation,
1942
+ gt as setKTX2TranscoderLocation,
1943
+ jt as useNeedleProgressive,
1944
+ bt as useRaycastMeshes
1939
1945
  };