@needle-tools/gltf-progressive 1.2.1-alpha.1 → 1.2.1-alpha.3

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,11 +1,11 @@
1
- var Me = Object.defineProperty;
2
- var we = (l, e, t) => e in l ? Me(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
3
- var f = (l, e, t) => (we(l, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { MeshoptDecoder as _e } from "three/examples/jsm/libs/meshopt_decoder.module.js";
5
- import { DRACOLoader as Oe } from "three/examples/jsm/loaders/DRACOLoader.js";
6
- import { KTX2Loader as ve } from "three/examples/jsm/loaders/KTX2Loader.js";
7
- import { BufferGeometry as H, Mesh as z, Material as Se, Texture as K, TextureLoader as Te, Matrix4 as de, Frustum as be, Sphere as Ae, Box3 as he, Vector3 as k } from "three";
8
- import { GLTFLoader as Pe } from "three/examples/jsm/loaders/GLTFLoader.js";
1
+ var De = Object.defineProperty;
2
+ var we = (l, e, t) => e in l ? De(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
3
+ var d = (l, e, t) => (we(l, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { BufferGeometry as ee, Mesh as N, Material as _e, Texture as K, TextureLoader as Oe, Matrix4 as de, Frustum as ve, Sphere as Se, Box3 as he, Vector3 as R } from "three";
5
+ import { GLTFLoader as Te } from "three/examples/jsm/loaders/GLTFLoader.js";
6
+ import { MeshoptDecoder as be } from "three/examples/jsm/libs/meshopt_decoder.module.js";
7
+ import { DRACOLoader as Ae } from "three/examples/jsm/loaders/DRACOLoader.js";
8
+ import { KTX2Loader as Pe } from "three/examples/jsm/loaders/KTX2Loader.js";
9
9
  let te = "https://www.gstatic.com/draco/versioned/decoders/1.4.1/", ue = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
10
10
  fetch(te + "draco_decoder.js", { method: "head" }).catch((l) => {
11
11
  te = "./include/draco/", ue = "./include/ktx2/";
@@ -17,10 +17,10 @@ function Ye(l) {
17
17
  ue = l;
18
18
  }
19
19
  let Y, ae, V;
20
- function xe(l) {
21
- Y || (Y = new Oe(), Y.setDecoderPath(te), Y.setDecoderConfig({ type: "js" })), V || (V = new ve(), V.setTranscoderPath(ue)), ae || (ae = _e), l ? V.detectSupport(l) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
22
- }
23
20
  function me(l) {
21
+ Y || (Y = new Ae(), Y.setDecoderPath(te), Y.setDecoderConfig({ type: "js" })), V || (V = new Pe(), V.setTranscoderPath(ue)), ae || (ae = be), l ? V.detectSupport(l) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
22
+ }
23
+ function xe(l) {
24
24
  l.dracoLoader || l.setDRACOLoader(Y), l.ktx2Loader || l.setKTX2Loader(V), l.meshoptDecoder || l.setMeshoptDecoder(ae);
25
25
  }
26
26
  function re(l) {
@@ -45,7 +45,7 @@ function Be() {
45
45
  }
46
46
  const le = Symbol("needle:raycast-mesh");
47
47
  function fe(l) {
48
- return (l == null ? void 0 : l[le]) instanceof H ? l[le] : null;
48
+ return (l == null ? void 0 : l[le]) instanceof ee ? l[le] : null;
49
49
  }
50
50
  function ke(l, e) {
51
51
  if ((l.type === "Mesh" || l.type === "SkinnedMesh") && !fe(l)) {
@@ -57,8 +57,8 @@ function Ve(l = !0) {
57
57
  if (l) {
58
58
  if (X)
59
59
  return;
60
- const e = X = z.prototype.raycast;
61
- z.prototype.raycast = function(t, r) {
60
+ const e = X = N.prototype.raycast;
61
+ N.prototype.raycast = function(t, r) {
62
62
  const i = this, o = fe(i);
63
63
  let s;
64
64
  o && i.isMesh && (s = i.geometry, i.geometry = o), e.call(this, t, r), s && (i.geometry = s);
@@ -66,20 +66,20 @@ function Ve(l = !0) {
66
66
  } else {
67
67
  if (!X)
68
68
  return;
69
- z.prototype.raycast = X, X = null;
69
+ N.prototype.raycast = X, X = null;
70
70
  }
71
71
  }
72
72
  let X = null;
73
73
  function Re(l) {
74
- const e = new H();
74
+ const e = new ee();
75
75
  for (const t in l.attributes)
76
76
  e.setAttribute(t, l.getAttribute(t));
77
77
  return e.setIndex(l.getIndex()), e;
78
78
  }
79
- const G = new Array(), R = "NEEDLE_progressive", L = re("debugprogressive"), oe = Symbol("needle-progressive-texture"), J = /* @__PURE__ */ new Map(), ce = /* @__PURE__ */ new Set();
80
- if (L) {
79
+ const $ = new Array(), E = "NEEDLE_progressive", y = re("debugprogressive"), oe = Symbol("needle-progressive-texture"), H = /* @__PURE__ */ new Map(), ce = /* @__PURE__ */ new Set();
80
+ if (y) {
81
81
  let l = function() {
82
- e += 1, console.log("Toggle LOD level", e, J), J.forEach((i, o) => {
82
+ e += 1, console.log("Toggle LOD level", e, H), H.forEach((i, o) => {
83
83
  for (const s of i.keys) {
84
84
  const n = o[s];
85
85
  if (n != null) {
@@ -102,29 +102,32 @@ if (L) {
102
102
  }
103
103
  function ge(l, e, t) {
104
104
  var i;
105
- if (!L)
105
+ if (!y)
106
106
  return;
107
- J.has(l) || J.set(l, { keys: [], sourceId: t });
108
- const r = J.get(l);
107
+ H.has(l) || H.set(l, { keys: [], sourceId: t });
108
+ const r = H.get(l);
109
109
  ((i = r == null ? void 0 : r.keys) == null ? void 0 : i.includes(e)) == !1 && r.keys.push(e);
110
110
  }
111
- const w = class {
111
+ const O = class {
112
112
  constructor(e, t) {
113
- f(this, "parser");
114
- f(this, "url");
115
- f(this, "_isLoadingMesh");
116
- f(this, "loadMesh", (e) => {
113
+ d(this, "parser");
114
+ d(this, "url");
115
+ d(this, "_isLoadingMesh");
116
+ d(this, "loadMesh", (e) => {
117
117
  var r, i;
118
118
  if (this._isLoadingMesh)
119
119
  return null;
120
- const t = (i = (r = this.parser.json.meshes[e]) == null ? void 0 : r.extensions) == null ? void 0 : i[R];
121
- return t ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", e).then((o) => (this._isLoadingMesh = !1, o && w.registerMesh(this.url, t.guid, o, t.lods.length, void 0, t), o))) : null;
120
+ const t = (i = (r = this.parser.json.meshes[e]) == null ? void 0 : r.extensions) == null ? void 0 : i[E];
121
+ return t ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", e).then((o) => {
122
+ var s;
123
+ return this._isLoadingMesh = !1, o && O.registerMesh(this.url, t.guid, o, (s = t.lods) == null ? void 0 : s.length, void 0, t), o;
124
+ })) : null;
122
125
  });
123
- L && console.log("Progressive extension registered for", t), this.parser = e, this.url = t;
126
+ y && console.log("Progressive extension registered for", t), this.parser = e, this.url = t;
124
127
  }
125
128
  /** The name of the extension */
126
129
  get name() {
127
- return R;
130
+ return E;
128
131
  }
129
132
  static getMeshLODInformation(e) {
130
133
  const t = this.getAssignedLODInformation(e);
@@ -143,7 +146,7 @@ const w = class {
143
146
  this.getMaterialMinMaxLODsCount(n, t);
144
147
  return e[i] = t, t;
145
148
  }
146
- if (L === "verbose" && console.log("getMaterialMinMaxLODsCount", e), e.type === "ShaderMaterial" || e.type === "RawShaderMaterial") {
149
+ if (y === "verbose" && console.log("getMaterialMinMaxLODsCount", e), e.type === "ShaderMaterial" || e.type === "RawShaderMaterial") {
147
150
  const n = e;
148
151
  for (const a of Object.keys(n.uniforms)) {
149
152
  const h = n.uniforms[a].value;
@@ -158,12 +161,12 @@ const w = class {
158
161
  function s(n, a) {
159
162
  const h = r.getAssignedLODInformation(n);
160
163
  if (h) {
161
- const d = r.lodInfos.get(h.key);
162
- if (d && d.lods) {
163
- a.min_count = Math.min(a.min_count, d.lods.length), a.max_count = Math.max(a.max_count, d.lods.length);
164
- for (let y = 0; y < d.lods.length; y++) {
165
- const c = d.lods[y];
166
- c.width && (a.lods[y] = a.lods[y] || { min_height: 1 / 0, max_height: 0 }, a.lods[y].min_height = Math.min(a.lods[y].min_height, c.height), a.lods[y].max_height = Math.max(a.lods[y].max_height, c.height));
164
+ const c = r.lodInfos.get(h.key);
165
+ if (c && c.lods) {
166
+ a.min_count = Math.min(a.min_count, c.lods.length), a.max_count = Math.max(a.max_count, c.lods.length);
167
+ for (let m = 0; m < c.lods.length; m++) {
168
+ const u = c.lods[m];
169
+ u.width && (a.lods[m] = a.lods[m] || { min_height: 1 / 0, max_height: 0 }, a.lods[m].min_height = Math.min(a.lods[m].min_height, u.height), a.lods[m].max_height = Math.max(a.lods[m].max_height, u.height));
167
170
  }
168
171
  }
169
172
  }
@@ -222,24 +225,24 @@ const w = class {
222
225
  var r;
223
226
  if (!e)
224
227
  return Promise.resolve(null);
225
- if (e instanceof z || e.isMesh === !0) {
228
+ if (e instanceof N || e.isMesh === !0) {
226
229
  const i = e.geometry, o = this.getAssignedLODInformation(i);
227
230
  if (!o)
228
231
  return Promise.resolve(null);
229
- for (const s of G)
232
+ for (const s of $)
230
233
  (r = s.onBeforeGetLODMesh) == null || r.call(s, e, t);
231
- return e["LOD:requested level"] = t, w.getOrLoadLOD(i, t).then((s) => {
234
+ return e["LOD:requested level"] = t, O.getOrLoadLOD(i, t).then((s) => {
232
235
  if (e["LOD:requested level"] === t) {
233
236
  if (delete e["LOD:requested level"], Array.isArray(s)) {
234
237
  const n = o.index || 0;
235
238
  s = s[n];
236
239
  }
237
- s && i != s && s instanceof H && (e.geometry = s, L && ge(e, "geometry", o.url));
240
+ s && i != s && ((s == null ? void 0 : s.isBufferGeometry) ? (e.geometry = s, y && ge(e, "geometry", o.url)) : y && console.error("Invalid LOD geometry", s));
238
241
  }
239
242
  return s;
240
243
  }).catch((s) => (console.error("Error loading mesh LOD", e, s), null));
241
244
  } else
242
- L && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", e);
245
+ y && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", e);
243
246
  return Promise.resolve(null);
244
247
  }
245
248
  /** Load a different resolution of a texture (if available)
@@ -252,9 +255,9 @@ const w = class {
252
255
  static assignTextureLOD(e, t = 0) {
253
256
  if (!e)
254
257
  return Promise.resolve(null);
255
- if (e instanceof Se || e.isMaterial === !0) {
258
+ if (e instanceof _e || e.isMaterial === !0) {
256
259
  const r = e, i = [], o = new Array();
257
- if (L && ce.add(r), r.uniforms && r.isRawShaderMaterial || r.isShaderMaterial === !0) {
260
+ if (y && ce.add(r), r.uniforms && r.isRawShaderMaterial || r.isShaderMaterial === !0) {
258
261
  const s = r;
259
262
  for (const n of Object.keys(s.uniforms)) {
260
263
  const a = s.uniforms[n].value;
@@ -274,8 +277,8 @@ const w = class {
274
277
  return Promise.all(i).then((s) => {
275
278
  const n = new Array();
276
279
  for (let a = 0; a < s.length; a++) {
277
- const h = s[a], d = o[a];
278
- h && h.isTexture === !0 ? n.push({ material: r, slot: d, texture: h, level: t }) : n.push({ material: r, slot: d, texture: null, level: t });
280
+ const h = s[a], c = o[a];
281
+ h && h.isTexture === !0 ? n.push({ material: r, slot: c, texture: h, level: t }) : n.push({ material: r, slot: c, texture: null, level: t });
279
282
  }
280
283
  return n;
281
284
  });
@@ -287,7 +290,7 @@ const w = class {
287
290
  return Promise.resolve(null);
288
291
  }
289
292
  static assignTextureLODForSlot(e, t, r, i) {
290
- return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : i === "glyphMap" ? Promise.resolve(e) : w.getOrLoadLOD(e, t).then((o) => {
293
+ return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : i === "glyphMap" ? Promise.resolve(e) : O.getOrLoadLOD(e, t).then((o) => {
291
294
  if (Array.isArray(o))
292
295
  return null;
293
296
  if ((o == null ? void 0 : o.isTexture) === !0) {
@@ -297,158 +300,161 @@ const w = class {
297
300
  if (s) {
298
301
  const n = this.getAssignedLODInformation(s);
299
302
  if (n && (n == null ? void 0 : n.level) < t)
300
- return L === "verbose" && console.warn("Assigned texture level is already higher: ", n.level, t, r, s, o), null;
303
+ return y === "verbose" && console.warn("Assigned texture level is already higher: ", n.level, t, r, s, o), null;
301
304
  }
302
305
  r[i] = o;
303
306
  }
304
- if (L && i && r) {
307
+ if (y && i && r) {
305
308
  const s = this.getAssignedLODInformation(e);
306
309
  s && ge(r, i, s.url);
307
310
  }
308
311
  }
309
312
  return o;
310
313
  } else
311
- L == "verbose" && console.warn("No LOD found for", e, t);
314
+ y == "verbose" && console.warn("No LOD found for", e, t);
312
315
  return null;
313
316
  }).catch((o) => (console.error("Error loading LOD", e, o), null));
314
317
  }
315
318
  afterRoot(e) {
316
319
  var t, r;
317
- return L && console.log("AFTER", this.url, e), (t = this.parser.json.textures) == null || t.forEach((i, o) => {
320
+ return y && console.log("AFTER", this.url, e), (t = this.parser.json.textures) == null || t.forEach((i, o) => {
321
+ var s;
318
322
  if (i != null && i.extensions) {
319
- const s = i == null ? void 0 : i.extensions[R];
320
- if (s) {
321
- if (!s.lods) {
322
- L && console.warn("Texture has no LODs", s);
323
+ const n = i == null ? void 0 : i.extensions[E];
324
+ if (n) {
325
+ if (!n.lods) {
326
+ y && console.warn("Texture has no LODs", n);
323
327
  return;
324
328
  }
325
- let n = !1;
326
- for (const a of this.parser.associations.keys())
327
- a.isTexture === !0 && this.parser.associations.get(a).textures === o && (n = !0, w.registerTexture(this.url, a, s.lods.length, o, s));
328
- n || this.parser.getDependency("texture", o).then((a) => {
329
- a && w.registerTexture(this.url, a, s.lods.length, o, s);
329
+ let a = !1;
330
+ for (const h of this.parser.associations.keys())
331
+ h.isTexture === !0 && this.parser.associations.get(h).textures === o && (a = !0, O.registerTexture(this.url, h, (s = n.lods) == null ? void 0 : s.length, o, n));
332
+ a || this.parser.getDependency("texture", o).then((h) => {
333
+ var c;
334
+ h && O.registerTexture(this.url, h, (c = n.lods) == null ? void 0 : c.length, o, n);
330
335
  });
331
336
  }
332
337
  }
333
338
  }), (r = this.parser.json.meshes) == null || r.forEach((i, o) => {
334
339
  if (i != null && i.extensions) {
335
- const s = i == null ? void 0 : i.extensions[R];
340
+ const s = i == null ? void 0 : i.extensions[E];
336
341
  if (s && s.lods) {
337
342
  for (const n of this.parser.associations.keys())
338
343
  if (n.isMesh) {
339
344
  const a = this.parser.associations.get(n);
340
- a.meshes === o && w.registerMesh(this.url, s.guid, n, s.lods.length, a.primitives, s);
345
+ a.meshes === o && O.registerMesh(this.url, s.guid, n, s.lods.length, a.primitives, s);
341
346
  }
342
347
  }
343
348
  }
344
349
  }), null;
345
350
  }
346
351
  static async getOrLoadLOD(e, t) {
347
- var n, a, h, d;
348
- const r = L == "verbose", i = e.userData.LODS;
352
+ var n, a, h, c;
353
+ const r = y == "verbose", i = e.userData.LODS;
349
354
  if (!i)
350
355
  return null;
351
356
  const o = i == null ? void 0 : i.key;
352
357
  let s;
353
358
  if (e.isTexture === !0) {
354
- const y = e;
355
- y.source && y.source[oe] && (s = y.source[oe]);
359
+ const m = e;
360
+ m.source && m.source[oe] && (s = m.source[oe]);
356
361
  }
357
- if (s || (s = w.lodInfos.get(o)), s) {
362
+ if (s || (s = O.lodInfos.get(o)), s) {
358
363
  if (t > 0) {
359
364
  let p = !1;
360
365
  const x = Array.isArray(s.lods);
361
366
  if (x && t >= s.lods.length ? p = !0 : x || (p = !0), p)
362
367
  return this.lowresCache.get(o);
363
368
  }
364
- const y = Array.isArray(s.lods) ? (n = s.lods[t]) == null ? void 0 : n.path : s.lods;
365
- if (!y)
366
- return L && !s["missing:uri"] && (s["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + t, s)), null;
367
- const c = Ce(i.url, y);
368
- if (c.endsWith(".glb") || c.endsWith(".gltf")) {
369
+ const m = Array.isArray(s.lods) ? (n = s.lods[t]) == null ? void 0 : n.path : s.lods;
370
+ if (!m)
371
+ return y && !s["missing:uri"] && (s["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + t, s)), null;
372
+ const u = Ce(i.url, m);
373
+ if (u.endsWith(".glb") || u.endsWith(".gltf")) {
369
374
  if (!s.guid)
370
375
  return console.warn("missing pointer for glb/gltf texture", s), null;
371
- const p = c + "_" + s.guid, x = this.previouslyLoaded.get(p);
376
+ const p = u + "_" + s.guid, x = this.previouslyLoaded.get(p);
372
377
  if (x !== void 0) {
373
378
  r && console.log(`LOD ${t} was already loading/loaded: ${p}`);
374
- let M = await x.catch((A) => (console.error(`Error loading LOD ${t} from ${c}
379
+ let _ = await x.catch((A) => (console.error(`Error loading LOD ${t} from ${u}
375
380
  `, A), null)), b = !1;
376
- if (M == null || (M instanceof K && e instanceof K ? (a = M.image) != null && a.data || (h = M.source) != null && h.data ? M = this.copySettings(e, M) : (b = !0, this.previouslyLoaded.delete(p)) : M instanceof H && e instanceof H && ((d = M.attributes.position) != null && d.array || (b = !0, this.previouslyLoaded.delete(p)))), !b)
377
- return M;
381
+ if (_ == null || (_ instanceof K && e instanceof K ? (a = _.image) != null && a.data || (h = _.source) != null && h.data ? _ = this.copySettings(e, _) : (b = !0, this.previouslyLoaded.delete(p)) : _ instanceof ee && e instanceof ee && ((c = _.attributes.position) != null && c.array || (b = !0, this.previouslyLoaded.delete(p)))), !b)
382
+ return _;
378
383
  }
379
- const _ = s, D = new Promise(async (M, b) => {
380
- const A = new Pe();
381
- me(A), L && (await new Promise((g) => setTimeout(g, 1e3)), r && console.warn("Start loading (delayed) " + c, _.guid));
382
- let Q = c;
383
- if (_ && Array.isArray(_.lods)) {
384
- const g = _.lods[t];
385
- g.hash && (Q += "?v=" + g.hash);
384
+ const w = s, D = new Promise(async (_, b) => {
385
+ const A = new Te();
386
+ xe(A), y && (await new Promise((g) => setTimeout(g, 1e3)), r && console.warn("Start loading (delayed) " + u, w.guid));
387
+ let J = u;
388
+ if (w && Array.isArray(w.lods)) {
389
+ const g = w.lods[t];
390
+ g.hash && (J += "?v=" + g.hash);
386
391
  }
387
- const F = await A.loadAsync(Q).catch((g) => (console.error(`Error loading LOD ${t} from ${c}
392
+ const k = await A.loadAsync(J).catch((g) => (console.error(`Error loading LOD ${t} from ${u}
388
393
  `, g), null));
389
- if (!F)
394
+ if (!k)
390
395
  return null;
391
- const U = F.parser;
392
- r && console.log("Loading finished " + c, _.guid);
393
- let E = 0;
394
- if (F.parser.json.textures) {
396
+ const U = k.parser;
397
+ r && console.log("Loading finished " + u, w.guid);
398
+ let I = 0;
399
+ if (k.parser.json.textures) {
395
400
  let g = !1;
396
- for (const u of F.parser.json.textures) {
397
- if (u != null && u.extensions) {
398
- const m = u == null ? void 0 : u.extensions[R];
399
- if (m != null && m.guid && m.guid === _.guid) {
401
+ for (const f of k.parser.json.textures) {
402
+ if (f != null && f.extensions) {
403
+ const L = f == null ? void 0 : f.extensions[E];
404
+ if (L != null && L.guid && L.guid === w.guid) {
400
405
  g = !0;
401
406
  break;
402
407
  }
403
408
  }
404
- E++;
409
+ I++;
405
410
  }
406
411
  if (g) {
407
- let u = await U.getDependency("texture", E);
408
- return u && w.assignLODInformation(i.url, u, o, t, void 0, void 0), r && console.log('change "' + e.name + '" → "' + u.name + '"', c, E, u, p), e instanceof K && (u = this.copySettings(e, u)), u && (u.guid = _.guid), M(u);
412
+ let f = await U.getDependency("texture", I);
413
+ return f && O.assignLODInformation(i.url, f, o, t, void 0, void 0), r && console.log('change "' + e.name + '" → "' + f.name + '"', u, I, f, p), e instanceof K && (f = this.copySettings(e, f)), f && (f.guid = w.guid), _(f);
409
414
  } else
410
- L && console.warn("Could not find texture with guid", _.guid);
415
+ y && console.warn("Could not find texture with guid", w.guid, k.parser.json);
411
416
  }
412
- if (E = 0, F.parser.json.meshes) {
417
+ if (I = 0, k.parser.json.meshes) {
413
418
  let g = !1;
414
- for (const u of F.parser.json.meshes) {
415
- if (u != null && u.extensions) {
416
- const m = u == null ? void 0 : u.extensions[R];
417
- if (m != null && m.guid && m.guid === _.guid) {
419
+ for (const f of k.parser.json.meshes) {
420
+ if (f != null && f.extensions) {
421
+ const L = f == null ? void 0 : f.extensions[E];
422
+ if (L != null && L.guid && L.guid === w.guid) {
418
423
  g = !0;
419
424
  break;
420
425
  }
421
426
  }
422
- E++;
427
+ I++;
423
428
  }
424
429
  if (g) {
425
- const u = await U.getDependency("mesh", E), m = _;
426
- if (r && console.log(`Loaded Mesh "${u.name}"`, c, E, u, p), u.isMesh === !0) {
427
- const S = u.geometry;
428
- return w.assignLODInformation(i.url, S, o, t, void 0, m.density), M(S);
430
+ const f = await U.getDependency("mesh", I), L = w;
431
+ if (r && console.log(`Loaded Mesh "${f.name}"`, u, I, f, p), f.isMesh === !0) {
432
+ const S = f.geometry;
433
+ return O.assignLODInformation(i.url, S, o, t, void 0, L.density), _(S);
429
434
  } else {
430
435
  const S = new Array();
431
- for (let T = 0; T < u.children.length; T++) {
432
- const I = u.children[T];
433
- if (I instanceof z) {
434
- const $ = I.geometry;
435
- w.assignLODInformation(i.url, $, o, t, T, m.density), S.push($);
436
+ for (let T = 0; T < f.children.length; T++) {
437
+ const G = f.children[T];
438
+ if (G.isMesh === !0) {
439
+ const F = G.geometry;
440
+ O.assignLODInformation(i.url, F, o, t, T, L.density), S.push(F);
436
441
  }
437
442
  }
438
- return M(S);
443
+ return _(S);
439
444
  }
440
- }
445
+ } else
446
+ y && console.warn("Could not find mesh with guid", w.guid, k.parser.json);
441
447
  }
442
- return M(null);
448
+ return _(null);
443
449
  });
444
450
  return this.previouslyLoaded.set(p, D), await D;
445
451
  } else if (e instanceof K) {
446
- r && console.log("Load texture from uri: " + c);
447
- const x = await new Te().loadAsync(c);
448
- return x ? (x.guid = s.guid, x.flipY = !1, x.needsUpdate = !0, x.colorSpace = e.colorSpace, r && console.log(s, x)) : L && console.warn("failed loading", c), x;
452
+ r && console.log("Load texture from uri: " + u);
453
+ const x = await new Oe().loadAsync(u);
454
+ return x ? (x.guid = s.guid, x.flipY = !1, x.needsUpdate = !0, x.colorSpace = e.colorSpace, r && console.log(s, x)) : y && console.warn("failed loading", u), x;
449
455
  }
450
456
  } else
451
- L && console.warn(`Can not load LOD ${t}: no LOD info found for "${o}" ${e.name}`, e.type);
457
+ y && console.warn(`Can not load LOD ${t}: no LOD info found for "${o}" ${e.name}`, e.type);
452
458
  return null;
453
459
  }
454
460
  static assignLODInformation(e, t, r, i, o, s) {
@@ -464,85 +470,85 @@ const w = class {
464
470
  }
465
471
  // private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
466
472
  static copySettings(e, t) {
467
- return t = t.clone(), L && console.warn(`Copying texture settings
473
+ return t = t.clone(), y && console.warn(`Copying texture settings
468
474
  `, e.uuid, `
469
475
  `, t.uuid), 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.mipmaps || (t.generateMipmaps = e.generateMipmaps), t;
470
476
  }
471
477
  };
472
- let v = w;
478
+ let v = O;
473
479
  /**
474
480
  * Register a texture with LOD information
475
481
  */
476
- f(v, "registerTexture", (e, t, r, i, o) => {
477
- if (L && console.log("> Progressive: register texture", i, t.name, t.uuid, t, o), !t) {
478
- L && console.error("gltf-progressive: Register texture without texture");
482
+ d(v, "registerTexture", (e, t, r, i, o) => {
483
+ if (y && console.log("> Progressive: register texture", i, t.name, t.uuid, t, o), !t) {
484
+ y && console.error("gltf-progressive: Register texture without texture");
479
485
  return;
480
486
  }
481
487
  t.source && (t.source[oe] = o);
482
488
  const s = o.guid;
483
- w.assignLODInformation(e, t, s, r, i, void 0), w.lodInfos.set(s, o), w.lowresCache.set(s, t);
489
+ O.assignLODInformation(e, t, s, r, i, void 0), O.lodInfos.set(s, o), O.lowresCache.set(s, t);
484
490
  }), /**
485
491
  * Register a mesh with LOD information
486
492
  */
487
- f(v, "registerMesh", (e, t, r, i, o, s) => {
493
+ d(v, "registerMesh", (e, t, r, i, o, s) => {
488
494
  var h;
489
- L && console.log("> Progressive: register mesh", o, r.name, s, r.uuid, r);
495
+ y && console.log("> Progressive: register mesh", o, r.name, s, r.uuid, r);
490
496
  const n = r.geometry;
491
497
  if (!n) {
492
- L && console.warn("gltf-progressive: Register mesh without geometry");
498
+ y && console.warn("gltf-progressive: Register mesh without geometry");
493
499
  return;
494
500
  }
495
- n.userData || (n.userData = {}), w.assignLODInformation(e, n, t, i, o, s.density), w.lodInfos.set(t, s);
496
- let a = w.lowresCache.get(t);
497
- a ? a.push(r.geometry) : a = [r.geometry], w.lowresCache.set(t, a), i > 0 && !fe(r) && ke(r, n);
498
- for (const d of G)
499
- (h = d.onRegisteredNewMesh) == null || h.call(d, r, s);
501
+ n.userData || (n.userData = {}), O.assignLODInformation(e, n, t, i, o, s.density), O.lodInfos.set(t, s);
502
+ let a = O.lowresCache.get(t);
503
+ a ? a.push(r.geometry) : a = [r.geometry], O.lowresCache.set(t, a), i > 0 && !fe(r) && ke(r, n);
504
+ for (const c of $)
505
+ (h = c.onRegisteredNewMesh) == null || h.call(c, r, s);
500
506
  }), /** A map of key = asset uuid and value = LOD information */
501
- f(v, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
502
- f(v, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
503
- f(v, "lowresCache", /* @__PURE__ */ new Map());
507
+ d(v, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
508
+ d(v, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
509
+ d(v, "lowresCache", /* @__PURE__ */ new Map());
504
510
  class Ee {
505
511
  constructor(e, t, r, i, o) {
506
- f(this, "url");
512
+ d(this, "url");
507
513
  /** the key to lookup the LOD information */
508
- f(this, "key");
509
- f(this, "level");
514
+ d(this, "key");
515
+ d(this, "level");
510
516
  /** For multi objects (e.g. a group of meshes) this is the index of the object */
511
- f(this, "index");
517
+ d(this, "index");
512
518
  /** the mesh density */
513
- f(this, "density");
519
+ d(this, "density");
514
520
  this.url = e, this.key = t, this.level = r, i != null && (this.index = i), o != null && (this.density = o);
515
521
  }
516
522
  }
517
- const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:LODSManager"), ne = Symbol("Needle:LODState"), W = Symbol("Needle:CurrentLOD"), C = { mesh_lod: -1, texture_lod: -1 }, P = class {
523
+ const z = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:LODSManager"), ne = Symbol("Needle:LODState"), W = Symbol("Needle:CurrentLOD"), C = { mesh_lod: -1, texture_lod: -1 }, P = class {
518
524
  // readonly plugins: NEEDLE_progressive_plugin[] = [];
519
525
  constructor(e) {
520
- f(this, "renderer");
521
- f(this, "projectionScreenMatrix", new de());
522
- f(this, "cameraFrustrum", new be());
526
+ d(this, "renderer");
527
+ d(this, "projectionScreenMatrix", new de());
528
+ d(this, "cameraFrustrum", new ve());
523
529
  /**
524
530
  * The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
525
531
  * @default 200_000
526
532
  */
527
- f(this, "targetTriangleDensity", 2e5);
533
+ d(this, "targetTriangleDensity", 2e5);
528
534
  /**
529
535
  * 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.
530
536
  */
531
- f(this, "updateInterval", 0);
537
+ d(this, "updateInterval", 0);
532
538
  /**
533
539
  * If set to true, the LODsManager will not update the LODs.
534
540
  */
535
- f(this, "pause", !1);
536
- f(this, "_frame", 0);
537
- f(this, "_originalRender");
541
+ d(this, "pause", !1);
542
+ d(this, "_frame", 0);
543
+ d(this, "_originalRender");
538
544
  // private testIfLODLevelsAreAvailable() {
539
- f(this, "_sphere", new Ae());
540
- f(this, "_tempBox", new he());
541
- f(this, "_tempBox2", new he());
542
- f(this, "tempMatrix", new de());
543
- f(this, "_tempWorldPosition", new k());
544
- f(this, "_tempBoxSize", new k());
545
- f(this, "_tempBox2Size", new k());
545
+ d(this, "_sphere", new Se());
546
+ d(this, "_tempBox", new he());
547
+ d(this, "_tempBox2", new he());
548
+ d(this, "tempMatrix", new de());
549
+ d(this, "_tempWorldPosition", new R());
550
+ d(this, "_tempBoxSize", new R());
551
+ d(this, "_tempBox2Size", new R());
546
552
  this.renderer = e;
547
553
  }
548
554
  /** @internal */
@@ -550,11 +556,11 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
550
556
  return e[ne];
551
557
  }
552
558
  static addPlugin(e) {
553
- G.push(e);
559
+ $.push(e);
554
560
  }
555
561
  static removePlugin(e) {
556
- const t = G.indexOf(e);
557
- t >= 0 && G.splice(t, 1);
562
+ const t = $.indexOf(e);
563
+ t >= 0 && $.splice(t, 1);
558
564
  }
559
565
  /**
560
566
  * Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
@@ -566,7 +572,7 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
566
572
  }
567
573
  /** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
568
574
  get plugins() {
569
- return G;
575
+ return $;
570
576
  }
571
577
  /**
572
578
  * Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
@@ -577,7 +583,7 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
577
583
  let e = 0;
578
584
  this._originalRender = this.renderer.render;
579
585
  const t = this;
580
- xe(this.renderer), this.renderer.render = function(r, i) {
586
+ me(this.renderer), this.renderer.render = function(r, i) {
581
587
  t.renderer.getRenderTarget() == null && (e = 0, t._frame += 1);
582
588
  const s = t._frame, n = e++;
583
589
  t.onBeforeRender(r, i, n, s), t._originalRender.call(this, r, i), t.onAfterRender(r, i, n, s);
@@ -595,20 +601,20 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
595
601
  const o = this.renderer.renderLists.get(e, 0), s = o.opaque;
596
602
  let n = !0;
597
603
  if (s.length === 1) {
598
- const d = s[0].material;
599
- (d.name === "EffectMaterial" || d.name === "CopyShader") && (n = !1);
604
+ const c = s[0].material;
605
+ (c.name === "EffectMaterial" || c.name === "CopyShader") && (n = !1);
600
606
  }
601
607
  if ((t.parent && t.parent.type === "CubeCamera" || r >= 1 && t.type === "OrthographicCamera") && (n = !1), n) {
602
608
  if (Ie || this.updateInterval > 0 && i % this.updateInterval != 0)
603
609
  return;
604
610
  this.projectionScreenMatrix.multiplyMatrices(t.projectionMatrix, t.matrixWorldInverse), this.cameraFrustrum.setFromProjectionMatrix(this.projectionScreenMatrix, this.renderer.coordinateSystem);
605
- const d = this.targetTriangleDensity;
606
- for (const c of s) {
607
- if (c.material && (((a = c.geometry) == null ? void 0 : a.type) === "BoxGeometry" || ((h = c.geometry) == null ? void 0 : h.type) === "BufferGeometry") && (c.material.name === "SphericalGaussianBlur" || c.material.name == "BackgroundCubeMaterial" || c.material.name === "CubemapFromEquirect" || c.material.name === "EquirectangularToCubeUV")) {
608
- N && (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)));
611
+ const c = this.targetTriangleDensity;
612
+ for (const u of s) {
613
+ if (u.material && (((a = u.geometry) == null ? void 0 : a.type) === "BoxGeometry" || ((h = u.geometry) == null ? void 0 : h.type) === "BufferGeometry") && (u.material.name === "SphericalGaussianBlur" || u.material.name == "BackgroundCubeMaterial" || u.material.name === "CubemapFromEquirect" || u.material.name === "EquirectangularToCubeUV")) {
614
+ z && (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)));
609
615
  continue;
610
616
  }
611
- switch (c.material.type) {
617
+ switch (u.material.type) {
612
618
  case "LineBasicMaterial":
613
619
  case "LineDashedMaterial":
614
620
  case "PointsMaterial":
@@ -617,13 +623,13 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
617
623
  case "MeshDepthMaterial":
618
624
  continue;
619
625
  }
620
- const p = c.object;
621
- (p instanceof z || p.isMesh) && this.updateLODs(e, t, p, d, i);
626
+ const p = u.object;
627
+ (p instanceof N || p.isMesh) && this.updateLODs(e, t, p, c, i);
622
628
  }
623
- const y = o.transparent;
624
- for (const c of y) {
625
- const p = c.object;
626
- (p instanceof z || p.isMesh) && this.updateLODs(e, t, p, d, i);
629
+ const m = o.transparent;
630
+ for (const u of m) {
631
+ const p = u.object;
632
+ (p instanceof N || p.isMesh) && this.updateLODs(e, t, p, c, i);
627
633
  }
628
634
  }
629
635
  }
@@ -634,16 +640,16 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
634
640
  let s = r[ne];
635
641
  if (s || (s = new Ge(), r[ne] = s), s.frames++ < 2)
636
642
  return;
637
- for (const d of G)
638
- (a = d.onBeforeUpdateLOD) == null || a.call(d, this.renderer, e, t, r);
643
+ for (const c of $)
644
+ (a = c.onBeforeUpdateLOD) == null || a.call(c, this.renderer, e, t, r);
639
645
  this.calculateLodLevel(t, r, s, i, C), C.mesh_lod = Math.round(C.mesh_lod), C.texture_lod = Math.round(C.texture_lod), C.mesh_lod >= 0 && this.loadProgressiveMeshes(r, C.mesh_lod);
640
646
  let n = C.texture_lod;
641
647
  if (r.material && n >= 0) {
642
- const d = r["DEBUG:LOD"];
643
- d != null && (n = d), this.loadProgressiveTextures(r.material, n);
648
+ const c = r["DEBUG:LOD"];
649
+ c != null && (n = c), this.loadProgressiveTextures(r.material, n);
644
650
  }
645
- for (const d of G)
646
- (h = d.onAfterUpdatedLOD) == null || h.call(d, this.renderer, e, t, r, C);
651
+ for (const c of $)
652
+ (h = c.onAfterUpdatedLOD) == null || h.call(c, this.renderer, e, t, r, C);
647
653
  s.lastLodLevel_Mesh = C.mesh_lod, s.lastLodLevel_Texture = C.texture_lod;
648
654
  }
649
655
  /** Load progressive textures for the given material
@@ -683,7 +689,7 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
683
689
  return this._tempPtInside.set(o, s, r.z).applyMatrix4(t).z < 0;
684
690
  }
685
691
  calculateLodLevel(e, t, r, i, o) {
686
- var _;
692
+ var w;
687
693
  if (!t) {
688
694
  o.mesh_lod = -1, o.texture_lod = -1;
689
695
  return;
@@ -693,14 +699,14 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
693
699
  return;
694
700
  }
695
701
  let n = 10 + 1, a = !1;
696
- if (N && t["DEBUG:LOD"] != null)
702
+ if (z && t["DEBUG:LOD"] != null)
697
703
  return t["DEBUG:LOD"];
698
- const h = v.getMeshLODInformation(t.geometry), d = h == null ? void 0 : h.lods, y = d && d.length > 0, c = v.getMaterialMinMaxLODsCount(t.material), p = (c == null ? void 0 : c.min_count) != 1 / 0 && c.min_count > 0 && c.max_count > 0;
699
- if (!y && !p) {
704
+ const h = v.getMeshLODInformation(t.geometry), c = h == null ? void 0 : h.lods, m = c && c.length > 0, u = v.getMaterialMinMaxLODsCount(t.material), p = (u == null ? void 0 : u.min_count) != 1 / 0 && u.min_count > 0 && u.max_count > 0;
705
+ if (!m && !p) {
700
706
  o.mesh_lod = 0, o.texture_lod = 0;
701
707
  return;
702
708
  }
703
- if (y || (a = !0, n = 0), !((_ = this.cameraFrustrum) != null && _.intersectsObject(t))) {
709
+ if (m || (a = !0, n = 0), !((w = this.cameraFrustrum) != null && w.intersectsObject(t))) {
704
710
  o.mesh_lod = 99, o.texture_lod = 99;
705
711
  return;
706
712
  }
@@ -724,49 +730,53 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
724
730
  return;
725
731
  }
726
732
  if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && D.fov > 70) {
727
- const g = this._tempBox.min, u = this._tempBox.max;
728
- let m = g.x, S = g.y, T = u.x, I = u.y;
729
- const $ = 2, se = 1.5, Z = (g.x + u.x) * 0.5, j = (g.y + u.y) * 0.5;
730
- m = (m - Z) * $ + Z, S = (S - j) * $ + j, T = (T - Z) * $ + Z, I = (I - j) * $ + j;
731
- const Le = m < 0 && T > 0 ? 0 : Math.min(Math.abs(g.x), Math.abs(u.x)), De = S < 0 && I > 0 ? 0 : Math.min(Math.abs(g.y), Math.abs(u.y)), ie = Math.max(Le, De);
733
+ const g = this._tempBox.min, f = this._tempBox.max;
734
+ let L = g.x, S = g.y, T = f.x, G = f.y;
735
+ const F = 2, se = 1.5, Q = (g.x + f.x) * 0.5, Z = (g.y + f.y) * 0.5;
736
+ L = (L - Q) * F + Q, S = (S - Z) * F + Z, T = (T - Q) * F + Q, G = (G - Z) * F + Z;
737
+ const Le = L < 0 && T > 0 ? 0 : Math.min(Math.abs(g.x), Math.abs(f.x)), Me = S < 0 && G > 0 ? 0 : Math.min(Math.abs(g.y), Math.abs(f.y)), ie = Math.max(Le, Me);
732
738
  r.lastCentrality = (se - ie) * (se - ie) * (se - ie);
733
739
  } else
734
740
  r.lastCentrality = 1;
735
- const O = this._tempBox.getSize(this._tempBoxSize);
736
- O.multiplyScalar(0.5), screen.availHeight > 0 && O.multiplyScalar(this.renderer.domElement.clientHeight / screen.availHeight), O.x *= D.aspect;
737
- const M = e.matrixWorldInverse, b = this._tempBox2;
738
- b.copy(x), b.applyMatrix4(t.matrixWorld), b.applyMatrix4(M);
739
- const A = b.getSize(this._tempBox2Size), Q = Math.max(A.x, A.y);
740
- if (Math.max(O.x, O.y) != 0 && Q != 0 && (O.z = A.z / Math.max(A.x, A.y) * Math.max(O.x, O.y)), r.lastScreenCoverage = Math.max(O.x, O.y, O.z), r.lastScreenspaceVolume.copy(O), r.lastScreenCoverage *= r.lastCentrality, N && P.debugDrawLine) {
741
+ const M = this._tempBox.getSize(this._tempBoxSize);
742
+ M.multiplyScalar(0.5), screen.availHeight > 0 && M.multiplyScalar(this.renderer.domElement.clientHeight / screen.availHeight), M.x *= D.aspect;
743
+ const _ = e.matrixWorldInverse, b = this._tempBox2;
744
+ b.copy(x), b.applyMatrix4(t.matrixWorld), b.applyMatrix4(_);
745
+ const A = b.getSize(this._tempBox2Size), J = Math.max(A.x, A.y);
746
+ if (Math.max(M.x, M.y) != 0 && J != 0 && (M.z = A.z / Math.max(A.x, A.y) * Math.max(M.x, M.y)), r.lastScreenCoverage = Math.max(M.x, M.y, M.z), r.lastScreenspaceVolume.copy(M), r.lastScreenCoverage *= r.lastCentrality, z && P.debugDrawLine) {
741
747
  const g = this.tempMatrix.copy(this.projectionScreenMatrix);
742
748
  g.invert();
743
- const u = P.corner0, m = P.corner1, S = P.corner2, T = P.corner3;
744
- u.copy(this._tempBox.min), m.copy(this._tempBox.max), m.x = u.x, S.copy(this._tempBox.max), S.y = u.y, T.copy(this._tempBox.max);
745
- const I = (u.z + T.z) * 0.5;
746
- u.z = m.z = S.z = T.z = I, u.applyMatrix4(g), m.applyMatrix4(g), S.applyMatrix4(g), T.applyMatrix4(g), P.debugDrawLine(u, m, 255), P.debugDrawLine(u, S, 255), P.debugDrawLine(m, T, 255), P.debugDrawLine(S, T, 255);
749
+ const f = P.corner0, L = P.corner1, S = P.corner2, T = P.corner3;
750
+ f.copy(this._tempBox.min), L.copy(this._tempBox.max), L.x = f.x, S.copy(this._tempBox.max), S.y = f.y, T.copy(this._tempBox.max);
751
+ const G = (f.z + T.z) * 0.5;
752
+ f.z = L.z = S.z = T.z = G, f.applyMatrix4(g), L.applyMatrix4(g), S.applyMatrix4(g), T.applyMatrix4(g), P.debugDrawLine(f, L, 255), P.debugDrawLine(f, S, 255), P.debugDrawLine(L, T, 255), P.debugDrawLine(S, T, 255);
747
753
  }
748
754
  let U = 999;
749
- if (d && r.lastScreenCoverage > 0) {
750
- for (let g = 0; g < d.length; g++)
751
- if (d[g].density / r.lastScreenCoverage < i) {
755
+ if (c && r.lastScreenCoverage > 0) {
756
+ for (let g = 0; g < c.length; g++)
757
+ if (c[g].density / r.lastScreenCoverage < i) {
752
758
  U = g;
753
759
  break;
754
760
  }
755
761
  }
756
762
  U < n && (n = U, a = !0);
757
763
  }
758
- if (a ? o.mesh_lod = n : o.mesh_lod = r.lastLodLevel_Mesh, p)
764
+ if (a ? o.mesh_lod = n : o.mesh_lod = r.lastLodLevel_Mesh, z && o.mesh_lod != r.lastLodLevel_Mesh) {
765
+ const M = c == null ? void 0 : c[o.mesh_lod];
766
+ M && console.log(`Mesh LOD changed: ${r.lastLodLevel_Mesh} → ${o.mesh_lod} (${M.density.toFixed(0)}) - ${t.name}`);
767
+ }
768
+ if (p)
759
769
  if (r.lastLodLevel_Texture < 0) {
760
- if (o.texture_lod = c.max_count - 1, N) {
761
- const D = c.lods[c.max_count - 1];
762
- N && console.log(`First Texture LOD ${o.texture_lod} (${D.max_height}px) - ${t.name}`);
770
+ if (o.texture_lod = u.max_count - 1, z) {
771
+ const D = u.lods[u.max_count - 1];
772
+ z && console.log(`First Texture LOD ${o.texture_lod} (${D.max_height}px) - ${t.name}`);
763
773
  }
764
774
  } else {
765
- const D = r.lastScreenCoverage * 1.5, M = this.renderer.domElement.clientHeight / window.devicePixelRatio * D;
766
- for (let b = c.lods.length - 1; b >= 0; b--) {
767
- const A = c.lods[b];
768
- if (!(Be() && A.max_height > 4096) && A.max_height > M) {
769
- o.texture_lod = b, o.texture_lod < r.lastLodLevel_Texture && N && console.log(`Texture LOD changed ${r.lastLodLevel_Texture} → ${o.texture_lod} (${A.max_height}px: ${(100 * r.lastScreenCoverage).toFixed(2)} % = ${M.toFixed(0)}px) - ${t.name}`);
775
+ const D = r.lastScreenCoverage * 1.5, _ = this.renderer.domElement.clientHeight / window.devicePixelRatio * D;
776
+ for (let b = u.lods.length - 1; b >= 0; b--) {
777
+ const A = u.lods[b];
778
+ if (!(Be() && A.max_height > 4096) && A.max_height > _) {
779
+ o.texture_lod = b, o.texture_lod < r.lastLodLevel_Texture && z && console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} → ${o.texture_lod} (${A.max_height}px: ${(100 * r.lastScreenCoverage).toFixed(2)} % = ${_.toFixed(0)}px) - ${t.name}`);
770
780
  break;
771
781
  }
772
782
  }
@@ -778,19 +788,19 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
778
788
  let B = P;
779
789
  /** 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.
780
790
  */
781
- f(B, "debugDrawLine"), f(B, "corner0", new k()), f(B, "corner1", new k()), f(B, "corner2", new k()), f(B, "corner3", new k()), f(B, "_tempPtInside", new k());
791
+ d(B, "debugDrawLine"), d(B, "corner0", new R()), d(B, "corner1", new R()), d(B, "corner2", new R()), d(B, "corner3", new R()), d(B, "_tempPtInside", new R());
782
792
  class Ge {
783
793
  constructor() {
784
- f(this, "frames", 0);
785
- f(this, "lastLodLevel_Mesh", -1);
786
- f(this, "lastLodLevel_Texture", -1);
787
- f(this, "lastScreenCoverage", 0);
788
- f(this, "lastScreenspaceVolume", new k());
789
- f(this, "lastCentrality", 0);
794
+ d(this, "frames", 0);
795
+ d(this, "lastLodLevel_Mesh", -1);
796
+ d(this, "lastLodLevel_Texture", -1);
797
+ d(this, "lastScreenCoverage", 0);
798
+ d(this, "lastScreenspaceVolume", new R());
799
+ d(this, "lastCentrality", 0);
790
800
  }
791
801
  }
792
- const ye = Symbol("NEEDLE_mesh_lod"), ee = Symbol("NEEDLE_texture_lod");
793
- function Fe(l) {
802
+ const ye = Symbol("NEEDLE_mesh_lod"), j = Symbol("NEEDLE_texture_lod");
803
+ function $e(l) {
794
804
  if (!l)
795
805
  return null;
796
806
  let e = null, t = null;
@@ -799,9 +809,8 @@ function Fe(l) {
799
809
  !e && o != null && (e = l[o].threeRenderer), !t && s != null && (t = l[s]);
800
810
  }
801
811
  if (e) {
802
- console.log("Adding Needle LODs to modelviewer");
803
812
  const r = B.get(e);
804
- if (B.addPlugin(new $e(l)), r.enable(), t) {
813
+ if (B.addPlugin(new Fe(l)), r.enable(), t) {
805
814
  const i = t.camera || t.traverse((o) => o.type == "PerspectiveCamera")[0];
806
815
  i && e.render(t, i);
807
816
  }
@@ -811,10 +820,10 @@ function Fe(l) {
811
820
  }
812
821
  return null;
813
822
  }
814
- class $e {
823
+ class Fe {
815
824
  constructor(e) {
816
- f(this, "modelviewer");
817
- f(this, "_didWarnAboutMissingUrl", !1);
825
+ d(this, "modelviewer");
826
+ d(this, "_didWarnAboutMissingUrl", !1);
818
827
  this.modelviewer = e;
819
828
  }
820
829
  onBeforeUpdateLOD(e, t, r, i) {
@@ -828,28 +837,28 @@ class $e {
828
837
  return e._currentGLTF;
829
838
  }
830
839
  tryParseTextureLOD(e, t) {
831
- if (t[ee] == !0)
840
+ if (t[j] == !0)
832
841
  return;
833
- t[ee] = !0;
842
+ t[j] = !0;
834
843
  const r = this.tryGetCurrentGLTF(e), i = this.getUrl();
835
844
  if (i && r && t.material) {
836
845
  let o = function(n) {
837
- var h, d, y;
838
- if (n[ee] == !0)
846
+ var h, c, m;
847
+ if (n[j] == !0)
839
848
  return;
840
- n[ee] = !0, n.userData && (n.userData.LOD = -1);
849
+ n[j] = !0, n.userData && (n.userData.LOD = -1);
841
850
  const a = Object.keys(n);
842
- for (let c = 0; c < a.length; c++) {
843
- const p = a[c], x = n[p];
851
+ for (let u = 0; u < a.length; u++) {
852
+ const p = a[u], x = n[p];
844
853
  if ((x == null ? void 0 : x.isTexture) === !0) {
845
- const _ = (d = (h = x.userData) == null ? void 0 : h.associations) == null ? void 0 : d.textures, D = r.parser.json.textures[_];
854
+ const w = (c = (h = x.userData) == null ? void 0 : h.associations) == null ? void 0 : c.textures, D = r.parser.json.textures[w];
846
855
  if (!D) {
847
- console.warn("Texture data not found for texture index " + _);
856
+ console.warn("Texture data not found for texture index " + w);
848
857
  continue;
849
858
  }
850
- if ((y = D == null ? void 0 : D.extensions) != null && y[R]) {
851
- const O = D.extensions[R];
852
- O && i && v.registerTexture(i, x, O.lods.length, _, O);
859
+ if ((m = D == null ? void 0 : D.extensions) != null && m[E]) {
860
+ const M = D.extensions[E];
861
+ M && i && v.registerTexture(i, x, M.lods.length, w, M);
853
862
  }
854
863
  }
855
864
  }
@@ -870,29 +879,29 @@ class $e {
870
879
  const r = this.getUrl();
871
880
  if (!r)
872
881
  return;
873
- const i = (s = (o = t.userData) == null ? void 0 : o.gltfExtensions) == null ? void 0 : s[R];
882
+ const i = (s = (o = t.userData) == null ? void 0 : o.gltfExtensions) == null ? void 0 : s[E];
874
883
  if (i && r) {
875
884
  const n = t.uuid;
876
885
  v.registerMesh(r, n, t, 0, i.lods.length, i);
877
886
  }
878
887
  }
879
888
  }
889
+ document.addEventListener("DOMContentLoaded", () => {
890
+ $e(document.querySelector("model-viewer"));
891
+ });
880
892
  function He(l, e, t, r) {
881
- xe(e), me(t), t.register((o) => new v(o, l));
893
+ me(e), xe(t), t.register((o) => new v(o, l));
882
894
  const i = B.get(e);
883
895
  return (r == null ? void 0 : r.enableLODsManager) !== !1 && i.enable(), i;
884
896
  }
885
- document.addEventListener("DOMContentLoaded", () => {
886
- Fe(document.querySelector("model-viewer"));
887
- });
888
897
  export {
889
- R as EXTENSION_NAME,
898
+ E as EXTENSION_NAME,
890
899
  B as LODsManager,
891
900
  v as NEEDLE_progressive,
892
- me as addDracoAndKTX2Loaders,
893
- xe as createLoaders,
901
+ xe as addDracoAndKTX2Loaders,
902
+ me as createLoaders,
894
903
  fe as getRaycastMesh,
895
- Fe as patchModelViewer,
904
+ $e as patchModelViewer,
896
905
  Xe as setDracoDecoderLocation,
897
906
  Ye as setKTX2TranscoderLocation,
898
907
  ke as setRaycastMesh,