@needle-tools/gltf-progressive 1.0.0-alpha.11 → 1.0.0-alpha.13

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,7 +1,7 @@
1
1
  var le = Object.defineProperty;
2
2
  var ue = (l, e, t) => e in l ? le(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
3
- var u = (l, e, t) => (ue(l, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { Mesh as q, BufferGeometry as V, Material as ce, Texture as U, TextureLoader as fe, Matrix4 as te, Frustum as de, Sphere as ge, Box3 as re, Vector3 as R } from "three";
3
+ var c = (l, e, t) => (ue(l, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { Mesh as q, BufferGeometry as Y, Material as ce, Texture as I, TextureLoader as fe, Matrix4 as te, Frustum as de, Sphere as ge, Box3 as re, Vector3 as C } from "three";
5
5
  import { GLTFLoader as he } from "three/examples/jsm/loaders/GLTFLoader.js";
6
6
  import { MeshoptDecoder as pe } from "three/examples/jsm/libs/meshopt_decoder.module.js";
7
7
  import { DRACOLoader as ye } from "three/examples/jsm/loaders/DRACOLoader.js";
@@ -16,12 +16,12 @@ function _e(l) {
16
16
  function Be(l) {
17
17
  j = l;
18
18
  }
19
- let F, J, W;
19
+ let U, J, W;
20
20
  function ne(l) {
21
- F || (F = new ye(), F.setDecoderPath(K), F.setDecoderConfig({ type: "js" })), W || (W = new me(), W.setTranscoderPath(j)), J || (J = pe), l ? W.detectSupport(l) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
21
+ U || (U = new ye(), U.setDecoderPath(K), U.setDecoderConfig({ type: "js" })), W || (W = new me(), W.setTranscoderPath(j)), J || (J = pe), l ? W.detectSupport(l) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
22
22
  }
23
23
  function oe(l) {
24
- l.dracoLoader || l.setDRACOLoader(F), l.ktx2Loader || l.setKTX2Loader(W), l.meshoptDecoder || l.setMeshoptDecoder(J);
24
+ l.dracoLoader || l.setDRACOLoader(U), l.ktx2Loader || l.setKTX2Loader(W), l.meshoptDecoder || l.setMeshoptDecoder(J);
25
25
  }
26
26
  function ee(l) {
27
27
  const t = new URL(window.location.href).searchParams.get(l);
@@ -40,18 +40,18 @@ function Le(l, e) {
40
40
  return e;
41
41
  }
42
42
  const Q = new Array();
43
- function Ce(l) {
43
+ function ke(l) {
44
44
  Q.push(l);
45
45
  }
46
- const k = "NEEDLE_progressive", S = ee("debugprogressive"), Y = Symbol("needle-progressive-texture"), z = /* @__PURE__ */ new Map(), Z = /* @__PURE__ */ new Set();
46
+ const R = "NEEDLE_progressive", S = ee("debugprogressive"), V = Symbol("needle-progressive-texture"), z = /* @__PURE__ */ new Map(), Z = /* @__PURE__ */ new Set();
47
47
  if (S) {
48
48
  let l = function() {
49
49
  e += 1, console.log("Toggle LOD level", e, z), z.forEach((i, n) => {
50
50
  for (const s of i.keys) {
51
51
  const o = n[s];
52
52
  if (o.isBufferGeometry === !0) {
53
- const a = v.getMeshLODInformation(o), h = a ? Math.min(e, a.lods.length) : 0;
54
- n["DEBUG:LOD"] = e, v.assignMeshLOD(n, h), a && (t = Math.max(t, a.lods.length - 1));
53
+ const a = v.getMeshLODInformation(o), g = a ? Math.min(e, a.lods.length) : 0;
54
+ n["DEBUG:LOD"] = e, v.assignMeshLOD(n, g), a && (t = Math.max(t, a.lods.length - 1));
55
55
  } else if (n.isMaterial === !0) {
56
56
  n["DEBUG:LOD"] = e, v.assignTextureLOD(n, e);
57
57
  break;
@@ -75,13 +75,13 @@ function se(l, e, t) {
75
75
  }
76
76
  const M = class {
77
77
  constructor(e, t) {
78
- u(this, "parser");
79
- u(this, "url");
78
+ c(this, "parser");
79
+ c(this, "url");
80
80
  S && console.log("Progressive extension registered for", t), this.parser = e, this.url = t;
81
81
  }
82
82
  /** The name of the extension */
83
83
  get name() {
84
- return k;
84
+ return R;
85
85
  }
86
86
  static getMeshLODInformation(e) {
87
87
  const t = this.getAssignedLODInformation(e);
@@ -146,7 +146,7 @@ const M = class {
146
146
  const o = n.index || 0;
147
147
  s = s[o];
148
148
  }
149
- s && i != s && s instanceof V && (e.geometry = s, S && se(e, "geometry", n.url));
149
+ s && i != s && s instanceof Y && (e.geometry = s, S && se(e, "geometry", n.url));
150
150
  }
151
151
  return s;
152
152
  }).catch((s) => (console.error("Error loading mesh LOD", e, s), null));
@@ -171,8 +171,8 @@ const M = class {
171
171
  for (const o of Object.keys(s.uniforms)) {
172
172
  const a = s.uniforms[o].value;
173
173
  if ((a == null ? void 0 : a.isTexture) === !0) {
174
- const h = this.assignTextureLODForSlot(a, t, r, o);
175
- i.push(h), n.push(o);
174
+ const g = this.assignTextureLODForSlot(a, t, r, o);
175
+ i.push(g), n.push(o);
176
176
  }
177
177
  }
178
178
  } else
@@ -186,13 +186,13 @@ const M = class {
186
186
  return Promise.all(i).then((s) => {
187
187
  const o = new Array();
188
188
  for (let a = 0; a < s.length; a++) {
189
- const h = s[a], g = n[a];
190
- h && h.isTexture === !0 ? o.push({ material: r, slot: g, texture: h, level: t }) : o.push({ material: r, slot: g, texture: null, level: t });
189
+ const g = s[a], f = n[a];
190
+ g && g.isTexture === !0 ? o.push({ material: r, slot: f, texture: g, level: t }) : o.push({ material: r, slot: f, texture: null, level: t });
191
191
  }
192
192
  return o;
193
193
  });
194
194
  }
195
- if (e instanceof U || e.isTexture === !0) {
195
+ if (e instanceof I || e.isTexture === !0) {
196
196
  const r = e;
197
197
  return this.assignTextureLODForSlot(r, t, null, null);
198
198
  }
@@ -217,7 +217,7 @@ const M = class {
217
217
  var t, r;
218
218
  return S && console.log("AFTER", this.url, e), (t = this.parser.json.textures) == null || t.forEach((i, n) => {
219
219
  if (i != null && i.extensions) {
220
- const s = i == null ? void 0 : i.extensions[k];
220
+ const s = i == null ? void 0 : i.extensions[R];
221
221
  if (s) {
222
222
  let o = !1;
223
223
  for (const a of this.parser.associations.keys())
@@ -229,7 +229,7 @@ const M = class {
229
229
  }
230
230
  }), (r = this.parser.json.meshes) == null || r.forEach((i, n) => {
231
231
  if (i != null && i.extensions) {
232
- const s = i == null ? void 0 : i.extensions[k];
232
+ const s = i == null ? void 0 : i.extensions[R];
233
233
  if (s && s.lods) {
234
234
  for (const o of this.parser.associations.keys())
235
235
  if (o.isMesh) {
@@ -241,87 +241,87 @@ const M = class {
241
241
  }), null;
242
242
  }
243
243
  static async getOrLoadLOD(e, t) {
244
- var o, a, h;
244
+ var o, a, g;
245
245
  const r = S == "verbose", i = e.userData.LODS;
246
246
  if (!i)
247
247
  return null;
248
248
  const n = i == null ? void 0 : i.key;
249
249
  let s;
250
250
  if (e.isTexture === !0) {
251
- const g = e;
252
- g.source && g.source[Y] && (s = g.source[Y]);
251
+ const f = e;
252
+ f.source && f.source[V] && (s = f.source[V]);
253
253
  }
254
254
  if (s || (s = M.lodInfos.get(n)), s) {
255
255
  if (t > 0) {
256
- let f = !1;
257
- const w = Array.isArray(s.lods);
258
- if (w && t >= s.lods.length ? f = !0 : w || (f = !0), f)
256
+ let u = !1;
257
+ const h = Array.isArray(s.lods);
258
+ if (h && t >= s.lods.length ? u = !0 : h || (u = !0), u)
259
259
  return this.lowresCache.get(n);
260
260
  }
261
- const g = Array.isArray(s.lods) ? s.lods[t].path : s.lods;
262
- if (!g)
261
+ const f = Array.isArray(s.lods) ? s.lods[t].path : s.lods;
262
+ if (!f)
263
263
  return S && !s["missing:uri"] && (s["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + t, s)), null;
264
- const c = Le(i.url, g);
265
- if (c.endsWith(".glb") || c.endsWith(".gltf")) {
264
+ const p = Le(i.url, f);
265
+ if (p.endsWith(".glb") || p.endsWith(".gltf")) {
266
266
  if (!s.guid)
267
267
  return console.warn("missing pointer for glb/gltf texture", s), null;
268
- const f = c + "_" + s.guid, w = this.previouslyLoaded.get(f);
269
- if (w !== void 0) {
270
- r && console.log(`LOD ${t} was already loading/loaded: ${f}`);
271
- let D = await w.catch((I) => (console.error(`Error loading LOD ${t} from ${c}
272
- `, I), null)), C = !1;
273
- if (D == null || (D instanceof U && e instanceof U ? (o = D.image) != null && o.data || (a = D.source) != null && a.data ? D = this.copySettings(e, D) : (C = !0, this.previouslyLoaded.delete(f)) : D instanceof V && e instanceof V && ((h = D.attributes.position) != null && h.array || (C = !0, this.previouslyLoaded.delete(f)))), !C)
274
- return D;
268
+ const u = p + "_" + s.guid, h = this.previouslyLoaded.get(u);
269
+ if (h !== void 0) {
270
+ r && console.log(`LOD ${t} was already loading/loaded: ${u}`);
271
+ let x = await h.catch((F) => (console.error(`Error loading LOD ${t} from ${p}
272
+ `, F), null)), k = !1;
273
+ if (x == null || (x instanceof I && e instanceof I ? (o = x.image) != null && o.data || (a = x.source) != null && a.data ? x = this.copySettings(e, x) : (k = !0, this.previouslyLoaded.delete(u)) : x instanceof Y && e instanceof Y && ((g = x.attributes.position) != null && g.array || (k = !0, this.previouslyLoaded.delete(u)))), !k)
274
+ return x;
275
275
  }
276
- const L = s, A = new Promise(async (D, C) => {
277
- const I = new he();
278
- oe(I), S && (await new Promise((y) => setTimeout(y, 1e3)), r && console.warn("Start loading (delayed) " + c, L.guid));
279
- let m = c;
280
- if (L && Array.isArray(L.lods)) {
281
- const y = L.lods[t];
282
- y.hash && (m += "?v=" + y.hash);
276
+ const D = s, A = new Promise(async (x, k) => {
277
+ const F = new he();
278
+ oe(F), S && (await new Promise((m) => setTimeout(m, 1e3)), r && console.warn("Start loading (delayed) " + p, D.guid));
279
+ let L = p;
280
+ if (D && Array.isArray(D.lods)) {
281
+ const m = D.lods[t];
282
+ m.hash && (L += "?v=" + m.hash);
283
283
  }
284
- const p = await I.loadAsync(m).catch((y) => (console.error(`Error loading LOD ${t} from ${c}
285
- `, y), null));
286
- if (!p)
284
+ const y = await F.loadAsync(L).catch((m) => (console.error(`Error loading LOD ${t} from ${p}
285
+ `, m), null));
286
+ if (!y)
287
287
  return null;
288
- const T = p.parser;
289
- r && console.log("Loading finished " + c, L.guid);
290
- let x = 0;
291
- if (p.parser.json.textures) {
292
- let y = !1;
293
- for (const d of p.parser.json.textures) {
288
+ const T = y.parser;
289
+ r && console.log("Loading finished " + p, D.guid);
290
+ let w = 0;
291
+ if (y.parser.json.textures) {
292
+ let m = !1;
293
+ for (const d of y.parser.json.textures) {
294
294
  if (d != null && d.extensions) {
295
- const O = d == null ? void 0 : d.extensions[k];
296
- if (O != null && O.guid && O.guid === L.guid) {
297
- y = !0;
295
+ const O = d == null ? void 0 : d.extensions[R];
296
+ if (O != null && O.guid && O.guid === D.guid) {
297
+ m = !0;
298
298
  break;
299
299
  }
300
300
  }
301
- x++;
301
+ w++;
302
302
  }
303
- if (y) {
304
- let d = await T.getDependency("texture", x);
305
- return r && console.log('change "' + e.name + '" → "' + d.name + '"', c, x, d, f), e instanceof U && (d = this.copySettings(e, d)), d && (d.guid = L.guid), D(d);
303
+ if (m) {
304
+ let d = await T.getDependency("texture", w);
305
+ return r && console.log('change "' + e.name + '" → "' + d.name + '"', p, w, d, u), e instanceof I && (d = this.copySettings(e, d)), d && (d.guid = D.guid), x(d);
306
306
  }
307
307
  }
308
- if (x = 0, p.parser.json.meshes) {
309
- let y = !1;
310
- for (const d of p.parser.json.meshes) {
308
+ if (w = 0, y.parser.json.meshes) {
309
+ let m = !1;
310
+ for (const d of y.parser.json.meshes) {
311
311
  if (d != null && d.extensions) {
312
- const O = d == null ? void 0 : d.extensions[k];
313
- if (O != null && O.guid && O.guid === L.guid) {
314
- y = !0;
312
+ const O = d == null ? void 0 : d.extensions[R];
313
+ if (O != null && O.guid && O.guid === D.guid) {
314
+ m = !0;
315
315
  break;
316
316
  }
317
317
  }
318
- x++;
318
+ w++;
319
319
  }
320
- if (y) {
321
- const d = await T.getDependency("mesh", x), O = L;
322
- if (r && console.log(`Loaded Mesh "${d.name}"`, c, x, d, f), d.isMesh === !0) {
320
+ if (m) {
321
+ const d = await T.getDependency("mesh", w), O = D;
322
+ if (r && console.log(`Loaded Mesh "${d.name}"`, p, w, d, u), d.isMesh === !0) {
323
323
  const P = d.geometry;
324
- return M.assignLODInformation(i.url, P, n, t, void 0, O.density), D(P);
324
+ return M.assignLODInformation(i.url, P, n, t, void 0, O.density), x(P);
325
325
  } else {
326
326
  const P = new Array();
327
327
  for (let _ = 0; _ < d.children.length; _++) {
@@ -331,17 +331,17 @@ const M = class {
331
331
  M.assignLODInformation(i.url, N, n, t, _, O.density), P.push(N);
332
332
  }
333
333
  }
334
- return D(P);
334
+ return x(P);
335
335
  }
336
336
  }
337
337
  }
338
- return D(null);
338
+ return x(null);
339
339
  });
340
- return this.previouslyLoaded.set(f, A), await A;
341
- } else if (e instanceof U) {
342
- r && console.log("Load texture from uri: " + c);
343
- const w = await new fe().loadAsync(c);
344
- return w ? (w.guid = s.guid, w.flipY = !1, w.needsUpdate = !0, w.colorSpace = e.colorSpace, r && console.log(s, w)) : S && console.warn("failed loading", c), w;
340
+ return this.previouslyLoaded.set(u, A), await A;
341
+ } else if (e instanceof I) {
342
+ r && console.log("Load texture from uri: " + p);
343
+ const h = await new fe().loadAsync(p);
344
+ return h ? (h.guid = s.guid, h.flipY = !1, h.needsUpdate = !0, h.colorSpace = e.colorSpace, r && console.log(s, h)) : S && console.warn("failed loading", p), h;
345
345
  }
346
346
  } else
347
347
  S && console.warn(`Can not load LOD ${t}: no LOD info found for "${n}" ${e.name}`, e.type);
@@ -360,69 +360,69 @@ const M = class {
360
360
  }
361
361
  static copySettings(e, t) {
362
362
  const r = this._copiedTextures.get(e);
363
- return r || (t = t.clone(), this._copiedTextures.set(e, t), t.offset = e.offset, t.repeat = e.repeat, t.colorSpace = e.colorSpace, t);
363
+ return r || (t = t.clone(), this._copiedTextures.set(e, t), t.offset = e.offset, t.repeat = e.repeat, t.colorSpace = e.colorSpace, t.magFilter = e.magFilter, t.minFilter = e.minFilter, t.wrapS = e.wrapS, t.wrapT = e.wrapT, t.flipY = e.flipY, t.anisotropy = e.anisotropy, t.generateMipmaps = e.generateMipmaps, t);
364
364
  }
365
365
  };
366
366
  let v = M;
367
367
  /**
368
368
  * Register a texture with LOD information
369
369
  */
370
- u(v, "registerTexture", (e, t, r, i) => {
371
- S && console.log("> Progressive: register texture", r, t.name, t.uuid, t, i), t.source && (t.source[Y] = i);
370
+ c(v, "registerTexture", (e, t, r, i) => {
371
+ S && console.log("> Progressive: register texture", r, t.name, t.uuid, t, i), t.source && (t.source[V] = i);
372
372
  const n = i.guid;
373
373
  M.assignLODInformation(e, t, n, 0, 0, void 0), M.lodInfos.set(n, i), M.lowresCache.set(n, t);
374
374
  }), /**
375
375
  * Register a mesh with LOD information
376
376
  */
377
- u(v, "registerMesh", (e, t, r, i, n, s) => {
378
- var h;
377
+ c(v, "registerMesh", (e, t, r, i, n, s) => {
378
+ var g;
379
379
  S && console.log("> Progressive: register mesh", n, r.name, s, r.uuid, r);
380
380
  const o = r.geometry;
381
381
  o.userData || (o.userData = {}), M.assignLODInformation(e, o, t, i, n, s.density), M.lodInfos.set(t, s);
382
382
  let a = M.lowresCache.get(t);
383
383
  a ? a.push(r.geometry) : a = [r.geometry], M.lowresCache.set(t, a);
384
- for (const g of Q)
385
- (h = g.onRegisteredNewMesh) == null || h.call(g, r, s);
384
+ for (const f of Q)
385
+ (g = f.onRegisteredNewMesh) == null || g.call(f, r, s);
386
386
  }), /** A map of key = asset uuid and value = LOD information */
387
- u(v, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
388
- u(v, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
389
- u(v, "lowresCache", /* @__PURE__ */ new Map()), u(v, "_copiedTextures", /* @__PURE__ */ new Map());
387
+ c(v, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
388
+ c(v, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
389
+ c(v, "lowresCache", /* @__PURE__ */ new Map()), c(v, "_copiedTextures", /* @__PURE__ */ new Map());
390
390
  class De {
391
391
  constructor(e, t, r, i, n) {
392
- u(this, "url");
392
+ c(this, "url");
393
393
  /** the key to lookup the LOD information */
394
- u(this, "key");
395
- u(this, "level");
394
+ c(this, "key");
395
+ c(this, "level");
396
396
  /** For multi objects (e.g. a group of meshes) this is the index of the object */
397
- u(this, "index");
397
+ c(this, "index");
398
398
  /** the mesh density */
399
- u(this, "density");
399
+ c(this, "density");
400
400
  this.url = e, this.key = t, this.level = r, i != null && (this.index = i), n != null && (this.density = n);
401
401
  }
402
402
  }
403
403
  const H = ee("debugprogressive"), xe = ee("noprogressive"), b = class {
404
404
  constructor(e) {
405
- u(this, "renderer");
406
- u(this, "projectionScreenMatrix", new te());
407
- u(this, "cameraFrustrum", new de());
405
+ c(this, "renderer");
406
+ c(this, "projectionScreenMatrix", new te());
407
+ c(this, "cameraFrustrum", new de());
408
408
  /**
409
409
  * The update interval in frames. If set to 0, the LODs will be updated every frame. If set to 1, the LODs will be updated every second frame, etc.
410
410
  */
411
- u(this, "updateInterval", 0);
411
+ c(this, "updateInterval", 0);
412
412
  /**
413
413
  * If set to true, the LODsManager will not update the LODs.
414
414
  */
415
- u(this, "pause", !1);
416
- u(this, "plugins", []);
417
- u(this, "_frame", 0);
418
- u(this, "_originalRender");
415
+ c(this, "pause", !1);
416
+ c(this, "plugins", []);
417
+ c(this, "_frame", 0);
418
+ c(this, "_originalRender");
419
419
  // private testIfLODLevelsAreAvailable() {
420
- u(this, "_sphere", new ge());
421
- u(this, "_tempBox", new re());
422
- u(this, "tempMatrix", new te());
423
- u(this, "_tempWorldPosition", new R());
424
- u(this, "_tempBoxSize", new R());
425
- u(this, "_tempBox2Size", new R());
420
+ c(this, "_sphere", new ge());
421
+ c(this, "_tempBox", new re());
422
+ c(this, "tempMatrix", new te());
423
+ c(this, "_tempWorldPosition", new C());
424
+ c(this, "_tempBoxSize", new C());
425
+ c(this, "_tempBox2Size", new C());
426
426
  this.renderer = e;
427
427
  }
428
428
  /** @internal */
@@ -451,47 +451,55 @@ const H = ee("debugprogressive"), xe = ee("noprogressive"), b = class {
451
451
  onBeforeRender(e, t, r, i) {
452
452
  }
453
453
  onAfterRender(e, t, r, i) {
454
- var n, s;
455
- if (!this.pause && r == 0) {
454
+ var a, g;
455
+ if (this.pause)
456
+ return;
457
+ const n = this.renderer.renderLists.get(e, 0), s = n.opaque;
458
+ let o = !0;
459
+ if (s.length === 1) {
460
+ const f = s[0].material;
461
+ (f.name === "EffectMaterial" || f.name === "CopyShader") && (o = !1);
462
+ }
463
+ if (o) {
456
464
  if (xe || this.updateInterval > 0 && i % this.updateInterval != 0)
457
465
  return;
458
466
  this.projectionScreenMatrix.multiplyMatrices(t.projectionMatrix, t.matrixWorldInverse), this.cameraFrustrum.setFromProjectionMatrix(this.projectionScreenMatrix, this.renderer.coordinateSystem);
459
- const o = 1e5, a = this.renderer.renderLists.get(e, r), h = a.opaque;
460
- for (const c of h) {
461
- if (c.material && (((n = c.geometry) == null ? void 0 : n.type) === "BoxGeometry" || ((s = c.geometry) == null ? void 0 : s.type) === "BufferGeometry") && (c.material.name === "SphericalGaussianBlur" || c.material.name == "BackgroundCubeMaterial" || c.material.name === "CubemapFromEquirect" || c.material.name === "EquirectangularToCubeUV")) {
462
- H && (c.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (c.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", c, c.material.name, c.material.type)));
467
+ const f = 1e5;
468
+ for (const u of s) {
469
+ if (u.material && (((a = u.geometry) == null ? void 0 : a.type) === "BoxGeometry" || ((g = u.geometry) == null ? void 0 : g.type) === "BufferGeometry") && (u.material.name === "SphericalGaussianBlur" || u.material.name == "BackgroundCubeMaterial" || u.material.name === "CubemapFromEquirect" || u.material.name === "EquirectangularToCubeUV")) {
470
+ H && (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)));
463
471
  continue;
464
472
  }
465
- const f = c.object;
466
- (f instanceof q || f.isMesh) && this.updateLODs(e, t, f, o);
473
+ const h = u.object;
474
+ (h instanceof q || h.isMesh) && this.updateLODs(e, t, h, f);
467
475
  }
468
- const g = a.transparent;
469
- for (const c of g) {
470
- const f = c.object;
471
- (f instanceof q || f.isMesh) && this.updateLODs(e, t, f, o);
476
+ const p = n.transparent;
477
+ for (const u of p) {
478
+ const h = u.object;
479
+ (h instanceof q || h.isMesh) && this.updateLODs(e, t, h, f);
472
480
  }
473
481
  }
474
482
  }
475
483
  /** Update the LOD levels for the renderer. */
476
484
  updateLODs(e, t, r, i) {
477
- var a, h;
478
- for (const g of this.plugins)
479
- (a = g.onBeforeUpdateLOD) == null || a.call(g, this.renderer, e, t, r);
485
+ var a, g;
486
+ for (const f of this.plugins)
487
+ (a = f.onBeforeUpdateLOD) == null || a.call(f, this.renderer, e, t, r);
480
488
  let n = r.userData.LOD_state;
481
489
  n || (n = new we(), r.userData.LOD_state = n);
482
490
  let s = this.calculateLodLevel(t, r, n, i);
483
491
  s = Math.round(s), s >= 0 && this.loadProgressiveMeshes(r, s);
484
492
  let o = 0;
485
493
  if (r.material) {
486
- const g = r["DEBUG:LOD"];
487
- if (g != null && (o = g), Array.isArray(r.material))
488
- for (const c of r.material)
489
- this.loadProgressiveTextures(c, o);
494
+ const f = r["DEBUG:LOD"];
495
+ if (f != null && (o = f), Array.isArray(r.material))
496
+ for (const p of r.material)
497
+ this.loadProgressiveTextures(p, o);
490
498
  else
491
499
  this.loadProgressiveTextures(r.material, o);
492
500
  }
493
- for (const g of this.plugins)
494
- (h = g.onAfterUpdatedLOD) == null || h.call(g, this.renderer, e, t, r, s);
501
+ for (const f of this.plugins)
502
+ (g = f.onAfterUpdatedLOD) == null || g.call(f, this.renderer, e, t, r, s);
495
503
  n.lastLodLevel = s;
496
504
  }
497
505
  /** Load progressive textures for the given material
@@ -526,49 +534,49 @@ const H = ee("debugprogressive"), xe = ee("noprogressive"), b = class {
526
534
  if (e) {
527
535
  if (H && t["DEBUG:LOD"] != null)
528
536
  return t["DEBUG:LOD"];
529
- const a = v.getMeshLODInformation(t.geometry), h = a == null ? void 0 : a.lods;
530
- if (!h || h.length <= 0 || !((o = this.cameraFrustrum) != null && o.intersectsObject(t)))
537
+ const a = v.getMeshLODInformation(t.geometry), g = a == null ? void 0 : a.lods;
538
+ if (!g || g.length <= 0 || !((o = this.cameraFrustrum) != null && o.intersectsObject(t)))
531
539
  return 99;
532
- const g = t.geometry.boundingBox;
533
- if (g && e.isPerspectiveCamera) {
534
- const c = e;
540
+ const f = t.geometry.boundingBox;
541
+ if (f && e.isPerspectiveCamera) {
542
+ const p = e;
535
543
  if (t.geometry.attributes.color && t.geometry.attributes.color.count < 100 && t.geometry.boundingSphere) {
536
544
  this._sphere.copy(t.geometry.boundingSphere), this._sphere.applyMatrix4(t.matrixWorld);
537
- const m = e.getWorldPosition(this._tempWorldPosition);
538
- if (this._sphere.containsPoint(m))
545
+ const L = e.getWorldPosition(this._tempWorldPosition);
546
+ if (this._sphere.containsPoint(L))
539
547
  return 0;
540
548
  }
541
- if (this._tempBox.copy(g), this._tempBox.applyMatrix4(t.matrixWorld), this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && c.fov > 70) {
542
- const m = this._tempBox.min, p = this._tempBox.max;
543
- let T = m.x, x = m.y, y = p.x, d = p.y;
544
- const O = 2, P = 1.5, _ = (m.x + p.x) * 0.5, E = (m.y + p.y) * 0.5;
545
- T = (T - _) * O + _, x = (x - E) * O + E, y = (y - _) * O + _, d = (d - E) * O + E;
546
- const N = T < 0 && y > 0 ? 0 : Math.min(Math.abs(m.x), Math.abs(p.x)), ae = x < 0 && d > 0 ? 0 : Math.min(Math.abs(m.y), Math.abs(p.y)), X = Math.max(N, ae);
549
+ if (this._tempBox.copy(f), this._tempBox.applyMatrix4(t.matrixWorld), this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && p.fov > 70) {
550
+ const L = this._tempBox.min, y = this._tempBox.max;
551
+ let T = L.x, w = L.y, m = y.x, d = y.y;
552
+ const O = 2, P = 1.5, _ = (L.x + y.x) * 0.5, E = (L.y + y.y) * 0.5;
553
+ T = (T - _) * O + _, w = (w - E) * O + E, m = (m - _) * O + _, d = (d - E) * O + E;
554
+ const N = T < 0 && m > 0 ? 0 : Math.min(Math.abs(L.x), Math.abs(y.x)), ae = w < 0 && d > 0 ? 0 : Math.min(Math.abs(L.y), Math.abs(y.y)), X = Math.max(N, ae);
547
555
  r.lastCentrality = (P - X) * (P - X) * (P - X);
548
556
  } else
549
557
  r.lastCentrality = 1;
550
- const f = this._tempBox.getSize(this._tempBoxSize);
551
- f.multiplyScalar(0.5), screen.availHeight > 0 && f.multiplyScalar(this.renderer.domElement.clientHeight / screen.availHeight), f.x *= c.aspect;
552
- const w = e.matrixWorldInverse, L = new re();
553
- L.copy(g), L.applyMatrix4(t.matrixWorld), L.applyMatrix4(w);
554
- const A = L.getSize(this._tempBox2Size), G = Math.max(A.x, A.y);
555
- if (Math.max(f.x, f.y) != 0 && G != 0 && (f.z = A.z / Math.max(A.x, A.y) * Math.max(f.x, f.y)), r.lastScreenCoverage = Math.max(f.x, f.y, f.z), r.lastScreenspaceVolume.copy(f), r.lastScreenCoverage *= r.lastCentrality, H && b.debugDrawLine) {
556
- const m = this.tempMatrix.copy(this.projectionScreenMatrix);
557
- m.invert();
558
- const p = b.corner0, T = b.corner1, x = b.corner2, y = b.corner3;
559
- p.copy(this._tempBox.min), T.copy(this._tempBox.max), T.x = p.x, x.copy(this._tempBox.max), x.y = p.y, y.copy(this._tempBox.max);
560
- const d = (p.z + y.z) * 0.5;
561
- p.z = T.z = x.z = y.z = d, p.applyMatrix4(m), T.applyMatrix4(m), x.applyMatrix4(m), y.applyMatrix4(m), b.debugDrawLine(p, T, 255), b.debugDrawLine(p, x, 255), b.debugDrawLine(T, y, 255), b.debugDrawLine(x, y, 255);
558
+ const u = this._tempBox.getSize(this._tempBoxSize);
559
+ u.multiplyScalar(0.5), screen.availHeight > 0 && u.multiplyScalar(this.renderer.domElement.clientHeight / screen.availHeight), u.x *= p.aspect;
560
+ const h = e.matrixWorldInverse, D = new re();
561
+ D.copy(f), D.applyMatrix4(t.matrixWorld), D.applyMatrix4(h);
562
+ const A = D.getSize(this._tempBox2Size), G = Math.max(A.x, A.y);
563
+ if (Math.max(u.x, u.y) != 0 && G != 0 && (u.z = A.z / Math.max(A.x, A.y) * Math.max(u.x, u.y)), r.lastScreenCoverage = Math.max(u.x, u.y, u.z), r.lastScreenspaceVolume.copy(u), r.lastScreenCoverage *= r.lastCentrality, H && b.debugDrawLine) {
564
+ const L = this.tempMatrix.copy(this.projectionScreenMatrix);
565
+ L.invert();
566
+ const y = b.corner0, T = b.corner1, w = b.corner2, m = b.corner3;
567
+ y.copy(this._tempBox.min), T.copy(this._tempBox.max), T.x = y.x, w.copy(this._tempBox.max), w.y = y.y, m.copy(this._tempBox.max);
568
+ const d = (y.z + m.z) * 0.5;
569
+ y.z = T.z = w.z = m.z = d, y.applyMatrix4(L), T.applyMatrix4(L), w.applyMatrix4(L), m.applyMatrix4(L), b.debugDrawLine(y, T, 255), b.debugDrawLine(y, w, 255), b.debugDrawLine(T, m, 255), b.debugDrawLine(w, m, 255);
562
570
  }
563
- let C = 999;
564
- if (h && r.lastScreenCoverage > 0) {
565
- for (let m = 0; m < h.length; m++)
566
- if (h[m].density / r.lastScreenCoverage < i) {
567
- C = m;
571
+ let k = 999;
572
+ if (g && r.lastScreenCoverage > 0) {
573
+ for (let L = 0; L < g.length; L++)
574
+ if (g[L].density / r.lastScreenCoverage < i) {
575
+ k = L;
568
576
  break;
569
577
  }
570
578
  }
571
- C < s && (s = C);
579
+ k < s && (s = k);
572
580
  }
573
581
  }
574
582
  return s;
@@ -577,13 +585,13 @@ const H = ee("debugprogressive"), xe = ee("noprogressive"), b = class {
577
585
  let B = b;
578
586
  /** 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.
579
587
  */
580
- u(B, "debugDrawLine"), u(B, "corner0", new R()), u(B, "corner1", new R()), u(B, "corner2", new R()), u(B, "corner3", new R());
588
+ c(B, "debugDrawLine"), c(B, "corner0", new C()), c(B, "corner1", new C()), c(B, "corner2", new C()), c(B, "corner3", new C());
581
589
  class we {
582
590
  constructor() {
583
- u(this, "lastLodLevel", 0);
584
- u(this, "lastScreenCoverage", 0);
585
- u(this, "lastScreenspaceVolume", new R());
586
- u(this, "lastCentrality", 0);
591
+ c(this, "lastLodLevel", 0);
592
+ c(this, "lastScreenCoverage", 0);
593
+ c(this, "lastScreenspaceVolume", new C());
594
+ c(this, "lastCentrality", 0);
587
595
  }
588
596
  }
589
597
  const ie = Symbol("NEEDLE_mesh_lod"), $ = Symbol("NEEDLE_texture_lod");
@@ -610,8 +618,8 @@ function Oe(l) {
610
618
  }
611
619
  class Me {
612
620
  constructor(e) {
613
- u(this, "modelviewer");
614
- u(this, "_didWarnAboutMissingUrl", !1);
621
+ c(this, "modelviewer");
622
+ c(this, "_didWarnAboutMissingUrl", !1);
615
623
  this.modelviewer = e;
616
624
  }
617
625
  onBeforeUpdateLOD(e, t, r, i) {
@@ -631,18 +639,18 @@ class Me {
631
639
  const r = this.tryGetCurrentGLTF(e), i = this.getUrl();
632
640
  if (i && r && t.material) {
633
641
  let n = function(o) {
634
- var h, g, c;
642
+ var g, f, p;
635
643
  if (o[$] == !0)
636
644
  return;
637
645
  o[$] = !0, o.userData && (o.userData.LOD = -1);
638
646
  const a = Object.keys(o);
639
- for (let f = 0; f < a.length; f++) {
640
- const w = a[f], L = o[w];
641
- if ((L == null ? void 0 : L.isTexture) === !0) {
642
- const A = (g = (h = L.userData) == null ? void 0 : h.associations) == null ? void 0 : g.textures, G = r.parser.json.textures[A];
643
- if ((c = G.extensions) != null && c[k]) {
644
- const D = G.extensions[k];
645
- D && i && v.registerTexture(i, L, D.lods.length, D);
647
+ for (let u = 0; u < a.length; u++) {
648
+ const h = a[u], D = o[h];
649
+ if ((D == null ? void 0 : D.isTexture) === !0) {
650
+ const A = (f = (g = D.userData) == null ? void 0 : g.associations) == null ? void 0 : f.textures, G = r.parser.json.textures[A];
651
+ if ((p = G.extensions) != null && p[R]) {
652
+ const x = G.extensions[R];
653
+ x && i && v.registerTexture(i, D, x.lods.length, x);
646
654
  }
647
655
  }
648
656
  }
@@ -663,14 +671,14 @@ class Me {
663
671
  const r = this.getUrl();
664
672
  if (!r)
665
673
  return;
666
- const i = (s = (n = t.userData) == null ? void 0 : n.gltfExtensions) == null ? void 0 : s[k];
674
+ const i = (s = (n = t.userData) == null ? void 0 : n.gltfExtensions) == null ? void 0 : s[R];
667
675
  if (i && r) {
668
676
  const o = t.uuid;
669
677
  v.registerMesh(r, o, t, 0, i.lods.length, i);
670
678
  }
671
679
  }
672
680
  }
673
- function Re(l, e, t, r) {
681
+ function Ce(l, e, t, r) {
674
682
  ne(e), oe(t), t.register((n) => new v(n, l));
675
683
  const i = new B(e);
676
684
  return (r == null ? void 0 : r.enableLODsManager) !== !1 && i.enable(), i;
@@ -679,12 +687,14 @@ document.addEventListener("DOMContentLoaded", () => {
679
687
  Oe(document.querySelector("model-viewer"));
680
688
  });
681
689
  export {
682
- k as EXTENSION_NAME,
690
+ R as EXTENSION_NAME,
683
691
  B as LODsManager,
684
692
  v as NEEDLE_progressive,
693
+ oe as addDracoAndKTX2Loaders,
694
+ ne as createLoaders,
685
695
  Oe as patchModelViewer,
686
- Ce as registerPlugin,
696
+ ke as registerPlugin,
687
697
  _e as setDracoDecoderLocation,
688
698
  Be as setKTX2TranscoderLocation,
689
- Re as useNeedleProgressive
699
+ Ce as useNeedleProgressive
690
700
  };