@needle-tools/gltf-progressive 1.2.3-alpha.3 → 1.2.4-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,15 @@
1
1
  var ze = Object.defineProperty;
2
2
  var Ve = (a, t, e) => t in a ? ze(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
3
- var d = (a, t, e) => (Ve(a, typeof t != "symbol" ? t + "" : t, e), e), Se = (a, t, e) => {
3
+ var f = (a, t, e) => (Ve(a, typeof t != "symbol" ? t + "" : t, e), e), Se = (a, t, e) => {
4
4
  if (!t.has(a))
5
5
  throw TypeError("Cannot " + e);
6
6
  };
7
- var m = (a, t, e) => (Se(a, t, "read from private field"), e ? e.call(a) : t.get(a)), X = (a, t, e) => {
7
+ var x = (a, t, e) => (Se(a, t, "read from private field"), e ? e.call(a) : t.get(a)), X = (a, t, e) => {
8
8
  if (t.has(a))
9
9
  throw TypeError("Cannot add the same private member more than once");
10
10
  t instanceof WeakSet ? t.add(a) : t.set(a, e);
11
11
  }, F = (a, t, e, r) => (Se(a, t, "write to private field"), r ? r.call(a, e) : t.set(a, e), e);
12
- import { BufferGeometry as de, Mesh as J, Material as Ne, Texture as ee, TextureLoader as Ue, Matrix4 as be, Frustum as We, Clock as Ke, MeshStandardMaterial as qe, Sphere as Xe, Box3 as Te, Vector3 as N } from "three";
12
+ import { BufferGeometry as he, Mesh as H, Material as Ne, Texture as re, TextureLoader as Ue, Matrix4 as be, Frustum as We, Clock as Ke, MeshStandardMaterial as qe, Sphere as Xe, Box3 as Te, Vector3 as N } from "three";
13
13
  import { GLTFLoader as Ye } from "three/examples/jsm/loaders/GLTFLoader.js";
14
14
  import { MeshoptDecoder as He } from "three/examples/jsm/libs/meshopt_decoder.module.js";
15
15
  import { DRACOLoader as Je } from "three/examples/jsm/loaders/DRACOLoader.js";
@@ -17,22 +17,22 @@ import { KTX2Loader as Qe } from "three/examples/jsm/loaders/KTX2Loader.js";
17
17
  const Be = "";
18
18
  globalThis.GLTF_PROGRESSIVE_VERSION = Be;
19
19
  console.debug(`[gltf-progressive] version ${Be}`);
20
- let he = "https://www.gstatic.com/draco/versioned/decoders/1.4.1/", _e = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
21
- fetch(he + "draco_decoder.js", { method: "head" }).catch((a) => {
22
- he = "./include/draco/", _e = "./include/ktx2/";
20
+ let ge = "https://www.gstatic.com/draco/versioned/decoders/1.4.1/", _e = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
21
+ fetch(ge + "draco_decoder.js", { method: "head" }).catch((a) => {
22
+ ge = "./include/draco/", _e = "./include/ktx2/";
23
23
  });
24
24
  function gt(a) {
25
- he = a;
25
+ ge = a;
26
26
  }
27
27
  function pt(a) {
28
28
  _e = a;
29
29
  }
30
- let ie, De, oe;
30
+ let Q, de, Z;
31
31
  function ke(a) {
32
- ie || (ie = new Je(), ie.setDecoderPath(he), ie.setDecoderConfig({ type: "js" })), oe || (oe = new Qe(), oe.setTranscoderPath(_e)), De || (De = He), a ? oe.detectSupport(a) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
32
+ return Q || (Q = new Je(), Q.setDecoderPath(ge), Q.setDecoderConfig({ type: "js" })), Z || (Z = new Qe(), Z.setTranscoderPath(_e)), de || (de = He), a ? Z.detectSupport(a) : a !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: Q, ktx2Loader: Z, meshoptDecoder: de };
33
33
  }
34
34
  function Ie(a) {
35
- a.dracoLoader || a.setDRACOLoader(ie), a.ktx2Loader || a.setKTX2Loader(oe), a.meshoptDecoder || a.setMeshoptDecoder(De);
35
+ a.dracoLoader || a.setDRACOLoader(Q), a.ktx2Loader || a.setKTX2Loader(Z), a.meshoptDecoder || a.setMeshoptDecoder(de);
36
36
  }
37
37
  ae("debugprogressive");
38
38
  function ae(a) {
@@ -51,13 +51,13 @@ function Ze(a, t) {
51
51
  }
52
52
  return t;
53
53
  }
54
- let te;
54
+ let se;
55
55
  function je() {
56
- return te !== void 0 || (te = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), ae("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", te)), te;
56
+ return se !== void 0 || (se = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), ae("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", se)), se;
57
57
  }
58
58
  const we = Symbol("needle:raycast-mesh");
59
59
  function Oe(a) {
60
- return (a == null ? void 0 : a[we]) instanceof de ? a[we] : null;
60
+ return (a == null ? void 0 : a[we]) instanceof he ? a[we] : null;
61
61
  }
62
62
  function et(a, t) {
63
63
  if ((a.type === "Mesh" || a.type === "SkinnedMesh") && !Oe(a)) {
@@ -67,37 +67,37 @@ function et(a, t) {
67
67
  }
68
68
  function yt(a = !0) {
69
69
  if (a) {
70
- if (re)
70
+ if (ie)
71
71
  return;
72
- const t = re = J.prototype.raycast;
73
- J.prototype.raycast = function(e, r) {
72
+ const t = ie = H.prototype.raycast;
73
+ H.prototype.raycast = function(e, r) {
74
74
  const o = this, i = Oe(o);
75
75
  let s;
76
76
  i && o.isMesh && (s = o.geometry, o.geometry = i), t.call(this, e, r), s && (o.geometry = s);
77
77
  };
78
78
  } else {
79
- if (!re)
79
+ if (!ie)
80
80
  return;
81
- J.prototype.raycast = re, re = null;
81
+ H.prototype.raycast = ie, ie = null;
82
82
  }
83
83
  }
84
- let re = null;
84
+ let ie = null;
85
85
  function tt(a) {
86
- const t = new de();
86
+ const t = new he();
87
87
  for (const e in a.attributes)
88
88
  t.setAttribute(e, a.getAttribute(e));
89
89
  return t.setIndex(a.getIndex()), t;
90
90
  }
91
- const Y = new Array(), U = "NEEDLE_progressive", L = ae("debugprogressive"), xe = Symbol("needle-progressive-texture"), ne = /* @__PURE__ */ new Map(), ve = /* @__PURE__ */ new Set();
92
- if (L) {
91
+ const Y = new Array(), U = "NEEDLE_progressive", M = ae("debugprogressive"), Le = Symbol("needle-progressive-texture"), ne = /* @__PURE__ */ new Map(), ve = /* @__PURE__ */ new Set();
92
+ if (M) {
93
93
  let a = function() {
94
94
  t += 1, console.log("Toggle LOD level", t, ne), ne.forEach((o, i) => {
95
95
  for (const s of o.keys) {
96
96
  const n = i[s];
97
97
  if (n != null) {
98
98
  if (n.isBufferGeometry === !0) {
99
- const l = b.getMeshLODInformation(n), f = l ? Math.min(t, l.lods.length) : 0;
100
- i["DEBUG:LOD"] = t, b.assignMeshLOD(i, f), l && (e = Math.max(e, l.lods.length - 1));
99
+ const l = b.getMeshLODInformation(n), u = l ? Math.min(t, l.lods.length) : 0;
100
+ i["DEBUG:LOD"] = t, b.assignMeshLOD(i, u), l && (e = Math.max(e, l.lods.length - 1));
101
101
  } else if (i.isMaterial === !0) {
102
102
  i["DEBUG:LOD"] = t, b.assignTextureLOD(i, t);
103
103
  break;
@@ -114,7 +114,7 @@ if (L) {
114
114
  }
115
115
  function Ae(a, t, e) {
116
116
  var o;
117
- if (!L)
117
+ if (!M)
118
118
  return;
119
119
  ne.has(a) || ne.set(a, { keys: [], sourceId: e });
120
120
  const r = ne.get(a);
@@ -122,10 +122,10 @@ function Ae(a, t, e) {
122
122
  }
123
123
  const _ = class {
124
124
  constructor(t, e) {
125
- d(this, "parser");
126
- d(this, "url");
127
- d(this, "_isLoadingMesh");
128
- d(this, "loadMesh", (t) => {
125
+ f(this, "parser");
126
+ f(this, "url");
127
+ f(this, "_isLoadingMesh");
128
+ f(this, "loadMesh", (t) => {
129
129
  var r, o;
130
130
  if (this._isLoadingMesh)
131
131
  return null;
@@ -135,7 +135,7 @@ const _ = class {
135
135
  return this._isLoadingMesh = !1, i && _.registerMesh(this.url, e.guid, i, (s = e.lods) == null ? void 0 : s.length, void 0, e), i;
136
136
  })) : null;
137
137
  });
138
- L && console.log("Progressive extension registered for", e), this.parser = t, this.url = e;
138
+ M && console.log("Progressive extension registered for", e), this.parser = t, this.url = e;
139
139
  }
140
140
  /** The name of the extension */
141
141
  get name() {
@@ -158,11 +158,11 @@ const _ = class {
158
158
  this.getMaterialMinMaxLODsCount(n, e);
159
159
  return t[o] = e, e;
160
160
  }
161
- if (L === "verbose" && console.log("getMaterialMinMaxLODsCount", t), t.type === "ShaderMaterial" || t.type === "RawShaderMaterial") {
161
+ if (M === "verbose" && console.log("getMaterialMinMaxLODsCount", t), t.type === "ShaderMaterial" || t.type === "RawShaderMaterial") {
162
162
  const n = t;
163
163
  for (const l of Object.keys(n.uniforms)) {
164
- const f = n.uniforms[l].value;
165
- (f == null ? void 0 : f.isTexture) === !0 && s(f, e);
164
+ const u = n.uniforms[l].value;
165
+ (u == null ? void 0 : u.isTexture) === !0 && s(u, e);
166
166
  }
167
167
  } else if (t.isMaterial)
168
168
  for (const n of Object.keys(t)) {
@@ -171,14 +171,14 @@ const _ = class {
171
171
  }
172
172
  return t[o] = e, e;
173
173
  function s(n, l) {
174
- const f = r.getAssignedLODInformation(n);
175
- if (f) {
176
- const c = r.lodInfos.get(f.key);
174
+ const u = r.getAssignedLODInformation(n);
175
+ if (u) {
176
+ const c = r.lodInfos.get(u.key);
177
177
  if (c && c.lods) {
178
178
  l.min_count = Math.min(l.min_count, c.lods.length), l.max_count = Math.max(l.max_count, c.lods.length);
179
- for (let M = 0; M < c.lods.length; M++) {
180
- const u = c.lods[M];
181
- u.width && (l.lods[M] = l.lods[M] || { min_height: 1 / 0, max_height: 0 }, l.lods[M].min_height = Math.min(l.lods[M].min_height, u.height), l.lods[M].max_height = Math.max(l.lods[M].max_height, u.height));
179
+ for (let D = 0; D < c.lods.length; D++) {
180
+ const h = c.lods[D];
181
+ h.width && (l.lods[D] = l.lods[D] || { min_height: 1 / 0, max_height: 0 }, l.lods[D].min_height = Math.min(l.lods[D].min_height, h.height), l.lods[D].max_height = Math.max(l.lods[D].max_height, h.height));
182
182
  }
183
183
  }
184
184
  }
@@ -237,7 +237,7 @@ const _ = class {
237
237
  var r;
238
238
  if (!t)
239
239
  return Promise.resolve(null);
240
- if (t instanceof J || t.isMesh === !0) {
240
+ if (t instanceof H || t.isMesh === !0) {
241
241
  const o = t.geometry, i = this.getAssignedLODInformation(o);
242
242
  if (!i)
243
243
  return Promise.resolve(null);
@@ -249,12 +249,12 @@ const _ = class {
249
249
  const n = i.index || 0;
250
250
  s = s[n];
251
251
  }
252
- s && o != s && ((s == null ? void 0 : s.isBufferGeometry) ? (t.geometry = s, L && Ae(t, "geometry", i.url)) : L && console.error("Invalid LOD geometry", s));
252
+ s && o != s && ((s == null ? void 0 : s.isBufferGeometry) ? (t.geometry = s, M && Ae(t, "geometry", i.url)) : M && console.error("Invalid LOD geometry", s));
253
253
  }
254
254
  return s;
255
255
  }).catch((s) => (console.error("Error loading mesh LOD", t, s), null));
256
256
  } else
257
- L && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", t);
257
+ M && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", t);
258
258
  return Promise.resolve(null);
259
259
  }
260
260
  /** Load a different resolution of a texture (if available)
@@ -269,13 +269,13 @@ const _ = class {
269
269
  return Promise.resolve(null);
270
270
  if (t instanceof Ne || t.isMaterial === !0) {
271
271
  const r = t, o = [], i = new Array();
272
- if (L && ve.add(r), r.uniforms && r.isRawShaderMaterial || r.isShaderMaterial === !0) {
272
+ if (M && ve.add(r), r.uniforms && r.isRawShaderMaterial || r.isShaderMaterial === !0) {
273
273
  const s = r;
274
274
  for (const n of Object.keys(s.uniforms)) {
275
275
  const l = s.uniforms[n].value;
276
276
  if ((l == null ? void 0 : l.isTexture) === !0) {
277
- const f = this.assignTextureLODForSlot(l, e, r, n);
278
- o.push(f), i.push(n);
277
+ const u = this.assignTextureLODForSlot(l, e, r, n);
278
+ o.push(u), i.push(n);
279
279
  }
280
280
  }
281
281
  } else
@@ -289,13 +289,13 @@ const _ = class {
289
289
  return Promise.all(o).then((s) => {
290
290
  const n = new Array();
291
291
  for (let l = 0; l < s.length; l++) {
292
- const f = s[l], c = i[l];
293
- f && f.isTexture === !0 ? n.push({ material: r, slot: c, texture: f, level: e }) : n.push({ material: r, slot: c, texture: null, level: e });
292
+ const u = s[l], c = i[l];
293
+ u && u.isTexture === !0 ? n.push({ material: r, slot: c, texture: u, level: e }) : n.push({ material: r, slot: c, texture: null, level: e });
294
294
  }
295
295
  return n;
296
296
  });
297
297
  }
298
- if (t instanceof ee || t.isTexture === !0) {
298
+ if (t instanceof re || t.isTexture === !0) {
299
299
  const r = t;
300
300
  return this.assignTextureLODForSlot(r, e, null, null);
301
301
  }
@@ -312,41 +312,41 @@ const _ = class {
312
312
  if (s) {
313
313
  const n = this.getAssignedLODInformation(s);
314
314
  if (n && (n == null ? void 0 : n.level) < e)
315
- return L === "verbose" && console.warn("Assigned texture level is already higher: ", n.level, e, r, s, i), null;
315
+ return M === "verbose" && console.warn("Assigned texture level is already higher: ", n.level, e, r, s, i), null;
316
316
  }
317
317
  r[o] = i;
318
318
  }
319
- if (L && o && r) {
319
+ if (M && o && r) {
320
320
  const s = this.getAssignedLODInformation(t);
321
321
  s && Ae(r, o, s.url);
322
322
  }
323
323
  }
324
324
  return i;
325
325
  } else
326
- L == "verbose" && console.warn("No LOD found for", t, e);
326
+ M == "verbose" && console.warn("No LOD found for", t, e);
327
327
  return null;
328
328
  }).catch((i) => (console.error("Error loading LOD", t, i), null));
329
329
  }
330
330
  afterRoot(t) {
331
331
  var e, r;
332
- return L && console.log("AFTER", this.url, t), (e = this.parser.json.textures) == null || e.forEach((o, i) => {
332
+ return M && console.log("AFTER", this.url, t), (e = this.parser.json.textures) == null || e.forEach((o, i) => {
333
333
  var s;
334
334
  if (o != null && o.extensions) {
335
335
  const n = o == null ? void 0 : o.extensions[U];
336
336
  if (n) {
337
337
  if (!n.lods) {
338
- L && console.warn("Texture has no LODs", n);
338
+ M && console.warn("Texture has no LODs", n);
339
339
  return;
340
340
  }
341
341
  let l = !1;
342
- for (const f of this.parser.associations.keys())
343
- if (f.isTexture === !0) {
344
- const c = this.parser.associations.get(f);
345
- (c == null ? void 0 : c.textures) === i && (l = !0, _.registerTexture(this.url, f, (s = n.lods) == null ? void 0 : s.length, i, n));
342
+ for (const u of this.parser.associations.keys())
343
+ if (u.isTexture === !0) {
344
+ const c = this.parser.associations.get(u);
345
+ (c == null ? void 0 : c.textures) === i && (l = !0, _.registerTexture(this.url, u, (s = n.lods) == null ? void 0 : s.length, i, n));
346
346
  }
347
- l || this.parser.getDependency("texture", i).then((f) => {
347
+ l || this.parser.getDependency("texture", i).then((u) => {
348
348
  var c;
349
- f && _.registerTexture(this.url, f, (c = n.lods) == null ? void 0 : c.length, i, n);
349
+ u && _.registerTexture(this.url, u, (c = n.lods) == null ? void 0 : c.length, i, n);
350
350
  });
351
351
  }
352
352
  }
@@ -364,59 +364,59 @@ const _ = class {
364
364
  }), null;
365
365
  }
366
366
  static async getOrLoadLOD(t, e) {
367
- var n, l, f, c;
368
- const r = L == "verbose", o = t.userData.LODS;
367
+ var n, l, u, c;
368
+ const r = M == "verbose", o = t.userData.LODS;
369
369
  if (!o)
370
370
  return null;
371
371
  const i = o == null ? void 0 : o.key;
372
372
  let s;
373
373
  if (t.isTexture === !0) {
374
- const M = t;
375
- M.source && M.source[xe] && (s = M.source[xe]);
374
+ const D = t;
375
+ D.source && D.source[Le] && (s = D.source[Le]);
376
376
  }
377
377
  if (s || (s = _.lodInfos.get(i)), s) {
378
378
  if (e > 0) {
379
- let y = !1;
380
- const v = Array.isArray(s.lods);
381
- if (v && e >= s.lods.length ? y = !0 : v || (y = !0), y)
379
+ let d = !1;
380
+ const p = Array.isArray(s.lods);
381
+ if (p && e >= s.lods.length ? d = !0 : p || (d = !0), d)
382
382
  return this.lowresCache.get(i);
383
383
  }
384
- const M = Array.isArray(s.lods) ? (n = s.lods[e]) == null ? void 0 : n.path : s.lods;
385
- if (!M)
386
- return L && !s["missing:uri"] && (s["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, s)), null;
387
- const u = Ze(o.url, M);
388
- if (u.endsWith(".glb") || u.endsWith(".gltf")) {
384
+ const D = Array.isArray(s.lods) ? (n = s.lods[e]) == null ? void 0 : n.path : s.lods;
385
+ if (!D)
386
+ return M && !s["missing:uri"] && (s["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, s)), null;
387
+ const h = Ze(o.url, D);
388
+ if (h.endsWith(".glb") || h.endsWith(".gltf")) {
389
389
  if (!s.guid)
390
390
  return console.warn("missing pointer for glb/gltf texture", s), null;
391
- const y = u + "_" + s.guid, v = this.previouslyLoaded.get(y);
392
- if (v !== void 0) {
393
- r && console.log(`LOD ${e} was already loading/loaded: ${y}`);
394
- let p = await v.catch((z) => (console.error(`Error loading LOD ${e} from ${u}
395
- `, z), null)), D = !1;
396
- if (p == null || (p instanceof ee && t instanceof ee ? (l = p.image) != null && l.data || (f = p.source) != null && f.data ? p = this.copySettings(t, p) : (D = !0, this.previouslyLoaded.delete(y)) : p instanceof de && t instanceof de && ((c = p.attributes.position) != null && c.array || (D = !0, this.previouslyLoaded.delete(y)))), !D)
397
- return p;
391
+ const d = h + "_" + s.guid, p = this.previouslyLoaded.get(d);
392
+ if (p !== void 0) {
393
+ r && console.log(`LOD ${e} was already loading/loaded: ${d}`);
394
+ let m = await p.catch((z) => (console.error(`Error loading LOD ${e} from ${h}
395
+ `, z), null)), w = !1;
396
+ if (m == null || (m instanceof re && t instanceof re ? (l = m.image) != null && l.data || (u = m.source) != null && u.data ? m = this.copySettings(t, m) : (w = !0, this.previouslyLoaded.delete(d)) : m instanceof he && t instanceof he && ((c = m.attributes.position) != null && c.array || (w = !0, this.previouslyLoaded.delete(d)))), !w)
397
+ return m;
398
398
  }
399
- const x = s, G = new Promise(async (p, D) => {
399
+ const L = s, k = new Promise(async (m, w) => {
400
400
  const z = new Ye();
401
- Ie(z), L && (await new Promise((O) => setTimeout(O, 1e3)), r && console.warn("Start loading (delayed) " + u, x.guid));
402
- let q = u;
403
- if (x && Array.isArray(x.lods)) {
404
- const O = x.lods[e];
401
+ Ie(z), M && (await new Promise((O) => setTimeout(O, 1e3)), r && console.warn("Start loading (delayed) " + h, L.guid));
402
+ let q = h;
403
+ if (L && Array.isArray(L.lods)) {
404
+ const O = L.lods[e];
405
405
  O.hash && (q += "?v=" + O.hash);
406
406
  }
407
- const S = await z.loadAsync(q).catch((O) => (console.error(`Error loading LOD ${e} from ${u}
407
+ const S = await z.loadAsync(q).catch((O) => (console.error(`Error loading LOD ${e} from ${h}
408
408
  `, O), null));
409
409
  if (!S)
410
410
  return null;
411
411
  const V = S.parser;
412
- r && console.log("Loading finished " + u, x.guid);
412
+ r && console.log("Loading finished " + h, L.guid);
413
413
  let A = 0;
414
414
  if (S.parser.json.textures) {
415
415
  let O = !1;
416
- for (const g of S.parser.json.textures) {
417
- if (g != null && g.extensions) {
418
- const h = g == null ? void 0 : g.extensions[U];
419
- if (h != null && h.guid && h.guid === x.guid) {
416
+ for (const y of S.parser.json.textures) {
417
+ if (y != null && y.extensions) {
418
+ const g = y == null ? void 0 : y.extensions[U];
419
+ if (g != null && g.guid && g.guid === L.guid) {
420
420
  O = !0;
421
421
  break;
422
422
  }
@@ -424,17 +424,17 @@ const _ = class {
424
424
  A++;
425
425
  }
426
426
  if (O) {
427
- let g = await V.getDependency("texture", A);
428
- return g && _.assignLODInformation(o.url, g, i, e, void 0, void 0), r && console.log('change "' + t.name + '" → "' + g.name + '"', u, A, g, y), t instanceof ee && (g = this.copySettings(t, g)), g && (g.guid = x.guid), p(g);
427
+ let y = await V.getDependency("texture", A);
428
+ return y && _.assignLODInformation(o.url, y, i, e, void 0, void 0), r && console.log('change "' + t.name + '" → "' + y.name + '"', h, A, y, d), t instanceof re && (y = this.copySettings(t, y)), y && (y.guid = L.guid), m(y);
429
429
  } else
430
- L && console.warn("Could not find texture with guid", x.guid, S.parser.json);
430
+ M && console.warn("Could not find texture with guid", L.guid, S.parser.json);
431
431
  }
432
432
  if (A = 0, S.parser.json.meshes) {
433
433
  let O = !1;
434
- for (const g of S.parser.json.meshes) {
435
- if (g != null && g.extensions) {
436
- const h = g == null ? void 0 : g.extensions[U];
437
- if (h != null && h.guid && h.guid === x.guid) {
434
+ for (const y of S.parser.json.meshes) {
435
+ if (y != null && y.extensions) {
436
+ const g = y == null ? void 0 : y.extensions[U];
437
+ if (g != null && g.guid && g.guid === L.guid) {
438
438
  O = !0;
439
439
  break;
440
440
  }
@@ -442,34 +442,34 @@ const _ = class {
442
442
  A++;
443
443
  }
444
444
  if (O) {
445
- const g = await V.getDependency("mesh", A), h = x;
446
- if (r && console.log(`Loaded Mesh "${g.name}"`, u, A, g, y), g.isMesh === !0) {
447
- const w = g.geometry;
448
- return _.assignLODInformation(o.url, w, i, e, void 0, h.density), p(w);
445
+ const y = await V.getDependency("mesh", A), g = L;
446
+ if (r && console.log(`Loaded Mesh "${y.name}"`, h, A, y, d), y.isMesh === !0) {
447
+ const v = y.geometry;
448
+ return _.assignLODInformation(o.url, v, i, e, void 0, g.density), m(v);
449
449
  } else {
450
- const w = new Array();
451
- for (let T = 0; T < g.children.length; T++) {
452
- const P = g.children[T];
450
+ const v = new Array();
451
+ for (let T = 0; T < y.children.length; T++) {
452
+ const P = y.children[T];
453
453
  if (P.isMesh === !0) {
454
454
  const E = P.geometry;
455
- _.assignLODInformation(o.url, E, i, e, T, h.density), w.push(E);
455
+ _.assignLODInformation(o.url, E, i, e, T, g.density), v.push(E);
456
456
  }
457
457
  }
458
- return p(w);
458
+ return m(v);
459
459
  }
460
460
  } else
461
- L && console.warn("Could not find mesh with guid", x.guid, S.parser.json);
461
+ M && console.warn("Could not find mesh with guid", L.guid, S.parser.json);
462
462
  }
463
- return p(null);
463
+ return m(null);
464
464
  });
465
- return this.previouslyLoaded.set(y, G), await G;
466
- } else if (t instanceof ee) {
467
- r && console.log("Load texture from uri: " + u);
468
- const v = await new Ue().loadAsync(u);
469
- return v ? (v.guid = s.guid, v.flipY = !1, v.needsUpdate = !0, v.colorSpace = t.colorSpace, r && console.log(s, v)) : L && console.warn("failed loading", u), v;
465
+ return this.previouslyLoaded.set(d, k), await k;
466
+ } else if (t instanceof re) {
467
+ r && console.log("Load texture from uri: " + h);
468
+ const p = await new Ue().loadAsync(h);
469
+ return p ? (p.guid = s.guid, p.flipY = !1, p.needsUpdate = !0, p.colorSpace = t.colorSpace, r && console.log(s, p)) : M && console.warn("failed loading", h), p;
470
470
  }
471
471
  } else
472
- L && console.warn(`Can not load LOD ${e}: no LOD info found for "${i}" ${t.name}`, t.type);
472
+ M && console.warn(`Can not load LOD ${e}: no LOD info found for "${i}" ${t.name}`, t.type);
473
473
  return null;
474
474
  }
475
475
  static assignLODInformation(t, e, r, o, i, s) {
@@ -485,7 +485,7 @@ const _ = class {
485
485
  }
486
486
  // private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
487
487
  static copySettings(t, e) {
488
- return e = e.clone(), L && console.warn(`Copying texture settings
488
+ return e = e.clone(), M && console.warn(`Copying texture settings
489
489
  `, t.uuid, `
490
490
  `, e.uuid), 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;
491
491
  }
@@ -494,91 +494,91 @@ let b = _;
494
494
  /**
495
495
  * Register a texture with LOD information
496
496
  */
497
- d(b, "registerTexture", (t, e, r, o, i) => {
498
- if (L && console.log("> Progressive: register texture", o, e.name, e.uuid, e, i), !e) {
499
- L && console.error("gltf-progressive: Register texture without texture");
497
+ f(b, "registerTexture", (t, e, r, o, i) => {
498
+ if (M && console.log("> Progressive: register texture", o, e.name, e.uuid, e, i), !e) {
499
+ M && console.error("gltf-progressive: Register texture without texture");
500
500
  return;
501
501
  }
502
- e.source && (e.source[xe] = i);
502
+ e.source && (e.source[Le] = i);
503
503
  const s = i.guid;
504
504
  _.assignLODInformation(t, e, s, r, o, void 0), _.lodInfos.set(s, i), _.lowresCache.set(s, e);
505
505
  }), /**
506
506
  * Register a mesh with LOD information
507
507
  */
508
- d(b, "registerMesh", (t, e, r, o, i, s) => {
509
- var f;
510
- L && console.log("> Progressive: register mesh", i, r.name, s, r.uuid, r);
508
+ f(b, "registerMesh", (t, e, r, o, i, s) => {
509
+ var u;
510
+ M && console.log("> Progressive: register mesh", i, r.name, s, r.uuid, r);
511
511
  const n = r.geometry;
512
512
  if (!n) {
513
- L && console.warn("gltf-progressive: Register mesh without geometry");
513
+ M && console.warn("gltf-progressive: Register mesh without geometry");
514
514
  return;
515
515
  }
516
516
  n.userData || (n.userData = {}), _.assignLODInformation(t, n, e, o, i, s.density), _.lodInfos.set(e, s);
517
517
  let l = _.lowresCache.get(e);
518
518
  l ? l.push(r.geometry) : l = [r.geometry], _.lowresCache.set(e, l), o > 0 && !Oe(r) && et(r, n);
519
519
  for (const c of Y)
520
- (f = c.onRegisteredNewMesh) == null || f.call(c, r, s);
520
+ (u = c.onRegisteredNewMesh) == null || u.call(c, r, s);
521
521
  }), /** A map of key = asset uuid and value = LOD information */
522
- d(b, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
523
- d(b, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
524
- d(b, "lowresCache", /* @__PURE__ */ new Map());
522
+ f(b, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
523
+ f(b, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
524
+ f(b, "lowresCache", /* @__PURE__ */ new Map());
525
525
  class rt {
526
526
  constructor(t, e, r, o, i) {
527
- d(this, "url");
527
+ f(this, "url");
528
528
  /** the key to lookup the LOD information */
529
- d(this, "key");
530
- d(this, "level");
529
+ f(this, "key");
530
+ f(this, "level");
531
531
  /** For multi objects (e.g. a group of meshes) this is the index of the object */
532
- d(this, "index");
532
+ f(this, "index");
533
533
  /** the mesh density */
534
- d(this, "density");
534
+ f(this, "density");
535
535
  this.url = t, this.key = e, this.level = r, o != null && (this.index = o), i != null && (this.density = i);
536
536
  }
537
537
  }
538
- const k = ae("debugprogressive"), st = ae("noprogressive"), Le = Symbol("Needle:LODSManager"), Me = Symbol("Needle:LODState"), H = Symbol("Needle:CurrentLOD"), I = { mesh_lod: -1, texture_lod: -1 };
539
- var B, W, ge, Q, Z, pe, K;
538
+ const I = ae("debugprogressive"), st = ae("noprogressive"), Me = Symbol("Needle:LODSManager"), De = Symbol("Needle:LODState"), J = Symbol("Needle:CurrentLOD"), R = { mesh_lod: -1, texture_lod: -1 };
539
+ var B, W, pe, j, ee, ye, K;
540
540
  const C = class {
541
541
  // readonly plugins: NEEDLE_progressive_plugin[] = [];
542
542
  constructor(t, e) {
543
- d(this, "context");
544
- d(this, "renderer");
545
- d(this, "projectionScreenMatrix", new be());
546
- d(this, "cameraFrustrum", new We());
543
+ f(this, "context");
544
+ f(this, "renderer");
545
+ f(this, "projectionScreenMatrix", new be());
546
+ f(this, "cameraFrustrum", new We());
547
547
  /**
548
548
  * The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
549
549
  * @default 200_000
550
550
  */
551
- d(this, "targetTriangleDensity", 2e5);
551
+ f(this, "targetTriangleDensity", 2e5);
552
552
  /**
553
553
  * The update interval in frames. If set to 0, the LODs will be updated every frame. If set to 2, the LODs will be updated every second frame, etc.
554
554
  */
555
- d(this, "updateInterval", "auto");
555
+ f(this, "updateInterval", "auto");
556
556
  X(this, B, 1);
557
557
  /**
558
558
  * If set to true, the LODsManager will not update the LODs.
559
559
  */
560
- d(this, "pause", !1);
561
- d(this, "_lodchangedlisteners", []);
560
+ f(this, "pause", !1);
561
+ f(this, "_lodchangedlisteners", []);
562
562
  X(this, W, void 0);
563
- X(this, ge, new Ke());
564
- X(this, Q, 0);
565
- X(this, Z, 0);
566
- X(this, pe, 0);
563
+ X(this, pe, new Ke());
564
+ X(this, j, 0);
565
+ X(this, ee, 0);
566
+ X(this, ye, 0);
567
567
  X(this, K, 0);
568
- d(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
568
+ f(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
569
569
  // private testIfLODLevelsAreAvailable() {
570
- d(this, "_sphere", new Xe());
571
- d(this, "_tempBox", new Te());
572
- d(this, "_tempBox2", new Te());
573
- d(this, "tempMatrix", new be());
574
- d(this, "_tempWorldPosition", new N());
575
- d(this, "_tempBoxSize", new N());
576
- d(this, "_tempBox2Size", new N());
570
+ f(this, "_sphere", new Xe());
571
+ f(this, "_tempBox", new Te());
572
+ f(this, "_tempBox2", new Te());
573
+ f(this, "tempMatrix", new be());
574
+ f(this, "_tempWorldPosition", new N());
575
+ f(this, "_tempBoxSize", new N());
576
+ f(this, "_tempBox2Size", new N());
577
577
  this.renderer = t, this.context = { ...e };
578
578
  }
579
579
  /** @internal */
580
580
  static getObjectLODState(t) {
581
- return t[Me];
581
+ return t[De];
582
582
  }
583
583
  static addPlugin(t) {
584
584
  Y.push(t);
@@ -593,13 +593,13 @@ const C = class {
593
593
  * @returns The LODsManager instance.
594
594
  */
595
595
  static get(t, e) {
596
- if (t[Le])
597
- return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[Le];
596
+ if (t[Me])
597
+ return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[Me];
598
598
  const r = new C(t, {
599
599
  engine: "unknown",
600
600
  ...e
601
601
  });
602
- return t[Le] = r, r;
602
+ return t[Me] = r, r;
603
603
  }
604
604
  /** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
605
605
  get plugins() {
@@ -612,25 +612,25 @@ const C = class {
612
612
  * Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
613
613
  */
614
614
  enable() {
615
- if (m(this, W))
615
+ if (x(this, W))
616
616
  return;
617
617
  console.debug("[gltf-progressive] Enabling LODsManager for renderer");
618
618
  let t = 0;
619
619
  F(this, W, this.renderer.render);
620
620
  const e = this;
621
621
  ke(this.renderer), this.renderer.render = function(r, o) {
622
- e.renderer.getRenderTarget() == null && (t = 0, F(e, Q, m(e, Q) + 1), F(e, Z, m(e, ge).getDelta()), F(e, pe, m(e, pe) + m(e, Z)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / m(e, Z)), F(e, K, e._fpsBuffer.reduce((l, f) => l + f) / e._fpsBuffer.length), k && m(e, Q) % 30 === 0 && console.log("FPS", Math.round(m(e, K)), "Interval:", m(e, B)));
623
- const s = m(e, Q), n = t++;
624
- e.onBeforeRender(r, o, n, s), m(e, W).call(this, r, o), e.onAfterRender(r, o, n, s);
622
+ e.renderer.getRenderTarget() == null && (t = 0, F(e, j, x(e, j) + 1), F(e, ee, x(e, pe).getDelta()), F(e, ye, x(e, ye) + x(e, ee)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / x(e, ee)), F(e, K, e._fpsBuffer.reduce((l, u) => l + u) / e._fpsBuffer.length), I && x(e, j) % 30 === 0 && console.log("FPS", Math.round(x(e, K)), "Interval:", x(e, B)));
623
+ const s = x(e, j), n = t++;
624
+ e.onBeforeRender(r, o, n, s), x(e, W).call(this, r, o), e.onAfterRender(r, o, n, s);
625
625
  };
626
626
  }
627
627
  disable() {
628
- m(this, W) && (this.renderer.render = m(this, W), F(this, W, void 0));
628
+ x(this, W) && (this.renderer.render = x(this, W), F(this, W, void 0));
629
629
  }
630
630
  onBeforeRender(t, e, r, o) {
631
631
  }
632
632
  onAfterRender(t, e, r, o) {
633
- var l, f;
633
+ var l, u;
634
634
  if (this.pause)
635
635
  return;
636
636
  const i = this.renderer.renderLists.get(t, 0), s = i.opaque;
@@ -640,16 +640,16 @@ const C = class {
640
640
  (c.name === "EffectMaterial" || c.name === "CopyShader") && (n = !1);
641
641
  }
642
642
  if ((e.parent && e.parent.type === "CubeCamera" || r >= 1 && e.type === "OrthographicCamera") && (n = !1), n) {
643
- if (st || (this.updateInterval === "auto" ? m(this, K) < 40 && m(this, B) < 10 ? (F(this, B, m(this, B) + 1), k && console.warn("↓ Reducing LOD updates", m(this, B), m(this, K).toFixed(0))) : m(this, K) >= 60 && m(this, B) > 1 && (F(this, B, m(this, B) - 1), k && console.warn("↑ Increasing LOD updates", m(this, B), m(this, K).toFixed(0))) : F(this, B, this.updateInterval), m(this, B) > 0 && o % m(this, B) != 0))
643
+ if (st || (this.updateInterval === "auto" ? x(this, K) < 40 && x(this, B) < 10 ? (F(this, B, x(this, B) + 1), I && console.warn("↓ Reducing LOD updates", x(this, B), x(this, K).toFixed(0))) : x(this, K) >= 60 && x(this, B) > 1 && (F(this, B, x(this, B) - 1), I && console.warn("↑ Increasing LOD updates", x(this, B), x(this, K).toFixed(0))) : F(this, B, this.updateInterval), x(this, B) > 0 && o % x(this, B) != 0))
644
644
  return;
645
645
  this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix, e.matrixWorldInverse), this.cameraFrustrum.setFromProjectionMatrix(this.projectionScreenMatrix, this.renderer.coordinateSystem);
646
646
  const c = this.targetTriangleDensity;
647
- for (const u of s) {
648
- if (u.material && (((l = u.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((f = u.geometry) == null ? void 0 : f.type) === "BufferGeometry") && (u.material.name === "SphericalGaussianBlur" || u.material.name == "BackgroundCubeMaterial" || u.material.name === "CubemapFromEquirect" || u.material.name === "EquirectangularToCubeUV")) {
649
- 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)));
647
+ for (const d of s) {
648
+ if (d.material && (((l = d.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((u = d.geometry) == null ? void 0 : u.type) === "BufferGeometry") && (d.material.name === "SphericalGaussianBlur" || d.material.name == "BackgroundCubeMaterial" || d.material.name === "CubemapFromEquirect" || d.material.name === "EquirectangularToCubeUV")) {
649
+ I && (d.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (d.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", d, d.material.name, d.material.type)));
650
650
  continue;
651
651
  }
652
- switch (u.material.type) {
652
+ switch (d.material.type) {
653
653
  case "LineBasicMaterial":
654
654
  case "LineDashedMaterial":
655
655
  case "PointsMaterial":
@@ -658,39 +658,44 @@ const C = class {
658
658
  case "MeshDepthMaterial":
659
659
  continue;
660
660
  }
661
- if (k === "color" && u.material && !u.object.progressive_debug_color) {
662
- u.object.progressive_debug_color = !0;
663
- const v = Math.random() * 16777215, x = new qe({ color: v });
664
- u.object.material = x;
661
+ if (I === "color" && d.material && !d.object.progressive_debug_color) {
662
+ d.object.progressive_debug_color = !0;
663
+ const L = Math.random() * 16777215, k = new qe({ color: L });
664
+ d.object.material = k;
665
665
  }
666
- const y = u.object;
667
- (y instanceof J || y.isMesh) && this.updateLODs(t, e, y, c, o);
666
+ const p = d.object;
667
+ (p instanceof H || p.isMesh) && this.updateLODs(t, e, p, c, o);
668
668
  }
669
- const M = i.transparent;
670
- for (const u of M) {
671
- const y = u.object;
672
- (y instanceof J || y.isMesh) && this.updateLODs(t, e, y, c, o);
669
+ const D = i.transparent;
670
+ for (const d of D) {
671
+ const p = d.object;
672
+ (p instanceof H || p.isMesh) && this.updateLODs(t, e, p, c, o);
673
+ }
674
+ const h = i.transmissive;
675
+ for (const d of h) {
676
+ const p = d.object;
677
+ (p instanceof H || p.isMesh) && this.updateLODs(t, e, p, c, o);
673
678
  }
674
679
  }
675
680
  }
676
681
  /** Update the LOD levels for the renderer. */
677
682
  updateLODs(t, e, r, o, i) {
678
- var l, f;
683
+ var l, u;
679
684
  r.userData || (r.userData = {});
680
- let s = r[Me];
681
- if (s || (s = new it(), r[Me] = s), s.frames++ < 2)
685
+ let s = r[De];
686
+ if (s || (s = new it(), r[De] = s), s.frames++ < 2)
682
687
  return;
683
688
  for (const c of Y)
684
689
  (l = c.onBeforeUpdateLOD) == null || l.call(c, this.renderer, t, e, r);
685
- this.calculateLodLevel(e, r, s, o, I), I.mesh_lod = Math.round(I.mesh_lod), I.texture_lod = Math.round(I.texture_lod), I.mesh_lod >= 0 && this.loadProgressiveMeshes(r, I.mesh_lod);
686
- let n = I.texture_lod;
690
+ this.calculateLodLevel(e, r, s, o, R), R.mesh_lod = Math.round(R.mesh_lod), R.texture_lod = Math.round(R.texture_lod), R.mesh_lod >= 0 && this.loadProgressiveMeshes(r, R.mesh_lod);
691
+ let n = R.texture_lod;
687
692
  if (r.material && n >= 0) {
688
693
  const c = r["DEBUG:LOD"];
689
694
  c != null && (n = c), this.loadProgressiveTextures(r.material, n);
690
695
  }
691
696
  for (const c of Y)
692
- (f = c.onAfterUpdatedLOD) == null || f.call(c, this.renderer, t, e, r, I);
693
- s.lastLodLevel_Mesh = I.mesh_lod, s.lastLodLevel_Texture = I.texture_lod;
697
+ (u = c.onAfterUpdatedLOD) == null || u.call(c, this.renderer, t, e, r, R);
698
+ s.lastLodLevel_Mesh = R.mesh_lod, s.lastLodLevel_Texture = R.texture_lod;
694
699
  }
695
700
  /** Load progressive textures for the given material
696
701
  * @param material the material to load the textures for
@@ -706,7 +711,7 @@ const C = class {
706
711
  return;
707
712
  }
708
713
  let r = !1;
709
- (t[H] === void 0 || e < t[H]) && (r = !0), r && (t[H] = e, b.assignTextureLOD(t, e).then((o) => {
714
+ (t[J] === void 0 || e < t[J]) && (r = !0), r && (t[J] = e, b.assignTextureLOD(t, e).then((o) => {
710
715
  this._lodchangedlisteners.forEach((i) => i({ type: "texture", level: e, object: t }));
711
716
  }));
712
717
  }
@@ -719,10 +724,10 @@ const C = class {
719
724
  loadProgressiveMeshes(t, e) {
720
725
  if (!t)
721
726
  return Promise.resolve(null);
722
- if (t[H] !== e) {
723
- t[H] = e;
727
+ if (t[J] !== e) {
728
+ t[J] = e;
724
729
  const r = t.geometry;
725
- return b.assignMeshLOD(t, e).then((o) => (o && t[H] == e && r != t.geometry && this._lodchangedlisteners.forEach((i) => i({ type: "mesh", level: e, object: t })), o));
730
+ return b.assignMeshLOD(t, e).then((o) => (o && t[J] == e && r != t.geometry && this._lodchangedlisteners.forEach((i) => i({ type: "mesh", level: e, object: t })), o));
726
731
  }
727
732
  return Promise.resolve(null);
728
733
  }
@@ -731,7 +736,7 @@ const C = class {
731
736
  return this._tempPtInside.set(i, s, r.z).applyMatrix4(e).z < 0;
732
737
  }
733
738
  calculateLodLevel(t, e, r, o, i) {
734
- var G, $;
739
+ var k, $;
735
740
  if (!e) {
736
741
  i.mesh_lod = -1, i.texture_lod = -1;
737
742
  return;
@@ -741,92 +746,92 @@ const C = class {
741
746
  return;
742
747
  }
743
748
  let n = 10 + 1, l = !1;
744
- if (k && e["DEBUG:LOD"] != null)
749
+ if (I && e["DEBUG:LOD"] != null)
745
750
  return e["DEBUG:LOD"];
746
- const f = b.getMeshLODInformation(e.geometry), c = f == null ? void 0 : f.lods, M = c && c.length > 0, u = b.getMaterialMinMaxLODsCount(e.material), y = (u == null ? void 0 : u.min_count) != 1 / 0 && u.min_count > 0 && u.max_count > 0;
747
- if (!M && !y) {
751
+ const u = b.getMeshLODInformation(e.geometry), c = u == null ? void 0 : u.lods, D = c && c.length > 0, h = b.getMaterialMinMaxLODsCount(e.material), d = (h == null ? void 0 : h.min_count) != 1 / 0 && h.min_count > 0 && h.max_count > 0;
752
+ if (!D && !d) {
748
753
  i.mesh_lod = 0, i.texture_lod = 0;
749
754
  return;
750
755
  }
751
- if (M || (l = !0, n = 0), !((G = this.cameraFrustrum) != null && G.intersectsObject(e))) {
756
+ if (D || (l = !0, n = 0), !((k = this.cameraFrustrum) != null && k.intersectsObject(e))) {
752
757
  i.mesh_lod = 99, i.texture_lod = 99;
753
758
  return;
754
759
  }
755
- const v = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
756
- let x = e.geometry.boundingBox;
760
+ const p = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
761
+ let L = e.geometry.boundingBox;
757
762
  if (e.type === "SkinnedMesh") {
758
- const p = e;
759
- p.boundingBox || p.computeBoundingBox(), x = p.boundingBox;
763
+ const m = e;
764
+ m.boundingBox || m.computeBoundingBox(), L = m.boundingBox;
760
765
  }
761
- if (x && t.isPerspectiveCamera) {
762
- const p = t;
766
+ if (L && t.isPerspectiveCamera) {
767
+ const m = t;
763
768
  if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
764
769
  this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
765
- const h = t.getWorldPosition(this._tempWorldPosition);
766
- if (this._sphere.containsPoint(h)) {
770
+ const g = t.getWorldPosition(this._tempWorldPosition);
771
+ if (this._sphere.containsPoint(g)) {
767
772
  i.mesh_lod = 0, i.texture_lod = 0;
768
773
  return;
769
774
  }
770
775
  }
771
- if (this._tempBox.copy(x), this._tempBox.applyMatrix4(e.matrixWorld), C.isInside(this._tempBox, this.projectionScreenMatrix)) {
776
+ if (this._tempBox.copy(L), this._tempBox.applyMatrix4(e.matrixWorld), C.isInside(this._tempBox, this.projectionScreenMatrix)) {
772
777
  i.mesh_lod = 0, i.texture_lod = 0;
773
778
  return;
774
779
  }
775
- if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && p.fov > 70) {
776
- const h = this._tempBox.min, w = this._tempBox.max;
777
- let T = h.x, P = h.y, E = w.x, j = w.y;
778
- const le = 2, ye = 1.5, ce = (h.x + w.x) * 0.5, ue = (h.y + w.y) * 0.5;
779
- T = (T - ce) * le + ce, P = (P - ue) * le + ue, E = (E - ce) * le + ce, j = (j - ue) * le + ue;
780
- const Fe = T < 0 && E > 0 ? 0 : Math.min(Math.abs(h.x), Math.abs(w.x)), $e = P < 0 && j > 0 ? 0 : Math.min(Math.abs(h.y), Math.abs(w.y)), me = Math.max(Fe, $e);
781
- r.lastCentrality = (ye - me) * (ye - me) * (ye - me);
780
+ if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && m.fov > 70) {
781
+ const g = this._tempBox.min, v = this._tempBox.max;
782
+ let T = g.x, P = g.y, E = v.x, te = v.y;
783
+ const le = 2, me = 1.5, ce = (g.x + v.x) * 0.5, ue = (g.y + v.y) * 0.5;
784
+ T = (T - ce) * le + ce, P = (P - ue) * le + ue, E = (E - ce) * le + ce, te = (te - ue) * le + ue;
785
+ const Fe = T < 0 && E > 0 ? 0 : Math.min(Math.abs(g.x), Math.abs(v.x)), $e = P < 0 && te > 0 ? 0 : Math.min(Math.abs(g.y), Math.abs(v.y)), xe = Math.max(Fe, $e);
786
+ r.lastCentrality = (me - xe) * (me - xe) * (me - xe);
782
787
  } else
783
788
  r.lastCentrality = 1;
784
- const D = this._tempBox.getSize(this._tempBoxSize);
785
- D.multiplyScalar(0.5), screen.availHeight > 0 && v > 0 && D.multiplyScalar(v / screen.availHeight), D.x *= p.aspect;
789
+ const w = this._tempBox.getSize(this._tempBoxSize);
790
+ w.multiplyScalar(0.5), screen.availHeight > 0 && p > 0 && w.multiplyScalar(p / screen.availHeight), w.x *= m.aspect;
786
791
  const z = t.matrixWorldInverse, q = this._tempBox2;
787
- q.copy(x), q.applyMatrix4(e.matrixWorld), q.applyMatrix4(z);
792
+ q.copy(L), q.applyMatrix4(e.matrixWorld), q.applyMatrix4(z);
788
793
  const S = q.getSize(this._tempBox2Size), V = Math.max(S.x, S.y);
789
- if (Math.max(D.x, D.y) != 0 && V != 0 && (D.z = S.z / Math.max(S.x, S.y) * Math.max(D.x, D.y)), r.lastScreenCoverage = Math.max(D.x, D.y, D.z), r.lastScreenspaceVolume.copy(D), r.lastScreenCoverage *= r.lastCentrality, k && C.debugDrawLine) {
790
- const h = this.tempMatrix.copy(this.projectionScreenMatrix);
791
- h.invert();
792
- const w = C.corner0, T = C.corner1, P = C.corner2, E = C.corner3;
793
- w.copy(this._tempBox.min), T.copy(this._tempBox.max), T.x = w.x, P.copy(this._tempBox.max), P.y = w.y, E.copy(this._tempBox.max);
794
- const j = (w.z + E.z) * 0.5;
795
- w.z = T.z = P.z = E.z = j, w.applyMatrix4(h), T.applyMatrix4(h), P.applyMatrix4(h), E.applyMatrix4(h), C.debugDrawLine(w, T, 255), C.debugDrawLine(w, P, 255), C.debugDrawLine(T, E, 255), C.debugDrawLine(P, E, 255);
794
+ if (Math.max(w.x, w.y) != 0 && V != 0 && (w.z = S.z / Math.max(S.x, S.y) * Math.max(w.x, w.y)), r.lastScreenCoverage = Math.max(w.x, w.y, w.z), r.lastScreenspaceVolume.copy(w), r.lastScreenCoverage *= r.lastCentrality, I && C.debugDrawLine) {
795
+ const g = this.tempMatrix.copy(this.projectionScreenMatrix);
796
+ g.invert();
797
+ const v = C.corner0, T = C.corner1, P = C.corner2, E = C.corner3;
798
+ v.copy(this._tempBox.min), T.copy(this._tempBox.max), T.x = v.x, P.copy(this._tempBox.max), P.y = v.y, E.copy(this._tempBox.max);
799
+ const te = (v.z + E.z) * 0.5;
800
+ v.z = T.z = P.z = E.z = te, v.applyMatrix4(g), T.applyMatrix4(g), P.applyMatrix4(g), E.applyMatrix4(g), C.debugDrawLine(v, T, 255), C.debugDrawLine(v, P, 255), C.debugDrawLine(T, E, 255), C.debugDrawLine(P, E, 255);
796
801
  }
797
802
  let O = 999;
798
803
  if (c && r.lastScreenCoverage > 0) {
799
- for (let h = 0; h < c.length; h++)
800
- if (c[h].density / r.lastScreenCoverage < o) {
801
- O = h;
804
+ for (let g = 0; g < c.length; g++)
805
+ if (c[g].density / r.lastScreenCoverage < o) {
806
+ O = g;
802
807
  break;
803
808
  }
804
809
  }
805
810
  O < n && (n = O, l = !0);
806
811
  }
807
- if (l ? i.mesh_lod = n : i.mesh_lod = r.lastLodLevel_Mesh, k && i.mesh_lod != r.lastLodLevel_Mesh) {
808
- const D = c == null ? void 0 : c[i.mesh_lod];
809
- D && console.log(`Mesh LOD changed: ${r.lastLodLevel_Mesh} → ${i.mesh_lod} (${D.density.toFixed(0)}) - ${e.name}`);
812
+ if (l ? i.mesh_lod = n : i.mesh_lod = r.lastLodLevel_Mesh, I && i.mesh_lod != r.lastLodLevel_Mesh) {
813
+ const w = c == null ? void 0 : c[i.mesh_lod];
814
+ w && console.log(`Mesh LOD changed: ${r.lastLodLevel_Mesh} → ${i.mesh_lod} (${w.density.toFixed(0)}) - ${e.name}`);
810
815
  }
811
- if (y) {
812
- const p = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
816
+ if (d) {
817
+ const m = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
813
818
  if (r.lastLodLevel_Texture < 0) {
814
- if (i.texture_lod = u.max_count - 1, k) {
815
- const D = u.lods[u.max_count - 1];
816
- k && console.log(`First Texture LOD ${i.texture_lod} (${D.max_height}px) - ${e.name}`);
819
+ if (i.texture_lod = h.max_count - 1, I) {
820
+ const w = h.lods[h.max_count - 1];
821
+ I && console.log(`First Texture LOD ${i.texture_lod} (${w.max_height}px) - ${e.name}`);
817
822
  }
818
823
  } else {
819
- const D = r.lastScreenspaceVolume.x + r.lastScreenspaceVolume.y + r.lastScreenspaceVolume.z;
824
+ const w = r.lastScreenspaceVolume.x + r.lastScreenspaceVolume.y + r.lastScreenspaceVolume.z;
820
825
  let z = r.lastScreenCoverage * 2;
821
826
  (($ = this.context) == null ? void 0 : $.engine) === "model-viewer" && (z *= 2);
822
- const S = v / window.devicePixelRatio * z;
823
- for (let V = u.lods.length - 1; V >= 0; V--) {
824
- let A = u.lods[V];
825
- if (!(p && A.max_height >= 2048) && !(je() && A.max_height > 4096) && A.max_height > S) {
827
+ const S = p / window.devicePixelRatio * z;
828
+ for (let V = h.lods.length - 1; V >= 0; V--) {
829
+ let A = h.lods[V];
830
+ if (!(m && A.max_height >= 2048) && !(je() && A.max_height > 4096) && A.max_height > S) {
826
831
  if (i.texture_lod = V, i.texture_lod < r.lastLodLevel_Texture) {
827
832
  const O = A.max_height;
828
- k && console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} → ${i.texture_lod} = ${O}px
829
- Screensize: ${S.toFixed(0)}px, Coverage: ${(100 * r.lastScreenCoverage).toFixed(2)}%, Volume ${D.toFixed(1)}
833
+ I && console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} → ${i.texture_lod} = ${O}px
834
+ Screensize: ${S.toFixed(0)}px, Coverage: ${(100 * r.lastScreenCoverage).toFixed(2)}%, Volume ${w.toFixed(1)}
830
835
  ${e.name}`);
831
836
  }
832
837
  break;
@@ -837,33 +842,33 @@ ${e.name}`);
837
842
  i.texture_lod = 0;
838
843
  }
839
844
  };
840
- let R = C;
841
- B = new WeakMap(), W = new WeakMap(), ge = new WeakMap(), Q = new WeakMap(), Z = new WeakMap(), pe = new WeakMap(), K = new WeakMap(), /** 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.
845
+ let G = C;
846
+ B = new WeakMap(), W = new WeakMap(), pe = new WeakMap(), j = new WeakMap(), ee = new WeakMap(), ye = new WeakMap(), K = new WeakMap(), /** 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.
842
847
  */
843
- d(R, "debugDrawLine"), d(R, "corner0", new N()), d(R, "corner1", new N()), d(R, "corner2", new N()), d(R, "corner3", new N()), d(R, "_tempPtInside", new N());
848
+ f(G, "debugDrawLine"), f(G, "corner0", new N()), f(G, "corner1", new N()), f(G, "corner2", new N()), f(G, "corner3", new N()), f(G, "_tempPtInside", new N());
844
849
  class it {
845
850
  constructor() {
846
- d(this, "frames", 0);
847
- d(this, "lastLodLevel_Mesh", -1);
848
- d(this, "lastLodLevel_Texture", -1);
849
- d(this, "lastScreenCoverage", 0);
850
- d(this, "lastScreenspaceVolume", new N());
851
- d(this, "lastCentrality", 0);
851
+ f(this, "frames", 0);
852
+ f(this, "lastLodLevel_Mesh", -1);
853
+ f(this, "lastLodLevel_Texture", -1);
854
+ f(this, "lastScreenCoverage", 0);
855
+ f(this, "lastScreenspaceVolume", new N());
856
+ f(this, "lastCentrality", 0);
852
857
  }
853
858
  }
854
859
  const Pe = Symbol("NEEDLE_mesh_lod"), fe = Symbol("NEEDLE_texture_lod");
855
- let se = null;
860
+ let oe = null;
856
861
  function Re() {
857
862
  const a = ot();
858
863
  a && (a.mapURLs(function(t) {
859
864
  return Ee(), t;
860
- }), Ee(), se == null || se.disconnect(), se = new MutationObserver((t) => {
865
+ }), Ee(), oe == null || oe.disconnect(), oe = new MutationObserver((t) => {
861
866
  t.forEach((e) => {
862
867
  e.addedNodes.forEach((r) => {
863
868
  r instanceof HTMLElement && r.tagName.toLowerCase() === "model-viewer" && Ge(r);
864
869
  });
865
870
  });
866
- }), se.observe(document, { childList: !0, subtree: !0 }));
871
+ }), oe.observe(document, { childList: !0, subtree: !0 }));
867
872
  }
868
873
  function ot() {
869
874
  const a = customElements.get("model-viewer");
@@ -885,7 +890,7 @@ function Ge(a) {
885
890
  `, a.getAttribute("src"));
886
891
  let t = null, e = null, r = null;
887
892
  for (let o = a; o != null; o = Object.getPrototypeOf(o)) {
888
- const i = Object.getOwnPropertySymbols(o), s = i.find((f) => f.toString() == "Symbol(renderer)"), n = i.find((f) => f.toString() == "Symbol(scene)"), l = i.find((f) => f.toString() == "Symbol(needsRender)");
893
+ const i = Object.getOwnPropertySymbols(o), s = i.find((u) => u.toString() == "Symbol(renderer)"), n = i.find((u) => u.toString() == "Symbol(scene)"), l = i.find((u) => u.toString() == "Symbol(needsRender)");
889
894
  !t && s != null && (t = a[s].threeRenderer), !e && n != null && (e = a[n]), !r && l != null && (r = a[l]);
890
895
  }
891
896
  if (t && e) {
@@ -901,8 +906,8 @@ function Ge(a) {
901
906
  }
902
907
  };
903
908
  console.debug("[gltf-progressive] setup model-viewer");
904
- const i = R.get(t, { engine: "model-viewer" });
905
- return R.addPlugin(new at()), i.enable(), i.addEventListener("changed", () => {
909
+ const i = G.get(t, { engine: "model-viewer" });
910
+ return G.addPlugin(new at()), i.enable(), i.addEventListener("changed", () => {
906
911
  r == null || r.call(a);
907
912
  }), a.addEventListener("model-visibility", (s) => {
908
913
  s.detail.visible && (r == null || r.call(a));
@@ -916,7 +921,7 @@ function Ge(a) {
916
921
  }
917
922
  class at {
918
923
  constructor() {
919
- d(this, "_didWarnAboutMissingUrl", !1);
924
+ f(this, "_didWarnAboutMissingUrl", !1);
920
925
  }
921
926
  onBeforeUpdateLOD(t, e, r, o) {
922
927
  this.tryParseMeshLOD(e, o), this.tryParseTextureLOD(e, o);
@@ -940,25 +945,25 @@ class at {
940
945
  const r = this.tryGetCurrentGLTF(t), o = this.tryGetCurrentModelViewer(t), i = this.getUrl(o);
941
946
  if (i && r && e.material) {
942
947
  let s = function(l) {
943
- var c, M, u;
948
+ var c, D, h;
944
949
  if (l[fe] == !0)
945
950
  return;
946
951
  l[fe] = !0, l.userData && (l.userData.LOD = -1);
947
- const f = Object.keys(l);
948
- for (let y = 0; y < f.length; y++) {
949
- const v = f[y], x = l[v];
950
- if ((x == null ? void 0 : x.isTexture) === !0) {
951
- const G = (M = (c = x.userData) == null ? void 0 : c.associations) == null ? void 0 : M.textures;
952
- if (G == null)
952
+ const u = Object.keys(l);
953
+ for (let d = 0; d < u.length; d++) {
954
+ const p = u[d], L = l[p];
955
+ if ((L == null ? void 0 : L.isTexture) === !0) {
956
+ const k = (D = (c = L.userData) == null ? void 0 : c.associations) == null ? void 0 : D.textures;
957
+ if (k == null)
953
958
  continue;
954
- const $ = r.parser.json.textures[G];
959
+ const $ = r.parser.json.textures[k];
955
960
  if (!$) {
956
- console.warn("Texture data not found for texture index " + G);
961
+ console.warn("Texture data not found for texture index " + k);
957
962
  continue;
958
963
  }
959
- if ((u = $ == null ? void 0 : $.extensions) != null && u[U]) {
960
- const p = $.extensions[U];
961
- p && i && b.registerTexture(i, x, p.lods.length, G, p);
964
+ if ((h = $ == null ? void 0 : $.extensions) != null && h[U]) {
965
+ const m = $.extensions[U];
966
+ m && i && b.registerTexture(i, L, m.lods.length, k, m);
962
967
  }
963
968
  }
964
969
  }
@@ -988,13 +993,13 @@ class at {
988
993
  }
989
994
  function mt(a, t, e, r) {
990
995
  ke(t), Ie(e), e.register((i) => new b(i, a));
991
- const o = R.get(t);
996
+ const o = G.get(t);
992
997
  return (r == null ? void 0 : r.enableLODsManager) !== !1 && o.enable(), o;
993
998
  }
994
999
  Re();
995
1000
  export {
996
1001
  U as EXTENSION_NAME,
997
- R as LODsManager,
1002
+ G as LODsManager,
998
1003
  b as NEEDLE_progressive,
999
1004
  Be as VERSION,
1000
1005
  Ie as addDracoAndKTX2Loaders,