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