@needle-tools/gltf-progressive 1.2.2-alpha.1 → 1.2.2-alpha.2

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,37 +1,37 @@
1
- var _e = Object.defineProperty;
2
- var Se = (l, e, t) => e in l ? _e(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
3
- var h = (l, e, t) => (Se(l, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { BufferGeometry as re, Mesh as V, Material as be, Texture as K, TextureLoader as Te, Matrix4 as pe, Frustum as Ae, Sphere as Pe, Box3 as ye, Vector3 as I } from "three";
5
- import { GLTFLoader as Ce } from "three/examples/jsm/loaders/GLTFLoader.js";
6
- import { MeshoptDecoder as Re } from "three/examples/jsm/libs/meshopt_decoder.module.js";
7
- import { DRACOLoader as Be } from "three/examples/jsm/loaders/DRACOLoader.js";
8
- import { KTX2Loader as Ee } from "three/examples/jsm/loaders/KTX2Loader.js";
9
- const Me = "";
10
- globalThis.GLTF_PROGRESSIVE_VERSION = Me;
11
- console.debug(`[gltf-progressive] version ${Me}`);
12
- let se = "https://www.gstatic.com/draco/versioned/decoders/1.4.1/", he = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
13
- fetch(se + "draco_decoder.js", { method: "head" }).catch((l) => {
14
- se = "./include/draco/", he = "./include/ktx2/";
1
+ var Se = Object.defineProperty;
2
+ var be = (l, e, t) => e in l ? Se(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
3
+ var d = (l, e, t) => (be(l, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { BufferGeometry as se, Mesh as W, Material as Te, Texture as q, TextureLoader as Ae, Matrix4 as ye, Frustum as Pe, Sphere as Ce, Box3 as me, Vector3 as G } from "three";
5
+ import { GLTFLoader as Re } 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 Ee } from "three/examples/jsm/loaders/DRACOLoader.js";
8
+ import { KTX2Loader as ke } from "three/examples/jsm/loaders/KTX2Loader.js";
9
+ const De = "";
10
+ globalThis.GLTF_PROGRESSIVE_VERSION = De;
11
+ console.debug(`[gltf-progressive] version ${De}`);
12
+ let ie = "https://www.gstatic.com/draco/versioned/decoders/1.4.1/", ge = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
13
+ fetch(ie + "draco_decoder.js", { method: "head" }).catch((l) => {
14
+ ie = "./include/draco/", ge = "./include/ktx2/";
15
15
  });
16
- function Qe(l) {
17
- se = l;
18
- }
19
16
  function Ze(l) {
20
- he = l;
17
+ ie = l;
21
18
  }
22
- let Y, ue, H;
23
- function De(l) {
24
- Y || (Y = new Be(), Y.setDecoderPath(se), Y.setDecoderConfig({ type: "js" })), H || (H = new Ee(), H.setTranscoderPath(he)), ue || (ue = Re), l ? H.detectSupport(l) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
19
+ function je(l) {
20
+ ge = l;
25
21
  }
22
+ let H, fe, J;
26
23
  function we(l) {
27
- l.dracoLoader || l.setDRACOLoader(Y), l.ktx2Loader || l.setKTX2Loader(H), l.meshoptDecoder || l.setMeshoptDecoder(ue);
24
+ H || (H = new Ee(), H.setDecoderPath(ie), H.setDecoderConfig({ type: "js" })), J || (J = new ke(), J.setTranscoderPath(ge)), fe || (fe = Be), l ? J.detectSupport(l) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
25
+ }
26
+ function ve(l) {
27
+ l.dracoLoader || l.setDRACOLoader(H), l.ktx2Loader || l.setKTX2Loader(J), l.meshoptDecoder || l.setMeshoptDecoder(fe);
28
28
  }
29
- Q("debugprogressive");
30
- function Q(l) {
29
+ Z("debugprogressive");
30
+ function Z(l) {
31
31
  const t = new URL(window.location.href).searchParams.get(l);
32
32
  return t == null || t === "0" || t === "false" ? !1 : t === "" ? !0 : t;
33
33
  }
34
- function ke(l, e) {
34
+ function Ie(l, e) {
35
35
  if (e === void 0 || e.startsWith("./") || e.startsWith("http") || l === void 0)
36
36
  return e;
37
37
  const t = l.lastIndexOf("/");
@@ -43,55 +43,55 @@ function ke(l, e) {
43
43
  }
44
44
  return e;
45
45
  }
46
- let q;
47
- function Ie() {
48
- return q !== void 0 || (q = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), Q("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", q)), q;
46
+ let X;
47
+ function Ge() {
48
+ return X !== void 0 || (X = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), Z("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", X)), X;
49
49
  }
50
- const fe = Symbol("needle:raycast-mesh");
51
- function ge(l) {
52
- return (l == null ? void 0 : l[fe]) instanceof re ? l[fe] : null;
50
+ const de = Symbol("needle:raycast-mesh");
51
+ function pe(l) {
52
+ return (l == null ? void 0 : l[de]) instanceof se ? l[de] : null;
53
53
  }
54
- function Ge(l, e) {
55
- if ((l.type === "Mesh" || l.type === "SkinnedMesh") && !ge(l)) {
56
- const r = Fe(e);
57
- r.userData = { isRaycastMesh: !0 }, l[fe] = r;
54
+ function Fe(l, e) {
55
+ if ((l.type === "Mesh" || l.type === "SkinnedMesh") && !pe(l)) {
56
+ const r = $e(e);
57
+ r.userData = { isRaycastMesh: !0 }, l[de] = r;
58
58
  }
59
59
  }
60
- function je(l = !0) {
60
+ function et(l = !0) {
61
61
  if (l) {
62
- if (X)
62
+ if (Y)
63
63
  return;
64
- const e = X = V.prototype.raycast;
65
- V.prototype.raycast = function(t, r) {
66
- const n = this, i = ge(n);
64
+ const e = Y = W.prototype.raycast;
65
+ W.prototype.raycast = function(t, r) {
66
+ const n = this, i = pe(n);
67
67
  let s;
68
68
  i && n.isMesh && (s = n.geometry, n.geometry = i), e.call(this, t, r), s && (n.geometry = s);
69
69
  };
70
70
  } else {
71
- if (!X)
71
+ if (!Y)
72
72
  return;
73
- V.prototype.raycast = X, X = null;
73
+ W.prototype.raycast = Y, Y = null;
74
74
  }
75
75
  }
76
- let X = null;
77
- function Fe(l) {
78
- const e = new re();
76
+ let Y = null;
77
+ function $e(l) {
78
+ const e = new se();
79
79
  for (const t in l.attributes)
80
80
  e.setAttribute(t, l.getAttribute(t));
81
81
  return e.setIndex(l.getIndex()), e;
82
82
  }
83
- const $ = new Array(), G = "NEEDLE_progressive", m = Q("debugprogressive"), oe = Symbol("needle-progressive-texture"), J = /* @__PURE__ */ new Map(), de = /* @__PURE__ */ new Set();
83
+ const z = new Array(), F = "NEEDLE_progressive", m = Z("debugprogressive"), ae = Symbol("needle-progressive-texture"), Q = /* @__PURE__ */ new Map(), he = /* @__PURE__ */ new Set();
84
84
  if (m) {
85
85
  let l = function() {
86
- e += 1, console.log("Toggle LOD level", e, J), J.forEach((n, i) => {
86
+ e += 1, console.log("Toggle LOD level", e, Q), Q.forEach((n, i) => {
87
87
  for (const s of n.keys) {
88
88
  const o = i[s];
89
89
  if (o != null) {
90
90
  if (o.isBufferGeometry === !0) {
91
- const a = O.getMeshLODInformation(o), d = a ? Math.min(e, a.lods.length) : 0;
92
- i["DEBUG:LOD"] = e, O.assignMeshLOD(i, d), a && (t = Math.max(t, a.lods.length - 1));
91
+ const a = _.getMeshLODInformation(o), f = a ? Math.min(e, a.lods.length) : 0;
92
+ i["DEBUG:LOD"] = e, _.assignMeshLOD(i, f), a && (t = Math.max(t, a.lods.length - 1));
93
93
  } else if (i.isMaterial === !0) {
94
- i["DEBUG:LOD"] = e, O.assignTextureLOD(i, e);
94
+ i["DEBUG:LOD"] = e, _.assignTextureLOD(i, e);
95
95
  break;
96
96
  }
97
97
  }
@@ -99,39 +99,39 @@ if (m) {
99
99
  }), e >= t && (e = -1);
100
100
  }, e = -1, t = 2, r = !1;
101
101
  window.addEventListener("keyup", (n) => {
102
- n.key === "p" && l(), n.key === "w" && (r = !r, de && de.forEach((i) => {
102
+ n.key === "p" && l(), n.key === "w" && (r = !r, he && he.forEach((i) => {
103
103
  i.name != "BackgroundCubeMaterial" && i.glyphMap == null && "wireframe" in i && (i.wireframe = r);
104
104
  }));
105
105
  });
106
106
  }
107
- function me(l, e, t) {
107
+ function xe(l, e, t) {
108
108
  var n;
109
109
  if (!m)
110
110
  return;
111
- J.has(l) || J.set(l, { keys: [], sourceId: t });
112
- const r = J.get(l);
111
+ Q.has(l) || Q.set(l, { keys: [], sourceId: t });
112
+ const r = Q.get(l);
113
113
  ((n = r == null ? void 0 : r.keys) == null ? void 0 : n.includes(e)) == !1 && r.keys.push(e);
114
114
  }
115
- const D = class {
115
+ const O = class {
116
116
  constructor(e, t) {
117
- h(this, "parser");
118
- h(this, "url");
119
- h(this, "_isLoadingMesh");
120
- h(this, "loadMesh", (e) => {
117
+ d(this, "parser");
118
+ d(this, "url");
119
+ d(this, "_isLoadingMesh");
120
+ d(this, "loadMesh", (e) => {
121
121
  var r, n;
122
122
  if (this._isLoadingMesh)
123
123
  return null;
124
- const t = (n = (r = this.parser.json.meshes[e]) == null ? void 0 : r.extensions) == null ? void 0 : n[G];
124
+ const t = (n = (r = this.parser.json.meshes[e]) == null ? void 0 : r.extensions) == null ? void 0 : n[F];
125
125
  return t ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", e).then((i) => {
126
126
  var s;
127
- return this._isLoadingMesh = !1, i && D.registerMesh(this.url, t.guid, i, (s = t.lods) == null ? void 0 : s.length, void 0, t), i;
127
+ return this._isLoadingMesh = !1, i && O.registerMesh(this.url, t.guid, i, (s = t.lods) == null ? void 0 : s.length, void 0, t), i;
128
128
  })) : null;
129
129
  });
130
130
  m && console.log("Progressive extension registered for", t), this.parser = e, this.url = t;
131
131
  }
132
132
  /** The name of the extension */
133
133
  get name() {
134
- return G;
134
+ return F;
135
135
  }
136
136
  static getMeshLODInformation(e) {
137
137
  const t = this.getAssignedLODInformation(e);
@@ -153,8 +153,8 @@ const D = class {
153
153
  if (m === "verbose" && console.log("getMaterialMinMaxLODsCount", e), e.type === "ShaderMaterial" || e.type === "RawShaderMaterial") {
154
154
  const o = e;
155
155
  for (const a of Object.keys(o.uniforms)) {
156
- const d = o.uniforms[a].value;
157
- (d == null ? void 0 : d.isTexture) === !0 && s(d, t);
156
+ const f = o.uniforms[a].value;
157
+ (f == null ? void 0 : f.isTexture) === !0 && s(f, t);
158
158
  }
159
159
  } else if (e.isMaterial)
160
160
  for (const o of Object.keys(e)) {
@@ -163,14 +163,14 @@ const D = class {
163
163
  }
164
164
  return e[n] = t, t;
165
165
  function s(o, a) {
166
- const d = r.getAssignedLODInformation(o);
167
- if (d) {
168
- const c = r.lodInfos.get(d.key);
166
+ const f = r.getAssignedLODInformation(o);
167
+ if (f) {
168
+ const c = r.lodInfos.get(f.key);
169
169
  if (c && c.lods) {
170
170
  a.min_count = Math.min(a.min_count, c.lods.length), a.max_count = Math.max(a.max_count, c.lods.length);
171
171
  for (let x = 0; x < c.lods.length; x++) {
172
- const f = c.lods[x];
173
- f.width && (a.lods[x] = a.lods[x] || { min_height: 1 / 0, max_height: 0 }, a.lods[x].min_height = Math.min(a.lods[x].min_height, f.height), a.lods[x].max_height = Math.max(a.lods[x].max_height, f.height));
172
+ const u = c.lods[x];
173
+ u.width && (a.lods[x] = a.lods[x] || { min_height: 1 / 0, max_height: 0 }, a.lods[x].min_height = Math.min(a.lods[x].min_height, u.height), a.lods[x].max_height = Math.max(a.lods[x].max_height, u.height));
174
174
  }
175
175
  }
176
176
  }
@@ -229,19 +229,19 @@ const D = class {
229
229
  var r;
230
230
  if (!e)
231
231
  return Promise.resolve(null);
232
- if (e instanceof V || e.isMesh === !0) {
232
+ if (e instanceof W || e.isMesh === !0) {
233
233
  const n = e.geometry, i = this.getAssignedLODInformation(n);
234
234
  if (!i)
235
235
  return Promise.resolve(null);
236
- for (const s of $)
236
+ for (const s of z)
237
237
  (r = s.onBeforeGetLODMesh) == null || r.call(s, e, t);
238
- return e["LOD:requested level"] = t, D.getOrLoadLOD(n, t).then((s) => {
238
+ return e["LOD:requested level"] = t, O.getOrLoadLOD(n, t).then((s) => {
239
239
  if (e["LOD:requested level"] === t) {
240
240
  if (delete e["LOD:requested level"], Array.isArray(s)) {
241
241
  const o = i.index || 0;
242
242
  s = s[o];
243
243
  }
244
- s && n != s && ((s == null ? void 0 : s.isBufferGeometry) ? (e.geometry = s, m && me(e, "geometry", i.url)) : m && console.error("Invalid LOD geometry", s));
244
+ s && n != s && ((s == null ? void 0 : s.isBufferGeometry) ? (e.geometry = s, m && xe(e, "geometry", i.url)) : m && console.error("Invalid LOD geometry", s));
245
245
  }
246
246
  return s;
247
247
  }).catch((s) => (console.error("Error loading mesh LOD", e, s), null));
@@ -259,15 +259,15 @@ const D = class {
259
259
  static assignTextureLOD(e, t = 0) {
260
260
  if (!e)
261
261
  return Promise.resolve(null);
262
- if (e instanceof be || e.isMaterial === !0) {
262
+ if (e instanceof Te || e.isMaterial === !0) {
263
263
  const r = e, n = [], i = new Array();
264
- if (m && de.add(r), r.uniforms && r.isRawShaderMaterial || r.isShaderMaterial === !0) {
264
+ if (m && he.add(r), r.uniforms && r.isRawShaderMaterial || r.isShaderMaterial === !0) {
265
265
  const s = r;
266
266
  for (const o of Object.keys(s.uniforms)) {
267
267
  const a = s.uniforms[o].value;
268
268
  if ((a == null ? void 0 : a.isTexture) === !0) {
269
- const d = this.assignTextureLODForSlot(a, t, r, o);
270
- n.push(d), i.push(o);
269
+ const f = this.assignTextureLODForSlot(a, t, r, o);
270
+ n.push(f), i.push(o);
271
271
  }
272
272
  }
273
273
  } else
@@ -281,20 +281,20 @@ const D = class {
281
281
  return Promise.all(n).then((s) => {
282
282
  const o = new Array();
283
283
  for (let a = 0; a < s.length; a++) {
284
- const d = s[a], c = i[a];
285
- d && d.isTexture === !0 ? o.push({ material: r, slot: c, texture: d, level: t }) : o.push({ material: r, slot: c, texture: null, level: t });
284
+ const f = s[a], c = i[a];
285
+ f && f.isTexture === !0 ? o.push({ material: r, slot: c, texture: f, level: t }) : o.push({ material: r, slot: c, texture: null, level: t });
286
286
  }
287
287
  return o;
288
288
  });
289
289
  }
290
- if (e instanceof K || e.isTexture === !0) {
290
+ if (e instanceof q || e.isTexture === !0) {
291
291
  const r = e;
292
292
  return this.assignTextureLODForSlot(r, t, null, null);
293
293
  }
294
294
  return Promise.resolve(null);
295
295
  }
296
296
  static assignTextureLODForSlot(e, t, r, n) {
297
- return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : n === "glyphMap" ? Promise.resolve(e) : D.getOrLoadLOD(e, t).then((i) => {
297
+ return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : n === "glyphMap" ? Promise.resolve(e) : O.getOrLoadLOD(e, t).then((i) => {
298
298
  if (Array.isArray(i))
299
299
  return null;
300
300
  if ((i == null ? void 0 : i.isTexture) === !0) {
@@ -310,7 +310,7 @@ const D = class {
310
310
  }
311
311
  if (m && n && r) {
312
312
  const s = this.getAssignedLODInformation(e);
313
- s && me(r, n, s.url);
313
+ s && xe(r, n, s.url);
314
314
  }
315
315
  }
316
316
  return i;
@@ -324,36 +324,36 @@ const D = class {
324
324
  return m && console.log("AFTER", this.url, e), (t = this.parser.json.textures) == null || t.forEach((n, i) => {
325
325
  var s;
326
326
  if (n != null && n.extensions) {
327
- const o = n == null ? void 0 : n.extensions[G];
327
+ const o = n == null ? void 0 : n.extensions[F];
328
328
  if (o) {
329
329
  if (!o.lods) {
330
330
  m && console.warn("Texture has no LODs", o);
331
331
  return;
332
332
  }
333
333
  let a = !1;
334
- for (const d of this.parser.associations.keys())
335
- d.isTexture === !0 && this.parser.associations.get(d).textures === i && (a = !0, D.registerTexture(this.url, d, (s = o.lods) == null ? void 0 : s.length, i, o));
336
- a || this.parser.getDependency("texture", i).then((d) => {
334
+ for (const f of this.parser.associations.keys())
335
+ f.isTexture === !0 && this.parser.associations.get(f).textures === i && (a = !0, O.registerTexture(this.url, f, (s = o.lods) == null ? void 0 : s.length, i, o));
336
+ a || this.parser.getDependency("texture", i).then((f) => {
337
337
  var c;
338
- d && D.registerTexture(this.url, d, (c = o.lods) == null ? void 0 : c.length, i, o);
338
+ f && O.registerTexture(this.url, f, (c = o.lods) == null ? void 0 : c.length, i, o);
339
339
  });
340
340
  }
341
341
  }
342
342
  }), (r = this.parser.json.meshes) == null || r.forEach((n, i) => {
343
343
  if (n != null && n.extensions) {
344
- const s = n == null ? void 0 : n.extensions[G];
344
+ const s = n == null ? void 0 : n.extensions[F];
345
345
  if (s && s.lods) {
346
346
  for (const o of this.parser.associations.keys())
347
347
  if (o.isMesh) {
348
348
  const a = this.parser.associations.get(o);
349
- a.meshes === i && D.registerMesh(this.url, s.guid, o, s.lods.length, a.primitives, s);
349
+ a.meshes === i && O.registerMesh(this.url, s.guid, o, s.lods.length, a.primitives, s);
350
350
  }
351
351
  }
352
352
  }
353
353
  }), null;
354
354
  }
355
355
  static async getOrLoadLOD(e, t) {
356
- var o, a, d, c;
356
+ var o, a, f, c;
357
357
  const r = m == "verbose", n = e.userData.LODS;
358
358
  if (!n)
359
359
  return null;
@@ -361,101 +361,101 @@ const D = class {
361
361
  let s;
362
362
  if (e.isTexture === !0) {
363
363
  const x = e;
364
- x.source && x.source[oe] && (s = x.source[oe]);
364
+ x.source && x.source[ae] && (s = x.source[ae]);
365
365
  }
366
- if (s || (s = D.lodInfos.get(i)), s) {
366
+ if (s || (s = O.lodInfos.get(i)), s) {
367
367
  if (t > 0) {
368
368
  let y = !1;
369
- const M = Array.isArray(s.lods);
370
- if (M && t >= s.lods.length ? y = !0 : M || (y = !0), y)
369
+ const w = Array.isArray(s.lods);
370
+ if (w && t >= s.lods.length ? y = !0 : w || (y = !0), y)
371
371
  return this.lowresCache.get(i);
372
372
  }
373
373
  const x = Array.isArray(s.lods) ? (o = s.lods[t]) == null ? void 0 : o.path : s.lods;
374
374
  if (!x)
375
375
  return m && !s["missing:uri"] && (s["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + t, s)), null;
376
- const f = ke(n.url, x);
377
- if (f.endsWith(".glb") || f.endsWith(".gltf")) {
376
+ const u = Ie(n.url, x);
377
+ if (u.endsWith(".glb") || u.endsWith(".gltf")) {
378
378
  if (!s.guid)
379
379
  return console.warn("missing pointer for glb/gltf texture", s), null;
380
- const y = f + "_" + s.guid, M = this.previouslyLoaded.get(y);
381
- if (M !== void 0) {
380
+ const y = u + "_" + s.guid, w = this.previouslyLoaded.get(y);
381
+ if (w !== void 0) {
382
382
  r && console.log(`LOD ${t} was already loading/loaded: ${y}`);
383
- let g = await M.catch((C) => (console.error(`Error loading LOD ${t} from ${f}
384
- `, C), null)), z = !1;
385
- if (g == null || (g instanceof K && e instanceof K ? (a = g.image) != null && a.data || (d = g.source) != null && d.data ? g = this.copySettings(e, g) : (z = !0, this.previouslyLoaded.delete(y)) : g instanceof re && e instanceof re && ((c = g.attributes.position) != null && c.array || (z = !0, this.previouslyLoaded.delete(y)))), !z)
386
- return g;
383
+ let p = await w.catch((U) => (console.error(`Error loading LOD ${t} from ${u}
384
+ `, U), null)), M = !1;
385
+ if (p == null || (p instanceof q && e instanceof q ? (a = p.image) != null && a.data || (f = p.source) != null && f.data ? p = this.copySettings(e, p) : (M = !0, this.previouslyLoaded.delete(y)) : p instanceof se && e instanceof se && ((c = p.attributes.position) != null && c.array || (M = !0, this.previouslyLoaded.delete(y)))), !M)
386
+ return p;
387
387
  }
388
- const L = s, k = new Promise(async (g, z) => {
389
- const C = new Ce();
390
- we(C), m && (await new Promise((T) => setTimeout(T, 1e3)), r && console.warn("Start loading (delayed) " + f, L.guid));
391
- let b = f;
388
+ const L = s, B = new Promise(async (p, M) => {
389
+ const U = new Re();
390
+ ve(U), m && (await new Promise((S) => setTimeout(S, 1e3)), r && console.warn("Start loading (delayed) " + u, L.guid));
391
+ let E = u;
392
392
  if (L && Array.isArray(L.lods)) {
393
- const T = L.lods[t];
394
- T.hash && (b += "?v=" + T.hash);
393
+ const S = L.lods[t];
394
+ S.hash && (E += "?v=" + S.hash);
395
395
  }
396
- const S = await C.loadAsync(b).catch((T) => (console.error(`Error loading LOD ${t} from ${f}
397
- `, T), null));
398
- if (!S)
396
+ const v = await U.loadAsync(E).catch((S) => (console.error(`Error loading LOD ${t} from ${u}
397
+ `, S), null));
398
+ if (!v)
399
399
  return null;
400
- const W = S.parser;
401
- r && console.log("Loading finished " + f, L.guid);
402
- let R = 0;
403
- if (S.parser.json.textures) {
404
- let T = !1;
405
- for (const u of S.parser.json.textures) {
406
- if (u != null && u.extensions) {
407
- const p = u == null ? void 0 : u.extensions[G];
408
- if (p != null && p.guid && p.guid === L.guid) {
409
- T = !0;
400
+ const $ = v.parser;
401
+ r && console.log("Loading finished " + u, L.guid);
402
+ let k = 0;
403
+ if (v.parser.json.textures) {
404
+ let S = !1;
405
+ for (const g of v.parser.json.textures) {
406
+ if (g != null && g.extensions) {
407
+ const h = g == null ? void 0 : g.extensions[F];
408
+ if (h != null && h.guid && h.guid === L.guid) {
409
+ S = !0;
410
410
  break;
411
411
  }
412
412
  }
413
- R++;
413
+ k++;
414
414
  }
415
- if (T) {
416
- let u = await W.getDependency("texture", R);
417
- return u && D.assignLODInformation(n.url, u, i, t, void 0, void 0), r && console.log('change "' + e.name + '" → "' + u.name + '"', f, R, u, y), e instanceof K && (u = this.copySettings(e, u)), u && (u.guid = L.guid), g(u);
415
+ if (S) {
416
+ let g = await $.getDependency("texture", k);
417
+ return g && O.assignLODInformation(n.url, g, i, t, void 0, void 0), r && console.log('change "' + e.name + '" → "' + g.name + '"', u, k, g, y), e instanceof q && (g = this.copySettings(e, g)), g && (g.guid = L.guid), p(g);
418
418
  } else
419
- m && console.warn("Could not find texture with guid", L.guid, S.parser.json);
419
+ m && console.warn("Could not find texture with guid", L.guid, v.parser.json);
420
420
  }
421
- if (R = 0, S.parser.json.meshes) {
422
- let T = !1;
423
- for (const u of S.parser.json.meshes) {
424
- if (u != null && u.extensions) {
425
- const p = u == null ? void 0 : u.extensions[G];
426
- if (p != null && p.guid && p.guid === L.guid) {
427
- T = !0;
421
+ if (k = 0, v.parser.json.meshes) {
422
+ let S = !1;
423
+ for (const g of v.parser.json.meshes) {
424
+ if (g != null && g.extensions) {
425
+ const h = g == null ? void 0 : g.extensions[F];
426
+ if (h != null && h.guid && h.guid === L.guid) {
427
+ S = !0;
428
428
  break;
429
429
  }
430
430
  }
431
- R++;
431
+ k++;
432
432
  }
433
- if (T) {
434
- const u = await W.getDependency("mesh", R), p = L;
435
- if (r && console.log(`Loaded Mesh "${u.name}"`, f, R, u, y), u.isMesh === !0) {
436
- const v = u.geometry;
437
- return D.assignLODInformation(n.url, v, i, t, void 0, p.density), g(v);
433
+ if (S) {
434
+ const g = await $.getDependency("mesh", k), h = L;
435
+ if (r && console.log(`Loaded Mesh "${g.name}"`, u, k, g, y), g.isMesh === !0) {
436
+ const D = g.geometry;
437
+ return O.assignLODInformation(n.url, D, i, t, void 0, h.density), p(D);
438
438
  } else {
439
- const v = new Array();
440
- for (let _ = 0; _ < u.children.length; _++) {
441
- const A = u.children[_];
442
- if (A.isMesh === !0) {
443
- const F = A.geometry;
444
- D.assignLODInformation(n.url, F, i, t, _, p.density), v.push(F);
439
+ const D = new Array();
440
+ for (let b = 0; b < g.children.length; b++) {
441
+ const T = g.children[b];
442
+ if (T.isMesh === !0) {
443
+ const A = T.geometry;
444
+ O.assignLODInformation(n.url, A, i, t, b, h.density), D.push(A);
445
445
  }
446
446
  }
447
- return g(v);
447
+ return p(D);
448
448
  }
449
449
  } else
450
- m && console.warn("Could not find mesh with guid", L.guid, S.parser.json);
450
+ m && console.warn("Could not find mesh with guid", L.guid, v.parser.json);
451
451
  }
452
- return g(null);
452
+ return p(null);
453
453
  });
454
- return this.previouslyLoaded.set(y, k), await k;
455
- } else if (e instanceof K) {
456
- r && console.log("Load texture from uri: " + f);
457
- const M = await new Te().loadAsync(f);
458
- return M ? (M.guid = s.guid, M.flipY = !1, M.needsUpdate = !0, M.colorSpace = e.colorSpace, r && console.log(s, M)) : m && console.warn("failed loading", f), M;
454
+ return this.previouslyLoaded.set(y, B), await B;
455
+ } else if (e instanceof q) {
456
+ r && console.log("Load texture from uri: " + u);
457
+ const w = await new Ae().loadAsync(u);
458
+ return w ? (w.guid = s.guid, w.flipY = !1, w.needsUpdate = !0, w.colorSpace = e.colorSpace, r && console.log(s, w)) : m && console.warn("failed loading", u), w;
459
459
  }
460
460
  } else
461
461
  m && console.warn(`Can not load LOD ${t}: no LOD info found for "${i}" ${e.name}`, e.type);
@@ -465,7 +465,7 @@ const D = class {
465
465
  if (!t)
466
466
  return;
467
467
  t.userData || (t.userData = {});
468
- const o = new $e(e, r, n, i, s);
468
+ const o = new ze(e, r, n, i, s);
469
469
  t.userData.LODS = o;
470
470
  }
471
471
  static getAssignedLODInformation(e) {
@@ -479,93 +479,93 @@ const D = class {
479
479
  `, 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;
480
480
  }
481
481
  };
482
- let O = D;
482
+ let _ = O;
483
483
  /**
484
484
  * Register a texture with LOD information
485
485
  */
486
- h(O, "registerTexture", (e, t, r, n, i) => {
486
+ d(_, "registerTexture", (e, t, r, n, i) => {
487
487
  if (m && console.log("> Progressive: register texture", n, t.name, t.uuid, t, i), !t) {
488
488
  m && console.error("gltf-progressive: Register texture without texture");
489
489
  return;
490
490
  }
491
- t.source && (t.source[oe] = i);
491
+ t.source && (t.source[ae] = i);
492
492
  const s = i.guid;
493
- D.assignLODInformation(e, t, s, r, n, void 0), D.lodInfos.set(s, i), D.lowresCache.set(s, t);
493
+ O.assignLODInformation(e, t, s, r, n, void 0), O.lodInfos.set(s, i), O.lowresCache.set(s, t);
494
494
  }), /**
495
495
  * Register a mesh with LOD information
496
496
  */
497
- h(O, "registerMesh", (e, t, r, n, i, s) => {
498
- var d;
497
+ d(_, "registerMesh", (e, t, r, n, i, s) => {
498
+ var f;
499
499
  m && console.log("> Progressive: register mesh", i, r.name, s, r.uuid, r);
500
500
  const o = r.geometry;
501
501
  if (!o) {
502
502
  m && console.warn("gltf-progressive: Register mesh without geometry");
503
503
  return;
504
504
  }
505
- o.userData || (o.userData = {}), D.assignLODInformation(e, o, t, n, i, s.density), D.lodInfos.set(t, s);
506
- let a = D.lowresCache.get(t);
507
- a ? a.push(r.geometry) : a = [r.geometry], D.lowresCache.set(t, a), n > 0 && !ge(r) && Ge(r, o);
508
- for (const c of $)
509
- (d = c.onRegisteredNewMesh) == null || d.call(c, r, s);
505
+ o.userData || (o.userData = {}), O.assignLODInformation(e, o, t, n, i, s.density), O.lodInfos.set(t, s);
506
+ let a = O.lowresCache.get(t);
507
+ a ? a.push(r.geometry) : a = [r.geometry], O.lowresCache.set(t, a), n > 0 && !pe(r) && Fe(r, o);
508
+ for (const c of z)
509
+ (f = c.onRegisteredNewMesh) == null || f.call(c, r, s);
510
510
  }), /** A map of key = asset uuid and value = LOD information */
511
- h(O, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
512
- h(O, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
513
- h(O, "lowresCache", /* @__PURE__ */ new Map());
514
- class $e {
511
+ d(_, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
512
+ d(_, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
513
+ d(_, "lowresCache", /* @__PURE__ */ new Map());
514
+ class ze {
515
515
  constructor(e, t, r, n, i) {
516
- h(this, "url");
516
+ d(this, "url");
517
517
  /** the key to lookup the LOD information */
518
- h(this, "key");
519
- h(this, "level");
518
+ d(this, "key");
519
+ d(this, "level");
520
520
  /** For multi objects (e.g. a group of meshes) this is the index of the object */
521
- h(this, "index");
521
+ d(this, "index");
522
522
  /** the mesh density */
523
- h(this, "density");
523
+ d(this, "density");
524
524
  this.url = e, this.key = t, this.level = r, n != null && (this.index = n), i != null && (this.density = i);
525
525
  }
526
526
  }
527
- const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LODSManager"), le = Symbol("Needle:LODState"), N = Symbol("Needle:CurrentLOD"), B = { mesh_lod: -1, texture_lod: -1 }, P = class {
527
+ const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = Symbol("Needle:LODSManager"), ce = Symbol("Needle:LODState"), V = Symbol("Needle:CurrentLOD"), C = { mesh_lod: -1, texture_lod: -1 }, P = class {
528
528
  // readonly plugins: NEEDLE_progressive_plugin[] = [];
529
529
  constructor(e, t) {
530
- h(this, "context");
531
- h(this, "renderer");
532
- h(this, "projectionScreenMatrix", new pe());
533
- h(this, "cameraFrustrum", new Ae());
530
+ d(this, "context");
531
+ d(this, "renderer");
532
+ d(this, "projectionScreenMatrix", new ye());
533
+ d(this, "cameraFrustrum", new Pe());
534
534
  /**
535
535
  * The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
536
536
  * @default 200_000
537
537
  */
538
- h(this, "targetTriangleDensity", 2e5);
538
+ d(this, "targetTriangleDensity", 2e5);
539
539
  /**
540
540
  * 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.
541
541
  */
542
- h(this, "updateInterval", 0);
542
+ d(this, "updateInterval", 0);
543
543
  /**
544
544
  * If set to true, the LODsManager will not update the LODs.
545
545
  */
546
- h(this, "pause", !1);
547
- h(this, "_frame", 0);
548
- h(this, "_originalRender");
546
+ d(this, "pause", !1);
547
+ d(this, "_frame", 0);
548
+ d(this, "_originalRender");
549
549
  // private testIfLODLevelsAreAvailable() {
550
- h(this, "_sphere", new Pe());
551
- h(this, "_tempBox", new ye());
552
- h(this, "_tempBox2", new ye());
553
- h(this, "tempMatrix", new pe());
554
- h(this, "_tempWorldPosition", new I());
555
- h(this, "_tempBoxSize", new I());
556
- h(this, "_tempBox2Size", new I());
550
+ d(this, "_sphere", new Ce());
551
+ d(this, "_tempBox", new me());
552
+ d(this, "_tempBox2", new me());
553
+ d(this, "tempMatrix", new ye());
554
+ d(this, "_tempWorldPosition", new G());
555
+ d(this, "_tempBoxSize", new G());
556
+ d(this, "_tempBox2Size", new G());
557
557
  this.renderer = e, this.context = { ...t };
558
558
  }
559
559
  /** @internal */
560
560
  static getObjectLODState(e) {
561
- return e[le];
561
+ return e[ce];
562
562
  }
563
563
  static addPlugin(e) {
564
- $.push(e);
564
+ z.push(e);
565
565
  }
566
566
  static removePlugin(e) {
567
- const t = $.indexOf(e);
568
- t >= 0 && $.splice(t, 1);
567
+ const t = z.indexOf(e);
568
+ t >= 0 && z.splice(t, 1);
569
569
  }
570
570
  /**
571
571
  * Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
@@ -573,17 +573,17 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
573
573
  * @returns The LODsManager instance.
574
574
  */
575
575
  static get(e, t) {
576
- if (e[ae])
577
- return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), e[ae];
576
+ if (e[le])
577
+ return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), e[le];
578
578
  const r = new P(e, {
579
579
  engine: "unknown",
580
580
  ...t
581
581
  });
582
- return e[ae] = r, r;
582
+ return e[le] = r, r;
583
583
  }
584
584
  /** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
585
585
  get plugins() {
586
- return $;
586
+ return z;
587
587
  }
588
588
  /**
589
589
  * Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
@@ -595,7 +595,7 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
595
595
  let e = 0;
596
596
  this._originalRender = this.renderer.render;
597
597
  const t = this;
598
- De(this.renderer), this.renderer.render = function(r, n) {
598
+ we(this.renderer), this.renderer.render = function(r, n) {
599
599
  t.renderer.getRenderTarget() == null && (e = 0, t._frame += 1);
600
600
  const s = t._frame, o = e++;
601
601
  t.onBeforeRender(r, n, o, s), t._originalRender.call(this, r, n), t.onAfterRender(r, n, o, s);
@@ -607,7 +607,7 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
607
607
  onBeforeRender(e, t, r, n) {
608
608
  }
609
609
  onAfterRender(e, t, r, n) {
610
- var a, d;
610
+ var a, f;
611
611
  if (this.pause)
612
612
  return;
613
613
  const i = this.renderer.renderLists.get(e, 0), s = i.opaque;
@@ -617,16 +617,16 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
617
617
  (c.name === "EffectMaterial" || c.name === "CopyShader") && (o = !1);
618
618
  }
619
619
  if ((t.parent && t.parent.type === "CubeCamera" || r >= 1 && t.type === "OrthographicCamera") && (o = !1), o) {
620
- if (ze || this.updateInterval > 0 && n % this.updateInterval != 0)
620
+ if (Ue || this.updateInterval > 0 && n % this.updateInterval != 0)
621
621
  return;
622
622
  this.projectionScreenMatrix.multiplyMatrices(t.projectionMatrix, t.matrixWorldInverse), this.cameraFrustrum.setFromProjectionMatrix(this.projectionScreenMatrix, this.renderer.coordinateSystem);
623
623
  const c = this.targetTriangleDensity;
624
- for (const f of s) {
625
- if (f.material && (((a = f.geometry) == null ? void 0 : a.type) === "BoxGeometry" || ((d = f.geometry) == null ? void 0 : d.type) === "BufferGeometry") && (f.material.name === "SphericalGaussianBlur" || f.material.name == "BackgroundCubeMaterial" || f.material.name === "CubemapFromEquirect" || f.material.name === "EquirectangularToCubeUV")) {
626
- U && (f.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (f.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", f, f.material.name, f.material.type)));
624
+ for (const u of s) {
625
+ if (u.material && (((a = u.geometry) == null ? void 0 : a.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")) {
626
+ N && (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)));
627
627
  continue;
628
628
  }
629
- switch (f.material.type) {
629
+ switch (u.material.type) {
630
630
  case "LineBasicMaterial":
631
631
  case "LineDashedMaterial":
632
632
  case "PointsMaterial":
@@ -635,34 +635,34 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
635
635
  case "MeshDepthMaterial":
636
636
  continue;
637
637
  }
638
- const y = f.object;
639
- (y instanceof V || y.isMesh) && this.updateLODs(e, t, y, c, n);
638
+ const y = u.object;
639
+ (y instanceof W || y.isMesh) && this.updateLODs(e, t, y, c, n);
640
640
  }
641
641
  const x = i.transparent;
642
- for (const f of x) {
643
- const y = f.object;
644
- (y instanceof V || y.isMesh) && this.updateLODs(e, t, y, c, n);
642
+ for (const u of x) {
643
+ const y = u.object;
644
+ (y instanceof W || y.isMesh) && this.updateLODs(e, t, y, c, n);
645
645
  }
646
646
  }
647
647
  }
648
648
  /** Update the LOD levels for the renderer. */
649
649
  updateLODs(e, t, r, n, i) {
650
- var a, d;
650
+ var a, f;
651
651
  r.userData || (r.userData = {});
652
- let s = r[le];
653
- if (s || (s = new Ue(), r[le] = s), s.frames++ < 2)
652
+ let s = r[ce];
653
+ if (s || (s = new Ne(), r[ce] = s), s.frames++ < 2)
654
654
  return;
655
- for (const c of $)
655
+ for (const c of z)
656
656
  (a = c.onBeforeUpdateLOD) == null || a.call(c, this.renderer, e, t, r);
657
- this.calculateLodLevel(t, r, s, n, B), B.mesh_lod = Math.round(B.mesh_lod), B.texture_lod = Math.round(B.texture_lod), B.mesh_lod >= 0 && this.loadProgressiveMeshes(r, B.mesh_lod);
658
- let o = B.texture_lod;
657
+ this.calculateLodLevel(t, r, s, n, 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);
658
+ let o = C.texture_lod;
659
659
  if (r.material && o >= 0) {
660
660
  const c = r["DEBUG:LOD"];
661
661
  c != null && (o = c), this.loadProgressiveTextures(r.material, o);
662
662
  }
663
- for (const c of $)
664
- (d = c.onAfterUpdatedLOD) == null || d.call(c, this.renderer, e, t, r, B);
665
- s.lastLodLevel_Mesh = B.mesh_lod, s.lastLodLevel_Texture = B.texture_lod;
663
+ for (const c of z)
664
+ (f = c.onAfterUpdatedLOD) == null || f.call(c, this.renderer, e, t, r, C);
665
+ s.lastLodLevel_Mesh = C.mesh_lod, s.lastLodLevel_Texture = C.texture_lod;
666
666
  }
667
667
  /** Load progressive textures for the given material
668
668
  * @param material the material to load the textures for
@@ -678,7 +678,7 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
678
678
  return;
679
679
  }
680
680
  let r = !1;
681
- (e[N] === void 0 || t < e[N]) && (r = !0), r && (e[N] = t, O.assignTextureLOD(e, t));
681
+ (e[V] === void 0 || t < e[V]) && (r = !0), r && (e[V] = t, _.assignTextureLOD(e, t));
682
682
  }
683
683
  /** Load progressive meshes for the given mesh
684
684
  * @param mesh the mesh to load the LOD for
@@ -689,10 +689,10 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
689
689
  loadProgressiveMeshes(e, t) {
690
690
  if (!e)
691
691
  return Promise.resolve(null);
692
- if (e[N] !== t) {
693
- e[N] = t;
692
+ if (e[V] !== t) {
693
+ e[V] = t;
694
694
  const r = e.geometry;
695
- return O.assignMeshLOD(e, t).then((n) => (n && e[N] == t && r != e.geometry, n));
695
+ return _.assignMeshLOD(e, t).then((n) => (n && e[V] == t && r != e.geometry, n));
696
696
  }
697
697
  return Promise.resolve(null);
698
698
  }
@@ -701,7 +701,7 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
701
701
  return this._tempPtInside.set(i, s, r.z).applyMatrix4(t).z < 0;
702
702
  }
703
703
  calculateLodLevel(e, t, r, n, i) {
704
- var k;
704
+ var B, I;
705
705
  if (!t) {
706
706
  i.mesh_lod = -1, i.texture_lod = -1;
707
707
  return;
@@ -711,29 +711,29 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
711
711
  return;
712
712
  }
713
713
  let o = 10 + 1, a = !1;
714
- if (U && t["DEBUG:LOD"] != null)
714
+ if (N && t["DEBUG:LOD"] != null)
715
715
  return t["DEBUG:LOD"];
716
- const d = O.getMeshLODInformation(t.geometry), c = d == null ? void 0 : d.lods, x = c && c.length > 0, f = O.getMaterialMinMaxLODsCount(t.material), y = (f == null ? void 0 : f.min_count) != 1 / 0 && f.min_count > 0 && f.max_count > 0;
716
+ const f = _.getMeshLODInformation(t.geometry), c = f == null ? void 0 : f.lods, x = c && c.length > 0, u = _.getMaterialMinMaxLODsCount(t.material), y = (u == null ? void 0 : u.min_count) != 1 / 0 && u.min_count > 0 && u.max_count > 0;
717
717
  if (!x && !y) {
718
718
  i.mesh_lod = 0, i.texture_lod = 0;
719
719
  return;
720
720
  }
721
- if (x || (a = !0, o = 0), !((k = this.cameraFrustrum) != null && k.intersectsObject(t))) {
721
+ if (x || (a = !0, o = 0), !((B = this.cameraFrustrum) != null && B.intersectsObject(t))) {
722
722
  i.mesh_lod = 99, i.texture_lod = 99;
723
723
  return;
724
724
  }
725
- const M = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
725
+ const w = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
726
726
  let L = t.geometry.boundingBox;
727
727
  if (t.type === "SkinnedMesh") {
728
- const w = t;
729
- w.boundingBox || w.computeBoundingBox(), L = w.boundingBox;
728
+ const p = t;
729
+ p.boundingBox || p.computeBoundingBox(), L = p.boundingBox;
730
730
  }
731
731
  if (L && e.isPerspectiveCamera) {
732
- const w = e;
732
+ const p = e;
733
733
  if (t.geometry.attributes.color && t.geometry.attributes.color.count < 100 && t.geometry.boundingSphere) {
734
734
  this._sphere.copy(t.geometry.boundingSphere), this._sphere.applyMatrix4(t.matrixWorld);
735
- const u = e.getWorldPosition(this._tempWorldPosition);
736
- if (this._sphere.containsPoint(u)) {
735
+ const h = e.getWorldPosition(this._tempWorldPosition);
736
+ if (this._sphere.containsPoint(h)) {
737
737
  i.mesh_lod = 0, i.texture_lod = 0;
738
738
  return;
739
739
  }
@@ -742,57 +742,60 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
742
742
  i.mesh_lod = 0, i.texture_lod = 0;
743
743
  return;
744
744
  }
745
- if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && w.fov > 70) {
746
- const u = this._tempBox.min, p = this._tempBox.max;
747
- let v = u.x, _ = u.y, A = p.x, F = p.y;
748
- const Z = 2, ie = 1.5, j = (u.x + p.x) * 0.5, ee = (u.y + p.y) * 0.5;
749
- v = (v - j) * Z + j, _ = (_ - ee) * Z + ee, A = (A - j) * Z + j, F = (F - ee) * Z + ee;
750
- const ve = v < 0 && A > 0 ? 0 : Math.min(Math.abs(u.x), Math.abs(p.x)), Oe = _ < 0 && F > 0 ? 0 : Math.min(Math.abs(u.y), Math.abs(p.y)), ne = Math.max(ve, Oe);
751
- r.lastCentrality = (ie - ne) * (ie - ne) * (ie - ne);
745
+ if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && p.fov > 70) {
746
+ const h = this._tempBox.min, D = this._tempBox.max;
747
+ let b = h.x, T = h.y, A = D.x, K = D.y;
748
+ const j = 2, ne = 1.5, ee = (h.x + D.x) * 0.5, te = (h.y + D.y) * 0.5;
749
+ b = (b - ee) * j + ee, T = (T - te) * j + te, A = (A - ee) * j + ee, K = (K - te) * j + te;
750
+ const Oe = b < 0 && A > 0 ? 0 : Math.min(Math.abs(h.x), Math.abs(D.x)), _e = T < 0 && K > 0 ? 0 : Math.min(Math.abs(h.y), Math.abs(D.y)), oe = Math.max(Oe, _e);
751
+ r.lastCentrality = (ne - oe) * (ne - oe) * (ne - oe);
752
752
  } else
753
753
  r.lastCentrality = 1;
754
- const g = this._tempBox.getSize(this._tempBoxSize);
755
- g.multiplyScalar(0.5), screen.availHeight > 0 && M > 0 && g.multiplyScalar(M / screen.availHeight), g.x *= w.aspect;
756
- const z = e.matrixWorldInverse, C = this._tempBox2;
757
- C.copy(L), C.applyMatrix4(t.matrixWorld), C.applyMatrix4(z);
758
- const b = C.getSize(this._tempBox2Size), S = Math.max(b.x, b.y);
759
- if (Math.max(g.x, g.y) != 0 && S != 0 && (g.z = b.z / Math.max(b.x, b.y) * Math.max(g.x, g.y)), r.lastScreenCoverage = Math.max(g.x, g.y, g.z), r.lastScreenspaceVolume.copy(g), r.lastScreenCoverage *= r.lastCentrality, U && P.debugDrawLine) {
760
- const u = this.tempMatrix.copy(this.projectionScreenMatrix);
761
- u.invert();
762
- const p = P.corner0, v = P.corner1, _ = P.corner2, A = P.corner3;
763
- p.copy(this._tempBox.min), v.copy(this._tempBox.max), v.x = p.x, _.copy(this._tempBox.max), _.y = p.y, A.copy(this._tempBox.max);
764
- const F = (p.z + A.z) * 0.5;
765
- p.z = v.z = _.z = A.z = F, p.applyMatrix4(u), v.applyMatrix4(u), _.applyMatrix4(u), A.applyMatrix4(u), P.debugDrawLine(p, v, 255), P.debugDrawLine(p, _, 255), P.debugDrawLine(v, A, 255), P.debugDrawLine(_, A, 255);
754
+ const M = this._tempBox.getSize(this._tempBoxSize);
755
+ M.multiplyScalar(0.5), screen.availHeight > 0 && w > 0 && M.multiplyScalar(w / screen.availHeight), M.x *= p.aspect;
756
+ const U = e.matrixWorldInverse, E = this._tempBox2;
757
+ E.copy(L), E.applyMatrix4(t.matrixWorld), E.applyMatrix4(U);
758
+ const v = E.getSize(this._tempBox2Size), $ = Math.max(v.x, v.y);
759
+ if (Math.max(M.x, M.y) != 0 && $ != 0 && (M.z = v.z / Math.max(v.x, v.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, N && P.debugDrawLine) {
760
+ const h = this.tempMatrix.copy(this.projectionScreenMatrix);
761
+ h.invert();
762
+ const D = P.corner0, b = P.corner1, T = P.corner2, A = P.corner3;
763
+ D.copy(this._tempBox.min), b.copy(this._tempBox.max), b.x = D.x, T.copy(this._tempBox.max), T.y = D.y, A.copy(this._tempBox.max);
764
+ const K = (D.z + A.z) * 0.5;
765
+ D.z = b.z = T.z = A.z = K, D.applyMatrix4(h), b.applyMatrix4(h), T.applyMatrix4(h), A.applyMatrix4(h), P.debugDrawLine(D, b, 255), P.debugDrawLine(D, T, 255), P.debugDrawLine(b, A, 255), P.debugDrawLine(T, A, 255);
766
766
  }
767
- let R = 999;
767
+ let S = 999;
768
768
  if (c && r.lastScreenCoverage > 0) {
769
- for (let u = 0; u < c.length; u++)
770
- if (c[u].density / r.lastScreenCoverage < n) {
771
- R = u;
769
+ for (let h = 0; h < c.length; h++)
770
+ if (c[h].density / r.lastScreenCoverage < n) {
771
+ S = h;
772
772
  break;
773
773
  }
774
774
  }
775
- R < o && (o = R, a = !0);
775
+ S < o && (o = S, a = !0);
776
776
  }
777
- if (a ? i.mesh_lod = o : i.mesh_lod = r.lastLodLevel_Mesh, U && i.mesh_lod != r.lastLodLevel_Mesh) {
778
- const g = c == null ? void 0 : c[i.mesh_lod];
779
- g && console.log(`Mesh LOD changed: ${r.lastLodLevel_Mesh} → ${i.mesh_lod} (${g.density.toFixed(0)}) - ${t.name}`);
777
+ if (a ? i.mesh_lod = o : i.mesh_lod = r.lastLodLevel_Mesh, N && i.mesh_lod != r.lastLodLevel_Mesh) {
778
+ const M = c == null ? void 0 : c[i.mesh_lod];
779
+ M && console.log(`Mesh LOD changed: ${r.lastLodLevel_Mesh} → ${i.mesh_lod} (${M.density.toFixed(0)}) - ${t.name}`);
780
780
  }
781
781
  if (y)
782
782
  if (r.lastLodLevel_Texture < 0) {
783
- if (i.texture_lod = f.max_count - 1, U) {
784
- const w = f.lods[f.max_count - 1];
785
- U && console.log(`First Texture LOD ${i.texture_lod} (${w.max_height}px) - ${t.name}`);
783
+ if (i.texture_lod = u.max_count - 1, N) {
784
+ const p = u.lods[u.max_count - 1];
785
+ N && console.log(`First Texture LOD ${i.texture_lod} (${p.max_height}px) - ${t.name}`);
786
786
  }
787
787
  } else {
788
- const w = r.lastScreenspaceVolume.x + r.lastScreenspaceVolume.y + r.lastScreenspaceVolume.z, g = r.lastScreenCoverage * 2, C = M / window.devicePixelRatio * g;
789
- for (let b = f.lods.length - 1; b >= 0; b--) {
790
- let S = f.lods[b];
791
- if (!(Ie() && S.max_height > 4096) && S.max_height > C) {
792
- if (i.texture_lod = b, i.texture_lod < r.lastLodLevel_Texture) {
793
- const W = S.max_height;
794
- U && console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} ${i.texture_lod} = ${W}px
795
- Screensize: ${C.toFixed(0)}px, Coverage: ${(100 * r.lastScreenCoverage).toFixed(2)}%, Volume ${w.toFixed(1)}
788
+ const p = r.lastScreenspaceVolume.x + r.lastScreenspaceVolume.y + r.lastScreenspaceVolume.z;
789
+ let M = r.lastScreenCoverage * 2;
790
+ ((I = this.context) == null ? void 0 : I.engine) === "model-viewer" && (M *= 2);
791
+ const E = w / window.devicePixelRatio * M;
792
+ for (let v = u.lods.length - 1; v >= 0; v--) {
793
+ let $ = u.lods[v];
794
+ if (!(Ge() && $.max_height > 4096) && $.max_height > E) {
795
+ if (i.texture_lod = v, i.texture_lod < r.lastLodLevel_Texture) {
796
+ const k = $.max_height;
797
+ N && console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} → ${i.texture_lod} = ${k}px
798
+ Screensize: ${E.toFixed(0)}px, Coverage: ${(100 * r.lastScreenCoverage).toFixed(2)}%, Volume ${p.toFixed(1)}
796
799
  ${t.name}`);
797
800
  }
798
801
  break;
@@ -803,43 +806,43 @@ ${t.name}`);
803
806
  i.texture_lod = 0;
804
807
  }
805
808
  };
806
- let E = P;
809
+ let R = P;
807
810
  /** 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.
808
811
  */
809
- h(E, "debugDrawLine"), h(E, "corner0", new I()), h(E, "corner1", new I()), h(E, "corner2", new I()), h(E, "corner3", new I()), h(E, "_tempPtInside", new I());
810
- class Ue {
812
+ d(R, "debugDrawLine"), d(R, "corner0", new G()), d(R, "corner1", new G()), d(R, "corner2", new G()), d(R, "corner3", new G()), d(R, "_tempPtInside", new G());
813
+ class Ne {
811
814
  constructor() {
812
- h(this, "frames", 0);
813
- h(this, "lastLodLevel_Mesh", -1);
814
- h(this, "lastLodLevel_Texture", -1);
815
- h(this, "lastScreenCoverage", 0);
816
- h(this, "lastScreenspaceVolume", new I());
817
- h(this, "lastCentrality", 0);
815
+ d(this, "frames", 0);
816
+ d(this, "lastLodLevel_Mesh", -1);
817
+ d(this, "lastLodLevel_Texture", -1);
818
+ d(this, "lastScreenCoverage", 0);
819
+ d(this, "lastScreenspaceVolume", new G());
820
+ d(this, "lastCentrality", 0);
818
821
  }
819
822
  }
820
- const xe = Symbol("NEEDLE_mesh_lod"), te = Symbol("NEEDLE_texture_lod");
821
- function Ne() {
822
- document.removeEventListener("DOMContentLoaded", ce), document.addEventListener("DOMContentLoaded", ce), ce();
823
+ const Le = Symbol("NEEDLE_mesh_lod"), re = Symbol("NEEDLE_texture_lod");
824
+ function Ve() {
825
+ document.removeEventListener("DOMContentLoaded", ue), document.addEventListener("DOMContentLoaded", ue), ue();
823
826
  }
824
- function ce() {
827
+ function ue() {
825
828
  document.querySelectorAll("model-viewer").forEach((e, t) => {
826
- Ve(e, t);
829
+ We(e, t);
827
830
  });
828
831
  }
829
- const Le = /* @__PURE__ */ new WeakSet();
830
- function Ve(l, e) {
831
- if (!l || Le.has(l))
832
+ const Me = /* @__PURE__ */ new WeakSet();
833
+ function We(l, e) {
834
+ if (!l || Me.has(l))
832
835
  return null;
833
- Le.add(l), console.debug("[gltf-progressive] found model-viewer..." + e);
836
+ Me.add(l), console.debug("[gltf-progressive] found model-viewer..." + e);
834
837
  let t = null, r = null, n = null;
835
838
  for (let i = l; i != null; i = Object.getPrototypeOf(i)) {
836
- const s = Object.getOwnPropertySymbols(i), o = s.find((c) => c.toString() == "Symbol(renderer)"), a = s.find((c) => c.toString() == "Symbol(scene)"), d = s.find((c) => c.toString() == "Symbol(needsRender)");
837
- !t && o != null && (t = l[o].threeRenderer), !r && a != null && (r = l[a]), !n && d != null && (n = l[d]);
839
+ const s = Object.getOwnPropertySymbols(i), o = s.find((c) => c.toString() == "Symbol(renderer)"), a = s.find((c) => c.toString() == "Symbol(scene)"), f = s.find((c) => c.toString() == "Symbol(needsRender)");
840
+ !t && o != null && (t = l[o].threeRenderer), !r && a != null && (r = l[a]), !n && f != null && (n = l[f]);
838
841
  }
839
842
  if (t && r) {
840
843
  console.debug("[gltf-progressive] setup model-viewer");
841
- const i = E.get(t, { engine: "model-viewer" });
842
- if (E.addPlugin(new We()), i.enable(), r && n) {
844
+ const i = R.get(t, { engine: "model-viewer" });
845
+ if (R.addPlugin(new Ke()), i.enable(), r && n) {
843
846
  let s = 0, o = setInterval(() => {
844
847
  if (s++ > 10) {
845
848
  clearInterval(o);
@@ -854,9 +857,9 @@ function Ve(l, e) {
854
857
  }
855
858
  return null;
856
859
  }
857
- class We {
860
+ class Ke {
858
861
  constructor() {
859
- h(this, "_didWarnAboutMissingUrl", !1);
862
+ d(this, "_didWarnAboutMissingUrl", !1);
860
863
  }
861
864
  onBeforeUpdateLOD(e, t, r, n) {
862
865
  this.tryParseMeshLOD(t, n), this.tryParseTextureLOD(t, n);
@@ -874,31 +877,31 @@ class We {
874
877
  return e.element;
875
878
  }
876
879
  tryParseTextureLOD(e, t) {
877
- if (t[te] == !0)
880
+ if (t[re] == !0)
878
881
  return;
879
- t[te] = !0;
882
+ t[re] = !0;
880
883
  const r = this.tryGetCurrentGLTF(e), n = this.tryGetCurrentModelViewer(e), i = this.getUrl(n);
881
884
  if (i && r && t.material) {
882
885
  let s = function(a) {
883
- var c, x, f;
884
- if (a[te] == !0)
886
+ var c, x, u;
887
+ if (a[re] == !0)
885
888
  return;
886
- a[te] = !0, a.userData && (a.userData.LOD = -1);
887
- const d = Object.keys(a);
888
- for (let y = 0; y < d.length; y++) {
889
- const M = d[y], L = a[M];
889
+ a[re] = !0, a.userData && (a.userData.LOD = -1);
890
+ const f = Object.keys(a);
891
+ for (let y = 0; y < f.length; y++) {
892
+ const w = f[y], L = a[w];
890
893
  if ((L == null ? void 0 : L.isTexture) === !0) {
891
- const k = (x = (c = L.userData) == null ? void 0 : c.associations) == null ? void 0 : x.textures;
892
- if (k == null)
894
+ const B = (x = (c = L.userData) == null ? void 0 : c.associations) == null ? void 0 : x.textures;
895
+ if (B == null)
893
896
  continue;
894
- const w = r.parser.json.textures[k];
895
- if (!w) {
896
- console.warn("Texture data not found for texture index " + k);
897
+ const I = r.parser.json.textures[B];
898
+ if (!I) {
899
+ console.warn("Texture data not found for texture index " + B);
897
900
  continue;
898
901
  }
899
- if ((f = w == null ? void 0 : w.extensions) != null && f[G]) {
900
- const g = w.extensions[G];
901
- g && i && O.registerTexture(i, L, g.lods.length, k, g);
902
+ if ((u = I == null ? void 0 : I.extensions) != null && u[F]) {
903
+ const p = I.extensions[F];
904
+ p && i && _.registerTexture(i, L, p.lods.length, B, p);
902
905
  }
903
906
  }
904
907
  }
@@ -913,37 +916,37 @@ class We {
913
916
  }
914
917
  tryParseMeshLOD(e, t) {
915
918
  var s, o;
916
- if (t[xe] == !0)
919
+ if (t[Le] == !0)
917
920
  return;
918
- t[xe] = !0;
921
+ t[Le] = !0;
919
922
  const r = this.tryGetCurrentModelViewer(e), n = this.getUrl(r);
920
923
  if (!n)
921
924
  return;
922
- const i = (o = (s = t.userData) == null ? void 0 : s.gltfExtensions) == null ? void 0 : o[G];
925
+ const i = (o = (s = t.userData) == null ? void 0 : s.gltfExtensions) == null ? void 0 : o[F];
923
926
  if (i && n) {
924
927
  const a = t.uuid;
925
- O.registerMesh(n, a, t, 0, i.lods.length, i);
928
+ _.registerMesh(n, a, t, 0, i.lods.length, i);
926
929
  }
927
930
  }
928
931
  }
929
- Ne();
930
- function et(l, e, t, r) {
931
- De(e), we(t), t.register((i) => new O(i, l));
932
- const n = E.get(e);
932
+ Ve();
933
+ function tt(l, e, t, r) {
934
+ we(e), ve(t), t.register((i) => new _(i, l));
935
+ const n = R.get(e);
933
936
  return (r == null ? void 0 : r.enableLODsManager) !== !1 && n.enable(), n;
934
937
  }
935
938
  export {
936
- G as EXTENSION_NAME,
937
- E as LODsManager,
938
- O as NEEDLE_progressive,
939
- Me as VERSION,
940
- we as addDracoAndKTX2Loaders,
941
- De as createLoaders,
942
- ge as getRaycastMesh,
943
- Ne as patchModelViewer,
944
- Qe as setDracoDecoderLocation,
945
- Ze as setKTX2TranscoderLocation,
946
- Ge as setRaycastMesh,
947
- et as useNeedleProgressive,
948
- je as useRaycastMeshes
939
+ F as EXTENSION_NAME,
940
+ R as LODsManager,
941
+ _ as NEEDLE_progressive,
942
+ De as VERSION,
943
+ ve as addDracoAndKTX2Loaders,
944
+ we as createLoaders,
945
+ pe as getRaycastMesh,
946
+ Ve as patchModelViewer,
947
+ Ze as setDracoDecoderLocation,
948
+ je as setKTX2TranscoderLocation,
949
+ Fe as setRaycastMesh,
950
+ tt as useNeedleProgressive,
951
+ et as useRaycastMeshes
949
952
  };