@algorisys/tinyfly 0.86.2 → 0.88.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +7 -4
  2. package/bin/tinyfly.mjs +44 -6
  3. package/lib/addons/adapters.js +389 -281
  4. package/lib/addons/characters.js +3 -3
  5. package/lib/addons/load-scene-CQvcFWGJ.js +331 -0
  6. package/lib/addons/maps.js +1 -1
  7. package/lib/addons/scene-3d-webgl.js +52 -49
  8. package/lib/addons/scene-3d.js +299 -215
  9. package/lib/addons/shading-o5T_v9DT.js +89 -0
  10. package/lib/addons/{sketch-CA8ZXhxI.js → sketch-CYPUbk3Q.js} +2 -2
  11. package/lib/browser/tinyfly-scene-3d-webgl.iife.js +4 -2
  12. package/lib/browser/tinyfly-scene-3d.iife.js +2 -2
  13. package/lib/browser/tinyfly.iife.js +4 -4
  14. package/lib/browser/tinyfly.js +2204 -2043
  15. package/lib/browser/tinyfly.umd.js +4 -4
  16. package/lib/engine/tinyfly-engine.js +149 -106
  17. package/lib/engine/tinyfly-engine.umd.cjs +2 -2
  18. package/lib/headless/headless.js +165 -18
  19. package/lib/types/adapters/canvas/bloom.d.ts +33 -0
  20. package/lib/types/adapters/canvas/index.d.ts +3 -0
  21. package/lib/types/adapters/canvas/offscreen.d.ts +13 -0
  22. package/lib/types/adapters/canvas/trail.d.ts +57 -0
  23. package/lib/types/browser/index.d.ts +4 -0
  24. package/lib/types/engine/path/index.d.ts +2 -0
  25. package/lib/types/engine/path/trail.d.ts +79 -0
  26. package/lib/types/headless/index.d.ts +1 -0
  27. package/lib/types/headless/loop-check.d.ts +41 -0
  28. package/lib/types/headless/node-video.d.ts +8 -0
  29. package/lib/types/headless/video-scene.d.ts +9 -1
  30. package/lib/types/scene-3d/resolve-scene.d.ts +6 -0
  31. package/lib/types/scene-3d/scene-3d-adapter.d.ts +9 -1
  32. package/lib/types/scene-3d/scene-types.d.ts +42 -2
  33. package/lib/types/scene-3d/strokes.d.ts +30 -0
  34. package/lib/types/scene-3d/webgl/gl-data.d.ts +1 -0
  35. package/lib/types/scene-3d/webgl/shaders.d.ts +1 -1
  36. package/package.json +1 -1
  37. package/lib/addons/load-scene-vp14_Jj-.js +0 -324
  38. package/lib/addons/shading-ByG9UXd0.js +0 -85
@@ -1,7 +1,7 @@
1
- import { b as mn, s as Je, p as Rt, c as lt } from "./sketch-CA8ZXhxI.js";
2
- import { a as xs } from "./sketch-CA8ZXhxI.js";
1
+ import { c as mn, s as Je, p as Rt, b as lt } from "./sketch-CYPUbk3Q.js";
2
+ import { a as xs } from "./sketch-CYPUbk3Q.js";
3
3
  import { createRandom as yn, hashSeed as wn, getEasingFunction as Le, mat4 as N, vec3 as U, quat as yt } from "@algorisys/tinyfly";
4
- import { f as wt, h as kn, a as Sn } from "./load-scene-vp14_Jj-.js";
4
+ import { f as wt, h as kn, a as Sn } from "./load-scene-CQvcFWGJ.js";
5
5
  function Ke(e, t, n) {
6
6
  const r = e.length;
7
7
  if (r < 2) return [];
@@ -0,0 +1,331 @@
1
+ import { parsePath as B } from "@algorisys/tinyfly";
2
+ class j {
3
+ positions = [];
4
+ normals = [];
5
+ indices = [];
6
+ /** Add a vertex; returns its index. */
7
+ vertex(c, a, n, s, i, t) {
8
+ const o = Math.hypot(s, i, t) || 1;
9
+ return this.positions.push(c, a, n), this.normals.push(s / o, i / o, t / o), this.positions.length / 3 - 1;
10
+ }
11
+ /** Add a triangle, counter-clockwise seen from its front. */
12
+ triangle(c, a, n) {
13
+ this.indices.push(c, a, n);
14
+ }
15
+ /** Add a quad a-b-c-d (counter-clockwise) as two triangles. */
16
+ quad(c, a, n, s) {
17
+ this.indices.push(c, a, n, c, n, s);
18
+ }
19
+ build() {
20
+ return { positions: this.positions, normals: this.normals, indices: this.indices };
21
+ }
22
+ }
23
+ function C(e) {
24
+ const c = /* @__PURE__ */ new Map(), a = [];
25
+ for (let s = 0; s < e.positions.length / 3; s++) {
26
+ const i = [0, 1, 2].map((t) => Math.round(e.positions[s * 3 + t] * 1e6)).join(",");
27
+ c.has(i) || c.set(i, s), a.push(c.get(i));
28
+ }
29
+ const n = /* @__PURE__ */ new Map();
30
+ for (let s = 0; s < e.indices.length / 3; s++)
31
+ for (let i = 0; i < 3; i++) {
32
+ const t = a[e.indices[s * 3 + i]], o = a[e.indices[s * 3 + (i + 1) % 3]];
33
+ if (t === o) continue;
34
+ const r = t < o ? `${t}-${o}` : `${o}-${t}`, l = n.get(r);
35
+ l ? l.faces.push(s) : n.set(r, { a: Math.min(t, o), b: Math.max(t, o), faces: [s] });
36
+ }
37
+ return [...n.values()];
38
+ }
39
+ function z(e) {
40
+ let c = 0;
41
+ for (let a = 0; a < e.length; a++) {
42
+ const n = e[a], s = e[(a + 1) % e.length];
43
+ c += n.x * s.y - s.x * n.y;
44
+ }
45
+ return c;
46
+ }
47
+ function _(e, c) {
48
+ let a = !1;
49
+ for (let n = 0, s = c.length - 1; n < c.length; s = n++) {
50
+ const i = c[n], t = c[s];
51
+ i.y > e.y != t.y > e.y && e.x < (t.x - i.x) * (e.y - i.y) / (t.y - i.y) + i.x && (a = !a);
52
+ }
53
+ return a;
54
+ }
55
+ const X = (e, c, a) => (c.x - e.x) * (a.y - e.y) - (c.y - e.y) * (a.x - e.x), Y = (e, c) => e.x === c.x && e.y === c.y;
56
+ function N(e, c, a, n) {
57
+ return X(c, a, e) >= 0 && X(a, n, e) >= 0 && X(n, c, e) >= 0;
58
+ }
59
+ function F(e, c) {
60
+ let a = 0;
61
+ for (let h = 1; h < c.length; h++) c[h].x > c[a].x && (a = h);
62
+ const n = c[a];
63
+ let s = -1, i = 1 / 0;
64
+ for (let h = 0; h < e.length; h++) {
65
+ const f = e[h], m = e[(h + 1) % e.length];
66
+ if (f.y > n.y == m.y > n.y) continue;
67
+ const g = f.x + (n.y - f.y) * (m.x - f.x) / (m.y - f.y);
68
+ g >= n.x && g < i && (i = g, s = h);
69
+ }
70
+ if (s < 0) return e;
71
+ const t = e[s], o = e[(s + 1) % e.length];
72
+ let r = t.x > o.x ? s : (s + 1) % e.length;
73
+ const l = { x: i, y: n.y };
74
+ let u = 1 / 0;
75
+ for (let h = 0; h < e.length; h++) {
76
+ const f = e[h];
77
+ if (h === r || f.x < n.x) continue;
78
+ const m = e[r];
79
+ if (!(N(f, n, l, m) || N(f, n, m, l))) continue;
80
+ const p = Math.abs(Math.atan2(f.y - n.y, f.x - n.x));
81
+ p < u && (u = p, r = h);
82
+ }
83
+ const d = c.slice(a).concat(c.slice(0, a));
84
+ return [...e.slice(0, r + 1), ...d, n, e[r], ...e.slice(r + 1)];
85
+ }
86
+ function H(e, c = []) {
87
+ const a = z(e) >= 0 ? e : [...e].reverse(), n = c.map((d) => z(d) <= 0 ? d : [...d].reverse()), s = [...a, ...n.flat()], i = /* @__PURE__ */ new Map();
88
+ s.forEach((d, h) => i.set(d, h));
89
+ const t = [...n].sort((d, h) => Math.max(...h.map((f) => f.x)) - Math.max(...d.map((f) => f.x)));
90
+ let o = a;
91
+ for (const d of t) o = F(o, d);
92
+ const r = o.map((d) => i.get(d)), l = [];
93
+ let u = r.length * r.length;
94
+ for (; r.length > 3 && u-- > 0; ) {
95
+ let d = !1;
96
+ for (let h = 0; h < r.length; h++) {
97
+ const f = r[(h + r.length - 1) % r.length], m = r[h], g = r[(h + 1) % r.length], [p, M, b] = [s[f], s[m], s[g]];
98
+ if (X(p, M, b) <= 0) continue;
99
+ let $ = !1;
100
+ for (const y of r) {
101
+ const w = s[y];
102
+ if (!(y === f || y === m || y === g || Y(w, p) || Y(w, M) || Y(w, b)) && N(w, p, M, b)) {
103
+ $ = !0;
104
+ break;
105
+ }
106
+ }
107
+ if (!$) {
108
+ l.push(f, m, g), r.splice(h, 1), d = !0;
109
+ break;
110
+ }
111
+ }
112
+ d || (l.push(r[r.length - 1], r[0], r[1]), r.splice(0, 1));
113
+ }
114
+ return r.length === 3 && l.push(r[0], r[1], r[2]), { points: s, triangles: l };
115
+ }
116
+ function U(e, c) {
117
+ const a = /* @__PURE__ */ new Map();
118
+ for (const n of B(e).segments) {
119
+ a.has(n.subpath) || a.set(n.subpath, [{ x: n.startX, y: -n.startY }]);
120
+ const s = a.get(n.subpath);
121
+ if (n.type === "L")
122
+ s.push({ x: n.endX, y: -n.endY });
123
+ else {
124
+ const [i, t, o, r, l, u] = n.points;
125
+ for (let d = 1; d <= c; d++) {
126
+ const h = d / c, f = 1 - h, m = f * f * f * n.startX + 3 * f * f * h * i + 3 * f * h * h * o + h * h * h * l, g = f * f * f * n.startY + 3 * f * f * h * t + 3 * f * h * h * r + h * h * h * u;
127
+ s.push({ x: m, y: -g });
128
+ }
129
+ }
130
+ }
131
+ return [...a.values()].map((n) => n.filter((s, i) => i === 0 || s.x !== n[i - 1].x || s.y !== n[i - 1].y)).map((n) => n.length > 1 && n[0].x === n[n.length - 1].x && n[0].y === n[n.length - 1].y ? n.slice(0, -1) : n).filter((n) => n.length >= 3 && Math.abs(z(n)) > 1e-12);
132
+ }
133
+ function W(e, c) {
134
+ const a = U(e, Math.max(1, Math.round(c.curveSegments ?? 12))), n = new j();
135
+ if (a.length === 0) return n.build();
136
+ const s = a.flat(), i = Math.min(...s.map((p) => p.x)), t = Math.max(...s.map((p) => p.x)), o = Math.min(...s.map((p) => p.y)), r = Math.max(...s.map((p) => p.y)), l = (c.width ?? 1) / Math.max(t - i, 1e-9), u = (i + t) / 2, d = (o + r) / 2, h = a.map((p) => p.map((M) => ({ x: (M.x - u) * l, y: (M.y - d) * l }))), f = h.map((p, M) => h.filter((b, $) => $ !== M && _(p[0], b)).length), m = c.depth / 2, g = -c.depth / 2;
137
+ return h.forEach((p, M) => {
138
+ if (f[M] % 2 === 1) return;
139
+ const b = h.filter((x, v) => f[v] === f[M] + 1 && _(x[0], p)), { points: $, triangles: y } = H(p, b), w = $.map((x) => n.vertex(x.x, x.y, m, 0, 0, 1)), E = $.map((x) => n.vertex(x.x, x.y, g, 0, 0, -1));
140
+ for (let x = 0; x < y.length; x += 3)
141
+ n.triangle(w[y[x]], w[y[x + 1]], w[y[x + 2]]), n.triangle(E[y[x]], E[y[x + 2]], E[y[x + 1]]);
142
+ for (const x of [z(p) >= 0 ? p : [...p].reverse(), ...b.map((v) => z(v) <= 0 ? v : [...v].reverse())])
143
+ for (let v = 0; v < x.length; v++) {
144
+ const q = x[v], A = x[(v + 1) % x.length], I = A.y - q.y, S = -(A.x - q.x), D = n.vertex(q.x, q.y, g, I, S, 0), L = n.vertex(A.x, A.y, g, I, S, 0), O = n.vertex(A.x, A.y, m, I, S, 0), T = n.vertex(q.x, q.y, m, I, S, 0);
145
+ n.quad(D, L, O, T);
146
+ }
147
+ }), n.build();
148
+ }
149
+ const k = Math.PI * 2;
150
+ function Z([e, c, a]) {
151
+ const n = new j(), s = e / 2, i = c / 2, t = a / 2, o = [
152
+ [[0, 0, 1], [[-s, -i, t], [s, -i, t], [s, i, t], [-s, i, t]]],
153
+ [[0, 0, -1], [[s, -i, -t], [-s, -i, -t], [-s, i, -t], [s, i, -t]]],
154
+ [[1, 0, 0], [[s, -i, t], [s, -i, -t], [s, i, -t], [s, i, t]]],
155
+ [[-1, 0, 0], [[-s, -i, -t], [-s, -i, t], [-s, i, t], [-s, i, -t]]],
156
+ [[0, 1, 0], [[-s, i, t], [s, i, t], [s, i, -t], [-s, i, -t]]],
157
+ [[0, -1, 0], [[-s, -i, -t], [s, -i, -t], [s, -i, t], [-s, -i, t]]]
158
+ ];
159
+ for (const [[r, l, u], d] of o) {
160
+ const [h, f, m, g] = d.map(([p, M, b]) => n.vertex(p, M, b, r, l, u));
161
+ n.quad(h, f, m, g);
162
+ }
163
+ return n.build();
164
+ }
165
+ function G([e, c], a = 1) {
166
+ const n = new j(), s = Math.max(1, Math.round(a)), i = [];
167
+ for (let t = 0; t <= s; t++) {
168
+ const o = c / 2 - c * t / s;
169
+ i.push(Array.from({ length: s + 1 }, (r, l) => n.vertex(-e / 2 + e * l / s, 0, o, 0, 1, 0)));
170
+ }
171
+ for (let t = 0; t < s; t++)
172
+ for (let o = 0; o < s; o++) n.quad(i[t][o], i[t][o + 1], i[t + 1][o + 1], i[t + 1][o]);
173
+ return n.build();
174
+ }
175
+ function J(e, c = 16) {
176
+ const a = new j(), n = Math.max(6, Math.round(c)), s = Math.max(3, Math.round(n / 2)), i = [];
177
+ for (let t = 0; t <= s; t++) {
178
+ const o = t / s * Math.PI, r = [];
179
+ for (let l = 0; l <= n; l++) {
180
+ const u = l / n * k, d = Math.sin(o) * Math.sin(u), h = Math.cos(o), f = Math.sin(o) * Math.cos(u);
181
+ r.push(a.vertex(d * e, h * e, f * e, d, h, f));
182
+ }
183
+ i.push(r);
184
+ }
185
+ for (let t = 0; t < s; t++)
186
+ for (let o = 0; o < n; o++) {
187
+ const r = i[t][o], l = i[t + 1][o], u = i[t + 1][o + 1], d = i[t][o + 1];
188
+ t > 0 && a.triangle(r, l, d), t < s - 1 && a.triangle(l, u, d);
189
+ }
190
+ return a.build();
191
+ }
192
+ function P(e, c, a, n, s) {
193
+ const i = e.vertex(0, a, 0, 0, n, 0), t = Array.from({ length: s }, (o, r) => {
194
+ const l = r / s * k;
195
+ return e.vertex(Math.sin(l) * c, a, Math.cos(l) * c, 0, n, 0);
196
+ });
197
+ for (let o = 0; o < s; o++) {
198
+ const r = t[o], l = t[(o + 1) % s];
199
+ n === 1 ? e.triangle(i, r, l) : e.triangle(i, l, r);
200
+ }
201
+ }
202
+ function K(e, c, a = 24) {
203
+ const n = new j(), s = Math.max(6, Math.round(a)), i = c / 2, t = -c / 2, o = (u) => Array.from({ length: s + 1 }, (d, h) => {
204
+ const f = h / s * k;
205
+ return n.vertex(Math.sin(f) * e, u, Math.cos(f) * e, Math.sin(f), 0, Math.cos(f));
206
+ }), r = o(t), l = o(i);
207
+ for (let u = 0; u < s; u++) n.quad(r[u], r[u + 1], l[u + 1], l[u]);
208
+ return P(n, e, i, 1, s), P(n, e, t, -1, s), n.build();
209
+ }
210
+ function Q(e, c, a = 24) {
211
+ const n = new j(), s = Math.max(6, Math.round(a)), i = c / 2, t = -c / 2, o = e / c;
212
+ for (let r = 0; r < s; r++) {
213
+ const l = r / s * k, u = (r + 1) / s * k, d = (l + u) / 2, h = n.vertex(Math.sin(l) * e, t, Math.cos(l) * e, Math.sin(l), o, Math.cos(l)), f = n.vertex(Math.sin(u) * e, t, Math.cos(u) * e, Math.sin(u), o, Math.cos(u)), m = n.vertex(0, i, 0, Math.sin(d), o, Math.cos(d));
214
+ n.triangle(h, f, m);
215
+ }
216
+ return P(n, e, t, -1, s), n.build();
217
+ }
218
+ function R(e, c, a = 24) {
219
+ const n = new j(), s = Math.max(6, Math.round(a)), i = Math.max(4, Math.round(s / 2)), t = [];
220
+ for (let o = 0; o <= s; o++) {
221
+ const r = o / s * k, l = [];
222
+ for (let u = 0; u <= i; u++) {
223
+ const d = u / i * k, h = Math.cos(d) * Math.sin(r), f = Math.sin(d), m = Math.cos(d) * Math.cos(r), g = e + c * Math.cos(d);
224
+ l.push(n.vertex(g * Math.sin(r), c * Math.sin(d), g * Math.cos(r), h, f, m));
225
+ }
226
+ t.push(l);
227
+ }
228
+ for (let o = 0; o < s; o++)
229
+ for (let r = 0; r < i; r++) n.quad(t[o][r], t[o + 1][r], t[o + 1][r + 1], t[o][r + 1]);
230
+ return n.build();
231
+ }
232
+ function V(e) {
233
+ switch (e.type) {
234
+ case "box":
235
+ return Z(e.size);
236
+ case "plane":
237
+ return G(e.size, e.segments);
238
+ case "sphere":
239
+ return J(e.radius, e.segments);
240
+ case "cylinder":
241
+ return K(e.radius, e.height, e.segments);
242
+ case "cone":
243
+ return Q(e.radius, e.height, e.segments);
244
+ case "torus":
245
+ return R(e.radius, e.tube, e.segments);
246
+ case "extrude":
247
+ return W(e.path, { depth: e.depth, width: e.width, curveSegments: e.curveSegments });
248
+ }
249
+ }
250
+ const tt = [
251
+ { name: "position", vector: "position", components: ["x", "y", "z"] },
252
+ { name: "rotation", vector: "quaternion", components: ["rotateX", "rotateY", "rotateZ"] }
253
+ ];
254
+ function nt(e, c = []) {
255
+ const a = [], n = /* @__PURE__ */ new Map();
256
+ for (const t of e.objects) {
257
+ if (t.id ? n.has(t.id) && a.push(`two objects share the id "${t.id}"`) : a.push("an object has no id"), t.parent !== void 0 && !n.has(t.parent) && a.push(`"${t.id}" has parent "${t.parent}", which must be an earlier object`), t.quaternion && t.quaternion.length !== 4 && a.push(`"${t.id}": a quaternion has four numbers`), t.kind === "mesh") {
258
+ e.materials?.[t.material] || a.push(`"${t.id}" uses material "${t.material}", which is not in materials`);
259
+ const o = t.geometry, r = o.type === "box" || o.type === "plane" ? o.size : o.type === "torus" ? [o.radius, o.tube] : o.type === "sphere" ? [o.radius] : o.type === "extrude" ? [o.depth, o.width ?? 1] : [o.radius, o.height];
260
+ o.type === "extrude" && !(typeof o.path == "string" && /^\s*[Mm]/.test(o.path)) && a.push(`"${t.id}": an extrude needs a path that starts with M`), r.every((l) => Number.isFinite(l) && l > 0) || a.push(`"${t.id}": a ${o.type}'s sizes must be positive`);
261
+ }
262
+ if (t.kind === "line" || t.kind === "trail") {
263
+ t.width !== void 0 && !(t.width > 0) && a.push(`"${t.id}": width must be positive`);
264
+ for (const o of ["taper", "fade", "opacity"]) {
265
+ const r = t[o];
266
+ r !== void 0 && !(r >= 0 && r <= 1) && a.push(`"${t.id}": ${o} is between 0 and 1`);
267
+ }
268
+ }
269
+ t.kind === "line" && (Array.isArray(t.points) && t.points.length >= 2 && t.points.every((r) => Array.isArray(r) && r.length === 3 && r.every(Number.isFinite)) || a.push(`"${t.id}": a line needs two or more points of three numbers`)), t.kind === "trail" && (t.length > 0 || a.push(`"${t.id}": a trail's length (ms) must be positive`), (t.follow === t.id || !e.objects.some((o) => o.id === t.follow)) && a.push(`"${t.id}" follows "${t.follow}", which is not another object in the scene`), t.samples !== void 0 && !(t.samples >= 2) && a.push(`"${t.id}": a trail needs at least 2 samples`)), t.kind === "camera" && (t.near > 0 && t.far > t.near || a.push(`camera "${t.id}": near must be above 0 and far beyond it`), t.projection === "perspective" && !(t.fov > 0 && t.fov < 180) && a.push(`camera "${t.id}": fov is between 0 and 180 degrees`), t.projection === "orthographic" && !(t.height > 0) && a.push(`camera "${t.id}": height must be positive`)), t.id && n.set(t.id, t);
270
+ }
271
+ const s = n.get(e.camera);
272
+ s ? s.kind !== "camera" && a.push(`the scene's camera "${e.camera}" is a ${s.kind}, not a camera`) : a.push(`the scene's camera "${e.camera}" is not one of its objects`), e.fog && !(e.fog.far > e.fog.near) && a.push("fog: far must be beyond near");
273
+ const i = /* @__PURE__ */ new Map();
274
+ for (const t of c) {
275
+ if (!t.target.startsWith(`${e.id}/`)) continue;
276
+ const o = t.target.slice(e.id.length + 1);
277
+ i.has(o) || i.set(o, /* @__PURE__ */ new Set()), i.get(o).add(t.property);
278
+ }
279
+ for (const [t, o] of i) {
280
+ n.has(t) || a.push(`a track animates "${e.id}/${t}", which is not in the scene`);
281
+ for (const r of tt)
282
+ o.has(r.vector) && r.components.some((l) => o.has(l)) && a.push(`"${t}": its ${r.name} is animated both by ${r.vector} and by ${r.components.join(" / ")}; use one`);
283
+ }
284
+ return a;
285
+ }
286
+ function et(e) {
287
+ const c = Array.from({ length: e.indices.length / 3 }, () => []);
288
+ for (const a of C(e))
289
+ for (const n of a.faces) {
290
+ const s = a.faces.find((i) => i !== n) ?? -1;
291
+ c[n].push({ a: a.a, b: a.b, across: s });
292
+ }
293
+ return { ...e, faceEdges: c };
294
+ }
295
+ function at(e, c = {}) {
296
+ const a = new Map((c.kinds ?? []).map((t) => [t.kind, t])), n = nt(e);
297
+ for (const t of e.objects) {
298
+ if (st.has(t.kind)) continue;
299
+ const o = a.get(t.kind);
300
+ o ? n.push(...(o.validate?.(t) ?? []).map((r) => `"${t.id}": ${r}`)) : n.push(`"${t.id}" is a ${t.kind}: load the scene with that kind (for characters: loadScene3D(scene, { kinds: [characterObjects] }), from @algorisys/tinyfly/characters)`);
301
+ }
302
+ if (n.length > 0) throw new Error(`scene-3d: "${e.id}" is not valid:
303
+ - ${n.join(`
304
+ - `)}`);
305
+ const s = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
306
+ for (const t of e.objects) {
307
+ t.kind === "mesh" && s.set(t.id, et(V(t.geometry)));
308
+ const o = a.get(t.kind);
309
+ o?.prepare && i.set(t.id, o.prepare(t));
310
+ }
311
+ return { scene: e, meshes: s, kinds: a, prepared: i };
312
+ }
313
+ const st = /* @__PURE__ */ new Set(["group", "mesh", "camera", "light", "line", "trail"]);
314
+ export {
315
+ j as M,
316
+ K as a,
317
+ Z as b,
318
+ Q as c,
319
+ _ as d,
320
+ W as e,
321
+ et as f,
322
+ V as g,
323
+ J as h,
324
+ H as i,
325
+ at as l,
326
+ C as m,
327
+ G as p,
328
+ z as s,
329
+ R as t,
330
+ nt as v
331
+ };
@@ -1,4 +1,4 @@
1
- import { s as B, p as K, a as v, c as R } from "./sketch-CA8ZXhxI.js";
1
+ import { s as B, p as K, a as v, b as R } from "./sketch-CYPUbk3Q.js";
2
2
  const T = 256, N = 85.05112878, O = (a) => Math.max(-N, Math.min(N, a));
3
3
  function A(a, n) {
4
4
  const e = Math.sin(O(n) * Math.PI / 180);
@@ -1,6 +1,6 @@
1
- import { p as _ } from "./shading-ByG9UXd0.js";
1
+ import { p as _ } from "./shading-o5T_v9DT.js";
2
2
  import { mat4 as h, vec3 as v } from "@algorisys/tinyfly";
3
- const s = 8, p = { unlit: 0, flat: 1, lambert: 2, toon: 3 }, w = { ambient: 0, directional: 1, point: 2, spot: 3 }, A = `#version 300 es
3
+ const c = 8, p = { unlit: 0, flat: 1, lambert: 2, toon: 3 }, w = { ambient: 0, directional: 1, point: 2, spot: 3 }, A = `#version 300 es
4
4
  in vec3 a_position;
5
5
  in vec3 a_normal;
6
6
  uniform mat4 u_model;
@@ -17,7 +17,7 @@ void main() {
17
17
  }
18
18
  `, b = `#version 300 es
19
19
  precision highp float;
20
- #define MAX_LIGHTS ${s}
20
+ #define MAX_LIGHTS ${c}
21
21
  uniform int u_lightCount;
22
22
  uniform int u_lightKind[MAX_LIGHTS];
23
23
  uniform vec3 u_lightColor[MAX_LIGHTS];
@@ -27,6 +27,7 @@ uniform vec3 u_lightDirection[MAX_LIGHTS];
27
27
  uniform float u_lightRange[MAX_LIGHTS];
28
28
  uniform vec2 u_lightCone[MAX_LIGHTS];
29
29
  uniform vec3 u_color;
30
+ uniform vec3 u_emissive;
30
31
  uniform float u_opacity;
31
32
  uniform int u_shading;
32
33
  uniform float u_bands;
@@ -80,6 +81,7 @@ void main() {
80
81
  }
81
82
  rgb *= light;
82
83
  }
84
+ rgb += u_emissive;
83
85
  if (u_fog) {
84
86
  float amount = clamp((distance(v_world, u_eye) - u_fogRange.x) / (u_fogRange.y - u_fogRange.x), 0.0, 1.0);
85
87
  rgb = mix(rgb, u_fogColor, amount);
@@ -117,31 +119,32 @@ void main() {
117
119
  { id: "default-ambient", light: "ambient", color: "#ffffff", intensity: 0.35, position: [0, 0, 0], direction: [0, -1, 0], angle: 30 },
118
120
  { id: "default-key", light: "directional", color: "#ffffff", intensity: 0.8, position: [3, 5, 4], direction: v.normalize([-3, -5, -4]), angle: 30 }
119
121
  ];
120
- function F(l) {
121
- const t = (l.length > 0 ? l : R).slice(0, s), i = {
122
+ function F(a) {
123
+ const t = (a.length > 0 ? a : R).slice(0, c), i = {
122
124
  count: t.length,
123
- kind: new Int32Array(s),
124
- color: new Float32Array(s * 3),
125
- intensity: new Float32Array(s),
126
- position: new Float32Array(s * 3),
127
- direction: new Float32Array(s * 3),
128
- range: new Float32Array(s),
129
- cone: new Float32Array(s * 2)
125
+ kind: new Int32Array(c),
126
+ color: new Float32Array(c * 3),
127
+ intensity: new Float32Array(c),
128
+ position: new Float32Array(c * 3),
129
+ direction: new Float32Array(c * 3),
130
+ range: new Float32Array(c),
131
+ cone: new Float32Array(c * 2)
130
132
  };
131
133
  return t.forEach((o, n) => {
132
134
  i.kind[n] = w[o.light], i.color.set(_(o.color), n * 3), i.intensity[n] = o.intensity, i.position.set(o.position, n * 3), i.direction.set(o.direction, n * 3), i.range[n] = o.range ?? 0, i.cone[n * 2] = Math.cos(o.angle * Math.PI / 180), i.cone[n * 2 + 1] = Math.cos(o.angle * 0.8 * Math.PI / 180);
133
135
  }), i;
134
136
  }
135
- function L(l, t, i) {
137
+ function L(a, t, i) {
136
138
  return {
137
- color: _(t ?? l.color),
139
+ color: _(t ?? a.color),
140
+ emissive: a.emissive ? _(a.emissive) : [0, 0, 0],
138
141
  opacity: i,
139
- shading: p[l.shading ?? "lambert"],
140
- bands: l.bands ?? 3
142
+ shading: p[a.shading ?? "lambert"],
143
+ bands: a.bands ?? 3
141
144
  };
142
145
  }
143
- function g(l) {
144
- const t = h.transpose(h.invert(l) ?? h.identity());
146
+ function m(a) {
147
+ const t = h.transpose(h.invert(a) ?? h.identity());
145
148
  return new Float32Array([t[0], t[1], t[2], t[4], t[5], t[6], t[8], t[9], t[10]]);
146
149
  }
147
150
  class C {
@@ -151,17 +154,17 @@ class C {
151
154
  buffers = /* @__PURE__ */ new WeakMap();
152
155
  overlay;
153
156
  constructor(t, i = {}) {
154
- this.gl = t, this.overlay = i.overlay, this.surface = m(t, A, b), this.outline = m(t, E, y);
157
+ this.gl = t, this.overlay = i.overlay, this.surface = g(t, A, b), this.outline = g(t, E, y);
155
158
  }
156
159
  render(t) {
157
160
  const i = this.gl, o = i.drawingBufferWidth, n = i.drawingBufferHeight;
158
161
  i.viewport(0, 0, o, n);
159
162
  const e = t.background && t.background !== "transparent" ? _(t.background) : null;
160
163
  i.clearColor(e?.[0] ?? 0, e?.[1] ?? 0, e?.[2] ?? 0, e ? 1 : 0), i.clearDepth(1), i.clear(i.COLOR_BUFFER_BIT | i.DEPTH_BUFFER_BIT), i.enable(i.DEPTH_TEST), i.depthFunc(i.LEQUAL), i.enable(i.CULL_FACE), i.frontFace(i.CCW);
161
- const a = t.meshes.filter((r) => r.opacity >= 1), c = t.camera.position, u = (r) => Math.hypot(r.world[12] - c[0], r.world[13] - c[1], r.world[14] - c[2]), d = t.meshes.filter((r) => r.opacity < 1).sort((r, f) => u(f) - u(r) || r.objectIndex - f.objectIndex);
164
+ const l = t.meshes.filter((r) => r.opacity >= 1), s = t.camera.position, u = (r) => Math.hypot(r.world[12] - s[0], r.world[13] - s[1], r.world[14] - s[2]), d = t.meshes.filter((r) => r.opacity < 1).sort((r, f) => u(f) - u(r) || r.objectIndex - f.objectIndex);
162
165
  i.disable(i.BLEND), i.depthMask(!0);
163
- for (const r of a) r.material.outline && this.drawOutline(t, r, o, n);
164
- for (const r of a) this.drawSurface(t, r);
166
+ for (const r of l) r.material.outline && this.drawOutline(t, r, o, n);
167
+ for (const r of l) this.drawSurface(t, r);
165
168
  i.enable(i.BLEND), i.blendFunc(i.SRC_ALPHA, i.ONE_MINUS_SRC_ALPHA), i.depthMask(!1);
166
169
  for (const r of d) this.drawSurface(t, r);
167
170
  if (i.depthMask(!0), i.disable(i.BLEND), this.overlay && t.drawables.length > 0) {
@@ -176,18 +179,18 @@ class C {
176
179
  const o = this.gl, n = this.surface;
177
180
  o.useProgram(n.program), i.material.doubleSided ? o.disable(o.CULL_FACE) : (o.enable(o.CULL_FACE), o.cullFace(o.BACK)), this.bindMesh(n, i.mesh);
178
181
  const e = n.uniform;
179
- o.uniformMatrix4fv(e("u_model"), !1, i.world), o.uniformMatrix4fv(e("u_view"), !1, t.camera.view), o.uniformMatrix4fv(e("u_projection"), !1, t.camera.projection), o.uniformMatrix3fv(e("u_normalMatrix"), !1, g(i.world));
180
- const a = F(t.lights);
181
- o.uniform1i(e("u_lightCount"), a.count), o.uniform1iv(e("u_lightKind"), a.kind), o.uniform3fv(e("u_lightColor"), a.color), o.uniform1fv(e("u_lightIntensity"), a.intensity), o.uniform3fv(e("u_lightPosition"), a.position), o.uniform3fv(e("u_lightDirection"), a.direction), o.uniform1fv(e("u_lightRange"), a.range), o.uniform2fv(e("u_lightCone"), a.cone);
182
- const c = L(i.material, i.color, i.opacity);
183
- o.uniform3fv(e("u_color"), c.color), o.uniform1f(e("u_opacity"), c.opacity), o.uniform1i(e("u_shading"), c.shading), o.uniform1f(e("u_bands"), c.bands), o.uniform3fv(e("u_eye"), t.camera.position), o.uniform3fv(e("u_forward"), t.camera.forward), o.uniform1i(e("u_orthographic"), t.camera.orthographic ? 1 : 0), o.uniform1i(e("u_fog"), t.fog ? 1 : 0), t.fog && (o.uniform3fv(e("u_fogColor"), _(t.fog.color)), o.uniform2f(e("u_fogRange"), t.fog.near, t.fog.far)), o.drawElements(o.TRIANGLES, i.mesh.indices.length, o.UNSIGNED_INT, 0);
182
+ o.uniformMatrix4fv(e("u_model"), !1, i.world), o.uniformMatrix4fv(e("u_view"), !1, t.camera.view), o.uniformMatrix4fv(e("u_projection"), !1, t.camera.projection), o.uniformMatrix3fv(e("u_normalMatrix"), !1, m(i.world));
183
+ const l = F(t.lights);
184
+ o.uniform1i(e("u_lightCount"), l.count), o.uniform1iv(e("u_lightKind"), l.kind), o.uniform3fv(e("u_lightColor"), l.color), o.uniform1fv(e("u_lightIntensity"), l.intensity), o.uniform3fv(e("u_lightPosition"), l.position), o.uniform3fv(e("u_lightDirection"), l.direction), o.uniform1fv(e("u_lightRange"), l.range), o.uniform2fv(e("u_lightCone"), l.cone);
185
+ const s = L(i.material, i.color, i.opacity);
186
+ o.uniform3fv(e("u_color"), s.color), o.uniform3fv(e("u_emissive"), s.emissive), o.uniform1f(e("u_opacity"), s.opacity), o.uniform1i(e("u_shading"), s.shading), o.uniform1f(e("u_bands"), s.bands), o.uniform3fv(e("u_eye"), t.camera.position), o.uniform3fv(e("u_forward"), t.camera.forward), o.uniform1i(e("u_orthographic"), t.camera.orthographic ? 1 : 0), o.uniform1i(e("u_fog"), t.fog ? 1 : 0), t.fog && (o.uniform3fv(e("u_fogColor"), _(t.fog.color)), o.uniform2f(e("u_fogRange"), t.fog.near, t.fog.far)), o.drawElements(o.TRIANGLES, i.mesh.indices.length, o.UNSIGNED_INT, 0);
184
187
  }
185
188
  drawOutline(t, i, o, n) {
186
- const e = this.gl, a = this.outline, c = i.material.outline;
187
- e.useProgram(a.program), e.enable(e.CULL_FACE), e.cullFace(e.FRONT), this.bindMesh(a, i.mesh);
188
- const u = a.uniform;
189
- e.uniformMatrix4fv(u("u_model"), !1, i.world), e.uniformMatrix4fv(u("u_view"), !1, t.camera.view), e.uniformMatrix4fv(u("u_projection"), !1, t.camera.projection), e.uniformMatrix3fv(u("u_normalMatrix"), !1, g(i.world)), e.uniform2f(u("u_viewport"), o, n), e.uniform1f(u("u_width"), c.width * (o / t.width));
190
- const [d, r, f] = _(c.color);
189
+ const e = this.gl, l = this.outline, s = i.material.outline;
190
+ e.useProgram(l.program), e.enable(e.CULL_FACE), e.cullFace(e.FRONT), this.bindMesh(l, i.mesh);
191
+ const u = l.uniform;
192
+ e.uniformMatrix4fv(u("u_model"), !1, i.world), e.uniformMatrix4fv(u("u_view"), !1, t.camera.view), e.uniformMatrix4fv(u("u_projection"), !1, t.camera.projection), e.uniformMatrix3fv(u("u_normalMatrix"), !1, m(i.world)), e.uniform2f(u("u_viewport"), o, n), e.uniform1f(u("u_width"), s.width * (o / t.width));
193
+ const [d, r, f] = _(s.color);
191
194
  e.uniform4f(u("u_ink"), d, r, f, 1), e.drawElements(e.TRIANGLES, i.mesh.indices.length, e.UNSIGNED_INT, 0), e.cullFace(e.BACK);
192
195
  }
193
196
  /** Upload a mesh once; bind its buffers to the program's attributes. */
@@ -195,16 +198,16 @@ class C {
195
198
  const o = this.gl;
196
199
  let n = this.buffers.get(i);
197
200
  if (!n) {
198
- const a = o.createBuffer();
199
- o.bindBuffer(o.ARRAY_BUFFER, a), o.bufferData(o.ARRAY_BUFFER, new Float32Array(i.positions), o.STATIC_DRAW);
200
- const c = o.createBuffer();
201
- o.bindBuffer(o.ARRAY_BUFFER, c), o.bufferData(o.ARRAY_BUFFER, new Float32Array(i.normals), o.STATIC_DRAW);
201
+ const l = o.createBuffer();
202
+ o.bindBuffer(o.ARRAY_BUFFER, l), o.bufferData(o.ARRAY_BUFFER, new Float32Array(i.positions), o.STATIC_DRAW);
203
+ const s = o.createBuffer();
204
+ o.bindBuffer(o.ARRAY_BUFFER, s), o.bufferData(o.ARRAY_BUFFER, new Float32Array(i.normals), o.STATIC_DRAW);
202
205
  const u = o.createBuffer();
203
- o.bindBuffer(o.ELEMENT_ARRAY_BUFFER, u), o.bufferData(o.ELEMENT_ARRAY_BUFFER, new Uint32Array(i.indices), o.STATIC_DRAW), n = { position: a, normal: c, index: u }, this.buffers.set(i, n);
206
+ o.bindBuffer(o.ELEMENT_ARRAY_BUFFER, u), o.bufferData(o.ELEMENT_ARRAY_BUFFER, new Uint32Array(i.indices), o.STATIC_DRAW), n = { position: l, normal: s, index: u }, this.buffers.set(i, n);
204
207
  }
205
- const e = (a, c) => {
206
- const u = o.getAttribLocation(t.program, a);
207
- u < 0 || (o.bindBuffer(o.ARRAY_BUFFER, c), o.enableVertexAttribArray(u), o.vertexAttribPointer(u, 3, o.FLOAT, !1, 0, 0));
208
+ const e = (l, s) => {
209
+ const u = o.getAttribLocation(t.program, l);
210
+ u < 0 || (o.bindBuffer(o.ARRAY_BUFFER, s), o.enableVertexAttribArray(u), o.vertexAttribPointer(u, 3, o.FLOAT, !1, 0, 0));
208
211
  };
209
212
  e("a_position", n.position), e("a_normal", n.normal), o.bindBuffer(o.ELEMENT_ARRAY_BUFFER, n.index);
210
213
  }
@@ -213,25 +216,25 @@ class C {
213
216
  this.gl.deleteProgram(this.surface.program), this.gl.deleteProgram(this.outline.program);
214
217
  }
215
218
  }
216
- function m(l, t, i) {
217
- const o = (a, c) => {
218
- const u = l.createShader(a);
219
- if (l.shaderSource(u, c), l.compileShader(u), !l.getShaderParameter(u, l.COMPILE_STATUS)) throw new Error(`scene-3d webgl: shader failed to compile — ${l.getShaderInfoLog(u)}`);
219
+ function g(a, t, i) {
220
+ const o = (l, s) => {
221
+ const u = a.createShader(l);
222
+ if (a.shaderSource(u, s), a.compileShader(u), !a.getShaderParameter(u, a.COMPILE_STATUS)) throw new Error(`scene-3d webgl: shader failed to compile — ${a.getShaderInfoLog(u)}`);
220
223
  return u;
221
- }, n = l.createProgram();
222
- if (l.attachShader(n, o(l.VERTEX_SHADER, t)), l.attachShader(n, o(l.FRAGMENT_SHADER, i)), l.linkProgram(n), !l.getProgramParameter(n, l.LINK_STATUS)) throw new Error(`scene-3d webgl: program failed to link — ${l.getProgramInfoLog(n)}`);
224
+ }, n = a.createProgram();
225
+ if (a.attachShader(n, o(a.VERTEX_SHADER, t)), a.attachShader(n, o(a.FRAGMENT_SHADER, i)), a.linkProgram(n), !a.getProgramParameter(n, a.LINK_STATUS)) throw new Error(`scene-3d webgl: program failed to link — ${a.getProgramInfoLog(n)}`);
223
226
  const e = /* @__PURE__ */ new Map();
224
227
  return {
225
228
  program: n,
226
- uniform: (a) => (e.has(a) || e.set(a, l.getUniformLocation(n, a)), e.get(a))
229
+ uniform: (l) => (e.has(l) || e.set(l, a.getUniformLocation(n, l)), e.get(l))
227
230
  };
228
231
  }
229
232
  export {
230
233
  w as LIGHT_CODE,
231
- s as MAX_LIGHTS,
234
+ c as MAX_LIGHTS,
232
235
  p as SHADING_CODE,
233
236
  C as WebGL2Renderer,
234
- g as normalMatrix3,
237
+ m as normalMatrix3,
235
238
  F as packLights,
236
239
  L as surfaceUniforms
237
240
  };