@algorisys/tinyfly 0.100.0 → 0.102.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 (71) hide show
  1. package/README.md +6 -6
  2. package/bin/tinyfly.mjs +16 -6
  3. package/docs/character-appearance.md +26 -0
  4. package/docs/editor-guide.md +1 -1
  5. package/docs/examples.md +1 -1
  6. package/docs/getting-started.md +1 -1
  7. package/docs/gsap-compat.md +1 -1
  8. package/docs/llm-guide.md +22 -4
  9. package/docs/maps.md +2 -2
  10. package/docs/scene-3d.md +140 -9
  11. package/docs/teaching.md +1 -1
  12. package/docs/video-rendering.md +198 -1
  13. package/lib/addons/adapters.js +431 -332
  14. package/lib/addons/characters.js +3889 -3773
  15. package/lib/addons/load-scene-oWNsYYC1.js +372 -0
  16. package/lib/addons/scene-3d-webgl.js +31 -31
  17. package/lib/addons/scene-3d.js +669 -314
  18. package/lib/addons/shading-0lPgnXmD.js +96 -0
  19. package/lib/browser/tinyfly-scene-3d-webgl.iife.js +2 -2
  20. package/lib/browser/tinyfly-scene-3d.iife.js +2 -2
  21. package/lib/browser/tinyfly.iife.js +15 -15
  22. package/lib/browser/tinyfly.js +6232 -5723
  23. package/lib/browser/tinyfly.umd.js +15 -15
  24. package/lib/engine/tinyfly-engine.js +1563 -1170
  25. package/lib/engine/tinyfly-engine.umd.cjs +2 -2
  26. package/lib/headless/headless.js +189 -6
  27. package/lib/types/adapters/canvas/framing.d.ts +27 -0
  28. package/lib/types/adapters/canvas/impossible.d.ts +15 -0
  29. package/lib/types/adapters/canvas/index.d.ts +4 -0
  30. package/lib/types/adapters/canvas/nested-zoom.d.ts +40 -0
  31. package/lib/types/adapters/canvas/zoom-blur.d.ts +49 -0
  32. package/lib/types/characters/character-script-3d.d.ts +21 -1
  33. package/lib/types/characters/character.d.ts +23 -3
  34. package/lib/types/characters/head/face.d.ts +19 -2
  35. package/lib/types/characters/index.d.ts +2 -1
  36. package/lib/types/characters/staging-3d.d.ts +56 -0
  37. package/lib/types/engine/authoring/beat-loop.d.ts +46 -0
  38. package/lib/types/engine/authoring/curve.d.ts +26 -0
  39. package/lib/types/engine/authoring/framing.d.ts +48 -0
  40. package/lib/types/engine/authoring/index.d.ts +4 -0
  41. package/lib/types/engine/authoring/periodic.d.ts +89 -0
  42. package/lib/types/engine/path/goo.d.ts +103 -0
  43. package/lib/types/engine/path/impossible.d.ts +92 -0
  44. package/lib/types/engine/path/index.d.ts +6 -0
  45. package/lib/types/engine/path/similarity.d.ts +48 -0
  46. package/lib/types/headless/audio-mix.d.ts +40 -0
  47. package/lib/types/headless/ffmpeg-args.d.ts +2 -0
  48. package/lib/types/headless/frame-renderer.d.ts +7 -1
  49. package/lib/types/headless/index.d.ts +2 -0
  50. package/lib/types/headless/loop-audio.d.ts +21 -0
  51. package/lib/types/headless/node-audio.d.ts +39 -0
  52. package/lib/types/headless/node-video.d.ts +2 -0
  53. package/lib/types/headless/video-scene.d.ts +21 -0
  54. package/lib/types/scene-3d/camera.d.ts +11 -2
  55. package/lib/types/scene-3d/geometry/mesh.d.ts +2 -0
  56. package/lib/types/scene-3d/geometry/primitives.d.ts +7 -0
  57. package/lib/types/scene-3d/impossible-3d.d.ts +29 -0
  58. package/lib/types/scene-3d/index.d.ts +7 -3
  59. package/lib/types/scene-3d/lighting.d.ts +58 -0
  60. package/lib/types/scene-3d/resolve-scene.d.ts +18 -2
  61. package/lib/types/scene-3d/scene-3d-adapter.d.ts +4 -0
  62. package/lib/types/scene-3d/scene-types.d.ts +43 -6
  63. package/lib/types/scene-3d/shading.d.ts +2 -0
  64. package/lib/types/scene-3d/shots.d.ts +162 -0
  65. package/lib/types/scene-3d/software-renderer.d.ts +40 -0
  66. package/llms-full.txt +395 -23
  67. package/llms.txt +29 -29
  68. package/package.json +1 -1
  69. package/skills/tinyfly/SKILL.md +11 -1
  70. package/lib/addons/load-scene-CQvcFWGJ.js +0 -331
  71. package/lib/addons/shading-o5T_v9DT.js +0 -89
@@ -0,0 +1,372 @@
1
+ import { parsePath as L } from "@algorisys/tinyfly";
2
+ class q {
3
+ positions = [];
4
+ normals = [];
5
+ indices = [];
6
+ /** Add a vertex; returns its index. */
7
+ vertex(c, i, e, o, a, t) {
8
+ const n = Math.hypot(o, a, t) || 1;
9
+ return this.positions.push(c, i, e), this.normals.push(o / n, a / n, t / n), this.positions.length / 3 - 1;
10
+ }
11
+ /** Add a triangle, counter-clockwise seen from its front. */
12
+ triangle(c, i, e) {
13
+ this.indices.push(c, i, e);
14
+ }
15
+ /** Add a quad a-b-c-d (counter-clockwise) as two triangles. */
16
+ quad(c, i, e, o) {
17
+ this.indices.push(c, i, e, c, e, o);
18
+ }
19
+ build() {
20
+ return { positions: this.positions, normals: this.normals, indices: this.indices };
21
+ }
22
+ }
23
+ function O(s) {
24
+ const c = /* @__PURE__ */ new Map(), i = [];
25
+ for (let o = 0; o < s.positions.length / 3; o++) {
26
+ const a = [0, 1, 2].map((t) => Math.round(s.positions[o * 3 + t] * 1e6)).join(",");
27
+ c.has(a) || c.set(a, o), i.push(c.get(a));
28
+ }
29
+ const e = /* @__PURE__ */ new Map();
30
+ for (let o = 0; o < s.indices.length / 3; o++)
31
+ for (let a = 0; a < 3; a++) {
32
+ const t = i[s.indices[o * 3 + a]], n = i[s.indices[o * 3 + (a + 1) % 3]];
33
+ if (t === n) continue;
34
+ const r = t < n ? `${t}-${n}` : `${n}-${t}`, l = e.get(r);
35
+ l ? l.faces.push(o) : e.set(r, { a: Math.min(t, n), b: Math.max(t, n), faces: [o] });
36
+ }
37
+ return [...e.values()];
38
+ }
39
+ function X(s) {
40
+ let c = 0;
41
+ for (let i = 0; i < s.length; i++) {
42
+ const e = s[i], o = s[(i + 1) % s.length];
43
+ c += e.x * o.y - o.x * e.y;
44
+ }
45
+ return c;
46
+ }
47
+ function D(s, c) {
48
+ let i = !1;
49
+ for (let e = 0, o = c.length - 1; e < c.length; o = e++) {
50
+ const a = c[e], t = c[o];
51
+ a.y > s.y != t.y > s.y && s.x < (t.x - a.x) * (s.y - a.y) / (t.y - a.y) + a.x && (i = !i);
52
+ }
53
+ return i;
54
+ }
55
+ const E = (s, c, i) => (c.x - s.x) * (i.y - s.y) - (c.y - s.y) * (i.x - s.x), P = (s, c) => s.x === c.x && s.y === c.y;
56
+ function _(s, c, i, e) {
57
+ return E(c, i, s) >= 0 && E(i, e, s) >= 0 && E(e, c, s) >= 0;
58
+ }
59
+ function T(s, c) {
60
+ let i = 0;
61
+ for (let h = 1; h < c.length; h++) c[h].x > c[i].x && (i = h);
62
+ const e = c[i];
63
+ let o = -1, a = 1 / 0;
64
+ for (let h = 0; h < s.length; h++) {
65
+ const f = s[h], m = s[(h + 1) % s.length];
66
+ if (f.y > e.y == m.y > e.y) continue;
67
+ const g = f.x + (e.y - f.y) * (m.x - f.x) / (m.y - f.y);
68
+ g >= e.x && g < a && (a = g, o = h);
69
+ }
70
+ if (o < 0) return s;
71
+ const t = s[o], n = s[(o + 1) % s.length];
72
+ let r = t.x > n.x ? o : (o + 1) % s.length;
73
+ const l = { x: a, y: e.y };
74
+ let d = 1 / 0;
75
+ for (let h = 0; h < s.length; h++) {
76
+ const f = s[h];
77
+ if (h === r || f.x < e.x) continue;
78
+ const m = s[r];
79
+ if (!(_(f, e, l, m) || _(f, e, m, l))) continue;
80
+ const p = Math.abs(Math.atan2(f.y - e.y, f.x - e.x));
81
+ p < d && (d = p, r = h);
82
+ }
83
+ const u = c.slice(i).concat(c.slice(0, i));
84
+ return [...s.slice(0, r + 1), ...u, e, s[r], ...s.slice(r + 1)];
85
+ }
86
+ function B(s, c = []) {
87
+ const i = X(s) >= 0 ? s : [...s].reverse(), e = c.map((u) => X(u) <= 0 ? u : [...u].reverse()), o = [...i, ...e.flat()], a = /* @__PURE__ */ new Map();
88
+ o.forEach((u, h) => a.set(u, h));
89
+ const t = [...e].sort((u, h) => Math.max(...h.map((f) => f.x)) - Math.max(...u.map((f) => f.x)));
90
+ let n = i;
91
+ for (const u of t) n = T(n, u);
92
+ const r = n.map((u) => a.get(u)), l = [];
93
+ let d = r.length * r.length;
94
+ for (; r.length > 3 && d-- > 0; ) {
95
+ let u = !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, v] = [o[f], o[m], o[g]];
98
+ if (E(p, M, v) <= 0) continue;
99
+ let $ = !1;
100
+ for (const y of r) {
101
+ const w = o[y];
102
+ if (!(y === f || y === m || y === g || P(w, p) || P(w, M) || P(w, v)) && _(w, p, M, v)) {
103
+ $ = !0;
104
+ break;
105
+ }
106
+ }
107
+ if (!$) {
108
+ l.push(f, m, g), r.splice(h, 1), u = !0;
109
+ break;
110
+ }
111
+ }
112
+ u || (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: o, triangles: l };
115
+ }
116
+ function U(s, c) {
117
+ const i = /* @__PURE__ */ new Map();
118
+ for (const e of L(s).segments) {
119
+ i.has(e.subpath) || i.set(e.subpath, [{ x: e.startX, y: -e.startY }]);
120
+ const o = i.get(e.subpath);
121
+ if (e.type === "L")
122
+ o.push({ x: e.endX, y: -e.endY });
123
+ else {
124
+ const [a, t, n, r, l, d] = e.points;
125
+ for (let u = 1; u <= c; u++) {
126
+ const h = u / c, f = 1 - h, m = f * f * f * e.startX + 3 * f * f * h * a + 3 * f * h * h * n + h * h * h * l, g = f * f * f * e.startY + 3 * f * f * h * t + 3 * f * h * h * r + h * h * h * d;
127
+ o.push({ x: m, y: -g });
128
+ }
129
+ }
130
+ }
131
+ return [...i.values()].map((e) => e.filter((o, a) => a === 0 || o.x !== e[a - 1].x || o.y !== e[a - 1].y)).map((e) => e.length > 1 && e[0].x === e[e.length - 1].x && e[0].y === e[e.length - 1].y ? e.slice(0, -1) : e).filter((e) => e.length >= 3 && Math.abs(X(e)) > 1e-12);
132
+ }
133
+ function W(s, c) {
134
+ const i = U(s, Math.max(1, Math.round(c.curveSegments ?? 12))), e = new q();
135
+ if (i.length === 0) return e.build();
136
+ const o = i.flat(), a = Math.min(...o.map((p) => p.x)), t = Math.max(...o.map((p) => p.x)), n = Math.min(...o.map((p) => p.y)), r = Math.max(...o.map((p) => p.y)), l = (c.width ?? 1) / Math.max(t - a, 1e-9), d = (a + t) / 2, u = (n + r) / 2, h = i.map((p) => p.map((M) => ({ x: (M.x - d) * l, y: (M.y - u) * l }))), f = h.map((p, M) => h.filter((v, $) => $ !== M && D(p[0], v)).length), m = c.depth / 2, g = -c.depth / 2;
137
+ return h.forEach((p, M) => {
138
+ if (f[M] % 2 === 1) return;
139
+ const v = h.filter((x, b) => f[b] === f[M] + 1 && D(x[0], p)), { points: $, triangles: y } = B(p, v), w = $.map((x) => e.vertex(x.x, x.y, m, 0, 0, 1)), I = $.map((x) => e.vertex(x.x, x.y, g, 0, 0, -1));
140
+ for (let x = 0; x < y.length; x += 3)
141
+ e.triangle(w[y[x]], w[y[x + 1]], w[y[x + 2]]), e.triangle(I[y[x]], I[y[x + 2]], I[y[x + 1]]);
142
+ for (const x of [X(p) >= 0 ? p : [...p].reverse(), ...v.map((b) => X(b) <= 0 ? b : [...b].reverse())])
143
+ for (let b = 0; b < x.length; b++) {
144
+ const k = x[b], j = x[(b + 1) % x.length], S = j.y - k.y, N = -(j.x - k.x), Y = e.vertex(k.x, k.y, g, S, N, 0), z = e.vertex(j.x, j.y, g, S, N, 0), F = e.vertex(j.x, j.y, m, S, N, 0), H = e.vertex(k.x, k.y, m, S, N, 0);
145
+ e.quad(Y, z, F, H);
146
+ }
147
+ }), e.build();
148
+ }
149
+ const A = Math.PI * 2;
150
+ function Z([s, c, i]) {
151
+ const e = new q(), o = s / 2, a = c / 2, t = i / 2, n = [
152
+ [[0, 0, 1], [[-o, -a, t], [o, -a, t], [o, a, t], [-o, a, t]]],
153
+ [[0, 0, -1], [[o, -a, -t], [-o, -a, -t], [-o, a, -t], [o, a, -t]]],
154
+ [[1, 0, 0], [[o, -a, t], [o, -a, -t], [o, a, -t], [o, a, t]]],
155
+ [[-1, 0, 0], [[-o, -a, -t], [-o, -a, t], [-o, a, t], [-o, a, -t]]],
156
+ [[0, 1, 0], [[-o, a, t], [o, a, t], [o, a, -t], [-o, a, -t]]],
157
+ [[0, -1, 0], [[-o, -a, -t], [o, -a, -t], [o, -a, t], [-o, -a, t]]]
158
+ ];
159
+ for (const [[r, l, d], u] of n) {
160
+ const [h, f, m, g] = u.map(([p, M, v]) => e.vertex(p, M, v, r, l, d));
161
+ e.quad(h, f, m, g);
162
+ }
163
+ return e.build();
164
+ }
165
+ function G([s, c], i = 1) {
166
+ const e = new q(), o = Math.max(1, Math.round(i)), a = [];
167
+ for (let t = 0; t <= o; t++) {
168
+ const n = c / 2 - c * t / o;
169
+ a.push(Array.from({ length: o + 1 }, (r, l) => e.vertex(-s / 2 + s * l / o, 0, n, 0, 1, 0)));
170
+ }
171
+ for (let t = 0; t < o; t++)
172
+ for (let n = 0; n < o; n++) e.quad(a[t][n], a[t][n + 1], a[t + 1][n + 1], a[t + 1][n]);
173
+ return e.build();
174
+ }
175
+ function J(s, c = 16) {
176
+ const i = new q(), e = Math.max(6, Math.round(c)), o = Math.max(3, Math.round(e / 2)), a = [];
177
+ for (let t = 0; t <= o; t++) {
178
+ const n = t / o * Math.PI, r = [];
179
+ for (let l = 0; l <= e; l++) {
180
+ const d = l / e * A, u = Math.sin(n) * Math.sin(d), h = Math.cos(n), f = Math.sin(n) * Math.cos(d);
181
+ r.push(i.vertex(u * s, h * s, f * s, u, h, f));
182
+ }
183
+ a.push(r);
184
+ }
185
+ for (let t = 0; t < o; t++)
186
+ for (let n = 0; n < e; n++) {
187
+ const r = a[t][n], l = a[t + 1][n], d = a[t + 1][n + 1], u = a[t][n + 1];
188
+ t > 0 && i.triangle(r, l, u), t < o - 1 && i.triangle(l, d, u);
189
+ }
190
+ return i.build();
191
+ }
192
+ function C(s, c, i, e, o) {
193
+ const a = s.vertex(0, i, 0, 0, e, 0), t = Array.from({ length: o }, (n, r) => {
194
+ const l = r / o * A;
195
+ return s.vertex(Math.sin(l) * c, i, Math.cos(l) * c, 0, e, 0);
196
+ });
197
+ for (let n = 0; n < o; n++) {
198
+ const r = t[n], l = t[(n + 1) % o];
199
+ e === 1 ? s.triangle(a, r, l) : s.triangle(a, l, r);
200
+ }
201
+ }
202
+ function K(s, c, i = 24) {
203
+ const e = new q(), o = Math.max(6, Math.round(i)), a = c / 2, t = -c / 2, n = (d) => Array.from({ length: o + 1 }, (u, h) => {
204
+ const f = h / o * A;
205
+ return e.vertex(Math.sin(f) * s, d, Math.cos(f) * s, Math.sin(f), 0, Math.cos(f));
206
+ }), r = n(t), l = n(a);
207
+ for (let d = 0; d < o; d++) e.quad(r[d], r[d + 1], l[d + 1], l[d]);
208
+ return C(e, s, a, 1, o), C(e, s, t, -1, o), e.build();
209
+ }
210
+ function Q(s, c, i = 24) {
211
+ const e = new q(), o = Math.max(6, Math.round(i)), a = c / 2, t = -c / 2, n = s / c;
212
+ for (let r = 0; r < o; r++) {
213
+ const l = r / o * A, d = (r + 1) / o * A, u = (l + d) / 2, h = e.vertex(Math.sin(l) * s, t, Math.cos(l) * s, Math.sin(l), n, Math.cos(l)), f = e.vertex(Math.sin(d) * s, t, Math.cos(d) * s, Math.sin(d), n, Math.cos(d)), m = e.vertex(0, a, 0, Math.sin(u), n, Math.cos(u));
214
+ e.triangle(h, f, m);
215
+ }
216
+ return C(e, s, t, -1, o), e.build();
217
+ }
218
+ function R(s, c, i = 24) {
219
+ const e = new q(), o = Math.max(6, Math.round(i)), a = Math.max(4, Math.round(o / 2)), t = [];
220
+ for (let n = 0; n <= o; n++) {
221
+ const r = n / o * A, l = [];
222
+ for (let d = 0; d <= a; d++) {
223
+ const u = d / a * A, h = Math.cos(u) * Math.sin(r), f = Math.sin(u), m = Math.cos(u) * Math.cos(r), g = s + c * Math.cos(u);
224
+ l.push(e.vertex(g * Math.sin(r), c * Math.sin(u), g * Math.cos(r), h, f, m));
225
+ }
226
+ t.push(l);
227
+ }
228
+ for (let n = 0; n < o; n++)
229
+ for (let r = 0; r < a; r++) e.quad(t[n][r], t[n + 1][r], t[n + 1][r + 1], t[n][r + 1]);
230
+ return e.build();
231
+ }
232
+ function V(s) {
233
+ switch (s.type) {
234
+ case "box":
235
+ return Z(s.size);
236
+ case "plane":
237
+ return G(s.size, s.segments);
238
+ case "sphere":
239
+ return J(s.radius, s.segments);
240
+ case "cylinder":
241
+ return K(s.radius, s.height, s.segments);
242
+ case "cone":
243
+ return Q(s.radius, s.height, s.segments);
244
+ case "torus":
245
+ return R(s.radius, s.tube, s.segments);
246
+ case "extrude":
247
+ return W(s.path, { depth: s.depth, width: s.width, curveSegments: s.curveSegments });
248
+ case "mesh":
249
+ return tt(s);
250
+ }
251
+ }
252
+ function tt(s) {
253
+ const c = [...s.positions], i = [...s.indices], e = c.length / 3, o = i.length / 3;
254
+ let a;
255
+ if (s.normals && s.normals.length === c.length)
256
+ a = [...s.normals];
257
+ else {
258
+ a = new Array(c.length).fill(0);
259
+ for (let n = 0; n < o; n++) {
260
+ const [r, l, d] = [i[n * 3], i[n * 3 + 1], i[n * 3 + 2]], u = (z) => [c[z * 3], c[z * 3 + 1], c[z * 3 + 2]], [h, f, m] = u(r), [g, p, M] = u(l), [v, $, y] = u(d), w = g - h, I = p - f, x = M - m, b = v - h, k = $ - f, j = y - m, S = I * j - x * k, N = x * b - w * j, Y = w * k - I * b;
261
+ for (const z of [r, l, d])
262
+ a[z * 3] += S, a[z * 3 + 1] += N, a[z * 3 + 2] += Y;
263
+ }
264
+ for (let n = 0; n < e; n++) {
265
+ const r = Math.hypot(a[n * 3], a[n * 3 + 1], a[n * 3 + 2]) || 1;
266
+ a[n * 3] /= r, a[n * 3 + 1] /= r, a[n * 3 + 2] /= r;
267
+ }
268
+ }
269
+ let t;
270
+ if (s.colors && s.colors.length === o) t = [...s.colors];
271
+ else if (s.colors && s.colors.length === e) {
272
+ t = [];
273
+ for (let n = 0; n < o; n++) {
274
+ const r = [0, 1, 2].map((d) => st(s.colors[i[n * 3 + d]])), l = [0, 1, 2].map((d) => Math.round((r[0][d] + r[1][d] + r[2][d]) / 3));
275
+ t.push(`#${l.map((d) => d.toString(16).padStart(2, "0")).join("")}`);
276
+ }
277
+ }
278
+ return t ? { positions: c, normals: a, indices: i, faceColors: t } : { positions: c, normals: a, indices: i };
279
+ }
280
+ function st(s) {
281
+ const c = s.trim().replace("#", ""), i = c.length === 3 ? c.split("").map((o) => o + o).join("") : c, e = parseInt(i, 16);
282
+ return Number.isFinite(e) && i.length === 6 ? [e >> 16 & 255, e >> 8 & 255, e & 255] : [0, 0, 0];
283
+ }
284
+ const nt = [
285
+ { name: "position", vector: "position", components: ["x", "y", "z"] },
286
+ { name: "rotation", vector: "quaternion", components: ["rotateX", "rotateY", "rotateZ"] }
287
+ ];
288
+ function et(s, c = []) {
289
+ const i = [], e = /* @__PURE__ */ new Map();
290
+ for (const t of s.objects) {
291
+ if (t.id ? e.has(t.id) && i.push(`two objects share the id "${t.id}"`) : i.push("an object has no id"), t.parent !== void 0 && !e.has(t.parent) && i.push(`"${t.id}" has parent "${t.parent}", which must be an earlier object`), t.quaternion && t.quaternion.length !== 4 && i.push(`"${t.id}": a quaternion has four numbers`), t.kind === "mesh") {
292
+ s.materials?.[t.material] || i.push(`"${t.id}" uses material "${t.material}", which is not in materials`);
293
+ const n = t.geometry;
294
+ if (n.type === "mesh") {
295
+ const r = (n.positions?.length ?? 0) / 3;
296
+ (!Array.isArray(n.positions) || n.positions.length % 3 !== 0 || r < 3) && i.push(`"${t.id}": a mesh needs positions as x, y, z runs for at least three vertices`), !Array.isArray(n.indices) || n.indices.length % 3 !== 0 || n.indices.length < 3 ? i.push(`"${t.id}": a mesh needs indices in triples`) : n.indices.every((l) => Number.isInteger(l) && l >= 0 && l < r) || i.push(`"${t.id}": a mesh index is out of range`), n.normals && n.normals.length !== (n.positions?.length ?? 0) && i.push(`"${t.id}": a mesh's normals must match its positions`), n.colors && n.colors.length !== (n.indices?.length ?? 0) / 3 && n.colors.length !== r && i.push(`"${t.id}": a mesh's colors are one per face or one per vertex`);
297
+ } else {
298
+ const r = n.type === "box" || n.type === "plane" ? n.size : n.type === "torus" ? [n.radius, n.tube] : n.type === "sphere" ? [n.radius] : n.type === "extrude" ? [n.depth, n.width ?? 1] : [n.radius, n.height];
299
+ n.type === "extrude" && !(typeof n.path == "string" && /^\s*[Mm]/.test(n.path)) && i.push(`"${t.id}": an extrude needs a path that starts with M`), r.every((l) => Number.isFinite(l) && l > 0) || i.push(`"${t.id}": a ${n.type}'s sizes must be positive`);
300
+ }
301
+ }
302
+ if (t.kind === "line" || t.kind === "trail") {
303
+ t.width !== void 0 && !(t.width > 0) && i.push(`"${t.id}": width must be positive`);
304
+ for (const n of ["taper", "fade", "opacity"]) {
305
+ const r = t[n];
306
+ r !== void 0 && !(r >= 0 && r <= 1) && i.push(`"${t.id}": ${n} is between 0 and 1`);
307
+ }
308
+ }
309
+ 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)) || i.push(`"${t.id}": a line needs two or more points of three numbers`)), t.kind === "trail" && (t.length > 0 || i.push(`"${t.id}": a trail's length (ms) must be positive`), (t.follow === t.id || !s.objects.some((n) => n.id === t.follow)) && i.push(`"${t.id}" follows "${t.follow}", which is not another object in the scene`), t.samples !== void 0 && !(t.samples >= 2) && i.push(`"${t.id}": a trail needs at least 2 samples`)), t.kind === "camera" && (t.near > 0 && t.far > t.near || i.push(`camera "${t.id}": near must be above 0 and far beyond it`), t.projection === "perspective" && !(t.fov > 0 && t.fov < 180) && i.push(`camera "${t.id}": fov is between 0 and 180 degrees`), t.projection === "orthographic" && !(t.height > 0) && i.push(`camera "${t.id}": height must be positive`)), t.id && e.set(t.id, t);
310
+ }
311
+ const o = e.get(s.camera);
312
+ o ? o.kind !== "camera" && i.push(`the scene's camera "${s.camera}" is a ${o.kind}, not a camera`) : i.push(`the scene's camera "${s.camera}" is not one of its objects`), s.fog && !(s.fog.far > s.fog.near) && i.push("fog: far must be beyond near");
313
+ const a = /* @__PURE__ */ new Map();
314
+ for (const t of c) {
315
+ if (!t.target.startsWith(`${s.id}/`)) continue;
316
+ const n = t.target.slice(s.id.length + 1);
317
+ a.has(n) || a.set(n, /* @__PURE__ */ new Set()), a.get(n).add(t.property);
318
+ }
319
+ for (const [t, n] of a) {
320
+ e.has(t) || i.push(`a track animates "${s.id}/${t}", which is not in the scene`);
321
+ for (const r of nt)
322
+ n.has(r.vector) && r.components.some((l) => n.has(l)) && i.push(`"${t}": its ${r.name} is animated both by ${r.vector} and by ${r.components.join(" / ")}; use one`);
323
+ }
324
+ return i;
325
+ }
326
+ function ot(s) {
327
+ const c = Array.from({ length: s.indices.length / 3 }, () => []);
328
+ for (const i of O(s))
329
+ for (const e of i.faces) {
330
+ const o = i.faces.find((a) => a !== e) ?? -1;
331
+ c[e].push({ a: i.a, b: i.b, across: o });
332
+ }
333
+ return { ...s, faceEdges: c };
334
+ }
335
+ function rt(s, c = {}) {
336
+ const i = new Map((c.kinds ?? []).map((t) => [t.kind, t])), e = et(s);
337
+ for (const t of s.objects) {
338
+ if (it.has(t.kind)) continue;
339
+ const n = i.get(t.kind);
340
+ n ? e.push(...(n.validate?.(t) ?? []).map((r) => `"${t.id}": ${r}`)) : e.push(`"${t.id}" is a ${t.kind}: load the scene with that kind (for characters: loadScene3D(scene, { kinds: [characterObjects] }), from @algorisys/tinyfly/characters)`);
341
+ }
342
+ if (e.length > 0) throw new Error(`scene-3d: "${s.id}" is not valid:
343
+ - ${e.join(`
344
+ - `)}`);
345
+ const o = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
346
+ for (const t of s.objects) {
347
+ t.kind === "mesh" && o.set(t.id, ot(V(t.geometry)));
348
+ const n = i.get(t.kind);
349
+ n?.prepare && a.set(t.id, n.prepare(t));
350
+ }
351
+ return { scene: s, meshes: o, kinds: i, prepared: a };
352
+ }
353
+ const it = /* @__PURE__ */ new Set(["group", "mesh", "camera", "light", "line", "trail"]);
354
+ export {
355
+ q as M,
356
+ K as a,
357
+ Z as b,
358
+ Q as c,
359
+ D as d,
360
+ W as e,
361
+ ot as f,
362
+ V as g,
363
+ J as h,
364
+ B as i,
365
+ rt as l,
366
+ O as m,
367
+ G as p,
368
+ tt as r,
369
+ X as s,
370
+ R as t,
371
+ et as v
372
+ };
@@ -1,6 +1,6 @@
1
- import { p as _ } from "./shading-o5T_v9DT.js";
1
+ import { p as _ } from "./shading-0lPgnXmD.js";
2
2
  import { mat4 as h, vec3 as v } from "@algorisys/tinyfly";
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
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
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 ${c}
20
+ #define MAX_LIGHTS ${s}
21
21
  uniform int u_lightCount;
22
22
  uniform int u_lightKind[MAX_LIGHTS];
23
23
  uniform vec3 u_lightColor[MAX_LIGHTS];
@@ -120,15 +120,15 @@ void main() {
120
120
  { id: "default-key", light: "directional", color: "#ffffff", intensity: 0.8, position: [3, 5, 4], direction: v.normalize([-3, -5, -4]), angle: 30 }
121
121
  ];
122
122
  function F(a) {
123
- const t = (a.length > 0 ? a : R).slice(0, c), i = {
123
+ const t = (a.length > 0 ? a : R).slice(0, s), i = {
124
124
  count: t.length,
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)
125
+ kind: new Int32Array(s),
126
+ color: new Float32Array(s * 3),
127
+ intensity: new Float32Array(s),
128
+ position: new Float32Array(s * 3),
129
+ direction: new Float32Array(s * 3),
130
+ range: new Float32Array(s),
131
+ cone: new Float32Array(s * 2)
132
132
  };
133
133
  return t.forEach((o, n) => {
134
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);
@@ -143,7 +143,7 @@ function L(a, t, i) {
143
143
  bands: a.bands ?? 3
144
144
  };
145
145
  }
146
- function m(a) {
146
+ function g(a) {
147
147
  const t = h.transpose(h.invert(a) ?? h.identity());
148
148
  return new Float32Array([t[0], t[1], t[2], t[4], t[5], t[6], t[8], t[9], t[10]]);
149
149
  }
@@ -154,14 +154,14 @@ class C {
154
154
  buffers = /* @__PURE__ */ new WeakMap();
155
155
  overlay;
156
156
  constructor(t, i = {}) {
157
- this.gl = t, this.overlay = i.overlay, this.surface = g(t, A, b), this.outline = g(t, E, y);
157
+ this.gl = t, this.overlay = i.overlay, this.surface = m(t, A, b), this.outline = m(t, E, y);
158
158
  }
159
159
  render(t) {
160
160
  const i = this.gl, o = i.drawingBufferWidth, n = i.drawingBufferHeight;
161
161
  i.viewport(0, 0, o, n);
162
- const e = t.background && t.background !== "transparent" ? _(t.background) : null;
162
+ const e = t.background && t.background !== "transparent" ? _(typeof t.background == "string" ? t.background : t.background.bottom) : null;
163
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);
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);
164
+ const l = 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);
165
165
  i.disable(i.BLEND), i.depthMask(!0);
166
166
  for (const r of l) r.material.outline && this.drawOutline(t, r, o, n);
167
167
  for (const r of l) this.drawSurface(t, r);
@@ -179,18 +179,18 @@ class C {
179
179
  const o = this.gl, n = this.surface;
180
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);
181
181
  const e = n.uniform;
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));
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, g(i.world));
183
183
  const l = F(t.lights);
184
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);
185
+ const c = L(i.material, i.color, i.opacity);
186
+ o.uniform3fv(e("u_color"), c.color), o.uniform3fv(e("u_emissive"), c.emissive), 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);
187
187
  }
188
188
  drawOutline(t, i, o, n) {
189
- const e = this.gl, l = this.outline, s = i.material.outline;
189
+ const e = this.gl, l = this.outline, c = i.material.outline;
190
190
  e.useProgram(l.program), e.enable(e.CULL_FACE), e.cullFace(e.FRONT), this.bindMesh(l, i.mesh);
191
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);
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, g(i.world)), e.uniform2f(u("u_viewport"), o, n), e.uniform1f(u("u_width"), c.width * (o / t.width));
193
+ const [d, r, f] = _(c.color);
194
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);
195
195
  }
196
196
  /** Upload a mesh once; bind its buffers to the program's attributes. */
@@ -200,14 +200,14 @@ class C {
200
200
  if (!n) {
201
201
  const l = o.createBuffer();
202
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);
203
+ const c = o.createBuffer();
204
+ o.bindBuffer(o.ARRAY_BUFFER, c), o.bufferData(o.ARRAY_BUFFER, new Float32Array(i.normals), o.STATIC_DRAW);
205
205
  const u = o.createBuffer();
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);
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: c, index: u }, this.buffers.set(i, n);
207
207
  }
208
- const e = (l, s) => {
208
+ const e = (l, c) => {
209
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));
210
+ u < 0 || (o.bindBuffer(o.ARRAY_BUFFER, c), o.enableVertexAttribArray(u), o.vertexAttribPointer(u, 3, o.FLOAT, !1, 0, 0));
211
211
  };
212
212
  e("a_position", n.position), e("a_normal", n.normal), o.bindBuffer(o.ELEMENT_ARRAY_BUFFER, n.index);
213
213
  }
@@ -216,10 +216,10 @@ class C {
216
216
  this.gl.deleteProgram(this.surface.program), this.gl.deleteProgram(this.outline.program);
217
217
  }
218
218
  }
219
- function g(a, t, i) {
220
- const o = (l, s) => {
219
+ function m(a, t, i) {
220
+ const o = (l, c) => {
221
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)}`);
222
+ if (a.shaderSource(u, c), a.compileShader(u), !a.getShaderParameter(u, a.COMPILE_STATUS)) throw new Error(`scene-3d webgl: shader failed to compile — ${a.getShaderInfoLog(u)}`);
223
223
  return u;
224
224
  }, n = a.createProgram();
225
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)}`);
@@ -231,10 +231,10 @@ function g(a, t, i) {
231
231
  }
232
232
  export {
233
233
  w as LIGHT_CODE,
234
- c as MAX_LIGHTS,
234
+ s as MAX_LIGHTS,
235
235
  p as SHADING_CODE,
236
236
  C as WebGL2Renderer,
237
- m as normalMatrix3,
237
+ g as normalMatrix3,
238
238
  F as packLights,
239
239
  L as surfaceUniforms
240
240
  };