@algorisys/tinyfly 0.87.0 → 0.89.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 (34) hide show
  1. package/README.md +6 -4
  2. package/lib/addons/adapters.js +370 -310
  3. package/lib/addons/characters.js +1878 -1449
  4. package/lib/addons/load-scene-CQvcFWGJ.js +331 -0
  5. package/lib/addons/scene-3d.js +299 -215
  6. package/lib/browser/tinyfly-scene-3d.iife.js +2 -2
  7. package/lib/browser/tinyfly.iife.js +4 -4
  8. package/lib/browser/tinyfly.js +4395 -3858
  9. package/lib/browser/tinyfly.umd.js +4 -4
  10. package/lib/engine/tinyfly-engine.js +155 -106
  11. package/lib/engine/tinyfly-engine.umd.cjs +2 -2
  12. package/lib/headless/headless.js +8 -4
  13. package/lib/types/adapters/canvas/index.d.ts +1 -0
  14. package/lib/types/adapters/canvas/trail.d.ts +57 -0
  15. package/lib/types/browser/index.d.ts +2 -0
  16. package/lib/types/characters/acting/act-tracks.d.ts +28 -0
  17. package/lib/types/characters/acting/acting.d.ts +187 -0
  18. package/lib/types/characters/acting/effects.d.ts +65 -0
  19. package/lib/types/characters/acting/gags.d.ts +54 -0
  20. package/lib/types/characters/acting/index.d.ts +10 -0
  21. package/lib/types/characters/acting/rigs.d.ts +9 -0
  22. package/lib/types/characters/character.d.ts +7 -0
  23. package/lib/types/characters/index.d.ts +1 -0
  24. package/lib/types/characters/stick-figure.d.ts +7 -0
  25. package/lib/types/engine/core/clock.d.ts +7 -0
  26. package/lib/types/engine/path/index.d.ts +2 -0
  27. package/lib/types/engine/path/trail.d.ts +79 -0
  28. package/lib/types/headless/video-scene.d.ts +9 -0
  29. package/lib/types/scene-3d/resolve-scene.d.ts +6 -0
  30. package/lib/types/scene-3d/scene-3d-adapter.d.ts +9 -1
  31. package/lib/types/scene-3d/scene-types.d.ts +40 -1
  32. package/lib/types/scene-3d/strokes.d.ts +30 -0
  33. package/package.json +1 -1
  34. package/lib/addons/load-scene-vp14_Jj-.js +0 -324
@@ -1,324 +0,0 @@
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(i, c, n, e, a, t) {
8
- const o = Math.hypot(e, a, t) || 1;
9
- return this.positions.push(i, c, n), this.normals.push(e / o, a / o, t / o), this.positions.length / 3 - 1;
10
- }
11
- /** Add a triangle, counter-clockwise seen from its front. */
12
- triangle(i, c, n) {
13
- this.indices.push(i, c, n);
14
- }
15
- /** Add a quad a-b-c-d (counter-clockwise) as two triangles. */
16
- quad(i, c, n, e) {
17
- this.indices.push(i, c, n, i, n, e);
18
- }
19
- build() {
20
- return { positions: this.positions, normals: this.normals, indices: this.indices };
21
- }
22
- }
23
- function C(s) {
24
- const i = /* @__PURE__ */ new Map(), c = [];
25
- for (let e = 0; e < s.positions.length / 3; e++) {
26
- const a = [0, 1, 2].map((t) => Math.round(s.positions[e * 3 + t] * 1e6)).join(",");
27
- i.has(a) || i.set(a, e), c.push(i.get(a));
28
- }
29
- const n = /* @__PURE__ */ new Map();
30
- for (let e = 0; e < s.indices.length / 3; e++)
31
- for (let a = 0; a < 3; a++) {
32
- const t = c[s.indices[e * 3 + a]], o = c[s.indices[e * 3 + (a + 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(e) : n.set(r, { a: Math.min(t, o), b: Math.max(t, o), faces: [e] });
36
- }
37
- return [...n.values()];
38
- }
39
- function I(s) {
40
- let i = 0;
41
- for (let c = 0; c < s.length; c++) {
42
- const n = s[c], e = s[(c + 1) % s.length];
43
- i += n.x * e.y - e.x * n.y;
44
- }
45
- return i;
46
- }
47
- function _(s, i) {
48
- let c = !1;
49
- for (let n = 0, e = i.length - 1; n < i.length; e = n++) {
50
- const a = i[n], t = i[e];
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 && (c = !c);
52
- }
53
- return c;
54
- }
55
- const X = (s, i, c) => (i.x - s.x) * (c.y - s.y) - (i.y - s.y) * (c.x - s.x), Y = (s, i) => s.x === i.x && s.y === i.y;
56
- function P(s, i, c, n) {
57
- return X(i, c, s) >= 0 && X(c, n, s) >= 0 && X(n, i, s) >= 0;
58
- }
59
- function H(s, i) {
60
- let c = 0;
61
- for (let h = 1; h < i.length; h++) i[h].x > i[c].x && (c = h);
62
- const n = i[c];
63
- let e = -1, a = 1 / 0;
64
- for (let h = 0; h < s.length; h++) {
65
- const f = s[h], x = s[(h + 1) % s.length];
66
- if (f.y > n.y == x.y > n.y) continue;
67
- const g = f.x + (n.y - f.y) * (x.x - f.x) / (x.y - f.y);
68
- g >= n.x && g < a && (a = g, e = h);
69
- }
70
- if (e < 0) return s;
71
- const t = s[e], o = s[(e + 1) % s.length];
72
- let r = t.x > o.x ? e : (e + 1) % s.length;
73
- const l = { x: a, y: n.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 < n.x) continue;
78
- const x = s[r];
79
- if (!(P(f, n, l, x) || P(f, n, x, l))) continue;
80
- const p = Math.abs(Math.atan2(f.y - n.y, f.x - n.x));
81
- p < d && (d = p, r = h);
82
- }
83
- const u = i.slice(c).concat(i.slice(0, c));
84
- return [...s.slice(0, r + 1), ...u, n, s[r], ...s.slice(r + 1)];
85
- }
86
- function U(s, i = []) {
87
- const c = I(s) >= 0 ? s : [...s].reverse(), n = i.map((u) => I(u) <= 0 ? u : [...u].reverse()), e = [...c, ...n.flat()], a = /* @__PURE__ */ new Map();
88
- e.forEach((u, h) => a.set(u, h));
89
- const t = [...n].sort((u, h) => Math.max(...h.map((f) => f.x)) - Math.max(...u.map((f) => f.x)));
90
- let o = c;
91
- for (const u of t) o = H(o, u);
92
- const r = o.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], x = r[h], g = r[(h + 1) % r.length], [p, M, b] = [e[f], e[x], e[g]];
98
- if (X(p, M, b) <= 0) continue;
99
- let $ = !1;
100
- for (const y of r) {
101
- const w = e[y];
102
- if (!(y === f || y === x || y === g || Y(w, p) || Y(w, M) || Y(w, b)) && P(w, p, M, b)) {
103
- $ = !0;
104
- break;
105
- }
106
- }
107
- if (!$) {
108
- l.push(f, x, 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: e, triangles: l };
115
- }
116
- function F(s, i) {
117
- const c = /* @__PURE__ */ new Map();
118
- for (const n of B(s).segments) {
119
- c.has(n.subpath) || c.set(n.subpath, [{ x: n.startX, y: -n.startY }]);
120
- const e = c.get(n.subpath);
121
- if (n.type === "L")
122
- e.push({ x: n.endX, y: -n.endY });
123
- else {
124
- const [a, t, o, r, l, d] = n.points;
125
- for (let u = 1; u <= i; u++) {
126
- const h = u / i, f = 1 - h, x = f * f * f * n.startX + 3 * f * f * h * a + 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 * d;
127
- e.push({ x, y: -g });
128
- }
129
- }
130
- }
131
- return [...c.values()].map((n) => n.filter((e, a) => a === 0 || e.x !== n[a - 1].x || e.y !== n[a - 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(I(n)) > 1e-12);
132
- }
133
- function W(s, i) {
134
- const c = F(s, Math.max(1, Math.round(i.curveSegments ?? 12))), n = new j();
135
- if (c.length === 0) return n.build();
136
- const e = c.flat(), a = Math.min(...e.map((p) => p.x)), t = Math.max(...e.map((p) => p.x)), o = Math.min(...e.map((p) => p.y)), r = Math.max(...e.map((p) => p.y)), l = (i.width ?? 1) / Math.max(t - a, 1e-9), d = (a + t) / 2, u = (o + r) / 2, h = c.map((p) => p.map((M) => ({ x: (M.x - d) * l, y: (M.y - u) * l }))), f = h.map((p, M) => h.filter((b, $) => $ !== M && _(p[0], b)).length), x = i.depth / 2, g = -i.depth / 2;
137
- return h.forEach((p, M) => {
138
- if (f[M] % 2 === 1) return;
139
- const b = h.filter((m, v) => f[v] === f[M] + 1 && _(m[0], p)), { points: $, triangles: y } = U(p, b), w = $.map((m) => n.vertex(m.x, m.y, x, 0, 0, 1)), E = $.map((m) => n.vertex(m.x, m.y, g, 0, 0, -1));
140
- for (let m = 0; m < y.length; m += 3)
141
- n.triangle(w[y[m]], w[y[m + 1]], w[y[m + 2]]), n.triangle(E[y[m]], E[y[m + 2]], E[y[m + 1]]);
142
- for (const m of [I(p) >= 0 ? p : [...p].reverse(), ...b.map((v) => I(v) <= 0 ? v : [...v].reverse())])
143
- for (let v = 0; v < m.length; v++) {
144
- const q = m[v], z = m[(v + 1) % m.length], A = z.y - q.y, S = -(z.x - q.x), D = n.vertex(q.x, q.y, g, A, S, 0), L = n.vertex(z.x, z.y, g, A, S, 0), O = n.vertex(z.x, z.y, x, A, S, 0), T = n.vertex(q.x, q.y, x, A, S, 0);
145
- n.quad(D, L, O, T);
146
- }
147
- }), n.build();
148
- }
149
- const k = Math.PI * 2;
150
- function Z([s, i, c]) {
151
- const n = new j(), e = s / 2, a = i / 2, t = c / 2, o = [
152
- [[0, 0, 1], [[-e, -a, t], [e, -a, t], [e, a, t], [-e, a, t]]],
153
- [[0, 0, -1], [[e, -a, -t], [-e, -a, -t], [-e, a, -t], [e, a, -t]]],
154
- [[1, 0, 0], [[e, -a, t], [e, -a, -t], [e, a, -t], [e, a, t]]],
155
- [[-1, 0, 0], [[-e, -a, -t], [-e, -a, t], [-e, a, t], [-e, a, -t]]],
156
- [[0, 1, 0], [[-e, a, t], [e, a, t], [e, a, -t], [-e, a, -t]]],
157
- [[0, -1, 0], [[-e, -a, -t], [e, -a, -t], [e, -a, t], [-e, -a, t]]]
158
- ];
159
- for (const [[r, l, d], u] of o) {
160
- const [h, f, x, g] = u.map(([p, M, b]) => n.vertex(p, M, b, r, l, d));
161
- n.quad(h, f, x, g);
162
- }
163
- return n.build();
164
- }
165
- function G([s, i], c = 1) {
166
- const n = new j(), e = Math.max(1, Math.round(c)), a = [];
167
- for (let t = 0; t <= e; t++) {
168
- const o = i / 2 - i * t / e;
169
- a.push(Array.from({ length: e + 1 }, (r, l) => n.vertex(-s / 2 + s * l / e, 0, o, 0, 1, 0)));
170
- }
171
- for (let t = 0; t < e; t++)
172
- for (let o = 0; o < e; o++) n.quad(a[t][o], a[t][o + 1], a[t + 1][o + 1], a[t + 1][o]);
173
- return n.build();
174
- }
175
- function J(s, i = 16) {
176
- const c = new j(), n = Math.max(6, Math.round(i)), e = Math.max(3, Math.round(n / 2)), a = [];
177
- for (let t = 0; t <= e; t++) {
178
- const o = t / e * Math.PI, r = [];
179
- for (let l = 0; l <= n; l++) {
180
- const d = l / n * k, u = Math.sin(o) * Math.sin(d), h = Math.cos(o), f = Math.sin(o) * Math.cos(d);
181
- r.push(c.vertex(u * s, h * s, f * s, u, h, f));
182
- }
183
- a.push(r);
184
- }
185
- for (let t = 0; t < e; t++)
186
- for (let o = 0; o < n; o++) {
187
- const r = a[t][o], l = a[t + 1][o], d = a[t + 1][o + 1], u = a[t][o + 1];
188
- t > 0 && c.triangle(r, l, u), t < e - 1 && c.triangle(l, d, u);
189
- }
190
- return c.build();
191
- }
192
- function N(s, i, c, n, e) {
193
- const a = s.vertex(0, c, 0, 0, n, 0), t = Array.from({ length: e }, (o, r) => {
194
- const l = r / e * k;
195
- return s.vertex(Math.sin(l) * i, c, Math.cos(l) * i, 0, n, 0);
196
- });
197
- for (let o = 0; o < e; o++) {
198
- const r = t[o], l = t[(o + 1) % e];
199
- n === 1 ? s.triangle(a, r, l) : s.triangle(a, l, r);
200
- }
201
- }
202
- function K(s, i, c = 24) {
203
- const n = new j(), e = Math.max(6, Math.round(c)), a = i / 2, t = -i / 2, o = (d) => Array.from({ length: e + 1 }, (u, h) => {
204
- const f = h / e * k;
205
- return n.vertex(Math.sin(f) * s, d, Math.cos(f) * s, Math.sin(f), 0, Math.cos(f));
206
- }), r = o(t), l = o(a);
207
- for (let d = 0; d < e; d++) n.quad(r[d], r[d + 1], l[d + 1], l[d]);
208
- return N(n, s, a, 1, e), N(n, s, t, -1, e), n.build();
209
- }
210
- function Q(s, i, c = 24) {
211
- const n = new j(), e = Math.max(6, Math.round(c)), a = i / 2, t = -i / 2, o = s / i;
212
- for (let r = 0; r < e; r++) {
213
- const l = r / e * k, d = (r + 1) / e * k, u = (l + d) / 2, h = n.vertex(Math.sin(l) * s, t, Math.cos(l) * s, Math.sin(l), o, Math.cos(l)), f = n.vertex(Math.sin(d) * s, t, Math.cos(d) * s, Math.sin(d), o, Math.cos(d)), x = n.vertex(0, a, 0, Math.sin(u), o, Math.cos(u));
214
- n.triangle(h, f, x);
215
- }
216
- return N(n, s, t, -1, e), n.build();
217
- }
218
- function R(s, i, c = 24) {
219
- const n = new j(), e = Math.max(6, Math.round(c)), a = Math.max(4, Math.round(e / 2)), t = [];
220
- for (let o = 0; o <= e; o++) {
221
- const r = o / e * k, l = [];
222
- for (let d = 0; d <= a; d++) {
223
- const u = d / a * k, h = Math.cos(u) * Math.sin(r), f = Math.sin(u), x = Math.cos(u) * Math.cos(r), g = s + i * Math.cos(u);
224
- l.push(n.vertex(g * Math.sin(r), i * Math.sin(u), g * Math.cos(r), h, f, x));
225
- }
226
- t.push(l);
227
- }
228
- for (let o = 0; o < e; o++)
229
- for (let r = 0; r < a; 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(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
- }
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(s, i = []) {
255
- const c = [], n = /* @__PURE__ */ new Map();
256
- for (const t of s.objects) {
257
- if (t.id ? n.has(t.id) && c.push(`two objects share the id "${t.id}"`) : c.push("an object has no id"), t.parent !== void 0 && !n.has(t.parent) && c.push(`"${t.id}" has parent "${t.parent}", which must be an earlier object`), t.quaternion && t.quaternion.length !== 4 && c.push(`"${t.id}": a quaternion has four numbers`), t.kind === "mesh") {
258
- s.materials?.[t.material] || c.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)) && c.push(`"${t.id}": an extrude needs a path that starts with M`), r.every((l) => Number.isFinite(l) && l > 0) || c.push(`"${t.id}": a ${o.type}'s sizes must be positive`);
261
- }
262
- t.kind === "camera" && (t.near > 0 && t.far > t.near || c.push(`camera "${t.id}": near must be above 0 and far beyond it`), t.projection === "perspective" && !(t.fov > 0 && t.fov < 180) && c.push(`camera "${t.id}": fov is between 0 and 180 degrees`), t.projection === "orthographic" && !(t.height > 0) && c.push(`camera "${t.id}": height must be positive`)), t.id && n.set(t.id, t);
263
- }
264
- const e = n.get(s.camera);
265
- e ? e.kind !== "camera" && c.push(`the scene's camera "${s.camera}" is a ${e.kind}, not a camera`) : c.push(`the scene's camera "${s.camera}" is not one of its objects`), s.fog && !(s.fog.far > s.fog.near) && c.push("fog: far must be beyond near");
266
- const a = /* @__PURE__ */ new Map();
267
- for (const t of i) {
268
- if (!t.target.startsWith(`${s.id}/`)) continue;
269
- const o = t.target.slice(s.id.length + 1);
270
- a.has(o) || a.set(o, /* @__PURE__ */ new Set()), a.get(o).add(t.property);
271
- }
272
- for (const [t, o] of a) {
273
- n.has(t) || c.push(`a track animates "${s.id}/${t}", which is not in the scene`);
274
- for (const r of tt)
275
- o.has(r.vector) && r.components.some((l) => o.has(l)) && c.push(`"${t}": its ${r.name} is animated both by ${r.vector} and by ${r.components.join(" / ")}; use one`);
276
- }
277
- return c;
278
- }
279
- function st(s) {
280
- const i = Array.from({ length: s.indices.length / 3 }, () => []);
281
- for (const c of C(s))
282
- for (const n of c.faces) {
283
- const e = c.faces.find((a) => a !== n) ?? -1;
284
- i[n].push({ a: c.a, b: c.b, across: e });
285
- }
286
- return { ...s, faceEdges: i };
287
- }
288
- function at(s, i = {}) {
289
- const c = new Map((i.kinds ?? []).map((t) => [t.kind, t])), n = nt(s);
290
- for (const t of s.objects) {
291
- if (et.has(t.kind)) continue;
292
- const o = c.get(t.kind);
293
- 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)`);
294
- }
295
- if (n.length > 0) throw new Error(`scene-3d: "${s.id}" is not valid:
296
- - ${n.join(`
297
- - `)}`);
298
- const e = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
299
- for (const t of s.objects) {
300
- t.kind === "mesh" && e.set(t.id, st(V(t.geometry)));
301
- const o = c.get(t.kind);
302
- o?.prepare && a.set(t.id, o.prepare(t));
303
- }
304
- return { scene: s, meshes: e, kinds: c, prepared: a };
305
- }
306
- const et = /* @__PURE__ */ new Set(["group", "mesh", "camera", "light"]);
307
- export {
308
- j as M,
309
- K as a,
310
- Z as b,
311
- Q as c,
312
- _ as d,
313
- W as e,
314
- st as f,
315
- V as g,
316
- J as h,
317
- U as i,
318
- at as l,
319
- C as m,
320
- G as p,
321
- I as s,
322
- R as t,
323
- nt as v
324
- };