@algorisys/tinyfly 0.99.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 +9 -9
- package/bin/tinyfly.mjs +7 -3
- package/docs/acting.md +10 -6
- package/docs/character-appearance.md +71 -7
- package/docs/editor-guide.md +38 -3
- 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 +34 -9
- package/docs/maps.md +2 -2
- package/docs/props.md +61 -1
- 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 +4795 -3752
- 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 +7294 -5893
- 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/acting/character-script.d.ts +14 -2
- package/lib/types/characters/acting/script.d.ts +9 -0
- package/lib/types/characters/capabilities.d.ts +2 -0
- package/lib/types/characters/character.d.ts +28 -1
- package/lib/types/characters/hair-follow.d.ts +12 -6
- package/lib/types/characters/hands/held-items.d.ts +6 -2
- package/lib/types/characters/head/face.d.ts +23 -1
- package/lib/types/characters/index.d.ts +3 -2
- package/lib/types/characters/interactions.d.ts +60 -0
- package/lib/types/characters/props/families/animals.d.ts +6 -0
- package/lib/types/characters/props/families/birds.d.ts +16 -0
- package/lib/types/characters/props/families/furniture.d.ts +102 -0
- package/lib/types/characters/props/index.d.ts +1 -0
- package/lib/types/characters/props/presets.d.ts +15 -2
- package/lib/types/characters/props/ride-3d.d.ts +4 -1
- package/lib/types/characters/scenery.d.ts +126 -0
- package/lib/types/characters/species/human-motion.d.ts +17 -0
- package/lib/types/characters/species/human.d.ts +6 -0
- package/lib/types/characters/wardrobe/basic-outfit.d.ts +16 -5
- 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 +423 -47
- package/llms.txt +29 -29
- package/package.json +2 -2
- package/skills/tinyfly/SKILL.md +20 -6
- package/lib/addons/load-scene-CQvcFWGJ.js +0 -331
- 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,4 +1,4 @@
|
|
|
1
|
-
import { p as _ } from "./shading-
|
|
1
|
+
import { p as _ } from "./shading-0lPgnXmD.js";
|
|
2
2
|
import { mat4 as h, vec3 as v } from "@algorisys/tinyfly";
|
|
3
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;
|