@needle-tools/gltf-progressive 1.2.3-alpha.2 → 1.2.3-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)), q = (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
- }, $ = (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 V } from "three";
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 H, 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";
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";
@@ -69,8 +69,8 @@ function yt(a = !0) {
69
69
  if (a) {
70
70
  if (re)
71
71
  return;
72
- const t = re = J.prototype.raycast;
73
- J.prototype.raycast = function(e, r) {
72
+ const t = re = 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);
@@ -78,7 +78,7 @@ function yt(a = !0) {
78
78
  } else {
79
79
  if (!re)
80
80
  return;
81
- J.prototype.raycast = re, re = null;
81
+ H.prototype.raycast = re, re = null;
82
82
  }
83
83
  }
84
84
  let re = null;
@@ -88,18 +88,18 @@ function tt(a) {
88
88
  t.setAttribute(e, a.getAttribute(e));
89
89
  return t.setIndex(a.getIndex()), t;
90
90
  }
91
- const X = new Array(), N = "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"), xe = 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 = S.getMeshLODInformation(n), f = l ? Math.min(t, l.lods.length) : 0;
100
- i["DEBUG:LOD"] = t, S.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
- i["DEBUG:LOD"] = t, S.assignTextureLOD(i, t);
102
+ i["DEBUG:LOD"] = t, b.assignTextureLOD(i, t);
103
103
  break;
104
104
  }
105
105
  }
@@ -114,32 +114,32 @@ 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);
121
121
  ((o = r == null ? void 0 : r.keys) == null ? void 0 : o.includes(t)) == !1 && r.keys.push(t);
122
122
  }
123
- const O = class {
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;
132
- const e = (o = (r = this.parser.json.meshes[t]) == null ? void 0 : r.extensions) == null ? void 0 : o[N];
132
+ const e = (o = (r = this.parser.json.meshes[t]) == null ? void 0 : r.extensions) == null ? void 0 : o[U];
133
133
  return e ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", t).then((i) => {
134
134
  var s;
135
- return this._isLoadingMesh = !1, i && O.registerMesh(this.url, e.guid, i, (s = e.lods) == null ? void 0 : s.length, void 0, e), i;
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() {
142
- return N;
142
+ return U;
143
143
  }
144
144
  static getMeshLODInformation(t) {
145
145
  const e = this.getAssignedLODInformation(t);
@@ -158,11 +158,11 @@ const O = 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 O = 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,24 +237,24 @@ const O = 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);
244
- for (const s of X)
244
+ for (const s of Y)
245
245
  (r = s.onBeforeGetLODMesh) == null || r.call(s, t, e);
246
- return t["LOD:requested level"] = e, O.getOrLoadLOD(o, e).then((s) => {
246
+ return t["LOD:requested level"] = e, _.getOrLoadLOD(o, e).then((s) => {
247
247
  if (t["LOD:requested level"] === e) {
248
248
  if (delete t["LOD:requested level"], Array.isArray(s)) {
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 O = 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,8 +289,8 @@ const O = 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
  });
@@ -302,7 +302,7 @@ const O = class {
302
302
  return Promise.resolve(null);
303
303
  }
304
304
  static assignTextureLODForSlot(t, e, r, o) {
305
- return (t == null ? void 0 : t.isTexture) !== !0 ? Promise.resolve(null) : o === "glyphMap" ? Promise.resolve(t) : O.getOrLoadLOD(t, e).then((i) => {
305
+ return (t == null ? void 0 : t.isTexture) !== !0 ? Promise.resolve(null) : o === "glyphMap" ? Promise.resolve(t) : _.getOrLoadLOD(t, e).then((i) => {
306
306
  if (Array.isArray(i))
307
307
  return null;
308
308
  if ((i == null ? void 0 : i.isTexture) === !0) {
@@ -312,164 +312,164 @@ const O = 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
- const n = o == null ? void 0 : o.extensions[N];
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, O.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 && O.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
  }
353
353
  }), (r = this.parser.json.meshes) == null || r.forEach((o, i) => {
354
354
  if (o != null && o.extensions) {
355
- const s = o == null ? void 0 : o.extensions[N];
355
+ const s = o == null ? void 0 : o.extensions[U];
356
356
  if (s && s.lods) {
357
357
  for (const n of this.parser.associations.keys())
358
358
  if (n.isMesh) {
359
359
  const l = this.parser.associations.get(n);
360
- (l == null ? void 0 : l.meshes) === i && O.registerMesh(this.url, s.guid, n, s.lods.length, l.primitives, s);
360
+ (l == null ? void 0 : l.meshes) === i && _.registerMesh(this.url, s.guid, n, s.lods.length, l.primitives, s);
361
361
  }
362
362
  }
363
363
  }
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[xe] && (s = D.source[xe]);
376
376
  }
377
- if (s || (s = O.lodInfos.get(i)), s) {
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((Y) => (console.error(`Error loading LOD ${e} from ${u}
395
- `, Y), 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 ee && t instanceof ee ? (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 de && t instanceof de && ((c = m.attributes.position) != null && c.array || (w = !0, this.previouslyLoaded.delete(d)))), !w)
397
+ return m;
398
398
  }
399
- const x = s, R = new Promise(async (p, D) => {
400
- const Y = new Ye();
401
- Ie(Y), L && (await new Promise((b) => setTimeout(b, 1e3)), r && console.warn("Start loading (delayed) " + u, x.guid));
402
- let G = u;
403
- if (x && Array.isArray(x.lods)) {
404
- const b = x.lods[e];
405
- b.hash && (G += "?v=" + b.hash);
399
+ const L = s, k = new Promise(async (m, w) => {
400
+ const z = new Ye();
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
+ O.hash && (q += "?v=" + O.hash);
406
406
  }
407
- const _ = await Y.loadAsync(G).catch((b) => (console.error(`Error loading LOD ${e} from ${u}
408
- `, b), null));
409
- if (!_)
407
+ const S = await z.loadAsync(q).catch((O) => (console.error(`Error loading LOD ${e} from ${h}
408
+ `, O), null));
409
+ if (!S)
410
410
  return null;
411
- const K = _.parser;
412
- r && console.log("Loading finished " + u, x.guid);
413
- let F = 0;
414
- if (_.parser.json.textures) {
415
- let b = !1;
416
- for (const g of _.parser.json.textures) {
417
- if (g != null && g.extensions) {
418
- const h = g == null ? void 0 : g.extensions[N];
419
- if (h != null && h.guid && h.guid === x.guid) {
420
- b = !0;
411
+ const V = S.parser;
412
+ r && console.log("Loading finished " + h, L.guid);
413
+ let A = 0;
414
+ if (S.parser.json.textures) {
415
+ let O = !1;
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
+ O = !0;
421
421
  break;
422
422
  }
423
423
  }
424
- F++;
424
+ A++;
425
425
  }
426
- if (b) {
427
- let g = await K.getDependency("texture", F);
428
- return g && O.assignLODInformation(o.url, g, i, e, void 0, void 0), r && console.log('change "' + t.name + '" → "' + g.name + '"', u, F, g, y), t instanceof ee && (g = this.copySettings(t, g)), g && (g.guid = x.guid), p(g);
426
+ if (O) {
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 ee && (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, _.parser.json);
430
+ M && console.warn("Could not find texture with guid", L.guid, S.parser.json);
431
431
  }
432
- if (F = 0, _.parser.json.meshes) {
433
- let b = !1;
434
- for (const g of _.parser.json.meshes) {
435
- if (g != null && g.extensions) {
436
- const h = g == null ? void 0 : g.extensions[N];
437
- if (h != null && h.guid && h.guid === x.guid) {
438
- b = !0;
432
+ if (A = 0, S.parser.json.meshes) {
433
+ let O = !1;
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
+ O = !0;
439
439
  break;
440
440
  }
441
441
  }
442
- F++;
442
+ A++;
443
443
  }
444
- if (b) {
445
- const g = await K.getDependency("mesh", F), h = x;
446
- if (r && console.log(`Loaded Mesh "${g.name}"`, u, F, g, y), g.isMesh === !0) {
447
- const w = g.geometry;
448
- return O.assignLODInformation(o.url, w, i, e, void 0, h.density), p(w);
444
+ if (O) {
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 A = g.children[T];
453
- if (A.isMesh === !0) {
454
- const P = A.geometry;
455
- O.assignLODInformation(o.url, P, i, e, T, h.density), w.push(P);
450
+ const v = new Array();
451
+ for (let T = 0; T < y.children.length; T++) {
452
+ const P = y.children[T];
453
+ if (P.isMesh === !0) {
454
+ const E = P.geometry;
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, _.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, R), await R;
465
+ return this.previouslyLoaded.set(d, k), await k;
466
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;
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,95 +485,95 @@ const O = 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
  }
492
492
  };
493
- let S = O;
493
+ let b = _;
494
494
  /**
495
495
  * Register a texture with LOD information
496
496
  */
497
- d(S, "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
502
  e.source && (e.source[xe] = i);
503
503
  const s = i.guid;
504
- O.assignLODInformation(t, e, s, r, o, void 0), O.lodInfos.set(s, i), O.lowresCache.set(s, e);
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(S, "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
- n.userData || (n.userData = {}), O.assignLODInformation(t, n, e, o, i, s.density), O.lodInfos.set(e, s);
517
- let l = O.lowresCache.get(e);
518
- l ? l.push(r.geometry) : l = [r.geometry], O.lowresCache.set(e, l), o > 0 && !Oe(r) && et(r, n);
519
- for (const c of X)
520
- (f = c.onRegisteredNewMesh) == null || f.call(c, r, s);
516
+ n.userData || (n.userData = {}), _.assignLODInformation(t, n, e, o, i, s.density), _.lodInfos.set(e, s);
517
+ let l = _.lowresCache.get(e);
518
+ l ? l.push(r.geometry) : l = [r.geometry], _.lowresCache.set(e, l), o > 0 && !Oe(r) && et(r, n);
519
+ for (const c of Y)
520
+ (u = c.onRegisteredNewMesh) == null || u.call(c, r, s);
521
521
  }), /** A map of key = asset uuid and value = LOD information */
522
- d(S, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
523
- d(S, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
524
- d(S, "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 B = ae("debugprogressive"), st = ae("noprogressive"), Le = Symbol("Needle:LODSManager"), Me = Symbol("Needle:LODState"), H = Symbol("Needle:CurrentLOD"), k = { mesh_lod: -1, texture_lod: -1 };
539
- var C, U, ge, Q, Z, pe, W;
540
- const E = class {
538
+ const I = ae("debugprogressive"), st = ae("noprogressive"), Le = Symbol("Needle:LODSManager"), Me = Symbol("Needle:LODState"), J = Symbol("Needle:CurrentLOD"), R = { mesh_lod: -1, texture_lod: -1 };
539
+ var B, W, ge, Q, Z, pe, K;
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");
556
- q(this, C, 1);
555
+ f(this, "updateInterval", "auto");
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", []);
562
- q(this, U, void 0);
563
- q(this, ge, new Ke());
564
- q(this, Q, 0);
565
- q(this, Z, 0);
566
- q(this, pe, 0);
567
- q(this, W, 0);
568
- d(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
560
+ f(this, "pause", !1);
561
+ f(this, "_lodchangedlisteners", []);
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);
567
+ X(this, K, 0);
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 V());
575
- d(this, "_tempBoxSize", new V());
576
- d(this, "_tempBox2Size", new V());
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 */
@@ -581,11 +581,11 @@ const E = class {
581
581
  return t[Me];
582
582
  }
583
583
  static addPlugin(t) {
584
- X.push(t);
584
+ Y.push(t);
585
585
  }
586
586
  static removePlugin(t) {
587
- const e = X.indexOf(t);
588
- e >= 0 && X.splice(e, 1);
587
+ const e = Y.indexOf(t);
588
+ e >= 0 && Y.splice(e, 1);
589
589
  }
590
590
  /**
591
591
  * Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
@@ -595,7 +595,7 @@ const E = class {
595
595
  static get(t, e) {
596
596
  if (t[Le])
597
597
  return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[Le];
598
- const r = new E(t, {
598
+ const r = new C(t, {
599
599
  engine: "unknown",
600
600
  ...e
601
601
  });
@@ -603,7 +603,7 @@ const E = class {
603
603
  }
604
604
  /** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
605
605
  get plugins() {
606
- return X;
606
+ return Y;
607
607
  }
608
608
  addEventListener(t, e) {
609
609
  t === "changed" && this._lodchangedlisteners.push(e);
@@ -612,25 +612,25 @@ const E = 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, U))
615
+ if (x(this, W))
616
616
  return;
617
617
  console.debug("[gltf-progressive] Enabling LODsManager for renderer");
618
618
  let t = 0;
619
- $(this, U, this.renderer.render);
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, $(e, Q, m(e, Q) + 1), $(e, Z, m(e, ge).getDelta()), $(e, pe, m(e, pe) + m(e, Z)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / m(e, Z)), $(e, W, e._fpsBuffer.reduce((l, f) => l + f) / e._fpsBuffer.length), B && m(e, Q) % 30 === 0 && console.log("FPS", Math.round(m(e, W)), "Interval:", m(e, C)));
623
- const s = m(e, Q), n = t++;
624
- e.onBeforeRender(r, o, n, s), m(e, U).call(this, r, o), e.onAfterRender(r, o, n, s);
622
+ e.renderer.getRenderTarget() == null && (t = 0, F(e, Q, x(e, Q) + 1), F(e, Z, x(e, ge).getDelta()), F(e, pe, x(e, pe) + x(e, Z)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / x(e, Z)), F(e, K, e._fpsBuffer.reduce((l, u) => l + u) / e._fpsBuffer.length), I && x(e, Q) % 30 === 0 && console.log("FPS", Math.round(x(e, K)), "Interval:", x(e, B)));
623
+ const s = x(e, Q), 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, U) && (this.renderer.render = m(this, U), $(this, U, 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 E = 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, W) < 40 && m(this, C) < 10 ? ($(this, C, m(this, C) + 1), B && console.warn("↓ Reducing LOD updates", m(this, C), m(this, W).toFixed(0))) : m(this, W) >= 80 && m(this, C) > 1 && ($(this, C, m(this, C) - 1), B && console.warn("↑ Increasing LOD updates", m(this, C), m(this, W).toFixed(0))) : $(this, C, this.updateInterval), m(this, C) > 0 && o % m(this, C) != 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
- B && (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 E = class {
658
658
  case "MeshDepthMaterial":
659
659
  continue;
660
660
  }
661
- if (B === "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
685
  let s = r[Me];
681
686
  if (s || (s = new it(), r[Me] = s), s.frames++ < 2)
682
687
  return;
683
- for (const c of X)
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, k), k.mesh_lod = Math.round(k.mesh_lod), k.texture_lod = Math.round(k.texture_lod), k.mesh_lod >= 0 && this.loadProgressiveMeshes(r, k.mesh_lod);
686
- let n = k.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
- for (const c of X)
692
- (f = c.onAfterUpdatedLOD) == null || f.call(c, this.renderer, t, e, r, k);
693
- s.lastLodLevel_Mesh = k.mesh_lod, s.lastLodLevel_Texture = k.texture_lod;
696
+ for (const c of Y)
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 E = 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, S.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 E = 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 S.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 E = 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 R, z;
739
+ var k, $;
735
740
  if (!e) {
736
741
  i.mesh_lod = -1, i.texture_lod = -1;
737
742
  return;
@@ -741,113 +746,114 @@ const E = class {
741
746
  return;
742
747
  }
743
748
  let n = 10 + 1, l = !1;
744
- if (B && e["DEBUG:LOD"] != null)
749
+ if (I && e["DEBUG:LOD"] != null)
745
750
  return e["DEBUG:LOD"];
746
- const f = S.getMeshLODInformation(e.geometry), c = f == null ? void 0 : f.lods, M = c && c.length > 0, u = S.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), !((R = this.cameraFrustrum) != null && R.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), E.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, A = h.y, P = 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, A = (A - ue) * le + ue, P = (P - ce) * le + ce, j = (j - ue) * le + ue;
780
- const Fe = T < 0 && P > 0 ? 0 : Math.min(Math.abs(h.x), Math.abs(w.x)), $e = A < 0 && j > 0 ? 0 : Math.min(Math.abs(h.y), Math.abs(w.y)), me = Math.max(Fe, $e);
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, j = v.y;
783
+ const le = 2, ye = 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, j = (j - ue) * le + ue;
785
+ const Fe = T < 0 && E > 0 ? 0 : Math.min(Math.abs(g.x), Math.abs(v.x)), $e = P < 0 && j > 0 ? 0 : Math.min(Math.abs(g.y), Math.abs(v.y)), me = Math.max(Fe, $e);
781
786
  r.lastCentrality = (ye - me) * (ye - me) * (ye - me);
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;
786
- const Y = t.matrixWorldInverse, G = this._tempBox2;
787
- G.copy(x), G.applyMatrix4(e.matrixWorld), G.applyMatrix4(Y);
788
- const _ = G.getSize(this._tempBox2Size), K = Math.max(_.x, _.y);
789
- if (Math.max(D.x, D.y) != 0 && K != 0 && (D.z = _.z / Math.max(_.x, _.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, B && E.debugDrawLine) {
790
- const h = this.tempMatrix.copy(this.projectionScreenMatrix);
791
- h.invert();
792
- const w = E.corner0, T = E.corner1, A = E.corner2, P = E.corner3;
793
- w.copy(this._tempBox.min), T.copy(this._tempBox.max), T.x = w.x, A.copy(this._tempBox.max), A.y = w.y, P.copy(this._tempBox.max);
794
- const j = (w.z + P.z) * 0.5;
795
- w.z = T.z = A.z = P.z = j, w.applyMatrix4(h), T.applyMatrix4(h), A.applyMatrix4(h), P.applyMatrix4(h), E.debugDrawLine(w, T, 255), E.debugDrawLine(w, A, 255), E.debugDrawLine(T, P, 255), E.debugDrawLine(A, P, 255);
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;
791
+ const z = t.matrixWorldInverse, q = this._tempBox2;
792
+ q.copy(L), q.applyMatrix4(e.matrixWorld), q.applyMatrix4(z);
793
+ const S = q.getSize(this._tempBox2Size), V = Math.max(S.x, S.y);
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 j = (v.z + E.z) * 0.5;
800
+ v.z = T.z = P.z = E.z = j, 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
- let b = 999;
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
- b = 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
- b < n && (n = b, l = !0);
810
+ O < n && (n = O, l = !0);
806
811
  }
807
- if (l ? i.mesh_lod = n : i.mesh_lod = r.lastLodLevel_Mesh, B && 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)
816
+ if (d) {
817
+ const m = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
812
818
  if (r.lastLodLevel_Texture < 0) {
813
- if (i.texture_lod = u.max_count - 1, B) {
814
- const p = u.lods[u.max_count - 1];
815
- B && console.log(`First Texture LOD ${i.texture_lod} (${p.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}`);
816
822
  }
817
823
  } else {
818
- const p = r.lastScreenspaceVolume.x + r.lastScreenspaceVolume.y + r.lastScreenspaceVolume.z;
819
- let D = r.lastScreenCoverage * 2;
820
- ((z = this.context) == null ? void 0 : z.engine) === "model-viewer" && (D *= 2);
821
- const G = v / window.devicePixelRatio * D;
822
- for (let _ = u.lods.length - 1; _ >= 0; _--) {
823
- let K = u.lods[_];
824
- if (!(je() && K.max_height > 4096) && K.max_height > G) {
825
- if (i.texture_lod = _, i.texture_lod < r.lastLodLevel_Texture) {
826
- const F = K.max_height;
827
- B && console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} → ${i.texture_lod} = ${F}px
828
- Screensize: ${G.toFixed(0)}px, Coverage: ${(100 * r.lastScreenCoverage).toFixed(2)}%, Volume ${p.toFixed(1)}
824
+ const w = r.lastScreenspaceVolume.x + r.lastScreenspaceVolume.y + r.lastScreenspaceVolume.z;
825
+ let z = r.lastScreenCoverage * 2;
826
+ (($ = this.context) == null ? void 0 : $.engine) === "model-viewer" && (z *= 2);
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) {
831
+ if (i.texture_lod = V, i.texture_lod < r.lastLodLevel_Texture) {
832
+ const O = A.max_height;
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)}
829
835
  ${e.name}`);
830
836
  }
831
837
  break;
832
838
  }
833
839
  }
834
840
  }
835
- else
841
+ } else
836
842
  i.texture_lod = 0;
837
843
  }
838
844
  };
839
- let I = E;
840
- C = new WeakMap(), U = new WeakMap(), ge = new WeakMap(), Q = new WeakMap(), Z = new WeakMap(), pe = new WeakMap(), W = 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(), 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.
841
847
  */
842
- d(I, "debugDrawLine"), d(I, "corner0", new V()), d(I, "corner1", new V()), d(I, "corner2", new V()), d(I, "corner3", new V()), d(I, "_tempPtInside", new V());
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());
843
849
  class it {
844
850
  constructor() {
845
- d(this, "frames", 0);
846
- d(this, "lastLodLevel_Mesh", -1);
847
- d(this, "lastLodLevel_Texture", -1);
848
- d(this, "lastScreenCoverage", 0);
849
- d(this, "lastScreenspaceVolume", new V());
850
- 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);
851
857
  }
852
858
  }
853
859
  const Pe = Symbol("NEEDLE_mesh_lod"), fe = Symbol("NEEDLE_texture_lod");
@@ -884,7 +890,7 @@ function Ge(a) {
884
890
  `, a.getAttribute("src"));
885
891
  let t = null, e = null, r = null;
886
892
  for (let o = a; o != null; o = Object.getPrototypeOf(o)) {
887
- 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)");
888
894
  !t && s != null && (t = a[s].threeRenderer), !e && n != null && (e = a[n]), !r && l != null && (r = a[l]);
889
895
  }
890
896
  if (t && e) {
@@ -900,8 +906,8 @@ function Ge(a) {
900
906
  }
901
907
  };
902
908
  console.debug("[gltf-progressive] setup model-viewer");
903
- const i = I.get(t, { engine: "model-viewer" });
904
- return I.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", () => {
905
911
  r == null || r.call(a);
906
912
  }), a.addEventListener("model-visibility", (s) => {
907
913
  s.detail.visible && (r == null || r.call(a));
@@ -915,7 +921,7 @@ function Ge(a) {
915
921
  }
916
922
  class at {
917
923
  constructor() {
918
- d(this, "_didWarnAboutMissingUrl", !1);
924
+ f(this, "_didWarnAboutMissingUrl", !1);
919
925
  }
920
926
  onBeforeUpdateLOD(t, e, r, o) {
921
927
  this.tryParseMeshLOD(e, o), this.tryParseTextureLOD(e, o);
@@ -939,25 +945,25 @@ class at {
939
945
  const r = this.tryGetCurrentGLTF(t), o = this.tryGetCurrentModelViewer(t), i = this.getUrl(o);
940
946
  if (i && r && e.material) {
941
947
  let s = function(l) {
942
- var c, M, u;
948
+ var c, D, h;
943
949
  if (l[fe] == !0)
944
950
  return;
945
951
  l[fe] = !0, l.userData && (l.userData.LOD = -1);
946
- const f = Object.keys(l);
947
- for (let y = 0; y < f.length; y++) {
948
- const v = f[y], x = l[v];
949
- if ((x == null ? void 0 : x.isTexture) === !0) {
950
- const R = (M = (c = x.userData) == null ? void 0 : c.associations) == null ? void 0 : M.textures;
951
- if (R == 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)
952
958
  continue;
953
- const z = r.parser.json.textures[R];
954
- if (!z) {
955
- console.warn("Texture data not found for texture index " + R);
959
+ const $ = r.parser.json.textures[k];
960
+ if (!$) {
961
+ console.warn("Texture data not found for texture index " + k);
956
962
  continue;
957
963
  }
958
- if ((u = z == null ? void 0 : z.extensions) != null && u[N]) {
959
- const p = z.extensions[N];
960
- p && i && S.registerTexture(i, x, p.lods.length, R, 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);
961
967
  }
962
968
  }
963
969
  }
@@ -978,23 +984,23 @@ class at {
978
984
  const r = this.tryGetCurrentModelViewer(t), o = this.getUrl(r);
979
985
  if (!o)
980
986
  return;
981
- const i = (n = (s = e.userData) == null ? void 0 : s.gltfExtensions) == null ? void 0 : n[N];
987
+ const i = (n = (s = e.userData) == null ? void 0 : s.gltfExtensions) == null ? void 0 : n[U];
982
988
  if (i && o) {
983
989
  const l = e.uuid;
984
- S.registerMesh(o, l, e, 0, i.lods.length, i);
990
+ b.registerMesh(o, l, e, 0, i.lods.length, i);
985
991
  }
986
992
  }
987
993
  }
988
994
  function mt(a, t, e, r) {
989
- ke(t), Ie(e), e.register((i) => new S(i, a));
990
- const o = I.get(t);
995
+ ke(t), Ie(e), e.register((i) => new b(i, a));
996
+ const o = G.get(t);
991
997
  return (r == null ? void 0 : r.enableLODsManager) !== !1 && o.enable(), o;
992
998
  }
993
999
  Re();
994
1000
  export {
995
- N as EXTENSION_NAME,
996
- I as LODsManager,
997
- S as NEEDLE_progressive,
1001
+ U as EXTENSION_NAME,
1002
+ G as LODsManager,
1003
+ b as NEEDLE_progressive,
998
1004
  Be as VERSION,
999
1005
  Ie as addDracoAndKTX2Loaders,
1000
1006
  ke as createLoaders,