@needle-tools/gltf-progressive 1.2.3-beta → 1.2.4-beta.1

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