@needle-tools/engine 4.7.3-next.65e7878 → 4.7.3-next.ec2c716

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.
Files changed (32) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/dist/{gltf-progressive-CCddD-3B.js → gltf-progressive-Bgh1c4Fd.js} +430 -365
  3. package/dist/gltf-progressive-D6f5talj.min.js +8 -0
  4. package/dist/gltf-progressive-otA_hxSA.umd.cjs +8 -0
  5. package/dist/{needle-engine.bundle-C6yScKUU.umd.cjs → needle-engine.bundle-CSWNTmt9.umd.cjs} +8 -8
  6. package/dist/{needle-engine.bundle-BCAZfCyl.min.js → needle-engine.bundle-Uxct1AXJ.min.js} +7 -7
  7. package/dist/{needle-engine.bundle-B0QYYufM.js → needle-engine.bundle-jF8XuQ81.js} +37 -11
  8. package/dist/needle-engine.js +3 -3
  9. package/dist/needle-engine.min.js +1 -1
  10. package/dist/needle-engine.umd.cjs +1 -1
  11. package/dist/{postprocessing-TkXiVrjY.min.js → postprocessing-BzY0H7ry.min.js} +8 -8
  12. package/dist/{postprocessing-CNCT892s.umd.cjs → postprocessing-Dw2OCMp4.umd.cjs} +8 -8
  13. package/dist/{postprocessing-qvgDnYKK.js → postprocessing-vKBVFpSz.js} +9 -9
  14. package/lib/engine/engine_lods.js +1 -1
  15. package/lib/engine/engine_lods.js.map +1 -1
  16. package/lib/engine-components/OrbitControls.d.ts +19 -1
  17. package/lib/engine-components/OrbitControls.js +30 -1
  18. package/lib/engine-components/OrbitControls.js.map +1 -1
  19. package/lib/engine-components/postprocessing/PostProcessingHandler.js +1 -1
  20. package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
  21. package/lib/engine-components/postprocessing/Volume.d.ts +3 -1
  22. package/lib/engine-components/postprocessing/Volume.js +2 -0
  23. package/lib/engine-components/postprocessing/Volume.js.map +1 -1
  24. package/package.json +2 -2
  25. package/plugins/vite/logger.client.js +68 -30
  26. package/plugins/vite/logger.js +5 -5
  27. package/src/engine/engine_lods.ts +3 -3
  28. package/src/engine-components/OrbitControls.ts +34 -2
  29. package/src/engine-components/postprocessing/PostProcessingHandler.ts +1 -1
  30. package/src/engine-components/postprocessing/Volume.ts +2 -1
  31. package/dist/gltf-progressive-BCZdu3Gc.min.js +0 -8
  32. package/dist/gltf-progressive-C6QbvrB4.umd.cjs +0 -8
@@ -1,51 +1,51 @@
1
- var He = Object.defineProperty;
1
+ var Qe = Object.defineProperty;
2
2
  var Ee = (o) => {
3
3
  throw TypeError(o);
4
4
  };
5
- var je = (o, t, e) => t in o ? He(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
6
- var d = (o, t, e) => je(o, typeof t != "symbol" ? t + "" : t, e), Ge = (o, t, e) => t.has(o) || Ee("Cannot " + e);
7
- var p = (o, t, e) => (Ge(o, t, "read from private field"), e ? e.call(o) : t.get(o)), j = (o, t, e) => t.has(o) ? Ee("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(o) : t.set(o, e), N = (o, t, e, s) => (Ge(o, t, "write to private field"), s ? s.call(o, e) : t.set(o, e), e);
8
- import { BufferGeometry as ye, Mesh as te, Texture as ne, TextureLoader as Je, Matrix4 as Be, Clock as Qe, MeshStandardMaterial as Ze, Sphere as et, Box3 as Ie, Vector3 as q } from "./three-DrqIzZTH.js";
9
- import { DRACOLoader as tt, KTX2Loader as st, MeshoptDecoder as rt, GLTFLoader as Ce } from "./three-examples-tvuhV8Ne.js";
10
- const it = "";
11
- globalThis.GLTF_PROGRESSIVE_VERSION = it;
5
+ var je = (o, t, e) => t in o ? Qe(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
6
+ var u = (o, t, e) => je(o, typeof t != "symbol" ? t + "" : t, e), $e = (o, t, e) => t.has(o) || Ee("Cannot " + e);
7
+ var x = (o, t, e) => ($e(o, t, "read from private field"), e ? e.call(o) : t.get(o)), Y = (o, t, e) => t.has(o) ? Ee("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(o) : t.set(o, e), U = (o, t, e, s) => ($e(o, t, "write to private field"), s ? s.call(o, e) : t.set(o, e), e);
8
+ import { BufferGeometry as ye, Mesh as te, Texture as ne, TextureLoader as Je, Matrix4 as Ie, Clock as Ze, MeshStandardMaterial as et, Sphere as tt, Box3 as Ge, Vector3 as V } from "./three-DrqIzZTH.js";
9
+ import { DRACOLoader as st, KTX2Loader as rt, MeshoptDecoder as it, GLTFLoader as Ce } from "./three-examples-tvuhV8Ne.js";
10
+ const nt = "";
11
+ globalThis.GLTF_PROGRESSIVE_VERSION = nt;
12
12
  console.debug("[gltf-progressive] version -");
13
- let V = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", se = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
14
- const nt = V, ot = se, Fe = new URL(V + "draco_decoder.js");
15
- Fe.searchParams.append("range", "true");
16
- fetch(Fe, {
13
+ let q = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", se = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
14
+ const ot = q, at = se, Ne = new URL(q + "draco_decoder.js");
15
+ Ne.searchParams.append("range", "true");
16
+ fetch(Ne, {
17
17
  method: "GET",
18
18
  headers: {
19
19
  Range: "bytes=0-1"
20
20
  }
21
21
  }).catch((o) => {
22
- console.debug(`Failed to fetch remote Draco decoder from ${V} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), V === nt && at("./include/draco/"), se === ot && lt("./include/ktx2/");
22
+ console.debug(`Failed to fetch remote Draco decoder from ${q} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), q === ot && lt("./include/draco/"), se === at && ut("./include/ktx2/");
23
23
  }).finally(() => {
24
24
  Ue();
25
25
  });
26
- function at(o) {
27
- V = o, G && G[Pe] != V ? (console.debug("Updating Draco decoder path to " + o), G[Pe] = V, G.setDecoderPath(V), G.preload()) : console.debug("Setting Draco decoder path to " + o);
28
- }
29
26
  function lt(o) {
30
- se = o, $ && $.transcoderPath != se ? (console.debug("Updating KTX2 transcoder path to " + o), $.setTranscoderPath(se), $.init()) : console.debug("Setting KTX2 transcoder path to " + o);
27
+ q = o, G && G[Pe] != q ? (console.debug("Updating Draco decoder path to " + o), G[Pe] = q, G.setDecoderPath(q), G.preload()) : console.debug("Setting Draco decoder path to " + o);
28
+ }
29
+ function ut(o) {
30
+ se = o, R && R.transcoderPath != se ? (console.debug("Updating KTX2 transcoder path to " + o), R.setTranscoderPath(se), R.init()) : console.debug("Setting KTX2 transcoder path to " + o);
31
31
  }
32
32
  const Pe = Symbol("dracoDecoderPath");
33
- let G, Le, $;
33
+ let G, Le, R;
34
34
  function Ue() {
35
- G || (G = new tt(), G[Pe] = V, G.setDecoderPath(V), G.setDecoderConfig({ type: "js" }), G.preload()), $ || ($ = new st(), $.setTranscoderPath(se), $.init()), Le || (Le = rt);
36
- }
37
- function Ne(o) {
38
- return Ue(), o ? $.detectSupport(o) : o !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: G, ktx2Loader: $, meshoptDecoder: Le };
35
+ G || (G = new st(), G[Pe] = q, G.setDecoderPath(q), G.setDecoderConfig({ type: "js" }), G.preload()), R || (R = new rt(), R.setTranscoderPath(se), R.init()), Le || (Le = it);
39
36
  }
40
37
  function ze(o) {
41
- o.dracoLoader || o.setDRACOLoader(G), o.ktx2Loader || o.setKTX2Loader($), o.meshoptDecoder || o.setMeshoptDecoder(Le);
38
+ return Ue(), o ? R.detectSupport(o) : o !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: G, ktx2Loader: R, meshoptDecoder: Le };
39
+ }
40
+ function qe(o) {
41
+ o.dracoLoader || o.setDRACOLoader(G), o.ktx2Loader || o.setKTX2Loader(R), o.meshoptDecoder || o.setMeshoptDecoder(Le);
42
42
  }
43
43
  const Te = /* @__PURE__ */ new WeakMap();
44
44
  function Ve(o, t) {
45
45
  let e = Te.get(o);
46
46
  e ? e = Object.assign(e, t) : e = t, Te.set(o, e);
47
47
  }
48
- const Me = Ce.prototype.load;
48
+ const ve = Ce.prototype.load;
49
49
  function dt(...o) {
50
50
  const t = Te.get(this);
51
51
  let e = o[0];
@@ -54,16 +54,16 @@ function dt(...o) {
54
54
  const r = (t == null ? void 0 : t.progressive) !== void 0 ? t.progressive : !0, i = t != null && t.usecase ? t.usecase : "default";
55
55
  r ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${i}` : this.requestHeader.Accept = `*/*;usecase=${i}`, e = s.toString();
56
56
  }
57
- return o[0] = e, Me == null ? void 0 : Me.call(this, ...o);
57
+ return o[0] = e, ve == null ? void 0 : ve.call(this, ...o);
58
58
  }
59
59
  Ce.prototype.load = dt;
60
- de("debugprogressive");
61
- function de(o) {
60
+ ue("debugprogressive");
61
+ function ue(o) {
62
62
  if (typeof window > "u") return !1;
63
63
  const e = new URL(window.location.href).searchParams.get(o);
64
64
  return e == null || e === "0" || e === "false" ? !1 : e === "" ? !0 : e;
65
65
  }
66
- function ut(o, t) {
66
+ function ct(o, t) {
67
67
  if (t === void 0 || t.startsWith("./") || t.startsWith("http") || o === void 0)
68
68
  return t;
69
69
  const e = o.lastIndexOf("/");
@@ -75,30 +75,64 @@ function ut(o, t) {
75
75
  return t;
76
76
  }
77
77
  let oe;
78
- function ct() {
79
- return oe !== void 0 || (oe = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), de("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", oe)), oe;
80
- }
81
78
  function ft() {
79
+ return oe !== void 0 || (oe = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), ue("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", oe)), oe;
80
+ }
81
+ function Be() {
82
82
  if (typeof window > "u") return !1;
83
83
  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);
84
84
  return o.hostname === "127.0.0.1" || t;
85
85
  }
86
- const ht = typeof window > "u" && typeof document > "u", Ae = Symbol("needle:raycast-mesh");
87
- function ue(o) {
86
+ class ht {
87
+ constructor(t = 100, e = {}) {
88
+ u(this, "_running", /* @__PURE__ */ new Map());
89
+ u(this, "_queue", []);
90
+ u(this, "debug", !1);
91
+ u(this, "tick", () => {
92
+ this.internalUpdate(), setTimeout(this.tick, 10);
93
+ });
94
+ this.maxConcurrent = t, this.debug = e.debug ?? !1, window.requestAnimationFrame(this.tick);
95
+ }
96
+ /**
97
+ * Request a slot for a promise with a specific key. This function returns a promise with a `use` method that can be called to add the promise to the queue.
98
+ */
99
+ slot(t) {
100
+ return this.debug && console.debug(`[PromiseQueue]: Requesting slot for key ${t}, running: ${this._running.size}, waiting: ${this._queue.length}`), new Promise((e) => {
101
+ this._queue.push({ key: t, resolve: e });
102
+ });
103
+ }
104
+ add(t, e) {
105
+ this._running.has(t) || (this._running.set(t, e), e.finally(() => {
106
+ this._running.delete(t), this.debug && console.debug(`[PromiseQueue]: Promise finished now running: ${this._running.size}, waiting: ${this._queue.length}. (finished ${t})`);
107
+ }), this.debug && console.debug(`[PromiseQueue]: Added new promise, now running: ${this._running.size}, waiting: ${this._queue.length}. (added ${t})`));
108
+ }
109
+ internalUpdate() {
110
+ const t = this.maxConcurrent - this._running.size;
111
+ for (let e = 0; e < t && this._queue.length > 0; e++) {
112
+ this.debug && console.debug(`[PromiseQueue]: Running ${this._running.size} promises, waiting for ${this._queue.length} more.`);
113
+ const { key: s, resolve: n } = this._queue.shift();
114
+ n({
115
+ use: (r) => this.add(s, r)
116
+ });
117
+ }
118
+ }
119
+ }
120
+ const gt = typeof window > "u" && typeof document > "u", Ae = Symbol("needle:raycast-mesh");
121
+ function de(o) {
88
122
  return (o == null ? void 0 : o[Ae]) instanceof ye ? o[Ae] : null;
89
123
  }
90
- function gt(o, t) {
91
- if ((o.type === "Mesh" || o.type === "SkinnedMesh") && !ue(o)) {
92
- const s = mt(t);
124
+ function pt(o, t) {
125
+ if ((o.type === "Mesh" || o.type === "SkinnedMesh") && !de(o)) {
126
+ const s = yt(t);
93
127
  s.userData = { isRaycastMesh: !0 }, o[Ae] = s;
94
128
  }
95
129
  }
96
- function pt(o = !0) {
130
+ function mt(o = !0) {
97
131
  if (o) {
98
132
  if (ae) return;
99
133
  const t = ae = te.prototype.raycast;
100
134
  te.prototype.raycast = function(e, s) {
101
- const n = this, r = ue(n);
135
+ const n = this, r = de(n);
102
136
  let i;
103
137
  r && n.isMesh && (i = n.geometry, n.geometry = r), t.call(this, e, s), i && (n.geometry = i);
104
138
  };
@@ -108,15 +142,15 @@ function pt(o = !0) {
108
142
  }
109
143
  }
110
144
  let ae = null;
111
- function mt(o) {
145
+ function yt(o) {
112
146
  const t = new ye();
113
147
  for (const e in o.attributes)
114
148
  t.setAttribute(e, o.getAttribute(e));
115
149
  return t.setIndex(o.getIndex()), t;
116
150
  }
117
- const Q = new Array(), y = de("debugprogressive");
151
+ const Q = new Array(), L = ue("debugprogressive");
118
152
  let pe, ee = -1;
119
- if (y) {
153
+ if (L) {
120
154
  let o = function() {
121
155
  ee += 1, ee >= t && (ee = -1), console.log(`Toggle LOD level [${ee}]`);
122
156
  }, t = 6;
@@ -127,31 +161,31 @@ if (y) {
127
161
  });
128
162
  }
129
163
  function We(o) {
130
- if (y)
164
+ if (L)
131
165
  if (Array.isArray(o))
132
166
  for (const t of o)
133
167
  We(t);
134
168
  else o && "wireframe" in o && (o.wireframe = pe === !0);
135
169
  }
136
- const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = class w {
170
+ const W = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), _ = class _ {
137
171
  constructor(t, e) {
138
- d(this, "parser");
139
- d(this, "url");
140
- d(this, "_isLoadingMesh");
141
- d(this, "loadMesh", (t) => {
172
+ u(this, "parser");
173
+ u(this, "url");
174
+ u(this, "_isLoadingMesh");
175
+ u(this, "loadMesh", (t) => {
142
176
  var s, n;
143
177
  if (this._isLoadingMesh) return null;
144
- const e = (n = (s = this.parser.json.meshes[t]) == null ? void 0 : s.extensions) == null ? void 0 : n[K];
178
+ const e = (n = (s = this.parser.json.meshes[t]) == null ? void 0 : s.extensions) == null ? void 0 : n[W];
145
179
  return e ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", t).then((r) => {
146
180
  var i;
147
- return this._isLoadingMesh = !1, r && w.registerMesh(this.url, e.guid, r, (i = e.lods) == null ? void 0 : i.length, 0, e), r;
181
+ return this._isLoadingMesh = !1, r && _.registerMesh(this.url, e.guid, r, (i = e.lods) == null ? void 0 : i.length, 0, e), r;
148
182
  })) : null;
149
183
  });
150
- y && console.log("Progressive extension registered for", e), this.parser = t, this.url = e;
184
+ L && console.log("Progressive extension registered for", e), this.parser = t, this.url = e;
151
185
  }
152
186
  /** The name of the extension */
153
187
  get name() {
154
- return K;
188
+ return W;
155
189
  }
156
190
  static getMeshLODExtension(t) {
157
191
  const e = this.getAssignedLODInformation(t);
@@ -174,7 +208,7 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
174
208
  this.getMaterialMinMaxLODsCount(a, e);
175
209
  return t[n] = e, e;
176
210
  }
177
- if (y === "verbose" && console.log("getMaterialMinMaxLODsCount", t), t.type === "ShaderMaterial" || t.type === "RawShaderMaterial") {
211
+ if (L === "verbose" && console.log("getMaterialMinMaxLODsCount", t), t.type === "ShaderMaterial" || t.type === "RawShaderMaterial") {
178
212
  const a = t;
179
213
  for (const l of Object.keys(a.uniforms)) {
180
214
  const c = a.uniforms[l].value;
@@ -189,12 +223,12 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
189
223
  function i(a, l) {
190
224
  const c = s.getAssignedLODInformation(a);
191
225
  if (c) {
192
- const u = s.lodInfos.get(c.key);
193
- if (u && u.lods) {
194
- l.min_count = Math.min(l.min_count, u.lods.length), l.max_count = Math.max(l.max_count, u.lods.length);
195
- for (let h = 0; h < u.lods.length; h++) {
196
- const g = u.lods[h];
197
- g.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, g.height), l.lods[h].max_height = Math.max(l.lods[h].max_height, g.height));
226
+ const d = s.lodInfos.get(c.key);
227
+ if (d && d.lods) {
228
+ l.min_count = Math.min(l.min_count, d.lods.length), l.max_count = Math.max(l.max_count, d.lods.length);
229
+ for (let h = 0; h < d.lods.length; h++) {
230
+ const f = d.lods[h];
231
+ 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));
198
232
  }
199
233
  }
200
234
  }
@@ -256,14 +290,14 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
256
290
  return Promise.resolve(null);
257
291
  for (const i of Q)
258
292
  (s = i.onBeforeGetLODMesh) == null || s.call(i, t, e);
259
- return t["LOD:requested level"] = e, w.getOrLoadLOD(n, e).then((i) => {
293
+ return t["LOD:requested level"] = e, _.getOrLoadLOD(n, e).then((i) => {
260
294
  if (Array.isArray(i)) {
261
295
  const a = r.index || 0;
262
296
  i = i[a];
263
297
  }
264
- 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;
298
+ return t["LOD:requested level"] === e && (delete t["LOD:requested level"], i && n != i && ((i == null ? void 0 : i.isBufferGeometry) ? t.geometry = i : L && console.error("Invalid LOD geometry", i))), i;
265
299
  }).catch((i) => (console.error("Error loading mesh LOD", t, i), null));
266
- } else y && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", t);
300
+ } else L && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", t);
267
301
  return Promise.resolve(null);
268
302
  }
269
303
  static assignTextureLOD(t, e = 0) {
@@ -292,7 +326,7 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
292
326
  for (const a of Object.keys(i.uniforms)) {
293
327
  const l = i.uniforms[a].value;
294
328
  if ((l == null ? void 0 : l.isTexture) === !0) {
295
- const c = this.assignTextureLODForSlot(l, e, s, a).then((u) => (u && i.uniforms[a].value != u && (i.uniforms[a].value = u, i.uniformsNeedUpdate = !0), u));
329
+ 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));
296
330
  n.push(c), r.push(a);
297
331
  }
298
332
  }
@@ -307,8 +341,8 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
307
341
  return Promise.all(n).then((i) => {
308
342
  const a = new Array();
309
343
  for (let l = 0; l < i.length; l++) {
310
- const c = i[l], u = r[l];
311
- c && c.isTexture === !0 ? a.push({ material: s, slot: u, texture: c, level: e }) : a.push({ material: s, slot: u, texture: null, level: e });
344
+ const c = i[l], d = r[l];
345
+ c && c.isTexture === !0 ? a.push({ material: s, slot: d, texture: c, level: e }) : a.push({ material: s, slot: d, texture: null, level: e });
312
346
  }
313
347
  return a;
314
348
  });
@@ -320,178 +354,197 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
320
354
  return Promise.resolve(null);
321
355
  }
322
356
  static assignTextureLODForSlot(t, e, s, n) {
323
- return (t == null ? void 0 : t.isTexture) !== !0 ? Promise.resolve(null) : n === "glyphMap" ? Promise.resolve(t) : w.getOrLoadLOD(t, e).then((r) => {
324
- if (Array.isArray(r)) return null;
357
+ return (t == null ? void 0 : t.isTexture) !== !0 ? Promise.resolve(null) : n === "glyphMap" ? Promise.resolve(t) : _.getOrLoadLOD(t, e).then((r) => {
358
+ if (Array.isArray(r))
359
+ return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen", r), null;
325
360
  if ((r == null ? void 0 : r.isTexture) === !0) {
326
361
  if (r != t && s && n) {
327
362
  const i = s[n];
328
- if (i && !y) {
363
+ if (i && !L) {
329
364
  const a = this.getAssignedLODInformation(i);
330
365
  if (a && (a == null ? void 0 : a.level) < e)
331
- return y === "verbose" && console.warn("Assigned texture level is already higher: ", a.level, e, s, i, r), null;
366
+ return L === "verbose" && console.warn("Assigned texture level is already higher: ", a.level, e, s, i, r), null;
332
367
  }
333
368
  s[n] = r;
334
369
  }
335
370
  return r;
336
- } else y == "verbose" && console.warn("No LOD found for", t, e);
371
+ } else L == "verbose" && console.warn("No LOD found for", t, e);
337
372
  return null;
338
373
  }).catch((r) => (console.error("Error loading LOD", t, r), null));
339
374
  }
375
+ // private _isLoadingTexture;
376
+ // loadTexture = (textureIndex: number) => {
377
+ // if (this._isLoadingTexture) return null;
378
+ // const ext = this.parser.json.textures[textureIndex]?.extensions?.[EXTENSION_NAME] as NEEDLE_ext_progressive_texture;
379
+ // if (!ext) return null;
380
+ // this._isLoadingTexture = true;
381
+ // return this.parser.getDependency("texture", textureIndex).then(tex => {
382
+ // this._isLoadingTexture = false;
383
+ // if (tex) {
384
+ // NEEDLE_progressive.registerTexture(this.url, tex as Texture, ext.lods?.length, textureIndex, ext);
385
+ // }
386
+ // return tex;
387
+ // });
388
+ // }
340
389
  afterRoot(t) {
341
390
  var e, s;
342
- return y && console.log("AFTER", this.url, t), (e = this.parser.json.textures) == null || e.forEach((n, r) => {
391
+ return L && console.log("AFTER", this.url, t), (e = this.parser.json.textures) == null || e.forEach((n, r) => {
343
392
  var i;
344
393
  if (n != null && n.extensions) {
345
- const a = n == null ? void 0 : n.extensions[K];
394
+ const a = n == null ? void 0 : n.extensions[W];
346
395
  if (a) {
347
396
  if (!a.lods) {
348
- y && console.warn("Texture has no LODs", a);
397
+ L && console.warn("Texture has no LODs", a);
349
398
  return;
350
399
  }
351
400
  let l = !1;
352
401
  for (const c of this.parser.associations.keys())
353
402
  if (c.isTexture === !0) {
354
- const u = this.parser.associations.get(c);
355
- (u == null ? void 0 : u.textures) === r && (l = !0, w.registerTexture(this.url, c, (i = a.lods) == null ? void 0 : i.length, r, a));
403
+ const d = this.parser.associations.get(c);
404
+ (d == null ? void 0 : d.textures) === r && (l = !0, _.registerTexture(this.url, c, (i = a.lods) == null ? void 0 : i.length, r, a));
356
405
  }
357
406
  l || this.parser.getDependency("texture", r).then((c) => {
358
- var u;
359
- c && w.registerTexture(this.url, c, (u = a.lods) == null ? void 0 : u.length, r, a);
407
+ var d;
408
+ c && _.registerTexture(this.url, c, (d = a.lods) == null ? void 0 : d.length, r, a);
360
409
  });
361
410
  }
362
411
  }
363
412
  }), (s = this.parser.json.meshes) == null || s.forEach((n, r) => {
364
413
  if (n != null && n.extensions) {
365
- const i = n == null ? void 0 : n.extensions[K];
414
+ const i = n == null ? void 0 : n.extensions[W];
366
415
  if (i && i.lods) {
367
416
  for (const a of this.parser.associations.keys())
368
417
  if (a.isMesh) {
369
418
  const l = this.parser.associations.get(a);
370
- (l == null ? void 0 : l.meshes) === r && w.registerMesh(this.url, i.guid, a, i.lods.length, l.primitives, i);
419
+ (l == null ? void 0 : l.meshes) === r && _.registerMesh(this.url, i.guid, a, i.lods.length, l.primitives, i);
371
420
  }
372
421
  }
373
422
  }
374
423
  }), null;
375
424
  }
376
425
  static async getOrLoadLOD(t, e) {
377
- var a, l, c, u;
378
- const s = y == "verbose", n = t.userData.LODS;
426
+ var a, l, c, d;
427
+ const s = L == "verbose", n = this.getAssignedLODInformation(t);
379
428
  if (!n)
380
- return null;
429
+ return L && console.warn(`[gltf-progressive] No LOD information found: ${t.name}, uuid: ${t.uuid}, type: ${t.type}`, t), null;
381
430
  const r = n == null ? void 0 : n.key;
382
431
  let i;
383
432
  if (t.isTexture === !0) {
384
433
  const h = t;
385
434
  h.source && h.source[Oe] && (i = h.source[Oe]);
386
435
  }
387
- if (i || (i = w.lodInfos.get(r)), i) {
436
+ if (i || (i = _.lodInfos.get(r)), i) {
388
437
  if (e > 0) {
389
- let v = !1;
390
- const b = Array.isArray(i.lods);
391
- if (b && e >= i.lods.length ? v = !0 : b || (v = !0), v)
438
+ let D = !1;
439
+ const v = Array.isArray(i.lods);
440
+ if (v && e >= i.lods.length ? D = !0 : v || (D = !0), D)
392
441
  return this.lowresCache.get(r);
393
442
  }
394
443
  const h = Array.isArray(i.lods) ? (a = i.lods[e]) == null ? void 0 : a.path : i.lods;
395
444
  if (!h)
396
- return y && !i["missing:uri"] && (i["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, i)), null;
397
- const g = ut(n.url, h);
398
- if (g.endsWith(".glb") || g.endsWith(".gltf")) {
445
+ return L && !i["missing:uri"] && (i["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, i)), null;
446
+ const f = ct(n.url, h);
447
+ if (f.endsWith(".glb") || f.endsWith(".gltf")) {
399
448
  if (!i.guid)
400
449
  return console.warn("missing pointer for glb/gltf texture", i), null;
401
- const v = g + "_" + i.guid, b = this.previouslyLoaded.get(v);
402
- if (b !== void 0) {
403
- s && console.log(`LOD ${e} was already loading/loaded: ${v}`);
404
- let D = await b.catch((m) => (console.error(`Error loading LOD ${e} from ${g}
405
- `, m), null)), O = !1;
406
- if (D == null || (D instanceof ne && t instanceof ne ? (l = D.image) != null && l.data || (c = D.source) != null && c.data ? D = this.copySettings(t, D) : (O = !0, this.previouslyLoaded.delete(v)) : D instanceof ye && t instanceof ye && ((u = D.attributes.position) != null && u.array || (O = !0, this.previouslyLoaded.delete(v)))), !O)
407
- return D;
450
+ const D = f + "_" + i.guid, v = this.previouslyLoaded.get(D);
451
+ if (v !== void 0) {
452
+ s && console.log(`LOD ${e} was already loading/loaded: ${D}`);
453
+ let g = await v.catch((A) => (console.error(`Error loading LOD ${e} from ${f}
454
+ `, A), null)), w = !1;
455
+ if (g == null || (g instanceof ne && t instanceof ne ? (l = g.image) != null && l.data || (c = g.source) != null && c.data ? g = this.copySettings(t, g) : (w = !0, this.previouslyLoaded.delete(D)) : g instanceof ye && t instanceof ye && ((d = g.attributes.position) != null && d.array || (w = !0, this.previouslyLoaded.delete(D)))), !w)
456
+ return g;
408
457
  }
409
- const _ = i, F = new Promise(async (D, O) => {
410
- const m = new Ce();
411
- ze(m), y && (await new Promise((S) => setTimeout(S, 1e3)), s && console.warn("Start loading (delayed) " + g, _.guid));
412
- let X = g;
413
- if (_ && Array.isArray(_.lods)) {
414
- const S = _.lods[e];
415
- S.hash && (X += "?v=" + S.hash);
458
+ const P = await this.queue.slot(f);
459
+ if (!P.use)
460
+ return L && console.log(`LOD ${e} was aborted: ${f}`), null;
461
+ const b = i, B = new Promise(async (g, w) => {
462
+ const A = new Ce();
463
+ qe(A), L && (await new Promise((O) => setTimeout(O, 1e3)), s && console.warn("Start loading (delayed) " + f, b.guid));
464
+ let F = f;
465
+ if (b && Array.isArray(b.lods)) {
466
+ const O = b.lods[e];
467
+ O.hash && (F += "?v=" + O.hash);
416
468
  }
417
- const T = await m.loadAsync(X).catch((S) => (console.error(`Error loading LOD ${e} from ${g}
418
- `, S), null));
419
- if (!T) return null;
420
- const I = T.parser;
421
- s && console.log("Loading finished " + g, _.guid);
422
- let B = 0;
423
- if (T.parser.json.textures) {
424
- let S = !1;
425
- for (const f of T.parser.json.textures) {
426
- if (f != null && f.extensions) {
427
- const P = f == null ? void 0 : f.extensions[K];
428
- if (P != null && P.guid && P.guid === _.guid) {
429
- S = !0;
469
+ const S = await A.loadAsync(F).catch((O) => (console.error(`Error loading LOD ${e} from ${f}
470
+ `, O), g(null)));
471
+ if (!S)
472
+ return g(null);
473
+ const Z = S.parser;
474
+ s && console.log("Loading finished " + f, b.guid);
475
+ let C = 0;
476
+ if (S.parser.json.textures) {
477
+ let O = !1;
478
+ for (const m of S.parser.json.textures) {
479
+ if (m != null && m.extensions) {
480
+ const p = m == null ? void 0 : m.extensions[W];
481
+ if (p != null && p.guid && p.guid === b.guid) {
482
+ O = !0;
430
483
  break;
431
484
  }
432
485
  }
433
- B++;
486
+ C++;
434
487
  }
435
- if (S) {
436
- let f = await I.getDependency("texture", B);
437
- return f && w.assignLODInformation(n.url, f, r, e, void 0), s && console.log('change "' + t.name + '" → "' + f.name + '"', g, B, f, v), t instanceof ne && (f = this.copySettings(t, f)), f && (f.guid = _.guid), D(f);
438
- } else y && console.warn("Could not find texture with guid", _.guid, T.parser.json);
488
+ if (O) {
489
+ let m = await Z.getDependency("texture", C);
490
+ return m && _.assignLODInformation(n.url, m, r, e, void 0), s && console.log('change "' + t.name + '" → "' + m.name + '"', f, C, m, D), t instanceof ne && (m = this.copySettings(t, m)), m && (m.guid = b.guid), g(m);
491
+ } else L && console.warn("Could not find texture with guid", b.guid, S.parser.json);
439
492
  }
440
- if (B = 0, T.parser.json.meshes) {
441
- let S = !1;
442
- for (const f of T.parser.json.meshes) {
443
- if (f != null && f.extensions) {
444
- const P = f == null ? void 0 : f.extensions[K];
445
- if (P != null && P.guid && P.guid === _.guid) {
446
- S = !0;
493
+ if (C = 0, S.parser.json.meshes) {
494
+ let O = !1;
495
+ for (const m of S.parser.json.meshes) {
496
+ if (m != null && m.extensions) {
497
+ const p = m == null ? void 0 : m.extensions[W];
498
+ if (p != null && p.guid && p.guid === b.guid) {
499
+ O = !0;
447
500
  break;
448
501
  }
449
502
  }
450
- B++;
503
+ C++;
451
504
  }
452
- if (S) {
453
- const f = await I.getDependency("mesh", B);
454
- if (s && console.log(`Loaded Mesh "${f.name}"`, g, B, f, v), f.isMesh === !0) {
455
- const P = f.geometry;
456
- return w.assignLODInformation(n.url, P, r, e, 0), D(P);
505
+ if (O) {
506
+ const m = await Z.getDependency("mesh", C);
507
+ if (s && console.log(`Loaded Mesh "${m.name}"`, f, C, m, D), m.isMesh === !0) {
508
+ const p = m.geometry;
509
+ return _.assignLODInformation(n.url, p, r, e, 0), g(p);
457
510
  } else {
458
- const P = new Array();
459
- for (let x = 0; x < f.children.length; x++) {
460
- const M = f.children[x];
461
- if (M.isMesh === !0) {
462
- const A = M.geometry;
463
- w.assignLODInformation(n.url, A, r, e, x), P.push(A);
511
+ const p = new Array();
512
+ for (let M = 0; M < m.children.length; M++) {
513
+ const E = m.children[M];
514
+ if (E.isMesh === !0) {
515
+ const T = E.geometry;
516
+ _.assignLODInformation(n.url, T, r, e, M), p.push(T);
464
517
  }
465
518
  }
466
- return D(P);
519
+ return g(p);
467
520
  }
468
- } else y && console.warn("Could not find mesh with guid", _.guid, T.parser.json);
521
+ } else L && console.warn("Could not find mesh with guid", b.guid, S.parser.json);
469
522
  }
470
- return D(null);
523
+ return g(null);
471
524
  });
472
- return this.previouslyLoaded.set(v, F), await F;
525
+ return this.previouslyLoaded.set(D, B), P.use(B), await B;
473
526
  } else if (t instanceof ne) {
474
- s && console.log("Load texture from uri: " + g);
475
- const b = await new Je().loadAsync(g);
476
- return b ? (b.guid = i.guid, b.flipY = !1, b.needsUpdate = !0, b.colorSpace = t.colorSpace, s && console.log(i, b)) : y && console.warn("failed loading", g), b;
527
+ s && console.log("Load texture from uri: " + f);
528
+ const v = await new Je().loadAsync(f);
529
+ return v ? (v.guid = i.guid, v.flipY = !1, v.needsUpdate = !0, v.colorSpace = t.colorSpace, s && console.log(i, v)) : L && console.warn("failed loading", f), v;
477
530
  }
478
531
  } else
479
- y && console.warn(`Can not load LOD ${e}: no LOD info found for "${r}" ${t.name}`, t.type);
532
+ L && console.warn(`Can not load LOD ${e}: no LOD info found for "${r}" ${t.name}`, t.type);
480
533
  return null;
481
534
  }
482
535
  static assignLODInformation(t, e, s, n, r) {
483
536
  if (!e) return;
484
537
  e.userData || (e.userData = {});
485
- const i = new yt(t, s, n, r);
486
- e.userData.LODS = i;
538
+ const i = new Lt(t, s, n, r);
539
+ e.userData.LODS = i, "source" in e && typeof e.source == "object" && (e.source.LODS = i);
487
540
  }
488
541
  static getAssignedLODInformation(t) {
489
- var e;
490
- return ((e = t == null ? void 0 : t.userData) == null ? void 0 : e.LODS) || null;
542
+ var e, s;
543
+ 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;
491
544
  }
492
545
  // private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
493
546
  static copySettings(t, e) {
494
- return e ? (y && console.warn(`Copy texture settings
547
+ return e ? (L && console.warn(`Copy texture settings
495
548
  `, t.uuid, `
496
549
  `, 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;
497
550
  }
@@ -499,60 +552,65 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
499
552
  /**
500
553
  * Register a texture with LOD information
501
554
  */
502
- d(w, "registerTexture", (t, e, s, n, r) => {
503
- if (y && console.log("> Progressive: register texture", n, e.name, e.uuid, e, r), !e) {
504
- y && console.error("gltf-progressive: Register texture without texture");
555
+ u(_, "registerTexture", (t, e, s, n, r) => {
556
+ var a, l, c, d, h, f, D, v;
557
+ if (!e) {
558
+ L && console.error("gltf-progressive: Called register texture without texture");
505
559
  return;
506
560
  }
561
+ if (L) {
562
+ 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, b = ((d = e.image) == null ? void 0 : d.height) || ((f = (h = e.source) == null ? void 0 : h.data) == null ? void 0 : f.height) || 0;
563
+ console.log(`> Progressive: register texture[${n}] "${e.name || e.uuid}", Current: ${P}x${b}, Max: ${(D = r.lods[0]) == null ? void 0 : D.width}x${(v = r.lods[0]) == null ? void 0 : v.height}, uuid: ${e.uuid}`, r, e);
564
+ }
507
565
  e.source && (e.source[Oe] = r);
508
566
  const i = r.guid;
509
- w.assignLODInformation(t, e, i, s, n), w.lodInfos.set(i, r), w.lowresCache.set(i, e);
567
+ _.assignLODInformation(t, e, i, s, n), _.lodInfos.set(i, r), _.lowresCache.set(i, e);
510
568
  }), /**
511
569
  * Register a mesh with LOD information
512
570
  */
513
- d(w, "registerMesh", (t, e, s, n, r, i) => {
571
+ u(_, "registerMesh", (t, e, s, n, r, i) => {
514
572
  var c;
515
573
  const a = s.geometry;
516
574
  if (!a) {
517
- y && console.warn("gltf-progressive: Register mesh without geometry");
575
+ L && console.warn("gltf-progressive: Register mesh without geometry");
518
576
  return;
519
577
  }
520
- a.userData || (a.userData = {}), y && console.log("> Progressive: register mesh " + s.name, { index: r, uuid: s.uuid }, i, s), w.assignLODInformation(t, a, e, n, r), w.lodInfos.set(e, i);
521
- let l = w.lowresCache.get(e);
522
- l ? l.push(s.geometry) : l = [s.geometry], w.lowresCache.set(e, l), n > 0 && !ue(s) && gt(s, a);
523
- for (const u of Q)
524
- (c = u.onRegisteredNewMesh) == null || c.call(u, s, i);
578
+ a.userData || (a.userData = {}), L && console.log("> Progressive: register mesh " + s.name, { index: r, uuid: s.uuid }, i, s), _.assignLODInformation(t, a, e, n, r), _.lodInfos.set(e, i);
579
+ let l = _.lowresCache.get(e);
580
+ l ? l.push(s.geometry) : l = [s.geometry], _.lowresCache.set(e, l), n > 0 && !de(s) && pt(s, a);
581
+ for (const d of Q)
582
+ (c = d.onRegisteredNewMesh) == null || c.call(d, s, i);
525
583
  }), /** A map of key = asset uuid and value = LOD information */
526
- d(w, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
527
- d(w, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
528
- d(w, "lowresCache", /* @__PURE__ */ new Map());
529
- let z = w;
530
- class yt {
584
+ u(_, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
585
+ u(_, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
586
+ u(_, "lowresCache", /* @__PURE__ */ new Map()), u(_, "queue", new ht(100, { debug: L != !1 }));
587
+ let z = _;
588
+ class Lt {
531
589
  constructor(t, e, s, n) {
532
- d(this, "url");
590
+ u(this, "url");
533
591
  /** the key to lookup the LOD information */
534
- d(this, "key");
535
- d(this, "level");
592
+ u(this, "key");
593
+ u(this, "level");
536
594
  /** For multi objects (e.g. a group of meshes) this is the index of the object */
537
- d(this, "index");
595
+ u(this, "index");
538
596
  this.url = t, this.key = e, this.level = s, n != null && (this.index = n);
539
597
  }
540
598
  }
541
599
  class me {
542
600
  constructor(t, e) {
543
- d(this, "frame_start");
544
- d(this, "frame_capture_end");
545
- d(this, "ready");
546
- d(this, "_resolve");
547
- d(this, "_signal");
548
- d(this, "_resolved", !1);
549
- d(this, "_addedCount", 0);
550
- d(this, "_resolvedCount", 0);
601
+ u(this, "frame_start");
602
+ u(this, "frame_capture_end");
603
+ u(this, "ready");
604
+ u(this, "_resolve");
605
+ u(this, "_signal");
606
+ u(this, "_resolved", !1);
607
+ u(this, "_addedCount", 0);
608
+ u(this, "_resolvedCount", 0);
551
609
  /** These promises are currently being awaited */
552
- d(this, "_awaiting", []);
553
- d(this, "_maxPromisesPerObject", 1);
554
- d(this, "_currentFrame", 0);
555
- d(this, "_seen", /* @__PURE__ */ new WeakMap());
610
+ u(this, "_awaiting", []);
611
+ u(this, "_maxPromisesPerObject", 1);
612
+ u(this, "_currentFrame", 0);
613
+ u(this, "_seen", /* @__PURE__ */ new WeakMap());
556
614
  var r;
557
615
  const n = Math.max(e.frames ?? 2, 2);
558
616
  this.frame_start = t, this.frame_capture_end = t + n, this.ready = new Promise((i) => {
@@ -581,7 +639,7 @@ class me {
581
639
  }
582
640
  add(t, e, s) {
583
641
  if (this._resolved) {
584
- y && console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");
642
+ L && console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");
585
643
  return;
586
644
  }
587
645
  if (!(this._currentFrame > this.frame_capture_end)) {
@@ -589,7 +647,7 @@ class me {
589
647
  if (this._seen.has(e)) {
590
648
  let n = this._seen.get(e);
591
649
  if (n >= this._maxPromisesPerObject) {
592
- y && console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");
650
+ L && console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");
593
651
  return;
594
652
  }
595
653
  this._seen.set(e, n + 1);
@@ -609,65 +667,65 @@ class me {
609
667
  });
610
668
  }
611
669
  }
612
- d(me, "addPromise", (t, e, s, n) => {
670
+ u(me, "addPromise", (t, e, s, n) => {
613
671
  n.forEach((r) => {
614
672
  r.add(t, e, s);
615
673
  });
616
674
  });
617
- const k = de("debugprogressive"), Lt = de("noprogressive"), be = Symbol("Needle:LODSManager"), Se = Symbol("Needle:LODState"), J = Symbol("Needle:CurrentLOD"), C = { mesh_lod: -1, texture_lod: -1 };
618
- var L, E, Y, we, Z, re, _e, H;
619
- let xe = (L = class {
675
+ const k = ue("debugprogressive"), xt = ue("noprogressive"), be = Symbol("Needle:LODSManager"), Se = Symbol("Needle:LODState"), H = Symbol("Needle:CurrentLOD"), $ = { mesh_lod: -1, texture_lod: -1 };
676
+ var y, I, X, we, j, re, _e, K;
677
+ let xe = (y = class {
620
678
  // readonly plugins: NEEDLE_progressive_plugin[] = [];
621
679
  constructor(t, e) {
622
- d(this, "renderer");
623
- d(this, "context");
624
- d(this, "projectionScreenMatrix", new Be());
680
+ u(this, "renderer");
681
+ u(this, "context");
682
+ u(this, "projectionScreenMatrix", new Ie());
625
683
  /**
626
684
  * The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
627
685
  * @default 200_000
628
686
  */
629
- d(this, "targetTriangleDensity", 2e5);
687
+ u(this, "targetTriangleDensity", 2e5);
630
688
  /**
631
689
  * The interval in frames to automatically update the bounds of skinned meshes.
632
690
  * Set to 0 or a negative value to disable automatic bounds updates.
633
691
  * @default 30
634
692
  */
635
- d(this, "skinnedMeshAutoUpdateBoundsInterval", 30);
693
+ u(this, "skinnedMeshAutoUpdateBoundsInterval", 30);
636
694
  /**
637
695
  * 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.
638
696
  * @default "auto"
639
697
  */
640
- d(this, "updateInterval", "auto");
641
- j(this, E, 1);
698
+ u(this, "updateInterval", "auto");
699
+ Y(this, I, 1);
642
700
  /**
643
701
  * If set to true, the LODsManager will not update the LODs.
644
702
  * @default false
645
703
  */
646
- d(this, "pause", !1);
704
+ u(this, "pause", !1);
647
705
  /**
648
706
  * When set to true the LODsManager will not update the LODs. This can be used to manually update the LODs using the `update` method.
649
707
  * Otherwise the LODs will be updated automatically when the renderer renders the scene.
650
708
  * @default false
651
709
  */
652
- d(this, "manual", !1);
653
- d(this, "_newPromiseGroups", []);
654
- d(this, "_promiseGroupIds", 0);
655
- d(this, "_lodchangedlisteners", []);
656
- j(this, Y);
657
- j(this, we, new Qe());
658
- j(this, Z, 0);
659
- j(this, re, 0);
660
- j(this, _e, 0);
661
- j(this, H, 0);
662
- d(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
710
+ u(this, "manual", !1);
711
+ u(this, "_newPromiseGroups", []);
712
+ u(this, "_promiseGroupIds", 0);
713
+ u(this, "_lodchangedlisteners", []);
714
+ Y(this, X);
715
+ Y(this, we, new Ze());
716
+ Y(this, j, 0);
717
+ Y(this, re, 0);
718
+ Y(this, _e, 0);
719
+ Y(this, K, 0);
720
+ u(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
663
721
  // private testIfLODLevelsAreAvailable() {
664
- d(this, "_sphere", new et());
665
- d(this, "_tempBox", new Ie());
666
- d(this, "_tempBox2", new Ie());
667
- d(this, "tempMatrix", new Be());
668
- d(this, "_tempWorldPosition", new q());
669
- d(this, "_tempBoxSize", new q());
670
- d(this, "_tempBox2Size", new q());
722
+ u(this, "_sphere", new tt());
723
+ u(this, "_tempBox", new Ge());
724
+ u(this, "_tempBox2", new Ge());
725
+ u(this, "tempMatrix", new Ie());
726
+ u(this, "_tempWorldPosition", new V());
727
+ u(this, "_tempBoxSize", new V());
728
+ u(this, "_tempBox2Size", new V());
671
729
  this.renderer = t, this.context = { ...e };
672
730
  }
673
731
  /** @internal */
@@ -689,7 +747,7 @@ let xe = (L = class {
689
747
  static get(t, e) {
690
748
  if (t[be])
691
749
  return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[be];
692
- const s = new L(t, {
750
+ const s = new y(t, {
693
751
  engine: "unknown",
694
752
  ...e
695
753
  });
@@ -703,12 +761,12 @@ let xe = (L = class {
703
761
  * Call to await LODs loading during the next render cycle.
704
762
  */
705
763
  awaitLoading(t) {
706
- const e = this._promiseGroupIds++, s = new me(p(this, Z), { ...t });
764
+ const e = this._promiseGroupIds++, s = new me(x(this, j), { ...t });
707
765
  this._newPromiseGroups.push(s);
708
766
  const n = performance.now();
709
767
  return s.ready.finally(() => {
710
768
  const r = this._newPromiseGroups.indexOf(s);
711
- r >= 0 && (this._newPromiseGroups.splice(r, 1), ft() && performance.measure("LODsManager:awaitLoading", {
769
+ r >= 0 && (this._newPromiseGroups.splice(r, 1), Be() && performance.measure("LODsManager:awaitLoading", {
712
770
  start: n,
713
771
  detail: { id: e, name: t == null ? void 0 : t.name, awaited: s.awaitedCount, resolved: s.resolvedCount }
714
772
  }));
@@ -717,7 +775,7 @@ let xe = (L = class {
717
775
  _postprocessPromiseGroups() {
718
776
  if (this._newPromiseGroups.length !== 0)
719
777
  for (let t = this._newPromiseGroups.length - 1; t >= 0; t--)
720
- this._newPromiseGroups[t].update(p(this, Z));
778
+ this._newPromiseGroups[t].update(x(this, j));
721
779
  }
722
780
  addEventListener(t, e) {
723
781
  t === "changed" && this._lodchangedlisteners.push(e);
@@ -732,20 +790,20 @@ let xe = (L = class {
732
790
  * Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
733
791
  */
734
792
  enable() {
735
- if (p(this, Y)) return;
793
+ if (x(this, X)) return;
736
794
  console.debug("[gltf-progressive] Enabling LODsManager for renderer");
737
795
  let t = 0;
738
- N(this, Y, this.renderer.render);
796
+ U(this, X, this.renderer.render);
739
797
  const e = this;
740
- Ne(this.renderer), this.renderer.render = function(s, n) {
798
+ ze(this.renderer), this.renderer.render = function(s, n) {
741
799
  const r = e.renderer.getRenderTarget();
742
- (r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (t = 0, N(e, Z, p(e, Z) + 1), N(e, re, p(e, we).getDelta()), N(e, _e, p(e, _e) + p(e, re)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / p(e, re)), N(e, H, e._fpsBuffer.reduce((a, l) => a + l) / e._fpsBuffer.length), k && p(e, Z) % 200 === 0 && console.log("FPS", Math.round(p(e, H)), "Interval:", p(e, E)));
800
+ (r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (t = 0, U(e, j, x(e, j) + 1), U(e, re, x(e, we).getDelta()), U(e, _e, x(e, _e) + x(e, re)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / x(e, re)), U(e, K, e._fpsBuffer.reduce((a, l) => a + l) / e._fpsBuffer.length), k && x(e, j) % 200 === 0 && console.log("FPS", Math.round(x(e, K)), "Interval:", x(e, I)));
743
801
  const i = t++;
744
- p(e, Y).call(this, s, n), e.onAfterRender(s, n, i);
802
+ x(e, X).call(this, s, n), e.onAfterRender(s, n, i);
745
803
  };
746
804
  }
747
805
  disable() {
748
- p(this, Y) && (console.debug("[gltf-progressive] Disabling LODsManager for renderer"), this.renderer.render = p(this, Y), N(this, Y, void 0));
806
+ x(this, X) && (console.debug("[gltf-progressive] Disabling LODsManager for renderer"), this.renderer.render = x(this, X), U(this, X, void 0));
749
807
  }
750
808
  update(t, e) {
751
809
  this.internalUpdate(t, e);
@@ -759,7 +817,7 @@ let xe = (L = class {
759
817
  (a.name === "EffectMaterial" || a.name === "CopyShader") && (i = !1);
760
818
  }
761
819
  if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (i = !1), i) {
762
- if (Lt || (this.updateInterval === "auto" ? p(this, H) < 40 && p(this, E) < 10 ? (N(this, E, p(this, E) + 1), k && console.warn("↓ Reducing LOD updates", p(this, E), p(this, H).toFixed(0))) : p(this, H) >= 60 && p(this, E) > 1 && (N(this, E, p(this, E) - 1), k && console.warn("↑ Increasing LOD updates", p(this, E), p(this, H).toFixed(0))) : N(this, E, this.updateInterval), p(this, E) > 0 && p(this, Z) % p(this, E) != 0))
820
+ if (xt || (this.updateInterval === "auto" ? x(this, K) < 40 && x(this, I) < 10 ? (U(this, I, x(this, I) + 1), k && console.warn("↓ Reducing LOD updates", x(this, I), x(this, K).toFixed(0))) : x(this, K) >= 60 && x(this, I) > 1 && (U(this, I, x(this, I) - 1), k && console.warn("↑ Increasing LOD updates", x(this, I), x(this, K).toFixed(0))) : U(this, I, this.updateInterval), x(this, I) > 0 && x(this, j) % x(this, I) != 0))
763
821
  return;
764
822
  this.internalUpdate(t, e), this._postprocessPromiseGroups();
765
823
  }
@@ -772,12 +830,12 @@ let xe = (L = class {
772
830
  const s = this.renderer.renderLists.get(t, 0), n = s.opaque;
773
831
  this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix, e.matrixWorldInverse);
774
832
  const r = this.targetTriangleDensity;
775
- for (const u of n) {
776
- if (u.material && (((l = u.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((c = u.geometry) == null ? void 0 : c.type) === "BufferGeometry") && (u.material.name === "SphericalGaussianBlur" || u.material.name == "BackgroundCubeMaterial" || u.material.name === "CubemapFromEquirect" || u.material.name === "EquirectangularToCubeUV")) {
777
- k && (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)));
833
+ for (const d of n) {
834
+ 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")) {
835
+ k && (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)));
778
836
  continue;
779
837
  }
780
- switch (u.material.type) {
838
+ switch (d.material.type) {
781
839
  case "LineBasicMaterial":
782
840
  case "LineDashedMaterial":
783
841
  case "PointsMaterial":
@@ -786,22 +844,22 @@ let xe = (L = class {
786
844
  case "MeshDepthMaterial":
787
845
  continue;
788
846
  }
789
- if (k === "color" && u.material && !u.object.progressive_debug_color) {
790
- u.object.progressive_debug_color = !0;
791
- const g = Math.random() * 16777215, v = new Ze({ color: g });
792
- u.object.material = v;
847
+ if (k === "color" && d.material && !d.object.progressive_debug_color) {
848
+ d.object.progressive_debug_color = !0;
849
+ const f = Math.random() * 16777215, D = new et({ color: f });
850
+ d.object.material = D;
793
851
  }
794
- const h = u.object;
852
+ const h = d.object;
795
853
  (h instanceof te || h.isMesh) && this.updateLODs(t, e, h, r);
796
854
  }
797
855
  const i = s.transparent;
798
- for (const u of i) {
799
- const h = u.object;
856
+ for (const d of i) {
857
+ const h = d.object;
800
858
  (h instanceof te || h.isMesh) && this.updateLODs(t, e, h, r);
801
859
  }
802
860
  const a = s.transmissive;
803
- for (const u of a) {
804
- const h = u.object;
861
+ for (const d of a) {
862
+ const h = d.object;
805
863
  (h instanceof te || h.isMesh) && this.updateLODs(t, e, h, r);
806
864
  }
807
865
  }
@@ -810,15 +868,15 @@ let xe = (L = class {
810
868
  var a, l;
811
869
  s.userData || (s.userData = {});
812
870
  let r = s[Se];
813
- if (r || (r = new xt(), s[Se] = r), r.frames++ < 2)
871
+ if (r || (r = new wt(), s[Se] = r), r.frames++ < 2)
814
872
  return;
815
873
  for (const c of Q)
816
874
  (a = c.onBeforeUpdateLOD) == null || a.call(c, this.renderer, t, e, s);
817
- const i = L.overrideGlobalLodLevel !== void 0 ? L.overrideGlobalLodLevel : ee;
818
- i >= 0 ? (C.mesh_lod = i, C.texture_lod = i) : (this.calculateLodLevel(e, s, r, n, C), C.mesh_lod = Math.round(C.mesh_lod), C.texture_lod = Math.round(C.texture_lod)), C.mesh_lod >= 0 && this.loadProgressiveMeshes(s, C.mesh_lod), s.material && C.texture_lod >= 0 && this.loadProgressiveTextures(s.material, C.texture_lod), y && s.material && !s.isGizmo && We(s.material);
875
+ const i = y.overrideGlobalLodLevel !== void 0 ? y.overrideGlobalLodLevel : ee;
876
+ i >= 0 ? ($.mesh_lod = i, $.texture_lod = i) : (this.calculateLodLevel(e, s, r, n, $), $.mesh_lod = Math.round($.mesh_lod), $.texture_lod = Math.round($.texture_lod)), $.mesh_lod >= 0 && this.loadProgressiveMeshes(s, $.mesh_lod), s.material && $.texture_lod >= 0 && this.loadProgressiveTextures(s.material, $.texture_lod), L && s.material && !s.isGizmo && We(s.material);
819
877
  for (const c of Q)
820
- (l = c.onAfterUpdatedLOD) == null || l.call(c, this.renderer, t, e, s, C);
821
- r.lastLodLevel_Mesh = C.mesh_lod, r.lastLodLevel_Texture = C.texture_lod;
878
+ (l = c.onAfterUpdatedLOD) == null || l.call(c, this.renderer, t, e, s, $);
879
+ r.lastLodLevel_Mesh = $.mesh_lod, r.lastLodLevel_Texture = $.texture_lod;
822
880
  }
823
881
  /** Load progressive textures for the given material
824
882
  * @param material the material to load the textures for
@@ -833,10 +891,10 @@ let xe = (L = class {
833
891
  return;
834
892
  }
835
893
  let s = !1;
836
- (t[J] === void 0 || e < t[J]) && (s = !0);
894
+ (t[H] === void 0 || e < t[H]) && (s = !0);
837
895
  const n = t["DEBUG:LOD"];
838
- if (n != null && (s = t[J] != n, e = n), s) {
839
- t[J] = e;
896
+ if (n != null && (s = t[H] != n, e = n), s) {
897
+ t[H] = e;
840
898
  const r = z.assignTextureLOD(t, e).then((i) => {
841
899
  this._lodchangedlisteners.forEach((a) => a({ type: "texture", level: e, object: t }));
842
900
  });
@@ -851,11 +909,11 @@ let xe = (L = class {
851
909
  */
852
910
  loadProgressiveMeshes(t, e) {
853
911
  if (!t) return Promise.resolve(null);
854
- let s = t[J] !== e;
912
+ let s = t[H] !== e;
855
913
  const n = t["DEBUG:LOD"];
856
- if (n != null && (s = t[J] != n, e = n), s) {
857
- t[J] = e;
858
- const r = t.geometry, i = z.assignMeshLOD(t, e).then((a) => (a && t[J] == e && r != t.geometry && this._lodchangedlisteners.forEach((l) => l({ type: "mesh", level: e, object: t })), a));
914
+ if (n != null && (s = t[H] != n, e = n), s) {
915
+ t[H] = e;
916
+ const r = t.geometry, i = z.assignMeshLOD(t, e).then((a) => (a && t[H] == e && r != t.geometry && this._lodchangedlisteners.forEach((l) => l({ type: "mesh", level: e, object: t })), a));
859
917
  return me.addPromise("mesh", t, i, this._newPromiseGroups), i;
860
918
  }
861
919
  return Promise.resolve(null);
@@ -865,7 +923,7 @@ let xe = (L = class {
865
923
  return this._tempPtInside.set(r, i, s.z).applyMatrix4(e).z < 0;
866
924
  }
867
925
  calculateLodLevel(t, e, s, n, r) {
868
- var F, W, D;
926
+ var b, B, J;
869
927
  if (!e) {
870
928
  r.mesh_lod = -1, r.texture_lod = -1;
871
929
  return;
@@ -877,95 +935,102 @@ let xe = (L = class {
877
935
  let a = 10 + 1, l = !1;
878
936
  if (k && e["DEBUG:LOD"] != null)
879
937
  return e["DEBUG:LOD"];
880
- const c = (F = z.getMeshLODExtension(e.geometry)) == null ? void 0 : F.lods, u = z.getPrimitiveIndex(e.geometry), h = c && c.length > 0, g = z.getMaterialMinMaxLODsCount(e.material), v = (g == null ? void 0 : g.min_count) != 1 / 0 && g.min_count > 0 && g.max_count > 0;
881
- if (!h && !v) {
938
+ const c = (b = z.getMeshLODExtension(e.geometry)) == null ? void 0 : b.lods, d = z.getPrimitiveIndex(e.geometry), h = c && c.length > 0, f = z.getMaterialMinMaxLODsCount(e.material), D = (f == null ? void 0 : f.min_count) != 1 / 0 && f.min_count > 0 && f.max_count > 0;
939
+ if (!h && !D) {
882
940
  r.mesh_lod = 0, r.texture_lod = 0;
883
941
  return;
884
942
  }
885
943
  h || (l = !0, a = 0);
886
- const b = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
887
- let _ = e.geometry.boundingBox;
944
+ const v = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
945
+ let P = e.geometry.boundingBox;
888
946
  if (e.type === "SkinnedMesh") {
889
- const O = e;
890
- if (!O.boundingBox)
891
- O.computeBoundingBox();
892
- else if (this.skinnedMeshAutoUpdateBoundsInterval > 0 && s.frames % this.skinnedMeshAutoUpdateBoundsInterval === 0) {
893
- const m = ue(O), X = O.geometry;
894
- m && (O.geometry = m), O.computeBoundingBox(), O.geometry = X;
947
+ const g = e;
948
+ if (!g.boundingBox)
949
+ g.computeBoundingBox();
950
+ else if (this.skinnedMeshAutoUpdateBoundsInterval > 0) {
951
+ if (!g[y.$skinnedMeshBoundsOffset]) {
952
+ const A = y.skinnedMeshBoundsFrameOffsetCounter++;
953
+ g[y.$skinnedMeshBoundsOffset] = A;
954
+ }
955
+ const w = g[y.$skinnedMeshBoundsOffset];
956
+ if ((s.frames + w) % this.skinnedMeshAutoUpdateBoundsInterval === 0) {
957
+ const A = de(g), F = g.geometry;
958
+ A && (g.geometry = A), g.computeBoundingBox(), g.geometry = F;
959
+ }
895
960
  }
896
- _ = O.boundingBox;
961
+ P = g.boundingBox;
897
962
  }
898
- if (_) {
899
- const O = t;
963
+ if (P) {
964
+ const g = t;
900
965
  if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
901
966
  this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
902
- const x = t.getWorldPosition(this._tempWorldPosition);
903
- if (this._sphere.containsPoint(x)) {
967
+ const p = t.getWorldPosition(this._tempWorldPosition);
968
+ if (this._sphere.containsPoint(p)) {
904
969
  r.mesh_lod = 0, r.texture_lod = 0;
905
970
  return;
906
971
  }
907
972
  }
908
- if (this._tempBox.copy(_), this._tempBox.applyMatrix4(e.matrixWorld), O.isPerspectiveCamera && L.isInside(this._tempBox, this.projectionScreenMatrix)) {
973
+ if (this._tempBox.copy(P), this._tempBox.applyMatrix4(e.matrixWorld), g.isPerspectiveCamera && y.isInside(this._tempBox, this.projectionScreenMatrix)) {
909
974
  r.mesh_lod = 0, r.texture_lod = 0;
910
975
  return;
911
976
  }
912
- if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && O.isPerspectiveCamera && O.fov > 70) {
913
- const x = this._tempBox.min, M = this._tempBox.max;
914
- let A = x.x, R = x.y, U = M.x, ie = M.y;
915
- const ce = 2, ve = 1.5, fe = (x.x + M.x) * 0.5, he = (x.y + M.y) * 0.5;
916
- A = (A - fe) * ce + fe, R = (R - he) * ce + he, U = (U - fe) * ce + fe, ie = (ie - he) * ce + he;
917
- const Ke = A < 0 && U > 0 ? 0 : Math.min(Math.abs(x.x), Math.abs(M.x)), Ye = R < 0 && ie > 0 ? 0 : Math.min(Math.abs(x.y), Math.abs(M.y)), De = Math.max(Ke, Ye);
918
- s.lastCentrality = (ve - De) * (ve - De) * (ve - De);
977
+ if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && g.isPerspectiveCamera && g.fov > 70) {
978
+ const p = this._tempBox.min, M = this._tempBox.max;
979
+ let E = p.x, T = p.y, N = M.x, ie = M.y;
980
+ const ce = 2, De = 1.5, fe = (p.x + M.x) * 0.5, he = (p.y + M.y) * 0.5;
981
+ E = (E - fe) * ce + fe, T = (T - he) * ce + he, N = (N - fe) * ce + fe, ie = (ie - he) * ce + he;
982
+ const Ye = E < 0 && N > 0 ? 0 : Math.min(Math.abs(p.x), Math.abs(M.x)), He = T < 0 && ie > 0 ? 0 : Math.min(Math.abs(p.y), Math.abs(M.y)), Me = Math.max(Ye, He);
983
+ s.lastCentrality = (De - Me) * (De - Me) * (De - Me);
919
984
  } else
920
985
  s.lastCentrality = 1;
921
- const m = this._tempBox.getSize(this._tempBoxSize);
922
- m.multiplyScalar(0.5), screen.availHeight > 0 && b > 0 && m.multiplyScalar(b / screen.availHeight), t.isPerspectiveCamera ? m.x *= t.aspect : t.isOrthographicCamera;
923
- const X = t.matrixWorldInverse, T = this._tempBox2;
924
- T.copy(_), T.applyMatrix4(e.matrixWorld), T.applyMatrix4(X);
925
- const I = T.getSize(this._tempBox2Size), B = Math.max(I.x, I.y);
926
- if (Math.max(m.x, m.y) != 0 && B != 0 && (m.z = I.z / Math.max(I.x, I.y) * Math.max(m.x, m.y)), s.lastScreenCoverage = Math.max(m.x, m.y, m.z), s.lastScreenspaceVolume.copy(m), s.lastScreenCoverage *= s.lastCentrality, k && L.debugDrawLine) {
927
- const x = this.tempMatrix.copy(this.projectionScreenMatrix);
928
- x.invert();
929
- const M = L.corner0, A = L.corner1, R = L.corner2, U = L.corner3;
930
- M.copy(this._tempBox.min), A.copy(this._tempBox.max), A.x = M.x, R.copy(this._tempBox.max), R.y = M.y, U.copy(this._tempBox.max);
931
- const ie = (M.z + U.z) * 0.5;
932
- M.z = A.z = R.z = U.z = ie, M.applyMatrix4(x), A.applyMatrix4(x), R.applyMatrix4(x), U.applyMatrix4(x), L.debugDrawLine(M, A, 255), L.debugDrawLine(M, R, 255), L.debugDrawLine(A, U, 255), L.debugDrawLine(R, U, 255);
986
+ const w = this._tempBox.getSize(this._tempBoxSize);
987
+ w.multiplyScalar(0.5), screen.availHeight > 0 && v > 0 && w.multiplyScalar(v / screen.availHeight), t.isPerspectiveCamera ? w.x *= t.aspect : t.isOrthographicCamera;
988
+ const A = t.matrixWorldInverse, F = this._tempBox2;
989
+ F.copy(P), F.applyMatrix4(e.matrixWorld), F.applyMatrix4(A);
990
+ const S = F.getSize(this._tempBox2Size), Z = Math.max(S.x, S.y);
991
+ if (Math.max(w.x, w.y) != 0 && Z != 0 && (w.z = S.z / Math.max(S.x, S.y) * Math.max(w.x, w.y)), s.lastScreenCoverage = Math.max(w.x, w.y, w.z), s.lastScreenspaceVolume.copy(w), s.lastScreenCoverage *= s.lastCentrality, k && y.debugDrawLine) {
992
+ const p = this.tempMatrix.copy(this.projectionScreenMatrix);
993
+ p.invert();
994
+ const M = y.corner0, E = y.corner1, T = y.corner2, N = y.corner3;
995
+ M.copy(this._tempBox.min), E.copy(this._tempBox.max), E.x = M.x, T.copy(this._tempBox.max), T.y = M.y, N.copy(this._tempBox.max);
996
+ const ie = (M.z + N.z) * 0.5;
997
+ M.z = E.z = T.z = N.z = ie, M.applyMatrix4(p), E.applyMatrix4(p), T.applyMatrix4(p), N.applyMatrix4(p), y.debugDrawLine(M, E, 255), y.debugDrawLine(M, T, 255), y.debugDrawLine(E, N, 255), y.debugDrawLine(T, N, 255);
933
998
  }
934
- let f = 999;
999
+ let O = 999;
935
1000
  if (c && s.lastScreenCoverage > 0)
936
- for (let x = 0; x < c.length; x++) {
937
- const M = c[x];
938
- if ((((W = M.densities) == null ? void 0 : W[u]) || M.density || 1e-5) / s.lastScreenCoverage < n) {
939
- f = x;
1001
+ for (let p = 0; p < c.length; p++) {
1002
+ const M = c[p], T = (((B = M.densities) == null ? void 0 : B[d]) || M.density || 1e-5) / s.lastScreenCoverage;
1003
+ if (d > 0 && Be() && !M.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.")), T < n) {
1004
+ O = p;
940
1005
  break;
941
1006
  }
942
1007
  }
943
- f < a && (a = f, l = !0);
1008
+ O < a && (a = O, l = !0);
944
1009
  }
945
1010
  if (l ? r.mesh_lod = a : r.mesh_lod = s.lastLodLevel_Mesh, k && r.mesh_lod != s.lastLodLevel_Mesh) {
946
- const m = c == null ? void 0 : c[r.mesh_lod];
947
- m && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${r.mesh_lod} (${m.density.toFixed(0)}) - ${e.name}`);
1011
+ const w = c == null ? void 0 : c[r.mesh_lod];
1012
+ w && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${r.mesh_lod} (${w.density.toFixed(0)}) - ${e.name}`);
948
1013
  }
949
- if (v) {
950
- const O = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
1014
+ if (D) {
1015
+ const g = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
951
1016
  if (s.lastLodLevel_Texture < 0) {
952
- if (r.texture_lod = g.max_count - 1, k) {
953
- const m = g.lods[g.max_count - 1];
954
- k && console.log(`First Texture LOD ${r.texture_lod} (${m.max_height}px) - ${e.name}`);
1017
+ if (r.texture_lod = f.max_count - 1, k) {
1018
+ const w = f.lods[f.max_count - 1];
1019
+ k && console.log(`First Texture LOD ${r.texture_lod} (${w.max_height}px) - ${e.name}`);
955
1020
  }
956
1021
  } else {
957
- const m = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
958
- let X = s.lastScreenCoverage * 4;
959
- ((D = this.context) == null ? void 0 : D.engine) === "model-viewer" && (X *= 1.5);
960
- const I = b / window.devicePixelRatio * X;
961
- let B = !1;
962
- for (let S = g.lods.length - 1; S >= 0; S--) {
963
- const f = g.lods[S];
964
- if (!(O && f.max_height >= 2048) && !(ct() && f.max_height > 4096) && (f.max_height > I || !B && S === 0)) {
965
- if (B = !0, r.texture_lod = S, r.texture_lod < s.lastLodLevel_Texture) {
966
- const P = f.max_height;
967
- k && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${r.texture_lod} = ${P}px
968
- Screensize: ${I.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${m.toFixed(1)}
1022
+ const w = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
1023
+ let A = s.lastScreenCoverage * 4;
1024
+ ((J = this.context) == null ? void 0 : J.engine) === "model-viewer" && (A *= 1.5);
1025
+ const S = v / window.devicePixelRatio * A;
1026
+ let Z = !1;
1027
+ for (let C = f.lods.length - 1; C >= 0; C--) {
1028
+ const O = f.lods[C];
1029
+ if (!(g && O.max_height >= 2048) && !(ft() && O.max_height > 4096) && (O.max_height > S || !Z && C === 0)) {
1030
+ if (Z = !0, r.texture_lod = C, r.texture_lod < s.lastLodLevel_Texture) {
1031
+ const m = O.max_height;
1032
+ k && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${r.texture_lod} = ${m}px
1033
+ Screensize: ${S.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${w.toFixed(1)}
969
1034
  ${e.name}`);
970
1035
  }
971
1036
  break;
@@ -975,56 +1040,56 @@ ${e.name}`);
975
1040
  } else
976
1041
  r.texture_lod = 0;
977
1042
  }
978
- }, E = new WeakMap(), Y = new WeakMap(), we = new WeakMap(), Z = new WeakMap(), re = new WeakMap(), _e = new WeakMap(), H = new WeakMap(), /**
1043
+ }, I = new WeakMap(), X = new WeakMap(), we = new WeakMap(), j = new WeakMap(), re = new WeakMap(), _e = new WeakMap(), K = new WeakMap(), /**
979
1044
  * 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.
980
1045
  */
981
- d(L, "debugDrawLine"), /**
1046
+ u(y, "debugDrawLine"), /**
982
1047
  * Force override the LOD level for all objects in the scene
983
1048
  */
984
- d(L, "overrideGlobalLodLevel"), d(L, "corner0", new q()), d(L, "corner1", new q()), d(L, "corner2", new q()), d(L, "corner3", new q()), d(L, "_tempPtInside", new q()), L);
985
- class xt {
1049
+ u(y, "overrideGlobalLodLevel"), u(y, "corner0", new V()), u(y, "corner1", new V()), u(y, "corner2", new V()), u(y, "corner3", new V()), u(y, "_tempPtInside", new V()), u(y, "skinnedMeshBoundsFrameOffsetCounter", 0), u(y, "$skinnedMeshBoundsOffset", Symbol("gltf-progressive-skinnedMeshBoundsOffset")), y);
1050
+ class wt {
986
1051
  constructor() {
987
- d(this, "frames", 0);
988
- d(this, "lastLodLevel_Mesh", -1);
989
- d(this, "lastLodLevel_Texture", -1);
990
- d(this, "lastScreenCoverage", 0);
991
- d(this, "lastScreenspaceVolume", new q());
992
- d(this, "lastCentrality", 0);
1052
+ u(this, "frames", 0);
1053
+ u(this, "lastLodLevel_Mesh", -1);
1054
+ u(this, "lastLodLevel_Texture", -1);
1055
+ u(this, "lastScreenCoverage", 0);
1056
+ u(this, "lastScreenspaceVolume", new V());
1057
+ u(this, "lastCentrality", 0);
993
1058
  }
994
1059
  }
995
- const Re = Symbol("NEEDLE_mesh_lod"), ge = Symbol("NEEDLE_texture_lod");
1060
+ const ke = Symbol("NEEDLE_mesh_lod"), ge = Symbol("NEEDLE_texture_lod");
996
1061
  let le = null;
997
1062
  function Xe() {
998
- const o = wt();
1063
+ const o = _t();
999
1064
  o && (o.mapURLs(function(t) {
1000
- return ke(), t;
1001
- }), ke(), le == null || le.disconnect(), le = new MutationObserver((t) => {
1065
+ return Re(), t;
1066
+ }), Re(), le == null || le.disconnect(), le = new MutationObserver((t) => {
1002
1067
  t.forEach((e) => {
1003
1068
  e.addedNodes.forEach((s) => {
1004
- s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && qe(s);
1069
+ s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && Ke(s);
1005
1070
  });
1006
1071
  });
1007
1072
  }), le.observe(document, { childList: !0, subtree: !0 }));
1008
1073
  }
1009
- function wt() {
1074
+ function _t() {
1010
1075
  if (typeof customElements > "u") return null;
1011
1076
  const o = customElements.get("model-viewer");
1012
1077
  return o || (customElements.whenDefined("model-viewer").then(() => {
1013
1078
  console.debug("[gltf-progressive] model-viewer defined"), Xe();
1014
1079
  }), null);
1015
1080
  }
1016
- function ke() {
1081
+ function Re() {
1017
1082
  if (typeof document > "u") return;
1018
1083
  document.querySelectorAll("model-viewer").forEach((t) => {
1019
- qe(t);
1084
+ Ke(t);
1020
1085
  });
1021
1086
  }
1022
- const $e = /* @__PURE__ */ new WeakSet();
1023
- let _t = 0;
1024
- function qe(o) {
1025
- if (!o || $e.has(o))
1087
+ const Fe = /* @__PURE__ */ new WeakSet();
1088
+ let Dt = 0;
1089
+ function Ke(o) {
1090
+ if (!o || Fe.has(o))
1026
1091
  return null;
1027
- $e.add(o), console.debug("[gltf-progressive] found new model-viewer..." + ++_t + `
1092
+ Fe.add(o), console.debug("[gltf-progressive] found new model-viewer..." + ++Dt + `
1028
1093
  `, o.getAttribute("src"));
1029
1094
  let t = null, e = null, s = null;
1030
1095
  for (let n = o; n != null; n = Object.getPrototypeOf(n)) {
@@ -1045,7 +1110,7 @@ function qe(o) {
1045
1110
  };
1046
1111
  console.debug("[gltf-progressive] setup model-viewer");
1047
1112
  const r = xe.get(t, { engine: "model-viewer" });
1048
- return xe.addPlugin(new vt()), r.enable(), r.addEventListener("changed", () => {
1113
+ return xe.addPlugin(new Mt()), r.enable(), r.addEventListener("changed", () => {
1049
1114
  s == null || s.call(o);
1050
1115
  }), o.addEventListener("model-visibility", (i) => {
1051
1116
  i.detail.visible && (s == null || s.call(o));
@@ -1057,9 +1122,9 @@ function qe(o) {
1057
1122
  }
1058
1123
  return null;
1059
1124
  }
1060
- class vt {
1125
+ class Mt {
1061
1126
  constructor() {
1062
- d(this, "_didWarnAboutMissingUrl", !1);
1127
+ u(this, "_didWarnAboutMissingUrl", !1);
1063
1128
  }
1064
1129
  onBeforeUpdateLOD(t, e, s, n) {
1065
1130
  this.tryParseMeshLOD(e, n), this.tryParseTextureLOD(e, n);
@@ -1082,23 +1147,23 @@ class vt {
1082
1147
  const s = this.tryGetCurrentGLTF(t), n = this.tryGetCurrentModelViewer(t), r = this.getUrl(n);
1083
1148
  if (r && s && e.material) {
1084
1149
  let i = function(l) {
1085
- var u, h, g;
1150
+ var d, h, f;
1086
1151
  if (l[ge] == !0) return;
1087
1152
  l[ge] = !0, l.userData && (l.userData.LOD = -1);
1088
1153
  const c = Object.keys(l);
1089
- for (let v = 0; v < c.length; v++) {
1090
- const b = c[v], _ = l[b];
1091
- if ((_ == null ? void 0 : _.isTexture) === !0) {
1092
- const F = (h = (u = _.userData) == null ? void 0 : u.associations) == null ? void 0 : h.textures;
1093
- if (F == null) continue;
1094
- const W = s.parser.json.textures[F];
1095
- if (!W) {
1096
- console.warn("Texture data not found for texture index " + F);
1154
+ for (let D = 0; D < c.length; D++) {
1155
+ const v = c[D], P = l[v];
1156
+ if ((P == null ? void 0 : P.isTexture) === !0) {
1157
+ const b = (h = (d = P.userData) == null ? void 0 : d.associations) == null ? void 0 : h.textures;
1158
+ if (b == null) continue;
1159
+ const B = s.parser.json.textures[b];
1160
+ if (!B) {
1161
+ console.warn("Texture data not found for texture index " + b);
1097
1162
  continue;
1098
1163
  }
1099
- if ((g = W == null ? void 0 : W.extensions) != null && g[K]) {
1100
- const D = W.extensions[K];
1101
- D && r && z.registerTexture(r, _, D.lods.length, F, D);
1164
+ if ((f = B == null ? void 0 : B.extensions) != null && f[W]) {
1165
+ const J = B.extensions[W];
1166
+ J && r && z.registerTexture(r, P, J.lods.length, b, J);
1102
1167
  }
1103
1168
  }
1104
1169
  }
@@ -1110,20 +1175,20 @@ class vt {
1110
1175
  }
1111
1176
  tryParseMeshLOD(t, e) {
1112
1177
  var i, a;
1113
- if (e[Re] == !0) return;
1114
- e[Re] = !0;
1178
+ if (e[ke] == !0) return;
1179
+ e[ke] = !0;
1115
1180
  const s = this.tryGetCurrentModelViewer(t), n = this.getUrl(s);
1116
1181
  if (!n)
1117
1182
  return;
1118
- const r = (a = (i = e.userData) == null ? void 0 : i.gltfExtensions) == null ? void 0 : a[K];
1183
+ const r = (a = (i = e.userData) == null ? void 0 : i.gltfExtensions) == null ? void 0 : a[W];
1119
1184
  if (r && n) {
1120
1185
  const l = e.uuid;
1121
1186
  z.registerMesh(n, l, e, 0, r.lods.length, r);
1122
1187
  }
1123
1188
  }
1124
1189
  }
1125
- function Dt(o, t, e, s) {
1126
- Ne(t), ze(e), Ve(e, {
1190
+ function vt(o, t, e, s) {
1191
+ ze(t), qe(e), Ve(e, {
1127
1192
  progressive: !0,
1128
1193
  ...s == null ? void 0 : s.hints
1129
1194
  }), e.register((r) => new z(r, o));
@@ -1131,14 +1196,14 @@ function Dt(o, t, e, s) {
1131
1196
  return (s == null ? void 0 : s.enableLODsManager) !== !1 && n.enable(), n;
1132
1197
  }
1133
1198
  Xe();
1134
- if (!ht) {
1199
+ if (!gt) {
1135
1200
  const o = {
1136
1201
  gltfProgressive: {
1137
- useNeedleProgressive: Dt,
1202
+ useNeedleProgressive: vt,
1138
1203
  LODsManager: xe,
1139
1204
  configureLoader: Ve,
1140
- getRaycastMesh: ue,
1141
- useRaycastMeshes: pt
1205
+ getRaycastMesh: de,
1206
+ useRaycastMeshes: mt
1142
1207
  }
1143
1208
  };
1144
1209
  if (!globalThis.Needle)
@@ -1150,10 +1215,10 @@ if (!ht) {
1150
1215
  export {
1151
1216
  xe as LODsManager,
1152
1217
  z as NEEDLE_progressive,
1153
- ze as addDracoAndKTX2Loaders,
1218
+ qe as addDracoAndKTX2Loaders,
1154
1219
  Ve as configureLoader,
1155
- Ne as createLoaders,
1156
- ue as getRaycastMesh,
1157
- at as setDracoDecoderLocation,
1158
- lt as setKTX2TranscoderLocation
1220
+ ze as createLoaders,
1221
+ de as getRaycastMesh,
1222
+ lt as setDracoDecoderLocation,
1223
+ ut as setKTX2TranscoderLocation
1159
1224
  };