@needle-tools/gltf-progressive 1.2.0-alpha.2 → 1.2.0-alpha.3

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