phoria2 1.0.0 → 1.1.0

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.
Files changed (46) hide show
  1. package/README.md +6 -6
  2. package/dist/bloom.js +4 -4
  3. package/dist/bloom.js.map +1 -1
  4. package/dist/charts.js +377 -377
  5. package/dist/charts.js.map +1 -1
  6. package/dist/core.js +1052 -558
  7. package/dist/core.js.map +1 -1
  8. package/dist/edit.js +48 -48
  9. package/dist/edit.js.map +1 -1
  10. package/dist/explain.js +1 -1
  11. package/dist/gltf.js +207 -162
  12. package/dist/gltf.js.map +1 -1
  13. package/dist/motion.js +27 -27
  14. package/dist/motion.js.map +1 -1
  15. package/dist/particles.js +50 -50
  16. package/dist/particles.js.map +1 -1
  17. package/dist/passes.js +199 -97
  18. package/dist/passes.js.map +1 -1
  19. package/dist/phoria2.js +1 -1
  20. package/dist/picking.js +16 -21
  21. package/dist/picking.js.map +1 -1
  22. package/dist/snapshot.js +1 -1
  23. package/dist/tooltip.js +3 -3
  24. package/dist/tooltip.js.map +1 -1
  25. package/dist/types/View.d.ts +5 -0
  26. package/dist/types/geometry/Geometry.d.ts +6 -0
  27. package/dist/types/material/Material.d.ts +125 -0
  28. package/dist/types/material/Texture.d.ts +37 -5
  29. package/dist/types/webgl/WebGLRenderer.d.ts +6 -0
  30. package/dist/types/webgl/passes.d.ts +37 -13
  31. package/dist/types/webgl/resources.d.ts +24 -2
  32. package/dist/types/webgl/shaders.d.ts +4 -2
  33. package/llms-full.txt +96 -7
  34. package/package.json +1 -1
  35. package/schema/scene.schema.json +127 -0
  36. package/src/View.js +4 -2
  37. package/src/geometry/Geometry.js +8 -1
  38. package/src/gltf/load.js +50 -6
  39. package/src/material/Material.js +104 -19
  40. package/src/material/Texture.js +116 -11
  41. package/src/watch.js +19 -0
  42. package/src/webgl/WebGLRenderer.js +51 -12
  43. package/src/webgl/passes.js +190 -32
  44. package/src/webgl/picking.js +0 -1
  45. package/src/webgl/resources.js +89 -8
  46. package/src/webgl/shaders.js +350 -48
package/dist/core.js CHANGED
@@ -2704,11 +2704,11 @@ var Xt = /* @__PURE__ */ new Float32Array(16), Zt = /* @__PURE__ */ new Float32A
2704
2704
  }
2705
2705
  #d(e) {
2706
2706
  let t = e.geometry, n = e.material;
2707
- this.#o(J(t)), this.#o(t.version), this.#o(t.drawCount ?? -1), this.#o(e.renderOrder), this.#o(+!!e.castShadow | (e.receiveShadow ? 2 : 0)), this.#o(e.labels ? J(e.labels) : 0), this.#o(e.data && typeof e.data == "object" ? J(e.data) : 0), "instanceMatrices" in e && (this.#o(e.count), this.#o(e.version)), this.#o(J(n)), this.#s(n.color), this.#s(n.emissive), this.#o(n.emissiveIntensity), this.#o(n.opacity), this.#o(n.roughness), this.#o(n.metalness), this.#o(n.size), this.#o(n.width), this.#o(n.alphaTest), this.#o(n.normalScale), this.#o(n.aoMapIntensity), this.#o(n.triplanar), this.#o(n.bumpScale), this.#o(+!!n.unlit | (n.flatShading ? 2 : 0) | (n.doubleSided ? 4 : 0) | (n.vertexColors ? 8 : 0) | (n.depthWrite ? 16 : 0) | (n.depthTest ? 32 : 0) | (n.sizeAttenuation ? 64 : 0) | (n.blending === "additive" ? 128 : n.blending === "multiply" ? 1024 : 0) | (n.transparent ? 256 : 0) | (n.fog ? 512 : 0));
2707
+ this.#o(J(t)), this.#o(t.version), this.#o(t.drawCount ?? -1), this.#o(e.renderOrder), this.#o(+!!e.castShadow | (e.receiveShadow ? 2 : 0)), this.#o(e.labels ? J(e.labels) : 0), this.#o(e.data && typeof e.data == "object" ? J(e.data) : 0), "instanceMatrices" in e && (this.#o(e.count), this.#o(e.version)), this.#o(J(n)), this.#s(n.color), this.#s(n.emissive), this.#o(n.emissiveIntensity), this.#o(n.opacity), this.#o(n.roughness), this.#o(n.metalness), this.#o(n.size), this.#o(n.width), this.#o(n.alphaTest), this.#o(n.normalScale), this.#o(n.aoMapIntensity), this.#o(n.triplanar), this.#o(n.bumpScale), this.#o(n.transmission), this.#o(n.clearcoat), this.#o(n.clearcoatRoughness), this.#o(n.sheen), this.#s(n.sheenColor), this.#o(n.sheenRoughness), this.#o(n.ior), this.#o(n.specularIntensity), this.#s(n.specularColor), this.#o(n.anisotropy), this.#o(n.anisotropyRotation), this.#o(n.translucency), this.#o(n.toon), this.#o(n.lightMapIntensity), this.#o(n.environmentIntensity), this.#s(n.translucencyColor), this.#o(+!!n.unlit | (n.flatShading ? 2 : 0) | (n.doubleSided ? 4 : 0) | (n.vertexColors ? 8 : 0) | (n.depthWrite ? 16 : 0) | (n.depthTest ? 32 : 0) | (n.sizeAttenuation ? 64 : 0) | (n.blending === "additive" ? 128 : n.blending === "multiply" ? 1024 : 0) | (n.transparent ? 256 : 0) | (n.fog ? 512 : 0));
2708
2708
  for (let [, e] of n.textures) this.#f(e);
2709
2709
  }
2710
2710
  #f(e) {
2711
- this.#o(J(e)), this.#o(e.version), this.#s(e.repeat), this.#s(e.offset);
2711
+ this.#o(J(e)), this.#o(e.version), this.#s(e.repeat), this.#o(e.rotation), this.#s(e.center), this.#o(e.uvSet), this.#s(e.offset);
2712
2712
  }
2713
2713
  #p(e) {
2714
2714
  this.#i.push(e.text, e.className, e.place, e.overlap, e.edge ?? ""), this.#s(e.offset), this.#o(e.priority), this.#o(+!!e.occlude), this.#o(+!!e.leader);
@@ -2723,6 +2723,9 @@ var Xt = /* @__PURE__ */ new Float32Array(16), Zt = /* @__PURE__ */ new Float32A
2723
2723
  "wrap",
2724
2724
  "repeat",
2725
2725
  "offset",
2726
+ "rotation",
2727
+ "center",
2728
+ "uvSet",
2726
2729
  "filter",
2727
2730
  "mipmaps",
2728
2731
  "anisotropy",
@@ -2732,6 +2735,9 @@ var Xt = /* @__PURE__ */ new Float32Array(16), Zt = /* @__PURE__ */ new Float32A
2732
2735
  wrap: "repeat",
2733
2736
  repeat: [1, 1],
2734
2737
  offset: [0, 0],
2738
+ rotation: 0,
2739
+ center: [0, 0],
2740
+ uvSet: 0,
2735
2741
  filter: "linear",
2736
2742
  mipmaps: !0,
2737
2743
  anisotropy: 8,
@@ -2740,53 +2746,82 @@ var Xt = /* @__PURE__ */ new Float32Array(16), Zt = /* @__PURE__ */ new Float32A
2740
2746
  src: "use 'url' for the image address",
2741
2747
  encoding: "use colorSpace: 'srgb' | 'linear'",
2742
2748
  wrapS: "use wrap: 'repeat' | 'clamp' | 'mirror' (applies to both directions)",
2743
- maxAnisotropy: "use 'anisotropy' - samples along glancing angles, 1 for off"
2749
+ maxAnisotropy: "use 'anisotropy' - samples along glancing angles, 1 for off",
2750
+ channel: "use 'uvSet' - 0 for the first UV set, 1 for the second",
2751
+ texCoord: "use 'uvSet' - 0 for the first UV set, 1 for the second",
2752
+ scale: "use 'repeat' - [u, v] times across"
2744
2753
  }, Y = class {
2745
2754
  static OPTIONS = on;
2746
2755
  static HINTS = cn;
2747
- image = null;
2756
+ #e = null;
2748
2757
  url = null;
2749
- #e = "srgb";
2750
- #t = !1;
2758
+ #t = "srgb";
2759
+ #n = !1;
2751
2760
  wrap = "repeat";
2752
2761
  repeat = [1, 1];
2753
2762
  offset = [0, 0];
2763
+ rotation = 0;
2764
+ center = [0, 0];
2765
+ uvSet = 0;
2754
2766
  filter = "linear";
2755
2767
  mipmaps = !0;
2756
2768
  anisotropy = 8;
2757
2769
  flipY = !1;
2758
2770
  version = 0;
2759
2771
  ready;
2760
- #n = /* @__PURE__ */ new Set();
2772
+ #r = /* @__PURE__ */ new Set();
2761
2773
  constructor(e = {}) {
2762
2774
  typeof e == "string" && (e = { url: e }), A("Texture", e, on, cn);
2763
2775
  let t = {
2764
2776
  ...sn,
2765
2777
  ...e
2766
2778
  };
2767
- this.#e = P("Texture", "colorSpace", t.colorSpace, ["srgb", "linear"]), this.#t = e.colorSpace !== void 0, this.wrap = P("Texture", "wrap", t.wrap, [
2779
+ this.#t = P("Texture", "colorSpace", t.colorSpace, ["srgb", "linear"]), this.#n = e.colorSpace !== void 0, this.wrap = P("Texture", "wrap", t.wrap, [
2768
2780
  "repeat",
2769
2781
  "clamp",
2770
2782
  "mirror"
2771
- ]), this.filter = P("Texture", "filter", t.filter, ["linear", "nearest"]), this.repeat = un("repeat", t.repeat), this.offset = un("offset", t.offset), this.mipmaps = !!t.mipmaps, this.anisotropy = M("Texture", "anisotropy", t.anisotropy), this.anisotropy >= 1 || E("Texture", `'anisotropy' is how many samples along a glancing angle - 1 (off) or more, got ${this.anisotropy}`), this.flipY = !!t.flipY, this.url = t.url ?? null, t.image ? (this.image = t.image, this.ready = Promise.resolve(this)) : this.url ? (this.ready = this.#r(this.url), this.ready.catch(() => {})) : E("Texture", "needs an 'image' or a 'url'");
2783
+ ]), this.filter = P("Texture", "filter", t.filter, ["linear", "nearest"]), this.repeat = pn("repeat", t.repeat), this.offset = pn("offset", t.offset), this.rotation = M("Texture", "rotation", t.rotation), this.center = pn("center", t.center), t.uvSet !== 0 && t.uvSet !== 1 && E("Texture", `'uvSet' is 0 (the first UV set) or 1 (the second), got ${j(t.uvSet)}`), this.uvSet = t.uvSet, this.mipmaps = e.mipmaps === void 0 ? !(un(t.image) || !t.image && ln.test(t.url ?? "")) : !!e.mipmaps, this.anisotropy = M("Texture", "anisotropy", t.anisotropy), this.anisotropy >= 1 || E("Texture", `'anisotropy' is how many samples along a glancing angle - 1 (off) or more, got ${this.anisotropy}`), this.flipY = !!t.flipY, this.url = t.url ?? null, t.image ? (this.image = t.image, this.ready = un(t.image) ? dn(t.image).then(() => this) : Promise.resolve(this), this.ready.catch(() => {})) : this.url ? (this.ready = this.#a(this.url), this.ready.catch(() => {})) : E("Texture", "needs an 'image' or a 'url'");
2772
2784
  }
2773
- get colorSpace() {
2785
+ get image() {
2774
2786
  return this.#e;
2775
2787
  }
2788
+ set image(e) {
2789
+ this.#e = e, this.needsUpdate(), un(e) && this.#i(e);
2790
+ }
2791
+ #i(e) {
2792
+ if (typeof e.requestVideoFrameCallback == "function") {
2793
+ let t = () => {
2794
+ this.#e === e && (this.needsUpdate(), e.requestVideoFrameCallback(t));
2795
+ };
2796
+ e.requestVideoFrameCallback(t);
2797
+ return;
2798
+ }
2799
+ let t = -1, n = !1, r = () => {
2800
+ this.#e !== e || e.paused || e.ended ? n = !1 : (e.currentTime !== t && (t = e.currentTime, this.needsUpdate()), requestAnimationFrame(r));
2801
+ }, i = () => {
2802
+ n || this.#e !== e || (n = !0, requestAnimationFrame(r));
2803
+ };
2804
+ e.addEventListener("play", i), e.addEventListener("seeked", () => {
2805
+ this.#e === e && this.needsUpdate();
2806
+ }), e.paused || i();
2807
+ }
2808
+ get colorSpace() {
2809
+ return this.#t;
2810
+ }
2776
2811
  set colorSpace(e) {
2777
- this.#e = P("Texture", "colorSpace", e, ["srgb", "linear"]), this.#t = !0;
2812
+ this.#t = P("Texture", "colorSpace", e, ["srgb", "linear"]), this.#n = !0;
2778
2813
  }
2779
2814
  get colorSpaceSet() {
2780
- return this.#t;
2815
+ return this.#n;
2781
2816
  }
2782
2817
  needsUpdate() {
2783
2818
  return this.version++, this;
2784
2819
  }
2785
2820
  dispose() {
2786
- for (let e of this.#n) e();
2821
+ for (let e of this.#r) e();
2787
2822
  }
2788
2823
  onDispose(e) {
2789
- return this.#n.add(e), () => this.#n.delete(e);
2824
+ return this.#r.add(e), () => this.#r.delete(e);
2790
2825
  }
2791
2826
  toJSON() {
2792
2827
  if (!this.url) return null;
@@ -2800,11 +2835,29 @@ var Xt = /* @__PURE__ */ new Float32Array(16), Zt = /* @__PURE__ */ new Float32A
2800
2835
  get isHDR() {
2801
2836
  return !!this.image && "data" in this.image && this.image.data instanceof Float32Array;
2802
2837
  }
2803
- async #r(e) {
2838
+ async #a(e) {
2839
+ if (ln.test(e)) {
2840
+ if (typeof document > "u") throw Error(`Texture: can't load '${e}' - no video support in this environment`);
2841
+ let t = document.createElement("video");
2842
+ Object.assign(t, {
2843
+ crossOrigin: "anonymous",
2844
+ muted: !0,
2845
+ loop: !0,
2846
+ playsInline: !0,
2847
+ autoplay: !0,
2848
+ src: e
2849
+ });
2850
+ try {
2851
+ await dn(t);
2852
+ } catch {
2853
+ throw Error(`Texture: failed to load '${e}'`);
2854
+ }
2855
+ return t.play()?.catch(() => {}), this.image = t, this;
2856
+ }
2804
2857
  if (/\.hdr($|[?#])/i.test(e)) {
2805
2858
  let [{ parseHDR: t }, n] = await Promise.all([import("./hdr.js"), fetch(e)]);
2806
2859
  if (!n.ok) throw Error(`Texture: failed to load '${e}' (${n.status})`);
2807
- return this.image = t(await n.arrayBuffer()), this.colorSpace = "linear", this.needsUpdate(), this;
2860
+ return this.image = t(await n.arrayBuffer()), this.colorSpace = "linear", this;
2808
2861
  }
2809
2862
  if (typeof Image > "u") throw Error(`Texture: can't load '${e}' - no Image support in this environment`);
2810
2863
  let t = new Image();
@@ -2814,37 +2867,45 @@ var Xt = /* @__PURE__ */ new Float32Array(16), Zt = /* @__PURE__ */ new Float32A
2814
2867
  } catch {
2815
2868
  throw Error(`Texture: failed to load '${e}'`);
2816
2869
  }
2817
- return this.image = t, this.needsUpdate(), this;
2870
+ return this.image = t, this;
2818
2871
  }
2819
- };
2820
- function ln(e, t = {}) {
2872
+ }, ln = /\.(mp4|webm|ogv|mov|m4v)($|[?#])/i;
2873
+ function un(e) {
2874
+ return typeof HTMLVideoElement < "u" && e instanceof HTMLVideoElement;
2875
+ }
2876
+ function dn(e) {
2877
+ return e.readyState >= 2 ? Promise.resolve() : new Promise((t, n) => {
2878
+ e.addEventListener("loadeddata", () => t(), { once: !0 }), e.addEventListener("error", () => n(/* @__PURE__ */ Error("Texture: the video failed to load")), { once: !0 });
2879
+ });
2880
+ }
2881
+ function fn(e, t = {}) {
2821
2882
  return new Y({
2822
2883
  ...t,
2823
2884
  url: e
2824
2885
  }).ready;
2825
2886
  }
2826
- function un(e, t) {
2887
+ function pn(e, t) {
2827
2888
  return (!Array.isArray(t) || t.length !== 2 || t.some((e) => typeof e != "number")) && E("Texture", `'${e}' must be [u, v], got ${j(t)}`), [t[0], t[1]];
2828
2889
  }
2829
2890
  // src/fog.js
2830
- var dn = [
2891
+ var mn = [
2831
2892
  "color",
2832
2893
  "density",
2833
2894
  "near",
2834
2895
  "far"
2835
- ], fn = {
2896
+ ], hn = {
2836
2897
  start: "use 'near' for where linear fog starts",
2837
2898
  end: "use 'far' for where linear fog is complete",
2838
2899
  type: "give 'density' for exponential fog, or 'near' and 'far' for linear",
2839
2900
  exp2: "give 'density' for exponential fog",
2840
2901
  colour: "use 'color'"
2841
- }, pn = class e {
2902
+ }, gn = class e {
2842
2903
  color = new H(8421504);
2843
2904
  density = .05;
2844
2905
  near = 0;
2845
2906
  far = 100;
2846
2907
  constructor(e = {}) {
2847
- A("fog", e, dn, fn), e.color !== void 0 && this.color.set(e.color, "fog");
2908
+ A("fog", e, mn, hn), e.color !== void 0 && this.color.set(e.color, "fog");
2848
2909
  let t = e.near !== void 0 || e.far !== void 0;
2849
2910
  t && e.density !== void 0 && E("fog", "give 'density' for exponential fog, or 'near' and 'far' for linear - not both"), t ? (this.density = 0, e.near !== void 0 && (this.near = M("fog", "near", e.near)), e.far !== void 0 && (this.far = M("fog", "far", e.far)), this.near >= 0 && this.far > this.near || E("fog", `'near' must be 0 or more and 'far' beyond it, got near ${this.near}, far ${this.far}`)) : e.density !== void 0 && (this.density = M("fog", "density", e.density), this.density > 0 || E("fog", `'density' must be more than 0, got ${this.density}`));
2850
2911
  }
@@ -2865,7 +2926,7 @@ var dn = [
2865
2926
  density: this.density
2866
2927
  };
2867
2928
  }
2868
- }, mn = class extends W {
2929
+ }, _n = class extends W {
2869
2930
  static type = "scene";
2870
2931
  static get OPTIONS() {
2871
2932
  return [
@@ -2890,13 +2951,13 @@ var dn = [
2890
2951
  backgroundBlur = 0;
2891
2952
  #n = null;
2892
2953
  constructor(e = {}) {
2893
- super(e), e.background !== void 0 && this.#r(e.background), e.environment !== void 0 && this.#i(e.environment), e.environmentIntensity !== void 0 && (this.environmentIntensity = M("Scene", "environmentIntensity", e.environmentIntensity)), e.backgroundBlur !== void 0 && (this.backgroundBlur = M("Scene", "backgroundBlur", e.backgroundBlur)), e.fog != null && (this.#n = pn.fromInput(e.fog, "Scene"));
2954
+ super(e), e.background !== void 0 && this.#r(e.background), e.environment !== void 0 && this.#i(e.environment), e.environmentIntensity !== void 0 && (this.environmentIntensity = M("Scene", "environmentIntensity", e.environmentIntensity)), e.backgroundBlur !== void 0 && (this.backgroundBlur = M("Scene", "backgroundBlur", e.backgroundBlur)), e.fog != null && (this.#n = gn.fromInput(e.fog, "Scene"));
2894
2955
  }
2895
2956
  get fog() {
2896
2957
  return this.#n;
2897
2958
  }
2898
2959
  set fog(e) {
2899
- this.#n = e == null ? null : pn.fromInput(e, "Scene");
2960
+ this.#n = e == null ? null : gn.fromInput(e, "Scene");
2900
2961
  }
2901
2962
  get background() {
2902
2963
  return this.#e;
@@ -2925,7 +2986,7 @@ var dn = [
2925
2986
  }) : E("Scene", `'environment' must be 'studio', 'none', an .hdr url or a texture, got ${j(e)}`);
2926
2987
  }
2927
2988
  update(e, t) {
2928
- return hn(this, e, t, /* @__PURE__ */ new Set()), this.updateWorldTree(), this;
2989
+ return vn(this, e, t, /* @__PURE__ */ new Set()), this.updateWorldTree(), this;
2929
2990
  }
2930
2991
  get ready() {
2931
2992
  let e = [];
@@ -2954,24 +3015,24 @@ var dn = [
2954
3015
  return this.environmentIntensity !== 1 && (e.environmentIntensity = this.environmentIntensity), this.backgroundBlur && (e.backgroundBlur = this.backgroundBlur), this.#n && (e.fog = this.#n.toJSON()), e;
2955
3016
  }
2956
3017
  };
2957
- function hn(e, t, n, r) {
3018
+ function vn(e, t, n, r) {
2958
3019
  e.hasHandlers && !r.has(e) && (r.add(e), e.runHandlers(t, n));
2959
3020
  let i = e.children;
2960
- if (i.length) for (let e of [...i]) hn(e, t, n, r);
3021
+ if (i.length) for (let e of [...i]) vn(e, t, n, r);
2961
3022
  }
2962
3023
  // src/scene/lights.js
2963
- var gn = [
3024
+ var yn = [
2964
3025
  ...U,
2965
3026
  "color",
2966
3027
  "intensity"
2967
- ], _n = {
3028
+ ], bn = {
2968
3029
  distance: "use 'range' (0 = infinite)",
2969
3030
  decay: "falloff is physical (inverse square), as in glTF - limit it with range",
2970
3031
  attenuation: "use 'range' - falloff is physical (inverse square)",
2971
3032
  shadow: "use 'castShadow: true' (directional, spot and point lights)"
2972
- }, vn = class extends W {
2973
- static OPTIONS = gn;
2974
- static HINTS = _n;
3033
+ }, xn = class extends W {
3034
+ static OPTIONS = yn;
3035
+ static HINTS = bn;
2975
3036
  static kind = "ambient";
2976
3037
  get lightKind() {
2977
3038
  return this.constructor.kind;
@@ -3000,10 +3061,10 @@ var gn = [
3000
3061
  let e = {};
3001
3062
  return this.#e.getHex() !== 16777215 && (e.color = this.#e.getStyle()), this.intensity !== 1 && (e.intensity = this.intensity), e;
3002
3063
  }
3003
- }, yn = class extends vn {
3064
+ }, Sn = class extends xn {
3004
3065
  static type = "ambient-light";
3005
3066
  static kind = "ambient";
3006
- }, bn = class extends vn {
3067
+ }, Cn = class extends xn {
3007
3068
  static type = "hemisphere-light";
3008
3069
  static kind = "hemisphere";
3009
3070
  static get OPTIONS() {
@@ -3051,7 +3112,7 @@ var gn = [
3051
3112
  ...this.#e.getHex() === 4473924 ? {} : { ground: this.#e.getStyle() }
3052
3113
  };
3053
3114
  }
3054
- }, xn = class extends vn {
3115
+ }, wn = class extends xn {
3055
3116
  #e = new z(0, -1, 0);
3056
3117
  #t = null;
3057
3118
  get direction() {
@@ -3096,12 +3157,12 @@ var gn = [
3096
3157
  ...this.target ? { target: this.target.toArray() } : { direction: this.direction.toArray() }
3097
3158
  };
3098
3159
  }
3099
- }, Sn = class extends xn {
3160
+ }, Tn = class extends wn {
3100
3161
  static type = "directional-light";
3101
3162
  static kind = "directional";
3102
3163
  static get OPTIONS() {
3103
3164
  return [
3104
- ...gn,
3165
+ ...yn,
3105
3166
  "direction",
3106
3167
  "target",
3107
3168
  "castShadow"
@@ -3123,12 +3184,12 @@ var gn = [
3123
3184
  ...this.castShadow ? { castShadow: !0 } : {}
3124
3185
  };
3125
3186
  }
3126
- }, Cn = class extends vn {
3187
+ }, En = class extends xn {
3127
3188
  static type = "point-light";
3128
3189
  static kind = "point";
3129
3190
  static get OPTIONS() {
3130
3191
  return [
3131
- ...gn,
3192
+ ...yn,
3132
3193
  "range",
3133
3194
  "castShadow"
3134
3195
  ];
@@ -3136,7 +3197,7 @@ var gn = [
3136
3197
  range = 0;
3137
3198
  castShadow = !1;
3138
3199
  constructor(e = {}) {
3139
- super(e), e.range !== void 0 && (this.range = Tn(this.constructor.name, e.range)), e.castShadow !== void 0 && (this.castShadow = !!e.castShadow);
3200
+ super(e), e.range !== void 0 && (this.range = On(this.constructor.name, e.range)), e.castShadow !== void 0 && (this.castShadow = !!e.castShadow);
3140
3201
  }
3141
3202
  cloneOptions() {
3142
3203
  return {
@@ -3152,12 +3213,12 @@ var gn = [
3152
3213
  ...this.castShadow ? { castShadow: !0 } : {}
3153
3214
  };
3154
3215
  }
3155
- }, wn = class extends xn {
3216
+ }, Dn = class extends wn {
3156
3217
  static type = "spot-light";
3157
3218
  static kind = "spot";
3158
3219
  static get OPTIONS() {
3159
3220
  return [
3160
- ...gn,
3221
+ ...yn,
3161
3222
  "direction",
3162
3223
  "target",
3163
3224
  "range",
@@ -3171,7 +3232,7 @@ var gn = [
3171
3232
  angle = Math.PI / 6;
3172
3233
  penumbra = .1;
3173
3234
  constructor(e = {}) {
3174
- super(e), e.castShadow !== void 0 && (this.castShadow = !!e.castShadow), e.range !== void 0 && (this.range = Tn("SpotLight", e.range)), e.angle !== void 0 && (this.angle = M("SpotLight", "angle", e.angle), (this.angle <= 0 || this.angle > Math.PI / 2) && E("SpotLight", `'angle' is the cone's half-angle in radians, above 0 and up to PI/2, got ${this.angle}`)), e.penumbra !== void 0 && (this.penumbra = M("SpotLight", "penumbra", e.penumbra), (this.penumbra < 0 || this.penumbra > 1) && E("SpotLight", `'penumbra' must be 0-1, got ${this.penumbra}`));
3235
+ super(e), e.castShadow !== void 0 && (this.castShadow = !!e.castShadow), e.range !== void 0 && (this.range = On("SpotLight", e.range)), e.angle !== void 0 && (this.angle = M("SpotLight", "angle", e.angle), (this.angle <= 0 || this.angle > Math.PI / 2) && E("SpotLight", `'angle' is the cone's half-angle in radians, above 0 and up to PI/2, got ${this.angle}`)), e.penumbra !== void 0 && (this.penumbra = M("SpotLight", "penumbra", e.penumbra), (this.penumbra < 0 || this.penumbra > 1) && E("SpotLight", `'penumbra' must be 0-1, got ${this.penumbra}`));
3175
3236
  }
3176
3237
  cloneOptions() {
3177
3238
  return {
@@ -3187,21 +3248,23 @@ var gn = [
3187
3248
  return this.range && (e.range = this.range), this.angle !== Math.PI / 6 && (e.angle = this.angle), this.penumbra !== .1 && (e.penumbra = this.penumbra), this.castShadow && (e.castShadow = !0), e;
3188
3249
  }
3189
3250
  };
3190
- function Tn(e, t) {
3251
+ function On(e, t) {
3191
3252
  let n = M(e, "range", t);
3192
3253
  return n < 0 && E(e, `'range' can't be negative (0 means unlimited), got ${n}`), n;
3193
3254
  }
3194
3255
  // src/geometry/Geometry.js
3195
- var En = [
3256
+ var kn = [
3196
3257
  "positions",
3197
3258
  "normals",
3198
3259
  "uvs",
3260
+ "uvs2",
3199
3261
  "colors",
3200
3262
  "indices"
3201
3263
  ], X = class e {
3202
- static OPTIONS = En;
3264
+ static OPTIONS = kn;
3203
3265
  positions;
3204
3266
  uvs = null;
3267
+ uvs2 = null;
3205
3268
  colors = null;
3206
3269
  indices = null;
3207
3270
  version = 0;
@@ -3211,9 +3274,9 @@ var En = [
3211
3274
  #t = null;
3212
3275
  #n = /* @__PURE__ */ new Set();
3213
3276
  constructor(e) {
3214
- A("Geometry", e, En), e?.positions || E("Geometry", "'positions' is required - an array of x, y, z per vertex"), this.positions = Dn("positions", e.positions, 3);
3277
+ A("Geometry", e, kn), e?.positions || E("Geometry", "'positions' is required - an array of x, y, z per vertex"), this.positions = An("positions", e.positions, 3);
3215
3278
  let t = this.vertexCount;
3216
- if (e.normals && (this.#e = Dn("normals", e.normals, 3, t)), e.uvs && (this.uvs = Dn("uvs", e.uvs, 2, t)), e.colors && (this.colors = Dn("colors", e.colors, 3, t)), e.indices) {
3279
+ if (e.normals && (this.#e = An("normals", e.normals, 3, t)), e.uvs && (this.uvs = An("uvs", e.uvs, 2, t)), e.uvs2 && (this.uvs2 = An("uvs2", e.uvs2, 2, t)), e.colors && (this.colors = An("colors", e.colors, 3, t)), e.indices) {
3217
3280
  let n = -1;
3218
3281
  for (let t = 0; t < e.indices.length; t++) {
3219
3282
  let r = e.indices[t];
@@ -3274,6 +3337,7 @@ var En = [
3274
3337
  positions: this.positions,
3275
3338
  normals: this.#e ?? void 0,
3276
3339
  uvs: this.uvs ?? void 0,
3340
+ uvs2: this.uvs2 ?? void 0,
3277
3341
  colors: this.colors ?? void 0,
3278
3342
  indices: this.indices ?? void 0
3279
3343
  });
@@ -3288,7 +3352,7 @@ var En = [
3288
3352
  toJSON() {
3289
3353
  if (this.source) return { ...this.source };
3290
3354
  let e = { positions: Array.from(this.positions) };
3291
- return this.#e && (e.normals = Array.from(this.#e)), this.uvs && (e.uvs = Array.from(this.uvs)), this.colors && (e.colors = Array.from(this.colors)), this.indices && (e.indices = Array.from(this.indices)), e;
3355
+ return this.#e && (e.normals = Array.from(this.#e)), this.uvs && (e.uvs = Array.from(this.uvs)), this.uvs2 && (e.uvs2 = Array.from(this.uvs2)), this.colors && (e.colors = Array.from(this.colors)), this.indices && (e.indices = Array.from(this.indices)), e;
3292
3356
  }
3293
3357
  #i(e) {
3294
3358
  return this.indices ? this.indices[e] : e;
@@ -3300,31 +3364,33 @@ var En = [
3300
3364
  for (let i = 0; i < e.length; i++) for (let a = 0; a < n; a++) r[i * n + a] = t[e[i] * n + a];
3301
3365
  return r;
3302
3366
  };
3303
- this.positions = t(this.positions, 3), this.uvs = t(this.uvs, 2), this.colors = t(this.colors, 3), this.indices = null, this.source = null;
3367
+ this.positions = t(this.positions, 3), this.uvs = t(this.uvs, 2), this.uvs2 = t(this.uvs2, 2), this.colors = t(this.colors, 3), this.indices = null, this.source = null;
3304
3368
  }
3305
3369
  };
3306
- function Dn(e, t, n, r) {
3370
+ function An(e, t, n, r) {
3307
3371
  t && typeof t == "object" && typeof t.length == "number" || E("Geometry", `'${e}' must be an array of numbers, got ${j(t)}`), t.length % n !== 0 && E("Geometry", `'${e}' has ${t.length} numbers - expected ${n} per vertex`), r !== void 0 && t.length !== r * n && E("Geometry", `'${e}' has ${t.length / n} entries but 'positions' has ${r} vertices`);
3308
3372
  let i = Float32Array.from(t);
3309
3373
  for (let t = 0; t < i.length; t++) Number.isNaN(i[t]) && E("Geometry", `'${e}' contains a non-number at index ${t}`);
3310
3374
  return i;
3311
3375
  }
3312
3376
  // src/material/Material.js
3313
- var On = [
3377
+ var jn = [
3314
3378
  "map",
3315
3379
  "roughnessMap",
3316
3380
  "metalnessMap",
3317
3381
  "normalMap",
3318
3382
  "bumpMap",
3319
3383
  "aoMap",
3320
- "emissiveMap"
3321
- ], kn = /* @__PURE__ */ new Set([
3384
+ "emissiveMap",
3385
+ "lightMap",
3386
+ "matcap"
3387
+ ], Mn = /* @__PURE__ */ new Set([
3322
3388
  "roughnessMap",
3323
3389
  "metalnessMap",
3324
3390
  "normalMap",
3325
3391
  "bumpMap",
3326
3392
  "aoMap"
3327
- ]), An = [
3393
+ ]), Nn = [
3328
3394
  "unlit",
3329
3395
  "flatShading",
3330
3396
  "doubleSided",
@@ -3334,7 +3400,7 @@ var On = [
3334
3400
  "sizeAttenuation",
3335
3401
  "transparent",
3336
3402
  "fog"
3337
- ], jn = {
3403
+ ], Pn = {
3338
3404
  opacity: [0, 1],
3339
3405
  roughness: [0, 1],
3340
3406
  metalness: [0, 1],
@@ -3345,8 +3411,27 @@ var On = [
3345
3411
  normalScale: [-Infinity, Infinity],
3346
3412
  aoMapIntensity: [0, 1],
3347
3413
  triplanar: [0, Infinity],
3348
- bumpScale: [-Infinity, Infinity]
3349
- }, Mn = {
3414
+ bumpScale: [-Infinity, Infinity],
3415
+ transmission: [0, 1],
3416
+ clearcoat: [0, 1],
3417
+ clearcoatRoughness: [0, 1],
3418
+ sheen: [0, 1],
3419
+ sheenRoughness: [0, 1],
3420
+ ior: [1, Infinity],
3421
+ specularIntensity: [0, 1],
3422
+ anisotropy: [0, 1],
3423
+ anisotropyRotation: [-Infinity, Infinity],
3424
+ translucency: [0, 1],
3425
+ toon: [0, 16],
3426
+ lightMapIntensity: [0, Infinity],
3427
+ environmentIntensity: [0, Infinity]
3428
+ }, Fn = {
3429
+ color: 16777215,
3430
+ emissive: 0,
3431
+ sheenColor: 16777215,
3432
+ specularColor: 16777215,
3433
+ translucencyColor: 16777215
3434
+ }, In = {
3350
3435
  name: "",
3351
3436
  opacity: 1,
3352
3437
  alphaTest: 0,
@@ -3357,6 +3442,19 @@ var On = [
3357
3442
  aoMapIntensity: 1,
3358
3443
  triplanar: 0,
3359
3444
  emissiveIntensity: 1,
3445
+ transmission: 0,
3446
+ clearcoat: 0,
3447
+ clearcoatRoughness: 0,
3448
+ sheen: 0,
3449
+ sheenRoughness: .5,
3450
+ ior: 1.5,
3451
+ specularIntensity: 1,
3452
+ anisotropy: 0,
3453
+ anisotropyRotation: 0,
3454
+ translucency: 0,
3455
+ toon: 0,
3456
+ lightMapIntensity: 1,
3457
+ environmentIntensity: 1,
3360
3458
  unlit: !1,
3361
3459
  flatShading: !1,
3362
3460
  doubleSided: !1,
@@ -3368,26 +3466,35 @@ var On = [
3368
3466
  size: 1,
3369
3467
  sizeAttenuation: !0,
3370
3468
  width: 1
3371
- }, Nn = [
3469
+ }, Ln = [
3372
3470
  "name",
3373
- "color",
3374
- "emissive",
3375
- ...On,
3376
- ...An,
3377
- ...Object.keys(jn),
3471
+ ...Object.keys(Fn),
3472
+ ...jn,
3473
+ ...Nn,
3474
+ ...Object.keys(Pn),
3378
3475
  "blending"
3379
- ], Pn = {
3476
+ ], Rn = {
3380
3477
  type: "phoria2 has one material - drop 'type' and set 'unlit: true' for a flat colour",
3381
3478
  side: "use 'doubleSided: true'",
3382
3479
  wireframe: "use new Lines({ geometry: edges(geometry) }) for a wireframe",
3383
3480
  shininess: "use 'roughness' (0 = mirror, 1 = matte)",
3384
- specular: "use 'roughness' and 'metalness'",
3481
+ envMapIntensity: "use 'environmentIntensity'",
3482
+ reflectivityScale: "use 'environmentIntensity'",
3483
+ matcapMap: "use 'matcap'",
3484
+ gradientMap: "use 'toon' - the number of flat tones",
3485
+ cel: "use 'toon' - the number of flat tones",
3486
+ celShading: "use 'toon' - the number of flat tones",
3487
+ specular: "use 'specularIntensity' and 'specularColor' for a non-metal's reflections, or 'roughness' and 'metalness'",
3488
+ reflectivity: "use 'ior' (1.5 by default) or 'specularIntensity'",
3489
+ anisotropyStrength: "use 'anisotropy'",
3490
+ diffuseTransmission: "use 'translucency'",
3491
+ subsurface: "use 'translucency' for light through thin surfaces",
3385
3492
  colour: "use 'color'",
3386
3493
  emissiveColor: "use 'emissive'",
3387
3494
  alpha: "use 'opacity'"
3388
- }, Fn = class e {
3389
- static OPTIONS = Nn;
3390
- static HINTS = Pn;
3495
+ }, zn = class e {
3496
+ static OPTIONS = Ln;
3497
+ static HINTS = Rn;
3391
3498
  name;
3392
3499
  opacity;
3393
3500
  alphaTest;
@@ -3398,6 +3505,19 @@ var On = [
3398
3505
  roughness;
3399
3506
  metalness;
3400
3507
  emissiveIntensity;
3508
+ transmission;
3509
+ clearcoat;
3510
+ clearcoatRoughness;
3511
+ sheen;
3512
+ sheenRoughness;
3513
+ ior;
3514
+ specularIntensity;
3515
+ anisotropy;
3516
+ anisotropyRotation;
3517
+ translucency;
3518
+ toon;
3519
+ lightMapIntensity;
3520
+ environmentIntensity;
3401
3521
  unlit;
3402
3522
  flatShading;
3403
3523
  doubleSided;
@@ -3409,14 +3529,13 @@ var On = [
3409
3529
  size;
3410
3530
  sizeAttenuation;
3411
3531
  width;
3412
- #e = new H(16777215);
3413
- #t = new H(0);
3414
- #n = !1;
3415
- #r = Object.fromEntries(On.map((e) => [e, null]));
3416
- #i = /* @__PURE__ */ new Set();
3532
+ #e = Object.fromEntries(Object.entries(Fn).map(([e, t]) => [e, new H(t)]));
3533
+ #t = !1;
3534
+ #n = Object.fromEntries(jn.map((e) => [e, null]));
3535
+ #r = /* @__PURE__ */ new Set();
3417
3536
  constructor(e = {}) {
3418
- A("Material", e, Nn, Pn), Object.assign(this, Mn);
3419
- for (let [t, n] of Object.entries(e)) n !== void 0 && (t === "color" ? this.color = n : t === "emissive" ? this.emissive = n : On.includes(t) ? this.setMap(t, n) : An.includes(t) ? this[t] = In(t, n) : t in jn ? this[t] = Ln(t, n, jn[t]) : t === "blending" ? this.blending = P("Material", "blending", n, [
3537
+ A("Material", e, Ln, Rn), Object.assign(this, In);
3538
+ for (let [t, n] of Object.entries(e)) n !== void 0 && (t in Fn ? this.#e[t].set(n, "Material") : jn.includes(t) ? this.setMap(t, n) : Nn.includes(t) ? this[t] = Bn(t, n) : t in Pn ? this[t] = Vn(t, n, Pn[t]) : t === "blending" ? this.blending = P("Material", "blending", n, [
3420
3539
  "normal",
3421
3540
  "additive",
3422
3541
  "multiply"
@@ -3426,105 +3545,137 @@ var On = [
3426
3545
  return t instanceof e ? t : ((!t || typeof t != "object" || Array.isArray(t)) && E("Material", `expected material options such as { color: 'orange' }, got ${j(t)}`), new e(t));
3427
3546
  }
3428
3547
  get color() {
3429
- return this.#e;
3548
+ return this.#e.color;
3430
3549
  }
3431
3550
  set color(e) {
3432
- this.#e.set(e, "Material");
3551
+ this.#e.color.set(e, "Material");
3433
3552
  }
3434
3553
  get emissive() {
3435
- return this.#t;
3554
+ return this.#e.emissive;
3436
3555
  }
3437
3556
  set emissive(e) {
3438
- this.#t.set(e, "Material");
3557
+ this.#e.emissive.set(e, "Material");
3558
+ }
3559
+ get sheenColor() {
3560
+ return this.#e.sheenColor;
3561
+ }
3562
+ set sheenColor(e) {
3563
+ this.#e.sheenColor.set(e, "Material");
3564
+ }
3565
+ get specularColor() {
3566
+ return this.#e.specularColor;
3567
+ }
3568
+ set specularColor(e) {
3569
+ this.#e.specularColor.set(e, "Material");
3570
+ }
3571
+ get translucencyColor() {
3572
+ return this.#e.translucencyColor;
3573
+ }
3574
+ set translucencyColor(e) {
3575
+ this.#e.translucencyColor.set(e, "Material");
3439
3576
  }
3440
3577
  get map() {
3441
- return this.#r.map;
3578
+ return this.#n.map;
3442
3579
  }
3443
3580
  set map(e) {
3444
3581
  this.setMap("map", e);
3445
3582
  }
3446
3583
  get roughnessMap() {
3447
- return this.#r.roughnessMap;
3584
+ return this.#n.roughnessMap;
3448
3585
  }
3449
3586
  set roughnessMap(e) {
3450
3587
  this.setMap("roughnessMap", e);
3451
3588
  }
3452
3589
  get metalnessMap() {
3453
- return this.#r.metalnessMap;
3590
+ return this.#n.metalnessMap;
3454
3591
  }
3455
3592
  set metalnessMap(e) {
3456
3593
  this.setMap("metalnessMap", e);
3457
3594
  }
3458
3595
  get normalMap() {
3459
- return this.#r.normalMap;
3596
+ return this.#n.normalMap;
3460
3597
  }
3461
3598
  set normalMap(e) {
3462
3599
  this.setMap("normalMap", e);
3463
3600
  }
3464
3601
  get bumpMap() {
3465
- return this.#r.bumpMap;
3602
+ return this.#n.bumpMap;
3466
3603
  }
3467
3604
  set bumpMap(e) {
3468
3605
  this.setMap("bumpMap", e);
3469
3606
  }
3470
3607
  get aoMap() {
3471
- return this.#r.aoMap;
3608
+ return this.#n.aoMap;
3472
3609
  }
3473
3610
  set aoMap(e) {
3474
3611
  this.setMap("aoMap", e);
3475
3612
  }
3476
3613
  get emissiveMap() {
3477
- return this.#r.emissiveMap;
3614
+ return this.#n.emissiveMap;
3478
3615
  }
3479
3616
  set emissiveMap(e) {
3480
3617
  this.setMap("emissiveMap", e);
3481
3618
  }
3619
+ get lightMap() {
3620
+ return this.#n.lightMap;
3621
+ }
3622
+ set lightMap(e) {
3623
+ this.setMap("lightMap", e);
3624
+ }
3625
+ get matcap() {
3626
+ return this.#n.matcap;
3627
+ }
3628
+ set matcap(e) {
3629
+ this.setMap("matcap", e);
3630
+ }
3482
3631
  setMap(e, t) {
3483
3632
  if (t == null) {
3484
- this.#r[e] = null;
3633
+ this.#n[e] = null;
3485
3634
  return;
3486
3635
  }
3487
3636
  if (t instanceof Y) {
3488
- kn.has(e) && t.colorSpace === "srgb" && (t.colorSpaceSet ? F(t, `'${e}' holds data, not colour, so its texture should be colorSpace: 'linear' - this one is 'srgb', and will be decoded as colour`) : (t.colorSpace = "linear", t.needsUpdate())), this.#r[e] = t;
3637
+ Mn.has(e) && t.colorSpace === "srgb" && (t.colorSpaceSet ? F(t, `'${e}' holds data, not colour, so its texture should be colorSpace: 'linear' - this one is 'srgb', and will be decoded as colour`) : (t.colorSpace = "linear", t.needsUpdate())), this.#n[e] = t;
3489
3638
  return;
3490
3639
  }
3491
3640
  let n = typeof t == "string" ? { url: t } : t;
3492
- (typeof n != "object" || Array.isArray(n)) && E("Material", `'${e}' must be a Texture, a url or texture options, got ${j(t)}`), this.#r[e] = new Y({
3493
- colorSpace: kn.has(e) ? "linear" : "srgb",
3641
+ (typeof n != "object" || Array.isArray(n)) && E("Material", `'${e}' must be a Texture, a url or texture options, got ${j(t)}`), this.#n[e] = new Y({
3642
+ colorSpace: Mn.has(e) ? "linear" : "srgb",
3494
3643
  ...n
3495
3644
  });
3496
3645
  }
3497
3646
  get textures() {
3498
- return Object.entries(this.#r).filter(([, e]) => e);
3647
+ return Object.entries(this.#n).filter(([, e]) => e);
3499
3648
  }
3500
3649
  get transparent() {
3501
- return this.#n || this.opacity < 1 || this.blending !== "normal";
3650
+ return this.#t || this.opacity < 1 || this.transmission > 0 || this.blending !== "normal";
3502
3651
  }
3503
3652
  set transparent(e) {
3504
- this.#n = !!e;
3653
+ this.#t = !!e;
3505
3654
  }
3506
3655
  get variant() {
3507
3656
  let e = [this.unlit ? "unlit" : "lit"];
3508
3657
  for (let [t] of this.textures) e.push(t);
3509
- return this.alphaTest > 0 && e.push("cutout"), this.flatShading && e.push("flat"), this.vertexColors && e.push("vcolor"), e.join("+");
3658
+ return this.alphaTest > 0 && e.push("cutout"), this.transmission > 0 && e.push("glass"), this.clearcoat > 0 && e.push("clearcoat"), this.sheen > 0 && e.push("sheen"), this.anisotropy > 0 && e.push("brushed"), this.translucency > 0 && e.push("translucent"), this.toon > 0 && e.push("toon"), this.flatShading && e.push("flat"), this.vertexColors && e.push("vcolor"), e.join("+");
3510
3659
  }
3511
3660
  async ready() {
3512
3661
  await Promise.all(this.textures.map(([, e]) => e.ready));
3513
3662
  }
3514
3663
  clone() {
3515
3664
  let t = new e(this.toJSON(!0));
3516
- return t.color.set(this.#e), t.emissive.set(this.#t), t;
3665
+ for (let [e, n] of Object.entries(this.#e)) t.#e[e].set(n);
3666
+ return t;
3517
3667
  }
3518
3668
  dispose() {
3519
- for (let e of this.#i) e();
3669
+ for (let e of this.#r) e();
3520
3670
  }
3521
3671
  onDispose(e) {
3522
- return this.#i.add(e), () => this.#i.delete(e);
3672
+ return this.#r.add(e), () => this.#r.delete(e);
3523
3673
  }
3524
3674
  toJSON(e = !1) {
3525
3675
  let t = {};
3526
- for (let [e, n] of Object.entries(Mn)) this[e] !== n && (t[e] = this[e]);
3527
- this.#n && (t.transparent = !0), this.#e.getHex() !== 16777215 && (t.color = this.#e.getStyle()), this.#t.getHex() !== 0 && (t.emissive = this.#t.getStyle());
3676
+ for (let [e, n] of Object.entries(In)) this[e] !== n && (t[e] = this[e]);
3677
+ this.#t && (t.transparent = !0);
3678
+ for (let [e, n] of Object.entries(this.#e)) n.getHex() !== Fn[e] && (t[e] = n.getStyle());
3528
3679
  for (let [n, r] of this.textures) {
3529
3680
  let i = e ? r : r.toJSON();
3530
3681
  i && (t[n] = i);
@@ -3532,10 +3683,10 @@ var On = [
3532
3683
  return t;
3533
3684
  }
3534
3685
  };
3535
- function In(e, t) {
3686
+ function Bn(e, t) {
3536
3687
  return typeof t != "boolean" && E("Material", `'${e}' must be true or false, got ${j(t)}`), t;
3537
3688
  }
3538
- function Ln(e, t, [n, r]) {
3689
+ function Vn(e, t, [n, r]) {
3539
3690
  M("Material", e, t);
3540
3691
  let i = t;
3541
3692
  return (i < n || i > r) && E("Material", `'${e}' must be ${r === Infinity ? `${n} or more` : `${n}-${r}`}, got ${i}`), i;
@@ -3548,12 +3699,56 @@ var Z = {
3548
3699
  color: 3,
3549
3700
  instanceMatrix: 4,
3550
3701
  instanceColor: 8,
3702
+ tangent: 9,
3703
+ uv2: 10,
3551
3704
  segmentStart: 0,
3552
3705
  segmentEnd: 1,
3553
3706
  segmentColorStart: 2,
3554
3707
  segmentColorEnd: 3,
3555
3708
  corner: 4
3556
- }, Rn = "#ifdef CLIP\nuniform vec4 uClipPlane;\nvoid clipAway(vec3 p) {\nif (dot(uClipPlane.xyz, p) + uClipPlane.w > 0.0) discard;\n}\n#else\nvoid clipAway(vec3 p) {}\n#endif\n", zn = "#ifdef FOG\nuniform vec3 uFogColor;\nuniform vec2 uFogRange;\nuniform float uFogDensity;\nin float vFogDepth;\nvec3 fogged(vec3 c) {\n#ifdef FOG_LINEAR\nfloat f = clamp((vFogDepth - uFogRange.x) / max(uFogRange.y - uFogRange.x, 1e-4), 0.0, 1.0);\n#else\nfloat d = uFogDensity * vFogDepth;\nfloat f = 1.0 - exp(-d * d);\n#endif\n#ifdef FOG_ADD\nreturn c * (1.0 - f);\n#elif defined(FOG_MULTIPLY)\nreturn mix(c, vec3(1.0), f);\n#else\nreturn mix(c, uFogColor, f);\n#endif\n}\n#else\nvec3 fogged(vec3 c) { return c; }\n#endif\n", Bn = "#ifdef TRIPLANAR\nin vec3 vObjectPosition;\nin vec3 vObjectNormal;\nin mat3 vObjectToWorld;\nuniform float uTriplanar;\nuniform vec4 uUvTransform;\nvec2 projected(vec2 p) {\nreturn p * uUvTransform.xy + uUvTransform.zw;\n}\nvec3 triplanarWeights(vec3 n) {\nvec3 w = pow(abs(n), vec3(4.0));\nreturn w / (w.x + w.y + w.z);\n}\nvec4 triplanar(sampler2D s) {\nvec3 p = vObjectPosition * uTriplanar, w = triplanarWeights(normalize(vObjectNormal));\nreturn texture(s, projected(p.zy)) * w.x + texture(s, projected(p.xz)) * w.y + texture(s, projected(p.xy)) * w.z;\n}\n#define SAMPLE(s) triplanar(s)\n#else\n#define SAMPLE(s) texture(s, vUv)\n#endif\n", Vn = `precision highp float;
3709
+ }, Hn = "#ifdef CLIP\nuniform vec4 uClipPlane;\nvoid clipAway(vec3 p) {\nif (dot(uClipPlane.xyz, p) + uClipPlane.w > 0.0) discard;\n}\n#else\nvoid clipAway(vec3 p) {}\n#endif\n", Un = "#ifdef FOG\nuniform vec3 uFogColor;\nuniform vec2 uFogRange;\nuniform float uFogDensity;\nin float vFogDepth;\nvec3 fogged(vec3 c) {\n#ifdef FOG_LINEAR\nfloat f = clamp((vFogDepth - uFogRange.x) / max(uFogRange.y - uFogRange.x, 1e-4), 0.0, 1.0);\n#else\nfloat d = uFogDensity * vFogDepth;\nfloat f = 1.0 - exp(-d * d);\n#endif\n#ifdef FOG_ADD\nreturn c * (1.0 - f);\n#elif defined(FOG_MULTIPLY)\nreturn mix(c, vec3(1.0), f);\n#else\nreturn mix(c, uFogColor, f);\n#endif\n}\n#else\nvec3 fogged(vec3 c) { return c; }\n#endif\n", Wn = [
3710
+ "uMap",
3711
+ "uRoughnessMap",
3712
+ "uMetalnessMap",
3713
+ "uNormalMap",
3714
+ "uBumpMap",
3715
+ "uAoMap",
3716
+ "uEmissiveMap",
3717
+ "uLightMap"
3718
+ ], Gn = `#ifdef UV2
3719
+ in vec2 vUv2;
3720
+ #endif
3721
+ ${Wn.map((e) => `uniform mat3 ${e}Uv;
3722
+ #ifndef ${e}Set
3723
+ #define ${e}Set vUv
3724
+ #endif
3725
+ #define ${e}Coord (${e}Uv * vec3(${e}Set, 1.0)).xy`).join("\n")}
3726
+ #ifdef TRIPLANAR
3727
+ in vec3 vObjectPosition;
3728
+ in vec3 vObjectNormal;
3729
+ in mat3 vObjectToWorld;
3730
+ uniform float uTriplanar; // repeats per unit of the mesh's own space
3731
+
3732
+ // a projection's coordinates through the map's transform, as UVs would be
3733
+ vec2 projected(vec2 p, mat3 t) {
3734
+ return (t * vec3(p, 1.0)).xy;
3735
+ }
3736
+
3737
+ // how much each axis's projection counts: mostly the one the surface faces, blended at the turns
3738
+ vec3 triplanarWeights(vec3 n) {
3739
+ vec3 w = pow(abs(n), vec3(4.0));
3740
+ return w / (w.x + w.y + w.z);
3741
+ }
3742
+ // a map seen from the three axes and blended - for meshes with no UVs, scans and CAD models
3743
+ vec4 triplanar(sampler2D s, mat3 t) {
3744
+ vec3 p = vObjectPosition * uTriplanar, w = triplanarWeights(normalize(vObjectNormal));
3745
+ return texture(s, projected(p.zy, t)) * w.x + texture(s, projected(p.xz, t)) * w.y + texture(s, projected(p.xy, t)) * w.z;
3746
+ }
3747
+ ${Wn.map((e) => `#define ${e}Texel triplanar(${e}, ${e}Uv)`).join("\n")}
3748
+ #else
3749
+ ${Wn.map((e) => `#define ${e}Texel texture(${e}, ${e}Coord)`).join("\n")}
3750
+ #endif
3751
+ `, Kn = `precision highp float;
3557
3752
  in vec3 vWorldPosition;
3558
3753
  out vec4 fragColor;
3559
3754
  #ifdef ALPHA_TEST
@@ -3562,22 +3757,22 @@ uniform float uOpacity;
3562
3757
  uniform float uAlphaTest;
3563
3758
  #ifdef MAP
3564
3759
  uniform sampler2D uMap;
3565
- ${Bn}
3760
+ ${Gn}
3566
3761
  #endif
3567
3762
  #endif
3568
- ${Rn}
3763
+ ${Hn}
3569
3764
  void main() {
3570
3765
  clipAway(vWorldPosition);
3571
3766
  #ifdef ALPHA_TEST
3572
3767
  float alpha = uOpacity;
3573
3768
  #ifdef MAP
3574
- alpha *= SAMPLE(uMap).a;
3769
+ alpha *= uMapTexel.a;
3575
3770
  #endif
3576
3771
  if (alpha < uAlphaTest) discard;
3577
3772
  #endif
3578
3773
  fragColor = vec4(1.0);
3579
3774
  }
3580
- `, Hn = "vec3 srgbToLinear(vec3 c) {\nreturn mix(c / 12.92, pow((c + 0.055) / 1.055, vec3(2.4)), step(0.04045, c));\n}\nvec3 linearToSrgb(vec3 c) {\nc = clamp(c, 0.0, 1.0);\nreturn mix(c * 12.92, 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, step(0.0031308, c));\n}\n", Un = "vec2 equirectUv(vec3 d) {\nreturn vec2(atan(d.z, d.x) * 0.15915494 + 0.5, acos(clamp(d.y, -1.0, 1.0)) * 0.31830989);\n}\nvec3 equirectDirection(vec2 uv) {\nfloat phi = (uv.x - 0.5) * 6.28318531, theta = uv.y * 3.14159265;\nreturn vec3(cos(phi) * sin(theta), cos(theta), sin(phi) * sin(theta));\n}\n", Wn = "out vec2 vUv;\nvoid main() {\nvec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));\nvUv = p;\ngl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);\n}\n", Gn = "uniform float uExposure;\nuniform int uToneMapping;\nvec3 toneMap(vec3 c) {\nc *= uExposure;\nif (uToneMapping == 1) {\nc = clamp((c * (2.51 * c + 0.03)) / (c * (2.43 * c + 0.59) + 0.14), 0.0, 1.0);\n} else if (uToneMapping == 2) {\nfloat x = min(c.r, min(c.g, c.b));\nfloat offset = x < 0.08 ? x - 6.25 * x * x : 0.04;\nc -= offset;\nfloat peak = max(c.r, max(c.g, c.b));\nif (peak > 0.8) {\nfloat d = 0.2;\nfloat newPeak = 1.0 - d * d / (peak + d - 0.8);\nc *= newPeak / peak;\nfloat g = 1.0 - 1.0 / (0.15 * (peak - newPeak) + 1.0);\nc = mix(c, vec3(newPeak), g);\n}\n}\nreturn c;\n}\n", Kn = `layout(location = 0) in vec3 position;
3775
+ `, qn = "vec3 srgbToLinear(vec3 c) {\nreturn mix(c / 12.92, pow((c + 0.055) / 1.055, vec3(2.4)), step(0.04045, c));\n}\nvec3 linearToSrgb(vec3 c) {\nc = clamp(c, 0.0, 1.0);\nreturn mix(c * 12.92, 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, step(0.0031308, c));\n}\n", Jn = "vec2 equirectUv(vec3 d) {\nreturn vec2(atan(d.z, d.x) * 0.15915494 + 0.5, acos(clamp(d.y, -1.0, 1.0)) * 0.31830989);\n}\nvec3 equirectDirection(vec2 uv) {\nfloat phi = (uv.x - 0.5) * 6.28318531, theta = uv.y * 3.14159265;\nreturn vec3(cos(phi) * sin(theta), cos(theta), sin(phi) * sin(theta));\n}\n", Yn = "out vec2 vUv;\nvoid main() {\nvec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));\nvUv = p;\ngl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);\n}\n", Xn = "uniform float uExposure;\nuniform int uToneMapping;\nvec3 toneMap(vec3 c) {\nc *= uExposure;\nif (uToneMapping == 1) {\nc = clamp((c * (2.51 * c + 0.03)) / (c * (2.43 * c + 0.59) + 0.14), 0.0, 1.0);\n} else if (uToneMapping == 2) {\nfloat x = min(c.r, min(c.g, c.b));\nfloat offset = x < 0.08 ? x - 6.25 * x * x : 0.04;\nc -= offset;\nfloat peak = max(c.r, max(c.g, c.b));\nif (peak > 0.8) {\nfloat d = 0.2;\nfloat newPeak = 1.0 - d * d / (peak + d - 0.8);\nc *= newPeak / peak;\nfloat g = 1.0 - 1.0 / (0.15 * (peak - newPeak) + 1.0);\nc = mix(c, vec3(newPeak), g);\n}\n}\nreturn c;\n}\n", Zn = `layout(location = 0) in vec3 position;
3581
3776
  layout(location = 1) in vec3 normal;
3582
3777
  layout(location = 2) in vec2 uv;
3583
3778
  layout(location = 3) in vec3 color;
@@ -3585,10 +3780,17 @@ layout(location = 3) in vec3 color;
3585
3780
  layout(location = 4) in mat4 instanceMatrix;
3586
3781
  layout(location = 8) in vec3 instanceColor;
3587
3782
  #endif
3783
+ #ifdef ANISOTROPY
3784
+ layout(location = 9) in vec4 tangent;
3785
+ out vec4 vTangent;
3786
+ #endif
3787
+ #ifdef UV2
3788
+ layout(location = 10) in vec2 uv2;
3789
+ out vec2 vUv2;
3790
+ #endif
3588
3791
  uniform mat4 uModel;
3589
3792
  uniform mat3 uNormalMatrix;
3590
3793
  uniform mat4 uViewProjection;
3591
- uniform vec4 uUvTransform;
3592
3794
  uniform int uHighlightIndex;
3593
3795
  #ifdef FOG
3594
3796
  uniform mat4 uView;
@@ -3607,7 +3809,7 @@ out mat3 vObjectToWorld;
3607
3809
  #ifdef PICK
3608
3810
  flat out uint vPickElement;
3609
3811
  #endif
3610
- ${Hn}
3812
+ ${qn}
3611
3813
  void main() {
3612
3814
  vColor = vec3(1.0);
3613
3815
  vHighlight = uHighlightIndex == -1 ? 1.0 : 0.0;
@@ -3628,7 +3830,17 @@ vColor *= srgbToLinear(color);
3628
3830
  vec4 world = uModel * local;
3629
3831
  vWorldPosition = world.xyz;
3630
3832
  vNormal = uNormalMatrix * n;
3631
- vUv = uv * uUvTransform.xy + uUvTransform.zw;
3833
+ vUv = uv;
3834
+ #ifdef UV2
3835
+ vUv2 = uv2;
3836
+ #endif
3837
+ #ifdef ANISOTROPY
3838
+ #ifdef INSTANCED
3839
+ vTangent = vec4(mat3(uModel) * (m * tangent.xyz), tangent.w);
3840
+ #else
3841
+ vTangent = vec4(mat3(uModel) * tangent.xyz, tangent.w);
3842
+ #endif
3843
+ #endif
3632
3844
  #ifdef TRIPLANAR
3633
3845
  vObjectPosition = position;
3634
3846
  vObjectNormal = normal;
@@ -3646,7 +3858,7 @@ vFogDepth = -(uView * world).z;
3646
3858
  vPickElement = uint(gl_InstanceID);
3647
3859
  #endif
3648
3860
  }
3649
- `, qn = `precision highp float;
3861
+ `, Qn = `precision highp float;
3650
3862
  precision highp sampler2DShadow;
3651
3863
  precision highp samplerCubeShadow;
3652
3864
  in vec3 vWorldPosition;
@@ -3667,7 +3879,7 @@ uniform float uAlphaTest;
3667
3879
  #ifdef EMISSIVE_MAP
3668
3880
  uniform sampler2D uEmissiveMap;
3669
3881
  #endif
3670
- ${Bn}
3882
+ ${Gn}
3671
3883
  #ifdef LIT
3672
3884
  uniform vec3 uCameraPosition;
3673
3885
  uniform float uRoughness;
@@ -3690,6 +3902,38 @@ uniform float uBumpScale;
3690
3902
  uniform sampler2D uAoMap;
3691
3903
  uniform float uAoMapIntensity;
3692
3904
  #endif
3905
+ #ifdef LIGHT_MAP
3906
+ uniform sampler2D uLightMap;
3907
+ uniform float uLightMapIntensity;
3908
+ #endif
3909
+ uniform float uEnvStrength;
3910
+ #ifdef TRANSMISSION
3911
+ uniform float uTransmission;
3912
+ #endif
3913
+ #ifdef CLEARCOAT
3914
+ uniform float uClearcoat;
3915
+ uniform float uClearcoatRoughness;
3916
+ #endif
3917
+ uniform vec4 uSpecular;
3918
+ #ifdef MATCAP
3919
+ uniform sampler2D uMatcap;
3920
+ uniform mat4 uView;
3921
+ #endif
3922
+ #ifdef TOON
3923
+ uniform float uToon;
3924
+ #endif
3925
+ #ifdef SHEEN
3926
+ uniform vec3 uSheenColor;
3927
+ uniform float uSheenRoughness;
3928
+ #endif
3929
+ #ifdef ANISOTROPY
3930
+ uniform float uAnisotropy;
3931
+ uniform vec2 uAnisotropyDirection;
3932
+ in vec4 vTangent;
3933
+ #endif
3934
+ #ifdef TRANSLUCENCY
3935
+ uniform vec4 uTranslucency;
3936
+ #endif
3693
3937
  uniform vec3 uAmbient;
3694
3938
  uniform vec3 uHemisphereSky;
3695
3939
  uniform vec3 uHemisphereGround;
@@ -3733,10 +3977,10 @@ uniform float uPointShadowBias;
3733
3977
  #endif
3734
3978
  #endif
3735
3979
  out vec4 fragColor;
3980
+ ${qn}
3736
3981
  ${Hn}
3737
- ${Rn}
3738
- ${zn}
3739
- ${Gn}
3982
+ ${Un}
3983
+ ${Xn}
3740
3984
  #ifdef LIT
3741
3985
  const float PI = 3.14159265359;
3742
3986
  float D_GGX(float NoH, float a) {
@@ -3750,36 +3994,102 @@ float gv = NoL * sqrt(NoV * NoV * (1.0 - a2) + a2);
3750
3994
  float gl = NoV * sqrt(NoL * NoL * (1.0 - a2) + a2);
3751
3995
  return 0.5 / max(gv + gl, 1e-5);
3752
3996
  }
3753
- vec3 F_Schlick(float VoH, vec3 f0) {
3754
- return f0 + (1.0 - f0) * pow(1.0 - VoH, 5.0);
3997
+ vec3 F_Schlick(float VoH, vec3 f0, float f90) {
3998
+ return f0 + (f90 - f0) * pow(1.0 - VoH, 5.0);
3999
+ }
4000
+ #ifdef ANISOTROPY
4001
+ vec3 brushT, brushB;
4002
+ float brushAT, brushAB;
4003
+ float anisotropicDV(vec3 v, vec3 l, vec3 h, float NoV, float NoL, float NoH) {
4004
+ float a2 = brushAT * brushAB;
4005
+ vec3 f = vec3(brushAB * dot(brushT, h), brushAT * dot(brushB, h), a2 * NoH);
4006
+ float w2 = a2 / dot(f, f);
4007
+ float gv = NoL * length(vec3(brushAT * dot(brushT, v), brushAB * dot(brushB, v), NoV));
4008
+ float gl = NoV * length(vec3(brushAT * dot(brushT, l), brushAB * dot(brushB, l), NoL));
4009
+ return a2 * w2 * w2 / PI * 0.5 / max(gv + gl, 1e-5);
4010
+ }
4011
+ #endif
4012
+ #ifdef TOON
4013
+ vec3 toonHighlight;
4014
+ float toonTone(float x) {
4015
+ float steps = uToon - 1.0;
4016
+ float b = x * steps + 0.6;
4017
+ float w = fwidth(b);
4018
+ return min(floor(b) + smoothstep(1.0 - w, 1.0, fract(b)), steps) / steps;
4019
+ }
4020
+ vec3 toonShade(vec3 n, vec3 v, vec3 l, vec3 radiance, vec3 diffuse, float a) {
4021
+ float lit = toonTone(clamp(dot(n, l), 0.0, 1.0));
4022
+ float s = D_GGX(clamp(dot(n, normalize(l + v)), 0.0, 1.0), a) * PI * a * a;
4023
+ float w = fwidth(s);
4024
+ float spot = smoothstep(0.5 - w, 0.5 + w, s) * step(0.001, lit);
4025
+ return (diffuse * lit + toonHighlight * spot) * radiance;
3755
4026
  }
3756
- vec3 shade(vec3 n, vec3 v, vec3 l, vec3 radiance, vec3 diffuse, vec3 f0, float a) {
4027
+ #endif
4028
+ vec3 shade(vec3 n, vec3 v, vec3 l, vec3 radiance, vec3 diffuse, vec3 f0, float f90, float a) {
4029
+ #ifdef TOON
4030
+ return toonShade(n, v, l, radiance, diffuse, a);
4031
+ #endif
3757
4032
  float NoL = clamp(dot(n, l), 0.0, 1.0);
3758
4033
  if (NoL <= 0.0) return vec3(0.0);
3759
4034
  vec3 h = normalize(l + v);
3760
4035
  float NoV = clamp(abs(dot(n, v)), 1e-4, 1.0);
3761
4036
  float NoH = clamp(dot(n, h), 0.0, 1.0);
3762
4037
  float VoH = clamp(dot(v, h), 0.0, 1.0);
3763
- vec3 F = F_Schlick(VoH, f0);
4038
+ vec3 F = F_Schlick(VoH, f0, f90);
4039
+ #ifdef ANISOTROPY
4040
+ vec3 specular = anisotropicDV(v, l, h, NoV, NoL, NoH) * F * PI;
4041
+ #else
3764
4042
  vec3 specular = D_GGX(NoH, a) * V_SmithGGXCorrelated(NoV, NoL, a) * F * PI;
4043
+ #endif
3765
4044
  return (diffuse * (1.0 - F) + specular) * radiance * NoL;
3766
4045
  }
4046
+ #ifdef SHEEN
4047
+ vec3 sheenShade(vec3 n, vec3 v, vec3 l, vec3 radiance, float a) {
4048
+ float NoL = clamp(dot(n, l), 0.0, 1.0);
4049
+ if (NoL <= 0.0) return vec3(0.0);
4050
+ vec3 h = normalize(l + v);
4051
+ float NoV = clamp(abs(dot(n, v)), 1e-4, 1.0);
4052
+ float NoH = clamp(dot(n, h), 0.0, 1.0);
4053
+ float invA = 1.0 / a;
4054
+ float sin2h = max(1.0 - NoH * NoH, 0.0078125);
4055
+ float D = (2.0 + invA) * pow(sin2h, invA * 0.5) / (2.0 * PI);
4056
+ float V = clamp(1.0 / (4.0 * (NoL + NoV - NoL * NoV)), 0.0, 1.0);
4057
+ return uSheenColor * D * V * PI * radiance * NoL;
4058
+ }
4059
+ float sheenEnvironment(float NoV, float r) {
4060
+ float r2 = r * r;
4061
+ float a = r < 0.25 ? -339.2 * r2 + 161.4 * r - 25.9 : -8.48 * r2 + 14.3 * r - 9.95;
4062
+ float b = r < 0.25 ? 44.0 * r2 - 23.7 * r + 3.26 : 1.97 * r2 - 3.27 * r + 0.72;
4063
+ return min(exp(a * NoV + b) + (r < 0.25 ? 0.0 : 0.1 * (r - 0.25)), PI);
4064
+ }
4065
+ #endif
4066
+ #ifdef CLEARCOAT
4067
+ vec3 coatShade(vec3 n, vec3 v, vec3 l, vec3 radiance, float a) {
4068
+ float NoL = clamp(dot(n, l), 0.0, 1.0);
4069
+ if (NoL <= 0.0) return vec3(0.0);
4070
+ vec3 h = normalize(l + v);
4071
+ float NoV = clamp(abs(dot(n, v)), 1e-4, 1.0);
4072
+ float NoH = clamp(dot(n, h), 0.0, 1.0);
4073
+ float VoH = clamp(dot(v, h), 0.0, 1.0);
4074
+ return D_GGX(NoH, a) * V_SmithGGXCorrelated(NoV, NoL, a) * F_Schlick(VoH, vec3(0.04), 1.0) * PI * radiance * NoL;
4075
+ }
4076
+ #endif
3767
4077
  vec3 studio(vec3 d) {
3768
4078
  float up = d.y * 0.5 + 0.5;
3769
4079
  vec3 sky = mix(vec3(0.35, 0.36, 0.38), vec3(1.0), smoothstep(0.55, 0.95, up));
3770
4080
  vec3 floorColor = vec3(0.18, 0.17, 0.16);
3771
4081
  return mix(floorColor, sky, smoothstep(0.35, 0.55, up));
3772
4082
  }
3773
- vec3 envBRDF(vec3 f0, float roughness, float NoV) {
4083
+ vec3 envBRDF(vec3 f0, float f90, float roughness, float NoV) {
3774
4084
  vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);
3775
4085
  vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);
3776
4086
  vec4 r = roughness * c0 + c1;
3777
4087
  float a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;
3778
4088
  vec2 ab = vec2(-1.04, 1.04) * a004 + r.zw;
3779
- return f0 * ab.x + ab.y;
4089
+ return f0 * ab.x + ab.y * f90;
3780
4090
  }
3781
4091
  #ifdef ENV_MAP
3782
- ${Un}
4092
+ ${Jn}
3783
4093
  vec3 envIrradiance(vec3 n) {
3784
4094
  return uEnvSH[0]
3785
4095
  + uEnvSH[1] * n.y + uEnvSH[2] * n.z + uEnvSH[3] * n.x
@@ -3789,7 +4099,7 @@ return uEnvSH[0]
3789
4099
  #endif
3790
4100
  #ifdef BUMP_MAP
3791
4101
  vec3 bumpNormal(vec3 n) {
3792
- float h = SAMPLE(uBumpMap).r * uBumpScale;
4102
+ float h = uBumpMapTexel.r * uBumpScale;
3793
4103
  vec2 dh = vec2(dFdx(h), dFdy(h));
3794
4104
  vec3 sx = dFdx(vWorldPosition), sy = dFdy(vWorldPosition);
3795
4105
  vec3 r1 = cross(sy, n), r2 = cross(n, sx);
@@ -3801,9 +4111,9 @@ return normalize(abs(det) * n - grad);
3801
4111
  #if defined(NORMAL_MAP) && defined(TRIPLANAR)
3802
4112
  vec3 triplanarNormal(float strength) {
3803
4113
  vec3 n = normalize(vObjectNormal), p = vObjectPosition * uTriplanar, w = triplanarWeights(n);
3804
- vec3 tx = texture(uNormalMap, projected(p.zy)).xyz * 2.0 - 1.0;
3805
- vec3 ty = texture(uNormalMap, projected(p.xz)).xyz * 2.0 - 1.0;
3806
- vec3 tz = texture(uNormalMap, projected(p.xy)).xyz * 2.0 - 1.0;
4114
+ vec3 tx = texture(uNormalMap, projected(p.zy, uNormalMapUv)).xyz * 2.0 - 1.0;
4115
+ vec3 ty = texture(uNormalMap, projected(p.xz, uNormalMapUv)).xyz * 2.0 - 1.0;
4116
+ vec3 tz = texture(uNormalMap, projected(p.xy, uNormalMapUv)).xyz * 2.0 - 1.0;
3807
4117
  tx.xy *= strength; ty.xy *= strength; tz.xy *= strength;
3808
4118
  tx = vec3(tx.xy + n.zy, abs(tx.z) * n.x);
3809
4119
  ty = vec3(ty.xy + n.xz, abs(ty.z) * n.y);
@@ -3811,10 +4121,18 @@ tz = vec3(tz.xy + n.xy, abs(tz.z) * n.z);
3811
4121
  return normalize(vObjectToWorld * normalize(tx.zyx * w.x + ty.xzy * w.y + tz.xyz * w.z));
3812
4122
  }
3813
4123
  #endif
4124
+ #ifdef ANISOTROPY
4125
+ vec3 brushDirection(vec3 n) {
4126
+ vec3 t = vTangent.xyz - n * dot(n, vTangent.xyz);
4127
+ float len = length(t);
4128
+ t = len > 1e-6 ? t / len : normalize(cross(abs(n.y) < 0.999 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0), n));
4129
+ return t * uAnisotropyDirection.x + cross(n, t) * (vTangent.w < 0.0 ? -1.0 : 1.0) * uAnisotropyDirection.y;
4130
+ }
4131
+ #endif
3814
4132
  #ifdef NORMAL_MAP
3815
- vec3 perturbNormal(vec3 n, vec3 m) {
4133
+ vec3 perturbNormal(vec3 n, vec3 m, vec2 uv) {
3816
4134
  vec3 dp1 = dFdx(vWorldPosition), dp2 = dFdy(vWorldPosition);
3817
- vec2 duv1 = dFdx(vUv), duv2 = dFdy(vUv);
4135
+ vec2 duv1 = dFdx(uv), duv2 = dFdy(uv);
3818
4136
  vec3 dp2perp = cross(dp2, n), dp1perp = cross(n, dp1);
3819
4137
  vec3 t = dp2perp * duv1.x + dp1perp * duv2.x;
3820
4138
  vec3 b = dp2perp * duv1.y + dp1perp * duv2.y;
@@ -3870,20 +4188,48 @@ for (int y = -1; y <= 1; y++) lit += texture(uPointShadowMap, vec4(dir + (u * fl
3870
4188
  return lit / 9.0;
3871
4189
  }
3872
4190
  #endif
4191
+ #ifdef MATCAP
4192
+ vec3 matcapAt(vec3 n, vec3 v) {
4193
+ vec3 nv = normalize(mat3(uView) * n), vv = normalize(mat3(uView) * v);
4194
+ vec3 x = normalize(vec3(vv.z, 0.0, -vv.x));
4195
+ vec3 y = cross(vv, x);
4196
+ vec2 uv = vec2(dot(x, nv), dot(y, nv)) * 0.495 + 0.5;
4197
+ return texture(uMatcap, vec2(uv.x, 1.0 - uv.y)).rgb;
4198
+ }
4199
+ #endif
4200
+ vec3 irradianceAt(vec3 n) {
4201
+ vec3 e = uAmbient + mix(uHemisphereGround, uHemisphereSky, n.y * 0.5 + 0.5);
4202
+ #ifdef ENV_MAP
4203
+ e += envIrradiance(n) * uEnvIntensity * uEnvStrength;
4204
+ #elif defined(STUDIO)
4205
+ e += studio(n) * 0.35 * uEnvStrength;
4206
+ #endif
4207
+ return e;
4208
+ }
4209
+ vec3 reflected(vec3 r, vec3 n, float roughness, vec3 irradiance) {
4210
+ #ifdef ENV_MAP
4211
+ return textureLod(uEnvMap, equirectUv(r), roughness * uEnvMaxLod).rgb * uEnvIntensity * uEnvStrength;
4212
+ #elif defined(STUDIO)
4213
+ return mix(studio(r), studio(n), roughness * roughness) * uEnvStrength;
4214
+ #else
4215
+ return irradiance * 0.5;
4216
+ #endif
4217
+ }
3873
4218
  #endif
3874
4219
  void main() {
3875
4220
  clipAway(vWorldPosition);
3876
4221
  vec4 base = vec4(uColor * vColor, uOpacity);
3877
4222
  #ifdef MAP
3878
- base *= SAMPLE(uMap);
4223
+ base *= uMapTexel;
3879
4224
  #endif
3880
4225
  #ifdef ALPHA_TEST
3881
4226
  if (base.a < uAlphaTest) discard;
3882
4227
  base.a = 1.0;
3883
4228
  #endif
4229
+ float coverage = base.a;
3884
4230
  vec3 emissive = uEmissive;
3885
4231
  #ifdef EMISSIVE_MAP
3886
- emissive *= SAMPLE(uEmissiveMap).rgb;
4232
+ emissive *= uEmissiveMapTexel.rgb;
3887
4233
  #endif
3888
4234
  #ifdef LIT
3889
4235
  #ifdef FLAT_SHADING
@@ -3902,27 +4248,58 @@ n = triplanarNormal(uNormalScale);
3902
4248
  if (!gl_FrontFacing) n = -n;
3903
4249
  #endif
3904
4250
  #else
3905
- vec3 m = texture(uNormalMap, vUv).xyz * 2.0 - 1.0;
4251
+ vec2 normalUv = uNormalMapCoord;
4252
+ vec3 m = texture(uNormalMap, normalUv).xyz * 2.0 - 1.0;
3906
4253
  m.xy *= uNormalScale;
3907
- n = perturbNormal(n, m);
4254
+ n = perturbNormal(n, m, normalUv);
3908
4255
  #endif
3909
4256
  #endif
3910
4257
  #ifdef BUMP_MAP
3911
4258
  n = bumpNormal(n);
3912
4259
  #endif
3913
4260
  vec3 v = normalize(uCameraPosition - vWorldPosition);
4261
+ #ifdef MATCAP
4262
+ vec3 color = base.rgb * matcapAt(n, v) + emissive;
4263
+ #else
3914
4264
  float roughness = uRoughness;
3915
4265
  float metalness = uMetalness;
3916
4266
  #ifdef ROUGHNESS_MAP
3917
- roughness *= SAMPLE(uRoughnessMap).g;
4267
+ roughness *= uRoughnessMapTexel.g;
3918
4268
  #endif
3919
4269
  #ifdef METALNESS_MAP
3920
- metalness *= SAMPLE(uMetalnessMap).b;
4270
+ metalness *= uMetalnessMapTexel.b;
3921
4271
  #endif
3922
4272
  roughness = clamp(roughness, 0.04, 1.0);
3923
4273
  float a = roughness * roughness;
3924
4274
  vec3 diffuse = base.rgb * (1.0 - metalness);
3925
- vec3 f0 = mix(vec3(0.04), base.rgb, metalness);
4275
+ vec3 f0 = mix(uSpecular.rgb, base.rgb, metalness);
4276
+ float f90 = mix(uSpecular.a, 1.0, metalness);
4277
+ #ifdef TOON
4278
+ diffuse = base.rgb;
4279
+ toonHighlight = mix(vec3(uSpecular.a), base.rgb, metalness) * (1.0 - roughness);
4280
+ #endif
4281
+ #ifdef TRANSMISSION
4282
+ diffuse *= 1.0 - uTransmission;
4283
+ #endif
4284
+ #ifdef CLEARCOAT
4285
+ float coatRoughness = clamp(uClearcoatRoughness, 0.04, 1.0);
4286
+ float coatA = coatRoughness * coatRoughness;
4287
+ vec3 coat = vec3(0.0);
4288
+ #endif
4289
+ #ifdef SHEEN
4290
+ float sheenRoughness = clamp(uSheenRoughness, 0.07, 1.0);
4291
+ vec3 sheen = vec3(0.0);
4292
+ #endif
4293
+ #ifdef ANISOTROPY
4294
+ brushT = brushDirection(n);
4295
+ brushB = cross(n, brushT);
4296
+ brushAT = mix(a, 1.0, uAnisotropy * uAnisotropy);
4297
+ brushAB = max(a, 0.001);
4298
+ #endif
4299
+ #ifdef TRANSLUCENCY
4300
+ vec3 through = diffuse * uTranslucency.rgb;
4301
+ diffuse *= 1.0 - uTranslucency.a;
4302
+ #endif
3926
4303
  vec3 color = vec3(0.0);
3927
4304
  #if NUM_DIRECTIONAL > 0
3928
4305
  for (int i = 0; i < NUM_DIRECTIONAL; i++) {
@@ -3930,7 +4307,23 @@ vec3 radiance = uDirectionalColor[i];
3930
4307
  #ifdef SHADOW
3931
4308
  if (i == 0) radiance *= shadowAt(surfaceNormal, uDirectionalDirection[0]);
3932
4309
  #endif
3933
- color += shade(n, v, uDirectionalDirection[i], radiance, diffuse, f0, a);
4310
+ color += shade(n, v, uDirectionalDirection[i], radiance, diffuse, f0, f90, a);
4311
+ #ifdef CLEARCOAT
4312
+ coat += coatShade(surfaceNormal, v, uDirectionalDirection[i], radiance, coatA);
4313
+ #endif
4314
+ #ifdef SHEEN
4315
+ sheen += sheenShade(n, v, uDirectionalDirection[i], radiance, sheenRoughness * sheenRoughness);
4316
+ #endif
4317
+ #ifdef TRANSLUCENCY
4318
+ float behind = clamp(-dot(n, uDirectionalDirection[i]), 0.0, 1.0);
4319
+ if (behind > 0.0) {
4320
+ vec3 light = uDirectionalColor[i];
4321
+ #ifdef SHADOW
4322
+ if (i == 0) light *= shadowAt(-surfaceNormal, uDirectionalDirection[0]);
4323
+ #endif
4324
+ color += through * light * behind;
4325
+ }
4326
+ #endif
3934
4327
  }
3935
4328
  #endif
3936
4329
  #if NUM_PUNCTUAL > 0
@@ -3951,38 +4344,78 @@ if (tile >= 0.0 && cone > 0.0) radiance *= spotShadowAt(int(tile), surfaceNormal
3951
4344
  #ifdef POINT_SHADOW
3952
4345
  if (float(i) == uPointShadowIndex) radiance *= pointShadowAt(uPunctualPosition[i], surfaceNormal, d);
3953
4346
  #endif
3954
- color += shade(n, v, l, radiance, diffuse, f0, a);
4347
+ color += shade(n, v, l, radiance, diffuse, f0, f90, a);
4348
+ #ifdef CLEARCOAT
4349
+ coat += coatShade(surfaceNormal, v, l, radiance, coatA);
4350
+ #endif
4351
+ #ifdef SHEEN
4352
+ sheen += sheenShade(n, v, l, radiance, sheenRoughness * sheenRoughness);
4353
+ #endif
4354
+ #ifdef TRANSLUCENCY
4355
+ float behind = clamp(-dot(n, l), 0.0, 1.0);
4356
+ if (behind > 0.0) {
4357
+ vec3 light = uPunctualColor[i] * falloff * cone;
4358
+ #ifdef SPOT_SHADOWS
4359
+ if (tile >= 0.0 && cone > 0.0) light *= spotShadowAt(int(tile), -surfaceNormal, d);
4360
+ #endif
4361
+ #ifdef POINT_SHADOW
4362
+ if (float(i) == uPointShadowIndex) light *= pointShadowAt(uPunctualPosition[i], -surfaceNormal, d);
4363
+ #endif
4364
+ color += through * light * behind;
4365
+ }
4366
+ #endif
3955
4367
  }
3956
4368
  #endif
3957
- vec3 irradiance = uAmbient + mix(uHemisphereGround, uHemisphereSky, n.y * 0.5 + 0.5);
4369
+ vec3 irradiance = irradianceAt(n);
3958
4370
  float NoV = clamp(abs(dot(n, v)), 1e-4, 1.0);
3959
- vec3 brdf = envBRDF(f0, roughness, NoV);
3960
- vec3 ambientSpecular;
3961
- #ifdef ENV_MAP
3962
- irradiance += envIrradiance(n) * uEnvIntensity;
3963
- vec3 r = reflect(-v, n);
3964
- ambientSpecular = textureLod(uEnvMap, equirectUv(r), roughness * uEnvMaxLod).rgb * uEnvIntensity * brdf;
3965
- #elif defined(STUDIO)
3966
- irradiance += studio(n) * 0.35;
3967
- vec3 r = reflect(-v, n);
3968
- ambientSpecular = mix(studio(r), studio(n), roughness * roughness) * brdf;
4371
+ vec3 brdf = envBRDF(f0, f90, roughness, NoV);
4372
+ #ifdef ANISOTROPY
4373
+ vec3 brushNormal = cross(cross(brushB, v), brushB);
4374
+ float bend = 1.0 - uAnisotropy * (1.0 - roughness);
4375
+ bend *= bend;
4376
+ vec3 r = reflect(-v, normalize(mix(brushNormal, n, bend * bend)));
3969
4377
  #else
3970
- ambientSpecular = irradiance * brdf * 0.5;
4378
+ vec3 r = reflect(-v, n);
3971
4379
  #endif
4380
+ #ifdef TOON
4381
+ vec3 indirect = diffuse * 0.5 * (irradianceAt(vec3(0.0, 1.0, 0.0)) + irradianceAt(vec3(0.0, -1.0, 0.0)));
4382
+ #else
4383
+ vec3 ambientSpecular = reflected(r, n, roughness, irradiance) * brdf;
3972
4384
  vec3 indirect = diffuse * irradiance + ambientSpecular;
4385
+ #endif
4386
+ #ifdef TRANSLUCENCY
4387
+ indirect += through * irradianceAt(-n);
4388
+ #endif
4389
+ #ifdef LIGHT_MAP
4390
+ indirect += diffuse * uLightMapTexel.rgb * uLightMapIntensity;
4391
+ #endif
3973
4392
  #ifdef AO_MAP
3974
- indirect *= mix(1.0, SAMPLE(uAoMap).r, uAoMapIntensity);
4393
+ indirect *= mix(1.0, uAoMapTexel.r, uAoMapIntensity);
3975
4394
  #endif
3976
4395
  color += indirect + emissive;
4396
+ #ifdef SHEEN
4397
+ sheen += irradiance * uSheenColor * sheenEnvironment(NoV, sheenRoughness);
4398
+ color = color * (1.0 - 0.157 * max(uSheenColor.r, max(uSheenColor.g, uSheenColor.b))) + sheen;
4399
+ #endif
4400
+ #ifdef CLEARCOAT
4401
+ float coatNoV = clamp(abs(dot(surfaceNormal, v)), 1e-4, 1.0);
4402
+ coat += reflected(reflect(-v, surfaceNormal), surfaceNormal, coatRoughness, irradiance) * envBRDF(vec3(0.04), 1.0, coatRoughness, coatNoV);
4403
+ color = color * (1.0 - uClearcoat * F_Schlick(coatNoV, vec3(0.04), 1.0).x) + coat * uClearcoat;
4404
+ #endif
4405
+ #ifdef TRANSMISSION
4406
+ coverage *= mix(1.0, clamp(max(brdf.r, max(brdf.g, brdf.b)), 0.0, 1.0), uTransmission);
4407
+ #endif
3977
4408
  color = toneMap(color);
4409
+ #endif
3978
4410
  #else
3979
4411
  vec3 color = base.rgb + emissive;
3980
4412
  #endif
3981
4413
  color = mix(color, uHighlight.rgb, vHighlight * uHighlight.a);
4414
+ coverage = mix(coverage, base.a, vHighlight * uHighlight.a);
3982
4415
  color = fogged(color);
3983
- fragColor = vec4(linearToSrgb(color) * base.a, base.a);
4416
+ fragColor = vec4(linearToSrgb(color) * base.a, coverage);
3984
4417
  }
3985
- `, Jn = `layout(location = 0) in vec3 position;
4418
+ `, $n = `layout(location = 0) in vec3 position;
3986
4419
  layout(location = 3) in vec3 color;
3987
4420
  uniform mat4 uModel;
3988
4421
  uniform mat4 uView;
@@ -3998,7 +4431,7 @@ flat out uint vPickElement;
3998
4431
  #ifdef FOG
3999
4432
  out float vFogDepth;
4000
4433
  #endif
4001
- ${Hn}
4434
+ ${qn}
4002
4435
  void main() {
4003
4436
  vec4 viewPosition = uView * (uModel * vec4(position, 1.0));
4004
4437
  gl_Position = uProjection * viewPosition;
@@ -4020,7 +4453,7 @@ vHighlight = uHighlightIndex == -1 || gl_VertexID == uHighlightIndex ? 1.0 : 0.0
4020
4453
  vPickElement = uint(gl_VertexID);
4021
4454
  #endif
4022
4455
  }
4023
- `, Yn = `precision highp float;
4456
+ `, er = `precision highp float;
4024
4457
  in vec3 vColor;
4025
4458
  flat in float vHighlight;
4026
4459
  uniform vec4 uHighlight;
@@ -4030,8 +4463,8 @@ uniform float uOpacity;
4030
4463
  uniform sampler2D uMap;
4031
4464
  #endif
4032
4465
  out vec4 fragColor;
4033
- ${Hn}
4034
- ${zn}
4466
+ ${qn}
4467
+ ${Un}
4035
4468
  void main() {
4036
4469
  vec4 base = vec4(uColor * vColor, uOpacity);
4037
4470
  #ifdef MAP
@@ -4046,7 +4479,7 @@ if (base.a <= 0.0) discard;
4046
4479
  base.rgb = fogged(mix(base.rgb, uHighlight.rgb, vHighlight * uHighlight.a));
4047
4480
  fragColor = vec4(linearToSrgb(base.rgb) * base.a, base.a);
4048
4481
  }
4049
- `, Xn = `layout(location = 0) in vec3 segmentStart;
4482
+ `, tr = `layout(location = 0) in vec3 segmentStart;
4050
4483
  layout(location = 1) in vec3 segmentEnd;
4051
4484
  layout(location = 2) in vec3 segmentColorStart;
4052
4485
  layout(location = 3) in vec3 segmentColorEnd;
@@ -4064,7 +4497,7 @@ flat out uint vPickElement;
4064
4497
  #ifdef FOG
4065
4498
  out float vFogDepth;
4066
4499
  #endif
4067
- ${Hn}
4500
+ ${qn}
4068
4501
  void main() {
4069
4502
  vec4 a = uView * (uModel * vec4(segmentStart, 1.0));
4070
4503
  vec4 b = uView * (uModel * vec4(segmentEnd, 1.0));
@@ -4098,28 +4531,28 @@ vColor = vec3(1.0);
4098
4531
  vColor = srgbToLinear(mix(segmentColorStart, segmentColorEnd, corner.x));
4099
4532
  #endif
4100
4533
  }
4101
- `, Zn = `precision highp float;
4534
+ `, nr = `precision highp float;
4102
4535
  in vec3 vColor;
4103
4536
  uniform vec3 uColor;
4104
4537
  uniform float uOpacity;
4105
4538
  out vec4 fragColor;
4106
- ${Hn}
4107
- ${zn}
4539
+ ${qn}
4540
+ ${Un}
4108
4541
  void main() {
4109
4542
  vec3 color = fogged(uColor * vColor);
4110
4543
  fragColor = vec4(linearToSrgb(color) * uOpacity, uOpacity);
4111
4544
  }
4112
- `, Qn = {
4113
- mesh: [Kn, qn],
4114
- points: [Jn, Yn],
4115
- lines: [Xn, Zn]
4545
+ `, rr = {
4546
+ mesh: [Zn, Qn],
4547
+ points: [$n, er],
4548
+ lines: [tr, nr]
4116
4549
  };
4117
- function $n(e, t) {
4118
- let n = `#version 300 es\n${t.map((e) => `#define ${e}\n`).join("")}`, [r, i] = typeof e == "string" ? Qn[e] : e;
4550
+ function ir(e, t) {
4551
+ let n = `#version 300 es\n${t.map((e) => `#define ${e}\n`).join("")}`, [r, i] = typeof e == "string" ? rr[e] : e;
4119
4552
  return [n + r, n + i];
4120
4553
  }
4121
4554
  // src/webgl/programs.js
4122
- var er = class {
4555
+ var ar = class {
4123
4556
  #e = /* @__PURE__ */ new Map();
4124
4557
  #t;
4125
4558
  #n = null;
@@ -4136,7 +4569,7 @@ var er = class {
4136
4569
  }
4137
4570
  get(e, t, n) {
4138
4571
  let r = `${e}|${t.join(",")}`, i = this.#e.get(r);
4139
- return i || (i = this.#r(r, $n(n ?? e, t)), this.#e.set(r, i)), i;
4572
+ return i || (i = this.#r(r, ir(n ?? e, t)), this.#e.set(r, i)), i;
4140
4573
  }
4141
4574
  ready(e, t, n) {
4142
4575
  let r = this.get(e, t, n);
@@ -4176,18 +4609,18 @@ var er = class {
4176
4609
  #i(e) {
4177
4610
  let t = this.gl, { program: n, key: r, shaders: i, sources: a } = e;
4178
4611
  if (!t.getProgramParameter(n, t.LINK_STATUS) && !t.isContextLost()) throw i.forEach((e, n) => {
4179
- if (!t.getShaderParameter(e, t.COMPILE_STATUS)) throw Error(`phoria2: ${n ? "fragment" : "vertex"} shader '${r}' failed to compile:\n${t.getShaderInfoLog(e)}\n${nr(a[n])}`);
4612
+ if (!t.getShaderParameter(e, t.COMPILE_STATUS)) throw Error(`phoria2: ${n ? "fragment" : "vertex"} shader '${r}' failed to compile:\n${t.getShaderInfoLog(e)}\n${sr(a[n])}`);
4180
4613
  }), Error(`phoria2: shader program '${r}' failed to link: ${t.getProgramInfoLog(n)}`);
4181
4614
  for (let e of i) t.deleteShader(e);
4182
4615
  let o = /* @__PURE__ */ new Map(), s = t.getProgramParameter(n, t.ACTIVE_UNIFORMS), c = 0;
4183
4616
  for (let e = 0; e < s; e++) {
4184
4617
  let r = t.getActiveUniform(n, e), i = r.name.replace(/\[0\]$/, ""), a = t.getUniformLocation(n, r.name), s = r.type === t.SAMPLER_2D || r.type === t.SAMPLER_2D_SHADOW || r.type === t.SAMPLER_CUBE_SHADOW;
4185
- o.set(i, tr(t, r.type, a, s ? c++ : 0));
4618
+ o.set(i, or(t, r.type, a, s ? c++ : 0));
4186
4619
  }
4187
4620
  e.set = (e, t) => o.get(e)?.(t), e.ready = !0;
4188
4621
  }
4189
4622
  };
4190
- function tr(e, t, n, r) {
4623
+ function or(e, t, n, r) {
4191
4624
  switch (t) {
4192
4625
  case e.FLOAT: return (t) => typeof t == "number" ? e.uniform1f(n, t) : e.uniform1fv(n, t);
4193
4626
  case e.FLOAT_VEC2: return (t) => e.uniform2fv(n, t);
@@ -4208,19 +4641,56 @@ function tr(e, t, n, r) {
4208
4641
  default: return () => {};
4209
4642
  }
4210
4643
  }
4211
- var nr = (e) => e.split("\n").map((e, t) => `${String(t + 1).padStart(4)} ${e}`).join("\n"), rr = 15;
4212
- function ir(e, t, n) {
4644
+ var sr = (e) => e.split("\n").map((e, t) => `${String(t + 1).padStart(4)} ${e}`).join("\n"), cr = 15;
4645
+ function lr(e, t, n, r) {
4213
4646
  return [
4214
4647
  e.positions.length,
4215
4648
  n,
4216
4649
  e.uvs?.length,
4650
+ e.uvs2?.length,
4217
4651
  e.colors?.length,
4218
4652
  e.indices?.length,
4219
4653
  t?.instanceMatrices.length,
4220
- t?.instanceColors?.length
4654
+ t?.instanceColors?.length,
4655
+ r
4221
4656
  ].join();
4222
4657
  }
4223
- var ar = new Float32Array([
4658
+ function ur(e) {
4659
+ let t = e.positions, n = e.normals, r = e.uvs, i = t.length / 3, a = new Float32Array(i * 4), o = new Float32Array(i * 3), s = new Float32Array(i * 3);
4660
+ if (r) {
4661
+ let n = e.indices, a = (n ? n.length : i) / 3;
4662
+ for (let e = 0; e < a; e++) {
4663
+ let i = n ? n[e * 3] : e * 3, a = n ? n[e * 3 + 1] : e * 3 + 1, c = n ? n[e * 3 + 2] : e * 3 + 2, l = t[a * 3] - t[i * 3], u = t[a * 3 + 1] - t[i * 3 + 1], d = t[a * 3 + 2] - t[i * 3 + 2], f = t[c * 3] - t[i * 3], p = t[c * 3 + 1] - t[i * 3 + 1], m = t[c * 3 + 2] - t[i * 3 + 2], h = r[a * 2] - r[i * 2], g = r[a * 2 + 1] - r[i * 2 + 1], _ = r[c * 2] - r[i * 2], v = r[c * 2 + 1] - r[i * 2 + 1], y = h * v - _ * g;
4664
+ if (Math.abs(y) < 1e-12) continue;
4665
+ let b = 1 / y, x = (l * v - f * g) * b, S = (u * v - p * g) * b, C = (d * v - m * g) * b, w = (f * h - l * _) * b, T = (p * h - u * _) * b, E = (m * h - d * _) * b;
4666
+ for (let e of [
4667
+ i,
4668
+ a,
4669
+ c
4670
+ ]) o[e * 3] += x, o[e * 3 + 1] += S, o[e * 3 + 2] += C, s[e * 3] += w, s[e * 3 + 1] += T, s[e * 3 + 2] += E;
4671
+ }
4672
+ }
4673
+ for (let e = 0; e < i; e++) {
4674
+ let t = n[e * 3], r = n[e * 3 + 1], i = n[e * 3 + 2], c = o[e * 3], l = o[e * 3 + 1], u = o[e * 3 + 2], d = t * c + r * l + i * u;
4675
+ c -= t * d, l -= r * d, u -= i * d;
4676
+ let f = Math.hypot(c, l, u);
4677
+ if (f < 1e-9) {
4678
+ Math.abs(r) < .999 ? (c = i, l = 0, u = -t) : (c = 1, l = 0, u = 0);
4679
+ let e = t * c + r * l + i * u;
4680
+ c -= t * e, l -= r * e, u -= i * e, f = Math.hypot(c, l, u) || 1;
4681
+ }
4682
+ a[e * 4] = c / f, a[e * 4 + 1] = l / f, a[e * 4 + 2] = u / f;
4683
+ let p = r * u - i * l, m = i * c - t * u, h = t * l - r * c;
4684
+ a[e * 4 + 3] = p * s[e * 3] + m * s[e * 3 + 1] + h * s[e * 3 + 2] < 0 ? -1 : 1;
4685
+ }
4686
+ return a;
4687
+ }
4688
+ var dr = /* @__PURE__ */ new Float32Array(9);
4689
+ function fr(e) {
4690
+ let t = Math.cos(e.rotation), n = Math.sin(e.rotation), [r, i] = e.repeat, [a, o] = e.center, s = dr;
4691
+ return s[0] = t * r, s[1] = -n * r, s[2] = 0, s[3] = n * i, s[4] = t * i, s[5] = 0, s[6] = a - t * a - n * o + e.offset[0], s[7] = o + n * a - t * o + e.offset[1], s[8] = 1, s;
4692
+ }
4693
+ var pr = new Float32Array([
4224
4694
  0,
4225
4695
  -1,
4226
4696
  0,
@@ -4229,7 +4699,7 @@ var ar = new Float32Array([
4229
4699
  -1,
4230
4700
  1,
4231
4701
  1
4232
- ]), or = class {
4702
+ ]), mr = class {
4233
4703
  gl;
4234
4704
  #e = /* @__PURE__ */ new WeakMap();
4235
4705
  #t = /* @__PURE__ */ new WeakMap();
@@ -4255,60 +4725,60 @@ var ar = new Float32Array([
4255
4725
  max: this.gl.getParameter(e.MAX_TEXTURE_MAX_ANISOTROPY_EXT) || 1
4256
4726
  } : null, this.#s;
4257
4727
  }
4258
- mesh(e, t, n) {
4259
- let r = t ?? e;
4260
- this.#u(r);
4261
- let i = n ? this.#e : this.#t, a = i.get(r), o = a?.geometry === e;
4262
- if (a && o && a.version === e.version && (!t || a.instanceVersion === t.version)) return a;
4263
- let s = ir(e, t, n);
4264
- if (a && o && a.layout === s) {
4265
- if (a.version !== e.version) {
4266
- let t = a.attributes;
4267
- this.#l(t.position, e.positions), n && this.#l(t.normal, e.normals), e.uvs && this.#l(t.uv, e.uvs), e.colors && this.#l(t.color, e.colors), e.indices && (this.gl.bindVertexArray(a.vao), this.gl.bufferSubData(this.gl.ELEMENT_ARRAY_BUFFER, 0, e.indices), this.gl.bindVertexArray(null)), a.version = e.version;
4728
+ mesh(e, t, n, r = !1) {
4729
+ let i = t ?? e;
4730
+ this.#u(i);
4731
+ let a = n ? this.#e : this.#t, o = a.get(i), s = o?.geometry === e;
4732
+ if (r = n && (r || s && !!o?.attributes?.tangent), o && s && o.version === e.version && (!t || o.instanceVersion === t.version) && r === !!o.attributes?.tangent) return o;
4733
+ let c = lr(e, t, n, r);
4734
+ if (o && s && o.layout === c) {
4735
+ if (o.version !== e.version) {
4736
+ let t = o.attributes;
4737
+ this.#l(t.position, e.positions), n && this.#l(t.normal, e.normals), e.uvs && this.#l(t.uv, e.uvs), e.uvs2 && this.#l(t.uv2, e.uvs2), e.colors && this.#l(t.color, e.colors), r && this.#l(t.tangent, ur(e)), e.indices && (this.gl.bindVertexArray(o.vao), this.gl.bufferSubData(this.gl.ELEMENT_ARRAY_BUFFER, 0, e.indices), this.gl.bindVertexArray(null)), o.version = e.version;
4268
4738
  }
4269
- return t && a.instanceVersion !== t.version && (this.#l(a.matrixBuffer, t.instanceMatrices), t.instanceColors && this.#l(a.colorBuffer, t.instanceColors), a.instanceVersion = t.version), a;
4739
+ return t && o.instanceVersion !== t.version && (this.#l(o.matrixBuffer, t.instanceMatrices), t.instanceColors && this.#l(o.colorBuffer, t.instanceColors), o.instanceVersion = t.version), o;
4270
4740
  }
4271
- a ? (this.#p(a), o || (this.counts.geometries--, this.#f(e, r, i))) : this.#f(e, r, i);
4272
- let c = this.gl, l = c.createVertexArray();
4273
- c.bindVertexArray(l);
4274
- let u = [], d = (e, t, n, r = 0) => {
4275
- let i = c.createBuffer();
4276
- return c.bindBuffer(c.ARRAY_BUFFER, i), c.bufferData(c.ARRAY_BUFFER, t, c.STATIC_DRAW), c.enableVertexAttribArray(e), c.vertexAttribPointer(e, n, c.FLOAT, !1, 0, 0), r && c.vertexAttribDivisor(e, r), u.push(i), i;
4277
- }, f = {};
4278
- f.position = d(Z.position, e.positions, 3), n && (f.normal = d(Z.normal, e.normals, 3)), e.uvs ? f.uv = d(Z.uv, e.uvs, 2) : c.vertexAttrib2f(Z.uv, 0, 0), e.colors ? f.color = d(Z.color, e.colors, 3) : c.vertexAttrib3f(Z.color, 1, 1, 1);
4279
- let p = null, m = null;
4741
+ o ? (this.#p(o), s || (this.counts.geometries--, this.#f(e, i, a))) : this.#f(e, i, a);
4742
+ let l = this.gl, u = l.createVertexArray();
4743
+ l.bindVertexArray(u);
4744
+ let d = [], f = (e, t, n, r = 0) => {
4745
+ let i = l.createBuffer();
4746
+ return l.bindBuffer(l.ARRAY_BUFFER, i), l.bufferData(l.ARRAY_BUFFER, t, l.STATIC_DRAW), l.enableVertexAttribArray(e), l.vertexAttribPointer(e, n, l.FLOAT, !1, 0, 0), r && l.vertexAttribDivisor(e, r), d.push(i), i;
4747
+ }, p = {};
4748
+ p.position = f(Z.position, e.positions, 3), n && (p.normal = f(Z.normal, e.normals, 3)), e.uvs ? p.uv = f(Z.uv, e.uvs, 2) : l.vertexAttrib2f(Z.uv, 0, 0), e.uvs2 && (p.uv2 = f(Z.uv2, e.uvs2, 2)), e.colors ? p.color = f(Z.color, e.colors, 3) : l.vertexAttrib3f(Z.color, 1, 1, 1), r && (p.tangent = f(Z.tangent, ur(e), 4));
4749
+ let m = null, h = null;
4280
4750
  if (t) {
4281
- p = c.createBuffer(), c.bindBuffer(c.ARRAY_BUFFER, p), c.bufferData(c.ARRAY_BUFFER, t.instanceMatrices, c.STATIC_DRAW);
4751
+ m = l.createBuffer(), l.bindBuffer(l.ARRAY_BUFFER, m), l.bufferData(l.ARRAY_BUFFER, t.instanceMatrices, l.STATIC_DRAW);
4282
4752
  for (let e = 0; e < 4; e++) {
4283
4753
  let t = Z.instanceMatrix + e;
4284
- c.enableVertexAttribArray(t), c.vertexAttribPointer(t, 4, c.FLOAT, !1, 64, e * 16), c.vertexAttribDivisor(t, 1);
4754
+ l.enableVertexAttribArray(t), l.vertexAttribPointer(t, 4, l.FLOAT, !1, 64, e * 16), l.vertexAttribDivisor(t, 1);
4285
4755
  }
4286
- u.push(p), t.instanceColors ? m = d(Z.instanceColor, t.instanceColors, 3, 1) : c.vertexAttrib3f(Z.instanceColor, 1, 1, 1);
4756
+ d.push(m), t.instanceColors ? h = f(Z.instanceColor, t.instanceColors, 3, 1) : l.vertexAttrib3f(Z.instanceColor, 1, 1, 1);
4287
4757
  }
4288
- let h = 0;
4758
+ let g = 0;
4289
4759
  if (e.indices) {
4290
- let t = c.createBuffer();
4291
- c.bindBuffer(c.ELEMENT_ARRAY_BUFFER, t), c.bufferData(c.ELEMENT_ARRAY_BUFFER, e.indices, c.STATIC_DRAW), u.push(t), h = e.indices instanceof Uint32Array ? c.UNSIGNED_INT : c.UNSIGNED_SHORT;
4760
+ let t = l.createBuffer();
4761
+ l.bindBuffer(l.ELEMENT_ARRAY_BUFFER, t), l.bufferData(l.ELEMENT_ARRAY_BUFFER, e.indices, l.STATIC_DRAW), d.push(t), g = e.indices instanceof Uint32Array ? l.UNSIGNED_INT : l.UNSIGNED_SHORT;
4292
4762
  }
4293
- return c.bindVertexArray(null), a = {
4294
- vao: l,
4295
- buffers: u,
4763
+ return l.bindVertexArray(null), o = {
4764
+ vao: u,
4765
+ buffers: d,
4296
4766
  count: e.elementCount,
4297
- indexType: h,
4767
+ indexType: g,
4298
4768
  geometry: e,
4299
4769
  version: e.version,
4300
4770
  instanceVersion: t?.version ?? 0,
4301
- matrixBuffer: p,
4302
- colorBuffer: m,
4303
- attributes: f,
4304
- layout: s
4305
- }, i.set(r, a), a;
4306
- }
4307
- drawTriangles(e, t) {
4308
- let n = this.gl, r = this.mesh(e, t, !0);
4309
- n.bindVertexArray(r.vao);
4310
- let i = e.drawnCount - e.drawnCount % 3, a = t ? t.count : 1;
4311
- return r.indexType ? t ? n.drawElementsInstanced(n.TRIANGLES, i, r.indexType, 0, a) : n.drawElements(n.TRIANGLES, i, r.indexType, 0) : t ? n.drawArraysInstanced(n.TRIANGLES, 0, i, a) : n.drawArrays(n.TRIANGLES, 0, i), i / 3 * a;
4771
+ matrixBuffer: m,
4772
+ colorBuffer: h,
4773
+ attributes: p,
4774
+ layout: c
4775
+ }, a.set(i, o), o;
4776
+ }
4777
+ drawTriangles(e, t, n = !1) {
4778
+ let r = this.gl, i = this.mesh(e, t, !0, n);
4779
+ r.bindVertexArray(i.vao);
4780
+ let a = e.drawnCount - e.drawnCount % 3, o = t ? t.count : 1;
4781
+ return i.indexType ? t ? r.drawElementsInstanced(r.TRIANGLES, a, i.indexType, 0, o) : r.drawElements(r.TRIANGLES, a, i.indexType, 0) : t ? r.drawArraysInstanced(r.TRIANGLES, 0, a, o) : r.drawArrays(r.TRIANGLES, 0, a), a / 3 * o;
4312
4782
  }
4313
4783
  #l(e, t) {
4314
4784
  let n = this.gl;
@@ -4347,10 +4817,11 @@ var ar = new Float32Array([
4347
4817
  this.#u(e);
4348
4818
  let t = this.gl, n = this.#r.get(e);
4349
4819
  if (n && n.version === e.version) return n.texture;
4820
+ if (un(e.image) && e.image.readyState < 2) return n?.texture ?? this.#m();
4350
4821
  n || (n = {
4351
4822
  texture: t.createTexture(),
4352
4823
  version: -1
4353
- }, this.#r.set(e, n), this.counts.textures++, e.onDispose(() => this.#d(e))), t.activeTexture(t.TEXTURE0 + rr), t.bindTexture(t.TEXTURE_2D, n.texture), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, e.flipY), t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1);
4824
+ }, this.#r.set(e, n), this.counts.textures++, e.onDispose(() => this.#d(e))), t.activeTexture(t.TEXTURE0 + cr), t.bindTexture(t.TEXTURE_2D, n.texture), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, e.flipY), t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1);
4354
4825
  let r = e.image;
4355
4826
  if ("data" in r) {
4356
4827
  let n = r, i = n.data instanceof Float32Array, a = i ? t.RGBA16F : e.colorSpace === "srgb" ? t.SRGB8_ALPHA8 : t.RGBA8;
@@ -4427,7 +4898,7 @@ var ar = new Float32Array([
4427
4898
  #m() {
4428
4899
  if (this.#i) return this.#i;
4429
4900
  let e = this.gl;
4430
- return this.#i = e.createTexture(), e.activeTexture(e.TEXTURE0 + rr), e.bindTexture(e.TEXTURE_2D, this.#i), e.texImage2D(e.TEXTURE_2D, 0, e.RGBA8, 1, 1, 0, e.RGBA, e.UNSIGNED_BYTE, new Uint8Array([
4901
+ return this.#i = e.createTexture(), e.activeTexture(e.TEXTURE0 + cr), e.bindTexture(e.TEXTURE_2D, this.#i), e.texImage2D(e.TEXTURE_2D, 0, e.RGBA8, 1, 1, 0, e.RGBA, e.UNSIGNED_BYTE, new Uint8Array([
4431
4902
  255,
4432
4903
  255,
4433
4904
  255,
@@ -4437,9 +4908,9 @@ var ar = new Float32Array([
4437
4908
  #h() {
4438
4909
  if (this.#a) return this.#a;
4439
4910
  let e = this.gl;
4440
- return this.#a = e.createBuffer(), e.bindBuffer(e.ARRAY_BUFFER, this.#a), e.bufferData(e.ARRAY_BUFFER, ar, e.STATIC_DRAW), this.#a;
4911
+ return this.#a = e.createBuffer(), e.bindBuffer(e.ARRAY_BUFFER, this.#a), e.bufferData(e.ARRAY_BUFFER, pr, e.STATIC_DRAW), this.#a;
4441
4912
  }
4442
- }, sr = null, cr = class e {
4913
+ }, hr = null, gr = class e {
4443
4914
  canvas;
4444
4915
  gl;
4445
4916
  programs;
@@ -4458,8 +4929,8 @@ var ar = new Float32Array([
4458
4929
  #i;
4459
4930
  constructor(e, { antialias: t = !0, shared: n = !1 } = {}) {
4460
4931
  this.canvas = e, this.isShared = n;
4461
- let r = lr.get(e);
4462
- r && (clearTimeout(r.timer), lr.delete(e));
4932
+ let r = _r.get(e);
4933
+ r && (clearTimeout(r.timer), _r.delete(e));
4463
4934
  let i = e.getContext("webgl2", {
4464
4935
  antialias: t,
4465
4936
  alpha: !0,
@@ -4467,7 +4938,7 @@ var ar = new Float32Array([
4467
4938
  stencil: !0,
4468
4939
  powerPreference: "high-performance"
4469
4940
  });
4470
- i || E("WebGLRenderer", "WebGL 2 is not available in this browser or on this device"), this.gl = i, this.programs = new er(this.gl), this.resources = new or(this.gl);
4941
+ i || E("WebGLRenderer", "WebGL 2 is not available in this browser or on this device"), this.gl = i, this.programs = new ar(this.gl), this.resources = new mr(this.gl);
4471
4942
  let a = (e) => {
4472
4943
  e.preventDefault(), this.lost = !0;
4473
4944
  }, o = () => {
@@ -4479,11 +4950,11 @@ var ar = new Float32Array([
4479
4950
  }, r && i.isContextLost() && (this.lost = !0, r.lose?.restoreContext());
4480
4951
  }
4481
4952
  static shared() {
4482
- if (!sr) {
4953
+ if (!hr) {
4483
4954
  let t = typeof document < "u" ? document.createElement("canvas") : new OffscreenCanvas(1, 1);
4484
- sr = new e(t, { shared: !0 });
4955
+ hr = new e(t, { shared: !0 });
4485
4956
  }
4486
- return sr;
4957
+ return hr;
4487
4958
  }
4488
4959
  fit(e, t) {
4489
4960
  let n = this.canvas;
@@ -4524,60 +4995,64 @@ var ar = new Float32Array([
4524
4995
  if (this.users.delete(e), t && this.resources.release(e, t), this.users.size) return;
4525
4996
  this.programs.dispose(), this.resources.reset(), this.passes?.reset(), this.bloom?.dispose(), this.#i();
4526
4997
  let n = this.gl.getExtension("WEBGL_lose_context");
4527
- this === sr ? (n?.loseContext(), sr = null) : lr.set(this.canvas, {
4998
+ this === hr ? (n?.loseContext(), hr = null) : _r.set(this.canvas, {
4528
4999
  lose: n,
4529
5000
  timer: setTimeout(() => n?.loseContext())
4530
5001
  });
4531
5002
  }
4532
- }, lr = /* @__PURE__ */ new WeakMap(), ur = [
5003
+ }, _r = /* @__PURE__ */ new WeakMap(), vr = [
4533
5004
  "canvas",
4534
5005
  "shared",
4535
5006
  "antialias",
5007
+ "outlineAntialias",
4536
5008
  "toneMapping",
4537
5009
  "exposure",
4538
5010
  "pixelRatio",
4539
5011
  "bloom"
4540
- ], dr = {
5012
+ ], yr = {
4541
5013
  strength: 1,
4542
5014
  radius: .6,
4543
5015
  threshold: .6
4544
- }, fr = Object.keys(dr), pr = {
5016
+ }, br = Object.keys(yr), xr = {
4545
5017
  intensity: "use 'strength'",
4546
5018
  amount: "use 'strength'",
4547
5019
  size: "use 'radius'",
4548
5020
  blur: "use 'radius'"
4549
- }, mr = { alpha: "the canvas is always transparent where the scene has no background" };
4550
- function hr(e, t) {
5021
+ }, Sr = { alpha: "the canvas is always transparent where the scene has no background" };
5022
+ function Cr(e, t) {
4551
5023
  if (t == null || t === !1) return null;
4552
- if (t === !0) return { ...dr };
4553
- typeof t != "object" && E(e, `bloom is true, false or { strength, radius, threshold }, got ${j(t)}`), A(`${e} bloom`, t, fr, pr);
4554
- let n = { ...dr };
4555
- for (let r of Object.keys(dr)) t[r] !== void 0 && (n[r] = M(`${e} bloom`, r, t[r]));
5024
+ if (t === !0) return { ...yr };
5025
+ typeof t != "object" && E(e, `bloom is true, false or { strength, radius, threshold }, got ${j(t)}`), A(`${e} bloom`, t, br, xr);
5026
+ let n = { ...yr };
5027
+ for (let r of Object.keys(yr)) t[r] !== void 0 && (n[r] = M(`${e} bloom`, r, t[r]));
4556
5028
  return n;
4557
5029
  }
4558
- var gr = {
5030
+ var wr = {
4559
5031
  none: 0,
4560
5032
  aces: 1,
4561
5033
  neutral: 2
4562
- }, _r = [], vr = {
5034
+ }, Tr = [], Er = {
4563
5035
  roughnessMap: "ROUGHNESS_MAP",
4564
5036
  metalnessMap: "METALNESS_MAP",
4565
5037
  normalMap: "NORMAL_MAP",
4566
5038
  bumpMap: "BUMP_MAP",
4567
- aoMap: "AO_MAP"
4568
- }, yr = [
5039
+ aoMap: "AO_MAP",
5040
+ lightMap: "LIGHT_MAP"
5041
+ }, Dr = [
4569
5042
  "map",
4570
5043
  "emissiveMap",
4571
- ...Object.keys(vr)
4572
- ], br = {
5044
+ ...Object.keys(Er)
5045
+ ], Or = {
5046
+ matcap: "uMatcap",
4573
5047
  map: "uMap",
4574
5048
  roughnessMap: "uRoughnessMap",
4575
5049
  metalnessMap: "uMetalnessMap",
4576
5050
  normalMap: "uNormalMap",
4577
5051
  bumpMap: "uBumpMap",
4578
5052
  aoMap: "uAoMap",
4579
- emissiveMap: "uEmissiveMap"
4580
- }, xr = [Kn, Vn], Sr = new X({
5053
+ emissiveMap: "uEmissiveMap",
5054
+ lightMap: "uLightMap"
5055
+ }, kr = [Zn, Kn], Ar = new X({
4581
5056
  positions: [
4582
5057
  -1,
4583
5058
  0,
@@ -4624,18 +5099,19 @@ var gr = {
4624
5099
  3,
4625
5100
  2
4626
5101
  ]
4627
- }), Cr = {
5102
+ }), jr = {
4628
5103
  drawMode: "triangles",
4629
5104
  receiveShadow: !0,
4630
5105
  castShadow: !1,
4631
5106
  renderOrder: 0
4632
- }, wr = class {
4633
- static OPTIONS = ur;
4634
- static HINTS = mr;
5107
+ }, Mr = class {
5108
+ static OPTIONS = vr;
5109
+ static HINTS = Sr;
4635
5110
  canvas;
4636
5111
  toneMapping = "neutral";
4637
5112
  exposure = 1;
4638
5113
  pixelRatio = 1;
5114
+ outlineAntialias = !0;
4639
5115
  #e = null;
4640
5116
  info = {
4641
5117
  drawCalls: 0,
@@ -4657,22 +5133,22 @@ var gr = {
4657
5133
  #l = !1;
4658
5134
  #u = /* @__PURE__ */ new Map();
4659
5135
  constructor(e) {
4660
- if (A("WebGLRenderer", e, ur, mr), e?.canvas || E("WebGLRenderer", "'canvas' is required"), this.canvas = e.canvas, e.toneMapping !== void 0 && (this.toneMapping = P("WebGLRenderer", "toneMapping", e.toneMapping, [
5136
+ if (A("WebGLRenderer", e, vr, Sr), e?.canvas || E("WebGLRenderer", "'canvas' is required"), this.canvas = e.canvas, e.toneMapping !== void 0 && (this.toneMapping = P("WebGLRenderer", "toneMapping", e.toneMapping, [
4661
5137
  "aces",
4662
5138
  "neutral",
4663
5139
  "none"
4664
- ])), e.exposure !== void 0 && (this.exposure = N("WebGLRenderer", "exposure", e.exposure, 0)), e.pixelRatio !== void 0 && (this.pixelRatio = N("WebGLRenderer", "pixelRatio", e.pixelRatio, 0, Infinity, { above: !0 })), this.#e = hr("WebGLRenderer", e.bloom), e.shared) {
4665
- this.#t = cr.shared();
5140
+ ])), e.exposure !== void 0 && (this.exposure = N("WebGLRenderer", "exposure", e.exposure, 0)), e.pixelRatio !== void 0 && (this.pixelRatio = N("WebGLRenderer", "pixelRatio", e.pixelRatio, 0, Infinity, { above: !0 })), this.#e = Cr("WebGLRenderer", e.bloom), this.outlineAntialias = e.outlineAntialias === void 0 ? e.shared || e.antialias !== !1 : !!e.outlineAntialias, e.shared) {
5141
+ this.#t = gr.shared();
4666
5142
  let e = this.canvas.getContext("2d");
4667
5143
  e || E("WebGLRenderer", "a shared renderer's canvas needs a 2D context - give it a canvas that has no WebGL context yet"), this.#n = e;
4668
- } else this.#t = new cr(this.canvas, { antialias: e.antialias });
5144
+ } else this.#t = new gr(this.canvas, { antialias: e.antialias });
4669
5145
  this.#t.users.add(this);
4670
5146
  }
4671
5147
  get bloom() {
4672
5148
  return this.#e;
4673
5149
  }
4674
5150
  set bloom(e) {
4675
- this.#e = hr("WebGLRenderer", e);
5151
+ this.#e = Cr("WebGLRenderer", e);
4676
5152
  }
4677
5153
  get gl() {
4678
5154
  return this.#t.gl;
@@ -4699,20 +5175,20 @@ var gr = {
4699
5175
  e.spotShadows.length > 0 && c.spotShadowMaps(e.spotShadows),
4700
5176
  e.pointShadow && c.pointShadowMap(e.pointShadow)
4701
5177
  ].filter((e) => !!e) : [];
4702
- let l = c && e.outlines.length ? c.outlineMask(e.outlines, e, i, a, this.pixelRatio) : null, u = this.#e ? n.loadBloom() : null;
5178
+ let l = c && e.outlines.length ? c.outlineMask(e.outlines, e, i, a, this.pixelRatio, this.outlineAntialias) : null, u = this.#e ? n.loadBloom() : null;
4703
5179
  if (!u && n.bloom && ![...n.users].some((e) => e.bloom) && n.bloom.dispose(), u ? u.begin(i, a) : (r.bindFramebuffer(r.FRAMEBUFFER, null), r.viewport(0, 0, i, a)), s && "getHex" in s) {
4704
5180
  let [e, t, n] = s.toSRGB();
4705
5181
  r.clearColor(e, t, n, 1);
4706
5182
  } else r.clearColor(0, 0, 0, 0);
4707
5183
  r.depthMask(!0), r.enable(r.SCISSOR_TEST), r.scissor(0, 0, i, a), r.clear(r.COLOR_BUFFER_BIT | r.DEPTH_BUFFER_BIT), r.disable(r.SCISSOR_TEST), c && s && !("getHex" in s) && s.image && c.background(e, s, {
4708
5184
  exposure: this.exposure,
4709
- toneMapping: gr[this.toneMapping]
5185
+ toneMapping: wr[this.toneMapping]
4710
5186
  }), r.enable(r.DEPTH_TEST), r.depthFunc(r.LEQUAL), this.#d(e), r.disable(r.BLEND);
4711
5187
  for (let t of e.opaque) this.#f(t, e, !1);
4712
5188
  for (let t of e.caps) this.#p(t, e, i, a);
4713
5189
  r.enable(r.BLEND);
4714
5190
  for (let t of e.transparent) this.#f(t, e, !0);
4715
- if (l && c && c.outlineComposite(l, a), r.depthMask(!0), r.disable(r.BLEND), r.bindVertexArray(null), u && this.#e && u.end(this.#e), this.info.compiling && n.whenCompiled(), this.#n) {
5191
+ if (l && c && c.outlineComposite(l), r.depthMask(!0), r.disable(r.BLEND), r.bindVertexArray(null), u && this.#e && u.end(this.#e), this.info.compiling && n.whenCompiled(), this.#n) {
4716
5192
  let e = this.#n, t = n.canvas;
4717
5193
  e.globalCompositeOperation = "copy", e.drawImage(t, 0, t.height - a, i, a, 0, 0, i, a);
4718
5194
  }
@@ -4788,7 +5264,7 @@ var gr = {
4788
5264
  };
4789
5265
  }
4790
5266
  #f(e, t, n) {
4791
- let r = this.gl, { node: i, geometry: a, material: s, worldMatrix: c, instances: l } = e, u = i.drawMode, d = u === "points" ? "points" : u === "lines" ? "lines" : "mesh", f = d === "mesh" && i.receiveShadow && !s.unlit ? this.#i : _r, p = d === "mesh" ? e.clip : null, m = this.#h(d, s, a.colors !== null, !!l);
5267
+ let r = this.gl, { node: i, geometry: a, material: s, worldMatrix: c, instances: l } = e, u = i.drawMode, d = u === "points" ? "points" : u === "lines" ? "lines" : "mesh", f = d === "mesh" && i.receiveShadow && !s.unlit ? this.#i : Tr, p = d === "mesh" ? e.clip : null, m = this.#h(d, s, a.colors !== null, !!l, a.uvs2 !== null);
4792
5268
  for (let e of f) m.push(e.define);
4793
5269
  let h = s.fog ? t.fog : null;
4794
5270
  h && (m.push("FOG"), h.linear && m.push("FOG_LINEAR"), s.blending === "additive" ? m.push("FOG_ADD") : s.blending === "multiply" && m.push("FOG_MULTIPLY")), p && m.push("CLIP");
@@ -4800,7 +5276,7 @@ var gr = {
4800
5276
  }
4801
5277
  g.ready(d, m);
4802
5278
  }
4803
- if (r.useProgram(_.program), _.frame !== this.#t.frame && (_.frame = this.#t.frame, _.set("uView", t.camera.view), _.set("uProjection", t.camera.projection), _.set("uViewProjection", t.camera.viewProjection), _.set("uCameraPosition", t.camera.position), _.set("uExposure", this.exposure), _.set("uToneMapping", gr[this.toneMapping]), _.set("uResolution", [this.canvas.width, this.canvas.height]), _.set("uNear", t.camera.near), _.set("uScale", t.camera.projection[5] * this.canvas.height / 2), d === "mesh" && !s.unlit)) {
5279
+ if (r.useProgram(_.program), _.frame !== this.#t.frame && (_.frame = this.#t.frame, _.set("uView", t.camera.view), _.set("uProjection", t.camera.projection), _.set("uViewProjection", t.camera.viewProjection), _.set("uCameraPosition", t.camera.position), _.set("uExposure", this.exposure), _.set("uToneMapping", wr[this.toneMapping]), _.set("uResolution", [this.canvas.width, this.canvas.height]), _.set("uNear", t.camera.near), _.set("uScale", t.camera.projection[5] * this.canvas.height / 2), d === "mesh" && !s.unlit)) {
4804
5280
  for (let [e, t] of Object.entries(this.#o)) _.set(e, t);
4805
5281
  let e = this.#r;
4806
5282
  e && (_.set("uEnvMaxLod", e.maxLod), _.set("uEnvSH", e.sh), _.set("uEnvIntensity", t.environmentIntensity));
@@ -4823,21 +5299,35 @@ var gr = {
4823
5299
  y[0] * b,
4824
5300
  y[1] * b,
4825
5301
  y[2] * b
4826
- ]), _.set("uRoughness", s.roughness), _.set("uMetalness", s.metalness), _.set("uNormalScale", s.normalScale), s.bumpMap && _.set("uBumpScale", s.bumpScale), s.triplanar > 0 && _.set("uTriplanar", s.triplanar), _.set("uAoMapIntensity", s.aoMapIntensity), _.set("uAlphaTest", s.alphaTest);
4827
- let x = d === "mesh" ? s.textures : s.map ? [["map", s.map]] : [], S = x.map(([e, t]) => [br[e], this.#t.resources.texture(t)]);
4828
- for (let [e, t] of S) _.set(e, t);
4829
- let C = x[0]?.[1];
4830
- if (_.set("uUvTransform", C ? [
4831
- C.repeat[0],
4832
- C.repeat[1],
4833
- C.offset[0],
4834
- C.offset[1]
4835
- ] : [
4836
- 1,
4837
- 1,
4838
- 0,
4839
- 0
4840
- ]), r.depthMask(!n && s.depthWrite), s.depthTest ? r.enable(r.DEPTH_TEST) : r.disable(r.DEPTH_TEST), n && (s.blending === "additive" ? r.blendFunc(r.ONE, r.ONE) : s.blending === "multiply" ? r.blendFunc(r.DST_COLOR, r.ONE_MINUS_SRC_ALPHA) : r.blendFunc(r.ONE, r.ONE_MINUS_SRC_ALPHA)), d === "lines") {
5302
+ ]), _.set("uRoughness", s.roughness), _.set("uMetalness", s.metalness), _.set("uNormalScale", s.normalScale), s.bumpMap && _.set("uBumpScale", s.bumpScale), s.triplanar > 0 && _.set("uTriplanar", s.triplanar), _.set("uAoMapIntensity", s.aoMapIntensity), s.transmission > 0 && _.set("uTransmission", s.transmission), s.clearcoat > 0 && (_.set("uClearcoat", s.clearcoat), _.set("uClearcoatRoughness", s.clearcoatRoughness));
5303
+ let x = (s.ior - 1) / (s.ior + 1), S = s.specularColor, C = s.specularIntensity;
5304
+ if (_.set("uSpecular", [
5305
+ Math.min(x * x * S[0], 1) * C,
5306
+ Math.min(x * x * S[1], 1) * C,
5307
+ Math.min(x * x * S[2], 1) * C,
5308
+ C
5309
+ ]), s.sheen > 0) {
5310
+ let e = s.sheenColor, t = s.sheen;
5311
+ _.set("uSheenColor", [
5312
+ e[0] * t,
5313
+ e[1] * t,
5314
+ e[2] * t
5315
+ ]), _.set("uSheenRoughness", s.sheenRoughness);
5316
+ }
5317
+ if (s.anisotropy > 0 && (_.set("uAnisotropy", s.anisotropy), _.set("uAnisotropyDirection", [Math.cos(s.anisotropyRotation), Math.sin(s.anisotropyRotation)])), s.translucency > 0) {
5318
+ let e = s.translucencyColor, t = s.translucency;
5319
+ _.set("uTranslucency", [
5320
+ e[0] * t,
5321
+ e[1] * t,
5322
+ e[2] * t,
5323
+ t
5324
+ ]);
5325
+ }
5326
+ s.toon > 0 && _.set("uToon", Math.max(2, Math.round(s.toon))), _.set("uAlphaTest", s.alphaTest);
5327
+ let w = d === "mesh" ? s.textures : s.map ? [["map", s.map]] : [], T = w.map(([e, t]) => [Or[e], this.#t.resources.texture(t)]);
5328
+ for (let [e, t] of T) _.set(e, t);
5329
+ for (let [e, t] of w) e !== "matcap" && _.set(`${Or[e]}Uv`, fr(t));
5330
+ if (s.lightMap && _.set("uLightMapIntensity", s.lightMapIntensity), _.set("uEnvStrength", s.environmentIntensity), r.depthMask(!n && s.depthWrite), s.depthTest ? r.enable(r.DEPTH_TEST) : r.disable(r.DEPTH_TEST), n && (s.blending === "additive" ? r.blendFunc(r.ONE, r.ONE) : s.blending === "multiply" ? r.blendFunc(r.DST_COLOR, r.ONE_MINUS_SRC_ALPHA) : r.blendFunc(r.ONE, r.ONE_MINUS_SRC_ALPHA)), d === "lines") {
4841
5331
  r.disable(r.CULL_FACE), _.set("uWidth", s.width * this.pixelRatio);
4842
5332
  let e = this.#t.resources.lines(a);
4843
5333
  r.bindVertexArray(e.vao), r.drawArraysInstanced(r.TRIANGLE_STRIP, 0, 4, Math.min(e.count, Math.floor(a.drawnCount / 2))), this.info.drawCalls++;
@@ -4845,16 +5335,16 @@ var gr = {
4845
5335
  r.disable(r.CULL_FACE), _.set("uSize", s.sizeAttenuation ? s.size : s.size * this.pixelRatio);
4846
5336
  let e = this.#t.resources.mesh(a, null, !1);
4847
5337
  r.bindVertexArray(e.vao), r.drawArrays(r.POINTS, 0, a.drawnVertices), this.info.drawCalls++;
4848
- } else et(this.#a, c) || $e(this.#a), _.set("uNormalMatrix", this.#a), r.frontFace(o(c) < 0 ? r.CW : r.CCW), s.doubleSided ? r.disable(r.CULL_FACE) : (r.enable(r.CULL_FACE), r.cullFace(r.BACK)), r.enable(r.POLYGON_OFFSET_FILL), r.polygonOffset(1, 2), this.info.triangles += this.#t.resources.drawTriangles(a, l), r.disable(r.POLYGON_OFFSET_FILL), this.info.drawCalls++;
5338
+ } else et(this.#a, c) || $e(this.#a), _.set("uNormalMatrix", this.#a), r.frontFace(o(c) < 0 ? r.CW : r.CCW), s.doubleSided ? r.disable(r.CULL_FACE) : (r.enable(r.CULL_FACE), r.cullFace(r.BACK)), r.enable(r.POLYGON_OFFSET_FILL), r.polygonOffset(1, 2), this.info.triangles += this.#t.resources.drawTriangles(a, l, s.anisotropy > 0 && !s.unlit), r.disable(r.POLYGON_OFFSET_FILL), this.info.drawCalls++;
4849
5339
  }
4850
5340
  #p(e, t, n, r) {
4851
- let i = this.gl, a = this.#t.programs, s = [!1, !0].map((e) => a.get("clip-mask", e ? ["INSTANCED", "CLIP"] : ["CLIP"], xr));
5341
+ let i = this.gl, a = this.#t.programs, s = [!1, !0].map((e) => a.get("clip-mask", e ? ["INSTANCED", "CLIP"] : ["CLIP"], kr));
4852
5342
  if (!s.every((e) => a.isReady(e))) {
4853
5343
  if (!this.#s) {
4854
5344
  this.info.compiling++;
4855
5345
  return;
4856
5346
  }
4857
- for (let e of [!1, !0]) a.ready("clip-mask", e ? ["INSTANCED", "CLIP"] : ["CLIP"], xr);
5347
+ for (let e of [!1, !0]) a.ready("clip-mask", e ? ["INSTANCED", "CLIP"] : ["CLIP"], kr);
4858
5348
  }
4859
5349
  i.enable(i.STENCIL_TEST), i.enable(i.SCISSOR_TEST), i.scissor(0, 0, n, r), i.clearStencil(0), i.clear(i.STENCIL_BUFFER_BIT), i.disable(i.SCISSOR_TEST), i.colorMask(!1, !1, !1, !1), i.depthMask(!1), i.disable(i.DEPTH_TEST), i.disable(i.CULL_FACE), i.stencilFunc(i.ALWAYS, 0, 255), i.stencilOpSeparate(i.BACK, i.KEEP, i.KEEP, i.INCR_WRAP), i.stencilOpSeparate(i.FRONT, i.KEEP, i.KEEP, i.DECR_WRAP);
4860
5350
  for (let n of e.items) {
@@ -4865,7 +5355,7 @@ var gr = {
4865
5355
  }
4866
5356
  #m(e) {
4867
5357
  let t = e.color.getHex(), n = this.#u.get(t);
4868
- n || this.#u.set(t, n = new Fn({
5358
+ n || this.#u.set(t, n = new zn({
4869
5359
  color: e.color.getStyle(),
4870
5360
  roughness: .6
4871
5361
  }));
@@ -4898,8 +5388,8 @@ var gr = {
4898
5388
  1
4899
5389
  ]);
4900
5390
  return {
4901
- node: Cr,
4902
- geometry: Sr,
5391
+ node: jr,
5392
+ geometry: Ar,
4903
5393
  material: n,
4904
5394
  worldMatrix: g,
4905
5395
  instances: null,
@@ -4907,19 +5397,21 @@ var gr = {
4907
5397
  clip: null
4908
5398
  };
4909
5399
  }
4910
- #h(e, t, n, r) {
4911
- let i = [];
4912
- if (t.vertexColors && n && i.push("VERTEX_COLORS"), e === "mesh") {
5400
+ #h(e, t, n, r, i) {
5401
+ let a = [];
5402
+ if (t.vertexColors && n && a.push("VERTEX_COLORS"), e === "mesh") {
4913
5403
  if (!t.unlit) {
4914
- i.push("LIT");
4915
- for (let [e, n] of Object.entries(vr)) t[e] && i.push(n);
4916
- i.push(...this.#c), this.#r ? i.push("ENV_MAP") : this.#l && i.push("STUDIO");
5404
+ a.push("LIT");
5405
+ for (let [e, n] of Object.entries(Er)) t[e] && a.push(n);
5406
+ a.push(...this.#c), this.#r ? a.push("ENV_MAP") : this.#l && a.push("STUDIO"), t.transmission > 0 && a.push("TRANSMISSION"), t.clearcoat > 0 && a.push("CLEARCOAT"), t.sheen > 0 && a.push("SHEEN"), t.anisotropy > 0 && a.push("ANISOTROPY"), t.translucency > 0 && a.push("TRANSLUCENCY"), t.matcap && a.push("MATCAP"), t.toon > 0 && a.push("TOON");
4917
5407
  }
4918
- t.map && i.push("MAP"), t.emissiveMap && i.push("EMISSIVE_MAP"), t.alphaTest > 0 && i.push("ALPHA_TEST"), t.flatShading && i.push("FLAT_SHADING"), t.doubleSided && i.push("DOUBLE_SIDED"), t.triplanar > 0 && yr.some((e) => t[e]) && i.push("TRIPLANAR"), r && i.push("INSTANCED");
4919
- } else e === "points" && (t.map && i.push("MAP"), t.sizeAttenuation && i.push("SIZE_ATTENUATION"));
4920
- return i;
5408
+ t.map && a.push("MAP"), t.emissiveMap && a.push("EMISSIVE_MAP"), t.alphaTest > 0 && a.push("ALPHA_TEST"), t.flatShading && a.push("FLAT_SHADING"), t.doubleSided && a.push("DOUBLE_SIDED"), t.triplanar > 0 && Dr.some((e) => t[e]) && a.push("TRIPLANAR");
5409
+ let e = i ? t.textures.filter(([e, t]) => t.uvSet === 1 && e !== "matcap") : [];
5410
+ e.length && a.push("UV2", ...e.map(([e]) => `${Or[e]}Set vUv2`)), r && a.push("INSTANCED");
5411
+ } else e === "points" && (t.map && a.push("MAP"), t.sizeAttenuation && a.push("SIZE_ATTENUATION"));
5412
+ return a;
4921
5413
  }
4922
- }, Tr = [
5414
+ }, Nr = [
4923
5415
  "canvas",
4924
5416
  "scene",
4925
5417
  "camera",
@@ -4931,13 +5423,14 @@ var gr = {
4931
5423
  "tooltip",
4932
5424
  "pixelRatio",
4933
5425
  "antialias",
5426
+ "outlineAntialias",
4934
5427
  "context",
4935
5428
  "toneMapping",
4936
5429
  "exposure",
4937
5430
  "bloom",
4938
5431
  "autoLight",
4939
5432
  "maxDelta"
4940
- ], Er = ["keep", "aspect"], Dr = {
5433
+ ], Pr = ["keep", "aspect"], Fr = {
4941
5434
  renderer: "the View makes its renderer - read it from view.renderer",
4942
5435
  controls: "use orbit: true (or orbit options); the control is then view.controls",
4943
5436
  container: "use canvas: an element or selector (a full-window canvas is made when omitted)",
@@ -4947,7 +5440,7 @@ var gr = {
4947
5440
  keep: "use framing: { keep: 'width' | 'height' | 'both' }",
4948
5441
  fit: "use framing: { keep: 'both' } to keep everything framed in view as the canvas changes shape",
4949
5442
  aspect: "the canvas sets the aspect; framing: { aspect } says which shape the camera was set up for"
4950
- }, Or = {
5443
+ }, Ir = {
4951
5444
  mouseover: "hover",
4952
5445
  mouseenter: "hover",
4953
5446
  mousemove: "hover",
@@ -4961,10 +5454,10 @@ var gr = {
4961
5454
  select: "click",
4962
5455
  pointerdown: "click",
4963
5456
  mousedown: "click"
4964
- }, kr = .45, Ar = 4, jr = 5e3, Mr = 0, Nr = class {
4965
- static OPTIONS = Tr;
4966
- static HINTS = Dr;
4967
- static FRAMING_OPTIONS = Er;
5457
+ }, Lr = .45, Rr = 4, zr = 5e3, Br = 0, Vr = class {
5458
+ static OPTIONS = Nr;
5459
+ static HINTS = Fr;
5460
+ static FRAMING_OPTIONS = Pr;
4968
5461
  canvas;
4969
5462
  scene;
4970
5463
  #e;
@@ -5016,12 +5509,12 @@ var gr = {
5016
5509
  #I = null;
5017
5510
  #L = null;
5018
5511
  #R = null;
5019
- #z = new bn({
5512
+ #z = new Cn({
5020
5513
  sky: "#ffffff",
5021
5514
  ground: "#444444",
5022
5515
  intensity: .5
5023
5516
  });
5024
- #B = new Sn({
5517
+ #B = new Tn({
5025
5518
  direction: [
5026
5519
  -.5,
5027
5520
  -1,
@@ -5031,7 +5524,7 @@ var gr = {
5031
5524
  });
5032
5525
  #V = !1;
5033
5526
  constructor(e = {}) {
5034
- A("View", e, Tr, Dr), this.canvas = Kr(e.canvas), this.#a = e.canvas === void 0, e.scene === void 0 ? this.scene = new mn() : e.scene instanceof mn ? this.scene = e.scene : E("View", `'scene' must be a Scene${e.scene && typeof e.scene == "object" && "type" in e.scene ? " - build one from a description with create({ type: 'scene', ... })" : `, got ${j(e.scene)}`}`), e.background !== void 0 && (this.scene.background = e.background), e.camera instanceof Dt ? this.#e = e.camera : typeof e.camera == "string" ? (this.#e = Nt(e.camera), this.#m = !0) : e.camera === void 0 ? (this.#e = Nt("perspective"), this.#m = !0) : this.#e = new Ot({
5527
+ A("View", e, Nr, Fr), this.canvas = ei(e.canvas), this.#a = e.canvas === void 0, e.scene === void 0 ? this.scene = new _n() : e.scene instanceof _n ? this.scene = e.scene : E("View", `'scene' must be a Scene${e.scene && typeof e.scene == "object" && "type" in e.scene ? " - build one from a description with create({ type: 'scene', ... })" : `, got ${j(e.scene)}`}`), e.background !== void 0 && (this.scene.background = e.background), e.camera instanceof Dt ? this.#e = e.camera : typeof e.camera == "string" ? (this.#e = Nt(e.camera), this.#m = !0) : e.camera === void 0 ? (this.#e = Nt("perspective"), this.#m = !0) : this.#e = new Ot({
5035
5528
  position: [
5036
5529
  0,
5037
5530
  1.5,
@@ -5043,22 +5536,23 @@ var gr = {
5043
5536
  0
5044
5537
  ],
5045
5538
  ...e.camera
5046
- }), this.#m && (this.#h = Pr(this.#e));
5539
+ }), this.#m && (this.#h = Hr(this.#e));
5047
5540
  let t = e.context === void 0 ? "auto" : P("View", "context", e.context, [
5048
5541
  "auto",
5049
5542
  "own",
5050
5543
  "shared"
5051
5544
  ]);
5052
5545
  e.exposure !== void 0 && N("View", "exposure", e.exposure, 0);
5053
- let n = t === "shared" || t === "auto" && Mr >= Ar;
5054
- if (this.renderer = new wr({
5546
+ let n = t === "shared" || t === "auto" && Br >= Rr;
5547
+ if (this.renderer = new Mr({
5055
5548
  canvas: this.canvas,
5056
5549
  shared: n,
5057
5550
  antialias: e.antialias,
5551
+ outlineAntialias: e.outlineAntialias,
5058
5552
  toneMapping: e.toneMapping,
5059
5553
  exposure: e.exposure,
5060
5554
  bloom: e.bloom
5061
- }), n || (this.#i = !0, Mr++), this.renderer.onReady = () => {
5555
+ }), n || (this.#i = !0, Br++), this.renderer.onReady = () => {
5062
5556
  this.#A = !0, this.invalidate();
5063
5557
  }, e.autoLight !== void 0 && (this.autoLight = !!e.autoLight), e.maxDelta !== void 0 && (this.maxDelta = N("View", "maxDelta", e.maxDelta, 0, Infinity, { above: !0 })), e.renderMode !== void 0 && (this.renderMode = P("View", "renderMode", e.renderMode, [
5064
5558
  "auto",
@@ -5072,11 +5566,11 @@ var gr = {
5072
5566
  } : t), this.#P = this.controls.handOverPointer();
5073
5567
  }
5074
5568
  if (e.highlight !== void 0 && this.#H(e.highlight), e.tooltip !== void 0 && this.tooltip(e.tooltip), this.#x = new Ke(this.canvas, {
5075
- interactive: (e) => Wr(e, "click").length > 0 || Wr(e, "hover").length > 0,
5569
+ interactive: (e) => Qr(e, "click").length > 0 || Qr(e, "hover").length > 0,
5076
5570
  on: (e, t, n) => this.#ie(e, t, n)
5077
5571
  }), e.framing !== void 0) {
5078
5572
  let t = typeof e.framing == "string" ? { keep: e.framing } : e.framing;
5079
- A("View", t, Er, {}, "framing"), t.keep !== void 0 && (this.#g = P("View", "framing.keep", t.keep, [
5573
+ A("View", t, Pr, {}, "framing"), t.keep !== void 0 && (this.#g = P("View", "framing.keep", t.keep, [
5080
5574
  "height",
5081
5575
  "width",
5082
5576
  "both"
@@ -5095,7 +5589,7 @@ var gr = {
5095
5589
  distance: Math.max(.001, t.position.distanceTo(n))
5096
5590
  }), this.#m = !0;
5097
5591
  } else this.#m = !1;
5098
- e instanceof Dt || E("View", `'camera' must be a camera or a preset name, got ${j(e)}`), this.#L = null, this.#e = e, this.#d && (e.aspect = this.#u / this.#d), this.#_ = e.aspect, this.#v = 1, this.controls && (e.target ??= this.controls.target.clone(), this.controls.camera = e), this.#m && (this.#h = Pr(e)), this.invalidate();
5592
+ e instanceof Dt || E("View", `'camera' must be a camera or a preset name, got ${j(e)}`), this.#L = null, this.#e = e, this.#d && (e.aspect = this.#u / this.#d), this.#_ = e.aspect, this.#v = 1, this.controls && (e.target ??= this.controls.target.clone(), this.controls.camera = e), this.#m && (this.#h = Hr(e)), this.invalidate();
5099
5593
  }
5100
5594
  get bloom() {
5101
5595
  return this.renderer.bloom;
@@ -5145,8 +5639,8 @@ var gr = {
5145
5639
  #U(e) {
5146
5640
  if (this.#L) return this.#G(e);
5147
5641
  if (!this.controls) return;
5148
- let t = this.#m && Fr(Pr(this.camera), this.#h);
5149
- this.controls.update(e), t && (this.#h = Pr(this.camera));
5642
+ let t = this.#m && Ur(Hr(this.camera), this.#h);
5643
+ this.controls.update(e), t && (this.#h = Hr(this.camera));
5150
5644
  }
5151
5645
  render() {
5152
5646
  return this.#W(!1);
@@ -5155,7 +5649,7 @@ var gr = {
5155
5649
  if (this.#m) {
5156
5650
  this.resize();
5157
5651
  let e = this.scene.bounds;
5158
- Fr(Pr(this.camera), this.#h) ? e.isEmpty() || this.frame(this.scene) : this.#m = !1;
5652
+ Ur(Hr(this.camera), this.#h) ? e.isEmpty() || this.frame(this.scene) : this.#m = !1;
5159
5653
  }
5160
5654
  this.scene.updateWorldTree();
5161
5655
  let t = Ce(this.scene, this.camera);
@@ -5170,16 +5664,16 @@ var gr = {
5170
5664
  }
5171
5665
  let n = e || this.canvas.width || 1, r = t || this.canvas.height || 1;
5172
5666
  this.#p || (this.#f = Math.min(globalThis.devicePixelRatio || 1, 2)), this.#u = n, this.#d = r, this.renderer.setSize(n, r, this.#f), this.camera.aspect = n / r;
5173
- let i = this.#m && Fr(Pr(this.camera), this.#h);
5174
- this.#Q(), i && (this.#h = Pr(this.camera)), this.#c = !0;
5667
+ let i = this.#m && Ur(Hr(this.camera), this.#h);
5668
+ this.#Q(), i && (this.#h = Hr(this.camera)), this.#c = !0;
5175
5669
  }
5176
5670
  frame(e = this.scene, { padding: t = .2, direction: n, duration: r = 0 } = {}) {
5177
5671
  t >= 0 || E("View", `frame() padding is the margin around, as a fraction of the size (0.2 = 20%), got ${j(t)}`), t >= 1 && F(this, `frame() padding ${t} leaves a margin of ${Math.round(t * 100)}% - it is a fraction of the size (0.2 = 20%)`), N("View", "frame() duration", r, 0);
5178
- let i = this.camera, a = Br(i);
5672
+ let i = this.camera, a = Jr(i);
5179
5673
  this.#L = null;
5180
5674
  let o = n === void 0 ? i.position.clone().sub(i.target ?? new z()).normalize() : typeof n == "string" ? Pt(n) : z.fromInput(n, "View").normalize();
5181
5675
  n !== void 0 && !(o.len() > 0) && E("View", `frame() direction is a preset name or a vector from the target towards the camera, got ${j(n)}`), o.len() === 0 && o.set(0, .3, 1).normalize();
5182
- let s = e instanceof V ? Ir(e) : this.#K(e, o);
5676
+ let s = e instanceof V ? Wr(e) : this.#K(e, o);
5183
5677
  if (this.#m = !1, !s.length) return this;
5184
5678
  let c = i.constructor.type === "orthographic-camera", { center: l, size: u } = It(s, o, {
5185
5679
  aspect: i.aspect,
@@ -5193,24 +5687,24 @@ var gr = {
5193
5687
  }
5194
5688
  return i.target = l, this.#_ = i.aspect, this.#v = 1, r > 0 && (this.#L = {
5195
5689
  from: a,
5196
- to: Br(i),
5690
+ to: Jr(i),
5197
5691
  time: 0,
5198
5692
  duration: r
5199
- }, Vr(i, a)), this.invalidate(), this;
5693
+ }, Yr(i, a)), this.invalidate(), this;
5200
5694
  }
5201
5695
  #G(e) {
5202
5696
  let t = this.#L;
5203
5697
  t.time = Math.min(t.duration, t.time + e);
5204
- let n = Rt.inOut(t.time / t.duration), r = this.camera, i = t.from.target.clone().lerp(t.to.target, n), a = t.from.position.clone().sub(t.from.target), o = t.to.position.clone().sub(t.to.target), s = a.len() || 1e-6, c = o.len() || 1e-6, l = Ur(a.multiplyScalar(1 / s), o.multiplyScalar(1 / c), n);
5205
- Hr(r, i), r.position.copy(i).add(l.multiplyScalar(s * (c / s) ** n)), t.to.height !== void 0 && (r.height = t.from.height * (t.to.height / t.from.height) ** n), t.time >= t.duration && (Vr(r, t.to), this.#L = null), this.invalidate();
5698
+ let n = Rt.inOut(t.time / t.duration), r = this.camera, i = t.from.target.clone().lerp(t.to.target, n), a = t.from.position.clone().sub(t.from.target), o = t.to.position.clone().sub(t.to.target), s = a.len() || 1e-6, c = o.len() || 1e-6, l = Zr(a.multiplyScalar(1 / s), o.multiplyScalar(1 / c), n);
5699
+ Xr(r, i), r.position.copy(i).add(l.multiplyScalar(s * (c / s) ** n)), t.to.height !== void 0 && (r.height = t.from.height * (t.to.height / t.from.height) ** n), t.time >= t.duration && (Yr(r, t.to), this.#L = null), this.invalidate();
5206
5700
  }
5207
5701
  #K(e, t) {
5208
5702
  let n = e.bounds;
5209
5703
  if (n.isEmpty()) return [];
5210
5704
  let r = this.camera, i = r.position.clone();
5211
5705
  r.position.copy(n.getCenter()).add(t.clone().multiplyScalar(Math.max(n.getRadius(), .001) * 3)), r.updateWorld();
5212
- let a = Rr(e, r);
5213
- return r.position.copy(i), r.updateWorld(), a.length ? a : Ir(n);
5706
+ let a = Kr(e, r);
5707
+ return r.position.copy(i), r.updateWorld(), a.length ? a : Wr(n);
5214
5708
  }
5215
5709
  pick(e, t) {
5216
5710
  if (typeof e == "object") {
@@ -5236,7 +5730,7 @@ var gr = {
5236
5730
  let e = n.drawMode;
5237
5731
  t += i ? i.count : e === "points" ? r.drawnVertices : e === "lines" ? r.drawnCount / 2 : r.drawnCount / 3;
5238
5732
  }
5239
- return t > jr ? e : null;
5733
+ return t > zr ? e : null;
5240
5734
  }
5241
5735
  #J(e, t) {
5242
5736
  let n = e.item.node, r = new tn().setFromCamera(e.ndc, this.camera), i = r.intersectElement(n, e.element);
@@ -5263,7 +5757,7 @@ var gr = {
5263
5757
  };
5264
5758
  }
5265
5759
  screenBounds(e = this.scene) {
5266
- let t = e instanceof V ? Ir(e) : Rr(e, this.camera);
5760
+ let t = e instanceof V ? Wr(e) : Kr(e, this.camera);
5267
5761
  if (!t.length) return null;
5268
5762
  let n = Infinity, r = Infinity, i = -Infinity, a = -Infinity;
5269
5763
  for (let e of t) {
@@ -5298,7 +5792,7 @@ var gr = {
5298
5792
  }
5299
5793
  on(e, t) {
5300
5794
  if (!(e in this.#C)) {
5301
- let t = Or[e];
5795
+ let t = Ir[e];
5302
5796
  t && E("View", `on('${e}') - use '${t}'${t === "hover" ? ", which fires as the thing under the pointer changes (null when it leaves)" : ""}`), P("View", "event", e, ["click", "hover"]);
5303
5797
  }
5304
5798
  typeof t != "function" && E("View", `on('${e}', fn) needs a function, got ${j(t)}`);
@@ -5357,7 +5851,7 @@ var gr = {
5357
5851
  if (!this.#r) {
5358
5852
  this.#r = !0, this.#n = !1, cancelAnimationFrame(this.#o);
5359
5853
  for (let e of this.#b) e();
5360
- this.controls?.dispose(), this.#x.dispose(), this.#w?.dispose(), this.renderer.dispose(this.scene), this.#i && Mr--, this.#a && this.canvas.remove();
5854
+ this.controls?.dispose(), this.#x.dispose(), this.#w?.dispose(), this.renderer.dispose(this.scene), this.#i && Br--, this.#a && this.canvas.remove();
5361
5855
  }
5362
5856
  }
5363
5857
  #Q() {
@@ -5407,8 +5901,8 @@ var gr = {
5407
5901
  #re(e) {
5408
5902
  let t = this.#k, n = this.#I, r = n === e || n && e && n.node === e.node && n.instance === e.instance && n.datum === e.datum && (e.node.drawMode !== "points" || n.face === e.face);
5409
5903
  if (this.#I = e, t && e && this.#w ? this.#w.show(e, t.clientX, t.clientY) : this.#w?.hide(), r) return;
5410
- (this.#oe(n) || this.#oe(e)) && this.invalidate(), (this.#C.click.size || this.lastFrame?.interactive) && (this.canvas.style.cursor = e && zr(e.node, "onDrag") ? "grab" : e && this.#ae(e) ? "pointer" : "");
5411
- let i = Gr(n?.node, "hover"), a = Gr(e?.node, "hover");
5904
+ (this.#oe(n) || this.#oe(e)) && this.invalidate(), (this.#C.click.size || this.lastFrame?.interactive) && (this.canvas.style.cursor = e && qr(e.node, "onDrag") ? "grab" : e && this.#ae(e) ? "pointer" : "");
5905
+ let i = $r(n?.node, "hover"), a = $r(e?.node, "hover");
5412
5906
  for (let e of i) a.includes(e) || e(null);
5413
5907
  for (let t of a) t(e);
5414
5908
  for (let n of this.#C.hover) n(e, t?.event ?? null);
@@ -5425,7 +5919,7 @@ var gr = {
5425
5919
  datum: r.datumAt?.(i) ?? null
5426
5920
  };
5427
5921
  if (e === "click") {
5428
- for (let e of Gr(r, "click")) e(o);
5922
+ for (let e of $r(r, "click")) e(o);
5429
5923
  for (let e of this.#C.click) e(o, n);
5430
5924
  } else {
5431
5925
  if (this.#R = e === "over" ? o : null, n) {
@@ -5442,7 +5936,7 @@ var gr = {
5442
5936
  }
5443
5937
  }
5444
5938
  #ae(e) {
5445
- return this.#C.click.size > 0 || Gr(e.node, "click").length > 0;
5939
+ return this.#C.click.size > 0 || $r(e.node, "click").length > 0;
5446
5940
  }
5447
5941
  #oe(e) {
5448
5942
  if (!e) return null;
@@ -5459,14 +5953,14 @@ var gr = {
5459
5953
  index: null,
5460
5954
  nodes: e,
5461
5955
  color: t,
5462
- amount: kr
5956
+ amount: Lr
5463
5957
  };
5464
5958
  }
5465
5959
  return {
5466
5960
  node: r,
5467
5961
  index: e.instance ?? (r.drawMode === "points" ? e.face : null),
5468
5962
  color: t,
5469
- amount: kr
5963
+ amount: Lr
5470
5964
  };
5471
5965
  }
5472
5966
  #se(e) {
@@ -5508,7 +6002,7 @@ var gr = {
5508
6002
  y: r.y,
5509
6003
  moved: !1
5510
6004
  };
5511
- let i = this.lastFrame?.draggable && (n.pointerType !== "mouse" || n.button === 0) ? this.pick(n) : null, a = i && zr(i.node, "onDrag");
6005
+ let i = this.lastFrame?.draggable && (n.pointerType !== "mouse" || n.button === 0) ? this.pick(n) : null, a = i && qr(i.node, "onDrag");
5512
6006
  if (!i || !a) {
5513
6007
  this.#P?.down(n);
5514
6008
  return;
@@ -5545,7 +6039,7 @@ var gr = {
5545
6039
  }
5546
6040
  if (!this.#C.click.size && !this.lastFrame?.interactive) return;
5547
6041
  let t = this.pick(e);
5548
- if (t) for (let e of Gr(t.node, "click")) e(t);
6042
+ if (t) for (let e of $r(t.node, "click")) e(t);
5549
6043
  for (let n of this.#C.click) n(t, e);
5550
6044
  };
5551
6045
  e.addEventListener("pointerdown", a), e.addEventListener("pointermove", n), e.addEventListener("pointerleave", r), e.addEventListener("pointerup", i), e.addEventListener("pointercancel", i), e.addEventListener("click", o);
@@ -5616,15 +6110,15 @@ var gr = {
5616
6110
  });
5617
6111
  }
5618
6112
  };
5619
- function Pr(e) {
6113
+ function Hr(e) {
5620
6114
  return [
5621
6115
  ...e.position,
5622
6116
  ...e.target ?? [],
5623
6117
  e.fov ?? e.height
5624
6118
  ];
5625
6119
  }
5626
- var Fr = (e, t) => !!t && e.length === t.length && e.every((e, n) => e === t[n]);
5627
- function Ir(e) {
6120
+ var Ur = (e, t) => !!t && e.length === t.length && e.every((e, n) => e === t[n]);
6121
+ function Wr(e) {
5628
6122
  if (e.isEmpty()) return [];
5629
6123
  if (e.min.equals(e.max)) return [e.min.toArray()];
5630
6124
  let t = [];
@@ -5635,14 +6129,14 @@ function Ir(e) {
5635
6129
  ]);
5636
6130
  return t;
5637
6131
  }
5638
- var Lr = 4e3;
5639
- function Rr(e, t) {
6132
+ var Gr = 4e3;
6133
+ function Kr(e, t) {
5640
6134
  e.updateWorld();
5641
6135
  let n = [];
5642
6136
  return e.eachShownTo(t, (e) => {
5643
6137
  let t = e;
5644
- if ("instanceMatrices" in t && t.count <= Lr) t.eachInstanceBox((e, t, r, i, a, o) => {
5645
- n.push(...Ir(new V([
6138
+ if ("instanceMatrices" in t && t.count <= Gr) t.eachInstanceBox((e, t, r, i, a, o) => {
6139
+ n.push(...Wr(new V([
5646
6140
  e,
5647
6141
  t,
5648
6142
  r
@@ -5652,7 +6146,7 @@ function Rr(e, t) {
5652
6146
  o
5653
6147
  ])));
5654
6148
  });
5655
- else if ((t.drawMode === "lines" || t.drawMode === "points") && t.geometry.vertexCount <= Lr) {
6149
+ else if ((t.drawMode === "lines" || t.drawMode === "points") && t.geometry.vertexCount <= Gr) {
5656
6150
  let e = t.geometry, r = e.positions, i = t.worldMatrix, a = e.indices ? e.vertexCount : e.drawnVertices;
5657
6151
  for (let e = 0; e < a; e++) {
5658
6152
  let t = r[e * 3], a = r[e * 3 + 1], o = r[e * 3 + 2];
@@ -5662,45 +6156,45 @@ function Rr(e, t) {
5662
6156
  i[2] * t + i[6] * a + i[10] * o + i[14]
5663
6157
  ]);
5664
6158
  }
5665
- } else n.push(...Ir(e.expandBounds(new V())));
6159
+ } else n.push(...Wr(e.expandBounds(new V())));
5666
6160
  }), n;
5667
6161
  }
5668
- function zr(e, t) {
6162
+ function qr(e, t) {
5669
6163
  for (let n = e; n; n = n.parent) if (n[t]) return n;
5670
6164
  return null;
5671
6165
  }
5672
- function Br(e) {
6166
+ function Jr(e) {
5673
6167
  return {
5674
6168
  position: e.position.clone(),
5675
6169
  target: (e.target ?? new z()).clone(),
5676
6170
  height: e.height
5677
6171
  };
5678
6172
  }
5679
- function Vr(e, t) {
5680
- e.position.copy(t.position), Hr(e, t.target), t.height !== void 0 && (e.height = t.height);
6173
+ function Yr(e, t) {
6174
+ e.position.copy(t.position), Xr(e, t.target), t.height !== void 0 && (e.height = t.height);
5681
6175
  }
5682
- function Hr(e, t) {
6176
+ function Xr(e, t) {
5683
6177
  e.target ? e.target.copy(t) : e.target = t.clone();
5684
6178
  }
5685
- function Ur(e, t, n) {
6179
+ function Zr(e, t, n) {
5686
6180
  let r = Math.max(-1, Math.min(1, e.dot(t)));
5687
6181
  if (r > .9999) return e.clone().lerp(t, n).normalize();
5688
6182
  if (r < -.9999) {
5689
6183
  let r = Math.abs(e[1]) < .9 ? new z(0, 1, 0) : new z(1, 0, 0), i = e.clone().cross(r).normalize();
5690
- return n < .5 ? Ur(e, i, n * 2) : Ur(i, t, n * 2 - 1);
6184
+ return n < .5 ? Zr(e, i, n * 2) : Zr(i, t, n * 2 - 1);
5691
6185
  }
5692
6186
  let i = Math.acos(r), a = Math.sin(i);
5693
6187
  return e.clone().multiplyScalar(Math.sin((1 - n) * i) / a).add(t.clone().multiplyScalar(Math.sin(n * i) / a));
5694
6188
  }
5695
- function Wr(e, t) {
5696
- return e.index === null && !e.node.handlersFor(t).length ? [] : Gr(e.node, t);
6189
+ function Qr(e, t) {
6190
+ return e.index === null && !e.node.handlersFor(t).length ? [] : $r(e.node, t);
5697
6191
  }
5698
- function Gr(e, t) {
6192
+ function $r(e, t) {
5699
6193
  let n = [];
5700
6194
  for (let r = e; r; r = r.parent) n.push(...r.handlersFor(t));
5701
6195
  return n;
5702
6196
  }
5703
- function Kr(e) {
6197
+ function ei(e) {
5704
6198
  if (e === void 0) {
5705
6199
  let e = document.createElement("canvas");
5706
6200
  return Object.assign(e.style, {
@@ -5718,7 +6212,7 @@ function Kr(e) {
5718
6212
  return e instanceof HTMLCanvasElement || E("View", `'canvas' must be a <canvas> element or a selector, got ${j(e)}`), e;
5719
6213
  }
5720
6214
  // src/resolve.js
5721
- function qr(e, t) {
6215
+ function ti(e, t) {
5722
6216
  if (e instanceof X) return e;
5723
6217
  if ((!e || typeof e != "object" || Array.isArray(e)) && E(t, `'geometry' must be a Geometry such as box(2), got ${j(e)}`), "type" in e) {
5724
6218
  let n = e.type;
@@ -5726,17 +6220,17 @@ function qr(e, t) {
5726
6220
  }
5727
6221
  return new X(e);
5728
6222
  }
5729
- function Jr(e) {
5730
- return e === void 0 ? new Fn() : Fn.fromInput(e);
6223
+ function ni(e) {
6224
+ return e === void 0 ? new zn() : zn.fromInput(e);
5731
6225
  }
5732
6226
  // src/scene/drawables.js
5733
- var Yr = [
6227
+ var ri = [
5734
6228
  "center",
5735
6229
  "above",
5736
6230
  "below",
5737
6231
  "left",
5738
6232
  "right"
5739
- ], Xr = [
6233
+ ], ii = [
5740
6234
  "place",
5741
6235
  "offset",
5742
6236
  "className",
@@ -5745,7 +6239,7 @@ var Yr = [
5745
6239
  "occlude",
5746
6240
  "leader",
5747
6241
  "edge"
5748
- ], Zr = {
6242
+ ], ai = {
5749
6243
  line: "use leader: true - a line from the point to the label",
5750
6244
  callout: "use leader: true, with edge: 'left' | 'right' to line the labels up down the side",
5751
6245
  column: "use edge: 'left' | 'right' - the label sits at that edge of the view, level with its point",
@@ -5754,14 +6248,14 @@ var Yr = [
5754
6248
  anchor: "use place: 'center' | 'above' | 'below' | 'left' | 'right' (where the label goes)",
5755
6249
  zIndex: "use 'priority': higher stays when labels overlap",
5756
6250
  collision: "use overlap: 'hide' | 'dim' | 'show'"
5757
- }, Qr = {
5758
- ...Zr,
6251
+ }, oi = {
6252
+ ...ai,
5759
6253
  position: "labels per instance sit on their instance - offset moves them in pixels"
5760
6254
  };
5761
- function $r(e, t) {
6255
+ function si(e, t) {
5762
6256
  let n = t.offset ?? [0, 0];
5763
6257
  return Array.isArray(n) && n.length === 2 && n.every(Number.isFinite) || E(e, `'offset' must be [x, y] in pixels, got ${j(n)}`), {
5764
- place: t.place === void 0 ? "center" : P(e, "place", t.place, Yr),
6258
+ place: t.place === void 0 ? "center" : P(e, "place", t.place, ri),
5765
6259
  offset: [n[0], n[1]],
5766
6260
  className: t.className ? String(t.className) : "",
5767
6261
  priority: t.priority === void 0 ? 0 : M(e, "priority", t.priority),
@@ -5775,12 +6269,12 @@ function $r(e, t) {
5775
6269
  edge: t.edge == null ? null : P(e, "edge", t.edge, ["left", "right"])
5776
6270
  };
5777
6271
  }
5778
- function ei(e, t) {
6272
+ function ci(e, t) {
5779
6273
  if (t == null) return null;
5780
6274
  (typeof t != "object" || typeof t.text != "function") && E(e, `'labels' must be { text: (datum, index) => string, ... }, got ${j(t)}`);
5781
6275
  let n = t;
5782
- for (let t of Object.keys(n)) t !== "text" && t !== "at" && !Xr.includes(t) && E(e, `unknown labels option '${t}'${Qr[t] ? ` - ${Qr[t]}` : ` - expected text, at, ${Xr.join(", ")}`}`);
5783
- let r = n.at === void 0 ? "top" : P(e, "labels.at", n.at, ["top", "center"]), i = typeof n.priority == "function", a = $r(e, i ? {
6276
+ for (let t of Object.keys(n)) t !== "text" && t !== "at" && !ii.includes(t) && E(e, `unknown labels option '${t}'${oi[t] ? ` - ${oi[t]}` : ` - expected text, at, ${ii.join(", ")}`}`);
6277
+ let r = n.at === void 0 ? "top" : P(e, "labels.at", n.at, ["top", "center"]), i = typeof n.priority == "function", a = si(e, i ? {
5784
6278
  ...n,
5785
6279
  priority: 0
5786
6280
  } : n);
@@ -5791,7 +6285,7 @@ function ei(e, t) {
5791
6285
  priority: i ? n.priority : a.priority
5792
6286
  };
5793
6287
  }
5794
- var ti = [
6288
+ var li = [
5795
6289
  ...U,
5796
6290
  "geometry",
5797
6291
  "material",
@@ -5800,13 +6294,13 @@ var ti = [
5800
6294
  "renderOrder",
5801
6295
  "frustumCulled",
5802
6296
  "data"
5803
- ], ni = {
6297
+ ], ui = {
5804
6298
  mesh: "pass 'geometry' and 'material' directly",
5805
6299
  materials: "one 'material' per node - use a Group of meshes for several",
5806
6300
  rows: "use 'data' - one row per instance or point"
5807
- }, ri = class extends W {
5808
- static OPTIONS = ti;
5809
- static HINTS = ni;
6301
+ }, di = class extends W {
6302
+ static OPTIONS = li;
6303
+ static HINTS = ui;
5810
6304
  #e;
5811
6305
  #t;
5812
6306
  castShadow = !1;
@@ -5817,19 +6311,19 @@ var ti = [
5817
6311
  constructor(e) {
5818
6312
  super(e);
5819
6313
  let t = this.constructor.name;
5820
- e && e.geometry !== void 0 || E(t, `'geometry' is required, e.g. new ${t}({ geometry: box(1), material: { color: 'orange' } })`), this.#e = qr(e.geometry, t), this.#t = Jr(e.material), e.castShadow !== void 0 && (this.castShadow = !!e.castShadow), e.receiveShadow !== void 0 && (this.receiveShadow = !!e.receiveShadow), e.renderOrder !== void 0 && (this.renderOrder = M(t, "renderOrder", e.renderOrder)), e.frustumCulled !== void 0 && (this.frustumCulled = !!e.frustumCulled), e.data !== void 0 && (this.data = e.data), this.checkGeometry();
6314
+ e && e.geometry !== void 0 || E(t, `'geometry' is required, e.g. new ${t}({ geometry: box(1), material: { color: 'orange' } })`), this.#e = ti(e.geometry, t), this.#t = ni(e.material), e.castShadow !== void 0 && (this.castShadow = !!e.castShadow), e.receiveShadow !== void 0 && (this.receiveShadow = !!e.receiveShadow), e.renderOrder !== void 0 && (this.renderOrder = M(t, "renderOrder", e.renderOrder)), e.frustumCulled !== void 0 && (this.frustumCulled = !!e.frustumCulled), e.data !== void 0 && (this.data = e.data), this.checkGeometry();
5821
6315
  }
5822
6316
  get geometry() {
5823
6317
  return this.#e;
5824
6318
  }
5825
6319
  set geometry(e) {
5826
- this.#e = qr(e, this.constructor.name), this.checkGeometry();
6320
+ this.#e = ti(e, this.constructor.name), this.checkGeometry();
5827
6321
  }
5828
6322
  get material() {
5829
6323
  return this.#t;
5830
6324
  }
5831
6325
  set material(e) {
5832
- this.#t = Jr(e);
6326
+ this.#t = ni(e);
5833
6327
  }
5834
6328
  datumAt(e) {
5835
6329
  return ("instanceMatrices" in this || this.drawMode !== "triangles") && Array.isArray(this.data) ? e === null ? null : this.data[e] ?? null : this.data ?? null;
@@ -5868,28 +6362,28 @@ var ti = [
5868
6362
  for (let [, e] of this.material.textures) e.dispose();
5869
6363
  super.dispose();
5870
6364
  }
5871
- }, ii = class extends ri {
6365
+ }, fi = class extends di {
5872
6366
  static type = "mesh";
5873
6367
  checkGeometry() {
5874
6368
  let e = this.geometry.elementCount;
5875
6369
  e % 3 != 0 && E("Mesh", `geometry has ${e} ${this.geometry.indices ? "indices" : "vertices"}, not a multiple of 3 - triangles need three each (use Lines for pairs, Points for single vertices)`);
5876
6370
  }
5877
- }, ai = /* @__PURE__ */ new Set([
6371
+ }, pi = /* @__PURE__ */ new Set([
5878
6372
  "position",
5879
6373
  "rotation",
5880
6374
  "quaternion",
5881
6375
  "scale",
5882
6376
  "color"
5883
- ]), oi = {
6377
+ ]), mi = {
5884
6378
  position: new z(),
5885
6379
  scale: new z(),
5886
6380
  quaternion: new ut(),
5887
6381
  rotation: new lt()
5888
- }, si = /* @__PURE__ */ new Float32Array(16), ci = class extends ii {
6382
+ }, hi = /* @__PURE__ */ new Float32Array(16), gi = class extends fi {
5889
6383
  static type = "instanced-mesh";
5890
6384
  static get OPTIONS() {
5891
6385
  return [
5892
- ...ti,
6386
+ ...li,
5893
6387
  "count",
5894
6388
  "instances",
5895
6389
  "instanceMatrices",
@@ -5903,7 +6397,7 @@ var ti = [
5903
6397
  version = 0;
5904
6398
  labels = null;
5905
6399
  constructor(e) {
5906
- super(e), this.labels = ei("InstancedMesh", e.labels);
6400
+ super(e), this.labels = ci("InstancedMesh", e.labels);
5907
6401
  let t = e.count ?? e.instances?.length ?? (Array.isArray(e.data) ? e.data.length : void 0);
5908
6402
  (!Number.isInteger(t) || t < 0) && E("InstancedMesh", `'count' must be a whole number, got ${j(t)}`), this.count = t, this.instanceMatrices = new Float32Array(t * 16);
5909
6403
  let n = this.instanceMatrices;
@@ -5912,11 +6406,11 @@ var ti = [
5912
6406
  }
5913
6407
  setInstance(e, t) {
5914
6408
  this.#e(e);
5915
- for (let e in t) ai.has(e) || E("InstancedMesh", `unknown instance option '${e}' - expected position, rotation, quaternion, scale or color`);
5916
- let { position: n, scale: r, quaternion: i } = oi;
6409
+ for (let e in t) pi.has(e) || E("InstancedMesh", `unknown instance option '${e}' - expected position, rotation, quaternion, scale or color`);
6410
+ let { position: n, scale: r, quaternion: i } = mi;
5917
6411
  if (t.position === void 0 ? n.set(0, 0, 0) : n.copy(t.position, "InstancedMesh"), t.scale === void 0 ? r.set(1, 1, 1) : typeof t.scale == "number" ? r.set(t.scale, t.scale, t.scale) : r.copy(t.scale, "InstancedMesh"), i.set(0, 0, 0, 1), t.quaternion) i.copy(t.quaternion, "InstancedMesh").normalize();
5918
6412
  else if (t.rotation) {
5919
- let e = t.rotation instanceof lt ? t.rotation : oi.rotation.copy(t.rotation, "InstancedMesh");
6413
+ let e = t.rotation instanceof lt ? t.rotation : mi.rotation.copy(t.rotation, "InstancedMesh");
5920
6414
  i.setFromEuler(e.x, e.y, e.z);
5921
6415
  }
5922
6416
  return u(this.instanceMatrices.subarray(e * 16, e * 16 + 16), i, n, r), t.color !== void 0 && this.#t(e, t.color), this.version++, this;
@@ -5940,7 +6434,7 @@ var ti = [
5940
6434
  }
5941
6435
  eachInstanceBox(e) {
5942
6436
  if (!this.count || !this.geometry.vertexCount) return;
5943
- let t = this.geometry.bounds, n = (t.min[0] + t.max[0]) / 2, r = (t.min[1] + t.max[1]) / 2, i = (t.min[2] + t.max[2]) / 2, a = (t.max[0] - t.min[0]) / 2, o = (t.max[1] - t.min[1]) / 2, c = (t.max[2] - t.min[2]) / 2, l = this.worldMatrix, u = this.instanceMatrices, d = si;
6437
+ let t = this.geometry.bounds, n = (t.min[0] + t.max[0]) / 2, r = (t.min[1] + t.max[1]) / 2, i = (t.min[2] + t.max[2]) / 2, a = (t.max[0] - t.min[0]) / 2, o = (t.max[1] - t.min[1]) / 2, c = (t.max[2] - t.min[2]) / 2, l = this.worldMatrix, u = this.instanceMatrices, d = hi;
5944
6438
  for (let t = 0; t < this.count; t++) {
5945
6439
  s(d, l, u.subarray(t * 16, t * 16 + 16));
5946
6440
  let f = d[0] * n + d[4] * r + d[8] * i + d[12], p = d[1] * n + d[5] * r + d[9] * i + d[13], m = d[2] * n + d[6] * r + d[10] * i + d[14], h = Math.abs(d[0]) * a + Math.abs(d[4]) * o + Math.abs(d[8]) * c, g = Math.abs(d[1]) * a + Math.abs(d[5]) * o + Math.abs(d[9]) * c, _ = Math.abs(d[2]) * a + Math.abs(d[6]) * o + Math.abs(d[10]) * c;
@@ -5966,14 +6460,14 @@ var ti = [
5966
6460
  ...this.instanceColors ? { instanceColors: Array.from(this.instanceColors) } : {}
5967
6461
  };
5968
6462
  }
5969
- }, li = class extends ri {
6463
+ }, _i = class extends di {
5970
6464
  static type = "points";
5971
6465
  static get OPTIONS() {
5972
- return [...ti, "labels"];
6466
+ return [...li, "labels"];
5973
6467
  }
5974
6468
  labels = null;
5975
6469
  constructor(e) {
5976
- super(e), this.labels = ei(this.constructor.name, e?.labels);
6470
+ super(e), this.labels = ci(this.constructor.name, e?.labels);
5977
6471
  }
5978
6472
  cloneOptions() {
5979
6473
  return {
@@ -5984,7 +6478,7 @@ var ti = [
5984
6478
  get drawMode() {
5985
6479
  return "points";
5986
6480
  }
5987
- }, ui = class extends ri {
6481
+ }, vi = class extends di {
5988
6482
  static type = "lines";
5989
6483
  get drawMode() {
5990
6484
  return "lines";
@@ -5993,17 +6487,17 @@ var ti = [
5993
6487
  let e = this.geometry.elementCount;
5994
6488
  e % 2 != 0 && E("Lines", `geometry has ${e} ${this.geometry.indices ? "indices" : "vertices"} - segments need them in pairs`);
5995
6489
  }
5996
- }, di = class extends W {
6490
+ }, yi = class extends W {
5997
6491
  static type = "label";
5998
6492
  static get OPTIONS() {
5999
6493
  return [
6000
6494
  ...U,
6001
6495
  "text",
6002
- ...Xr
6496
+ ...ii
6003
6497
  ];
6004
6498
  }
6005
6499
  static get HINTS() {
6006
- return Zr;
6500
+ return ai;
6007
6501
  }
6008
6502
  text = "";
6009
6503
  className = "";
@@ -6015,7 +6509,7 @@ var ti = [
6015
6509
  leader = !1;
6016
6510
  edge = null;
6017
6511
  constructor(e) {
6018
- super(e), typeof e?.text != "string" && typeof e?.text != "number" && E("Label", `'text' is required, got ${j(e?.text)}`), this.text = String(e.text), Object.assign(this, $r("Label", e));
6512
+ super(e), typeof e?.text != "string" && typeof e?.text != "number" && E("Label", `'text' is required, got ${j(e?.text)}`), this.text = String(e.text), Object.assign(this, si("Label", e));
6019
6513
  }
6020
6514
  get isLabel() {
6021
6515
  return !0;
@@ -6043,25 +6537,25 @@ var ti = [
6043
6537
  }
6044
6538
  };
6045
6539
  // src/geometry/triangulate.js
6046
- function fi(e) {
6540
+ function bi(e) {
6047
6541
  let t = 0;
6048
6542
  for (let n = 0, r = e.length - 1; n < e.length; r = n++) t += (e[r][0] - e[n][0]) * (e[r][1] + e[n][1]);
6049
6543
  return t;
6050
6544
  }
6051
- function pi(e, t = []) {
6545
+ function xi(e, t = []) {
6052
6546
  let n = [...e], r = e.map((e, t) => t);
6053
- fi(e) < 0 && r.reverse();
6547
+ bi(e) < 0 && r.reverse();
6054
6548
  let i = t.map((e) => {
6055
6549
  let t = n.length;
6056
6550
  n.push(...e);
6057
6551
  let r = e.map((e, n) => t + n);
6058
- return fi(e) > 0 && r.reverse(), r;
6059
- }).sort((e, t) => mi(n, t) - mi(n, e));
6060
- for (let e of i) r = hi(n, r, e, i);
6061
- return vi(n, r);
6552
+ return bi(e) > 0 && r.reverse(), r;
6553
+ }).sort((e, t) => Si(n, t) - Si(n, e));
6554
+ for (let e of i) r = Ci(n, r, e, i);
6555
+ return Ei(n, r);
6062
6556
  }
6063
- var mi = (e, t) => Math.max(...t.map((t) => e[t][0]));
6064
- function hi(e, t, n, r) {
6557
+ var Si = (e, t) => Math.max(...t.map((t) => e[t][0]));
6558
+ function Ci(e, t, n, r) {
6065
6559
  let i = 0;
6066
6560
  n.forEach((t, r) => {
6067
6561
  e[t][0] > e[n[i]][0] && (i = r);
@@ -6071,7 +6565,7 @@ function hi(e, t, n, r) {
6071
6565
  let s = -1, c = Infinity;
6072
6566
  t.forEach((t, n) => {
6073
6567
  let r = e[t], i = ((r[0] - a[0]) ** 2 + (r[1] - a[1]) ** 2) * (r[0] >= a[0] ? 1 : 4);
6074
- i >= c || o.some(([e, t]) => gi(a, r, e, t)) || (s = n, c = i);
6568
+ i >= c || o.some(([e, t]) => wi(a, r, e, t)) || (s = n, c = i);
6075
6569
  }), s < 0 && (s = 0);
6076
6570
  let l = [...n.slice(i), ...n.slice(0, i)];
6077
6571
  return [
@@ -6082,52 +6576,52 @@ function hi(e, t, n, r) {
6082
6576
  ...t.slice(s + 1)
6083
6577
  ];
6084
6578
  }
6085
- function gi(e, t, n, r) {
6086
- if (_i(e, n) || _i(e, r) || _i(t, n) || _i(t, r)) return !1;
6579
+ function wi(e, t, n, r) {
6580
+ if (Ti(e, n) || Ti(e, r) || Ti(t, n) || Ti(t, r)) return !1;
6087
6581
  let i = Q(n, r, e), a = Q(n, r, t), o = Q(e, t, n), s = Q(e, t, r);
6088
6582
  return i * a < 0 && o * s < 0;
6089
6583
  }
6090
- var _i = (e, t) => e[0] === t[0] && e[1] === t[1], Q = (e, t, n) => (t[0] - e[0]) * (n[1] - e[1]) - (t[1] - e[1]) * (n[0] - e[0]);
6091
- function vi(e, t) {
6584
+ var Ti = (e, t) => e[0] === t[0] && e[1] === t[1], Q = (e, t, n) => (t[0] - e[0]) * (n[1] - e[1]) - (t[1] - e[1]) * (n[0] - e[0]);
6585
+ function Ei(e, t) {
6092
6586
  let n = [...t], r = [];
6093
6587
  for (; n.length > 3;) {
6094
6588
  let t = -1;
6095
- for (let r = 0; r < n.length && t < 0; r++) bi(e, n, r) && (t = r);
6096
- if (t < 0) for (let r = 0; r < n.length && t < 0; r++) yi(e, n, r) && (t = r);
6589
+ for (let r = 0; r < n.length && t < 0; r++) Oi(e, n, r) && (t = r);
6590
+ if (t < 0) for (let r = 0; r < n.length && t < 0; r++) Di(e, n, r) && (t = r);
6097
6591
  t < 0 && (t = 0);
6098
6592
  let i = n.length;
6099
6593
  r.push(n[(t + i - 1) % i], n[t], n[(t + 1) % i]), n.splice(t, 1);
6100
6594
  }
6101
6595
  return n.length === 3 && r.push(...n), r;
6102
6596
  }
6103
- function yi(e, t, n) {
6597
+ function Di(e, t, n) {
6104
6598
  let r = t.length;
6105
6599
  return Q(e[t[(n + r - 1) % r]], e[t[n]], e[t[(n + 1) % r]]) > 0;
6106
6600
  }
6107
- function bi(e, t, n) {
6108
- if (!yi(e, t, n)) return !1;
6601
+ function Oi(e, t, n) {
6602
+ if (!Di(e, t, n)) return !1;
6109
6603
  let r = t.length, i = e[t[(n + r - 1) % r]], a = e[t[n]], o = e[t[(n + 1) % r]];
6110
6604
  for (let n of t) {
6111
6605
  let t = e[n];
6112
- if (!(_i(t, i) || _i(t, a) || _i(t, o)) && Q(i, a, t) >= 0 && Q(a, o, t) >= 0 && Q(o, i, t) >= 0) return !1;
6606
+ if (!(Ti(t, i) || Ti(t, a) || Ti(t, o)) && Q(i, a, t) >= 0 && Q(a, o, t) >= 0 && Q(o, i, t) >= 0) return !1;
6113
6607
  }
6114
6608
  return !0;
6115
6609
  }
6116
6610
  // src/geometry/generators.js
6117
- var xi = /* @__PURE__ */ t({
6611
+ var ki = /* @__PURE__ */ t({
6118
6612
  GENERATOR_OPTIONS: () => $,
6119
- axes: () => Ri,
6120
- box: () => wi,
6121
- cylinder: () => Oi,
6122
- edges: () => Li,
6123
- extrude: () => Ni,
6124
- grid: () => zi,
6125
- icosphere: () => ji,
6126
- lathe: () => Mi,
6127
- plane: () => Di,
6128
- sphere: () => Ei,
6129
- torus: () => Ai
6130
- }), Si = Math.PI * 2, $ = {
6613
+ axes: () => Ki,
6614
+ box: () => Mi,
6615
+ cylinder: () => Ii,
6616
+ edges: () => Gi,
6617
+ extrude: () => Vi,
6618
+ grid: () => qi,
6619
+ icosphere: () => zi,
6620
+ lathe: () => Bi,
6621
+ plane: () => Fi,
6622
+ sphere: () => Pi,
6623
+ torus: () => Ri
6624
+ }), Ai = Math.PI * 2, $ = {
6131
6625
  box: [
6132
6626
  "size",
6133
6627
  "width",
@@ -6174,18 +6668,18 @@ var xi = /* @__PURE__ */ t({
6174
6668
  ],
6175
6669
  axes: ["size"],
6176
6670
  grid: ["size", "divisions"]
6177
- }, Ci = "has one 'segments' option, used for every face";
6178
- function wi(e) {
6671
+ }, ji = "has one 'segments' option, used for every face";
6672
+ function Mi(e) {
6179
6673
  let t = "box()", n = I(t, e, $.box, (e) => ({ size: e }), {
6180
- widthSegments: `box() ${Ci}`,
6181
- heightSegments: `box() ${Ci}`,
6182
- depthSegments: `box() ${Ci}`
6674
+ widthSegments: `box() ${ji}`,
6675
+ heightSegments: `box() ${ji}`,
6676
+ depthSegments: `box() ${ji}`
6183
6677
  }), r = L(t, "size", n.size, 1), i = L(t, "width", n.width, r), a = L(t, "height", n.height, r), o = L(t, "depth", n.depth, r), s = R(t, "segments", n.segments, 1), c = [
6184
6678
  i,
6185
6679
  a,
6186
6680
  o
6187
- ], l = new Bi();
6188
- for (let [e, t, n] of Ti) {
6681
+ ], l = new Ji();
6682
+ for (let [e, t, n] of Ni) {
6189
6683
  let r = l.count;
6190
6684
  for (let r = 0; r <= s; r++) {
6191
6685
  let i = r / s;
@@ -6208,7 +6702,7 @@ function wi(e) {
6208
6702
  segments: s
6209
6703
  });
6210
6704
  }
6211
- var Ti = [
6705
+ var Ni = [
6212
6706
  [
6213
6707
  [
6214
6708
  1,
@@ -6312,15 +6806,15 @@ var Ti = [
6312
6806
  ]
6313
6807
  ]
6314
6808
  ];
6315
- function Ei(e) {
6809
+ function Pi(e) {
6316
6810
  let t = "sphere()", n = I(t, e, $.sphere, (e) => ({ radius: e }), {
6317
6811
  widthSegments: "sphere(): use 'segments' for the divisions around the sphere",
6318
6812
  heightSegments: "sphere(): use 'rings' for the divisions from pole to pole"
6319
- }), r = L(t, "radius", n.radius, 1), i = R(t, "segments", n.segments, 32, 3), a = R(t, "rings", n.rings, 16, 2), o = new Bi();
6813
+ }), r = L(t, "radius", n.radius, 1), i = R(t, "segments", n.segments, 32, 3), a = R(t, "rings", n.rings, 16, 2), o = new Ji();
6320
6814
  for (let e = 0; e <= a; e++) {
6321
6815
  let t = e / a, n = e === 0 || e === a, s = n ? 0 : Math.sin(t * Math.PI), c = e === 0 ? 1 : e === a ? -1 : Math.cos(t * Math.PI);
6322
6816
  for (let e = 0; e <= i; e++) {
6323
- let a = n && e < i ? (e + .5) / i : e / i, l = e % i / i * Si, u = -Math.cos(l) * s, d = c, f = Math.sin(l) * s;
6817
+ let a = n && e < i ? (e + .5) / i : e / i, l = e % i / i * Ai, u = -Math.cos(l) * s, d = c, f = Math.sin(l) * s;
6324
6818
  o.vertex(u * r, d * r, f * r, u, d, f, a, t);
6325
6819
  }
6326
6820
  }
@@ -6334,12 +6828,12 @@ function Ei(e) {
6334
6828
  rings: a
6335
6829
  });
6336
6830
  }
6337
- function Di(e) {
6831
+ function Fi(e) {
6338
6832
  let t = "plane()", n = I(t, e, $.plane, (e) => ({ size: e }), {
6339
6833
  height: "plane() lies in the x-z plane - use 'depth' rather than 'height'",
6340
- widthSegments: `plane() ${Ci}`,
6341
- heightSegments: `plane() ${Ci}`
6342
- }), r = L(t, "size", n.size, 1), i = L(t, "width", n.width, r), a = L(t, "depth", n.depth, r), o = R(t, "segments", n.segments, 1), s = new Bi();
6834
+ widthSegments: `plane() ${ji}`,
6835
+ heightSegments: `plane() ${ji}`
6836
+ }), r = L(t, "size", n.size, 1), i = L(t, "width", n.width, r), a = L(t, "depth", n.depth, r), o = R(t, "segments", n.segments, 1), s = new Ji();
6343
6837
  for (let e = 0; e <= o; e++) {
6344
6838
  let t = e / o;
6345
6839
  for (let e = 0; e <= o; e++) {
@@ -6354,7 +6848,7 @@ function Di(e) {
6354
6848
  segments: o
6355
6849
  });
6356
6850
  }
6357
- function Oi(e) {
6851
+ function Ii(e) {
6358
6852
  let t = "cylinder()", n = I(t, e, $.cylinder, null, {
6359
6853
  radiusBottom: "cylinder(): use 'radius' for the bottom radius",
6360
6854
  radialSegments: "cylinder(): use 'segments' for the divisions around the cylinder",
@@ -6363,18 +6857,18 @@ function Oi(e) {
6363
6857
  r === 0 && i === 0 && E(t, "'radius' and 'radiusTop' can't both be 0");
6364
6858
  let a = L(t, "height", n.height, 1), o = R(t, "segments", n.segments, 32, 3), s = n.caps ?? !0;
6365
6859
  typeof s != "boolean" && E(t, `'caps' must be true or false, got ${j(s)}`);
6366
- let c = Hi(t, n.axis, "y"), l = new Bi(), u = r - i, d = Math.hypot(a, u), f = a / d, p = u / d;
6860
+ let c = Xi(t, n.axis, "y"), l = new Ji(), u = r - i, d = Math.hypot(a, u), f = a / d, p = u / d;
6367
6861
  for (let e = 0; e <= 1; e++) {
6368
6862
  let t = e === 0 ? i : r, n = e === 0 ? a / 2 : -a / 2;
6369
6863
  for (let r = 0; r <= o; r++) {
6370
- let i = t === 0 && r < o ? (r + .5) / o : r / o, a = t === 0 ? i * Si : r % o / o * Si, s = Math.sin(a), c = Math.cos(a);
6864
+ let i = t === 0 && r < o ? (r + .5) / o : r / o, a = t === 0 ? i * Ai : r % o / o * Ai, s = Math.sin(a), c = Math.cos(a);
6371
6865
  l.vertex(t * s, n, t * c, f * s, p, f * c, i, e);
6372
6866
  }
6373
6867
  }
6374
6868
  return l.grid(0, o, 1, {
6375
6869
  pinchTop: i === 0,
6376
6870
  pinchBottom: r === 0
6377
- }), s && (i > 0 && ki(l, i, a / 2, 1, o), r > 0 && ki(l, r, -a / 2, -1, o)), l.turn("y", c), l.build({
6871
+ }), s && (i > 0 && Li(l, i, a / 2, 1, o), r > 0 && Li(l, r, -a / 2, -1, o)), l.turn("y", c), l.build({
6378
6872
  type: "cylinder",
6379
6873
  radius: r,
6380
6874
  radiusTop: i,
@@ -6384,10 +6878,10 @@ function Oi(e) {
6384
6878
  ...c !== "y" && { axis: c }
6385
6879
  });
6386
6880
  }
6387
- function ki(e, t, n, r, i) {
6881
+ function Li(e, t, n, r, i) {
6388
6882
  let a = e.vertex(0, n, 0, 0, r, 0, .5, .5);
6389
6883
  for (let a = 0; a < i; a++) {
6390
- let o = a / i * Si, s = Math.sin(o), c = Math.cos(o);
6884
+ let o = a / i * Ai, s = Math.sin(o), c = Math.cos(o);
6391
6885
  e.vertex(t * s, n, t * c, 0, r, 0, .5 + s / 2, .5 + r * c / 2);
6392
6886
  }
6393
6887
  for (let t = 0; t < i; t++) {
@@ -6395,15 +6889,15 @@ function ki(e, t, n, r, i) {
6395
6889
  r > 0 ? e.indices.push(a, n, o) : e.indices.push(a, o, n);
6396
6890
  }
6397
6891
  }
6398
- function Ai(e) {
6892
+ function Ri(e) {
6399
6893
  let t = "torus()", n = I(t, e, $.torus, null, {
6400
6894
  tubularSegments: "torus(): use 'segments' for the divisions around the ring",
6401
6895
  radialSegments: "torus(): use 'tubeSegments' for the divisions around the tube"
6402
- }), r = L(t, "radius", n.radius, 1), i = L(t, "tube", n.tube, .4), a = R(t, "segments", n.segments, 48, 3), o = R(t, "tubeSegments", n.tubeSegments, 16, 3), s = new Bi();
6896
+ }), r = L(t, "radius", n.radius, 1), i = L(t, "tube", n.tube, .4), a = R(t, "segments", n.segments, 48, 3), o = R(t, "tubeSegments", n.tubeSegments, 16, 3), s = new Ji();
6403
6897
  for (let e = 0; e <= o; e++) {
6404
- let t = e / o, n = -(e % o / o) * Si, c = Math.cos(n), l = Math.sin(n);
6898
+ let t = e / o, n = -(e % o / o) * Ai, c = Math.cos(n), l = Math.sin(n);
6405
6899
  for (let e = 0; e <= a; e++) {
6406
- let n = e / a, o = e % a / a * Si, u = Math.sin(o), d = Math.cos(o), f = c * u, p = l, m = c * d;
6900
+ let n = e / a, o = e % a / a * Ai, u = Math.sin(o), d = Math.cos(o), f = c * u, p = l, m = c * d;
6407
6901
  s.vertex(r * u + i * f, i * p, r * d + i * m, f, p, m, n, t);
6408
6902
  }
6409
6903
  }
@@ -6415,7 +6909,7 @@ function Ai(e) {
6415
6909
  tubeSegments: o
6416
6910
  });
6417
6911
  }
6418
- function ji(e) {
6912
+ function zi(e) {
6419
6913
  let t = "icosphere()", n = I(t, e, $.icosphere, (e) => ({ radius: e }), { subdivisions: "icosphere(): use 'detail' (0-6) for the subdivision level" }), r = L(t, "radius", n.radius, 1), i = R(t, "detail", n.detail, 2, 0, 6), a = (1 + Math.sqrt(5)) / 2, o = [], s = (e, t, n) => {
6420
6914
  let r = Math.hypot(e, t, n);
6421
6915
  return o.push(e / r, t / r, n / r), o.length / 3 - 1;
@@ -6566,14 +7060,14 @@ function ji(e) {
6566
7060
  detail: i
6567
7061
  }, l;
6568
7062
  }
6569
- function Mi(e) {
7063
+ function Bi(e) {
6570
7064
  let t = "lathe()", n = I(t, e, $.lathe, null, {
6571
7065
  divisions: "lathe(): use 'segments' for the divisions around the axis",
6572
7066
  phiSegments: "lathe(): use 'segments' for the divisions around the axis",
6573
7067
  profile: "lathe(): use 'points' for the profile, as [radius, y] pairs"
6574
- }), r = Ii(t, "points", n.points, 2).map(([e, t]) => [Math.abs(e) < 1e-9 ? 0 : e, t]);
7068
+ }), r = Wi(t, "points", n.points, 2).map(([e, t]) => [Math.abs(e) < 1e-9 ? 0 : e, t]);
6575
7069
  r.some(([e]) => e < 0) && E(t, "'points' are [radius, y] pairs - a radius can't be below 0");
6576
- let i = R(t, "segments", n.segments, 32, 3), a = Hi(t, n.axis, "y"), o = [];
7070
+ let i = R(t, "segments", n.segments, 32, 3), a = Xi(t, n.axis, "y"), o = [];
6577
7071
  for (let e = 0; e + 1 < r.length; e++) {
6578
7072
  let [t, n] = r[e], [i, a] = r[e + 1], s = Math.hypot(i - t, a - n);
6579
7073
  s !== 0 && o.push({
@@ -6584,9 +7078,9 @@ function Mi(e) {
6584
7078
  });
6585
7079
  }
6586
7080
  o.length || E(t, "'points' need at least two different points");
6587
- let s = o.reduce((e, t) => e + t.len, 0), c = new Bi(), l = 0;
7081
+ let s = o.reduce((e, t) => e + t.len, 0), c = new Ji(), l = 0;
6588
7082
  return o.forEach((e, t) => {
6589
- let n = Fi(o[t - 1]?.normal, e.normal), r = Fi(o[t + 1]?.normal, e.normal), a = c.count;
7083
+ let n = Ui(o[t - 1]?.normal, e.normal), r = Ui(o[t + 1]?.normal, e.normal), a = c.count;
6590
7084
  for (let [[t, a], [o, u], d] of [[
6591
7085
  e.to,
6592
7086
  r,
@@ -6596,7 +7090,7 @@ function Mi(e) {
6596
7090
  n,
6597
7091
  1 - l / s
6598
7092
  ]]) for (let e = 0; e <= i; e++) {
6599
- let n = e % i / i * Si, r = Math.sin(n), s = Math.cos(n);
7093
+ let n = e % i / i * Ai, r = Math.sin(n), s = Math.cos(n);
6600
7094
  c.vertex(t * r, a, t * s, o * r, u, o * s, e / i, d);
6601
7095
  }
6602
7096
  c.grid(a, i, 1, {
@@ -6610,17 +7104,17 @@ function Mi(e) {
6610
7104
  ...a !== "y" && { axis: a }
6611
7105
  });
6612
7106
  }
6613
- function Ni(e) {
7107
+ function Vi(e) {
6614
7108
  let t = "extrude()", n = I(t, e, $.extrude, null, {
6615
7109
  amount: "extrude(): use 'depth'",
6616
7110
  points: "extrude(): use 'shape' for the outline, as [x, y] pairs",
6617
7111
  outline: "extrude(): use 'shape' for the outline, as [x, y] pairs",
6618
7112
  bevelEnabled: "extrude() has no bevel - round the shape's corners instead"
6619
- }), r = Ui(Ii(t, "shape", n.shape, 3));
7113
+ }), r = Zi(Wi(t, "shape", n.shape, 3));
6620
7114
  n.holes !== void 0 && !Array.isArray(n.holes) && E(t, `'holes' must be a list of outlines, got ${j(n.holes)}`), typeof n.holes?.[0]?.[0] == "number" && E(t, "'holes' is a list of outlines - for one hole, holes: [outline]");
6621
- let i = (n.holes ?? []).map((e, n) => Ui(Ii(t, `holes[${n}]`, e, 3))), a = L(t, "depth", n.depth, 1), o = Hi(t, n.axis, "z"), s = a / 2, c = fi(r) < 0 ? [...r].reverse() : r, l = i.map((e) => fi(e) > 0 ? [...e].reverse() : e), u = [c, ...l].flat(), d = Infinity, f = -Infinity, p = Infinity, m = -Infinity;
7115
+ let i = (n.holes ?? []).map((e, n) => Zi(Wi(t, `holes[${n}]`, e, 3))), a = L(t, "depth", n.depth, 1), o = Xi(t, n.axis, "z"), s = a / 2, c = bi(r) < 0 ? [...r].reverse() : r, l = i.map((e) => bi(e) > 0 ? [...e].reverse() : e), u = [c, ...l].flat(), d = Infinity, f = -Infinity, p = Infinity, m = -Infinity;
6622
7116
  for (let [e, t] of u) d = Math.min(d, e), f = Math.max(f, e), p = Math.min(p, t), m = Math.max(m, t);
6623
- let h = f - d || 1, g = m - p || 1, _ = new Bi(), v = pi(c, l);
7117
+ let h = f - d || 1, g = m - p || 1, _ = new Ji(), v = xi(c, l);
6624
7118
  for (let [e, t] of [[s, 1], [-s, -1]]) {
6625
7119
  let n = _.count;
6626
7120
  for (let [n, r] of u) _.vertex(n, r, e, 0, 0, t, t > 0 ? (n - d) / h : (f - n) / h, (m - r) / g);
@@ -6632,7 +7126,7 @@ function Ni(e) {
6632
7126
  return [(s - i) / c, -(o - r) / c];
6633
7127
  }), i = n.reduce((e, t) => e + t, 0) || 1, a = 0;
6634
7128
  for (let o = 0; o < t; o++) {
6635
- let c = r[o], [l, u] = [Fi(r[(o + t - 1) % t], c), Fi(r[(o + 1) % t], c)], [d, f] = e[o], [p, m] = e[(o + 1) % t], h = a / i, g = (a + n[o]) / i, v = _.vertex(d, f, s, l[0], l[1], 0, h, 0), y = _.vertex(d, f, -s, l[0], l[1], 0, h, 1), b = _.vertex(p, m, -s, u[0], u[1], 0, g, 1), x = _.vertex(p, m, s, u[0], u[1], 0, g, 0);
7129
+ let c = r[o], [l, u] = [Ui(r[(o + t - 1) % t], c), Ui(r[(o + 1) % t], c)], [d, f] = e[o], [p, m] = e[(o + 1) % t], h = a / i, g = (a + n[o]) / i, v = _.vertex(d, f, s, l[0], l[1], 0, h, 0), y = _.vertex(d, f, -s, l[0], l[1], 0, h, 1), b = _.vertex(p, m, -s, u[0], u[1], 0, g, 1), x = _.vertex(p, m, s, u[0], u[1], 0, g, 0);
6636
7130
  _.indices.push(v, y, b, v, b, x), a += n[o];
6637
7131
  }
6638
7132
  }
@@ -6644,13 +7138,13 @@ function Ni(e) {
6644
7138
  ...o !== "z" && { axis: o }
6645
7139
  });
6646
7140
  }
6647
- var Pi = Math.cos(Math.PI / 6);
6648
- function Fi(e, t) {
6649
- if (!e || e[0] * t[0] + e[1] * t[1] < Pi) return t;
7141
+ var Hi = Math.cos(Math.PI / 6);
7142
+ function Ui(e, t) {
7143
+ if (!e || e[0] * t[0] + e[1] * t[1] < Hi) return t;
6650
7144
  let n = e[0] + t[0], r = e[1] + t[1], i = Math.hypot(n, r) || 1;
6651
7145
  return [n / i, r / i];
6652
7146
  }
6653
- function Ii(e, t, n, r) {
7147
+ function Wi(e, t, n, r) {
6654
7148
  Array.isArray(n) || E(e, `'${t}' must be a list of [x, y] pairs, got ${j(n)}`);
6655
7149
  let i = n;
6656
7150
  return i.length < r && E(e, `'${t}' needs at least ${r} points, got ${i.length}`), i.map((n, r) => {
@@ -6659,7 +7153,7 @@ function Ii(e, t, n, r) {
6659
7153
  return typeof i == "number" && typeof a == "number" && Number.isFinite(i) && Number.isFinite(a) || E(e, `'${t}' point ${r} must be two finite numbers, got ${j(n)}`), [i, a];
6660
7154
  });
6661
7155
  }
6662
- function Li(e, t = {}) {
7156
+ function Gi(e, t = {}) {
6663
7157
  e instanceof X || E("edges()", `expected a Geometry, got ${j(e)}`);
6664
7158
  let { angle: n = 1 } = I("edges()", t, ["angle"], null);
6665
7159
  n >= 0 && n < 180 || E("edges()", `'angle' is in degrees, 0 to under 180, got ${j(n)}`);
@@ -6701,7 +7195,7 @@ function Li(e, t = {}) {
6701
7195
  indices: p
6702
7196
  });
6703
7197
  }
6704
- function Ri(e) {
7198
+ function Ki(e) {
6705
7199
  let t = "axes()", n = L(t, "size", I(t, e, $.axes, (e) => ({ size: e })).size, 1), r = new X({
6706
7200
  positions: [
6707
7201
  0,
@@ -6749,7 +7243,7 @@ function Ri(e) {
6749
7243
  size: n
6750
7244
  }, r;
6751
7245
  }
6752
- function zi(e) {
7246
+ function qi(e) {
6753
7247
  let t = "grid()", n = I(t, e, $.grid, (e) => ({ size: e }), { segments: "grid() uses 'divisions' for the number of squares along each side" }), r = L(t, "size", n.size, 10), i = R(t, "divisions", n.divisions, 10), a = r / 2, o = [];
6754
7248
  for (let e = 0; e <= i; e++) {
6755
7249
  let t = -a + r * e / i;
@@ -6762,7 +7256,7 @@ function zi(e) {
6762
7256
  divisions: i
6763
7257
  }, s;
6764
7258
  }
6765
- var Bi = class {
7259
+ var Ji = class {
6766
7260
  positions = [];
6767
7261
  normals = [];
6768
7262
  uvs = [];
@@ -6782,7 +7276,7 @@ var Bi = class {
6782
7276
  }
6783
7277
  turn(e, t) {
6784
7278
  if (e === t) return;
6785
- let n = Vi[e][t];
7279
+ let n = Yi[e][t];
6786
7280
  for (let e of [this.positions, this.normals]) for (let t = 0; t < e.length; t += 3) {
6787
7281
  let [r, i, a] = n(e[t], e[t + 1], e[t + 2]);
6788
7282
  e[t] = r, e[t + 1] = i, e[t + 2] = a;
@@ -6797,7 +7291,7 @@ var Bi = class {
6797
7291
  });
6798
7292
  return a.source = e, a;
6799
7293
  }
6800
- }, Vi = {
7294
+ }, Yi = {
6801
7295
  y: {
6802
7296
  x: (e, t, n) => [
6803
7297
  t,
@@ -6823,14 +7317,14 @@ var Bi = class {
6823
7317
  ]
6824
7318
  }
6825
7319
  };
6826
- function Hi(e, t, n) {
7320
+ function Xi(e, t, n) {
6827
7321
  return t === void 0 ? n : P(e, "axis", t, [
6828
7322
  "x",
6829
7323
  "y",
6830
7324
  "z"
6831
7325
  ]);
6832
7326
  }
6833
- function Ui(e) {
7327
+ function Zi(e) {
6834
7328
  let t = e.filter((t, n) => {
6835
7329
  let r = e[(n + e.length - 1) % e.length];
6836
7330
  return t[0] !== r[0] || t[1] !== r[1];
@@ -6838,7 +7332,7 @@ function Ui(e) {
6838
7332
  return t.length >= 3 ? t : e;
6839
7333
  }
6840
7334
  // src/geometry/outline.js
6841
- var Wi = Math.PI * 2, Gi = {
7335
+ var Qi = Math.PI * 2, $i = {
6842
7336
  circle: [
6843
7337
  "radius",
6844
7338
  "segments",
@@ -6871,7 +7365,7 @@ var Wi = Math.PI * 2, Gi = {
6871
7365
  "depth",
6872
7366
  "center"
6873
7367
  ]
6874
- }, Ki = {
7368
+ }, ea = {
6875
7369
  r: "use 'radius'",
6876
7370
  x: "use center: [x, y]",
6877
7371
  y: "use center: [x, y]",
@@ -6881,17 +7375,17 @@ var Wi = Math.PI * 2, Gi = {
6881
7375
  cornerRadius: "use 'radius' for the corners' rounding",
6882
7376
  n: "use 'sides' (polygon) or 'segments'"
6883
7377
  };
6884
- function qi(e) {
6885
- let t = "outline.circle()", n = $i(t, e, Gi.circle, (e) => ({ radius: e })), r = L(t, "radius", n.radius, 1), i = R(t, "segments", n.segments, 32, 3), [a, o] = ea(t, "center", n.center);
7378
+ function ta(e) {
7379
+ let t = "outline.circle()", n = sa(t, e, $i.circle, (e) => ({ radius: e })), r = L(t, "radius", n.radius, 1), i = R(t, "segments", n.segments, 32, 3), [a, o] = ca(t, "center", n.center);
6886
7380
  return Array.from({ length: i }, (e, t) => {
6887
- let n = t / i * Wi;
7381
+ let n = t / i * Qi;
6888
7382
  return [a + Math.cos(n) * r, o + Math.sin(n) * r];
6889
7383
  });
6890
7384
  }
6891
- function Ji(e) {
6892
- let t = "outline.rect()", n = $i(t, e, Gi.rect, (e) => ({ size: e })), r = L(t, "size", n.size, 1), i = L(t, "width", n.width, r), a = L(t, "height", n.height, r), o = n.radius === void 0 ? 0 : M(t, "radius", n.radius);
7385
+ function na(e) {
7386
+ let t = "outline.rect()", n = sa(t, e, $i.rect, (e) => ({ size: e })), r = L(t, "size", n.size, 1), i = L(t, "width", n.width, r), a = L(t, "height", n.height, r), o = n.radius === void 0 ? 0 : M(t, "radius", n.radius);
6893
7387
  (o < 0 || o > Math.min(i, a) / 2) && E(t, `'radius' must be from 0 to half the shorter side (${Math.min(i, a) / 2}), got ${o}`);
6894
- let s = R(t, "segments", n.segments, 8, 1), [c, l] = ea(t, "center", n.center), u = i / 2, d = a / 2;
7388
+ let s = R(t, "segments", n.segments, 8, 1), [c, l] = ca(t, "center", n.center), u = i / 2, d = a / 2;
6895
7389
  if (o === 0) return [
6896
7390
  [c - u, l - d],
6897
7391
  [c + u, l - d],
@@ -6926,26 +7420,26 @@ function Ji(e) {
6926
7420
  }
6927
7421
  return f;
6928
7422
  }
6929
- function Yi(e) {
6930
- let t = "outline.polygon()", n = $i(t, e, Gi.polygon, (e) => ({ radius: e })), r = L(t, "radius", n.radius, 1), i = R(t, "sides", n.sides, 6, 3), a = n.angle === void 0 ? 0 : M(t, "angle", n.angle), [o, s] = ea(t, "center", n.center);
7423
+ function ra(e) {
7424
+ let t = "outline.polygon()", n = sa(t, e, $i.polygon, (e) => ({ radius: e })), r = L(t, "radius", n.radius, 1), i = R(t, "sides", n.sides, 6, 3), a = n.angle === void 0 ? 0 : M(t, "angle", n.angle), [o, s] = ca(t, "center", n.center);
6931
7425
  return Array.from({ length: i }, (e, t) => {
6932
- let n = a + t / i * Wi;
7426
+ let n = a + t / i * Qi;
6933
7427
  return [o + Math.cos(n) * r, s + Math.sin(n) * r];
6934
7428
  });
6935
7429
  }
6936
- function Xi(e) {
6937
- let t = "outline.arc()", n = $i(t, e, Gi.arc, null), r = L(t, "radius", n.radius, 1), i = n.from === void 0 ? 0 : M(t, "from", n.from), a = n.to === void 0 ? i + Wi : M(t, "to", n.to);
7430
+ function ia(e) {
7431
+ let t = "outline.arc()", n = sa(t, e, $i.arc, null), r = L(t, "radius", n.radius, 1), i = n.from === void 0 ? 0 : M(t, "from", n.from), a = n.to === void 0 ? i + Qi : M(t, "to", n.to);
6938
7432
  a === i && E(t, "'from' and 'to' are the same angle - there's no arc between them");
6939
- let o = R(t, "segments", n.segments, Math.max(1, Math.ceil(Math.abs(a - i) / Wi * 32)), 1), [s, c] = ea(t, "center", n.center);
7433
+ let o = R(t, "segments", n.segments, Math.max(1, Math.ceil(Math.abs(a - i) / Qi * 32)), 1), [s, c] = ca(t, "center", n.center);
6940
7434
  return Array.from({ length: o + 1 }, (e, t) => {
6941
7435
  let n = i + (a - i) * t / o;
6942
7436
  return [s + Math.cos(n) * r, c + Math.sin(n) * r];
6943
7437
  });
6944
7438
  }
6945
- function Zi(e) {
6946
- let t = "outline.gear()", n = $i(t, e, Gi.gear, (e) => ({ radius: e })), r = L(t, "radius", n.radius, 1), i = R(t, "teeth", n.teeth, 24, 3), a = L(t, "depth", n.depth, Math.min(r / 2, r * Math.PI / i));
7439
+ function aa(e) {
7440
+ let t = "outline.gear()", n = sa(t, e, $i.gear, (e) => ({ radius: e })), r = L(t, "radius", n.radius, 1), i = R(t, "teeth", n.teeth, 24, 3), a = L(t, "depth", n.depth, Math.min(r / 2, r * Math.PI / i));
6947
7441
  a >= r && E(t, `'depth' must be less than the radius (${r}), got ${a}`);
6948
- let [o, s] = ea(t, "center", n.center), c = r - a, l = Wi / i, u = [];
7442
+ let [o, s] = ca(t, "center", n.center), c = r - a, l = Qi / i, u = [];
6949
7443
  for (let e = 0; e < i; e++) for (let [t, n] of [
6950
7444
  [0, c],
6951
7445
  [.12, r],
@@ -6957,43 +7451,43 @@ function Zi(e) {
6957
7451
  }
6958
7452
  return u;
6959
7453
  }
6960
- var Qi = {
6961
- circle: qi,
6962
- rect: Ji,
6963
- polygon: Yi,
6964
- arc: Xi,
6965
- gear: Zi
6966
- }, $i = (e, t, n, r) => I(e, t, n, r, Ki);
6967
- function ea(e, t, n) {
7454
+ var oa = {
7455
+ circle: ta,
7456
+ rect: na,
7457
+ polygon: ra,
7458
+ arc: ia,
7459
+ gear: aa
7460
+ }, sa = (e, t, n, r) => I(e, t, n, r, ea);
7461
+ function ca(e, t, n) {
6968
7462
  if (n === void 0) return [0, 0];
6969
7463
  let r = n;
6970
7464
  return r && typeof r == "object" && typeof r[0] == "number" && typeof r[1] == "number" && Number.isFinite(r[0]) && Number.isFinite(r[1]) || E(e, `'${t}' must be [x, y], got ${j(n)}`), [r[0], r[1]];
6971
7465
  }
6972
7466
  // src/geometry/fromPolygons.js
6973
- var ta = "fromPolygons()";
6974
- function na(e) {
6975
- A(ta, e, [
7467
+ var la = "fromPolygons()";
7468
+ function ua(e) {
7469
+ A(la, e, [
6976
7470
  "points",
6977
7471
  "polygons",
6978
7472
  "edges",
6979
7473
  "smooth"
6980
7474
  ]);
6981
7475
  let { points: t, polygons: n } = e ?? {};
6982
- Array.isArray(t) || E(ta, `'points' must be an array of { x, y, z } or [x, y, z], got ${j(t)}`), Array.isArray(n) || E(ta, `'polygons' must be an array of { vertices: [...] }, got ${j(n)}`);
7476
+ Array.isArray(t) || E(la, `'points' must be an array of { x, y, z } or [x, y, z], got ${j(t)}`), Array.isArray(n) || E(la, `'polygons' must be an array of { vertices: [...] }, got ${j(n)}`);
6983
7477
  let r = t.map((e, t) => {
6984
7478
  let n = Array.isArray(e) ? e : e && typeof e == "object" ? [
6985
7479
  e.x,
6986
7480
  e.y,
6987
7481
  e.z
6988
7482
  ] : null;
6989
- return n && n.length === 3 && n.every(Number.isFinite) || E(ta, `point ${t} must be { x, y, z } or [x, y, z] numbers, got ${j(e)}`), n;
7483
+ return n && n.length === 3 && n.every(Number.isFinite) || E(la, `point ${t} must be { x, y, z } or [x, y, z] numbers, got ${j(e)}`), n;
6990
7484
  });
6991
7485
  n.forEach((e, t) => {
6992
7486
  let n = e?.vertices;
6993
- (!Array.isArray(n) || n.length < 3) && E(ta, `polygon ${t} needs 'vertices' with 3 or more point indices, got ${j(n)}`);
6994
- for (let e of n) (!Number.isInteger(e) || e < 0 || e >= r.length) && E(ta, `polygon ${t} refers to point ${j(e)} but there are only ${r.length} points`);
7487
+ (!Array.isArray(n) || n.length < 3) && E(la, `polygon ${t} needs 'vertices' with 3 or more point indices, got ${j(n)}`);
7488
+ for (let e of n) (!Number.isInteger(e) || e < 0 || e >= r.length) && E(la, `polygon ${t} refers to point ${j(e)} but there are only ${r.length} points`);
6995
7489
  let i = e.uvs;
6996
- i === void 0 || Array.isArray(i) && i.length === n.length * 2 && i.every(Number.isFinite) || E(ta, `polygon ${t} 'uvs' must be ${n.length * 2} numbers (a u, v pair per vertex), got ${j(i)}`);
7490
+ i === void 0 || Array.isArray(i) && i.length === n.length * 2 && i.every(Number.isFinite) || E(la, `polygon ${t} 'uvs' must be ${n.length * 2} numbers (a u, v pair per vertex), got ${j(i)}`);
6997
7491
  });
6998
7492
  let i = [];
6999
7493
  n.forEach(({ vertices: e }, t) => {
@@ -7017,29 +7511,29 @@ function na(e) {
7017
7511
  return a.computeNormals({ flat: !(e.smooth && !o) });
7018
7512
  }
7019
7513
  // src/geometry/Curve.js
7020
- var ra = ["closed", "tension"], ia = {
7514
+ var da = ["closed", "tension"], fa = {
7021
7515
  loop: "use 'closed: true'",
7022
7516
  smooth: "the curve is always smooth - 'tension' (0-1) sets how tight"
7023
- }, aa = ["segments", "dash"], oa = { dashed: "use 'dash: [on, off]' - lengths in the curve's units" }, sa = [
7517
+ }, pa = ["segments", "dash"], ma = { dashed: "use 'dash: [on, off]' - lengths in the curve's units" }, ha = [
7024
7518
  "radius",
7025
7519
  "segments",
7026
7520
  "sides"
7027
- ], ca = {
7521
+ ], ga = {
7028
7522
  tubularSegments: "use 'segments'",
7029
7523
  radialSegments: "use 'sides'"
7030
- }, la = [
7524
+ }, _a = [
7031
7525
  "plane",
7032
7526
  "radius",
7033
7527
  "center",
7034
7528
  "tilt"
7035
- ], ua = 48, da = class {
7529
+ ], va = 48, ya = class {
7036
7530
  #e;
7037
7531
  #t;
7038
7532
  #n;
7039
7533
  #r;
7040
7534
  constructor(e, t = {}) {
7041
- (!Array.isArray(e) || e.length < 2) && E("curve()", `needs an array of two or more points, got ${j(e)}`), A("curve()", t, ra, ia), this.#e = e.map((e) => z.fromInput(e, "curve()")), this.#t = !!t.closed, this.#n = t.tension === void 0 ? 0 : M("curve()", "tension", t.tension);
7042
- let n = this.#i() * ua;
7535
+ (!Array.isArray(e) || e.length < 2) && E("curve()", `needs an array of two or more points, got ${j(e)}`), A("curve()", t, da, fa), this.#e = e.map((e) => z.fromInput(e, "curve()")), this.#t = !!t.closed, this.#n = t.tension === void 0 ? 0 : M("curve()", "tension", t.tension);
7536
+ let n = this.#i() * va;
7043
7537
  this.#r = new Float64Array(n + 1);
7044
7538
  let r = this.#s(0);
7045
7539
  for (let e = 1; e <= n; e++) {
@@ -7065,7 +7559,7 @@ var ra = ["closed", "tension"], ia = {
7065
7559
  return Array.from({ length: t }, (e, t) => this.at(t / n));
7066
7560
  }
7067
7561
  line(e = {}) {
7068
- A("curve.line()", e, aa, oa);
7562
+ A("curve.line()", e, pa, ma);
7069
7563
  let t = this.#a("curve.line()", e.segments), n = this.length / t, r = [], i = (e, t) => {
7070
7564
  let i = Math.max(1, Math.ceil((t - e) / n - 1e-9)), a = this.at(e / this.length);
7071
7565
  for (let n = 1; n <= i; n++) {
@@ -7082,7 +7576,7 @@ var ra = ["closed", "tension"], ia = {
7082
7576
  return new X({ positions: r });
7083
7577
  }
7084
7578
  tube(e = {}) {
7085
- A("curve.tube()", e, sa, ca);
7579
+ A("curve.tube()", e, ha, ga);
7086
7580
  let t = e.radius === void 0 ? .1 : M("curve.tube()", "radius", e.radius), n = R("curve.tube()", "sides", e.sides, 8, 3), r = this.#a("curve.tube()", e.segments), i = this.#t ? r : r + 1, a = [], o = [], s = this.tangentAt(0), c = new z(...Math.abs(s[1]) < .9 ? [
7087
7581
  0,
7088
7582
  1,
@@ -7137,17 +7631,17 @@ var ra = ["closed", "tension"], ia = {
7137
7631
  return t;
7138
7632
  }
7139
7633
  };
7140
- function fa(e, t) {
7141
- return new da(e, t);
7634
+ function ba(e, t) {
7635
+ return new ya(e, t);
7142
7636
  }
7143
- function pa(e = {}) {
7637
+ function xa(e = {}) {
7144
7638
  let t = e.plane === void 0 ? "xz" : P("ellipse()", "plane", e.plane, [
7145
7639
  "xz",
7146
7640
  "xy",
7147
7641
  "yz"
7148
7642
  ]), [n, r] = [...t].map((e) => "xyz".indexOf(e)), i = (e) => `radius${"XYZ"[e]}`, a = i(3 - n - r);
7149
7643
  A("ellipse()", e, [
7150
- ...la,
7644
+ ..._a,
7151
7645
  i(n),
7152
7646
  i(r)
7153
7647
  ], { [a]: `an ellipse in '${t}' has '${i(n)}' and '${i(r)}' - set plane for another` });
@@ -7162,21 +7656,21 @@ function pa(e = {}) {
7162
7656
  ];
7163
7657
  f[n] = 1;
7164
7658
  let p = nt(/* @__PURE__ */ new Float32Array(4), f, d);
7165
- return new da(Array.from({ length: 64 }, (e, t) => {
7659
+ return new ya(Array.from({ length: 64 }, (e, t) => {
7166
7660
  let i = t / 64 * Math.PI * 2, a = new z();
7167
7661
  return a[n] = Math.cos(i) * c, a[r] = Math.sin(i) * l, a.applyQuaternion(p).add(u);
7168
7662
  }), { closed: !0 });
7169
7663
  }
7170
7664
  // src/registry.js
7171
- var ma = /* @__PURE__ */ new Map();
7172
- function ha(e) {
7173
- ma.set(e.type, e);
7665
+ var Sa = /* @__PURE__ */ new Map();
7666
+ function Ca(e) {
7667
+ Sa.set(e.type, e);
7174
7668
  }
7175
- function ga() {
7176
- return ma;
7669
+ function wa() {
7670
+ return Sa;
7177
7671
  }
7178
7672
  // src/describe.js
7179
- var _a = [
7673
+ var Ta = [
7180
7674
  "box",
7181
7675
  "sphere",
7182
7676
  "plane",
@@ -7187,27 +7681,27 @@ var _a = [
7187
7681
  "extrude",
7188
7682
  "axes",
7189
7683
  "grid"
7190
- ], va = null, ya = () => {
7191
- va ??= new Map([
7684
+ ], Ea = null, Da = () => {
7685
+ Ea ??= new Map([
7192
7686
  W,
7193
7687
  bt,
7194
- mn,
7195
- ii,
7196
- ci,
7197
- li,
7198
- ui,
7199
- di,
7688
+ _n,
7689
+ fi,
7690
+ gi,
7691
+ _i,
7692
+ vi,
7693
+ yi,
7200
7694
  Ot,
7201
7695
  kt,
7202
- yn,
7203
- bn,
7204
7696
  Sn,
7205
7697
  Cn,
7206
- wn
7698
+ Tn,
7699
+ En,
7700
+ Dn
7207
7701
  ].map((e) => [e.type, e]));
7208
- for (let [e, t] of ga()) va.set(e, t);
7209
- return va;
7210
- }, ba = {
7702
+ for (let [e, t] of wa()) Ea.set(e, t);
7703
+ return Ea;
7704
+ }, Oa = {
7211
7705
  Mesh: "mesh",
7212
7706
  Group: "group",
7213
7707
  Object3D: "node",
@@ -7225,10 +7719,10 @@ var _a = [
7225
7719
  Scene: "scene",
7226
7720
  light: "directional-light",
7227
7721
  camera: "perspective-camera"
7228
- }, xa = {
7722
+ }, ka = {
7229
7723
  chart: "import { chart } from 'phoria2/charts' first, which registers 'chart'",
7230
7724
  emitter: "'emitter' descriptions aren't supported yet - use new Emitter() from 'phoria2/particles'"
7231
- }, Sa = {
7725
+ }, Aa = {
7232
7726
  cube: "box",
7233
7727
  ball: "sphere",
7234
7728
  globe: "sphere",
@@ -7248,29 +7742,29 @@ var _a = [
7248
7742
  ExtrudeGeometry: "extrude",
7249
7743
  ShapeGeometry: "extrude"
7250
7744
  };
7251
- function Ca(e) {
7745
+ function ja(e) {
7252
7746
  if (/Material$/.test(e)) return "materials aren't nodes - give a mesh material: { color, roughness, metalness, ... }";
7253
- let t = Sa[e];
7747
+ let t = Aa[e];
7254
7748
  return t ? `geometry isn't a node - give a mesh geometry: { type: '${t}', ... }` : null;
7255
7749
  }
7256
- function wa(e) {
7750
+ function Ma(e) {
7257
7751
  if (e instanceof W) return e;
7258
7752
  (!e || typeof e != "object" || Array.isArray(e)) && E("create()", `expected a description such as { type: 'mesh', ... }, got ${j(e)}`);
7259
7753
  let { type: t, ...n } = e;
7260
- typeof t != "string" && E("create()", `a description needs a 'type': one of ${[...ya().keys()].join(", ")}`);
7261
- let r = ya().get(t);
7754
+ typeof t != "string" && E("create()", `a description needs a 'type': one of ${[...Da().keys()].join(", ")}`);
7755
+ let r = Da().get(t);
7262
7756
  if (!r) {
7263
- let e = ba[t], n = Ca(t) ?? xa[t];
7264
- E("create()", `unknown type '${t}' - ${e ? `use '${e}'` : n ?? `expected one of ${[...ya().keys()].join(", ")}${k(t, ya().keys())}`}`);
7757
+ let e = Oa[t], n = ja(t) ?? ka[t];
7758
+ E("create()", `unknown type '${t}' - ${e ? `use '${e}'` : n ?? `expected one of ${[...Da().keys()].join(", ")}${k(t, Da().keys())}`}`);
7265
7759
  }
7266
- return Array.isArray(n.children) && (n.children = n.children.map((e) => wa(e))), n.geometry && !(n.geometry instanceof X) && typeof n.geometry == "object" && "type" in n.geometry && (n.geometry = Ta(n.geometry, `create({ type: '${t}' })`)), new r(n);
7760
+ return Array.isArray(n.children) && (n.children = n.children.map((e) => Ma(e))), n.geometry && !(n.geometry instanceof X) && typeof n.geometry == "object" && "type" in n.geometry && (n.geometry = Na(n.geometry, `create({ type: '${t}' })`)), new r(n);
7267
7761
  }
7268
- function Ta(e, t = "createGeometry()") {
7269
- let { type: n, ...r } = e, i = Sa[n];
7270
- i && E(t, `geometry type '${n}' - use '${i}'`), P(t, "geometry.type", n, _a);
7271
- let a = xi[n];
7762
+ function Na(e, t = "createGeometry()") {
7763
+ let { type: n, ...r } = e, i = Aa[n];
7764
+ i && E(t, `geometry type '${n}' - use '${i}'`), P(t, "geometry.type", n, Ta);
7765
+ let a = ki[n];
7272
7766
  return a(Object.keys(r).length ? r : void 0);
7273
7767
  }
7274
- export { Dt as $, Un as A, F as At, bn as B, ii as C, T as Ct, Rn as D, j as Dt, wr as E, A as Et, Gn as F, s as Ft, pn as G, Cn as H, Fn as I, tn as J, Y as K, X as L, Xn as M, r as Mt, Kn as N, o as Nt, Vn as O, k as Ot, Jn as P, a as Pt, Nt as Q, yn as R, ui as S, z as St, Nr as T, P as Tt, wn as U, vn as V, mn as W, Rt as X, Ut as Y, jt as Z, Ei as _, oe as _t, pa as a, ut as at, ci as b, V as bt, Ri as c, rt as ct, Li as d, ot as dt, kt as et, Ni as f, Qe as ft, Di as g, H as gt, Mi as h, ye as ht, fa as i, W as it, Wn as j, x as jt, Hn as k, E as kt, wi as l, it as lt, ji as m, Ne as mt, ha as n, bt as nt, na as o, lt as ot, zi as p, Se as pt, ln as q, da as r, U as rt, Qi as s, st, wa as t, Ot as tt, Oi as u, nt as ut, Ai as v, ne as vt, li as w, M as wt, di as x, B as xt, ri as y, ie as yt, Sn as z };
7768
+ export { Nt as $, qn as A, E as At, Tn as B, fi as C, z as Ct, fr as D, A as Dt, Mr as E, P as Et, $n as F, a as Ft, _n as G, xn as H, Xn as I, s as It, fn as J, gn as K, zn as L, Yn as M, x as Mt, tr as N, r as Nt, Hn as O, j as Ot, Zn as P, o as Pt, jt as Q, X as R, vi as S, B as St, Vr as T, M as Tt, En as U, Cn as V, Dn as W, Ut as X, tn as Y, Rt as Z, Pi as _, H as _t, xa as a, W as at, gi as b, ie as bt, Ki as c, st as ct, Gi as d, nt as dt, Dt as et, Vi as f, ot as ft, Fi as g, ye as gt, Bi as h, Ne as ht, ba as i, U as it, Jn as j, F as jt, Kn as k, k as kt, Mi as l, rt as lt, zi as m, Se as mt, Ca as n, Ot as nt, ua as o, ut as ot, qi as p, Qe as pt, Y as q, ya as r, bt as rt, oa as s, lt as st, Ma as t, kt as tt, Ii as u, it as ut, Ri as v, oe as vt, _i as w, T as wt, yi as x, V as xt, di as y, ne as yt, Sn as z };
7275
7769
 
7276
7770
  //# sourceMappingURL=core.js.map