@needle-tools/gltf-progressive 3.1.0-next.f550970 → 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 He = Object.defineProperty;
2
- var Qe = (o, t, e) => t in o ? He(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
3
- var u = (o, t, e) => (Qe(o, typeof t != "symbol" ? t + "" : t, e), e), Ee = (o, t, e) => {
4
- if (!t.has(o))
5
- throw TypeError("Cannot " + e);
1
+ var 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 L = (o, t, e) => (Ee(o, t, "read from private field"), e ? e.call(o) : t.get(o)), H = (o, t, e) => {
8
- if (t.has(o))
7
+ var 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
- }, V = (o, t, e, s) => (Ee(o, t, "write to private field"), s ? s.call(o, e) : t.set(o, e), e);
12
- import { BufferGeometry as Le, Mesh as se, Texture as oe, TextureLoader as je, Matrix4 as Ie, Clock as Je, MeshStandardMaterial as Ze, Sphere as et, Box3 as $e, Vector3 as W } from "three";
13
- import { GLTFLoader as Ce } from "three/examples/jsm/loaders/GLTFLoader.js";
14
- import { MeshoptDecoder as tt } from "three/examples/jsm/libs/meshopt_decoder.module.js";
15
- import { DRACOLoader as st } from "three/examples/jsm/loaders/DRACOLoader.js";
16
- import { KTX2Loader as rt } from "three/examples/jsm/loaders/KTX2Loader.js";
17
- const it = "";
18
- globalThis.GLTF_PROGRESSIVE_VERSION = it;
10
+ e instanceof WeakSet ? e.add(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 q = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", re = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
21
- const nt = q, ot = re, Fe = new URL(q + "draco_decoder.js");
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
22
  Fe.searchParams.append("range", "true");
23
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 ${q} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), q === nt && at("./include/draco/"), re === ot && lt("./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
- Ne();
31
+ Ue();
32
32
  });
33
- function at(o) {
34
- q = o, k && k[Pe] != q ? (console.debug("Updating Draco decoder path to " + o), k[Pe] = q, k.setDecoderPath(q), k.preload()) : console.debug("Setting Draco decoder path to " + o);
33
+ const 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 lt(o) {
37
- re = o, N && N.transcoderPath != re ? (console.debug("Updating KTX2 transcoder path to " + o), N.setTranscoderPath(re), N.init()) : console.debug("Setting KTX2 transcoder path to " + o);
40
+ function 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 k, xe, N;
41
- function Ne() {
42
- k || (k = new st(), k[Pe] = q, k.setDecoderPath(q), k.setDecoderConfig({ type: "js" }), k.preload()), N || (N = new rt(), N.setTranscoderPath(re), N.init()), xe || (xe = tt);
43
+ function 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 Ne(), o ? N.detectSupport(o) : o !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: k, ktx2Loader: N, meshoptDecoder: xe };
46
+ function Ee(n) {
47
+ n.dracoLoader || n.setDRACOLoader(K), n.ktx2Loader || n.setKTX2Loader(Y), n.meshoptDecoder || n.setMeshoptDecoder(xe);
46
48
  }
47
- function ze(o) {
48
- o.dracoLoader || o.setDRACOLoader(k), o.ktx2Loader || o.setKTX2Loader(N), o.meshoptDecoder || o.setMeshoptDecoder(xe);
49
+ const ke = Symbol("dracoDecoderPath");
50
+ let 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 Ve(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 Me = Ce.prototype.load;
56
- function ut(...o) {
57
- const t = Te.get(this);
58
- let e = o[0];
59
- const s = new URL(e, window.location.href);
59
+ const 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, Me == null ? void 0 : Me.call(this, ...o);
68
+ return n[0] = t, Me == null ? void 0 : Me.call(this, ...n);
65
69
  }
66
- Ce.prototype.load = ut;
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 dt(o, t) {
75
- if (t === void 0 || t.startsWith("./") || t.startsWith("http") || o === void 0)
76
- return t;
77
- const e = o.lastIndexOf("/");
78
- if (e >= 0) {
79
- const s = o.substring(0, e + 1);
80
- for (; s.endsWith("/") && t.startsWith("/"); )
81
- t = t.substring(1);
82
- return s + t;
83
- }
84
- return t;
78
+ function 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 ct() {
88
- return ae !== void 0 || (ae = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), de("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", ae)), ae;
90
+ let 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 Ge() {
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 finished now running: ${this._running.size}, waiting: ${this._queue.length}. (finished ${t})`);
117
- }), this.debug && console.debug(`[PromiseQueue]: Added new promise, now running: ${this._running.size}, waiting: ${this._queue.length}. (added ${t})`));
118
+ add(e, t) {
119
+ this._running.has(e) || (this._running.set(e, t), t.finally(() => {
120
+ this._running.delete(e), this.debug && console.debug(`[PromiseQueue]: Promise finished now running: ${this._running.size}, waiting: ${this._queue.length}. (finished ${e})`);
121
+ }), this.debug && console.debug(`[PromiseQueue]: Added new promise, now running: ${this._running.size}, waiting: ${this._queue.length}. (added ${e})`));
118
122
  }
119
123
  internalUpdate() {
120
- const t = this.maxConcurrent - this._running.size;
121
- for (let e = 0; e < t && this._queue.length > 0; e++) {
124
+ const e = this.maxConcurrent - this._running.size;
125
+ for (let t = 0; t < e && this._queue.length > 0; t++) {
122
126
  this.debug && console.debug(`[PromiseQueue]: Running ${this._running.size} promises, waiting for ${this._queue.length} more.`);
123
- const { key: s, resolve: n } = this._queue.shift();
124
- n({
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 Le ? 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 Le();
159
- for (const e in o.attributes)
160
- t.setAttribute(e, o.getAttribute(e));
161
- return t.setIndex(o.getIndex()), t;
160
+ let de = null;
161
+ function 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(), y = de("debugprogressive");
164
- let me, te = -1;
165
- if (y) {
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 (y)
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"), O = class {
184
- constructor(t, e) {
185
- u(this, "parser");
186
- u(this, "url");
187
- u(this, "_isLoadingMesh");
188
- u(this, "loadMesh", (t) => {
189
- var s, n;
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 && O.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
- y && 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 (y === "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 h = 0; h < d.lods.length; h++) {
245
- const f = d.lods[h];
246
- f.width && (l.lods[h] = l.lods[h] || { min_height: 1 / 0, max_height: 0 }, l.lods[h].min_height = Math.min(l.lods[h].min_height, f.height), l.lods[h].max_height = Math.max(l.lods[h].max_height, f.height));
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"), O = 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,100 +459,105 @@ const X = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), O = 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, O.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 : y && 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
- y && 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) : O.getOrLoadLOD(t, e).then((r) => {
378
- if (Array.isArray(r))
379
- return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen", r), null;
380
- if ((r == null ? void 0 : r.isTexture) === !0) {
381
- if (r != t && s && n) {
382
- const i = s[n];
383
- if (i && !y) {
384
- const a = this.getAssignedLODInformation(i);
385
- if (a && (a == null ? void 0 : a.level) < e)
386
- return y === "verbose" && console.warn("Assigned texture level is already higher: ", a.level, e, s, i, r), null;
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
- y == "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));
560
+ }).catch((i) => (console.error("Error loading LOD", e, i), null));
395
561
  }
396
562
  // private _isLoadingTexture;
397
563
  // loadTexture = (textureIndex: number) => {
@@ -407,243 +573,259 @@ const X = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), O = c
407
573
  // return tex;
408
574
  // });
409
575
  // }
410
- afterRoot(t) {
411
- var e, s;
412
- return y && console.log("AFTER", this.url, t), (e = this.parser.json.textures) == null || e.forEach((n, r) => {
413
- var i;
414
- if (n != null && n.extensions) {
415
- const a = n == null ? void 0 : n.extensions[X];
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];
416
582
  if (a) {
417
583
  if (!a.lods) {
418
- y && console.warn("Texture has no LODs", a);
584
+ C && console.warn("Texture has no LODs", a);
419
585
  return;
420
586
  }
421
587
  let l = !1;
422
- for (const c of this.parser.associations.keys())
423
- if (c.isTexture === !0) {
424
- const d = this.parser.associations.get(c);
425
- (d == null ? void 0 : d.textures) === r && (l = !0, O.registerTexture(this.url, c, (i = a.lods) == null ? void 0 : i.length, r, a));
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));
426
592
  }
427
- l || this.parser.getDependency("texture", r).then((c) => {
428
- var d;
429
- c && O.registerTexture(this.url, c, (d = a.lods) == null ? void 0 : d.length, r, a);
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);
430
596
  });
431
597
  }
432
598
  }
433
- }), (s = this.parser.json.meshes) == null || s.forEach((n, r) => {
434
- if (n != null && n.extensions) {
435
- const i = n == null ? void 0 : n.extensions[X];
436
- if (i && i.lods) {
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) {
437
603
  for (const a of this.parser.associations.keys())
438
604
  if (a.isMesh) {
439
605
  const l = this.parser.associations.get(a);
440
- (l == null ? void 0 : l.meshes) === r && O.registerMesh(this.url, i.guid, a, i.lods.length, l.primitives, i);
606
+ (l == null ? void 0 : l.meshes) === i && M.registerMesh(this.url, o.guid, a, o.lods.length, l.primitives, o);
441
607
  }
442
608
  }
443
609
  }
444
610
  }), null;
445
611
  }
446
- static async getOrLoadLOD(t, e) {
447
- var a, l, c, d;
448
- const s = y == "verbose", n = this.getAssignedLODInformation(t);
449
- if (!n)
450
- return y && console.warn(`[gltf-progressive] No LOD information found: ${t.name}, uuid: ${t.uuid}, type: ${t.type}`, t), null;
451
- const r = n == null ? void 0 : n.key;
452
- let i;
453
- if (t.isTexture === !0) {
454
- const h = t;
455
- h.source && h.source[Oe] && (i = h.source[Oe]);
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]);
456
622
  }
457
- if (i || (i = O.lodInfos.get(r)), i) {
458
- if (e > 0) {
459
- let w = !1;
460
- const v = Array.isArray(i.lods);
461
- if (v && e >= i.lods.length ? w = !0 : v || (w = !0), w)
462
- 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);
463
629
  }
464
- const h = Array.isArray(i.lods) ? (a = i.lods[e]) == null ? void 0 : a.path : i.lods;
465
- if (!h)
466
- return y && !i["missing:uri"] && (i["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, i)), null;
467
- const f = dt(n.url, h);
468
- if (f.endsWith(".glb") || f.endsWith(".gltf")) {
469
- if (!i.guid)
470
- return console.warn("missing pointer for glb/gltf texture", i), null;
471
- const w = f + "_" + i.guid, v = this.previouslyLoaded.get(w);
472
- if (v !== void 0) {
473
- s && console.log(`LOD ${e} was already loading/loaded: ${w}`);
474
- let g = await v.catch((E) => (console.error(`Error loading LOD ${e} from ${f}
475
- `, E), null)), x = !1;
476
- if (g == null || (g instanceof oe && t instanceof oe ? (l = g.image) != null && l.data || (c = g.source) != null && c.data ? g = this.copySettings(t, g) : (x = !0, this.previouslyLoaded.delete(w)) : g instanceof Le && t instanceof Le && ((d = g.attributes.position) != null && d.array || (x = !0, this.previouslyLoaded.delete(w)))), !x)
477
- return g;
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;
478
644
  }
479
- const P = await this.queue.slot(f);
480
- if (!P.use)
481
- return y && console.log(`LOD ${e} was aborted: ${f}`), null;
482
- const M = i, R = new Promise(async (g, x) => {
483
- const E = new Ce();
484
- ze(E), y && (await new Promise((D) => setTimeout(D, 1e3)), s && console.warn("Start loading (delayed) " + f, M.guid));
485
- let U = f;
486
- if (M && Array.isArray(M.lods)) {
487
- const D = M.lods[e];
488
- D.hash && (U += "?v=" + D.hash);
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);
489
671
  }
490
- const S = await E.loadAsync(U).catch((D) => (console.error(`Error loading LOD ${e} from ${f}
491
- `, D), g(null)));
492
- if (!S)
493
- return g(null);
494
- const ee = S.parser;
495
- s && console.log("Loading finished " + f, M.guid);
496
- let I = 0;
497
- if (S.parser.json.textures) {
498
- let D = !1;
499
- for (const m of S.parser.json.textures) {
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) {
500
682
  if (m != null && m.extensions) {
501
- const p = m == null ? void 0 : m.extensions[X];
502
- if (p != null && p.guid && p.guid === M.guid) {
503
- D = !0;
683
+ const h = m == null ? void 0 : m.extensions[U];
684
+ if (h != null && h.guid && h.guid === v.guid) {
685
+ Z = !0;
504
686
  break;
505
687
  }
506
688
  }
507
- I++;
689
+ W++;
508
690
  }
509
- if (D) {
510
- let m = await ee.getDependency("texture", I);
511
- return m && O.assignLODInformation(n.url, m, r, e, void 0), s && console.log('change "' + t.name + '" → "' + m.name + '"', f, I, m, w), t instanceof oe && (m = this.copySettings(t, m)), m && (m.guid = M.guid), g(m);
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);
512
694
  } else
513
- y && console.warn("Could not find texture with guid", M.guid, S.parser.json);
695
+ C && console.warn("Could not find texture with guid", v.guid, R.parser.json);
514
696
  }
515
- if (I = 0, S.parser.json.meshes) {
516
- let D = !1;
517
- 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) {
518
700
  if (m != null && m.extensions) {
519
- const p = m == null ? void 0 : m.extensions[X];
520
- if (p != null && p.guid && p.guid === M.guid) {
521
- D = !0;
701
+ const h = m == null ? void 0 : m.extensions[U];
702
+ if (h != null && h.guid && h.guid === v.guid) {
703
+ Z = !0;
522
704
  break;
523
705
  }
524
706
  }
525
- I++;
707
+ W++;
526
708
  }
527
- if (D) {
528
- const m = await ee.getDependency("mesh", I);
529
- if (s && console.log(`Loaded Mesh "${m.name}"`, f, I, m, w), m.isMesh === !0) {
530
- const p = m.geometry;
531
- return O.assignLODInformation(n.url, p, r, e, 0), g(p);
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);
532
714
  } else {
533
- const p = new Array();
534
- for (let _ = 0; _ < m.children.length; _++) {
535
- const $ = m.children[_];
536
- if ($.isMesh === !0) {
537
- const A = $.geometry;
538
- O.assignLODInformation(n.url, A, r, e, _), p.push(A);
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);
539
721
  }
540
722
  }
541
- return g(p);
723
+ return f(h);
542
724
  }
543
725
  } else
544
- y && console.warn("Could not find mesh with guid", M.guid, S.parser.json);
726
+ C && console.warn("Could not find mesh with guid", v.guid, R.parser.json);
545
727
  }
546
- return g(null);
728
+ return f(null);
547
729
  });
548
- return this.previouslyLoaded.set(w, R), P.use(R), await R;
549
- } else if (t instanceof oe) {
550
- s && console.log("Load texture from uri: " + f);
551
- const v = await new je().loadAsync(f);
552
- return v ? (v.guid = i.guid, v.flipY = !1, v.needsUpdate = !0, v.colorSpace = t.colorSpace, s && console.log(i, v)) : y && console.warn("failed loading", f), v;
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;
553
735
  }
554
736
  } else
555
- y && 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);
556
738
  return null;
557
739
  }
558
- static assignLODInformation(t, e, s, n, r) {
559
- if (!e)
740
+ static assignLODInformation(e, t, s, r, i) {
741
+ if (!t)
560
742
  return;
561
- e.userData || (e.userData = {});
562
- const i = new yt(t, s, n, r);
563
- e.userData.LODS = i, "source" in e && typeof e.source == "object" && (e.source.LODS = i);
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);
564
746
  }
565
- static getAssignedLODInformation(t) {
566
- var e, s;
567
- return t ? (e = t.userData) != null && e.LODS ? t.userData.LODS : "source" in t && ((s = t.source) != null && s.LODS) ? t.source.LODS : null : null;
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;
568
750
  }
569
751
  // private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
570
- static copySettings(t, e) {
571
- return e ? (y && console.warn(`Copy texture settings
572
- `, t.uuid, `
573
- `, e.uuid), e = e.clone(), e.offset = t.offset, e.repeat = t.repeat, e.colorSpace = t.colorSpace, e.magFilter = t.magFilter, e.minFilter = t.minFilter, e.wrapS = t.wrapS, e.wrapT = t.wrapT, e.flipY = t.flipY, e.anisotropy = t.anisotropy, e.mipmaps || (e.generateMipmaps = t.generateMipmaps), e) : t;
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;
574
756
  }
575
757
  };
576
- let T = O;
758
+ let D = M;
577
759
  /**
578
760
  * Register a texture with LOD information
579
761
  */
580
- u(T, "registerTexture", (t, e, s, n, r) => {
581
- var a, l, c, d, h, f, w, v;
582
- if (!e) {
583
- y && console.error("gltf-progressive: Called register texture without texture");
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");
584
766
  return;
585
767
  }
586
- if (y) {
587
- const P = ((a = e.image) == null ? void 0 : a.width) || ((c = (l = e.source) == null ? void 0 : l.data) == null ? void 0 : c.width) || 0, M = ((d = e.image) == null ? void 0 : d.height) || ((f = (h = e.source) == null ? void 0 : h.data) == null ? void 0 : f.height) || 0;
588
- console.log(`> Progressive: register texture[${n}] "${e.name || e.uuid}", Current: ${P}x${M}, Max: ${(w = r.lods[0]) == null ? void 0 : w.width}x${(v = r.lods[0]) == null ? void 0 : v.height}, uuid: ${e.uuid}`, r, e);
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);
589
771
  }
590
- e.source && (e.source[Oe] = r);
591
- const i = r.guid;
592
- O.assignLODInformation(t, e, i, s, n), O.lodInfos.set(i, r), O.lowresCache.set(i, e);
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);
593
775
  }), /**
594
776
  * Register a mesh with LOD information
595
777
  */
596
- u(T, "registerMesh", (t, e, s, n, r, i) => {
597
- var c;
778
+ c(D, "registerMesh", (e, t, s, r, i, o) => {
779
+ var g;
598
780
  const a = s.geometry;
599
781
  if (!a) {
600
- y && console.warn("gltf-progressive: Register mesh without geometry");
782
+ C && console.warn("gltf-progressive: Register mesh without geometry");
601
783
  return;
602
784
  }
603
- a.userData || (a.userData = {}), y && console.log("> Progressive: register mesh " + s.name, { index: r, uuid: s.uuid }, i, s), O.assignLODInformation(t, a, e, n, r), O.lodInfos.set(e, i);
604
- let l = O.lowresCache.get(e);
605
- l ? l.push(s.geometry) : l = [s.geometry], O.lowresCache.set(e, l), n > 0 && !ce(s) && gt(s, a);
606
- for (const d of j)
607
- (c = d.onRegisteredNewMesh) == null || c.call(d, s, i);
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);
608
790
  }), /** A map of key = asset uuid and value = LOD information */
609
- u(T, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
610
- u(T, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
611
- u(T, "lowresCache", /* @__PURE__ */ new Map()), u(T, "queue", new ft(100, { debug: y != !1 }));
612
- class yt {
613
- constructor(t, e, s, n) {
614
- u(this, "url");
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");
615
797
  /** the key to lookup the LOD information */
616
- u(this, "key");
617
- u(this, "level");
798
+ c(this, "key");
799
+ c(this, "level");
618
800
  /** For multi objects (e.g. a group of meshes) this is the index of the object */
619
- u(this, "index");
620
- this.url = t, this.key = e, this.level = s, n != null && (this.index = n);
801
+ c(this, "index");
802
+ this.url = e, this.key = t, this.level = s, r != null && (this.index = r);
621
803
  }
622
804
  }
623
- class ye {
624
- constructor(t, e) {
625
- u(this, "frame_start");
626
- u(this, "frame_capture_end");
627
- u(this, "ready");
628
- u(this, "_resolve");
629
- u(this, "_signal");
630
- u(this, "_resolved", !1);
631
- u(this, "_addedCount", 0);
632
- u(this, "_resolvedCount", 0);
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);
633
815
  /** These promises are currently being awaited */
634
- u(this, "_awaiting", []);
635
- u(this, "_maxPromisesPerObject", 1);
636
- u(this, "_currentFrame", 0);
637
- u(this, "_seen", /* @__PURE__ */ new WeakMap());
638
- var r;
639
- const n = Math.max(e.frames ?? 2, 2);
640
- this.frame_start = t, this.frame_capture_end = t + n, this.ready = new Promise((i) => {
641
- this._resolve = i;
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;
642
824
  }), this.ready.finally(() => {
643
825
  this._resolved = !0, this._awaiting.length = 0;
644
- }), this._signal = e.signal, (r = this._signal) == null || r.addEventListener("abort", () => {
826
+ }), this._signal = t.signal, (i = this._signal) == null || i.addEventListener("abort", () => {
645
827
  this.resolveNow();
646
- }), this._maxPromisesPerObject = Math.max(1, e.maxPromisesPerObject ?? 1);
828
+ }), this._maxPromisesPerObject = Math.max(1, t.maxPromisesPerObject ?? 1);
647
829
  }
648
830
  /**
649
831
  * The number of promises that have been added to this group so far.
@@ -657,125 +839,125 @@ class ye {
657
839
  get currentlyAwaiting() {
658
840
  return this._awaiting.length;
659
841
  }
660
- update(t) {
661
- var e;
662
- this._currentFrame = t, ((e = this._signal) != null && e.aborted || this._currentFrame > this.frame_capture_end && this._awaiting.length === 0) && this.resolveNow();
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();
663
845
  }
664
- add(t, e, s) {
846
+ add(e, t, s) {
665
847
  if (this._resolved) {
666
- y && 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.");
667
849
  return;
668
850
  }
669
851
  if (!(this._currentFrame > this.frame_capture_end)) {
670
852
  if (this._maxPromisesPerObject >= 1)
671
- if (this._seen.has(e)) {
672
- let n = this._seen.get(e);
673
- if (n >= this._maxPromisesPerObject) {
674
- y && console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");
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.");
675
857
  return;
676
858
  }
677
- this._seen.set(e, n + 1);
859
+ this._seen.set(t, r + 1);
678
860
  } else
679
- this._seen.set(e, 1);
861
+ this._seen.set(t, 1);
680
862
  this._awaiting.push(s), this._addedCount++, s.finally(() => {
681
863
  this._resolvedCount++, this._awaiting.splice(this._awaiting.indexOf(s), 1);
682
864
  });
683
865
  }
684
866
  }
685
867
  resolveNow() {
686
- var t, e;
687
- this._resolved || (e = this._resolve) == null || e.call(this, {
868
+ var e, t;
869
+ this._resolved || (t = this._resolve) == null || t.call(this, {
688
870
  awaited_count: this._addedCount,
689
871
  resolved_count: this._resolvedCount,
690
- cancelled: ((t = this._signal) == null ? void 0 : t.aborted) ?? !1
872
+ cancelled: ((e = this._signal) == null ? void 0 : e.aborted) ?? !1
691
873
  });
692
874
  }
693
875
  }
694
- u(ye, "addPromise", (t, e, s, n) => {
695
- n.forEach((r) => {
696
- r.add(t, e, s);
876
+ c(be, "addPromise", (e, t, s, r) => {
877
+ r.forEach((i) => {
878
+ i.add(e, t, s);
697
879
  });
698
880
  });
699
- const F = de("debugprogressive"), Lt = de("noprogressive"), be = Symbol("Needle:LODSManager"), Se = Symbol("Needle:LODState"), Q = Symbol("Needle:CurrentLOD"), G = { mesh_lod: -1, texture_lod: -1 };
700
- var B, K, we, J, ie, _e, Y;
701
- const b = class {
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 {
702
884
  // readonly plugins: NEEDLE_progressive_plugin[] = [];
703
- constructor(t, e) {
704
- u(this, "renderer");
705
- u(this, "context");
706
- u(this, "projectionScreenMatrix", new Ie());
885
+ constructor(e, t) {
886
+ c(this, "renderer");
887
+ c(this, "context");
888
+ c(this, "projectionScreenMatrix", new Ke());
707
889
  /**
708
890
  * The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
709
891
  * @default 200_000
710
892
  */
711
- u(this, "targetTriangleDensity", 2e5);
893
+ c(this, "targetTriangleDensity", 2e5);
712
894
  /**
713
895
  * The interval in frames to automatically update the bounds of skinned meshes.
714
896
  * Set to 0 or a negative value to disable automatic bounds updates.
715
897
  * @default 30
716
898
  */
717
- u(this, "skinnedMeshAutoUpdateBoundsInterval", 30);
899
+ c(this, "skinnedMeshAutoUpdateBoundsInterval", 30);
718
900
  /**
719
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.
720
902
  * @default "auto"
721
903
  */
722
- u(this, "updateInterval", "auto");
723
- H(this, B, 1);
904
+ c(this, "updateInterval", "auto");
905
+ q(this, X, 1);
724
906
  /**
725
907
  * If set to true, the LODsManager will not update the LODs.
726
908
  * @default false
727
909
  */
728
- u(this, "pause", !1);
910
+ c(this, "pause", !1);
729
911
  /**
730
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.
731
913
  * Otherwise the LODs will be updated automatically when the renderer renders the scene.
732
914
  * @default false
733
915
  */
734
- u(this, "manual", !1);
735
- u(this, "_newPromiseGroups", []);
736
- u(this, "_promiseGroupIds", 0);
737
- u(this, "_lodchangedlisteners", []);
738
- H(this, K, void 0);
739
- H(this, we, new Je());
740
- H(this, J, 0);
741
- H(this, ie, 0);
742
- H(this, _e, 0);
743
- H(this, Y, 0);
744
- u(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
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]);
745
927
  // private testIfLODLevelsAreAvailable() {
746
- u(this, "_sphere", new et());
747
- u(this, "_tempBox", new $e());
748
- u(this, "_tempBox2", new $e());
749
- u(this, "tempMatrix", new Ie());
750
- u(this, "_tempWorldPosition", new W());
751
- u(this, "_tempBoxSize", new W());
752
- u(this, "_tempBox2Size", new W());
753
- this.renderer = t, this.context = { ...e };
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 };
754
936
  }
755
937
  /** @internal */
756
- static getObjectLODState(t) {
757
- return t[Se];
938
+ static getObjectLODState(e) {
939
+ return e[Re];
758
940
  }
759
- static addPlugin(t) {
760
- j.push(t);
941
+ static addPlugin(e) {
942
+ j.push(e);
761
943
  }
762
- static removePlugin(t) {
763
- const e = j.indexOf(t);
764
- e >= 0 && j.splice(e, 1);
944
+ static removePlugin(e) {
945
+ const t = j.indexOf(e);
946
+ t >= 0 && j.splice(t, 1);
765
947
  }
766
948
  /**
767
949
  * Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
768
950
  * @param renderer The renderer to get the LODsManager for.
769
951
  * @returns The LODsManager instance.
770
952
  */
771
- static get(t, e) {
772
- if (t[be])
773
- return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[be];
774
- const s = new b(t, {
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, {
775
957
  engine: "unknown",
776
- ...e
958
+ ...t
777
959
  });
778
- return t[be] = s, s;
960
+ return e[De] = s, s;
779
961
  }
780
962
  /** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
781
963
  get plugins() {
@@ -784,29 +966,29 @@ const b = class {
784
966
  /**
785
967
  * Call to await LODs loading during the next render cycle.
786
968
  */
787
- awaitLoading(t) {
788
- const e = this._promiseGroupIds++, s = new ye(L(this, J), { ...t });
969
+ awaitLoading(e) {
970
+ const t = this._promiseGroupIds++, s = new be(L(this, ee), { ...e });
789
971
  this._newPromiseGroups.push(s);
790
- const n = performance.now();
972
+ const r = performance.now();
791
973
  return s.ready.finally(() => {
792
- const r = this._newPromiseGroups.indexOf(s);
793
- r >= 0 && (this._newPromiseGroups.splice(r, 1), Ge() && performance.measure("LODsManager:awaitLoading", {
794
- start: n,
795
- detail: { id: e, name: t == null ? void 0 : t.name, awaited: s.awaitedCount, resolved: s.resolvedCount }
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 }
796
978
  }));
797
979
  }), s.ready;
798
980
  }
799
981
  _postprocessPromiseGroups() {
800
982
  if (this._newPromiseGroups.length !== 0)
801
- for (let t = this._newPromiseGroups.length - 1; t >= 0; t--)
802
- this._newPromiseGroups[t].update(L(this, J));
983
+ for (let e = this._newPromiseGroups.length - 1; e >= 0; e--)
984
+ this._newPromiseGroups[e].update(L(this, ee));
803
985
  }
804
- addEventListener(t, e) {
805
- t === "changed" && this._lodchangedlisteners.push(e);
986
+ addEventListener(e, t) {
987
+ e === "changed" && this._lodchangedlisteners.push(t);
806
988
  }
807
- removeEventListener(t, e) {
808
- if (t === "changed") {
809
- const s = this._lodchangedlisteners.indexOf(e);
989
+ removeEventListener(e, t) {
990
+ if (e === "changed") {
991
+ const s = this._lodchangedlisteners.indexOf(t);
810
992
  s >= 0 && this._lodchangedlisteners.splice(s, 1);
811
993
  }
812
994
  }
@@ -814,54 +996,54 @@ const b = class {
814
996
  * Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
815
997
  */
816
998
  enable() {
817
- if (L(this, K))
999
+ if (L(this, J))
818
1000
  return;
819
1001
  console.debug("[gltf-progressive] Enabling LODsManager for renderer");
820
- let t = 0;
821
- V(this, K, this.renderer.render);
822
- const e = this;
823
- Ue(this.renderer), this.renderer.render = function(s, n) {
824
- const r = e.renderer.getRenderTarget();
825
- (r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (t = 0, V(e, J, L(e, J) + 1), V(e, ie, L(e, we).getDelta()), V(e, _e, L(e, _e) + L(e, ie)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / L(e, ie)), V(e, Y, e._fpsBuffer.reduce((a, l) => a + l) / e._fpsBuffer.length), F && L(e, J) % 200 === 0 && console.log("FPS", Math.round(L(e, Y)), "Interval:", L(e, B)));
826
- const i = t++;
827
- L(e, K).call(this, s, n), e.onAfterRender(s, n, i);
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);
828
1010
  };
829
1011
  }
830
1012
  disable() {
831
- L(this, K) && (console.debug("[gltf-progressive] Disabling LODsManager for renderer"), this.renderer.render = L(this, K), V(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));
832
1014
  }
833
- update(t, e) {
834
- this.internalUpdate(t, e);
1015
+ update(e, t) {
1016
+ this.internalUpdate(e, t);
835
1017
  }
836
- onAfterRender(t, e, s) {
1018
+ onAfterRender(e, t, s) {
837
1019
  if (this.pause)
838
1020
  return;
839
- const r = this.renderer.renderLists.get(t, 0).opaque;
840
- let i = !0;
841
- if (r.length === 1) {
842
- const a = r[0].material;
843
- (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);
844
1026
  }
845
- if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (i = !1), i) {
846
- if (Lt || (this.updateInterval === "auto" ? L(this, Y) < 40 && L(this, B) < 10 ? (V(this, B, L(this, B) + 1), F && console.warn("↓ Reducing LOD updates", L(this, B), L(this, Y).toFixed(0))) : L(this, Y) >= 60 && L(this, B) > 1 && (V(this, B, L(this, B) - 1), F && console.warn("↑ Increasing LOD updates", L(this, B), L(this, Y).toFixed(0))) : V(this, B, this.updateInterval), L(this, B) > 0 && L(this, J) % L(this, B) != 0))
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))
847
1029
  return;
848
- this.internalUpdate(t, e), this._postprocessPromiseGroups();
1030
+ this.internalUpdate(e, t), this._postprocessPromiseGroups();
849
1031
  }
850
1032
  }
851
1033
  /**
852
1034
  * Update LODs in a scene
853
1035
  */
854
- internalUpdate(t, e) {
855
- var l, c;
856
- const s = this.renderer.renderLists.get(t, 0), n = s.opaque;
857
- this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix, e.matrixWorldInverse);
858
- const r = this.targetTriangleDensity;
859
- for (const d of n) {
860
- if (d.material && (((l = d.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((c = d.geometry) == null ? void 0 : c.type) === "BufferGeometry") && (d.material.name === "SphericalGaussianBlur" || d.material.name == "BackgroundCubeMaterial" || d.material.name === "CubemapFromEquirect" || d.material.name === "EquirectangularToCubeUV")) {
861
- F && (d.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (d.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", d, d.material.name, d.material.type)));
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)));
862
1044
  continue;
863
1045
  }
864
- switch (d.material.type) {
1046
+ switch (u.material.type) {
865
1047
  case "LineBasicMaterial":
866
1048
  case "LineDashedMaterial":
867
1049
  case "PointsMaterial":
@@ -870,62 +1052,60 @@ const b = class {
870
1052
  case "MeshDepthMaterial":
871
1053
  continue;
872
1054
  }
873
- if (F === "color" && d.material && !d.object.progressive_debug_color) {
874
- d.object.progressive_debug_color = !0;
875
- const f = Math.random() * 16777215, w = new Ze({ color: f });
876
- d.object.material = w;
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;
877
1059
  }
878
- const h = d.object;
879
- (h instanceof se || h.isMesh) && this.updateLODs(t, e, h, r);
1060
+ const p = u.object;
1061
+ (p instanceof oe || p.isMesh) && this.updateLODs(e, t, p, i);
880
1062
  }
881
- const i = s.transparent;
882
- for (const d of i) {
883
- const h = d.object;
884
- (h instanceof se || h.isMesh) && this.updateLODs(t, e, h, r);
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);
885
1067
  }
886
1068
  const a = s.transmissive;
887
- for (const d of a) {
888
- const h = d.object;
889
- (h instanceof se || h.isMesh) && this.updateLODs(t, e, h, r);
1069
+ for (const u of a) {
1070
+ const p = u.object;
1071
+ (p instanceof oe || p.isMesh) && this.updateLODs(e, t, p, i);
890
1072
  }
891
1073
  }
892
1074
  /** Update the LOD levels for the renderer. */
893
- updateLODs(t, e, s, n) {
1075
+ updateLODs(e, t, s, r) {
894
1076
  var a, l;
895
1077
  s.userData || (s.userData = {});
896
- let r = s[Se];
897
- if (r || (r = new xt(), s[Se] = r), r.frames++ < 2)
1078
+ let i = s[Re];
1079
+ if (i || (i = new Ot(), s[Re] = i), i.frames++ < 2)
898
1080
  return;
899
- for (const c of j)
900
- (a = c.onBeforeUpdateLOD) == null || a.call(c, this.renderer, t, e, s);
901
- const i = b.overrideGlobalLodLevel !== void 0 ? b.overrideGlobalLodLevel : te;
902
- i >= 0 ? (G.mesh_lod = i, G.texture_lod = i) : (this.calculateLodLevel(e, s, r, n, G), G.mesh_lod = Math.round(G.mesh_lod), G.texture_lod = Math.round(G.texture_lod)), G.mesh_lod >= 0 && this.loadProgressiveMeshes(s, G.mesh_lod), s.material && G.texture_lod >= 0 && this.loadProgressiveTextures(s.material, G.texture_lod), y && s.material && !s.isGizmo && qe(s.material);
903
- for (const c of j)
904
- (l = c.onAfterUpdatedLOD) == null || l.call(c, this.renderer, t, e, s, G);
905
- r.lastLodLevel_Mesh = G.mesh_lod, r.lastLodLevel_Texture = G.texture_lod;
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;
906
1088
  }
907
1089
  /** Load progressive textures for the given material
908
1090
  * @param material the material to load the textures for
909
1091
  * @param level the LOD level to load. Level 0 is the best quality, higher levels are lower quality
910
1092
  * @returns Promise with true if the LOD was loaded, false if not
911
1093
  */
912
- loadProgressiveTextures(t, e) {
913
- if (!t)
1094
+ loadProgressiveTextures(e, t, s) {
1095
+ if (!e)
914
1096
  return;
915
- if (Array.isArray(t)) {
916
- for (const r of t)
917
- this.loadProgressiveTextures(r, e);
1097
+ if (Array.isArray(e)) {
1098
+ for (const i of e)
1099
+ this.loadProgressiveTextures(i, t);
918
1100
  return;
919
1101
  }
920
- let s = !1;
921
- (t[Q] === void 0 || e < t[Q]) && (s = !0);
922
- const n = t["DEBUG:LOD"];
923
- if (n != null && (s = t[Q] != n, e = n), s) {
924
- t[Q] = e;
925
- const r = T.assignTextureLOD(t, e).then((i) => {
926
- this._lodchangedlisteners.forEach((a) => a({ type: "texture", level: e, object: t }));
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 }));
927
1107
  });
928
- ye.addPromise("texture", t, r, this._newPromiseGroups);
1108
+ be.addPromise("texture", e, i, this._newPromiseGroups);
929
1109
  }
930
1110
  }
931
1111
  /** Load progressive meshes for the given mesh
@@ -934,336 +1114,341 @@ const b = class {
934
1114
  * @param level the LOD level to load. Level 0 is the best quality, higher levels are lower quality
935
1115
  * @returns Promise with true if the LOD was loaded, false if not
936
1116
  */
937
- loadProgressiveMeshes(t, e) {
938
- if (!t)
1117
+ loadProgressiveMeshes(e, t) {
1118
+ if (!e)
939
1119
  return Promise.resolve(null);
940
- let s = t[Q] !== e;
941
- const n = t["DEBUG:LOD"];
942
- if (n != null && (s = t[Q] != n, e = n), s) {
943
- t[Q] = e;
944
- const r = t.geometry, i = T.assignMeshLOD(t, e).then((a) => (a && t[Q] == e && r != t.geometry && this._lodchangedlisteners.forEach((l) => l({ type: "mesh", level: e, object: t })), a));
945
- return ye.addPromise("mesh", t, i, this._newPromiseGroups), i;
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;
946
1126
  }
947
1127
  return Promise.resolve(null);
948
1128
  }
949
- static isInside(t, e) {
950
- const s = t.min, n = t.max, r = (s.x + n.x) * 0.5, i = (s.y + n.y) * 0.5;
951
- return this._tempPtInside.set(r, i, s.z).applyMatrix4(e).z < 0;
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;
952
1132
  }
953
- calculateLodLevel(t, e, s, n, r) {
954
- var M, R, Z;
955
- if (!e) {
956
- 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;
957
1138
  return;
958
1139
  }
959
- if (!t) {
960
- r.mesh_lod = -1, r.texture_lod = -1;
1140
+ if (!e) {
1141
+ i.mesh_lod = -1, i.texture_lod = -1;
961
1142
  return;
962
1143
  }
963
1144
  let a = 10 + 1, l = !1;
964
- if (F && e["DEBUG:LOD"] != null)
965
- return e["DEBUG:LOD"];
966
- const c = (M = T.getMeshLODExtension(e.geometry)) == null ? void 0 : M.lods, d = T.getPrimitiveIndex(e.geometry), h = c && c.length > 0, f = T.getMaterialMinMaxLODsCount(e.material), w = (f == null ? void 0 : f.min_count) != 1 / 0 && f.min_count > 0 && f.max_count > 0;
967
- if (!h && !w) {
968
- 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;
969
1150
  return;
970
1151
  }
971
- h || (l = !0, a = 0);
972
- const v = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
973
- let P = e.geometry.boundingBox;
974
- if (e.type === "SkinnedMesh") {
975
- const g = e;
976
- if (!g.boundingBox)
977
- g.computeBoundingBox();
1152
+ p || (l = !0, a = 0);
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();
978
1159
  else if (this.skinnedMeshAutoUpdateBoundsInterval > 0) {
979
- if (!g[b.$skinnedMeshBoundsOffset]) {
980
- const E = b.skinnedMeshBoundsFrameOffsetCounter++;
981
- g[b.$skinnedMeshBoundsOffset] = E;
1160
+ if (!f[S.$skinnedMeshBoundsOffset]) {
1161
+ const _ = S.skinnedMeshBoundsFrameOffsetCounter++;
1162
+ f[S.$skinnedMeshBoundsOffset] = _;
982
1163
  }
983
- const x = g[b.$skinnedMeshBoundsOffset];
984
- if ((s.frames + x) % this.skinnedMeshAutoUpdateBoundsInterval === 0) {
985
- const E = ce(g), U = g.geometry;
986
- E && (g.geometry = E), g.computeBoundingBox(), g.geometry = U;
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;
987
1168
  }
988
1169
  }
989
- P = g.boundingBox;
1170
+ b = f.boundingBox;
990
1171
  }
991
- if (P) {
992
- const g = t;
993
- if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
994
- this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
995
- const p = t.getWorldPosition(this._tempWorldPosition);
996
- if (this._sphere.containsPoint(p)) {
997
- 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;
998
1179
  return;
999
1180
  }
1000
1181
  }
1001
- if (this._tempBox.copy(P), this._tempBox.applyMatrix4(e.matrixWorld), g.isPerspectiveCamera && b.isInside(this._tempBox, this.projectionScreenMatrix)) {
1002
- 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;
1003
1184
  return;
1004
1185
  }
1005
- if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && g.isPerspectiveCamera && g.fov > 70) {
1006
- const p = this._tempBox.min, _ = this._tempBox.max;
1007
- let $ = p.x, A = p.y, z = _.x, ne = _.y;
1008
- const fe = 2, ve = 1.5, he = (p.x + _.x) * 0.5, ge = (p.y + _.y) * 0.5;
1009
- $ = ($ - he) * fe + he, A = (A - ge) * fe + ge, z = (z - he) * fe + he, ne = (ne - ge) * fe + ge;
1010
- const Ke = $ < 0 && z > 0 ? 0 : Math.min(Math.abs(p.x), Math.abs(_.x)), Ye = A < 0 && ne > 0 ? 0 : Math.min(Math.abs(p.y), Math.abs(_.y)), De = Math.max(Ke, Ye);
1011
- s.lastCentrality = (ve - De) * (ve - De) * (ve - De);
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);
1012
1193
  } else
1013
1194
  s.lastCentrality = 1;
1014
- const x = this._tempBox.getSize(this._tempBoxSize);
1015
- x.multiplyScalar(0.5), screen.availHeight > 0 && v > 0 && x.multiplyScalar(v / screen.availHeight), t.isPerspectiveCamera ? x.x *= t.aspect : t.isOrthographicCamera;
1016
- const E = t.matrixWorldInverse, U = this._tempBox2;
1017
- U.copy(P), U.applyMatrix4(e.matrixWorld), U.applyMatrix4(E);
1018
- const S = U.getSize(this._tempBox2Size), ee = Math.max(S.x, S.y);
1019
- if (Math.max(x.x, x.y) != 0 && ee != 0 && (x.z = S.z / Math.max(S.x, S.y) * Math.max(x.x, x.y)), s.lastScreenCoverage = Math.max(x.x, x.y, x.z), s.lastScreenspaceVolume.copy(x), s.lastScreenCoverage *= s.lastCentrality, F && b.debugDrawLine) {
1020
- const p = this.tempMatrix.copy(this.projectionScreenMatrix);
1021
- p.invert();
1022
- const _ = b.corner0, $ = b.corner1, A = b.corner2, z = b.corner3;
1023
- _.copy(this._tempBox.min), $.copy(this._tempBox.max), $.x = _.x, A.copy(this._tempBox.max), A.y = _.y, z.copy(this._tempBox.max);
1024
- const ne = (_.z + z.z) * 0.5;
1025
- _.z = $.z = A.z = z.z = ne, _.applyMatrix4(p), $.applyMatrix4(p), A.applyMatrix4(p), z.applyMatrix4(p), b.debugDrawLine(_, $, 255), b.debugDrawLine(_, A, 255), b.debugDrawLine($, z, 255), b.debugDrawLine(A, z, 255);
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);
1026
1207
  }
1027
- let D = 999;
1028
- if (c && s.lastScreenCoverage > 0)
1029
- for (let p = 0; p < c.length; p++) {
1030
- const _ = c[p], A = (((R = _.densities) == null ? void 0 : R[d]) || _.density || 1e-5) / s.lastScreenCoverage;
1031
- if (d > 0 && Ge() && !_.densities && !globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] && (window["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] = !0, console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")), A < n) {
1032
- D = p;
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;
1033
1214
  break;
1034
1215
  }
1035
1216
  }
1036
- D < a && (a = D, l = !0);
1217
+ Z < a && (a = Z, l = !0);
1037
1218
  }
1038
- if (l ? r.mesh_lod = a : r.mesh_lod = s.lastLodLevel_Mesh, F && r.mesh_lod != s.lastLodLevel_Mesh) {
1039
- const x = c == null ? void 0 : c[r.mesh_lod];
1040
- x && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${r.mesh_lod} (${x.density.toFixed(0)}) - ${e.name}`);
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}`);
1041
1222
  }
1042
- if (w) {
1043
- const g = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
1223
+ if (y) {
1224
+ const f = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
1044
1225
  if (s.lastLodLevel_Texture < 0) {
1045
- if (r.texture_lod = f.max_count - 1, F) {
1046
- const x = f.lods[f.max_count - 1];
1047
- F && console.log(`First Texture LOD ${r.texture_lod} (${x.max_height}px) - ${e.name}`);
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}`);
1048
1229
  }
1049
1230
  } else {
1050
- const x = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
1051
- let E = s.lastScreenCoverage * 4;
1052
- ((Z = this.context) == null ? void 0 : Z.engine) === "model-viewer" && (E *= 1.5);
1053
- const S = v / window.devicePixelRatio * E;
1054
- let ee = !1;
1055
- for (let I = f.lods.length - 1; I >= 0; I--) {
1056
- const D = f.lods[I];
1057
- if (!(g && D.max_height >= 2048) && !(ct() && D.max_height > 4096) && (D.max_height > S || !ee && I === 0)) {
1058
- if (ee = !0, r.texture_lod = I, r.texture_lod < s.lastLodLevel_Texture) {
1059
- const m = D.max_height;
1060
- F && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${r.texture_lod} = ${m}px
1061
- Screensize: ${S.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${x.toFixed(1)}
1062
- ${e.name}`);
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}`);
1063
1244
  }
1064
1245
  break;
1065
1246
  }
1066
1247
  }
1067
1248
  }
1068
1249
  } else
1069
- r.texture_lod = 0;
1250
+ i.texture_lod = 0;
1070
1251
  }
1071
1252
  };
1072
- let C = b;
1073
- B = new WeakMap(), K = new WeakMap(), we = new WeakMap(), J = new WeakMap(), ie = new WeakMap(), _e = new WeakMap(), Y = new WeakMap(), /**
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(), /**
1074
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.
1075
1256
  */
1076
- u(C, "debugDrawLine"), /**
1257
+ c(O, "debugDrawLine"), /**
1077
1258
  * Force override the LOD level for all objects in the scene
1078
1259
  */
1079
- u(C, "overrideGlobalLodLevel"), u(C, "corner0", new W()), u(C, "corner1", new W()), u(C, "corner2", new W()), u(C, "corner3", new W()), u(C, "_tempPtInside", new W()), u(C, "skinnedMeshBoundsFrameOffsetCounter", 0), u(C, "$skinnedMeshBoundsOffset", Symbol("gltf-progressive-skinnedMeshBoundsOffset"));
1080
- class xt {
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 {
1081
1262
  constructor() {
1082
- u(this, "frames", 0);
1083
- u(this, "lastLodLevel_Mesh", -1);
1084
- u(this, "lastLodLevel_Texture", -1);
1085
- u(this, "lastScreenCoverage", 0);
1086
- u(this, "lastScreenspaceVolume", new W());
1087
- u(this, "lastCentrality", 0);
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);
1088
1269
  }
1089
1270
  }
1090
- const Be = Symbol("NEEDLE_mesh_lod"), pe = Symbol("NEEDLE_texture_lod");
1091
- let ue = null;
1092
- function We() {
1093
- const o = wt();
1094
- o && (o.mapURLs(function(t) {
1095
- return ke(), t;
1096
- }), ke(), ue == null || ue.disconnect(), ue = new MutationObserver((t) => {
1097
- t.forEach((e) => {
1098
- e.addedNodes.forEach((s) => {
1099
- s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && Xe(s);
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);
1100
1281
  });
1101
1282
  });
1102
- }), ue.observe(document, { childList: !0, subtree: !0 }));
1283
+ }), fe.observe(document, { childList: !0, subtree: !0 }));
1103
1284
  }
1104
- function wt() {
1285
+ function Wt() {
1105
1286
  if (typeof customElements > "u")
1106
1287
  return null;
1107
- const o = customElements.get("model-viewer");
1108
- return o || (customElements.whenDefined("model-viewer").then(() => {
1109
- console.debug("[gltf-progressive] model-viewer defined"), We();
1288
+ const n = customElements.get("model-viewer");
1289
+ return n || (customElements.whenDefined("model-viewer").then(() => {
1290
+ console.debug("[gltf-progressive] model-viewer defined"), Qe();
1110
1291
  }), null);
1111
1292
  }
1112
- function ke() {
1293
+ function ze() {
1113
1294
  if (typeof document > "u")
1114
1295
  return;
1115
- document.querySelectorAll("model-viewer").forEach((t) => {
1116
- Xe(t);
1296
+ document.querySelectorAll("model-viewer").forEach((e) => {
1297
+ je(e);
1117
1298
  });
1118
1299
  }
1119
- const Re = /* @__PURE__ */ new WeakSet();
1120
- let _t = 0;
1121
- function Xe(o) {
1122
- if (!o || Re.has(o))
1300
+ const He = /* @__PURE__ */ new WeakSet();
1301
+ let Tt = 0;
1302
+ function je(n) {
1303
+ if (!n || He.has(n))
1123
1304
  return null;
1124
- Re.add(o), console.debug("[gltf-progressive] found new model-viewer..." + ++_t + `
1125
- `, o.getAttribute("src"));
1126
- let t = null, e = null, s = null;
1127
- for (let n = o; n != null; n = Object.getPrototypeOf(n)) {
1128
- const r = Object.getOwnPropertySymbols(n), i = r.find((c) => c.toString() == "Symbol(renderer)"), a = r.find((c) => c.toString() == "Symbol(scene)"), l = r.find((c) => c.toString() == "Symbol(needsRender)");
1129
- !t && i != null && (t = o[i].threeRenderer), !e && a != null && (e = o[a]), !s && l != null && (s = o[l]);
1130
- }
1131
- if (t && e) {
1132
- 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() {
1133
1314
  if (s) {
1134
- let i = 0, a = setInterval(() => {
1135
- if (i++ > 5) {
1315
+ let o = 0, a = setInterval(() => {
1316
+ if (o++ > 5) {
1136
1317
  clearInterval(a);
1137
1318
  return;
1138
1319
  }
1139
- s == null || s.call(o);
1320
+ s == null || s.call(n);
1140
1321
  }, 300);
1141
1322
  }
1142
1323
  };
1143
1324
  console.debug("[gltf-progressive] setup model-viewer");
1144
- const r = C.get(t, { engine: "model-viewer" });
1145
- return C.addPlugin(new vt()), r.enable(), r.addEventListener("changed", () => {
1146
- s == null || s.call(o);
1147
- }), o.addEventListener("model-visibility", (i) => {
1148
- i.detail.visible && (s == null || s.call(o));
1149
- }), o.addEventListener("load", () => {
1150
- 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();
1151
1332
  }), () => {
1152
- r.disable();
1333
+ i.disable();
1153
1334
  };
1154
1335
  }
1155
1336
  return null;
1156
1337
  }
1157
- class vt {
1338
+ class Xt {
1158
1339
  constructor() {
1159
- u(this, "_didWarnAboutMissingUrl", !1);
1340
+ c(this, "_didWarnAboutMissingUrl", !1);
1160
1341
  }
1161
- onBeforeUpdateLOD(t, e, s, n) {
1162
- this.tryParseMeshLOD(e, n), this.tryParseTextureLOD(e, n);
1342
+ onBeforeUpdateLOD(e, t, s, r) {
1343
+ this.tryParseMeshLOD(t, r), this.tryParseTextureLOD(t, r);
1163
1344
  }
1164
- getUrl(t) {
1165
- if (!t)
1345
+ getUrl(e) {
1346
+ if (!e)
1166
1347
  return null;
1167
- let e = t.getAttribute("src");
1168
- return e || (e = t.src), e || (this._didWarnAboutMissingUrl || console.warn("No url found in modelviewer", t), this._didWarnAboutMissingUrl = !0), e;
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;
1169
1350
  }
1170
- tryGetCurrentGLTF(t) {
1171
- return t._currentGLTF;
1351
+ tryGetCurrentGLTF(e) {
1352
+ return e._currentGLTF;
1172
1353
  }
1173
- tryGetCurrentModelViewer(t) {
1174
- return t.element;
1354
+ tryGetCurrentModelViewer(e) {
1355
+ return e.element;
1175
1356
  }
1176
- tryParseTextureLOD(t, e) {
1177
- if (e[pe] == !0)
1357
+ tryParseTextureLOD(e, t) {
1358
+ if (t[ye] == !0)
1178
1359
  return;
1179
- e[pe] = !0;
1180
- const s = this.tryGetCurrentGLTF(t), n = this.tryGetCurrentModelViewer(t), r = this.getUrl(n);
1181
- if (r && s && e.material) {
1182
- let i = function(l) {
1183
- var d, h, f;
1184
- if (l[pe] == !0)
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)
1185
1366
  return;
1186
- l[pe] = !0, l.userData && (l.userData.LOD = -1);
1187
- const c = Object.keys(l);
1188
- for (let w = 0; w < c.length; w++) {
1189
- const v = c[w], P = l[v];
1190
- if ((P == null ? void 0 : P.isTexture) === !0) {
1191
- const M = (h = (d = P.userData) == null ? void 0 : d.associations) == null ? void 0 : h.textures;
1192
- if (M == null)
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)
1193
1374
  continue;
1194
- const R = s.parser.json.textures[M];
1195
- if (!R) {
1196
- console.warn("Texture data not found for texture index " + M);
1375
+ const v = s.parser.json.textures[k];
1376
+ if (!v) {
1377
+ console.warn("Texture data not found for texture index " + k);
1197
1378
  continue;
1198
1379
  }
1199
- if ((f = R == null ? void 0 : R.extensions) != null && f[X]) {
1200
- const Z = R.extensions[X];
1201
- Z && r && T.registerTexture(r, P, Z.lods.length, M, Z);
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);
1202
1383
  }
1203
1384
  }
1204
1385
  }
1205
1386
  };
1206
- const a = e.material;
1387
+ const a = t.material;
1207
1388
  if (Array.isArray(a))
1208
1389
  for (const l of a)
1209
- i(l);
1390
+ o(l);
1210
1391
  else
1211
- i(a);
1392
+ o(a);
1212
1393
  }
1213
1394
  }
1214
- tryParseMeshLOD(t, e) {
1215
- var i, a;
1216
- if (e[Be] == !0)
1395
+ tryParseMeshLOD(e, t) {
1396
+ var o, a;
1397
+ if (t[Ne] == !0)
1217
1398
  return;
1218
- e[Be] = !0;
1219
- const s = this.tryGetCurrentModelViewer(t), n = this.getUrl(s);
1220
- if (!n)
1399
+ t[Ne] = !0;
1400
+ const s = this.tryGetCurrentModelViewer(e), r = this.getUrl(s);
1401
+ if (!r)
1221
1402
  return;
1222
- const r = (a = (i = e.userData) == null ? void 0 : i.gltfExtensions) == null ? void 0 : a[X];
1223
- if (r && n) {
1224
- const l = e.uuid;
1225
- T.registerMesh(n, l, e, 0, r.lods.length, r);
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);
1226
1407
  }
1227
1408
  }
1228
1409
  }
1229
- function Dt(o, t, e, s) {
1230
- Ue(t), ze(e), Ve(e, {
1410
+ function Kt(n, e, t, s) {
1411
+ Te(e), Ee(t), Je(t, {
1231
1412
  progressive: !0,
1232
1413
  ...s == null ? void 0 : s.hints
1233
- }), e.register((r) => new T(r, o));
1234
- const n = C.get(t);
1235
- return (s == null ? void 0 : s.enableLODsManager) !== !1 && n.enable(), n;
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;
1236
1417
  }
1237
- We();
1238
- if (!ht) {
1239
- const o = {
1418
+ Qe();
1419
+ if (!Lt) {
1420
+ const n = {
1240
1421
  gltfProgressive: {
1241
- useNeedleProgressive: Dt,
1242
- LODsManager: C,
1243
- configureLoader: Ve,
1244
- getRaycastMesh: ce,
1245
- useRaycastMeshes: pt
1422
+ useNeedleProgressive: Kt,
1423
+ LODsManager: O,
1424
+ configureLoader: Je,
1425
+ getRaycastMesh: me,
1426
+ useRaycastMeshes: Gt
1246
1427
  }
1247
1428
  };
1248
1429
  if (!globalThis.Needle)
1249
- globalThis.Needle = o;
1430
+ globalThis.Needle = n;
1250
1431
  else
1251
- for (const t in o)
1252
- globalThis.Needle[t] = o[t];
1432
+ for (const e in n)
1433
+ globalThis.Needle[e] = n[e];
1253
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" }));
1254
1439
  export {
1255
- X as EXTENSION_NAME,
1256
- C as LODsManager,
1257
- T as NEEDLE_progressive,
1258
- it as VERSION,
1259
- ze as addDracoAndKTX2Loaders,
1260
- Ve as configureLoader,
1261
- Ue as createLoaders,
1262
- ce as getRaycastMesh,
1263
- We as patchModelViewer,
1264
- gt as registerRaycastMesh,
1265
- at as setDracoDecoderLocation,
1266
- lt as setKTX2TranscoderLocation,
1267
- Dt as useNeedleProgressive,
1268
- pt as useRaycastMeshes
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
1269
1454
  };