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