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