@needle-tools/gltf-progressive 1.2.0-alpha.3 → 1.2.0-alpha.4

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