@needle-tools/gltf-progressive 1.2.2-alpha.3 → 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 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 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 Ze(l) {
17
- ie = l;
24
+ function gt(a) {
25
+ he = a;
18
26
  }
19
- function je(l) {
20
- ge = l;
27
+ function pt(a) {
28
+ _e = a;
21
29
  }
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");
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(l) {
27
- l.dracoLoader || l.setDRACOLoader(H), l.ktx2Loader || l.setKTX2Loader(J), l.meshoptDecoder || l.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
- Z("debugprogressive");
30
- function Z(l) {
31
- const t = new URL(window.location.href).searchParams.get(l);
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 Ie(l, e) {
35
- if (e === void 0 || e.startsWith("./") || e.startsWith("http") || l === void 0)
36
- return e;
37
- const t = l.lastIndexOf("/");
38
- if (t >= 0) {
39
- const r = l.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 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;
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(l) {
52
- return (l == null ? void 0 : l[de]) instanceof se ? l[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 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;
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 et(l = !0) {
61
- if (l) {
62
- if (Y)
68
+ function yt(a = !0) {
69
+ if (a) {
70
+ if (re)
63
71
  return;
64
- const e = Y = W.prototype.raycast;
65
- W.prototype.raycast = function(t, r) {
66
- const i = this, n = pe(i);
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
- n && i.isMesh && (s = i.geometry, i.geometry = n), e.call(this, t, r), s && (i.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 $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;
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 = Z("debugprogressive"), ae = Symbol("needle-progressive-texture"), Q = /* @__PURE__ */ new Map(), he = /* @__PURE__ */ new Set();
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];
89
- if (o != null) {
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 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) {
93
+ let a = function() {
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));
101
+ } else if (i.isMaterial === !0) {
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", (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);
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) => {
111
+ i.name != "BackgroundCubeMaterial" && i.glyphMap == null && "wireframe" in i && (i.wireframe = r);
104
112
  }));
105
113
  });
106
114
  }
107
- function xe(l, e, t) {
108
- var i;
109
- if (!m)
115
+ function Ae(a, t, e) {
116
+ var o;
117
+ if (!L)
110
118
  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);
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 v = class {
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;
123
+ const O = class {
124
+ constructor(t, e) {
125
+ d(this, "parser");
126
+ d(this, "url");
127
+ d(this, "_isLoadingMesh");
128
+ d(this, "loadMesh", (t) => {
129
+ var r, o;
122
130
  if (this._isLoadingMesh)
123
131
  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) => {
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, n && v.registerMesh(this.url, t.guid, n, (s = t.lods) == null ? void 0 : s.length, void 0, t), n;
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, i = "LODS:minmax", n = e[i];
142
- if (n != null)
143
- return n;
144
- if (t || (t = {
148
+ static getMaterialMinMaxLODsCount(t, e) {
149
+ const r = this, o = "LODS:minmax", i = t[o];
150
+ if (i != null)
151
+ return i;
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[i] = 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 a of Object.keys(o.uniforms)) {
156
- const d = o.uniforms[a].value;
157
- (d == null ? void 0 : d.isTexture) === !0 && s(d, 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 a = e[o];
162
- (a == null ? void 0 : a.isTexture) === !0 && s(a, 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[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);
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);
171
- for (let x = 0; x < c.lods.length; x++) {
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));
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 v = 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) {
185
- var n;
186
- if (Array.isArray(e)) {
187
- for (const s of e)
188
- if (this.hasLODLevelAvailable(s, t))
192
+ static hasLODLevelAvailable(t, e) {
193
+ var i;
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, 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) {
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 (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;
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 v = 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 i = e.geometry, n = this.getAssignedLODInformation(i);
234
- if (!n)
240
+ if (t instanceof J || t.isMesh === !0) {
241
+ const o = t.geometry, i = this.getAssignedLODInformation(o);
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, v.getOrLoadLOD(i, t).then((s) => {
239
- if (e["LOD:requested level"] === t) {
240
- if (delete e["LOD:requested level"], Array.isArray(s)) {
241
- const o = n.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 && i != s && ((s == null ? void 0 : s.isBufferGeometry) ? (e.geometry = s, m && xe(e, "geometry", n.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,381 +264,389 @@ const v = 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 Te || e.isMaterial === !0) {
263
- const r = e, i = [], n = 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 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);
274
+ for (const n of Object.keys(s.uniforms)) {
275
+ const l = s.uniforms[n].value;
276
+ if ((l == null ? void 0 : l.isTexture) === !0) {
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 a = this.assignTextureLODForSlot(o, t, r, s);
278
- i.push(a), n.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(i).then((s) => {
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 });
289
+ return Promise.all(o).then((s) => {
290
+ const n = new Array();
291
+ for (let l = 0; l < s.length; l++) {
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, 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))
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) => {
306
+ if (Array.isArray(i))
299
307
  return null;
300
- if ((n == null ? void 0 : n.isTexture) === !0) {
301
- if (n != e) {
302
- if (r && i) {
303
- const s = r[i];
308
+ if ((i == null ? void 0 : i.isTexture) === !0) {
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, n), 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[i] = n;
317
+ r[o] = i;
310
318
  }
311
- if (m && i && r) {
312
- const s = this.getAssignedLODInformation(e);
313
- s && xe(r, i, 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
- return n;
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((n) => (console.error("Error loading LOD", e, n), 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((i, n) => {
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 (i != null && i.extensions) {
327
- const o = i == null ? void 0 : i.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
- 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) => {
337
- var c;
338
- d && v.registerTexture(this.url, d, (c = o.lods) == null ? void 0 : c.length, n, o);
341
+ let l = !1;
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((i, n) => {
343
- if (i != null && i.extensions) {
344
- const s = i == null ? void 0 : i.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 a = this.parser.associations.get(o);
349
- a.meshes === n && v.registerMesh(this.url, s.guid, o, s.lods.length, a.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, a, d, c;
357
- const r = m == "verbose", i = e.userData.LODS;
358
- if (!i)
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 n = i == null ? void 0 : i.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[ae] && (s = x.source[ae]);
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 = v.lodInfos.get(n)), 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)
371
- return this.lowresCache.get(n);
377
+ const v = Array.isArray(s.lods);
378
+ if (v && e >= s.lods.length ? y = !0 : v || (y = !0), y)
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 = Ie(i.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((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)
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 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;
392
- if (L && Array.isArray(L.lods)) {
393
- const S = L.lods[t];
394
- S.hash && (k += "?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 _ = await U.loadAsync(k).catch((S) => (console.error(`Error loading LOD ${t} from ${u}
397
- `, S), null));
404
+ const _ = await Y.loadAsync(G).catch((b) => (console.error(`Error loading LOD ${e} from ${c}
405
+ `, b), null));
398
406
  if (!_)
399
407
  return null;
400
- const $ = _.parser;
401
- r && console.log("Loading finished " + u, L.guid);
402
- let R = 0;
408
+ const K = _.parser;
409
+ r && console.log("Loading finished " + c, x.guid);
410
+ let F = 0;
403
411
  if (_.parser.json.textures) {
404
- let S = !1;
412
+ let b = !1;
405
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
- R++;
421
+ F++;
414
422
  }
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);
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, _.parser.json);
427
+ L && console.warn("Could not find texture with guid", x.guid, _.parser.json);
420
428
  }
421
- if (R = 0, _.parser.json.meshes) {
422
- let S = !1;
429
+ if (F = 0, _.parser.json.meshes) {
430
+ let b = !1;
423
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
- R++;
439
+ F++;
432
440
  }
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) {
436
- const D = g.geometry;
437
- return v.assignLODInformation(i.url, D, n, 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
- v.assignLODInformation(i.url, A, n, 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, _.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 Ae().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 "${n}" ${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, i, n, 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 ze(e, r, i, n, 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 = v;
490
+ let S = O;
483
491
  /**
484
492
  * Register a texture with LOD information
485
493
  */
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) {
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[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);
499
+ e.source && (e.source[xe] = i);
500
+ const s = i.guid;
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
- 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);
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 = {}), 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);
508
- for (const c of z)
509
- (d = c.onRegisteredNewMesh) == null || d.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
- 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");
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) {
524
+ d(this, "url");
517
525
  /** the key to lookup the LOD information */
518
- f(this, "key");
519
- f(this, "level");
526
+ d(this, "key");
527
+ d(this, "level");
520
528
  /** For multi objects (e.g. a group of meshes) this is the index of the object */
521
- f(this, "index");
529
+ d(this, "index");
522
530
  /** 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);
531
+ d(this, "density");
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 = 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 {
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) {
530
- f(this, "context");
531
- f(this, "renderer");
532
- f(this, "projectionScreenMatrix", new ye());
533
- f(this, "cameraFrustrum", new Pe());
539
+ constructor(t, e) {
540
+ d(this, "context");
541
+ d(this, "renderer");
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
- f(this, "targetTriangleDensity", 2e5);
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
- f(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
- f(this, "pause", !1);
547
- f(this, "_lodchangedlisteners", []);
548
- f(this, "_frame", 0);
549
- f(this, "_originalRender");
557
+ d(this, "pause", !1);
558
+ d(this, "_lodchangedlisteners", []);
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
- 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());
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[ce];
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[le])
578
- return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), e[le];
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[le] = 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
- we(this.renderer), this.renderer.render = function(r, i) {
603
- t.renderer.getRenderTarget() == null && (e = 0, t._frame += 1);
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);
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, i) {
627
+ onBeforeRender(t, e, r, o) {
612
628
  }
613
- onAfterRender(e, t, r, i) {
614
- var a, d;
629
+ onAfterRender(t, e, r, o) {
630
+ var l, u;
615
631
  if (this.pause)
616
632
  return;
617
- const n = this.renderer.renderLists.get(e, 0), s = n.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 (Ue || this.updateInterval > 0 && i % 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 && (((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")) {
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 = Z("debugprogressive"), Ue = Z("noprogressive"), le = 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, i);
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 = n.transparent;
646
- for (const u of x) {
647
- const y = u.object;
648
- (y instanceof W || y.isMesh) && this.updateLODs(e, t, y, c, i);
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, i, n) {
654
- var a, d;
674
+ updateLODs(t, e, r, o, i) {
675
+ var l, u;
655
676
  r.userData || (r.userData = {});
656
- let s = r[ce];
657
- if (s || (s = new Ne(), r[ce] = 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
- (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;
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
- (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;
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 i of e)
681
- this.loadProgressiveTextures(i, 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[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 }));
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,275 +713,293 @@ const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = 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[V] !== t) {
699
- e[V] = t;
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));
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, 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;
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, i, n) {
710
- var B, I;
711
- if (!t) {
712
- n.mesh_lod = -1, n.texture_lod = -1;
713
- return;
714
- }
730
+ calculateLodLevel(t, e, r, o, i) {
731
+ var R, z;
715
732
  if (!e) {
716
- n.mesh_lod = -1, n.texture_lod = -1;
733
+ i.mesh_lod = -1, i.texture_lod = -1;
717
734
  return;
718
735
  }
719
- let o = 10 + 1, a = !1;
720
- if (N && t["DEBUG:LOD"] != null)
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;
723
- if (!x && !y) {
724
- n.mesh_lod = 0, n.texture_lod = 0;
736
+ if (!t) {
737
+ i.mesh_lod = -1, i.texture_lod = -1;
725
738
  return;
726
739
  }
727
- if (x || (a = !0, o = 0), !((B = this.cameraFrustrum) != null && B.intersectsObject(t))) {
728
- n.mesh_lod = 99, n.texture_lod = 99;
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) {
745
+ i.mesh_lod = 0, i.texture_lod = 0;
729
746
  return;
730
747
  }
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;
748
+ if (M || (l = !0, n = 0), !((R = this.cameraFrustrum) != null && R.intersectsObject(e))) {
749
+ i.mesh_lod = 99, i.texture_lod = 99;
750
+ return;
736
751
  }
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
- n.mesh_lod = 0, n.texture_lod = 0;
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)) {
748
- n.mesh_lod = 0, n.texture_lod = 0;
768
+ if (this._tempBox.copy(x), this._tempBox.applyMatrix4(e.matrixWorld), E.isInside(this._tempBox, this.projectionScreenMatrix)) {
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 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);
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 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) {
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 < i) {
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, a = !0);
802
+ b < n && (n = b, l = !0);
782
803
  }
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}`);
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 (n.texture_lod = u.max_count - 1, N) {
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}`);
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 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)}
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
  }
809
830
  }
810
831
  }
811
832
  else
812
- n.texture_lod = 0;
833
+ i.texture_lod = 0;
813
834
  }
814
835
  };
815
- let E = 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
- 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 {
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
- 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);
842
+ d(this, "frames", 0);
843
+ d(this, "lastLodLevel_Mesh", -1);
844
+ d(this, "lastLodLevel_Texture", -1);
845
+ d(this, "lastScreenCoverage", 0);
846
+ d(this, "lastScreenspaceVolume", new V());
847
+ d(this, "lastCentrality", 0);
827
848
  }
828
849
  }
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();
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);
860
+ });
861
+ });
862
+ }), se.observe(document, { childList: !0, subtree: !0 }));
863
+ }
864
+ function ot() {
865
+ const a = customElements.get("model-viewer");
866
+ return a || (customElements.whenDefined("model-viewer").then(() => {
867
+ console.debug("[gltf-progressive] model-viewer defined"), Re();
868
+ }), null);
832
869
  }
833
- function ue() {
834
- document.querySelectorAll("model-viewer").forEach((e, t) => {
835
- We(e, t);
870
+ function Ee() {
871
+ document.querySelectorAll("model-viewer").forEach((t) => {
872
+ Ge(t);
836
873
  });
837
874
  }
838
- const Me = /* @__PURE__ */ new WeakSet();
839
- function We(l, e) {
840
- if (!l || Me.has(l))
875
+ const Ce = /* @__PURE__ */ new WeakSet();
876
+ let nt = 0;
877
+ function Ge(a) {
878
+ if (!a || Ce.has(a))
841
879
  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) {
849
- let n = function() {
850
- if (i) {
851
- let o = 0, a = setInterval(() => {
852
- if (o++ > 5) {
853
- clearInterval(a);
880
+ Ce.add(a), console.debug("[gltf-progressive] found new model-viewer..." + ++nt + `
881
+ `, a.getAttribute("src"));
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]);
886
+ }
887
+ if (t && e) {
888
+ let o = function() {
889
+ if (r) {
890
+ let s = 0, n = setInterval(() => {
891
+ if (s++ > 5) {
892
+ clearInterval(n);
854
893
  return;
855
894
  }
856
- i == null || i.call(l);
895
+ r == null || r.call(a);
857
896
  }, 300);
858
897
  }
859
898
  };
860
899
  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", () => {
867
- n();
900
+ const i = I.get(t, { engine: "model-viewer" });
901
+ return I.addPlugin(new at()), i.enable(), i.addEventListener("changed", () => {
902
+ r == null || r.call(a);
903
+ }), a.addEventListener("model-visibility", (s) => {
904
+ s.detail.visible && (r == null || r.call(a));
905
+ }), a.addEventListener("load", () => {
906
+ o();
868
907
  }), () => {
869
- s.disable();
908
+ i.disable();
870
909
  };
871
910
  }
872
911
  return null;
873
912
  }
874
- class Ke {
913
+ class at {
875
914
  constructor() {
876
- f(this, "_didWarnAboutMissingUrl", !1);
915
+ d(this, "_didWarnAboutMissingUrl", !1);
877
916
  }
878
- onBeforeUpdateLOD(e, t, r, i) {
879
- this.tryParseMeshLOD(t, i), this.tryParseTextureLOD(t, i);
917
+ onBeforeUpdateLOD(t, e, r, o) {
918
+ this.tryParseMeshLOD(e, o), this.tryParseTextureLOD(e, o);
880
919
  }
881
- getUrl(e) {
882
- if (!e)
920
+ getUrl(t) {
921
+ if (!t)
883
922
  return null;
884
- let t = e.getAttribute("src");
885
- 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;
886
925
  }
887
- tryGetCurrentGLTF(e) {
888
- return e._currentGLTF;
926
+ tryGetCurrentGLTF(t) {
927
+ return t._currentGLTF;
889
928
  }
890
- tryGetCurrentModelViewer(e) {
891
- return e.element;
929
+ tryGetCurrentModelViewer(t) {
930
+ return t.element;
892
931
  }
893
- tryParseTextureLOD(e, t) {
894
- if (t[re] == !0)
932
+ tryParseTextureLOD(t, e) {
933
+ if (e[fe] == !0)
895
934
  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) {
900
- var c, x, u;
901
- if (a[re] == !0)
935
+ e[fe] = !0;
936
+ const r = this.tryGetCurrentGLTF(t), o = this.tryGetCurrentModelViewer(t), i = this.getUrl(o);
937
+ if (i && r && e.material) {
938
+ let s = function(l) {
939
+ var f, M, c;
940
+ if (l[fe] == !0)
902
941
  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];
907
- if ((L == null ? void 0 : L.isTexture) === !0) {
908
- const B = (x = (c = L.userData) == null ? void 0 : c.associations) == null ? void 0 : x.textures;
909
- 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)
910
949
  continue;
911
- const I = r.parser.json.textures[B];
912
- if (!I) {
913
- 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);
914
953
  continue;
915
954
  }
916
- if ((u = I == null ? void 0 : I.extensions) != null && u[F]) {
917
- const p = I.extensions[F];
918
- p && n && O.registerTexture(n, 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);
919
958
  }
920
959
  }
921
960
  }
922
961
  };
923
- const o = t.material;
924
- if (Array.isArray(o))
925
- for (const a of o)
926
- s(a);
962
+ const n = e.material;
963
+ if (Array.isArray(n))
964
+ for (const l of n)
965
+ s(l);
927
966
  else
928
- s(o);
967
+ s(n);
929
968
  }
930
969
  }
931
- tryParseMeshLOD(e, t) {
932
- var s, o;
933
- if (t[Le] == !0)
970
+ tryParseMeshLOD(t, e) {
971
+ var s, n;
972
+ if (e[Pe] == !0)
934
973
  return;
935
- t[Le] = !0;
936
- const r = this.tryGetCurrentModelViewer(e), i = this.getUrl(r);
937
- if (!i)
974
+ e[Pe] = !0;
975
+ const r = this.tryGetCurrentModelViewer(t), o = this.getUrl(r);
976
+ if (!o)
938
977
  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);
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);
943
982
  }
944
983
  }
945
984
  }
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;
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;
951
989
  }
990
+ Re();
952
991
  export {
953
- F as EXTENSION_NAME,
954
- E as LODsManager,
955
- O as NEEDLE_progressive,
956
- De as VERSION,
957
- _e as addDracoAndKTX2Loaders,
958
- we as createLoaders,
959
- 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
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
966
1005
  };