@algorisys/tinyfly 0.100.0 → 0.101.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.
- package/README.md +5 -5
- package/bin/tinyfly.mjs +7 -3
- package/docs/character-appearance.md +26 -0
- package/docs/editor-guide.md +1 -1
- package/docs/examples.md +1 -1
- package/docs/getting-started.md +1 -1
- package/docs/gsap-compat.md +1 -1
- package/docs/llm-guide.md +14 -2
- package/docs/maps.md +2 -2
- package/docs/scene-3d.md +23 -4
- package/docs/teaching.md +1 -1
- package/docs/video-rendering.md +154 -0
- package/lib/addons/adapters.js +387 -333
- package/lib/addons/characters.js +4467 -4448
- package/lib/addons/load-scene-oWNsYYC1.js +372 -0
- package/lib/addons/scene-3d-webgl.js +1 -1
- package/lib/addons/scene-3d.js +323 -277
- package/lib/addons/shading-0lPgnXmD.js +96 -0
- package/lib/browser/tinyfly-scene-3d.iife.js +2 -2
- package/lib/browser/tinyfly.iife.js +14 -14
- package/lib/browser/tinyfly.js +5888 -5511
- package/lib/browser/tinyfly.umd.js +14 -14
- package/lib/engine/tinyfly-engine.js +1389 -1031
- package/lib/engine/tinyfly-engine.umd.cjs +2 -2
- package/lib/headless/headless.js +39 -0
- package/lib/types/adapters/canvas/impossible.d.ts +15 -0
- package/lib/types/adapters/canvas/index.d.ts +3 -0
- package/lib/types/adapters/canvas/nested-zoom.d.ts +40 -0
- package/lib/types/adapters/canvas/zoom-blur.d.ts +49 -0
- package/lib/types/characters/character.d.ts +23 -3
- package/lib/types/characters/head/face.d.ts +19 -2
- package/lib/types/engine/authoring/beat-loop.d.ts +46 -0
- package/lib/types/engine/authoring/curve.d.ts +26 -0
- package/lib/types/engine/authoring/index.d.ts +3 -0
- package/lib/types/engine/authoring/periodic.d.ts +89 -0
- package/lib/types/engine/path/goo.d.ts +103 -0
- package/lib/types/engine/path/impossible.d.ts +92 -0
- package/lib/types/engine/path/index.d.ts +6 -0
- package/lib/types/engine/path/similarity.d.ts +48 -0
- package/lib/types/headless/index.d.ts +1 -0
- package/lib/types/headless/loop-audio.d.ts +21 -0
- package/lib/types/headless/node-audio.d.ts +20 -0
- package/lib/types/headless/video-scene.d.ts +9 -0
- package/lib/types/scene-3d/camera.d.ts +11 -2
- package/lib/types/scene-3d/geometry/mesh.d.ts +2 -0
- package/lib/types/scene-3d/geometry/primitives.d.ts +7 -0
- package/lib/types/scene-3d/impossible-3d.d.ts +29 -0
- package/lib/types/scene-3d/index.d.ts +4 -3
- package/lib/types/scene-3d/resolve-scene.d.ts +13 -1
- package/lib/types/scene-3d/scene-3d-adapter.d.ts +2 -0
- package/lib/types/scene-3d/scene-types.d.ts +29 -4
- package/lib/types/scene-3d/shading.d.ts +2 -0
- package/llms-full.txt +226 -15
- package/llms.txt +29 -29
- package/package.json +1 -1
- package/skills/tinyfly/SKILL.md +7 -0
- package/lib/addons/load-scene-CQvcFWGJ.js +0 -331
- package/lib/addons/shading-o5T_v9DT.js +0 -89
|
@@ -1,331 +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(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,89 +0,0 @@
|
|
|
1
|
-
import { vec3 as f } from "@algorisys/tinyfly";
|
|
2
|
-
const b = /* @__PURE__ */ new Map();
|
|
3
|
-
function M(n) {
|
|
4
|
-
const i = b.get(n);
|
|
5
|
-
if (i) return i;
|
|
6
|
-
let r = [1, 1, 1];
|
|
7
|
-
const o = n.trim().replace("#", "");
|
|
8
|
-
if (n.trim().startsWith("#") && (o.length === 3 || o.length === 6)) {
|
|
9
|
-
const t = o.length === 3 ? o.split("").map((s) => s + s).join("") : o;
|
|
10
|
-
r = [0, 2, 4].map((s) => Number.parseInt(t.slice(s, s + 2), 16) / 255);
|
|
11
|
-
} else {
|
|
12
|
-
const t = n.match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/);
|
|
13
|
-
t && (r = [Number(t[1]) / 255, Number(t[2]) / 255, Number(t[3]) / 255]);
|
|
14
|
-
}
|
|
15
|
-
return b.size < 512 && b.set(n, r), r;
|
|
16
|
-
}
|
|
17
|
-
const x = [
|
|
18
|
-
{ id: "default-ambient", light: "ambient", color: "#ffffff", intensity: 0.35, position: [0, 0, 0], direction: [0, -1, 0], angle: 30 },
|
|
19
|
-
{ id: "default-key", light: "directional", color: "#ffffff", intensity: 0.8, position: [3, 5, 4], direction: f.normalize([-3, -5, -4]), angle: 30 }
|
|
20
|
-
], y = (n, i, r) => {
|
|
21
|
-
const o = Math.min(1, Math.max(0, (r - n) / (i - n)));
|
|
22
|
-
return o * o * (3 - 2 * o);
|
|
23
|
-
};
|
|
24
|
-
function g(n, i, r) {
|
|
25
|
-
const o = [0, 0, 0];
|
|
26
|
-
for (const t of r) {
|
|
27
|
-
const s = M(t.color);
|
|
28
|
-
let l;
|
|
29
|
-
if (t.light === "ambient")
|
|
30
|
-
l = t.intensity;
|
|
31
|
-
else if (t.light === "directional")
|
|
32
|
-
l = t.intensity * Math.max(0, -f.dot(i, t.direction));
|
|
33
|
-
else {
|
|
34
|
-
const e = f.subtract(t.position, n), m = f.length(e), d = m > 0 ? f.scale(e, 1 / m) : i, a = t.range ? Math.max(0, 1 - m / t.range) ** 2 : 1;
|
|
35
|
-
if (l = t.intensity * Math.max(0, f.dot(i, d)) * a, t.light === "spot") {
|
|
36
|
-
const c = Math.cos(t.angle * Math.PI / 180), h = Math.cos(t.angle * 0.8 * Math.PI / 180);
|
|
37
|
-
l *= y(c, h, -f.dot(d, t.direction));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
o[0] += s[0] * l, o[1] += s[1] * l, o[2] += s[2] * l;
|
|
41
|
-
}
|
|
42
|
-
return o;
|
|
43
|
-
}
|
|
44
|
-
function v(n, i) {
|
|
45
|
-
const r = Math.max(2, Math.round(i));
|
|
46
|
-
return Math.min(1.2, Math.ceil(Math.min(1, n) * r - 1e-9) / r);
|
|
47
|
-
}
|
|
48
|
-
function N(n, i) {
|
|
49
|
-
return n ? Math.min(1, Math.max(0, (i - n.near) / (n.far - n.near))) : 0;
|
|
50
|
-
}
|
|
51
|
-
function C(n, i, r, o) {
|
|
52
|
-
const t = n.material, s = M(n.color ?? t.color), l = t.shading ?? "lambert";
|
|
53
|
-
let e;
|
|
54
|
-
if (l === "unlit")
|
|
55
|
-
e = [...s];
|
|
56
|
-
else {
|
|
57
|
-
const a = i.length > 0 ? i : x;
|
|
58
|
-
let c;
|
|
59
|
-
if (l === "lambert") {
|
|
60
|
-
const h = [0, 0, 0];
|
|
61
|
-
for (const u of n.vertexNormals) {
|
|
62
|
-
const p = g(n.centroid, u, a);
|
|
63
|
-
h[0] += p[0] / 3, h[1] += p[1] / 3, h[2] += p[2] / 3;
|
|
64
|
-
}
|
|
65
|
-
c = h;
|
|
66
|
-
} else if (c = g(n.centroid, n.normal, a), l === "toon") {
|
|
67
|
-
const h = Math.max(c[0], c[1], c[2]), u = h > 0 ? v(h, t.bands ?? 3) / h : 0;
|
|
68
|
-
c = [c[0] * u, c[1] * u, c[2] * u];
|
|
69
|
-
}
|
|
70
|
-
e = [s[0] * c[0], s[1] * c[1], s[2] * c[2]];
|
|
71
|
-
}
|
|
72
|
-
if (t.emissive) {
|
|
73
|
-
const a = M(t.emissive);
|
|
74
|
-
e = [e[0] + a[0], e[1] + a[1], e[2] + a[2]];
|
|
75
|
-
}
|
|
76
|
-
const m = N(o, f.distance(n.centroid, r.position));
|
|
77
|
-
if (o && m > 0) {
|
|
78
|
-
const a = M(o.color);
|
|
79
|
-
e = [e[0] + (a[0] - e[0]) * m, e[1] + (a[1] - e[1]) * m, e[2] + (a[2] - e[2]) * m];
|
|
80
|
-
}
|
|
81
|
-
const d = (a) => Math.round(Math.min(1, Math.max(0, a)) * 255);
|
|
82
|
-
return { color: `rgb(${d(e[0])}, ${d(e[1])}, ${d(e[2])})`, alpha: n.opacity };
|
|
83
|
-
}
|
|
84
|
-
export {
|
|
85
|
-
N as f,
|
|
86
|
-
g as l,
|
|
87
|
-
M as p,
|
|
88
|
-
C as s
|
|
89
|
-
};
|