@needle-tools/gltf-progressive 3.1.0-next.f550970 → 3.1.1-next.26e0b81

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,249 +1,406 @@
1
- var He = Object.defineProperty;
2
- var Qe = (o, t, e) => t in o ? He(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
3
- var u = (o, t, e) => (Qe(o, typeof t != "symbol" ? t + "" : t, e), e), Ee = (o, t, e) => {
4
- if (!t.has(o))
5
- throw TypeError("Cannot " + e);
1
+ var tt = Object.defineProperty;
2
+ var st = (o, e, t) => e in o ? tt(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
+ var d = (o, e, t) => (st(o, typeof e != "symbol" ? e + "" : e, t), t), Ee = (o, e, t) => {
4
+ if (!e.has(o))
5
+ throw TypeError("Cannot " + t);
6
6
  };
7
- var L = (o, t, e) => (Ee(o, t, "read from private field"), e ? e.call(o) : t.get(o)), H = (o, t, e) => {
8
- if (t.has(o))
7
+ var D = (o, e, t) => (Ee(o, e, "read from private field"), t ? t.call(o) : e.get(o)), Q = (o, e, t) => {
8
+ if (e.has(o))
9
9
  throw TypeError("Cannot add the same private member more than once");
10
- t instanceof WeakSet ? t.add(o) : t.set(o, e);
11
- }, V = (o, t, e, s) => (Ee(o, t, "write to private field"), s ? s.call(o, e) : t.set(o, e), e);
12
- import { BufferGeometry as Le, Mesh as se, Texture as oe, TextureLoader as je, Matrix4 as Ie, Clock as Je, MeshStandardMaterial as Ze, Sphere as et, Box3 as $e, Vector3 as W } from "three";
13
- import { GLTFLoader as Ce } from "three/examples/jsm/loaders/GLTFLoader.js";
14
- import { MeshoptDecoder as tt } from "three/examples/jsm/libs/meshopt_decoder.module.js";
15
- import { DRACOLoader as st } from "three/examples/jsm/loaders/DRACOLoader.js";
16
- import { KTX2Loader as rt } from "three/examples/jsm/loaders/KTX2Loader.js";
17
- const it = "";
18
- globalThis.GLTF_PROGRESSIVE_VERSION = it;
10
+ e instanceof WeakSet ? e.add(o) : e.set(o, t);
11
+ }, K = (o, e, t, s) => (Ee(o, e, "write to private field"), s ? s.call(o, t) : e.set(o, t), t);
12
+ import { BufferGeometry as he, Mesh as ne, Box3 as Ce, Vector3 as W, Sphere as qe, CompressedTexture as rt, Texture as se, Matrix3 as nt, InterleavedBuffer as it, InterleavedBufferAttribute as ot, BufferAttribute as at, TextureLoader as lt, Matrix4 as Fe, Clock as ut, MeshStandardMaterial as dt } from "three";
13
+ import { GLTFLoader as Re } from "three/examples/jsm/loaders/GLTFLoader.js";
14
+ import { MeshoptDecoder as ct } from "three/examples/jsm/libs/meshopt_decoder.module.js";
15
+ import { DRACOLoader as ft } from "three/examples/jsm/loaders/DRACOLoader.js";
16
+ import { KTX2Loader as ht } from "three/examples/jsm/loaders/KTX2Loader.js";
17
+ const gt = "";
18
+ globalThis.GLTF_PROGRESSIVE_VERSION = gt;
19
19
  console.debug("[gltf-progressive] version -");
20
- let q = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", re = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
21
- const nt = q, ot = re, Fe = new URL(q + "draco_decoder.js");
22
- Fe.searchParams.append("range", "true");
23
- fetch(Fe, {
20
+ let q = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", ie = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
21
+ const pt = q, mt = ie, Ve = new URL(q + "draco_decoder.js");
22
+ Ve.searchParams.append("range", "true");
23
+ fetch(Ve, {
24
24
  method: "GET",
25
25
  headers: {
26
26
  Range: "bytes=0-1"
27
27
  }
28
28
  }).catch((o) => {
29
- console.debug(`Failed to fetch remote Draco decoder from ${q} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), q === nt && at("./include/draco/"), re === ot && lt("./include/ktx2/");
29
+ console.debug(`Failed to fetch remote Draco decoder from ${q} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), q === pt && xt("./include/draco/"), ie === mt && wt("./include/ktx2/");
30
30
  }).finally(() => {
31
- Ne();
31
+ Ke();
32
32
  });
33
- function at(o) {
34
- q = o, k && k[Pe] != q ? (console.debug("Updating Draco decoder path to " + o), k[Pe] = q, k.setDecoderPath(q), k.preload()) : console.debug("Setting Draco decoder path to " + o);
33
+ const yt = () => ({
34
+ dracoDecoderPath: q,
35
+ ktx2TranscoderPath: ie
36
+ });
37
+ function xt(o) {
38
+ q = o, N && N[ke] != q ? (console.debug("Updating Draco decoder path to " + o), N[ke] = q, N.setDecoderPath(q), N.preload()) : console.debug("Setting Draco decoder path to " + o);
35
39
  }
36
- function lt(o) {
37
- re = o, N && N.transcoderPath != re ? (console.debug("Updating KTX2 transcoder path to " + o), N.setTranscoderPath(re), N.init()) : console.debug("Setting KTX2 transcoder path to " + o);
40
+ function wt(o) {
41
+ ie = o, V && V.transcoderPath != ie ? (console.debug("Updating KTX2 transcoder path to " + o), V.setTranscoderPath(ie), V.init()) : console.debug("Setting KTX2 transcoder path to " + o);
38
42
  }
39
- const Pe = Symbol("dracoDecoderPath");
40
- let k, xe, N;
41
- function Ne() {
42
- k || (k = new st(), k[Pe] = q, k.setDecoderPath(q), k.setDecoderConfig({ type: "js" }), k.preload()), N || (N = new rt(), N.setTranscoderPath(re), N.init()), xe || (xe = tt);
43
+ function $e(o) {
44
+ return Ke(), o ? V.detectSupport(o) : o !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: N, ktx2Loader: V, meshoptDecoder: _e };
43
45
  }
44
- function Ue(o) {
45
- return Ne(), o ? N.detectSupport(o) : o !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: k, ktx2Loader: N, meshoptDecoder: xe };
46
+ function Xe(o) {
47
+ o.dracoLoader || o.setDRACOLoader(N), o.ktx2Loader || o.setKTX2Loader(V), o.meshoptDecoder || o.setMeshoptDecoder(_e);
46
48
  }
47
- function ze(o) {
48
- o.dracoLoader || o.setDRACOLoader(k), o.ktx2Loader || o.setKTX2Loader(N), o.meshoptDecoder || o.setMeshoptDecoder(xe);
49
+ const ke = Symbol("dracoDecoderPath");
50
+ let N, _e, V;
51
+ function Ke() {
52
+ N || (N = new ft(), N[ke] = q, N.setDecoderPath(q), N.setDecoderConfig({ type: "js" }), N.preload()), V || (V = new ht(), V.setTranscoderPath(ie), V.init()), _e || (_e = ct);
49
53
  }
50
- const Te = /* @__PURE__ */ new WeakMap();
51
- function Ve(o, t) {
52
- let e = Te.get(o);
53
- e ? e = Object.assign(e, t) : e = t, Te.set(o, e);
54
+ const Ie = /* @__PURE__ */ new WeakMap();
55
+ function Ye(o, e) {
56
+ let t = Ie.get(o);
57
+ t ? t = Object.assign(t, e) : t = e, Ie.set(o, t);
54
58
  }
55
- const Me = Ce.prototype.load;
56
- function ut(...o) {
57
- const t = Te.get(this);
58
- let e = o[0];
59
- const s = new URL(e, window.location.href);
59
+ const Oe = Re.prototype.load;
60
+ function Lt(...o) {
61
+ const e = Ie.get(this);
62
+ let t = o[0];
63
+ const s = new URL(t, window.location.href);
60
64
  if (s.hostname.endsWith("needle.tools")) {
61
- const r = (t == null ? void 0 : t.progressive) !== void 0 ? t.progressive : !0, i = t != null && t.usecase ? t.usecase : "default";
62
- r ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${i}` : this.requestHeader.Accept = `*/*;usecase=${i}`, e = s.toString();
65
+ const r = (e == null ? void 0 : e.progressive) !== void 0 ? e.progressive : !0, n = e != null && e.usecase ? e.usecase : "default";
66
+ r ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${n}` : this.requestHeader.Accept = `*/*;usecase=${n}`, t = s.toString();
63
67
  }
64
- return o[0] = e, Me == null ? void 0 : Me.call(this, ...o);
68
+ return o[0] = t, Oe == null ? void 0 : Oe.call(this, ...o);
65
69
  }
66
- Ce.prototype.load = ut;
67
- de("debugprogressive");
68
- function de(o) {
70
+ Re.prototype.load = Lt;
71
+ oe("debugprogressive");
72
+ function oe(o) {
69
73
  if (typeof window > "u")
70
74
  return !1;
71
- const e = new URL(window.location.href).searchParams.get(o);
72
- return e == null || e === "0" || e === "false" ? !1 : e === "" ? !0 : e;
75
+ const t = new URL(window.location.href).searchParams.get(o);
76
+ return t == null || t === "0" || t === "false" ? !1 : t === "" ? !0 : t;
73
77
  }
74
- function dt(o, t) {
75
- if (t === void 0 || t.startsWith("./") || t.startsWith("http") || o === void 0)
76
- return t;
77
- const e = o.lastIndexOf("/");
78
- if (e >= 0) {
79
- const s = o.substring(0, e + 1);
80
- for (; s.endsWith("/") && t.startsWith("/"); )
81
- t = t.substring(1);
82
- return s + t;
83
- }
84
- return t;
78
+ function _t(o, e) {
79
+ if (e === void 0 || e.startsWith("./") || e.startsWith("http") || o === void 0)
80
+ return e;
81
+ const t = o.lastIndexOf("/");
82
+ if (t >= 0) {
83
+ const s = o.substring(0, t + 1);
84
+ for (; s.endsWith("/") && e.startsWith("/"); )
85
+ e = e.substring(1);
86
+ return s + e;
87
+ }
88
+ return e;
85
89
  }
86
- let ae;
87
- function ct() {
88
- return ae !== void 0 || (ae = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), de("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", ae)), ae;
90
+ let ue;
91
+ function je() {
92
+ return ue !== void 0 || (ue = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), oe("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", ue)), ue;
89
93
  }
90
- function Ge() {
94
+ function Ne() {
91
95
  if (typeof window > "u")
92
96
  return !1;
93
- const o = new URL(window.location.href), t = o.hostname === "localhost" || /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(o.hostname);
94
- return o.hostname === "127.0.0.1" || t;
97
+ const o = new URL(window.location.href), e = o.hostname === "localhost" || /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(o.hostname);
98
+ return o.hostname === "127.0.0.1" || e;
95
99
  }
96
- class ft {
97
- constructor(t = 100, e = {}) {
98
- u(this, "_running", /* @__PURE__ */ new Map());
99
- u(this, "_queue", []);
100
- u(this, "debug", !1);
101
- u(this, "tick", () => {
100
+ class Mt {
101
+ constructor(e = 100, t = {}) {
102
+ d(this, "_running", /* @__PURE__ */ new Map());
103
+ d(this, "_queue", []);
104
+ d(this, "debug", !1);
105
+ d(this, "tick", () => {
102
106
  this.internalUpdate(), setTimeout(this.tick, 10);
103
107
  });
104
- this.maxConcurrent = t, this.debug = e.debug ?? !1, window.requestAnimationFrame(this.tick);
108
+ this.maxConcurrent = e, this.debug = t.debug ?? !1, window.requestAnimationFrame(this.tick);
105
109
  }
106
110
  /**
107
111
  * Request a slot for a promise with a specific key. This function returns a promise with a `use` method that can be called to add the promise to the queue.
108
112
  */
109
- slot(t) {
110
- return this.debug && console.debug(`[PromiseQueue]: Requesting slot for key ${t}, running: ${this._running.size}, waiting: ${this._queue.length}`), new Promise((e) => {
111
- this._queue.push({ key: t, resolve: e });
113
+ slot(e) {
114
+ return this.debug && console.debug(`[PromiseQueue]: Requesting slot for key ${e}, running: ${this._running.size}, waiting: ${this._queue.length}`), new Promise((t) => {
115
+ this._queue.push({ key: e, resolve: t });
112
116
  });
113
117
  }
114
- add(t, e) {
115
- this._running.has(t) || (this._running.set(t, e), e.finally(() => {
116
- this._running.delete(t), this.debug && console.debug(`[PromiseQueue]: Promise finished now running: ${this._running.size}, waiting: ${this._queue.length}. (finished ${t})`);
117
- }), this.debug && console.debug(`[PromiseQueue]: Added new promise, now running: ${this._running.size}, waiting: ${this._queue.length}. (added ${t})`));
118
+ add(e, t) {
119
+ this._running.has(e) || (this._running.set(e, t), t.finally(() => {
120
+ this._running.delete(e), this.debug && console.debug(`[PromiseQueue]: Promise finished now running: ${this._running.size}, waiting: ${this._queue.length}. (finished ${e})`);
121
+ }), this.debug && console.debug(`[PromiseQueue]: Added new promise, now running: ${this._running.size}, waiting: ${this._queue.length}. (added ${e})`));
118
122
  }
119
123
  internalUpdate() {
120
- const t = this.maxConcurrent - this._running.size;
121
- for (let e = 0; e < t && this._queue.length > 0; e++) {
124
+ const e = this.maxConcurrent - this._running.size;
125
+ for (let t = 0; t < e && this._queue.length > 0; t++) {
122
126
  this.debug && console.debug(`[PromiseQueue]: Running ${this._running.size} promises, waiting for ${this._queue.length} more.`);
123
- const { key: s, resolve: n } = this._queue.shift();
124
- n({
127
+ const { key: s, resolve: i } = this._queue.shift();
128
+ i({
125
129
  use: (r) => this.add(s, r)
126
130
  });
127
131
  }
128
132
  }
129
133
  }
130
- const ht = typeof window > "u" && typeof document > "u", Ae = Symbol("needle:raycast-mesh");
131
- function ce(o) {
132
- return (o == null ? void 0 : o[Ae]) instanceof Le ? o[Ae] : null;
134
+ const vt = typeof window > "u" && typeof document > "u", Be = Symbol("needle:raycast-mesh");
135
+ function ge(o) {
136
+ return (o == null ? void 0 : o[Be]) instanceof he ? o[Be] : null;
133
137
  }
134
- function gt(o, t) {
135
- if ((o.type === "Mesh" || o.type === "SkinnedMesh") && !ce(o)) {
136
- const s = mt(t);
137
- s.userData = { isRaycastMesh: !0 }, o[Ae] = s;
138
+ function Dt(o, e) {
139
+ if ((o.type === "Mesh" || o.type === "SkinnedMesh") && !ge(o)) {
140
+ const s = Ot(e);
141
+ s.userData = { isRaycastMesh: !0 }, o[Be] = s;
138
142
  }
139
143
  }
140
- function pt(o = !0) {
144
+ function bt(o = !0) {
141
145
  if (o) {
142
- if (le)
146
+ if (de)
143
147
  return;
144
- const t = le = se.prototype.raycast;
145
- se.prototype.raycast = function(e, s) {
146
- const n = this, r = ce(n);
147
- let i;
148
- r && n.isMesh && (i = n.geometry, n.geometry = r), t.call(this, e, s), i && (n.geometry = i);
148
+ const e = de = ne.prototype.raycast;
149
+ ne.prototype.raycast = function(t, s) {
150
+ const i = this, r = ge(i);
151
+ let n;
152
+ r && i.isMesh && (n = i.geometry, i.geometry = r), e.call(this, t, s), n && (i.geometry = n);
149
153
  };
150
154
  } else {
151
- if (!le)
155
+ if (!de)
152
156
  return;
153
- se.prototype.raycast = le, le = null;
157
+ ne.prototype.raycast = de, de = null;
154
158
  }
155
159
  }
156
- let le = null;
157
- function mt(o) {
158
- const t = new Le();
159
- for (const e in o.attributes)
160
- t.setAttribute(e, o.getAttribute(e));
161
- return t.setIndex(o.getIndex()), t;
160
+ let de = null;
161
+ function Ot(o) {
162
+ const e = new he();
163
+ for (const t in o.attributes)
164
+ e.setAttribute(t, o.getAttribute(t));
165
+ return e.setIndex(o.getIndex()), e;
162
166
  }
163
- const j = new Array(), y = de("debugprogressive");
164
- let me, te = -1;
165
- if (y) {
167
+ const Z = new Array(), x = oe("debugprogressive");
168
+ let we, re = -1;
169
+ if (x) {
166
170
  let o = function() {
167
- te += 1, te >= t && (te = -1), console.log(`Toggle LOD level [${te}]`);
168
- }, t = 6;
169
- window.addEventListener("keyup", (e) => {
170
- e.key === "p" && o(), e.key === "w" && (me = !me, console.log(`Toggle wireframe [${me}]`));
171
- const s = parseInt(e.key);
172
- !isNaN(s) && s >= 0 && (te = s, console.log(`Set LOD level to [${te}]`));
171
+ re += 1, re >= e && (re = -1), console.log(`Toggle LOD level [${re}]`);
172
+ }, e = 6;
173
+ window.addEventListener("keyup", (t) => {
174
+ t.key === "p" && o(), t.key === "w" && (we = !we, console.log(`Toggle wireframe [${we}]`));
175
+ const s = parseInt(t.key);
176
+ !isNaN(s) && s >= 0 && (re = s, console.log(`Set LOD level to [${re}]`));
173
177
  });
174
178
  }
175
- function qe(o) {
176
- if (y)
179
+ function He(o) {
180
+ if (x)
177
181
  if (Array.isArray(o))
178
- for (const t of o)
179
- qe(t);
182
+ for (const e of o)
183
+ He(e);
180
184
  else
181
- o && "wireframe" in o && (o.wireframe = me === !0);
185
+ o && "wireframe" in o && (o.wireframe = we === !0);
182
186
  }
183
- const X = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), O = class {
184
- constructor(t, e) {
185
- u(this, "parser");
186
- u(this, "url");
187
- u(this, "_isLoadingMesh");
188
- u(this, "loadMesh", (t) => {
189
- var s, n;
187
+ const ce = new Array();
188
+ let St = 0;
189
+ const Pt = je() ? 2 : 10;
190
+ function Tt(o) {
191
+ if (ce.length < Pt) {
192
+ const s = ce.length;
193
+ x && console.warn(`[Worker] Creating new worker #${s}`);
194
+ const i = Ge.createWorker(o || {});
195
+ return ce.push(i), i;
196
+ }
197
+ const e = St++ % ce.length;
198
+ return ce[e];
199
+ }
200
+ class Ge {
201
+ constructor(e, t) {
202
+ d(this, "_running", []);
203
+ d(this, "_webglRenderer", null);
204
+ d(this, "_debug", !1);
205
+ this.worker = e, this._debug = t.debug ?? !1, e.onmessage = (s) => {
206
+ const i = s.data;
207
+ switch (this._debug && console.log("[Worker] EVENT", i), i.type) {
208
+ case "loaded-gltf":
209
+ for (const r of this._running)
210
+ if (r.url === i.result.url) {
211
+ At(i.result), r.resolve(i.result);
212
+ const n = r.url;
213
+ n.startsWith("blob:") && URL.revokeObjectURL(n);
214
+ }
215
+ }
216
+ }, e.onerror = (s) => {
217
+ console.error("[Worker] Error in gltf-progressive worker:", s);
218
+ }, e.postMessage({
219
+ type: "init"
220
+ });
221
+ }
222
+ static async createWorker(e) {
223
+ const t = new Worker(new URL("/assets/loader.worker-c528e7f2.js", self.location), {
224
+ type: "module"
225
+ });
226
+ return new Ge(t, e);
227
+ }
228
+ async load(e, t) {
229
+ const s = yt();
230
+ let i = t == null ? void 0 : t.renderer;
231
+ i || (this._webglRenderer ?? (this._webglRenderer = (async () => {
232
+ const { WebGLRenderer: u } = await import("three");
233
+ return new u();
234
+ })()), i = await this._webglRenderer);
235
+ const a = $e(i).ktx2Loader.workerConfig;
236
+ e instanceof URL ? e = e.toString() : e.startsWith("file:") ? e = URL.createObjectURL(new Blob([e])) : !e.startsWith("blob:") && !e.startsWith("http:") && !e.startsWith("https:") && (e = new URL(e, window.location.href).toString());
237
+ const l = {
238
+ type: "load",
239
+ url: e,
240
+ dracoDecoderPath: s.dracoDecoderPath,
241
+ ktx2TranscoderPath: s.ktx2TranscoderPath,
242
+ ktx2LoaderConfig: a
243
+ };
244
+ return this._debug && console.debug("[Worker] Sending load request", l), this.worker.postMessage(l), new Promise((u) => {
245
+ this._running.push({
246
+ url: e.toString(),
247
+ resolve: u
248
+ });
249
+ });
250
+ }
251
+ }
252
+ function At(o) {
253
+ var e, t, s, i, r, n, a, l, u, f, m, _, w, O, M, B;
254
+ for (const b of o.geometries) {
255
+ const c = b.geometry, v = new he();
256
+ if (v.name = c.name || "", c.index) {
257
+ const h = c.index;
258
+ v.setIndex(Se(h));
259
+ }
260
+ for (const h in c.attributes) {
261
+ const L = c.attributes[h], T = Se(L);
262
+ v.setAttribute(h, T);
263
+ }
264
+ if (c.morphAttributes)
265
+ for (const h in c.morphAttributes) {
266
+ const T = c.morphAttributes[h].map((U) => Se(U));
267
+ v.morphAttributes[h] = T;
268
+ }
269
+ if (v.morphTargetsRelative = c.morphTargetsRelative ?? !1, v.boundingBox = new Ce(), v.boundingBox.min = new W(
270
+ (e = c.boundingBox) == null ? void 0 : e.min.x,
271
+ (t = c.boundingBox) == null ? void 0 : t.min.y,
272
+ (s = c.boundingBox) == null ? void 0 : s.min.z
273
+ ), v.boundingBox.max = new W(
274
+ (i = c.boundingBox) == null ? void 0 : i.max.x,
275
+ (r = c.boundingBox) == null ? void 0 : r.max.y,
276
+ (n = c.boundingBox) == null ? void 0 : n.max.z
277
+ ), v.boundingSphere = new qe(
278
+ new W(
279
+ (a = c.boundingSphere) == null ? void 0 : a.center.x,
280
+ (l = c.boundingSphere) == null ? void 0 : l.center.y,
281
+ (u = c.boundingSphere) == null ? void 0 : u.center.z
282
+ ),
283
+ (f = c.boundingSphere) == null ? void 0 : f.radius
284
+ ), c.groups)
285
+ for (const h of c.groups)
286
+ v.addGroup(h.start, h.count, h.materialIndex);
287
+ c.userData && (v.userData = c.userData), b.geometry = v;
288
+ }
289
+ for (const b of o.textures) {
290
+ const c = b.texture;
291
+ let v = null;
292
+ if (c.isCompressedTexture) {
293
+ const h = c.mipmaps, L = ((m = c.image) == null ? void 0 : m.width) || ((w = (_ = c.source) == null ? void 0 : _.data) == null ? void 0 : w.width) || -1, T = ((O = c.image) == null ? void 0 : O.height) || ((B = (M = c.source) == null ? void 0 : M.data) == null ? void 0 : B.height) || -1;
294
+ v = new rt(
295
+ h,
296
+ L,
297
+ T,
298
+ c.format,
299
+ c.type,
300
+ c.mapping,
301
+ c.wrapS,
302
+ c.wrapT,
303
+ c.magFilter,
304
+ c.minFilter,
305
+ c.anisotropy,
306
+ c.colorSpace
307
+ );
308
+ } else
309
+ v = new se(
310
+ c.image,
311
+ c.mapping,
312
+ c.wrapS,
313
+ c.wrapT,
314
+ c.magFilter,
315
+ c.minFilter,
316
+ c.format,
317
+ c.type,
318
+ c.anisotropy,
319
+ c.colorSpace
320
+ ), v.mipmaps = c.mipmaps, v.channel = c.channel, v.source.data = c.source.data, v.flipY = c.flipY, v.premultiplyAlpha = c.premultiplyAlpha, v.unpackAlignment = c.unpackAlignment, v.matrix = new nt(...c.matrix.elements);
321
+ if (!v) {
322
+ console.error("[Worker] Failed to create new texture from received data. Texture is not a CompressedTexture or Texture.");
323
+ continue;
324
+ }
325
+ b.texture = v;
326
+ }
327
+ return o;
328
+ }
329
+ function Se(o) {
330
+ let e = o;
331
+ if ("isInterleavedBufferAttribute" in o && o.isInterleavedBufferAttribute) {
332
+ const t = o.data, s = t.array, i = new it(s, t.stride);
333
+ e = new ot(i, o.itemSize, s.byteOffset, o.normalized), e.offset = o.offset;
334
+ } else
335
+ "isBufferAttribute" in o && o.isBufferAttribute && (e = new at(o.array, o.itemSize, o.normalized), e.usage = o.usage, e.gpuType = o.gpuType, e.updateRanges = o.updateRanges);
336
+ return e;
337
+ }
338
+ const Ct = oe("gltf-progressive-worker"), kt = oe("gltf-progressive-reduce-mipmaps"), Pe = Symbol("needle-progressive-texture"), Y = "NEEDLE_progressive", P = class {
339
+ constructor(e, t) {
340
+ d(this, "parser");
341
+ d(this, "url");
342
+ d(this, "_isLoadingMesh");
343
+ d(this, "loadMesh", (e) => {
344
+ var s, i;
190
345
  if (this._isLoadingMesh)
191
346
  return null;
192
- const e = (n = (s = this.parser.json.meshes[t]) == null ? void 0 : s.extensions) == null ? void 0 : n[X];
193
- return e ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", t).then((r) => {
194
- var i;
195
- return this._isLoadingMesh = !1, r && O.registerMesh(this.url, e.guid, r, (i = e.lods) == null ? void 0 : i.length, 0, e), r;
347
+ const t = (i = (s = this.parser.json.meshes[e]) == null ? void 0 : s.extensions) == null ? void 0 : i[Y];
348
+ return t ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", e).then((r) => {
349
+ var n;
350
+ return this._isLoadingMesh = !1, r && P.registerMesh(this.url, t.guid, r, (n = t.lods) == null ? void 0 : n.length, 0, t), r;
196
351
  })) : null;
197
352
  });
198
- y && console.log("Progressive extension registered for", e), this.parser = t, this.url = e;
353
+ x && console.log("Progressive extension registered for", t), this.parser = e, this.url = t;
199
354
  }
200
355
  /** The name of the extension */
201
356
  get name() {
202
- return X;
357
+ return Y;
203
358
  }
204
- static getMeshLODExtension(t) {
205
- const e = this.getAssignedLODInformation(t);
206
- return e != null && e.key ? this.lodInfos.get(e.key) : null;
359
+ static getMeshLODExtension(e) {
360
+ const t = this.getAssignedLODInformation(e);
361
+ return t != null && t.key ? this.lodInfos.get(t.key) : null;
207
362
  }
208
- static getPrimitiveIndex(t) {
363
+ static getPrimitiveIndex(e) {
209
364
  var s;
210
- const e = (s = this.getAssignedLODInformation(t)) == null ? void 0 : s.index;
211
- return e ?? -1;
365
+ const t = (s = this.getAssignedLODInformation(e)) == null ? void 0 : s.index;
366
+ return t ?? -1;
212
367
  }
213
- static getMaterialMinMaxLODsCount(t, e) {
214
- const s = this, n = "LODS:minmax", r = t[n];
368
+ static getMaterialMinMaxLODsCount(e, t) {
369
+ const s = this, i = "LODS:minmax", r = e[i];
215
370
  if (r != null)
216
371
  return r;
217
- if (e || (e = {
372
+ if (t || (t = {
218
373
  min_count: 1 / 0,
219
374
  max_count: 0,
220
375
  lods: []
221
- }), Array.isArray(t)) {
222
- for (const a of t)
223
- this.getMaterialMinMaxLODsCount(a, e);
224
- return t[n] = e, e;
376
+ }), Array.isArray(e)) {
377
+ for (const a of e)
378
+ this.getMaterialMinMaxLODsCount(a, t);
379
+ return e[i] = t, t;
225
380
  }
226
- if (y === "verbose" && console.log("getMaterialMinMaxLODsCount", t), t.type === "ShaderMaterial" || t.type === "RawShaderMaterial") {
227
- const a = t;
381
+ if (x === "verbose" && console.log("getMaterialMinMaxLODsCount", e), e.type === "ShaderMaterial" || e.type === "RawShaderMaterial") {
382
+ const a = e;
228
383
  for (const l of Object.keys(a.uniforms)) {
229
- const c = a.uniforms[l].value;
230
- (c == null ? void 0 : c.isTexture) === !0 && i(c, e);
384
+ const u = a.uniforms[l].value;
385
+ (u == null ? void 0 : u.isTexture) === !0 && n(u, t);
231
386
  }
232
- } else if (t.isMaterial)
233
- for (const a of Object.keys(t)) {
234
- const l = t[a];
235
- (l == null ? void 0 : l.isTexture) === !0 && i(l, e);
387
+ } else if (e.isMaterial)
388
+ for (const a of Object.keys(e)) {
389
+ const l = e[a];
390
+ (l == null ? void 0 : l.isTexture) === !0 && n(l, t);
236
391
  }
237
- return t[n] = e, e;
238
- function i(a, l) {
239
- const c = s.getAssignedLODInformation(a);
240
- if (c) {
241
- const d = s.lodInfos.get(c.key);
242
- if (d && d.lods) {
243
- l.min_count = Math.min(l.min_count, d.lods.length), l.max_count = Math.max(l.max_count, d.lods.length);
244
- for (let h = 0; h < d.lods.length; h++) {
245
- const f = d.lods[h];
246
- f.width && (l.lods[h] = l.lods[h] || { min_height: 1 / 0, max_height: 0 }, l.lods[h].min_height = Math.min(l.lods[h].min_height, f.height), l.lods[h].max_height = Math.max(l.lods[h].max_height, f.height));
392
+ else
393
+ x && console.warn(`[getMaterialMinMaxLODsCount] Unsupported material type: ${e.type}`);
394
+ return e[i] = t, t;
395
+ function n(a, l) {
396
+ const u = s.getAssignedLODInformation(a);
397
+ if (u) {
398
+ const f = s.lodInfos.get(u.key);
399
+ if (f && f.lods) {
400
+ l.min_count = Math.min(l.min_count, f.lods.length), l.max_count = Math.max(l.max_count, f.lods.length);
401
+ for (let m = 0; m < f.lods.length; m++) {
402
+ const _ = f.lods[m];
403
+ _.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, _.height), l.lods[m].max_height = Math.max(l.lods[m].max_height, _.height));
247
404
  }
248
405
  }
249
406
  }
@@ -254,33 +411,33 @@ const X = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), O = c
254
411
  * @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
255
412
  * @returns true if the LOD level is available (or if any LOD level is available if level is undefined)
256
413
  */
257
- static hasLODLevelAvailable(t, e) {
414
+ static hasLODLevelAvailable(e, t) {
258
415
  var r;
259
- if (Array.isArray(t)) {
260
- for (const i of t)
261
- if (this.hasLODLevelAvailable(i, e))
416
+ if (Array.isArray(e)) {
417
+ for (const n of e)
418
+ if (this.hasLODLevelAvailable(n, t))
262
419
  return !0;
263
420
  return !1;
264
421
  }
265
- if (t.isMaterial === !0) {
266
- for (const i of Object.keys(t)) {
267
- const a = t[i];
268
- if (a && a.isTexture && this.hasLODLevelAvailable(a, e))
422
+ if (e.isMaterial === !0) {
423
+ for (const n of Object.keys(e)) {
424
+ const a = e[n];
425
+ if (a && a.isTexture && this.hasLODLevelAvailable(a, t))
269
426
  return !0;
270
427
  }
271
428
  return !1;
272
- } else if (t.isGroup === !0) {
273
- for (const i of t.children)
274
- if (i.isMesh === !0 && this.hasLODLevelAvailable(i, e))
429
+ } else if (e.isGroup === !0) {
430
+ for (const n of e.children)
431
+ if (n.isMesh === !0 && this.hasLODLevelAvailable(n, t))
275
432
  return !0;
276
433
  }
277
- let s, n;
278
- if (t.isMesh ? s = t.geometry : (t.isBufferGeometry || t.isTexture) && (s = t), s && (r = s == null ? void 0 : s.userData) != null && r.LODS) {
279
- const i = s.userData.LODS;
280
- if (n = this.lodInfos.get(i.key), e === void 0)
281
- return n != null;
282
- if (n)
283
- return Array.isArray(n.lods) ? e < n.lods.length : e === 0;
434
+ let s, i;
435
+ if (e.isMesh ? s = e.geometry : (e.isBufferGeometry || e.isTexture) && (s = e), s && (r = s == null ? void 0 : s.userData) != null && r.LODS) {
436
+ const n = s.userData.LODS;
437
+ if (i = this.lodInfos.get(n.key), t === void 0)
438
+ return i != null;
439
+ if (i)
440
+ return Array.isArray(i.lods) ? t < i.lods.length : t === 0;
284
441
  }
285
442
  return !1;
286
443
  }
@@ -298,100 +455,105 @@ const X = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), O = c
298
455
  * });
299
456
  * ```
300
457
  */
301
- static assignMeshLOD(t, e) {
458
+ static assignMeshLOD(e, t) {
302
459
  var s;
303
- if (!t)
460
+ if (!e)
304
461
  return Promise.resolve(null);
305
- if (t instanceof se || t.isMesh === !0) {
306
- const n = t.geometry, r = this.getAssignedLODInformation(n);
462
+ if (e instanceof ne || e.isMesh === !0) {
463
+ const i = e.geometry, r = this.getAssignedLODInformation(i);
307
464
  if (!r)
308
465
  return Promise.resolve(null);
309
- for (const i of j)
310
- (s = i.onBeforeGetLODMesh) == null || s.call(i, t, e);
311
- return t["LOD:requested level"] = e, O.getOrLoadLOD(n, e).then((i) => {
312
- if (Array.isArray(i)) {
466
+ for (const n of Z)
467
+ (s = n.onBeforeGetLODMesh) == null || s.call(n, e, t);
468
+ return e["LOD:requested level"] = t, P.getOrLoadLOD(i, t).then((n) => {
469
+ if (Array.isArray(n)) {
313
470
  const a = r.index || 0;
314
- i = i[a];
471
+ n = n[a];
315
472
  }
316
- return t["LOD:requested level"] === e && (delete t["LOD:requested level"], i && n != i && ((i == null ? void 0 : i.isBufferGeometry) ? t.geometry = i : y && console.error("Invalid LOD geometry", i))), i;
317
- }).catch((i) => (console.error("Error loading mesh LOD", t, i), null));
473
+ return e["LOD:requested level"] === t && (delete e["LOD:requested level"], n && i != n && ((n == null ? void 0 : n.isBufferGeometry) ? e.geometry = n : x && console.error("Invalid LOD geometry", n))), n;
474
+ }).catch((n) => (console.error("Error loading mesh LOD", e, n), null));
318
475
  } else
319
- y && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", t);
476
+ x && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", e);
320
477
  return Promise.resolve(null);
321
478
  }
322
- static assignTextureLOD(t, e = 0) {
323
- if (!t)
479
+ static assignTextureLOD(e, t = 0) {
480
+ if (!e)
324
481
  return Promise.resolve(null);
325
- if (t.isMesh === !0) {
326
- const s = t;
482
+ if (e.isMesh === !0) {
483
+ const s = e;
327
484
  if (Array.isArray(s.material)) {
328
- const n = new Array();
485
+ const i = new Array();
329
486
  for (const r of s.material) {
330
- const i = this.assignTextureLOD(r, e);
331
- n.push(i);
487
+ const n = this.assignTextureLOD(r, t);
488
+ i.push(n);
332
489
  }
333
- return Promise.all(n).then((r) => {
334
- const i = new Array();
490
+ return Promise.all(i).then((r) => {
491
+ const n = new Array();
335
492
  for (const a of r)
336
- Array.isArray(a) && i.push(...a);
337
- return i;
493
+ Array.isArray(a) && n.push(...a);
494
+ return n;
338
495
  });
339
496
  } else
340
- return this.assignTextureLOD(s.material, e);
497
+ return this.assignTextureLOD(s.material, t);
341
498
  }
342
- if (t.isMaterial === !0) {
343
- const s = t, n = [], r = new Array();
499
+ if (e.isMaterial === !0) {
500
+ const s = e, i = [], r = new Array();
344
501
  if (s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
345
- const i = s;
346
- for (const a of Object.keys(i.uniforms)) {
347
- const l = i.uniforms[a].value;
502
+ const n = s;
503
+ for (const a of Object.keys(n.uniforms)) {
504
+ const l = n.uniforms[a].value;
348
505
  if ((l == null ? void 0 : l.isTexture) === !0) {
349
- const c = this.assignTextureLODForSlot(l, e, s, a).then((d) => (d && i.uniforms[a].value != d && (i.uniforms[a].value = d, i.uniformsNeedUpdate = !0), d));
350
- n.push(c), r.push(a);
506
+ const u = this.assignTextureLODForSlot(l, t, s, a).then((f) => (f && n.uniforms[a].value != f && (n.uniforms[a].value = f, n.uniformsNeedUpdate = !0), f));
507
+ i.push(u), r.push(a);
351
508
  }
352
509
  }
353
510
  } else
354
- for (const i of Object.keys(s)) {
355
- const a = s[i];
511
+ for (const n of Object.keys(s)) {
512
+ const a = s[n];
356
513
  if ((a == null ? void 0 : a.isTexture) === !0) {
357
- const l = this.assignTextureLODForSlot(a, e, s, i);
358
- n.push(l), r.push(i);
514
+ const l = this.assignTextureLODForSlot(a, t, s, n);
515
+ i.push(l), r.push(n);
359
516
  }
360
517
  }
361
- return Promise.all(n).then((i) => {
518
+ return Promise.all(i).then((n) => {
362
519
  const a = new Array();
363
- for (let l = 0; l < i.length; l++) {
364
- const c = i[l], d = r[l];
365
- c && c.isTexture === !0 ? a.push({ material: s, slot: d, texture: c, level: e }) : a.push({ material: s, slot: d, texture: null, level: e });
520
+ for (let l = 0; l < n.length; l++) {
521
+ const u = n[l], f = r[l];
522
+ u && u.isTexture === !0 ? a.push({ material: s, slot: f, texture: u, level: t }) : a.push({ material: s, slot: f, texture: null, level: t });
366
523
  }
367
524
  return a;
368
525
  });
369
526
  }
370
- if (t instanceof oe || t.isTexture === !0) {
371
- const s = t;
372
- return this.assignTextureLODForSlot(s, e, null, null);
527
+ if (e instanceof se || e.isTexture === !0) {
528
+ const s = e;
529
+ return this.assignTextureLODForSlot(s, t, null, null);
373
530
  }
374
531
  return Promise.resolve(null);
375
532
  }
376
- static assignTextureLODForSlot(t, e, s, n) {
377
- return (t == null ? void 0 : t.isTexture) !== !0 ? Promise.resolve(null) : n === "glyphMap" ? Promise.resolve(t) : O.getOrLoadLOD(t, e).then((r) => {
533
+ static assignTextureLODForSlot(e, t, s, i) {
534
+ return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : i === "glyphMap" ? Promise.resolve(e) : P.getOrLoadLOD(e, t).then((r) => {
535
+ var n, a;
378
536
  if (Array.isArray(r))
379
- return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen", r), null;
537
+ return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen..."), null;
380
538
  if ((r == null ? void 0 : r.isTexture) === !0) {
381
- if (r != t && s && n) {
382
- const i = s[n];
383
- if (i && !y) {
384
- const a = this.getAssignedLODInformation(i);
385
- if (a && (a == null ? void 0 : a.level) < e)
386
- return y === "verbose" && console.warn("Assigned texture level is already higher: ", a.level, e, s, i, r), null;
539
+ if (r != e && s && i) {
540
+ const l = s[i];
541
+ if (l && !x) {
542
+ const u = this.getAssignedLODInformation(l);
543
+ if (u && (u == null ? void 0 : u.level) < t)
544
+ return x === "verbose" && console.warn("Assigned texture level is already higher: ", u.level, t, s, l, r), null;
545
+ }
546
+ if (kt && r.mipmaps) {
547
+ const u = r.mipmaps.length;
548
+ r.mipmaps.length = Math.min(r.mipmaps.length, 3), u !== r.mipmaps.length && x && console.debug(`Reduced mipmap count from ${u} to ${r.mipmaps.length} for ${r.uuid}: ${(n = r.image) == null ? void 0 : n.width}x${(a = r.image) == null ? void 0 : a.height}.`);
387
549
  }
388
- s[n] = r;
550
+ s[i] = r;
389
551
  }
390
552
  return r;
391
553
  } else
392
- y == "verbose" && console.warn("No LOD found for", t, e);
554
+ x == "verbose" && console.warn("No LOD found for", e, t);
393
555
  return null;
394
- }).catch((r) => (console.error("Error loading LOD", t, r), null));
556
+ }).catch((r) => (console.error("Error loading LOD", e, r), null));
395
557
  }
396
558
  // private _isLoadingTexture;
397
559
  // loadTexture = (textureIndex: number) => {
@@ -407,243 +569,259 @@ const X = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), O = c
407
569
  // return tex;
408
570
  // });
409
571
  // }
410
- afterRoot(t) {
411
- var e, s;
412
- return y && console.log("AFTER", this.url, t), (e = this.parser.json.textures) == null || e.forEach((n, r) => {
413
- var i;
414
- if (n != null && n.extensions) {
415
- const a = n == null ? void 0 : n.extensions[X];
572
+ afterRoot(e) {
573
+ var t, s;
574
+ return x && console.log("AFTER", this.url, e), (t = this.parser.json.textures) == null || t.forEach((i, r) => {
575
+ var n;
576
+ if (i != null && i.extensions) {
577
+ const a = i == null ? void 0 : i.extensions[Y];
416
578
  if (a) {
417
579
  if (!a.lods) {
418
- y && console.warn("Texture has no LODs", a);
580
+ x && console.warn("Texture has no LODs", a);
419
581
  return;
420
582
  }
421
583
  let l = !1;
422
- for (const c of this.parser.associations.keys())
423
- if (c.isTexture === !0) {
424
- const d = this.parser.associations.get(c);
425
- (d == null ? void 0 : d.textures) === r && (l = !0, O.registerTexture(this.url, c, (i = a.lods) == null ? void 0 : i.length, r, a));
584
+ for (const u of this.parser.associations.keys())
585
+ if (u.isTexture === !0) {
586
+ const f = this.parser.associations.get(u);
587
+ (f == null ? void 0 : f.textures) === r && (l = !0, P.registerTexture(this.url, u, (n = a.lods) == null ? void 0 : n.length, r, a));
426
588
  }
427
- l || this.parser.getDependency("texture", r).then((c) => {
428
- var d;
429
- c && O.registerTexture(this.url, c, (d = a.lods) == null ? void 0 : d.length, r, a);
589
+ l || this.parser.getDependency("texture", r).then((u) => {
590
+ var f;
591
+ u && P.registerTexture(this.url, u, (f = a.lods) == null ? void 0 : f.length, r, a);
430
592
  });
431
593
  }
432
594
  }
433
- }), (s = this.parser.json.meshes) == null || s.forEach((n, r) => {
434
- if (n != null && n.extensions) {
435
- const i = n == null ? void 0 : n.extensions[X];
436
- if (i && i.lods) {
595
+ }), (s = this.parser.json.meshes) == null || s.forEach((i, r) => {
596
+ if (i != null && i.extensions) {
597
+ const n = i == null ? void 0 : i.extensions[Y];
598
+ if (n && n.lods) {
437
599
  for (const a of this.parser.associations.keys())
438
600
  if (a.isMesh) {
439
601
  const l = this.parser.associations.get(a);
440
- (l == null ? void 0 : l.meshes) === r && O.registerMesh(this.url, i.guid, a, i.lods.length, l.primitives, i);
602
+ (l == null ? void 0 : l.meshes) === r && P.registerMesh(this.url, n.guid, a, n.lods.length, l.primitives, n);
441
603
  }
442
604
  }
443
605
  }
444
606
  }), null;
445
607
  }
446
- static async getOrLoadLOD(t, e) {
447
- var a, l, c, d;
448
- const s = y == "verbose", n = this.getAssignedLODInformation(t);
449
- if (!n)
450
- return y && console.warn(`[gltf-progressive] No LOD information found: ${t.name}, uuid: ${t.uuid}, type: ${t.type}`, t), null;
451
- const r = n == null ? void 0 : n.key;
452
- let i;
453
- if (t.isTexture === !0) {
454
- const h = t;
455
- h.source && h.source[Oe] && (i = h.source[Oe]);
608
+ static async getOrLoadLOD(e, t) {
609
+ var l, u, f, m;
610
+ const s = x == "verbose", i = this.getAssignedLODInformation(e);
611
+ if (!i)
612
+ return x && console.warn(`[gltf-progressive] No LOD information found: ${e.name}, uuid: ${e.uuid}, type: ${e.type}`, e), null;
613
+ const r = i == null ? void 0 : i.key;
614
+ let n;
615
+ if (e.isTexture === !0) {
616
+ const _ = e;
617
+ _.source && _.source[Pe] && (n = _.source[Pe]);
456
618
  }
457
- if (i || (i = O.lodInfos.get(r)), i) {
458
- if (e > 0) {
459
- let w = !1;
460
- const v = Array.isArray(i.lods);
461
- if (v && e >= i.lods.length ? w = !0 : v || (w = !0), w)
619
+ if (n || (n = P.lodInfos.get(r)), n) {
620
+ if (t > 0) {
621
+ let O = !1;
622
+ const M = Array.isArray(n.lods);
623
+ if (M && t >= n.lods.length ? O = !0 : M || (O = !0), O)
462
624
  return this.lowresCache.get(r);
463
625
  }
464
- const h = Array.isArray(i.lods) ? (a = i.lods[e]) == null ? void 0 : a.path : i.lods;
465
- if (!h)
466
- return y && !i["missing:uri"] && (i["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, i)), null;
467
- const f = dt(n.url, h);
468
- if (f.endsWith(".glb") || f.endsWith(".gltf")) {
469
- if (!i.guid)
470
- return console.warn("missing pointer for glb/gltf texture", i), null;
471
- const w = f + "_" + i.guid, v = this.previouslyLoaded.get(w);
472
- if (v !== void 0) {
473
- s && console.log(`LOD ${e} was already loading/loaded: ${w}`);
474
- let g = await v.catch((E) => (console.error(`Error loading LOD ${e} from ${f}
475
- `, E), null)), x = !1;
476
- if (g == null || (g instanceof oe && t instanceof oe ? (l = g.image) != null && l.data || (c = g.source) != null && c.data ? g = this.copySettings(t, g) : (x = !0, this.previouslyLoaded.delete(w)) : g instanceof Le && t instanceof Le && ((d = g.attributes.position) != null && d.array || (x = !0, this.previouslyLoaded.delete(w)))), !x)
477
- return g;
626
+ const _ = Array.isArray(n.lods) ? (l = n.lods[t]) == null ? void 0 : l.path : n.lods;
627
+ if (!_)
628
+ return x && !n["missing:uri"] && (n["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + t, n)), null;
629
+ const w = _t(i.url, _);
630
+ if (w.endsWith(".glb") || w.endsWith(".gltf")) {
631
+ if (!n.guid)
632
+ return console.warn("missing pointer for glb/gltf texture", n), null;
633
+ const O = w + "_" + n.guid, M = await this.queue.slot(w), B = this.previouslyLoaded.get(O);
634
+ if (B !== void 0) {
635
+ s && console.log(`LOD ${t} was already loading/loaded: ${O}`);
636
+ let h = await B.catch((T) => (console.error(`Error loading LOD ${t} from ${w}
637
+ `, T), null)), L = !1;
638
+ if (h == null || (h instanceof se && e instanceof se ? (u = h.image) != null && u.data || (f = h.source) != null && f.data ? h = this.copySettings(e, h) : (L = !0, this.previouslyLoaded.delete(O)) : h instanceof he && e instanceof he && ((m = h.attributes.position) != null && m.array || (L = !0, this.previouslyLoaded.delete(O)))), !L)
639
+ return h;
478
640
  }
479
- const P = await this.queue.slot(f);
480
- if (!P.use)
481
- return y && console.log(`LOD ${e} was aborted: ${f}`), null;
482
- const M = i, R = new Promise(async (g, x) => {
483
- const E = new Ce();
484
- ze(E), y && (await new Promise((D) => setTimeout(D, 1e3)), s && console.warn("Start loading (delayed) " + f, M.guid));
485
- let U = f;
486
- if (M && Array.isArray(M.lods)) {
487
- const D = M.lods[e];
488
- D.hash && (U += "?v=" + D.hash);
641
+ if (!M.use)
642
+ return x && console.log(`LOD ${t} was aborted: ${w}`), null;
643
+ const b = n, c = new Promise(async (h, L) => {
644
+ if (Ct) {
645
+ const p = await (await Tt({})).load(w);
646
+ if (p.textures.length > 0)
647
+ for (const g of p.textures) {
648
+ let y = g.texture;
649
+ return P.assignLODInformation(i.url, y, r, t, void 0), e instanceof se && (y = this.copySettings(e, y)), y && (y.guid = b.guid), h(y);
650
+ }
651
+ if (p.geometries.length > 0) {
652
+ const g = new Array();
653
+ for (const y of p.geometries) {
654
+ const I = y.geometry;
655
+ P.assignLODInformation(i.url, I, r, t, y.primitiveIndex), g.push(I);
656
+ }
657
+ return h(g);
658
+ }
659
+ return h(null);
660
+ }
661
+ const T = new Re();
662
+ Xe(T), x && (await new Promise((S) => setTimeout(S, 1e3)), s && console.warn("Start loading (delayed) " + w, b.guid));
663
+ let U = w;
664
+ if (b && Array.isArray(b.lods)) {
665
+ const S = b.lods[t];
666
+ S.hash && (U += "?v=" + S.hash);
489
667
  }
490
- const S = await E.loadAsync(U).catch((D) => (console.error(`Error loading LOD ${e} from ${f}
491
- `, D), g(null)));
492
- if (!S)
493
- return g(null);
494
- const ee = S.parser;
495
- s && console.log("Loading finished " + f, M.guid);
496
- let I = 0;
497
- if (S.parser.json.textures) {
498
- let D = !1;
499
- for (const m of S.parser.json.textures) {
500
- if (m != null && m.extensions) {
501
- const p = m == null ? void 0 : m.extensions[X];
502
- if (p != null && p.guid && p.guid === M.guid) {
503
- D = !0;
668
+ const k = await T.loadAsync(U).catch((S) => (console.error(`Error loading LOD ${t} from ${w}
669
+ `, S), h(null)));
670
+ if (!k)
671
+ return h(null);
672
+ const te = k.parser;
673
+ s && console.log("Loading finished " + w, b.guid);
674
+ let G = 0;
675
+ if (k.parser.json.textures) {
676
+ let S = !1;
677
+ for (const p of k.parser.json.textures) {
678
+ if (p != null && p.extensions) {
679
+ const g = p == null ? void 0 : p.extensions[Y];
680
+ if (g != null && g.guid && g.guid === b.guid) {
681
+ S = !0;
504
682
  break;
505
683
  }
506
684
  }
507
- I++;
685
+ G++;
508
686
  }
509
- if (D) {
510
- let m = await ee.getDependency("texture", I);
511
- return m && O.assignLODInformation(n.url, m, r, e, void 0), s && console.log('change "' + t.name + '" → "' + m.name + '"', f, I, m, w), t instanceof oe && (m = this.copySettings(t, m)), m && (m.guid = M.guid), g(m);
687
+ if (S) {
688
+ let p = await te.getDependency("texture", G);
689
+ return p && P.assignLODInformation(i.url, p, r, t, void 0), s && console.log('change "' + e.name + '" → "' + p.name + '"', w, G, p, O), e instanceof se && (p = this.copySettings(e, p)), p && (p.guid = b.guid), h(p);
512
690
  } else
513
- y && console.warn("Could not find texture with guid", M.guid, S.parser.json);
691
+ x && console.warn("Could not find texture with guid", b.guid, k.parser.json);
514
692
  }
515
- if (I = 0, S.parser.json.meshes) {
516
- let D = !1;
517
- for (const m of S.parser.json.meshes) {
518
- if (m != null && m.extensions) {
519
- const p = m == null ? void 0 : m.extensions[X];
520
- if (p != null && p.guid && p.guid === M.guid) {
521
- D = !0;
693
+ if (G = 0, k.parser.json.meshes) {
694
+ let S = !1;
695
+ for (const p of k.parser.json.meshes) {
696
+ if (p != null && p.extensions) {
697
+ const g = p == null ? void 0 : p.extensions[Y];
698
+ if (g != null && g.guid && g.guid === b.guid) {
699
+ S = !0;
522
700
  break;
523
701
  }
524
702
  }
525
- I++;
703
+ G++;
526
704
  }
527
- if (D) {
528
- const m = await ee.getDependency("mesh", I);
529
- if (s && console.log(`Loaded Mesh "${m.name}"`, f, I, m, w), m.isMesh === !0) {
530
- const p = m.geometry;
531
- return O.assignLODInformation(n.url, p, r, e, 0), g(p);
705
+ if (S) {
706
+ const p = await te.getDependency("mesh", G);
707
+ if (s && console.log(`Loaded Mesh "${p.name}"`, w, G, p, O), p.isMesh === !0) {
708
+ const g = p.geometry;
709
+ return P.assignLODInformation(i.url, g, r, t, 0), h(g);
532
710
  } else {
533
- const p = new Array();
534
- for (let _ = 0; _ < m.children.length; _++) {
535
- const $ = m.children[_];
536
- if ($.isMesh === !0) {
537
- const A = $.geometry;
538
- O.assignLODInformation(n.url, A, r, e, _), p.push(A);
711
+ const g = new Array();
712
+ for (let y = 0; y < p.children.length; y++) {
713
+ const I = p.children[y];
714
+ if (I.isMesh === !0) {
715
+ const R = I.geometry;
716
+ P.assignLODInformation(i.url, R, r, t, y), g.push(R);
539
717
  }
540
718
  }
541
- return g(p);
719
+ return h(g);
542
720
  }
543
721
  } else
544
- y && console.warn("Could not find mesh with guid", M.guid, S.parser.json);
722
+ x && console.warn("Could not find mesh with guid", b.guid, k.parser.json);
545
723
  }
546
- return g(null);
724
+ return h(null);
547
725
  });
548
- return this.previouslyLoaded.set(w, R), P.use(R), await R;
549
- } else if (t instanceof oe) {
550
- s && console.log("Load texture from uri: " + f);
551
- const v = await new je().loadAsync(f);
552
- return v ? (v.guid = i.guid, v.flipY = !1, v.needsUpdate = !0, v.colorSpace = t.colorSpace, s && console.log(i, v)) : y && console.warn("failed loading", f), v;
726
+ return this.previouslyLoaded.set(O, c), M.use(c), await c;
727
+ } else if (e instanceof se) {
728
+ s && console.log("Load texture from uri: " + w);
729
+ const M = await new lt().loadAsync(w);
730
+ return M ? (M.guid = n.guid, M.flipY = !1, M.needsUpdate = !0, M.colorSpace = e.colorSpace, s && console.log(n, M)) : x && console.warn("failed loading", w), M;
553
731
  }
554
732
  } else
555
- y && console.warn(`Can not load LOD ${e}: no LOD info found for "${r}" ${t.name}`, t.type);
733
+ x && console.warn(`Can not load LOD ${t}: no LOD info found for "${r}" ${e.name}`, e.type);
556
734
  return null;
557
735
  }
558
- static assignLODInformation(t, e, s, n, r) {
559
- if (!e)
736
+ static assignLODInformation(e, t, s, i, r) {
737
+ if (!t)
560
738
  return;
561
- e.userData || (e.userData = {});
562
- const i = new yt(t, s, n, r);
563
- e.userData.LODS = i, "source" in e && typeof e.source == "object" && (e.source.LODS = i);
739
+ t.userData || (t.userData = {});
740
+ const n = new It(e, s, i, r);
741
+ t.userData.LODS = n, "source" in t && typeof t.source == "object" && (t.source.LODS = n);
564
742
  }
565
- static getAssignedLODInformation(t) {
566
- var e, s;
567
- return t ? (e = t.userData) != null && e.LODS ? t.userData.LODS : "source" in t && ((s = t.source) != null && s.LODS) ? t.source.LODS : null : null;
743
+ static getAssignedLODInformation(e) {
744
+ var t, s;
745
+ return e ? (t = e.userData) != null && t.LODS ? e.userData.LODS : "source" in e && ((s = e.source) != null && s.LODS) ? e.source.LODS : null : null;
568
746
  }
569
747
  // private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
570
- static copySettings(t, e) {
571
- return e ? (y && console.warn(`Copy texture settings
572
- `, t.uuid, `
573
- `, e.uuid), e = e.clone(), 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) : t;
748
+ static copySettings(e, t) {
749
+ return t ? (x === "verbose" && console.debug(`Copy texture settings
750
+ `, e.uuid, `
751
+ `, t.uuid), t = t.clone(), 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) : e;
574
752
  }
575
753
  };
576
- let T = O;
754
+ let C = P;
577
755
  /**
578
756
  * Register a texture with LOD information
579
757
  */
580
- u(T, "registerTexture", (t, e, s, n, r) => {
581
- var a, l, c, d, h, f, w, v;
582
- if (!e) {
583
- y && console.error("gltf-progressive: Called register texture without texture");
758
+ d(C, "registerTexture", (e, t, s, i, r) => {
759
+ var a, l, u, f, m, _, w, O;
760
+ if (!t) {
761
+ x && console.error("gltf-progressive: Called register texture without texture");
584
762
  return;
585
763
  }
586
- if (y) {
587
- const P = ((a = e.image) == null ? void 0 : a.width) || ((c = (l = e.source) == null ? void 0 : l.data) == null ? void 0 : c.width) || 0, M = ((d = e.image) == null ? void 0 : d.height) || ((f = (h = e.source) == null ? void 0 : h.data) == null ? void 0 : f.height) || 0;
588
- console.log(`> Progressive: register texture[${n}] "${e.name || e.uuid}", Current: ${P}x${M}, Max: ${(w = r.lods[0]) == null ? void 0 : w.width}x${(v = r.lods[0]) == null ? void 0 : v.height}, uuid: ${e.uuid}`, r, e);
764
+ if (x) {
765
+ const M = ((a = t.image) == null ? void 0 : a.width) || ((u = (l = t.source) == null ? void 0 : l.data) == null ? void 0 : u.width) || 0, B = ((f = t.image) == null ? void 0 : f.height) || ((_ = (m = t.source) == null ? void 0 : m.data) == null ? void 0 : _.height) || 0;
766
+ console.log(`> Progressive: register texture[${i}] "${t.name || t.uuid}", Current: ${M}x${B}, Max: ${(w = r.lods[0]) == null ? void 0 : w.width}x${(O = r.lods[0]) == null ? void 0 : O.height}, uuid: ${t.uuid}`, r, t);
589
767
  }
590
- e.source && (e.source[Oe] = r);
591
- const i = r.guid;
592
- O.assignLODInformation(t, e, i, s, n), O.lodInfos.set(i, r), O.lowresCache.set(i, e);
768
+ t.source && (t.source[Pe] = r);
769
+ const n = r.guid;
770
+ P.assignLODInformation(e, t, n, s, i), P.lodInfos.set(n, r), P.lowresCache.set(n, t);
593
771
  }), /**
594
772
  * Register a mesh with LOD information
595
773
  */
596
- u(T, "registerMesh", (t, e, s, n, r, i) => {
597
- var c;
774
+ d(C, "registerMesh", (e, t, s, i, r, n) => {
775
+ var u;
598
776
  const a = s.geometry;
599
777
  if (!a) {
600
- y && console.warn("gltf-progressive: Register mesh without geometry");
778
+ x && console.warn("gltf-progressive: Register mesh without geometry");
601
779
  return;
602
780
  }
603
- a.userData || (a.userData = {}), y && console.log("> Progressive: register mesh " + s.name, { index: r, uuid: s.uuid }, i, s), O.assignLODInformation(t, a, e, n, r), O.lodInfos.set(e, i);
604
- let l = O.lowresCache.get(e);
605
- l ? l.push(s.geometry) : l = [s.geometry], O.lowresCache.set(e, l), n > 0 && !ce(s) && gt(s, a);
606
- for (const d of j)
607
- (c = d.onRegisteredNewMesh) == null || c.call(d, s, i);
781
+ a.userData || (a.userData = {}), x && console.log("> Progressive: register mesh " + s.name, { index: r, uuid: s.uuid }, n, s), P.assignLODInformation(e, a, t, i, r), P.lodInfos.set(t, n);
782
+ let l = P.lowresCache.get(t);
783
+ l ? l.push(s.geometry) : l = [s.geometry], P.lowresCache.set(t, l), i > 0 && !ge(s) && Dt(s, a);
784
+ for (const f of Z)
785
+ (u = f.onRegisteredNewMesh) == null || u.call(f, s, n);
608
786
  }), /** A map of key = asset uuid and value = LOD information */
609
- u(T, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
610
- u(T, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
611
- u(T, "lowresCache", /* @__PURE__ */ new Map()), u(T, "queue", new ft(100, { debug: y != !1 }));
612
- class yt {
613
- constructor(t, e, s, n) {
614
- u(this, "url");
787
+ d(C, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
788
+ d(C, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
789
+ d(C, "lowresCache", /* @__PURE__ */ new Map()), d(C, "workers", []), d(C, "_workersIndex", 0), d(C, "maxConcurrent", 50), d(C, "queue", new Mt(P.maxConcurrent, { debug: x != !1 }));
790
+ class It {
791
+ constructor(e, t, s, i) {
792
+ d(this, "url");
615
793
  /** the key to lookup the LOD information */
616
- u(this, "key");
617
- u(this, "level");
794
+ d(this, "key");
795
+ d(this, "level");
618
796
  /** For multi objects (e.g. a group of meshes) this is the index of the object */
619
- u(this, "index");
620
- this.url = t, this.key = e, this.level = s, n != null && (this.index = n);
797
+ d(this, "index");
798
+ this.url = e, this.key = t, this.level = s, i != null && (this.index = i);
621
799
  }
622
800
  }
623
- class ye {
624
- constructor(t, e) {
625
- u(this, "frame_start");
626
- u(this, "frame_capture_end");
627
- u(this, "ready");
628
- u(this, "_resolve");
629
- u(this, "_signal");
630
- u(this, "_resolved", !1);
631
- u(this, "_addedCount", 0);
632
- u(this, "_resolvedCount", 0);
801
+ class Le {
802
+ constructor(e, t) {
803
+ d(this, "frame_start");
804
+ d(this, "frame_capture_end");
805
+ d(this, "ready");
806
+ d(this, "_resolve");
807
+ d(this, "_signal");
808
+ d(this, "_resolved", !1);
809
+ d(this, "_addedCount", 0);
810
+ d(this, "_resolvedCount", 0);
633
811
  /** These promises are currently being awaited */
634
- u(this, "_awaiting", []);
635
- u(this, "_maxPromisesPerObject", 1);
636
- u(this, "_currentFrame", 0);
637
- u(this, "_seen", /* @__PURE__ */ new WeakMap());
812
+ d(this, "_awaiting", []);
813
+ d(this, "_maxPromisesPerObject", 1);
814
+ d(this, "_currentFrame", 0);
815
+ d(this, "_seen", /* @__PURE__ */ new WeakMap());
638
816
  var r;
639
- const n = Math.max(e.frames ?? 2, 2);
640
- this.frame_start = t, this.frame_capture_end = t + n, this.ready = new Promise((i) => {
641
- this._resolve = i;
817
+ const i = Math.max(t.frames ?? 2, 2);
818
+ this.frame_start = e, this.frame_capture_end = e + i, this.ready = new Promise((n) => {
819
+ this._resolve = n;
642
820
  }), this.ready.finally(() => {
643
821
  this._resolved = !0, this._awaiting.length = 0;
644
- }), this._signal = e.signal, (r = this._signal) == null || r.addEventListener("abort", () => {
822
+ }), this._signal = t.signal, (r = this._signal) == null || r.addEventListener("abort", () => {
645
823
  this.resolveNow();
646
- }), this._maxPromisesPerObject = Math.max(1, e.maxPromisesPerObject ?? 1);
824
+ }), this._maxPromisesPerObject = Math.max(1, t.maxPromisesPerObject ?? 1);
647
825
  }
648
826
  /**
649
827
  * The number of promises that have been added to this group so far.
@@ -657,156 +835,156 @@ class ye {
657
835
  get currentlyAwaiting() {
658
836
  return this._awaiting.length;
659
837
  }
660
- update(t) {
661
- var e;
662
- this._currentFrame = t, ((e = this._signal) != null && e.aborted || this._currentFrame > this.frame_capture_end && this._awaiting.length === 0) && this.resolveNow();
838
+ update(e) {
839
+ var t;
840
+ this._currentFrame = e, ((t = this._signal) != null && t.aborted || this._currentFrame > this.frame_capture_end && this._awaiting.length === 0) && this.resolveNow();
663
841
  }
664
- add(t, e, s) {
842
+ add(e, t, s) {
665
843
  if (this._resolved) {
666
- y && console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");
844
+ x && console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");
667
845
  return;
668
846
  }
669
847
  if (!(this._currentFrame > this.frame_capture_end)) {
670
848
  if (this._maxPromisesPerObject >= 1)
671
- if (this._seen.has(e)) {
672
- let n = this._seen.get(e);
673
- if (n >= this._maxPromisesPerObject) {
674
- y && console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");
849
+ if (this._seen.has(t)) {
850
+ let i = this._seen.get(t);
851
+ if (i >= this._maxPromisesPerObject) {
852
+ x && console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");
675
853
  return;
676
854
  }
677
- this._seen.set(e, n + 1);
855
+ this._seen.set(t, i + 1);
678
856
  } else
679
- this._seen.set(e, 1);
857
+ this._seen.set(t, 1);
680
858
  this._awaiting.push(s), this._addedCount++, s.finally(() => {
681
859
  this._resolvedCount++, this._awaiting.splice(this._awaiting.indexOf(s), 1);
682
860
  });
683
861
  }
684
862
  }
685
863
  resolveNow() {
686
- var t, e;
687
- this._resolved || (e = this._resolve) == null || e.call(this, {
864
+ var e, t;
865
+ this._resolved || (t = this._resolve) == null || t.call(this, {
688
866
  awaited_count: this._addedCount,
689
867
  resolved_count: this._resolvedCount,
690
- cancelled: ((t = this._signal) == null ? void 0 : t.aborted) ?? !1
868
+ cancelled: ((e = this._signal) == null ? void 0 : e.aborted) ?? !1
691
869
  });
692
870
  }
693
871
  }
694
- u(ye, "addPromise", (t, e, s, n) => {
695
- n.forEach((r) => {
696
- r.add(t, e, s);
872
+ d(Le, "addPromise", (e, t, s, i) => {
873
+ i.forEach((r) => {
874
+ r.add(e, t, s);
697
875
  });
698
876
  });
699
- const F = de("debugprogressive"), Lt = de("noprogressive"), be = Symbol("Needle:LODSManager"), Se = Symbol("Needle:LODState"), Q = Symbol("Needle:CurrentLOD"), G = { mesh_lod: -1, texture_lod: -1 };
700
- var B, K, we, J, ie, _e, Y;
701
- const b = class {
877
+ const z = oe("debugprogressive"), Bt = oe("noprogressive"), Te = Symbol("Needle:LODSManager"), Ae = Symbol("Needle:LODState"), J = Symbol("Needle:CurrentLOD"), E = { mesh_lod: -1, texture_lod: -1 };
878
+ var F, j, Me, ee, ae, ve, H;
879
+ const A = class {
702
880
  // readonly plugins: NEEDLE_progressive_plugin[] = [];
703
- constructor(t, e) {
704
- u(this, "renderer");
705
- u(this, "context");
706
- u(this, "projectionScreenMatrix", new Ie());
881
+ constructor(e, t) {
882
+ d(this, "renderer");
883
+ d(this, "context");
884
+ d(this, "projectionScreenMatrix", new Fe());
707
885
  /**
708
886
  * The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
709
887
  * @default 200_000
710
888
  */
711
- u(this, "targetTriangleDensity", 2e5);
889
+ d(this, "targetTriangleDensity", 2e5);
712
890
  /**
713
891
  * The interval in frames to automatically update the bounds of skinned meshes.
714
892
  * Set to 0 or a negative value to disable automatic bounds updates.
715
893
  * @default 30
716
894
  */
717
- u(this, "skinnedMeshAutoUpdateBoundsInterval", 30);
895
+ d(this, "skinnedMeshAutoUpdateBoundsInterval", 30);
718
896
  /**
719
897
  * 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.
720
898
  * @default "auto"
721
899
  */
722
- u(this, "updateInterval", "auto");
723
- H(this, B, 1);
900
+ d(this, "updateInterval", "auto");
901
+ Q(this, F, 1);
724
902
  /**
725
903
  * If set to true, the LODsManager will not update the LODs.
726
904
  * @default false
727
905
  */
728
- u(this, "pause", !1);
906
+ d(this, "pause", !1);
729
907
  /**
730
908
  * When set to true the LODsManager will not update the LODs. This can be used to manually update the LODs using the `update` method.
731
909
  * Otherwise the LODs will be updated automatically when the renderer renders the scene.
732
910
  * @default false
733
911
  */
734
- u(this, "manual", !1);
735
- u(this, "_newPromiseGroups", []);
736
- u(this, "_promiseGroupIds", 0);
737
- u(this, "_lodchangedlisteners", []);
738
- H(this, K, void 0);
739
- H(this, we, new Je());
740
- H(this, J, 0);
741
- H(this, ie, 0);
742
- H(this, _e, 0);
743
- H(this, Y, 0);
744
- u(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
912
+ d(this, "manual", !1);
913
+ d(this, "_newPromiseGroups", []);
914
+ d(this, "_promiseGroupIds", 0);
915
+ d(this, "_lodchangedlisteners", []);
916
+ Q(this, j, void 0);
917
+ Q(this, Me, new ut());
918
+ Q(this, ee, 0);
919
+ Q(this, ae, 0);
920
+ Q(this, ve, 0);
921
+ Q(this, H, 0);
922
+ d(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
745
923
  // private testIfLODLevelsAreAvailable() {
746
- u(this, "_sphere", new et());
747
- u(this, "_tempBox", new $e());
748
- u(this, "_tempBox2", new $e());
749
- u(this, "tempMatrix", new Ie());
750
- u(this, "_tempWorldPosition", new W());
751
- u(this, "_tempBoxSize", new W());
752
- u(this, "_tempBox2Size", new W());
753
- this.renderer = t, this.context = { ...e };
924
+ d(this, "_sphere", new qe());
925
+ d(this, "_tempBox", new Ce());
926
+ d(this, "_tempBox2", new Ce());
927
+ d(this, "tempMatrix", new Fe());
928
+ d(this, "_tempWorldPosition", new W());
929
+ d(this, "_tempBoxSize", new W());
930
+ d(this, "_tempBox2Size", new W());
931
+ this.renderer = e, this.context = { ...t };
754
932
  }
755
933
  /** @internal */
756
- static getObjectLODState(t) {
757
- return t[Se];
934
+ static getObjectLODState(e) {
935
+ return e[Ae];
758
936
  }
759
- static addPlugin(t) {
760
- j.push(t);
937
+ static addPlugin(e) {
938
+ Z.push(e);
761
939
  }
762
- static removePlugin(t) {
763
- const e = j.indexOf(t);
764
- e >= 0 && j.splice(e, 1);
940
+ static removePlugin(e) {
941
+ const t = Z.indexOf(e);
942
+ t >= 0 && Z.splice(t, 1);
765
943
  }
766
944
  /**
767
945
  * Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
768
946
  * @param renderer The renderer to get the LODsManager for.
769
947
  * @returns The LODsManager instance.
770
948
  */
771
- static get(t, e) {
772
- if (t[be])
773
- return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[be];
774
- const s = new b(t, {
949
+ static get(e, t) {
950
+ if (e[Te])
951
+ return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), e[Te];
952
+ const s = new A(e, {
775
953
  engine: "unknown",
776
- ...e
954
+ ...t
777
955
  });
778
- return t[be] = s, s;
956
+ return e[Te] = s, s;
779
957
  }
780
958
  /** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
781
959
  get plugins() {
782
- return j;
960
+ return Z;
783
961
  }
784
962
  /**
785
963
  * Call to await LODs loading during the next render cycle.
786
964
  */
787
- awaitLoading(t) {
788
- const e = this._promiseGroupIds++, s = new ye(L(this, J), { ...t });
965
+ awaitLoading(e) {
966
+ const t = this._promiseGroupIds++, s = new Le(D(this, ee), { ...e });
789
967
  this._newPromiseGroups.push(s);
790
- const n = performance.now();
968
+ const i = performance.now();
791
969
  return s.ready.finally(() => {
792
970
  const r = this._newPromiseGroups.indexOf(s);
793
- r >= 0 && (this._newPromiseGroups.splice(r, 1), Ge() && performance.measure("LODsManager:awaitLoading", {
794
- start: n,
795
- detail: { id: e, name: t == null ? void 0 : t.name, awaited: s.awaitedCount, resolved: s.resolvedCount }
971
+ r >= 0 && (this._newPromiseGroups.splice(r, 1), Ne() && performance.measure("LODsManager:awaitLoading", {
972
+ start: i,
973
+ detail: { id: t, name: e == null ? void 0 : e.name, awaited: s.awaitedCount, resolved: s.resolvedCount }
796
974
  }));
797
975
  }), s.ready;
798
976
  }
799
977
  _postprocessPromiseGroups() {
800
978
  if (this._newPromiseGroups.length !== 0)
801
- for (let t = this._newPromiseGroups.length - 1; t >= 0; t--)
802
- this._newPromiseGroups[t].update(L(this, J));
979
+ for (let e = this._newPromiseGroups.length - 1; e >= 0; e--)
980
+ this._newPromiseGroups[e].update(D(this, ee));
803
981
  }
804
- addEventListener(t, e) {
805
- t === "changed" && this._lodchangedlisteners.push(e);
982
+ addEventListener(e, t) {
983
+ e === "changed" && this._lodchangedlisteners.push(t);
806
984
  }
807
- removeEventListener(t, e) {
808
- if (t === "changed") {
809
- const s = this._lodchangedlisteners.indexOf(e);
985
+ removeEventListener(e, t) {
986
+ if (e === "changed") {
987
+ const s = this._lodchangedlisteners.indexOf(t);
810
988
  s >= 0 && this._lodchangedlisteners.splice(s, 1);
811
989
  }
812
990
  }
@@ -814,54 +992,54 @@ const b = class {
814
992
  * Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
815
993
  */
816
994
  enable() {
817
- if (L(this, K))
995
+ if (D(this, j))
818
996
  return;
819
997
  console.debug("[gltf-progressive] Enabling LODsManager for renderer");
820
- let t = 0;
821
- V(this, K, this.renderer.render);
822
- const e = this;
823
- Ue(this.renderer), this.renderer.render = function(s, n) {
824
- const r = e.renderer.getRenderTarget();
825
- (r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (t = 0, V(e, J, L(e, J) + 1), V(e, ie, L(e, we).getDelta()), V(e, _e, L(e, _e) + L(e, ie)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / L(e, ie)), V(e, Y, e._fpsBuffer.reduce((a, l) => a + l) / e._fpsBuffer.length), F && L(e, J) % 200 === 0 && console.log("FPS", Math.round(L(e, Y)), "Interval:", L(e, B)));
826
- const i = t++;
827
- L(e, K).call(this, s, n), e.onAfterRender(s, n, i);
998
+ let e = 0;
999
+ K(this, j, this.renderer.render);
1000
+ const t = this;
1001
+ $e(this.renderer), this.renderer.render = function(s, i) {
1002
+ const r = t.renderer.getRenderTarget();
1003
+ (r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (e = 0, K(t, ee, D(t, ee) + 1), K(t, ae, D(t, Me).getDelta()), K(t, ve, D(t, ve) + D(t, ae)), t._fpsBuffer.shift(), t._fpsBuffer.push(1 / D(t, ae)), K(t, H, t._fpsBuffer.reduce((a, l) => a + l) / t._fpsBuffer.length), z && D(t, ee) % 200 === 0 && console.log("FPS", Math.round(D(t, H)), "Interval:", D(t, F)));
1004
+ const n = e++;
1005
+ D(t, j).call(this, s, i), t.onAfterRender(s, i, n);
828
1006
  };
829
1007
  }
830
1008
  disable() {
831
- L(this, K) && (console.debug("[gltf-progressive] Disabling LODsManager for renderer"), this.renderer.render = L(this, K), V(this, K, void 0));
1009
+ D(this, j) && (console.debug("[gltf-progressive] Disabling LODsManager for renderer"), this.renderer.render = D(this, j), K(this, j, void 0));
832
1010
  }
833
- update(t, e) {
834
- this.internalUpdate(t, e);
1011
+ update(e, t) {
1012
+ this.internalUpdate(e, t);
835
1013
  }
836
- onAfterRender(t, e, s) {
1014
+ onAfterRender(e, t, s) {
837
1015
  if (this.pause)
838
1016
  return;
839
- const r = this.renderer.renderLists.get(t, 0).opaque;
840
- let i = !0;
1017
+ const r = this.renderer.renderLists.get(e, 0).opaque;
1018
+ let n = !0;
841
1019
  if (r.length === 1) {
842
1020
  const a = r[0].material;
843
- (a.name === "EffectMaterial" || a.name === "CopyShader") && (i = !1);
1021
+ (a.name === "EffectMaterial" || a.name === "CopyShader") && (n = !1);
844
1022
  }
845
- if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (i = !1), i) {
846
- if (Lt || (this.updateInterval === "auto" ? L(this, Y) < 40 && L(this, B) < 10 ? (V(this, B, L(this, B) + 1), F && console.warn("↓ Reducing LOD updates", L(this, B), L(this, Y).toFixed(0))) : L(this, Y) >= 60 && L(this, B) > 1 && (V(this, B, L(this, B) - 1), F && console.warn("↑ Increasing LOD updates", L(this, B), L(this, Y).toFixed(0))) : V(this, B, this.updateInterval), L(this, B) > 0 && L(this, J) % L(this, B) != 0))
1023
+ if ((t.parent && t.parent.type === "CubeCamera" || s >= 1 && t.type === "OrthographicCamera") && (n = !1), n) {
1024
+ if (Bt || (this.updateInterval === "auto" ? D(this, H) < 40 && D(this, F) < 10 ? (K(this, F, D(this, F) + 1), z && console.warn("↓ Reducing LOD updates", D(this, F), D(this, H).toFixed(0))) : D(this, H) >= 60 && D(this, F) > 1 && (K(this, F, D(this, F) - 1), z && console.warn("↑ Increasing LOD updates", D(this, F), D(this, H).toFixed(0))) : K(this, F, this.updateInterval), D(this, F) > 0 && D(this, ee) % D(this, F) != 0))
847
1025
  return;
848
- this.internalUpdate(t, e), this._postprocessPromiseGroups();
1026
+ this.internalUpdate(e, t), this._postprocessPromiseGroups();
849
1027
  }
850
1028
  }
851
1029
  /**
852
1030
  * Update LODs in a scene
853
1031
  */
854
- internalUpdate(t, e) {
855
- var l, c;
856
- const s = this.renderer.renderLists.get(t, 0), n = s.opaque;
857
- this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix, e.matrixWorldInverse);
1032
+ internalUpdate(e, t) {
1033
+ var l, u;
1034
+ const s = this.renderer.renderLists.get(e, 0), i = s.opaque;
1035
+ this.projectionScreenMatrix.multiplyMatrices(t.projectionMatrix, t.matrixWorldInverse);
858
1036
  const r = this.targetTriangleDensity;
859
- for (const d of n) {
860
- if (d.material && (((l = d.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((c = d.geometry) == null ? void 0 : c.type) === "BufferGeometry") && (d.material.name === "SphericalGaussianBlur" || d.material.name == "BackgroundCubeMaterial" || d.material.name === "CubemapFromEquirect" || d.material.name === "EquirectangularToCubeUV")) {
861
- F && (d.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (d.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", d, d.material.name, d.material.type)));
1037
+ for (const f of i) {
1038
+ if (f.material && (((l = f.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((u = f.geometry) == null ? void 0 : u.type) === "BufferGeometry") && (f.material.name === "SphericalGaussianBlur" || f.material.name == "BackgroundCubeMaterial" || f.material.name === "CubemapFromEquirect" || f.material.name === "EquirectangularToCubeUV")) {
1039
+ z && (f.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (f.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", f, f.material.name, f.material.type)));
862
1040
  continue;
863
1041
  }
864
- switch (d.material.type) {
1042
+ switch (f.material.type) {
865
1043
  case "LineBasicMaterial":
866
1044
  case "LineDashedMaterial":
867
1045
  case "PointsMaterial":
@@ -870,62 +1048,60 @@ const b = class {
870
1048
  case "MeshDepthMaterial":
871
1049
  continue;
872
1050
  }
873
- if (F === "color" && d.material && !d.object.progressive_debug_color) {
874
- d.object.progressive_debug_color = !0;
875
- const f = Math.random() * 16777215, w = new Ze({ color: f });
876
- d.object.material = w;
1051
+ if (z === "color" && f.material && !f.object.progressive_debug_color) {
1052
+ f.object.progressive_debug_color = !0;
1053
+ const _ = Math.random() * 16777215, w = new dt({ color: _ });
1054
+ f.object.material = w;
877
1055
  }
878
- const h = d.object;
879
- (h instanceof se || h.isMesh) && this.updateLODs(t, e, h, r);
1056
+ const m = f.object;
1057
+ (m instanceof ne || m.isMesh) && this.updateLODs(e, t, m, r);
880
1058
  }
881
- const i = s.transparent;
882
- for (const d of i) {
883
- const h = d.object;
884
- (h instanceof se || h.isMesh) && this.updateLODs(t, e, h, r);
1059
+ const n = s.transparent;
1060
+ for (const f of n) {
1061
+ const m = f.object;
1062
+ (m instanceof ne || m.isMesh) && this.updateLODs(e, t, m, r);
885
1063
  }
886
1064
  const a = s.transmissive;
887
- for (const d of a) {
888
- const h = d.object;
889
- (h instanceof se || h.isMesh) && this.updateLODs(t, e, h, r);
1065
+ for (const f of a) {
1066
+ const m = f.object;
1067
+ (m instanceof ne || m.isMesh) && this.updateLODs(e, t, m, r);
890
1068
  }
891
1069
  }
892
1070
  /** Update the LOD levels for the renderer. */
893
- updateLODs(t, e, s, n) {
1071
+ updateLODs(e, t, s, i) {
894
1072
  var a, l;
895
1073
  s.userData || (s.userData = {});
896
- let r = s[Se];
897
- if (r || (r = new xt(), s[Se] = r), r.frames++ < 2)
1074
+ let r = s[Ae];
1075
+ if (r || (r = new Rt(), s[Ae] = r), r.frames++ < 2)
898
1076
  return;
899
- for (const c of j)
900
- (a = c.onBeforeUpdateLOD) == null || a.call(c, this.renderer, t, e, s);
901
- const i = b.overrideGlobalLodLevel !== void 0 ? b.overrideGlobalLodLevel : te;
902
- i >= 0 ? (G.mesh_lod = i, G.texture_lod = i) : (this.calculateLodLevel(e, s, r, n, G), G.mesh_lod = Math.round(G.mesh_lod), G.texture_lod = Math.round(G.texture_lod)), G.mesh_lod >= 0 && this.loadProgressiveMeshes(s, G.mesh_lod), s.material && G.texture_lod >= 0 && this.loadProgressiveTextures(s.material, G.texture_lod), y && s.material && !s.isGizmo && qe(s.material);
903
- for (const c of j)
904
- (l = c.onAfterUpdatedLOD) == null || l.call(c, this.renderer, t, e, s, G);
905
- r.lastLodLevel_Mesh = G.mesh_lod, r.lastLodLevel_Texture = G.texture_lod;
1077
+ for (const u of Z)
1078
+ (a = u.onBeforeUpdateLOD) == null || a.call(u, this.renderer, e, t, s);
1079
+ const n = A.overrideGlobalLodLevel !== void 0 ? A.overrideGlobalLodLevel : re;
1080
+ n >= 0 ? (E.mesh_lod = n, E.texture_lod = n) : (this.calculateLodLevel(t, s, r, i, E), E.mesh_lod = Math.round(E.mesh_lod), E.texture_lod = Math.round(E.texture_lod)), E.mesh_lod >= 0 && this.loadProgressiveMeshes(s, E.mesh_lod), s.material && E.texture_lod >= 0 && this.loadProgressiveTextures(s.material, E.texture_lod, n), x && s.material && !s.isGizmo && He(s.material);
1081
+ for (const u of Z)
1082
+ (l = u.onAfterUpdatedLOD) == null || l.call(u, this.renderer, e, t, s, E);
1083
+ r.lastLodLevel_Mesh = E.mesh_lod, r.lastLodLevel_Texture = E.texture_lod;
906
1084
  }
907
1085
  /** Load progressive textures for the given material
908
1086
  * @param material the material to load the textures for
909
1087
  * @param level the LOD level to load. Level 0 is the best quality, higher levels are lower quality
910
1088
  * @returns Promise with true if the LOD was loaded, false if not
911
1089
  */
912
- loadProgressiveTextures(t, e) {
913
- if (!t)
1090
+ loadProgressiveTextures(e, t, s) {
1091
+ if (!e)
914
1092
  return;
915
- if (Array.isArray(t)) {
916
- for (const r of t)
917
- this.loadProgressiveTextures(r, e);
1093
+ if (Array.isArray(e)) {
1094
+ for (const r of e)
1095
+ this.loadProgressiveTextures(r, t);
918
1096
  return;
919
1097
  }
920
- let s = !1;
921
- (t[Q] === void 0 || e < t[Q]) && (s = !0);
922
- const n = t["DEBUG:LOD"];
923
- if (n != null && (s = t[Q] != n, e = n), s) {
924
- t[Q] = e;
925
- const r = T.assignTextureLOD(t, e).then((i) => {
926
- this._lodchangedlisteners.forEach((a) => a({ type: "texture", level: e, object: t }));
1098
+ let i = !1;
1099
+ if ((e[J] === void 0 || t < e[J]) && (i = !0), s !== void 0 && s >= 0 && (i = e[J] != s, t = s), i) {
1100
+ e[J] = t;
1101
+ const r = C.assignTextureLOD(e, t).then((n) => {
1102
+ this._lodchangedlisteners.forEach((a) => a({ type: "texture", level: t, object: e }));
927
1103
  });
928
- ye.addPromise("texture", t, r, this._newPromiseGroups);
1104
+ Le.addPromise("texture", e, r, this._newPromiseGroups);
929
1105
  }
930
1106
  }
931
1107
  /** Load progressive meshes for the given mesh
@@ -934,132 +1110,133 @@ const b = class {
934
1110
  * @param level the LOD level to load. Level 0 is the best quality, higher levels are lower quality
935
1111
  * @returns Promise with true if the LOD was loaded, false if not
936
1112
  */
937
- loadProgressiveMeshes(t, e) {
938
- if (!t)
1113
+ loadProgressiveMeshes(e, t) {
1114
+ if (!e)
939
1115
  return Promise.resolve(null);
940
- let s = t[Q] !== e;
941
- const n = t["DEBUG:LOD"];
942
- if (n != null && (s = t[Q] != n, e = n), s) {
943
- t[Q] = e;
944
- const r = t.geometry, i = T.assignMeshLOD(t, e).then((a) => (a && t[Q] == e && r != t.geometry && this._lodchangedlisteners.forEach((l) => l({ type: "mesh", level: e, object: t })), a));
945
- return ye.addPromise("mesh", t, i, this._newPromiseGroups), i;
1116
+ let s = e[J] !== t;
1117
+ const i = e["DEBUG:LOD"];
1118
+ if (i != null && (s = e[J] != i, t = i), s) {
1119
+ e[J] = t;
1120
+ const r = e.geometry, n = C.assignMeshLOD(e, t).then((a) => (a && e[J] == t && r != e.geometry && this._lodchangedlisteners.forEach((l) => l({ type: "mesh", level: t, object: e })), a));
1121
+ return Le.addPromise("mesh", e, n, this._newPromiseGroups), n;
946
1122
  }
947
1123
  return Promise.resolve(null);
948
1124
  }
949
- static isInside(t, e) {
950
- const s = t.min, n = t.max, r = (s.x + n.x) * 0.5, i = (s.y + n.y) * 0.5;
951
- return this._tempPtInside.set(r, i, s.z).applyMatrix4(e).z < 0;
1125
+ static isInside(e, t) {
1126
+ const s = e.min, i = e.max, r = (s.x + i.x) * 0.5, n = (s.y + i.y) * 0.5;
1127
+ return this._tempPtInside.set(r, n, s.z).applyMatrix4(t).z < 0;
952
1128
  }
953
- calculateLodLevel(t, e, s, n, r) {
954
- var M, R, Z;
955
- if (!e) {
1129
+ // #region calculateLodLevel
1130
+ calculateLodLevel(e, t, s, i, r) {
1131
+ var B, b, c, v;
1132
+ if (!t) {
956
1133
  r.mesh_lod = -1, r.texture_lod = -1;
957
1134
  return;
958
1135
  }
959
- if (!t) {
1136
+ if (!e) {
960
1137
  r.mesh_lod = -1, r.texture_lod = -1;
961
1138
  return;
962
1139
  }
963
1140
  let a = 10 + 1, l = !1;
964
- if (F && e["DEBUG:LOD"] != null)
965
- return e["DEBUG:LOD"];
966
- const c = (M = T.getMeshLODExtension(e.geometry)) == null ? void 0 : M.lods, d = T.getPrimitiveIndex(e.geometry), h = c && c.length > 0, f = T.getMaterialMinMaxLODsCount(e.material), w = (f == null ? void 0 : f.min_count) != 1 / 0 && f.min_count > 0 && f.max_count > 0;
967
- if (!h && !w) {
1141
+ if (z && t["DEBUG:LOD"] != null)
1142
+ return t["DEBUG:LOD"];
1143
+ const u = (B = C.getMeshLODExtension(t.geometry)) == null ? void 0 : B.lods, f = C.getPrimitiveIndex(t.geometry), m = u && u.length > 0, _ = C.getMaterialMinMaxLODsCount(t.material), w = _.min_count !== 1 / 0 && _.min_count >= 0 && _.max_count >= 0;
1144
+ if (!m && !w) {
968
1145
  r.mesh_lod = 0, r.texture_lod = 0;
969
1146
  return;
970
1147
  }
971
- h || (l = !0, a = 0);
972
- const v = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
973
- let P = e.geometry.boundingBox;
974
- if (e.type === "SkinnedMesh") {
975
- const g = e;
976
- if (!g.boundingBox)
977
- g.computeBoundingBox();
1148
+ m || (l = !0, a = 0);
1149
+ const O = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
1150
+ let M = t.geometry.boundingBox;
1151
+ if (t.type === "SkinnedMesh") {
1152
+ const h = t;
1153
+ if (!h.boundingBox)
1154
+ h.computeBoundingBox();
978
1155
  else if (this.skinnedMeshAutoUpdateBoundsInterval > 0) {
979
- if (!g[b.$skinnedMeshBoundsOffset]) {
980
- const E = b.skinnedMeshBoundsFrameOffsetCounter++;
981
- g[b.$skinnedMeshBoundsOffset] = E;
1156
+ if (!h[A.$skinnedMeshBoundsOffset]) {
1157
+ const T = A.skinnedMeshBoundsFrameOffsetCounter++;
1158
+ h[A.$skinnedMeshBoundsOffset] = T;
982
1159
  }
983
- const x = g[b.$skinnedMeshBoundsOffset];
984
- if ((s.frames + x) % this.skinnedMeshAutoUpdateBoundsInterval === 0) {
985
- const E = ce(g), U = g.geometry;
986
- E && (g.geometry = E), g.computeBoundingBox(), g.geometry = U;
1160
+ const L = h[A.$skinnedMeshBoundsOffset];
1161
+ if ((s.frames + L) % this.skinnedMeshAutoUpdateBoundsInterval === 0) {
1162
+ const T = ge(h), U = h.geometry;
1163
+ T && (h.geometry = T), h.computeBoundingBox(), h.geometry = U;
987
1164
  }
988
1165
  }
989
- P = g.boundingBox;
1166
+ M = h.boundingBox;
990
1167
  }
991
- if (P) {
992
- const g = t;
993
- if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
994
- this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
995
- const p = t.getWorldPosition(this._tempWorldPosition);
996
- if (this._sphere.containsPoint(p)) {
1168
+ if (M) {
1169
+ const h = e;
1170
+ if (t.geometry.attributes.color && t.geometry.attributes.color.count < 100 && t.geometry.boundingSphere) {
1171
+ this._sphere.copy(t.geometry.boundingSphere), this._sphere.applyMatrix4(t.matrixWorld);
1172
+ const g = e.getWorldPosition(this._tempWorldPosition);
1173
+ if (this._sphere.containsPoint(g)) {
997
1174
  r.mesh_lod = 0, r.texture_lod = 0;
998
1175
  return;
999
1176
  }
1000
1177
  }
1001
- if (this._tempBox.copy(P), this._tempBox.applyMatrix4(e.matrixWorld), g.isPerspectiveCamera && b.isInside(this._tempBox, this.projectionScreenMatrix)) {
1178
+ if (this._tempBox.copy(M), this._tempBox.applyMatrix4(t.matrixWorld), h.isPerspectiveCamera && A.isInside(this._tempBox, this.projectionScreenMatrix)) {
1002
1179
  r.mesh_lod = 0, r.texture_lod = 0;
1003
1180
  return;
1004
1181
  }
1005
- if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && g.isPerspectiveCamera && g.fov > 70) {
1006
- const p = this._tempBox.min, _ = this._tempBox.max;
1007
- let $ = p.x, A = p.y, z = _.x, ne = _.y;
1008
- const fe = 2, ve = 1.5, he = (p.x + _.x) * 0.5, ge = (p.y + _.y) * 0.5;
1009
- $ = ($ - he) * fe + he, A = (A - ge) * fe + ge, z = (z - he) * fe + he, ne = (ne - ge) * fe + ge;
1010
- const Ke = $ < 0 && z > 0 ? 0 : Math.min(Math.abs(p.x), Math.abs(_.x)), Ye = A < 0 && ne > 0 ? 0 : Math.min(Math.abs(p.y), Math.abs(_.y)), De = Math.max(Ke, Ye);
1011
- s.lastCentrality = (ve - De) * (ve - De) * (ve - De);
1182
+ if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && h.isPerspectiveCamera && h.fov > 70) {
1183
+ const g = this._tempBox.min, y = this._tempBox.max;
1184
+ let I = g.x, R = g.y, X = y.x, le = y.y;
1185
+ const pe = 2, De = 1.5, me = (g.x + y.x) * 0.5, ye = (g.y + y.y) * 0.5;
1186
+ I = (I - me) * pe + me, R = (R - ye) * pe + ye, X = (X - me) * pe + me, le = (le - ye) * pe + ye;
1187
+ const Ze = I < 0 && X > 0 ? 0 : Math.min(Math.abs(g.x), Math.abs(y.x)), et = R < 0 && le > 0 ? 0 : Math.min(Math.abs(g.y), Math.abs(y.y)), be = Math.max(Ze, et);
1188
+ s.lastCentrality = (De - be) * (De - be) * (De - be);
1012
1189
  } else
1013
1190
  s.lastCentrality = 1;
1014
- const x = this._tempBox.getSize(this._tempBoxSize);
1015
- x.multiplyScalar(0.5), screen.availHeight > 0 && v > 0 && x.multiplyScalar(v / screen.availHeight), t.isPerspectiveCamera ? x.x *= t.aspect : t.isOrthographicCamera;
1016
- const E = t.matrixWorldInverse, U = this._tempBox2;
1017
- U.copy(P), U.applyMatrix4(e.matrixWorld), U.applyMatrix4(E);
1018
- const S = U.getSize(this._tempBox2Size), ee = Math.max(S.x, S.y);
1019
- if (Math.max(x.x, x.y) != 0 && ee != 0 && (x.z = S.z / Math.max(S.x, S.y) * Math.max(x.x, x.y)), s.lastScreenCoverage = Math.max(x.x, x.y, x.z), s.lastScreenspaceVolume.copy(x), s.lastScreenCoverage *= s.lastCentrality, F && b.debugDrawLine) {
1020
- const p = this.tempMatrix.copy(this.projectionScreenMatrix);
1021
- p.invert();
1022
- const _ = b.corner0, $ = b.corner1, A = b.corner2, z = b.corner3;
1023
- _.copy(this._tempBox.min), $.copy(this._tempBox.max), $.x = _.x, A.copy(this._tempBox.max), A.y = _.y, z.copy(this._tempBox.max);
1024
- const ne = (_.z + z.z) * 0.5;
1025
- _.z = $.z = A.z = z.z = ne, _.applyMatrix4(p), $.applyMatrix4(p), A.applyMatrix4(p), z.applyMatrix4(p), b.debugDrawLine(_, $, 255), b.debugDrawLine(_, A, 255), b.debugDrawLine($, z, 255), b.debugDrawLine(A, z, 255);
1191
+ const L = this._tempBox.getSize(this._tempBoxSize);
1192
+ L.multiplyScalar(0.5), screen.availHeight > 0 && O > 0 && L.multiplyScalar(O / screen.availHeight), e.isPerspectiveCamera ? L.x *= e.aspect : e.isOrthographicCamera;
1193
+ const T = e.matrixWorldInverse, U = this._tempBox2;
1194
+ U.copy(M), U.applyMatrix4(t.matrixWorld), U.applyMatrix4(T);
1195
+ const k = U.getSize(this._tempBox2Size), te = Math.max(k.x, k.y);
1196
+ if (Math.max(L.x, L.y) != 0 && te != 0 && (L.z = k.z / Math.max(k.x, k.y) * Math.max(L.x, L.y)), s.lastScreenCoverage = Math.max(L.x, L.y, L.z), s.lastScreenspaceVolume.copy(L), s.lastScreenCoverage *= s.lastCentrality, z && A.debugDrawLine) {
1197
+ const g = this.tempMatrix.copy(this.projectionScreenMatrix);
1198
+ g.invert();
1199
+ const y = A.corner0, I = A.corner1, R = A.corner2, X = A.corner3;
1200
+ y.copy(this._tempBox.min), I.copy(this._tempBox.max), I.x = y.x, R.copy(this._tempBox.max), R.y = y.y, X.copy(this._tempBox.max);
1201
+ const le = (y.z + X.z) * 0.5;
1202
+ y.z = I.z = R.z = X.z = le, y.applyMatrix4(g), I.applyMatrix4(g), R.applyMatrix4(g), X.applyMatrix4(g), A.debugDrawLine(y, I, 255), A.debugDrawLine(y, R, 255), A.debugDrawLine(I, X, 255), A.debugDrawLine(R, X, 255);
1026
1203
  }
1027
- let D = 999;
1028
- if (c && s.lastScreenCoverage > 0)
1029
- for (let p = 0; p < c.length; p++) {
1030
- const _ = c[p], A = (((R = _.densities) == null ? void 0 : R[d]) || _.density || 1e-5) / s.lastScreenCoverage;
1031
- if (d > 0 && Ge() && !_.densities && !globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] && (window["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] = !0, console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")), A < n) {
1032
- D = p;
1204
+ let S = 999;
1205
+ if (u && s.lastScreenCoverage > 0)
1206
+ for (let g = 0; g < u.length; g++) {
1207
+ const y = u[g], R = (((b = y.densities) == null ? void 0 : b[f]) || y.density || 1e-5) / s.lastScreenCoverage;
1208
+ if (f > 0 && Ne() && !y.densities && !globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] && (window["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] = !0, console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")), R < i) {
1209
+ S = g;
1033
1210
  break;
1034
1211
  }
1035
1212
  }
1036
- D < a && (a = D, l = !0);
1213
+ S < a && (a = S, l = !0);
1037
1214
  }
1038
- if (l ? r.mesh_lod = a : r.mesh_lod = s.lastLodLevel_Mesh, F && r.mesh_lod != s.lastLodLevel_Mesh) {
1039
- const x = c == null ? void 0 : c[r.mesh_lod];
1040
- x && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${r.mesh_lod} (${x.density.toFixed(0)}) - ${e.name}`);
1215
+ if (l ? r.mesh_lod = a : r.mesh_lod = s.lastLodLevel_Mesh, z && r.mesh_lod != s.lastLodLevel_Mesh) {
1216
+ const L = u == null ? void 0 : u[r.mesh_lod];
1217
+ L && console.debug(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${r.mesh_lod} (density: ${(c = L.densities) == null ? void 0 : c[f].toFixed(0)}) | ${t.name}`);
1041
1218
  }
1042
1219
  if (w) {
1043
- const g = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
1220
+ const h = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
1044
1221
  if (s.lastLodLevel_Texture < 0) {
1045
- if (r.texture_lod = f.max_count - 1, F) {
1046
- const x = f.lods[f.max_count - 1];
1047
- F && console.log(`First Texture LOD ${r.texture_lod} (${x.max_height}px) - ${e.name}`);
1222
+ if (r.texture_lod = _.max_count - 1, z) {
1223
+ const L = _.lods[_.max_count - 1];
1224
+ z && console.log(`First Texture LOD ${r.texture_lod} (${L.max_height}px) - ${t.name}`);
1048
1225
  }
1049
1226
  } else {
1050
- const x = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
1051
- let E = s.lastScreenCoverage * 4;
1052
- ((Z = this.context) == null ? void 0 : Z.engine) === "model-viewer" && (E *= 1.5);
1053
- const S = v / window.devicePixelRatio * E;
1054
- let ee = !1;
1055
- for (let I = f.lods.length - 1; I >= 0; I--) {
1056
- const D = f.lods[I];
1057
- if (!(g && D.max_height >= 2048) && !(ct() && D.max_height > 4096) && (D.max_height > S || !ee && I === 0)) {
1058
- if (ee = !0, r.texture_lod = I, r.texture_lod < s.lastLodLevel_Texture) {
1059
- const m = D.max_height;
1060
- F && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${r.texture_lod} = ${m}px
1061
- Screensize: ${S.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${x.toFixed(1)}
1062
- ${e.name}`);
1227
+ const L = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
1228
+ let T = s.lastScreenCoverage * 4;
1229
+ ((v = this.context) == null ? void 0 : v.engine) === "model-viewer" && (T *= 1.5);
1230
+ const k = O / window.devicePixelRatio * T;
1231
+ let te = !1;
1232
+ for (let G = _.lods.length - 1; G >= 0; G--) {
1233
+ const S = _.lods[G];
1234
+ if (!(h && S.max_height >= 2048) && !(je() && S.max_height > 4096) && (S.max_height > k || !te && G === 0)) {
1235
+ if (te = !0, r.texture_lod = G, z && r.texture_lod < s.lastLodLevel_Texture) {
1236
+ const p = S.max_height;
1237
+ console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${r.texture_lod} = ${p}px
1238
+ Screensize: ${k.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${L.toFixed(1)}
1239
+ ${t.name}`);
1063
1240
  }
1064
1241
  break;
1065
1242
  }
@@ -1069,70 +1246,70 @@ ${e.name}`);
1069
1246
  r.texture_lod = 0;
1070
1247
  }
1071
1248
  };
1072
- let C = b;
1073
- B = new WeakMap(), K = new WeakMap(), we = new WeakMap(), J = new WeakMap(), ie = new WeakMap(), _e = new WeakMap(), Y = new WeakMap(), /**
1249
+ let $ = A;
1250
+ F = new WeakMap(), j = new WeakMap(), Me = new WeakMap(), ee = new WeakMap(), ae = new WeakMap(), ve = new WeakMap(), H = new WeakMap(), /**
1074
1251
  * 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.
1075
1252
  */
1076
- u(C, "debugDrawLine"), /**
1253
+ d($, "debugDrawLine"), /**
1077
1254
  * Force override the LOD level for all objects in the scene
1078
1255
  */
1079
- u(C, "overrideGlobalLodLevel"), u(C, "corner0", new W()), u(C, "corner1", new W()), u(C, "corner2", new W()), u(C, "corner3", new W()), u(C, "_tempPtInside", new W()), u(C, "skinnedMeshBoundsFrameOffsetCounter", 0), u(C, "$skinnedMeshBoundsOffset", Symbol("gltf-progressive-skinnedMeshBoundsOffset"));
1080
- class xt {
1256
+ d($, "overrideGlobalLodLevel"), d($, "corner0", new W()), d($, "corner1", new W()), d($, "corner2", new W()), d($, "corner3", new W()), d($, "_tempPtInside", new W()), d($, "skinnedMeshBoundsFrameOffsetCounter", 0), d($, "$skinnedMeshBoundsOffset", Symbol("gltf-progressive-skinnedMeshBoundsOffset"));
1257
+ class Rt {
1081
1258
  constructor() {
1082
- u(this, "frames", 0);
1083
- u(this, "lastLodLevel_Mesh", -1);
1084
- u(this, "lastLodLevel_Texture", -1);
1085
- u(this, "lastScreenCoverage", 0);
1086
- u(this, "lastScreenspaceVolume", new W());
1087
- u(this, "lastCentrality", 0);
1259
+ d(this, "frames", 0);
1260
+ d(this, "lastLodLevel_Mesh", -1);
1261
+ d(this, "lastLodLevel_Texture", -1);
1262
+ d(this, "lastScreenCoverage", 0);
1263
+ d(this, "lastScreenspaceVolume", new W());
1264
+ d(this, "lastCentrality", 0);
1088
1265
  }
1089
1266
  }
1090
- const Be = Symbol("NEEDLE_mesh_lod"), pe = Symbol("NEEDLE_texture_lod");
1091
- let ue = null;
1092
- function We() {
1093
- const o = wt();
1094
- o && (o.mapURLs(function(t) {
1095
- return ke(), t;
1096
- }), ke(), ue == null || ue.disconnect(), ue = new MutationObserver((t) => {
1097
- t.forEach((e) => {
1098
- e.addedNodes.forEach((s) => {
1099
- s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && Xe(s);
1267
+ const Ue = Symbol("NEEDLE_mesh_lod"), xe = Symbol("NEEDLE_texture_lod");
1268
+ let fe = null;
1269
+ function Qe() {
1270
+ const o = $t();
1271
+ o && (o.mapURLs(function(e) {
1272
+ return We(), e;
1273
+ }), We(), fe == null || fe.disconnect(), fe = new MutationObserver((e) => {
1274
+ e.forEach((t) => {
1275
+ t.addedNodes.forEach((s) => {
1276
+ s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && Je(s);
1100
1277
  });
1101
1278
  });
1102
- }), ue.observe(document, { childList: !0, subtree: !0 }));
1279
+ }), fe.observe(document, { childList: !0, subtree: !0 }));
1103
1280
  }
1104
- function wt() {
1281
+ function $t() {
1105
1282
  if (typeof customElements > "u")
1106
1283
  return null;
1107
1284
  const o = customElements.get("model-viewer");
1108
1285
  return o || (customElements.whenDefined("model-viewer").then(() => {
1109
- console.debug("[gltf-progressive] model-viewer defined"), We();
1286
+ console.debug("[gltf-progressive] model-viewer defined"), Qe();
1110
1287
  }), null);
1111
1288
  }
1112
- function ke() {
1289
+ function We() {
1113
1290
  if (typeof document > "u")
1114
1291
  return;
1115
- document.querySelectorAll("model-viewer").forEach((t) => {
1116
- Xe(t);
1292
+ document.querySelectorAll("model-viewer").forEach((e) => {
1293
+ Je(e);
1117
1294
  });
1118
1295
  }
1119
- const Re = /* @__PURE__ */ new WeakSet();
1120
- let _t = 0;
1121
- function Xe(o) {
1122
- if (!o || Re.has(o))
1296
+ const ze = /* @__PURE__ */ new WeakSet();
1297
+ let Gt = 0;
1298
+ function Je(o) {
1299
+ if (!o || ze.has(o))
1123
1300
  return null;
1124
- Re.add(o), console.debug("[gltf-progressive] found new model-viewer..." + ++_t + `
1301
+ ze.add(o), console.debug("[gltf-progressive] found new model-viewer..." + ++Gt + `
1125
1302
  `, o.getAttribute("src"));
1126
- let t = null, e = null, s = null;
1127
- for (let n = o; n != null; n = Object.getPrototypeOf(n)) {
1128
- const r = Object.getOwnPropertySymbols(n), i = r.find((c) => c.toString() == "Symbol(renderer)"), a = r.find((c) => c.toString() == "Symbol(scene)"), l = r.find((c) => c.toString() == "Symbol(needsRender)");
1129
- !t && i != null && (t = o[i].threeRenderer), !e && a != null && (e = o[a]), !s && l != null && (s = o[l]);
1303
+ let e = null, t = null, s = null;
1304
+ for (let i = o; i != null; i = Object.getPrototypeOf(i)) {
1305
+ const r = Object.getOwnPropertySymbols(i), n = r.find((u) => u.toString() == "Symbol(renderer)"), a = r.find((u) => u.toString() == "Symbol(scene)"), l = r.find((u) => u.toString() == "Symbol(needsRender)");
1306
+ !e && n != null && (e = o[n].threeRenderer), !t && a != null && (t = o[a]), !s && l != null && (s = o[l]);
1130
1307
  }
1131
- if (t && e) {
1132
- let n = function() {
1308
+ if (e && t) {
1309
+ let i = function() {
1133
1310
  if (s) {
1134
- let i = 0, a = setInterval(() => {
1135
- if (i++ > 5) {
1311
+ let n = 0, a = setInterval(() => {
1312
+ if (n++ > 5) {
1136
1313
  clearInterval(a);
1137
1314
  return;
1138
1315
  }
@@ -1141,129 +1318,129 @@ function Xe(o) {
1141
1318
  }
1142
1319
  };
1143
1320
  console.debug("[gltf-progressive] setup model-viewer");
1144
- const r = C.get(t, { engine: "model-viewer" });
1145
- return C.addPlugin(new vt()), r.enable(), r.addEventListener("changed", () => {
1321
+ const r = $.get(e, { engine: "model-viewer" });
1322
+ return $.addPlugin(new Et()), r.enable(), r.addEventListener("changed", () => {
1146
1323
  s == null || s.call(o);
1147
- }), o.addEventListener("model-visibility", (i) => {
1148
- i.detail.visible && (s == null || s.call(o));
1324
+ }), o.addEventListener("model-visibility", (n) => {
1325
+ n.detail.visible && (s == null || s.call(o));
1149
1326
  }), o.addEventListener("load", () => {
1150
- n();
1327
+ i();
1151
1328
  }), () => {
1152
1329
  r.disable();
1153
1330
  };
1154
1331
  }
1155
1332
  return null;
1156
1333
  }
1157
- class vt {
1334
+ class Et {
1158
1335
  constructor() {
1159
- u(this, "_didWarnAboutMissingUrl", !1);
1336
+ d(this, "_didWarnAboutMissingUrl", !1);
1160
1337
  }
1161
- onBeforeUpdateLOD(t, e, s, n) {
1162
- this.tryParseMeshLOD(e, n), this.tryParseTextureLOD(e, n);
1338
+ onBeforeUpdateLOD(e, t, s, i) {
1339
+ this.tryParseMeshLOD(t, i), this.tryParseTextureLOD(t, i);
1163
1340
  }
1164
- getUrl(t) {
1165
- if (!t)
1341
+ getUrl(e) {
1342
+ if (!e)
1166
1343
  return null;
1167
- let e = t.getAttribute("src");
1168
- return e || (e = t.src), e || (this._didWarnAboutMissingUrl || console.warn("No url found in modelviewer", t), this._didWarnAboutMissingUrl = !0), e;
1344
+ let t = e.getAttribute("src");
1345
+ return t || (t = e.src), t || (this._didWarnAboutMissingUrl || console.warn("No url found in modelviewer", e), this._didWarnAboutMissingUrl = !0), t;
1169
1346
  }
1170
- tryGetCurrentGLTF(t) {
1171
- return t._currentGLTF;
1347
+ tryGetCurrentGLTF(e) {
1348
+ return e._currentGLTF;
1172
1349
  }
1173
- tryGetCurrentModelViewer(t) {
1174
- return t.element;
1350
+ tryGetCurrentModelViewer(e) {
1351
+ return e.element;
1175
1352
  }
1176
- tryParseTextureLOD(t, e) {
1177
- if (e[pe] == !0)
1353
+ tryParseTextureLOD(e, t) {
1354
+ if (t[xe] == !0)
1178
1355
  return;
1179
- e[pe] = !0;
1180
- const s = this.tryGetCurrentGLTF(t), n = this.tryGetCurrentModelViewer(t), r = this.getUrl(n);
1181
- if (r && s && e.material) {
1182
- let i = function(l) {
1183
- var d, h, f;
1184
- if (l[pe] == !0)
1356
+ t[xe] = !0;
1357
+ const s = this.tryGetCurrentGLTF(e), i = this.tryGetCurrentModelViewer(e), r = this.getUrl(i);
1358
+ if (r && s && t.material) {
1359
+ let n = function(l) {
1360
+ var f, m, _;
1361
+ if (l[xe] == !0)
1185
1362
  return;
1186
- l[pe] = !0, l.userData && (l.userData.LOD = -1);
1187
- const c = Object.keys(l);
1188
- for (let w = 0; w < c.length; w++) {
1189
- const v = c[w], P = l[v];
1190
- if ((P == null ? void 0 : P.isTexture) === !0) {
1191
- const M = (h = (d = P.userData) == null ? void 0 : d.associations) == null ? void 0 : h.textures;
1192
- if (M == null)
1363
+ l[xe] = !0, l.userData && (l.userData.LOD = -1);
1364
+ const u = Object.keys(l);
1365
+ for (let w = 0; w < u.length; w++) {
1366
+ const O = u[w], M = l[O];
1367
+ if ((M == null ? void 0 : M.isTexture) === !0) {
1368
+ const B = (m = (f = M.userData) == null ? void 0 : f.associations) == null ? void 0 : m.textures;
1369
+ if (B == null)
1193
1370
  continue;
1194
- const R = s.parser.json.textures[M];
1195
- if (!R) {
1196
- console.warn("Texture data not found for texture index " + M);
1371
+ const b = s.parser.json.textures[B];
1372
+ if (!b) {
1373
+ console.warn("Texture data not found for texture index " + B);
1197
1374
  continue;
1198
1375
  }
1199
- if ((f = R == null ? void 0 : R.extensions) != null && f[X]) {
1200
- const Z = R.extensions[X];
1201
- Z && r && T.registerTexture(r, P, Z.lods.length, M, Z);
1376
+ if ((_ = b == null ? void 0 : b.extensions) != null && _[Y]) {
1377
+ const c = b.extensions[Y];
1378
+ c && r && C.registerTexture(r, M, c.lods.length, B, c);
1202
1379
  }
1203
1380
  }
1204
1381
  }
1205
1382
  };
1206
- const a = e.material;
1383
+ const a = t.material;
1207
1384
  if (Array.isArray(a))
1208
1385
  for (const l of a)
1209
- i(l);
1386
+ n(l);
1210
1387
  else
1211
- i(a);
1388
+ n(a);
1212
1389
  }
1213
1390
  }
1214
- tryParseMeshLOD(t, e) {
1215
- var i, a;
1216
- if (e[Be] == !0)
1391
+ tryParseMeshLOD(e, t) {
1392
+ var n, a;
1393
+ if (t[Ue] == !0)
1217
1394
  return;
1218
- e[Be] = !0;
1219
- const s = this.tryGetCurrentModelViewer(t), n = this.getUrl(s);
1220
- if (!n)
1395
+ t[Ue] = !0;
1396
+ const s = this.tryGetCurrentModelViewer(e), i = this.getUrl(s);
1397
+ if (!i)
1221
1398
  return;
1222
- const r = (a = (i = e.userData) == null ? void 0 : i.gltfExtensions) == null ? void 0 : a[X];
1223
- if (r && n) {
1224
- const l = e.uuid;
1225
- T.registerMesh(n, l, e, 0, r.lods.length, r);
1399
+ const r = (a = (n = t.userData) == null ? void 0 : n.gltfExtensions) == null ? void 0 : a[Y];
1400
+ if (r && i) {
1401
+ const l = t.uuid;
1402
+ C.registerMesh(i, l, t, 0, r.lods.length, r);
1226
1403
  }
1227
1404
  }
1228
1405
  }
1229
- function Dt(o, t, e, s) {
1230
- Ue(t), ze(e), Ve(e, {
1406
+ function Ft(o, e, t, s) {
1407
+ $e(e), Xe(t), Ye(t, {
1231
1408
  progressive: !0,
1232
1409
  ...s == null ? void 0 : s.hints
1233
- }), e.register((r) => new T(r, o));
1234
- const n = C.get(t);
1235
- return (s == null ? void 0 : s.enableLODsManager) !== !1 && n.enable(), n;
1410
+ }), t.register((r) => new C(r, o));
1411
+ const i = $.get(e);
1412
+ return (s == null ? void 0 : s.enableLODsManager) !== !1 && i.enable(), i;
1236
1413
  }
1237
- We();
1238
- if (!ht) {
1414
+ Qe();
1415
+ if (!vt) {
1239
1416
  const o = {
1240
1417
  gltfProgressive: {
1241
- useNeedleProgressive: Dt,
1242
- LODsManager: C,
1243
- configureLoader: Ve,
1244
- getRaycastMesh: ce,
1245
- useRaycastMeshes: pt
1418
+ useNeedleProgressive: Ft,
1419
+ LODsManager: $,
1420
+ configureLoader: Ye,
1421
+ getRaycastMesh: ge,
1422
+ useRaycastMeshes: bt
1246
1423
  }
1247
1424
  };
1248
1425
  if (!globalThis.Needle)
1249
1426
  globalThis.Needle = o;
1250
1427
  else
1251
- for (const t in o)
1252
- globalThis.Needle[t] = o[t];
1428
+ for (const e in o)
1429
+ globalThis.Needle[e] = o[e];
1253
1430
  }
1254
1431
  export {
1255
- X as EXTENSION_NAME,
1256
- C as LODsManager,
1257
- T as NEEDLE_progressive,
1258
- it as VERSION,
1259
- ze as addDracoAndKTX2Loaders,
1260
- Ve as configureLoader,
1261
- Ue as createLoaders,
1262
- ce as getRaycastMesh,
1263
- We as patchModelViewer,
1264
- gt as registerRaycastMesh,
1265
- at as setDracoDecoderLocation,
1266
- lt as setKTX2TranscoderLocation,
1267
- Dt as useNeedleProgressive,
1268
- pt as useRaycastMeshes
1432
+ Y as EXTENSION_NAME,
1433
+ $ as LODsManager,
1434
+ C as NEEDLE_progressive,
1435
+ gt as VERSION,
1436
+ Xe as addDracoAndKTX2Loaders,
1437
+ Ye as configureLoader,
1438
+ $e as createLoaders,
1439
+ ge as getRaycastMesh,
1440
+ Qe as patchModelViewer,
1441
+ Dt as registerRaycastMesh,
1442
+ xt as setDracoDecoderLocation,
1443
+ wt as setKTX2TranscoderLocation,
1444
+ Ft as useNeedleProgressive,
1445
+ bt as useRaycastMeshes
1269
1446
  };