@needle-tools/gltf-progressive 1.2.1-alpha.4 → 1.2.2-alpha

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