@needle-tools/gltf-progressive 1.2.0-alpha.9 → 1.2.1-alpha.1

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