@needle-tools/gltf-progressive 1.2.14 → 2.0.0-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,51 +1,70 @@
1
- var $e = Object.defineProperty;
2
- var Ue = (a, t, e) => t in a ? $e(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
3
- var d = (a, t, e) => (Ue(a, typeof t != "symbol" ? t + "" : t, e), e), _e = (a, t, e) => {
4
- if (!t.has(a))
1
+ var Ve = Object.defineProperty;
2
+ var Ne = (o, t, e) => t in o ? Ve(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
3
+ var d = (o, t, e) => (Ne(o, typeof t != "symbol" ? t + "" : t, e), e), Te = (o, t, e) => {
4
+ if (!t.has(o))
5
5
  throw TypeError("Cannot " + e);
6
6
  };
7
- var m = (a, t, e) => (_e(a, t, "read from private field"), e ? e.call(a) : t.get(a)), K = (a, t, e) => {
8
- if (t.has(a))
7
+ var m = (o, t, e) => (Te(o, t, "read from private field"), e ? e.call(o) : t.get(o)), K = (o, t, e) => {
8
+ if (t.has(o))
9
9
  throw TypeError("Cannot add the same private member more than once");
10
- t instanceof WeakSet ? t.add(a) : t.set(a, e);
11
- }, U = (a, t, e, s) => (_e(a, t, "write to private field"), s ? s.call(a, e) : t.set(a, e), e);
12
- import { BufferGeometry as ge, Mesh as H, Material as ze, Texture as se, TextureLoader as Ve, Matrix4 as Se, Clock as Ne, MeshStandardMaterial as We, Sphere as Xe, Box3 as be, Vector3 as z } from "three";
13
- import { GLTFLoader as qe } from "three/examples/jsm/loaders/GLTFLoader.js";
14
- import { MeshoptDecoder as Ke } from "three/examples/jsm/libs/meshopt_decoder.module.js";
15
- import { DRACOLoader as Ye } from "three/examples/jsm/loaders/DRACOLoader.js";
16
- import { KTX2Loader as He } from "three/examples/jsm/loaders/KTX2Loader.js";
17
- const Ce = "";
18
- globalThis.GLTF_PROGRESSIVE_VERSION = Ce;
19
- console.debug(`[gltf-progressive] version ${Ce}`);
10
+ t instanceof WeakSet ? t.add(o) : t.set(o, e);
11
+ }, U = (o, t, e, s) => (Te(o, t, "write to private field"), s ? s.call(o, e) : t.set(o, e), e);
12
+ import { BufferGeometry as ge, Mesh as H, Material as We, Texture as se, TextureLoader as qe, Matrix4 as Ae, Clock as Xe, MeshStandardMaterial as Ke, Sphere as Ye, Box3 as Ee, Vector3 as z } from "three";
13
+ import { GLTFLoader as be } from "three/examples/jsm/loaders/GLTFLoader.js";
14
+ import { MeshoptDecoder as He } from "three/examples/jsm/libs/meshopt_decoder.module.js";
15
+ import { DRACOLoader as Je } from "three/examples/jsm/loaders/DRACOLoader.js";
16
+ import { KTX2Loader as Qe } from "three/examples/jsm/loaders/KTX2Loader.js";
17
+ const Ie = "";
18
+ globalThis.GLTF_PROGRESSIVE_VERSION = Ie;
19
+ console.debug(`[gltf-progressive] version ${Ie}`);
20
20
  let j = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", ae = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
21
- const Je = j, Qe = ae;
22
- fetch(j + "draco_decoder.js", { method: "head" }).catch((a) => {
23
- j === Je && (j = "./include/draco/"), ae === Qe && (ae = "./include/ktx2/");
21
+ const Ze = j, je = ae;
22
+ fetch(j + "draco_decoder.js", { method: "head" }).catch((o) => {
23
+ j === Ze && (j = "./include/draco/"), ae === je && (ae = "./include/ktx2/");
24
24
  });
25
- function gt(a) {
26
- j = a;
25
+ function xt(o) {
26
+ j = o;
27
27
  }
28
- function pt(a) {
29
- ae = a;
28
+ function Lt(o) {
29
+ ae = o;
30
30
  }
31
31
  let Q, he, Z;
32
- function Be(a) {
33
- return Q || (Q = new Ye(), Q.setDecoderPath(j), Q.setDecoderConfig({ type: "js" })), Z || (Z = new He(), Z.setTranscoderPath(ae)), he || (he = Ke), a ? Z.detectSupport(a) : a !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: Q, ktx2Loader: Z, meshoptDecoder: he };
32
+ function Re(o) {
33
+ return Q || (Q = new Je(), Q.setDecoderPath(j), Q.setDecoderConfig({ type: "js" })), Z || (Z = new Qe(), Z.setTranscoderPath(ae)), he || (he = He), o ? Z.detectSupport(o) : o !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: Q, ktx2Loader: Z, meshoptDecoder: he };
34
34
  }
35
- function Ie(a) {
36
- a.dracoLoader || a.setDRACOLoader(Q), a.ktx2Loader || a.setKTX2Loader(Z), a.meshoptDecoder || a.setMeshoptDecoder(he);
35
+ function Ge(o) {
36
+ o.dracoLoader || o.setDRACOLoader(Q), o.ktx2Loader || o.setKTX2Loader(Z), o.meshoptDecoder || o.setMeshoptDecoder(he);
37
37
  }
38
+ const Oe = /* @__PURE__ */ new WeakMap();
39
+ function et(o, t) {
40
+ let e = Oe.get(o);
41
+ e ? e = Object.assign(e, t) : e = t, Oe.set(o, e);
42
+ }
43
+ const Me = be.prototype.load;
44
+ function tt(...o) {
45
+ const t = Oe.get(this);
46
+ let e = o[0];
47
+ const s = new URL(e, window.location.href);
48
+ if (s.hostname.endsWith("needle.tools")) {
49
+ const r = t ? t.progressive : !0, i = t ? t.usecase : "default";
50
+ r ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${i}` : this.requestHeader.Accept = `*/*;usecase=${i}`, e = s.toString();
51
+ }
52
+ return o[0] = e, Me == null ? void 0 : Me.call(this, ...o);
53
+ }
54
+ be.prototype.load = tt;
38
55
  le("debugprogressive");
39
- function le(a) {
40
- const e = new URL(window.location.href).searchParams.get(a);
56
+ function le(o) {
57
+ if (typeof window > "u")
58
+ return !1;
59
+ const e = new URL(window.location.href).searchParams.get(o);
41
60
  return e == null || e === "0" || e === "false" ? !1 : e === "" ? !0 : e;
42
61
  }
43
- function Ze(a, t) {
44
- if (t === void 0 || t.startsWith("./") || t.startsWith("http") || a === void 0)
62
+ function st(o, t) {
63
+ if (t === void 0 || t.startsWith("./") || t.startsWith("http") || o === void 0)
45
64
  return t;
46
- const e = a.lastIndexOf("/");
65
+ const e = o.lastIndexOf("/");
47
66
  if (e >= 0) {
48
- const s = a.substring(0, e + 1);
67
+ const s = o.substring(0, e + 1);
49
68
  for (; s.endsWith("/") && t.startsWith("/"); )
50
69
  t = t.substring(1);
51
70
  return s + t;
@@ -53,21 +72,21 @@ function Ze(a, t) {
53
72
  return t;
54
73
  }
55
74
  let re;
56
- function je() {
75
+ function rt() {
57
76
  return re !== void 0 || (re = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), le("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", re)), re;
58
77
  }
59
- const ve = Symbol("needle:raycast-mesh");
60
- function me(a) {
61
- return (a == null ? void 0 : a[ve]) instanceof ge ? a[ve] : null;
78
+ const _e = Symbol("needle:raycast-mesh");
79
+ function me(o) {
80
+ return (o == null ? void 0 : o[_e]) instanceof ge ? o[_e] : null;
62
81
  }
63
- function et(a, t) {
64
- if ((a.type === "Mesh" || a.type === "SkinnedMesh") && !me(a)) {
65
- const s = tt(t);
66
- s.userData = { isRaycastMesh: !0 }, a[ve] = s;
82
+ function it(o, t) {
83
+ if ((o.type === "Mesh" || o.type === "SkinnedMesh") && !me(o)) {
84
+ const s = nt(t);
85
+ s.userData = { isRaycastMesh: !0 }, o[_e] = s;
67
86
  }
68
87
  }
69
- function yt(a = !0) {
70
- if (a) {
88
+ function Mt(o = !0) {
89
+ if (o) {
71
90
  if (ie)
72
91
  return;
73
92
  const t = ie = H.prototype.raycast;
@@ -83,21 +102,21 @@ function yt(a = !0) {
83
102
  }
84
103
  }
85
104
  let ie = null;
86
- function tt(a) {
105
+ function nt(o) {
87
106
  const t = new ge();
88
- for (const e in a.attributes)
89
- t.setAttribute(e, a.getAttribute(e));
90
- return t.setIndex(a.getIndex()), t;
107
+ for (const e in o.attributes)
108
+ t.setAttribute(e, o.getAttribute(e));
109
+ return t.setIndex(o.getIndex()), t;
91
110
  }
92
- const Y = new Array(), V = "NEEDLE_progressive", x = le("debugprogressive"), Me = Symbol("needle-progressive-texture"), oe = /* @__PURE__ */ new Map(), Oe = /* @__PURE__ */ new Set();
111
+ const Y = new Array(), V = "NEEDLE_progressive", x = le("debugprogressive"), De = Symbol("needle-progressive-texture"), oe = /* @__PURE__ */ new Map(), Se = /* @__PURE__ */ new Set();
93
112
  if (x) {
94
- let a = function() {
113
+ let o = function() {
95
114
  t += 1, console.log("Toggle LOD level", t, oe), oe.forEach((n, r) => {
96
115
  for (const i of n.keys) {
97
- const o = r[i];
98
- if (o != null) {
99
- if (o.isBufferGeometry === !0) {
100
- const l = _.getMeshLODInformation(o), u = l ? Math.min(t, l.lods.length) : 0;
116
+ const a = r[i];
117
+ if (a != null) {
118
+ if (a.isBufferGeometry === !0) {
119
+ const l = _.getMeshLODInformation(a), u = l ? Math.min(t, l.lods.length) : 0;
101
120
  r["DEBUG:LOD"] = t, _.assignMeshLOD(r, u), l && (e = Math.max(e, l.lods.length - 1));
102
121
  } else if (r.isMaterial === !0) {
103
122
  r["DEBUG:LOD"] = t, _.assignTextureLOD(r, t);
@@ -108,17 +127,17 @@ if (x) {
108
127
  }), t >= e && (t = -1);
109
128
  }, t = -1, e = 2, s = !1;
110
129
  window.addEventListener("keyup", (n) => {
111
- n.key === "p" && a(), n.key === "w" && (s = !s, Oe && Oe.forEach((r) => {
130
+ n.key === "p" && o(), n.key === "w" && (s = !s, Se && Se.forEach((r) => {
112
131
  r.name != "BackgroundCubeMaterial" && r.glyphMap == null && "wireframe" in r && (r.wireframe = s);
113
132
  }));
114
133
  });
115
134
  }
116
- function Te(a, t, e) {
135
+ function Pe(o, t, e) {
117
136
  var n;
118
137
  if (!x)
119
138
  return;
120
- oe.has(a) || oe.set(a, { keys: [], sourceId: e });
121
- const s = oe.get(a);
139
+ oe.has(o) || oe.set(o, { keys: [], sourceId: e });
140
+ const s = oe.get(o);
122
141
  ((n = s == null ? void 0 : s.keys) == null ? void 0 : n.includes(t)) == !1 && s.keys.push(t);
123
142
  }
124
143
  const v = class {
@@ -155,24 +174,24 @@ const v = class {
155
174
  max_count: 0,
156
175
  lods: []
157
176
  }), Array.isArray(t)) {
158
- for (const o of t)
159
- this.getMaterialMinMaxLODsCount(o, e);
177
+ for (const a of t)
178
+ this.getMaterialMinMaxLODsCount(a, e);
160
179
  return t[n] = e, e;
161
180
  }
162
181
  if (x === "verbose" && console.log("getMaterialMinMaxLODsCount", t), t.type === "ShaderMaterial" || t.type === "RawShaderMaterial") {
163
- const o = t;
164
- for (const l of Object.keys(o.uniforms)) {
165
- const u = o.uniforms[l].value;
182
+ const a = t;
183
+ for (const l of Object.keys(a.uniforms)) {
184
+ const u = a.uniforms[l].value;
166
185
  (u == null ? void 0 : u.isTexture) === !0 && i(u, e);
167
186
  }
168
187
  } else if (t.isMaterial)
169
- for (const o of Object.keys(t)) {
170
- const l = t[o];
188
+ for (const a of Object.keys(t)) {
189
+ const l = t[a];
171
190
  (l == null ? void 0 : l.isTexture) === !0 && i(l, e);
172
191
  }
173
192
  return t[n] = e, e;
174
- function i(o, l) {
175
- const u = s.getAssignedLODInformation(o);
193
+ function i(a, l) {
194
+ const u = s.getAssignedLODInformation(a);
176
195
  if (u) {
177
196
  const c = s.lodInfos.get(u.key);
178
197
  if (c && c.lods) {
@@ -200,8 +219,8 @@ const v = class {
200
219
  }
201
220
  if (t.isMaterial === !0) {
202
221
  for (const i of Object.keys(t)) {
203
- const o = t[i];
204
- if (o && o.isTexture && this.hasLODLevelAvailable(o, e))
222
+ const a = t[i];
223
+ if (a && a.isTexture && this.hasLODLevelAvailable(a, e))
205
224
  return !0;
206
225
  }
207
226
  return !1;
@@ -247,10 +266,10 @@ const v = class {
247
266
  return t["LOD:requested level"] = e, v.getOrLoadLOD(n, e).then((i) => {
248
267
  if (t["LOD:requested level"] === e) {
249
268
  if (delete t["LOD:requested level"], Array.isArray(i)) {
250
- const o = r.index || 0;
251
- i = i[o];
269
+ const a = r.index || 0;
270
+ i = i[a];
252
271
  }
253
- i && n != i && ((i == null ? void 0 : i.isBufferGeometry) ? (t.geometry = i, x && Te(t, "geometry", r.url)) : x && console.error("Invalid LOD geometry", i));
272
+ i && n != i && ((i == null ? void 0 : i.isBufferGeometry) ? (t.geometry = i, x && Pe(t, "geometry", r.url)) : x && console.error("Invalid LOD geometry", i));
254
273
  }
255
274
  return i;
256
275
  }).catch((i) => (console.error("Error loading mesh LOD", t, i), null));
@@ -271,39 +290,39 @@ const v = class {
271
290
  }
272
291
  return Promise.all(n).then((r) => {
273
292
  const i = new Array();
274
- for (const o of r)
275
- Array.isArray(o) && i.push(...o);
293
+ for (const a of r)
294
+ Array.isArray(a) && i.push(...a);
276
295
  return i;
277
296
  });
278
297
  } else
279
298
  return this.assignTextureLOD(s.material, e);
280
299
  }
281
- if (t instanceof ze || t.isMaterial === !0) {
300
+ if (t instanceof We || t.isMaterial === !0) {
282
301
  const s = t, n = [], r = new Array();
283
- if (x && Oe.add(s), s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
302
+ if (x && Se.add(s), s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
284
303
  const i = s;
285
- for (const o of Object.keys(i.uniforms)) {
286
- const l = i.uniforms[o].value;
304
+ for (const a of Object.keys(i.uniforms)) {
305
+ const l = i.uniforms[a].value;
287
306
  if ((l == null ? void 0 : l.isTexture) === !0) {
288
- const u = this.assignTextureLODForSlot(l, e, s, o).then((c) => (c && i.uniforms[o].value != c && (i.uniforms[o].value = c, i.uniformsNeedUpdate = !0), c));
289
- n.push(u), r.push(o);
307
+ const u = this.assignTextureLODForSlot(l, e, s, a).then((c) => (c && i.uniforms[a].value != c && (i.uniforms[a].value = c, i.uniformsNeedUpdate = !0), c));
308
+ n.push(u), r.push(a);
290
309
  }
291
310
  }
292
311
  } else
293
312
  for (const i of Object.keys(s)) {
294
- const o = s[i];
295
- if ((o == null ? void 0 : o.isTexture) === !0) {
296
- const l = this.assignTextureLODForSlot(o, e, s, i);
313
+ const a = s[i];
314
+ if ((a == null ? void 0 : a.isTexture) === !0) {
315
+ const l = this.assignTextureLODForSlot(a, e, s, i);
297
316
  n.push(l), r.push(i);
298
317
  }
299
318
  }
300
319
  return Promise.all(n).then((i) => {
301
- const o = new Array();
320
+ const a = new Array();
302
321
  for (let l = 0; l < i.length; l++) {
303
322
  const u = i[l], c = r[l];
304
- u && u.isTexture === !0 ? o.push({ material: s, slot: c, texture: u, level: e }) : o.push({ material: s, slot: c, texture: null, level: e });
323
+ u && u.isTexture === !0 ? a.push({ material: s, slot: c, texture: u, level: e }) : a.push({ material: s, slot: c, texture: null, level: e });
305
324
  }
306
- return o;
325
+ return a;
307
326
  });
308
327
  }
309
328
  if (t instanceof se || t.isTexture === !0) {
@@ -321,15 +340,15 @@ const v = class {
321
340
  if (s && n) {
322
341
  const i = s[n];
323
342
  if (i) {
324
- const o = this.getAssignedLODInformation(i);
325
- if (o && (o == null ? void 0 : o.level) < e)
326
- return x === "verbose" && console.warn("Assigned texture level is already higher: ", o.level, e, s, i, r), null;
343
+ const a = this.getAssignedLODInformation(i);
344
+ if (a && (a == null ? void 0 : a.level) < e)
345
+ return x === "verbose" && console.warn("Assigned texture level is already higher: ", a.level, e, s, i, r), null;
327
346
  }
328
347
  s[n] = r;
329
348
  }
330
349
  if (x && n && s) {
331
350
  const i = this.getAssignedLODInformation(t);
332
- i && Te(s, n, i.url);
351
+ i && Pe(s, n, i.url);
333
352
  }
334
353
  }
335
354
  return r;
@@ -343,21 +362,21 @@ const v = class {
343
362
  return x && console.log("AFTER", this.url, t), (e = this.parser.json.textures) == null || e.forEach((n, r) => {
344
363
  var i;
345
364
  if (n != null && n.extensions) {
346
- const o = n == null ? void 0 : n.extensions[V];
347
- if (o) {
348
- if (!o.lods) {
349
- x && console.warn("Texture has no LODs", o);
365
+ const a = n == null ? void 0 : n.extensions[V];
366
+ if (a) {
367
+ if (!a.lods) {
368
+ x && console.warn("Texture has no LODs", a);
350
369
  return;
351
370
  }
352
371
  let l = !1;
353
372
  for (const u of this.parser.associations.keys())
354
373
  if (u.isTexture === !0) {
355
374
  const c = this.parser.associations.get(u);
356
- (c == null ? void 0 : c.textures) === r && (l = !0, v.registerTexture(this.url, u, (i = o.lods) == null ? void 0 : i.length, r, o));
375
+ (c == null ? void 0 : c.textures) === r && (l = !0, v.registerTexture(this.url, u, (i = a.lods) == null ? void 0 : i.length, r, a));
357
376
  }
358
377
  l || this.parser.getDependency("texture", r).then((u) => {
359
378
  var c;
360
- u && v.registerTexture(this.url, u, (c = o.lods) == null ? void 0 : c.length, r, o);
379
+ u && v.registerTexture(this.url, u, (c = a.lods) == null ? void 0 : c.length, r, a);
361
380
  });
362
381
  }
363
382
  }
@@ -365,17 +384,17 @@ const v = class {
365
384
  if (n != null && n.extensions) {
366
385
  const i = n == null ? void 0 : n.extensions[V];
367
386
  if (i && i.lods) {
368
- for (const o of this.parser.associations.keys())
369
- if (o.isMesh) {
370
- const l = this.parser.associations.get(o);
371
- (l == null ? void 0 : l.meshes) === r && v.registerMesh(this.url, i.guid, o, i.lods.length, l.primitives, i);
387
+ for (const a of this.parser.associations.keys())
388
+ if (a.isMesh) {
389
+ const l = this.parser.associations.get(a);
390
+ (l == null ? void 0 : l.meshes) === r && v.registerMesh(this.url, i.guid, a, i.lods.length, l.primitives, i);
372
391
  }
373
392
  }
374
393
  }
375
394
  }), null;
376
395
  }
377
396
  static async getOrLoadLOD(t, e) {
378
- var o, l, u, c;
397
+ var a, l, u, c;
379
398
  const s = x == "verbose", n = t.userData.LODS;
380
399
  if (!n)
381
400
  return null;
@@ -383,7 +402,7 @@ const v = class {
383
402
  let i;
384
403
  if (t.isTexture === !0) {
385
404
  const g = t;
386
- g.source && g.source[Me] && (i = g.source[Me]);
405
+ g.source && g.source[De] && (i = g.source[De]);
387
406
  }
388
407
  if (i || (i = v.lodInfos.get(r)), i) {
389
408
  if (e > 0) {
@@ -392,34 +411,34 @@ const v = class {
392
411
  if (w && e >= i.lods.length ? M = !0 : w || (M = !0), M)
393
412
  return this.lowresCache.get(r);
394
413
  }
395
- const g = Array.isArray(i.lods) ? (o = i.lods[e]) == null ? void 0 : o.path : i.lods;
414
+ const g = Array.isArray(i.lods) ? (a = i.lods[e]) == null ? void 0 : a.path : i.lods;
396
415
  if (!g)
397
416
  return x && !i["missing:uri"] && (i["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, i)), null;
398
- const p = Ze(n.url, g);
417
+ const p = st(n.url, g);
399
418
  if (p.endsWith(".glb") || p.endsWith(".gltf")) {
400
419
  if (!i.guid)
401
420
  return console.warn("missing pointer for glb/gltf texture", i), null;
402
421
  const M = p + "_" + i.guid, w = this.previouslyLoaded.get(M);
403
422
  if (w !== void 0) {
404
423
  s && console.log(`LOD ${e} was already loading/loaded: ${M}`);
405
- let h = await w.catch(($) => (console.error(`Error loading LOD ${e} from ${p}
406
- `, $), null)), B = !1;
424
+ let h = await w.catch((F) => (console.error(`Error loading LOD ${e} from ${p}
425
+ `, F), null)), B = !1;
407
426
  if (h == null || (h instanceof se && t instanceof se ? (l = h.image) != null && l.data || (u = h.source) != null && u.data ? h = this.copySettings(t, h) : (B = !0, this.previouslyLoaded.delete(M)) : h instanceof ge && t instanceof ge && ((c = h.attributes.position) != null && c.array || (B = !0, this.previouslyLoaded.delete(M)))), !B)
408
427
  return h;
409
428
  }
410
- const L = i, F = new Promise(async (h, B) => {
411
- const $ = new qe();
412
- Ie($), x && (await new Promise((A) => setTimeout(A, 1e3)), s && console.warn("Start loading (delayed) " + p, L.guid));
413
- let I = p;
429
+ const L = i, $ = new Promise(async (h, B) => {
430
+ const F = new be();
431
+ Ge(F), x && (await new Promise((A) => setTimeout(A, 1e3)), s && console.warn("Start loading (delayed) " + p, L.guid));
432
+ let k = p;
414
433
  if (L && Array.isArray(L.lods)) {
415
434
  const A = L.lods[e];
416
- A.hash && (I += "?v=" + A.hash);
435
+ A.hash && (k += "?v=" + A.hash);
417
436
  }
418
- const S = await $.loadAsync(I).catch((A) => (console.error(`Error loading LOD ${e} from ${p}
437
+ const S = await F.loadAsync(k).catch((A) => (console.error(`Error loading LOD ${e} from ${p}
419
438
  `, A), null));
420
439
  if (!S)
421
440
  return null;
422
- const X = S.parser;
441
+ const q = S.parser;
423
442
  s && console.log("Loading finished " + p, L.guid);
424
443
  let T = 0;
425
444
  if (S.parser.json.textures) {
@@ -435,7 +454,7 @@ const v = class {
435
454
  T++;
436
455
  }
437
456
  if (A) {
438
- let f = await X.getDependency("texture", T);
457
+ let f = await q.getDependency("texture", T);
439
458
  return f && v.assignLODInformation(n.url, f, r, e, void 0, void 0), s && console.log('change "' + t.name + '" → "' + f.name + '"', p, T, f, M), t instanceof se && (f = this.copySettings(t, f)), f && (f.guid = L.guid), h(f);
440
459
  } else
441
460
  x && console.warn("Could not find texture with guid", L.guid, S.parser.json);
@@ -453,7 +472,7 @@ const v = class {
453
472
  T++;
454
473
  }
455
474
  if (A) {
456
- const f = await X.getDependency("mesh", T), y = L;
475
+ const f = await q.getDependency("mesh", T), y = L;
457
476
  if (s && console.log(`Loaded Mesh "${f.name}"`, p, T, f, M), f.isMesh === !0) {
458
477
  const O = f.geometry;
459
478
  return v.assignLODInformation(n.url, O, r, e, void 0, y.density), h(O);
@@ -462,8 +481,8 @@ const v = class {
462
481
  for (let b = 0; b < f.children.length; b++) {
463
482
  const E = f.children[b];
464
483
  if (E.isMesh === !0) {
465
- const q = E.geometry;
466
- v.assignLODInformation(n.url, q, r, e, b, y.density), O.push(q);
484
+ const X = E.geometry;
485
+ v.assignLODInformation(n.url, X, r, e, b, y.density), O.push(X);
467
486
  }
468
487
  }
469
488
  return h(O);
@@ -473,10 +492,10 @@ const v = class {
473
492
  }
474
493
  return h(null);
475
494
  });
476
- return this.previouslyLoaded.set(M, F), await F;
495
+ return this.previouslyLoaded.set(M, $), await $;
477
496
  } else if (t instanceof se) {
478
497
  s && console.log("Load texture from uri: " + p);
479
- const w = await new Ve().loadAsync(p);
498
+ const w = await new qe().loadAsync(p);
480
499
  return w ? (w.guid = i.guid, w.flipY = !1, w.needsUpdate = !0, w.colorSpace = t.colorSpace, s && console.log(i, w)) : x && console.warn("failed loading", p), w;
481
500
  }
482
501
  } else
@@ -487,8 +506,8 @@ const v = class {
487
506
  if (!e)
488
507
  return;
489
508
  e.userData || (e.userData = {});
490
- const o = new st(t, s, n, r, i);
491
- e.userData.LODS = o;
509
+ const a = new ot(t, s, n, r, i);
510
+ e.userData.LODS = a;
492
511
  }
493
512
  static getAssignedLODInformation(t) {
494
513
  var e;
@@ -510,7 +529,7 @@ d(_, "registerTexture", (t, e, s, n, r) => {
510
529
  x && console.error("gltf-progressive: Register texture without texture");
511
530
  return;
512
531
  }
513
- e.source && (e.source[Me] = r);
532
+ e.source && (e.source[De] = r);
514
533
  const i = r.guid;
515
534
  v.assignLODInformation(t, e, i, s, n, void 0), v.lodInfos.set(i, r), v.lowresCache.set(i, e);
516
535
  }), /**
@@ -519,21 +538,21 @@ d(_, "registerTexture", (t, e, s, n, r) => {
519
538
  d(_, "registerMesh", (t, e, s, n, r, i) => {
520
539
  var u;
521
540
  x && console.log("> Progressive: register mesh", r, s.name, i, s.uuid, s);
522
- const o = s.geometry;
523
- if (!o) {
541
+ const a = s.geometry;
542
+ if (!a) {
524
543
  x && console.warn("gltf-progressive: Register mesh without geometry");
525
544
  return;
526
545
  }
527
- o.userData || (o.userData = {}), v.assignLODInformation(t, o, e, n, r, i.density), v.lodInfos.set(e, i);
546
+ a.userData || (a.userData = {}), v.assignLODInformation(t, a, e, n, r, i.density), v.lodInfos.set(e, i);
528
547
  let l = v.lowresCache.get(e);
529
- l ? l.push(s.geometry) : l = [s.geometry], v.lowresCache.set(e, l), n > 0 && !me(s) && et(s, o);
548
+ l ? l.push(s.geometry) : l = [s.geometry], v.lowresCache.set(e, l), n > 0 && !me(s) && it(s, a);
530
549
  for (const c of Y)
531
550
  (u = c.onRegisteredNewMesh) == null || u.call(c, s, i);
532
551
  }), /** A map of key = asset uuid and value = LOD information */
533
552
  d(_, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
534
553
  d(_, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
535
554
  d(_, "lowresCache", /* @__PURE__ */ new Map());
536
- class st {
555
+ class ot {
537
556
  constructor(t, e, s, n, r) {
538
557
  d(this, "url");
539
558
  /** the key to lookup the LOD information */
@@ -546,14 +565,14 @@ class st {
546
565
  this.url = t, this.key = e, this.level = s, n != null && (this.index = n), r != null && (this.density = r);
547
566
  }
548
567
  }
549
- const k = le("debugprogressive"), rt = le("noprogressive"), De = Symbol("Needle:LODSManager"), we = Symbol("Needle:LODState"), J = Symbol("Needle:CurrentLOD"), R = { mesh_lod: -1, texture_lod: -1 };
568
+ const I = le("debugprogressive"), at = le("noprogressive"), we = Symbol("Needle:LODSManager"), ve = Symbol("Needle:LODState"), J = Symbol("Needle:CurrentLOD"), R = { mesh_lod: -1, texture_lod: -1 };
550
569
  var C, N, pe, ee, te, ye, W;
551
570
  const P = class {
552
571
  // readonly plugins: NEEDLE_progressive_plugin[] = [];
553
572
  constructor(t, e) {
554
573
  d(this, "context");
555
574
  d(this, "renderer");
556
- d(this, "projectionScreenMatrix", new Se());
575
+ d(this, "projectionScreenMatrix", new Ae());
557
576
  /**
558
577
  * The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
559
578
  * @default 200_000
@@ -578,17 +597,17 @@ const P = class {
578
597
  d(this, "manual", !1);
579
598
  d(this, "_lodchangedlisteners", []);
580
599
  K(this, N, void 0);
581
- K(this, pe, new Ne());
600
+ K(this, pe, new Xe());
582
601
  K(this, ee, 0);
583
602
  K(this, te, 0);
584
603
  K(this, ye, 0);
585
604
  K(this, W, 0);
586
605
  d(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
587
606
  // private testIfLODLevelsAreAvailable() {
588
- d(this, "_sphere", new Xe());
589
- d(this, "_tempBox", new be());
590
- d(this, "_tempBox2", new be());
591
- d(this, "tempMatrix", new Se());
607
+ d(this, "_sphere", new Ye());
608
+ d(this, "_tempBox", new Ee());
609
+ d(this, "_tempBox2", new Ee());
610
+ d(this, "tempMatrix", new Ae());
592
611
  d(this, "_tempWorldPosition", new z());
593
612
  d(this, "_tempBoxSize", new z());
594
613
  d(this, "_tempBox2Size", new z());
@@ -596,7 +615,7 @@ const P = class {
596
615
  }
597
616
  /** @internal */
598
617
  static getObjectLODState(t) {
599
- return t[we];
618
+ return t[ve];
600
619
  }
601
620
  static addPlugin(t) {
602
621
  Y.push(t);
@@ -611,13 +630,13 @@ const P = class {
611
630
  * @returns The LODsManager instance.
612
631
  */
613
632
  static get(t, e) {
614
- if (t[De])
615
- return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[De];
633
+ if (t[we])
634
+ return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[we];
616
635
  const s = new P(t, {
617
636
  engine: "unknown",
618
637
  ...e
619
638
  });
620
- return t[De] = s, s;
639
+ return t[we] = s, s;
621
640
  }
622
641
  /** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
623
642
  get plugins() {
@@ -642,9 +661,9 @@ const P = class {
642
661
  let t = 0;
643
662
  U(this, N, this.renderer.render);
644
663
  const e = this;
645
- Be(this.renderer), this.renderer.render = function(s, n) {
664
+ Re(this.renderer), this.renderer.render = function(s, n) {
646
665
  const r = e.renderer.getRenderTarget();
647
- (r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (t = 0, U(e, ee, m(e, ee) + 1), U(e, te, m(e, pe).getDelta()), U(e, ye, m(e, ye) + m(e, te)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / m(e, te)), U(e, W, e._fpsBuffer.reduce((o, l) => o + l) / e._fpsBuffer.length), k && m(e, ee) % 200 === 0 && console.log("FPS", Math.round(m(e, W)), "Interval:", m(e, C)));
666
+ (r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (t = 0, U(e, ee, m(e, ee) + 1), U(e, te, m(e, pe).getDelta()), U(e, ye, m(e, ye) + m(e, te)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / m(e, te)), U(e, W, e._fpsBuffer.reduce((a, l) => a + l) / e._fpsBuffer.length), I && m(e, ee) % 200 === 0 && console.log("FPS", Math.round(m(e, W)), "Interval:", m(e, C)));
648
667
  const i = t++;
649
668
  m(e, N).call(this, s, n), e.onAfterRender(s, n, i);
650
669
  };
@@ -661,11 +680,11 @@ const P = class {
661
680
  const r = this.renderer.renderLists.get(t, 0).opaque;
662
681
  let i = !0;
663
682
  if (r.length === 1) {
664
- const o = r[0].material;
665
- (o.name === "EffectMaterial" || o.name === "CopyShader") && (i = !1);
683
+ const a = r[0].material;
684
+ (a.name === "EffectMaterial" || a.name === "CopyShader") && (i = !1);
666
685
  }
667
686
  if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (i = !1), i) {
668
- if (rt || (this.updateInterval === "auto" ? m(this, W) < 40 && m(this, C) < 10 ? (U(this, C, m(this, C) + 1), k && console.warn("↓ Reducing LOD updates", m(this, C), m(this, W).toFixed(0))) : m(this, W) >= 60 && m(this, C) > 1 && (U(this, C, m(this, C) - 1), k && console.warn("↑ Increasing LOD updates", m(this, C), m(this, W).toFixed(0))) : U(this, C, this.updateInterval), m(this, C) > 0 && m(this, ee) % m(this, C) != 0))
687
+ if (at || (this.updateInterval === "auto" ? m(this, W) < 40 && m(this, C) < 10 ? (U(this, C, m(this, C) + 1), I && console.warn("↓ Reducing LOD updates", m(this, C), m(this, W).toFixed(0))) : m(this, W) >= 60 && m(this, C) > 1 && (U(this, C, m(this, C) - 1), I && console.warn("↑ Increasing LOD updates", m(this, C), m(this, W).toFixed(0))) : U(this, C, this.updateInterval), m(this, C) > 0 && m(this, ee) % m(this, C) != 0))
669
688
  return;
670
689
  this.internalUpdate(t, e);
671
690
  }
@@ -680,7 +699,7 @@ const P = class {
680
699
  const r = this.targetTriangleDensity;
681
700
  for (const c of n) {
682
701
  if (c.material && (((l = c.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((u = c.geometry) == null ? void 0 : u.type) === "BufferGeometry") && (c.material.name === "SphericalGaussianBlur" || c.material.name == "BackgroundCubeMaterial" || c.material.name === "CubemapFromEquirect" || c.material.name === "EquirectangularToCubeUV")) {
683
- k && (c.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (c.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", c, c.material.name, c.material.type)));
702
+ I && (c.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (c.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", c, c.material.name, c.material.type)));
684
703
  continue;
685
704
  }
686
705
  switch (c.material.type) {
@@ -692,9 +711,9 @@ const P = class {
692
711
  case "MeshDepthMaterial":
693
712
  continue;
694
713
  }
695
- if (k === "color" && c.material && !c.object.progressive_debug_color) {
714
+ if (I === "color" && c.material && !c.object.progressive_debug_color) {
696
715
  c.object.progressive_debug_color = !0;
697
- const p = Math.random() * 16777215, M = new We({ color: p });
716
+ const p = Math.random() * 16777215, M = new Ke({ color: p });
698
717
  c.object.material = M;
699
718
  }
700
719
  const g = c.object;
@@ -705,21 +724,21 @@ const P = class {
705
724
  const g = c.object;
706
725
  (g instanceof H || g.isMesh) && this.updateLODs(t, e, g, r);
707
726
  }
708
- const o = s.transmissive;
709
- for (const c of o) {
727
+ const a = s.transmissive;
728
+ for (const c of a) {
710
729
  const g = c.object;
711
730
  (g instanceof H || g.isMesh) && this.updateLODs(t, e, g, r);
712
731
  }
713
732
  }
714
733
  /** Update the LOD levels for the renderer. */
715
734
  updateLODs(t, e, s, n) {
716
- var o, l;
735
+ var a, l;
717
736
  s.userData || (s.userData = {});
718
- let r = s[we];
719
- if (r || (r = new it(), s[we] = r), r.frames++ < 2)
737
+ let r = s[ve];
738
+ if (r || (r = new lt(), s[ve] = r), r.frames++ < 2)
720
739
  return;
721
740
  for (const u of Y)
722
- (o = u.onBeforeUpdateLOD) == null || o.call(u, this.renderer, t, e, s);
741
+ (a = u.onBeforeUpdateLOD) == null || a.call(u, this.renderer, t, e, s);
723
742
  this.calculateLodLevel(e, s, r, n, R), R.mesh_lod = Math.round(R.mesh_lod), R.texture_lod = Math.round(R.texture_lod), R.mesh_lod >= 0 && this.loadProgressiveMeshes(s, R.mesh_lod);
724
743
  let i = R.texture_lod;
725
744
  if (s.material && i >= 0) {
@@ -769,7 +788,7 @@ const P = class {
769
788
  return this._tempPtInside.set(r, i, s.z).applyMatrix4(e).z < 0;
770
789
  }
771
790
  calculateLodLevel(t, e, s, n, r) {
772
- var F;
791
+ var $;
773
792
  if (!e) {
774
793
  r.mesh_lod = -1, r.texture_lod = -1;
775
794
  return;
@@ -778,15 +797,15 @@ const P = class {
778
797
  r.mesh_lod = -1, r.texture_lod = -1;
779
798
  return;
780
799
  }
781
- let o = 10 + 1, l = !1;
782
- if (k && e["DEBUG:LOD"] != null)
800
+ let a = 10 + 1, l = !1;
801
+ if (I && e["DEBUG:LOD"] != null)
783
802
  return e["DEBUG:LOD"];
784
803
  const u = _.getMeshLODInformation(e.geometry), c = u == null ? void 0 : u.lods, g = c && c.length > 0, p = _.getMaterialMinMaxLODsCount(e.material), M = (p == null ? void 0 : p.min_count) != 1 / 0 && p.min_count > 0 && p.max_count > 0;
785
804
  if (!g && !M) {
786
805
  r.mesh_lod = 0, r.texture_lod = 0;
787
806
  return;
788
807
  }
789
- g || (l = !0, o = 0);
808
+ g || (l = !0, a = 0);
790
809
  const w = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
791
810
  let L = e.geometry.boundingBox;
792
811
  if (e.type === "SkinnedMesh") {
@@ -815,25 +834,25 @@ const P = class {
815
834
  }
816
835
  if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && D.fov > 70) {
817
836
  const f = this._tempBox.min, y = this._tempBox.max;
818
- let O = f.x, b = f.y, E = y.x, q = y.y;
837
+ let O = f.x, b = f.y, E = y.x, X = y.y;
819
838
  const ce = 2, xe = 1.5, ue = (f.x + y.x) * 0.5, fe = (f.y + y.y) * 0.5;
820
- O = (O - ue) * ce + ue, b = (b - fe) * ce + fe, E = (E - ue) * ce + ue, q = (q - fe) * ce + fe;
821
- const Ge = O < 0 && E > 0 ? 0 : Math.min(Math.abs(f.x), Math.abs(y.x)), Fe = b < 0 && q > 0 ? 0 : Math.min(Math.abs(f.y), Math.abs(y.y)), Le = Math.max(Ge, Fe);
839
+ O = (O - ue) * ce + ue, b = (b - fe) * ce + fe, E = (E - ue) * ce + ue, X = (X - fe) * ce + fe;
840
+ const Ue = O < 0 && E > 0 ? 0 : Math.min(Math.abs(f.x), Math.abs(y.x)), ze = b < 0 && X > 0 ? 0 : Math.min(Math.abs(f.y), Math.abs(y.y)), Le = Math.max(Ue, ze);
822
841
  s.lastCentrality = (xe - Le) * (xe - Le) * (xe - Le);
823
842
  } else
824
843
  s.lastCentrality = 1;
825
844
  const h = this._tempBox.getSize(this._tempBoxSize);
826
845
  h.multiplyScalar(0.5), screen.availHeight > 0 && w > 0 && h.multiplyScalar(w / screen.availHeight), h.x *= D.aspect;
827
- const B = t.matrixWorldInverse, $ = this._tempBox2;
828
- $.copy(L), $.applyMatrix4(e.matrixWorld), $.applyMatrix4(B);
829
- const I = $.getSize(this._tempBox2Size), S = Math.max(I.x, I.y);
830
- if (Math.max(h.x, h.y) != 0 && S != 0 && (h.z = I.z / Math.max(I.x, I.y) * Math.max(h.x, h.y)), s.lastScreenCoverage = Math.max(h.x, h.y, h.z), s.lastScreenspaceVolume.copy(h), s.lastScreenCoverage *= s.lastCentrality, k && P.debugDrawLine) {
846
+ const B = t.matrixWorldInverse, F = this._tempBox2;
847
+ F.copy(L), F.applyMatrix4(e.matrixWorld), F.applyMatrix4(B);
848
+ const k = F.getSize(this._tempBox2Size), S = Math.max(k.x, k.y);
849
+ if (Math.max(h.x, h.y) != 0 && S != 0 && (h.z = k.z / Math.max(k.x, k.y) * Math.max(h.x, h.y)), s.lastScreenCoverage = Math.max(h.x, h.y, h.z), s.lastScreenspaceVolume.copy(h), s.lastScreenCoverage *= s.lastCentrality, I && P.debugDrawLine) {
831
850
  const f = this.tempMatrix.copy(this.projectionScreenMatrix);
832
851
  f.invert();
833
852
  const y = P.corner0, O = P.corner1, b = P.corner2, E = P.corner3;
834
853
  y.copy(this._tempBox.min), O.copy(this._tempBox.max), O.x = y.x, b.copy(this._tempBox.max), b.y = y.y, E.copy(this._tempBox.max);
835
- const q = (y.z + E.z) * 0.5;
836
- y.z = O.z = b.z = E.z = q, y.applyMatrix4(f), O.applyMatrix4(f), b.applyMatrix4(f), E.applyMatrix4(f), P.debugDrawLine(y, O, 255), P.debugDrawLine(y, b, 255), P.debugDrawLine(O, E, 255), P.debugDrawLine(b, E, 255);
854
+ const X = (y.z + E.z) * 0.5;
855
+ y.z = O.z = b.z = E.z = X, y.applyMatrix4(f), O.applyMatrix4(f), b.applyMatrix4(f), E.applyMatrix4(f), P.debugDrawLine(y, O, 255), P.debugDrawLine(y, b, 255), P.debugDrawLine(O, E, 255), P.debugDrawLine(b, E, 255);
837
856
  }
838
857
  let T = 999;
839
858
  if (c && s.lastScreenCoverage > 0) {
@@ -843,31 +862,31 @@ const P = class {
843
862
  break;
844
863
  }
845
864
  }
846
- T < o && (o = T, l = !0);
865
+ T < a && (a = T, l = !0);
847
866
  }
848
- if (l ? r.mesh_lod = o : r.mesh_lod = s.lastLodLevel_Mesh, k && r.mesh_lod != s.lastLodLevel_Mesh) {
867
+ if (l ? r.mesh_lod = a : r.mesh_lod = s.lastLodLevel_Mesh, I && r.mesh_lod != s.lastLodLevel_Mesh) {
849
868
  const h = c == null ? void 0 : c[r.mesh_lod];
850
869
  h && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${r.mesh_lod} (${h.density.toFixed(0)}) - ${e.name}`);
851
870
  }
852
871
  if (M) {
853
872
  const D = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
854
873
  if (s.lastLodLevel_Texture < 0) {
855
- if (r.texture_lod = p.max_count - 1, k) {
874
+ if (r.texture_lod = p.max_count - 1, I) {
856
875
  const h = p.lods[p.max_count - 1];
857
- k && console.log(`First Texture LOD ${r.texture_lod} (${h.max_height}px) - ${e.name}`);
876
+ I && console.log(`First Texture LOD ${r.texture_lod} (${h.max_height}px) - ${e.name}`);
858
877
  }
859
878
  } else {
860
879
  const h = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
861
880
  let B = s.lastScreenCoverage * 2;
862
- ((F = this.context) == null ? void 0 : F.engine) === "model-viewer" && (B *= 2);
863
- const I = w / window.devicePixelRatio * B;
881
+ (($ = this.context) == null ? void 0 : $.engine) === "model-viewer" && (B *= 2);
882
+ const k = w / window.devicePixelRatio * B;
864
883
  for (let S = p.lods.length - 1; S >= 0; S--) {
865
- let X = p.lods[S];
866
- if (!(D && X.max_height >= 2048) && !(je() && X.max_height > 4096) && X.max_height > I) {
884
+ let q = p.lods[S];
885
+ if (!(D && q.max_height >= 2048) && !(rt() && q.max_height > 4096) && q.max_height > k) {
867
886
  if (r.texture_lod = S, r.texture_lod < s.lastLodLevel_Texture) {
868
- const T = X.max_height;
869
- k && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${r.texture_lod} = ${T}px
870
- Screensize: ${I.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${h.toFixed(1)}
887
+ const T = q.max_height;
888
+ I && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${r.texture_lod} = ${T}px
889
+ Screensize: ${k.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${h.toFixed(1)}
871
890
  ${e.name}`);
872
891
  }
873
892
  break;
@@ -882,7 +901,7 @@ let G = P;
882
901
  C = new WeakMap(), N = new WeakMap(), pe = new WeakMap(), ee = new WeakMap(), te = new WeakMap(), ye = new WeakMap(), W = new WeakMap(), /** 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.
883
902
  */
884
903
  d(G, "debugDrawLine"), d(G, "corner0", new z()), d(G, "corner1", new z()), d(G, "corner2", new z()), d(G, "corner3", new z()), d(G, "_tempPtInside", new z());
885
- class it {
904
+ class lt {
886
905
  constructor() {
887
906
  d(this, "frames", 0);
888
907
  d(this, "lastLodLevel_Mesh", -1);
@@ -892,66 +911,66 @@ class it {
892
911
  d(this, "lastCentrality", 0);
893
912
  }
894
913
  }
895
- const Ae = Symbol("NEEDLE_mesh_lod"), de = Symbol("NEEDLE_texture_lod");
914
+ const Ce = Symbol("NEEDLE_mesh_lod"), de = Symbol("NEEDLE_texture_lod");
896
915
  let ne = null;
897
- function ke() {
898
- const a = nt();
899
- a && (a.mapURLs(function(t) {
900
- return Ee(), t;
901
- }), Ee(), ne == null || ne.disconnect(), ne = new MutationObserver((t) => {
916
+ function $e() {
917
+ const o = ct();
918
+ o && (o.mapURLs(function(t) {
919
+ return Be(), t;
920
+ }), Be(), ne == null || ne.disconnect(), ne = new MutationObserver((t) => {
902
921
  t.forEach((e) => {
903
922
  e.addedNodes.forEach((s) => {
904
- s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && Re(s);
923
+ s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && Fe(s);
905
924
  });
906
925
  });
907
926
  }), ne.observe(document, { childList: !0, subtree: !0 }));
908
927
  }
909
- function nt() {
928
+ function ct() {
910
929
  if (typeof customElements > "u")
911
930
  return null;
912
- const a = customElements.get("model-viewer");
913
- return a || (customElements.whenDefined("model-viewer").then(() => {
914
- console.debug("[gltf-progressive] model-viewer defined"), ke();
931
+ const o = customElements.get("model-viewer");
932
+ return o || (customElements.whenDefined("model-viewer").then(() => {
933
+ console.debug("[gltf-progressive] model-viewer defined"), $e();
915
934
  }), null);
916
935
  }
917
- function Ee() {
936
+ function Be() {
918
937
  if (typeof document > "u")
919
938
  return;
920
939
  document.querySelectorAll("model-viewer").forEach((t) => {
921
- Re(t);
940
+ Fe(t);
922
941
  });
923
942
  }
924
- const Pe = /* @__PURE__ */ new WeakSet();
925
- let ot = 0;
926
- function Re(a) {
927
- if (!a || Pe.has(a))
943
+ const ke = /* @__PURE__ */ new WeakSet();
944
+ let ut = 0;
945
+ function Fe(o) {
946
+ if (!o || ke.has(o))
928
947
  return null;
929
- Pe.add(a), console.debug("[gltf-progressive] found new model-viewer..." + ++ot + `
930
- `, a.getAttribute("src"));
948
+ ke.add(o), console.debug("[gltf-progressive] found new model-viewer..." + ++ut + `
949
+ `, o.getAttribute("src"));
931
950
  let t = null, e = null, s = null;
932
- for (let n = a; n != null; n = Object.getPrototypeOf(n)) {
933
- const r = Object.getOwnPropertySymbols(n), i = r.find((u) => u.toString() == "Symbol(renderer)"), o = r.find((u) => u.toString() == "Symbol(scene)"), l = r.find((u) => u.toString() == "Symbol(needsRender)");
934
- !t && i != null && (t = a[i].threeRenderer), !e && o != null && (e = a[o]), !s && l != null && (s = a[l]);
951
+ for (let n = o; n != null; n = Object.getPrototypeOf(n)) {
952
+ const r = Object.getOwnPropertySymbols(n), i = r.find((u) => u.toString() == "Symbol(renderer)"), a = r.find((u) => u.toString() == "Symbol(scene)"), l = r.find((u) => u.toString() == "Symbol(needsRender)");
953
+ !t && i != null && (t = o[i].threeRenderer), !e && a != null && (e = o[a]), !s && l != null && (s = o[l]);
935
954
  }
936
955
  if (t && e) {
937
956
  let n = function() {
938
957
  if (s) {
939
- let i = 0, o = setInterval(() => {
958
+ let i = 0, a = setInterval(() => {
940
959
  if (i++ > 5) {
941
- clearInterval(o);
960
+ clearInterval(a);
942
961
  return;
943
962
  }
944
- s == null || s.call(a);
963
+ s == null || s.call(o);
945
964
  }, 300);
946
965
  }
947
966
  };
948
967
  console.debug("[gltf-progressive] setup model-viewer");
949
968
  const r = G.get(t, { engine: "model-viewer" });
950
- return G.addPlugin(new at()), r.enable(), r.addEventListener("changed", () => {
951
- s == null || s.call(a);
952
- }), a.addEventListener("model-visibility", (i) => {
953
- i.detail.visible && (s == null || s.call(a));
954
- }), a.addEventListener("load", () => {
969
+ return G.addPlugin(new ft()), r.enable(), r.addEventListener("changed", () => {
970
+ s == null || s.call(o);
971
+ }), o.addEventListener("model-visibility", (i) => {
972
+ i.detail.visible && (s == null || s.call(o));
973
+ }), o.addEventListener("load", () => {
955
974
  n();
956
975
  }), () => {
957
976
  r.disable();
@@ -959,7 +978,7 @@ function Re(a) {
959
978
  }
960
979
  return null;
961
980
  }
962
- class at {
981
+ class ft {
963
982
  constructor() {
964
983
  d(this, "_didWarnAboutMissingUrl", !1);
965
984
  }
@@ -993,62 +1012,66 @@ class at {
993
1012
  for (let M = 0; M < u.length; M++) {
994
1013
  const w = u[M], L = l[w];
995
1014
  if ((L == null ? void 0 : L.isTexture) === !0) {
996
- const F = (g = (c = L.userData) == null ? void 0 : c.associations) == null ? void 0 : g.textures;
997
- if (F == null)
1015
+ const $ = (g = (c = L.userData) == null ? void 0 : c.associations) == null ? void 0 : g.textures;
1016
+ if ($ == null)
998
1017
  continue;
999
- const D = s.parser.json.textures[F];
1018
+ const D = s.parser.json.textures[$];
1000
1019
  if (!D) {
1001
- console.warn("Texture data not found for texture index " + F);
1020
+ console.warn("Texture data not found for texture index " + $);
1002
1021
  continue;
1003
1022
  }
1004
1023
  if ((p = D == null ? void 0 : D.extensions) != null && p[V]) {
1005
1024
  const h = D.extensions[V];
1006
- h && r && _.registerTexture(r, L, h.lods.length, F, h);
1025
+ h && r && _.registerTexture(r, L, h.lods.length, $, h);
1007
1026
  }
1008
1027
  }
1009
1028
  }
1010
1029
  };
1011
- const o = e.material;
1012
- if (Array.isArray(o))
1013
- for (const l of o)
1030
+ const a = e.material;
1031
+ if (Array.isArray(a))
1032
+ for (const l of a)
1014
1033
  i(l);
1015
1034
  else
1016
- i(o);
1035
+ i(a);
1017
1036
  }
1018
1037
  }
1019
1038
  tryParseMeshLOD(t, e) {
1020
- var i, o;
1021
- if (e[Ae] == !0)
1039
+ var i, a;
1040
+ if (e[Ce] == !0)
1022
1041
  return;
1023
- e[Ae] = !0;
1042
+ e[Ce] = !0;
1024
1043
  const s = this.tryGetCurrentModelViewer(t), n = this.getUrl(s);
1025
1044
  if (!n)
1026
1045
  return;
1027
- const r = (o = (i = e.userData) == null ? void 0 : i.gltfExtensions) == null ? void 0 : o[V];
1046
+ const r = (a = (i = e.userData) == null ? void 0 : i.gltfExtensions) == null ? void 0 : a[V];
1028
1047
  if (r && n) {
1029
1048
  const l = e.uuid;
1030
1049
  _.registerMesh(n, l, e, 0, r.lods.length, r);
1031
1050
  }
1032
1051
  }
1033
1052
  }
1034
- function mt(a, t, e, s) {
1035
- Be(t), Ie(e), e.register((r) => new _(r, a));
1053
+ function Dt(o, t, e, s) {
1054
+ Re(t), Ge(e), et(e, {
1055
+ progressive: !0,
1056
+ ...s == null ? void 0 : s.hints
1057
+ }), e.register((r) => new _(r, o));
1036
1058
  const n = G.get(t);
1037
1059
  return (s == null ? void 0 : s.enableLODsManager) !== !1 && n.enable(), n;
1038
1060
  }
1039
- ke();
1061
+ $e();
1040
1062
  export {
1041
1063
  V as EXTENSION_NAME,
1042
1064
  G as LODsManager,
1043
1065
  _ as NEEDLE_progressive,
1044
- Ce as VERSION,
1045
- Ie as addDracoAndKTX2Loaders,
1046
- Be as createLoaders,
1066
+ Ie as VERSION,
1067
+ Ge as addDracoAndKTX2Loaders,
1068
+ et as configureLoader,
1069
+ Re as createLoaders,
1047
1070
  me as getRaycastMesh,
1048
- ke as patchModelViewer,
1049
- et as registerRaycastMesh,
1050
- gt as setDracoDecoderLocation,
1051
- pt as setKTX2TranscoderLocation,
1052
- mt as useNeedleProgressive,
1053
- yt as useRaycastMeshes
1071
+ $e as patchModelViewer,
1072
+ it as registerRaycastMesh,
1073
+ xt as setDracoDecoderLocation,
1074
+ Lt as setKTX2TranscoderLocation,
1075
+ Dt as useNeedleProgressive,
1076
+ Mt as useRaycastMeshes
1054
1077
  };