@needle-tools/gltf-progressive 1.1.0-alpha.1 → 1.2.0-alpha

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,85 +1,93 @@
1
1
  var ge = Object.defineProperty;
2
- var pe = (a, e, t) => e in a ? ge(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
3
- var f = (a, e, t) => (pe(a, typeof e != "symbol" ? e + "" : e, t), t);
2
+ var pe = (l, e, t) => e in l ? ge(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
3
+ var c = (l, e, t) => (pe(l, typeof e != "symbol" ? e + "" : e, t), t);
4
4
  import { MeshoptDecoder as ye } from "three/examples/jsm/libs/meshopt_decoder.module.js";
5
5
  import { DRACOLoader as me } from "three/examples/jsm/loaders/DRACOLoader.js";
6
6
  import { KTX2Loader as Le } from "three/examples/jsm/loaders/KTX2Loader.js";
7
- import { BufferGeometry as Y, Mesh as V, Material as xe, Texture as N, TextureLoader as De, Matrix4 as ne, Frustum as Me, Sphere as Oe, Box3 as oe, Vector3 as k } from "three";
7
+ import { BufferGeometry as V, Mesh as H, Material as xe, Texture as U, TextureLoader as De, Matrix4 as ne, Frustum as Me, Sphere as Oe, Box3 as oe, Vector3 as k } from "three";
8
8
  import { GLTFLoader as we } from "three/examples/jsm/loaders/GLTFLoader.js";
9
- let H = "https://www.gstatic.com/draco/versioned/decoders/1.4.1/", se = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
10
- fetch(H + "draco_decoder.js", { method: "head" }).catch((a) => {
11
- H = "./include/draco/", se = "./include/ktx2/";
9
+ let J = "https://www.gstatic.com/draco/versioned/decoders/1.4.1/", se = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
10
+ fetch(J + "draco_decoder.js", { method: "head" }).catch((l) => {
11
+ J = "./include/draco/", se = "./include/ktx2/";
12
12
  });
13
- function Ue(a) {
14
- H = a;
13
+ function Ge(l) {
14
+ J = l;
15
15
  }
16
- function Ne(a) {
17
- se = a;
16
+ function ze(l) {
17
+ se = l;
18
18
  }
19
- let z, te, W;
20
- function fe(a) {
21
- z || (z = new me(), z.setDecoderPath(H), z.setDecoderConfig({ type: "js" })), W || (W = new Le(), W.setTranscoderPath(se)), te || (te = ye), a ? W.detectSupport(a) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
19
+ let N, te, W;
20
+ function ue(l) {
21
+ N || (N = new me(), N.setDecoderPath(J), N.setDecoderConfig({ type: "js" })), W || (W = new Le(), W.setTranscoderPath(se)), te || (te = ye), l ? W.detectSupport(l) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
22
22
  }
23
- function ue(a) {
24
- a.dracoLoader || a.setDRACOLoader(z), a.ktx2Loader || a.setKTX2Loader(W), a.meshoptDecoder || a.setMeshoptDecoder(te);
23
+ function fe(l) {
24
+ l.dracoLoader || l.setDRACOLoader(N), l.ktx2Loader || l.setKTX2Loader(W), l.meshoptDecoder || l.setMeshoptDecoder(te);
25
25
  }
26
- function ie(a) {
27
- const t = new URL(window.location.href).searchParams.get(a);
26
+ function ie(l) {
27
+ const t = new URL(window.location.href).searchParams.get(l);
28
28
  return t == null || t === "0" || t === "false" ? !1 : t === "" ? !0 : t;
29
29
  }
30
- function ve(a, e) {
31
- if (e === void 0 || e.startsWith("./") || e.startsWith("http") || a === void 0)
30
+ function _e(l, e) {
31
+ if (e === void 0 || e.startsWith("./") || e.startsWith("http") || l === void 0)
32
32
  return e;
33
- const t = a.lastIndexOf("/");
33
+ const t = l.lastIndexOf("/");
34
34
  if (t >= 0) {
35
- const r = a.substring(0, t + 1);
35
+ const r = l.substring(0, t + 1);
36
36
  for (; r.endsWith("/") && e.startsWith("/"); )
37
37
  e = e.substring(1);
38
38
  return r + e;
39
39
  }
40
40
  return e;
41
41
  }
42
- function Se(a) {
42
+ function ve(l) {
43
43
  var e;
44
- return ((e = a.userData) == null ? void 0 : e["needle:raycast-mesh"]) instanceof Y ? a.userData["needle:raycast-mesh"] : null;
44
+ return ((e = l.userData) == null ? void 0 : e["needle:raycast-mesh"]) instanceof V ? l.userData["needle:raycast-mesh"] : null;
45
45
  }
46
- function _e(a, e) {
47
- (a.type === "Mesh" || a.type === "SkinnedMesh") && (a.userData || (a.userData = {}), a.userData["needle:raycast-mesh"] = e);
46
+ function Se(l, e) {
47
+ (l.type === "Mesh" || l.type === "SkinnedMesh") && (l.userData || (l.userData = {}), l.userData["needle:raycast-mesh"] = e);
48
48
  }
49
- const B = new Array(), R = "NEEDLE_progressive", w = ie("debugprogressive"), j = Symbol("needle-progressive-texture"), $ = /* @__PURE__ */ new Map(), re = /* @__PURE__ */ new Set();
49
+ const I = new Array(), R = "NEEDLE_progressive", w = ie("debugprogressive"), ee = Symbol("needle-progressive-texture"), K = /* @__PURE__ */ new Map(), re = /* @__PURE__ */ new Set();
50
50
  if (w) {
51
- let a = function() {
52
- e += 1, console.log("Toggle LOD level", e, $), $.forEach((i, n) => {
51
+ let l = function() {
52
+ e += 1, console.log("Toggle LOD level", e, K), K.forEach((i, n) => {
53
53
  for (const s of i.keys) {
54
54
  const o = n[s];
55
55
  if (o.isBufferGeometry === !0) {
56
- const l = S.getMeshLODInformation(o), d = l ? Math.min(e, l.lods.length) : 0;
57
- n["DEBUG:LOD"] = e, S.assignMeshLOD(n, d), l && (t = Math.max(t, l.lods.length - 1));
56
+ const a = v.getMeshLODInformation(o), f = a ? Math.min(e, a.lods.length) : 0;
57
+ n["DEBUG:LOD"] = e, v.assignMeshLOD(n, f), a && (t = Math.max(t, a.lods.length - 1));
58
58
  } else if (n.isMaterial === !0) {
59
- n["DEBUG:LOD"] = e, S.assignTextureLOD(n, e);
59
+ n["DEBUG:LOD"] = e, v.assignTextureLOD(n, e);
60
60
  break;
61
61
  }
62
62
  }
63
63
  }), e >= t && (e = -1);
64
64
  }, e = -1, t = 2, r = !1;
65
65
  window.addEventListener("keyup", (i) => {
66
- i.key === "p" && a(), i.key === "w" && (r = !r, re && re.forEach((n) => {
66
+ i.key === "p" && l(), i.key === "w" && (r = !r, re && re.forEach((n) => {
67
67
  n.name != "BackgroundCubeMaterial" && "wireframe" in n && (n.wireframe = r);
68
68
  }));
69
69
  });
70
70
  }
71
- function ae(a, e, t) {
71
+ function ae(l, e, t) {
72
72
  var i;
73
73
  if (!w)
74
74
  return;
75
- $.has(a) || $.set(a, { keys: [], sourceId: t });
76
- const r = $.get(a);
75
+ K.has(l) || K.set(l, { keys: [], sourceId: t });
76
+ const r = K.get(l);
77
77
  ((i = r == null ? void 0 : r.keys) == null ? void 0 : i.includes(e)) == !1 && r.keys.push(e);
78
78
  }
79
- const v = class {
79
+ const _ = class {
80
80
  constructor(e, t) {
81
- f(this, "parser");
82
- f(this, "url");
81
+ c(this, "parser");
82
+ c(this, "url");
83
+ c(this, "_isLoadingMesh");
84
+ c(this, "loadMesh", (e) => {
85
+ var r, i;
86
+ if (this._isLoadingMesh)
87
+ return null;
88
+ const t = (i = (r = this.parser.json.meshes[e]) == null ? void 0 : r.extensions) == null ? void 0 : i[R];
89
+ return t ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", e).then((n) => (this._isLoadingMesh = !1, n && _.registerMesh(this.url, t.guid, n, t.lods.length, void 0, t), n))) : null;
90
+ });
83
91
  w && console.log("Progressive extension registered for", t), this.parser = e, this.url = t;
84
92
  }
85
93
  /** The name of the extension */
@@ -90,37 +98,45 @@ const v = class {
90
98
  const t = this.getAssignedLODInformation(e);
91
99
  return t != null && t.key ? this.lodInfos.get(t.key) : null;
92
100
  }
93
- static getMaterialMinMaxLODsCount(e, t = { min: 1 / 0, max: -1 }) {
94
- if (Array.isArray(e)) {
95
- for (const n of e)
96
- this.getMaterialMinMaxLODsCount(n, t);
97
- return t;
101
+ static getMaterialMinMaxLODsCount(e, t) {
102
+ const r = "LODS:minmax", i = e[r];
103
+ if (i != null)
104
+ return i;
105
+ if (t || (t = {
106
+ min_count: 1 / 0,
107
+ max_count: 0,
108
+ lods: []
109
+ }), Array.isArray(e)) {
110
+ for (const s of e)
111
+ this.getMaterialMinMaxLODsCount(s, t);
112
+ return e[r] = t, t;
98
113
  }
99
- let r = t.min, i = t.max;
100
- if (e.type === "ShaderMaterial" || e.type === "RawShaderMaterial") {
101
- const n = e;
102
- for (const s of Object.keys(n.uniforms)) {
103
- const o = n.uniforms[s].value;
104
- if ((o == null ? void 0 : o.isTexture) === !0) {
105
- const l = this.getAssignedLODInformation(o);
106
- if (l) {
107
- const d = this.lodInfos.get(l.key);
108
- d && d.lods && (r = Math.min(r, d.lods.length), i = Math.max(i, d.lods.length));
114
+ w === "verbose" && console.log("getMaterialMinMaxLODsCount", e);
115
+ const n = (s) => {
116
+ const o = this.getAssignedLODInformation(s);
117
+ if (o) {
118
+ const a = this.lodInfos.get(o.key);
119
+ if (a && a.lods) {
120
+ t.min_count = Math.min(t.min_count, a.lods.length), t.max_count = Math.max(t.max_count, a.lods.length);
121
+ for (let f = 0; f < a.lods.length; f++) {
122
+ const h = a.lods[f];
123
+ h.width && (t.lods[f] = t.lods[f] || { min_height: 1 / 0, max_height: 0 }, t.lods[f].min_height = Math.min(t.lods[f].min_height, h.height), t.lods[f].max_height = Math.max(t.lods[f].max_height, h.height));
109
124
  }
110
125
  }
111
126
  }
127
+ };
128
+ if (e.type === "ShaderMaterial" || e.type === "RawShaderMaterial") {
129
+ const s = e;
130
+ for (const o of Object.keys(s.uniforms)) {
131
+ const a = s.uniforms[o].value;
132
+ (a == null ? void 0 : a.isTexture) === !0 && n(a);
133
+ }
112
134
  } else if (e.isMaterial)
113
- for (const n of Object.keys(e)) {
114
- const s = e[n];
115
- if ((s == null ? void 0 : s.isTexture) === !0) {
116
- const o = this.getAssignedLODInformation(s);
117
- if (o) {
118
- const l = this.lodInfos.get(o.key);
119
- l && l.lods && (r = Math.min(r, l.lods.length), i = Math.max(i, l.lods.length));
120
- }
121
- }
135
+ for (const s of Object.keys(e)) {
136
+ const o = e[s];
137
+ (o == null ? void 0 : o.isTexture) === !0 && n(o);
122
138
  }
123
- return t.min = r, t.max = i, t;
139
+ return e[r] = t, t;
124
140
  }
125
141
  /** Check if a LOD level is available for a mesh or a texture
126
142
  * @param obj the mesh or texture to check
@@ -175,19 +191,19 @@ const v = class {
175
191
  var r;
176
192
  if (!e)
177
193
  return Promise.resolve(null);
178
- if (e instanceof V || e.isMesh === !0) {
194
+ if (e instanceof H || e.isMesh === !0) {
179
195
  const i = e.geometry, n = this.getAssignedLODInformation(i);
180
196
  if (!n)
181
197
  return Promise.resolve(null);
182
- for (const s of B)
198
+ for (const s of I)
183
199
  (r = s.onBeforeGetLODMesh) == null || r.call(s, e, t);
184
- return e["LOD:requested level"] = t, v.getOrLoadLOD(i, t).then((s) => {
200
+ return e["LOD:requested level"] = t, _.getOrLoadLOD(i, t).then((s) => {
185
201
  if (e["LOD:requested level"] === t) {
186
202
  if (delete e["LOD:requested level"], Array.isArray(s)) {
187
203
  const o = n.index || 0;
188
204
  s = s[o];
189
205
  }
190
- s && i != s && s instanceof Y && (e.geometry = s, w && ae(e, "geometry", n.url));
206
+ s && i != s && s instanceof V && (e.geometry = s, w && ae(e, "geometry", n.url));
191
207
  }
192
208
  return s;
193
209
  }).catch((s) => (console.error("Error loading mesh LOD", e, s), null));
@@ -210,54 +226,60 @@ const v = class {
210
226
  if (w && re.add(r), r.uniforms && r.isRawShaderMaterial || r.isShaderMaterial === !0) {
211
227
  const s = r;
212
228
  for (const o of Object.keys(s.uniforms)) {
213
- const l = s.uniforms[o].value;
214
- if ((l == null ? void 0 : l.isTexture) === !0) {
215
- const d = this.assignTextureLODForSlot(l, t, r, o);
216
- i.push(d), n.push(o);
229
+ const a = s.uniforms[o].value;
230
+ if ((a == null ? void 0 : a.isTexture) === !0) {
231
+ const f = this.assignTextureLODForSlot(a, t, r, o);
232
+ i.push(f), n.push(o);
217
233
  }
218
234
  }
219
235
  } else
220
236
  for (const s of Object.keys(r)) {
221
237
  const o = r[s];
222
238
  if ((o == null ? void 0 : o.isTexture) === !0) {
223
- const l = this.assignTextureLODForSlot(o, t, r, s);
224
- i.push(l), n.push(s);
239
+ const a = this.assignTextureLODForSlot(o, t, r, s);
240
+ i.push(a), n.push(s);
225
241
  }
226
242
  }
227
243
  return Promise.all(i).then((s) => {
228
244
  const o = new Array();
229
- for (let l = 0; l < s.length; l++) {
230
- const d = s[l], h = n[l];
231
- d && d.isTexture === !0 ? o.push({ material: r, slot: h, texture: d, level: t }) : o.push({ material: r, slot: h, texture: null, level: t });
245
+ for (let a = 0; a < s.length; a++) {
246
+ const f = s[a], h = n[a];
247
+ f && f.isTexture === !0 ? o.push({ material: r, slot: h, texture: f, level: t }) : o.push({ material: r, slot: h, texture: null, level: t });
232
248
  }
233
249
  return o;
234
250
  });
235
251
  }
236
- if (e instanceof N || e.isTexture === !0) {
252
+ if (e instanceof U || e.isTexture === !0) {
237
253
  const r = e;
238
254
  return this.assignTextureLODForSlot(r, t, null, null);
239
255
  }
240
256
  return Promise.resolve(null);
241
257
  }
242
258
  static assignTextureLODForSlot(e, t, r, i) {
243
- if ((e == null ? void 0 : e.isTexture) !== !0)
244
- return Promise.resolve(null);
245
- if (i === "glyphMap")
246
- return Promise.resolve(e);
247
- const n = "LOD:requested level:" + i;
248
- return r && (r[n] = t), v.getOrLoadLOD(e, t).then((s) => {
249
- if (r && r[n] != t || Array.isArray(s))
259
+ return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : i === "glyphMap" ? Promise.resolve(e) : _.getOrLoadLOD(e, t).then((n) => {
260
+ if (Array.isArray(n))
250
261
  return null;
251
- if ((s == null ? void 0 : s.isTexture) === !0) {
252
- if (s != e && (r && i && (r[i] = s), w && i && r)) {
253
- const o = this.getAssignedLODInformation(e);
254
- o && ae(r, i, o.url);
262
+ if ((n == null ? void 0 : n.isTexture) === !0) {
263
+ if (n != e) {
264
+ if (r && i) {
265
+ const s = r[i];
266
+ if (s) {
267
+ const o = this.getAssignedLODInformation(s);
268
+ if (o && (o == null ? void 0 : o.level) < t)
269
+ return w === "verbose" && console.warn("Assigned texture level is already higher: ", o.level, t, r, s, n), null;
270
+ }
271
+ r[i] = n;
272
+ }
273
+ if (w && i && r) {
274
+ const s = this.getAssignedLODInformation(e);
275
+ s && ae(r, i, s.url);
276
+ }
255
277
  }
256
- return s;
278
+ return n;
257
279
  } else
258
280
  w == "verbose" && console.warn("No LOD found for", e, t);
259
281
  return null;
260
- }).catch((s) => (console.error("Error loading LOD", e, s), null));
282
+ }).catch((n) => (console.error("Error loading LOD", e, n), null));
261
283
  }
262
284
  afterRoot(e) {
263
285
  var t, r;
@@ -266,10 +288,10 @@ const v = class {
266
288
  const s = i == null ? void 0 : i.extensions[R];
267
289
  if (s) {
268
290
  let o = !1;
269
- for (const l of this.parser.associations.keys())
270
- l.isTexture === !0 && this.parser.associations.get(l).textures === n && (o = !0, v.registerTexture(this.url, l, n, s));
271
- o || this.parser.getDependency("texture", n).then((l) => {
272
- l && v.registerTexture(this.url, l, n, s);
291
+ for (const a of this.parser.associations.keys())
292
+ a.isTexture === !0 && this.parser.associations.get(a).textures === n && (o = !0, _.registerTexture(this.url, a, s.lods.length, n, s));
293
+ o || this.parser.getDependency("texture", n).then((a) => {
294
+ a && _.registerTexture(this.url, a, s.lods.length, n, s);
273
295
  });
274
296
  }
275
297
  }
@@ -279,66 +301,66 @@ const v = class {
279
301
  if (s && s.lods) {
280
302
  for (const o of this.parser.associations.keys())
281
303
  if (o.isMesh) {
282
- const l = this.parser.associations.get(o);
283
- l.meshes === n && v.registerMesh(this.url, s.guid, o, s.lods.length, l.primitives, s);
304
+ const a = this.parser.associations.get(o);
305
+ a.meshes === n && _.registerMesh(this.url, s.guid, o, s.lods.length, a.primitives, s);
284
306
  }
285
307
  }
286
308
  }
287
309
  }), null;
288
310
  }
289
311
  static async getOrLoadLOD(e, t) {
290
- var o, l, d, h;
312
+ var o, a, f, h;
291
313
  const r = w == "verbose", i = e.userData.LODS;
292
314
  if (!i)
293
315
  return null;
294
316
  const n = i == null ? void 0 : i.key;
295
317
  let s;
296
318
  if (e.isTexture === !0) {
297
- const m = e;
298
- m.source && m.source[j] && (s = m.source[j]);
319
+ const x = e;
320
+ x.source && x.source[ee] && (s = x.source[ee]);
299
321
  }
300
- if (s || (s = v.lodInfos.get(n)), s) {
322
+ if (s || (s = _.lodInfos.get(n)), s) {
301
323
  if (t > 0) {
302
324
  let y = !1;
303
- const x = Array.isArray(s.lods);
304
- if (x && t >= s.lods.length ? y = !0 : x || (y = !0), y)
325
+ const D = Array.isArray(s.lods);
326
+ if (D && t >= s.lods.length ? y = !0 : D || (y = !0), y)
305
327
  return this.lowresCache.get(n);
306
328
  }
307
- const m = Array.isArray(s.lods) ? (o = s.lods[t]) == null ? void 0 : o.path : s.lods;
308
- if (!m)
329
+ const x = Array.isArray(s.lods) ? (o = s.lods[t]) == null ? void 0 : o.path : s.lods;
330
+ if (!x)
309
331
  return w && !s["missing:uri"] && (s["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + t, s)), null;
310
- const u = ve(i.url, m);
311
- if (u.endsWith(".glb") || u.endsWith(".gltf")) {
332
+ const d = _e(i.url, x);
333
+ if (d.endsWith(".glb") || d.endsWith(".gltf")) {
312
334
  if (!s.guid)
313
335
  return console.warn("missing pointer for glb/gltf texture", s), null;
314
- const y = u + "_" + s.guid, x = this.previouslyLoaded.get(y);
315
- if (x !== void 0) {
336
+ const y = d + "_" + s.guid, D = this.previouslyLoaded.get(y);
337
+ if (D !== void 0) {
316
338
  r && console.log(`LOD ${t} was already loading/loaded: ${y}`);
317
- let O = await x.catch((F) => (console.error(`Error loading LOD ${t} from ${u}
318
- `, F), null)), P = !1;
319
- if (O == null || (O instanceof N && e instanceof N ? (l = O.image) != null && l.data || (d = O.source) != null && d.data ? O = this.copySettings(e, O) : (P = !0, this.previouslyLoaded.delete(y)) : O instanceof Y && e instanceof Y && ((h = O.attributes.position) != null && h.array || (P = !0, this.previouslyLoaded.delete(y)))), !P)
320
- return O;
339
+ let m = await D.catch((G) => (console.error(`Error loading LOD ${t} from ${d}
340
+ `, G), null)), T = !1;
341
+ if (m == null || (m instanceof U && e instanceof U ? (a = m.image) != null && a.data || (f = m.source) != null && f.data ? m = this.copySettings(e, m) : (T = !0, this.previouslyLoaded.delete(y)) : m instanceof V && e instanceof V && ((h = m.attributes.position) != null && h.array || (T = !0, this.previouslyLoaded.delete(y)))), !T)
342
+ return m;
321
343
  }
322
- const M = s, D = new Promise(async (O, P) => {
323
- const F = new we();
324
- ue(F), w && (await new Promise((g) => setTimeout(g, 1e3)), r && console.warn("Start loading (delayed) " + u, M.guid));
325
- let J = u;
344
+ const M = s, O = new Promise(async (m, T) => {
345
+ const G = new we();
346
+ fe(G), w && (await new Promise((g) => setTimeout(g, 1e3)), r && console.warn("Start loading (delayed) " + d, M.guid));
347
+ let Q = d;
326
348
  if (M && Array.isArray(M.lods)) {
327
349
  const g = M.lods[t];
328
- g.hash && (J += "?v=" + g.hash);
350
+ g.hash && (Q += "?v=" + g.hash);
329
351
  }
330
- const E = await F.loadAsync(J).catch((g) => (console.error(`Error loading LOD ${t} from ${u}
352
+ const E = await G.loadAsync(Q).catch((g) => (console.error(`Error loading LOD ${t} from ${d}
331
353
  `, g), null));
332
354
  if (!E)
333
355
  return null;
334
- const Q = E.parser;
335
- r && console.log("Loading finished " + u, M.guid);
356
+ const Z = E.parser;
357
+ r && console.log("Loading finished " + d, M.guid);
336
358
  let p = 0;
337
359
  if (E.parser.json.textures) {
338
360
  let g = !1;
339
- for (const c of E.parser.json.textures) {
340
- if (c != null && c.extensions) {
341
- const L = c == null ? void 0 : c.extensions[R];
361
+ for (const u of E.parser.json.textures) {
362
+ if (u != null && u.extensions) {
363
+ const L = u == null ? void 0 : u.extensions[R];
342
364
  if (L != null && L.guid && L.guid === M.guid) {
343
365
  g = !0;
344
366
  break;
@@ -347,16 +369,16 @@ const v = class {
347
369
  p++;
348
370
  }
349
371
  if (g) {
350
- let c = await Q.getDependency("texture", p);
351
- return c && v.assignLODInformation(i.url, c, n, t, void 0, void 0), r && console.log('change "' + e.name + '" → "' + c.name + '"', u, p, c, y), e instanceof N && (c = this.copySettings(e, c)), c && (c.guid = M.guid), O(c);
372
+ let u = await Z.getDependency("texture", p);
373
+ return u && _.assignLODInformation(i.url, u, n, t, void 0, void 0), r && console.log('change "' + e.name + '" → "' + u.name + '"', d, p, u, y), e instanceof U && (u = this.copySettings(e, u)), u && (u.guid = M.guid), m(u);
352
374
  } else
353
375
  w && console.warn("Could not find texture with guid", M.guid);
354
376
  }
355
377
  if (p = 0, E.parser.json.meshes) {
356
378
  let g = !1;
357
- for (const c of E.parser.json.meshes) {
358
- if (c != null && c.extensions) {
359
- const L = c == null ? void 0 : c.extensions[R];
379
+ for (const u of E.parser.json.meshes) {
380
+ if (u != null && u.extensions) {
381
+ const L = u == null ? void 0 : u.extensions[R];
360
382
  if (L != null && L.guid && L.guid === M.guid) {
361
383
  g = !0;
362
384
  break;
@@ -365,30 +387,30 @@ const v = class {
365
387
  p++;
366
388
  }
367
389
  if (g) {
368
- const c = await Q.getDependency("mesh", p), L = M;
369
- if (r && console.log(`Loaded Mesh "${c.name}"`, u, p, c, y), c.isMesh === !0) {
370
- const _ = c.geometry;
371
- return v.assignLODInformation(i.url, _, n, t, void 0, L.density), O(_);
390
+ const u = await Z.getDependency("mesh", p), L = M;
391
+ if (r && console.log(`Loaded Mesh "${u.name}"`, d, p, u, y), u.isMesh === !0) {
392
+ const S = u.geometry;
393
+ return _.assignLODInformation(i.url, S, n, t, void 0, L.density), m(S);
372
394
  } else {
373
- const _ = new Array();
374
- for (let C = 0; C < c.children.length; C++) {
375
- const I = c.children[C];
376
- if (I instanceof V) {
377
- const U = I.geometry;
378
- v.assignLODInformation(i.url, U, n, t, C, L.density), _.push(U);
395
+ const S = new Array();
396
+ for (let C = 0; C < u.children.length; C++) {
397
+ const F = u.children[C];
398
+ if (F instanceof H) {
399
+ const z = F.geometry;
400
+ _.assignLODInformation(i.url, z, n, t, C, L.density), S.push(z);
379
401
  }
380
402
  }
381
- return O(_);
403
+ return m(S);
382
404
  }
383
405
  }
384
406
  }
385
- return O(null);
407
+ return m(null);
386
408
  });
387
- return this.previouslyLoaded.set(y, D), await D;
388
- } else if (e instanceof N) {
389
- r && console.log("Load texture from uri: " + u);
390
- const x = await new De().loadAsync(u);
391
- return x ? (x.guid = s.guid, x.flipY = !1, x.needsUpdate = !0, x.colorSpace = e.colorSpace, r && console.log(s, x)) : w && console.warn("failed loading", u), x;
409
+ return this.previouslyLoaded.set(y, O), await O;
410
+ } else if (e instanceof U) {
411
+ r && console.log("Load texture from uri: " + d);
412
+ const D = await new De().loadAsync(d);
413
+ return D ? (D.guid = s.guid, D.flipY = !1, D.needsUpdate = !0, D.colorSpace = e.colorSpace, r && console.log(s, D)) : w && console.warn("failed loading", d), D;
392
414
  }
393
415
  } else
394
416
  w && console.warn(`Can not load LOD ${t}: no LOD info found for "${n}" ${e.name}`, e.type);
@@ -412,72 +434,72 @@ const v = class {
412
434
  `, 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;
413
435
  }
414
436
  };
415
- let S = v;
437
+ let v = _;
416
438
  /**
417
439
  * Register a texture with LOD information
418
440
  */
419
- f(S, "registerTexture", (e, t, r, i) => {
420
- w && console.log("> Progressive: register texture", r, t.name, t.uuid, t, i), t.source && (t.source[j] = i);
421
- const n = i.guid;
422
- v.assignLODInformation(e, t, n, 0, 0, void 0), v.lodInfos.set(n, i), v.lowresCache.set(n, t);
441
+ c(v, "registerTexture", (e, t, r, i, n) => {
442
+ w && console.log("> Progressive: register texture", i, t.name, t.uuid, t, n), t.source && (t.source[ee] = n);
443
+ const s = n.guid;
444
+ _.assignLODInformation(e, t, s, r, i, void 0), _.lodInfos.set(s, n), _.lowresCache.set(s, t);
423
445
  }), /**
424
446
  * Register a mesh with LOD information
425
447
  */
426
- f(S, "registerMesh", (e, t, r, i, n, s) => {
427
- var d;
448
+ c(v, "registerMesh", (e, t, r, i, n, s) => {
449
+ var f;
428
450
  w && console.log("> Progressive: register mesh", n, r.name, s, r.uuid, r);
429
451
  const o = r.geometry;
430
- o.userData || (o.userData = {}), v.assignLODInformation(e, o, t, i, n, s.density), v.lodInfos.set(t, s);
431
- let l = v.lowresCache.get(t);
432
- l ? l.push(r.geometry) : l = [r.geometry], v.lowresCache.set(t, l), i > 0 && !Se(r) && _e(r, o);
433
- for (const h of B)
434
- (d = h.onRegisteredNewMesh) == null || d.call(h, r, s);
452
+ o.userData || (o.userData = {}), _.assignLODInformation(e, o, t, i, n, s.density), _.lodInfos.set(t, s);
453
+ let a = _.lowresCache.get(t);
454
+ a ? a.push(r.geometry) : a = [r.geometry], _.lowresCache.set(t, a), i > 0 && !ve(r) && Se(r, o);
455
+ for (const h of I)
456
+ (f = h.onRegisteredNewMesh) == null || f.call(h, r, s);
435
457
  }), /** A map of key = asset uuid and value = LOD information */
436
- f(S, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
437
- f(S, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
438
- f(S, "lowresCache", /* @__PURE__ */ new Map());
458
+ c(v, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
459
+ c(v, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
460
+ c(v, "lowresCache", /* @__PURE__ */ new Map());
439
461
  class Te {
440
462
  constructor(e, t, r, i, n) {
441
- f(this, "url");
463
+ c(this, "url");
442
464
  /** the key to lookup the LOD information */
443
- f(this, "key");
444
- f(this, "level");
465
+ c(this, "key");
466
+ c(this, "level");
445
467
  /** For multi objects (e.g. a group of meshes) this is the index of the object */
446
- f(this, "index");
468
+ c(this, "index");
447
469
  /** the mesh density */
448
- f(this, "density");
470
+ c(this, "density");
449
471
  this.url = e, this.key = t, this.level = r, i != null && (this.index = i), n != null && (this.density = n);
450
472
  }
451
473
  }
452
- const ee = ie("debugprogressive"), Ae = ie("noprogressive"), le = Symbol("Needle:LODSManager"), A = { mesh_lod: -1, texture_lod: -1 }, T = class {
474
+ const $ = ie("debugprogressive"), Ae = ie("noprogressive"), le = Symbol("Needle:LODSManager"), b = { mesh_lod: -1, texture_lod: -1 }, A = class {
453
475
  // readonly plugins: NEEDLE_progressive_plugin[] = [];
454
476
  constructor(e) {
455
- f(this, "renderer");
456
- f(this, "projectionScreenMatrix", new ne());
457
- f(this, "cameraFrustrum", new Me());
477
+ c(this, "renderer");
478
+ c(this, "projectionScreenMatrix", new ne());
479
+ c(this, "cameraFrustrum", new Me());
458
480
  /**
459
481
  * The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
460
482
  * @default 200_000
461
483
  */
462
- f(this, "targetTriangleDensity", 2e5);
484
+ c(this, "targetTriangleDensity", 2e5);
463
485
  /**
464
486
  * 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.
465
487
  */
466
- f(this, "updateInterval", 0);
488
+ c(this, "updateInterval", 0);
467
489
  /**
468
490
  * If set to true, the LODsManager will not update the LODs.
469
491
  */
470
- f(this, "pause", !1);
471
- f(this, "_frame", 0);
472
- f(this, "_originalRender");
492
+ c(this, "pause", !1);
493
+ c(this, "_frame", 0);
494
+ c(this, "_originalRender");
473
495
  // private testIfLODLevelsAreAvailable() {
474
- f(this, "_sphere", new Oe());
475
- f(this, "_tempBox", new oe());
476
- f(this, "_tempBox2", new oe());
477
- f(this, "tempMatrix", new ne());
478
- f(this, "_tempWorldPosition", new k());
479
- f(this, "_tempBoxSize", new k());
480
- f(this, "_tempBox2Size", new k());
496
+ c(this, "_sphere", new Oe());
497
+ c(this, "_tempBox", new oe());
498
+ c(this, "_tempBox2", new oe());
499
+ c(this, "tempMatrix", new ne());
500
+ c(this, "_tempWorldPosition", new k());
501
+ c(this, "_tempBoxSize", new k());
502
+ c(this, "_tempBox2Size", new k());
481
503
  this.renderer = e;
482
504
  }
483
505
  /** @internal */
@@ -486,11 +508,11 @@ const ee = ie("debugprogressive"), Ae = ie("noprogressive"), le = Symbol("Needle
486
508
  return (t = e.userData) == null ? void 0 : t.LOD_state;
487
509
  }
488
510
  static addPlugin(e) {
489
- B.push(e);
511
+ I.push(e);
490
512
  }
491
513
  static removePlugin(e) {
492
- const t = B.indexOf(e);
493
- t >= 0 && B.splice(t, 1);
514
+ const t = I.indexOf(e);
515
+ t >= 0 && I.splice(t, 1);
494
516
  }
495
517
  /**
496
518
  * Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
@@ -498,11 +520,11 @@ const ee = ie("debugprogressive"), Ae = ie("noprogressive"), le = Symbol("Needle
498
520
  * @returns The LODsManager instance.
499
521
  */
500
522
  static get(e) {
501
- return e[le] ? e[le] : new T(e);
523
+ return e[le] ? e[le] : new A(e);
502
524
  }
503
525
  /** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
504
526
  get plugins() {
505
- return B;
527
+ return I;
506
528
  }
507
529
  /**
508
530
  * Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
@@ -513,7 +535,7 @@ const ee = ie("debugprogressive"), Ae = ie("noprogressive"), le = Symbol("Needle
513
535
  let e = 0;
514
536
  this._originalRender = this.renderer.render;
515
537
  const t = this;
516
- fe(this.renderer), this.renderer.render = function(r, i) {
538
+ ue(this.renderer), this.renderer.render = function(r, i) {
517
539
  t.renderer.getRenderTarget() == null && (e = 0, t._frame += 1);
518
540
  const s = t._frame, o = e++;
519
541
  t.onBeforeRender(r, i, o, s), t._originalRender.call(this, r, i), t.onAfterRender(r, i, o, s);
@@ -525,7 +547,7 @@ const ee = ie("debugprogressive"), Ae = ie("noprogressive"), le = Symbol("Needle
525
547
  onBeforeRender(e, t, r, i) {
526
548
  }
527
549
  onAfterRender(e, t, r, i) {
528
- var l, d;
550
+ var a, f;
529
551
  if (this.pause)
530
552
  return;
531
553
  const n = this.renderer.renderLists.get(e, 0), s = n.opaque;
@@ -539,12 +561,12 @@ const ee = ie("debugprogressive"), Ae = ie("noprogressive"), le = Symbol("Needle
539
561
  return;
540
562
  this.projectionScreenMatrix.multiplyMatrices(t.projectionMatrix, t.matrixWorldInverse), this.cameraFrustrum.setFromProjectionMatrix(this.projectionScreenMatrix, this.renderer.coordinateSystem);
541
563
  const h = this.targetTriangleDensity;
542
- for (const u of s) {
543
- if (u.material && (((l = u.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((d = u.geometry) == null ? void 0 : d.type) === "BufferGeometry") && (u.material.name === "SphericalGaussianBlur" || u.material.name == "BackgroundCubeMaterial" || u.material.name === "CubemapFromEquirect" || u.material.name === "EquirectangularToCubeUV")) {
544
- ee && (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)));
564
+ for (const d of s) {
565
+ if (d.material && (((a = d.geometry) == null ? void 0 : a.type) === "BoxGeometry" || ((f = d.geometry) == null ? void 0 : f.type) === "BufferGeometry") && (d.material.name === "SphericalGaussianBlur" || d.material.name == "BackgroundCubeMaterial" || d.material.name === "CubemapFromEquirect" || d.material.name === "EquirectangularToCubeUV")) {
566
+ $ && (d.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (d.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", d, d.material.name, d.material.type)));
545
567
  continue;
546
568
  }
547
- switch (u.material.type) {
569
+ switch (d.material.type) {
548
570
  case "LineBasicMaterial":
549
571
  case "LineDashedMaterial":
550
572
  case "PointsMaterial":
@@ -553,33 +575,33 @@ const ee = ie("debugprogressive"), Ae = ie("noprogressive"), le = Symbol("Needle
553
575
  case "MeshDepthMaterial":
554
576
  continue;
555
577
  }
556
- const y = u.object;
557
- (y instanceof V || y.isMesh) && this.updateLODs(e, t, y, h, i);
578
+ const y = d.object;
579
+ (y instanceof H || y.isMesh) && this.updateLODs(e, t, y, h, i);
558
580
  }
559
- const m = n.transparent;
560
- for (const u of m) {
561
- const y = u.object;
562
- (y instanceof V || y.isMesh) && this.updateLODs(e, t, y, h, i);
581
+ const x = n.transparent;
582
+ for (const d of x) {
583
+ const y = d.object;
584
+ (y instanceof H || y.isMesh) && this.updateLODs(e, t, y, h, i);
563
585
  }
564
586
  }
565
587
  }
566
588
  /** Update the LOD levels for the renderer. */
567
589
  updateLODs(e, t, r, i, n) {
568
- var l, d;
590
+ var a, f;
569
591
  let s = r.userData.LOD_state;
570
- if (s || (s = new Pe(), r.userData.LOD_state = s), s.frames++ < 2)
592
+ if (s || (s = new be(), r.userData.LOD_state = s), s.frames++ < 2)
571
593
  return;
572
- for (const h of B)
573
- (l = h.onBeforeUpdateLOD) == null || l.call(h, this.renderer, e, t, r);
574
- this.calculateLodLevel(t, r, s, i, A), A.mesh_lod = Math.round(A.mesh_lod), A.texture_lod = Math.round(A.texture_lod), A.mesh_lod >= 0 && this.loadProgressiveMeshes(r, A.mesh_lod);
575
- let o = A.texture_lod;
594
+ for (const h of I)
595
+ (a = h.onBeforeUpdateLOD) == null || a.call(h, this.renderer, e, t, r);
596
+ this.calculateLodLevel(t, r, s, i, 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);
597
+ let o = b.texture_lod;
576
598
  if (r.material && o >= 0) {
577
599
  const h = r["DEBUG:LOD"];
578
600
  h != null && (o = h), this.loadProgressiveTextures(r.material, o);
579
601
  }
580
- for (const h of B)
581
- (d = h.onAfterUpdatedLOD) == null || d.call(h, this.renderer, e, t, r, A);
582
- s.lastLodLevel_Mesh = A.mesh_lod, s.lasLodLevel_Texture = A.texture_lod;
602
+ for (const h of I)
603
+ (f = h.onAfterUpdatedLOD) == null || f.call(h, this.renderer, e, t, r, b);
604
+ s.lastLodLevel_Mesh = b.mesh_lod, s.lastLodLevel_Texture = b.texture_lod;
583
605
  }
584
606
  /** Load progressive textures for the given material
585
607
  * @param material the material to load the textures for
@@ -596,7 +618,7 @@ const ee = ie("debugprogressive"), Ae = ie("noprogressive"), le = Symbol("Needle
596
618
  }
597
619
  const r = e;
598
620
  let i = !1;
599
- (r.NEEDLE_LOD == null || t < r.NEEDLE_LOD) && (i = !0), i && (r.NEEDLE_LOD = t, S.assignTextureLOD(e, t));
621
+ (r.NEEDLE_LOD == null || t < r.NEEDLE_LOD) && (i = !0), i && (r.NEEDLE_LOD = t, v.assignTextureLOD(e, t));
600
622
  }
601
623
  /** Load progressive meshes for the given mesh
602
624
  * @param mesh the mesh to load the LOD for
@@ -610,7 +632,7 @@ const ee = ie("debugprogressive"), Ae = ie("noprogressive"), le = Symbol("Needle
610
632
  if (e.userData || (e.userData = {}), e.userData.LOD !== t) {
611
633
  e.userData.LOD = t;
612
634
  const r = e.geometry;
613
- return S.assignMeshLOD(e, t).then((i) => (i && e.userData.LOD == t && r != e.geometry, i));
635
+ return v.assignMeshLOD(e, t).then((i) => (i && e.userData.LOD == t && r != e.geometry, i));
614
636
  }
615
637
  return Promise.resolve(null);
616
638
  }
@@ -619,7 +641,7 @@ const ee = ie("debugprogressive"), Ae = ie("noprogressive"), le = Symbol("Needle
619
641
  return this._tempPtInside.set(n, s, r.z).applyMatrix4(t).z < 0;
620
642
  }
621
643
  calculateLodLevel(e, t, r, i, n) {
622
- var x;
644
+ var D;
623
645
  if (!t) {
624
646
  n.mesh_lod = -1, n.texture_lod = -1;
625
647
  return;
@@ -629,14 +651,14 @@ const ee = ie("debugprogressive"), Ae = ie("noprogressive"), le = Symbol("Needle
629
651
  return;
630
652
  }
631
653
  let o = 10 + 1;
632
- if (ee && t["DEBUG:LOD"] != null)
654
+ if ($ && t["DEBUG:LOD"] != null)
633
655
  return t["DEBUG:LOD"];
634
- const l = S.getMeshLODInformation(t.geometry), d = l == null ? void 0 : l.lods, h = d && d.length > 0, m = S.getMaterialMinMaxLODsCount(t.material), u = (m == null ? void 0 : m.min) != 1 / 0 && m.min > 0 && m.max > 0;
635
- if (!h && !u) {
656
+ const a = v.getMeshLODInformation(t.geometry), f = a == null ? void 0 : a.lods, h = f && f.length > 0, x = v.getMaterialMinMaxLODsCount(t.material), d = (x == null ? void 0 : x.min_count) != 1 / 0 && x.min_count > 0 && x.max_count > 0;
657
+ if (!h && !d) {
636
658
  n.mesh_lod = 0, n.texture_lod = 0;
637
659
  return;
638
660
  }
639
- if (h || (o = 0), !((x = this.cameraFrustrum) != null && x.intersectsObject(t))) {
661
+ if (h || (o = 0), !((D = this.cameraFrustrum) != null && D.intersectsObject(t))) {
640
662
  n.mesh_lod = 99, n.texture_lod = 99;
641
663
  return;
642
664
  }
@@ -651,79 +673,89 @@ const ee = ie("debugprogressive"), Ae = ie("noprogressive"), le = Symbol("Needle
651
673
  return;
652
674
  }
653
675
  }
654
- if (this._tempBox.copy(y), this._tempBox.applyMatrix4(t.matrixWorld), T.isInside(this._tempBox, this.projectionScreenMatrix)) {
676
+ if (this._tempBox.copy(y), this._tempBox.applyMatrix4(t.matrixWorld), A.isInside(this._tempBox, this.projectionScreenMatrix)) {
655
677
  n.mesh_lod = 0, n.texture_lod = 0;
656
678
  return;
657
679
  }
658
680
  if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && M.fov > 70) {
659
681
  const p = this._tempBox.min, g = this._tempBox.max;
660
- let c = p.x, L = p.y, _ = g.x, C = g.y;
661
- const I = 2, U = 1.5, q = (p.x + g.x) * 0.5, K = (p.y + g.y) * 0.5;
662
- c = (c - q) * I + q, L = (L - K) * I + K, _ = (_ - q) * I + q, C = (C - K) * I + K;
663
- const de = c < 0 && _ > 0 ? 0 : Math.min(Math.abs(p.x), Math.abs(g.x)), he = L < 0 && C > 0 ? 0 : Math.min(Math.abs(p.y), Math.abs(g.y)), Z = Math.max(de, he);
664
- r.lastCentrality = (U - Z) * (U - Z) * (U - Z);
682
+ let u = p.x, L = p.y, S = g.x, C = g.y;
683
+ const F = 2, z = 1.5, q = (p.x + g.x) * 0.5, X = (p.y + g.y) * 0.5;
684
+ u = (u - q) * F + q, L = (L - X) * F + X, S = (S - q) * F + q, C = (C - X) * F + X;
685
+ const de = u < 0 && S > 0 ? 0 : Math.min(Math.abs(p.x), Math.abs(g.x)), he = L < 0 && C > 0 ? 0 : Math.min(Math.abs(p.y), Math.abs(g.y)), j = Math.max(de, he);
686
+ r.lastCentrality = (z - j) * (z - j) * (z - j);
665
687
  } else
666
688
  r.lastCentrality = 1;
667
- const D = this._tempBox.getSize(this._tempBoxSize);
668
- D.multiplyScalar(0.5), screen.availHeight > 0 && D.multiplyScalar(this.renderer.domElement.clientHeight / screen.availHeight), D.x *= M.aspect;
669
- const G = e.matrixWorldInverse, O = this._tempBox2;
670
- O.copy(y), O.applyMatrix4(t.matrixWorld), O.applyMatrix4(G);
671
- const P = O.getSize(this._tempBox2Size), F = Math.max(P.x, P.y);
672
- if (Math.max(D.x, D.y) != 0 && F != 0 && (D.z = P.z / Math.max(P.x, P.y) * Math.max(D.x, D.y)), r.lastScreenCoverage = Math.max(D.x, D.y, D.z), r.lastScreenspaceVolume.copy(D), r.lastScreenCoverage *= r.lastCentrality, ee && T.debugDrawLine) {
689
+ const O = this._tempBox.getSize(this._tempBoxSize);
690
+ O.multiplyScalar(0.5), screen.availHeight > 0 && O.multiplyScalar(this.renderer.domElement.clientHeight / screen.availHeight), O.x *= M.aspect;
691
+ const B = e.matrixWorldInverse, m = this._tempBox2;
692
+ m.copy(y), m.applyMatrix4(t.matrixWorld), m.applyMatrix4(B);
693
+ const T = m.getSize(this._tempBox2Size), G = Math.max(T.x, T.y);
694
+ if (Math.max(O.x, O.y) != 0 && G != 0 && (O.z = T.z / Math.max(T.x, T.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, $ && A.debugDrawLine) {
673
695
  const p = this.tempMatrix.copy(this.projectionScreenMatrix);
674
696
  p.invert();
675
- const g = T.corner0, c = T.corner1, L = T.corner2, _ = T.corner3;
676
- g.copy(this._tempBox.min), c.copy(this._tempBox.max), c.x = g.x, L.copy(this._tempBox.max), L.y = g.y, _.copy(this._tempBox.max);
677
- const C = (g.z + _.z) * 0.5;
678
- g.z = c.z = L.z = _.z = C, g.applyMatrix4(p), c.applyMatrix4(p), L.applyMatrix4(p), _.applyMatrix4(p), T.debugDrawLine(g, c, 255), T.debugDrawLine(g, L, 255), T.debugDrawLine(c, _, 255), T.debugDrawLine(L, _, 255);
697
+ const g = A.corner0, u = A.corner1, L = A.corner2, S = A.corner3;
698
+ g.copy(this._tempBox.min), u.copy(this._tempBox.max), u.x = g.x, L.copy(this._tempBox.max), L.y = g.y, S.copy(this._tempBox.max);
699
+ const C = (g.z + S.z) * 0.5;
700
+ g.z = u.z = L.z = S.z = C, g.applyMatrix4(p), u.applyMatrix4(p), L.applyMatrix4(p), S.applyMatrix4(p), A.debugDrawLine(g, u, 255), A.debugDrawLine(g, L, 255), A.debugDrawLine(u, S, 255), A.debugDrawLine(L, S, 255);
679
701
  }
680
702
  let E = 999;
681
- if (d && r.lastScreenCoverage > 0) {
682
- for (let p = 0; p < d.length; p++)
683
- if (d[p].density / r.lastScreenCoverage < i) {
703
+ if (f && r.lastScreenCoverage > 0) {
704
+ for (let p = 0; p < f.length; p++)
705
+ if (f[p].density / r.lastScreenCoverage < i) {
684
706
  E = p;
685
707
  break;
686
708
  }
687
709
  }
688
710
  E < o && (o = E);
689
711
  }
690
- if (n.mesh_lod = o, m != null && m.min && m.min > 0 && m.max > 0) {
691
- const M = Math.min(1, Math.max(0, r.lastScreenCoverage * 3));
692
- n.texture_lod = be(m.max, 0, M);
693
- } else
712
+ if (n.mesh_lod = o, d)
713
+ if (r.lastLodLevel_Texture < 0) {
714
+ if (n.texture_lod = x.max_count - 1, $) {
715
+ const M = x.lods[x.max_count - 1];
716
+ $ && console.log(`First Texture LOD ${n.texture_lod} (${M.max_height}px) - ${t.name}`);
717
+ }
718
+ } else {
719
+ const M = r.lastScreenCoverage * 1.5, B = this.renderer.domElement.clientHeight / window.devicePixelRatio * M;
720
+ for (let m = x.lods.length - 1; m >= 0; m--) {
721
+ const T = x.lods[m];
722
+ if (T.max_height > B) {
723
+ n.texture_lod = m, n.texture_lod < r.lastLodLevel_Texture && $ && console.log(`Texture LOD changed ${r.lastLodLevel_Texture} → ${n.texture_lod} (${T.max_height}px: ${(100 * r.lastScreenCoverage).toFixed(2)} % = ${B.toFixed(0)}px) - ${t.name}`);
724
+ break;
725
+ }
726
+ }
727
+ }
728
+ else
694
729
  n.texture_lod = 0;
695
730
  }
696
731
  };
697
- let b = T;
732
+ let P = A;
698
733
  /** 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.
699
734
  */
700
- 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());
701
- function be(a, e, t) {
702
- return a + (e - a) * t;
703
- }
704
- class Pe {
735
+ c(P, "debugDrawLine"), c(P, "corner0", new k()), c(P, "corner1", new k()), c(P, "corner2", new k()), c(P, "corner3", new k()), c(P, "_tempPtInside", new k());
736
+ class be {
705
737
  constructor() {
706
- f(this, "frames", 0);
707
- f(this, "lastLodLevel_Mesh", 0);
708
- f(this, "lasLodLevel_Texture", 0);
709
- f(this, "lastScreenCoverage", 0);
710
- f(this, "lastScreenspaceVolume", new k());
711
- f(this, "lastCentrality", 0);
738
+ c(this, "frames", 0);
739
+ c(this, "lastLodLevel_Mesh", -1);
740
+ c(this, "lastLodLevel_Texture", -1);
741
+ c(this, "lastScreenCoverage", 0);
742
+ c(this, "lastScreenspaceVolume", new k());
743
+ c(this, "lastCentrality", 0);
712
744
  }
713
745
  }
714
- const ce = Symbol("NEEDLE_mesh_lod"), X = Symbol("NEEDLE_texture_lod");
715
- function Ee(a) {
716
- if (!a)
746
+ const ce = Symbol("NEEDLE_mesh_lod"), Y = Symbol("NEEDLE_texture_lod");
747
+ function Pe(l) {
748
+ if (!l)
717
749
  return null;
718
750
  let e = null, t = null;
719
- for (let r = a; r != null; r = Object.getPrototypeOf(r)) {
751
+ for (let r = l; r != null; r = Object.getPrototypeOf(r)) {
720
752
  const i = Object.getOwnPropertySymbols(r), n = i.find((o) => o.toString() == "Symbol(renderer)"), s = i.find((o) => o.toString() == "Symbol(scene)");
721
- !e && n != null && (e = a[n].threeRenderer), !t && s != null && (t = a[s]);
753
+ !e && n != null && (e = l[n].threeRenderer), !t && s != null && (t = l[s]);
722
754
  }
723
755
  if (e) {
724
756
  console.log("Adding Needle LODs to modelviewer");
725
- const r = b.get(e);
726
- if (b.addPlugin(new Ce(a)), r.enable(), t) {
757
+ const r = P.get(e);
758
+ if (P.addPlugin(new Ee(l)), r.enable(), t) {
727
759
  const i = t.camera || t.traverse((n) => n.type == "PerspectiveCamera")[0];
728
760
  i && e.render(t, i);
729
761
  }
@@ -733,10 +765,10 @@ function Ee(a) {
733
765
  }
734
766
  return null;
735
767
  }
736
- class Ce {
768
+ class Ee {
737
769
  constructor(e) {
738
- f(this, "modelviewer");
739
- f(this, "_didWarnAboutMissingUrl", !1);
770
+ c(this, "modelviewer");
771
+ c(this, "_didWarnAboutMissingUrl", !1);
740
772
  this.modelviewer = e;
741
773
  }
742
774
  onBeforeUpdateLOD(e, t, r, i) {
@@ -750,28 +782,28 @@ class Ce {
750
782
  return e._currentGLTF;
751
783
  }
752
784
  tryParseTextureLOD(e, t) {
753
- if (t[X] == !0)
785
+ if (t[Y] == !0)
754
786
  return;
755
- t[X] = !0;
787
+ t[Y] = !0;
756
788
  const r = this.tryGetCurrentGLTF(e), i = this.getUrl();
757
789
  if (i && r && t.material) {
758
790
  let n = function(o) {
759
- var d, h, m;
760
- if (o[X] == !0)
791
+ var f, h, x;
792
+ if (o[Y] == !0)
761
793
  return;
762
- o[X] = !0, o.userData && (o.userData.LOD = -1);
763
- const l = Object.keys(o);
764
- for (let u = 0; u < l.length; u++) {
765
- const y = l[u], x = o[y];
766
- if ((x == null ? void 0 : x.isTexture) === !0) {
767
- const M = (h = (d = x.userData) == null ? void 0 : d.associations) == null ? void 0 : h.textures, D = r.parser.json.textures[M];
768
- if (!D) {
794
+ o[Y] = !0, o.userData && (o.userData.LOD = -1);
795
+ const a = Object.keys(o);
796
+ for (let d = 0; d < a.length; d++) {
797
+ const y = a[d], D = o[y];
798
+ if ((D == null ? void 0 : D.isTexture) === !0) {
799
+ const M = (h = (f = D.userData) == null ? void 0 : f.associations) == null ? void 0 : h.textures, O = r.parser.json.textures[M];
800
+ if (!O) {
769
801
  console.warn("Texture data not found for texture index " + M);
770
802
  continue;
771
803
  }
772
- if ((m = D == null ? void 0 : D.extensions) != null && m[R]) {
773
- const G = D.extensions[R];
774
- G && i && S.registerTexture(i, x, G.lods.length, G);
804
+ if ((x = O == null ? void 0 : O.extensions) != null && x[R]) {
805
+ const B = O.extensions[R];
806
+ B && i && v.registerTexture(i, D, B.lods.length, M, B);
775
807
  }
776
808
  }
777
809
  }
@@ -795,28 +827,28 @@ class Ce {
795
827
  const i = (s = (n = t.userData) == null ? void 0 : n.gltfExtensions) == null ? void 0 : s[R];
796
828
  if (i && r) {
797
829
  const o = t.uuid;
798
- S.registerMesh(r, o, t, 0, i.lods.length, i);
830
+ v.registerMesh(r, o, t, 0, i.lods.length, i);
799
831
  }
800
832
  }
801
833
  }
802
- function ze(a, e, t, r) {
803
- fe(e), ue(t), t.register((n) => new S(n, a));
804
- const i = b.get(e);
834
+ function $e(l, e, t, r) {
835
+ ue(e), fe(t), t.register((n) => new v(n, l));
836
+ const i = P.get(e);
805
837
  return (r == null ? void 0 : r.enableLODsManager) !== !1 && i.enable(), i;
806
838
  }
807
839
  document.addEventListener("DOMContentLoaded", () => {
808
- Ee(document.querySelector("model-viewer"));
840
+ Pe(document.querySelector("model-viewer"));
809
841
  });
810
842
  export {
811
843
  R as EXTENSION_NAME,
812
- b as LODsManager,
813
- S as NEEDLE_progressive,
814
- ue as addDracoAndKTX2Loaders,
815
- fe as createLoaders,
816
- Se as getRaycastMesh,
817
- Ee as patchModelViewer,
818
- Ue as setDracoDecoderLocation,
819
- Ne as setKTX2TranscoderLocation,
820
- _e as setRaycastMesh,
821
- ze as useNeedleProgressive
844
+ P as LODsManager,
845
+ v as NEEDLE_progressive,
846
+ fe as addDracoAndKTX2Loaders,
847
+ ue as createLoaders,
848
+ ve as getRaycastMesh,
849
+ Pe as patchModelViewer,
850
+ Ge as setDracoDecoderLocation,
851
+ ze as setKTX2TranscoderLocation,
852
+ Se as setRaycastMesh,
853
+ $e as useNeedleProgressive
822
854
  };