material-designer-runtime 0.1.0 → 0.1.2

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 se, normalLocal as ce, normalMap as le, normalWorld as ue, normalize as de, parallaxDirection as fe, positionLocal as pe, positionWorld as me, pow as R, radians as he, reflect as ge, round as _e, sRGBTransferOETF as ve, saturate as ye, select as z, sign as be, sin as B, sinh as xe, smoothstep as V, sqrt as Se, step as Ce, tan as we, tanh as Te, texture as H, trunc as Ee, uint as U, uniform as W, uniformArray as De, uv as G, vec2 as K, vec3 as q, vec4 as Oe } from "three/tsl";
5
- var ke = {
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 ke = {
29
29
  toNode: "out",
30
30
  toInput: "surface"
31
31
  }]
32
- }, Ae = [
32
+ }, Fe = [
33
33
  0,
34
34
  .25,
35
35
  .5,
36
36
  .75,
37
37
  1
38
- ], je = [
38
+ ], Ie = [
39
39
  "C",
40
40
  "R",
41
41
  "G",
42
42
  "B"
43
43
  ];
44
- function Me(e) {
45
- let t = (e) => Array.from({ length: 5 }, (t, n) => e?.[n] ?? Ae[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 Me(e) {
50
50
  ...t(e?.B)
51
51
  ];
52
52
  }
53
- var Ne = "group", Pe = "group-input", Fe = "group-output", Ie = "material-output", Le = [
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
- ], Re = {
108
+ ], Ke = {
61
109
  float: {
62
110
  float: "identity",
63
111
  vector: "float-to-vector",
@@ -75,28 +123,28 @@ var Ne = "group", Pe = "group-input", Fe = "group-output", Ie = "material-output
75
123
  },
76
124
  shader: { shader: "identity" }
77
125
  };
78
- function ze(e, t) {
79
- return Re[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 J = (e, t) => e.shiftLeft(t).bitOr(e.shiftRight(32 - t));
84
- function Be(e, t, n) {
85
- let r = 3735928584, i = U(r).toVar(), a = U(r).toVar(), o = U(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(J(a, 14))), i.assign(i.bitXor(o)), i.assign(i.sub(J(o, 11))), a.assign(a.bitXor(i)), a.assign(a.sub(J(i, 25))), o.assign(o.bitXor(a)), o.assign(o.sub(J(a, 16))), i.assign(i.bitXor(o)), i.assign(i.sub(J(o, 4))), a.assign(a.bitXor(i)), a.assign(a.sub(J(i, 14))), o.assign(o.bitXor(a)), o.assign(o.sub(J(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 Ve = (e, t, n) => Be(U(e), U(t), U(n)), He = (e) => e.mul(e).mul(e).mul(e.mul(e.mul(6).sub(15)).add(10)), Ue = (e, t) => z(t.notEqual(U(0)), e.negate(), e);
89
- function We(e, t, n, r) {
90
- let i = e.bitAnd(U(15)).toVar(), a = z(i.lessThan(U(8)), t, n), o = z(i.equal(U(12)).or(i.equal(U(14))), t, r), s = z(i.lessThan(U(4)), n, o);
91
- return Ue(a, i.bitAnd(U(1))).add(Ue(s, i.bitAnd(U(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 Ge(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 Ke(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 = He(i), d = He(a), f = He(o), p = (e, t, n) => We(Ve(s.add(e), c.add(t), l.add(n)), i.sub(e), a.sub(t), o.sub(n));
99
- return Ge([
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 Ke(e) {
107
155
  p(1, 1, 1)
108
156
  ], u, d, f);
109
157
  }
110
- var qe = (e) => Ke(e).mul(.982);
111
- function Je(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(qe(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 Ye = {
169
+ var it = {
122
170
  type: "fbm",
123
171
  nodeClass: "texture",
124
172
  label: "Noise (FBM)",
@@ -169,9 +217,9 @@ var Ye = {
169
217
  }
170
218
  ],
171
219
  build(e) {
172
- return { field: Je((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
- }, Xe = {
222
+ }, at = {
175
223
  type: "domain-warp",
176
224
  nodeClass: "vector",
177
225
  label: "Domain Warp",
@@ -201,163 +249,165 @@ var Ye = {
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 = se(n.add(q(11.3, 0, 0))), i = se(n.add(q(0, 47.7, 0))), a = se(n.add(q(0, 0, 93.1)));
205
- return { coord: t.add(q(r, i, a).mul(e.uniforms.amount)) };
206
- }
207
- }, Ze = (e) => L(e.mul(34).add(1).mul(e), 289), Qe = (e) => e.mul(e).mul(e).mul(e.mul(e.mul(6).sub(15)).add(10)), $e = d(([e, t]) => {
208
- let n = A(e.xyxy).add(Oe(0, 0, 1, 1)), r = j(e.xyxy).sub(Oe(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(Ze(Ze(a).add(o)).mul(.0243902439)).mul(2).sub(1), u = f(l).sub(.5), d = l.sub(A(l.add(.5))), p = K(d.x, u.x), m = K(d.y, u.y), h = K(d.z, u.z), g = K(d.w, u.w), _ = k(1.79284291400159).sub(k(.85373472095314).mul(Oe(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, K(s.x, c.x)), y = D(m, K(s.y, c.y)), b = D(h, K(s.z, c.z)), x = D(g, K(s.w, c.w)), S = Qe(r.xy), C = I(K(v, b), K(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 et(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 = K(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(V(.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($e(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 tt(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(K(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(V(.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 nt = 1 / 2147483648, rt = 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 q(k(r.bitAnd(o)).mul(nt), k(i.bitAnd(o)).mul(nt), k(a.bitAnd(o)).mul(nt));
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 it(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 at(e, t, n, r) {
251
- return rt(it(e, n), it(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 ot(e, t, n, r) {
254
- return rt(it(e, n), it(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 st(e, t, n, r, i) {
257
- return rt(it(e, r), it(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 ct(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 = at(o, s, t, n), l = at(o.add(1), s, t, n), u = at(o, s.add(1), t, n), d = at(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 lt = 2;
268
- function ut(e, t, n) {
269
- let r = A(e), i = e.sub(r), a = M(r.x), o = M(r.y), s = q(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 = ot(a.add(e), o.add(r), t, n), l = q(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 dt(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 = ot(a.add(e), o.add(r), t, n), u = R(V(1.414, 0, N(K(e, r).sub(i).add(K(l.x, l.y)))), lt);
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 ft = (e, t) => $e(e, K(t, t)), pt = d(([e, t]) => {
287
- let n = k(.1), r = ft(e.add(K(n, 0)), t), i = ft(e.add(K(0, n)), t), a = ft(e.sub(K(n, 0)), t), o = ft(e.sub(K(0, n)), t);
288
- return K(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 mt(e, t, n) {
291
- let r = pt(e, t);
292
- return q(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 ht(e, t, n) {
295
- return b(pt(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 gt(e, t, n) {
298
- let r = pt(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 _t(e, t, n) {
302
- let r = pt(e, t).mul(.4);
303
- return ft(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 vt = 6.283185307179586, yt = Math.PI, bt = 8, xt = 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(K(a, e));
311
- for (let e = 0; e < bt; e++) {
312
- let a = st(l, u, e * 2, t, t), o = st(l, u, e * 2 + 1, t, t), s = i.add(o.x.sub(.5).mul(yt).mul(r)), f = d.sub(K(a.x, a.y)), p = D(f, f), m = O(p.mul(-yt)).mul(k(.5).add(S(p.mul(yt)).mul(.5))), h = D(f, K(S(s), B(s)).mul(n)).mul(vt), g = I(k(-1), k(1), Ce(.5, a.z)), _ = k(1).sub(Ce(1, p));
313
- c.addAssign(B(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 St(e, t, n) {
321
- let r = K(e.x.add(e.y.mul(.5)), e.y), i = A(r), a = r.sub(i), o = Ce(a.y, a.x), s = K(o, k(1).sub(o)), c = K(i.x.sub(i.y.mul(.5)), i.y), l = K(c.x.add(s.x).sub(s.y.mul(.5)), c.y.add(s.y)), u = K(c.x.add(.5), c.y.add(1)), d = e.sub(c), f = e.sub(l), p = e.sub(u), m = L(q(c.x, l.x, u.x), k(t)), h = L(q(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 = B(y), w = K(x.x, C.x), T = K(x.y, C.y), E = K(x.z, C.z), ee = P(k(.8).sub(q(D(d, d), D(f, f), D(p, p))), 0), O = ee.mul(ee);
324
- return b(D(O.mul(O), q(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 Ct = 6.283185307179586;
329
- function wt(e, t, n) {
330
- let r = A(e), i = j(e).sub(.5), a = at(M(r.x), M(r.y), t, n).mul(Ct), o = S(a), s = B(a), c = o.mul(i.x).sub(s.mul(i.y)), l = s.mul(i.x).add(o.mul(i.y)), u = V(.25, 0, D(K(c, l), K(c, l)));
331
- return b(B(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 Tt(e, t, n) {
336
- let r = pt(e, t), i = $e(e.add(r.mul(.6)), K(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 Et = [
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"
402
+ "stone",
403
+ "erosion"
354
404
  ], Y = [
355
405
  "octaves",
356
406
  "gain",
357
407
  "lacunarity",
358
408
  "antialias",
359
409
  "tileSize"
360
- ], Dt = {
410
+ ], It = {
361
411
  "perlin-fbm": ["aspect", ...Y],
362
412
  value: ["aspect", ...Y],
363
413
  worley: Y,
@@ -375,25 +425,25 @@ var Et = [
375
425
  "tileSize"
376
426
  ],
377
427
  curl: []
378
- }, Ot = {
379
- value: ct,
380
- worley: ut,
381
- "voronoi-smooth": dt,
382
- stone: _t,
383
- paper: ht,
384
- wool: gt,
385
- wavelet: wt,
386
- erosion: Tt
387
- }, kt = [{
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
- }], At = [{
440
+ }], zt = [{
391
441
  key: "field",
392
442
  kind: "float"
393
443
  }, {
394
444
  key: "vector",
395
445
  kind: "vector"
396
- }], jt = {
446
+ }], Bt = {
397
447
  type: "tileable-noise",
398
448
  nodeClass: "texture",
399
449
  label: "Tileable Noise",
@@ -409,11 +459,18 @@ var Et = [
409
459
  params: [
410
460
  {
411
461
  key: "noiseType",
412
- label: "type",
462
+ label: "algorithm",
413
463
  type: "select",
414
- options: Et,
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 Et = [
516
573
  key: "coord",
517
574
  kind: "vector"
518
575
  }],
519
- outputs: e.noiseType === "curl" ? At : kt
576
+ outputs: e.noiseType === "perlin-fbm" && e.preset === "curl" ? zt : Rt
520
577
  };
521
578
  },
522
579
  paramsFor(e) {
523
- let t = Dt[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 jt.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: Je(t.mul(o), n, a, e.uniforms.lacunarity) };
533
- let s = K(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 = mt(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: tt(s, e, e, n, a, St, 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: xt(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 = Ot[i];
550
- return p ? { field: tt(s, i === "value" ? f : u, u, n, a, p, c, r) } : { field: et(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
- }, Mt = 4294967295;
553
- function Nt(e) {
554
- let t = ne(e.mul(K(141421356, 2718281828)));
555
- return k(t.x.bitXor(t.y).mul(U(3141592653))).div(Mt);
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 Pt(e) {
558
- return j(k(52.9829189).mul(j(D(e, K(.06711056, .00583715)))));
614
+ function Ut(e) {
615
+ return j(k(52.9829189).mul(j(O(e, G(.06711056, .00583715)))));
559
616
  }
560
- function Ft(e) {
561
- let t = U(e.x), n = U(e.y);
562
- return k(t.mul(U(3242174889)).add(n.mul(U(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 It(e) {
621
+ function Gt(e) {
565
622
  let t = k(0);
566
- for (let n = 0; n < 9; n++) t = t.add(Nt(e.add(K(n % 3 - 1, Math.floor(n / 3) - 1))));
567
- return k(.9).mul(k(1.125).mul(Nt(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 Lt = 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 = z(n.bitAnd(t).notEqual(M(0)), M(1), M(0)), o = z(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 Rt(e) {
580
- let t = Lt(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 zt = 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(B(n.x.mul(51024)).mul(3104))), n.y.assign(A(B(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(K(r.y.negate(), r.x).mul(B(i))), r = r.add(B(n.x.sub(n.y))), r = r.mul(.5).add(.5);
588
- let a = B(n.x.add(r.y.mul(3.1415))).add(B(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 = V(-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 Bt(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, zt(n, r)), n = K(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 Vt = {
653
+ var Xt = {
597
654
  type: "screen-noise",
598
655
  nodeClass: "texture",
599
656
  label: "Screen Noise",
@@ -627,16 +684,17 @@ var Vt = {
627
684
  default: 512
628
685
  }],
629
686
  build(e) {
630
- let t = e.inputs.coord ?? e.coord, n = K(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: Rt(A(i)) };
633
- case "ign": return { field: Pt(A(i)) };
634
- case "golden-ign": return { field: Ft(A(i)) };
635
- case "scratches": return { field: Bt(n.mul(5), k(3)) };
636
- default: return { field: It(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
- }, Ht = {
697
+ }, Zt = {
640
698
  type: "tileable-warp",
641
699
  nodeClass: "vector",
642
700
  label: "Tileable Warp",
@@ -666,74 +724,74 @@ var Vt = {
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 = se(r.add(q(11.3, 0, 0))), a = se(r.add(q(0, 47.7, 0))), o = se(r.add(q(0, 0, 93.1)));
672
- return { coord: t.add(q(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 = K(t.x, t.y), a = K(r, r), o = $e(i.mul(r), a), s = $e(i.mul(r).add(K(5.2, 1.3)), a), c = i.add(K(o, s).mul(n));
675
- return { coord: q(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
- }, Ut = 1 / 2147483648;
678
- function Wt(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 q(k(r.bitAnd(o)).mul(Ut), k(i.bitAnd(o)).mul(Ut), k(a.bitAnd(o)).mul(Ut));
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 Gt(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 Kt(e, t, n, r) {
688
- return typeof r == "number" && r <= 0 ? Wt(e, t, n) : Wt(Gt(e, r), Gt(t, r), Gt(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 qt(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 R(R(i.x, e).add(R(i.y, e)).add(R(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 Jt(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 = q(0, 0, 0).toVar(), p = q(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 = q(o, i, e), h = m.add(Kt(c.add(o), l.add(i), u.add(e), a).mul(t)), g = qt(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" ? Kt(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 Yt(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 = q(0, 0, 0).toVar(), m = q(0, 0, 0).toVar(), h = q(0, 0, 0).toVar(), g = q(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 _ = q(o, i, e), v = _.add(Kt(c.add(o), l.add(i), u.add(e), a).mul(t)), y = qt(v, s, n, r), b = y.lessThan(d).toVar(), x = y.lessThan(f).toVar(), S = z(b, d, z(x, y, f)), C = z(b, p, z(x, _, m)), w = z(b, h, z(x, v, g)), T = z(b, y, d), E = z(b, _, p), ee = z(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" ? Kt(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 Xt = 1;
721
- function Zt(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 = q(0, 0, 0).toVar(), h = q(0, 0, 0).toVar(), g = k(-1).toVar();
724
- for (let e = -1; e <= Xt; e++) for (let i = -1; i <= Xt; i++) for (let a = -1; a <= Xt; a++) {
725
- let s = q(a, i, e), _ = Kt(l.add(a), u.add(i), d.add(e), o), v = s.add(_.mul(t)), y = qt(v, c, n, r);
726
- g.assign(z(g.equal(-1), k(1), V(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 Qt = (e, t, n, r, i = 0) => Jt(e, t, n, r, "distance", i), $t = (e, t, n, r, i = 0) => Jt(e, t, n, r, "color", i), en = (e, t, n, r, i = 0) => Jt(e, t, n, r, "position", i), tn = (e, t, n, r, i = 0) => Yt(e, t, n, r, "distance", i), nn = (e, t, n, r, i = 0) => Yt(e, t, n, r, "color", i), rn = (e, t, n, r, i = 0) => Yt(e, t, n, r, "position", i), an = (e, t, n, r, i, a = 0) => Zt(e, t, n, r, i, "distance", a), on = (e, t, n, r, i, a = 0) => Zt(e, t, n, r, i, "color", a), sn = (e, t, n, r, i, a = 0) => Zt(e, t, n, r, i, "position", a);
734
- function cn(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) => q(e, r, c).add(Kt(a.add(e), o.add(r), s.add(c), n).mul(t)).sub(i), l = q(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 cn(e, t, n = 0) {
748
806
  }
749
807
  //#endregion
750
808
  //#region src/tsl/lloyd-points.ts
751
- function ln(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 un(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 dn(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] = ln(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 dn(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 = un(a[i], u, e), m = un(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] + un(u, a[p], e), n[p] += o[p] + un(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 dn(e, t, n, r = 0) {
789
847
  }
790
848
  //#endregion
791
849
  //#region src/tsl/relaxed-voronoi.ts
792
- function fn(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) => q(e, n, 0).add(t(i.add(e), a.add(n))).sub(r), s = q(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 fn(e, t) {
804
862
  return l;
805
863
  })();
806
864
  }
807
- function pn(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) => q(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 pn(e, t, n) {
816
874
  }
817
875
  //#endregion
818
876
  //#region src/graph/nodes/texture/voronoi.ts
819
- var mn = [
877
+ var Cn = [
820
878
  "euclidean",
821
879
  "manhattan",
822
880
  "chebychev",
823
881
  "minkowski"
824
- ], hn = [
882
+ ], wn = [
825
883
  "f1",
826
884
  "f2",
827
885
  "smooth-f1",
828
886
  "distance-to-edge"
829
- ], gn = [
887
+ ], Tn = [
830
888
  {
831
889
  key: "distance",
832
890
  label: "Distance",
@@ -842,19 +900,27 @@ var mn = [
842
900
  label: "Position",
843
901
  kind: "vector"
844
902
  }
845
- ], _n = [{
846
- key: "distance",
847
- label: "Distance",
848
- kind: "float"
849
- }, {
850
- key: "random",
851
- label: "Random",
852
- kind: "float"
853
- }], vn = [{
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 yn(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 yn(e) {
862
928
  }
863
929
  return t;
864
930
  }
865
- var bn = {
931
+ var kn = {
866
932
  type: "voronoi",
867
933
  nodeClass: "texture",
868
934
  label: "Voronoi",
869
- inputs: vn,
870
- outputs: gn,
935
+ inputs: Dn,
936
+ outputs: Tn,
871
937
  params: [
872
938
  {
873
939
  key: "scale",
@@ -891,14 +957,14 @@ var bn = {
891
957
  key: "metric",
892
958
  label: "metric",
893
959
  type: "select",
894
- options: mn,
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: hn,
967
+ options: wn,
902
968
  default: "f1"
903
969
  },
904
970
  {
@@ -919,6 +985,15 @@ var bn = {
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 bn = {
931
1006
  ],
932
1007
  declare(e) {
933
1008
  return {
934
- inputs: vn,
935
- outputs: (e.feature ?? "f1") === "distance-to-edge" ? _n : gn
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"), bn.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, mn.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 = dn(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 = De(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 = De(yn(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: fn(n, u),
955
- random: pn(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: cn(f, r, p),
962
- random: $t(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: tn(f, r, n, i, p),
966
- color: nn(f, r, n, i, p),
967
- position: rn(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: an(f, r, n, i, a, p),
971
- color: on(f, r, n, i, a, p),
972
- position: sn(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: Qt(f, r, n, i, p),
976
- color: $t(f, r, n, i, p),
977
- position: en(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
- }, xn = {
1064
+ }, An = {
982
1065
  type: "checker",
983
1066
  nodeClass: "texture",
984
1067
  label: "Checker",
@@ -1030,56 +1113,60 @@ var bn = {
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: z(n, e.inputs.color1 ?? e.uniforms.color1, e.inputs.color2 ?? e.uniforms.color2),
1036
- fac: z(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
- }, Sn = 6.283185307179586;
1040
- function Cn(e, t, n) {
1041
- let { columns: r, rows: i, offsetFreq: a } = t, o = d(() => {
1042
- let t = K(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 = z(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 = st(o, u, 0, r, i), h = st(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(Sn * .5).negate(), w = S(C), T = B(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(K(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(z(oe, h.y, c)), s.assign(z(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 K(V(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 wn(e, t, n, r, i) {
1058
- let a = t, o = n, s = d(() => {
1059
- let t = K(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 = z(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(K(e.x.sub(r), e.y.sub(p))), h = m.lessThan(s);
1064
- s.assign(z(h, m, s)), c.assign(z(h, r, c)), l.assign(z(h, p, l)), u.assign(z(h, at(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 = z(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(K(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, z(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 K(V(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 Tn = {
1169
+ var Pn = {
1083
1170
  type: "tile",
1084
1171
  nodeClass: "texture",
1085
1172
  label: "Tile Generator",
@@ -1087,15 +1174,28 @@ var Tn = {
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 Tn = {
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 } = wn(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 } = Cn(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
- }, En = Math.PI;
1226
- function Dn(e, t, n) {
1227
- let r = t, i = d(() => {
1228
- let t = K(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 = st(p, f, 0, r, r), h = st(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 = z(g, N(K(w, T)), k(1e9)), ee = h.x.sub(.5).mul(2).mul(n.rotRandom).mul(En).negate(), D = S(ee), O = B(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(z(A, te, s)), c.assign(z(A, ne, c)), l.assign(z(A, h.y, l)), u.assign(z(A, _, u)), o.assign(z(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 Oe(s, c, l, u);
1340
+ return Ne(s, c, l, u);
1237
1341
  })();
1238
1342
  return {
1239
- coord: q(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 On = {
1350
+ var Ln = {
1247
1351
  type: "scatter",
1248
1352
  nodeClass: "texture",
1249
1353
  label: "Scatter",
@@ -1325,12 +1429,12 @@ var On = {
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 } = Dn(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 On = {
1338
1442
  size: a
1339
1443
  };
1340
1444
  }
1341
- }, kn = 6.283185307179586;
1342
- function An(e, t, n, r, i) {
1343
- let a = r ?? k(0), o = d(() => {
1344
- let r = N(K(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 = kn / 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 = V(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(kn), t = j(a.mul(27.71)).mul(kn), n = j(a.mul(51.37)).mul(kn), l = B(o.mul(2).add(e)).mul(.5).add(B(o.mul(3).add(t)).mul(.3)).add(B(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 = V(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 = R(b(l.mul(l).oneMinus(), 0, 1), i.dome), d = V(0, .3, c), f = u.mul(d);
1353
- return q(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 jn = {
1464
+ var Bn = {
1361
1465
  type: "shape",
1362
1466
  nodeClass: "texture",
1363
1467
  label: "Shape",
@@ -1424,18 +1528,18 @@ var jn = {
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 } = An(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
- }, Mn = Math.PI * 2;
1438
- function Nn(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 Nn(e, t) {
1452
1556
  a = n.add(r).mul(.5);
1453
1557
  break;
1454
1558
  case 4:
1455
- a = h(r, n).div(Mn).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 Nn(e, t) {
1468
1572
  }
1469
1573
  //#endregion
1470
1574
  //#region src/graph/nodes/texture/gradient.ts
1471
- var Pn = [
1575
+ var Un = [
1472
1576
  "linear",
1473
1577
  "quadratic",
1474
1578
  "easing",
@@ -1476,7 +1580,7 @@ var Pn = [
1476
1580
  "radial",
1477
1581
  "quadratic-sphere",
1478
1582
  "sphere"
1479
- ], Fn = {
1583
+ ], Wn = {
1480
1584
  type: "gradient",
1481
1585
  nodeClass: "texture",
1482
1586
  label: "Gradient",
@@ -1500,15 +1604,15 @@ var Pn = [
1500
1604
  key: "gradientType",
1501
1605
  label: "type",
1502
1606
  type: "select",
1503
- options: Pn,
1607
+ options: Un,
1504
1608
  default: "linear"
1505
1609
  }],
1506
1610
  build(e) {
1507
- return { field: Nn((e.inputs.coord ?? e.coord).mul(e.uniforms.scale), Math.max(0, Pn.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
- }, X = Math.PI * 2, In = Math.PI / 2, Ln = 20, Rn = 10;
1510
- function zn(e, t) {
1511
- if (t === 0) return k(.5).add(B(e.sub(In)).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
1617
  let t = e.div(X);
1514
1618
  return t.sub(A(t));
@@ -1516,52 +1620,52 @@ function zn(e, t) {
1516
1620
  let n = e.div(X);
1517
1621
  return n.sub(A(n.add(.5))).abs().mul(2);
1518
1622
  }
1519
- function Bn(e, t, n, r, i) {
1520
- let a = Math.max(1, Math.round(i.scaleNum * Ln / X)), o = Math.max(1, Math.round(i.scaleNum * Rn / X)), s;
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;
1521
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 = et(K(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 zn(s, i.profile);
1631
+ return Jn(s, i.profile);
1528
1632
  }
1529
- function Vn(e, t, n, r, i, a) {
1530
- let o = (e) => e.sub(_e(e)), s;
1531
- s = a.dir === 0 ? q(k(0), o(e.y), o(e.z)) : a.dir === 1 ? q(o(e.x), k(0), o(e.z)) : a.dir === 2 ? q(o(e.x), o(e.y), k(0)) : q(o(e.x), o(e.y), o(e.z));
1532
- let c = s.length().mul(t).mul(Ln).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 = et(K(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 zn(c, a.profile);
1641
+ return Jn(c, a.profile);
1538
1642
  }
1539
- function Hn(e, t, n, r, i, a, o) {
1540
- if (o.tileable) return o.waveType === 0 ? Bn(e, n, r, a, o) : Vn(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(Ln) : o.dir === 1 ? s.y.mul(Ln) : o.dir === 2 ? s.z.mul(Ln) : s.x.add(s.y).add(s.z).mul(Rn);
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(q(0, 1, 1)) : o.dir === 1 ? e = s.mul(q(1, 0, 1)) : o.dir === 2 && (e = s.mul(q(1, 1, 0))), c = e.length().mul(Ln);
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 = Je(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 zn(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 Un = ["bands", "rings"], Wn = [
1659
+ var Qn = ["bands", "rings"], $n = [
1556
1660
  "x",
1557
1661
  "y",
1558
1662
  "z",
1559
1663
  "diagonal"
1560
- ], Gn = [
1664
+ ], er = [
1561
1665
  "sine",
1562
1666
  "saw",
1563
1667
  "triangle"
1564
- ], Kn = {
1668
+ ], tr = {
1565
1669
  type: "wave",
1566
1670
  nodeClass: "texture",
1567
1671
  label: "Wave",
@@ -1588,21 +1692,21 @@ var Un = ["bands", "rings"], Wn = [
1588
1692
  key: "waveType",
1589
1693
  label: "type",
1590
1694
  type: "select",
1591
- options: Un,
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: Wn,
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: Gn,
1709
+ options: er,
1606
1710
  default: "sine"
1607
1711
  },
1608
1712
  {
@@ -1655,18 +1759,18 @@ var Un = ["bands", "rings"], Wn = [
1655
1759
  ],
1656
1760
  build(e) {
1657
1761
  let t = e.inputs.coord ?? e.coord, n = {
1658
- waveType: Math.max(0, Un.indexOf(e.params.waveType)),
1659
- dir: Math.max(0, Wn.indexOf(e.params.direction)),
1660
- profile: Math.max(0, Gn.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: Hn(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
- }, qn = 6.283185307179586, Jn = {
1773
+ }, nr = 6.283185307179586, rr = {
1670
1774
  type: "anisotropic-stripes",
1671
1775
  nodeClass: "texture",
1672
1776
  label: "Anisotropic Stripes",
@@ -1717,10 +1821,10 @@ var Un = ["bands", "rings"], Wn = [
1717
1821
  }
1718
1822
  ],
1719
1823
  build(e) {
1720
- let t = e.inputs.coord ?? e.coord, n = h(t.z, t.x).div(qn), r = se(q(t.y.mul(.6), n.mul(6), k(0))).mul(e.uniforms.waviness);
1721
- return { field: n.mul(e.uniforms.count).add(r).mul(qn).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
- }, Yn = /* @__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("."), Xn = 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 Un = ["bands", "rings"], Wn = [
1742
1846
  "tanh",
1743
1847
  "radians",
1744
1848
  "degrees"
1745
- ]), Zn = 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
- ]), Qn = {
1855
+ ]), sr = {
1752
1856
  power: ["Base", "Exponent"],
1753
1857
  logarithm: ["Value", "Base"],
1754
1858
  "multiply-add": [
@@ -1781,8 +1885,8 @@ var Un = ["bands", "rings"], Wn = [
1781
1885
  radians: ["Degrees"],
1782
1886
  degrees: ["Radians"]
1783
1887
  };
1784
- function $n(e) {
1785
- let [t, n, r] = Qn[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 $n(e) {
1791
1895
  label: t,
1792
1896
  kind: "float"
1793
1897
  }];
1794
- return Xn.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
- }), Zn.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 er = {
1908
+ var lr = {
1805
1909
  type: "math",
1806
1910
  nodeClass: "converter",
1807
1911
  label: "Math",
@@ -1823,7 +1927,7 @@ var er = {
1823
1927
  key: "op",
1824
1928
  label: "op",
1825
1929
  type: "select",
1826
- options: Yn,
1930
+ options: ir,
1827
1931
  default: "mix"
1828
1932
  },
1829
1933
  {
@@ -1847,7 +1951,7 @@ var er = {
1847
1951
  ],
1848
1952
  declare(e) {
1849
1953
  return {
1850
- inputs: $n(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 er = {
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: z(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: R(t, n) };
1866
- case "logarithm": return { field: z(t.greaterThan(0).and(n.greaterThan(0)), ae(t).div(ae(n)), k(0)) };
1867
- case "sqrt": return { field: Se(t) };
1868
- case "inverse-sqrt": return { field: z(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: z(t.lessThan(n), k(1), k(0)) };
1874
- case "greater-than": return { field: z(t.greaterThan(n), k(1), k(0)) };
1875
- case "sign": return { field: be(t) };
1876
- case "compare": return { field: z(t.sub(n).abs().lessThanEqual(P(r, k(1e-5))), k(1), k(0)) };
1877
- case "smooth-min": return { field: tr(t, n, r) };
1878
- case "smooth-max": return { field: tr(t.negate(), n.negate(), r).negate() };
1879
- case "round": return { field: _e(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: Ee(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: z(n.equal(0), k(0), t.sub(n.mul(Ee(t.div(n))))) };
1885
- case "floored-modulo": return { field: z(n.equal(0), k(0), t.sub(n.mul(A(t.div(n))))) };
1886
- case "wrap": return { field: nr(t, n, r) };
1887
- case "snap": return { field: z(n.equal(0), k(0), A(t.div(n)).mul(n)) };
1888
- case "pingpong": return { field: rr(t, n) };
1889
- case "sine": return { field: B(t) };
1890
- case "cosine": return { field: S(t) };
1891
- case "tangent": return { field: we(t) };
1892
- case "arcsine": return { field: z(t.abs().lessThanEqual(1), m(t), k(0)) };
1893
- case "arccosine": return { field: z(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: xe(t) };
1897
- case "cosh": return { field: C(t) };
1898
- case "tanh": return { field: Te(t) };
1899
- case "radians": return { field: he(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 tr(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 z(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 nr(e, t, n) {
2013
+ function dr(e, t, n) {
1910
2014
  let r = t.sub(n);
1911
- return z(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 rr(e, t) {
2017
+ function fr(e, t) {
1914
2018
  let n = t.mul(2);
1915
- return z(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 ir = {
2023
+ var pr = {
1920
2024
  type: "levels",
1921
2025
  nodeClass: "converter",
1922
2026
  label: "Levels / Remap",
@@ -1955,10 +2059,10 @@ var ir = {
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
- }, ar = {
2065
+ }, mr = {
1962
2066
  type: "color-ramp",
1963
2067
  nodeClass: "converter",
1964
2068
  label: "Color Ramp",
@@ -2003,10 +2107,10 @@ var ir = {
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
- }, or = {
2113
+ }, hr = {
2010
2114
  type: "height-blend",
2011
2115
  nodeClass: "converter",
2012
2116
  label: "Height Blend",
@@ -2061,12 +2165,12 @@ var ir = {
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: V(i.negate(), i, a) };
2171
+ return { fac: B(i.negate(), i, a) };
2068
2172
  }
2069
- }, sr = {
2173
+ }, gr = {
2070
2174
  type: "blend",
2071
2175
  nodeClass: "color",
2072
2176
  label: "Blend",
@@ -2111,8 +2215,8 @@ var ir = {
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 ir = {
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
- }, cr = {
2236
+ }, _r = {
2133
2237
  type: "invert",
2134
2238
  nodeClass: "color",
2135
2239
  label: "Invert Color",
@@ -2156,10 +2260,10 @@ var ir = {
2156
2260
  default: 1
2157
2261
  }],
2158
2262
  build(e) {
2159
- let t = e.inputs.color ?? q(0, 0, 0), n = e.inputs.fac ?? e.uniforms.fac;
2160
- return { color: I(t, q(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
- }, lr = {
2266
+ }, vr = {
2163
2267
  type: "bright-contrast",
2164
2268
  nodeClass: "color",
2165
2269
  label: "Bright / Contrast",
@@ -2202,21 +2306,21 @@ var ir = {
2202
2306
  default: 0
2203
2307
  }],
2204
2308
  build(e) {
2205
- let t = e.inputs.color ?? q(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
- }, ur = 1e-10;
2209
- function dr(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 = z(i.equal(0), k(0), o.div(P(i, k(ur)))), l = q(i, i, i).sub(e).div(P(o, k(ur))), 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 = z(n.equal(i), d, f);
2211
- return p = z(t.equal(i), u, p), p = p.div(6), p = z(p.lessThan(0), p.add(1), p), p = z(c.equal(0), k(0), p), q(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 fr(e) {
2214
- let t = e.x, n = e.y, r = e.z, i = z(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 = q(r, s, c);
2215
- return u = z(a.equal(4), q(l, s, r), u), u = z(a.equal(3), q(s, c, r), u), u = z(a.equal(2), q(s, r, l), u), u = z(a.equal(1), q(c, r, s), u), u = z(a.equal(0), q(r, l, s), u), z(n.equal(0), q(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 pr = {
2323
+ var Sr = {
2220
2324
  type: "hue-sat-val",
2221
2325
  nodeClass: "color",
2222
2326
  label: "Hue / Saturation",
@@ -2268,17 +2372,17 @@ var pr = {
2268
2372
  }
2269
2373
  ],
2270
2374
  build(e) {
2271
- let t = e.inputs.color ?? q(.8, .8, .8), n = dr(t);
2272
- return { color: I(t, fr(q(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
- }, mr = (e, t, n, r, i) => z(e.equal(0), t, z(e.equal(1), n, z(e.equal(2), r, i)));
2275
- function hr(e, t) {
2276
- let n = e.clamp(0, 1).mul(4), r = A(n).clamp(0, 3), i = n.sub(r), a = mr(r, t[0], t[0], t[1], t[2]), o = mr(r, t[0], t[1], t[2], t[3]), s = mr(r, t[1], t[2], t[3], t[4]), c = mr(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 gr = () => [...Ae], _r = {
2385
+ var Tr = () => [...Fe], Er = {
2282
2386
  type: "rgb-curves",
2283
2387
  nodeClass: "color",
2284
2388
  label: "RGB Curves",
@@ -2308,14 +2412,14 @@ var gr = () => [...Ae], _r = {
2308
2412
  label: "curves",
2309
2413
  type: "curve",
2310
2414
  default: {
2311
- C: gr(),
2312
- R: gr(),
2313
- G: gr(),
2314
- B: gr()
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 ?? q(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 gr = () => [...Ae], _r = {
2326
2430
  r(5),
2327
2431
  r(10),
2328
2432
  r(15)
2329
- ], c = hr(hr(t.x, i), a), l = hr(hr(t.y, i), o), u = hr(hr(t.z, i), s), d = e.inputs.fac ?? e.uniforms.fac;
2330
- return { color: I(t, q(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
- }, vr = {
2436
+ }, Dr = {
2333
2437
  type: "luminance",
2334
2438
  nodeClass: "converter",
2335
2439
  label: "Luminance",
@@ -2344,9 +2448,9 @@ var gr = () => [...Ae], _r = {
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
- }, yr = {
2453
+ }, Or = {
2350
2454
  type: "split-channels",
2351
2455
  nodeClass: "converter",
2352
2456
  label: "Split Channels",
@@ -2381,7 +2485,7 @@ var gr = () => [...Ae], _r = {
2381
2485
  b: k(0)
2382
2486
  };
2383
2487
  }
2384
- }, br = {
2488
+ }, kr = {
2385
2489
  type: "combine-channels",
2386
2490
  nodeClass: "converter",
2387
2491
  label: "Combine Channels",
@@ -2405,9 +2509,9 @@ var gr = () => [...Ae], _r = {
2405
2509
  }],
2406
2510
  params: [],
2407
2511
  build(e) {
2408
- return { color: q(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
- }, xr = {
2514
+ }, Ar = {
2411
2515
  type: "clamp",
2412
2516
  nodeClass: "converter",
2413
2517
  label: "Clamp",
@@ -2460,10 +2564,10 @@ var gr = () => [...Ae], _r = {
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
- }, Sr = {
2570
+ }, jr = {
2467
2571
  type: "separate-xyz",
2468
2572
  nodeClass: "converter",
2469
2573
  label: "Separate XYZ",
@@ -2487,14 +2591,14 @@ var gr = () => [...Ae], _r = {
2487
2591
  ],
2488
2592
  params: [],
2489
2593
  build(e) {
2490
- let t = e.inputs.vector ?? q(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
- }, Cr = {
2601
+ }, Mr = {
2498
2602
  type: "combine-xyz",
2499
2603
  nodeClass: "converter",
2500
2604
  label: "Combine XYZ",
@@ -2546,9 +2650,9 @@ var gr = () => [...Ae], _r = {
2546
2650
  }
2547
2651
  ],
2548
2652
  build(e) {
2549
- return { vector: q(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
- }, wr = {
2655
+ }, Nr = {
2552
2656
  type: "constant-field",
2553
2657
  nodeClass: "input",
2554
2658
  label: "Constant (Field)",
@@ -2567,9 +2671,9 @@ var gr = () => [...Ae], _r = {
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
- }, Tr = {
2676
+ }, Pr = {
2573
2677
  type: "constant-color",
2574
2678
  nodeClass: "input",
2575
2679
  label: "Constant (Color)",
@@ -2585,9 +2689,9 @@ var gr = () => [...Ae], _r = {
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
- }, Er = {
2694
+ }, Fr = {
2591
2695
  type: "tex-coordinate",
2592
2696
  nodeClass: "input",
2593
2697
  label: "Texture Coordinate",
@@ -2616,20 +2720,20 @@ var gr = () => [...Ae], _r = {
2616
2720
  ],
2617
2721
  params: [],
2618
2722
  build(e) {
2619
- let t = q(G().x, G().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: pe,
2730
+ generated: ve,
2627
2731
  uv: t,
2628
- object: pe,
2629
- normal: ce
2732
+ object: ve,
2733
+ normal: pe
2630
2734
  };
2631
2735
  }
2632
- }, Dr = [
2736
+ }, Ir = [
2633
2737
  "add",
2634
2738
  "subtract",
2635
2739
  "multiply",
@@ -2652,11 +2756,11 @@ var gr = () => [...Ae], _r = {
2652
2756
  "sine",
2653
2757
  "cosine",
2654
2758
  "tangent"
2655
- ], Or = new Set([
2759
+ ], Lr = new Set([
2656
2760
  "dot",
2657
2761
  "distance",
2658
2762
  "length"
2659
- ]), kr = [{
2763
+ ]), Rr = [{
2660
2764
  key: "vector1",
2661
2765
  label: "A",
2662
2766
  kind: "vector"
@@ -2664,11 +2768,11 @@ var gr = () => [...Ae], _r = {
2664
2768
  key: "vector2",
2665
2769
  label: "B",
2666
2770
  kind: "vector"
2667
- }], Ar = {
2771
+ }], zr = {
2668
2772
  type: "vector-math",
2669
2773
  nodeClass: "vector",
2670
2774
  label: "Vector Math",
2671
- inputs: kr,
2775
+ inputs: Rr,
2672
2776
  outputs: [{
2673
2777
  key: "vector",
2674
2778
  label: "Vector",
@@ -2678,7 +2782,7 @@ var gr = () => [...Ae], _r = {
2678
2782
  key: "operation",
2679
2783
  label: "op",
2680
2784
  type: "select",
2681
- options: Dr,
2785
+ options: Ir,
2682
2786
  default: "add"
2683
2787
  }, {
2684
2788
  key: "scale",
@@ -2692,8 +2796,8 @@ var gr = () => [...Ae], _r = {
2692
2796
  declare(e) {
2693
2797
  let t = e.operation ?? "add";
2694
2798
  return {
2695
- inputs: kr,
2696
- outputs: Or.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 gr = () => [...Ae], _r = {
2705
2809
  };
2706
2810
  },
2707
2811
  build(e) {
2708
- let t = e.inputs.vector1 ?? e.coord, n = e.inputs.vector2 ?? q(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: ge(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: B(t) };
2729
- case "cosine": return { vector: S(t) };
2730
- case "tangent": return { vector: we(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
- }, jr = 1, Mr = {
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 gr = () => [...Ae], _r = {
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 = G(), i = T(n).div(T(r.x)), a = E(n).div(E(r.y)), o = e.uniforms.strength, s = K(i, a).mul(o), c = k(jr), l = s.mul(c.div(s.length().max(c)));
2760
- return { normal: de(q(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
- }, Nr = {
2919
+ }, Gr = {
2763
2920
  type: "normal-map",
2764
2921
  nodeClass: "vector",
2765
2922
  label: "Normal Map",
@@ -2786,13 +2943,13 @@ var gr = () => [...Ae], _r = {
2786
2943
  default: 1
2787
2944
  }],
2788
2945
  build(e) {
2789
- return { normal: le(e.inputs.color ?? q(.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 Pr(e) {
2795
- let t = S(e.x), n = S(e.y), r = S(e.z), i = B(e.x), a = B(e.y), o = B(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 Pr(e) {
2805
2962
  m22: n.mul(t)
2806
2963
  };
2807
2964
  }
2808
- function Fr(e, t) {
2809
- return q(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 Ir(e, t) {
2812
- return q(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 Lr(e, t, n, r, i) {
2815
- let a = Pr(n);
2816
- return i === 1 ? Ir(a, e.sub(t)).div(r) : i === 2 ? Fr(a, e.mul(r)) : i === 3 ? Fr(a, e.div(r)).normalize() : Fr(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 Rr = [
2977
+ var Xr = [
2821
2978
  "point",
2822
2979
  "texture",
2823
2980
  "vector",
2824
2981
  "normal"
2825
- ], zr = {
2982
+ ], Zr = {
2826
2983
  type: "mapping",
2827
2984
  nodeClass: "vector",
2828
2985
  label: "Mapping",
@@ -2839,7 +2996,7 @@ var Rr = [
2839
2996
  key: "mappingType",
2840
2997
  label: "type",
2841
2998
  type: "select",
2842
- options: Rr,
2999
+ options: Xr,
2843
3000
  default: "point"
2844
3001
  },
2845
3002
  {
@@ -2874,10 +3031,323 @@ var Rr = [
2874
3031
  }
2875
3032
  ],
2876
3033
  build(e) {
2877
- let t = e.inputs.vector ?? e.coord, n = Math.max(0, Rr.indexOf(e.params.mappingType));
2878
- return { vector: Lr(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
- }, Br = [
3350
+ }, si = [
2881
3351
  {
2882
3352
  key: "baseColor",
2883
3353
  label: "base color",
@@ -2982,7 +3452,7 @@ var Rr = [
2982
3452
  step: .1,
2983
3453
  default: 1
2984
3454
  }
2985
- ], Vr = Object.fromEntries(Br.filter((e) => e.type === "float" || e.type === "int").map((e) => [e.key, e.default])), Hr = {
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 Rr = [
3067
3537
  key: "bsdf",
3068
3538
  kind: "shader"
3069
3539
  }],
3070
- params: Br,
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] ?? Vr[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
- }, Ur = {
3560
+ }, ui = {
3091
3561
  type: "emission",
3092
3562
  nodeClass: "shader",
3093
3563
  label: "Emission",
@@ -3119,22 +3589,22 @@ var Rr = [
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: q(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
- }, Wr = {
3131
- emission: q(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
- }, Gr = [
3607
+ }, fi = [
3138
3608
  "baseColor",
3139
3609
  "metallic",
3140
3610
  "roughness",
@@ -3149,21 +3619,21 @@ var Rr = [
3149
3619
  "sheenRoughness",
3150
3620
  "transmission"
3151
3621
  ];
3152
- function Kr(e, t, n) {
3622
+ function pi(e, t, n) {
3153
3623
  let r = {};
3154
- for (let i of Gr) {
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 = Wr[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 qr = {
3636
+ var mi = {
3167
3637
  type: "mix-shader",
3168
3638
  nodeClass: "shader",
3169
3639
  label: "Mix Shader",
@@ -3198,9 +3668,9 @@ var qr = {
3198
3668
  default: .5
3199
3669
  }],
3200
3670
  build(e) {
3201
- return { shader: Kr(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
- }, Jr = {
3673
+ }, hi = {
3204
3674
  type: "material-output",
3205
3675
  nodeClass: "output",
3206
3676
  label: "Material Output",
@@ -3227,7 +3697,7 @@ var qr = {
3227
3697
  build() {
3228
3698
  return {};
3229
3699
  }
3230
- }, Yr = {
3700
+ }, gi = {
3231
3701
  type: "group",
3232
3702
  nodeClass: "group",
3233
3703
  label: "Group",
@@ -3237,7 +3707,7 @@ var qr = {
3237
3707
  build() {
3238
3708
  return {};
3239
3709
  }
3240
- }, Xr = {
3710
+ }, _i = {
3241
3711
  type: "group-input",
3242
3712
  nodeClass: "input",
3243
3713
  label: "Group Input",
@@ -3247,7 +3717,7 @@ var qr = {
3247
3717
  build() {
3248
3718
  return {};
3249
3719
  }
3250
- }, Zr = {
3720
+ }, vi = {
3251
3721
  type: "group-output",
3252
3722
  nodeClass: "output",
3253
3723
  label: "Group Output",
@@ -3260,7 +3730,7 @@ var qr = {
3260
3730
  };
3261
3731
  //#endregion
3262
3732
  //#region src/graph/registry.ts
3263
- function Z(e, t) {
3733
+ function Q(e, t) {
3264
3734
  if (e.ports) return e.ports;
3265
3735
  let n = t.get(e.type);
3266
3736
  return n.declare ? n.declare(e.params) : {
@@ -3268,11 +3738,11 @@ function Z(e, t) {
3268
3738
  outputs: n.outputs
3269
3739
  };
3270
3740
  }
3271
- function Qr(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 $r = 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 $r = class {
3290
3760
  return [...this.defs.values()];
3291
3761
  }
3292
3762
  };
3293
- function ei() {
3294
- return new $r().register(Ye).register(Xe).register(jt).register(Vt).register(Ht).register(bn).register(xn).register(Tn).register(On).register(jn).register(Fn).register(Kn).register(Jn).register(er).register(ir).register(ar).register(or).register(sr).register(cr).register(lr).register(pr).register(_r).register(vr).register(yr).register(br).register(xr).register(Sr).register(Cr).register(wr).register(Tr).register(Er).register(Ar).register(Mr).register(Nr).register(zr).register(Hr).register(Ur).register(qr).register(Jr).register(Yr).register(Xr).register(Zr);
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);
3295
3765
  }
3296
- var ti = ei(), ni = 2048;
3297
- function ri(e, t, n) {
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;
3774
+ }
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 ri(e, t, n) {
3308
3792
  }
3309
3793
  return !1;
3310
3794
  }
3311
- function ii(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 === Pe)?.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 ii(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 === Fe), 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 ii(e, t) {
3347
3831
  };
3348
3832
  return d(e, () => {}), n;
3349
3833
  }
3350
- function ai(e, t) {
3351
- return t === "float" ? q(e) : e;
3834
+ function ki(e, t) {
3835
+ return t === "float" ? K(e) : e;
3352
3836
  }
3353
- function oi(e, t) {
3354
- let n = H(e, G());
3837
+ function Ai(e, t) {
3838
+ let n = V(e, W());
3355
3839
  return t === "float" ? n.r : n.xyz;
3356
3840
  }
3357
- function si(e) {
3358
- let t = e.nodes.find((e) => e.type === Ie)?.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 ci(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 li(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,178 +3902,233 @@ function li(e, t, n, r, i, a) {
3373
3902
  return i.push({
3374
3903
  cacheId: c,
3375
3904
  kind: "float",
3376
- colorNode: ai(n.field, "float"),
3905
+ colorNode: ki(n.field, "float"),
3377
3906
  sizing: { size: s }
3378
- }), { field: H(l, G().mul(k(a))).r };
3907
+ }), { field: V(l, W().mul(k(a))).r };
3379
3908
  }
3380
- function ui(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 += ui(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 di(e, t, n) {
3914
+ function Li(e, t, n) {
3386
3915
  let r = {
3387
3916
  ...n,
3388
- outputResolution: n.outputResolution ?? si(e)
3389
- }, i = r.backend === "live" ? me : q(G().x, G().y, k(0)), a = r.soloNodeId ? { id: r.soloNodeId } : void 0, o = [], { outputs: s, uniforms: c } = pi(e, t, r, i, o, r.allocCache ? ii(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" ? fi(a.value, a.kind) : Si(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 fi(e, t) {
3926
+ function Ri(e, t) {
3397
3927
  return {
3398
- baseColor: t === "float" ? q(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 pi(e, t, n, r, i, a, o, s) {
3404
- wi(e, t, o !== void 0);
3405
- let c = Ci(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 = Z(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 = mi(c, t, n, r, i, a, vi(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 = vi(c, e, u, l, t), h = t.get(c.type), g = xi(h, c);
3423
- d.set(f, g);
3424
- let _ = ci(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, li(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
- let e = l.get(s.id), n = e ? Z(e, t).outputs[0] : void 0;
3959
+ let e = l.get(s.id), n = e ? Q(e, t).outputs[0] : void 0;
3436
3960
  e && n && (s.value = u.get(s.id)?.[n.key], s.kind = n.kind);
3437
3961
  }
3438
3962
  return {
3439
3963
  outputs: u,
3440
- uniforms: d
3964
+ uniforms: d,
3965
+ usage: f
3966
+ };
3967
+ }
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
+ }
3441
3994
  };
3442
3995
  }
3443
- function mi(e, t, n, r, i, a, o, s) {
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 } = pi(c, t, n, r, i, a, o, s), d = c.nodes.find((e) => e.type === Fe), 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 Z(d, t).inputs) {
3456
- let o = c.edges.find((e) => e.toNode === d.id && e.toInput === r.key), u = o ? yi(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 && ri(o.fromNode, c, t) || a.has(s) ? { minSize: ni } : 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: ai(u, r.kind),
4017
+ colorNode: ki(u, r.kind),
3463
4018
  sizing: l
3464
- }), f[r.key] = oi(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 hi() {
3473
- return new c({
3474
- metalness: 0,
3475
- roughness: .9,
3476
- side: e.DoubleSide,
3477
- polygonOffset: !0,
3478
- polygonOffsetFactor: 1,
3479
- polygonOffsetUnits: 1
3480
- });
3481
- }
3482
- function gi(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);
3485
- }
3486
- function _i(e, t, n) {
3487
- let { bundle: r, uniforms: i } = di(e, t, n), a = hi();
3488
- return gi(a, r), {
3489
- material: a,
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
+ }
4061
+ }
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));
4069
+ }
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 vi(e, t, n, r, i) {
4077
+ function Ki(e, t, n, r, i) {
3494
4078
  let a = {};
3495
- for (let o of Z(e, i).inputs) {
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 ? yi(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 yi(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
- let o = r.get(e.fromNode), s = o ? Z(o, i).outputs.find((t) => t.key === e.fromOutput)?.kind : void 0;
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 = ze(s, t);
3507
- e && (a = bi(a, e));
4090
+ let e = qe(s, t);
4091
+ e && (a = Ji(a, e));
3508
4092
  }
3509
4093
  return a;
3510
4094
  }
3511
- function bi(e, t) {
4095
+ function Ji(e, t) {
3512
4096
  switch (t) {
3513
4097
  case "float-to-vector":
3514
- case "float-to-color": return q(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 xi(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] = W(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] = W(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] = W(Number.isFinite(e) ? e : Number(i.default) || 0);
3537
- } else i.type === "curve" && (r[i.key] = De(Me(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 Si(e, t, n) {
3542
- let r = e.nodes.find((e) => e.type === Ie);
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 ? yi(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 Ci(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,18 +4145,18 @@ function Ci(e) {
3561
4145
  if (i.length !== e.nodes.length) throw Error("Material graph has a cycle");
3562
4146
  return i;
3563
4147
  }
3564
- function wi(e, t, n = !1) {
3565
- let r = n ? Fe : Ie, 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) {
3569
4153
  let e = a.get(n.fromNode), r = a.get(n.toNode);
3570
4154
  if (!e) throw Error(`Edge from unknown node '${n.fromNode}'`);
3571
4155
  if (!r) throw Error(`Edge to unknown node '${n.toNode}'`);
3572
- let i = Z(e, t).outputs.find((e) => e.key === n.fromOutput), s = Z(r, t).inputs.find((e) => e.key === n.toInput);
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 && !ze(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 wi(e, t, n = !1) {
3580
4164
  }
3581
4165
  //#endregion
3582
4166
  //#region src/document.ts
3583
- var Ti = 2;
3584
- function Ei(e) {
4167
+ var $i = 4;
4168
+ function ea(e) {
3585
4169
  return structuredClone(e);
3586
4170
  }
3587
- function Di() {
3588
- return Ei(ke);
4171
+ function ta() {
4172
+ return ea(Pe);
3589
4173
  }
3590
- function Oi(e) {
3591
- return {
3592
- ...Ei(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 ki(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 Ai(e, t) {
4201
+ function sa(e, t) {
3600
4202
  return e.find((e) => e.key === t);
3601
4203
  }
3602
- function ji(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 Mi = 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 = Di(), t = ti) {
3612
- this.registry = t, this.doc = Oi(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 Mi = class {
3625
4227
  }
3626
4228
  compileBundle(e) {
3627
4229
  try {
3628
- let t = di(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 Mi = class {
3635
4237
  return this.listeners.add(e), () => this.listeners.delete(e);
3636
4238
  }
3637
4239
  setDocument(e) {
3638
- let t = Oi(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 Ei(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 === Ie);
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 Mi = class {
3654
4256
  this.setOutputResolution(e.resolution ?? e.size ?? 1024);
3655
4257
  }
3656
4258
  setNodeParam(e, t, n) {
3657
- let r = ki(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 = Ai(Qr(r, this.registry), t) ?? Ai(i.params, t);
3660
- return a ? Object.is(r.params[t], n) ? !0 : (r.params[t] = n, ji(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,71 +4274,80 @@ var Mi = class {
3672
4274
  return n;
3673
4275
  }
3674
4276
  validate(e) {
3675
- di(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
- }, Ni = [
4282
+ }, ua = [
3681
4283
  "roughness",
3682
4284
  "metallic",
3683
4285
  "ambientOcclusion"
3684
- ], Pi = ["baseColor", "emission"];
3685
- function Fi(e, t) {
3686
- return Ni.includes(t) ? q(e) : Pi.includes(t) ? ve(e) : e;
3687
- }
3688
- var Q = 2, Ii = new l(new s()), Li = new s(), $ = new u(Q, Q);
3689
- $.texture.colorSpace = n, $.texture.minFilter = $.texture.magFilter = t, $.texture.wrapS = $.texture.wrapT = i;
3690
- var Ri = W(K(1 / Q, 1 / Q));
3691
- function zi(e) {
3692
- let t = (Q - 1) / 2, n = q(0, 0, 0);
3693
- for (let r = 0; r < Q; r++) for (let i = 0; i < Q; i++) {
3694
- let a = K(i - t, r - t).mul(Ri), o = H($.texture, G().add(a)).xyz;
3695
- e && (o = o.mul(2).sub(1)), n = n.add(o);
3696
- }
3697
- return n = n.div(Q * Q), e ? de(n).mul(.5).add(.5) : n;
3698
- }
3699
- var Bi = new s();
3700
- Bi.colorNode = zi(!1);
3701
- var Vi = new s();
3702
- Vi.colorNode = zi(!0);
3703
- var Hi = new l(Bi), Ui = new l(Vi);
3704
- function Wi() {
3705
- return new s();
3706
- }
3707
- var Gi = new a(), Ki = new r(-1, 1, 1, -1, 0, 1), qi = [];
3708
- async function Ji(e, t) {
3709
- for (; qi.length < t.length;) qi.push(new l());
3710
- Gi.clear();
3711
- for (let e = 0; e < t.length; e++) qi[e].material = t[e], Gi.add(qi[e]);
3712
- let n = e.getRenderTarget();
3713
- e.setRenderTarget($), await e.compileAsync(Gi, Ki), e.setRenderTarget(n);
3714
- }
3715
- function Yi(e, t, n) {
3716
- Ii.material = t;
4286
+ ], da = ["baseColor", "emission"];
4287
+ function fa(e, t) {
4288
+ return ua.includes(t) ? K(e) : da.includes(t) ? Ce(e) : e;
4289
+ }
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);
4293
+ for (let a = 0; a < $; a++) for (let o = 0; o < $; o++) {
4294
+ let s = G(o - r, a - r).mul(t), c = V(e, W().add(s)).xyz;
4295
+ n && (c = c.mul(2).sub(1)), i = i.add(c);
4296
+ }
4297
+ return i = i.div($ * $), n ? ge(i).mul(.5).add(.5) : i;
4298
+ }
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
+ c.texture.colorSpace = n, c.texture.minFilter = c.texture.magFilter = t, c.texture.wrapS = c.texture.wrapT = i;
4305
+ let l = G(1 / e, 1 / r), u = (e) => {
4306
+ let t = new o();
4307
+ return t.colorNode = ha(c.texture, l, e), new p(t);
4308
+ }, d = {
4309
+ ssRT: c,
4310
+ downColorQuad: u(!1),
4311
+ downNormalQuad: u(!0)
4312
+ };
4313
+ return ga.set(a, d), d;
4314
+ }
4315
+ function va() {
4316
+ return new o();
4317
+ }
4318
+ var ya = new a(), ba = new r(-1, 1, 1, -1, 0, 1), xa = [];
4319
+ async function Sa(e, t, n) {
4320
+ for (; xa.length < t.length;) xa.push(new p());
4321
+ ya.clear();
4322
+ for (let e = 0; e < t.length; e++) xa[e].material = t[e], ya.add(xa[e]);
3717
4323
  let r = e.getRenderTarget();
3718
- e.setRenderTarget(n), Ii.render(e), e.setRenderTarget(r);
4324
+ e.setRenderTarget(_a(n * $, n * $).ssRT), await e.compileAsync(ya, ba), e.setRenderTarget(r);
3719
4325
  }
3720
- function Xi(e, t, n, r = !1) {
3721
- let i = n.width, a = n.height;
3722
- ($.width !== i * Q || $.height !== a * Q) && $.setSize(i * Q, a * Q), Ri.value.set(1 / (i * Q), 1 / (a * Q)), Ii.material = t;
3723
- let o = e.getRenderTarget();
3724
- e.setRenderTarget($), Ii.render(e), e.setRenderTarget(n), (r ? Ui : Hi).render(e), e.setRenderTarget(o);
4326
+ function Ca(e, t, n) {
4327
+ pa.material = t;
4328
+ let r = e.getRenderTarget();
4329
+ e.setRenderTarget(n), pa.render(e), e.setRenderTarget(r);
4330
+ }
4331
+ function wa(e, t, n, r = !1) {
4332
+ let { ssRT: i, downColorQuad: a, downNormalQuad: o } = _a(n.width * $, n.height * $);
4333
+ pa.material = t;
4334
+ let s = e.getRenderTarget();
4335
+ e.setRenderTarget(i), pa.render(e), e.setRenderTarget(n), (r ? o : a).render(e), e.setRenderTarget(s);
3725
4336
  }
3726
- function Zi(e, t, n, r = !1) {
3727
- Li.colorNode = t, Li.needsUpdate = !0, Xi(e, Li, n, r);
4337
+ function Ta(e, t, n, r = !1) {
4338
+ ma.colorNode = t, ma.needsUpdate = !0, wa(e, ma, n, r);
3728
4339
  }
3729
4340
  //#endregion
3730
4341
  //#region src/graph/bake-service.ts
3731
- var Qi = 1024, $i = 8, ea = 4096;
3732
- function ta(e, t) {
4342
+ var Ea = 1024, Da = 8, Oa = 4096;
4343
+ function ka(e, t) {
3733
4344
  let n = t?.size ?? Math.max(e, t?.minSize ?? 0);
3734
- return Math.min(n, ea);
4345
+ return Math.min(n, Oa);
3735
4346
  }
3736
- function na(e) {
4347
+ function Aa(e) {
3737
4348
  return e?.minSize != null;
3738
4349
  }
3739
- var ra = typeof navigator < "u" && /chrome|chromium|crios|edg\//i.test(navigator.userAgent) && !/firefox|fxios/i.test(navigator.userAgent), ia = [
4350
+ var ja = typeof navigator < "u" && /chrome|chromium|crios|edg\//i.test(navigator.userAgent) && !/firefox|fxios/i.test(navigator.userAgent), Ma = [
3740
4351
  "baseColor",
3741
4352
  "roughness",
3742
4353
  "metallic",
@@ -3744,15 +4355,15 @@ var ra = typeof navigator < "u" && /chrome|chromium|crios|edg\//i.test(navigator
3744
4355
  "normal",
3745
4356
  "emission"
3746
4357
  ];
3747
- function aa(t, n) {
3748
- let r = new u(n, n), i = r.texture;
3749
- return i.colorSpace = t !== "height" && Pi.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 = $i, r;
4358
+ function Na(t, n) {
4359
+ let r = new m(n, n), i = r.texture;
4360
+ 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;
3750
4361
  }
3751
- function oa(t, n = !1) {
3752
- let r = new u(t, t, { type: e.HalfFloatType }), i = r.texture;
4362
+ function Pa(t, n = !1) {
4363
+ let r = new m(t, t, { type: e.HalfFloatType }), i = r.texture;
3753
4364
  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;
3754
4365
  }
3755
- var sa = class {
4366
+ var Fa = class {
3756
4367
  channels;
3757
4368
  targets = /* @__PURE__ */ new Map();
3758
4369
  mats = /* @__PURE__ */ new Map();
@@ -3760,6 +4371,8 @@ var sa = class {
3760
4371
  cacheMats = /* @__PURE__ */ new Map();
3761
4372
  cachePlan = [];
3762
4373
  uniforms = /* @__PURE__ */ new Map();
4374
+ paramUsage = /* @__PURE__ */ new Map();
4375
+ constArrays = /* @__PURE__ */ new Map();
3763
4376
  heightTarget = null;
3764
4377
  hasHeight = !1;
3765
4378
  present = /* @__PURE__ */ new Set();
@@ -3771,46 +4384,75 @@ var sa = class {
3771
4384
  resize(e) {
3772
4385
  if (e !== this.size) {
3773
4386
  this.size = e;
3774
- for (let t of this.targets.values()) t.setSize(e, e);
3775
- this.heightTarget?.setSize(e, e), this.flushCaches();
4387
+ for (let t of this.targets.values()) t.setSize(e, e), t.texture.needsUpdate = !0;
4388
+ this.heightTarget && (this.heightTarget.setSize(e, e), this.heightTarget.texture.needsUpdate = !0), this.flushCaches();
3776
4389
  }
3777
4390
  }
3778
4391
  target(e) {
3779
4392
  let t = this.targets.get(e);
3780
- return t || (t = aa(e, this.size), this.targets.set(e, t)), t;
4393
+ return t || (t = Na(e, this.size), this.targets.set(e, t)), t;
3781
4394
  }
3782
4395
  channelMaterial(e) {
3783
4396
  let t = this.mats.get(e);
3784
- return t || (t = Wi(), this.mats.set(e, t)), t;
4397
+ return t || (t = va(), this.mats.set(e, t)), t;
3785
4398
  }
3786
4399
  cacheTarget(e, t = this.size, n = !1) {
3787
4400
  let r = this.cacheTargets.get(e);
3788
- 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 = oa(t, n), this.cacheTargets.set(e, r)), r;
4401
+ 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;
3789
4402
  }
3790
4403
  cacheMaterial(e) {
3791
4404
  let t = this.cacheMats.get(e);
3792
- return t || (t = Wi(), this.cacheMats.set(e, t)), t;
4405
+ return t || (t = va(), this.cacheMats.set(e, t)), t;
3793
4406
  }
3794
4407
  cacheTexture(e, t, n = !1) {
3795
4408
  return this.cacheTarget(e, t, n).texture;
3796
4409
  }
4410
+ pruneCaches(e) {
4411
+ for (let [t, n] of this.cacheTargets) e.has(t) || (n.dispose(), this.cacheTargets.delete(t));
4412
+ for (let [t, n] of this.cacheMats) e.has(t) || (n.dispose(), this.cacheMats.delete(t));
4413
+ }
3797
4414
  firstTarget() {
3798
4415
  for (let e of this.targets.values()) return e;
3799
4416
  return this.heightTarget;
3800
4417
  }
3801
4418
  ensureHeightTarget() {
3802
- return this.heightTarget ||= aa("height", this.size), this.heightTarget;
4419
+ return this.heightTarget ||= Na("height", this.size), this.heightTarget;
3803
4420
  }
3804
4421
  texture(e) {
3805
4422
  return this.targets.get(e)?.texture ?? null;
3806
4423
  }
4424
+ allocConstantArray(t, n, r, i) {
4425
+ let a = `${t}/${n}`, o = this.constArrays.get(a);
4426
+ if (o && o.length === r.length && o.elementType === i) {
4427
+ let e = o.node.array;
4428
+ if (i === "vec3") {
4429
+ let t = e;
4430
+ for (let e = 0; e < t.length; e++) t[e].set(r[e * 3], r[e * 3 + 1], r[e * 3 + 2]);
4431
+ } else {
4432
+ let t = e;
4433
+ for (let e = 0; e < r.length; e++) t[e] = r[e];
4434
+ }
4435
+ return o.node;
4436
+ }
4437
+ let s;
4438
+ if (i === "vec3") {
4439
+ let t = [];
4440
+ for (let n = 0; n < r.length; n += 3) t.push(new e.Vector3(r[n], r[n + 1], r[n + 2]));
4441
+ s = Me(t);
4442
+ } else s = Me(Array.from(r), "float");
4443
+ return this.constArrays.set(a, {
4444
+ node: s,
4445
+ length: r.length,
4446
+ elementType: i
4447
+ }), s;
4448
+ }
3807
4449
  flushCaches() {
3808
4450
  for (let e of this.mats.values()) e.dispose();
3809
4451
  this.mats.clear();
3810
4452
  for (let e of this.cacheTargets.values()) e.dispose();
3811
4453
  this.cacheTargets.clear();
3812
4454
  for (let e of this.cacheMats.values()) e.dispose();
3813
- this.cacheMats.clear(), this.cachePlan = [], this.uniforms = /* @__PURE__ */ new Map();
4455
+ this.cacheMats.clear(), this.cachePlan = [], this.uniforms = /* @__PURE__ */ new Map(), this.paramUsage = /* @__PURE__ */ new Map(), this.constArrays.clear();
3814
4456
  }
3815
4457
  dispose() {
3816
4458
  for (let e of this.targets.values()) e.dispose();
@@ -3820,9 +4462,9 @@ var sa = class {
3820
4462
  for (let e of this.cacheTargets.values()) e.dispose();
3821
4463
  this.cacheTargets.clear();
3822
4464
  for (let e of this.cacheMats.values()) e.dispose();
3823
- this.cacheMats.clear(), this.cachePlan = [], this.heightTarget?.dispose(), this.heightTarget = null;
4465
+ this.cacheMats.clear(), this.cachePlan = [], this.uniforms = /* @__PURE__ */ new Map(), this.paramUsage = /* @__PURE__ */ new Map(), this.constArrays.clear(), this.heightTarget?.dispose(), this.heightTarget = null;
3824
4466
  }
3825
- }, ca = class {
4467
+ }, Ia = class {
3826
4468
  renderer = null;
3827
4469
  compileGateDepth = 0;
3828
4470
  get rendererBusy() {
@@ -3874,79 +4516,80 @@ var sa = class {
3874
4516
  });
3875
4517
  return this.queue = n.then(() => void 0, () => void 0), n;
3876
4518
  }
3877
- createTextureSet(e = ia, t = Qi) {
3878
- return new sa(t, e);
4519
+ createTextureSet(e = Ma, t = Ea) {
4520
+ return new Fa(t, e);
3879
4521
  }
3880
4522
  bakeInto(e, t, n = {}) {
3881
4523
  return this.enqueue(n.label ?? "surface", async () => {
3882
4524
  let r = this.renderer;
3883
4525
  if (!r) return !1;
3884
- let i = performance.now(), { bundle: a, uniforms: o, cachePlan: s } = t.compileBundle({
4526
+ let i = performance.now(), { bundle: a, uniforms: o, cachePlan: s, paramUsage: c } = t.compileBundle({
3885
4527
  backend: "offline",
3886
4528
  soloNodeId: n.soloNodeId,
3887
- allocCache: (t, n, r) => e.cacheTexture(t, ta(e.size, r), na(r))
3888
- }), c = performance.now() - i, l = ui(t.document);
3889
- e.uniforms = o, e.cachePlan = s;
3890
- let u = n.channels ?? e.channels, d = /* @__PURE__ */ new Set(), f = [];
3891
- for (let t of u) {
4529
+ allocCache: (t, n, r) => e.cacheTexture(t, ka(e.size, r), Aa(r)),
4530
+ allocConstantArray: (t, n, r, i) => e.allocConstantArray(t, n, r, i)
4531
+ }), l = performance.now() - i, u = Ii(t.document);
4532
+ e.uniforms = o, e.paramUsage = c, e.cachePlan = s, n.soloNodeId || e.pruneCaches(new Set(s.map((e) => e.cacheId)));
4533
+ let d = n.channels ?? e.channels, f = /* @__PURE__ */ new Set(), p = [];
4534
+ for (let t of d) {
3892
4535
  let n = a[t];
3893
4536
  if (!n) continue;
3894
4537
  let r = e.channelMaterial(t);
3895
- r.colorNode = Fi(n, t), r.needsUpdate = !0, f.push({
4538
+ r.colorNode = fa(n, t), r.needsUpdate = !0, p.push({
3896
4539
  mat: r,
3897
4540
  target: e.target(t),
3898
4541
  isNormal: t === "normal"
3899
- }), d.add(t);
4542
+ }), f.add(t);
3900
4543
  }
3901
4544
  if (e.hasHeight = a.height !== void 0, e.hasHeight) {
3902
4545
  let t = e.channelMaterial("height");
3903
- t.colorNode = q(a.height), t.needsUpdate = !0, f.push({
4546
+ t.colorNode = K(a.height), t.needsUpdate = !0, p.push({
3904
4547
  mat: t,
3905
4548
  target: e.ensureHeightTarget(),
3906
4549
  isNormal: !1
3907
4550
  });
3908
4551
  }
3909
- let p = {
4552
+ let m = {
3910
4553
  runId: ++this.bakeRunId,
3911
4554
  source: n.source,
3912
4555
  phase: "nodes",
3913
- nodeCount: l,
3914
- compileMs: c,
3915
- texturesTotal: f.length,
4556
+ nodeCount: u,
4557
+ compileMs: l,
4558
+ texturesTotal: p.length,
3916
4559
  totalMs: 0
3917
4560
  };
3918
- this.emitReport(p);
4561
+ this.emitReport(m);
3919
4562
  for (let t of s) {
3920
4563
  let n = e.cacheMaterial(t.cacheId);
3921
- n.colorNode = t.colorNode, n.needsUpdate = !0, Yi(r, n, e.cacheTarget(t.cacheId, ta(e.size, t.sizing), na(t.sizing)));
4564
+ n.colorNode = t.colorNode, n.needsUpdate = !0, Ca(r, n, e.cacheTarget(t.cacheId, ka(e.size, t.sizing), Aa(t.sizing)));
3922
4565
  }
3923
- let m = 0;
3924
- if (ra) {
4566
+ let h = 0;
4567
+ if (ja) {
3925
4568
  this.emitReport({
3926
- ...p,
4569
+ ...m,
3927
4570
  phase: "shaders"
3928
4571
  });
3929
- let e = performance.now();
4572
+ let t = performance.now();
3930
4573
  this.compileGateDepth += 1;
3931
4574
  try {
3932
- await Ji(r, f.map((e) => e.mat));
4575
+ await Sa(r, p.map((e) => e.mat), e.size);
3933
4576
  } finally {
3934
4577
  --this.compileGateDepth;
3935
4578
  }
3936
- m = performance.now() - e;
4579
+ h = performance.now() - t;
3937
4580
  }
3938
- let h = performance.now();
3939
- for (let e of f) Xi(r, e.mat, e.target, e.isNormal);
3940
- let g = performance.now() - h, _ = [...d].sort().join(",") + (e.hasHeight ? "|h" : ""), v = _ !== e.signature;
3941
- e.present = d, e.signature = _;
3942
- let y = performance.now();
4581
+ let g = performance.now();
4582
+ for (let e of p) wa(r, e.mat, e.target, e.isNormal);
4583
+ let _ = performance.now() - g, v = [...f].sort().join(",") + (e.hasHeight ? "|h" : ""), y = v !== e.signature;
4584
+ e.present = f, e.signature = v;
4585
+ let b = performance.now();
3943
4586
  await this.gpuSync(e);
3944
- let b = performance.now() - y, x = c + m + g + b;
4587
+ let x = performance.now() - b, S = l + h + _ + x;
3945
4588
  return this.emitReport({
3946
- ...p,
4589
+ ...m,
3947
4590
  phase: "done",
3948
- totalMs: x
3949
- }), 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;
4591
+ totalMs: S
4592
+ }), 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;
3950
4593
  });
3951
4594
  }
3952
4595
  async gpuSync(e) {
@@ -3975,9 +4618,9 @@ var sa = class {
3975
4618
  };
3976
4619
  this.emitReport(i);
3977
4620
  let a = performance.now();
3978
- for (let t of e.cachePlan) Yi(n, e.cacheMaterial(t.cacheId), e.cacheTarget(t.cacheId, ta(e.size, t.sizing), na(t.sizing)));
3979
- for (let t of e.present) Xi(n, e.channelMaterial(t), e.target(t), t === "normal");
3980
- e.hasHeight && e.heightTarget && Xi(n, e.channelMaterial("height"), e.heightTarget, !1);
4621
+ for (let t of e.cachePlan) Ca(n, e.cacheMaterial(t.cacheId), e.cacheTarget(t.cacheId, ka(e.size, t.sizing), Aa(t.sizing)));
4622
+ for (let t of e.present) wa(n, e.channelMaterial(t), e.target(t), t === "normal");
4623
+ e.hasHeight && e.heightTarget && wa(n, e.channelMaterial("height"), e.heightTarget, !1);
3981
4624
  let o = performance.now() - a, s = performance.now();
3982
4625
  await this.gpuSync(e);
3983
4626
  let c = performance.now() - s;
@@ -3999,25 +4642,27 @@ var sa = class {
3999
4642
  if (!r) return null;
4000
4643
  let { bundle: i, cachePlan: a } = e.compileBundle({
4001
4644
  backend: "offline",
4002
- allocCache: (e, t, r) => this.scratchCache(e, n, ta(n, r), na(r)).rt.texture
4645
+ allocCache: (e, t, r) => this.scratchCache(e, n, ka(n, r), Aa(r)).rt.texture
4003
4646
  }), o = i[t];
4004
4647
  if (!o) return null;
4648
+ let s = new Set(a.map((e) => e.cacheId));
4649
+ for (let [e, t] of this.scratchCaches) s.has(e) || (t.rt.dispose(), t.mat.dispose(), this.scratchCaches.delete(e));
4005
4650
  for (let e of a) {
4006
- let t = this.scratchCache(e.cacheId, n, ta(n, e.sizing), na(e.sizing));
4007
- t.mat.colorNode = e.colorNode, t.mat.needsUpdate = !0, Yi(r, t.mat, t.rt);
4651
+ let t = this.scratchCache(e.cacheId, n, ka(n, e.sizing), Aa(e.sizing));
4652
+ t.mat.colorNode = e.colorNode, t.mat.needsUpdate = !0, Ca(r, t.mat, t.rt);
4008
4653
  }
4009
- let s = this.scratchTarget(n);
4010
- Zi(r, Fi(o, t), s, t === "normal");
4011
- let c = await r.readRenderTargetPixelsAsync(s, 0, 0, n, n), l = new Uint8ClampedArray(n * n * 4), u = n * 4;
4654
+ let c = this.scratchTarget(n);
4655
+ Ta(r, fa(o, t), c, t === "normal");
4656
+ let l = await r.readRenderTargetPixelsAsync(c, 0, 0, n, n), u = new Uint8ClampedArray(n * n * 4), d = n * 4;
4012
4657
  for (let e = 0; e < n; e++) {
4013
- let t = (n - 1 - e) * u;
4014
- l.set(c.subarray(t, t + u), e * u);
4658
+ let t = (n - 1 - e) * d;
4659
+ u.set(l.subarray(t, t + d), e * d);
4015
4660
  }
4016
- return new ImageData(l, n, n);
4661
+ return new ImageData(u, n, n);
4017
4662
  });
4018
4663
  }
4019
4664
  scratchTarget(e) {
4020
- return (!this.scratch || this.scratchSize !== e) && (this.scratch?.dispose(), this.scratch = new u(e, e), this.scratchSize = e), this.scratch;
4665
+ return (!this.scratch || this.scratchSize !== e) && (this.scratch?.dispose(), this.scratch = new m(e, e), this.scratchSize = e), this.scratch;
4021
4666
  }
4022
4667
  scratchCache(e, t, n, r = !1) {
4023
4668
  if (this.scratchCacheSize !== t) {
@@ -4026,59 +4671,71 @@ var sa = class {
4026
4671
  }
4027
4672
  let i = this.scratchCaches.get(e);
4028
4673
  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 = {
4029
- rt: oa(n, r),
4030
- mat: Wi()
4674
+ rt: Pa(n, r),
4675
+ mat: va()
4031
4676
  }, this.scratchCaches.set(e, i)), i;
4032
4677
  }
4033
- }, la = new ca();
4678
+ }, La = new Ia();
4034
4679
  //#endregion
4035
4680
  //#region src/tsl/triplanar.ts
4036
- function ua(e) {
4037
- let t = R(ue.abs(), e);
4038
- return t.div(t.dot(q(1, 1, 1)).max(1e-4));
4681
+ function Ra(e) {
4682
+ let t = L(he.abs(), e);
4683
+ return t.div(t.dot(K(1, 1, 1)).max(1e-4));
4039
4684
  }
4040
- function da(e, t, n) {
4041
- return d(() => {
4042
- let r = me.mul(t), i = ua(n), a = H(e, r.yz).mul(i.x), o = H(e, r.zx).mul(i.y), s = H(e, r.xy).mul(i.z);
4685
+ function za(e, t, n) {
4686
+ return h(() => {
4687
+ 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);
4043
4688
  return a.add(o).add(s);
4044
4689
  })();
4045
4690
  }
4046
4691
  //#endregion
4047
4692
  //#region src/tsl/triplanar-normal.ts
4048
- function fa(e, t, n) {
4049
- return d(() => {
4050
- let r = me.mul(t), i = ua(n), a = ue.sign(), o = H(e, r.yz).xyz.mul(2).sub(1), s = H(e, r.zx).xyz.mul(2).sub(1), c = H(e, r.xy).xyz.mul(2).sub(1), l = q(o.x, o.y, o.z.mul(a.x)), u = q(s.x, s.y, s.z.mul(a.y)), d = q(c.x, c.y, c.z.mul(a.z));
4693
+ function Ba(e, t, n) {
4694
+ return h(() => {
4695
+ 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));
4051
4696
  return l.zxy.mul(i.x).add(u.yzx.mul(i.y)).add(d.xyz.mul(i.z)).normalize();
4052
4697
  })();
4053
4698
  }
4054
4699
  //#endregion
4055
4700
  //#region src/tsl/parallax.ts
4056
- var pa = .3;
4057
- function ma(e, t, n, r) {
4058
- return d(() => {
4059
- let i = fe.normalize(), a = (t) => H(e, t).x, o = 1 / r, s = i.xy.div(i.z.abs().max(pa)).mul(n).mul(o), c = t.toVar(), l = _(!1).toVar(), u = t, d = k(1).sub(a(u));
4701
+ var Va = .3;
4702
+ function Ha(e, t, n, r) {
4703
+ return h(() => {
4704
+ 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));
4060
4705
  for (let e = 0; e < r; e++) {
4061
- 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 = ye(f.div(f.sub(p).max(1e-5))), h = I(t, u, m);
4062
- c.assign(z(l.not().and(i), h, c)), l.assign(l.or(i)), u = t, d = n;
4706
+ 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);
4707
+ c.assign(R(l.not().and(i), h, c)), l.assign(l.or(i)), u = t, d = n;
4063
4708
  }
4064
4709
  return c;
4065
4710
  })();
4066
4711
  }
4067
4712
  //#endregion
4068
4713
  //#region src/graph/textured-surface.ts
4069
- var ha = 12, ga = class {
4714
+ var Ua = 12;
4715
+ function Wa(e, t) {
4716
+ return [
4717
+ e,
4718
+ t.shininess,
4719
+ t.specular,
4720
+ t.gradientSteps,
4721
+ t.matcap
4722
+ ].join("|");
4723
+ }
4724
+ var Ga = class {
4070
4725
  graph;
4071
4726
  service;
4072
4727
  source;
4073
- offlineMat = hi();
4728
+ offlineMat = Ui();
4729
+ matType = "physical";
4730
+ matSig = "";
4074
4731
  liveUniforms = /* @__PURE__ */ new Map();
4075
4732
  material_;
4076
- scaleUniform = W(1.2);
4077
- sharpnessUniform = W(8);
4078
- roughnessFactor = W(1);
4079
- metalnessFactor = W(1);
4080
- colorTint = W(new e.Color(1, 1, 1));
4081
- parallaxScale = W(0);
4733
+ scaleUniform = U(1.2);
4734
+ sharpnessUniform = U(8);
4735
+ roughnessFactor = U(1);
4736
+ metalnessFactor = U(1);
4737
+ colorTint = U(new e.Color(1, 1, 1));
4738
+ parallaxScale = U(0);
4082
4739
  lastBakeMs = 0;
4083
4740
  set;
4084
4741
  backend = "offline";
@@ -4090,9 +4747,12 @@ var ha = 12, ga = class {
4090
4747
  pendingKind = "none";
4091
4748
  flushRequested = !1;
4092
4749
  listeners = /* @__PURE__ */ new Set();
4750
+ textureListeners = /* @__PURE__ */ new Set();
4093
4751
  lastError_ = null;
4752
+ processingDepth = 0;
4753
+ idleWaiters = [];
4094
4754
  constructor(e, t, n) {
4095
- this.graph = e, this.service = t, this.source = n, this.set = t.createTextureSet(ia, this.surfaceBakeSize()), this.material_ = this.buildLive(), this.graph.onChange((e) => this.onGraphChange(e));
4755
+ 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));
4096
4756
  }
4097
4757
  get material() {
4098
4758
  return this.material_;
@@ -4100,6 +4760,22 @@ var ha = 12, ga = class {
4100
4760
  get lastError() {
4101
4761
  return this.lastError_;
4102
4762
  }
4763
+ get busy() {
4764
+ return this.processingDepth > 0;
4765
+ }
4766
+ whenIdle() {
4767
+ return this.processingDepth === 0 ? Promise.resolve() : new Promise((e) => this.idleWaiters.push(e));
4768
+ }
4769
+ enterProcessing() {
4770
+ this.processingDepth += 1;
4771
+ }
4772
+ exitProcessing() {
4773
+ if (--this.processingDepth, this.processingDepth === 0) {
4774
+ let e = this.idleWaiters;
4775
+ this.idleWaiters = [];
4776
+ for (let t of e) t();
4777
+ }
4778
+ }
4103
4779
  getLastBakeMs() {
4104
4780
  return this.backend === "offline" ? this.lastBakeMs : 0;
4105
4781
  }
@@ -4109,6 +4785,21 @@ var ha = 12, ga = class {
4109
4785
  notify() {
4110
4786
  for (let e of this.listeners) e();
4111
4787
  }
4788
+ onTexturesUpdated(e) {
4789
+ return this.textureListeners.add(e), () => this.textureListeners.delete(e);
4790
+ }
4791
+ notifyTexturesUpdated() {
4792
+ for (let e of this.textureListeners) e();
4793
+ }
4794
+ getChannelTexture(e) {
4795
+ return this.set.texture(e);
4796
+ }
4797
+ getHeightTexture() {
4798
+ return this.set.heightTarget?.texture ?? null;
4799
+ }
4800
+ presentChannels() {
4801
+ return new Set(this.set.present);
4802
+ }
4112
4803
  refresh() {
4113
4804
  return this.rebuild();
4114
4805
  }
@@ -4170,7 +4861,7 @@ var ha = 12, ga = class {
4170
4861
  let e = n.value;
4171
4862
  t.value.set(e.x, e.y, e.z);
4172
4863
  } else if (n.paramType === "curve") {
4173
- let e = Me(n.value), r = t.array;
4864
+ let e = Le(n.value), r = t.array;
4174
4865
  for (let t = 0; t < e.length; t++) r[t] = e[t];
4175
4866
  } else t.value = Number(n.value);
4176
4867
  }
@@ -4179,7 +4870,7 @@ var ha = 12, ga = class {
4179
4870
  return t ? (this.applyUniformValue(t, e), !0) : !1;
4180
4871
  }
4181
4872
  updateOfflineUniform(e) {
4182
- if (e.bakeStructural) return !1;
4873
+ if (this.set.paramUsage.get(e.nodeId)?.[e.key] !== "live") return !1;
4183
4874
  let t = this.set.uniforms.get(e.nodeId)?.[e.key];
4184
4875
  return t ? (this.applyUniformValue(t, e), !0) : !1;
4185
4876
  }
@@ -4200,35 +4891,48 @@ var ha = 12, ga = class {
4200
4891
  }
4201
4892
  }
4202
4893
  async rerenderOffline() {
4203
- if (!(this.backend !== "offline" || !this.service.hasRenderer)) try {
4204
- await this.service.rerenderInto(this.set, this.source), this.lastError_ = this.graph.lastError;
4205
- } catch (e) {
4206
- this.lastError_ = e instanceof Error ? e.message : String(e), console.warn("[textured-surface] re-render failed:", this.lastError_);
4894
+ if (!(this.backend !== "offline" || !this.service.hasRenderer)) {
4895
+ this.enterProcessing();
4896
+ try {
4897
+ await this.service.rerenderInto(this.set, this.source), this.lastError_ = this.graph.lastError, this.notifyTexturesUpdated();
4898
+ } catch (e) {
4899
+ this.lastError_ = e instanceof Error ? e.message : String(e), console.warn("[textured-surface] re-render failed:", this.lastError_);
4900
+ } finally {
4901
+ this.exitProcessing();
4902
+ }
4207
4903
  }
4208
4904
  }
4209
4905
  surfaceBakeSize() {
4210
- return Math.max(64, Math.round(si(this.graph.document) / 64) * 64);
4906
+ return Math.max(64, Math.round(ji(this.graph.document) / 64) * 64);
4211
4907
  }
4212
4908
  async rebuild() {
4909
+ this.enterProcessing();
4910
+ let e = this.material_, t;
4213
4911
  try {
4214
- if (this.backend === "offline" && this.service.hasRenderer) {
4215
- let e = this.surfaceBakeSize();
4216
- this.flushRequested && (this.flushRequested = !1, this.set.flushCaches()), this.set.resize(e);
4217
- let t = this.graph.soloNode ?? void 0, n = performance.now(), r = await this.service.bakeInto(this.set, this.graph, {
4218
- soloNodeId: t,
4219
- label: "surface",
4220
- source: this.source
4221
- });
4222
- this.lastBakeMs = performance.now() - n, (r || !this.wiredOnce) && (this.wire(this.set.present), this.wiredOnce = !0), this.material_ = this.offlineMat;
4223
- } else this.material_ = this.buildLive();
4224
- this.lastError_ = this.graph.lastError;
4225
- } catch (e) {
4226
- this.lastError_ = e instanceof Error ? e.message : String(e), console.warn("[textured-surface] rebuild failed:", this.lastError_);
4912
+ try {
4913
+ if (this.backend === "offline" && this.service.hasRenderer) {
4914
+ let e = this.surfaceBakeSize();
4915
+ this.flushRequested && (this.flushRequested = !1, this.set.flushCaches()), this.set.resize(e);
4916
+ let { type: n, settings: r } = Mi(this.graph.document), i = Wa(n, r), a = i !== this.matSig;
4917
+ a && (t = this.offlineMat, this.offlineMat = Ui(n, r), this.matType = n, this.matSig = i);
4918
+ let o = this.graph.soloNode ?? void 0, s = performance.now(), c = await this.service.bakeInto(this.set, this.graph, {
4919
+ soloNodeId: o,
4920
+ label: "surface",
4921
+ source: this.source
4922
+ });
4923
+ this.lastBakeMs = performance.now() - s, (c || !this.wiredOnce || a) && (this.wire(this.set.present), this.wiredOnce = !0), this.material_ = this.offlineMat;
4924
+ } else this.material_ = this.buildLive();
4925
+ this.lastError_ = this.graph.lastError;
4926
+ } catch (e) {
4927
+ this.lastError_ = e instanceof Error ? e.message : String(e), console.warn("[textured-surface] rebuild failed:", this.lastError_);
4928
+ }
4929
+ this.notify(), this.notifyTexturesUpdated(), e !== this.material_ && e !== this.offlineMat && e !== t && e.dispose(), t && t.dispose();
4930
+ } finally {
4931
+ this.exitProcessing();
4227
4932
  }
4228
- this.notify();
4229
4933
  }
4230
4934
  buildLive() {
4231
- let e = this.graph.soloNode ?? void 0, { material: t, uniforms: n } = _i(this.graph.document, this.graph.getRegistry(), {
4935
+ let e = this.graph.soloNode ?? void 0, { material: t, uniforms: n } = Gi(this.graph.document, this.graph.getRegistry(), {
4232
4936
  backend: "live",
4233
4937
  soloNodeId: e
4234
4938
  });
@@ -4236,39 +4940,80 @@ var ha = 12, ga = class {
4236
4940
  }
4237
4941
  wire(e) {
4238
4942
  this.lastPresent = e;
4239
- let t = this.offlineMat, n = this.scaleUniform, r = this.sharpnessUniform, i = this.set.hasHeight && !this.triplanar && this.parallaxScale.value > 0, a = G(), o = i ? ma(this.set.heightTarget.texture, a, this.parallaxScale, ha) : void 0, s = a.dFdx(), c = a.dFdy(), l = (e) => i ? H(e, o).grad(s, c) : H(e), u = (e) => this.triplanar ? da(this.set.texture(e), n, r) : l(this.set.texture(e)), d = e.has("normal") ? this.triplanar ? fa(this.set.texture("normal"), n, r) : le(l(this.set.texture("normal")).xyz, k(1)) : ue;
4943
+ 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;
4240
4944
  if (this.debugNormals) {
4241
- t.colorNode = q(0, 0, 0), t.emissiveNode = d.normalize().mul(.5).add(.5), t.roughnessNode = t.metalnessNode = t.aoNode = t.normalNode = null, t.needsUpdate = !0;
4945
+ 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;
4242
4946
  return;
4243
4947
  }
4244
- 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;
4245
- let f = g("vertexAo", "float");
4246
- 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;
4948
+ 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) {
4949
+ let n = b("vertexAo", "float");
4950
+ t.aoNode = e.has("ambientOcclusion") ? d("ambientOcclusion").r.mul(n) : n;
4951
+ }
4952
+ n.emissive && (t.emissiveNode = e.has("emission") ? d("emission") : null), t.needsUpdate = !0;
4247
4953
  }
4248
4954
  dispose() {
4249
- this.set.dispose(), this.offlineMat.dispose();
4955
+ this.set.dispose(), this.offlineMat.dispose(), this.material_ !== this.offlineMat && this.material_.dispose();
4956
+ }
4957
+ };
4958
+ //#endregion
4959
+ //#region src/graph/mesh-material.ts
4960
+ function Ka(t) {
4961
+ let n = { side: e.DoubleSide };
4962
+ switch (t) {
4963
+ case "standard": return new e.MeshStandardMaterial(n);
4964
+ case "lambert": return new e.MeshLambertMaterial(n);
4965
+ case "phong": return new e.MeshPhongMaterial(n);
4966
+ case "toon": return new e.MeshToonMaterial(n);
4967
+ case "matcap": return new e.MeshMatcapMaterial(n);
4968
+ default: return new e.MeshPhysicalMaterial(n);
4250
4969
  }
4251
- }, _a = class {
4970
+ }
4971
+ function qa(e, t) {
4972
+ let n = Ni(e), r = ze[n.type], i = Ka(n.type), a = i, o = (e) => t.get(e), s = o("baseColor");
4973
+ s ? (a.map = s, a.color.set(16777215)) : a.color.set(n.baseColor);
4974
+ let c = o("normal");
4975
+ if (c && (a.normalMap = c), n.alpha < 1 && (a.transparent = !0, a.opacity = n.alpha), r.ao) {
4976
+ let e = o("ambientOcclusion");
4977
+ e && (a.aoMap = e);
4978
+ }
4979
+ if (r.emissive) {
4980
+ let e = o("emission");
4981
+ e ? (a.emissiveMap = e, a.emissive.set(16777215), a.emissiveIntensity = 1) : a.emissive.set(n.emission);
4982
+ }
4983
+ if (r.roughMetal) {
4984
+ let e = o("roughness");
4985
+ e ? (a.roughnessMap = e, a.roughness = 1) : a.roughness = n.roughness;
4986
+ let t = o("metallic");
4987
+ t ? (a.metalnessMap = t, a.metalness = 1) : a.metalness = n.metallic;
4988
+ }
4989
+ 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;
4990
+ }
4991
+ //#endregion
4992
+ //#region src/runtime.ts
4993
+ var Ja = class {
4252
4994
  graph;
4253
4995
  surface;
4254
4996
  service;
4255
4997
  constructor(e = {}) {
4256
- this.service = e.bakeService ?? la, this.graph = new Mi(e.document, e.registry ?? ti), this.surface = new ga(this.graph, this.service, e.source);
4998
+ this.service = e.bakeService ?? La, this.graph = new la(e.document, e.registry ?? Si), this.surface = new Ga(this.graph, this.service, e.source);
4257
4999
  }
4258
- get material() {
5000
+ getNodeMaterial() {
4259
5001
  return this.surface.material;
4260
5002
  }
5003
+ getMeshMaterial() {
5004
+ return qa(this.graph.document, { get: (e) => this.surface.getChannelTexture(e) });
5005
+ }
4261
5006
  get lastError() {
4262
5007
  return this.surface.lastError ?? this.graph.lastError;
4263
5008
  }
4264
- setRenderer(e) {
4265
- return this.service.attachRenderer(e), this;
5009
+ get busy() {
5010
+ return this.surface.busy;
4266
5011
  }
4267
- setBackend(e) {
4268
- return this.surface.setBackend(e), this;
5012
+ whenIdle() {
5013
+ return this.surface.whenIdle();
4269
5014
  }
4270
- getBackend() {
4271
- return this.surface.getBackend();
5015
+ setRenderer(e) {
5016
+ return this.service.attachRenderer(e), this;
4272
5017
  }
4273
5018
  fromDocument(e) {
4274
5019
  return this.setDocument(e);
@@ -4303,48 +5048,48 @@ var ha = 12, ga = class {
4303
5048
  };
4304
5049
  //#endregion
4305
5050
  //#region src/topology.ts
4306
- function va(e) {
4307
- return Array.isArray(e) ? `[${e.map(va).join(",")}]` : e && typeof e == "object" ? `{${Object.entries(e).sort(([e], [t]) => e.localeCompare(t)).map(([e, t]) => `${e}:${va(t)}`).join(",")}}` : JSON.stringify(e);
5051
+ function Ya(e) {
5052
+ 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);
4308
5053
  }
4309
- function ya(e, t) {
5054
+ function Xa(e, t) {
4310
5055
  let n = t.get(e.type), r = n.paramsFor ? n.paramsFor(e.params) : n.params, i = {};
4311
5056
  for (let t of r) (t.type === "int" || t.type === "bool" || t.type === "select" || t.bakeStructural) && (i[t.key] = e.params[t.key]);
4312
5057
  return i;
4313
5058
  }
4314
- function ba(e, t) {
5059
+ function Za(e, t) {
4315
5060
  return {
4316
5061
  id: e.id,
4317
5062
  type: e.type,
4318
5063
  enabled: e.enabled,
4319
- ports: Z(e, t),
4320
- params: ya(e, t),
4321
- subgraph: e.subgraph ? xa(e.subgraph, t) : null
5064
+ ports: Q(e, t),
5065
+ params: Xa(e, t),
5066
+ subgraph: e.subgraph ? Qa(e.subgraph, t) : null
4322
5067
  };
4323
5068
  }
4324
- function xa(e, t) {
5069
+ function Qa(e, t) {
4325
5070
  return {
4326
5071
  version: e.version,
4327
- nodes: e.nodes.map((e) => ba(e, t)).sort((e, t) => String(e.id).localeCompare(String(t.id))),
4328
- edges: [...e.edges].sort((e, t) => va(e).localeCompare(va(t)))
5072
+ nodes: e.nodes.map((e) => Za(e, t)).sort((e, t) => String(e.id).localeCompare(String(t.id))),
5073
+ edges: [...e.edges].sort((e, t) => Ya(e).localeCompare(Ya(t)))
4329
5074
  };
4330
5075
  }
4331
- function Sa(e, t) {
4332
- return va(xa(e, t));
5076
+ function $a(e, t) {
5077
+ return Ya(Qa(e, t));
4333
5078
  }
4334
5079
  //#endregion
4335
5080
  //#region src/graph/tiling-test.ts
4336
- function Ca(e) {
5081
+ function eo(e) {
4337
5082
  return {
4338
- version: 2,
5083
+ version: 4,
4339
5084
  nodes: [
4340
5085
  {
4341
5086
  id: "n",
4342
5087
  type: "tileable-noise",
4343
5088
  params: {
4344
- noiseType: e,
4345
5089
  scale: 5,
4346
5090
  octaves: 4,
4347
- gain: .5
5091
+ gain: .5,
5092
+ ...e
4348
5093
  },
4349
5094
  position: {
4350
5095
  x: 0,
@@ -4354,8 +5099,8 @@ function Ca(e) {
4354
5099
  },
4355
5100
  {
4356
5101
  id: "pr",
4357
- type: "principled-bsdf",
4358
- params: {},
5102
+ type: "shader-material",
5103
+ params: { materialType: "physical" },
4359
5104
  position: {
4360
5105
  x: 300,
4361
5106
  y: 0
@@ -4386,7 +5131,7 @@ function Ca(e) {
4386
5131
  }]
4387
5132
  };
4388
5133
  }
4389
- function wa(e, t) {
5134
+ function to(e, t) {
4390
5135
  let n = (n, r) => e.data[(r * t + n) * 4], r = 0, i = 0;
4391
5136
  for (let e = 0; e < t; e++) {
4392
5137
  r += Math.abs(n(t - 1, e) - n(0, e));
@@ -4406,12 +5151,15 @@ function wa(e, t) {
4406
5151
  ratioV: a / Math.max(o, .001)
4407
5152
  };
4408
5153
  }
4409
- async function Ta(e, t, n = {}) {
4410
- 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 = [];
4411
- for (let o of s) {
4412
- let s = new Mi(Ca(o), t), l = await e.readImage(s, a, r);
4413
- if (!l) {
4414
- c.push({
5154
+ async function no(e, t, n = {}) {
5155
+ 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 = [];
5156
+ for (let o of u) {
5157
+ let s = new la(eo(l.has(o) ? {
5158
+ noiseType: "perlin-fbm",
5159
+ preset: o
5160
+ } : { noiseType: o }), t), c = await e.readImage(s, a, r);
5161
+ if (!c) {
5162
+ d.push({
4415
5163
  type: o,
4416
5164
  ratioH: NaN,
4417
5165
  ratioV: NaN,
@@ -4423,15 +5171,15 @@ async function Ta(e, t, n = {}) {
4423
5171
  });
4424
5172
  continue;
4425
5173
  }
4426
- n.onTile && await n.onTile(o, l);
4427
- let u = wa(l, r);
4428
- c.push({
5174
+ n.onTile && await n.onTile(o, c);
5175
+ let u = to(c, r);
5176
+ d.push({
4429
5177
  type: o,
4430
5178
  ...u,
4431
5179
  pass: u.ratioH <= i && u.ratioV <= i
4432
5180
  });
4433
5181
  }
4434
- return c;
5182
+ return d;
4435
5183
  }
4436
5184
  //#endregion
4437
- export { sa as BakedTextureSet, Re as COERCION_MATRIX, je as CURVE_CHANNELS, Ae as CURVE_IDENTITY, Pe as GROUP_INPUT_TYPE, Fe as GROUP_OUTPUT_TYPE, Ne as GROUP_TYPE, Ti as MATERIAL_DOCUMENT_VERSION, Ie as MATERIAL_OUTPUT_TYPE, ca as MaterialBakeService, _a as MaterialGraphRuntime, Mi as MaterialGraphSession, $r as NodeRegistry, Le as PBR_SOCKETS, ia as SURFACE_CHANNELS, ga as TexturedSurface, la as bakeService, Ei as cloneMaterialDocument, ze as coercionFor, _i as compileGraph, di as compileSockets, ui as countGraphNodes, Di as createDefaultMaterialDocument, ei as createDefaultRegistry, Sa as createMaterialTopologyKey, Me as curveToArray, ti as defaultRegistry, Oi as migrateMaterialDocument, hi as newSurfaceMaterial, Qr as nodeParamDefs, Z as nodePorts, si as readOutputResolution, Ta as runTilingTest };
5185
+ 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 };