material-designer-runtime 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import * as e from "three";
2
- import { NearestFilter as t, NoColorSpace as n, OrthographicCamera as r, RepeatWrapping as i, Scene as a, Vector3 as o } from "three";
3
- import { MeshBasicNodeMaterial as s, MeshPhysicalNodeMaterial as c, QuadMesh as l, RenderTarget as u } from "three/webgpu";
4
- import { Fn as d, abs as f, acos as p, asin as m, atan as h, attribute as g, bool as _, bumpMap as v, ceil as y, clamp as b, color as x, cos as S, cosh as C, cross as w, dFdx as T, dFdy as E, degrees as ee, dot as D, exp as O, exp2 as te, float as k, floatBitsToUint as ne, floor as A, fract as j, fwidth as re, int as M, inverseSqrt as ie, length as N, log as ae, luminance as oe, max as P, min as F, mix as I, mod as L, mx_noise_float as R, normalLocal as se, normalMap as ce, normalWorld as le, normalize as ue, parallaxDirection as de, positionLocal as fe, positionWorld as pe, pow as z, radians as me, reflect as he, round as ge, sRGBTransferOETF as _e, saturate as ve, select as B, sign as ye, sin as V, sinh as be, smoothstep as H, sqrt as xe, step as Se, tan as Ce, tanh as we, texture as U, trunc as Te, uint as W, uniform as G, uniformArray as Ee, uv as K, vec2 as q, vec3 as J, vec4 as De } from "three/tsl";
5
- var Oe = {
6
- version: 2,
2
+ import { NearestFilter as t, NoColorSpace as n, OrthographicCamera as r, RepeatWrapping as i, Scene as a } from "three";
3
+ import { MeshBasicNodeMaterial as o, MeshLambertNodeMaterial as s, MeshMatcapNodeMaterial as c, MeshPhongNodeMaterial as l, MeshPhysicalNodeMaterial as u, MeshStandardNodeMaterial as d, MeshToonNodeMaterial as f, QuadMesh as p, RenderTarget as m } from "three/webgpu";
4
+ import { Fn as h, abs as g, acos as _, asin as v, atan as y, attribute as b, bool as x, bumpMap as S, ceil as C, clamp as w, color as T, cos as E, cosh as D, cross as ee, dFdx as te, dFdy as ne, degrees as re, dot as O, exp as ie, exp2 as ae, float as k, floatBitsToUint as oe, floor as A, fract as j, fwidth as se, int as M, inverseSqrt as ce, length as le, log as ue, luminance as de, max as N, min as P, mix as F, mod as I, mx_noise_float as fe, normalLocal as pe, normalMap as me, normalWorld as he, normalize as ge, parallaxDirection as _e, positionLocal as ve, positionWorld as ye, pow as L, radians as be, reflect as xe, round as Se, sRGBTransferOETF as Ce, saturate as we, select as R, sign as Te, sin as z, sinh as Ee, smoothstep as B, sqrt as De, step as Oe, tan as ke, tanh as Ae, texture as V, trunc as je, uint as H, uniform as U, uniformArray as Me, uv as W, vec2 as G, vec3 as K, vec4 as Ne } from "three/tsl";
5
+ var Pe = {
6
+ version: 3,
7
7
  nodes: [{
8
8
  id: "pr",
9
- type: "principled-bsdf",
10
- params: {},
9
+ type: "shader-material",
10
+ params: { materialType: "physical" },
11
11
  position: {
12
12
  x: 420,
13
13
  y: 160
@@ -29,20 +29,20 @@ var Oe = {
29
29
  toNode: "out",
30
30
  toInput: "surface"
31
31
  }]
32
- }, ke = [
32
+ }, Fe = [
33
33
  0,
34
34
  .25,
35
35
  .5,
36
36
  .75,
37
37
  1
38
- ], Ae = [
38
+ ], Ie = [
39
39
  "C",
40
40
  "R",
41
41
  "G",
42
42
  "B"
43
43
  ];
44
- function je(e) {
45
- let t = (e) => Array.from({ length: 5 }, (t, n) => e?.[n] ?? ke[n]);
44
+ function Le(e) {
45
+ let t = (e) => Array.from({ length: 5 }, (t, n) => e?.[n] ?? Fe[n]);
46
46
  return [
47
47
  ...t(e?.C),
48
48
  ...t(e?.R),
@@ -50,14 +50,62 @@ function je(e) {
50
50
  ...t(e?.B)
51
51
  ];
52
52
  }
53
- var Me = "group", Ne = "group-input", Pe = "group-output", Fe = "material-output", Ie = [
53
+ var Re = [
54
+ "standard",
55
+ "physical",
56
+ "lambert",
57
+ "toon",
58
+ "phong",
59
+ "matcap"
60
+ ], ze = {
61
+ standard: {
62
+ roughMetal: !0,
63
+ physicalLobes: !1,
64
+ ao: !0,
65
+ emissive: !0
66
+ },
67
+ physical: {
68
+ roughMetal: !0,
69
+ physicalLobes: !0,
70
+ ao: !0,
71
+ emissive: !0
72
+ },
73
+ lambert: {
74
+ roughMetal: !1,
75
+ physicalLobes: !1,
76
+ ao: !0,
77
+ emissive: !0
78
+ },
79
+ phong: {
80
+ roughMetal: !1,
81
+ physicalLobes: !1,
82
+ ao: !0,
83
+ emissive: !0
84
+ },
85
+ toon: {
86
+ roughMetal: !1,
87
+ physicalLobes: !1,
88
+ ao: !0,
89
+ emissive: !0
90
+ },
91
+ matcap: {
92
+ roughMetal: !1,
93
+ physicalLobes: !1,
94
+ ao: !1,
95
+ emissive: !1
96
+ }
97
+ };
98
+ function Be(e) {
99
+ return Re.includes(e) ? e : "physical";
100
+ }
101
+ var Ve = "group", He = "group-input", Ue = "group-output", q = "material-output", We = "shader-material", Ge = [
54
102
  "baseColor",
55
103
  "normal",
56
104
  "emission",
57
105
  "roughness",
58
106
  "metallic",
59
107
  "ambientOcclusion"
60
- ], Le = {
108
+ ], Ke = {
61
109
  float: {
62
110
  float: "identity",
63
111
  vector: "float-to-vector",
@@ -75,28 +123,28 @@ var Me = "group", Ne = "group-input", Pe = "group-output", Fe = "material-output
75
123
  },
76
124
  shader: { shader: "identity" }
77
125
  };
78
- function Re(e, t) {
79
- return Le[e]?.[t];
126
+ function qe(e, t) {
127
+ return Ke[e]?.[t];
80
128
  }
81
129
  //#endregion
82
130
  //#region src/tsl/blender-noise.ts
83
- var Y = (e, t) => e.shiftLeft(t).bitOr(e.shiftRight(32 - t));
84
- function ze(e, t, n) {
85
- let r = 3735928584, i = W(r).toVar(), a = W(r).toVar(), o = W(r).toVar();
86
- return o.assign(o.add(n)), a.assign(a.add(t)), i.assign(i.add(e)), o.assign(o.bitXor(a)), o.assign(o.sub(Y(a, 14))), i.assign(i.bitXor(o)), i.assign(i.sub(Y(o, 11))), a.assign(a.bitXor(i)), a.assign(a.sub(Y(i, 25))), o.assign(o.bitXor(a)), o.assign(o.sub(Y(a, 16))), i.assign(i.bitXor(o)), i.assign(i.sub(Y(o, 4))), a.assign(a.bitXor(i)), a.assign(a.sub(Y(i, 14))), o.assign(o.bitXor(a)), o.assign(o.sub(Y(a, 24))), o;
131
+ var Je = (e, t) => e.shiftLeft(t).bitOr(e.shiftRight(32 - t));
132
+ function Ye(e, t, n) {
133
+ let r = 3735928584, i = H(r).toVar(), a = H(r).toVar(), o = H(r).toVar();
134
+ return o.assign(o.add(n)), a.assign(a.add(t)), i.assign(i.add(e)), o.assign(o.bitXor(a)), o.assign(o.sub(Je(a, 14))), i.assign(i.bitXor(o)), i.assign(i.sub(Je(o, 11))), a.assign(a.bitXor(i)), a.assign(a.sub(Je(i, 25))), o.assign(o.bitXor(a)), o.assign(o.sub(Je(a, 16))), i.assign(i.bitXor(o)), i.assign(i.sub(Je(o, 4))), a.assign(a.bitXor(i)), a.assign(a.sub(Je(i, 14))), o.assign(o.bitXor(a)), o.assign(o.sub(Je(a, 24))), o;
87
135
  }
88
- var Be = (e, t, n) => ze(W(e), W(t), W(n)), Ve = (e) => e.mul(e).mul(e).mul(e.mul(e.mul(6).sub(15)).add(10)), He = (e, t) => B(t.notEqual(W(0)), e.negate(), e);
89
- function Ue(e, t, n, r) {
90
- let i = e.bitAnd(W(15)).toVar(), a = B(i.lessThan(W(8)), t, n), o = B(i.equal(W(12)).or(i.equal(W(14))), t, r), s = B(i.lessThan(W(4)), n, o);
91
- return He(a, i.bitAnd(W(1))).add(He(s, i.bitAnd(W(2))));
136
+ var Xe = (e, t, n) => Ye(H(e), H(t), H(n)), Ze = (e) => e.mul(e).mul(e).mul(e.mul(e.mul(6).sub(15)).add(10)), Qe = (e, t) => R(t.notEqual(H(0)), e.negate(), e);
137
+ function $e(e, t, n, r) {
138
+ let i = e.bitAnd(H(15)).toVar(), a = R(i.lessThan(H(8)), t, n), o = R(i.equal(H(12)).or(i.equal(H(14))), t, r), s = R(i.lessThan(H(4)), n, o);
139
+ return Qe(a, i.bitAnd(H(1))).add(Qe(s, i.bitAnd(H(2))));
92
140
  }
93
- function We(e, t, n, r) {
141
+ function et(e, t, n, r) {
94
142
  let i = k(1).sub(t), a = k(1).sub(n);
95
143
  return k(1).sub(r).mul(a.mul(e[0].mul(i).add(e[1].mul(t))).add(n.mul(e[2].mul(i).add(e[3].mul(t))))).add(r.mul(a.mul(e[4].mul(i).add(e[5].mul(t))).add(n.mul(e[6].mul(i).add(e[7].mul(t))))));
96
144
  }
97
- function Ge(e) {
98
- let t = A(e.x).toVar(), n = A(e.y).toVar(), r = A(e.z).toVar(), i = e.x.sub(t).toVar(), a = e.y.sub(n).toVar(), o = e.z.sub(r).toVar(), s = M(t), c = M(n), l = M(r), u = Ve(i), d = Ve(a), f = Ve(o), p = (e, t, n) => Ue(Be(s.add(e), c.add(t), l.add(n)), i.sub(e), a.sub(t), o.sub(n));
99
- return We([
145
+ function tt(e) {
146
+ let t = A(e.x).toVar(), n = A(e.y).toVar(), r = A(e.z).toVar(), i = e.x.sub(t).toVar(), a = e.y.sub(n).toVar(), o = e.z.sub(r).toVar(), s = M(t), c = M(n), l = M(r), u = Ze(i), d = Ze(a), f = Ze(o), p = (e, t, n) => $e(Xe(s.add(e), c.add(t), l.add(n)), i.sub(e), a.sub(t), o.sub(n));
147
+ return et([
100
148
  p(0, 0, 0),
101
149
  p(1, 0, 0),
102
150
  p(0, 1, 0),
@@ -107,18 +155,18 @@ function Ge(e) {
107
155
  p(1, 1, 1)
108
156
  ], u, d, f);
109
157
  }
110
- var Ke = (e) => Ge(e).mul(.982);
111
- function qe(e, t, n, r) {
158
+ var nt = (e) => tt(e).mul(.982);
159
+ function rt(e, t, n, r) {
112
160
  let i = Math.max(0, Math.min(15, Math.floor(t)));
113
- return d(() => {
161
+ return h(() => {
114
162
  let t = k(1).toVar(), a = k(1).toVar(), o = k(0).toVar(), s = k(0).toVar();
115
- for (let c = 0; c <= i; c++) o.assign(o.add(Ke(e.mul(a)).mul(t))), s.assign(s.add(t)), t.assign(t.mul(n)), a.assign(a.mul(r));
163
+ for (let c = 0; c <= i; c++) o.assign(o.add(nt(e.mul(a)).mul(t))), s.assign(s.add(t)), t.assign(t.mul(n)), a.assign(a.mul(r));
116
164
  return o.div(s).mul(.5).add(.5);
117
165
  })();
118
166
  }
119
167
  //#endregion
120
168
  //#region src/graph/nodes/texture/fbm.ts
121
- var Je = {
169
+ var it = {
122
170
  type: "fbm",
123
171
  nodeClass: "texture",
124
172
  label: "Noise (FBM)",
@@ -169,9 +217,9 @@ var Je = {
169
217
  }
170
218
  ],
171
219
  build(e) {
172
- return { field: qe((e.inputs.coord ?? e.coord).mul(e.uniforms.scale), e.params.octaves ?? 4, e.uniforms.gain, e.uniforms.lacunarity) };
220
+ return { field: rt((e.inputs.coord ?? e.coord).mul(e.live("scale")), e.constant("octaves") ?? 4, e.live("gain"), e.live("lacunarity")) };
173
221
  }
174
- }, Ye = {
222
+ }, at = {
175
223
  type: "domain-warp",
176
224
  nodeClass: "vector",
177
225
  label: "Domain Warp",
@@ -201,173 +249,175 @@ var Je = {
201
249
  default: 1
202
250
  }],
203
251
  build(e) {
204
- let t = e.inputs.coord ?? e.coord, n = t.div(e.uniforms.scale), r = R(n.add(J(11.3, 0, 0))), i = R(n.add(J(0, 47.7, 0))), a = R(n.add(J(0, 0, 93.1)));
205
- return { coord: t.add(J(r, i, a).mul(e.uniforms.amount)) };
206
- }
207
- }, Xe = (e) => L(e.mul(34).add(1).mul(e), 289), Ze = (e) => e.mul(e).mul(e).mul(e.mul(e.mul(6).sub(15)).add(10)), Qe = d(([e, t]) => {
208
- let n = A(e.xyxy).add(De(0, 0, 1, 1)), r = j(e.xyxy).sub(De(0, 0, 1, 1)), i = L(L(n, t.xyxy), 289), a = i.xzxz, o = i.yyww, s = r.xzxz, c = r.yyww, l = j(Xe(Xe(a).add(o)).mul(.0243902439)).mul(2).sub(1), u = f(l).sub(.5), d = l.sub(A(l.add(.5))), p = q(d.x, u.x), m = q(d.y, u.y), h = q(d.z, u.z), g = q(d.w, u.w), _ = k(1.79284291400159).sub(k(.85373472095314).mul(De(D(p, p), D(h, h), D(m, m), D(g, g))));
209
- p = p.mul(_.x), h = h.mul(_.y), m = m.mul(_.z), g = g.mul(_.w);
210
- let v = D(p, q(s.x, c.x)), y = D(m, q(s.y, c.y)), b = D(h, q(s.z, c.z)), x = D(g, q(s.w, c.w)), S = Ze(r.xy), C = I(q(v, b), q(y, x), S.x);
211
- return I(C.x, C.y, S.y).mul(2.3);
252
+ let t = e.inputs.coord ?? e.coord, n = t.div(e.live("scale")), r = fe(n.add(K(11.3, 0, 0))), i = fe(n.add(K(0, 47.7, 0))), a = fe(n.add(K(0, 0, 93.1)));
253
+ return { coord: t.add(K(r, i, a).mul(e.live("amount"))) };
254
+ }
255
+ }, ot = (e) => I(e.mul(34).add(1).mul(e), 289), st = (e) => e.mul(e).mul(e).mul(e.mul(e.mul(6).sub(15)).add(10)), ct = h(([e, t]) => {
256
+ let n = A(e.xyxy).add(Ne(0, 0, 1, 1)), r = j(e.xyxy).sub(Ne(0, 0, 1, 1)), i = I(I(n, t.xyxy), 289), a = i.xzxz, o = i.yyww, s = r.xzxz, c = r.yyww, l = j(ot(ot(a).add(o)).mul(.0243902439)).mul(2).sub(1), u = g(l).sub(.5), d = l.sub(A(l.add(.5))), f = G(d.x, u.x), p = G(d.y, u.y), m = G(d.z, u.z), h = G(d.w, u.w), _ = k(1.79284291400159).sub(k(.85373472095314).mul(Ne(O(f, f), O(m, m), O(p, p), O(h, h))));
257
+ f = f.mul(_.x), m = m.mul(_.y), p = p.mul(_.z), h = h.mul(_.w);
258
+ let v = O(f, G(s.x, c.x)), y = O(p, G(s.y, c.y)), b = O(m, G(s.z, c.z)), x = O(h, G(s.w, c.w)), S = st(r.xy), C = F(G(v, b), G(y, x), S.x);
259
+ return F(C.x, C.y, S.y).mul(2.3);
212
260
  });
213
- function $e(e, t, n, r, i, a, o = 2) {
214
- let s = typeof t == "number" ? k(Math.max(1, Math.round(t))) : t, c = typeof n == "number" ? k(Math.max(1, Math.round(n))) : n, l = re(e), u = k(0), d = k(0), f = k(1), p = Math.max(2, Math.round(o));
261
+ function lt(e, t, n, r, i, a, o = 2) {
262
+ let s = typeof t == "number" ? k(Math.max(1, Math.round(t))) : t, c = typeof n == "number" ? k(Math.max(1, Math.round(n))) : n, l = se(e), u = k(0), d = k(0), f = k(1), p = Math.max(2, Math.round(o));
215
263
  for (let t = 0; t < Math.max(1, r); t++) {
216
- let n = Math.round(p ** +t), r = q(s.mul(n), c.mul(n)), o = f;
264
+ let n = Math.round(p ** +t), r = G(s.mul(n), c.mul(n)), o = f;
217
265
  if (a !== void 0) {
218
- let e = P(r.x.mul(l.x), r.y.mul(l.y)), t = b(k(1).sub(H(.2, .5, e)), 0, 1);
219
- o = f.mul(I(k(1), t, a));
266
+ let e = N(r.x.mul(l.x), r.y.mul(l.y)), t = w(k(1).sub(B(.2, .5, e)), 0, 1);
267
+ o = f.mul(F(k(1), t, a));
220
268
  }
221
- u = u.add(o.mul(Qe(e.mul(r), r))), d = d.add(o), f = f.mul(i);
269
+ u = u.add(o.mul(ct(e.mul(r), r))), d = d.add(o), f = f.mul(i);
222
270
  }
223
- return I(k(0), u.div(d.max(1e-4)), F(d, 1));
271
+ return F(k(0), u.div(d.max(1e-4)), P(d, 1));
224
272
  }
225
273
  //#endregion
226
274
  //#region src/tsl/noise/fbm.ts
227
- function et(e, t, n, r, i, a, o, s = 2) {
228
- let c = typeof t == "number" ? k(Math.max(1, Math.round(t))) : t, l = typeof n == "number" ? k(Math.max(1, Math.round(n))) : n, u = re(e), d = k(0), f = k(0), p = k(1), m = Math.max(2, Math.round(s));
275
+ function ut(e, t, n, r, i, a, o, s = 2) {
276
+ let c = typeof t == "number" ? k(Math.max(1, Math.round(t))) : t, l = typeof n == "number" ? k(Math.max(1, Math.round(n))) : n, u = se(e), d = k(0), f = k(0), p = k(1), m = Math.max(2, Math.round(s));
229
277
  for (let t = 0; t < Math.max(1, r); t++) {
230
- let n = Math.round(m ** +t), r = c.mul(n), s = l.mul(n), h = e.mul(q(r, s)), g = p;
278
+ let n = Math.round(m ** +t), r = c.mul(n), s = l.mul(n), h = e.mul(G(r, s)), g = p;
231
279
  if (o !== void 0) {
232
- let e = P(r.mul(u.x), s.mul(u.y)), t = b(k(1).sub(H(.2, .5, e)), 0, 1);
233
- g = p.mul(I(k(1), t, o));
280
+ let e = N(r.mul(u.x), s.mul(u.y)), t = w(k(1).sub(B(.2, .5, e)), 0, 1);
281
+ g = p.mul(F(k(1), t, o));
234
282
  }
235
283
  d = d.add(g.mul(a(h, r, s))), f = f.add(g), p = p.mul(i);
236
284
  }
237
- return I(k(.5), d.div(f.max(1e-4)), F(f, 1));
285
+ return F(k(.5), d.div(f.max(1e-4)), P(f, 1));
238
286
  }
239
287
  //#endregion
240
288
  //#region src/tsl/noise/hash.ts
241
- var tt = 1 / 2147483648, nt = d(([e, t, n]) => {
289
+ var dt = 1 / 2147483648, ft = h(([e, t, n]) => {
242
290
  let r = e.mul(1664525).add(1013904223).toVar(), i = t.mul(1664525).add(1013904223).toVar(), a = n.mul(1664525).add(1013904223).toVar();
243
291
  r.assign(r.add(i.mul(a))), i.assign(i.add(a.mul(r))), a.assign(a.add(r.mul(i))), r.assign(r.bitXor(r.shiftRight(16))), i.assign(i.bitXor(i.shiftRight(16))), a.assign(a.bitXor(a.shiftRight(16))), r.assign(r.add(i.mul(a))), i.assign(i.add(a.mul(r))), a.assign(a.add(r.mul(i)));
244
292
  let o = M(2147483647);
245
- return J(k(r.bitAnd(o)).mul(tt), k(i.bitAnd(o)).mul(tt), k(a.bitAnd(o)).mul(tt));
293
+ return K(k(r.bitAnd(o)).mul(dt), k(i.bitAnd(o)).mul(dt), k(a.bitAnd(o)).mul(dt));
246
294
  });
247
- function rt(e, t) {
295
+ function pt(e, t) {
248
296
  return typeof t == "number" && t <= 0 ? e : e.sub(M(A(k(e).div(t))).mul(M(t)));
249
297
  }
250
- function it(e, t, n, r) {
251
- return nt(rt(e, n), rt(t, r), M(0)).x;
298
+ function mt(e, t, n, r) {
299
+ return ft(pt(e, n), pt(t, r), M(0)).x;
252
300
  }
253
- function at(e, t, n, r) {
254
- return nt(rt(e, n), rt(t, r), M(0));
301
+ function ht(e, t, n, r) {
302
+ return ft(pt(e, n), pt(t, r), M(0));
255
303
  }
256
- function ot(e, t, n, r, i) {
257
- return nt(rt(e, r), rt(t, i), M(n));
304
+ function J(e, t, n, r, i) {
305
+ return ft(pt(e, r), pt(t, i), M(n));
258
306
  }
259
307
  //#endregion
260
308
  //#region src/tsl/noise/value.ts
261
- function st(e, t, n) {
262
- let r = A(e), i = e.sub(r), a = i.mul(i).mul(k(3).sub(i.mul(2))), o = M(r.x), s = M(r.y), c = it(o, s, t, n), l = it(o.add(1), s, t, n), u = it(o, s.add(1), t, n), d = it(o.add(1), s.add(1), t, n);
263
- return I(I(c, l, a.x), I(u, d, a.x), a.y);
309
+ function gt(e, t, n) {
310
+ let r = A(e), i = e.sub(r), a = i.mul(i).mul(k(3).sub(i.mul(2))), o = M(r.x), s = M(r.y), c = mt(o, s, t, n), l = mt(o.add(1), s, t, n), u = mt(o, s.add(1), t, n), d = mt(o.add(1), s.add(1), t, n);
311
+ return F(F(c, l, a.x), F(u, d, a.x), a.y);
264
312
  }
265
313
  //#endregion
266
314
  //#region src/tsl/noise/cellular.ts
267
- var ct = 2;
268
- function lt(e, t, n) {
269
- let r = A(e), i = e.sub(r), a = M(r.x), o = M(r.y), s = J(i.x, i.y, k(0)), c = k(1e10);
315
+ var _t = 2;
316
+ function vt(e, t, n) {
317
+ let r = A(e), i = e.sub(r), a = M(r.x), o = M(r.y), s = K(i.x, i.y, k(0)), c = k(1e10);
270
318
  for (let e = -1; e <= 1; e++) for (let r = -1; r <= 1; r++) {
271
- let i = at(a.add(e), o.add(r), t, n), l = J(k(e).add(i.x), k(r).add(i.y), i.z);
272
- c = F(c, N(l.sub(s)));
319
+ let i = ht(a.add(e), o.add(r), t, n), l = K(k(e).add(i.x), k(r).add(i.y), i.z);
320
+ c = P(c, le(l.sub(s)));
273
321
  }
274
- return b(k(1).sub(c), 0, 1);
322
+ return w(k(1).sub(c), 0, 1);
275
323
  }
276
- function ut(e, t, n) {
324
+ function yt(e, t, n) {
277
325
  let r = A(e), i = e.sub(r), a = M(r.x), o = M(r.y), s = k(0), c = k(0);
278
326
  for (let e = -1; e <= 1; e++) for (let r = -1; r <= 1; r++) {
279
- let l = at(a.add(e), o.add(r), t, n), u = z(H(1.414, 0, N(q(e, r).sub(i).add(q(l.x, l.y)))), ct);
327
+ let l = ht(a.add(e), o.add(r), t, n), u = L(B(1.414, 0, le(G(e, r).sub(i).add(G(l.x, l.y)))), _t);
280
328
  s = s.add(l.z.mul(u)), c = c.add(u);
281
329
  }
282
330
  return s.div(c.max(1e-4));
283
331
  }
284
332
  //#endregion
285
333
  //#region src/tsl/noise/flow.ts
286
- var dt = (e, t) => Qe(e, q(t, t)), ft = d(([e, t]) => {
287
- let n = k(.1), r = dt(e.add(q(n, 0)), t), i = dt(e.add(q(0, n)), t), a = dt(e.sub(q(n, 0)), t), o = dt(e.sub(q(0, n)), t);
288
- return q(r.sub(a), i.sub(o)).div(n).mul(.5);
334
+ var bt = (e, t) => ct(e, G(t, t)), xt = h(([e, t]) => {
335
+ let n = k(.1), r = bt(e.add(G(n, 0)), t), i = bt(e.add(G(0, n)), t), a = bt(e.sub(G(n, 0)), t), o = bt(e.sub(G(0, n)), t);
336
+ return G(r.sub(a), i.sub(o)).div(n).mul(.5);
289
337
  });
290
- function pt(e, t, n) {
291
- let r = ft(e, t);
292
- return J(r.x, r.y, k(0));
338
+ function St(e, t, n) {
339
+ let r = xt(e, t);
340
+ return K(r.x, r.y, k(0));
293
341
  }
294
- function mt(e, t, n) {
295
- return b(ft(e, t).length().mul(.6).add(.2), 0, 1);
342
+ function Ct(e, t, n) {
343
+ return w(xt(e, t).length().mul(.6).add(.2), 0, 1);
296
344
  }
297
- function ht(e, t, n) {
298
- let r = ft(e, t);
299
- return b(P(f(r.x), f(r.y)), 0, 1);
345
+ function wt(e, t, n) {
346
+ let r = xt(e, t);
347
+ return w(N(g(r.x), g(r.y)), 0, 1);
300
348
  }
301
- function gt(e, t, n) {
302
- let r = ft(e, t).mul(.4);
303
- return dt(e.add(r), t).mul(.5).add(.5);
349
+ function Tt(e, t, n) {
350
+ let r = xt(e, t).mul(.4);
351
+ return bt(e.add(r), t).mul(.5).add(.5);
304
352
  }
305
353
  //#endregion
306
354
  //#region src/tsl/noise/gabor.ts
307
- var _t = 6.283185307179586, vt = Math.PI, yt = 8, bt = d(([e, t, n, r, i]) => {
355
+ var Et = 6.283185307179586, Dt = Math.PI, Ot = 8, kt = h(([e, t, n, r, i]) => {
308
356
  let a = e.mul(t), o = A(a), s = a.sub(o), c = k(0).toVar();
309
357
  for (let e = -1; e <= 1; e++) for (let a = -1; a <= 1; a++) {
310
- let l = M(o.x).add(a), u = M(o.y).add(e), d = s.sub(q(a, e));
311
- for (let e = 0; e < yt; e++) {
312
- let a = ot(l, u, e * 2, t, t), o = ot(l, u, e * 2 + 1, t, t), s = i.add(o.x.sub(.5).mul(vt).mul(r)), f = d.sub(q(a.x, a.y)), p = D(f, f), m = O(p.mul(-vt)).mul(k(.5).add(S(p.mul(vt)).mul(.5))), h = D(f, q(S(s), V(s)).mul(n)).mul(_t), g = I(k(-1), k(1), Se(.5, a.z)), _ = k(1).sub(Se(1, p));
313
- c.addAssign(V(h).mul(m).mul(g).mul(_));
358
+ let l = M(o.x).add(a), u = M(o.y).add(e), d = s.sub(G(a, e));
359
+ for (let e = 0; e < Ot; e++) {
360
+ let a = J(l, u, e * 2, t, t), o = J(l, u, e * 2 + 1, t, t), s = i.add(o.x.sub(.5).mul(Dt).mul(r)), f = d.sub(G(a.x, a.y)), p = O(f, f), m = ie(p.mul(-Dt)).mul(k(.5).add(E(p.mul(Dt)).mul(.5))), h = O(f, G(E(s), z(s)).mul(n)).mul(Et), g = F(k(-1), k(1), Oe(.5, a.z)), _ = k(1).sub(Oe(1, p));
361
+ c.addAssign(z(h).mul(m).mul(g).mul(_));
314
362
  }
315
363
  }
316
364
  return c.div(6).mul(.5).add(.5);
317
365
  });
318
366
  //#endregion
319
367
  //#region src/tsl/noise/simplex.ts
320
- function xt(e, t, n) {
321
- let r = q(e.x.add(e.y.mul(.5)), e.y), i = A(r), a = r.sub(i), o = Se(a.y, a.x), s = q(o, k(1).sub(o)), c = q(i.x.sub(i.y.mul(.5)), i.y), l = q(c.x.add(s.x).sub(s.y.mul(.5)), c.y.add(s.y)), u = q(c.x.add(.5), c.y.add(1)), d = e.sub(c), f = e.sub(l), p = e.sub(u), m = L(J(c.x, l.x, u.x), k(t)), h = L(J(c.y, l.y, u.y), k(n)), g = A(m.add(h.mul(.5)).add(.5)), _ = A(h.add(.5)), v = L(g, 289);
322
- v = L(v.mul(51).add(2).mul(v).add(_), 289), v = L(v.mul(34).add(10).mul(v), 289);
323
- let y = v.mul(.07482), x = S(y), C = V(y), w = q(x.x, C.x), T = q(x.y, C.y), E = q(x.z, C.z), ee = P(k(.8).sub(J(D(d, d), D(f, f), D(p, p))), 0), O = ee.mul(ee);
324
- return b(D(O.mul(O), J(D(w, d), D(T, f), D(E, p))).mul(10.9).mul(.5).add(.5), 0, 1);
368
+ function At(e, t, n) {
369
+ let r = G(e.x.add(e.y.mul(.5)), e.y), i = A(r), a = r.sub(i), o = Oe(a.y, a.x), s = G(o, k(1).sub(o)), c = G(i.x.sub(i.y.mul(.5)), i.y), l = G(c.x.add(s.x).sub(s.y.mul(.5)), c.y.add(s.y)), u = G(c.x.add(.5), c.y.add(1)), d = e.sub(c), f = e.sub(l), p = e.sub(u), m = I(K(c.x, l.x, u.x), k(t)), h = I(K(c.y, l.y, u.y), k(n)), g = A(m.add(h.mul(.5)).add(.5)), _ = A(h.add(.5)), v = I(g, 289);
370
+ v = I(v.mul(51).add(2).mul(v).add(_), 289), v = I(v.mul(34).add(10).mul(v), 289);
371
+ let y = v.mul(.07482), b = E(y), x = z(y), S = G(b.x, x.x), C = G(b.y, x.y), T = G(b.z, x.z), D = N(k(.8).sub(K(O(d, d), O(f, f), O(p, p))), 0), ee = D.mul(D);
372
+ return w(O(ee.mul(ee), K(O(S, d), O(C, f), O(T, p))).mul(10.9).mul(.5).add(.5), 0, 1);
325
373
  }
326
374
  //#endregion
327
375
  //#region src/tsl/noise/wavelet.ts
328
- var St = 6.283185307179586;
329
- function Ct(e, t, n) {
330
- let r = A(e), i = j(e).sub(.5), a = it(M(r.x), M(r.y), t, n).mul(St), o = S(a), s = V(a), c = o.mul(i.x).sub(s.mul(i.y)), l = s.mul(i.x).add(o.mul(i.y)), u = H(.25, 0, D(q(c, l), q(c, l)));
331
- return b(V(c.mul(10)).mul(u).mul(.5).add(.5), 0, 1);
376
+ var jt = 6.283185307179586;
377
+ function Mt(e, t, n) {
378
+ let r = A(e), i = j(e).sub(.5), a = mt(M(r.x), M(r.y), t, n).mul(jt), o = E(a), s = z(a), c = o.mul(i.x).sub(s.mul(i.y)), l = s.mul(i.x).add(o.mul(i.y)), u = B(.25, 0, O(G(c, l), G(c, l)));
379
+ return w(z(c.mul(10)).mul(u).mul(.5).add(.5), 0, 1);
332
380
  }
333
381
  //#endregion
334
382
  //#region src/tsl/noise/erosion.ts
335
- function wt(e, t, n) {
336
- let r = ft(e, t), i = Qe(e.add(r.mul(.6)), q(t, t)).mul(.5).add(.5);
337
- return b(k(1).sub(i.mul(2).sub(1).abs()), 0, 1);
383
+ function Nt(e, t, n) {
384
+ let r = xt(e, t), i = ct(e.add(r.mul(.6)), G(t, t)).mul(.5).add(.5);
385
+ return w(k(1).sub(i.mul(2).sub(1).abs()), 0, 1);
338
386
  }
339
387
  //#endregion
340
388
  //#region src/graph/nodes/texture/tileable-noise.ts
341
- var Tt = [
389
+ var Pt = [
342
390
  "perlin-fbm",
343
391
  "value",
344
392
  "worley",
345
393
  "voronoi-smooth",
346
394
  "gabor",
347
- "stone",
395
+ "simplex",
396
+ "wavelet"
397
+ ], Ft = [
398
+ "none",
399
+ "curl",
348
400
  "paper",
349
401
  "wool",
350
- "simplex",
351
- "wavelet",
352
- "erosion",
353
- "curl"
354
- ], X = [
402
+ "stone",
403
+ "erosion"
404
+ ], Y = [
355
405
  "octaves",
356
406
  "gain",
357
407
  "lacunarity",
358
408
  "antialias",
359
409
  "tileSize"
360
- ], Et = {
361
- "perlin-fbm": ["aspect", ...X],
362
- value: ["aspect", ...X],
363
- worley: X,
364
- "voronoi-smooth": X,
365
- stone: X,
366
- paper: X,
367
- wool: X,
368
- simplex: X,
369
- wavelet: X,
370
- erosion: X,
410
+ ], It = {
411
+ "perlin-fbm": ["aspect", ...Y],
412
+ value: ["aspect", ...Y],
413
+ worley: Y,
414
+ "voronoi-smooth": Y,
415
+ stone: Y,
416
+ paper: Y,
417
+ wool: Y,
418
+ simplex: Y,
419
+ wavelet: Y,
420
+ erosion: Y,
371
421
  gabor: [
372
422
  "gaborFreq",
373
423
  "gaborAniso",
@@ -375,25 +425,25 @@ var Tt = [
375
425
  "tileSize"
376
426
  ],
377
427
  curl: []
378
- }, Dt = {
379
- value: st,
380
- worley: lt,
381
- "voronoi-smooth": ut,
382
- stone: gt,
383
- paper: mt,
384
- wool: ht,
385
- wavelet: Ct,
386
- erosion: wt
387
- }, Ot = [{
428
+ }, Lt = {
429
+ value: gt,
430
+ worley: vt,
431
+ "voronoi-smooth": yt,
432
+ stone: Tt,
433
+ paper: Ct,
434
+ wool: wt,
435
+ wavelet: Mt,
436
+ erosion: Nt
437
+ }, Rt = [{
388
438
  key: "field",
389
439
  kind: "float"
390
- }], kt = [{
440
+ }], zt = [{
391
441
  key: "field",
392
442
  kind: "float"
393
443
  }, {
394
444
  key: "vector",
395
445
  kind: "vector"
396
- }], At = {
446
+ }], Bt = {
397
447
  type: "tileable-noise",
398
448
  nodeClass: "texture",
399
449
  label: "Tileable Noise",
@@ -409,11 +459,18 @@ var Tt = [
409
459
  params: [
410
460
  {
411
461
  key: "noiseType",
412
- label: "type",
462
+ label: "algorithm",
413
463
  type: "select",
414
- options: Tt,
464
+ options: Pt,
415
465
  default: "perlin-fbm"
416
466
  },
467
+ {
468
+ key: "preset",
469
+ label: "preset",
470
+ type: "select",
471
+ options: Ft,
472
+ default: "none"
473
+ },
417
474
  {
418
475
  key: "scale",
419
476
  label: "scale",
@@ -516,84 +573,84 @@ var Tt = [
516
573
  key: "coord",
517
574
  kind: "vector"
518
575
  }],
519
- outputs: e.noiseType === "curl" ? kt : Ot
576
+ outputs: e.noiseType === "perlin-fbm" && e.preset === "curl" ? zt : Rt
520
577
  };
521
578
  },
522
579
  paramsFor(e) {
523
- let t = Et[e.noiseType ?? "perlin-fbm"] ?? [], n = new Set([
580
+ let t = e.noiseType ?? "perlin-fbm", n = e.preset ?? "none", r = It[t === "perlin-fbm" && n !== "none" ? n : t] ?? [], i = new Set([
524
581
  "noiseType",
525
582
  "scale",
526
- ...t
583
+ ...r
527
584
  ]);
528
- return At.params.filter((e) => n.has(e.key));
585
+ return t === "perlin-fbm" && i.add("preset"), Bt.params.filter((e) => i.has(e.key));
529
586
  },
530
587
  build(e) {
531
- let t = e.inputs.coord ?? e.coord, n = Math.max(1, Math.round(Number.isFinite(Number(e.params.octaves)) ? Number(e.params.octaves) : 4)), r = Math.max(2, Math.round(Number.isFinite(Number(e.params.lacunarity)) ? Number(e.params.lacunarity) : 2)), i = e.params.noiseType ?? "perlin-fbm", a = e.uniforms.gain, o = e.uniforms.scale;
532
- if (e.backend === "live") return { field: qe(t.mul(o), n, a, e.uniforms.lacunarity) };
533
- let s = q(t.x, t.y), c = e.uniforms.antialias, l = Math.max(1, Math.round(e.tileRepeat ?? 1)), u = P(A((l > 1 ? o.div(k(l)) : o).add(.5)), k(1)), d = e.uniforms.aspect, f = P(A(u.mul(d).add(.5)), k(1));
534
- if (i === "curl") {
535
- let e = pt(s.mul(u), u, u);
588
+ let t = e.inputs.coord ?? e.coord, n = Math.max(1, Math.round(Number.isFinite(Number(e.constant("octaves"))) ? Number(e.constant("octaves")) : 4)), r = e.constant("noiseType") ?? "perlin-fbm", i = e.constant("preset") ?? "none", a = r === "perlin-fbm" && i !== "none" ? i : r, o = e.live("gain"), s = e.live("scale");
589
+ if (e.backend === "live") return { field: rt(t.mul(s), n, o, e.live("lacunarity")) };
590
+ let c = Math.max(2, Math.round(Number.isFinite(Number(e.constant("lacunarity"))) ? Number(e.constant("lacunarity")) : 2)), l = G(t.x, t.y), u = e.live("antialias"), d = Math.max(1, Math.round(e.tileRepeat ?? 1)), f = N(A((d > 1 ? s.div(k(d)) : s).add(.5)), k(1)), p = e.live("aspect"), m = N(A(f.mul(p).add(.5)), k(1));
591
+ if (a === "curl") {
592
+ let e = St(l.mul(f), f, f);
536
593
  return {
537
594
  field: e.length(),
538
595
  vector: e
539
596
  };
540
597
  }
541
- if (i === "simplex") {
542
- let e = u.add(L(u, k(2)));
543
- return { field: et(s, e, e, n, a, xt, c, r) };
598
+ if (a === "simplex") {
599
+ let e = f.add(I(f, k(2)));
600
+ return { field: ut(l, e, e, n, o, At, u, c) };
544
601
  }
545
- if (i === "gabor") {
546
- let t = k(1).sub(e.uniforms.gaborAniso);
547
- return { field: bt(s, u, e.uniforms.gaborFreq, t, e.uniforms.gaborOrient) };
602
+ if (a === "gabor") {
603
+ let t = k(1).sub(e.live("gaborAniso"));
604
+ return { field: kt(l, f, e.live("gaborFreq"), t, e.live("gaborOrient")) };
548
605
  }
549
- let p = Dt[i];
550
- return p ? { field: et(s, i === "value" ? f : u, u, n, a, p, c, r) } : { field: $e(s, f, u, n, a, c, r).mul(.5).add(.5) };
606
+ let h = Lt[a];
607
+ return h ? { field: ut(l, a === "value" ? m : f, f, n, o, h, u, c) } : { field: lt(l, m, f, n, o, u, c).mul(.5).add(.5) };
551
608
  }
552
- }, jt = 4294967295;
553
- function Mt(e) {
554
- let t = ne(e.mul(q(141421356, 2718281828)));
555
- return k(t.x.bitXor(t.y).mul(W(3141592653))).div(jt);
609
+ }, Vt = 4294967295;
610
+ function Ht(e) {
611
+ let t = oe(e.mul(G(141421356, 2718281828)));
612
+ return k(t.x.bitXor(t.y).mul(H(3141592653))).div(Vt);
556
613
  }
557
- function Nt(e) {
558
- return j(k(52.9829189).mul(j(D(e, q(.06711056, .00583715)))));
614
+ function Ut(e) {
615
+ return j(k(52.9829189).mul(j(O(e, G(.06711056, .00583715)))));
559
616
  }
560
- function Pt(e) {
561
- let t = W(e.x), n = W(e.y);
562
- return k(t.mul(W(3242174889)).add(n.mul(W(2447445413)))).mul(te(-32));
617
+ function Wt(e) {
618
+ let t = H(e.x), n = H(e.y);
619
+ return k(t.mul(H(3242174889)).add(n.mul(H(2447445413)))).mul(ae(-32));
563
620
  }
564
- function Ft(e) {
621
+ function Gt(e) {
565
622
  let t = k(0);
566
- for (let n = 0; n < 9; n++) t = t.add(Mt(e.add(q(n % 3 - 1, Math.floor(n / 3) - 1))));
567
- return k(.9).mul(k(1.125).mul(Mt(e)).sub(t.div(8))).add(.5);
623
+ for (let n = 0; n < 9; n++) t = t.add(Ht(e.add(G(n % 3 - 1, Math.floor(n / 3) - 1))));
624
+ return k(.9).mul(k(1.125).mul(Ht(e)).sub(t.div(8))).add(.5);
568
625
  }
569
- var It = d(([e, t]) => {
626
+ var Kt = h(([e, t]) => {
570
627
  let n = e.toVar(), r = t.toVar(), i = M(0).toVar();
571
628
  for (let e = 256; e > 0; e >>= 1) {
572
- let t = M(e), a = B(n.bitAnd(t).notEqual(M(0)), M(1), M(0)), o = B(r.bitAnd(t).notEqual(M(0)), M(1), M(0));
629
+ let t = M(e), a = R(n.bitAnd(t).notEqual(M(0)), M(1), M(0)), o = R(r.bitAnd(t).notEqual(M(0)), M(1), M(0));
573
630
  i.assign(i.add(t.mul(t).mul(a.shiftLeft(1).bitOr(a.bitXor(o)))));
574
631
  let s = n.bitXor(r).mul(M(1).sub(o)).bitXor(M(e - 1).mul(a.bitAnd(M(1).sub(o))));
575
632
  n.assign(n.bitXor(s)), r.assign(r.bitXor(s));
576
633
  }
577
634
  return i;
578
635
  });
579
- function Lt(e) {
580
- let t = It(M(e.x), M(e.y));
636
+ function qt(e) {
637
+ let t = Kt(M(e.x), M(e.y));
581
638
  return j(k(.6180339887498948).mul(k(t.mod(M(262144)))));
582
639
  }
583
- var Rt = d(([e, t]) => {
640
+ var Jt = h(([e, t]) => {
584
641
  let n = A(e).toVar(), r = e.sub(n);
585
- n.x.assign(A(V(n.x.mul(51024)).mul(3104))), n.y.assign(A(V(n.y.mul(1324)).mul(554)));
642
+ n.x.assign(A(z(n.x.mul(51024)).mul(3104))), n.y.assign(A(z(n.y.mul(1324)).mul(554)));
586
643
  let i = n.x.add(n.y);
587
- r = r.mul(2).sub(1), r = r.mul(S(i)).add(q(r.y.negate(), r.x).mul(V(i))), r = r.add(V(n.x.sub(n.y))), r = r.mul(.5).add(.5);
588
- let a = V(n.x.add(r.y.mul(3.1415))).add(V(n.y.add(r.y.mul(3.1415)))).mul(.2), o = f(r.x.sub(.5).add(a));
589
- return o = k(.5).sub(o.mul(t)), o = H(-2, re(o).mul(1.5).add(16), o).mul(12), o.mul(r.y);
644
+ r = r.mul(2).sub(1), r = r.mul(E(i)).add(G(r.y.negate(), r.x).mul(z(i))), r = r.add(z(n.x.sub(n.y))), r = r.mul(.5).add(.5);
645
+ let a = z(n.x.add(r.y.mul(3.1415))).add(z(n.y.add(r.y.mul(3.1415)))).mul(.2), o = g(r.x.sub(.5).add(a));
646
+ return o = k(.5).sub(o.mul(t)), o = B(-2, se(o).mul(1.5).add(16), o).mul(12), o.mul(r.y);
590
647
  });
591
- function zt(e, t) {
648
+ function Yt(e, t) {
592
649
  let n = e, r = t, i = k(0);
593
- for (let e = 0; e < 8; e++) i = P(i, Rt(n, r)), n = q(n.x.sub(n.y.mul(.7)), n.x.mul(.7).add(n.y)).sub(12.31);
650
+ for (let e = 0; e < 8; e++) i = N(i, Jt(n, r)), n = G(n.x.sub(n.y.mul(.7)), n.x.mul(.7).add(n.y)).sub(12.31);
594
651
  return i;
595
652
  }
596
- var Bt = {
653
+ var Xt = {
597
654
  type: "screen-noise",
598
655
  nodeClass: "texture",
599
656
  label: "Screen Noise",
@@ -627,16 +684,17 @@ var Bt = {
627
684
  default: 512
628
685
  }],
629
686
  build(e) {
630
- let t = e.inputs.coord ?? e.coord, n = q(t.x, t.y), r = e.params.noiseType ?? "blue", i = n.mul(e.uniforms.resolution);
687
+ let t = e.inputs.coord ?? e.coord, n = G(t.x, t.y), r = e.constant("noiseType") ?? "blue";
688
+ if (r === "scratches") return { field: Yt(n.mul(5), k(3)) };
689
+ let i = n.mul(e.live("resolution"));
631
690
  switch (r) {
632
- case "hilbert-blue": return { field: Lt(A(i)) };
633
- case "ign": return { field: Nt(A(i)) };
634
- case "golden-ign": return { field: Pt(A(i)) };
635
- case "scratches": return { field: zt(n.mul(5), k(3)) };
636
- default: return { field: Ft(A(i)) };
691
+ case "hilbert-blue": return { field: qt(A(i)) };
692
+ case "ign": return { field: Ut(A(i)) };
693
+ case "golden-ign": return { field: Wt(A(i)) };
694
+ default: return { field: Gt(A(i)) };
637
695
  }
638
696
  }
639
- }, Vt = {
697
+ }, Zt = {
640
698
  type: "tileable-warp",
641
699
  nodeClass: "vector",
642
700
  label: "Tileable Warp",
@@ -666,74 +724,74 @@ var Bt = {
666
724
  default: 4
667
725
  }],
668
726
  build(e) {
669
- let t = e.inputs.coord ?? e.coord, n = e.uniforms.amount;
727
+ let t = e.inputs.coord ?? e.coord, n = e.live("amount");
670
728
  if (e.backend === "live") {
671
- let r = t.div(Math.max(1, Number(e.params.scale ?? 4))), i = R(r.add(J(11.3, 0, 0))), a = R(r.add(J(0, 47.7, 0))), o = R(r.add(J(0, 0, 93.1)));
672
- return { coord: t.add(J(i, a, o).mul(n)) };
729
+ let r = t.div(Math.max(1, Number(e.constant("scale") ?? 4))), i = fe(r.add(K(11.3, 0, 0))), a = fe(r.add(K(0, 47.7, 0))), o = fe(r.add(K(0, 0, 93.1)));
730
+ return { coord: t.add(K(i, a, o).mul(n)) };
673
731
  }
674
- let r = Math.max(1, Math.round(Number(e.params.scale ?? 4))), i = q(t.x, t.y), a = q(r, r), o = Qe(i.mul(r), a), s = Qe(i.mul(r).add(q(5.2, 1.3)), a), c = i.add(q(o, s).mul(n));
675
- return { coord: J(c.x, c.y, t.z) };
732
+ let r = Math.max(1, Math.round(Number(e.constant("scale") ?? 4))), i = G(t.x, t.y), a = G(r, r), o = ct(i.mul(r), a), s = ct(i.mul(r).add(G(5.2, 1.3)), a), c = i.add(G(o, s).mul(n));
733
+ return { coord: K(c.x, c.y, t.z) };
676
734
  }
677
- }, Ht = 1 / 2147483648;
678
- function Ut(e, t, n) {
735
+ }, Qt = 1 / 2147483648;
736
+ function $t(e, t, n) {
679
737
  let r = e.mul(1664525).add(1013904223).toVar(), i = t.mul(1664525).add(1013904223).toVar(), a = n.mul(1664525).add(1013904223).toVar();
680
738
  r.assign(r.add(i.mul(a))), i.assign(i.add(a.mul(r))), a.assign(a.add(r.mul(i))), r.assign(r.bitXor(r.shiftRight(16))), i.assign(i.bitXor(i.shiftRight(16))), a.assign(a.bitXor(a.shiftRight(16))), r.assign(r.add(i.mul(a))), i.assign(i.add(a.mul(r))), a.assign(a.add(r.mul(i)));
681
739
  let o = M(2147483647);
682
- return J(k(r.bitAnd(o)).mul(Ht), k(i.bitAnd(o)).mul(Ht), k(a.bitAnd(o)).mul(Ht));
740
+ return K(k(r.bitAnd(o)).mul(Qt), k(i.bitAnd(o)).mul(Qt), k(a.bitAnd(o)).mul(Qt));
683
741
  }
684
- function Wt(e, t) {
742
+ function en(e, t) {
685
743
  return e.sub(M(A(k(e).div(t))).mul(M(t)));
686
744
  }
687
- function Gt(e, t, n, r) {
688
- return typeof r == "number" && r <= 0 ? Ut(e, t, n) : Ut(Wt(e, r), Wt(t, r), Wt(n, r));
745
+ function tn(e, t, n, r) {
746
+ return typeof r == "number" && r <= 0 ? $t(e, t, n) : $t(en(e, r), en(t, r), en(n, r));
689
747
  }
690
- function Kt(e, t, n, r) {
748
+ function nn(e, t, n, r) {
691
749
  let i = e.sub(t).abs();
692
750
  if (n === 1) return i.x.add(i.y).add(i.z);
693
751
  if (n === 2) return i.x.max(i.y.max(i.z));
694
752
  if (n === 3) {
695
753
  let e = r;
696
- return z(z(i.x, e).add(z(i.y, e)).add(z(i.z, e)), k(1).div(e));
754
+ return L(L(i.x, e).add(L(i.y, e)).add(L(i.z, e)), k(1).div(e));
697
755
  }
698
756
  return e.sub(t).length();
699
757
  }
700
- function qt(e, t, n, r, i, a) {
701
- return d(() => {
702
- let o = A(e), s = e.sub(o), c = M(o.x), l = M(o.y), u = M(o.z), d = k(1e10).toVar(), f = J(0, 0, 0).toVar(), p = J(0, 0, 0).toVar();
758
+ function rn(e, t, n, r, i, a) {
759
+ return h(() => {
760
+ let o = A(e), s = e.sub(o), c = M(o.x), l = M(o.y), u = M(o.z), d = k(1e10).toVar(), f = K(0, 0, 0).toVar(), p = K(0, 0, 0).toVar();
703
761
  for (let e = -1; e <= 1; e++) for (let i = -1; i <= 1; i++) for (let o = -1; o <= 1; o++) {
704
- let m = J(o, i, e), h = m.add(Gt(c.add(o), l.add(i), u.add(e), a).mul(t)), g = Kt(h, s, n, r), _ = g.lessThan(d);
762
+ let m = K(o, i, e), h = m.add(tn(c.add(o), l.add(i), u.add(e), a).mul(t)), g = nn(h, s, n, r), _ = g.lessThan(d);
705
763
  d.assign(_.select(g, d)), f.assign(_.select(m, f)), p.assign(_.select(h, p));
706
764
  }
707
- return i === "color" ? Gt(c.add(M(f.x)), l.add(M(f.y)), u.add(M(f.z)), a) : i === "position" ? p.add(o) : d;
765
+ return i === "color" ? tn(c.add(M(f.x)), l.add(M(f.y)), u.add(M(f.z)), a) : i === "position" ? p.add(o) : d;
708
766
  })();
709
767
  }
710
- function Jt(e, t, n, r, i, a) {
711
- return d(() => {
712
- let o = A(e), s = e.sub(o), c = M(o.x), l = M(o.y), u = M(o.z), d = k(1e10).toVar(), f = k(1e10).toVar(), p = J(0, 0, 0).toVar(), m = J(0, 0, 0).toVar(), h = J(0, 0, 0).toVar(), g = J(0, 0, 0).toVar();
768
+ function an(e, t, n, r, i, a) {
769
+ return h(() => {
770
+ let o = A(e), s = e.sub(o), c = M(o.x), l = M(o.y), u = M(o.z), d = k(1e10).toVar(), f = k(1e10).toVar(), p = K(0, 0, 0).toVar(), m = K(0, 0, 0).toVar(), h = K(0, 0, 0).toVar(), g = K(0, 0, 0).toVar();
713
771
  for (let e = -1; e <= 1; e++) for (let i = -1; i <= 1; i++) for (let o = -1; o <= 1; o++) {
714
- let _ = J(o, i, e), v = _.add(Gt(c.add(o), l.add(i), u.add(e), a).mul(t)), y = Kt(v, s, n, r), b = y.lessThan(d).toVar(), x = y.lessThan(f).toVar(), S = B(b, d, B(x, y, f)), C = B(b, p, B(x, _, m)), w = B(b, h, B(x, v, g)), T = B(b, y, d), E = B(b, _, p), ee = B(b, v, h);
715
- f.assign(S), m.assign(C), g.assign(w), d.assign(T), p.assign(E), h.assign(ee);
772
+ let _ = K(o, i, e), v = _.add(tn(c.add(o), l.add(i), u.add(e), a).mul(t)), y = nn(v, s, n, r), b = y.lessThan(d).toVar(), x = y.lessThan(f).toVar(), S = R(b, d, R(x, y, f)), C = R(b, p, R(x, _, m)), w = R(b, h, R(x, v, g)), T = R(b, y, d), E = R(b, _, p), D = R(b, v, h);
773
+ f.assign(S), m.assign(C), g.assign(w), d.assign(T), p.assign(E), h.assign(D);
716
774
  }
717
- return i === "color" ? Gt(c.add(M(m.x)), l.add(M(m.y)), u.add(M(m.z)), a) : i === "position" ? g.add(o) : f;
775
+ return i === "color" ? tn(c.add(M(m.x)), l.add(M(m.y)), u.add(M(m.z)), a) : i === "position" ? g.add(o) : f;
718
776
  })();
719
777
  }
720
- var Yt = 1;
721
- function Xt(e, t, n, r, i, a, o) {
722
- return d(() => {
723
- let s = A(e), c = e.sub(s), l = M(s.x), u = M(s.y), d = M(s.z), f = P(i, k(1e-6)), p = k(0).toVar(), m = J(0, 0, 0).toVar(), h = J(0, 0, 0).toVar(), g = k(-1).toVar();
724
- for (let e = -1; e <= Yt; e++) for (let i = -1; i <= Yt; i++) for (let a = -1; a <= Yt; a++) {
725
- let s = J(a, i, e), _ = Gt(l.add(a), u.add(i), d.add(e), o), v = s.add(_.mul(t)), y = Kt(v, c, n, r);
726
- g.assign(B(g.equal(-1), k(1), H(0, 1, k(.5).add(p.sub(y).mul(.5).div(f)))));
778
+ var on = 1;
779
+ function sn(e, t, n, r, i, a, o) {
780
+ return h(() => {
781
+ let s = A(e), c = e.sub(s), l = M(s.x), u = M(s.y), d = M(s.z), f = N(i, k(1e-6)), p = k(0).toVar(), m = K(0, 0, 0).toVar(), h = K(0, 0, 0).toVar(), g = k(-1).toVar();
782
+ for (let e = -1; e <= on; e++) for (let i = -1; i <= on; i++) for (let a = -1; a <= on; a++) {
783
+ let s = K(a, i, e), _ = tn(l.add(a), u.add(i), d.add(e), o), v = s.add(_.mul(t)), y = nn(v, c, n, r);
784
+ g.assign(R(g.equal(-1), k(1), B(0, 1, k(.5).add(p.sub(y).mul(.5).div(f)))));
727
785
  let b = f.mul(g).mul(k(1).sub(g)).toVar();
728
- p.assign(I(p, y, g).sub(b)), b.assign(b.div(k(1).add(f.mul(3)))), m.assign(I(m, _, g).sub(b)), h.assign(I(h, v, g).sub(b));
786
+ p.assign(F(p, y, g).sub(b)), b.assign(b.div(k(1).add(f.mul(3)))), m.assign(F(m, _, g).sub(b)), h.assign(F(h, v, g).sub(b));
729
787
  }
730
788
  return a === "color" ? m : a === "position" ? h.add(s) : p;
731
789
  })();
732
790
  }
733
- var Zt = (e, t, n, r, i = 0) => qt(e, t, n, r, "distance", i), Qt = (e, t, n, r, i = 0) => qt(e, t, n, r, "color", i), $t = (e, t, n, r, i = 0) => qt(e, t, n, r, "position", i), en = (e, t, n, r, i = 0) => Jt(e, t, n, r, "distance", i), tn = (e, t, n, r, i = 0) => Jt(e, t, n, r, "color", i), nn = (e, t, n, r, i = 0) => Jt(e, t, n, r, "position", i), rn = (e, t, n, r, i, a = 0) => Xt(e, t, n, r, i, "distance", a), an = (e, t, n, r, i, a = 0) => Xt(e, t, n, r, i, "color", a), on = (e, t, n, r, i, a = 0) => Xt(e, t, n, r, i, "position", a);
734
- function sn(e, t, n = 0) {
735
- return d(() => {
736
- let r = A(e), i = e.sub(r), a = M(r.x), o = M(r.y), s = M(r.z), c = (e, r, c) => J(e, r, c).add(Gt(a.add(e), o.add(r), s.add(c), n).mul(t)).sub(i), l = J(0, 0, 0).toVar(), u = k(1e10).toVar();
791
+ var cn = (e, t, n, r, i = 0) => rn(e, t, n, r, "distance", i), ln = (e, t, n, r, i = 0) => rn(e, t, n, r, "color", i), un = (e, t, n, r, i = 0) => rn(e, t, n, r, "position", i), dn = (e, t, n, r, i = 0) => an(e, t, n, r, "distance", i), fn = (e, t, n, r, i = 0) => an(e, t, n, r, "color", i), pn = (e, t, n, r, i = 0) => an(e, t, n, r, "position", i), mn = (e, t, n, r, i, a = 0) => sn(e, t, n, r, i, "distance", a), hn = (e, t, n, r, i, a = 0) => sn(e, t, n, r, i, "color", a), gn = (e, t, n, r, i, a = 0) => sn(e, t, n, r, i, "position", a);
792
+ function _n(e, t, n = 0) {
793
+ return h(() => {
794
+ let r = A(e), i = e.sub(r), a = M(r.x), o = M(r.y), s = M(r.z), c = (e, r, c) => K(e, r, c).add(tn(a.add(e), o.add(r), s.add(c), n).mul(t)).sub(i), l = K(0, 0, 0).toVar(), u = k(1e10).toVar();
737
795
  for (let e = -1; e <= 1; e++) for (let t = -1; t <= 1; t++) for (let n = -1; n <= 1; n++) {
738
796
  let r = c(n, t, e), i = r.dot(r), a = i.lessThan(u);
739
797
  u.assign(a.select(i, u)), l.assign(a.select(r, l));
@@ -748,20 +806,20 @@ function sn(e, t, n = 0) {
748
806
  }
749
807
  //#endregion
750
808
  //#region src/tsl/lloyd-points.ts
751
- function cn(e, t, n) {
809
+ function vn(e, t, n) {
752
810
  let r = Math.imul(e, 374761393) + Math.imul(t, 668265263) + Math.imul(n, 362437) >>> 0;
753
811
  r = Math.imul(r ^ r >>> 13, 1274126177) >>> 0;
754
812
  let i = (r & 65535) / 65536;
755
813
  return r = Math.imul(r ^ r >>> 16, 2246822519) >>> 0, [i, (r >>> 8 & 65535) / 65536];
756
814
  }
757
- function ln(e, t, n) {
815
+ function yn(e, t, n) {
758
816
  let r = e - t;
759
817
  return r -= n * Math.round(r / n), r;
760
818
  }
761
- function un(e, t, n, r = 0) {
819
+ function bn(e, t, n, r = 0) {
762
820
  let i = e * e, a = new Float64Array(i), o = new Float64Array(i);
763
821
  for (let n = 0; n < e; n++) for (let i = 0; i < e; i++) {
764
- let [s, c] = cn(i, n, r), l = n * e + i;
822
+ let [s, c] = vn(i, n, r), l = n * e + i;
765
823
  a[l] = i + .5 + (s - .5) * t, o[l] = n + .5 + (c - .5) * t;
766
824
  }
767
825
  let s = Math.max(64, e * 24);
@@ -772,10 +830,10 @@ function un(e, t, n, r = 0) {
772
830
  for (let i = 0; i < s; i++) {
773
831
  let u = (i + .5) / s * e, d = Math.floor(u), f = Infinity, p = 0;
774
832
  for (let t = -1; t <= 1; t++) for (let n = -1; n <= 1; n++) {
775
- let r = ((d + n) % e + e) % e, i = ((l + t) % e + e) % e * e + r, s = ln(a[i], u, e), m = ln(o[i], c, e), h = s * s + m * m;
833
+ let r = ((d + n) % e + e) % e, i = ((l + t) % e + e) % e * e + r, s = yn(a[i], u, e), m = yn(o[i], c, e), h = s * s + m * m;
776
834
  h < f && (f = h, p = i);
777
835
  }
778
- t[p] += a[p] + ln(u, a[p], e), n[p] += o[p] + ln(c, o[p], e), r[p]++;
836
+ t[p] += a[p] + yn(u, a[p], e), n[p] += o[p] + yn(c, o[p], e), r[p]++;
779
837
  }
780
838
  }
781
839
  for (let s = 0; s < i; s++) r[s] > 0 && (a[s] = (t[s] / r[s] % e + e) % e, o[s] = (n[s] / r[s] % e + e) % e);
@@ -789,9 +847,9 @@ function un(e, t, n, r = 0) {
789
847
  }
790
848
  //#endregion
791
849
  //#region src/tsl/relaxed-voronoi.ts
792
- function dn(e, t) {
793
- return d(() => {
794
- let n = A(e), r = e.sub(n), i = M(n.x), a = M(n.y), o = (e, n) => J(e, n, 0).add(t(i.add(e), a.add(n))).sub(r), s = J(0, 0, 0).toVar(), c = k(1e10).toVar();
850
+ function xn(e, t) {
851
+ return h(() => {
852
+ let n = A(e), r = e.sub(n), i = M(n.x), a = M(n.y), o = (e, n) => K(e, n, 0).add(t(i.add(e), a.add(n))).sub(r), s = K(0, 0, 0).toVar(), c = k(1e10).toVar();
795
853
  for (let e = -1; e <= 1; e++) for (let t = -1; t <= 1; t++) {
796
854
  let n = o(t, e), r = n.dot(n), i = r.lessThan(c);
797
855
  c.assign(i.select(r, c)), s.assign(i.select(n, s));
@@ -804,9 +862,9 @@ function dn(e, t) {
804
862
  return l;
805
863
  })();
806
864
  }
807
- function fn(e, t, n) {
808
- return d(() => {
809
- let r = A(e), i = e.sub(r), a = M(r.x), o = M(r.y), s = (e, n) => J(e, n, 0).add(t(a.add(e), o.add(n))).sub(i), c = k(1e10).toVar(), l = M(0).toVar(), u = M(0).toVar();
865
+ function Sn(e, t, n) {
866
+ return h(() => {
867
+ let r = A(e), i = e.sub(r), a = M(r.x), o = M(r.y), s = (e, n) => K(e, n, 0).add(t(a.add(e), o.add(n))).sub(i), c = k(1e10).toVar(), l = M(0).toVar(), u = M(0).toVar();
810
868
  for (let e = -1; e <= 1; e++) for (let t = -1; t <= 1; t++) {
811
869
  let n = s(t, e), r = n.dot(n), i = r.lessThan(c);
812
870
  c.assign(i.select(r, c)), l.assign(i.select(a.add(t), l)), u.assign(i.select(o.add(e), u));
@@ -816,17 +874,17 @@ function fn(e, t, n) {
816
874
  }
817
875
  //#endregion
818
876
  //#region src/graph/nodes/texture/voronoi.ts
819
- var pn = [
877
+ var Cn = [
820
878
  "euclidean",
821
879
  "manhattan",
822
880
  "chebychev",
823
881
  "minkowski"
824
- ], mn = [
882
+ ], wn = [
825
883
  "f1",
826
884
  "f2",
827
885
  "smooth-f1",
828
886
  "distance-to-edge"
829
- ], hn = [
887
+ ], Tn = [
830
888
  {
831
889
  key: "distance",
832
890
  label: "Distance",
@@ -842,19 +900,27 @@ var pn = [
842
900
  label: "Position",
843
901
  kind: "vector"
844
902
  }
845
- ], gn = [{
846
- key: "distance",
847
- label: "Distance",
848
- kind: "float"
849
- }, {
850
- key: "random",
851
- label: "Random",
852
- kind: "float"
853
- }], _n = [{
903
+ ], En = [
904
+ {
905
+ key: "distance",
906
+ label: "Distance",
907
+ kind: "float"
908
+ },
909
+ {
910
+ key: "edges",
911
+ label: "Edges",
912
+ kind: "float"
913
+ },
914
+ {
915
+ key: "random",
916
+ label: "Random",
917
+ kind: "float"
918
+ }
919
+ ], Dn = [{
854
920
  key: "coord",
855
921
  kind: "vector"
856
922
  }];
857
- function vn(e) {
923
+ function On(e) {
858
924
  let t = Array(e);
859
925
  for (let n = 0; n < e; n++) {
860
926
  let e = Math.sin(n * 12.9898 + 78.233) * 43758.5453;
@@ -862,12 +928,12 @@ function vn(e) {
862
928
  }
863
929
  return t;
864
930
  }
865
- var yn = {
931
+ var kn = {
866
932
  type: "voronoi",
867
933
  nodeClass: "texture",
868
934
  label: "Voronoi",
869
- inputs: _n,
870
- outputs: hn,
935
+ inputs: Dn,
936
+ outputs: Tn,
871
937
  params: [
872
938
  {
873
939
  key: "scale",
@@ -891,14 +957,14 @@ var yn = {
891
957
  key: "metric",
892
958
  label: "metric",
893
959
  type: "select",
894
- options: pn,
960
+ options: Cn,
895
961
  default: "euclidean"
896
962
  },
897
963
  {
898
964
  key: "feature",
899
965
  label: "feature",
900
966
  type: "select",
901
- options: mn,
967
+ options: wn,
902
968
  default: "f1"
903
969
  },
904
970
  {
@@ -919,6 +985,15 @@ var yn = {
919
985
  step: .01,
920
986
  default: .25
921
987
  },
988
+ {
989
+ key: "edgeWidth",
990
+ label: "edge width",
991
+ type: "float",
992
+ min: .005,
993
+ max: .5,
994
+ step: .005,
995
+ default: .05
996
+ },
922
997
  {
923
998
  key: "relax",
924
999
  label: "relax",
@@ -931,54 +1006,62 @@ var yn = {
931
1006
  ],
932
1007
  declare(e) {
933
1008
  return {
934
- inputs: _n,
935
- outputs: (e.feature ?? "f1") === "distance-to-edge" ? gn : hn
1009
+ inputs: Dn,
1010
+ outputs: (e.feature ?? "f1") === "distance-to-edge" ? En : Tn
936
1011
  };
937
1012
  },
938
1013
  paramsFor(e) {
939
- let t = e.metric ?? "euclidean", n = e.feature ?? "f1", r = new Set([
1014
+ let t = e.metric ?? "euclidean", n = e.feature ?? "f1", r = Math.round(Number(e.relax ?? 0)), i = new Set([
940
1015
  "scale",
941
1016
  "randomness",
942
1017
  "metric",
943
1018
  "feature"
944
1019
  ]);
945
- return t === "minkowski" && r.add("exponent"), n === "smooth-f1" && r.add("smoothness"), n === "distance-to-edge" && r.add("relax"), yn.params.filter((e) => r.has(e.key));
1020
+ t === "minkowski" && i.add("exponent"), n === "smooth-f1" && i.add("smoothness"), n === "distance-to-edge" && (i.add("relax"), i.add("edgeWidth"));
1021
+ let a = n === "distance-to-edge" && r > 0;
1022
+ return kn.params.filter((e) => i.has(e.key)).map((e) => a && (e.key === "scale" || e.key === "randomness") ? {
1023
+ ...e,
1024
+ bakeStructural: !0
1025
+ } : e);
946
1026
  },
947
1027
  build(e) {
948
- let t = e.backend === "offline", n = Math.max(0, pn.indexOf(e.params.metric)), r = e.uniforms.randomness, i = e.uniforms.exponent, a = e.uniforms.smoothness, s = e.params.feature ?? "f1", c = e.inputs.coord ?? e.coord, l = Math.max(0, Math.round(Number(e.params.relax ?? 0)));
949
- if (s === "distance-to-edge" && t && l > 0) {
950
- let t = Math.max(1, Math.round(Number(e.params.scale ?? 1))), n = c.mul(t), r = un(t, Number(e.params.randomness ?? 1), l), i = [];
951
- for (let e = 0; e < t * t; e++) i.push(new o(r[e * 3], r[e * 3 + 1], r[e * 3 + 2]));
952
- let a = Ee(i), s = (e) => e.sub(M(A(k(e).div(t))).mul(M(t))), u = (e, n) => a.element(s(n).mul(t).add(s(e))), d = Ee(vn(t * t));
1028
+ let t = e.backend === "offline", n = Math.max(0, Cn.indexOf(e.constant("metric"))), r = e.constant("feature") ?? "f1", i = e.inputs.coord ?? e.coord, a = Math.max(0, Math.round(Number(e.constant("relax") ?? 0)));
1029
+ if (r === "distance-to-edge" && t && a > 0) {
1030
+ let t = Math.max(1, Math.round(Number(e.constant("scale") ?? 1))), n = Number(e.constant("randomness") ?? 1), r = i.mul(t), o = e.constantArray("seeds", () => bn(t, n, a), "vec3"), s = (e) => e.sub(M(A(k(e).div(t))).mul(M(t))), c = (e, n) => o.element(s(n).mul(t).add(s(e))), l = e.constantArray("randoms", () => On(t * t), "float"), u = (e, n) => l.element(s(n).mul(t).add(s(e))), d = e.live("edgeWidth"), f = xn(r, c);
953
1031
  return {
954
- distance: dn(n, u),
955
- random: fn(n, u, (e, n) => d.element(s(n).mul(t).add(s(e))))
1032
+ distance: f,
1033
+ edges: B(k(0), d, f).oneMinus(),
1034
+ random: Sn(r, c, u)
956
1035
  };
957
1036
  }
958
- let u = e.uniforms.scale, d = P(A(u.add(.5)), k(1)), f = c.mul(t ? d : u), p = t ? d : 0;
959
- switch (s) {
960
- case "distance-to-edge": return {
961
- distance: sn(f, r, p),
962
- random: Qt(f, r, n, i, p).x
963
- };
1037
+ let o = e.live("randomness"), s = e.live("exponent"), c = e.live("smoothness"), l = e.live("edgeWidth"), u = e.live("scale"), d = N(A(u.add(.5)), k(1)), f = i.mul(t ? d : u), p = t ? d : 0;
1038
+ switch (r) {
1039
+ case "distance-to-edge": {
1040
+ let e = _n(f, o, p);
1041
+ return {
1042
+ distance: e,
1043
+ edges: B(k(0), l, e).oneMinus(),
1044
+ random: ln(f, o, n, s, p).x
1045
+ };
1046
+ }
964
1047
  case "f2": return {
965
- distance: en(f, r, n, i, p),
966
- color: tn(f, r, n, i, p),
967
- position: nn(f, r, n, i, p)
1048
+ distance: dn(f, o, n, s, p),
1049
+ color: fn(f, o, n, s, p),
1050
+ position: pn(f, o, n, s, p)
968
1051
  };
969
1052
  case "smooth-f1": return {
970
- distance: rn(f, r, n, i, a, p),
971
- color: an(f, r, n, i, a, p),
972
- position: on(f, r, n, i, a, p)
1053
+ distance: mn(f, o, n, s, c, p),
1054
+ color: hn(f, o, n, s, c, p),
1055
+ position: gn(f, o, n, s, c, p)
973
1056
  };
974
1057
  default: return {
975
- distance: Zt(f, r, n, i, p),
976
- color: Qt(f, r, n, i, p),
977
- position: $t(f, r, n, i, p)
1058
+ distance: cn(f, o, n, s, p),
1059
+ color: ln(f, o, n, s, p),
1060
+ position: un(f, o, n, s, p)
978
1061
  };
979
1062
  }
980
1063
  }
981
- }, bn = {
1064
+ }, An = {
982
1065
  type: "checker",
983
1066
  nodeClass: "texture",
984
1067
  label: "Checker",
@@ -1030,56 +1113,60 @@ var yn = {
1030
1113
  }
1031
1114
  ],
1032
1115
  build(e) {
1033
- let t = (e.inputs.coord ?? e.coord).mul(e.uniforms.scale), n = L(A(t.x).add(A(t.y)).add(A(t.z)), 2).lessThan(1);
1116
+ let t = (e.inputs.coord ?? e.coord).mul(e.live("scale")), n = I(A(t.x).add(A(t.y)).add(A(t.z)), 2).lessThan(1);
1034
1117
  return {
1035
- color: B(n, e.inputs.color1 ?? e.uniforms.color1, e.inputs.color2 ?? e.uniforms.color2),
1036
- fac: B(n, k(1), k(0))
1118
+ color: R(n, e.inputs.color1 ?? e.live("color1"), e.inputs.color2 ?? e.live("color2")),
1119
+ fac: R(n, k(1), k(0))
1037
1120
  };
1038
1121
  }
1039
- }, xn = 6.283185307179586;
1040
- function Sn(e, t, n) {
1041
- let { columns: r, rows: i, offsetFreq: a } = t, o = d(() => {
1042
- let t = q(e.x.mul(r), e.y.mul(i)), o = A(t.y), s = k(-1e9).toVar(), c = k(0).toVar();
1043
- for (let e = -1; e <= 1; e++) {
1044
- let l = o.add(e), u = M(l), d = B(L(l, k(a)).notEqual(0), n.rowOffset, k(0)), p = A(t.x.sub(d));
1122
+ }, jn = 6.283185307179586;
1123
+ function Mn(e, t, n) {
1124
+ let { columns: r, rows: i, offsetFreq: a } = t, o = G(e.x.mul(r), e.y.mul(i)), s = h(() => {
1125
+ let e = A(o.y), t = k(-1e9).toVar(), s = k(0).toVar(), c = k(0).toVar(), l = k(0).toVar();
1126
+ for (let u = -1; u <= 1; u++) {
1127
+ let d = e.add(u), f = M(d), p = R(I(d, k(a)).notEqual(0), n.rowOffset, k(0)), m = A(o.x.sub(p));
1045
1128
  for (let e = -1; e <= 1; e++) {
1046
- let a = p.add(e), o = M(a), m = ot(o, u, 0, r, i), h = ot(o, u, 1, r, i), g = m.x.sub(.5).mul(n.posRandom), _ = m.y.sub(.5).mul(n.posRandom), v = a.add(.5).add(d).add(g), y = l.add(.5).add(_), b = t.x.sub(v).div(r), x = t.y.sub(y).div(i), C = h.x.sub(.5).mul(2).mul(n.rotRandom).mul(xn * .5).negate(), w = S(C), T = V(C), E = w.mul(b).sub(T.mul(x)), ee = T.mul(b).add(w.mul(x)), D = k(1).add(m.z.sub(.5).mul(2).mul(n.sizeRandom)), O = k(.5).div(r).mul(D).sub(n.gap), te = k(.5).div(i).mul(D).sub(n.gap), ne = n.roundness.mul(F(O, te)), A = f(E).sub(O.sub(ne)), j = f(ee).sub(te.sub(ne)), re = N(q(P(A, 0), P(j, 0))), ie = F(P(A, j), 0), ae = re.add(ie).sub(ne).negate(), oe = ae.greaterThan(s);
1047
- c.assign(B(oe, h.y, c)), s.assign(B(oe, ae, s));
1129
+ let a = m.add(e), u = M(a), h = J(u, f, 0, r, i), _ = J(u, f, 1, r, i), v = h.x.sub(.5).mul(n.posRandom), y = h.y.sub(.5).mul(n.posRandom), b = a.add(.5).add(p).add(v), x = d.add(.5).add(y), S = o.x.sub(b).div(r), C = o.y.sub(x).div(i), w = _.x.sub(.5).mul(2).mul(n.rotRandom).mul(jn * .5).negate(), T = E(w), D = z(w), ee = T.mul(S).sub(D.mul(C)), te = D.mul(S).add(T.mul(C)), ne = k(1).add(h.z.sub(.5).mul(2).mul(n.sizeRandom)), re = k(.5).div(r).mul(ne).sub(n.gap), O = k(.5).div(i).mul(ne).sub(n.gap), ie = n.roundness.mul(P(re, O)), ae = g(ee).sub(re.sub(ie)), oe = g(te).sub(O.sub(ie)), A = le(G(N(ae, 0), N(oe, 0))), j = P(N(ae, oe), 0), se = A.add(j).sub(ie).negate(), ce = se.greaterThan(t);
1130
+ s.assign(R(ce, _.y, s)), c.assign(R(ce, a, c)), l.assign(R(ce, d, l)), t.assign(R(ce, se, t));
1048
1131
  }
1049
1132
  }
1050
- return q(H(0, n.edge.add(1e-5), s), c);
1051
- })();
1133
+ return Ne(B(0, n.edge.add(1e-5), t), s, c, l);
1134
+ })(), c = s.x, l = s.y, u = s.z, d = s.w, f = M(u), p = M(d), m = R(I(d, k(a)).notEqual(0), n.rowOffset, k(0)), _ = J(f, p, 0, r, i), v = u.add(.5).add(m).add(_.x.sub(.5).mul(n.posRandom)), y = d.add(.5).add(_.y.sub(.5).mul(n.posRandom));
1052
1135
  return {
1053
- mask: o.x,
1054
- value: o.y
1136
+ mask: c,
1137
+ value: l,
1138
+ cellCoord: K(o.x.sub(v), o.y.sub(y), 0),
1139
+ cellRandom: J(f, p, 2, r, i)
1055
1140
  };
1056
1141
  }
1057
- function Cn(e, t, n, r, i) {
1058
- let a = t, o = n, s = d(() => {
1059
- let t = q(e.x.mul(a), e.y.mul(o)), n = A(t.y), s = k(1e9).toVar(), c = k(0).toVar(), l = k(0).toVar(), u = k(0).toVar();
1142
+ function Nn(e, t, n, r, i) {
1143
+ let a = t, o = n, s = h(() => {
1144
+ let t = G(e.x.mul(a), e.y.mul(o)), n = A(t.y), s = k(1e9).toVar(), c = k(0).toVar(), l = k(0).toVar(), u = k(0).toVar(), d = k(0).toVar(), f = k(0).toVar();
1060
1145
  for (let r = -1; r <= 1; r++) {
1061
- let i = n.add(r), d = B(L(i, k(2)).notEqual(0), k(.5), k(0)), f = A(t.x.sub(d));
1146
+ let i = n.add(r), p = R(I(i, k(2)).notEqual(0), k(.5), k(0)), m = A(t.x.sub(p));
1062
1147
  for (let t = -1; t <= 1; t++) {
1063
- let n = f.add(t), r = n.add(.5).add(d).div(a), p = i.add(.5).div(o), m = N(q(e.x.sub(r), e.y.sub(p))), h = m.lessThan(s);
1064
- s.assign(B(h, m, s)), c.assign(B(h, r, c)), l.assign(B(h, p, l)), u.assign(B(h, it(M(n), M(i), a, o), u));
1148
+ let n = m.add(t), r = n.add(.5).add(p).div(a), h = i.add(.5).div(o), g = le(G(e.x.sub(r), e.y.sub(h))), _ = g.lessThan(s);
1149
+ s.assign(R(_, g, s)), c.assign(R(_, r, c)), l.assign(R(_, h, l)), d.assign(R(_, n, d)), f.assign(R(_, i, f)), u.assign(R(_, mt(M(n), M(i), a, o), u));
1065
1150
  }
1066
1151
  }
1067
- let d = k(1e9).toVar();
1152
+ let p = k(1e9).toVar();
1068
1153
  for (let r = -1; r <= 1; r++) {
1069
- let i = n.add(r), s = B(L(i, k(2)).notEqual(0), k(.5), k(0)), u = A(t.x.sub(s));
1154
+ let i = n.add(r), s = R(I(i, k(2)).notEqual(0), k(.5), k(0)), u = A(t.x.sub(s));
1070
1155
  for (let t = -1; t <= 1; t++) {
1071
- let n = u.add(t).add(.5).add(s).div(a), r = i.add(.5).div(o), f = n.sub(c), p = r.sub(l), m = N(q(f, p)).add(1e-9), h = c.add(n).mul(.5), g = l.add(r).mul(.5), _ = h.sub(e.x).mul(f.div(m)).add(g.sub(e.y).mul(p.div(m))), v = m.lessThan(1e-4);
1072
- d.assign(F(d, B(v, k(1e9), _)));
1156
+ let n = u.add(t).add(.5).add(s).div(a), r = i.add(.5).div(o), d = n.sub(c), f = r.sub(l), m = le(G(d, f)).add(1e-9), h = c.add(n).mul(.5), g = l.add(r).mul(.5), _ = h.sub(e.x).mul(d.div(m)).add(g.sub(e.y).mul(f.div(m))), v = m.lessThan(1e-4);
1157
+ p.assign(P(p, R(v, k(1e9), _)));
1073
1158
  }
1074
1159
  }
1075
- return q(H(r, r.add(i).add(1e-5), d), u);
1076
- })();
1160
+ return Ne(B(r, r.add(i).add(1e-5), p), u, d, f);
1161
+ })(), c = s.x, l = s.y, u = s.z, d = s.w, f = R(I(d, k(2)).notEqual(0), k(.5), k(0)), p = u.add(.5).add(f).div(a), m = d.add(.5).div(o);
1077
1162
  return {
1078
- mask: s.x,
1079
- value: s.y
1163
+ mask: c,
1164
+ value: l,
1165
+ cellCoord: K(e.x.sub(p).mul(a), e.y.sub(m).mul(o), 0),
1166
+ cellRandom: J(M(u), M(d), 2, a, o)
1080
1167
  };
1081
1168
  }
1082
- var wn = {
1169
+ var Pn = {
1083
1170
  type: "tile",
1084
1171
  nodeClass: "texture",
1085
1172
  label: "Tile Generator",
@@ -1087,15 +1174,28 @@ var wn = {
1087
1174
  key: "coord",
1088
1175
  kind: "vector"
1089
1176
  }],
1090
- outputs: [{
1091
- key: "mask",
1092
- label: "Mask",
1093
- kind: "float"
1094
- }, {
1095
- key: "value",
1096
- label: "Value",
1097
- kind: "float"
1098
- }],
1177
+ outputs: [
1178
+ {
1179
+ key: "mask",
1180
+ label: "Mask",
1181
+ kind: "float"
1182
+ },
1183
+ {
1184
+ key: "value",
1185
+ label: "Value",
1186
+ kind: "float"
1187
+ },
1188
+ {
1189
+ key: "cellCoord",
1190
+ label: "Cell Coord",
1191
+ kind: "vector"
1192
+ },
1193
+ {
1194
+ key: "cellRandom",
1195
+ label: "Cell Random",
1196
+ kind: "vector"
1197
+ }
1198
+ ],
1099
1199
  params: [
1100
1200
  {
1101
1201
  key: "lattice",
@@ -1196,54 +1296,58 @@ var wn = {
1196
1296
  }
1197
1297
  ],
1198
1298
  build(e) {
1199
- let t = e.inputs.coord ?? e.coord, n = Math.max(1, Math.round(Number(e.params.columns ?? 6)));
1200
- if (e.params.lattice === "hex") {
1201
- let { mask: r, value: i } = Cn(t, n, Math.max(2, Math.round(n * 2 / Math.sqrt(3) / 2) * 2), e.uniforms.gap, e.uniforms.edge);
1299
+ let t = e.inputs.coord ?? e.coord, n = Math.max(1, Math.round(Number(e.constant("columns") ?? 6)));
1300
+ if (e.constant("lattice") === "hex") {
1301
+ let { mask: r, value: i, cellCoord: a, cellRandom: o } = Nn(t, n, Math.max(2, Math.round(n * 2 / Math.sqrt(3) / 2) * 2), e.live("gap"), e.live("edge"));
1202
1302
  return {
1203
1303
  mask: r,
1204
- value: i
1304
+ value: i,
1305
+ cellCoord: a,
1306
+ cellRandom: o
1205
1307
  };
1206
1308
  }
1207
- let r = Math.max(1, Math.round(Number(e.params.offsetFreq ?? 2))), i = Math.max(1, Math.round(Number(e.params.rows ?? 12))), { mask: a, value: o } = Sn(t, {
1309
+ let r = Math.max(1, Math.round(Number(e.constant("offsetFreq") ?? 2))), i = Math.max(1, Math.round(Number(e.constant("rows") ?? 12))), { mask: a, value: o, cellCoord: s, cellRandom: c } = Mn(t, {
1208
1310
  columns: n,
1209
1311
  rows: Math.ceil(i / r) * r,
1210
1312
  offsetFreq: r
1211
1313
  }, {
1212
- rowOffset: e.uniforms.offset,
1213
- gap: e.uniforms.gap,
1214
- roundness: e.uniforms.roundness,
1215
- edge: e.uniforms.edge,
1216
- sizeRandom: e.uniforms.sizeRandom,
1217
- posRandom: e.uniforms.posRandom,
1218
- rotRandom: e.uniforms.rotRandom
1314
+ rowOffset: e.live("offset"),
1315
+ gap: e.live("gap"),
1316
+ roundness: e.live("roundness"),
1317
+ edge: e.live("edge"),
1318
+ sizeRandom: e.live("sizeRandom"),
1319
+ posRandom: e.live("posRandom"),
1320
+ rotRandom: e.live("rotRandom")
1219
1321
  });
1220
1322
  return {
1221
1323
  mask: a,
1222
- value: o
1324
+ value: o,
1325
+ cellCoord: s,
1326
+ cellRandom: c
1223
1327
  };
1224
1328
  }
1225
- }, Tn = Math.PI;
1226
- function En(e, t, n) {
1227
- let r = t, i = d(() => {
1228
- let t = q(e.x.mul(r), e.y.mul(r)), i = A(t.x), a = A(t.y), o = k(1e9).toVar(), s = k(10).toVar(), c = k(10).toVar(), l = k(0).toVar(), u = k(1).toVar();
1329
+ }, Fn = Math.PI;
1330
+ function In(e, t, n) {
1331
+ let r = t, i = h(() => {
1332
+ let t = G(e.x.mul(r), e.y.mul(r)), i = A(t.x), a = A(t.y), o = k(1e9).toVar(), s = k(10).toVar(), c = k(10).toVar(), l = k(0).toVar(), u = k(1).toVar();
1229
1333
  for (let e = -1; e <= 1; e++) {
1230
1334
  let d = a.add(e), f = M(d);
1231
1335
  for (let e = -1; e <= 1; e++) {
1232
- let a = i.add(e), p = M(a), m = ot(p, f, 0, r, r), h = ot(p, f, 1, r, r), g = h.z.lessThan(n.amount), _ = k(1).add(m.z.sub(.5).mul(2).mul(n.sizeRandom)), v = n.radius.div(r).mul(_), y = m.x.sub(.5).mul(n.posRandom), b = m.y.sub(.5).mul(n.posRandom), x = a.add(.5).add(y), C = d.add(.5).add(b), w = t.x.sub(x).div(r), T = t.y.sub(C).div(r), E = B(g, N(q(w, T)), k(1e9)), ee = h.x.sub(.5).mul(2).mul(n.rotRandom).mul(Tn).negate(), D = S(ee), O = V(ee), te = D.mul(w).sub(O.mul(T)).div(v.add(1e-9)), ne = O.mul(w).add(D.mul(T)).div(v.add(1e-9)), A = E.lessThan(o);
1233
- s.assign(B(A, te, s)), c.assign(B(A, ne, c)), l.assign(B(A, h.y, l)), u.assign(B(A, _, u)), o.assign(B(A, E, o));
1336
+ let a = i.add(e), p = M(a), m = J(p, f, 0, r, r), h = J(p, f, 1, r, r), g = h.z.lessThan(n.amount), _ = k(1).add(m.z.sub(.5).mul(2).mul(n.sizeRandom)), v = n.radius.div(r).mul(_), y = m.x.sub(.5).mul(n.posRandom), b = m.y.sub(.5).mul(n.posRandom), x = a.add(.5).add(y), S = d.add(.5).add(b), C = t.x.sub(x).div(r), w = t.y.sub(S).div(r), T = R(g, le(G(C, w)), k(1e9)), D = h.x.sub(.5).mul(2).mul(n.rotRandom).mul(Fn).negate(), ee = E(D), te = z(D), ne = ee.mul(C).sub(te.mul(w)).div(v.add(1e-9)), re = te.mul(C).add(ee.mul(w)).div(v.add(1e-9)), O = T.lessThan(o);
1337
+ s.assign(R(O, ne, s)), c.assign(R(O, re, c)), l.assign(R(O, h.y, l)), u.assign(R(O, _, u)), o.assign(R(O, T, o));
1234
1338
  }
1235
1339
  }
1236
- return De(s, c, l, u);
1340
+ return Ne(s, c, l, u);
1237
1341
  })();
1238
1342
  return {
1239
- coord: J(i.x, i.y, 0),
1343
+ coord: K(i.x, i.y, 0),
1240
1344
  value: i.z,
1241
1345
  size: i.w
1242
1346
  };
1243
1347
  }
1244
1348
  //#endregion
1245
1349
  //#region src/graph/nodes/texture/scatter.ts
1246
- var Dn = {
1350
+ var Ln = {
1247
1351
  type: "scatter",
1248
1352
  nodeClass: "texture",
1249
1353
  label: "Scatter",
@@ -1325,12 +1429,12 @@ var Dn = {
1325
1429
  }
1326
1430
  ],
1327
1431
  build(e) {
1328
- let t = e.inputs.coord ?? e.coord, n = Math.round(Number(e.params.density ?? 10)), { coord: r, value: i, size: a } = En(t, Number.isFinite(n) ? Math.max(1, n) : 10, {
1329
- amount: e.uniforms.amount,
1330
- radius: e.uniforms.radius,
1331
- sizeRandom: e.uniforms.sizeRandom,
1332
- posRandom: e.uniforms.posRandom,
1333
- rotRandom: e.uniforms.rotRandom
1432
+ let t = e.inputs.coord ?? e.coord, n = Math.round(Number(e.constant("density") ?? 10)), { coord: r, value: i, size: a } = In(t, Number.isFinite(n) ? Math.max(1, n) : 10, {
1433
+ amount: e.live("amount"),
1434
+ radius: e.live("radius"),
1435
+ sizeRandom: e.live("sizeRandom"),
1436
+ posRandom: e.live("posRandom"),
1437
+ rotRandom: e.live("rotRandom")
1334
1438
  });
1335
1439
  return {
1336
1440
  coord: r,
@@ -1338,26 +1442,26 @@ var Dn = {
1338
1442
  size: a
1339
1443
  };
1340
1444
  }
1341
- }, On = 6.283185307179586;
1342
- function kn(e, t, n, r, i) {
1343
- let a = r ?? k(0), o = d(() => {
1344
- let r = N(q(e.x, e.y)), o = h(e.y, e.x), s, c;
1445
+ }, Rn = 6.283185307179586;
1446
+ function zn(e, t, n, r, i) {
1447
+ let a = r ?? k(0), o = h(() => {
1448
+ let r = le(G(e.x, e.y)), o = y(e.y, e.x), s, c;
1345
1449
  if (t === "polygon") {
1346
- let e = Math.max(3, Math.round(n)), t = On / e, a = S(A(o.div(t).add(.5)).mul(t).sub(o)).mul(r), l = Math.cos(Math.PI / e), u = b(a.div(l), 0, 1);
1347
- s = H(0, i.edge.add(1e-4), u.oneMinus()), c = u.oneMinus();
1450
+ let e = Math.max(3, Math.round(n)), t = Rn / e, a = E(A(o.div(t).add(.5)).mul(t).sub(o)).mul(r), l = Math.cos(Math.PI / e), u = w(a.div(l), 0, 1);
1451
+ s = B(0, i.edge.add(1e-4), u.oneMinus()), c = u.oneMinus();
1348
1452
  } else {
1349
- let e = j(a.mul(13.13)).mul(On), t = j(a.mul(27.71)).mul(On), n = j(a.mul(51.37)).mul(On), l = V(o.mul(2).add(e)).mul(.5).add(V(o.mul(3).add(t)).mul(.3)).add(V(o.mul(5).add(n)).mul(.2)), u = k(1).add(l.mul(i.irregularity.mul(.4))), d = b(r.div(u.add(1e-6)), 0, 1);
1350
- s = H(0, i.edge.add(1e-4), d.oneMinus()), c = d.oneMinus();
1453
+ let e = j(a.mul(13.13)).mul(Rn), t = j(a.mul(27.71)).mul(Rn), n = j(a.mul(51.37)).mul(Rn), l = z(o.mul(2).add(e)).mul(.5).add(z(o.mul(3).add(t)).mul(.3)).add(z(o.mul(5).add(n)).mul(.2)), u = k(1).add(l.mul(i.irregularity.mul(.4))), d = w(r.div(u.add(1e-6)), 0, 1);
1454
+ s = B(0, i.edge.add(1e-4), d.oneMinus()), c = d.oneMinus();
1351
1455
  }
1352
- let l = b(r, 0, 1), u = z(b(l.mul(l).oneMinus(), 0, 1), i.dome), d = H(0, .3, c), f = u.mul(d);
1353
- return J(s, f, 0);
1456
+ let l = w(r, 0, 1), u = L(w(l.mul(l).oneMinus(), 0, 1), i.dome), d = B(0, .3, c), f = u.mul(d);
1457
+ return K(s, f, 0);
1354
1458
  })();
1355
1459
  return {
1356
1460
  mask: o.x,
1357
1461
  height: o.y
1358
1462
  };
1359
1463
  }
1360
- var An = {
1464
+ var Bn = {
1361
1465
  type: "shape",
1362
1466
  nodeClass: "texture",
1363
1467
  label: "Shape",
@@ -1424,18 +1528,18 @@ var An = {
1424
1528
  }
1425
1529
  ],
1426
1530
  build(e) {
1427
- let t = e.inputs.coord ?? e.coord, n = e.inputs.seed, r = e.params.shape ?? "blob", i = Math.round(Number(e.params.sides ?? 6)), { mask: a, height: o } = kn(t, r, Number.isFinite(i) ? Math.max(3, i) : 6, n ?? null, {
1428
- irregularity: e.uniforms.irregularity,
1429
- dome: e.uniforms.dome,
1430
- edge: e.uniforms.edge
1531
+ let t = e.inputs.coord ?? e.coord, n = e.inputs.seed, r = e.constant("shape") ?? "blob", i = Math.round(Number(e.constant("sides") ?? 6)), { mask: a, height: o } = zn(t, r, Number.isFinite(i) ? Math.max(3, i) : 6, n ?? null, {
1532
+ irregularity: e.live("irregularity"),
1533
+ dome: e.live("dome"),
1534
+ edge: e.live("edge")
1431
1535
  });
1432
1536
  return {
1433
1537
  mask: a,
1434
1538
  height: o
1435
1539
  };
1436
1540
  }
1437
- }, jn = Math.PI * 2;
1438
- function Mn(e, t) {
1541
+ }, Vn = Math.PI * 2;
1542
+ function Hn(e, t) {
1439
1543
  let n = e.x, r = e.y, i = e.z, a;
1440
1544
  switch (t) {
1441
1545
  case 1: {
@@ -1452,7 +1556,7 @@ function Mn(e, t) {
1452
1556
  a = n.add(r).mul(.5);
1453
1557
  break;
1454
1558
  case 4:
1455
- a = h(r, n).div(jn).add(.5);
1559
+ a = y(r, n).div(Vn).add(.5);
1456
1560
  break;
1457
1561
  case 5: {
1458
1562
  let e = k(.999999).sub(n.mul(n).add(r.mul(r)).add(i.mul(i)).sqrt()).max(0);
@@ -1468,7 +1572,7 @@ function Mn(e, t) {
1468
1572
  }
1469
1573
  //#endregion
1470
1574
  //#region src/graph/nodes/texture/gradient.ts
1471
- var Nn = [
1575
+ var Un = [
1472
1576
  "linear",
1473
1577
  "quadratic",
1474
1578
  "easing",
@@ -1476,7 +1580,7 @@ var Nn = [
1476
1580
  "radial",
1477
1581
  "quadratic-sphere",
1478
1582
  "sphere"
1479
- ], Pn = {
1583
+ ], Wn = {
1480
1584
  type: "gradient",
1481
1585
  nodeClass: "texture",
1482
1586
  label: "Gradient",
@@ -1500,68 +1604,68 @@ var Nn = [
1500
1604
  key: "gradientType",
1501
1605
  label: "type",
1502
1606
  type: "select",
1503
- options: Nn,
1607
+ options: Un,
1504
1608
  default: "linear"
1505
1609
  }],
1506
1610
  build(e) {
1507
- return { field: Mn((e.inputs.coord ?? e.coord).mul(e.uniforms.scale), Math.max(0, Nn.indexOf(e.params.gradientType))) };
1611
+ return { field: Hn((e.inputs.coord ?? e.coord).mul(e.live("scale")), Math.max(0, Un.indexOf(e.constant("gradientType")))) };
1508
1612
  }
1509
- }, Z = Math.PI * 2, Fn = Math.PI / 2, In = 20, Ln = 10;
1510
- function Rn(e, t) {
1511
- if (t === 0) return k(.5).add(V(e.sub(Fn)).mul(.5));
1613
+ }, X = Math.PI * 2, Gn = Math.PI / 2, Kn = 20, qn = 10;
1614
+ function Jn(e, t) {
1615
+ if (t === 0) return k(.5).add(z(e.sub(Gn)).mul(.5));
1512
1616
  if (t === 1) {
1513
- let t = e.div(Z);
1617
+ let t = e.div(X);
1514
1618
  return t.sub(A(t));
1515
1619
  }
1516
- let n = e.div(Z);
1620
+ let n = e.div(X);
1517
1621
  return n.sub(A(n.add(.5))).abs().mul(2);
1518
1622
  }
1519
- function zn(e, t, n, r, i) {
1520
- let a = Math.max(1, Math.round(i.scaleNum * In / Z)), o = Math.max(1, Math.round(i.scaleNum * Ln / Z)), s;
1521
- if (s = i.dir === 0 ? e.x.mul(a * Z) : i.dir === 1 ? e.y.mul(a * Z) : i.dir === 2 ? e.z.mul(a * Z) : e.x.add(e.y).add(e.z).mul(o * Z), s = s.add(t), i.withDistortion) {
1623
+ function Yn(e, t, n, r, i) {
1624
+ let a = Math.max(1, Math.round(i.scaleNum * Kn / X)), o = Math.max(1, Math.round(i.scaleNum * qn / X)), s;
1625
+ if (s = i.dir === 0 ? e.x.mul(a * X) : i.dir === 1 ? e.y.mul(a * X) : i.dir === 2 ? e.z.mul(a * X) : e.x.add(e.y).add(e.z).mul(o * X), s = s.add(t), i.withDistortion) {
1522
1626
  let t = Math.max(1, Math.round(i.scaleNum * i.detailScaleNum)), a = t, o = t;
1523
1627
  i.dir === 0 ? o = 2 : i.dir === 1 && (a = 2);
1524
- let c = $e(q(e.x, e.y), a, o, Math.max(1, i.detail), r);
1628
+ let c = lt(G(e.x, e.y), a, o, Math.max(1, i.detail), r);
1525
1629
  s = s.add(n.mul(c));
1526
1630
  }
1527
- return Rn(s, i.profile);
1631
+ return Jn(s, i.profile);
1528
1632
  }
1529
- function Bn(e, t, n, r, i, a) {
1530
- let o = (e) => e.sub(ge(e)), s;
1531
- s = a.dir === 0 ? J(k(0), o(e.y), o(e.z)) : a.dir === 1 ? J(o(e.x), k(0), o(e.z)) : a.dir === 2 ? J(o(e.x), o(e.y), k(0)) : J(o(e.x), o(e.y), o(e.z));
1532
- let c = s.length().mul(t).mul(In).add(n);
1633
+ function Xn(e, t, n, r, i, a) {
1634
+ let o = (e) => e.sub(Se(e)), s;
1635
+ s = a.dir === 0 ? K(k(0), o(e.y), o(e.z)) : a.dir === 1 ? K(o(e.x), k(0), o(e.z)) : a.dir === 2 ? K(o(e.x), o(e.y), k(0)) : K(o(e.x), o(e.y), o(e.z));
1636
+ let c = s.length().mul(t).mul(Kn).add(n);
1533
1637
  if (a.withDistortion) {
1534
- let t = Math.max(1, Math.round(a.scaleNum * a.detailScaleNum)), n = $e(q(e.x, e.y), t, t, Math.max(1, a.detail), i);
1638
+ let t = Math.max(1, Math.round(a.scaleNum * a.detailScaleNum)), n = lt(G(e.x, e.y), t, t, Math.max(1, a.detail), i);
1535
1639
  c = c.add(r.mul(n));
1536
1640
  }
1537
- return Rn(c, a.profile);
1641
+ return Jn(c, a.profile);
1538
1642
  }
1539
- function Vn(e, t, n, r, i, a, o) {
1540
- if (o.tileable) return o.waveType === 0 ? zn(e, n, r, a, o) : Bn(e, t, n, r, a, o);
1643
+ function Zn(e, t, n, r, i, a, o) {
1644
+ if (o.tileable) return o.waveType === 0 ? Yn(e, n, r, a, o) : Xn(e, t, n, r, a, o);
1541
1645
  let s = e.mul(t).add(1e-6).mul(.999999), c;
1542
- if (o.waveType === 0) c = o.dir === 0 ? s.x.mul(In) : o.dir === 1 ? s.y.mul(In) : o.dir === 2 ? s.z.mul(In) : s.x.add(s.y).add(s.z).mul(Ln);
1646
+ if (o.waveType === 0) c = o.dir === 0 ? s.x.mul(Kn) : o.dir === 1 ? s.y.mul(Kn) : o.dir === 2 ? s.z.mul(Kn) : s.x.add(s.y).add(s.z).mul(qn);
1543
1647
  else {
1544
1648
  let e = s;
1545
- o.dir === 0 ? e = s.mul(J(0, 1, 1)) : o.dir === 1 ? e = s.mul(J(1, 0, 1)) : o.dir === 2 && (e = s.mul(J(1, 1, 0))), c = e.length().mul(In);
1649
+ o.dir === 0 ? e = s.mul(K(0, 1, 1)) : o.dir === 1 ? e = s.mul(K(1, 0, 1)) : o.dir === 2 && (e = s.mul(K(1, 1, 0))), c = e.length().mul(Kn);
1546
1650
  }
1547
1651
  if (c = c.add(n), o.withDistortion) {
1548
- let e = qe(s.mul(i), o.detail, a, k(2));
1652
+ let e = rt(s.mul(i), o.detail, a, k(2));
1549
1653
  c = c.add(r.mul(e.mul(2).sub(1)));
1550
1654
  }
1551
- return Rn(c, o.profile);
1655
+ return Jn(c, o.profile);
1552
1656
  }
1553
1657
  //#endregion
1554
1658
  //#region src/graph/nodes/texture/wave.ts
1555
- var Hn = ["bands", "rings"], Un = [
1659
+ var Qn = ["bands", "rings"], $n = [
1556
1660
  "x",
1557
1661
  "y",
1558
1662
  "z",
1559
1663
  "diagonal"
1560
- ], Wn = [
1664
+ ], er = [
1561
1665
  "sine",
1562
1666
  "saw",
1563
1667
  "triangle"
1564
- ], Gn = {
1668
+ ], tr = {
1565
1669
  type: "wave",
1566
1670
  nodeClass: "texture",
1567
1671
  label: "Wave",
@@ -1588,21 +1692,21 @@ var Hn = ["bands", "rings"], Un = [
1588
1692
  key: "waveType",
1589
1693
  label: "type",
1590
1694
  type: "select",
1591
- options: Hn,
1695
+ options: Qn,
1592
1696
  default: "bands"
1593
1697
  },
1594
1698
  {
1595
1699
  key: "direction",
1596
1700
  label: "direction",
1597
1701
  type: "select",
1598
- options: Un,
1702
+ options: $n,
1599
1703
  default: "x"
1600
1704
  },
1601
1705
  {
1602
1706
  key: "profile",
1603
1707
  label: "profile",
1604
1708
  type: "select",
1605
- options: Wn,
1709
+ options: er,
1606
1710
  default: "sine"
1607
1711
  },
1608
1712
  {
@@ -1655,18 +1759,18 @@ var Hn = ["bands", "rings"], Un = [
1655
1759
  ],
1656
1760
  build(e) {
1657
1761
  let t = e.inputs.coord ?? e.coord, n = {
1658
- waveType: Math.max(0, Hn.indexOf(e.params.waveType)),
1659
- dir: Math.max(0, Un.indexOf(e.params.direction)),
1660
- profile: Math.max(0, Wn.indexOf(e.params.profile)),
1661
- withDistortion: Number(e.params.distortion ?? 0) > 0,
1662
- detail: e.params.detail ?? 2,
1762
+ waveType: Math.max(0, Qn.indexOf(e.constant("waveType"))),
1763
+ dir: Math.max(0, $n.indexOf(e.constant("direction"))),
1764
+ profile: Math.max(0, er.indexOf(e.constant("profile"))),
1765
+ withDistortion: Number(e.constant("distortion") ?? 0) > 0,
1766
+ detail: e.constant("detail") ?? 2,
1663
1767
  tileable: e.backend === "offline",
1664
- scaleNum: Number(e.params.scale ?? 1),
1665
- detailScaleNum: Number(e.params.detailScale ?? 1)
1768
+ scaleNum: Number(e.constant("scale") ?? 1),
1769
+ detailScaleNum: Number(e.constant("detailScale") ?? 1)
1666
1770
  };
1667
- return { field: Vn(t, e.uniforms.scale, e.uniforms.phase, e.uniforms.distortion, e.uniforms.detailScale, e.uniforms.detailRoughness, n) };
1771
+ return { field: Zn(t, e.live("scale"), e.live("phase"), e.live("distortion"), e.live("detailScale"), e.live("detailRoughness"), n) };
1668
1772
  }
1669
- }, Kn = 6.283185307179586, qn = {
1773
+ }, nr = 6.283185307179586, rr = {
1670
1774
  type: "anisotropic-stripes",
1671
1775
  nodeClass: "texture",
1672
1776
  label: "Anisotropic Stripes",
@@ -1717,10 +1821,10 @@ var Hn = ["bands", "rings"], Un = [
1717
1821
  }
1718
1822
  ],
1719
1823
  build(e) {
1720
- let t = e.inputs.coord ?? e.coord, n = h(t.z, t.x).div(Kn), r = R(J(t.y.mul(.6), n.mul(6), k(0))).mul(e.uniforms.waviness);
1721
- return { field: n.mul(e.uniforms.count).add(r).mul(Kn).sin().mul(.5).add(.5).pow(e.uniforms.sharpness).mul(e.uniforms.contrast) };
1824
+ let t = e.inputs.coord ?? e.coord, n = y(t.z, t.x).div(nr), r = fe(K(t.y.mul(.6), n.mul(6), k(0))).mul(e.live("waviness"));
1825
+ return { field: n.mul(e.live("count")).add(r).mul(nr).sin().mul(.5).add(.5).pow(e.live("sharpness")).mul(e.live("contrast")) };
1722
1826
  }
1723
- }, Jn = /* @__PURE__ */ "add.subtract.multiply.divide.multiply-add.power.logarithm.sqrt.inverse-sqrt.absolute.exponent.min.max.less-than.greater-than.sign.compare.smooth-min.smooth-max.round.floor.ceil.truncate.fraction.modulo.floored-modulo.wrap.snap.pingpong.sine.cosine.tangent.arcsine.arccosine.arctangent.arctan2.sinh.cosh.tanh.radians.degrees.mix".split("."), Yn = new Set([
1827
+ }, ir = /* @__PURE__ */ "add.subtract.multiply.divide.multiply-add.power.logarithm.sqrt.inverse-sqrt.absolute.exponent.min.max.less-than.greater-than.sign.compare.smooth-min.smooth-max.round.floor.ceil.truncate.fraction.modulo.floored-modulo.wrap.snap.pingpong.sine.cosine.tangent.arcsine.arccosine.arctangent.arctan2.sinh.cosh.tanh.radians.degrees.mix".split("."), ar = new Set([
1724
1828
  "sqrt",
1725
1829
  "inverse-sqrt",
1726
1830
  "absolute",
@@ -1742,13 +1846,13 @@ var Hn = ["bands", "rings"], Un = [
1742
1846
  "tanh",
1743
1847
  "radians",
1744
1848
  "degrees"
1745
- ]), Xn = new Set([
1849
+ ]), or = new Set([
1746
1850
  "multiply-add",
1747
1851
  "compare",
1748
1852
  "smooth-min",
1749
1853
  "smooth-max",
1750
1854
  "wrap"
1751
- ]), Zn = {
1855
+ ]), sr = {
1752
1856
  power: ["Base", "Exponent"],
1753
1857
  logarithm: ["Value", "Base"],
1754
1858
  "multiply-add": [
@@ -1781,8 +1885,8 @@ var Hn = ["bands", "rings"], Un = [
1781
1885
  radians: ["Degrees"],
1782
1886
  degrees: ["Radians"]
1783
1887
  };
1784
- function Qn(e) {
1785
- let [t, n, r] = Zn[e] ?? [
1888
+ function cr(e) {
1889
+ let [t, n, r] = sr[e] ?? [
1786
1890
  "A",
1787
1891
  "B",
1788
1892
  "C"
@@ -1791,17 +1895,17 @@ function Qn(e) {
1791
1895
  label: t,
1792
1896
  kind: "float"
1793
1897
  }];
1794
- return Yn.has(e) || i.push({
1898
+ return ar.has(e) || i.push({
1795
1899
  key: "b",
1796
1900
  label: n ?? "B",
1797
1901
  kind: "float"
1798
- }), Xn.has(e) && i.push({
1902
+ }), or.has(e) && i.push({
1799
1903
  key: "c",
1800
1904
  label: r ?? "C",
1801
1905
  kind: "float"
1802
1906
  }), i;
1803
1907
  }
1804
- var $n = {
1908
+ var lr = {
1805
1909
  type: "math",
1806
1910
  nodeClass: "converter",
1807
1911
  label: "Math",
@@ -1823,7 +1927,7 @@ var $n = {
1823
1927
  key: "op",
1824
1928
  label: "op",
1825
1929
  type: "select",
1826
- options: Jn,
1930
+ options: ir,
1827
1931
  default: "mix"
1828
1932
  },
1829
1933
  {
@@ -1847,7 +1951,7 @@ var $n = {
1847
1951
  ],
1848
1952
  declare(e) {
1849
1953
  return {
1850
- inputs: Qn(e.op ?? "mix"),
1954
+ inputs: cr(e.op ?? "mix"),
1851
1955
  outputs: [{
1852
1956
  key: "field",
1853
1957
  kind: "float"
@@ -1855,68 +1959,68 @@ var $n = {
1855
1959
  };
1856
1960
  },
1857
1961
  build(e) {
1858
- let t = e.inputs.a ?? k(0), n = e.inputs.b ?? e.uniforms.factor, r = e.inputs.c ?? e.uniforms.c;
1859
- switch (e.params.op) {
1962
+ let t = e.inputs.a ?? k(0), n = e.inputs.b ?? e.live("factor"), r = e.inputs.c ?? e.live("c");
1963
+ switch (e.constant("op")) {
1860
1964
  case "add": return { field: t.add(n) };
1861
1965
  case "subtract": return { field: t.sub(n) };
1862
1966
  case "multiply": return { field: t.mul(n) };
1863
- case "divide": return { field: B(n.equal(0), k(0), t.div(n)) };
1967
+ case "divide": return { field: R(n.equal(0), k(0), t.div(n)) };
1864
1968
  case "multiply-add": return { field: t.mul(n).add(r) };
1865
- case "power": return { field: z(t, n) };
1866
- case "logarithm": return { field: B(t.greaterThan(0).and(n.greaterThan(0)), ae(t).div(ae(n)), k(0)) };
1867
- case "sqrt": return { field: xe(t) };
1868
- case "inverse-sqrt": return { field: B(t.greaterThan(0), ie(t), k(0)) };
1869
- case "absolute": return { field: f(t) };
1870
- case "exponent": return { field: O(t) };
1871
- case "min": return { field: F(t, n) };
1872
- case "max": return { field: P(t, n) };
1873
- case "less-than": return { field: B(t.lessThan(n), k(1), k(0)) };
1874
- case "greater-than": return { field: B(t.greaterThan(n), k(1), k(0)) };
1875
- case "sign": return { field: ye(t) };
1876
- case "compare": return { field: B(t.sub(n).abs().lessThanEqual(P(r, k(1e-5))), k(1), k(0)) };
1877
- case "smooth-min": return { field: er(t, n, r) };
1878
- case "smooth-max": return { field: er(t.negate(), n.negate(), r).negate() };
1879
- case "round": return { field: ge(t) };
1969
+ case "power": return { field: L(t, n) };
1970
+ case "logarithm": return { field: R(t.greaterThan(0).and(n.greaterThan(0)), ue(t).div(ue(n)), k(0)) };
1971
+ case "sqrt": return { field: De(t) };
1972
+ case "inverse-sqrt": return { field: R(t.greaterThan(0), ce(t), k(0)) };
1973
+ case "absolute": return { field: g(t) };
1974
+ case "exponent": return { field: ie(t) };
1975
+ case "min": return { field: P(t, n) };
1976
+ case "max": return { field: N(t, n) };
1977
+ case "less-than": return { field: R(t.lessThan(n), k(1), k(0)) };
1978
+ case "greater-than": return { field: R(t.greaterThan(n), k(1), k(0)) };
1979
+ case "sign": return { field: Te(t) };
1980
+ case "compare": return { field: R(t.sub(n).abs().lessThanEqual(N(r, k(1e-5))), k(1), k(0)) };
1981
+ case "smooth-min": return { field: ur(t, n, r) };
1982
+ case "smooth-max": return { field: ur(t.negate(), n.negate(), r).negate() };
1983
+ case "round": return { field: Se(t) };
1880
1984
  case "floor": return { field: A(t) };
1881
- case "ceil": return { field: y(t) };
1882
- case "truncate": return { field: Te(t) };
1985
+ case "ceil": return { field: C(t) };
1986
+ case "truncate": return { field: je(t) };
1883
1987
  case "fraction": return { field: j(t) };
1884
- case "modulo": return { field: B(n.equal(0), k(0), t.sub(n.mul(Te(t.div(n))))) };
1885
- case "floored-modulo": return { field: B(n.equal(0), k(0), t.sub(n.mul(A(t.div(n))))) };
1886
- case "wrap": return { field: tr(t, n, r) };
1887
- case "snap": return { field: B(n.equal(0), k(0), A(t.div(n)).mul(n)) };
1888
- case "pingpong": return { field: nr(t, n) };
1889
- case "sine": return { field: V(t) };
1890
- case "cosine": return { field: S(t) };
1891
- case "tangent": return { field: Ce(t) };
1892
- case "arcsine": return { field: B(t.abs().lessThanEqual(1), m(t), k(0)) };
1893
- case "arccosine": return { field: B(t.abs().lessThanEqual(1), p(t), k(0)) };
1894
- case "arctangent": return { field: h(t) };
1895
- case "arctan2": return { field: h(t, n) };
1896
- case "sinh": return { field: be(t) };
1897
- case "cosh": return { field: C(t) };
1898
- case "tanh": return { field: we(t) };
1899
- case "radians": return { field: me(t) };
1900
- case "degrees": return { field: ee(t) };
1901
- default: return { field: I(t, n, e.uniforms.factor) };
1988
+ case "modulo": return { field: R(n.equal(0), k(0), t.sub(n.mul(je(t.div(n))))) };
1989
+ case "floored-modulo": return { field: R(n.equal(0), k(0), t.sub(n.mul(A(t.div(n))))) };
1990
+ case "wrap": return { field: dr(t, n, r) };
1991
+ case "snap": return { field: R(n.equal(0), k(0), A(t.div(n)).mul(n)) };
1992
+ case "pingpong": return { field: fr(t, n) };
1993
+ case "sine": return { field: z(t) };
1994
+ case "cosine": return { field: E(t) };
1995
+ case "tangent": return { field: ke(t) };
1996
+ case "arcsine": return { field: R(t.abs().lessThanEqual(1), v(t), k(0)) };
1997
+ case "arccosine": return { field: R(t.abs().lessThanEqual(1), _(t), k(0)) };
1998
+ case "arctangent": return { field: y(t) };
1999
+ case "arctan2": return { field: y(t, n) };
2000
+ case "sinh": return { field: Ee(t) };
2001
+ case "cosh": return { field: D(t) };
2002
+ case "tanh": return { field: Ae(t) };
2003
+ case "radians": return { field: be(t) };
2004
+ case "degrees": return { field: re(t) };
2005
+ default: return { field: F(t, n, e.live("factor")) };
1902
2006
  }
1903
2007
  }
1904
2008
  };
1905
- function er(e, t, n) {
1906
- let r = P(n.sub(e.sub(t).abs()), k(0)).div(n), i = F(e, t).sub(r.mul(r).mul(r).mul(n).div(6));
1907
- return B(n.equal(0), F(e, t), i);
2009
+ function ur(e, t, n) {
2010
+ let r = N(n.sub(e.sub(t).abs()), k(0)).div(n), i = P(e, t).sub(r.mul(r).mul(r).mul(n).div(6));
2011
+ return R(n.equal(0), P(e, t), i);
1908
2012
  }
1909
- function tr(e, t, n) {
2013
+ function dr(e, t, n) {
1910
2014
  let r = t.sub(n);
1911
- return B(r.equal(0), n, e.sub(r.mul(A(e.sub(n).div(r)))));
2015
+ return R(r.equal(0), n, e.sub(r.mul(A(e.sub(n).div(r)))));
1912
2016
  }
1913
- function nr(e, t) {
2017
+ function fr(e, t) {
1914
2018
  let n = t.mul(2);
1915
- return B(t.equal(0), k(0), j(e.sub(t).div(n)).mul(n).sub(t).abs());
2019
+ return R(t.equal(0), k(0), j(e.sub(t).div(n)).mul(n).sub(t).abs());
1916
2020
  }
1917
2021
  //#endregion
1918
2022
  //#region src/graph/nodes/converter/levels.ts
1919
- var rr = {
2023
+ var pr = {
1920
2024
  type: "levels",
1921
2025
  nodeClass: "converter",
1922
2026
  label: "Levels / Remap",
@@ -1955,10 +2059,10 @@ var rr = {
1955
2059
  }
1956
2060
  ],
1957
2061
  build(e) {
1958
- let t = e.inputs.field ?? k(.5), n = e.params.invert ? t.oneMinus() : t;
1959
- return { field: I(e.uniforms.min, e.uniforms.max, n) };
2062
+ let t = e.inputs.field ?? k(.5), n = e.constant("invert") ? t.oneMinus() : t;
2063
+ return { field: F(e.live("min"), e.live("max"), n) };
1960
2064
  }
1961
- }, ir = {
2065
+ }, mr = {
1962
2066
  type: "color-ramp",
1963
2067
  nodeClass: "converter",
1964
2068
  label: "Color Ramp",
@@ -2003,10 +2107,10 @@ var rr = {
2003
2107
  }
2004
2108
  ],
2005
2109
  build(e) {
2006
- let t = e.inputs.field ?? k(.5), n = e.uniforms.low, r = e.uniforms.high, i = b(t.sub(n).div(r.sub(n).max(1e-5)), 0, 1);
2007
- return { color: I(e.uniforms.colorA, e.uniforms.colorB, i) };
2110
+ let t = e.inputs.field ?? k(.5), n = e.live("low"), r = e.live("high"), i = w(t.sub(n).div(r.sub(n).max(1e-5)), 0, 1);
2111
+ return { color: F(e.live("colorA"), e.live("colorB"), i) };
2008
2112
  }
2009
- }, ar = {
2113
+ }, hr = {
2010
2114
  type: "height-blend",
2011
2115
  nodeClass: "converter",
2012
2116
  label: "Height Blend",
@@ -2061,12 +2165,12 @@ var rr = {
2061
2165
  }
2062
2166
  ],
2063
2167
  build(e) {
2064
- let t = e.inputs.heightA ?? k(.5), n = e.inputs.heightB ?? k(.5), r = e.uniforms.transition, i = e.uniforms.width;
2065
- e.inputs.breakup !== void 0 && (n = n.add(e.inputs.breakup.sub(.5).mul(e.uniforms.breakup)));
2168
+ let t = e.inputs.heightA ?? k(.5), n = e.inputs.heightB ?? k(.5), r = e.live("transition"), i = e.live("width");
2169
+ e.inputs.breakup !== void 0 && (n = n.add(e.inputs.breakup.sub(.5).mul(e.live("breakup"))));
2066
2170
  let a = n.sub(t).add(r.mul(2).sub(1));
2067
- return { fac: H(i.negate(), i, a) };
2171
+ return { fac: B(i.negate(), i, a) };
2068
2172
  }
2069
- }, or = {
2173
+ }, gr = {
2070
2174
  type: "blend",
2071
2175
  nodeClass: "color",
2072
2176
  label: "Blend",
@@ -2111,8 +2215,8 @@ var rr = {
2111
2215
  default: 1
2112
2216
  }],
2113
2217
  build(e) {
2114
- let t = e.inputs.a ?? x(0), n = e.inputs.b ?? x(16777215), r;
2115
- switch (e.params.mode) {
2218
+ let t = e.inputs.a ?? T(0), n = e.inputs.b ?? T(16777215), r;
2219
+ switch (e.constant("mode")) {
2116
2220
  case "multiply":
2117
2221
  r = t.mul(n);
2118
2222
  break;
@@ -2126,10 +2230,10 @@ var rr = {
2126
2230
  r = n;
2127
2231
  break;
2128
2232
  }
2129
- let i = (e.inputs.mask ?? k(1)).mul(e.uniforms.opacity);
2130
- return { color: I(t, r, i) };
2233
+ let i = (e.inputs.mask ?? k(1)).mul(e.live("opacity"));
2234
+ return { color: F(t, r, i) };
2131
2235
  }
2132
- }, sr = {
2236
+ }, _r = {
2133
2237
  type: "invert",
2134
2238
  nodeClass: "color",
2135
2239
  label: "Invert Color",
@@ -2156,10 +2260,10 @@ var rr = {
2156
2260
  default: 1
2157
2261
  }],
2158
2262
  build(e) {
2159
- let t = e.inputs.color ?? J(0, 0, 0), n = e.inputs.fac ?? e.uniforms.fac;
2160
- return { color: I(t, J(1, 1, 1).sub(t), n) };
2263
+ let t = e.inputs.color ?? K(0, 0, 0), n = e.inputs.fac ?? e.live("fac");
2264
+ return { color: F(t, K(1, 1, 1).sub(t), n) };
2161
2265
  }
2162
- }, cr = {
2266
+ }, vr = {
2163
2267
  type: "bright-contrast",
2164
2268
  nodeClass: "color",
2165
2269
  label: "Bright / Contrast",
@@ -2202,21 +2306,21 @@ var rr = {
2202
2306
  default: 0
2203
2307
  }],
2204
2308
  build(e) {
2205
- let t = e.inputs.color ?? J(0, 0, 0), n = e.inputs.contrast ?? e.uniforms.contrast, r = e.inputs.bright ?? e.uniforms.bright, i = k(1).add(n), a = r.sub(n.mul(.5));
2309
+ let t = e.inputs.color ?? K(0, 0, 0), n = e.inputs.contrast ?? e.live("contrast"), r = e.inputs.bright ?? e.live("bright"), i = k(1).add(n), a = r.sub(n.mul(.5));
2206
2310
  return { color: t.mul(i).add(a).max(0) };
2207
2311
  }
2208
- }, lr = 1e-10;
2209
- function ur(e) {
2210
- let t = e.x, n = e.y, r = e.z, i = P(t, P(n, r)), a = F(t, F(n, r)), o = i.sub(a), s = i, c = B(i.equal(0), k(0), o.div(P(i, k(lr)))), l = J(i, i, i).sub(e).div(P(o, k(lr))), u = l.z.sub(l.y), d = k(2).add(l.x).sub(l.z), f = k(4).add(l.y).sub(l.x), p = B(n.equal(i), d, f);
2211
- return p = B(t.equal(i), u, p), p = p.div(6), p = B(p.lessThan(0), p.add(1), p), p = B(c.equal(0), k(0), p), J(p, c, s);
2312
+ }, yr = 1e-10;
2313
+ function br(e) {
2314
+ let t = e.x, n = e.y, r = e.z, i = N(t, N(n, r)), a = P(t, P(n, r)), o = i.sub(a), s = i, c = R(i.equal(0), k(0), o.div(N(i, k(yr)))), l = K(i, i, i).sub(e).div(N(o, k(yr))), u = l.z.sub(l.y), d = k(2).add(l.x).sub(l.z), f = k(4).add(l.y).sub(l.x), p = R(n.equal(i), d, f);
2315
+ return p = R(t.equal(i), u, p), p = p.div(6), p = R(p.lessThan(0), p.add(1), p), p = R(c.equal(0), k(0), p), K(p, c, s);
2212
2316
  }
2213
- function dr(e) {
2214
- let t = e.x, n = e.y, r = e.z, i = B(t.equal(1), k(0), t).mul(6), a = A(i), o = i.sub(a), s = r.mul(k(1).sub(n)), c = r.mul(k(1).sub(n.mul(o))), l = r.mul(k(1).sub(n.mul(k(1).sub(o)))), u = J(r, s, c);
2215
- return u = B(a.equal(4), J(l, s, r), u), u = B(a.equal(3), J(s, c, r), u), u = B(a.equal(2), J(s, r, l), u), u = B(a.equal(1), J(c, r, s), u), u = B(a.equal(0), J(r, l, s), u), B(n.equal(0), J(r, r, r), u);
2317
+ function xr(e) {
2318
+ let t = e.x, n = e.y, r = e.z, i = R(t.equal(1), k(0), t).mul(6), a = A(i), o = i.sub(a), s = r.mul(k(1).sub(n)), c = r.mul(k(1).sub(n.mul(o))), l = r.mul(k(1).sub(n.mul(k(1).sub(o)))), u = K(r, s, c);
2319
+ return u = R(a.equal(4), K(l, s, r), u), u = R(a.equal(3), K(s, c, r), u), u = R(a.equal(2), K(s, r, l), u), u = R(a.equal(1), K(c, r, s), u), u = R(a.equal(0), K(r, l, s), u), R(n.equal(0), K(r, r, r), u);
2216
2320
  }
2217
2321
  //#endregion
2218
2322
  //#region src/graph/nodes/color/hue-sat-val.ts
2219
- var fr = {
2323
+ var Sr = {
2220
2324
  type: "hue-sat-val",
2221
2325
  nodeClass: "color",
2222
2326
  label: "Hue / Saturation",
@@ -2268,17 +2372,17 @@ var fr = {
2268
2372
  }
2269
2373
  ],
2270
2374
  build(e) {
2271
- let t = e.inputs.color ?? J(.8, .8, .8), n = ur(t);
2272
- return { color: I(t, dr(J(j(n.x.add(e.uniforms.hue).add(.5)), n.y.mul(e.uniforms.saturation).clamp(0, 1), n.z.mul(e.uniforms.value))), e.uniforms.fac) };
2375
+ let t = e.inputs.color ?? K(.8, .8, .8), n = br(t);
2376
+ return { color: F(t, xr(K(j(n.x.add(e.live("hue")).add(.5)), n.y.mul(e.live("saturation")).clamp(0, 1), n.z.mul(e.live("value")))), e.live("fac")) };
2273
2377
  }
2274
- }, pr = (e, t, n, r, i) => B(e.equal(0), t, B(e.equal(1), n, B(e.equal(2), r, i)));
2275
- function mr(e, t) {
2276
- let n = e.clamp(0, 1).mul(4), r = A(n).clamp(0, 3), i = n.sub(r), a = pr(r, t[0], t[0], t[1], t[2]), o = pr(r, t[0], t[1], t[2], t[3]), s = pr(r, t[1], t[2], t[3], t[4]), c = pr(r, t[2], t[3], t[4], t[4]), l = i.mul(i), u = l.mul(i);
2378
+ }, Cr = (e, t, n, r, i) => R(e.equal(0), t, R(e.equal(1), n, R(e.equal(2), r, i)));
2379
+ function wr(e, t) {
2380
+ let n = e.clamp(0, 1).mul(4), r = A(n).clamp(0, 3), i = n.sub(r), a = Cr(r, t[0], t[0], t[1], t[2]), o = Cr(r, t[0], t[1], t[2], t[3]), s = Cr(r, t[1], t[2], t[3], t[4]), c = Cr(r, t[2], t[3], t[4], t[4]), l = i.mul(i), u = l.mul(i);
2277
2381
  return o.mul(2).add(s.sub(a).mul(i)).add(a.mul(2).sub(o.mul(5)).add(s.mul(4)).sub(c).mul(l)).add(o.mul(3).sub(s.mul(3)).add(c).sub(a).mul(u)).mul(.5);
2278
2382
  }
2279
2383
  //#endregion
2280
2384
  //#region src/graph/nodes/color/rgb-curves.ts
2281
- var hr = () => [...ke], gr = {
2385
+ var Tr = () => [...Fe], Er = {
2282
2386
  type: "rgb-curves",
2283
2387
  nodeClass: "color",
2284
2388
  label: "RGB Curves",
@@ -2308,14 +2412,14 @@ var hr = () => [...ke], gr = {
2308
2412
  label: "curves",
2309
2413
  type: "curve",
2310
2414
  default: {
2311
- C: hr(),
2312
- R: hr(),
2313
- G: hr(),
2314
- B: hr()
2415
+ C: Tr(),
2416
+ R: Tr(),
2417
+ G: Tr(),
2418
+ B: Tr()
2315
2419
  }
2316
2420
  }],
2317
2421
  build(e) {
2318
- let t = e.inputs.color ?? J(0, 0, 0), n = e.uniforms.curves, r = (e) => [
2422
+ let t = e.inputs.color ?? K(0, 0, 0), n = e.live("curves"), r = (e) => [
2319
2423
  0,
2320
2424
  1,
2321
2425
  2,
@@ -2326,10 +2430,10 @@ var hr = () => [...ke], gr = {
2326
2430
  r(5),
2327
2431
  r(10),
2328
2432
  r(15)
2329
- ], c = mr(mr(t.x, i), a), l = mr(mr(t.y, i), o), u = mr(mr(t.z, i), s), d = e.inputs.fac ?? e.uniforms.fac;
2330
- return { color: I(t, J(c, l, u), d) };
2433
+ ], c = wr(wr(t.x, i), a), l = wr(wr(t.y, i), o), u = wr(wr(t.z, i), s), d = e.inputs.fac ?? e.live("fac");
2434
+ return { color: F(t, K(c, l, u), d) };
2331
2435
  }
2332
- }, _r = {
2436
+ }, Dr = {
2333
2437
  type: "luminance",
2334
2438
  nodeClass: "converter",
2335
2439
  label: "Luminance",
@@ -2344,9 +2448,9 @@ var hr = () => [...ke], gr = {
2344
2448
  params: [],
2345
2449
  build(e) {
2346
2450
  let t = e.inputs.color;
2347
- return { field: t ? oe(t) : k(0) };
2451
+ return { field: t ? de(t) : k(0) };
2348
2452
  }
2349
- }, vr = {
2453
+ }, Or = {
2350
2454
  type: "split-channels",
2351
2455
  nodeClass: "converter",
2352
2456
  label: "Split Channels",
@@ -2381,7 +2485,7 @@ var hr = () => [...ke], gr = {
2381
2485
  b: k(0)
2382
2486
  };
2383
2487
  }
2384
- }, yr = {
2488
+ }, kr = {
2385
2489
  type: "combine-channels",
2386
2490
  nodeClass: "converter",
2387
2491
  label: "Combine Channels",
@@ -2405,9 +2509,9 @@ var hr = () => [...ke], gr = {
2405
2509
  }],
2406
2510
  params: [],
2407
2511
  build(e) {
2408
- return { color: J(e.inputs.r ?? k(0), e.inputs.g ?? k(0), e.inputs.b ?? k(0)) };
2512
+ return { color: K(e.inputs.r ?? k(0), e.inputs.g ?? k(0), e.inputs.b ?? k(0)) };
2409
2513
  }
2410
- }, br = {
2514
+ }, Ar = {
2411
2515
  type: "clamp",
2412
2516
  nodeClass: "converter",
2413
2517
  label: "Clamp",
@@ -2460,10 +2564,10 @@ var hr = () => [...ke], gr = {
2460
2564
  }
2461
2565
  ],
2462
2566
  build(e) {
2463
- let t = e.inputs.value ?? k(0), n = e.inputs.min ?? e.uniforms.min, r = e.inputs.max ?? e.uniforms.max;
2464
- return e.params.mode === "range" ? { field: t.clamp(F(n, r), P(n, r)) } : { field: b(t, n, r) };
2567
+ let t = e.inputs.value ?? k(0), n = e.inputs.min ?? e.live("min"), r = e.inputs.max ?? e.live("max");
2568
+ return e.constant("mode") === "range" ? { field: t.clamp(P(n, r), N(n, r)) } : { field: w(t, n, r) };
2465
2569
  }
2466
- }, xr = {
2570
+ }, jr = {
2467
2571
  type: "separate-xyz",
2468
2572
  nodeClass: "converter",
2469
2573
  label: "Separate XYZ",
@@ -2487,14 +2591,14 @@ var hr = () => [...ke], gr = {
2487
2591
  ],
2488
2592
  params: [],
2489
2593
  build(e) {
2490
- let t = e.inputs.vector ?? J(0, 0, 0);
2594
+ let t = e.inputs.vector ?? K(0, 0, 0);
2491
2595
  return {
2492
2596
  x: t.x,
2493
2597
  y: t.y,
2494
2598
  z: t.z
2495
2599
  };
2496
2600
  }
2497
- }, Sr = {
2601
+ }, Mr = {
2498
2602
  type: "combine-xyz",
2499
2603
  nodeClass: "converter",
2500
2604
  label: "Combine XYZ",
@@ -2546,9 +2650,9 @@ var hr = () => [...ke], gr = {
2546
2650
  }
2547
2651
  ],
2548
2652
  build(e) {
2549
- return { vector: J(e.inputs.x ?? e.uniforms.x, e.inputs.y ?? e.uniforms.y, e.inputs.z ?? e.uniforms.z) };
2653
+ return { vector: K(e.inputs.x ?? e.live("x"), e.inputs.y ?? e.live("y"), e.inputs.z ?? e.live("z")) };
2550
2654
  }
2551
- }, Cr = {
2655
+ }, Nr = {
2552
2656
  type: "constant-field",
2553
2657
  nodeClass: "input",
2554
2658
  label: "Constant (Field)",
@@ -2567,9 +2671,9 @@ var hr = () => [...ke], gr = {
2567
2671
  default: .5
2568
2672
  }],
2569
2673
  build(e) {
2570
- return { field: e.uniforms.value };
2674
+ return { field: e.live("value") };
2571
2675
  }
2572
- }, wr = {
2676
+ }, Pr = {
2573
2677
  type: "constant-color",
2574
2678
  nodeClass: "input",
2575
2679
  label: "Constant (Color)",
@@ -2585,9 +2689,9 @@ var hr = () => [...ke], gr = {
2585
2689
  default: "#808080"
2586
2690
  }],
2587
2691
  build(e) {
2588
- return { color: e.uniforms.color };
2692
+ return { color: e.live("color") };
2589
2693
  }
2590
- }, Tr = {
2694
+ }, Fr = {
2591
2695
  type: "tex-coordinate",
2592
2696
  nodeClass: "input",
2593
2697
  label: "Texture Coordinate",
@@ -2616,20 +2720,20 @@ var hr = () => [...ke], gr = {
2616
2720
  ],
2617
2721
  params: [],
2618
2722
  build(e) {
2619
- let t = J(K().x, K().y, k(0));
2723
+ let t = K(W().x, W().y, k(0));
2620
2724
  return e.backend === "offline" ? {
2621
2725
  generated: t,
2622
2726
  uv: t,
2623
2727
  object: t,
2624
2728
  normal: t
2625
2729
  } : {
2626
- generated: fe,
2730
+ generated: ve,
2627
2731
  uv: t,
2628
- object: fe,
2629
- normal: se
2732
+ object: ve,
2733
+ normal: pe
2630
2734
  };
2631
2735
  }
2632
- }, Er = [
2736
+ }, Ir = [
2633
2737
  "add",
2634
2738
  "subtract",
2635
2739
  "multiply",
@@ -2652,11 +2756,11 @@ var hr = () => [...ke], gr = {
2652
2756
  "sine",
2653
2757
  "cosine",
2654
2758
  "tangent"
2655
- ], Dr = new Set([
2759
+ ], Lr = new Set([
2656
2760
  "dot",
2657
2761
  "distance",
2658
2762
  "length"
2659
- ]), Or = [{
2763
+ ]), Rr = [{
2660
2764
  key: "vector1",
2661
2765
  label: "A",
2662
2766
  kind: "vector"
@@ -2664,11 +2768,11 @@ var hr = () => [...ke], gr = {
2664
2768
  key: "vector2",
2665
2769
  label: "B",
2666
2770
  kind: "vector"
2667
- }], kr = {
2771
+ }], zr = {
2668
2772
  type: "vector-math",
2669
2773
  nodeClass: "vector",
2670
2774
  label: "Vector Math",
2671
- inputs: Or,
2775
+ inputs: Rr,
2672
2776
  outputs: [{
2673
2777
  key: "vector",
2674
2778
  label: "Vector",
@@ -2678,7 +2782,7 @@ var hr = () => [...ke], gr = {
2678
2782
  key: "operation",
2679
2783
  label: "op",
2680
2784
  type: "select",
2681
- options: Er,
2785
+ options: Ir,
2682
2786
  default: "add"
2683
2787
  }, {
2684
2788
  key: "scale",
@@ -2692,8 +2796,8 @@ var hr = () => [...ke], gr = {
2692
2796
  declare(e) {
2693
2797
  let t = e.operation ?? "add";
2694
2798
  return {
2695
- inputs: Or,
2696
- outputs: Dr.has(t) ? [{
2799
+ inputs: Rr,
2800
+ outputs: Lr.has(t) ? [{
2697
2801
  key: "value",
2698
2802
  label: "Value",
2699
2803
  kind: "float"
@@ -2705,33 +2809,86 @@ var hr = () => [...ke], gr = {
2705
2809
  };
2706
2810
  },
2707
2811
  build(e) {
2708
- let t = e.inputs.vector1 ?? e.coord, n = e.inputs.vector2 ?? J(0, 0, 0), r = e.uniforms.scale;
2709
- switch (e.params.operation ?? "add") {
2812
+ let t = e.inputs.vector1 ?? e.coord, n = e.inputs.vector2 ?? K(0, 0, 0);
2813
+ switch (e.constant("operation") ?? "add") {
2710
2814
  case "subtract": return { vector: t.sub(n) };
2711
2815
  case "multiply": return { vector: t.mul(n) };
2712
2816
  case "divide": return { vector: t.div(n) };
2713
- case "cross": return { vector: w(t, n) };
2714
- case "project": return { vector: n.mul(D(t, n).div(D(n, n))) };
2715
- case "reflect": return { vector: he(t, n.normalize()) };
2716
- case "dot": return { value: D(t, n) };
2817
+ case "cross": return { vector: ee(t, n) };
2818
+ case "project": return { vector: n.mul(O(t, n).div(O(n, n))) };
2819
+ case "reflect": return { vector: xe(t, n.normalize()) };
2820
+ case "dot": return { value: O(t, n) };
2717
2821
  case "distance": return { value: t.sub(n).length() };
2718
2822
  case "length": return { value: t.length() };
2719
- case "scale": return { vector: t.mul(r) };
2823
+ case "scale": return { vector: t.mul(e.live("scale")) };
2720
2824
  case "normalize": return { vector: t.normalize() };
2721
2825
  case "snap": return { vector: A(t.div(n)).mul(n) };
2722
2826
  case "floor": return { vector: A(t) };
2723
- case "ceil": return { vector: y(t) };
2827
+ case "ceil": return { vector: C(t) };
2724
2828
  case "fraction": return { vector: j(t) };
2725
2829
  case "absolute": return { vector: t.abs() };
2726
- case "minimum": return { vector: F(t, n) };
2727
- case "maximum": return { vector: P(t, n) };
2728
- case "sine": return { vector: V(t) };
2729
- case "cosine": return { vector: S(t) };
2730
- case "tangent": return { vector: Ce(t) };
2830
+ case "minimum": return { vector: P(t, n) };
2831
+ case "maximum": return { vector: N(t, n) };
2832
+ case "sine": return { vector: z(t) };
2833
+ case "cosine": return { vector: E(t) };
2834
+ case "tangent": return { vector: ke(t) };
2731
2835
  default: return { vector: t.add(n) };
2732
2836
  }
2733
2837
  }
2734
- }, Ar = 1, jr = {
2838
+ };
2839
+ //#endregion
2840
+ //#region src/tsl/vector-rotate.ts
2841
+ function Br(e, t, n, r) {
2842
+ let i = e.sub(t), a = E(n), o = z(n), s, c, l;
2843
+ return r === 0 ? (s = i.x, c = a.mul(i.y).sub(o.mul(i.z)), l = o.mul(i.y).add(a.mul(i.z))) : r === 1 ? (c = i.y, l = a.mul(i.z).sub(o.mul(i.x)), s = o.mul(i.z).add(a.mul(i.x))) : (l = i.z, s = a.mul(i.x).sub(o.mul(i.y)), c = o.mul(i.x).add(a.mul(i.y))), t.add(K(s, c, l));
2844
+ }
2845
+ //#endregion
2846
+ //#region src/graph/nodes/vector/vector-rotate.ts
2847
+ var Vr = [
2848
+ "x",
2849
+ "y",
2850
+ "z"
2851
+ ], Hr = {
2852
+ type: "vector-rotate",
2853
+ nodeClass: "vector",
2854
+ label: "Vector Rotate",
2855
+ inputs: [
2856
+ {
2857
+ key: "vector",
2858
+ kind: "vector"
2859
+ },
2860
+ {
2861
+ key: "center",
2862
+ kind: "vector"
2863
+ },
2864
+ {
2865
+ key: "angle",
2866
+ kind: "float"
2867
+ }
2868
+ ],
2869
+ outputs: [{
2870
+ key: "vector",
2871
+ kind: "vector"
2872
+ }],
2873
+ params: [{
2874
+ key: "axis",
2875
+ label: "axis",
2876
+ type: "select",
2877
+ options: Vr,
2878
+ default: "z"
2879
+ }, {
2880
+ key: "angle",
2881
+ label: "angle",
2882
+ type: "float",
2883
+ min: -6.283185,
2884
+ max: 6.283185,
2885
+ step: .01,
2886
+ default: 0
2887
+ }],
2888
+ build(e) {
2889
+ return { vector: Br(e.inputs.vector ?? e.coord, e.inputs.center ?? K(0, 0, 0), e.inputs.angle ?? e.live("angle"), Math.max(0, Vr.indexOf(e.constant("axis")))) };
2890
+ }
2891
+ }, Ur = 1, Wr = {
2735
2892
  type: "normal-from-height",
2736
2893
  nodeClass: "vector",
2737
2894
  label: "Normal From Height",
@@ -2755,11 +2912,11 @@ var hr = () => [...ke], gr = {
2755
2912
  }],
2756
2913
  build(e) {
2757
2914
  let t = e.inputs.height ?? k(.5);
2758
- if (e.backend === "live") return { normal: v(t, e.uniforms.strength) };
2759
- let n = t, r = K(), i = T(n).div(T(r.x)), a = E(n).div(E(r.y)), o = e.uniforms.strength, s = q(i, a).mul(o), c = k(Ar), l = s.mul(c.div(s.length().max(c)));
2760
- return { normal: ue(J(l.x.negate(), l.y.negate(), k(1))).mul(.5).add(.5) };
2915
+ if (e.backend === "live") return { normal: S(t, e.live("strength")) };
2916
+ let n = t, r = W(), i = te(n).div(te(r.x)), a = ne(n).div(ne(r.y)), o = e.live("strength"), s = G(i, a).mul(o), c = k(Ur), l = s.mul(c.div(s.length().max(c)));
2917
+ return { normal: ge(K(l.x.negate(), l.y.negate(), k(1))).mul(.5).add(.5) };
2761
2918
  }
2762
- }, Mr = {
2919
+ }, Gr = {
2763
2920
  type: "normal-map",
2764
2921
  nodeClass: "vector",
2765
2922
  label: "Normal Map",
@@ -2786,13 +2943,13 @@ var hr = () => [...ke], gr = {
2786
2943
  default: 1
2787
2944
  }],
2788
2945
  build(e) {
2789
- return { normal: ce(e.inputs.color ?? J(.5, .5, 1), e.inputs.strength ?? e.uniforms.strength) };
2946
+ return { normal: me(e.inputs.color ?? K(.5, .5, 1), e.inputs.strength ?? e.live("strength")) };
2790
2947
  }
2791
2948
  };
2792
2949
  //#endregion
2793
2950
  //#region src/tsl/blender-mapping.ts
2794
- function Nr(e) {
2795
- let t = S(e.x), n = S(e.y), r = S(e.z), i = V(e.x), a = V(e.y), o = V(e.z), s = t.mul(r), c = t.mul(o), l = i.mul(r), u = i.mul(o);
2951
+ function Kr(e) {
2952
+ let t = E(e.x), n = E(e.y), r = E(e.z), i = z(e.x), a = z(e.y), o = z(e.z), s = t.mul(r), c = t.mul(o), l = i.mul(r), u = i.mul(o);
2796
2953
  return {
2797
2954
  m00: n.mul(r),
2798
2955
  m10: a.mul(l).sub(c),
@@ -2805,24 +2962,24 @@ function Nr(e) {
2805
2962
  m22: n.mul(t)
2806
2963
  };
2807
2964
  }
2808
- function Pr(e, t) {
2809
- return J(e.m00.mul(t.x).add(e.m10.mul(t.y)).add(e.m20.mul(t.z)), e.m01.mul(t.x).add(e.m11.mul(t.y)).add(e.m21.mul(t.z)), e.m02.mul(t.x).add(e.m12.mul(t.y)).add(e.m22.mul(t.z)));
2965
+ function qr(e, t) {
2966
+ return K(e.m00.mul(t.x).add(e.m10.mul(t.y)).add(e.m20.mul(t.z)), e.m01.mul(t.x).add(e.m11.mul(t.y)).add(e.m21.mul(t.z)), e.m02.mul(t.x).add(e.m12.mul(t.y)).add(e.m22.mul(t.z)));
2810
2967
  }
2811
- function Fr(e, t) {
2812
- return J(e.m00.mul(t.x).add(e.m01.mul(t.y)).add(e.m02.mul(t.z)), e.m10.mul(t.x).add(e.m11.mul(t.y)).add(e.m12.mul(t.z)), e.m20.mul(t.x).add(e.m21.mul(t.y)).add(e.m22.mul(t.z)));
2968
+ function Jr(e, t) {
2969
+ return K(e.m00.mul(t.x).add(e.m01.mul(t.y)).add(e.m02.mul(t.z)), e.m10.mul(t.x).add(e.m11.mul(t.y)).add(e.m12.mul(t.z)), e.m20.mul(t.x).add(e.m21.mul(t.y)).add(e.m22.mul(t.z)));
2813
2970
  }
2814
- function Ir(e, t, n, r, i) {
2815
- let a = Nr(n);
2816
- return i === 1 ? Fr(a, e.sub(t)).div(r) : i === 2 ? Pr(a, e.mul(r)) : i === 3 ? Pr(a, e.div(r)).normalize() : Pr(a, e.mul(r)).add(t);
2971
+ function Yr(e, t, n, r, i) {
2972
+ let a = Kr(n);
2973
+ return i === 1 ? Jr(a, e.sub(t)).div(r) : i === 2 ? qr(a, e.mul(r)) : i === 3 ? qr(a, e.div(r)).normalize() : qr(a, e.mul(r)).add(t);
2817
2974
  }
2818
2975
  //#endregion
2819
2976
  //#region src/graph/nodes/vector/mapping.ts
2820
- var Lr = [
2977
+ var Xr = [
2821
2978
  "point",
2822
2979
  "texture",
2823
2980
  "vector",
2824
2981
  "normal"
2825
- ], Rr = {
2982
+ ], Zr = {
2826
2983
  type: "mapping",
2827
2984
  nodeClass: "vector",
2828
2985
  label: "Mapping",
@@ -2839,7 +2996,7 @@ var Lr = [
2839
2996
  key: "mappingType",
2840
2997
  label: "type",
2841
2998
  type: "select",
2842
- options: Lr,
2999
+ options: Xr,
2843
3000
  default: "point"
2844
3001
  },
2845
3002
  {
@@ -2874,10 +3031,323 @@ var Lr = [
2874
3031
  }
2875
3032
  ],
2876
3033
  build(e) {
2877
- let t = e.inputs.vector ?? e.coord, n = Math.max(0, Lr.indexOf(e.params.mappingType));
2878
- return { vector: Ir(t, e.uniforms.location, e.uniforms.rotation, e.uniforms.scale, n) };
3034
+ let t = e.inputs.vector ?? e.coord, n = Math.max(0, Xr.indexOf(e.constant("mappingType")));
3035
+ return { vector: Yr(t, e.live("location"), e.live("rotation"), e.live("scale"), n) };
3036
+ }
3037
+ }, Z = {
3038
+ baseColor: {
3039
+ key: "baseColor",
3040
+ label: "Base Color",
3041
+ kind: "color"
3042
+ },
3043
+ metallic: {
3044
+ key: "metallic",
3045
+ label: "Metallic",
3046
+ kind: "float"
3047
+ },
3048
+ roughness: {
3049
+ key: "roughness",
3050
+ label: "Roughness",
3051
+ kind: "float"
3052
+ },
3053
+ ior: {
3054
+ key: "ior",
3055
+ label: "IOR",
3056
+ kind: "float"
3057
+ },
3058
+ alpha: {
3059
+ key: "alpha",
3060
+ label: "Alpha",
3061
+ kind: "float"
3062
+ },
3063
+ normal: {
3064
+ key: "normal",
3065
+ label: "Normal",
3066
+ kind: "vector"
3067
+ },
3068
+ height: {
3069
+ key: "height",
3070
+ label: "Height",
3071
+ kind: "float"
3072
+ },
3073
+ ambientOcclusion: {
3074
+ key: "ambientOcclusion",
3075
+ label: "Ambient Occlusion",
3076
+ kind: "float"
3077
+ },
3078
+ coat: {
3079
+ key: "coat",
3080
+ label: "Coat Weight",
3081
+ kind: "float"
3082
+ },
3083
+ coatRoughness: {
3084
+ key: "coatRoughness",
3085
+ label: "Coat Roughness",
3086
+ kind: "float"
3087
+ },
3088
+ sheen: {
3089
+ key: "sheen",
3090
+ label: "Sheen Weight",
3091
+ kind: "float"
3092
+ },
3093
+ sheenRoughness: {
3094
+ key: "sheenRoughness",
3095
+ label: "Sheen Roughness",
3096
+ kind: "float"
3097
+ },
3098
+ transmission: {
3099
+ key: "transmission",
3100
+ label: "Transmission",
3101
+ kind: "float"
3102
+ },
3103
+ emission: {
3104
+ key: "emission",
3105
+ label: "Emission Color",
3106
+ kind: "color"
3107
+ },
3108
+ emissionStrength: {
3109
+ key: "emissionStrength",
3110
+ label: "Emission Strength",
3111
+ kind: "float"
3112
+ }
3113
+ }, Qr = [
3114
+ Z.baseColor,
3115
+ Z.alpha,
3116
+ Z.normal,
3117
+ Z.height,
3118
+ Z.ambientOcclusion,
3119
+ Z.emission,
3120
+ Z.emissionStrength
3121
+ ], $r = [
3122
+ Z.baseColor,
3123
+ Z.alpha,
3124
+ Z.normal,
3125
+ Z.height
3126
+ ], ei = [Z.metallic, Z.roughness], ti = [
3127
+ Z.ior,
3128
+ Z.coat,
3129
+ Z.coatRoughness,
3130
+ Z.sheen,
3131
+ Z.sheenRoughness,
3132
+ Z.transmission
3133
+ ], ni = [{
3134
+ key: "bsdf",
3135
+ kind: "shader"
3136
+ }], ri = [
3137
+ {
3138
+ key: "materialType",
3139
+ label: "type",
3140
+ type: "select",
3141
+ options: Re,
3142
+ default: "physical"
3143
+ },
3144
+ {
3145
+ key: "baseColor",
3146
+ label: "base color",
3147
+ type: "color",
3148
+ default: "#cccccc"
3149
+ },
3150
+ {
3151
+ key: "metallic",
3152
+ label: "metallic",
3153
+ type: "float",
3154
+ min: 0,
3155
+ max: 1,
3156
+ step: .01,
3157
+ default: 0
3158
+ },
3159
+ {
3160
+ key: "roughness",
3161
+ label: "roughness",
3162
+ type: "float",
3163
+ min: 0,
3164
+ max: 1,
3165
+ step: .01,
3166
+ default: .5
3167
+ },
3168
+ {
3169
+ key: "ior",
3170
+ label: "IOR",
3171
+ type: "float",
3172
+ min: 1,
3173
+ max: 2.5,
3174
+ step: .01,
3175
+ default: 1.5
3176
+ },
3177
+ {
3178
+ key: "alpha",
3179
+ label: "alpha",
3180
+ type: "float",
3181
+ min: 0,
3182
+ max: 1,
3183
+ step: .01,
3184
+ default: 1,
3185
+ bakeStructural: !0
3186
+ },
3187
+ {
3188
+ key: "coat",
3189
+ label: "coat weight",
3190
+ type: "float",
3191
+ min: 0,
3192
+ max: 1,
3193
+ step: .01,
3194
+ default: 0
3195
+ },
3196
+ {
3197
+ key: "coatRoughness",
3198
+ label: "coat rough",
3199
+ type: "float",
3200
+ min: 0,
3201
+ max: 1,
3202
+ step: .01,
3203
+ default: .03
3204
+ },
3205
+ {
3206
+ key: "sheen",
3207
+ label: "sheen weight",
3208
+ type: "float",
3209
+ min: 0,
3210
+ max: 1,
3211
+ step: .01,
3212
+ default: 0
3213
+ },
3214
+ {
3215
+ key: "sheenRoughness",
3216
+ label: "sheen rough",
3217
+ type: "float",
3218
+ min: 0,
3219
+ max: 1,
3220
+ step: .01,
3221
+ default: .3
3222
+ },
3223
+ {
3224
+ key: "transmission",
3225
+ label: "transmission",
3226
+ type: "float",
3227
+ min: 0,
3228
+ max: 1,
3229
+ step: .01,
3230
+ default: 0
3231
+ },
3232
+ {
3233
+ key: "emission",
3234
+ label: "emission",
3235
+ type: "color",
3236
+ default: "#000000",
3237
+ bakeStructural: !0
3238
+ },
3239
+ {
3240
+ key: "emissionStrength",
3241
+ label: "emission str",
3242
+ type: "float",
3243
+ min: 0,
3244
+ max: 10,
3245
+ step: .1,
3246
+ default: 1
3247
+ },
3248
+ {
3249
+ key: "shininess",
3250
+ label: "shininess",
3251
+ type: "float",
3252
+ min: 1,
3253
+ max: 200,
3254
+ step: 1,
3255
+ default: 30,
3256
+ structural: !0
3257
+ },
3258
+ {
3259
+ key: "specular",
3260
+ label: "specular",
3261
+ type: "color",
3262
+ default: "#111111",
3263
+ structural: !0
3264
+ },
3265
+ {
3266
+ key: "gradientSteps",
3267
+ label: "gradient steps",
3268
+ type: "int",
3269
+ min: 2,
3270
+ max: 5,
3271
+ step: 1,
3272
+ default: 3
3273
+ },
3274
+ {
3275
+ key: "matcap",
3276
+ label: "matcap",
3277
+ type: "select",
3278
+ options: ["default"],
3279
+ default: "default"
3280
+ }
3281
+ ], ii = Object.fromEntries(ri.filter((e) => e.type === "float" || e.type === "int").map((e) => [e.key, e.default]));
3282
+ function ai(e) {
3283
+ let t = Be(e.materialType), n = new Set([
3284
+ "materialType",
3285
+ "baseColor",
3286
+ "alpha",
3287
+ "emission",
3288
+ "emissionStrength"
3289
+ ]);
3290
+ if ((t === "standard" || t === "physical") && (n.add("metallic"), n.add("roughness")), t === "physical") for (let e of [
3291
+ "ior",
3292
+ "coat",
3293
+ "coatRoughness",
3294
+ "sheen",
3295
+ "sheenRoughness",
3296
+ "transmission"
3297
+ ]) n.add(e);
3298
+ return t === "phong" && (n.add("shininess"), n.add("specular")), t === "toon" && n.add("gradientSteps"), t === "matcap" && (n.delete("emission"), n.delete("emissionStrength"), n.add("matcap")), ri.filter((e) => n.has(e.key));
3299
+ }
3300
+ var oi = {
3301
+ type: We,
3302
+ nodeClass: "shader",
3303
+ label: "Material",
3304
+ inputs: [
3305
+ ...Qr,
3306
+ ...ei,
3307
+ ...ti
3308
+ ],
3309
+ outputs: ni,
3310
+ params: ri,
3311
+ declare(e) {
3312
+ switch (Be(e.materialType)) {
3313
+ case "standard": return {
3314
+ inputs: [...Qr, ...ei],
3315
+ outputs: ni
3316
+ };
3317
+ case "physical": return {
3318
+ inputs: [
3319
+ ...Qr,
3320
+ ...ei,
3321
+ ...ti
3322
+ ],
3323
+ outputs: ni
3324
+ };
3325
+ case "matcap": return {
3326
+ inputs: $r,
3327
+ outputs: ni
3328
+ };
3329
+ default: return {
3330
+ inputs: Qr,
3331
+ outputs: ni
3332
+ };
3333
+ }
3334
+ },
3335
+ paramsFor: ai,
3336
+ build(e) {
3337
+ let t = ze[Be(e.constant("materialType"))], n = (t) => e.inputs[t] ?? e.live(t), r = (t) => Number(e.constant(t) ?? ii[t] ?? 0), i = (t) => e.inputs[t] === void 0 ? r(t) > 0 ? e.live(t) : void 0 : e.inputs[t], a = e.inputs.emission !== void 0 || e.inputs.emissionStrength !== void 0 || (e.constant("emission") ?? "#000000") !== "#000000", o = t.emissive && a ? (e.inputs.emission ?? e.live("emission")).mul(e.inputs.emissionStrength ?? e.live("emissionStrength")) : void 0, s = {
3338
+ baseColor: n("baseColor"),
3339
+ normal: e.inputs.normal,
3340
+ height: e.inputs.height,
3341
+ alpha: e.inputs.alpha === void 0 ? r("alpha") < 1 ? e.live("alpha") : void 0 : e.inputs.alpha,
3342
+ emission: o
3343
+ };
3344
+ if (t.ao && (s.ambientOcclusion = e.inputs.ambientOcclusion), t.roughMetal && (s.roughness = n("roughness"), s.metallic = n("metallic")), t.physicalLobes) {
3345
+ let e = i("coat"), t = i("sheen");
3346
+ s.ior = n("ior"), s.coat = e, s.coatRoughness = e === void 0 ? void 0 : n("coatRoughness"), s.sheen = t, s.sheenRoughness = t === void 0 ? void 0 : n("sheenRoughness"), s.transmission = i("transmission");
3347
+ }
3348
+ return { bsdf: s };
2879
3349
  }
2880
- }, zr = [
3350
+ }, si = [
2881
3351
  {
2882
3352
  key: "baseColor",
2883
3353
  label: "base color",
@@ -2982,7 +3452,7 @@ var Lr = [
2982
3452
  step: .1,
2983
3453
  default: 1
2984
3454
  }
2985
- ], Br = Object.fromEntries(zr.filter((e) => e.type === "float" || e.type === "int").map((e) => [e.key, e.default])), Vr = {
3455
+ ], ci = Object.fromEntries(si.filter((e) => e.type === "float" || e.type === "int").map((e) => [e.key, e.default])), li = {
2986
3456
  type: "principled-bsdf",
2987
3457
  nodeClass: "shader",
2988
3458
  label: "Principled BSDF",
@@ -3067,27 +3537,27 @@ var Lr = [
3067
3537
  key: "bsdf",
3068
3538
  kind: "shader"
3069
3539
  }],
3070
- params: zr,
3540
+ params: si,
3071
3541
  build(e) {
3072
- let t = e.uniforms, n = (n) => e.inputs[n] ?? t[n], r = (t) => Number(e.params[t] ?? Br[t] ?? 0), i = (n) => e.inputs[n] === void 0 ? r(n) > 0 ? t[n] : void 0 : e.inputs[n], a = e.inputs.emission !== void 0 || e.inputs.emissionStrength !== void 0 || (e.params.emission ?? "#000000") !== "#000000" ? (e.inputs.emission ?? t.emission).mul(e.inputs.emissionStrength ?? t.emissionStrength) : void 0, o = i("coat"), s = i("sheen");
3542
+ let t = (t) => e.inputs[t] ?? e.live(t), n = (t) => Number(e.constant(t) ?? ci[t] ?? 0), r = (t) => e.inputs[t] === void 0 ? n(t) > 0 ? e.live(t) : void 0 : e.inputs[t], i = e.inputs.emission !== void 0 || e.inputs.emissionStrength !== void 0 || (e.constant("emission") ?? "#000000") !== "#000000" ? (e.inputs.emission ?? e.live("emission")).mul(e.inputs.emissionStrength ?? e.live("emissionStrength")) : void 0, a = r("coat"), o = r("sheen");
3073
3543
  return { bsdf: {
3074
- baseColor: n("baseColor"),
3075
- metallic: n("metallic"),
3076
- roughness: n("roughness"),
3077
- ior: n("ior"),
3544
+ baseColor: t("baseColor"),
3545
+ metallic: t("metallic"),
3546
+ roughness: t("roughness"),
3547
+ ior: t("ior"),
3078
3548
  normal: e.inputs.normal,
3079
3549
  height: e.inputs.height,
3080
3550
  ambientOcclusion: e.inputs.ambientOcclusion,
3081
- alpha: e.inputs.alpha === void 0 ? r("alpha") < 1 ? t.alpha : void 0 : e.inputs.alpha,
3082
- emission: a,
3083
- coat: o,
3084
- coatRoughness: o === void 0 ? void 0 : n("coatRoughness"),
3085
- sheen: s,
3086
- sheenRoughness: s === void 0 ? void 0 : n("sheenRoughness"),
3087
- transmission: i("transmission")
3551
+ alpha: e.inputs.alpha === void 0 ? n("alpha") < 1 ? e.live("alpha") : void 0 : e.inputs.alpha,
3552
+ emission: i,
3553
+ coat: a,
3554
+ coatRoughness: a === void 0 ? void 0 : t("coatRoughness"),
3555
+ sheen: o,
3556
+ sheenRoughness: o === void 0 ? void 0 : t("sheenRoughness"),
3557
+ transmission: r("transmission")
3088
3558
  } };
3089
3559
  }
3090
- }, Hr = {
3560
+ }, ui = {
3091
3561
  type: "emission",
3092
3562
  nodeClass: "shader",
3093
3563
  label: "Emission",
@@ -3119,22 +3589,22 @@ var Lr = [
3119
3589
  default: 1
3120
3590
  }],
3121
3591
  build(e) {
3122
- let t = e.inputs.color ?? e.uniforms.color, n = e.inputs.strength ?? e.uniforms.strength;
3592
+ let t = e.inputs.color ?? e.live("color"), n = e.inputs.strength ?? e.live("strength");
3123
3593
  return { bsdf: {
3124
- baseColor: J(0),
3594
+ baseColor: K(0),
3125
3595
  roughness: k(1),
3126
3596
  metallic: k(0),
3127
3597
  emission: t.mul(n)
3128
3598
  } };
3129
3599
  }
3130
- }, Ur = {
3131
- emission: J(0, 0, 0),
3600
+ }, di = {
3601
+ emission: K(0, 0, 0),
3132
3602
  ambientOcclusion: k(1),
3133
3603
  alpha: k(1),
3134
3604
  coat: k(0),
3135
3605
  sheen: k(0),
3136
3606
  transmission: k(0)
3137
- }, Wr = [
3607
+ }, fi = [
3138
3608
  "baseColor",
3139
3609
  "metallic",
3140
3610
  "roughness",
@@ -3149,21 +3619,21 @@ var Lr = [
3149
3619
  "sheenRoughness",
3150
3620
  "transmission"
3151
3621
  ];
3152
- function Gr(e, t, n) {
3622
+ function pi(e, t, n) {
3153
3623
  let r = {};
3154
- for (let i of Wr) {
3624
+ for (let i of fi) {
3155
3625
  let a = e[i], o = t[i];
3156
3626
  if (a === void 0 && o === void 0) continue;
3157
3627
  if (a !== void 0 && o !== void 0) {
3158
- r[i] = I(a, o, n);
3628
+ r[i] = F(a, o, n);
3159
3629
  continue;
3160
3630
  }
3161
- let s = Ur[i];
3162
- s === void 0 ? r[i] = a ?? o : r[i] = a === void 0 ? I(s, o, n) : I(a, s, n);
3631
+ let s = di[i];
3632
+ s === void 0 ? r[i] = a ?? o : r[i] = a === void 0 ? F(s, o, n) : F(a, s, n);
3163
3633
  }
3164
3634
  return r;
3165
3635
  }
3166
- var Kr = {
3636
+ var mi = {
3167
3637
  type: "mix-shader",
3168
3638
  nodeClass: "shader",
3169
3639
  label: "Mix Shader",
@@ -3198,9 +3668,9 @@ var Kr = {
3198
3668
  default: .5
3199
3669
  }],
3200
3670
  build(e) {
3201
- return { shader: Gr(e.inputs.shaderA ?? {}, e.inputs.shaderB ?? {}, e.inputs.fac ?? e.uniforms.fac) };
3671
+ return { shader: pi(e.inputs.shaderA ?? {}, e.inputs.shaderB ?? {}, e.inputs.fac ?? e.live("fac")) };
3202
3672
  }
3203
- }, qr = {
3673
+ }, hi = {
3204
3674
  type: "material-output",
3205
3675
  nodeClass: "output",
3206
3676
  label: "Material Output",
@@ -3227,7 +3697,7 @@ var Kr = {
3227
3697
  build() {
3228
3698
  return {};
3229
3699
  }
3230
- }, Jr = {
3700
+ }, gi = {
3231
3701
  type: "group",
3232
3702
  nodeClass: "group",
3233
3703
  label: "Group",
@@ -3237,7 +3707,7 @@ var Kr = {
3237
3707
  build() {
3238
3708
  return {};
3239
3709
  }
3240
- }, Yr = {
3710
+ }, _i = {
3241
3711
  type: "group-input",
3242
3712
  nodeClass: "input",
3243
3713
  label: "Group Input",
@@ -3247,7 +3717,7 @@ var Kr = {
3247
3717
  build() {
3248
3718
  return {};
3249
3719
  }
3250
- }, Xr = {
3720
+ }, vi = {
3251
3721
  type: "group-output",
3252
3722
  nodeClass: "output",
3253
3723
  label: "Group Output",
@@ -3268,11 +3738,11 @@ function Q(e, t) {
3268
3738
  outputs: n.outputs
3269
3739
  };
3270
3740
  }
3271
- function Zr(e, t) {
3741
+ function yi(e, t) {
3272
3742
  let n = t.get(e.type);
3273
3743
  return n.paramsFor ? n.paramsFor(e.params) : n.params;
3274
3744
  }
3275
- var Qr = class {
3745
+ var bi = class {
3276
3746
  defs = /* @__PURE__ */ new Map();
3277
3747
  register(e) {
3278
3748
  if (this.defs.has(e.type)) throw Error(`Duplicate node type: ${e.type}`);
@@ -3290,11 +3760,25 @@ var Qr = class {
3290
3760
  return [...this.defs.values()];
3291
3761
  }
3292
3762
  };
3293
- function $r() {
3294
- return new Qr().register(Je).register(Ye).register(At).register(Bt).register(Vt).register(yn).register(bn).register(wn).register(Dn).register(An).register(Pn).register(Gn).register(qn).register($n).register(rr).register(ir).register(ar).register(or).register(sr).register(cr).register(fr).register(gr).register(_r).register(vr).register(yr).register(br).register(xr).register(Sr).register(Cr).register(wr).register(Tr).register(kr).register(jr).register(Mr).register(Rr).register(Vr).register(Hr).register(Kr).register(qr).register(Jr).register(Yr).register(Xr);
3763
+ function xi() {
3764
+ return new bi().register(it).register(at).register(Bt).register(Xt).register(Zt).register(kn).register(An).register(Pn).register(Ln).register(Bn).register(Wn).register(tr).register(rr).register(lr).register(pr).register(mr).register(hr).register(gr).register(_r).register(vr).register(Sr).register(Er).register(Dr).register(Or).register(kr).register(Ar).register(jr).register(Mr).register(Nr).register(Pr).register(Fr).register(zr).register(Hr).register(Wr).register(Gr).register(Zr).register(oi).register(li).register(ui).register(mi).register(hi).register(gi).register(_i).register(vi);
3765
+ }
3766
+ var Si = xi(), Ci = /* @__PURE__ */ new Map();
3767
+ function wi(t) {
3768
+ let n = Math.max(2, Math.min(5, Math.round(t ?? 3))), r = Ci.get(n);
3769
+ if (r) return r;
3770
+ let i = new Uint8Array(n);
3771
+ for (let e = 0; e < n; e++) i[e] = Math.round(e / (n - 1) * 255);
3772
+ let a = new e.DataTexture(i, n, 1, e.RedFormat);
3773
+ return a.minFilter = e.NearestFilter, a.magFilter = e.NearestFilter, a.needsUpdate = !0, Ci.set(n, a), a;
3295
3774
  }
3296
- var ei = $r(), ti = 2048;
3297
- function ni(e, t, n) {
3775
+ function Ti(e) {
3776
+ return null;
3777
+ }
3778
+ //#endregion
3779
+ //#region src/graph/compiler.ts
3780
+ var Ei = 2048;
3781
+ function Di(e, t, n) {
3298
3782
  let r = new Map(t.nodes.map((e) => [e.id, e])), i = /* @__PURE__ */ new Set(), a = [e];
3299
3783
  for (; a.length;) {
3300
3784
  let e = a.pop();
@@ -3308,11 +3792,11 @@ function ni(e, t, n) {
3308
3792
  }
3309
3793
  return !1;
3310
3794
  }
3311
- function ri(e, t) {
3795
+ function Oi(e, t) {
3312
3796
  let n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map(), o = (e) => {
3313
3797
  let t = a.get(e);
3314
3798
  return t || (t = new Map(e.nodes.map((e) => [e.id, e])), a.set(e, t)), t;
3315
- }, s = (e) => e.nodes.find((e) => e.type === Ne)?.id, c = (e, t, r, i) => {
3799
+ }, s = (e) => e.nodes.find((e) => e.type === He)?.id, c = (e, t, r, i) => {
3316
3800
  if (t === s(e)) {
3317
3801
  i(r);
3318
3802
  return;
@@ -3336,7 +3820,7 @@ function ri(e, t) {
3336
3820
  i.add(a);
3337
3821
  let o = e.subgraph;
3338
3822
  if (!o) return;
3339
- let s = o.nodes.find((e) => e.type === Pe), l = s && o.edges.find((e) => e.toNode === s.id && e.toInput === t);
3823
+ let s = o.nodes.find((e) => e.type === Ue), l = s && o.edges.find((e) => e.toNode === s.id && e.toInput === t);
3340
3824
  l && c(o, l.fromNode, l.fromOutput, (t) => {
3341
3825
  for (let i of n.edges) i.toNode === e.id && i.toInput === t && c(n, i.fromNode, i.fromOutput, r);
3342
3826
  });
@@ -3347,25 +3831,70 @@ function ri(e, t) {
3347
3831
  };
3348
3832
  return d(e, () => {}), n;
3349
3833
  }
3350
- function ii(e, t) {
3351
- return t === "float" ? J(e) : e;
3834
+ function ki(e, t) {
3835
+ return t === "float" ? K(e) : e;
3352
3836
  }
3353
- function ai(e, t) {
3354
- let n = U(e, K());
3837
+ function Ai(e, t) {
3838
+ let n = V(e, W());
3355
3839
  return t === "float" ? n.r : n.xyz;
3356
3840
  }
3357
- function oi(e) {
3358
- let t = e.nodes.find((e) => e.type === Fe)?.params?.outputResolution, n = typeof t == "string" ? Number(t) : typeof t == "number" ? t : NaN;
3841
+ function ji(e) {
3842
+ let t = e.nodes.find((e) => e.type === q)?.params?.outputResolution, n = typeof t == "string" ? Number(t) : typeof t == "number" ? t : NaN;
3359
3843
  return Number.isFinite(n) && n > 0 ? n : 1024;
3360
3844
  }
3361
- function si(e, t, n) {
3845
+ function Mi(e) {
3846
+ let t = e.nodes.find((e) => e.type === q), n = t && e.edges.find((e) => e.toNode === t.id && e.toInput === "surface"), r = n && e.nodes.find((e) => e.id === n.fromNode);
3847
+ if (!r || r.type !== "shader-material") return {
3848
+ type: "physical",
3849
+ settings: {}
3850
+ };
3851
+ let i = r.params, a = (e, t) => {
3852
+ let n = Number(e);
3853
+ return Number.isFinite(n) ? n : t;
3854
+ };
3855
+ return {
3856
+ type: Be(i.materialType),
3857
+ settings: {
3858
+ shininess: a(i.shininess, 30),
3859
+ specular: typeof i.specular == "string" ? i.specular : "#111111",
3860
+ gradientSteps: a(i.gradientSteps, 3),
3861
+ matcap: typeof i.matcap == "string" ? i.matcap : "default"
3862
+ }
3863
+ };
3864
+ }
3865
+ function Ni(e) {
3866
+ let t = e.nodes.find((e) => e.type === q), n = t && e.edges.find((e) => e.toNode === t.id && e.toInput === "surface"), r = n && e.nodes.find((e) => e.id === n.fromNode), i = r && r.type === "shader-material" ? r.params : {}, a = (e, t) => {
3867
+ let n = Number(e);
3868
+ return Number.isFinite(n) ? n : t;
3869
+ }, o = (e, t) => typeof e == "string" ? e : t;
3870
+ return {
3871
+ type: Be(i.materialType),
3872
+ baseColor: o(i.baseColor, "#cccccc"),
3873
+ metallic: a(i.metallic, 0),
3874
+ roughness: a(i.roughness, .5),
3875
+ ior: a(i.ior, 1.5),
3876
+ alpha: a(i.alpha, 1),
3877
+ coat: a(i.coat, 0),
3878
+ coatRoughness: a(i.coatRoughness, .03),
3879
+ sheen: a(i.sheen, 0),
3880
+ sheenRoughness: a(i.sheenRoughness, .3),
3881
+ transmission: a(i.transmission, 0),
3882
+ emission: o(i.emission, "#000000"),
3883
+ emissionStrength: a(i.emissionStrength, 1),
3884
+ shininess: a(i.shininess, 30),
3885
+ specular: o(i.specular, "#111111"),
3886
+ gradientSteps: a(i.gradientSteps, 3),
3887
+ matcap: o(i.matcap, "default")
3888
+ };
3889
+ }
3890
+ function Pi(e, t, n) {
3362
3891
  if (n.backend === "live" || !n.allocCache || !t.bakeTileable) return 1;
3363
3892
  let r = e.params.tileSize, i = typeof r == "string" && r !== "off" ? Number(r) : NaN;
3364
3893
  if (!Number.isFinite(i) || i <= 0) return 1;
3365
3894
  let a = n.outputResolution ?? 1024, o = Math.max(1, Math.round(Number(e.params.scale) || 1));
3366
3895
  return Math.max(1, Math.min(Math.round(a / i), o));
3367
3896
  }
3368
- function ci(e, t, n, r, i, a) {
3897
+ function Fi(e, t, n, r, i, a) {
3369
3898
  if (r.backend === "live" || !r.allocCache || !t.bakeTileable || n.vector !== void 0 || n.field === void 0) return;
3370
3899
  let o = e.params.tileSize, s = typeof o == "string" && o !== "off" ? Number(o) : NaN;
3371
3900
  if (!Number.isFinite(s) || s <= 0) return;
@@ -3373,63 +3902,58 @@ function ci(e, t, n, r, i, a) {
3373
3902
  return i.push({
3374
3903
  cacheId: c,
3375
3904
  kind: "float",
3376
- colorNode: ii(n.field, "float"),
3905
+ colorNode: ki(n.field, "float"),
3377
3906
  sizing: { size: s }
3378
- }), { field: U(l, K().mul(k(a))).r };
3907
+ }), { field: V(l, W().mul(k(a))).r };
3379
3908
  }
3380
- function li(e) {
3909
+ function Ii(e) {
3381
3910
  let t = 0;
3382
- for (let n of e.nodes) t += 1, n.type === "group" && n.subgraph && (t += li(n.subgraph));
3911
+ for (let n of e.nodes) t += 1, n.type === "group" && n.subgraph && (t += Ii(n.subgraph));
3383
3912
  return t;
3384
3913
  }
3385
- function ui(e, t, n) {
3914
+ function Li(e, t, n) {
3386
3915
  let r = {
3387
3916
  ...n,
3388
- outputResolution: n.outputResolution ?? oi(e)
3389
- }, i = r.backend === "live" ? pe : J(K().x, K().y, k(0)), a = r.soloNodeId ? { id: r.soloNodeId } : void 0, o = [], { outputs: s, uniforms: c } = fi(e, t, r, i, o, r.allocCache ? ri(e, t) : /* @__PURE__ */ new Set(), void 0, a);
3917
+ outputResolution: n.outputResolution ?? ji(e)
3918
+ }, i = r.backend === "live" ? ye : K(W().x, W().y, k(0)), a = r.soloNodeId ? { id: r.soloNodeId } : void 0, o = [], { outputs: s, uniforms: c, usage: l } = zi(e, t, r, i, o, r.allocCache ? Oi(e, t) : /* @__PURE__ */ new Set(), void 0, a);
3390
3919
  return {
3391
- bundle: a && a.value !== void 0 && a.kind && a.kind !== "shader" ? di(a.value, a.kind) : xi(e, t, s),
3920
+ bundle: a && a.value !== void 0 && a.kind && a.kind !== "shader" ? Ri(a.value, a.kind) : Xi(e, t, s),
3392
3921
  uniforms: c,
3393
- cachePlan: o
3922
+ cachePlan: o,
3923
+ paramUsage: l
3394
3924
  };
3395
3925
  }
3396
- function di(e, t) {
3926
+ function Ri(e, t) {
3397
3927
  return {
3398
- baseColor: t === "float" ? J(e) : e,
3928
+ baseColor: t === "float" ? K(e) : e,
3399
3929
  roughness: k(1),
3400
3930
  metallic: k(0)
3401
3931
  };
3402
3932
  }
3403
- function fi(e, t, n, r, i, a, o, s) {
3404
- Ci(e, t, o !== void 0);
3405
- let c = Si(e), l = new Map(e.nodes.map((e) => [e.id, e])), u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map();
3406
- for (let f of c) {
3407
- let c = l.get(f);
3933
+ function zi(e, t, n, r, i, a, o, s) {
3934
+ Qi(e, t, o !== void 0);
3935
+ let c = Zi(e), l = new Map(e.nodes.map((e) => [e.id, e])), u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
3936
+ for (let p of c) {
3937
+ let c = l.get(p);
3408
3938
  if (!c) continue;
3409
- let p = Q(c, t);
3939
+ let m = Q(c, t);
3410
3940
  if (c.type === "group-input") {
3411
3941
  let e = {};
3412
- for (let t of p.outputs) e[t.key] = o?.[t.key];
3413
- u.set(f, e);
3942
+ for (let t of m.outputs) e[t.key] = o?.[t.key];
3943
+ u.set(p, e);
3414
3944
  continue;
3415
3945
  }
3416
3946
  if (c.type === "group") {
3417
- let o = pi(c, t, n, r, i, a, _i(c, e, u, l, t), s);
3418
- u.set(f, o.outputs);
3947
+ let o = Vi(c, t, n, r, i, a, Ki(c, e, u, l, t), s);
3948
+ u.set(p, o.outputs);
3419
3949
  for (let [e, t] of o.uniforms) d.set(e, t);
3950
+ for (let [e, t] of o.usage) f.set(e, t);
3420
3951
  continue;
3421
3952
  }
3422
- let m = _i(c, e, u, l, t), h = t.get(c.type), g = bi(h, c);
3423
- d.set(f, g);
3424
- let _ = si(c, h, n), v = {
3425
- inputs: m,
3426
- uniforms: g,
3427
- params: c.params,
3428
- coord: r,
3429
- backend: n.backend,
3430
- tileRepeat: _
3431
- }, y = h.build(v);
3432
- u.set(f, ci(c, h, y, n, i, _) ?? y);
3953
+ let h = Ki(c, e, u, l, t), g = t.get(c.type), _ = Yi(g, c);
3954
+ d.set(p, _);
3955
+ let v = Pi(c, g, n), y = Bi(p, c, g, h, _, r, n, v, f), b = g.build(y);
3956
+ u.set(p, Fi(c, g, b, n, i, v) ?? b);
3433
3957
  }
3434
3958
  if (s && s.value === void 0) {
3435
3959
  let e = l.get(s.id), n = e ? Q(e, t).outputs[0] : void 0;
@@ -3437,114 +3961,174 @@ function fi(e, t, n, r, i, a, o, s) {
3437
3961
  }
3438
3962
  return {
3439
3963
  outputs: u,
3440
- uniforms: d
3964
+ uniforms: d,
3965
+ usage: f
3441
3966
  };
3442
3967
  }
3443
- function pi(e, t, n, r, i, a, o, s) {
3968
+ function Bi(t, n, r, i, a, o, s, c, l) {
3969
+ let u = {};
3970
+ l.set(t, u);
3971
+ let d = n.params, f = (e) => r.params.find((t) => t.key === e)?.default;
3972
+ return {
3973
+ inputs: i,
3974
+ coord: o,
3975
+ backend: s.backend,
3976
+ tileRepeat: c,
3977
+ live(e) {
3978
+ return u[e] !== "constant" && (u[e] = "live"), a[e];
3979
+ },
3980
+ constant(e) {
3981
+ return u[e] = "constant", d[e] ?? f(e);
3982
+ },
3983
+ constantArray(n, r, i = "float") {
3984
+ u[n] = "constant";
3985
+ let a = r();
3986
+ if (s.allocConstantArray) return s.allocConstantArray(t, n, a, i);
3987
+ if (i === "vec3") {
3988
+ let t = [];
3989
+ for (let n = 0; n < a.length; n += 3) t.push(new e.Vector3(a[n], a[n + 1], a[n + 2]));
3990
+ return Me(t);
3991
+ }
3992
+ return Me(Array.from(a), "float");
3993
+ }
3994
+ };
3995
+ }
3996
+ function Vi(e, t, n, r, i, a, o, s) {
3444
3997
  let c = e.subgraph;
3445
3998
  if (!c) return {
3446
3999
  outputs: {},
3447
- uniforms: /* @__PURE__ */ new Map()
4000
+ uniforms: /* @__PURE__ */ new Map(),
4001
+ usage: /* @__PURE__ */ new Map()
3448
4002
  };
3449
- let { outputs: l, uniforms: u } = fi(c, t, n, r, i, a, o, s), d = c.nodes.find((e) => e.type === Pe), f = {};
3450
- if (!d) return {
3451
- outputs: f,
3452
- uniforms: u
4003
+ let { outputs: l, uniforms: u, usage: d } = zi(c, t, n, r, i, a, o, s), f = c.nodes.find((e) => e.type === Ue), p = {};
4004
+ if (!f) return {
4005
+ outputs: p,
4006
+ uniforms: u,
4007
+ usage: d
3453
4008
  };
3454
- let p = new Map(c.nodes.map((e) => [e.id, e]));
3455
- for (let r of Q(d, t).inputs) {
3456
- let o = c.edges.find((e) => e.toNode === d.id && e.toInput === r.key), u = o ? vi(o, r.kind, l, p, t) : void 0;
4009
+ let m = new Map(c.nodes.map((e) => [e.id, e]));
4010
+ for (let r of Q(f, t).inputs) {
4011
+ let o = c.edges.find((e) => e.toNode === f.id && e.toInput === r.key), u = o ? qi(o, r.kind, l, m, t) : void 0;
3457
4012
  if (n.allocCache && u !== void 0 && r.kind !== "shader" && !s) {
3458
- let s = `${e.id}/${r.key}`, l = o && ni(o.fromNode, c, t) || a.has(s) ? { minSize: ti } : void 0, d = n.allocCache(s, r.kind, l);
4013
+ let s = `${e.id}/${r.key}`, l = o && Di(o.fromNode, c, t) || a.has(s) ? { minSize: Ei } : void 0, d = n.allocCache(s, r.kind, l);
3459
4014
  i.push({
3460
4015
  cacheId: s,
3461
4016
  kind: r.kind,
3462
- colorNode: ii(u, r.kind),
4017
+ colorNode: ki(u, r.kind),
3463
4018
  sizing: l
3464
- }), f[r.key] = ai(d, r.kind);
3465
- } else f[r.key] = u;
4019
+ }), p[r.key] = Ai(d, r.kind);
4020
+ } else p[r.key] = u;
3466
4021
  }
3467
4022
  return {
3468
- outputs: f,
3469
- uniforms: u
4023
+ outputs: p,
4024
+ uniforms: u,
4025
+ usage: d
3470
4026
  };
3471
4027
  }
3472
- function mi() {
3473
- return new c({
3474
- metalness: 0,
3475
- roughness: .9,
3476
- side: e.DoubleSide,
3477
- polygonOffset: !0,
3478
- polygonOffsetFactor: 1,
3479
- polygonOffsetUnits: 1
3480
- });
4028
+ var Hi = {
4029
+ side: e.DoubleSide,
4030
+ polygonOffset: !0,
4031
+ polygonOffsetFactor: 1,
4032
+ polygonOffsetUnits: 1
4033
+ };
4034
+ function Ui(t = "physical", n = {}) {
4035
+ switch (t) {
4036
+ case "standard": return new d({
4037
+ metalness: 0,
4038
+ roughness: .9,
4039
+ ...Hi
4040
+ });
4041
+ case "lambert": return new s({ ...Hi });
4042
+ case "phong": return new l({
4043
+ shininess: n.shininess ?? 30,
4044
+ specular: new e.Color(n.specular ?? "#111111"),
4045
+ ...Hi
4046
+ });
4047
+ case "toon": return new f({
4048
+ gradientMap: wi(n.gradientSteps),
4049
+ ...Hi
4050
+ });
4051
+ case "matcap": return new c({
4052
+ matcap: Ti(n.matcap),
4053
+ ...Hi
4054
+ });
4055
+ default: return new u({
4056
+ metalness: 0,
4057
+ roughness: .9,
4058
+ ...Hi
4059
+ });
4060
+ }
3481
4061
  }
3482
- function hi(e, t) {
3483
- let n = g("vertexAo", "float");
3484
- e.aoNode = t.ambientOcclusion ? t.ambientOcclusion.mul(n) : n, t.baseColor && (e.colorNode = t.baseColor), t.emission && (e.emissiveNode = t.emission), t.roughness && (e.roughnessNode = t.roughness), t.metallic && (e.metalnessNode = t.metallic), t.normal && (e.normalNode = t.normal), t.ior && (e.iorNode = t.ior), t.alpha && (e.opacityNode = t.alpha, e.transparent = !0), t.coat && (e.clearcoatNode = t.coat), t.coatRoughness && (e.clearcoatRoughnessNode = t.coatRoughness), t.sheen && (e.sheenNode = t.sheen), t.sheenRoughness && (e.sheenRoughnessNode = t.sheenRoughness), t.transmission && (e.transmissionNode = t.transmission);
4062
+ function Wi(e, t, n) {
4063
+ let r = ze[n], i = e;
4064
+ if (t.baseColor && (i.colorNode = t.baseColor), t.normal && (i.normalNode = t.normal), t.alpha && (i.opacityNode = t.alpha, i.transparent = !0), r.ao) {
4065
+ let e = b("vertexAo", "float");
4066
+ i.aoNode = t.ambientOcclusion ? t.ambientOcclusion.mul(e) : e;
4067
+ }
4068
+ r.emissive && t.emission && (i.emissiveNode = t.emission), r.roughMetal && (t.roughness && (i.roughnessNode = t.roughness), t.metallic && (i.metalnessNode = t.metallic)), r.physicalLobes && (t.ior && (i.iorNode = t.ior), t.coat && (i.clearcoatNode = t.coat), t.coatRoughness && (i.clearcoatRoughnessNode = t.coatRoughness), t.sheen && (i.sheenNode = t.sheen), t.sheenRoughness && (i.sheenRoughnessNode = t.sheenRoughness), t.transmission && (i.transmissionNode = t.transmission));
3485
4069
  }
3486
- function gi(e, t, n) {
3487
- let { bundle: r, uniforms: i } = ui(e, t, n), a = mi();
3488
- return hi(a, r), {
3489
- material: a,
4070
+ function Gi(e, t, n) {
4071
+ let { bundle: r, uniforms: i } = Li(e, t, n), { type: a, settings: o } = Mi(e), s = Ui(a, o);
4072
+ return Wi(s, r, a), {
4073
+ material: s,
3490
4074
  uniforms: i
3491
4075
  };
3492
4076
  }
3493
- function _i(e, t, n, r, i) {
4077
+ function Ki(e, t, n, r, i) {
3494
4078
  let a = {};
3495
4079
  for (let o of Q(e, i).inputs) {
3496
4080
  let s = t.edges.find((t) => t.toNode === e.id && t.toInput === o.key);
3497
- a[o.key] = s ? vi(s, o.kind, n, r, i) : void 0;
4081
+ a[o.key] = s ? qi(s, o.kind, n, r, i) : void 0;
3498
4082
  }
3499
4083
  return a;
3500
4084
  }
3501
- function vi(e, t, n, r, i) {
4085
+ function qi(e, t, n, r, i) {
3502
4086
  let a = n.get(e.fromNode)?.[e.fromOutput];
3503
4087
  if (a === void 0) return;
3504
4088
  let o = r.get(e.fromNode), s = o ? Q(o, i).outputs.find((t) => t.key === e.fromOutput)?.kind : void 0;
3505
4089
  if (s && s !== t) {
3506
- let e = Re(s, t);
3507
- e && (a = yi(a, e));
4090
+ let e = qe(s, t);
4091
+ e && (a = Ji(a, e));
3508
4092
  }
3509
4093
  return a;
3510
4094
  }
3511
- function yi(e, t) {
4095
+ function Ji(e, t) {
3512
4096
  switch (t) {
3513
4097
  case "float-to-vector":
3514
- case "float-to-color": return J(e);
4098
+ case "float-to-color": return K(e);
3515
4099
  case "vector-to-float": return e.x.add(e.y).add(e.z).div(3);
3516
- case "color-to-float": return oe(e);
4100
+ case "color-to-float": return de(e);
3517
4101
  case "identity":
3518
4102
  case "vector-to-color":
3519
4103
  case "color-to-vector": return e;
3520
4104
  }
3521
4105
  }
3522
- function bi(t, n) {
4106
+ function Yi(t, n) {
3523
4107
  let r = {};
3524
4108
  for (let i of t.params) {
3525
4109
  let t = n.params[i.key] ?? i.default;
3526
- if (i.type === "color") r[i.key] = G(new e.Color(t));
4110
+ if (i.type === "color") r[i.key] = U(new e.Color(t));
3527
4111
  else if (i.type === "vec3") {
3528
4112
  let n = t ?? {
3529
4113
  x: 0,
3530
4114
  y: 0,
3531
4115
  z: 0
3532
4116
  };
3533
- r[i.key] = G(new e.Vector3(n.x, n.y, n.z));
4117
+ r[i.key] = U(new e.Vector3(n.x, n.y, n.z));
3534
4118
  } else if (i.type === "float" || i.type === "int") {
3535
4119
  let e = Number(t);
3536
- r[i.key] = G(Number.isFinite(e) ? e : Number(i.default) || 0);
3537
- } else i.type === "curve" && (r[i.key] = Ee(je(t), "float"));
4120
+ r[i.key] = U(Number.isFinite(e) ? e : Number(i.default) || 0);
4121
+ } else i.type === "curve" && (r[i.key] = Me(Le(t), "float"));
3538
4122
  }
3539
4123
  return r;
3540
4124
  }
3541
- function xi(e, t, n) {
3542
- let r = e.nodes.find((e) => e.type === Fe);
4125
+ function Xi(e, t, n) {
4126
+ let r = e.nodes.find((e) => e.type === q);
3543
4127
  if (!r) return {};
3544
4128
  let i = e.edges.find((e) => e.toNode === r.id && e.toInput === "surface");
3545
- return i ? vi(i, "shader", n, new Map(e.nodes.map((e) => [e.id, e])), t) ?? {} : {};
4129
+ return i ? qi(i, "shader", n, new Map(e.nodes.map((e) => [e.id, e])), t) ?? {} : {};
3546
4130
  }
3547
- function Si(e) {
4131
+ function Zi(e) {
3548
4132
  let t = /* @__PURE__ */ new Map();
3549
4133
  for (let n of e.nodes) t.set(n.id, 0);
3550
4134
  let n = /* @__PURE__ */ new Map();
@@ -3561,8 +4145,8 @@ function Si(e) {
3561
4145
  if (i.length !== e.nodes.length) throw Error("Material graph has a cycle");
3562
4146
  return i;
3563
4147
  }
3564
- function Ci(e, t, n = !1) {
3565
- let r = n ? Pe : Fe, i = e.nodes.filter((e) => e.type === r);
4148
+ function Qi(e, t, n = !1) {
4149
+ let r = n ? Ue : q, i = e.nodes.filter((e) => e.type === r);
3566
4150
  if (i.length !== 1) throw Error(`Expected exactly one ${r} node, found ${i.length}`);
3567
4151
  let a = new Map(e.nodes.map((e) => [e.id, e])), o = /* @__PURE__ */ new Set();
3568
4152
  for (let n of e.edges) {
@@ -3572,7 +4156,7 @@ function Ci(e, t, n = !1) {
3572
4156
  let i = Q(e, t).outputs.find((e) => e.key === n.fromOutput), s = Q(r, t).inputs.find((e) => e.key === n.toInput);
3573
4157
  if (!i) throw Error(`Node '${e.type}' has no output '${n.fromOutput}'`);
3574
4158
  if (!s) throw Error(`Node '${r.type}' has no input '${n.toInput}'`);
3575
- if (i.kind !== s.kind && !Re(i.kind, s.kind)) throw Error(`Type mismatch (no coercion): ${e.type}.${n.fromOutput} (${i.kind}) -> ${r.type}.${n.toInput} (${s.kind})`);
4159
+ if (i.kind !== s.kind && !qe(i.kind, s.kind)) throw Error(`Type mismatch (no coercion): ${e.type}.${n.fromOutput} (${i.kind}) -> ${r.type}.${n.toInput} (${s.kind})`);
3576
4160
  let c = `${n.toNode}/${n.toInput}`;
3577
4161
  if (o.has(c)) throw Error(`Multiple connections into ${r.type}.${n.toInput}`);
3578
4162
  o.add(c);
@@ -3580,36 +4164,54 @@ function Ci(e, t, n = !1) {
3580
4164
  }
3581
4165
  //#endregion
3582
4166
  //#region src/document.ts
3583
- var wi = 2;
3584
- function Ti(e) {
4167
+ var $i = 4;
4168
+ function ea(e) {
3585
4169
  return structuredClone(e);
3586
4170
  }
3587
- function Ei() {
3588
- return Ti(Oe);
4171
+ function ta() {
4172
+ return ea(Pe);
3589
4173
  }
3590
- function Di(e) {
3591
- return {
3592
- ...Ti(e),
3593
- version: e.version ?? 2
3594
- };
4174
+ function na(e) {
4175
+ for (let t of e.nodes) t.type === "principled-bsdf" && (t.type = We, t.params = {
4176
+ ...t.params,
4177
+ materialType: "physical"
4178
+ }), t.subgraph && na(t.subgraph);
3595
4179
  }
3596
- function Oi(e, t) {
4180
+ var ra = new Set([
4181
+ "curl",
4182
+ "paper",
4183
+ "wool",
4184
+ "stone",
4185
+ "erosion"
4186
+ ]);
4187
+ function ia(e) {
4188
+ for (let t of e.nodes) t.type === "tileable-noise" && ra.has(t.params.noiseType) && (t.params = {
4189
+ ...t.params,
4190
+ preset: t.params.noiseType,
4191
+ noiseType: "perlin-fbm"
4192
+ }), t.subgraph && ia(t.subgraph);
4193
+ }
4194
+ function aa(e) {
4195
+ let t = ea(e);
4196
+ return (e.version ?? 0) < 3 && na(t), (e.version ?? 0) < 4 && ia(t), t.version = 4, t;
4197
+ }
4198
+ function oa(e, t) {
3597
4199
  return e.nodes.find((e) => e.id === t);
3598
4200
  }
3599
- function ki(e, t) {
4201
+ function sa(e, t) {
3600
4202
  return e.find((e) => e.key === t);
3601
4203
  }
3602
- function Ai(e) {
3603
- return e.type === "float" || e.type === "color" || e.type === "vec3" || e.type === "curve" ? "param" : "structural";
4204
+ function ca(e) {
4205
+ return e.structural ? "structural" : e.type === "float" || e.type === "color" || e.type === "vec3" || e.type === "curve" ? "param" : "structural";
3604
4206
  }
3605
- var ji = class {
4207
+ var la = class {
3606
4208
  registry;
3607
4209
  doc;
3608
4210
  listeners = /* @__PURE__ */ new Set();
3609
4211
  lastError_ = null;
3610
4212
  soloNode_ = null;
3611
- constructor(e = Ei(), t = ei) {
3612
- this.registry = t, this.doc = Di(e), this.validate(this.doc);
4213
+ constructor(e = ta(), t = Si) {
4214
+ this.registry = t, this.doc = aa(e), this.validate(this.doc);
3613
4215
  }
3614
4216
  get document() {
3615
4217
  return this.doc;
@@ -3625,7 +4227,7 @@ var ji = class {
3625
4227
  }
3626
4228
  compileBundle(e) {
3627
4229
  try {
3628
- let t = ui(this.doc, this.registry, e);
4230
+ let t = Li(this.doc, this.registry, e);
3629
4231
  return this.lastError_ = null, t;
3630
4232
  } catch (e) {
3631
4233
  throw this.lastError_ = e instanceof Error ? e.message : String(e), e;
@@ -3635,17 +4237,17 @@ var ji = class {
3635
4237
  return this.listeners.add(e), () => this.listeners.delete(e);
3636
4238
  }
3637
4239
  setDocument(e) {
3638
- let t = Di(e);
4240
+ let t = aa(e);
3639
4241
  this.validate(t), this.doc = t, this.emit({ kind: "structural" });
3640
4242
  }
3641
4243
  getDocument() {
3642
- return Ti(this.doc);
4244
+ return ea(this.doc);
3643
4245
  }
3644
4246
  setSoloNode(e) {
3645
4247
  e !== this.soloNode_ && (this.soloNode_ = e, this.emit({ kind: "structural" }));
3646
4248
  }
3647
4249
  setOutputResolution(e) {
3648
- let t = this.doc.nodes.find((e) => e.type === Fe);
4250
+ let t = this.doc.nodes.find((e) => e.type === q);
3649
4251
  if (!t) return;
3650
4252
  let n = String(e);
3651
4253
  t.params.outputResolution !== n && (t.params.outputResolution = n, this.emit({ kind: "structural" }));
@@ -3654,10 +4256,10 @@ var ji = class {
3654
4256
  this.setOutputResolution(e.resolution ?? e.size ?? 1024);
3655
4257
  }
3656
4258
  setNodeParam(e, t, n) {
3657
- let r = Oi(this.doc, e);
4259
+ let r = oa(this.doc, e);
3658
4260
  if (!r) return !1;
3659
- let i = this.registry.get(r.type), a = ki(Zr(r, this.registry), t) ?? ki(i.params, t);
3660
- return a ? Object.is(r.params[t], n) ? !0 : (r.params[t] = n, Ai(a) === "param" ? this.emit({
4261
+ let i = this.registry.get(r.type), a = sa(yi(r, this.registry), t) ?? sa(i.params, t);
4262
+ return a ? Object.is(r.params[t], n) ? !0 : (r.params[t] = n, ca(a) === "param" ? this.emit({
3661
4263
  kind: "param",
3662
4264
  nodeId: e,
3663
4265
  key: t,
@@ -3672,80 +4274,83 @@ var ji = class {
3672
4274
  return n;
3673
4275
  }
3674
4276
  validate(e) {
3675
- ui(e, this.registry, { backend: "live" }), this.lastError_ = null;
4277
+ Li(e, this.registry, { backend: "live" }), this.lastError_ = null;
3676
4278
  }
3677
4279
  emit(e) {
3678
4280
  for (let t of this.listeners) t(e);
3679
4281
  }
3680
- }, Mi = [
4282
+ }, ua = [
3681
4283
  "roughness",
3682
4284
  "metallic",
3683
4285
  "ambientOcclusion"
3684
- ], Ni = ["baseColor", "emission"];
3685
- function Pi(e, t) {
3686
- return Mi.includes(t) ? J(e) : Ni.includes(t) ? _e(e) : e;
4286
+ ], da = ["baseColor", "emission"];
4287
+ function fa(e, t) {
4288
+ return ua.includes(t) ? K(e) : da.includes(t) ? Ce(e) : e;
3687
4289
  }
3688
- var $ = 2, Fi = new l(new s()), Ii = new s();
3689
- function Li(e, t, n) {
3690
- let r = ($ - 1) / 2, i = J(0, 0, 0);
4290
+ var $ = 2, pa = new p(new o()), ma = new o();
4291
+ function ha(e, t, n) {
4292
+ let r = ($ - 1) / 2, i = K(0, 0, 0);
3691
4293
  for (let a = 0; a < $; a++) for (let o = 0; o < $; o++) {
3692
- let s = q(o - r, a - r).mul(t), c = U(e, K().add(s)).xyz;
4294
+ let s = G(o - r, a - r).mul(t), c = V(e, W().add(s)).xyz;
3693
4295
  n && (c = c.mul(2).sub(1)), i = i.add(c);
3694
4296
  }
3695
- return i = i.div($ * $), n ? ue(i).mul(.5).add(.5) : i;
4297
+ return i = i.div($ * $), n ? ge(i).mul(.5).add(.5) : i;
3696
4298
  }
3697
- var Ri = /* @__PURE__ */ new Map();
3698
- function zi(e, r) {
3699
- let a = `${e}x${r}`, o = Ri.get(a);
3700
- if (o) return o;
3701
- let c = new u(e, r);
4299
+ var ga = /* @__PURE__ */ new Map();
4300
+ function _a(e, r) {
4301
+ let a = `${e}x${r}`, s = ga.get(a);
4302
+ if (s) return s;
4303
+ let c = new m(e, r, {
4304
+ depthBuffer: !1,
4305
+ stencilBuffer: !1
4306
+ });
3702
4307
  c.texture.colorSpace = n, c.texture.minFilter = c.texture.magFilter = t, c.texture.wrapS = c.texture.wrapT = i;
3703
- let d = q(1 / e, 1 / r), f = (e) => {
3704
- let t = new s();
3705
- return t.colorNode = Li(c.texture, d, e), new l(t);
3706
- }, p = {
4308
+ let l = G(1 / e, 1 / r), u = (e) => {
4309
+ let t = new o();
4310
+ return t.colorNode = ha(c.texture, l, e), new p(t);
4311
+ }, d = {
3707
4312
  ssRT: c,
3708
- downColorQuad: f(!1),
3709
- downNormalQuad: f(!0)
4313
+ downColorQuad: u(!1),
4314
+ downNormalQuad: u(!0)
3710
4315
  };
3711
- return Ri.set(a, p), p;
4316
+ return ga.set(a, d), d;
3712
4317
  }
3713
- function Bi() {
3714
- return new s();
4318
+ function va() {
4319
+ return new o();
3715
4320
  }
3716
- var Vi = new a(), Hi = new r(-1, 1, 1, -1, 0, 1), Ui = [];
3717
- async function Wi(e, t, n) {
3718
- for (; Ui.length < t.length;) Ui.push(new l());
3719
- Vi.clear();
3720
- for (let e = 0; e < t.length; e++) Ui[e].material = t[e], Vi.add(Ui[e]);
4321
+ var ya = new a(), ba = new r(-1, 1, 1, -1, 0, 1), xa = [];
4322
+ async function Sa(e, t, n) {
4323
+ for (; xa.length < t.length;) xa.push(new p());
4324
+ ya.clear();
4325
+ for (let e = 0; e < t.length; e++) xa[e].material = t[e], ya.add(xa[e]);
3721
4326
  let r = e.getRenderTarget();
3722
- e.setRenderTarget(zi(n * $, n * $).ssRT), await e.compileAsync(Vi, Hi), e.setRenderTarget(r);
4327
+ e.setRenderTarget(_a(n * $, n * $).ssRT), await e.compileAsync(ya, ba), e.setRenderTarget(r);
3723
4328
  }
3724
- function Gi(e, t, n) {
3725
- Fi.material = t;
4329
+ function Ca(e, t, n) {
4330
+ pa.material = t;
3726
4331
  let r = e.getRenderTarget();
3727
- e.setRenderTarget(n), Fi.render(e), e.setRenderTarget(r);
4332
+ e.setRenderTarget(n), pa.render(e), e.setRenderTarget(r);
3728
4333
  }
3729
- function Ki(e, t, n, r = !1) {
3730
- let { ssRT: i, downColorQuad: a, downNormalQuad: o } = zi(n.width * $, n.height * $);
3731
- Fi.material = t;
4334
+ function wa(e, t, n, r = !1) {
4335
+ let { ssRT: i, downColorQuad: a, downNormalQuad: o } = _a(n.width * $, n.height * $);
4336
+ pa.material = t;
3732
4337
  let s = e.getRenderTarget();
3733
- e.setRenderTarget(i), Fi.render(e), e.setRenderTarget(n), (r ? o : a).render(e), e.setRenderTarget(s);
4338
+ e.setRenderTarget(i), pa.render(e), e.setRenderTarget(n), (r ? o : a).render(e), e.setRenderTarget(s);
3734
4339
  }
3735
- function qi(e, t, n, r = !1) {
3736
- Ii.colorNode = t, Ii.needsUpdate = !0, Ki(e, Ii, n, r);
4340
+ function Ta(e, t, n, r = !1) {
4341
+ ma.colorNode = t, ma.needsUpdate = !0, wa(e, ma, n, r);
3737
4342
  }
3738
4343
  //#endregion
3739
4344
  //#region src/graph/bake-service.ts
3740
- var Ji = 1024, Yi = 8, Xi = 4096;
3741
- function Zi(e, t) {
4345
+ var Ea = 1024, Da = 8, Oa = 4096;
4346
+ function ka(e, t) {
3742
4347
  let n = t?.size ?? Math.max(e, t?.minSize ?? 0);
3743
- return Math.min(n, Xi);
4348
+ return Math.min(n, Oa);
3744
4349
  }
3745
- function Qi(e) {
4350
+ function Aa(e) {
3746
4351
  return e?.minSize != null;
3747
4352
  }
3748
- var $i = typeof navigator < "u" && /chrome|chromium|crios|edg\//i.test(navigator.userAgent) && !/firefox|fxios/i.test(navigator.userAgent), ea = [
4353
+ var ja = typeof navigator < "u" && /chrome|chromium|crios|edg\//i.test(navigator.userAgent) && !/firefox|fxios/i.test(navigator.userAgent), Ma = [
3749
4354
  "baseColor",
3750
4355
  "roughness",
3751
4356
  "metallic",
@@ -3753,15 +4358,22 @@ var $i = typeof navigator < "u" && /chrome|chromium|crios|edg\//i.test(navigator
3753
4358
  "normal",
3754
4359
  "emission"
3755
4360
  ];
3756
- function ta(t, n) {
3757
- let r = new u(n, n), i = r.texture;
3758
- return i.colorSpace = t !== "height" && Ni.includes(t) ? e.SRGBColorSpace : e.NoColorSpace, i.wrapS = i.wrapT = e.RepeatWrapping, i.generateMipmaps = !0, i.minFilter = e.LinearMipmapLinearFilter, i.magFilter = e.LinearFilter, i.anisotropy = Yi, r;
4361
+ function Na(t, n) {
4362
+ let r = new m(n, n, {
4363
+ depthBuffer: !1,
4364
+ stencilBuffer: !1
4365
+ }), i = r.texture;
4366
+ return i.colorSpace = t !== "height" && da.includes(t) ? e.SRGBColorSpace : e.NoColorSpace, i.wrapS = i.wrapT = e.RepeatWrapping, i.generateMipmaps = !0, i.minFilter = e.LinearMipmapLinearFilter, i.magFilter = e.LinearFilter, i.anisotropy = Da, r;
3759
4367
  }
3760
- function na(t, n = !1) {
3761
- let r = new u(t, t, { type: e.HalfFloatType }), i = r.texture;
4368
+ function Pa(t, n = !1) {
4369
+ let r = new m(t, t, {
4370
+ type: e.HalfFloatType,
4371
+ depthBuffer: !1,
4372
+ stencilBuffer: !1
4373
+ }), i = r.texture;
3762
4374
  return i.colorSpace = e.NoColorSpace, i.wrapS = i.wrapT = e.RepeatWrapping, i.generateMipmaps = n, i.minFilter = n ? e.LinearMipmapLinearFilter : e.LinearFilter, i.magFilter = e.LinearFilter, r;
3763
4375
  }
3764
- var ra = class {
4376
+ var Fa = class {
3765
4377
  channels;
3766
4378
  targets = /* @__PURE__ */ new Map();
3767
4379
  mats = /* @__PURE__ */ new Map();
@@ -3769,6 +4381,8 @@ var ra = class {
3769
4381
  cacheMats = /* @__PURE__ */ new Map();
3770
4382
  cachePlan = [];
3771
4383
  uniforms = /* @__PURE__ */ new Map();
4384
+ paramUsage = /* @__PURE__ */ new Map();
4385
+ constArrays = /* @__PURE__ */ new Map();
3772
4386
  heightTarget = null;
3773
4387
  hasHeight = !1;
3774
4388
  present = /* @__PURE__ */ new Set();
@@ -3780,25 +4394,25 @@ var ra = class {
3780
4394
  resize(e) {
3781
4395
  if (e !== this.size) {
3782
4396
  this.size = e;
3783
- for (let t of this.targets.values()) t.setSize(e, e);
3784
- this.heightTarget?.setSize(e, e), this.flushCaches();
4397
+ for (let t of this.targets.values()) t.setSize(e, e), t.texture.needsUpdate = !0;
4398
+ this.heightTarget && (this.heightTarget.setSize(e, e), this.heightTarget.texture.needsUpdate = !0), this.flushCaches();
3785
4399
  }
3786
4400
  }
3787
4401
  target(e) {
3788
4402
  let t = this.targets.get(e);
3789
- return t || (t = ta(e, this.size), this.targets.set(e, t)), t;
4403
+ return t || (t = Na(e, this.size), this.targets.set(e, t)), t;
3790
4404
  }
3791
4405
  channelMaterial(e) {
3792
4406
  let t = this.mats.get(e);
3793
- return t || (t = Bi(), this.mats.set(e, t)), t;
4407
+ return t || (t = va(), this.mats.set(e, t)), t;
3794
4408
  }
3795
4409
  cacheTarget(e, t = this.size, n = !1) {
3796
4410
  let r = this.cacheTargets.get(e);
3797
- return r && r.texture.generateMipmaps !== n && (r.dispose(), this.cacheTargets.delete(e), r = void 0), r ? (r.width !== t || r.height !== t) && r.setSize(t, t) : (r = na(t, n), this.cacheTargets.set(e, r)), r;
4411
+ return r && r.texture.generateMipmaps !== n && (r.dispose(), this.cacheTargets.delete(e), r = void 0), r ? (r.width !== t || r.height !== t) && r.setSize(t, t) : (r = Pa(t, n), this.cacheTargets.set(e, r)), r;
3798
4412
  }
3799
4413
  cacheMaterial(e) {
3800
4414
  let t = this.cacheMats.get(e);
3801
- return t || (t = Bi(), this.cacheMats.set(e, t)), t;
4415
+ return t || (t = va(), this.cacheMats.set(e, t)), t;
3802
4416
  }
3803
4417
  cacheTexture(e, t, n = !1) {
3804
4418
  return this.cacheTarget(e, t, n).texture;
@@ -3812,18 +4426,43 @@ var ra = class {
3812
4426
  return this.heightTarget;
3813
4427
  }
3814
4428
  ensureHeightTarget() {
3815
- return this.heightTarget ||= ta("height", this.size), this.heightTarget;
4429
+ return this.heightTarget ||= Na("height", this.size), this.heightTarget;
3816
4430
  }
3817
4431
  texture(e) {
3818
4432
  return this.targets.get(e)?.texture ?? null;
3819
4433
  }
4434
+ allocConstantArray(t, n, r, i) {
4435
+ let a = `${t}/${n}`, o = this.constArrays.get(a);
4436
+ if (o && o.length === r.length && o.elementType === i) {
4437
+ let e = o.node.array;
4438
+ if (i === "vec3") {
4439
+ let t = e;
4440
+ for (let e = 0; e < t.length; e++) t[e].set(r[e * 3], r[e * 3 + 1], r[e * 3 + 2]);
4441
+ } else {
4442
+ let t = e;
4443
+ for (let e = 0; e < r.length; e++) t[e] = r[e];
4444
+ }
4445
+ return o.node;
4446
+ }
4447
+ let s;
4448
+ if (i === "vec3") {
4449
+ let t = [];
4450
+ for (let n = 0; n < r.length; n += 3) t.push(new e.Vector3(r[n], r[n + 1], r[n + 2]));
4451
+ s = Me(t);
4452
+ } else s = Me(Array.from(r), "float");
4453
+ return this.constArrays.set(a, {
4454
+ node: s,
4455
+ length: r.length,
4456
+ elementType: i
4457
+ }), s;
4458
+ }
3820
4459
  flushCaches() {
3821
4460
  for (let e of this.mats.values()) e.dispose();
3822
4461
  this.mats.clear();
3823
4462
  for (let e of this.cacheTargets.values()) e.dispose();
3824
4463
  this.cacheTargets.clear();
3825
4464
  for (let e of this.cacheMats.values()) e.dispose();
3826
- this.cacheMats.clear(), this.cachePlan = [], this.uniforms = /* @__PURE__ */ new Map();
4465
+ this.cacheMats.clear(), this.cachePlan = [], this.uniforms = /* @__PURE__ */ new Map(), this.paramUsage = /* @__PURE__ */ new Map(), this.constArrays.clear();
3827
4466
  }
3828
4467
  dispose() {
3829
4468
  for (let e of this.targets.values()) e.dispose();
@@ -3833,9 +4472,9 @@ var ra = class {
3833
4472
  for (let e of this.cacheTargets.values()) e.dispose();
3834
4473
  this.cacheTargets.clear();
3835
4474
  for (let e of this.cacheMats.values()) e.dispose();
3836
- this.cacheMats.clear(), this.cachePlan = [], this.heightTarget?.dispose(), this.heightTarget = null;
4475
+ this.cacheMats.clear(), this.cachePlan = [], this.uniforms = /* @__PURE__ */ new Map(), this.paramUsage = /* @__PURE__ */ new Map(), this.constArrays.clear(), this.heightTarget?.dispose(), this.heightTarget = null;
3837
4476
  }
3838
- }, ia = class {
4477
+ }, Ia = class {
3839
4478
  renderer = null;
3840
4479
  compileGateDepth = 0;
3841
4480
  get rendererBusy() {
@@ -3887,79 +4526,80 @@ var ra = class {
3887
4526
  });
3888
4527
  return this.queue = n.then(() => void 0, () => void 0), n;
3889
4528
  }
3890
- createTextureSet(e = ea, t = Ji) {
3891
- return new ra(t, e);
4529
+ createTextureSet(e = Ma, t = Ea) {
4530
+ return new Fa(t, e);
3892
4531
  }
3893
4532
  bakeInto(e, t, n = {}) {
3894
4533
  return this.enqueue(n.label ?? "surface", async () => {
3895
4534
  let r = this.renderer;
3896
4535
  if (!r) return !1;
3897
- let i = performance.now(), { bundle: a, uniforms: o, cachePlan: s } = t.compileBundle({
4536
+ let i = performance.now(), { bundle: a, uniforms: o, cachePlan: s, paramUsage: c } = t.compileBundle({
3898
4537
  backend: "offline",
3899
4538
  soloNodeId: n.soloNodeId,
3900
- allocCache: (t, n, r) => e.cacheTexture(t, Zi(e.size, r), Qi(r))
3901
- }), c = performance.now() - i, l = li(t.document);
3902
- e.uniforms = o, e.cachePlan = s, n.soloNodeId || e.pruneCaches(new Set(s.map((e) => e.cacheId)));
3903
- let u = n.channels ?? e.channels, d = /* @__PURE__ */ new Set(), f = [];
3904
- for (let t of u) {
4539
+ allocCache: (t, n, r) => e.cacheTexture(t, ka(e.size, r), Aa(r)),
4540
+ allocConstantArray: (t, n, r, i) => e.allocConstantArray(t, n, r, i)
4541
+ }), l = performance.now() - i, u = Ii(t.document);
4542
+ e.uniforms = o, e.paramUsage = c, e.cachePlan = s, n.soloNodeId || e.pruneCaches(new Set(s.map((e) => e.cacheId)));
4543
+ let d = n.channels ?? e.channels, f = /* @__PURE__ */ new Set(), p = [];
4544
+ for (let t of d) {
3905
4545
  let n = a[t];
3906
4546
  if (!n) continue;
3907
4547
  let r = e.channelMaterial(t);
3908
- r.colorNode = Pi(n, t), r.needsUpdate = !0, f.push({
4548
+ r.colorNode = fa(n, t), r.needsUpdate = !0, p.push({
3909
4549
  mat: r,
3910
4550
  target: e.target(t),
3911
4551
  isNormal: t === "normal"
3912
- }), d.add(t);
4552
+ }), f.add(t);
3913
4553
  }
3914
4554
  if (e.hasHeight = a.height !== void 0, e.hasHeight) {
3915
4555
  let t = e.channelMaterial("height");
3916
- t.colorNode = J(a.height), t.needsUpdate = !0, f.push({
4556
+ t.colorNode = K(a.height), t.needsUpdate = !0, p.push({
3917
4557
  mat: t,
3918
4558
  target: e.ensureHeightTarget(),
3919
4559
  isNormal: !1
3920
4560
  });
3921
4561
  }
3922
- let p = {
4562
+ let m = {
3923
4563
  runId: ++this.bakeRunId,
3924
4564
  source: n.source,
3925
4565
  phase: "nodes",
3926
- nodeCount: l,
3927
- compileMs: c,
3928
- texturesTotal: f.length,
4566
+ nodeCount: u,
4567
+ compileMs: l,
4568
+ texturesTotal: p.length,
3929
4569
  totalMs: 0
3930
4570
  };
3931
- this.emitReport(p);
4571
+ this.emitReport(m);
3932
4572
  for (let t of s) {
3933
4573
  let n = e.cacheMaterial(t.cacheId);
3934
- n.colorNode = t.colorNode, n.needsUpdate = !0, Gi(r, n, e.cacheTarget(t.cacheId, Zi(e.size, t.sizing), Qi(t.sizing)));
4574
+ n.colorNode = t.colorNode, n.needsUpdate = !0, Ca(r, n, e.cacheTarget(t.cacheId, ka(e.size, t.sizing), Aa(t.sizing)));
3935
4575
  }
3936
- let m = 0;
3937
- if ($i) {
4576
+ let h = 0;
4577
+ if (ja) {
3938
4578
  this.emitReport({
3939
- ...p,
4579
+ ...m,
3940
4580
  phase: "shaders"
3941
4581
  });
3942
4582
  let t = performance.now();
3943
4583
  this.compileGateDepth += 1;
3944
4584
  try {
3945
- await Wi(r, f.map((e) => e.mat), e.size);
4585
+ await Sa(r, p.map((e) => e.mat), e.size);
3946
4586
  } finally {
3947
4587
  --this.compileGateDepth;
3948
4588
  }
3949
- m = performance.now() - t;
4589
+ h = performance.now() - t;
3950
4590
  }
3951
- let h = performance.now();
3952
- for (let e of f) Ki(r, e.mat, e.target, e.isNormal);
3953
- let g = performance.now() - h, _ = [...d].sort().join(",") + (e.hasHeight ? "|h" : ""), v = _ !== e.signature;
3954
- e.present = d, e.signature = _;
3955
- let y = performance.now();
4591
+ let g = performance.now();
4592
+ for (let e of p) wa(r, e.mat, e.target, e.isNormal);
4593
+ let _ = performance.now() - g, v = [...f].sort().join(",") + (e.hasHeight ? "|h" : ""), y = v !== e.signature;
4594
+ e.present = f, e.signature = v;
4595
+ let b = performance.now();
3956
4596
  await this.gpuSync(e);
3957
- let b = performance.now() - y, x = c + m + g + b;
4597
+ let x = performance.now() - b, S = l + h + _ + x;
3958
4598
  return this.emitReport({
3959
- ...p,
4599
+ ...m,
3960
4600
  phase: "done",
3961
- totalMs: x
3962
- }), console.log(`[bake-prof] rebuild compile=${c.toFixed(1)} precompile=${m.toFixed(1)} dispatch=${g.toFixed(1)} gpuWait=${b.toFixed(1)} total=${x.toFixed(1)}ms`), v;
4601
+ totalMs: S
4602
+ }), console.log(`[bake-prof] rebuild compile=${l.toFixed(1)} precompile=${h.toFixed(1)} dispatch=${_.toFixed(1)} gpuWait=${x.toFixed(1)} total=${S.toFixed(1)}ms`), y;
3963
4603
  });
3964
4604
  }
3965
4605
  async gpuSync(e) {
@@ -3988,9 +4628,9 @@ var ra = class {
3988
4628
  };
3989
4629
  this.emitReport(i);
3990
4630
  let a = performance.now();
3991
- for (let t of e.cachePlan) Gi(n, e.cacheMaterial(t.cacheId), e.cacheTarget(t.cacheId, Zi(e.size, t.sizing), Qi(t.sizing)));
3992
- for (let t of e.present) Ki(n, e.channelMaterial(t), e.target(t), t === "normal");
3993
- e.hasHeight && e.heightTarget && Ki(n, e.channelMaterial("height"), e.heightTarget, !1);
4631
+ for (let t of e.cachePlan) Ca(n, e.cacheMaterial(t.cacheId), e.cacheTarget(t.cacheId, ka(e.size, t.sizing), Aa(t.sizing)));
4632
+ for (let t of e.present) wa(n, e.channelMaterial(t), e.target(t), t === "normal");
4633
+ e.hasHeight && e.heightTarget && wa(n, e.channelMaterial("height"), e.heightTarget, !1);
3994
4634
  let o = performance.now() - a, s = performance.now();
3995
4635
  await this.gpuSync(e);
3996
4636
  let c = performance.now() - s;
@@ -4012,17 +4652,17 @@ var ra = class {
4012
4652
  if (!r) return null;
4013
4653
  let { bundle: i, cachePlan: a } = e.compileBundle({
4014
4654
  backend: "offline",
4015
- allocCache: (e, t, r) => this.scratchCache(e, n, Zi(n, r), Qi(r)).rt.texture
4655
+ allocCache: (e, t, r) => this.scratchCache(e, n, ka(n, r), Aa(r)).rt.texture
4016
4656
  }), o = i[t];
4017
4657
  if (!o) return null;
4018
4658
  let s = new Set(a.map((e) => e.cacheId));
4019
4659
  for (let [e, t] of this.scratchCaches) s.has(e) || (t.rt.dispose(), t.mat.dispose(), this.scratchCaches.delete(e));
4020
4660
  for (let e of a) {
4021
- let t = this.scratchCache(e.cacheId, n, Zi(n, e.sizing), Qi(e.sizing));
4022
- t.mat.colorNode = e.colorNode, t.mat.needsUpdate = !0, Gi(r, t.mat, t.rt);
4661
+ let t = this.scratchCache(e.cacheId, n, ka(n, e.sizing), Aa(e.sizing));
4662
+ t.mat.colorNode = e.colorNode, t.mat.needsUpdate = !0, Ca(r, t.mat, t.rt);
4023
4663
  }
4024
4664
  let c = this.scratchTarget(n);
4025
- qi(r, Pi(o, t), c, t === "normal");
4665
+ Ta(r, fa(o, t), c, t === "normal");
4026
4666
  let l = await r.readRenderTargetPixelsAsync(c, 0, 0, n, n), u = new Uint8ClampedArray(n * n * 4), d = n * 4;
4027
4667
  for (let e = 0; e < n; e++) {
4028
4668
  let t = (n - 1 - e) * d;
@@ -4032,7 +4672,10 @@ var ra = class {
4032
4672
  });
4033
4673
  }
4034
4674
  scratchTarget(e) {
4035
- return (!this.scratch || this.scratchSize !== e) && (this.scratch?.dispose(), this.scratch = new u(e, e), this.scratchSize = e), this.scratch;
4675
+ return (!this.scratch || this.scratchSize !== e) && (this.scratch?.dispose(), this.scratch = new m(e, e, {
4676
+ depthBuffer: !1,
4677
+ stencilBuffer: !1
4678
+ }), this.scratchSize = e), this.scratch;
4036
4679
  }
4037
4680
  scratchCache(e, t, n, r = !1) {
4038
4681
  if (this.scratchCacheSize !== t) {
@@ -4041,59 +4684,71 @@ var ra = class {
4041
4684
  }
4042
4685
  let i = this.scratchCaches.get(e);
4043
4686
  return i && i.rt.texture.generateMipmaps !== r && (i.rt.dispose(), i.mat.dispose(), this.scratchCaches.delete(e), i = void 0), i ? (i.rt.width !== n || i.rt.height !== n) && i.rt.setSize(n, n) : (i = {
4044
- rt: na(n, r),
4045
- mat: Bi()
4687
+ rt: Pa(n, r),
4688
+ mat: va()
4046
4689
  }, this.scratchCaches.set(e, i)), i;
4047
4690
  }
4048
- }, aa = new ia();
4691
+ }, La = new Ia();
4049
4692
  //#endregion
4050
4693
  //#region src/tsl/triplanar.ts
4051
- function oa(e) {
4052
- let t = z(le.abs(), e);
4053
- return t.div(t.dot(J(1, 1, 1)).max(1e-4));
4694
+ function Ra(e) {
4695
+ let t = L(he.abs(), e);
4696
+ return t.div(t.dot(K(1, 1, 1)).max(1e-4));
4054
4697
  }
4055
- function sa(e, t, n) {
4056
- return d(() => {
4057
- let r = pe.mul(t), i = oa(n), a = U(e, r.yz).mul(i.x), o = U(e, r.zx).mul(i.y), s = U(e, r.xy).mul(i.z);
4698
+ function za(e, t, n) {
4699
+ return h(() => {
4700
+ let r = ye.mul(t), i = Ra(n), a = V(e, r.yz).mul(i.x), o = V(e, r.zx).mul(i.y), s = V(e, r.xy).mul(i.z);
4058
4701
  return a.add(o).add(s);
4059
4702
  })();
4060
4703
  }
4061
4704
  //#endregion
4062
4705
  //#region src/tsl/triplanar-normal.ts
4063
- function ca(e, t, n) {
4064
- return d(() => {
4065
- let r = pe.mul(t), i = oa(n), a = le.sign(), o = U(e, r.yz).xyz.mul(2).sub(1), s = U(e, r.zx).xyz.mul(2).sub(1), c = U(e, r.xy).xyz.mul(2).sub(1), l = J(o.x, o.y, o.z.mul(a.x)), u = J(s.x, s.y, s.z.mul(a.y)), d = J(c.x, c.y, c.z.mul(a.z));
4706
+ function Ba(e, t, n) {
4707
+ return h(() => {
4708
+ let r = ye.mul(t), i = Ra(n), a = he.sign(), o = V(e, r.yz).xyz.mul(2).sub(1), s = V(e, r.zx).xyz.mul(2).sub(1), c = V(e, r.xy).xyz.mul(2).sub(1), l = K(o.x, o.y, o.z.mul(a.x)), u = K(s.x, s.y, s.z.mul(a.y)), d = K(c.x, c.y, c.z.mul(a.z));
4066
4709
  return l.zxy.mul(i.x).add(u.yzx.mul(i.y)).add(d.xyz.mul(i.z)).normalize();
4067
4710
  })();
4068
4711
  }
4069
4712
  //#endregion
4070
4713
  //#region src/tsl/parallax.ts
4071
- var la = .3;
4072
- function ua(e, t, n, r) {
4073
- return d(() => {
4074
- let i = de.normalize(), a = (t) => U(e, t).x, o = 1 / r, s = i.xy.div(i.z.abs().max(la)).mul(n).mul(o), c = t.toVar(), l = _(!1).toVar(), u = t, d = k(1).sub(a(u));
4714
+ var Va = .3;
4715
+ function Ha(e, t, n, r) {
4716
+ return h(() => {
4717
+ let i = _e.normalize(), a = (t) => V(e, t).x, o = 1 / r, s = i.xy.div(i.z.abs().max(Va)).mul(n).mul(o), c = t.toVar(), l = x(!1).toVar(), u = t, d = k(1).sub(a(u));
4075
4718
  for (let e = 0; e < r; e++) {
4076
- let t = u.sub(s), n = k(1).sub(a(t)), r = (e + 1) * o, i = k(r).greaterThanEqual(n), f = n.sub(r), p = d.sub(e * o), m = ve(f.div(f.sub(p).max(1e-5))), h = I(t, u, m);
4077
- c.assign(B(l.not().and(i), h, c)), l.assign(l.or(i)), u = t, d = n;
4719
+ let t = u.sub(s), n = k(1).sub(a(t)), r = (e + 1) * o, i = k(r).greaterThanEqual(n), f = n.sub(r), p = d.sub(e * o), m = we(f.div(f.sub(p).max(1e-5))), h = F(t, u, m);
4720
+ c.assign(R(l.not().and(i), h, c)), l.assign(l.or(i)), u = t, d = n;
4078
4721
  }
4079
4722
  return c;
4080
4723
  })();
4081
4724
  }
4082
4725
  //#endregion
4083
4726
  //#region src/graph/textured-surface.ts
4084
- var da = 12, fa = class {
4727
+ var Ua = 12;
4728
+ function Wa(e, t) {
4729
+ return [
4730
+ e,
4731
+ t.shininess,
4732
+ t.specular,
4733
+ t.gradientSteps,
4734
+ t.matcap
4735
+ ].join("|");
4736
+ }
4737
+ var Ga = class {
4085
4738
  graph;
4086
4739
  service;
4087
4740
  source;
4088
- offlineMat = mi();
4741
+ offlineMat = Ui();
4742
+ matType = "physical";
4743
+ matSig = "";
4089
4744
  liveUniforms = /* @__PURE__ */ new Map();
4090
4745
  material_;
4091
- scaleUniform = G(1.2);
4092
- sharpnessUniform = G(8);
4093
- roughnessFactor = G(1);
4094
- metalnessFactor = G(1);
4095
- colorTint = G(new e.Color(1, 1, 1));
4096
- parallaxScale = G(0);
4746
+ scaleUniform = U(1.2);
4747
+ sharpnessUniform = U(8);
4748
+ roughnessFactor = U(1);
4749
+ metalnessFactor = U(1);
4750
+ colorTint = U(new e.Color(1, 1, 1));
4751
+ parallaxScale = U(0);
4097
4752
  lastBakeMs = 0;
4098
4753
  set;
4099
4754
  backend = "offline";
@@ -4110,7 +4765,7 @@ var da = 12, fa = class {
4110
4765
  processingDepth = 0;
4111
4766
  idleWaiters = [];
4112
4767
  constructor(e, t, n) {
4113
- this.graph = e, this.service = t, this.source = n, this.set = t.createTextureSet(ea, this.surfaceBakeSize()), this.material_ = this.buildLive(), this.graph.onChange((e) => this.onGraphChange(e));
4768
+ this.graph = e, this.service = t, this.source = n, this.set = t.createTextureSet(Ma, this.surfaceBakeSize()), this.material_ = this.buildLive(), this.graph.onChange((e) => this.onGraphChange(e));
4114
4769
  }
4115
4770
  get material() {
4116
4771
  return this.material_;
@@ -4161,6 +4816,9 @@ var da = 12, fa = class {
4161
4816
  refresh() {
4162
4817
  return this.rebuild();
4163
4818
  }
4819
+ async releaseCaches() {
4820
+ await this.whenIdle(), this.set.flushCaches();
4821
+ }
4164
4822
  regenerate() {
4165
4823
  this.flushRequested = !0, this.requestUpdate("rebuild");
4166
4824
  }
@@ -4219,7 +4877,7 @@ var da = 12, fa = class {
4219
4877
  let e = n.value;
4220
4878
  t.value.set(e.x, e.y, e.z);
4221
4879
  } else if (n.paramType === "curve") {
4222
- let e = je(n.value), r = t.array;
4880
+ let e = Le(n.value), r = t.array;
4223
4881
  for (let t = 0; t < e.length; t++) r[t] = e[t];
4224
4882
  } else t.value = Number(n.value);
4225
4883
  }
@@ -4228,7 +4886,7 @@ var da = 12, fa = class {
4228
4886
  return t ? (this.applyUniformValue(t, e), !0) : !1;
4229
4887
  }
4230
4888
  updateOfflineUniform(e) {
4231
- if (e.bakeStructural) return !1;
4889
+ if (this.set.paramUsage.get(e.nodeId)?.[e.key] !== "live") return !1;
4232
4890
  let t = this.set.uniforms.get(e.nodeId)?.[e.key];
4233
4891
  return t ? (this.applyUniformValue(t, e), !0) : !1;
4234
4892
  }
@@ -4261,34 +4919,36 @@ var da = 12, fa = class {
4261
4919
  }
4262
4920
  }
4263
4921
  surfaceBakeSize() {
4264
- return Math.max(64, Math.round(oi(this.graph.document) / 64) * 64);
4922
+ return Math.max(64, Math.round(ji(this.graph.document) / 64) * 64);
4265
4923
  }
4266
4924
  async rebuild() {
4267
4925
  this.enterProcessing();
4268
- let e = this.material_;
4926
+ let e = this.material_, t;
4269
4927
  try {
4270
4928
  try {
4271
4929
  if (this.backend === "offline" && this.service.hasRenderer) {
4272
4930
  let e = this.surfaceBakeSize();
4273
4931
  this.flushRequested && (this.flushRequested = !1, this.set.flushCaches()), this.set.resize(e);
4274
- let t = this.graph.soloNode ?? void 0, n = performance.now(), r = await this.service.bakeInto(this.set, this.graph, {
4275
- soloNodeId: t,
4932
+ let { type: n, settings: r } = Mi(this.graph.document), i = Wa(n, r), a = i !== this.matSig;
4933
+ a && (t = this.offlineMat, this.offlineMat = Ui(n, r), this.matType = n, this.matSig = i);
4934
+ let o = this.graph.soloNode ?? void 0, s = performance.now(), c = await this.service.bakeInto(this.set, this.graph, {
4935
+ soloNodeId: o,
4276
4936
  label: "surface",
4277
4937
  source: this.source
4278
4938
  });
4279
- this.lastBakeMs = performance.now() - n, (r || !this.wiredOnce) && (this.wire(this.set.present), this.wiredOnce = !0), this.material_ = this.offlineMat;
4939
+ this.lastBakeMs = performance.now() - s, (c || !this.wiredOnce || a) && (this.wire(this.set.present), this.wiredOnce = !0), this.material_ = this.offlineMat;
4280
4940
  } else this.material_ = this.buildLive();
4281
4941
  this.lastError_ = this.graph.lastError;
4282
4942
  } catch (e) {
4283
4943
  this.lastError_ = e instanceof Error ? e.message : String(e), console.warn("[textured-surface] rebuild failed:", this.lastError_);
4284
4944
  }
4285
- this.notify(), this.notifyTexturesUpdated(), e !== this.material_ && e !== this.offlineMat && e.dispose();
4945
+ this.notify(), this.notifyTexturesUpdated(), e !== this.material_ && e !== this.offlineMat && e !== t && e.dispose(), t && t.dispose();
4286
4946
  } finally {
4287
4947
  this.exitProcessing();
4288
4948
  }
4289
4949
  }
4290
4950
  buildLive() {
4291
- let e = this.graph.soloNode ?? void 0, { material: t, uniforms: n } = gi(this.graph.document, this.graph.getRegistry(), {
4951
+ let e = this.graph.soloNode ?? void 0, { material: t, uniforms: n } = Gi(this.graph.document, this.graph.getRegistry(), {
4292
4952
  backend: "live",
4293
4953
  soloNodeId: e
4294
4954
  });
@@ -4296,28 +4956,72 @@ var da = 12, fa = class {
4296
4956
  }
4297
4957
  wire(e) {
4298
4958
  this.lastPresent = e;
4299
- let t = this.offlineMat, n = this.scaleUniform, r = this.sharpnessUniform, i = this.set.hasHeight && !this.triplanar && this.parallaxScale.value > 0, a = K(), o = i ? ua(this.set.heightTarget.texture, a, this.parallaxScale, da) : void 0, s = a.dFdx(), c = a.dFdy(), l = (e) => i ? U(e, o).grad(s, c) : U(e), u = (e) => this.triplanar ? sa(this.set.texture(e), n, r) : l(this.set.texture(e)), d = e.has("normal") ? this.triplanar ? ca(this.set.texture("normal"), n, r) : ce(l(this.set.texture("normal")).xyz, k(1)) : le;
4959
+ let t = this.offlineMat, n = ze[this.matType], r = this.scaleUniform, i = this.sharpnessUniform, a = this.set.hasHeight && !this.triplanar && this.parallaxScale.value > 0, o = W(), s = a ? Ha(this.set.heightTarget.texture, o, this.parallaxScale, Ua) : void 0, c = o.dFdx(), l = o.dFdy(), u = (e) => a ? V(e, s).grad(c, l) : V(e), d = (e) => this.triplanar ? za(this.set.texture(e), r, i) : u(this.set.texture(e)), f = e.has("normal") ? this.triplanar ? Ba(this.set.texture("normal"), r, i) : me(u(this.set.texture("normal")).xyz, k(1)) : he;
4300
4960
  if (this.debugNormals) {
4301
- t.colorNode = J(0, 0, 0), t.emissiveNode = d.normalize().mul(.5).add(.5), t.roughnessNode = t.metalnessNode = t.aoNode = t.normalNode = null, t.needsUpdate = !0;
4961
+ t.colorNode = K(0, 0, 0), t.emissiveNode = f.normalize().mul(.5).add(.5), t.roughnessNode = t.metalnessNode = t.aoNode = t.normalNode = null, t.needsUpdate = !0;
4302
4962
  return;
4303
4963
  }
4304
- t.colorNode = e.has("baseColor") ? u("baseColor").mul(this.colorTint) : null, t.roughnessNode = e.has("roughness") ? u("roughness").r.mul(this.roughnessFactor) : null, t.metalnessNode = e.has("metallic") ? u("metallic").r.mul(this.metalnessFactor) : null;
4305
- let f = g("vertexAo", "float");
4306
- t.aoNode = e.has("ambientOcclusion") ? u("ambientOcclusion").r.mul(f) : f, t.normalNode = e.has("normal") ? d : null, t.emissiveNode = e.has("emission") ? u("emission") : null, t.needsUpdate = !0;
4964
+ if (t.colorNode = e.has("baseColor") ? d("baseColor").mul(this.colorTint) : null, t.normalNode = e.has("normal") ? f : null, n.roughMetal && (t.roughnessNode = e.has("roughness") ? d("roughness").r.mul(this.roughnessFactor) : null, t.metalnessNode = e.has("metallic") ? d("metallic").r.mul(this.metalnessFactor) : null), n.ao) {
4965
+ let n = b("vertexAo", "float");
4966
+ t.aoNode = e.has("ambientOcclusion") ? d("ambientOcclusion").r.mul(n) : n;
4967
+ }
4968
+ n.emissive && (t.emissiveNode = e.has("emission") ? d("emission") : null), t.needsUpdate = !0;
4307
4969
  }
4308
4970
  dispose() {
4309
4971
  this.set.dispose(), this.offlineMat.dispose(), this.material_ !== this.offlineMat && this.material_.dispose();
4310
4972
  }
4311
- }, pa = class {
4973
+ };
4974
+ //#endregion
4975
+ //#region src/graph/mesh-material.ts
4976
+ function Ka(t) {
4977
+ let n = { side: e.DoubleSide };
4978
+ switch (t) {
4979
+ case "standard": return new e.MeshStandardMaterial(n);
4980
+ case "lambert": return new e.MeshLambertMaterial(n);
4981
+ case "phong": return new e.MeshPhongMaterial(n);
4982
+ case "toon": return new e.MeshToonMaterial(n);
4983
+ case "matcap": return new e.MeshMatcapMaterial(n);
4984
+ default: return new e.MeshPhysicalMaterial(n);
4985
+ }
4986
+ }
4987
+ function qa(e, t) {
4988
+ let n = Ni(e), r = ze[n.type], i = Ka(n.type), a = i, o = (e) => t.get(e), s = o("baseColor");
4989
+ s ? (a.map = s, a.color.set(16777215)) : a.color.set(n.baseColor);
4990
+ let c = o("normal");
4991
+ if (c && (a.normalMap = c), n.alpha < 1 && (a.transparent = !0, a.opacity = n.alpha), r.ao) {
4992
+ let e = o("ambientOcclusion");
4993
+ e && (a.aoMap = e);
4994
+ }
4995
+ if (r.emissive) {
4996
+ let e = o("emission");
4997
+ e ? (a.emissiveMap = e, a.emissive.set(16777215), a.emissiveIntensity = 1) : a.emissive.set(n.emission);
4998
+ }
4999
+ if (r.roughMetal) {
5000
+ let e = o("roughness");
5001
+ e ? (a.roughnessMap = e, a.roughness = 1) : a.roughness = n.roughness;
5002
+ let t = o("metallic");
5003
+ t ? (a.metalnessMap = t, a.metalness = 1) : a.metalness = n.metallic;
5004
+ }
5005
+ return r.physicalLobes && (a.ior = n.ior, a.clearcoat = n.coat, a.clearcoatRoughness = n.coatRoughness, a.sheen = n.sheen, n.sheen > 0 && a.sheenColor.set(16777215), a.sheenRoughness = n.sheenRoughness, a.transmission = n.transmission), n.type === "phong" && (a.shininess = n.shininess, a.specular.set(n.specular)), n.type === "toon" && (a.gradientMap = wi(n.gradientSteps)), n.type === "matcap" && (a.matcap = Ti(n.matcap)), i;
5006
+ }
5007
+ //#endregion
5008
+ //#region src/runtime.ts
5009
+ var Ja = class {
4312
5010
  graph;
4313
5011
  surface;
4314
5012
  service;
4315
5013
  constructor(e = {}) {
4316
- this.service = e.bakeService ?? aa, this.graph = new ji(e.document, e.registry ?? ei), this.surface = new fa(this.graph, this.service, e.source);
5014
+ this.service = e.bakeService ?? La, this.graph = new la(e.document, e.registry ?? Si), this.surface = new Ga(this.graph, this.service, e.source);
4317
5015
  }
4318
- get material() {
5016
+ getNodeMaterial() {
4319
5017
  return this.surface.material;
4320
5018
  }
5019
+ getMeshMaterial() {
5020
+ return qa(this.graph.document, { get: (e) => this.surface.getChannelTexture(e) });
5021
+ }
5022
+ releaseCaches() {
5023
+ return this.surface.releaseCaches();
5024
+ }
4321
5025
  get lastError() {
4322
5026
  return this.surface.lastError ?? this.graph.lastError;
4323
5027
  }
@@ -4330,12 +5034,6 @@ var da = 12, fa = class {
4330
5034
  setRenderer(e) {
4331
5035
  return this.service.attachRenderer(e), this;
4332
5036
  }
4333
- setBackend(e) {
4334
- return this.surface.setBackend(e), this;
4335
- }
4336
- getBackend() {
4337
- return this.surface.getBackend();
4338
- }
4339
5037
  fromDocument(e) {
4340
5038
  return this.setDocument(e);
4341
5039
  }
@@ -4369,48 +5067,48 @@ var da = 12, fa = class {
4369
5067
  };
4370
5068
  //#endregion
4371
5069
  //#region src/topology.ts
4372
- function ma(e) {
4373
- return Array.isArray(e) ? `[${e.map(ma).join(",")}]` : e && typeof e == "object" ? `{${Object.entries(e).sort(([e], [t]) => e.localeCompare(t)).map(([e, t]) => `${e}:${ma(t)}`).join(",")}}` : JSON.stringify(e);
5070
+ function Ya(e) {
5071
+ return Array.isArray(e) ? `[${e.map(Ya).join(",")}]` : e && typeof e == "object" ? `{${Object.entries(e).sort(([e], [t]) => e.localeCompare(t)).map(([e, t]) => `${e}:${Ya(t)}`).join(",")}}` : JSON.stringify(e);
4374
5072
  }
4375
- function ha(e, t) {
5073
+ function Xa(e, t) {
4376
5074
  let n = t.get(e.type), r = n.paramsFor ? n.paramsFor(e.params) : n.params, i = {};
4377
5075
  for (let t of r) (t.type === "int" || t.type === "bool" || t.type === "select" || t.bakeStructural) && (i[t.key] = e.params[t.key]);
4378
5076
  return i;
4379
5077
  }
4380
- function ga(e, t) {
5078
+ function Za(e, t) {
4381
5079
  return {
4382
5080
  id: e.id,
4383
5081
  type: e.type,
4384
5082
  enabled: e.enabled,
4385
5083
  ports: Q(e, t),
4386
- params: ha(e, t),
4387
- subgraph: e.subgraph ? _a(e.subgraph, t) : null
5084
+ params: Xa(e, t),
5085
+ subgraph: e.subgraph ? Qa(e.subgraph, t) : null
4388
5086
  };
4389
5087
  }
4390
- function _a(e, t) {
5088
+ function Qa(e, t) {
4391
5089
  return {
4392
5090
  version: e.version,
4393
- nodes: e.nodes.map((e) => ga(e, t)).sort((e, t) => String(e.id).localeCompare(String(t.id))),
4394
- edges: [...e.edges].sort((e, t) => ma(e).localeCompare(ma(t)))
5091
+ nodes: e.nodes.map((e) => Za(e, t)).sort((e, t) => String(e.id).localeCompare(String(t.id))),
5092
+ edges: [...e.edges].sort((e, t) => Ya(e).localeCompare(Ya(t)))
4395
5093
  };
4396
5094
  }
4397
- function va(e, t) {
4398
- return ma(_a(e, t));
5095
+ function $a(e, t) {
5096
+ return Ya(Qa(e, t));
4399
5097
  }
4400
5098
  //#endregion
4401
5099
  //#region src/graph/tiling-test.ts
4402
- function ya(e) {
5100
+ function eo(e) {
4403
5101
  return {
4404
- version: 2,
5102
+ version: 4,
4405
5103
  nodes: [
4406
5104
  {
4407
5105
  id: "n",
4408
5106
  type: "tileable-noise",
4409
5107
  params: {
4410
- noiseType: e,
4411
5108
  scale: 5,
4412
5109
  octaves: 4,
4413
- gain: .5
5110
+ gain: .5,
5111
+ ...e
4414
5112
  },
4415
5113
  position: {
4416
5114
  x: 0,
@@ -4420,8 +5118,8 @@ function ya(e) {
4420
5118
  },
4421
5119
  {
4422
5120
  id: "pr",
4423
- type: "principled-bsdf",
4424
- params: {},
5121
+ type: "shader-material",
5122
+ params: { materialType: "physical" },
4425
5123
  position: {
4426
5124
  x: 300,
4427
5125
  y: 0
@@ -4452,7 +5150,7 @@ function ya(e) {
4452
5150
  }]
4453
5151
  };
4454
5152
  }
4455
- function ba(e, t) {
5153
+ function to(e, t) {
4456
5154
  let n = (n, r) => e.data[(r * t + n) * 4], r = 0, i = 0;
4457
5155
  for (let e = 0; e < t; e++) {
4458
5156
  r += Math.abs(n(t - 1, e) - n(0, e));
@@ -4472,12 +5170,15 @@ function ba(e, t) {
4472
5170
  ratioV: a / Math.max(o, .001)
4473
5171
  };
4474
5172
  }
4475
- async function xa(e, t, n = {}) {
4476
- let r = n.size ?? 256, i = n.threshold ?? 3, a = n.channel ?? "baseColor", o = t.get("tileable-noise").params.find((e) => e.key === "noiseType"), s = n.types ?? o?.options ?? [], c = [];
4477
- for (let o of s) {
4478
- let s = new ji(ya(o), t), l = await e.readImage(s, a, r);
4479
- if (!l) {
4480
- c.push({
5173
+ async function no(e, t, n = {}) {
5174
+ let r = n.size ?? 256, i = n.threshold ?? 3, a = n.channel ?? "baseColor", o = t.get("tileable-noise").params, s = o.find((e) => e.key === "noiseType")?.options ?? [], c = (o.find((e) => e.key === "preset")?.options ?? []).filter((e) => e !== "none"), l = new Set(c), u = n.types ?? [...s, ...c], d = [];
5175
+ for (let o of u) {
5176
+ let s = new la(eo(l.has(o) ? {
5177
+ noiseType: "perlin-fbm",
5178
+ preset: o
5179
+ } : { noiseType: o }), t), c = await e.readImage(s, a, r);
5180
+ if (!c) {
5181
+ d.push({
4481
5182
  type: o,
4482
5183
  ratioH: NaN,
4483
5184
  ratioV: NaN,
@@ -4489,15 +5190,15 @@ async function xa(e, t, n = {}) {
4489
5190
  });
4490
5191
  continue;
4491
5192
  }
4492
- n.onTile && await n.onTile(o, l);
4493
- let u = ba(l, r);
4494
- c.push({
5193
+ n.onTile && await n.onTile(o, c);
5194
+ let u = to(c, r);
5195
+ d.push({
4495
5196
  type: o,
4496
5197
  ...u,
4497
5198
  pass: u.ratioH <= i && u.ratioV <= i
4498
5199
  });
4499
5200
  }
4500
- return c;
5201
+ return d;
4501
5202
  }
4502
5203
  //#endregion
4503
- export { ra as BakedTextureSet, Le as COERCION_MATRIX, Ae as CURVE_CHANNELS, ke as CURVE_IDENTITY, Ne as GROUP_INPUT_TYPE, Pe as GROUP_OUTPUT_TYPE, Me as GROUP_TYPE, wi as MATERIAL_DOCUMENT_VERSION, Fe as MATERIAL_OUTPUT_TYPE, ia as MaterialBakeService, pa as MaterialGraphRuntime, ji as MaterialGraphSession, Qr as NodeRegistry, Ie as PBR_SOCKETS, ea as SURFACE_CHANNELS, fa as TexturedSurface, aa as bakeService, Ti as cloneMaterialDocument, Re as coercionFor, gi as compileGraph, ui as compileSockets, li as countGraphNodes, Ei as createDefaultMaterialDocument, $r as createDefaultRegistry, va as createMaterialTopologyKey, je as curveToArray, ei as defaultRegistry, Di as migrateMaterialDocument, mi as newSurfaceMaterial, Zr as nodeParamDefs, Q as nodePorts, oi as readOutputResolution, xa as runTilingTest };
5204
+ export { Fa as BakedTextureSet, Ke as COERCION_MATRIX, Ie as CURVE_CHANNELS, Fe as CURVE_IDENTITY, He as GROUP_INPUT_TYPE, Ue as GROUP_OUTPUT_TYPE, Ve as GROUP_TYPE, $i as MATERIAL_DOCUMENT_VERSION, q as MATERIAL_OUTPUT_TYPE, Re as MATERIAL_TYPES, ze as MATERIAL_TYPE_CAPS, Ia as MaterialBakeService, Ja as MaterialGraphRuntime, la as MaterialGraphSession, bi as NodeRegistry, Ge as PBR_SOCKETS, We as SHADER_MATERIAL_TYPE, Ma as SURFACE_CHANNELS, Ga as TexturedSurface, La as bakeService, qa as buildMeshMaterial, ea as cloneMaterialDocument, qe as coercionFor, Gi as compileGraph, Li as compileSockets, Ii as countGraphNodes, ta as createDefaultMaterialDocument, xi as createDefaultRegistry, $a as createMaterialTopologyKey, Le as curveToArray, Si as defaultRegistry, aa as migrateMaterialDocument, Ui as newSurfaceMaterial, yi as nodeParamDefs, Q as nodePorts, Be as normalizeMaterialType, Ni as readMaterialConfig, Mi as readMaterialSurface, ji as readOutputResolution, no as runTilingTest };