@needle-tools/gltf-progressive 1.2.2-alpha.3 → 1.2.2-alpha.4

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,42 +1,42 @@
1
- var Se = Object.defineProperty;
2
- var be = (l, e, t) => e in l ? Se(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
3
- var f = (l, e, t) => (be(l, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { BufferGeometry as se, Mesh as W, Material as Te, Texture as q, TextureLoader as Ae, Matrix4 as ye, Frustum as Pe, Sphere as Ce, Box3 as me, Vector3 as G } from "three";
5
- import { GLTFLoader as Ee } from "three/examples/jsm/loaders/GLTFLoader.js";
6
- import { MeshoptDecoder as Be } from "three/examples/jsm/libs/meshopt_decoder.module.js";
7
- import { DRACOLoader as ke } from "three/examples/jsm/loaders/DRACOLoader.js";
8
- import { KTX2Loader as Re } from "three/examples/jsm/loaders/KTX2Loader.js";
9
- const De = "";
10
- globalThis.GLTF_PROGRESSIVE_VERSION = De;
11
- console.debug(`[gltf-progressive] version ${De}`);
12
- let ie = "https://www.gstatic.com/draco/versioned/decoders/1.4.1/", ge = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
13
- fetch(ie + "draco_decoder.js", { method: "head" }).catch((l) => {
14
- ie = "./include/draco/", ge = "./include/ktx2/";
1
+ var Ae = Object.defineProperty;
2
+ var Pe = (a, e, t) => e in a ? Ae(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
3
+ var d = (a, e, t) => (Pe(a, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { BufferGeometry as ie, Mesh as W, Material as Ee, Texture as q, TextureLoader as Ce, Matrix4 as ye, Frustum as Be, Sphere as Re, Box3 as me, Vector3 as G } from "three";
5
+ import { GLTFLoader as ke } from "three/examples/jsm/loaders/GLTFLoader.js";
6
+ import { MeshoptDecoder as Ie } from "three/examples/jsm/libs/meshopt_decoder.module.js";
7
+ import { DRACOLoader as Ge } from "three/examples/jsm/loaders/DRACOLoader.js";
8
+ import { KTX2Loader as Fe } from "three/examples/jsm/loaders/KTX2Loader.js";
9
+ const we = "";
10
+ globalThis.GLTF_PROGRESSIVE_VERSION = we;
11
+ console.debug(`[gltf-progressive] version ${we}`);
12
+ let ne = "https://www.gstatic.com/draco/versioned/decoders/1.4.1/", ge = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
13
+ fetch(ne + "draco_decoder.js", { method: "head" }).catch((a) => {
14
+ ne = "./include/draco/", ge = "./include/ktx2/";
15
15
  });
16
- function Ze(l) {
17
- ie = l;
16
+ function tt(a) {
17
+ ne = a;
18
18
  }
19
- function je(l) {
20
- ge = l;
19
+ function rt(a) {
20
+ ge = a;
21
21
  }
22
- let H, fe, J;
23
- function we(l) {
24
- H || (H = new ke(), H.setDecoderPath(ie), H.setDecoderConfig({ type: "js" })), J || (J = new Re(), J.setTranscoderPath(ge)), fe || (fe = Be), l ? J.detectSupport(l) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
22
+ let J, fe, Q;
23
+ function ve(a) {
24
+ J || (J = new Ge(), J.setDecoderPath(ne), J.setDecoderConfig({ type: "js" })), Q || (Q = new Fe(), Q.setTranscoderPath(ge)), fe || (fe = Ie), a ? Q.detectSupport(a) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
25
25
  }
26
- function _e(l) {
27
- l.dracoLoader || l.setDRACOLoader(H), l.ktx2Loader || l.setKTX2Loader(J), l.meshoptDecoder || l.setMeshoptDecoder(fe);
26
+ function _e(a) {
27
+ a.dracoLoader || a.setDRACOLoader(J), a.ktx2Loader || a.setKTX2Loader(Q), a.meshoptDecoder || a.setMeshoptDecoder(fe);
28
28
  }
29
- Z("debugprogressive");
30
- function Z(l) {
31
- const t = new URL(window.location.href).searchParams.get(l);
29
+ j("debugprogressive");
30
+ function j(a) {
31
+ const t = new URL(window.location.href).searchParams.get(a);
32
32
  return t == null || t === "0" || t === "false" ? !1 : t === "" ? !0 : t;
33
33
  }
34
- function Ie(l, e) {
35
- if (e === void 0 || e.startsWith("./") || e.startsWith("http") || l === void 0)
34
+ function $e(a, e) {
35
+ if (e === void 0 || e.startsWith("./") || e.startsWith("http") || a === void 0)
36
36
  return e;
37
- const t = l.lastIndexOf("/");
37
+ const t = a.lastIndexOf("/");
38
38
  if (t >= 0) {
39
- const r = l.substring(0, t + 1);
39
+ const r = a.substring(0, t + 1);
40
40
  for (; r.endsWith("/") && e.startsWith("/"); )
41
41
  e = e.substring(1);
42
42
  return r + e;
@@ -44,28 +44,28 @@ function Ie(l, e) {
44
44
  return e;
45
45
  }
46
46
  let X;
47
- function Ge() {
48
- return X !== void 0 || (X = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), Z("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", X)), X;
47
+ function ze() {
48
+ return X !== void 0 || (X = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), j("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", X)), X;
49
49
  }
50
50
  const de = Symbol("needle:raycast-mesh");
51
- function pe(l) {
52
- return (l == null ? void 0 : l[de]) instanceof se ? l[de] : null;
51
+ function pe(a) {
52
+ return (a == null ? void 0 : a[de]) instanceof ie ? a[de] : null;
53
53
  }
54
- function Fe(l, e) {
55
- if ((l.type === "Mesh" || l.type === "SkinnedMesh") && !pe(l)) {
56
- const r = $e(e);
57
- r.userData = { isRaycastMesh: !0 }, l[de] = r;
54
+ function Ve(a, e) {
55
+ if ((a.type === "Mesh" || a.type === "SkinnedMesh") && !pe(a)) {
56
+ const r = Ne(e);
57
+ r.userData = { isRaycastMesh: !0 }, a[de] = r;
58
58
  }
59
59
  }
60
- function et(l = !0) {
61
- if (l) {
60
+ function st(a = !0) {
61
+ if (a) {
62
62
  if (Y)
63
63
  return;
64
64
  const e = Y = W.prototype.raycast;
65
65
  W.prototype.raycast = function(t, r) {
66
- const i = this, n = pe(i);
66
+ const n = this, i = pe(n);
67
67
  let s;
68
- n && i.isMesh && (s = i.geometry, i.geometry = n), e.call(this, t, r), s && (i.geometry = s);
68
+ i && n.isMesh && (s = n.geometry, n.geometry = i), e.call(this, t, r), s && (n.geometry = s);
69
69
  };
70
70
  } else {
71
71
  if (!Y)
@@ -74,57 +74,57 @@ function et(l = !0) {
74
74
  }
75
75
  }
76
76
  let Y = null;
77
- function $e(l) {
78
- const e = new se();
79
- for (const t in l.attributes)
80
- e.setAttribute(t, l.getAttribute(t));
81
- return e.setIndex(l.getIndex()), e;
77
+ function Ne(a) {
78
+ const e = new ie();
79
+ for (const t in a.attributes)
80
+ e.setAttribute(t, a.getAttribute(t));
81
+ return e.setIndex(a.getIndex()), e;
82
82
  }
83
- const z = new Array(), F = "NEEDLE_progressive", m = Z("debugprogressive"), ae = Symbol("needle-progressive-texture"), Q = /* @__PURE__ */ new Map(), he = /* @__PURE__ */ new Set();
83
+ const z = new Array(), F = "NEEDLE_progressive", m = j("debugprogressive"), le = Symbol("needle-progressive-texture"), Z = /* @__PURE__ */ new Map(), he = /* @__PURE__ */ new Set();
84
84
  if (m) {
85
- let l = function() {
86
- e += 1, console.log("Toggle LOD level", e, Q), Q.forEach((i, n) => {
87
- for (const s of i.keys) {
88
- const o = n[s];
85
+ let a = function() {
86
+ e += 1, console.log("Toggle LOD level", e, Z), Z.forEach((n, i) => {
87
+ for (const s of n.keys) {
88
+ const o = i[s];
89
89
  if (o != null) {
90
90
  if (o.isBufferGeometry === !0) {
91
- const a = O.getMeshLODInformation(o), d = a ? Math.min(e, a.lods.length) : 0;
92
- n["DEBUG:LOD"] = e, O.assignMeshLOD(n, d), a && (t = Math.max(t, a.lods.length - 1));
93
- } else if (n.isMaterial === !0) {
94
- n["DEBUG:LOD"] = e, O.assignTextureLOD(n, e);
91
+ const l = O.getMeshLODInformation(o), f = l ? Math.min(e, l.lods.length) : 0;
92
+ i["DEBUG:LOD"] = e, O.assignMeshLOD(i, f), l && (t = Math.max(t, l.lods.length - 1));
93
+ } else if (i.isMaterial === !0) {
94
+ i["DEBUG:LOD"] = e, O.assignTextureLOD(i, e);
95
95
  break;
96
96
  }
97
97
  }
98
98
  }
99
99
  }), e >= t && (e = -1);
100
100
  }, e = -1, t = 2, r = !1;
101
- window.addEventListener("keyup", (i) => {
102
- i.key === "p" && l(), i.key === "w" && (r = !r, he && he.forEach((n) => {
103
- n.name != "BackgroundCubeMaterial" && n.glyphMap == null && "wireframe" in n && (n.wireframe = r);
101
+ window.addEventListener("keyup", (n) => {
102
+ n.key === "p" && a(), n.key === "w" && (r = !r, he && he.forEach((i) => {
103
+ i.name != "BackgroundCubeMaterial" && i.glyphMap == null && "wireframe" in i && (i.wireframe = r);
104
104
  }));
105
105
  });
106
106
  }
107
- function xe(l, e, t) {
108
- var i;
107
+ function xe(a, e, t) {
108
+ var n;
109
109
  if (!m)
110
110
  return;
111
- Q.has(l) || Q.set(l, { keys: [], sourceId: t });
112
- const r = Q.get(l);
113
- ((i = r == null ? void 0 : r.keys) == null ? void 0 : i.includes(e)) == !1 && r.keys.push(e);
111
+ Z.has(a) || Z.set(a, { keys: [], sourceId: t });
112
+ const r = Z.get(a);
113
+ ((n = r == null ? void 0 : r.keys) == null ? void 0 : n.includes(e)) == !1 && r.keys.push(e);
114
114
  }
115
- const v = class {
115
+ const _ = class {
116
116
  constructor(e, t) {
117
- f(this, "parser");
118
- f(this, "url");
119
- f(this, "_isLoadingMesh");
120
- f(this, "loadMesh", (e) => {
121
- var r, i;
117
+ d(this, "parser");
118
+ d(this, "url");
119
+ d(this, "_isLoadingMesh");
120
+ d(this, "loadMesh", (e) => {
121
+ var r, n;
122
122
  if (this._isLoadingMesh)
123
123
  return null;
124
- const t = (i = (r = this.parser.json.meshes[e]) == null ? void 0 : r.extensions) == null ? void 0 : i[F];
125
- return t ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", e).then((n) => {
124
+ const t = (n = (r = this.parser.json.meshes[e]) == null ? void 0 : r.extensions) == null ? void 0 : n[F];
125
+ return t ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", e).then((i) => {
126
126
  var s;
127
- return this._isLoadingMesh = !1, n && v.registerMesh(this.url, t.guid, n, (s = t.lods) == null ? void 0 : s.length, void 0, t), n;
127
+ return this._isLoadingMesh = !1, i && _.registerMesh(this.url, t.guid, i, (s = t.lods) == null ? void 0 : s.length, void 0, t), i;
128
128
  })) : null;
129
129
  });
130
130
  m && console.log("Progressive extension registered for", t), this.parser = e, this.url = t;
@@ -138,9 +138,9 @@ const v = class {
138
138
  return t != null && t.key ? this.lodInfos.get(t.key) : null;
139
139
  }
140
140
  static getMaterialMinMaxLODsCount(e, t) {
141
- const r = this, i = "LODS:minmax", n = e[i];
142
- if (n != null)
143
- return n;
141
+ const r = this, n = "LODS:minmax", i = e[n];
142
+ if (i != null)
143
+ return i;
144
144
  if (t || (t = {
145
145
  min_count: 1 / 0,
146
146
  max_count: 0,
@@ -148,29 +148,29 @@ const v = class {
148
148
  }), Array.isArray(e)) {
149
149
  for (const o of e)
150
150
  this.getMaterialMinMaxLODsCount(o, t);
151
- return e[i] = t, t;
151
+ return e[n] = t, t;
152
152
  }
153
153
  if (m === "verbose" && console.log("getMaterialMinMaxLODsCount", e), e.type === "ShaderMaterial" || e.type === "RawShaderMaterial") {
154
154
  const o = e;
155
- for (const a of Object.keys(o.uniforms)) {
156
- const d = o.uniforms[a].value;
157
- (d == null ? void 0 : d.isTexture) === !0 && s(d, t);
155
+ for (const l of Object.keys(o.uniforms)) {
156
+ const f = o.uniforms[l].value;
157
+ (f == null ? void 0 : f.isTexture) === !0 && s(f, t);
158
158
  }
159
159
  } else if (e.isMaterial)
160
160
  for (const o of Object.keys(e)) {
161
- const a = e[o];
162
- (a == null ? void 0 : a.isTexture) === !0 && s(a, t);
161
+ const l = e[o];
162
+ (l == null ? void 0 : l.isTexture) === !0 && s(l, t);
163
163
  }
164
- return e[i] = t, t;
165
- function s(o, a) {
166
- const d = r.getAssignedLODInformation(o);
167
- if (d) {
168
- const c = r.lodInfos.get(d.key);
164
+ return e[n] = t, t;
165
+ function s(o, l) {
166
+ const f = r.getAssignedLODInformation(o);
167
+ if (f) {
168
+ const c = r.lodInfos.get(f.key);
169
169
  if (c && c.lods) {
170
- a.min_count = Math.min(a.min_count, c.lods.length), a.max_count = Math.max(a.max_count, c.lods.length);
170
+ l.min_count = Math.min(l.min_count, c.lods.length), l.max_count = Math.max(l.max_count, c.lods.length);
171
171
  for (let x = 0; x < c.lods.length; x++) {
172
172
  const u = c.lods[x];
173
- u.width && (a.lods[x] = a.lods[x] || { min_height: 1 / 0, max_height: 0 }, a.lods[x].min_height = Math.min(a.lods[x].min_height, u.height), a.lods[x].max_height = Math.max(a.lods[x].max_height, u.height));
173
+ u.width && (l.lods[x] = l.lods[x] || { min_height: 1 / 0, max_height: 0 }, l.lods[x].min_height = Math.min(l.lods[x].min_height, u.height), l.lods[x].max_height = Math.max(l.lods[x].max_height, u.height));
174
174
  }
175
175
  }
176
176
  }
@@ -182,7 +182,7 @@ const v = class {
182
182
  * @returns true if the LOD level is available (or if any LOD level is available if level is undefined)
183
183
  */
184
184
  static hasLODLevelAvailable(e, t) {
185
- var n;
185
+ var i;
186
186
  if (Array.isArray(e)) {
187
187
  for (const s of e)
188
188
  if (this.hasLODLevelAvailable(s, t))
@@ -201,13 +201,13 @@ const v = class {
201
201
  if (s.isMesh === !0 && this.hasLODLevelAvailable(s, t))
202
202
  return !0;
203
203
  }
204
- let r, i;
205
- if (e.isMesh ? r = e.geometry : (e.isBufferGeometry || e.isTexture) && (r = e), r && (n = r == null ? void 0 : r.userData) != null && n.LODS) {
204
+ let r, n;
205
+ if (e.isMesh ? r = e.geometry : (e.isBufferGeometry || e.isTexture) && (r = e), r && (i = r == null ? void 0 : r.userData) != null && i.LODS) {
206
206
  const s = r.userData.LODS;
207
- if (i = this.lodInfos.get(s.key), t === void 0)
208
- return i != null;
209
- if (i)
210
- return Array.isArray(i.lods) ? t < i.lods.length : t === 0;
207
+ if (n = this.lodInfos.get(s.key), t === void 0)
208
+ return n != null;
209
+ if (n)
210
+ return Array.isArray(n.lods) ? t < n.lods.length : t === 0;
211
211
  }
212
212
  return !1;
213
213
  }
@@ -230,18 +230,18 @@ const v = class {
230
230
  if (!e)
231
231
  return Promise.resolve(null);
232
232
  if (e instanceof W || e.isMesh === !0) {
233
- const i = e.geometry, n = this.getAssignedLODInformation(i);
234
- if (!n)
233
+ const n = e.geometry, i = this.getAssignedLODInformation(n);
234
+ if (!i)
235
235
  return Promise.resolve(null);
236
236
  for (const s of z)
237
237
  (r = s.onBeforeGetLODMesh) == null || r.call(s, e, t);
238
- return e["LOD:requested level"] = t, v.getOrLoadLOD(i, t).then((s) => {
238
+ return e["LOD:requested level"] = t, _.getOrLoadLOD(n, t).then((s) => {
239
239
  if (e["LOD:requested level"] === t) {
240
240
  if (delete e["LOD:requested level"], Array.isArray(s)) {
241
- const o = n.index || 0;
241
+ const o = i.index || 0;
242
242
  s = s[o];
243
243
  }
244
- s && i != s && ((s == null ? void 0 : s.isBufferGeometry) ? (e.geometry = s, m && xe(e, "geometry", n.url)) : m && console.error("Invalid LOD geometry", s));
244
+ s && n != s && ((s == null ? void 0 : s.isBufferGeometry) ? (e.geometry = s, m && xe(e, "geometry", i.url)) : m && console.error("Invalid LOD geometry", s));
245
245
  }
246
246
  return s;
247
247
  }).catch((s) => (console.error("Error loading mesh LOD", e, s), null));
@@ -259,30 +259,30 @@ const v = class {
259
259
  static assignTextureLOD(e, t = 0) {
260
260
  if (!e)
261
261
  return Promise.resolve(null);
262
- if (e instanceof Te || e.isMaterial === !0) {
263
- const r = e, i = [], n = new Array();
262
+ if (e instanceof Ee || e.isMaterial === !0) {
263
+ const r = e, n = [], i = new Array();
264
264
  if (m && he.add(r), r.uniforms && r.isRawShaderMaterial || r.isShaderMaterial === !0) {
265
265
  const s = r;
266
266
  for (const o of Object.keys(s.uniforms)) {
267
- const a = s.uniforms[o].value;
268
- if ((a == null ? void 0 : a.isTexture) === !0) {
269
- const d = this.assignTextureLODForSlot(a, t, r, o);
270
- i.push(d), n.push(o);
267
+ const l = s.uniforms[o].value;
268
+ if ((l == null ? void 0 : l.isTexture) === !0) {
269
+ const f = this.assignTextureLODForSlot(l, t, r, o);
270
+ n.push(f), i.push(o);
271
271
  }
272
272
  }
273
273
  } else
274
274
  for (const s of Object.keys(r)) {
275
275
  const o = r[s];
276
276
  if ((o == null ? void 0 : o.isTexture) === !0) {
277
- const a = this.assignTextureLODForSlot(o, t, r, s);
278
- i.push(a), n.push(s);
277
+ const l = this.assignTextureLODForSlot(o, t, r, s);
278
+ n.push(l), i.push(s);
279
279
  }
280
280
  }
281
- return Promise.all(i).then((s) => {
281
+ return Promise.all(n).then((s) => {
282
282
  const o = new Array();
283
- for (let a = 0; a < s.length; a++) {
284
- const d = s[a], c = n[a];
285
- d && d.isTexture === !0 ? o.push({ material: r, slot: c, texture: d, level: t }) : o.push({ material: r, slot: c, texture: null, level: t });
283
+ for (let l = 0; l < s.length; l++) {
284
+ const f = s[l], c = i[l];
285
+ f && f.isTexture === !0 ? o.push({ material: r, slot: c, texture: f, level: t }) : o.push({ material: r, slot: c, texture: null, level: t });
286
286
  }
287
287
  return o;
288
288
  });
@@ -293,116 +293,116 @@ const v = class {
293
293
  }
294
294
  return Promise.resolve(null);
295
295
  }
296
- static assignTextureLODForSlot(e, t, r, i) {
297
- return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : i === "glyphMap" ? Promise.resolve(e) : v.getOrLoadLOD(e, t).then((n) => {
298
- if (Array.isArray(n))
296
+ static assignTextureLODForSlot(e, t, r, n) {
297
+ return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : n === "glyphMap" ? Promise.resolve(e) : _.getOrLoadLOD(e, t).then((i) => {
298
+ if (Array.isArray(i))
299
299
  return null;
300
- if ((n == null ? void 0 : n.isTexture) === !0) {
301
- if (n != e) {
302
- if (r && i) {
303
- const s = r[i];
300
+ if ((i == null ? void 0 : i.isTexture) === !0) {
301
+ if (i != e) {
302
+ if (r && n) {
303
+ const s = r[n];
304
304
  if (s) {
305
305
  const o = this.getAssignedLODInformation(s);
306
306
  if (o && (o == null ? void 0 : o.level) < t)
307
- return m === "verbose" && console.warn("Assigned texture level is already higher: ", o.level, t, r, s, n), null;
307
+ return m === "verbose" && console.warn("Assigned texture level is already higher: ", o.level, t, r, s, i), null;
308
308
  }
309
- r[i] = n;
309
+ r[n] = i;
310
310
  }
311
- if (m && i && r) {
311
+ if (m && n && r) {
312
312
  const s = this.getAssignedLODInformation(e);
313
- s && xe(r, i, s.url);
313
+ s && xe(r, n, s.url);
314
314
  }
315
315
  }
316
- return n;
316
+ return i;
317
317
  } else
318
318
  m == "verbose" && console.warn("No LOD found for", e, t);
319
319
  return null;
320
- }).catch((n) => (console.error("Error loading LOD", e, n), null));
320
+ }).catch((i) => (console.error("Error loading LOD", e, i), null));
321
321
  }
322
322
  afterRoot(e) {
323
323
  var t, r;
324
- return m && console.log("AFTER", this.url, e), (t = this.parser.json.textures) == null || t.forEach((i, n) => {
324
+ return m && console.log("AFTER", this.url, e), (t = this.parser.json.textures) == null || t.forEach((n, i) => {
325
325
  var s;
326
- if (i != null && i.extensions) {
327
- const o = i == null ? void 0 : i.extensions[F];
326
+ if (n != null && n.extensions) {
327
+ const o = n == null ? void 0 : n.extensions[F];
328
328
  if (o) {
329
329
  if (!o.lods) {
330
330
  m && console.warn("Texture has no LODs", o);
331
331
  return;
332
332
  }
333
- let a = !1;
334
- for (const d of this.parser.associations.keys())
335
- d.isTexture === !0 && this.parser.associations.get(d).textures === n && (a = !0, v.registerTexture(this.url, d, (s = o.lods) == null ? void 0 : s.length, n, o));
336
- a || this.parser.getDependency("texture", n).then((d) => {
333
+ let l = !1;
334
+ for (const f of this.parser.associations.keys())
335
+ f.isTexture === !0 && this.parser.associations.get(f).textures === i && (l = !0, _.registerTexture(this.url, f, (s = o.lods) == null ? void 0 : s.length, i, o));
336
+ l || this.parser.getDependency("texture", i).then((f) => {
337
337
  var c;
338
- d && v.registerTexture(this.url, d, (c = o.lods) == null ? void 0 : c.length, n, o);
338
+ f && _.registerTexture(this.url, f, (c = o.lods) == null ? void 0 : c.length, i, o);
339
339
  });
340
340
  }
341
341
  }
342
- }), (r = this.parser.json.meshes) == null || r.forEach((i, n) => {
343
- if (i != null && i.extensions) {
344
- const s = i == null ? void 0 : i.extensions[F];
342
+ }), (r = this.parser.json.meshes) == null || r.forEach((n, i) => {
343
+ if (n != null && n.extensions) {
344
+ const s = n == null ? void 0 : n.extensions[F];
345
345
  if (s && s.lods) {
346
346
  for (const o of this.parser.associations.keys())
347
347
  if (o.isMesh) {
348
- const a = this.parser.associations.get(o);
349
- a.meshes === n && v.registerMesh(this.url, s.guid, o, s.lods.length, a.primitives, s);
348
+ const l = this.parser.associations.get(o);
349
+ l.meshes === i && _.registerMesh(this.url, s.guid, o, s.lods.length, l.primitives, s);
350
350
  }
351
351
  }
352
352
  }
353
353
  }), null;
354
354
  }
355
355
  static async getOrLoadLOD(e, t) {
356
- var o, a, d, c;
357
- const r = m == "verbose", i = e.userData.LODS;
358
- if (!i)
356
+ var o, l, f, c;
357
+ const r = m == "verbose", n = e.userData.LODS;
358
+ if (!n)
359
359
  return null;
360
- const n = i == null ? void 0 : i.key;
360
+ const i = n == null ? void 0 : n.key;
361
361
  let s;
362
362
  if (e.isTexture === !0) {
363
363
  const x = e;
364
- x.source && x.source[ae] && (s = x.source[ae]);
364
+ x.source && x.source[le] && (s = x.source[le]);
365
365
  }
366
- if (s || (s = v.lodInfos.get(n)), s) {
366
+ if (s || (s = _.lodInfos.get(i)), s) {
367
367
  if (t > 0) {
368
368
  let y = !1;
369
369
  const w = Array.isArray(s.lods);
370
370
  if (w && t >= s.lods.length ? y = !0 : w || (y = !0), y)
371
- return this.lowresCache.get(n);
371
+ return this.lowresCache.get(i);
372
372
  }
373
373
  const x = Array.isArray(s.lods) ? (o = s.lods[t]) == null ? void 0 : o.path : s.lods;
374
374
  if (!x)
375
375
  return m && !s["missing:uri"] && (s["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + t, s)), null;
376
- const u = Ie(i.url, x);
376
+ const u = $e(n.url, x);
377
377
  if (u.endsWith(".glb") || u.endsWith(".gltf")) {
378
378
  if (!s.guid)
379
379
  return console.warn("missing pointer for glb/gltf texture", s), null;
380
380
  const y = u + "_" + s.guid, w = this.previouslyLoaded.get(y);
381
381
  if (w !== void 0) {
382
382
  r && console.log(`LOD ${t} was already loading/loaded: ${y}`);
383
- let p = await w.catch((U) => (console.error(`Error loading LOD ${t} from ${u}
384
- `, U), null)), M = !1;
385
- if (p == null || (p instanceof q && e instanceof q ? (a = p.image) != null && a.data || (d = p.source) != null && d.data ? p = this.copySettings(e, p) : (M = !0, this.previouslyLoaded.delete(y)) : p instanceof se && e instanceof se && ((c = p.attributes.position) != null && c.array || (M = !0, this.previouslyLoaded.delete(y)))), !M)
383
+ let p = await w.catch((V) => (console.error(`Error loading LOD ${t} from ${u}
384
+ `, V), null)), M = !1;
385
+ if (p == null || (p instanceof q && e instanceof q ? (l = p.image) != null && l.data || (f = p.source) != null && f.data ? p = this.copySettings(e, p) : (M = !0, this.previouslyLoaded.delete(y)) : p instanceof ie && e instanceof ie && ((c = p.attributes.position) != null && c.array || (M = !0, this.previouslyLoaded.delete(y)))), !M)
386
386
  return p;
387
387
  }
388
388
  const L = s, B = new Promise(async (p, M) => {
389
- const U = new Ee();
390
- _e(U), m && (await new Promise((S) => setTimeout(S, 1e3)), r && console.warn("Start loading (delayed) " + u, L.guid));
391
- let k = u;
389
+ const V = new ke();
390
+ _e(V), m && (await new Promise((S) => setTimeout(S, 1e3)), r && console.warn("Start loading (delayed) " + u, L.guid));
391
+ let R = u;
392
392
  if (L && Array.isArray(L.lods)) {
393
393
  const S = L.lods[t];
394
- S.hash && (k += "?v=" + S.hash);
394
+ S.hash && (R += "?v=" + S.hash);
395
395
  }
396
- const _ = await U.loadAsync(k).catch((S) => (console.error(`Error loading LOD ${t} from ${u}
396
+ const v = await V.loadAsync(R).catch((S) => (console.error(`Error loading LOD ${t} from ${u}
397
397
  `, S), null));
398
- if (!_)
398
+ if (!v)
399
399
  return null;
400
- const $ = _.parser;
400
+ const $ = v.parser;
401
401
  r && console.log("Loading finished " + u, L.guid);
402
- let R = 0;
403
- if (_.parser.json.textures) {
402
+ let k = 0;
403
+ if (v.parser.json.textures) {
404
404
  let S = !1;
405
- for (const g of _.parser.json.textures) {
405
+ for (const g of v.parser.json.textures) {
406
406
  if (g != null && g.extensions) {
407
407
  const h = g == null ? void 0 : g.extensions[F];
408
408
  if (h != null && h.guid && h.guid === L.guid) {
@@ -410,17 +410,17 @@ const v = class {
410
410
  break;
411
411
  }
412
412
  }
413
- R++;
413
+ k++;
414
414
  }
415
415
  if (S) {
416
- let g = await $.getDependency("texture", R);
417
- return g && v.assignLODInformation(i.url, g, n, t, void 0, void 0), r && console.log('change "' + e.name + '" → "' + g.name + '"', u, R, g, y), e instanceof q && (g = this.copySettings(e, g)), g && (g.guid = L.guid), p(g);
416
+ let g = await $.getDependency("texture", k);
417
+ return g && _.assignLODInformation(n.url, g, i, t, void 0, void 0), r && console.log('change "' + e.name + '" → "' + g.name + '"', u, k, g, y), e instanceof q && (g = this.copySettings(e, g)), g && (g.guid = L.guid), p(g);
418
418
  } else
419
- m && console.warn("Could not find texture with guid", L.guid, _.parser.json);
419
+ m && console.warn("Could not find texture with guid", L.guid, v.parser.json);
420
420
  }
421
- if (R = 0, _.parser.json.meshes) {
421
+ if (k = 0, v.parser.json.meshes) {
422
422
  let S = !1;
423
- for (const g of _.parser.json.meshes) {
423
+ for (const g of v.parser.json.meshes) {
424
424
  if (g != null && g.extensions) {
425
425
  const h = g == null ? void 0 : g.extensions[F];
426
426
  if (h != null && h.guid && h.guid === L.guid) {
@@ -428,44 +428,44 @@ const v = class {
428
428
  break;
429
429
  }
430
430
  }
431
- R++;
431
+ k++;
432
432
  }
433
433
  if (S) {
434
- const g = await $.getDependency("mesh", R), h = L;
435
- if (r && console.log(`Loaded Mesh "${g.name}"`, u, R, g, y), g.isMesh === !0) {
434
+ const g = await $.getDependency("mesh", k), h = L;
435
+ if (r && console.log(`Loaded Mesh "${g.name}"`, u, k, g, y), g.isMesh === !0) {
436
436
  const D = g.geometry;
437
- return v.assignLODInformation(i.url, D, n, t, void 0, h.density), p(D);
437
+ return _.assignLODInformation(n.url, D, i, t, void 0, h.density), p(D);
438
438
  } else {
439
439
  const D = new Array();
440
440
  for (let b = 0; b < g.children.length; b++) {
441
441
  const T = g.children[b];
442
442
  if (T.isMesh === !0) {
443
443
  const A = T.geometry;
444
- v.assignLODInformation(i.url, A, n, t, b, h.density), D.push(A);
444
+ _.assignLODInformation(n.url, A, i, t, b, h.density), D.push(A);
445
445
  }
446
446
  }
447
447
  return p(D);
448
448
  }
449
449
  } else
450
- m && console.warn("Could not find mesh with guid", L.guid, _.parser.json);
450
+ m && console.warn("Could not find mesh with guid", L.guid, v.parser.json);
451
451
  }
452
452
  return p(null);
453
453
  });
454
454
  return this.previouslyLoaded.set(y, B), await B;
455
455
  } else if (e instanceof q) {
456
456
  r && console.log("Load texture from uri: " + u);
457
- const w = await new Ae().loadAsync(u);
457
+ const w = await new Ce().loadAsync(u);
458
458
  return w ? (w.guid = s.guid, w.flipY = !1, w.needsUpdate = !0, w.colorSpace = e.colorSpace, r && console.log(s, w)) : m && console.warn("failed loading", u), w;
459
459
  }
460
460
  } else
461
- m && console.warn(`Can not load LOD ${t}: no LOD info found for "${n}" ${e.name}`, e.type);
461
+ m && console.warn(`Can not load LOD ${t}: no LOD info found for "${i}" ${e.name}`, e.type);
462
462
  return null;
463
463
  }
464
- static assignLODInformation(e, t, r, i, n, s) {
464
+ static assignLODInformation(e, t, r, n, i, s) {
465
465
  if (!t)
466
466
  return;
467
467
  t.userData || (t.userData = {});
468
- const o = new ze(e, r, i, n, s);
468
+ const o = new Ue(e, r, n, i, s);
469
469
  t.userData.LODS = o;
470
470
  }
471
471
  static getAssignedLODInformation(e) {
@@ -479,87 +479,87 @@ const v = class {
479
479
  `, t.uuid), t.offset = e.offset, t.repeat = e.repeat, t.colorSpace = e.colorSpace, t.magFilter = e.magFilter, t.minFilter = e.minFilter, t.wrapS = e.wrapS, t.wrapT = e.wrapT, t.flipY = e.flipY, t.anisotropy = e.anisotropy, t.mipmaps || (t.generateMipmaps = e.generateMipmaps), t;
480
480
  }
481
481
  };
482
- let O = v;
482
+ let O = _;
483
483
  /**
484
484
  * Register a texture with LOD information
485
485
  */
486
- f(O, "registerTexture", (e, t, r, i, n) => {
487
- if (m && console.log("> Progressive: register texture", i, t.name, t.uuid, t, n), !t) {
486
+ d(O, "registerTexture", (e, t, r, n, i) => {
487
+ if (m && console.log("> Progressive: register texture", n, t.name, t.uuid, t, i), !t) {
488
488
  m && console.error("gltf-progressive: Register texture without texture");
489
489
  return;
490
490
  }
491
- t.source && (t.source[ae] = n);
492
- const s = n.guid;
493
- v.assignLODInformation(e, t, s, r, i, void 0), v.lodInfos.set(s, n), v.lowresCache.set(s, t);
491
+ t.source && (t.source[le] = i);
492
+ const s = i.guid;
493
+ _.assignLODInformation(e, t, s, r, n, void 0), _.lodInfos.set(s, i), _.lowresCache.set(s, t);
494
494
  }), /**
495
495
  * Register a mesh with LOD information
496
496
  */
497
- f(O, "registerMesh", (e, t, r, i, n, s) => {
498
- var d;
499
- m && console.log("> Progressive: register mesh", n, r.name, s, r.uuid, r);
497
+ d(O, "registerMesh", (e, t, r, n, i, s) => {
498
+ var f;
499
+ m && console.log("> Progressive: register mesh", i, r.name, s, r.uuid, r);
500
500
  const o = r.geometry;
501
501
  if (!o) {
502
502
  m && console.warn("gltf-progressive: Register mesh without geometry");
503
503
  return;
504
504
  }
505
- o.userData || (o.userData = {}), v.assignLODInformation(e, o, t, i, n, s.density), v.lodInfos.set(t, s);
506
- let a = v.lowresCache.get(t);
507
- a ? a.push(r.geometry) : a = [r.geometry], v.lowresCache.set(t, a), i > 0 && !pe(r) && Fe(r, o);
505
+ o.userData || (o.userData = {}), _.assignLODInformation(e, o, t, n, i, s.density), _.lodInfos.set(t, s);
506
+ let l = _.lowresCache.get(t);
507
+ l ? l.push(r.geometry) : l = [r.geometry], _.lowresCache.set(t, l), n > 0 && !pe(r) && Ve(r, o);
508
508
  for (const c of z)
509
- (d = c.onRegisteredNewMesh) == null || d.call(c, r, s);
509
+ (f = c.onRegisteredNewMesh) == null || f.call(c, r, s);
510
510
  }), /** A map of key = asset uuid and value = LOD information */
511
- f(O, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
512
- f(O, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
513
- f(O, "lowresCache", /* @__PURE__ */ new Map());
514
- class ze {
515
- constructor(e, t, r, i, n) {
516
- f(this, "url");
511
+ d(O, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
512
+ d(O, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
513
+ d(O, "lowresCache", /* @__PURE__ */ new Map());
514
+ class Ue {
515
+ constructor(e, t, r, n, i) {
516
+ d(this, "url");
517
517
  /** the key to lookup the LOD information */
518
- f(this, "key");
519
- f(this, "level");
518
+ d(this, "key");
519
+ d(this, "level");
520
520
  /** For multi objects (e.g. a group of meshes) this is the index of the object */
521
- f(this, "index");
521
+ d(this, "index");
522
522
  /** the mesh density */
523
- f(this, "density");
524
- this.url = e, this.key = t, this.level = r, i != null && (this.index = i), n != null && (this.density = n);
523
+ d(this, "density");
524
+ this.url = e, this.key = t, this.level = r, n != null && (this.index = n), i != null && (this.density = i);
525
525
  }
526
526
  }
527
- const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = Symbol("Needle:LODSManager"), ce = Symbol("Needle:LODState"), V = Symbol("Needle:CurrentLOD"), C = { mesh_lod: -1, texture_lod: -1 }, P = class {
527
+ const N = j("debugprogressive"), We = j("noprogressive"), ce = Symbol("Needle:LODSManager"), ue = Symbol("Needle:LODState"), U = Symbol("Needle:CurrentLOD"), E = { mesh_lod: -1, texture_lod: -1 }, P = class {
528
528
  // readonly plugins: NEEDLE_progressive_plugin[] = [];
529
529
  constructor(e, t) {
530
- f(this, "context");
531
- f(this, "renderer");
532
- f(this, "projectionScreenMatrix", new ye());
533
- f(this, "cameraFrustrum", new Pe());
530
+ d(this, "context");
531
+ d(this, "renderer");
532
+ d(this, "projectionScreenMatrix", new ye());
533
+ d(this, "cameraFrustrum", new Be());
534
534
  /**
535
535
  * The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
536
536
  * @default 200_000
537
537
  */
538
- f(this, "targetTriangleDensity", 2e5);
538
+ d(this, "targetTriangleDensity", 2e5);
539
539
  /**
540
540
  * The update interval in frames. If set to 0, the LODs will be updated every frame. If set to 1, the LODs will be updated every second frame, etc.
541
541
  */
542
- f(this, "updateInterval", 0);
542
+ d(this, "updateInterval", 0);
543
543
  /**
544
544
  * If set to true, the LODsManager will not update the LODs.
545
545
  */
546
- f(this, "pause", !1);
547
- f(this, "_lodchangedlisteners", []);
548
- f(this, "_frame", 0);
549
- f(this, "_originalRender");
546
+ d(this, "pause", !1);
547
+ d(this, "_lodchangedlisteners", []);
548
+ d(this, "_frame", 0);
549
+ d(this, "_originalRender");
550
550
  // private testIfLODLevelsAreAvailable() {
551
- f(this, "_sphere", new Ce());
552
- f(this, "_tempBox", new me());
553
- f(this, "_tempBox2", new me());
554
- f(this, "tempMatrix", new ye());
555
- f(this, "_tempWorldPosition", new G());
556
- f(this, "_tempBoxSize", new G());
557
- f(this, "_tempBox2Size", new G());
551
+ d(this, "_sphere", new Re());
552
+ d(this, "_tempBox", new me());
553
+ d(this, "_tempBox2", new me());
554
+ d(this, "tempMatrix", new ye());
555
+ d(this, "_tempWorldPosition", new G());
556
+ d(this, "_tempBoxSize", new G());
557
+ d(this, "_tempBox2Size", new G());
558
558
  this.renderer = e, this.context = { ...t };
559
559
  }
560
560
  /** @internal */
561
561
  static getObjectLODState(e) {
562
- return e[ce];
562
+ return e[ue];
563
563
  }
564
564
  static addPlugin(e) {
565
565
  z.push(e);
@@ -574,13 +574,13 @@ const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = Symbol("Needle:LO
574
574
  * @returns The LODsManager instance.
575
575
  */
576
576
  static get(e, t) {
577
- if (e[le])
578
- return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), e[le];
577
+ if (e[ce])
578
+ return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), e[ce];
579
579
  const r = new P(e, {
580
580
  engine: "unknown",
581
581
  ...t
582
582
  });
583
- return e[le] = r, r;
583
+ return e[ce] = r, r;
584
584
  }
585
585
  /** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
586
586
  get plugins() {
@@ -599,34 +599,34 @@ const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = Symbol("Needle:LO
599
599
  let e = 0;
600
600
  this._originalRender = this.renderer.render;
601
601
  const t = this;
602
- we(this.renderer), this.renderer.render = function(r, i) {
602
+ ve(this.renderer), this.renderer.render = function(r, n) {
603
603
  t.renderer.getRenderTarget() == null && (e = 0, t._frame += 1);
604
604
  const s = t._frame, o = e++;
605
- t.onBeforeRender(r, i, o, s), t._originalRender.call(this, r, i), t.onAfterRender(r, i, o, s);
605
+ t.onBeforeRender(r, n, o, s), t._originalRender.call(this, r, n), t.onAfterRender(r, n, o, s);
606
606
  };
607
607
  }
608
608
  disable() {
609
609
  this._originalRender && (this.renderer.render = this._originalRender, this._originalRender = void 0);
610
610
  }
611
- onBeforeRender(e, t, r, i) {
611
+ onBeforeRender(e, t, r, n) {
612
612
  }
613
- onAfterRender(e, t, r, i) {
614
- var a, d;
613
+ onAfterRender(e, t, r, n) {
614
+ var l, f;
615
615
  if (this.pause)
616
616
  return;
617
- const n = this.renderer.renderLists.get(e, 0), s = n.opaque;
617
+ const i = this.renderer.renderLists.get(e, 0), s = i.opaque;
618
618
  let o = !0;
619
619
  if (s.length === 1) {
620
620
  const c = s[0].material;
621
621
  (c.name === "EffectMaterial" || c.name === "CopyShader") && (o = !1);
622
622
  }
623
623
  if ((t.parent && t.parent.type === "CubeCamera" || r >= 1 && t.type === "OrthographicCamera") && (o = !1), o) {
624
- if (Ue || this.updateInterval > 0 && i % this.updateInterval != 0)
624
+ if (We || this.updateInterval > 0 && n % this.updateInterval != 0)
625
625
  return;
626
626
  this.projectionScreenMatrix.multiplyMatrices(t.projectionMatrix, t.matrixWorldInverse), this.cameraFrustrum.setFromProjectionMatrix(this.projectionScreenMatrix, this.renderer.coordinateSystem);
627
627
  const c = this.targetTriangleDensity;
628
628
  for (const u of s) {
629
- if (u.material && (((a = u.geometry) == null ? void 0 : a.type) === "BoxGeometry" || ((d = u.geometry) == null ? void 0 : d.type) === "BufferGeometry") && (u.material.name === "SphericalGaussianBlur" || u.material.name == "BackgroundCubeMaterial" || u.material.name === "CubemapFromEquirect" || u.material.name === "EquirectangularToCubeUV")) {
629
+ if (u.material && (((l = u.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((f = u.geometry) == null ? void 0 : f.type) === "BufferGeometry") && (u.material.name === "SphericalGaussianBlur" || u.material.name == "BackgroundCubeMaterial" || u.material.name === "CubemapFromEquirect" || u.material.name === "EquirectangularToCubeUV")) {
630
630
  N && (u.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (u.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", u, u.material.name, u.material.type)));
631
631
  continue;
632
632
  }
@@ -640,33 +640,33 @@ const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = Symbol("Needle:LO
640
640
  continue;
641
641
  }
642
642
  const y = u.object;
643
- (y instanceof W || y.isMesh) && this.updateLODs(e, t, y, c, i);
643
+ (y instanceof W || y.isMesh) && this.updateLODs(e, t, y, c, n);
644
644
  }
645
- const x = n.transparent;
645
+ const x = i.transparent;
646
646
  for (const u of x) {
647
647
  const y = u.object;
648
- (y instanceof W || y.isMesh) && this.updateLODs(e, t, y, c, i);
648
+ (y instanceof W || y.isMesh) && this.updateLODs(e, t, y, c, n);
649
649
  }
650
650
  }
651
651
  }
652
652
  /** Update the LOD levels for the renderer. */
653
- updateLODs(e, t, r, i, n) {
654
- var a, d;
653
+ updateLODs(e, t, r, n, i) {
654
+ var l, f;
655
655
  r.userData || (r.userData = {});
656
- let s = r[ce];
657
- if (s || (s = new Ne(), r[ce] = s), s.frames++ < 2)
656
+ let s = r[ue];
657
+ if (s || (s = new Ke(), r[ue] = s), s.frames++ < 2)
658
658
  return;
659
659
  for (const c of z)
660
- (a = c.onBeforeUpdateLOD) == null || a.call(c, this.renderer, e, t, r);
661
- this.calculateLodLevel(t, r, s, i, C), C.mesh_lod = Math.round(C.mesh_lod), C.texture_lod = Math.round(C.texture_lod), C.mesh_lod >= 0 && this.loadProgressiveMeshes(r, C.mesh_lod);
662
- let o = C.texture_lod;
660
+ (l = c.onBeforeUpdateLOD) == null || l.call(c, this.renderer, e, t, r);
661
+ this.calculateLodLevel(t, r, s, n, E), E.mesh_lod = Math.round(E.mesh_lod), E.texture_lod = Math.round(E.texture_lod), E.mesh_lod >= 0 && this.loadProgressiveMeshes(r, E.mesh_lod);
662
+ let o = E.texture_lod;
663
663
  if (r.material && o >= 0) {
664
664
  const c = r["DEBUG:LOD"];
665
665
  c != null && (o = c), this.loadProgressiveTextures(r.material, o);
666
666
  }
667
667
  for (const c of z)
668
- (d = c.onAfterUpdatedLOD) == null || d.call(c, this.renderer, e, t, r, C);
669
- s.lastLodLevel_Mesh = C.mesh_lod, s.lastLodLevel_Texture = C.texture_lod;
668
+ (f = c.onAfterUpdatedLOD) == null || f.call(c, this.renderer, e, t, r, E);
669
+ s.lastLodLevel_Mesh = E.mesh_lod, s.lastLodLevel_Texture = E.texture_lod;
670
670
  }
671
671
  /** Load progressive textures for the given material
672
672
  * @param material the material to load the textures for
@@ -677,13 +677,13 @@ const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = Symbol("Needle:LO
677
677
  if (!e)
678
678
  return;
679
679
  if (Array.isArray(e)) {
680
- for (const i of e)
681
- this.loadProgressiveTextures(i, t);
680
+ for (const n of e)
681
+ this.loadProgressiveTextures(n, t);
682
682
  return;
683
683
  }
684
684
  let r = !1;
685
- (e[V] === void 0 || t < e[V]) && (r = !0), r && (e[V] = t, O.assignTextureLOD(e, t).then((i) => {
686
- this._lodchangedlisteners.forEach((n) => n({ type: "texture", level: t, object: e }));
685
+ (e[U] === void 0 || t < e[U]) && (r = !0), r && (e[U] = t, O.assignTextureLOD(e, t).then((n) => {
686
+ this._lodchangedlisteners.forEach((i) => i({ type: "texture", level: t, object: e }));
687
687
  }));
688
688
  }
689
689
  /** Load progressive meshes for the given mesh
@@ -695,37 +695,37 @@ const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = Symbol("Needle:LO
695
695
  loadProgressiveMeshes(e, t) {
696
696
  if (!e)
697
697
  return Promise.resolve(null);
698
- if (e[V] !== t) {
699
- e[V] = t;
698
+ if (e[U] !== t) {
699
+ e[U] = t;
700
700
  const r = e.geometry;
701
- return O.assignMeshLOD(e, t).then((i) => (i && e[V] == t && r != e.geometry && this._lodchangedlisteners.forEach((n) => n({ type: "mesh", level: t, object: e })), i));
701
+ return O.assignMeshLOD(e, t).then((n) => (n && e[U] == t && r != e.geometry && this._lodchangedlisteners.forEach((i) => i({ type: "mesh", level: t, object: e })), n));
702
702
  }
703
703
  return Promise.resolve(null);
704
704
  }
705
705
  static isInside(e, t) {
706
- const r = e.min, i = e.max, n = (r.x + i.x) * 0.5, s = (r.y + i.y) * 0.5;
707
- return this._tempPtInside.set(n, s, r.z).applyMatrix4(t).z < 0;
706
+ const r = e.min, n = e.max, i = (r.x + n.x) * 0.5, s = (r.y + n.y) * 0.5;
707
+ return this._tempPtInside.set(i, s, r.z).applyMatrix4(t).z < 0;
708
708
  }
709
- calculateLodLevel(e, t, r, i, n) {
709
+ calculateLodLevel(e, t, r, n, i) {
710
710
  var B, I;
711
711
  if (!t) {
712
- n.mesh_lod = -1, n.texture_lod = -1;
712
+ i.mesh_lod = -1, i.texture_lod = -1;
713
713
  return;
714
714
  }
715
715
  if (!e) {
716
- n.mesh_lod = -1, n.texture_lod = -1;
716
+ i.mesh_lod = -1, i.texture_lod = -1;
717
717
  return;
718
718
  }
719
- let o = 10 + 1, a = !1;
719
+ let o = 10 + 1, l = !1;
720
720
  if (N && t["DEBUG:LOD"] != null)
721
721
  return t["DEBUG:LOD"];
722
- const d = O.getMeshLODInformation(t.geometry), c = d == null ? void 0 : d.lods, x = c && c.length > 0, u = O.getMaterialMinMaxLODsCount(t.material), y = (u == null ? void 0 : u.min_count) != 1 / 0 && u.min_count > 0 && u.max_count > 0;
722
+ const f = O.getMeshLODInformation(t.geometry), c = f == null ? void 0 : f.lods, x = c && c.length > 0, u = O.getMaterialMinMaxLODsCount(t.material), y = (u == null ? void 0 : u.min_count) != 1 / 0 && u.min_count > 0 && u.max_count > 0;
723
723
  if (!x && !y) {
724
- n.mesh_lod = 0, n.texture_lod = 0;
724
+ i.mesh_lod = 0, i.texture_lod = 0;
725
725
  return;
726
726
  }
727
- if (x || (a = !0, o = 0), !((B = this.cameraFrustrum) != null && B.intersectsObject(t))) {
728
- n.mesh_lod = 99, n.texture_lod = 99;
727
+ if (x || (l = !0, o = 0), !((B = this.cameraFrustrum) != null && B.intersectsObject(t))) {
728
+ i.mesh_lod = 99, i.texture_lod = 99;
729
729
  return;
730
730
  }
731
731
  const w = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
@@ -740,29 +740,29 @@ const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = Symbol("Needle:LO
740
740
  this._sphere.copy(t.geometry.boundingSphere), this._sphere.applyMatrix4(t.matrixWorld);
741
741
  const h = e.getWorldPosition(this._tempWorldPosition);
742
742
  if (this._sphere.containsPoint(h)) {
743
- n.mesh_lod = 0, n.texture_lod = 0;
743
+ i.mesh_lod = 0, i.texture_lod = 0;
744
744
  return;
745
745
  }
746
746
  }
747
747
  if (this._tempBox.copy(L), this._tempBox.applyMatrix4(t.matrixWorld), P.isInside(this._tempBox, this.projectionScreenMatrix)) {
748
- n.mesh_lod = 0, n.texture_lod = 0;
748
+ i.mesh_lod = 0, i.texture_lod = 0;
749
749
  return;
750
750
  }
751
751
  if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && p.fov > 70) {
752
752
  const h = this._tempBox.min, D = this._tempBox.max;
753
753
  let b = h.x, T = h.y, A = D.x, K = D.y;
754
- const j = 2, ne = 1.5, ee = (h.x + D.x) * 0.5, te = (h.y + D.y) * 0.5;
755
- b = (b - ee) * j + ee, T = (T - te) * j + te, A = (A - ee) * j + ee, K = (K - te) * j + te;
756
- const ve = b < 0 && A > 0 ? 0 : Math.min(Math.abs(h.x), Math.abs(D.x)), Oe = T < 0 && K > 0 ? 0 : Math.min(Math.abs(h.y), Math.abs(D.y)), oe = Math.max(ve, Oe);
757
- r.lastCentrality = (ne - oe) * (ne - oe) * (ne - oe);
754
+ const ee = 2, oe = 1.5, te = (h.x + D.x) * 0.5, re = (h.y + D.y) * 0.5;
755
+ b = (b - te) * ee + te, T = (T - re) * ee + re, A = (A - te) * ee + te, K = (K - re) * ee + re;
756
+ const be = b < 0 && A > 0 ? 0 : Math.min(Math.abs(h.x), Math.abs(D.x)), Te = T < 0 && K > 0 ? 0 : Math.min(Math.abs(h.y), Math.abs(D.y)), ae = Math.max(be, Te);
757
+ r.lastCentrality = (oe - ae) * (oe - ae) * (oe - ae);
758
758
  } else
759
759
  r.lastCentrality = 1;
760
760
  const M = this._tempBox.getSize(this._tempBoxSize);
761
761
  M.multiplyScalar(0.5), screen.availHeight > 0 && w > 0 && M.multiplyScalar(w / screen.availHeight), M.x *= p.aspect;
762
- const U = e.matrixWorldInverse, k = this._tempBox2;
763
- k.copy(L), k.applyMatrix4(t.matrixWorld), k.applyMatrix4(U);
764
- const _ = k.getSize(this._tempBox2Size), $ = Math.max(_.x, _.y);
765
- if (Math.max(M.x, M.y) != 0 && $ != 0 && (M.z = _.z / Math.max(_.x, _.y) * Math.max(M.x, M.y)), r.lastScreenCoverage = Math.max(M.x, M.y, M.z), r.lastScreenspaceVolume.copy(M), r.lastScreenCoverage *= r.lastCentrality, N && P.debugDrawLine) {
762
+ const V = e.matrixWorldInverse, R = this._tempBox2;
763
+ R.copy(L), R.applyMatrix4(t.matrixWorld), R.applyMatrix4(V);
764
+ const v = R.getSize(this._tempBox2Size), $ = Math.max(v.x, v.y);
765
+ if (Math.max(M.x, M.y) != 0 && $ != 0 && (M.z = v.z / Math.max(v.x, v.y) * Math.max(M.x, M.y)), r.lastScreenCoverage = Math.max(M.x, M.y, M.z), r.lastScreenspaceVolume.copy(M), r.lastScreenCoverage *= r.lastCentrality, N && P.debugDrawLine) {
766
766
  const h = this.tempMatrix.copy(this.projectionScreenMatrix);
767
767
  h.invert();
768
768
  const D = P.corner0, b = P.corner1, T = P.corner2, A = P.corner3;
@@ -773,35 +773,35 @@ const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = Symbol("Needle:LO
773
773
  let S = 999;
774
774
  if (c && r.lastScreenCoverage > 0) {
775
775
  for (let h = 0; h < c.length; h++)
776
- if (c[h].density / r.lastScreenCoverage < i) {
776
+ if (c[h].density / r.lastScreenCoverage < n) {
777
777
  S = h;
778
778
  break;
779
779
  }
780
780
  }
781
- S < o && (o = S, a = !0);
781
+ S < o && (o = S, l = !0);
782
782
  }
783
- if (a ? n.mesh_lod = o : n.mesh_lod = r.lastLodLevel_Mesh, N && n.mesh_lod != r.lastLodLevel_Mesh) {
784
- const M = c == null ? void 0 : c[n.mesh_lod];
785
- M && console.log(`Mesh LOD changed: ${r.lastLodLevel_Mesh} → ${n.mesh_lod} (${M.density.toFixed(0)}) - ${t.name}`);
783
+ if (l ? i.mesh_lod = o : i.mesh_lod = r.lastLodLevel_Mesh, N && i.mesh_lod != r.lastLodLevel_Mesh) {
784
+ const M = c == null ? void 0 : c[i.mesh_lod];
785
+ M && console.log(`Mesh LOD changed: ${r.lastLodLevel_Mesh} → ${i.mesh_lod} (${M.density.toFixed(0)}) - ${t.name}`);
786
786
  }
787
787
  if (y)
788
788
  if (r.lastLodLevel_Texture < 0) {
789
- if (n.texture_lod = u.max_count - 1, N) {
789
+ if (i.texture_lod = u.max_count - 1, N) {
790
790
  const p = u.lods[u.max_count - 1];
791
- N && console.log(`First Texture LOD ${n.texture_lod} (${p.max_height}px) - ${t.name}`);
791
+ N && console.log(`First Texture LOD ${i.texture_lod} (${p.max_height}px) - ${t.name}`);
792
792
  }
793
793
  } else {
794
794
  const p = r.lastScreenspaceVolume.x + r.lastScreenspaceVolume.y + r.lastScreenspaceVolume.z;
795
795
  let M = r.lastScreenCoverage * 2;
796
796
  ((I = this.context) == null ? void 0 : I.engine) === "model-viewer" && (M *= 2);
797
- const k = w / window.devicePixelRatio * M;
798
- for (let _ = u.lods.length - 1; _ >= 0; _--) {
799
- let $ = u.lods[_];
800
- if (!(Ge() && $.max_height > 4096) && $.max_height > k) {
801
- if (n.texture_lod = _, n.texture_lod < r.lastLodLevel_Texture) {
802
- const R = $.max_height;
803
- N && console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} → ${n.texture_lod} = ${R}px
804
- Screensize: ${k.toFixed(0)}px, Coverage: ${(100 * r.lastScreenCoverage).toFixed(2)}%, Volume ${p.toFixed(1)}
797
+ const R = w / window.devicePixelRatio * M;
798
+ for (let v = u.lods.length - 1; v >= 0; v--) {
799
+ let $ = u.lods[v];
800
+ if (!(ze() && $.max_height > 4096) && $.max_height > R) {
801
+ if (i.texture_lod = v, i.texture_lod < r.lastLodLevel_Texture) {
802
+ const k = $.max_height;
803
+ N && console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} → ${i.texture_lod} = ${k}px
804
+ Screensize: ${R.toFixed(0)}px, Coverage: ${(100 * r.lastScreenCoverage).toFixed(2)}%, Volume ${p.toFixed(1)}
805
805
  ${t.name}`);
806
806
  }
807
807
  break;
@@ -809,74 +809,92 @@ ${t.name}`);
809
809
  }
810
810
  }
811
811
  else
812
- n.texture_lod = 0;
812
+ i.texture_lod = 0;
813
813
  }
814
814
  };
815
- let E = P;
815
+ let C = P;
816
816
  /** 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.
817
817
  */
818
- f(E, "debugDrawLine"), f(E, "corner0", new G()), f(E, "corner1", new G()), f(E, "corner2", new G()), f(E, "corner3", new G()), f(E, "_tempPtInside", new G());
819
- class Ne {
818
+ d(C, "debugDrawLine"), d(C, "corner0", new G()), d(C, "corner1", new G()), d(C, "corner2", new G()), d(C, "corner3", new G()), d(C, "_tempPtInside", new G());
819
+ class Ke {
820
820
  constructor() {
821
- f(this, "frames", 0);
822
- f(this, "lastLodLevel_Mesh", -1);
823
- f(this, "lastLodLevel_Texture", -1);
824
- f(this, "lastScreenCoverage", 0);
825
- f(this, "lastScreenspaceVolume", new G());
826
- f(this, "lastCentrality", 0);
821
+ d(this, "frames", 0);
822
+ d(this, "lastLodLevel_Mesh", -1);
823
+ d(this, "lastLodLevel_Texture", -1);
824
+ d(this, "lastScreenCoverage", 0);
825
+ d(this, "lastScreenspaceVolume", new G());
826
+ d(this, "lastCentrality", 0);
827
827
  }
828
828
  }
829
- const Le = Symbol("NEEDLE_mesh_lod"), re = Symbol("NEEDLE_texture_lod");
830
- function Ve() {
831
- document.removeEventListener("DOMContentLoaded", ue), document.addEventListener("DOMContentLoaded", ue), ue();
829
+ const Le = Symbol("NEEDLE_mesh_lod"), se = Symbol("NEEDLE_texture_lod");
830
+ let H = null;
831
+ function Oe() {
832
+ const a = qe();
833
+ a && (a.mapURLs(function(e) {
834
+ return Me(), e;
835
+ }), Me(), H == null || H.disconnect(), H = new MutationObserver((e) => {
836
+ e.forEach((t) => {
837
+ t.addedNodes.forEach((r) => {
838
+ r instanceof HTMLElement && r.tagName.toLowerCase() === "model-viewer" && Se(r);
839
+ });
840
+ });
841
+ }), H.observe(document, { childList: !0, subtree: !0 }));
842
+ }
843
+ function qe() {
844
+ const a = customElements.get("model-viewer");
845
+ return a || (customElements.whenDefined("model-viewer").then(() => {
846
+ console.debug("[gltf-progressive] model-viewer defined"), Oe();
847
+ }), null);
832
848
  }
833
- function ue() {
834
- document.querySelectorAll("model-viewer").forEach((e, t) => {
835
- We(e, t);
849
+ function Me() {
850
+ document.querySelectorAll("model-viewer").forEach((e) => {
851
+ Se(e);
836
852
  });
837
853
  }
838
- const Me = /* @__PURE__ */ new WeakSet();
839
- function We(l, e) {
840
- if (!l || Me.has(l))
854
+ const De = /* @__PURE__ */ new WeakSet();
855
+ let Xe = 0;
856
+ function Se(a) {
857
+ if (!a || De.has(a))
841
858
  return null;
842
- Me.add(l), console.debug("[gltf-progressive] found model-viewer..." + e);
843
- let t = null, r = null, i = null;
844
- for (let n = l; n != null; n = Object.getPrototypeOf(n)) {
845
- const s = Object.getOwnPropertySymbols(n), o = s.find((c) => c.toString() == "Symbol(renderer)"), a = s.find((c) => c.toString() == "Symbol(scene)"), d = s.find((c) => c.toString() == "Symbol(needsRender)");
846
- !t && o != null && (t = l[o].threeRenderer), !r && a != null && (r = l[a]), !i && d != null && (i = l[d]);
847
- }
848
- if (t && r) {
859
+ De.add(a), console.debug("[gltf-progressive] found new model-viewer..." + ++Xe + `
860
+ `, a.getAttribute("src"));
861
+ let e = null, t = null, r = null;
862
+ for (let n = a; n != null; n = Object.getPrototypeOf(n)) {
863
+ const i = Object.getOwnPropertySymbols(n), s = i.find((f) => f.toString() == "Symbol(renderer)"), o = i.find((f) => f.toString() == "Symbol(scene)"), l = i.find((f) => f.toString() == "Symbol(needsRender)");
864
+ !e && s != null && (e = a[s].threeRenderer), !t && o != null && (t = a[o]), !r && l != null && (r = a[l]);
865
+ }
866
+ if (e && t) {
849
867
  let n = function() {
850
- if (i) {
851
- let o = 0, a = setInterval(() => {
852
- if (o++ > 5) {
853
- clearInterval(a);
868
+ if (r) {
869
+ let s = 0, o = setInterval(() => {
870
+ if (s++ > 5) {
871
+ clearInterval(o);
854
872
  return;
855
873
  }
856
- i == null || i.call(l);
874
+ r == null || r.call(a);
857
875
  }, 300);
858
876
  }
859
877
  };
860
878
  console.debug("[gltf-progressive] setup model-viewer");
861
- const s = E.get(t, { engine: "model-viewer" });
862
- return E.addPlugin(new Ke()), s.enable(), s.addEventListener("changed", () => {
863
- i == null || i.call(l);
864
- }), l.addEventListener("model-visibility", (o) => {
865
- o.detail.visible && (i == null || i.call(l));
866
- }), l.addEventListener("load", () => {
879
+ const i = C.get(e, { engine: "model-viewer" });
880
+ return C.addPlugin(new Ye()), i.enable(), i.addEventListener("changed", () => {
881
+ r == null || r.call(a);
882
+ }), a.addEventListener("model-visibility", (s) => {
883
+ s.detail.visible && (r == null || r.call(a));
884
+ }), a.addEventListener("load", () => {
867
885
  n();
868
886
  }), () => {
869
- s.disable();
887
+ i.disable();
870
888
  };
871
889
  }
872
890
  return null;
873
891
  }
874
- class Ke {
892
+ class Ye {
875
893
  constructor() {
876
- f(this, "_didWarnAboutMissingUrl", !1);
894
+ d(this, "_didWarnAboutMissingUrl", !1);
877
895
  }
878
- onBeforeUpdateLOD(e, t, r, i) {
879
- this.tryParseMeshLOD(t, i), this.tryParseTextureLOD(t, i);
896
+ onBeforeUpdateLOD(e, t, r, n) {
897
+ this.tryParseMeshLOD(t, n), this.tryParseTextureLOD(t, n);
880
898
  }
881
899
  getUrl(e) {
882
900
  if (!e)
@@ -891,19 +909,19 @@ class Ke {
891
909
  return e.element;
892
910
  }
893
911
  tryParseTextureLOD(e, t) {
894
- if (t[re] == !0)
912
+ if (t[se] == !0)
895
913
  return;
896
- t[re] = !0;
897
- const r = this.tryGetCurrentGLTF(e), i = this.tryGetCurrentModelViewer(e), n = this.getUrl(i);
898
- if (n && r && t.material) {
899
- let s = function(a) {
914
+ t[se] = !0;
915
+ const r = this.tryGetCurrentGLTF(e), n = this.tryGetCurrentModelViewer(e), i = this.getUrl(n);
916
+ if (i && r && t.material) {
917
+ let s = function(l) {
900
918
  var c, x, u;
901
- if (a[re] == !0)
919
+ if (l[se] == !0)
902
920
  return;
903
- a[re] = !0, a.userData && (a.userData.LOD = -1);
904
- const d = Object.keys(a);
905
- for (let y = 0; y < d.length; y++) {
906
- const w = d[y], L = a[w];
921
+ l[se] = !0, l.userData && (l.userData.LOD = -1);
922
+ const f = Object.keys(l);
923
+ for (let y = 0; y < f.length; y++) {
924
+ const w = f[y], L = l[w];
907
925
  if ((L == null ? void 0 : L.isTexture) === !0) {
908
926
  const B = (x = (c = L.userData) == null ? void 0 : c.associations) == null ? void 0 : x.textures;
909
927
  if (B == null)
@@ -915,15 +933,15 @@ class Ke {
915
933
  }
916
934
  if ((u = I == null ? void 0 : I.extensions) != null && u[F]) {
917
935
  const p = I.extensions[F];
918
- p && n && O.registerTexture(n, L, p.lods.length, B, p);
936
+ p && i && O.registerTexture(i, L, p.lods.length, B, p);
919
937
  }
920
938
  }
921
939
  }
922
940
  };
923
941
  const o = t.material;
924
942
  if (Array.isArray(o))
925
- for (const a of o)
926
- s(a);
943
+ for (const l of o)
944
+ s(l);
927
945
  else
928
946
  s(o);
929
947
  }
@@ -933,34 +951,34 @@ class Ke {
933
951
  if (t[Le] == !0)
934
952
  return;
935
953
  t[Le] = !0;
936
- const r = this.tryGetCurrentModelViewer(e), i = this.getUrl(r);
937
- if (!i)
954
+ const r = this.tryGetCurrentModelViewer(e), n = this.getUrl(r);
955
+ if (!n)
938
956
  return;
939
- const n = (o = (s = t.userData) == null ? void 0 : s.gltfExtensions) == null ? void 0 : o[F];
940
- if (n && i) {
941
- const a = t.uuid;
942
- O.registerMesh(i, a, t, 0, n.lods.length, n);
957
+ const i = (o = (s = t.userData) == null ? void 0 : s.gltfExtensions) == null ? void 0 : o[F];
958
+ if (i && n) {
959
+ const l = t.uuid;
960
+ O.registerMesh(n, l, t, 0, i.lods.length, i);
943
961
  }
944
962
  }
945
963
  }
946
- Ve();
947
- function tt(l, e, t, r) {
948
- we(e), _e(t), t.register((n) => new O(n, l));
949
- const i = E.get(e);
950
- return (r == null ? void 0 : r.enableLODsManager) !== !1 && i.enable(), i;
964
+ function it(a, e, t, r) {
965
+ ve(e), _e(t), t.register((i) => new O(i, a));
966
+ const n = C.get(e);
967
+ return (r == null ? void 0 : r.enableLODsManager) !== !1 && n.enable(), n;
951
968
  }
969
+ Oe();
952
970
  export {
953
971
  F as EXTENSION_NAME,
954
- E as LODsManager,
972
+ C as LODsManager,
955
973
  O as NEEDLE_progressive,
956
- De as VERSION,
974
+ we as VERSION,
957
975
  _e as addDracoAndKTX2Loaders,
958
- we as createLoaders,
976
+ ve as createLoaders,
959
977
  pe as getRaycastMesh,
960
- Ve as patchModelViewer,
961
- Ze as setDracoDecoderLocation,
962
- je as setKTX2TranscoderLocation,
963
- Fe as setRaycastMesh,
964
- tt as useNeedleProgressive,
965
- et as useRaycastMeshes
978
+ Oe as patchModelViewer,
979
+ tt as setDracoDecoderLocation,
980
+ rt as setKTX2TranscoderLocation,
981
+ Ve as setRaycastMesh,
982
+ it as useNeedleProgressive,
983
+ st as useRaycastMeshes
966
984
  };