@needle-tools/engine 4.1.0-beta.3 → 4.1.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,8 +4,12 @@ All notable changes to this package will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [4.1.0-beta.4] - 2024-01-31
8
+ - Add: OrbitControls support for orthographic camera
9
+ - Fix: Orthographic camera aspect ratio
10
+
7
11
  ## [4.1.0-beta.3] - 2024-01-30
8
- - Fix issue where networked values with the `@syncField` decorator would not be updated correctly on instances spawned at runtime (e.g. via PlayerSync).
12
+ - Fix: issue where networked values with the `@syncField` decorator would not be updated correctly on instances spawned at runtime (e.g. via PlayerSync).
9
13
 
10
14
  ## [4.1.0-beta.2] - 2024-01-29
11
15
  - Fix: VideoPlayer screenspace mode colorspace
@@ -104,7 +104,7 @@ function nt(t) {
104
104
  e.setAttribute(s, t.getAttribute(s));
105
105
  return e.setIndex(t.getIndex()), e;
106
106
  }
107
- const q = new Array(), $ = "NEEDLE_progressive", y = oe("debugprogressive"), _e = Symbol("needle-progressive-texture"), ie = /* @__PURE__ */ new Map(), we = /* @__PURE__ */ new Set();
107
+ const q = new Array(), $ = "NEEDLE_progressive", y = oe("debugprogressive"), _e = Symbol("needle-progressive-texture"), ie = /* @__PURE__ */ new Map(), ve = /* @__PURE__ */ new Set();
108
108
  if (y) {
109
109
  let t = function() {
110
110
  e += 1, console.log("Toggle LOD level", e, ie), ie.forEach((i, r) => {
@@ -123,7 +123,7 @@ if (y) {
123
123
  }), e >= s && (e = -1);
124
124
  }, e = -1, s = 2, n = !1;
125
125
  window.addEventListener("keyup", (i) => {
126
- i.key === "p" && t(), i.key === "w" && (n = !n, we && we.forEach((r) => {
126
+ i.key === "p" && t(), i.key === "w" && (n = !n, ve && ve.forEach((r) => {
127
127
  r.name != "BackgroundCubeMaterial" && r.glyphMap == null && "wireframe" in r && (r.wireframe = n);
128
128
  }));
129
129
  });
@@ -288,7 +288,7 @@ const D = class {
288
288
  }
289
289
  if (t instanceof We || t.isMaterial === !0) {
290
290
  const s = t, n = [], i = new Array();
291
- if (y && we.add(s), s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
291
+ if (y && ve.add(s), s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
292
292
  const r = s;
293
293
  for (const o of Object.keys(r.uniforms)) {
294
294
  const a = r.uniforms[o].value;
@@ -395,9 +395,9 @@ const D = class {
395
395
  }
396
396
  if (r || (r = D.lodInfos.get(i)), r) {
397
397
  if (e > 0) {
398
- let m = !1;
398
+ let x = !1;
399
399
  const L = Array.isArray(r.lods);
400
- if (L && e >= r.lods.length ? m = !0 : L || (m = !0), m)
400
+ if (L && e >= r.lods.length ? x = !0 : L || (x = !0), x)
401
401
  return this.lowresCache.get(i);
402
402
  }
403
403
  const d = Array.isArray(r.lods) ? (o = r.lods[e]) == null ? void 0 : o.path : r.lods;
@@ -407,15 +407,15 @@ const D = class {
407
407
  if (h.endsWith(".glb") || h.endsWith(".gltf")) {
408
408
  if (!r.guid)
409
409
  return console.warn("missing pointer for glb/gltf texture", r), null;
410
- const m = h + "_" + r.guid, L = this.previouslyLoaded.get(m);
410
+ const x = h + "_" + r.guid, L = this.previouslyLoaded.get(x);
411
411
  if (L !== void 0) {
412
- s && console.log(`LOD ${e} was already loading/loaded: ${m}`);
412
+ s && console.log(`LOD ${e} was already loading/loaded: ${x}`);
413
413
  let f = await L.catch((I) => (console.error(`Error loading LOD ${e} from ${h}
414
- `, I), null)), v = !1;
415
- if (f == null || (f instanceof j && t instanceof j ? (a = f.image) != null && a.data || (c = f.source) != null && c.data ? f = this.copySettings(t, f) : (v = !0, this.previouslyLoaded.delete(m)) : f instanceof he && t instanceof he && ((l = f.attributes.position) != null && l.array || (v = !0, this.previouslyLoaded.delete(m)))), !v)
414
+ `, I), null)), w = !1;
415
+ if (f == null || (f instanceof j && t instanceof j ? (a = f.image) != null && a.data || (c = f.source) != null && c.data ? f = this.copySettings(t, f) : (w = !0, this.previouslyLoaded.delete(x)) : f instanceof he && t instanceof he && ((l = f.attributes.position) != null && l.array || (w = !0, this.previouslyLoaded.delete(x)))), !w)
416
416
  return f;
417
417
  }
418
- const M = r, P = new Promise(async (f, v) => {
418
+ const M = r, P = new Promise(async (f, w) => {
419
419
  const I = new Oe();
420
420
  Re(I), y && (await new Promise((O) => setTimeout(O, 1e3)), s && console.warn("Start loading (delayed) " + h, M.guid));
421
421
  let k = h;
@@ -429,7 +429,7 @@ const D = class {
429
429
  return null;
430
430
  const G = T.parser;
431
431
  s && console.log("Loading finished " + h, M.guid);
432
- let w = 0;
432
+ let v = 0;
433
433
  if (T.parser.json.textures) {
434
434
  let O = !1;
435
435
  for (const u of T.parser.json.textures) {
@@ -440,15 +440,15 @@ const D = class {
440
440
  break;
441
441
  }
442
442
  }
443
- w++;
443
+ v++;
444
444
  }
445
445
  if (O) {
446
- let u = await G.getDependency("texture", w);
447
- return u && D.assignLODInformation(n.url, u, i, e, void 0, void 0), s && console.log('change "' + t.name + '" → "' + u.name + '"', h, w, u, m), t instanceof j && (u = this.copySettings(t, u)), u && (u.guid = M.guid), f(u);
446
+ let u = await G.getDependency("texture", v);
447
+ return u && D.assignLODInformation(n.url, u, i, e, void 0, void 0), s && console.log('change "' + t.name + '" → "' + u.name + '"', h, v, u, x), t instanceof j && (u = this.copySettings(t, u)), u && (u.guid = M.guid), f(u);
448
448
  } else
449
449
  y && console.warn("Could not find texture with guid", M.guid, T.parser.json);
450
450
  }
451
- if (w = 0, T.parser.json.meshes) {
451
+ if (v = 0, T.parser.json.meshes) {
452
452
  let O = !1;
453
453
  for (const u of T.parser.json.meshes) {
454
454
  if (u != null && u.extensions) {
@@ -458,11 +458,11 @@ const D = class {
458
458
  break;
459
459
  }
460
460
  }
461
- w++;
461
+ v++;
462
462
  }
463
463
  if (O) {
464
- const u = await G.getDependency("mesh", w), g = M;
465
- if (s && console.log(`Loaded Mesh "${u.name}"`, h, w, u, m), u.isMesh === !0) {
464
+ const u = await G.getDependency("mesh", v), g = M;
465
+ if (s && console.log(`Loaded Mesh "${u.name}"`, h, v, u, x), u.isMesh === !0) {
466
466
  const _ = u.geometry;
467
467
  return D.assignLODInformation(n.url, _, i, e, void 0, g.density), f(_);
468
468
  } else {
@@ -481,7 +481,7 @@ const D = class {
481
481
  }
482
482
  return f(null);
483
483
  });
484
- return this.previouslyLoaded.set(m, P), await P;
484
+ return this.previouslyLoaded.set(x, P), await P;
485
485
  } else if (t instanceof j) {
486
486
  s && console.log("Load texture from uri: " + h);
487
487
  const L = await new ze().loadAsync(h);
@@ -548,11 +548,11 @@ var Ge = (t, e, s) => {
548
548
  if (e.has(t))
549
549
  throw TypeError("Cannot add the same private member more than once");
550
550
  e instanceof WeakSet ? e.add(t) : e.set(t, s);
551
- }, N = (t, e, s, n) => (Ge(t, e, "write to private field"), n ? n.call(t, s) : e.set(t, s), s), E, z, ve, Q, re, de, V;
551
+ }, N = (t, e, s, n) => (Ge(t, e, "write to private field"), n ? n.call(t, s) : e.set(t, s), s), E, z, we, Q, re, de, V;
552
552
  const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:LODSManager"), xe = Symbol("Needle:LODState"), J = Symbol("Needle:CurrentLOD"), R = { mesh_lod: -1, texture_lod: -1 }, C = class {
553
553
  // readonly plugins: NEEDLE_progressive_plugin[] = [];
554
554
  constructor(t, e) {
555
- this.projectionScreenMatrix = new Se(), this.targetTriangleDensity = 2e5, this.updateInterval = "auto", K(this, E, 1), this.pause = !1, this.manual = !1, this._lodchangedlisteners = [], K(this, z, void 0), K(this, ve, new Ke()), K(this, Q, 0), K(this, re, 0), K(this, de, 0), K(this, V, 0), this._fpsBuffer = [60, 60, 60, 60, 60], this._sphere = new Ve(), this._tempBox = new be(), this._tempBox2 = new be(), this.tempMatrix = new Se(), this._tempWorldPosition = new F(), this._tempBoxSize = new F(), this._tempBox2Size = new F(), this.renderer = t, this.context = { ...e };
555
+ this.projectionScreenMatrix = new Se(), this.targetTriangleDensity = 2e5, this.updateInterval = "auto", K(this, E, 1), this.pause = !1, this.manual = !1, this._lodchangedlisteners = [], K(this, z, void 0), K(this, we, new Ke()), K(this, Q, 0), K(this, re, 0), K(this, de, 0), K(this, V, 0), this._fpsBuffer = [60, 60, 60, 60, 60], this._sphere = new Ve(), this._tempBox = new be(), this._tempBox2 = new be(), this.tempMatrix = new Se(), this._tempWorldPosition = new F(), this._tempBoxSize = new F(), this._tempBox2Size = new F(), this.renderer = t, this.context = { ...e };
556
556
  }
557
557
  /** @internal */
558
558
  static getObjectLODState(t) {
@@ -604,7 +604,7 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
604
604
  const e = this;
605
605
  Be(this.renderer), this.renderer.render = function(s, n) {
606
606
  const i = e.renderer.getRenderTarget();
607
- (i == null || "isXRRenderTarget" in i && i.isXRRenderTarget) && (t = 0, N(e, Q, p(e, Q) + 1), N(e, re, p(e, ve).getDelta()), N(e, de, p(e, de) + p(e, re)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / p(e, re)), N(e, V, e._fpsBuffer.reduce((o, a) => o + a) / e._fpsBuffer.length), B && p(e, Q) % 200 === 0 && console.log("FPS", Math.round(p(e, V)), "Interval:", p(e, E)));
607
+ (i == null || "isXRRenderTarget" in i && i.isXRRenderTarget) && (t = 0, N(e, Q, p(e, Q) + 1), N(e, re, p(e, we).getDelta()), N(e, de, p(e, de) + p(e, re)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / p(e, re)), N(e, V, e._fpsBuffer.reduce((o, a) => o + a) / e._fpsBuffer.length), B && p(e, Q) % 200 === 0 && console.log("FPS", Math.round(p(e, V)), "Interval:", p(e, E)));
608
608
  const r = t++;
609
609
  p(e, z).call(this, s, n), e.onAfterRender(s, n, r);
610
610
  };
@@ -654,8 +654,8 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
654
654
  }
655
655
  if (B === "color" && l.material && !l.object.progressive_debug_color) {
656
656
  l.object.progressive_debug_color = !0;
657
- const h = Math.random() * 16777215, m = new qe({ color: h });
658
- l.object.material = m;
657
+ const h = Math.random() * 16777215, x = new qe({ color: h });
658
+ l.object.material = x;
659
659
  }
660
660
  const d = l.object;
661
661
  (d instanceof H || d.isMesh) && this.updateLODs(t, e, d, i);
@@ -741,8 +741,8 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
741
741
  let o = 10 + 1, a = !1;
742
742
  if (B && e["DEBUG:LOD"] != null)
743
743
  return e["DEBUG:LOD"];
744
- const c = b.getMeshLODInformation(e.geometry), l = c == null ? void 0 : c.lods, d = l && l.length > 0, h = b.getMaterialMinMaxLODsCount(e.material), m = (h == null ? void 0 : h.min_count) != 1 / 0 && h.min_count > 0 && h.max_count > 0;
745
- if (!d && !m) {
744
+ const c = b.getMeshLODInformation(e.geometry), l = c == null ? void 0 : c.lods, d = l && l.length > 0, h = b.getMaterialMinMaxLODsCount(e.material), x = (h == null ? void 0 : h.min_count) != 1 / 0 && h.min_count > 0 && h.max_count > 0;
745
+ if (!d && !x) {
746
746
  i.mesh_lod = 0, i.texture_lod = 0;
747
747
  return;
748
748
  }
@@ -750,17 +750,17 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
750
750
  const L = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
751
751
  let M = e.geometry.boundingBox;
752
752
  if (e.type === "SkinnedMesh") {
753
- const x = e;
754
- if (!x.boundingBox)
755
- x.computeBoundingBox();
753
+ const m = e;
754
+ if (!m.boundingBox)
755
+ m.computeBoundingBox();
756
756
  else if (s.frames % 30 === 0) {
757
- const f = ae(x), v = x.geometry;
758
- f && (x.geometry = f), x.computeBoundingBox(), x.geometry = v;
757
+ const f = ae(m), w = m.geometry;
758
+ f && (m.geometry = f), m.computeBoundingBox(), m.geometry = w;
759
759
  }
760
- M = x.boundingBox;
760
+ M = m.boundingBox;
761
761
  }
762
- if (M && t.isPerspectiveCamera) {
763
- const x = t;
762
+ if (M) {
763
+ const m = t;
764
764
  if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
765
765
  this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
766
766
  const u = t.getWorldPosition(this._tempWorldPosition);
@@ -769,11 +769,11 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
769
769
  return;
770
770
  }
771
771
  }
772
- if (this._tempBox.copy(M), this._tempBox.applyMatrix4(e.matrixWorld), C.isInside(this._tempBox, this.projectionScreenMatrix)) {
772
+ if (this._tempBox.copy(M), this._tempBox.applyMatrix4(e.matrixWorld), m.isPerspectiveCamera && C.isInside(this._tempBox, this.projectionScreenMatrix)) {
773
773
  i.mesh_lod = 0, i.texture_lod = 0;
774
774
  return;
775
775
  }
776
- if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && x.fov > 70) {
776
+ if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && m.isPerspectiveCamera && m.fov > 70) {
777
777
  const u = this._tempBox.min, g = this._tempBox.max;
778
778
  let _ = u.x, S = u.y, A = g.x, W = g.y;
779
779
  const le = 2, pe = 1.5, ce = (u.x + g.x) * 0.5, ue = (u.y + g.y) * 0.5;
@@ -783,9 +783,9 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
783
783
  } else
784
784
  s.lastCentrality = 1;
785
785
  const f = this._tempBox.getSize(this._tempBoxSize);
786
- f.multiplyScalar(0.5), screen.availHeight > 0 && L > 0 && f.multiplyScalar(L / screen.availHeight), f.x *= x.aspect;
787
- const v = t.matrixWorldInverse, I = this._tempBox2;
788
- I.copy(M), I.applyMatrix4(e.matrixWorld), I.applyMatrix4(v);
786
+ f.multiplyScalar(0.5), screen.availHeight > 0 && L > 0 && f.multiplyScalar(L / screen.availHeight), t.isPerspectiveCamera ? f.x *= t.aspect : t.isOrthographicCamera;
787
+ const w = t.matrixWorldInverse, I = this._tempBox2;
788
+ I.copy(M), I.applyMatrix4(e.matrixWorld), I.applyMatrix4(w);
789
789
  const k = I.getSize(this._tempBox2Size), T = Math.max(k.x, k.y);
790
790
  if (Math.max(f.x, f.y) != 0 && T != 0 && (f.z = k.z / Math.max(k.x, k.y) * Math.max(f.x, f.y)), s.lastScreenCoverage = Math.max(f.x, f.y, f.z), s.lastScreenspaceVolume.copy(f), s.lastScreenCoverage *= s.lastCentrality, B && C.debugDrawLine) {
791
791
  const u = this.tempMatrix.copy(this.projectionScreenMatrix);
@@ -795,22 +795,22 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
795
795
  const W = (g.z + A.z) * 0.5;
796
796
  g.z = _.z = S.z = A.z = W, g.applyMatrix4(u), _.applyMatrix4(u), S.applyMatrix4(u), A.applyMatrix4(u), C.debugDrawLine(g, _, 255), C.debugDrawLine(g, S, 255), C.debugDrawLine(_, A, 255), C.debugDrawLine(S, A, 255);
797
797
  }
798
- let w = 999;
798
+ let v = 999;
799
799
  if (l && s.lastScreenCoverage > 0) {
800
800
  for (let u = 0; u < l.length; u++)
801
801
  if (l[u].density / s.lastScreenCoverage < n) {
802
- w = u;
802
+ v = u;
803
803
  break;
804
804
  }
805
805
  }
806
- w < o && (o = w, a = !0);
806
+ v < o && (o = v, a = !0);
807
807
  }
808
808
  if (a ? i.mesh_lod = o : i.mesh_lod = s.lastLodLevel_Mesh, B && i.mesh_lod != s.lastLodLevel_Mesh) {
809
809
  const f = l == null ? void 0 : l[i.mesh_lod];
810
810
  f && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${i.mesh_lod} (${f.density.toFixed(0)}) - ${e.name}`);
811
811
  }
812
- if (m) {
813
- const x = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
812
+ if (x) {
813
+ const m = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
814
814
  if (s.lastLodLevel_Texture < 0) {
815
815
  if (i.texture_lod = h.max_count - 1, B) {
816
816
  const f = h.lods[h.max_count - 1];
@@ -818,15 +818,15 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
818
818
  }
819
819
  } else {
820
820
  const f = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
821
- let v = s.lastScreenCoverage * 4;
822
- ((P = this.context) == null ? void 0 : P.engine) === "model-viewer" && (v *= 1.5);
823
- const k = L / window.devicePixelRatio * v;
821
+ let w = s.lastScreenCoverage * 4;
822
+ ((P = this.context) == null ? void 0 : P.engine) === "model-viewer" && (w *= 1.5);
823
+ const k = L / window.devicePixelRatio * w;
824
824
  let T = !1;
825
825
  for (let G = h.lods.length - 1; G >= 0; G--) {
826
- let w = h.lods[G];
827
- if (!(x && w.max_height >= 2048) && !(tt() && w.max_height > 4096) && (w.max_height > k || !T && G === 0)) {
826
+ let v = h.lods[G];
827
+ if (!(m && v.max_height >= 2048) && !(tt() && v.max_height > 4096) && (v.max_height > k || !T && G === 0)) {
828
828
  if (T = !0, i.texture_lod = G, i.texture_lod < s.lastLodLevel_Texture) {
829
- const O = w.max_height;
829
+ const O = v.max_height;
830
830
  B && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${i.texture_lod} = ${O}px
831
831
  Screensize: ${k.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${f.toFixed(1)}
832
832
  ${e.name}`);
@@ -842,7 +842,7 @@ ${e.name}`);
842
842
  let U = C;
843
843
  E = /* @__PURE__ */ new WeakMap();
844
844
  z = /* @__PURE__ */ new WeakMap();
845
- ve = /* @__PURE__ */ new WeakMap();
845
+ we = /* @__PURE__ */ new WeakMap();
846
846
  Q = /* @__PURE__ */ new WeakMap();
847
847
  re = /* @__PURE__ */ new WeakMap();
848
848
  de = /* @__PURE__ */ new WeakMap();
@@ -950,7 +950,7 @@ class ft {
950
950
  const n = this.tryGetCurrentGLTF(e), i = this.tryGetCurrentModelViewer(e), r = this.getUrl(i);
951
951
  if (r && n && s.material) {
952
952
  let o = function(c) {
953
- var d, h, m;
953
+ var d, h, x;
954
954
  if (c[fe] == !0)
955
955
  return;
956
956
  c[fe] = !0, c.userData && (c.userData.LOD = -1);
@@ -958,17 +958,17 @@ class ft {
958
958
  for (let L = 0; L < l.length; L++) {
959
959
  const M = l[L], P = c[M];
960
960
  if ((P == null ? void 0 : P.isTexture) === !0) {
961
- const x = (h = (d = P.userData) == null ? void 0 : d.associations) == null ? void 0 : h.textures;
962
- if (x == null)
961
+ const m = (h = (d = P.userData) == null ? void 0 : d.associations) == null ? void 0 : h.textures;
962
+ if (m == null)
963
963
  continue;
964
- const f = n.parser.json.textures[x];
964
+ const f = n.parser.json.textures[m];
965
965
  if (!f) {
966
- console.warn("Texture data not found for texture index " + x);
966
+ console.warn("Texture data not found for texture index " + m);
967
967
  continue;
968
968
  }
969
- if ((m = f == null ? void 0 : f.extensions) != null && m[$]) {
970
- const v = f.extensions[$];
971
- v && r && b.registerTexture(r, P, v.lods.length, x, v);
969
+ if ((x = f == null ? void 0 : f.extensions) != null && x[$]) {
970
+ const w = f.extensions[$];
971
+ w && r && b.registerTexture(r, P, w.lods.length, m, w);
972
972
  }
973
973
  }
974
974
  }
@@ -104,7 +104,7 @@ function nt(t) {
104
104
  e.setAttribute(s, t.getAttribute(s));
105
105
  return e.setIndex(t.getIndex()), e;
106
106
  }
107
- const q = new Array(), $ = "NEEDLE_progressive", y = oe("debugprogressive"), _e = Symbol("needle-progressive-texture"), ie = /* @__PURE__ */ new Map(), we = /* @__PURE__ */ new Set();
107
+ const q = new Array(), $ = "NEEDLE_progressive", y = oe("debugprogressive"), _e = Symbol("needle-progressive-texture"), ie = /* @__PURE__ */ new Map(), ve = /* @__PURE__ */ new Set();
108
108
  if (y) {
109
109
  let t = function() {
110
110
  e += 1, console.log("Toggle LOD level", e, ie), ie.forEach((i, r) => {
@@ -123,7 +123,7 @@ if (y) {
123
123
  }), e >= s && (e = -1);
124
124
  }, e = -1, s = 2, n = !1;
125
125
  window.addEventListener("keyup", (i) => {
126
- i.key === "p" && t(), i.key === "w" && (n = !n, we && we.forEach((r) => {
126
+ i.key === "p" && t(), i.key === "w" && (n = !n, ve && ve.forEach((r) => {
127
127
  r.name != "BackgroundCubeMaterial" && r.glyphMap == null && "wireframe" in r && (r.wireframe = n);
128
128
  }));
129
129
  });
@@ -288,7 +288,7 @@ const D = class {
288
288
  }
289
289
  if (t instanceof We || t.isMaterial === !0) {
290
290
  const s = t, n = [], i = new Array();
291
- if (y && we.add(s), s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
291
+ if (y && ve.add(s), s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
292
292
  const r = s;
293
293
  for (const o of Object.keys(r.uniforms)) {
294
294
  const a = r.uniforms[o].value;
@@ -395,9 +395,9 @@ const D = class {
395
395
  }
396
396
  if (r || (r = D.lodInfos.get(i)), r) {
397
397
  if (e > 0) {
398
- let m = !1;
398
+ let x = !1;
399
399
  const L = Array.isArray(r.lods);
400
- if (L && e >= r.lods.length ? m = !0 : L || (m = !0), m)
400
+ if (L && e >= r.lods.length ? x = !0 : L || (x = !0), x)
401
401
  return this.lowresCache.get(i);
402
402
  }
403
403
  const d = Array.isArray(r.lods) ? (o = r.lods[e]) == null ? void 0 : o.path : r.lods;
@@ -407,15 +407,15 @@ const D = class {
407
407
  if (h.endsWith(".glb") || h.endsWith(".gltf")) {
408
408
  if (!r.guid)
409
409
  return console.warn("missing pointer for glb/gltf texture", r), null;
410
- const m = h + "_" + r.guid, L = this.previouslyLoaded.get(m);
410
+ const x = h + "_" + r.guid, L = this.previouslyLoaded.get(x);
411
411
  if (L !== void 0) {
412
- s && console.log(`LOD ${e} was already loading/loaded: ${m}`);
412
+ s && console.log(`LOD ${e} was already loading/loaded: ${x}`);
413
413
  let f = await L.catch((I) => (console.error(`Error loading LOD ${e} from ${h}
414
- `, I), null)), v = !1;
415
- if (f == null || (f instanceof j && t instanceof j ? (a = f.image) != null && a.data || (c = f.source) != null && c.data ? f = this.copySettings(t, f) : (v = !0, this.previouslyLoaded.delete(m)) : f instanceof he && t instanceof he && ((l = f.attributes.position) != null && l.array || (v = !0, this.previouslyLoaded.delete(m)))), !v)
414
+ `, I), null)), w = !1;
415
+ if (f == null || (f instanceof j && t instanceof j ? (a = f.image) != null && a.data || (c = f.source) != null && c.data ? f = this.copySettings(t, f) : (w = !0, this.previouslyLoaded.delete(x)) : f instanceof he && t instanceof he && ((l = f.attributes.position) != null && l.array || (w = !0, this.previouslyLoaded.delete(x)))), !w)
416
416
  return f;
417
417
  }
418
- const M = r, P = new Promise(async (f, v) => {
418
+ const M = r, P = new Promise(async (f, w) => {
419
419
  const I = new Oe();
420
420
  Re(I), y && (await new Promise((O) => setTimeout(O, 1e3)), s && console.warn("Start loading (delayed) " + h, M.guid));
421
421
  let k = h;
@@ -429,7 +429,7 @@ const D = class {
429
429
  return null;
430
430
  const G = T.parser;
431
431
  s && console.log("Loading finished " + h, M.guid);
432
- let w = 0;
432
+ let v = 0;
433
433
  if (T.parser.json.textures) {
434
434
  let O = !1;
435
435
  for (const u of T.parser.json.textures) {
@@ -440,15 +440,15 @@ const D = class {
440
440
  break;
441
441
  }
442
442
  }
443
- w++;
443
+ v++;
444
444
  }
445
445
  if (O) {
446
- let u = await G.getDependency("texture", w);
447
- return u && D.assignLODInformation(n.url, u, i, e, void 0, void 0), s && console.log('change "' + t.name + '" → "' + u.name + '"', h, w, u, m), t instanceof j && (u = this.copySettings(t, u)), u && (u.guid = M.guid), f(u);
446
+ let u = await G.getDependency("texture", v);
447
+ return u && D.assignLODInformation(n.url, u, i, e, void 0, void 0), s && console.log('change "' + t.name + '" → "' + u.name + '"', h, v, u, x), t instanceof j && (u = this.copySettings(t, u)), u && (u.guid = M.guid), f(u);
448
448
  } else
449
449
  y && console.warn("Could not find texture with guid", M.guid, T.parser.json);
450
450
  }
451
- if (w = 0, T.parser.json.meshes) {
451
+ if (v = 0, T.parser.json.meshes) {
452
452
  let O = !1;
453
453
  for (const u of T.parser.json.meshes) {
454
454
  if (u != null && u.extensions) {
@@ -458,11 +458,11 @@ const D = class {
458
458
  break;
459
459
  }
460
460
  }
461
- w++;
461
+ v++;
462
462
  }
463
463
  if (O) {
464
- const u = await G.getDependency("mesh", w), g = M;
465
- if (s && console.log(`Loaded Mesh "${u.name}"`, h, w, u, m), u.isMesh === !0) {
464
+ const u = await G.getDependency("mesh", v), g = M;
465
+ if (s && console.log(`Loaded Mesh "${u.name}"`, h, v, u, x), u.isMesh === !0) {
466
466
  const _ = u.geometry;
467
467
  return D.assignLODInformation(n.url, _, i, e, void 0, g.density), f(_);
468
468
  } else {
@@ -481,7 +481,7 @@ const D = class {
481
481
  }
482
482
  return f(null);
483
483
  });
484
- return this.previouslyLoaded.set(m, P), await P;
484
+ return this.previouslyLoaded.set(x, P), await P;
485
485
  } else if (t instanceof j) {
486
486
  s && console.log("Load texture from uri: " + h);
487
487
  const L = await new ze().loadAsync(h);
@@ -548,11 +548,11 @@ var Ge = (t, e, s) => {
548
548
  if (e.has(t))
549
549
  throw TypeError("Cannot add the same private member more than once");
550
550
  e instanceof WeakSet ? e.add(t) : e.set(t, s);
551
- }, N = (t, e, s, n) => (Ge(t, e, "write to private field"), n ? n.call(t, s) : e.set(t, s), s), E, z, ve, Q, re, de, V;
551
+ }, N = (t, e, s, n) => (Ge(t, e, "write to private field"), n ? n.call(t, s) : e.set(t, s), s), E, z, we, Q, re, de, V;
552
552
  const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:LODSManager"), xe = Symbol("Needle:LODState"), J = Symbol("Needle:CurrentLOD"), R = { mesh_lod: -1, texture_lod: -1 }, C = class {
553
553
  // readonly plugins: NEEDLE_progressive_plugin[] = [];
554
554
  constructor(t, e) {
555
- this.projectionScreenMatrix = new Se(), this.targetTriangleDensity = 2e5, this.updateInterval = "auto", K(this, E, 1), this.pause = !1, this.manual = !1, this._lodchangedlisteners = [], K(this, z, void 0), K(this, ve, new Ke()), K(this, Q, 0), K(this, re, 0), K(this, de, 0), K(this, V, 0), this._fpsBuffer = [60, 60, 60, 60, 60], this._sphere = new Ve(), this._tempBox = new be(), this._tempBox2 = new be(), this.tempMatrix = new Se(), this._tempWorldPosition = new F(), this._tempBoxSize = new F(), this._tempBox2Size = new F(), this.renderer = t, this.context = { ...e };
555
+ this.projectionScreenMatrix = new Se(), this.targetTriangleDensity = 2e5, this.updateInterval = "auto", K(this, E, 1), this.pause = !1, this.manual = !1, this._lodchangedlisteners = [], K(this, z, void 0), K(this, we, new Ke()), K(this, Q, 0), K(this, re, 0), K(this, de, 0), K(this, V, 0), this._fpsBuffer = [60, 60, 60, 60, 60], this._sphere = new Ve(), this._tempBox = new be(), this._tempBox2 = new be(), this.tempMatrix = new Se(), this._tempWorldPosition = new F(), this._tempBoxSize = new F(), this._tempBox2Size = new F(), this.renderer = t, this.context = { ...e };
556
556
  }
557
557
  /** @internal */
558
558
  static getObjectLODState(t) {
@@ -604,7 +604,7 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
604
604
  const e = this;
605
605
  Be(this.renderer), this.renderer.render = function(s, n) {
606
606
  const i = e.renderer.getRenderTarget();
607
- (i == null || "isXRRenderTarget" in i && i.isXRRenderTarget) && (t = 0, N(e, Q, p(e, Q) + 1), N(e, re, p(e, ve).getDelta()), N(e, de, p(e, de) + p(e, re)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / p(e, re)), N(e, V, e._fpsBuffer.reduce((o, a) => o + a) / e._fpsBuffer.length), B && p(e, Q) % 200 === 0 && console.log("FPS", Math.round(p(e, V)), "Interval:", p(e, E)));
607
+ (i == null || "isXRRenderTarget" in i && i.isXRRenderTarget) && (t = 0, N(e, Q, p(e, Q) + 1), N(e, re, p(e, we).getDelta()), N(e, de, p(e, de) + p(e, re)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / p(e, re)), N(e, V, e._fpsBuffer.reduce((o, a) => o + a) / e._fpsBuffer.length), B && p(e, Q) % 200 === 0 && console.log("FPS", Math.round(p(e, V)), "Interval:", p(e, E)));
608
608
  const r = t++;
609
609
  p(e, z).call(this, s, n), e.onAfterRender(s, n, r);
610
610
  };
@@ -654,8 +654,8 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
654
654
  }
655
655
  if (B === "color" && l.material && !l.object.progressive_debug_color) {
656
656
  l.object.progressive_debug_color = !0;
657
- const h = Math.random() * 16777215, m = new qe({ color: h });
658
- l.object.material = m;
657
+ const h = Math.random() * 16777215, x = new qe({ color: h });
658
+ l.object.material = x;
659
659
  }
660
660
  const d = l.object;
661
661
  (d instanceof H || d.isMesh) && this.updateLODs(t, e, d, i);
@@ -741,8 +741,8 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
741
741
  let o = 10 + 1, a = !1;
742
742
  if (B && e["DEBUG:LOD"] != null)
743
743
  return e["DEBUG:LOD"];
744
- const c = b.getMeshLODInformation(e.geometry), l = c == null ? void 0 : c.lods, d = l && l.length > 0, h = b.getMaterialMinMaxLODsCount(e.material), m = (h == null ? void 0 : h.min_count) != 1 / 0 && h.min_count > 0 && h.max_count > 0;
745
- if (!d && !m) {
744
+ const c = b.getMeshLODInformation(e.geometry), l = c == null ? void 0 : c.lods, d = l && l.length > 0, h = b.getMaterialMinMaxLODsCount(e.material), x = (h == null ? void 0 : h.min_count) != 1 / 0 && h.min_count > 0 && h.max_count > 0;
745
+ if (!d && !x) {
746
746
  i.mesh_lod = 0, i.texture_lod = 0;
747
747
  return;
748
748
  }
@@ -750,17 +750,17 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
750
750
  const L = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
751
751
  let M = e.geometry.boundingBox;
752
752
  if (e.type === "SkinnedMesh") {
753
- const x = e;
754
- if (!x.boundingBox)
755
- x.computeBoundingBox();
753
+ const m = e;
754
+ if (!m.boundingBox)
755
+ m.computeBoundingBox();
756
756
  else if (s.frames % 30 === 0) {
757
- const f = ae(x), v = x.geometry;
758
- f && (x.geometry = f), x.computeBoundingBox(), x.geometry = v;
757
+ const f = ae(m), w = m.geometry;
758
+ f && (m.geometry = f), m.computeBoundingBox(), m.geometry = w;
759
759
  }
760
- M = x.boundingBox;
760
+ M = m.boundingBox;
761
761
  }
762
- if (M && t.isPerspectiveCamera) {
763
- const x = t;
762
+ if (M) {
763
+ const m = t;
764
764
  if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
765
765
  this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
766
766
  const u = t.getWorldPosition(this._tempWorldPosition);
@@ -769,11 +769,11 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
769
769
  return;
770
770
  }
771
771
  }
772
- if (this._tempBox.copy(M), this._tempBox.applyMatrix4(e.matrixWorld), C.isInside(this._tempBox, this.projectionScreenMatrix)) {
772
+ if (this._tempBox.copy(M), this._tempBox.applyMatrix4(e.matrixWorld), m.isPerspectiveCamera && C.isInside(this._tempBox, this.projectionScreenMatrix)) {
773
773
  i.mesh_lod = 0, i.texture_lod = 0;
774
774
  return;
775
775
  }
776
- if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && x.fov > 70) {
776
+ if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && m.isPerspectiveCamera && m.fov > 70) {
777
777
  const u = this._tempBox.min, g = this._tempBox.max;
778
778
  let _ = u.x, S = u.y, A = g.x, W = g.y;
779
779
  const le = 2, pe = 1.5, ce = (u.x + g.x) * 0.5, ue = (u.y + g.y) * 0.5;
@@ -783,9 +783,9 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
783
783
  } else
784
784
  s.lastCentrality = 1;
785
785
  const f = this._tempBox.getSize(this._tempBoxSize);
786
- f.multiplyScalar(0.5), screen.availHeight > 0 && L > 0 && f.multiplyScalar(L / screen.availHeight), f.x *= x.aspect;
787
- const v = t.matrixWorldInverse, I = this._tempBox2;
788
- I.copy(M), I.applyMatrix4(e.matrixWorld), I.applyMatrix4(v);
786
+ f.multiplyScalar(0.5), screen.availHeight > 0 && L > 0 && f.multiplyScalar(L / screen.availHeight), t.isPerspectiveCamera ? f.x *= t.aspect : t.isOrthographicCamera;
787
+ const w = t.matrixWorldInverse, I = this._tempBox2;
788
+ I.copy(M), I.applyMatrix4(e.matrixWorld), I.applyMatrix4(w);
789
789
  const k = I.getSize(this._tempBox2Size), T = Math.max(k.x, k.y);
790
790
  if (Math.max(f.x, f.y) != 0 && T != 0 && (f.z = k.z / Math.max(k.x, k.y) * Math.max(f.x, f.y)), s.lastScreenCoverage = Math.max(f.x, f.y, f.z), s.lastScreenspaceVolume.copy(f), s.lastScreenCoverage *= s.lastCentrality, B && C.debugDrawLine) {
791
791
  const u = this.tempMatrix.copy(this.projectionScreenMatrix);
@@ -795,22 +795,22 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
795
795
  const W = (g.z + A.z) * 0.5;
796
796
  g.z = _.z = S.z = A.z = W, g.applyMatrix4(u), _.applyMatrix4(u), S.applyMatrix4(u), A.applyMatrix4(u), C.debugDrawLine(g, _, 255), C.debugDrawLine(g, S, 255), C.debugDrawLine(_, A, 255), C.debugDrawLine(S, A, 255);
797
797
  }
798
- let w = 999;
798
+ let v = 999;
799
799
  if (l && s.lastScreenCoverage > 0) {
800
800
  for (let u = 0; u < l.length; u++)
801
801
  if (l[u].density / s.lastScreenCoverage < n) {
802
- w = u;
802
+ v = u;
803
803
  break;
804
804
  }
805
805
  }
806
- w < o && (o = w, a = !0);
806
+ v < o && (o = v, a = !0);
807
807
  }
808
808
  if (a ? i.mesh_lod = o : i.mesh_lod = s.lastLodLevel_Mesh, B && i.mesh_lod != s.lastLodLevel_Mesh) {
809
809
  const f = l == null ? void 0 : l[i.mesh_lod];
810
810
  f && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${i.mesh_lod} (${f.density.toFixed(0)}) - ${e.name}`);
811
811
  }
812
- if (m) {
813
- const x = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
812
+ if (x) {
813
+ const m = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
814
814
  if (s.lastLodLevel_Texture < 0) {
815
815
  if (i.texture_lod = h.max_count - 1, B) {
816
816
  const f = h.lods[h.max_count - 1];
@@ -818,15 +818,15 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
818
818
  }
819
819
  } else {
820
820
  const f = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
821
- let v = s.lastScreenCoverage * 4;
822
- ((P = this.context) == null ? void 0 : P.engine) === "model-viewer" && (v *= 1.5);
823
- const k = L / window.devicePixelRatio * v;
821
+ let w = s.lastScreenCoverage * 4;
822
+ ((P = this.context) == null ? void 0 : P.engine) === "model-viewer" && (w *= 1.5);
823
+ const k = L / window.devicePixelRatio * w;
824
824
  let T = !1;
825
825
  for (let G = h.lods.length - 1; G >= 0; G--) {
826
- let w = h.lods[G];
827
- if (!(x && w.max_height >= 2048) && !(tt() && w.max_height > 4096) && (w.max_height > k || !T && G === 0)) {
826
+ let v = h.lods[G];
827
+ if (!(m && v.max_height >= 2048) && !(tt() && v.max_height > 4096) && (v.max_height > k || !T && G === 0)) {
828
828
  if (T = !0, i.texture_lod = G, i.texture_lod < s.lastLodLevel_Texture) {
829
- const O = w.max_height;
829
+ const O = v.max_height;
830
830
  B && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${i.texture_lod} = ${O}px
831
831
  Screensize: ${k.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${f.toFixed(1)}
832
832
  ${e.name}`);
@@ -842,7 +842,7 @@ ${e.name}`);
842
842
  let U = C;
843
843
  E = /* @__PURE__ */ new WeakMap();
844
844
  z = /* @__PURE__ */ new WeakMap();
845
- ve = /* @__PURE__ */ new WeakMap();
845
+ we = /* @__PURE__ */ new WeakMap();
846
846
  Q = /* @__PURE__ */ new WeakMap();
847
847
  re = /* @__PURE__ */ new WeakMap();
848
848
  de = /* @__PURE__ */ new WeakMap();
@@ -950,7 +950,7 @@ class ft {
950
950
  const n = this.tryGetCurrentGLTF(e), i = this.tryGetCurrentModelViewer(e), r = this.getUrl(i);
951
951
  if (r && n && s.material) {
952
952
  let o = function(c) {
953
- var d, h, m;
953
+ var d, h, x;
954
954
  if (c[fe] == !0)
955
955
  return;
956
956
  c[fe] = !0, c.userData && (c.userData.LOD = -1);
@@ -958,17 +958,17 @@ class ft {
958
958
  for (let L = 0; L < l.length; L++) {
959
959
  const M = l[L], P = c[M];
960
960
  if ((P == null ? void 0 : P.isTexture) === !0) {
961
- const x = (h = (d = P.userData) == null ? void 0 : d.associations) == null ? void 0 : h.textures;
962
- if (x == null)
961
+ const m = (h = (d = P.userData) == null ? void 0 : d.associations) == null ? void 0 : h.textures;
962
+ if (m == null)
963
963
  continue;
964
- const f = n.parser.json.textures[x];
964
+ const f = n.parser.json.textures[m];
965
965
  if (!f) {
966
- console.warn("Texture data not found for texture index " + x);
966
+ console.warn("Texture data not found for texture index " + m);
967
967
  continue;
968
968
  }
969
- if ((m = f == null ? void 0 : f.extensions) != null && m[$]) {
970
- const v = f.extensions[$];
971
- v && r && b.registerTexture(r, P, v.lods.length, x, v);
969
+ if ((x = f == null ? void 0 : f.extensions) != null && x[$]) {
970
+ const w = f.extensions[$];
971
+ w && r && b.registerTexture(r, P, w.lods.length, m, w);
972
972
  }
973
973
  }
974
974
  }