@needle-tools/gltf-progressive 3.1.0 → 3.1.1-next.80f25bb

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