@needle-tools/gltf-progressive 3.1.1-next.50e45f8 → 3.1.1-next.7384486

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