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