@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.
Files changed (58) hide show
  1. package/README.md +5 -5
  2. package/bin/tinyfly.mjs +7 -3
  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 +14 -2
  9. package/docs/maps.md +2 -2
  10. package/docs/scene-3d.md +23 -4
  11. package/docs/teaching.md +1 -1
  12. package/docs/video-rendering.md +154 -0
  13. package/lib/addons/adapters.js +387 -333
  14. package/lib/addons/characters.js +4467 -4448
  15. package/lib/addons/load-scene-oWNsYYC1.js +372 -0
  16. package/lib/addons/scene-3d-webgl.js +1 -1
  17. package/lib/addons/scene-3d.js +323 -277
  18. package/lib/addons/shading-0lPgnXmD.js +96 -0
  19. package/lib/browser/tinyfly-scene-3d.iife.js +2 -2
  20. package/lib/browser/tinyfly.iife.js +14 -14
  21. package/lib/browser/tinyfly.js +5888 -5511
  22. package/lib/browser/tinyfly.umd.js +14 -14
  23. package/lib/engine/tinyfly-engine.js +1389 -1031
  24. package/lib/engine/tinyfly-engine.umd.cjs +2 -2
  25. package/lib/headless/headless.js +39 -0
  26. package/lib/types/adapters/canvas/impossible.d.ts +15 -0
  27. package/lib/types/adapters/canvas/index.d.ts +3 -0
  28. package/lib/types/adapters/canvas/nested-zoom.d.ts +40 -0
  29. package/lib/types/adapters/canvas/zoom-blur.d.ts +49 -0
  30. package/lib/types/characters/character.d.ts +23 -3
  31. package/lib/types/characters/head/face.d.ts +19 -2
  32. package/lib/types/engine/authoring/beat-loop.d.ts +46 -0
  33. package/lib/types/engine/authoring/curve.d.ts +26 -0
  34. package/lib/types/engine/authoring/index.d.ts +3 -0
  35. package/lib/types/engine/authoring/periodic.d.ts +89 -0
  36. package/lib/types/engine/path/goo.d.ts +103 -0
  37. package/lib/types/engine/path/impossible.d.ts +92 -0
  38. package/lib/types/engine/path/index.d.ts +6 -0
  39. package/lib/types/engine/path/similarity.d.ts +48 -0
  40. package/lib/types/headless/index.d.ts +1 -0
  41. package/lib/types/headless/loop-audio.d.ts +21 -0
  42. package/lib/types/headless/node-audio.d.ts +20 -0
  43. package/lib/types/headless/video-scene.d.ts +9 -0
  44. package/lib/types/scene-3d/camera.d.ts +11 -2
  45. package/lib/types/scene-3d/geometry/mesh.d.ts +2 -0
  46. package/lib/types/scene-3d/geometry/primitives.d.ts +7 -0
  47. package/lib/types/scene-3d/impossible-3d.d.ts +29 -0
  48. package/lib/types/scene-3d/index.d.ts +4 -3
  49. package/lib/types/scene-3d/resolve-scene.d.ts +13 -1
  50. package/lib/types/scene-3d/scene-3d-adapter.d.ts +2 -0
  51. package/lib/types/scene-3d/scene-types.d.ts +29 -4
  52. package/lib/types/scene-3d/shading.d.ts +2 -0
  53. package/llms-full.txt +226 -15
  54. package/llms.txt +29 -29
  55. package/package.json +1 -1
  56. package/skills/tinyfly/SKILL.md +7 -0
  57. package/lib/addons/load-scene-CQvcFWGJ.js +0 -331
  58. package/lib/addons/shading-o5T_v9DT.js +0 -89
@@ -1,331 +1,350 @@
1
- import { M as mt, b as vt, c as Mt, a as bt, e as kt, g as At, l as It, m as Pt, p as St, d as Tt, f as Et, s as Ct, h as Dt, t as Ot, i as $t, v as Nt } from "./load-scene-CQvcFWGJ.js";
2
- import { vec3 as u, mat4 as I, ribbon as K, ribbonHeadCap as Q, quat as N, trailSamples as U } from "@algorisys/tinyfly";
3
- import { p as z, f as G, s as q } from "./shading-o5T_v9DT.js";
4
- import { l as Wt } from "./shading-o5T_v9DT.js";
5
- function x(t, e) {
6
- const i = u.normalize(u.subtract(e, t)), n = Math.abs(i[1]) > 0.9999 ? [0, 0, -1] : [0, 1, 0];
7
- return I.lookAt(t, e, n);
1
+ import { M as It, b as Pt, c as St, a as Tt, e as Ct, g as Et, l as $t, m as Dt, p as Ot, d as Ft, f as zt, r as Nt, s as Wt, h as Rt, t as Vt, i as Lt, v as Yt } from "./load-scene-oWNsYYC1.js";
2
+ import { vec3 as w, mat4 as S, quat as F, ribbon as U, ribbonHeadCap as q, trailSamples as G } from "@algorisys/tinyfly";
3
+ import { p as R, f as x, s as j, i as tt } from "./shading-0lPgnXmD.js";
4
+ import { l as Ht } from "./shading-0lPgnXmD.js";
5
+ function et(t, e, n = {}) {
6
+ const o = w.normalize(w.subtract(e, t)), s = n.up ?? (Math.abs(o[1]) > 0.9999 ? [0, 0, -1] : [0, 1, 0]);
7
+ return H(S.lookAt(t, e, s), n.roll ?? 0);
8
8
  }
9
- function dt(t, e, i, n) {
10
- const s = e * Math.PI / 180, a = i * Math.PI / 180;
11
- return [t[0] + n * Math.cos(a) * Math.sin(s), t[1] + n * Math.sin(a), t[2] + n * Math.cos(a) * Math.cos(s)];
9
+ function H(t, e) {
10
+ return e ? S.multiply(S.fromQuat(F.fromAxisAngle([0, 0, 1], -e)), t) : t;
12
11
  }
13
- function pt(t, e, i) {
14
- const n = u.subtract(t, e), s = u.length(n);
12
+ function yt(t, e, n, o) {
13
+ const s = e * Math.PI / 180, a = n * Math.PI / 180;
14
+ return [t[0] + o * Math.cos(a) * Math.sin(s), t[1] + o * Math.sin(a), t[2] + o * Math.cos(a) * Math.cos(s)];
15
+ }
16
+ function wt(t, e, n) {
17
+ const o = w.subtract(t, e), s = w.length(o);
15
18
  if (s === 0) return t;
16
- const a = Math.max(1e-3, s - i);
17
- return u.add(e, u.scale(n, a / s));
19
+ const a = Math.max(1e-3, s - n);
20
+ return w.add(e, w.scale(o, a / s));
18
21
  }
19
- function Y(t, e) {
20
- if (t.projection === "perspective") return I.perspective(t.fov, e, t.near, t.far);
21
- const i = t.height / 2;
22
- return I.orthographic(-i * e, i * e, -i, i, t.near, t.far);
22
+ function V(t, e) {
23
+ if (t.projection === "perspective") return S.perspective(t.fov, e, t.near, t.far);
24
+ const n = t.height / 2;
25
+ return S.orthographic(-n * e, n * e, -n, n, t.near, t.far);
23
26
  }
24
- function j(t, e, i, n) {
25
- const { camera: s } = n, a = s.near, r = t.map((d) => I.transformPoint(s.view, d)), p = s.projection[5] * n.height / 2, f = (d, h) => i.width * (1 - i.taper * d) * p / (s.orthographic ? 1 : Math.max(h, a)), k = z(i.color), y = [];
26
- let M = [];
27
- const E = (d) => -d[2] >= a;
27
+ function nt(t, e, n, o) {
28
+ const { camera: s } = o, a = s.near, r = t.map((d) => S.transformPoint(s.view, d)), f = s.projection[5] * o.height / 2, l = (d, c) => n.width * (1 - n.taper * d) * f / (s.orthographic ? 1 : Math.max(c, a)), m = R(n.color), A = [];
29
+ let y = [];
30
+ const T = (d) => -d[2] >= a;
28
31
  for (let d = 0; d < r.length; d++) {
29
- const h = r[d];
30
- E(h) ? (M.length === 0 && d > 0 && !E(r[d - 1]) && M.push(_(r[d - 1], h, e[d - 1], e[d], a)), M.push({ view: h, age: e[d] })) : M.length > 0 && (M.push(_(r[d - 1], h, e[d - 1], e[d], a)), y.push(M), M = []);
32
+ const c = r[d];
33
+ T(c) ? (y.length === 0 && d > 0 && !T(r[d - 1]) && y.push(L(r[d - 1], c, e[d - 1], e[d], a)), y.push({ view: c, age: e[d] })) : y.length > 0 && (y.push(L(r[d - 1], c, e[d - 1], e[d], a)), A.push(y), y = []);
31
34
  }
32
- M.length > 0 && y.push(M);
33
- const C = [];
34
- for (const d of y) {
35
+ y.length > 0 && A.push(y);
36
+ const $ = [];
37
+ for (const d of A) {
35
38
  if (d.length < 2) continue;
36
- const h = d.map((l) => -l.view[2]), o = d.map((l) => n.toScreen(l.view)).map((l, w) => ({ x: l.x, y: l.y, width: f(d[w].age, h[w]) })), c = K(o), b = d[d.length - 1].age === 0 ? Q(o) : null;
37
- for (let l = 0; l + 1 < d.length; l++) {
38
- const w = (h[l] + h[l + 1]) / 2;
39
- if (w > s.far) continue;
40
- let m = i.opacity * (1 - i.fade * ((d[l].age + d[l + 1].age) / 2));
41
- const O = u.lerp(d[l].view, d[l + 1].view, 0.5), S = G(n.fog, u.length(O));
42
- let D = k;
43
- if (n.fog && S > 0)
44
- if (i.additive) m *= 1 - S;
39
+ const c = d.map((h) => -h.view[2]), C = d.map((h) => o.toScreen(h.view)).map((h, g) => ({ x: h.x, y: h.y, width: l(d[g].age, c[g]) })), i = U(C), p = d[d.length - 1].age === 0 ? q(C) : null;
40
+ for (let h = 0; h + 1 < d.length; h++) {
41
+ const g = (c[h] + c[h + 1]) / 2;
42
+ if (g > s.far) continue;
43
+ let M = n.opacity * (1 - n.fade * ((d[h].age + d[h + 1].age) / 2));
44
+ const b = w.lerp(d[h].view, d[h + 1].view, 0.5), E = x(o.fog, w.length(b));
45
+ let D = m;
46
+ if (o.fog && E > 0)
47
+ if (n.additive) M *= 1 - E;
45
48
  else {
46
- const v = z(n.fog.color);
47
- D = [k[0] + (v[0] - k[0]) * S, k[1] + (v[1] - k[1]) * S, k[2] + (v[2] - k[2]) * S];
49
+ const v = R(o.fog.color);
50
+ D = [m[0] + (v[0] - m[0]) * E, m[1] + (v[1] - m[1]) * E, m[2] + (v[2] - m[2]) * E];
48
51
  }
49
- if (m <= 0) continue;
50
- const $ = `rgb(${D.map((v) => Math.round(Math.min(1, Math.max(0, v)) * 255)).join(", ")})`, g = [c.left[l], c.left[l + 1], c.right[l + 1], c.right[l]], T = l + 2 === d.length ? b : null;
51
- C.push({
52
- depth: w,
52
+ if (M <= 0) continue;
53
+ const O = `rgb(${D.map((v) => Math.round(Math.min(1, Math.max(0, v)) * 255)).join(", ")})`, I = [i.left[h], i.left[h + 1], i.right[h + 1], i.right[h]], u = h + 2 === d.length ? p : null;
54
+ $.push({
55
+ depth: g,
53
56
  draw(v) {
54
- i.additive && (v.globalCompositeOperation = "lighter"), v.globalAlpha = Math.min(1, m), v.fillStyle = $, v.beginPath(), v.moveTo(g[0].x, g[0].y), v.lineTo(g[1].x, g[1].y), T && v.arc(T.x, T.y, T.radius, T.start, T.start - Math.PI, !0), v.lineTo(g[2].x, g[2].y), v.lineTo(g[3].x, g[3].y), v.closePath(), v.fill(), !i.additive && m >= 1 && (v.strokeStyle = $, v.lineWidth = 0.75, v.stroke());
57
+ n.additive && (v.globalCompositeOperation = "lighter"), v.globalAlpha = Math.min(1, M), v.fillStyle = O, v.beginPath(), v.moveTo(I[0].x, I[0].y), v.lineTo(I[1].x, I[1].y), u && v.arc(u.x, u.y, u.radius, u.start, u.start - Math.PI, !0), v.lineTo(I[2].x, I[2].y), v.lineTo(I[3].x, I[3].y), v.closePath(), v.fill(), !n.additive && M >= 1 && (v.strokeStyle = O, v.lineWidth = 0.75, v.stroke());
55
58
  }
56
59
  });
57
60
  }
58
61
  }
59
- return C;
62
+ return $;
60
63
  }
61
- function _(t, e, i, n, s) {
64
+ function L(t, e, n, o, s) {
62
65
  const a = (-s - t[2]) / (e[2] - t[2]);
63
- return { view: u.lerp(t, e, a), age: i + (n - i) * a };
66
+ return { view: w.lerp(t, e, a), age: n + (o - n) * a };
64
67
  }
65
- const tt = Math.cos(30 * Math.PI / 180), L = /* @__PURE__ */ new Map(), A = (t) => typeof t == "number" ? t : void 0, R = (t, e) => Array.isArray(t) && t.length === e ? t : void 0;
66
- function V(t, e) {
67
- const i = t.position ?? [0, 0, 0], n = R(e.get("position"), 3) ?? [
68
- A(e.get("x")) ?? i[0],
69
- A(e.get("y")) ?? i[1],
70
- A(e.get("z")) ?? i[2]
68
+ const ot = Math.cos(30 * Math.PI / 180), Q = /* @__PURE__ */ new Map(), P = (t) => typeof t == "number" ? t : void 0, z = (t, e) => Array.isArray(t) && t.length === e ? t : void 0;
69
+ function X(t, e) {
70
+ const n = t.position ?? [0, 0, 0], o = z(e.get("position"), 3) ?? [
71
+ P(e.get("x")) ?? n[0],
72
+ P(e.get("y")) ?? n[1],
73
+ P(e.get("z")) ?? n[2]
71
74
  ];
72
75
  let s;
73
- const a = R(e.get("quaternion"), 4), r = ["rotateX", "rotateY", "rotateZ"].map((y) => A(e.get(y)));
74
- if (a) s = N.normalize(a);
75
- else if (r.some((y) => y !== void 0)) {
76
- const y = t.rotation ?? [0, 0, 0];
77
- s = N.fromEuler(r[0] ?? y[0], r[1] ?? y[1], r[2] ?? y[2]);
78
- } else t.quaternion ? s = N.normalize(t.quaternion) : s = t.rotation ? N.fromEuler(...t.rotation) : N.identity();
79
- const p = typeof t.scale == "number" ? [t.scale, t.scale, t.scale] : t.scale ?? [1, 1, 1], f = A(e.get("scale")), k = [
80
- A(e.get("scaleX")) ?? f ?? p[0],
81
- A(e.get("scaleY")) ?? f ?? p[1],
82
- A(e.get("scaleZ")) ?? f ?? p[2]
76
+ const a = z(e.get("quaternion"), 4), r = ["rotateX", "rotateY", "rotateZ"].map((A) => P(e.get(A)));
77
+ if (a) s = F.normalize(a);
78
+ else if (r.some((A) => A !== void 0)) {
79
+ const A = t.rotation ?? [0, 0, 0];
80
+ s = F.fromEuler(r[0] ?? A[0], r[1] ?? A[1], r[2] ?? A[2]);
81
+ } else t.quaternion ? s = F.normalize(t.quaternion) : s = t.rotation ? F.fromEuler(...t.rotation) : F.identity();
82
+ const f = typeof t.scale == "number" ? [t.scale, t.scale, t.scale] : t.scale ?? [1, 1, 1], l = P(e.get("scale")), m = [
83
+ P(e.get("scaleX")) ?? l ?? f[0],
84
+ P(e.get("scaleY")) ?? l ?? f[1],
85
+ P(e.get("scaleZ")) ?? l ?? f[2]
83
86
  ];
84
- return I.compose(n, s, k);
87
+ return S.compose(o, s, m);
85
88
  }
86
- const W = (t) => [t[12], t[13], t[14]];
87
- function et(t, e, i, n) {
88
- const s = W(e), a = R(i.get("lookAt"), 3) ?? t.lookAt, r = a ? x(s, a) : I.invert(e) ?? I.identity(), p = t.projection === "perspective" ? Y({ ...t, fov: A(i.get("fov")) ?? t.fov }, n) : Y({ ...t, height: A(i.get("height")) ?? t.height }, n);
89
+ const N = (t) => [t[12], t[13], t[14]];
90
+ function it(t, e, n, o) {
91
+ const s = N(e), a = z(n.get("lookAt"), 3) ?? t.lookAt, r = P(n.get("roll")) ?? t.roll ?? 0, f = a ? et(s, a, { up: t.up, roll: r }) : H(S.invert(e) ?? S.identity(), r), l = t.projection === "perspective" ? V({ ...t, fov: P(n.get("fov")) ?? t.fov }, o) : V({ ...t, height: P(n.get("height")) ?? t.height }, o);
89
92
  return {
90
93
  id: t.id,
91
- view: r,
92
- projection: p,
94
+ view: f,
95
+ projection: l,
93
96
  position: s,
94
- forward: u.normalize([-r[2], -r[6], -r[10]]),
97
+ forward: w.normalize([-f[2], -f[6], -f[10]]),
95
98
  orthographic: t.projection === "orthographic",
96
99
  near: t.near,
97
100
  far: t.far
98
101
  };
99
102
  }
100
- function F(t) {
101
- return I.transpose(I.invert(t) ?? I.identity());
103
+ function Y(t) {
104
+ return S.transpose(S.invert(t) ?? S.identity());
102
105
  }
103
- function nt(t, e, i, n) {
104
- return u.normalize([t[0] * e + t[4] * i + t[8] * n, t[1] * e + t[5] * i + t[9] * n, t[2] * e + t[6] * i + t[10] * n]);
106
+ function st(t, e, n, o) {
107
+ return w.normalize([t[0] * e + t[4] * n + t[8] * o, t[1] * e + t[5] * n + t[9] * o, t[2] * e + t[6] * n + t[10] * o]);
105
108
  }
106
- function ot(t, e) {
107
- const i = (s) => -s[2] >= e, n = [];
109
+ function rt(t, e) {
110
+ const n = (s) => -s[2] >= e, o = [];
108
111
  for (let s = 0; s < t.length; s++) {
109
112
  const a = t[s], r = t[(s + 1) % t.length];
110
- if (i(a) && n.push(a), i(a) !== i(r)) {
111
- const p = (-e - a[2]) / (r[2] - a[2]);
112
- n.push(u.lerp(a, r, p));
113
+ if (n(a) && o.push(a), n(a) !== n(r)) {
114
+ const f = (-e - a[2]) / (r[2] - a[2]);
115
+ o.push(w.lerp(a, r, f));
113
116
  }
114
117
  }
115
- return n;
118
+ return o;
116
119
  }
117
- function X(t, e = /* @__PURE__ */ new Map(), i) {
118
- const { scene: n } = t, s = (o) => e.get(`${n.id}/${o}`) ?? L, a = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
119
- for (const o of n.objects) {
120
- const c = s(o.id), b = V(o, c), l = o.parent ? a.get(o.parent) : void 0;
121
- a.set(o.id, l ? I.multiply(l, b) : b);
122
- const w = A(c.get("visible")) !== void 0 ? A(c.get("visible")) > 0.5 : o.visible !== !1;
123
- r.set(o.id, w && (o.parent ? r.get(o.parent) !== !1 : !0));
120
+ function at(t, e) {
121
+ const n = P(e.get("outlineWidth")) ?? t.outline?.width, o = e.get("outlineColor"), s = (typeof o == "string" ? o : void 0) ?? t.outline?.color ?? "#000000";
122
+ return n !== void 0 && n > 0 ? { width: n, color: s } : void 0;
123
+ }
124
+ function lt(t, e) {
125
+ return !t || t.to <= t.from ? 1 : Math.min(1, Math.max(0, (e - t.from) / (t.to - t.from)));
126
+ }
127
+ function Z(t, e = /* @__PURE__ */ new Map(), n) {
128
+ const { scene: o } = t, s = (i) => e.get(`${o.id}/${i}`) ?? Q, a = n.nearFade ?? o.nearFade, r = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
129
+ for (const i of o.objects) {
130
+ const p = s(i.id), h = X(i, p), g = i.parent ? r.get(i.parent) : void 0;
131
+ r.set(i.id, g ? S.multiply(g, h) : h);
132
+ const M = P(p.get("visible")) !== void 0 ? P(p.get("visible")) > 0.5 : i.visible !== !1;
133
+ f.set(i.id, M && (i.parent ? f.get(i.parent) !== !1 : !0));
124
134
  }
125
- const p = e.get(n.id)?.get("activeCamera"), f = typeof p == "string" && n.objects.some((o) => o.id === p && o.kind === "camera") ? p : n.camera, k = n.objects.find((o) => o.id === f), y = et(k, a.get(f), s(f), i.width / i.height), M = (o) => {
126
- const c = I.transformPoint(y.projection, o);
127
- return { x: (c[0] + 1) / 2 * i.width, y: (1 - c[1]) / 2 * i.height };
128
- }, E = [];
129
- for (const o of n.objects) {
130
- if (o.kind !== "light" || !r.get(o.id)) continue;
131
- const c = s(o.id), b = W(a.get(o.id)), l = R(c.get("target"), 3) ?? o.target ?? [0, 0, 0], w = c.get("color");
132
- E.push({
133
- id: o.id,
134
- light: o.light,
135
- color: typeof w == "string" ? w : o.color,
136
- intensity: A(c.get("intensity")) ?? o.intensity,
137
- position: b,
138
- direction: u.normalize(u.subtract(l, b)),
139
- range: o.range,
140
- angle: o.angle ?? 30
135
+ const l = e.get(o.id)?.get("activeCamera"), m = typeof l == "string" && o.objects.some((i) => i.id === l && i.kind === "camera") ? l : o.camera, A = o.objects.find((i) => i.id === m), y = it(A, r.get(m), s(m), n.width / n.height), T = (i) => {
136
+ const p = S.transformPoint(y.projection, i);
137
+ return { x: (p[0] + 1) / 2 * n.width, y: (1 - p[1]) / 2 * n.height };
138
+ }, $ = [];
139
+ for (const i of o.objects) {
140
+ if (i.kind !== "light" || !f.get(i.id)) continue;
141
+ const p = s(i.id), h = N(r.get(i.id)), g = z(p.get("target"), 3) ?? i.target ?? [0, 0, 0], M = p.get("color");
142
+ $.push({
143
+ id: i.id,
144
+ light: i.light,
145
+ color: typeof M == "string" ? M : i.color,
146
+ intensity: P(p.get("intensity")) ?? i.intensity,
147
+ position: h,
148
+ direction: w.normalize(w.subtract(g, h)),
149
+ range: i.range,
150
+ angle: i.angle ?? 30
141
151
  });
142
152
  }
143
- const C = [], d = [];
144
- n.objects.forEach((o, c) => {
145
- if (o.kind !== "mesh" || !r.get(o.id)) return;
146
- const b = t.meshes.get(o.id), l = n.materials?.[o.material];
147
- if (!b || !l) return;
148
- const w = s(o.id), m = a.get(o.id), O = F(m), S = w.get("color"), D = (A(w.get("opacity")) ?? 1) * (l.opacity ?? 1);
149
- D <= 0 || (d.push({ objectId: o.id, objectIndex: c, mesh: b, world: m, material: l, color: typeof S == "string" ? S : void 0, opacity: D }), C.push(...H(b, m, O, y, M, l, {
150
- objectId: o.id,
151
- objectIndex: c,
152
- layer: o.layer ?? 0,
153
- color: typeof S == "string" ? S : void 0,
154
- opacity: D
155
- })));
153
+ const d = [], c = [];
154
+ o.objects.forEach((i, p) => {
155
+ if (i.kind !== "mesh" || !f.get(i.id)) return;
156
+ const h = t.meshes.get(i.id), g = o.materials?.[i.material];
157
+ if (!h || !g) return;
158
+ const M = s(i.id), b = r.get(i.id), E = Y(b), D = M.get("color"), O = (P(M.get("opacity")) ?? 1) * (g.opacity ?? 1);
159
+ if (O <= 0) return;
160
+ const I = at(g, M), u = I === g.outline || I && g.outline && I.width === g.outline.width && I.color === g.outline.color ? g : { ...g, outline: I };
161
+ c.push({ objectId: i.id, objectIndex: p, mesh: h, world: b, material: u, color: typeof D == "string" ? D : void 0, opacity: O }), d.push(..._(h, b, E, y, T, u, {
162
+ objectId: i.id,
163
+ objectIndex: p,
164
+ layer: i.layer ?? 0,
165
+ color: typeof D == "string" ? D : void 0,
166
+ opacity: O,
167
+ ink: I,
168
+ nearFade: a
169
+ }));
156
170
  });
157
- const h = [];
158
- n.objects.forEach((o, c) => {
159
- const b = t.kinds.get(o.kind);
160
- if (!b || !r.get(o.id)) return;
161
- const l = b.resolve({
162
- object: o,
163
- prepared: t.prepared.get(o.id),
164
- values: s(o.id),
165
- world: a.get(o.id),
171
+ const k = [];
172
+ o.objects.forEach((i, p) => {
173
+ const h = t.kinds.get(i.kind);
174
+ if (!h || !f.get(i.id)) return;
175
+ const g = h.resolve({
176
+ object: i,
177
+ prepared: t.prepared.get(i.id),
178
+ values: s(i.id),
179
+ world: r.get(i.id),
166
180
  camera: y,
167
- lights: E,
168
- fog: n.fog,
169
- width: i.width,
170
- height: i.height,
171
- toScreen: M
181
+ lights: $,
182
+ fog: o.fog,
183
+ width: n.width,
184
+ height: n.height,
185
+ toScreen: T
172
186
  });
173
- if (!l) return;
174
- const w = o.layer ?? 0;
175
- for (const m of l.drawables ?? []) h.push({ ...m, objectId: o.id, objectIndex: c, layer: w });
176
- for (const m of l.meshes ?? [])
177
- d.push({ objectId: o.id, objectIndex: c, mesh: m.mesh, world: m.world, material: m.material, opacity: m.material.opacity ?? 1 }), C.push(...H(m.mesh, m.world, F(m.world), y, M, m.material, {
178
- objectId: o.id,
179
- objectIndex: c,
180
- layer: w,
181
- opacity: m.material.opacity ?? 1
187
+ if (!g) return;
188
+ const M = i.layer ?? 0;
189
+ for (const b of g.drawables ?? []) k.push({ ...b, objectId: i.id, objectIndex: p, layer: M });
190
+ for (const b of g.meshes ?? [])
191
+ c.push({ objectId: i.id, objectIndex: p, mesh: b.mesh, world: b.world, material: b.material, opacity: b.material.opacity ?? 1 }), d.push(..._(b.mesh, b.world, Y(b.world), y, T, b.material, {
192
+ objectId: i.id,
193
+ objectIndex: p,
194
+ layer: M,
195
+ opacity: b.material.opacity ?? 1,
196
+ ink: b.material.outline,
197
+ nearFade: a
182
198
  }));
183
199
  });
184
- const P = { camera: y, height: i.height, fog: n.fog, toScreen: M };
185
- return n.objects.forEach((o, c) => {
186
- if (o.kind !== "line" && o.kind !== "trail" || !r.get(o.id)) return;
187
- const b = s(o.id), l = o.kind === "line" ? st(o, a.get(o.id)) : rt(o, n, e, i);
188
- if (!l) return;
189
- const w = it(o, b);
190
- if (w.opacity <= 0 || w.width <= 0) return;
191
- const m = o.layer ?? 0;
192
- for (const O of j(l.points, l.ages, w, P)) h.push({ ...O, objectId: o.id, objectIndex: c, layer: m });
193
- }), h.sort((o, c) => o.layer - c.layer || c.depth - o.depth || o.objectIndex - c.objectIndex), C.sort((o, c) => o.layer - c.layer || c.depth - o.depth || o.objectIndex - c.objectIndex || o.face - c.face || o.part - c.part), {
194
- id: n.id,
195
- width: i.width,
196
- height: i.height,
197
- background: n.background,
198
- fog: n.fog,
200
+ const C = { camera: y, height: n.height, fog: o.fog, toScreen: T };
201
+ return o.objects.forEach((i, p) => {
202
+ if (i.kind !== "line" && i.kind !== "trail" || !f.get(i.id)) return;
203
+ const h = s(i.id), g = i.kind === "line" ? dt(i, r.get(i.id)) : ht(i, o, e, n);
204
+ if (!g) return;
205
+ const M = ct(i, h);
206
+ if (M.opacity <= 0 || M.width <= 0) return;
207
+ const b = i.layer ?? 0;
208
+ for (const E of nt(g.points, g.ages, M, C)) k.push({ ...E, objectId: i.id, objectIndex: p, layer: b });
209
+ }), k.sort((i, p) => i.layer - p.layer || p.depth - i.depth || i.objectIndex - p.objectIndex), d.sort((i, p) => i.layer - p.layer || p.depth - i.depth || i.objectIndex - p.objectIndex || i.face - p.face || i.part - p.part), {
210
+ id: o.id,
211
+ width: n.width,
212
+ height: n.height,
213
+ background: o.background,
214
+ fog: o.fog,
199
215
  camera: y,
200
- lights: E,
201
- worlds: a,
202
- triangles: C,
203
- drawables: h,
204
- meshes: d,
205
- time: i.time ?? 0
216
+ lights: $,
217
+ worlds: r,
218
+ triangles: d,
219
+ drawables: k,
220
+ meshes: c,
221
+ time: n.time ?? 0
206
222
  };
207
223
  }
208
- function it(t, e) {
209
- const i = e.get("color"), n = t.kind === "trail";
224
+ function ct(t, e) {
225
+ const n = e.get("color"), o = t.kind === "trail";
210
226
  return {
211
- color: typeof i == "string" ? i : t.color,
212
- width: A(e.get("width")) ?? t.width ?? 0.05,
213
- taper: t.taper ?? (n ? 1 : 0),
214
- fade: t.fade ?? (n ? 1 : 0),
215
- opacity: (A(e.get("opacity")) ?? 1) * (t.opacity ?? 1),
227
+ color: typeof n == "string" ? n : t.color,
228
+ width: P(e.get("width")) ?? t.width ?? 0.05,
229
+ taper: t.taper ?? (o ? 1 : 0),
230
+ fade: t.fade ?? (o ? 1 : 0),
231
+ opacity: (P(e.get("opacity")) ?? 1) * (t.opacity ?? 1),
216
232
  additive: t.blend === "add"
217
233
  };
218
234
  }
219
- function st(t, e) {
220
- const n = (t.closed ? [...t.points, t.points[0]] : t.points).map((s) => I.transformPoint(e, s));
221
- return { points: n, ages: n.map((s, a) => 1 - a / (n.length - 1)) };
235
+ function dt(t, e) {
236
+ const o = (t.closed ? [...t.points, t.points[0]] : t.points).map((s) => S.transformPoint(e, s));
237
+ return { points: o, ages: o.map((s, a) => 1 - a / (o.length - 1)) };
222
238
  }
223
- function rt(t, e, i, n) {
224
- if (!n.valuesAt) return null;
225
- const s = n.time ?? 0, a = A(i.get(`${e.id}/${t.id}`)?.get("length")) ?? t.length, r = U(
226
- (p) => W(Z(e, t.follow, p === s ? i : n.valuesAt(p))),
239
+ function ht(t, e, n, o) {
240
+ if (!o.valuesAt) return null;
241
+ const s = o.time ?? 0, a = P(n.get(`${e.id}/${t.id}`)?.get("length")) ?? t.length, r = G(
242
+ (f) => N(B(e, t.follow, f === s ? n : o.valuesAt(f))),
227
243
  s,
228
- { length: a, samples: t.samples ?? 32, period: t.period }
244
+ { length: a, samples: t.samples ?? 32, period: t.period ?? o.period }
229
245
  );
230
- return r.length >= 2 ? { points: r.map((p) => p.at), ages: r.map((p) => p.age) } : null;
246
+ return r.length >= 2 ? { points: r.map((f) => f.at), ages: r.map((f) => f.age) } : null;
231
247
  }
232
- function Z(t, e, i) {
233
- const n = t.objects.find((a) => a.id === e);
234
- if (!n) return I.identity();
235
- const s = V(n, i.get(`${t.id}/${e}`) ?? L);
236
- return n.parent ? I.multiply(Z(t, n.parent, i), s) : s;
248
+ function B(t, e, n) {
249
+ const o = t.objects.find((a) => a.id === e);
250
+ if (!o) return S.identity();
251
+ const s = X(o, n.get(`${t.id}/${e}`) ?? Q);
252
+ return o.parent ? S.multiply(B(t, o.parent, n), s) : s;
237
253
  }
238
- function H(t, e, i, n, s, a, r) {
239
- const p = t.positions.length / 3, f = [], k = [];
240
- for (let h = 0; h < p; h++) {
241
- const P = I.transformPoint(e, [t.positions[h * 3], t.positions[h * 3 + 1], t.positions[h * 3 + 2]]);
242
- f.push(P), k.push(I.transformPoint(n.view, P));
254
+ function _(t, e, n, o, s, a, r) {
255
+ const f = t.positions.length / 3, l = [], m = [];
256
+ for (let c = 0; c < f; c++) {
257
+ const k = S.transformPoint(e, [t.positions[c * 3], t.positions[c * 3 + 1], t.positions[c * 3 + 2]]);
258
+ l.push(k), m.push(S.transformPoint(o.view, k));
243
259
  }
244
- const y = t.indices.length / 3, M = [], E = [];
245
- for (let h = 0; h < y; h++) {
246
- const [P, o, c] = [0, 1, 2].map((w) => f[t.indices[h * 3 + w]]), b = u.normalize(u.cross(u.subtract(o, P), u.subtract(c, P)));
247
- M.push(b);
248
- const l = n.orthographic ? u.scale(n.forward, -1) : u.subtract(n.position, P);
249
- E.push(u.dot(b, l) > 0);
260
+ const A = t.indices.length / 3, y = [], T = [];
261
+ for (let c = 0; c < A; c++) {
262
+ const [k, C, i] = [0, 1, 2].map((g) => l[t.indices[c * 3 + g]]), p = w.normalize(w.cross(w.subtract(C, k), w.subtract(i, k)));
263
+ y.push(p);
264
+ const h = o.orthographic ? w.scale(o.forward, -1) : w.subtract(o.position, k);
265
+ T.push(w.dot(p, h) > 0);
250
266
  }
251
- const C = (h) => -k[h][2] >= n.near, d = [];
252
- for (let h = 0; h < y; h++) {
253
- const P = E[h];
254
- if (!P && !a.doubleSided) continue;
255
- const o = [t.indices[h * 3], t.indices[h * 3 + 1], t.indices[h * 3 + 2]], c = o.map((g) => k[g]);
256
- if (c.every((g) => -g[2] > n.far)) continue;
257
- const b = ot(c, n.near);
258
- if (b.length < 3) continue;
259
- const l = P ? 1 : -1, w = u.scale(M[h], l), m = o.map((g) => u.scale(nt(i, t.normals[g * 3], t.normals[g * 3 + 1], t.normals[g * 3 + 2]), l)), O = u.scale(u.add(u.add(f[o[0]], f[o[1]]), f[o[2]]), 1 / 3), S = -(c[0][2] + c[1][2] + c[2][2]) / 3, D = [];
260
- if (a.outline && P)
261
- for (const g of t.faceEdges[h]) {
262
- const T = g.across, v = T === -1 || !E[T], J = a.creases !== !1 && !v && h < T && u.dot(M[h], M[T]) < tt;
263
- (v || J) && C(g.a) && C(g.b) && D.push([s(k[g.a]), s(k[g.b])]);
267
+ const $ = (c) => -m[c][2] >= o.near, d = [];
268
+ for (let c = 0; c < A; c++) {
269
+ const k = T[c];
270
+ if (!k && !a.doubleSided) continue;
271
+ const C = [t.indices[c * 3], t.indices[c * 3 + 1], t.indices[c * 3 + 2]], i = C.map((u) => m[u]);
272
+ if (i.every((u) => -u[2] > o.far)) continue;
273
+ const p = rt(i, o.near);
274
+ if (p.length < 3) continue;
275
+ const h = k ? 1 : -1, g = w.scale(y[c], h), M = C.map((u) => w.scale(st(n, t.normals[u * 3], t.normals[u * 3 + 1], t.normals[u * 3 + 2]), h)), b = w.scale(w.add(w.add(l[C[0]], l[C[1]]), l[C[2]]), 1 / 3), E = -(i[0][2] + i[1][2] + i[2][2]) / 3, D = [];
276
+ if (r.ink && k)
277
+ for (const u of t.faceEdges[c]) {
278
+ const v = u.across, W = v === -1 || !T[v], K = a.creases !== !1 && !W && c < v && w.dot(y[c], y[v]) < ot;
279
+ (W || K) && $(u.a) && $(u.b) && D.push([s(m[u.a]), s(m[u.b])]);
264
280
  }
265
- const $ = b.map(s);
266
- for (let g = 1; g + 1 < $.length; g++)
281
+ const O = r.opacity * lt(r.nearFade, E);
282
+ if (O <= 0) continue;
283
+ const I = p.map(s);
284
+ for (let u = 1; u + 1 < I.length; u++)
267
285
  d.push({
268
286
  objectId: r.objectId,
269
287
  objectIndex: r.objectIndex,
270
288
  layer: r.layer,
271
- face: h,
272
- part: g - 1,
273
- screen: [$[0], $[g], $[g + 1]],
274
- depth: S,
275
- centroid: O,
276
- normal: w,
277
- vertexNormals: m,
289
+ face: c,
290
+ part: u - 1,
291
+ screen: [I[0], I[u], I[u + 1]],
292
+ depth: E,
293
+ centroid: b,
294
+ normal: g,
295
+ vertexNormals: M,
278
296
  material: a,
279
- color: r.color,
280
- opacity: r.opacity,
281
- outline: g === 1 ? D : []
297
+ color: r.color ?? t.faceColors?.[c],
298
+ opacity: O,
299
+ outline: u === 1 ? D : [],
300
+ ink: r.ink
282
301
  });
283
302
  }
284
303
  return d;
285
304
  }
286
- class ft {
305
+ class mt {
287
306
  ctx;
288
307
  constructor(e) {
289
308
  this.ctx = e;
290
309
  }
291
310
  render(e) {
292
- B(this.ctx, e);
311
+ J(this.ctx, e);
293
312
  }
294
313
  }
295
- function B(t, e) {
314
+ function J(t, e) {
296
315
  t.save(), e.background && e.background !== "transparent" && (t.fillStyle = e.background, t.fillRect(0, 0, e.width, e.height)), t.lineJoin = "round", t.lineCap = "round";
297
- let i = 0;
298
- const n = (r, p) => {
299
- for (; i < e.drawables.length; ) {
300
- const f = e.drawables[i];
301
- if (f.layer > r || f.layer === r && f.depth <= p) break;
302
- t.save(), f.draw(t, e), t.restore(), i++;
316
+ let n = 0;
317
+ const o = (r, f) => {
318
+ for (; n < e.drawables.length; ) {
319
+ const l = e.drawables[n];
320
+ if (l.layer > r || l.layer === r && l.depth <= f) break;
321
+ t.save(), l.draw(t, e), t.restore(), n++;
303
322
  }
304
323
  };
305
324
  let s = [];
306
325
  const a = (r) => {
307
326
  if (s.length === 0) return;
308
- const p = [];
309
- for (const f of s)
310
- r && r.objectId === f.objectId && r.layer === f.layer && f.depth - r.depth <= at * f.depth ? p.push(f) : lt(t, f.triangle);
311
- s = p;
327
+ const f = [];
328
+ for (const l of s)
329
+ r && r.objectId === l.objectId && r.layer === l.layer && l.depth - r.depth <= ft * l.depth ? f.push(l) : pt(t, l.triangle, e);
330
+ s = f;
312
331
  };
313
332
  for (const r of e.triangles) {
314
- a(r), n(r.layer, r.depth);
315
- const { color: p, alpha: f } = q(r, e.lights, e.camera, e.fog), [k, y, M] = r.screen;
316
- t.globalAlpha = f, t.beginPath(), t.moveTo(k.x, k.y), t.lineTo(y.x, y.y), t.lineTo(M.x, M.y), t.closePath(), t.fillStyle = p, t.fill(), f >= 1 && (t.strokeStyle = p, t.lineWidth = 0.75, t.stroke()), r.material.outline && r.outline.length > 0 && s.push({ objectId: r.objectId, layer: r.layer, depth: r.depth, triangle: r });
333
+ a(r), o(r.layer, r.depth);
334
+ const { color: f, alpha: l } = j(r, e.lights, e.camera, e.fog), [m, A, y] = r.screen;
335
+ t.globalAlpha = l, t.beginPath(), t.moveTo(m.x, m.y), t.lineTo(A.x, A.y), t.lineTo(y.x, y.y), t.closePath(), t.fillStyle = f, t.fill(), l >= 1 && (t.strokeStyle = f, t.lineWidth = 0.75, t.stroke()), r.ink && r.outline.length > 0 && s.push({ objectId: r.objectId, layer: r.layer, depth: r.depth, triangle: r });
317
336
  }
318
- a(), n(1 / 0, -1 / 0), t.restore();
337
+ a(), o(1 / 0, -1 / 0), t.restore();
319
338
  }
320
- const at = 0.04;
321
- function lt(t, e) {
322
- const i = e.material.outline;
323
- t.globalAlpha = e.opacity, t.strokeStyle = i.color, t.lineWidth = i.width, t.beginPath();
324
- for (const [n, s] of e.outline)
325
- t.moveTo(n.x, n.y), t.lineTo(s.x, s.y);
339
+ const ft = 0.04;
340
+ function pt(t, e, n) {
341
+ const o = e.ink;
342
+ t.globalAlpha = e.opacity, t.strokeStyle = tt(o.color, n.fog, w.distance(e.centroid, n.camera.position)), t.lineWidth = o.width, t.beginPath();
343
+ for (const [s, a] of e.outline)
344
+ t.moveTo(s.x, s.y), t.lineTo(a.x, a.y);
326
345
  t.stroke();
327
346
  }
328
- class gt {
347
+ class vt {
329
348
  renderer;
330
349
  width;
331
350
  height;
@@ -333,8 +352,8 @@ class gt {
333
352
  values = /* @__PURE__ */ new Map();
334
353
  valuesAt;
335
354
  /** `valuesAt`: the values at another time (`(t) => timeline.getStateAtTime(t).values`), for trails */
336
- constructor(e, i) {
337
- this.renderer = e, this.width = i.width, this.height = i.height, this.valuesAt = i.valuesAt;
355
+ constructor(e, n) {
356
+ this.renderer = e, this.width = n.width, this.height = n.height, this.valuesAt = n.valuesAt;
338
357
  }
339
358
  /** Add a scene; its tracks address `<scene.id>/<objectId>`. */
340
359
  registerScene(e) {
@@ -343,8 +362,8 @@ class gt {
343
362
  unregisterScene(e) {
344
363
  this.scenes.delete(e);
345
364
  }
346
- resize(e, i) {
347
- this.width = e, this.height = i;
365
+ resize(e, n) {
366
+ this.width = e, this.height = n;
348
367
  }
349
368
  applyState(e) {
350
369
  this.values = e.values, this.time = e.currentTime ?? this.time;
@@ -352,41 +371,68 @@ class gt {
352
371
  time = 0;
353
372
  render() {
354
373
  for (const e of this.scenes.values())
355
- this.renderer.render(X(e, this.values, { width: this.width, height: this.height, time: this.time, valuesAt: this.valuesAt }));
374
+ this.renderer.render(Z(e, this.values, { width: this.width, height: this.height, time: this.time, valuesAt: this.valuesAt }));
356
375
  }
357
376
  }
358
- function ut(t, e, i, n) {
359
- const s = n.stateAt, a = n.valuesAt ?? (s && ((r) => s(r).values));
360
- B(t, X(e, i ?? /* @__PURE__ */ new Map(), { width: n.width, height: n.height, time: n.time, valuesAt: a }));
377
+ function kt(t, e, n, o) {
378
+ const s = o.stateAt, a = o.valuesAt ?? (s && ((r) => s(r).values));
379
+ J(t, Z(e, n ?? /* @__PURE__ */ new Map(), { width: o.width, height: o.height, time: o.time, period: o.period, valuesAt: a }));
380
+ }
381
+ function Mt(t = {}) {
382
+ const e = t.id ?? "penrose", n = t.length ?? 4, o = t.thickness ?? 0.8, s = t.material ?? "penrose", [a, r, f] = t.position ?? [0, 0, 0], l = o / 2, m = (d, c, k) => ({
383
+ id: `${e}-${d}`,
384
+ kind: "mesh",
385
+ geometry: { type: "box", size: [k[0] - c[0], k[1] - c[1], k[2] - c[2]] },
386
+ material: s,
387
+ position: [a + (c[0] + k[0]) / 2, r + (c[1] + k[1]) / 2, f + (c[2] + k[2]) / 2]
388
+ }), A = [
389
+ m("x", [-l, -l, -l], [n - l, l, l]),
390
+ m("y", [n - l, -l, -l], [n + l, n - l, l]),
391
+ m("z", [n - l, n - l, -l], [n + l, n + l, n])
392
+ ], y = [a + 2 * n / 3, r + n / 3, f + n / 3], T = (t.distance ?? 20) / Math.sqrt(3), $ = {
393
+ id: `${e}-camera`,
394
+ kind: "camera",
395
+ projection: "orthographic",
396
+ height: n * 1.6,
397
+ near: 0.1,
398
+ far: (t.distance ?? 20) * 3,
399
+ position: [y[0] + T, y[1] + T, y[2] + T],
400
+ lookAt: y
401
+ };
402
+ return { objects: A, camera: $ };
361
403
  }
362
404
  export {
363
- ft as Canvas2DRenderer,
364
- mt as MeshBuilder,
365
- gt as Scene3DAdapter,
366
- vt as boxMesh,
367
- Mt as coneMesh,
368
- bt as cylinderMesh,
369
- pt as dollyPosition,
370
- B as drawResolvedScene,
371
- ut as drawScene3D,
372
- kt as extrudeMesh,
373
- G as fogAmount,
374
- At as geometryMesh,
375
- Wt as lightAt,
376
- It as loadScene3D,
377
- x as lookAtView,
378
- Pt as meshEdges,
379
- dt as orbitPosition,
380
- z as parseColor,
381
- St as planeMesh,
382
- Tt as pointInPolygon,
383
- Et as prepareMesh,
384
- Y as projectionMatrix,
385
- X as resolveScene3D,
386
- q as shadeTriangle,
387
- Ct as signedArea,
388
- Dt as sphereMesh,
389
- Ot as torusMesh,
390
- $t as triangulate,
391
- Nt as validateScene3D
405
+ mt as Canvas2DRenderer,
406
+ It as MeshBuilder,
407
+ vt as Scene3DAdapter,
408
+ Pt as boxMesh,
409
+ St as coneMesh,
410
+ Tt as cylinderMesh,
411
+ wt as dollyPosition,
412
+ J as drawResolvedScene,
413
+ kt as drawScene3D,
414
+ Ct as extrudeMesh,
415
+ x as fogAmount,
416
+ Et as geometryMesh,
417
+ tt as inkColor,
418
+ Ht as lightAt,
419
+ $t as loadScene3D,
420
+ et as lookAtView,
421
+ Dt as meshEdges,
422
+ yt as orbitPosition,
423
+ R as parseColor,
424
+ Mt as penroseTriangle3D,
425
+ Ot as planeMesh,
426
+ Ft as pointInPolygon,
427
+ zt as prepareMesh,
428
+ V as projectionMatrix,
429
+ Nt as rawMesh,
430
+ Z as resolveScene3D,
431
+ H as rollView,
432
+ j as shadeTriangle,
433
+ Wt as signedArea,
434
+ Rt as sphereMesh,
435
+ Vt as torusMesh,
436
+ Lt as triangulate,
437
+ Yt as validateScene3D
392
438
  };