@needle-tools/gltf-progressive 2.1.0-experimental.3 → 2.1.0

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,80 +1,80 @@
1
1
  var We = Object.defineProperty;
2
- var qe = (o, e, t) => e in o ? We(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
- var d = (o, e, t) => (qe(o, typeof e != "symbol" ? e + "" : e, t), t), Te = (o, e, t) => {
4
- if (!e.has(o))
2
+ var qe = (n, e, t) => e in n ? We(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var d = (n, e, t) => (qe(n, typeof e != "symbol" ? e + "" : e, t), t), Te = (n, e, t) => {
4
+ if (!e.has(n))
5
5
  throw TypeError("Cannot " + t);
6
6
  };
7
- var m = (o, e, t) => (Te(o, e, "read from private field"), t ? t.call(o) : e.get(o)), K = (o, e, t) => {
8
- if (e.has(o))
7
+ var m = (n, e, t) => (Te(n, e, "read from private field"), t ? t.call(n) : e.get(n)), K = (n, e, t) => {
8
+ if (e.has(n))
9
9
  throw TypeError("Cannot add the same private member more than once");
10
- e instanceof WeakSet ? e.add(o) : e.set(o, t);
11
- }, U = (o, e, t, s) => (Te(o, e, "write to private field"), s ? s.call(o, t) : e.set(o, t), t);
12
- import { BufferGeometry as ge, Mesh as Q, Material as Xe, Texture as se, TextureLoader as Ke, Matrix4 as Ae, Clock as Ye, MeshStandardMaterial as He, Sphere as Je, Box3 as Ee, Vector3 as N } from "three";
10
+ e instanceof WeakSet ? e.add(n) : e.set(n, t);
11
+ }, U = (n, e, t, s) => (Te(n, e, "write to private field"), s ? s.call(n, t) : e.set(n, t), t);
12
+ import { BufferGeometry as ge, Mesh as Z, Texture as se, TextureLoader as Xe, Matrix4 as Ae, Clock as Ke, MeshStandardMaterial as Ye, Sphere as He, Box3 as Ee, Vector3 as z } from "three";
13
13
  import { GLTFLoader as be } from "three/examples/jsm/loaders/GLTFLoader.js";
14
- import { MeshoptDecoder as Qe } from "three/examples/jsm/libs/meshopt_decoder.module.js";
15
- import { DRACOLoader as Ze } from "three/examples/jsm/loaders/DRACOLoader.js";
16
- import { KTX2Loader as je } from "three/examples/jsm/loaders/KTX2Loader.js";
14
+ import { MeshoptDecoder as Je } from "three/examples/jsm/libs/meshopt_decoder.module.js";
15
+ import { DRACOLoader as Qe } from "three/examples/jsm/loaders/DRACOLoader.js";
16
+ import { KTX2Loader as Ze } from "three/examples/jsm/loaders/KTX2Loader.js";
17
17
  const ke = "";
18
18
  globalThis.GLTF_PROGRESSIVE_VERSION = ke;
19
19
  console.debug(`[gltf-progressive] version ${ke}`);
20
20
  let te = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", ae = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
21
- const et = te, tt = ae, st = new URL(te + "draco_decoder.js");
22
- fetch(st, {
21
+ const je = te, et = ae, tt = new URL(te + "draco_decoder.js");
22
+ fetch(tt, {
23
23
  method: "GET",
24
24
  headers: {
25
25
  Range: "bytes=0-1"
26
26
  }
27
- }).catch((o) => {
28
- te === et && (te = "./include/draco/"), ae === tt && (ae = "./include/ktx2/");
27
+ }).catch((n) => {
28
+ te === je && (te = "./include/draco/"), ae === et && (ae = "./include/ktx2/");
29
29
  }).finally(() => {
30
30
  Ie();
31
31
  });
32
- function vt(o) {
33
- te = o;
32
+ function wt(n) {
33
+ te = n;
34
34
  }
35
- function Ot(o) {
36
- ae = o;
35
+ function vt(n) {
36
+ ae = n;
37
37
  }
38
- let H, pe, J;
38
+ let J, pe, Q;
39
39
  function Ie() {
40
- H || (H = new Ze(), H.setDecoderPath(te), H.setDecoderConfig({ type: "js" }), H.preload()), J || (J = new je(), J.setTranscoderPath(ae), J.init()), pe || (pe = Qe);
40
+ J || (J = new Qe(), J.setDecoderPath(te), J.setDecoderConfig({ type: "js" }), J.preload()), Q || (Q = new Ze(), Q.setTranscoderPath(ae), Q.init()), pe || (pe = Je);
41
41
  }
42
- function Ge(o) {
43
- return Ie(), o ? J.detectSupport(o) : o !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: H, ktx2Loader: J, meshoptDecoder: pe };
42
+ function Ge(n) {
43
+ return Ie(), n ? Q.detectSupport(n) : n !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: J, ktx2Loader: Q, meshoptDecoder: pe };
44
44
  }
45
- function $e(o) {
46
- o.dracoLoader || o.setDRACOLoader(H), o.ktx2Loader || o.setKTX2Loader(J), o.meshoptDecoder || o.setMeshoptDecoder(pe);
45
+ function $e(n) {
46
+ n.dracoLoader || n.setDRACOLoader(J), n.ktx2Loader || n.setKTX2Loader(Q), n.meshoptDecoder || n.setMeshoptDecoder(pe);
47
47
  }
48
48
  const Oe = /* @__PURE__ */ new WeakMap();
49
- function Fe(o, e) {
50
- let t = Oe.get(o);
51
- t ? t = Object.assign(t, e) : t = e, Oe.set(o, t);
49
+ function Fe(n, e) {
50
+ let t = Oe.get(n);
51
+ t ? t = Object.assign(t, e) : t = e, Oe.set(n, t);
52
52
  }
53
53
  const Me = be.prototype.load;
54
- function rt(...o) {
54
+ function st(...n) {
55
55
  const e = Oe.get(this);
56
- let t = o[0];
56
+ let t = n[0];
57
57
  const s = new URL(t, window.location.href);
58
58
  if (s.hostname.endsWith("needle.tools")) {
59
59
  const r = (e == null ? void 0 : e.progressive) !== void 0 ? e.progressive : !0, i = e != null && e.usecase ? e.usecase : "default";
60
60
  r ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${i}` : this.requestHeader.Accept = `*/*;usecase=${i}`, t = s.toString();
61
61
  }
62
- return o[0] = t, Me == null ? void 0 : Me.call(this, ...o);
62
+ return n[0] = t, Me == null ? void 0 : Me.call(this, ...n);
63
63
  }
64
- be.prototype.load = rt;
64
+ be.prototype.load = st;
65
65
  le("debugprogressive");
66
- function le(o) {
66
+ function le(n) {
67
67
  if (typeof window > "u")
68
68
  return !1;
69
- const t = new URL(window.location.href).searchParams.get(o);
69
+ const t = new URL(window.location.href).searchParams.get(n);
70
70
  return t == null || t === "0" || t === "false" ? !1 : t === "" ? !0 : t;
71
71
  }
72
- function it(o, e) {
73
- if (e === void 0 || e.startsWith("./") || e.startsWith("http") || o === void 0)
72
+ function rt(n, e) {
73
+ if (e === void 0 || e.startsWith("./") || e.startsWith("http") || n === void 0)
74
74
  return e;
75
- const t = o.lastIndexOf("/");
75
+ const t = n.lastIndexOf("/");
76
76
  if (t >= 0) {
77
- const s = o.substring(0, t + 1);
77
+ const s = n.substring(0, t + 1);
78
78
  for (; s.endsWith("/") && e.startsWith("/"); )
79
79
  e = e.substring(1);
80
80
  return s + e;
@@ -82,73 +82,70 @@ function it(o, e) {
82
82
  return e;
83
83
  }
84
84
  let re;
85
- function nt() {
85
+ function it() {
86
86
  return re !== void 0 || (re = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), le("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", re)), re;
87
87
  }
88
88
  const ot = typeof window > "u" && typeof document > "u", _e = Symbol("needle:raycast-mesh");
89
- function ce(o) {
90
- return (o == null ? void 0 : o[_e]) instanceof ge ? o[_e] : null;
89
+ function ce(n) {
90
+ return (n == null ? void 0 : n[_e]) instanceof ge ? n[_e] : null;
91
91
  }
92
- function at(o, e) {
93
- if ((o.type === "Mesh" || o.type === "SkinnedMesh") && !ce(o)) {
94
- const s = ct(e);
95
- s.userData = { isRaycastMesh: !0 }, o[_e] = s;
92
+ function nt(n, e) {
93
+ if ((n.type === "Mesh" || n.type === "SkinnedMesh") && !ce(n)) {
94
+ const s = lt(e);
95
+ s.userData = { isRaycastMesh: !0 }, n[_e] = s;
96
96
  }
97
97
  }
98
- function lt(o = !0) {
99
- if (o) {
98
+ function at(n = !0) {
99
+ if (n) {
100
100
  if (ie)
101
101
  return;
102
- const e = ie = Q.prototype.raycast;
103
- Q.prototype.raycast = function(t, s) {
104
- const n = this, r = ce(n);
102
+ const e = ie = Z.prototype.raycast;
103
+ Z.prototype.raycast = function(t, s) {
104
+ const o = this, r = ce(o);
105
105
  let i;
106
- r && n.isMesh && (i = n.geometry, n.geometry = r), e.call(this, t, s), i && (n.geometry = i);
106
+ r && o.isMesh && (i = o.geometry, o.geometry = r), e.call(this, t, s), i && (o.geometry = i);
107
107
  };
108
108
  } else {
109
109
  if (!ie)
110
110
  return;
111
- Q.prototype.raycast = ie, ie = null;
111
+ Z.prototype.raycast = ie, ie = null;
112
112
  }
113
113
  }
114
114
  let ie = null;
115
- function ct(o) {
115
+ function lt(n) {
116
116
  const e = new ge();
117
- for (const t in o.attributes)
118
- e.setAttribute(t, o.getAttribute(t));
119
- return e.setIndex(o.getIndex()), e;
117
+ for (const t in n.attributes)
118
+ e.setAttribute(t, n.getAttribute(t));
119
+ return e.setIndex(n.getIndex()), e;
120
120
  }
121
- const Y = new Array(), z = "NEEDLE_progressive", L = le("debugprogressive"), De = Symbol("needle-progressive-texture"), oe = /* @__PURE__ */ new Map(), Se = /* @__PURE__ */ new Set();
121
+ const H = new Array(), V = "NEEDLE_progressive", L = le("debugprogressive"), De = Symbol("needle-progressive-texture"), ne = /* @__PURE__ */ new Map(), Se = /* @__PURE__ */ new Set();
122
122
  if (L) {
123
- let o = function() {
124
- e += 1, console.log("Toggle LOD level", e, oe), oe.forEach((n, r) => {
125
- for (const i of n.keys) {
123
+ let n = function() {
124
+ e += 1, console.log("Toggle LOD level", e, ne), ne.forEach((o, r) => {
125
+ for (const i of o.keys) {
126
126
  const a = r[i];
127
- if (a != null) {
127
+ if (a != null)
128
128
  if (a.isBufferGeometry === !0) {
129
- const l = _.getMeshLODInformation(a), u = l ? Math.min(e, l.lods.length) : 0;
130
- r["DEBUG:LOD"] = e, _.assignMeshLOD(r, u), l && (t = Math.max(t, l.lods.length - 1));
131
- } else if (r.isMaterial === !0) {
132
- r["DEBUG:LOD"] = e, _.assignTextureLOD(r, e);
133
- break;
134
- }
135
- }
129
+ const l = T.getMeshLODInformation(a), u = l ? Math.min(e, l.lods.length) : 0;
130
+ r["DEBUG:LOD"] = u, l && (t = Math.max(t, l.lods.length - 1));
131
+ } else
132
+ r.isMaterial === !0 && (r["DEBUG:LOD"] = e);
136
133
  }
137
134
  }), e >= t && (e = -1);
138
135
  }, e = -1, t = 2, s = !1;
139
- window.addEventListener("keyup", (n) => {
140
- n.key === "p" && o(), n.key === "w" && (s = !s, Se && Se.forEach((r) => {
136
+ window.addEventListener("keyup", (o) => {
137
+ o.key === "p" && n(), o.key === "w" && (s = !s, Se && Se.forEach((r) => {
141
138
  r.name != "BackgroundCubeMaterial" && r.glyphMap == null && "wireframe" in r && (r.wireframe = s);
142
139
  }));
143
140
  });
144
141
  }
145
- function Pe(o, e, t) {
146
- var n;
142
+ function Pe(n, e, t) {
143
+ var o;
147
144
  if (!L)
148
145
  return;
149
- oe.has(o) || oe.set(o, { keys: [], sourceId: t });
150
- const s = oe.get(o);
151
- ((n = s == null ? void 0 : s.keys) == null ? void 0 : n.includes(e)) == !1 && s.keys.push(e);
146
+ ne.has(n) || ne.set(n, { keys: [], sourceId: t });
147
+ const s = ne.get(n);
148
+ ((o = s == null ? void 0 : s.keys) == null ? void 0 : o.includes(e)) == !1 && s.keys.push(e);
152
149
  }
153
150
  const v = class {
154
151
  constructor(e, t) {
@@ -156,10 +153,10 @@ const v = class {
156
153
  d(this, "url");
157
154
  d(this, "_isLoadingMesh");
158
155
  d(this, "loadMesh", (e) => {
159
- var s, n;
156
+ var s, o;
160
157
  if (this._isLoadingMesh)
161
158
  return null;
162
- const t = (n = (s = this.parser.json.meshes[e]) == null ? void 0 : s.extensions) == null ? void 0 : n[z];
159
+ const t = (o = (s = this.parser.json.meshes[e]) == null ? void 0 : s.extensions) == null ? void 0 : o[V];
163
160
  return t ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", e).then((r) => {
164
161
  var i;
165
162
  return this._isLoadingMesh = !1, r && v.registerMesh(this.url, t.guid, r, (i = t.lods) == null ? void 0 : i.length, void 0, t), r;
@@ -169,14 +166,14 @@ const v = class {
169
166
  }
170
167
  /** The name of the extension */
171
168
  get name() {
172
- return z;
169
+ return V;
173
170
  }
174
171
  static getMeshLODInformation(e) {
175
172
  const t = this.getAssignedLODInformation(e);
176
173
  return t != null && t.key ? this.lodInfos.get(t.key) : null;
177
174
  }
178
175
  static getMaterialMinMaxLODsCount(e, t) {
179
- const s = this, n = "LODS:minmax", r = e[n];
176
+ const s = this, o = "LODS:minmax", r = e[o];
180
177
  if (r != null)
181
178
  return r;
182
179
  if (t || (t = {
@@ -186,7 +183,7 @@ const v = class {
186
183
  }), Array.isArray(e)) {
187
184
  for (const a of e)
188
185
  this.getMaterialMinMaxLODsCount(a, t);
189
- return e[n] = t, t;
186
+ return e[o] = t, t;
190
187
  }
191
188
  if (L === "verbose" && console.log("getMaterialMinMaxLODsCount", e), e.type === "ShaderMaterial" || e.type === "RawShaderMaterial") {
192
189
  const a = e;
@@ -199,7 +196,7 @@ const v = class {
199
196
  const l = e[a];
200
197
  (l == null ? void 0 : l.isTexture) === !0 && i(l, t);
201
198
  }
202
- return e[n] = t, t;
199
+ return e[o] = t, t;
203
200
  function i(a, l) {
204
201
  const u = s.getAssignedLODInformation(a);
205
202
  if (u) {
@@ -239,13 +236,13 @@ const v = class {
239
236
  if (i.isMesh === !0 && this.hasLODLevelAvailable(i, t))
240
237
  return !0;
241
238
  }
242
- let s, n;
239
+ let s, o;
243
240
  if (e.isMesh ? s = e.geometry : (e.isBufferGeometry || e.isTexture) && (s = e), s && (r = s == null ? void 0 : s.userData) != null && r.LODS) {
244
241
  const i = s.userData.LODS;
245
- if (n = this.lodInfos.get(i.key), t === void 0)
246
- return n != null;
247
- if (n)
248
- return Array.isArray(n.lods) ? t < n.lods.length : t === 0;
242
+ if (o = this.lodInfos.get(i.key), t === void 0)
243
+ return o != null;
244
+ if (o)
245
+ return Array.isArray(o.lods) ? t < o.lods.length : t === 0;
249
246
  }
250
247
  return !1;
251
248
  }
@@ -267,18 +264,18 @@ const v = class {
267
264
  var s;
268
265
  if (!e)
269
266
  return Promise.resolve(null);
270
- if (e instanceof Q || e.isMesh === !0) {
271
- const n = e.geometry, r = this.getAssignedLODInformation(n);
267
+ if (e instanceof Z || e.isMesh === !0) {
268
+ const o = e.geometry, r = this.getAssignedLODInformation(o);
272
269
  if (!r)
273
270
  return Promise.resolve(null);
274
- for (const i of Y)
271
+ for (const i of H)
275
272
  (s = i.onBeforeGetLODMesh) == null || s.call(i, e, t);
276
- return e["LOD:requested level"] = t, v.getOrLoadLOD(n, t).then((i) => {
273
+ return e["LOD:requested level"] = t, v.getOrLoadLOD(o, t).then((i) => {
277
274
  if (Array.isArray(i)) {
278
275
  const a = r.index || 0;
279
276
  i = i[a];
280
277
  }
281
- return e["LOD:requested level"] === t && (delete e["LOD:requested level"], i && n != i && ((i == null ? void 0 : i.isBufferGeometry) ? (e.geometry = i, L && Pe(e, "geometry", r.url)) : L && console.error("Invalid LOD geometry", i))), i;
278
+ return e["LOD:requested level"] === t && (delete e["LOD:requested level"], i && o != i && ((i == null ? void 0 : i.isBufferGeometry) ? (e.geometry = i, L && Pe(e, "geometry", r.url)) : L && console.error("Invalid LOD geometry", i))), i;
282
279
  }).catch((i) => (console.error("Error loading mesh LOD", e, i), null));
283
280
  } else
284
281
  L && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", e);
@@ -290,12 +287,12 @@ const v = class {
290
287
  if (e.isMesh === !0) {
291
288
  const s = e;
292
289
  if (Array.isArray(s.material)) {
293
- const n = new Array();
290
+ const o = new Array();
294
291
  for (const r of s.material) {
295
292
  const i = this.assignTextureLOD(r, t);
296
- n.push(i);
293
+ o.push(i);
297
294
  }
298
- return Promise.all(n).then((r) => {
295
+ return Promise.all(o).then((r) => {
299
296
  const i = new Array();
300
297
  for (const a of r)
301
298
  Array.isArray(a) && i.push(...a);
@@ -304,15 +301,15 @@ const v = class {
304
301
  } else
305
302
  return this.assignTextureLOD(s.material, t);
306
303
  }
307
- if (e instanceof Xe || e.isMaterial === !0) {
308
- const s = e, n = [], r = new Array();
304
+ if (e.isMaterial === !0) {
305
+ const s = e, o = [], r = new Array();
309
306
  if (L && Se.add(s), s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
310
307
  const i = s;
311
308
  for (const a of Object.keys(i.uniforms)) {
312
309
  const l = i.uniforms[a].value;
313
310
  if ((l == null ? void 0 : l.isTexture) === !0) {
314
311
  const u = this.assignTextureLODForSlot(l, t, s, a).then((c) => (c && i.uniforms[a].value != c && (i.uniforms[a].value = c, i.uniformsNeedUpdate = !0), c));
315
- n.push(u), r.push(a);
312
+ o.push(u), r.push(a);
316
313
  }
317
314
  }
318
315
  } else
@@ -320,10 +317,10 @@ const v = class {
320
317
  const a = s[i];
321
318
  if ((a == null ? void 0 : a.isTexture) === !0) {
322
319
  const l = this.assignTextureLODForSlot(a, t, s, i);
323
- n.push(l), r.push(i);
320
+ o.push(l), r.push(i);
324
321
  }
325
322
  }
326
- return Promise.all(n).then((i) => {
323
+ return Promise.all(o).then((i) => {
327
324
  const a = new Array();
328
325
  for (let l = 0; l < i.length; l++) {
329
326
  const u = i[l], c = r[l];
@@ -338,24 +335,24 @@ const v = class {
338
335
  }
339
336
  return Promise.resolve(null);
340
337
  }
341
- static assignTextureLODForSlot(e, t, s, n) {
342
- return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : n === "glyphMap" ? Promise.resolve(e) : v.getOrLoadLOD(e, t).then((r) => {
338
+ static assignTextureLODForSlot(e, t, s, o) {
339
+ return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : o === "glyphMap" ? Promise.resolve(e) : v.getOrLoadLOD(e, t).then((r) => {
343
340
  if (Array.isArray(r))
344
341
  return null;
345
342
  if ((r == null ? void 0 : r.isTexture) === !0) {
346
343
  if (r != e) {
347
- if (s && n) {
348
- const i = s[n];
349
- if (i) {
344
+ if (s && o) {
345
+ const i = s[o];
346
+ if (i && !L) {
350
347
  const a = this.getAssignedLODInformation(i);
351
348
  if (a && (a == null ? void 0 : a.level) < t)
352
349
  return L === "verbose" && console.warn("Assigned texture level is already higher: ", a.level, t, s, i, r), null;
353
350
  }
354
- s[n] = r;
351
+ s[o] = r;
355
352
  }
356
- if (L && n && s) {
353
+ if (L && o && s) {
357
354
  const i = this.getAssignedLODInformation(e);
358
- i && Pe(s, n, i.url);
355
+ i ? Pe(s, o, i.url) : console.warn("No LOD info for texture", e);
359
356
  }
360
357
  }
361
358
  return r;
@@ -366,10 +363,10 @@ const v = class {
366
363
  }
367
364
  afterRoot(e) {
368
365
  var t, s;
369
- return L && console.log("AFTER", this.url, e), (t = this.parser.json.textures) == null || t.forEach((n, r) => {
366
+ return L && console.log("AFTER", this.url, e), (t = this.parser.json.textures) == null || t.forEach((o, r) => {
370
367
  var i;
371
- if (n != null && n.extensions) {
372
- const a = n == null ? void 0 : n.extensions[z];
368
+ if (o != null && o.extensions) {
369
+ const a = o == null ? void 0 : o.extensions[V];
373
370
  if (a) {
374
371
  if (!a.lods) {
375
372
  L && console.warn("Texture has no LODs", a);
@@ -387,9 +384,9 @@ const v = class {
387
384
  });
388
385
  }
389
386
  }
390
- }), (s = this.parser.json.meshes) == null || s.forEach((n, r) => {
391
- if (n != null && n.extensions) {
392
- const i = n == null ? void 0 : n.extensions[z];
387
+ }), (s = this.parser.json.meshes) == null || s.forEach((o, r) => {
388
+ if (o != null && o.extensions) {
389
+ const i = o == null ? void 0 : o.extensions[V];
393
390
  if (i && i.lods) {
394
391
  for (const a of this.parser.associations.keys())
395
392
  if (a.isMesh) {
@@ -402,10 +399,10 @@ const v = class {
402
399
  }
403
400
  static async getOrLoadLOD(e, t) {
404
401
  var a, l, u, c;
405
- const s = L == "verbose", n = e.userData.LODS;
406
- if (!n)
402
+ const s = L == "verbose", o = e.userData.LODS;
403
+ if (!o)
407
404
  return null;
408
- const r = n == null ? void 0 : n.key;
405
+ const r = o == null ? void 0 : o.key;
409
406
  let i;
410
407
  if (e.isTexture === !0) {
411
408
  const g = e;
@@ -413,107 +410,107 @@ const v = class {
413
410
  }
414
411
  if (i || (i = v.lodInfos.get(r)), i) {
415
412
  if (t > 0) {
416
- let M = !1;
413
+ let D = !1;
417
414
  const w = Array.isArray(i.lods);
418
- if (w && t >= i.lods.length ? M = !0 : w || (M = !0), M)
415
+ if (w && t >= i.lods.length ? D = !0 : w || (D = !0), D)
419
416
  return this.lowresCache.get(r);
420
417
  }
421
418
  const g = Array.isArray(i.lods) ? (a = i.lods[t]) == null ? void 0 : a.path : i.lods;
422
419
  if (!g)
423
420
  return L && !i["missing:uri"] && (i["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + t, i)), null;
424
- const p = it(n.url, g);
421
+ const p = rt(o.url, g);
425
422
  if (p.endsWith(".glb") || p.endsWith(".gltf")) {
426
423
  if (!i.guid)
427
424
  return console.warn("missing pointer for glb/gltf texture", i), null;
428
- const M = p + "_" + i.guid, w = this.previouslyLoaded.get(M);
425
+ const D = p + "_" + i.guid, w = this.previouslyLoaded.get(D);
429
426
  if (w !== void 0) {
430
- s && console.log(`LOD ${t} was already loading/loaded: ${M}`);
427
+ s && console.log(`LOD ${t} was already loading/loaded: ${D}`);
431
428
  let h = await w.catch((F) => (console.error(`Error loading LOD ${t} from ${p}
432
429
  `, F), null)), R = !1;
433
- if (h == null || (h instanceof se && e instanceof se ? (l = h.image) != null && l.data || (u = h.source) != null && u.data ? h = this.copySettings(e, h) : (R = !0, this.previouslyLoaded.delete(M)) : h instanceof ge && e instanceof ge && ((c = h.attributes.position) != null && c.array || (R = !0, this.previouslyLoaded.delete(M)))), !R)
430
+ if (h == null || (h instanceof se && e instanceof se ? (l = h.image) != null && l.data || (u = h.source) != null && u.data ? h = this.copySettings(e, h) : (R = !0, this.previouslyLoaded.delete(D)) : h instanceof ge && e instanceof ge && ((c = h.attributes.position) != null && c.array || (R = !0, this.previouslyLoaded.delete(D)))), !R)
434
431
  return h;
435
432
  }
436
433
  const x = i, $ = new Promise(async (h, R) => {
437
434
  const F = new be();
438
- $e(F), L && (await new Promise((A) => setTimeout(A, 1e3)), s && console.warn("Start loading (delayed) " + p, x.guid));
435
+ $e(F), L && (await new Promise((S) => setTimeout(S, 1e3)), s && console.warn("Start loading (delayed) " + p, x.guid));
439
436
  let k = p;
440
437
  if (x && Array.isArray(x.lods)) {
441
- const A = x.lods[t];
442
- A.hash && (k += "?v=" + A.hash);
438
+ const S = x.lods[t];
439
+ S.hash && (k += "?v=" + S.hash);
443
440
  }
444
- const S = await F.loadAsync(k).catch((A) => (console.error(`Error loading LOD ${t} from ${p}
445
- `, A), null));
446
- if (!S)
441
+ const A = await F.loadAsync(k).catch((S) => (console.error(`Error loading LOD ${t} from ${p}
442
+ `, S), null));
443
+ if (!A)
447
444
  return null;
448
- const q = S.parser;
445
+ const N = A.parser;
449
446
  s && console.log("Loading finished " + p, x.guid);
450
- let T = 0;
451
- if (S.parser.json.textures) {
452
- let A = !1;
453
- for (const f of S.parser.json.textures) {
447
+ let _ = 0;
448
+ if (A.parser.json.textures) {
449
+ let S = !1;
450
+ for (const f of A.parser.json.textures) {
454
451
  if (f != null && f.extensions) {
455
- const y = f == null ? void 0 : f.extensions[z];
452
+ const y = f == null ? void 0 : f.extensions[V];
456
453
  if (y != null && y.guid && y.guid === x.guid) {
457
- A = !0;
454
+ S = !0;
458
455
  break;
459
456
  }
460
457
  }
461
- T++;
458
+ _++;
462
459
  }
463
- if (A) {
464
- let f = await q.getDependency("texture", T);
465
- return f && v.assignLODInformation(n.url, f, r, t, void 0, void 0), s && console.log('change "' + e.name + '" → "' + f.name + '"', p, T, f, M), e instanceof se && (f = this.copySettings(e, f)), f && (f.guid = x.guid), h(f);
460
+ if (S) {
461
+ let f = await N.getDependency("texture", _);
462
+ return f && v.assignLODInformation(o.url, f, r, t, void 0, void 0), s && console.log('change "' + e.name + '" → "' + f.name + '"', p, _, f, D), e instanceof se && (f = this.copySettings(e, f)), f && (f.guid = x.guid), h(f);
466
463
  } else
467
- L && console.warn("Could not find texture with guid", x.guid, S.parser.json);
464
+ L && console.warn("Could not find texture with guid", x.guid, A.parser.json);
468
465
  }
469
- if (T = 0, S.parser.json.meshes) {
470
- let A = !1;
471
- for (const f of S.parser.json.meshes) {
466
+ if (_ = 0, A.parser.json.meshes) {
467
+ let S = !1;
468
+ for (const f of A.parser.json.meshes) {
472
469
  if (f != null && f.extensions) {
473
- const y = f == null ? void 0 : f.extensions[z];
470
+ const y = f == null ? void 0 : f.extensions[V];
474
471
  if (y != null && y.guid && y.guid === x.guid) {
475
- A = !0;
472
+ S = !0;
476
473
  break;
477
474
  }
478
475
  }
479
- T++;
476
+ _++;
480
477
  }
481
- if (A) {
482
- const f = await q.getDependency("mesh", T), y = x;
483
- if (s && console.log(`Loaded Mesh "${f.name}"`, p, T, f, M), f.isMesh === !0) {
478
+ if (S) {
479
+ const f = await N.getDependency("mesh", _), y = x;
480
+ if (s && console.log(`Loaded Mesh "${f.name}"`, p, _, f, D), f.isMesh === !0) {
484
481
  const O = f.geometry;
485
- return v.assignLODInformation(n.url, O, r, t, void 0, y.density), h(O);
482
+ return v.assignLODInformation(o.url, O, r, t, void 0, y.density), h(O);
486
483
  } else {
487
484
  const O = new Array();
488
485
  for (let b = 0; b < f.children.length; b++) {
489
486
  const E = f.children[b];
490
487
  if (E.isMesh === !0) {
491
488
  const X = E.geometry;
492
- v.assignLODInformation(n.url, X, r, t, b, y.density), O.push(X);
489
+ v.assignLODInformation(o.url, X, r, t, b, y.density), O.push(X);
493
490
  }
494
491
  }
495
492
  return h(O);
496
493
  }
497
494
  } else
498
- L && console.warn("Could not find mesh with guid", x.guid, S.parser.json);
495
+ L && console.warn("Could not find mesh with guid", x.guid, A.parser.json);
499
496
  }
500
497
  return h(null);
501
498
  });
502
- return this.previouslyLoaded.set(M, $), await $;
499
+ return this.previouslyLoaded.set(D, $), await $;
503
500
  } else if (e instanceof se) {
504
501
  s && console.log("Load texture from uri: " + p);
505
- const w = await new Ke().loadAsync(p);
502
+ const w = await new Xe().loadAsync(p);
506
503
  return w ? (w.guid = i.guid, w.flipY = !1, w.needsUpdate = !0, w.colorSpace = e.colorSpace, s && console.log(i, w)) : L && console.warn("failed loading", p), w;
507
504
  }
508
505
  } else
509
506
  L && console.warn(`Can not load LOD ${t}: no LOD info found for "${r}" ${e.name}`, e.type);
510
507
  return null;
511
508
  }
512
- static assignLODInformation(e, t, s, n, r, i) {
509
+ static assignLODInformation(e, t, s, o, r, i) {
513
510
  if (!t)
514
511
  return;
515
512
  t.userData || (t.userData = {});
516
- const a = new ut(e, s, n, r, i);
513
+ const a = new ct(e, s, o, r, i);
517
514
  t.userData.LODS = a;
518
515
  }
519
516
  static getAssignedLODInformation(e) {
@@ -522,27 +519,27 @@ const v = class {
522
519
  }
523
520
  // private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
524
521
  static copySettings(e, t) {
525
- return t = t.clone(), L && console.warn(`Copying texture settings
522
+ return L && console.warn(`Copy texture settings
526
523
  `, e.uuid, `
527
- `, t.uuid), 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;
524
+ `, 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;
528
525
  }
529
526
  };
530
- let _ = v;
527
+ let T = v;
531
528
  /**
532
529
  * Register a texture with LOD information
533
530
  */
534
- d(_, "registerTexture", (e, t, s, n, r) => {
535
- if (L && console.log("> Progressive: register texture", n, t.name, t.uuid, t, r), !t) {
531
+ d(T, "registerTexture", (e, t, s, o, r) => {
532
+ if (L && console.log("> Progressive: register texture", o, t.name, t.uuid, t, r), !t) {
536
533
  L && console.error("gltf-progressive: Register texture without texture");
537
534
  return;
538
535
  }
539
536
  t.source && (t.source[De] = r);
540
537
  const i = r.guid;
541
- v.assignLODInformation(e, t, i, s, n, void 0), v.lodInfos.set(i, r), v.lowresCache.set(i, t);
538
+ v.assignLODInformation(e, t, i, s, o, void 0), v.lodInfos.set(i, r), v.lowresCache.set(i, t);
542
539
  }), /**
543
540
  * Register a mesh with LOD information
544
541
  */
545
- d(_, "registerMesh", (e, t, s, n, r, i) => {
542
+ d(T, "registerMesh", (e, t, s, o, r, i) => {
546
543
  var u;
547
544
  L && console.log("> Progressive: register mesh", r, s.name, i, s.uuid, s);
548
545
  const a = s.geometry;
@@ -550,17 +547,17 @@ d(_, "registerMesh", (e, t, s, n, r, i) => {
550
547
  L && console.warn("gltf-progressive: Register mesh without geometry");
551
548
  return;
552
549
  }
553
- a.userData || (a.userData = {}), v.assignLODInformation(e, a, t, n, r, i.density), v.lodInfos.set(t, i);
550
+ a.userData || (a.userData = {}), v.assignLODInformation(e, a, t, o, r, i.density), v.lodInfos.set(t, i);
554
551
  let l = v.lowresCache.get(t);
555
- l ? l.push(s.geometry) : l = [s.geometry], v.lowresCache.set(t, l), n > 0 && !ce(s) && at(s, a);
556
- for (const c of Y)
552
+ l ? l.push(s.geometry) : l = [s.geometry], v.lowresCache.set(t, l), o > 0 && !ce(s) && nt(s, a);
553
+ for (const c of H)
557
554
  (u = c.onRegisteredNewMesh) == null || u.call(c, s, i);
558
555
  }), /** A map of key = asset uuid and value = LOD information */
559
- d(_, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
560
- d(_, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
561
- d(_, "lowresCache", /* @__PURE__ */ new Map());
562
- class ut {
563
- constructor(e, t, s, n, r) {
556
+ d(T, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
557
+ d(T, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
558
+ d(T, "lowresCache", /* @__PURE__ */ new Map());
559
+ class ct {
560
+ constructor(e, t, s, o, r) {
564
561
  d(this, "url");
565
562
  /** the key to lookup the LOD information */
566
563
  d(this, "key");
@@ -569,11 +566,11 @@ class ut {
569
566
  d(this, "index");
570
567
  /** the mesh density */
571
568
  d(this, "density");
572
- this.url = e, this.key = t, this.level = s, n != null && (this.index = n), r != null && (this.density = r);
569
+ this.url = e, this.key = t, this.level = s, o != null && (this.index = o), r != null && (this.density = r);
573
570
  }
574
571
  }
575
- const I = le("debugprogressive"), ft = le("noprogressive"), we = Symbol("Needle:LODSManager"), ve = Symbol("Needle:LODState"), Z = Symbol("Needle:CurrentLOD"), G = { mesh_lod: -1, texture_lod: -1 };
576
- var C, V, ye, j, ee, me, W;
572
+ const I = le("debugprogressive"), ut = le("noprogressive"), we = Symbol("Needle:LODSManager"), ve = Symbol("Needle:LODState"), Y = Symbol("Needle:CurrentLOD"), G = { mesh_lod: -1, texture_lod: -1 };
573
+ var C, W, ye, j, ee, me, q;
577
574
  const P = class {
578
575
  // readonly plugins: NEEDLE_progressive_plugin[] = [];
579
576
  constructor(e, t) {
@@ -603,21 +600,21 @@ const P = class {
603
600
  */
604
601
  d(this, "manual", !1);
605
602
  d(this, "_lodchangedlisteners", []);
606
- K(this, V, void 0);
607
- K(this, ye, new Ye());
603
+ K(this, W, void 0);
604
+ K(this, ye, new Ke());
608
605
  K(this, j, 0);
609
606
  K(this, ee, 0);
610
607
  K(this, me, 0);
611
- K(this, W, 0);
608
+ K(this, q, 0);
612
609
  d(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
613
610
  // private testIfLODLevelsAreAvailable() {
614
- d(this, "_sphere", new Je());
611
+ d(this, "_sphere", new He());
615
612
  d(this, "_tempBox", new Ee());
616
613
  d(this, "_tempBox2", new Ee());
617
614
  d(this, "tempMatrix", new Ae());
618
- d(this, "_tempWorldPosition", new N());
619
- d(this, "_tempBoxSize", new N());
620
- d(this, "_tempBox2Size", new N());
615
+ d(this, "_tempWorldPosition", new z());
616
+ d(this, "_tempBoxSize", new z());
617
+ d(this, "_tempBox2Size", new z());
621
618
  this.renderer = e, this.context = { ...t };
622
619
  }
623
620
  /** @internal */
@@ -625,11 +622,11 @@ const P = class {
625
622
  return e[ve];
626
623
  }
627
624
  static addPlugin(e) {
628
- Y.push(e);
625
+ H.push(e);
629
626
  }
630
627
  static removePlugin(e) {
631
- const t = Y.indexOf(e);
632
- t >= 0 && Y.splice(t, 1);
628
+ const t = H.indexOf(e);
629
+ t >= 0 && H.splice(t, 1);
633
630
  }
634
631
  /**
635
632
  * Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
@@ -647,7 +644,7 @@ const P = class {
647
644
  }
648
645
  /** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
649
646
  get plugins() {
650
- return Y;
647
+ return H;
651
648
  }
652
649
  addEventListener(e, t) {
653
650
  e === "changed" && this._lodchangedlisteners.push(t);
@@ -662,21 +659,21 @@ const P = class {
662
659
  * Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
663
660
  */
664
661
  enable() {
665
- if (m(this, V))
662
+ if (m(this, W))
666
663
  return;
667
664
  console.debug("[gltf-progressive] Enabling LODsManager for renderer");
668
665
  let e = 0;
669
- U(this, V, this.renderer.render);
666
+ U(this, W, this.renderer.render);
670
667
  const t = this;
671
- Ge(this.renderer), this.renderer.render = function(s, n) {
668
+ Ge(this.renderer), this.renderer.render = function(s, o) {
672
669
  const r = t.renderer.getRenderTarget();
673
- (r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (e = 0, U(t, j, m(t, j) + 1), U(t, ee, m(t, ye).getDelta()), U(t, me, m(t, me) + m(t, ee)), t._fpsBuffer.shift(), t._fpsBuffer.push(1 / m(t, ee)), U(t, W, t._fpsBuffer.reduce((a, l) => a + l) / t._fpsBuffer.length), I && m(t, j) % 200 === 0 && console.log("FPS", Math.round(m(t, W)), "Interval:", m(t, C)));
670
+ (r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (e = 0, U(t, j, m(t, j) + 1), U(t, ee, m(t, ye).getDelta()), U(t, me, m(t, me) + m(t, ee)), t._fpsBuffer.shift(), t._fpsBuffer.push(1 / m(t, ee)), U(t, q, t._fpsBuffer.reduce((a, l) => a + l) / t._fpsBuffer.length), I && m(t, j) % 200 === 0 && console.log("FPS", Math.round(m(t, q)), "Interval:", m(t, C)));
674
671
  const i = e++;
675
- m(t, V).call(this, s, n), t.onAfterRender(s, n, i);
672
+ m(t, W).call(this, s, o), t.onAfterRender(s, o, i);
676
673
  };
677
674
  }
678
675
  disable() {
679
- m(this, V) && (console.debug("[gltf-progressive] Disabling LODsManager for renderer"), this.renderer.render = m(this, V), U(this, V, void 0));
676
+ m(this, W) && (console.debug("[gltf-progressive] Disabling LODsManager for renderer"), this.renderer.render = m(this, W), U(this, W, void 0));
680
677
  }
681
678
  update(e, t) {
682
679
  this.internalUpdate(e, t);
@@ -691,7 +688,7 @@ const P = class {
691
688
  (a.name === "EffectMaterial" || a.name === "CopyShader") && (i = !1);
692
689
  }
693
690
  if ((t.parent && t.parent.type === "CubeCamera" || s >= 1 && t.type === "OrthographicCamera") && (i = !1), i) {
694
- if (ft || (this.updateInterval === "auto" ? m(this, W) < 40 && m(this, C) < 10 ? (U(this, C, m(this, C) + 1), I && console.warn("↓ Reducing LOD updates", m(this, C), m(this, W).toFixed(0))) : m(this, W) >= 60 && m(this, C) > 1 && (U(this, C, m(this, C) - 1), I && console.warn("↑ Increasing LOD updates", m(this, C), m(this, W).toFixed(0))) : U(this, C, this.updateInterval), m(this, C) > 0 && m(this, j) % m(this, C) != 0))
691
+ if (ut || (this.updateInterval === "auto" ? m(this, q) < 40 && m(this, C) < 10 ? (U(this, C, m(this, C) + 1), I && console.warn("↓ Reducing LOD updates", m(this, C), m(this, q).toFixed(0))) : m(this, q) >= 60 && m(this, C) > 1 && (U(this, C, m(this, C) - 1), I && console.warn("↑ Increasing LOD updates", m(this, C), m(this, q).toFixed(0))) : U(this, C, this.updateInterval), m(this, C) > 0 && m(this, j) % m(this, C) != 0))
695
692
  return;
696
693
  this.internalUpdate(e, t);
697
694
  }
@@ -701,10 +698,10 @@ const P = class {
701
698
  */
702
699
  internalUpdate(e, t) {
703
700
  var l, u;
704
- const s = this.renderer.renderLists.get(e, 0), n = s.opaque;
701
+ const s = this.renderer.renderLists.get(e, 0), o = s.opaque;
705
702
  this.projectionScreenMatrix.multiplyMatrices(t.projectionMatrix, t.matrixWorldInverse);
706
703
  const r = this.targetTriangleDensity;
707
- for (const c of n) {
704
+ for (const c of o) {
708
705
  if (c.material && (((l = c.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((u = c.geometry) == null ? void 0 : u.type) === "BufferGeometry") && (c.material.name === "SphericalGaussianBlur" || c.material.name == "BackgroundCubeMaterial" || c.material.name === "CubemapFromEquirect" || c.material.name === "EquirectangularToCubeUV")) {
709
706
  I && (c.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (c.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", c, c.material.name, c.material.type)));
710
707
  continue;
@@ -720,39 +717,36 @@ const P = class {
720
717
  }
721
718
  if (I === "color" && c.material && !c.object.progressive_debug_color) {
722
719
  c.object.progressive_debug_color = !0;
723
- const p = Math.random() * 16777215, M = new He({ color: p });
724
- c.object.material = M;
720
+ const p = Math.random() * 16777215, D = new Ye({ color: p });
721
+ c.object.material = D;
725
722
  }
726
723
  const g = c.object;
727
- (g instanceof Q || g.isMesh) && this.updateLODs(e, t, g, r);
724
+ (g instanceof Z || g.isMesh) && this.updateLODs(e, t, g, r);
728
725
  }
729
726
  const i = s.transparent;
730
727
  for (const c of i) {
731
728
  const g = c.object;
732
- (g instanceof Q || g.isMesh) && this.updateLODs(e, t, g, r);
729
+ (g instanceof Z || g.isMesh) && this.updateLODs(e, t, g, r);
733
730
  }
734
731
  const a = s.transmissive;
735
732
  for (const c of a) {
736
733
  const g = c.object;
737
- (g instanceof Q || g.isMesh) && this.updateLODs(e, t, g, r);
734
+ (g instanceof Z || g.isMesh) && this.updateLODs(e, t, g, r);
738
735
  }
739
736
  }
740
737
  /** Update the LOD levels for the renderer. */
741
- updateLODs(e, t, s, n) {
738
+ updateLODs(e, t, s, o) {
742
739
  var a, l;
743
740
  s.userData || (s.userData = {});
744
741
  let r = s[ve];
745
- if (r || (r = new dt(), s[ve] = r), r.frames++ < 2)
742
+ if (r || (r = new ft(), s[ve] = r), r.frames++ < 2)
746
743
  return;
747
- for (const u of Y)
744
+ for (const u of H)
748
745
  (a = u.onBeforeUpdateLOD) == null || a.call(u, this.renderer, e, t, s);
749
- this.calculateLodLevel(t, 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);
746
+ this.calculateLodLevel(t, s, r, o, 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);
750
747
  let i = G.texture_lod;
751
- if (s.material && i >= 0) {
752
- const u = s["DEBUG:LOD"];
753
- u != null && (i = u), this.loadProgressiveTextures(s.material, i);
754
- }
755
- for (const u of Y)
748
+ s.material && i >= 0 && this.loadProgressiveTextures(s.material, i);
749
+ for (const u of H)
756
750
  (l = u.onAfterUpdatedLOD) == null || l.call(u, this.renderer, e, t, s, G);
757
751
  r.lastLodLevel_Mesh = G.mesh_lod, r.lastLodLevel_Texture = G.texture_lod;
758
752
  }
@@ -765,13 +759,15 @@ const P = class {
765
759
  if (!e)
766
760
  return;
767
761
  if (Array.isArray(e)) {
768
- for (const n of e)
769
- this.loadProgressiveTextures(n, t);
762
+ for (const r of e)
763
+ this.loadProgressiveTextures(r, t);
770
764
  return;
771
765
  }
772
766
  let s = !1;
773
- (e[Z] === void 0 || t < e[Z]) && (s = !0), s && (e[Z] = t, _.assignTextureLOD(e, t).then((n) => {
774
- this._lodchangedlisteners.forEach((r) => r({ type: "texture", level: t, object: e }));
767
+ (e[Y] === void 0 || t < e[Y]) && (s = !0);
768
+ const o = e["DEBUG:LOD"];
769
+ o != null && (s = e[Y] != o, t = o), s && (e[Y] = t, T.assignTextureLOD(e, t).then((r) => {
770
+ this._lodchangedlisteners.forEach((i) => i({ type: "texture", level: t, object: e }));
775
771
  }));
776
772
  }
777
773
  /** Load progressive meshes for the given mesh
@@ -783,18 +779,20 @@ const P = class {
783
779
  loadProgressiveMeshes(e, t) {
784
780
  if (!e)
785
781
  return Promise.resolve(null);
786
- if (e[Z] !== t) {
787
- e[Z] = t;
788
- const s = e.geometry;
789
- return _.assignMeshLOD(e, t).then((n) => (n && e[Z] == t && s != e.geometry && this._lodchangedlisteners.forEach((r) => r({ type: "mesh", level: t, object: e })), n));
782
+ let s = e[Y] !== t;
783
+ const o = e["DEBUG:LOD"];
784
+ if (o != null && (s = e[Y] != o, t = o), s) {
785
+ e[Y] = t;
786
+ const r = e.geometry;
787
+ return T.assignMeshLOD(e, t).then((i) => (i && e[Y] == t && r != e.geometry && this._lodchangedlisteners.forEach((a) => a({ type: "mesh", level: t, object: e })), i));
790
788
  }
791
789
  return Promise.resolve(null);
792
790
  }
793
791
  static isInside(e, t) {
794
- const s = e.min, n = e.max, r = (s.x + n.x) * 0.5, i = (s.y + n.y) * 0.5;
792
+ const s = e.min, o = e.max, r = (s.x + o.x) * 0.5, i = (s.y + o.y) * 0.5;
795
793
  return this._tempPtInside.set(r, i, s.z).applyMatrix4(t).z < 0;
796
794
  }
797
- calculateLodLevel(e, t, s, n, r) {
795
+ calculateLodLevel(e, t, s, o, r) {
798
796
  var $;
799
797
  if (!t) {
800
798
  r.mesh_lod = -1, r.texture_lod = -1;
@@ -807,8 +805,8 @@ const P = class {
807
805
  let a = 10 + 1, l = !1;
808
806
  if (I && t["DEBUG:LOD"] != null)
809
807
  return t["DEBUG:LOD"];
810
- const u = _.getMeshLODInformation(t.geometry), c = u == null ? void 0 : u.lods, g = c && c.length > 0, p = _.getMaterialMinMaxLODsCount(t.material), M = (p == null ? void 0 : p.min_count) != 1 / 0 && p.min_count > 0 && p.max_count > 0;
811
- if (!g && !M) {
808
+ const u = T.getMeshLODInformation(t.geometry), c = u == null ? void 0 : u.lods, g = c && c.length > 0, p = T.getMaterialMinMaxLODsCount(t.material), D = (p == null ? void 0 : p.min_count) != 1 / 0 && p.min_count > 0 && p.max_count > 0;
809
+ if (!g && !D) {
812
810
  r.mesh_lod = 0, r.texture_lod = 0;
813
811
  return;
814
812
  }
@@ -816,17 +814,17 @@ const P = class {
816
814
  const w = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
817
815
  let x = t.geometry.boundingBox;
818
816
  if (t.type === "SkinnedMesh") {
819
- const D = t;
820
- if (!D.boundingBox)
821
- D.computeBoundingBox();
817
+ const M = t;
818
+ if (!M.boundingBox)
819
+ M.computeBoundingBox();
822
820
  else if (s.frames % 30 === 0) {
823
- const h = ce(D), R = D.geometry;
824
- h && (D.geometry = h), D.computeBoundingBox(), D.geometry = R;
821
+ const h = ce(M), R = M.geometry;
822
+ h && (M.geometry = h), M.computeBoundingBox(), M.geometry = R;
825
823
  }
826
- x = D.boundingBox;
824
+ x = M.boundingBox;
827
825
  }
828
- if (x && e.isPerspectiveCamera) {
829
- const D = e;
826
+ if (x) {
827
+ const M = e;
830
828
  if (t.geometry.attributes.color && t.geometry.attributes.color.count < 100 && t.geometry.boundingSphere) {
831
829
  this._sphere.copy(t.geometry.boundingSphere), this._sphere.applyMatrix4(t.matrixWorld);
832
830
  const f = e.getWorldPosition(this._tempWorldPosition);
@@ -835,11 +833,11 @@ const P = class {
835
833
  return;
836
834
  }
837
835
  }
838
- if (this._tempBox.copy(x), this._tempBox.applyMatrix4(t.matrixWorld), P.isInside(this._tempBox, this.projectionScreenMatrix)) {
836
+ if (this._tempBox.copy(x), this._tempBox.applyMatrix4(t.matrixWorld), M.isPerspectiveCamera && P.isInside(this._tempBox, this.projectionScreenMatrix)) {
839
837
  r.mesh_lod = 0, r.texture_lod = 0;
840
838
  return;
841
839
  }
842
- if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && D.fov > 70) {
840
+ if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && M.isPerspectiveCamera && M.fov > 70) {
843
841
  const f = this._tempBox.min, y = this._tempBox.max;
844
842
  let O = f.x, b = f.y, E = y.x, X = y.y;
845
843
  const ue = 2, Le = 1.5, fe = (f.x + y.x) * 0.5, de = (f.y + y.y) * 0.5;
@@ -849,11 +847,11 @@ const P = class {
849
847
  } else
850
848
  s.lastCentrality = 1;
851
849
  const h = this._tempBox.getSize(this._tempBoxSize);
852
- h.multiplyScalar(0.5), screen.availHeight > 0 && w > 0 && h.multiplyScalar(w / screen.availHeight), h.x *= D.aspect;
850
+ h.multiplyScalar(0.5), screen.availHeight > 0 && w > 0 && h.multiplyScalar(w / screen.availHeight), e.isPerspectiveCamera ? h.x *= e.aspect : e.isOrthographicCamera;
853
851
  const R = e.matrixWorldInverse, F = this._tempBox2;
854
852
  F.copy(x), F.applyMatrix4(t.matrixWorld), F.applyMatrix4(R);
855
- const k = F.getSize(this._tempBox2Size), S = Math.max(k.x, k.y);
856
- if (Math.max(h.x, h.y) != 0 && S != 0 && (h.z = k.z / Math.max(k.x, k.y) * Math.max(h.x, h.y)), s.lastScreenCoverage = Math.max(h.x, h.y, h.z), s.lastScreenspaceVolume.copy(h), s.lastScreenCoverage *= s.lastCentrality, I && P.debugDrawLine) {
853
+ const k = F.getSize(this._tempBox2Size), A = Math.max(k.x, k.y);
854
+ if (Math.max(h.x, h.y) != 0 && A != 0 && (h.z = k.z / Math.max(k.x, k.y) * Math.max(h.x, h.y)), s.lastScreenCoverage = Math.max(h.x, h.y, h.z), s.lastScreenspaceVolume.copy(h), s.lastScreenCoverage *= s.lastCentrality, I && P.debugDrawLine) {
857
855
  const f = this.tempMatrix.copy(this.projectionScreenMatrix);
858
856
  f.invert();
859
857
  const y = P.corner0, O = P.corner1, b = P.corner2, E = P.corner3;
@@ -861,22 +859,22 @@ const P = class {
861
859
  const X = (y.z + E.z) * 0.5;
862
860
  y.z = O.z = b.z = E.z = X, y.applyMatrix4(f), O.applyMatrix4(f), b.applyMatrix4(f), E.applyMatrix4(f), P.debugDrawLine(y, O, 255), P.debugDrawLine(y, b, 255), P.debugDrawLine(O, E, 255), P.debugDrawLine(b, E, 255);
863
861
  }
864
- let T = 999;
862
+ let _ = 999;
865
863
  if (c && s.lastScreenCoverage > 0) {
866
864
  for (let f = 0; f < c.length; f++)
867
- if (c[f].density / s.lastScreenCoverage < n) {
868
- T = f;
865
+ if (c[f].density / s.lastScreenCoverage < o) {
866
+ _ = f;
869
867
  break;
870
868
  }
871
869
  }
872
- T < a && (a = T, l = !0);
870
+ _ < a && (a = _, l = !0);
873
871
  }
874
872
  if (l ? r.mesh_lod = a : r.mesh_lod = s.lastLodLevel_Mesh, I && r.mesh_lod != s.lastLodLevel_Mesh) {
875
873
  const h = c == null ? void 0 : c[r.mesh_lod];
876
874
  h && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${r.mesh_lod} (${h.density.toFixed(0)}) - ${t.name}`);
877
875
  }
878
- if (M) {
879
- const D = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
876
+ if (D) {
877
+ const M = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
880
878
  if (s.lastLodLevel_Texture < 0) {
881
879
  if (r.texture_lod = p.max_count - 1, I) {
882
880
  const h = p.lods[p.max_count - 1];
@@ -887,12 +885,13 @@ const P = class {
887
885
  let R = s.lastScreenCoverage * 4;
888
886
  (($ = this.context) == null ? void 0 : $.engine) === "model-viewer" && (R *= 1.5);
889
887
  const k = w / window.devicePixelRatio * R;
890
- for (let S = p.lods.length - 1; S >= 0; S--) {
891
- let q = p.lods[S];
892
- if (!(D && q.max_height >= 2048) && !(nt() && q.max_height > 4096) && q.max_height > k) {
893
- if (r.texture_lod = S, r.texture_lod < s.lastLodLevel_Texture) {
894
- const T = q.max_height;
895
- I && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${r.texture_lod} = ${T}px
888
+ let A = !1;
889
+ for (let N = p.lods.length - 1; N >= 0; N--) {
890
+ let _ = p.lods[N];
891
+ if (!(M && _.max_height >= 2048) && !(it() && _.max_height > 4096) && (_.max_height > k || !A && N === 0)) {
892
+ if (A = !0, r.texture_lod = N, r.texture_lod < s.lastLodLevel_Texture) {
893
+ const S = _.max_height;
894
+ I && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${r.texture_lod} = ${S}px
896
895
  Screensize: ${k.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${h.toFixed(1)}
897
896
  ${t.name}`);
898
897
  }
@@ -905,38 +904,38 @@ ${t.name}`);
905
904
  }
906
905
  };
907
906
  let B = P;
908
- C = new WeakMap(), V = new WeakMap(), ye = new WeakMap(), j = new WeakMap(), ee = new WeakMap(), me = new WeakMap(), W = new WeakMap(), /** 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.
907
+ C = new WeakMap(), W = new WeakMap(), ye = new WeakMap(), j = new WeakMap(), ee = new WeakMap(), me = new WeakMap(), q = new WeakMap(), /** 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.
909
908
  */
910
- d(B, "debugDrawLine"), d(B, "corner0", new N()), d(B, "corner1", new N()), d(B, "corner2", new N()), d(B, "corner3", new N()), d(B, "_tempPtInside", new N());
911
- class dt {
909
+ d(B, "debugDrawLine"), d(B, "corner0", new z()), d(B, "corner1", new z()), d(B, "corner2", new z()), d(B, "corner3", new z()), d(B, "_tempPtInside", new z());
910
+ class ft {
912
911
  constructor() {
913
912
  d(this, "frames", 0);
914
913
  d(this, "lastLodLevel_Mesh", -1);
915
914
  d(this, "lastLodLevel_Texture", -1);
916
915
  d(this, "lastScreenCoverage", 0);
917
- d(this, "lastScreenspaceVolume", new N());
916
+ d(this, "lastScreenspaceVolume", new z());
918
917
  d(this, "lastCentrality", 0);
919
918
  }
920
919
  }
921
920
  const Ce = Symbol("NEEDLE_mesh_lod"), he = Symbol("NEEDLE_texture_lod");
922
- let ne = null;
921
+ let oe = null;
923
922
  function Ue() {
924
- const o = ht();
925
- o && (o.mapURLs(function(e) {
923
+ const n = dt();
924
+ n && (n.mapURLs(function(e) {
926
925
  return Be(), e;
927
- }), Be(), ne == null || ne.disconnect(), ne = new MutationObserver((e) => {
926
+ }), Be(), oe == null || oe.disconnect(), oe = new MutationObserver((e) => {
928
927
  e.forEach((t) => {
929
928
  t.addedNodes.forEach((s) => {
930
929
  s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && Ne(s);
931
930
  });
932
931
  });
933
- }), ne.observe(document, { childList: !0, subtree: !0 }));
932
+ }), oe.observe(document, { childList: !0, subtree: !0 }));
934
933
  }
935
- function ht() {
934
+ function dt() {
936
935
  if (typeof customElements > "u")
937
936
  return null;
938
- const o = customElements.get("model-viewer");
939
- return o || (customElements.whenDefined("model-viewer").then(() => {
937
+ const n = customElements.get("model-viewer");
938
+ return n || (customElements.whenDefined("model-viewer").then(() => {
940
939
  console.debug("[gltf-progressive] model-viewer defined"), Ue();
941
940
  }), null);
942
941
  }
@@ -948,49 +947,49 @@ function Be() {
948
947
  });
949
948
  }
950
949
  const Re = /* @__PURE__ */ new WeakSet();
951
- let gt = 0;
952
- function Ne(o) {
953
- if (!o || Re.has(o))
950
+ let ht = 0;
951
+ function Ne(n) {
952
+ if (!n || Re.has(n))
954
953
  return null;
955
- Re.add(o), console.debug("[gltf-progressive] found new model-viewer..." + ++gt + `
956
- `, o.getAttribute("src"));
954
+ Re.add(n), console.debug("[gltf-progressive] found new model-viewer..." + ++ht + `
955
+ `, n.getAttribute("src"));
957
956
  let e = null, t = null, s = null;
958
- for (let n = o; n != null; n = Object.getPrototypeOf(n)) {
959
- const r = Object.getOwnPropertySymbols(n), i = r.find((u) => u.toString() == "Symbol(renderer)"), a = r.find((u) => u.toString() == "Symbol(scene)"), l = r.find((u) => u.toString() == "Symbol(needsRender)");
960
- !e && i != null && (e = o[i].threeRenderer), !t && a != null && (t = o[a]), !s && l != null && (s = o[l]);
957
+ for (let o = n; o != null; o = Object.getPrototypeOf(o)) {
958
+ const r = Object.getOwnPropertySymbols(o), i = r.find((u) => u.toString() == "Symbol(renderer)"), a = r.find((u) => u.toString() == "Symbol(scene)"), l = r.find((u) => u.toString() == "Symbol(needsRender)");
959
+ !e && i != null && (e = n[i].threeRenderer), !t && a != null && (t = n[a]), !s && l != null && (s = n[l]);
961
960
  }
962
961
  if (e && t) {
963
- let n = function() {
962
+ let o = function() {
964
963
  if (s) {
965
964
  let i = 0, a = setInterval(() => {
966
965
  if (i++ > 5) {
967
966
  clearInterval(a);
968
967
  return;
969
968
  }
970
- s == null || s.call(o);
969
+ s == null || s.call(n);
971
970
  }, 300);
972
971
  }
973
972
  };
974
973
  console.debug("[gltf-progressive] setup model-viewer");
975
974
  const r = B.get(e, { engine: "model-viewer" });
976
- return B.addPlugin(new pt()), r.enable(), r.addEventListener("changed", () => {
977
- s == null || s.call(o);
978
- }), o.addEventListener("model-visibility", (i) => {
979
- i.detail.visible && (s == null || s.call(o));
980
- }), o.addEventListener("load", () => {
981
- n();
975
+ return B.addPlugin(new gt()), r.enable(), r.addEventListener("changed", () => {
976
+ s == null || s.call(n);
977
+ }), n.addEventListener("model-visibility", (i) => {
978
+ i.detail.visible && (s == null || s.call(n));
979
+ }), n.addEventListener("load", () => {
980
+ o();
982
981
  }), () => {
983
982
  r.disable();
984
983
  };
985
984
  }
986
985
  return null;
987
986
  }
988
- class pt {
987
+ class gt {
989
988
  constructor() {
990
989
  d(this, "_didWarnAboutMissingUrl", !1);
991
990
  }
992
- onBeforeUpdateLOD(e, t, s, n) {
993
- this.tryParseMeshLOD(t, n), this.tryParseTextureLOD(t, n);
991
+ onBeforeUpdateLOD(e, t, s, o) {
992
+ this.tryParseMeshLOD(t, o), this.tryParseTextureLOD(t, o);
994
993
  }
995
994
  getUrl(e) {
996
995
  if (!e)
@@ -1008,7 +1007,7 @@ class pt {
1008
1007
  if (t[he] == !0)
1009
1008
  return;
1010
1009
  t[he] = !0;
1011
- const s = this.tryGetCurrentGLTF(e), n = this.tryGetCurrentModelViewer(e), r = this.getUrl(n);
1010
+ const s = this.tryGetCurrentGLTF(e), o = this.tryGetCurrentModelViewer(e), r = this.getUrl(o);
1012
1011
  if (r && s && t.material) {
1013
1012
  let i = function(l) {
1014
1013
  var c, g, p;
@@ -1016,20 +1015,20 @@ class pt {
1016
1015
  return;
1017
1016
  l[he] = !0, l.userData && (l.userData.LOD = -1);
1018
1017
  const u = Object.keys(l);
1019
- for (let M = 0; M < u.length; M++) {
1020
- const w = u[M], x = l[w];
1018
+ for (let D = 0; D < u.length; D++) {
1019
+ const w = u[D], x = l[w];
1021
1020
  if ((x == null ? void 0 : x.isTexture) === !0) {
1022
1021
  const $ = (g = (c = x.userData) == null ? void 0 : c.associations) == null ? void 0 : g.textures;
1023
1022
  if ($ == null)
1024
1023
  continue;
1025
- const D = s.parser.json.textures[$];
1026
- if (!D) {
1024
+ const M = s.parser.json.textures[$];
1025
+ if (!M) {
1027
1026
  console.warn("Texture data not found for texture index " + $);
1028
1027
  continue;
1029
1028
  }
1030
- if ((p = D == null ? void 0 : D.extensions) != null && p[z]) {
1031
- const h = D.extensions[z];
1032
- h && r && _.registerTexture(r, x, h.lods.length, $, h);
1029
+ if ((p = M == null ? void 0 : M.extensions) != null && p[V]) {
1030
+ const h = M.extensions[V];
1031
+ h && r && T.registerTexture(r, x, h.lods.length, $, h);
1033
1032
  }
1034
1033
  }
1035
1034
  }
@@ -1047,54 +1046,54 @@ class pt {
1047
1046
  if (t[Ce] == !0)
1048
1047
  return;
1049
1048
  t[Ce] = !0;
1050
- const s = this.tryGetCurrentModelViewer(e), n = this.getUrl(s);
1051
- if (!n)
1049
+ const s = this.tryGetCurrentModelViewer(e), o = this.getUrl(s);
1050
+ if (!o)
1052
1051
  return;
1053
- const r = (a = (i = t.userData) == null ? void 0 : i.gltfExtensions) == null ? void 0 : a[z];
1054
- if (r && n) {
1052
+ const r = (a = (i = t.userData) == null ? void 0 : i.gltfExtensions) == null ? void 0 : a[V];
1053
+ if (r && o) {
1055
1054
  const l = t.uuid;
1056
- _.registerMesh(n, l, t, 0, r.lods.length, r);
1055
+ T.registerMesh(o, l, t, 0, r.lods.length, r);
1057
1056
  }
1058
1057
  }
1059
1058
  }
1060
- function yt(o, e, t, s) {
1059
+ function pt(n, e, t, s) {
1061
1060
  Ge(e), $e(t), Fe(t, {
1062
1061
  progressive: !0,
1063
1062
  ...s == null ? void 0 : s.hints
1064
- }), t.register((r) => new _(r, o));
1065
- const n = B.get(e);
1066
- return (s == null ? void 0 : s.enableLODsManager) !== !1 && n.enable(), n;
1063
+ }), t.register((r) => new T(r, n));
1064
+ const o = B.get(e);
1065
+ return (s == null ? void 0 : s.enableLODsManager) !== !1 && o.enable(), o;
1067
1066
  }
1068
1067
  Ue();
1069
1068
  if (!ot) {
1070
- const o = {
1069
+ const n = {
1071
1070
  gltfProgressive: {
1072
- useNeedleProgressive: yt,
1071
+ useNeedleProgressive: pt,
1073
1072
  LODsManager: B,
1074
1073
  configureLoader: Fe,
1075
1074
  getRaycastMesh: ce,
1076
- useRaycastMeshes: lt
1075
+ useRaycastMeshes: at
1077
1076
  }
1078
1077
  };
1079
1078
  if (!globalThis.Needle)
1080
- globalThis.Needle = o;
1079
+ globalThis.Needle = n;
1081
1080
  else
1082
- for (const e in o)
1083
- globalThis.Needle[e] = o[e];
1081
+ for (const e in n)
1082
+ globalThis.Needle[e] = n[e];
1084
1083
  }
1085
1084
  export {
1086
- z as EXTENSION_NAME,
1085
+ V as EXTENSION_NAME,
1087
1086
  B as LODsManager,
1088
- _ as NEEDLE_progressive,
1087
+ T as NEEDLE_progressive,
1089
1088
  ke as VERSION,
1090
1089
  $e as addDracoAndKTX2Loaders,
1091
1090
  Fe as configureLoader,
1092
1091
  Ge as createLoaders,
1093
1092
  ce as getRaycastMesh,
1094
1093
  Ue as patchModelViewer,
1095
- at as registerRaycastMesh,
1096
- vt as setDracoDecoderLocation,
1097
- Ot as setKTX2TranscoderLocation,
1098
- yt as useNeedleProgressive,
1099
- lt as useRaycastMeshes
1094
+ nt as registerRaycastMesh,
1095
+ wt as setDracoDecoderLocation,
1096
+ vt as setKTX2TranscoderLocation,
1097
+ pt as useNeedleProgressive,
1098
+ at as useRaycastMeshes
1100
1099
  };