@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
package/lib/addons/scene-3d.js
CHANGED
|
@@ -1,331 +1,350 @@
|
|
|
1
|
-
import { M as
|
|
2
|
-
import { vec3 as
|
|
3
|
-
import { p as
|
|
4
|
-
import { l as
|
|
5
|
-
function
|
|
6
|
-
const
|
|
7
|
-
return
|
|
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
|
|
10
|
-
|
|
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
|
|
14
|
-
const
|
|
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 -
|
|
17
|
-
return
|
|
19
|
+
const a = Math.max(1e-3, s - n);
|
|
20
|
+
return w.add(e, w.scale(o, a / s));
|
|
18
21
|
}
|
|
19
|
-
function
|
|
20
|
-
if (t.projection === "perspective") return
|
|
21
|
-
const
|
|
22
|
-
return
|
|
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
|
|
25
|
-
const { camera: s } =
|
|
26
|
-
let
|
|
27
|
-
const
|
|
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
|
|
30
|
-
|
|
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
|
-
|
|
33
|
-
const
|
|
34
|
-
for (const d of
|
|
35
|
+
y.length > 0 && A.push(y);
|
|
36
|
+
const $ = [];
|
|
37
|
+
for (const d of A) {
|
|
35
38
|
if (d.length < 2) continue;
|
|
36
|
-
const
|
|
37
|
-
for (let
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
40
|
-
let
|
|
41
|
-
const
|
|
42
|
-
let D =
|
|
43
|
-
if (
|
|
44
|
-
if (
|
|
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 =
|
|
47
|
-
D = [
|
|
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 (
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
depth:
|
|
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
|
-
|
|
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
|
|
62
|
+
return $;
|
|
60
63
|
}
|
|
61
|
-
function
|
|
64
|
+
function L(t, e, n, o, s) {
|
|
62
65
|
const a = (-s - t[2]) / (e[2] - t[2]);
|
|
63
|
-
return { view:
|
|
66
|
+
return { view: w.lerp(t, e, a), age: n + (o - n) * a };
|
|
64
67
|
}
|
|
65
|
-
const
|
|
66
|
-
function
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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 =
|
|
74
|
-
if (a) s =
|
|
75
|
-
else if (r.some((
|
|
76
|
-
const
|
|
77
|
-
s =
|
|
78
|
-
} else t.quaternion ? s =
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
|
87
|
+
return S.compose(o, s, m);
|
|
85
88
|
}
|
|
86
|
-
const
|
|
87
|
-
function
|
|
88
|
-
const s =
|
|
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:
|
|
92
|
-
projection:
|
|
94
|
+
view: f,
|
|
95
|
+
projection: l,
|
|
93
96
|
position: s,
|
|
94
|
-
forward:
|
|
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
|
|
101
|
-
return
|
|
103
|
+
function Y(t) {
|
|
104
|
+
return S.transpose(S.invert(t) ?? S.identity());
|
|
102
105
|
}
|
|
103
|
-
function
|
|
104
|
-
return
|
|
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
|
|
107
|
-
const
|
|
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 (
|
|
111
|
-
const
|
|
112
|
-
|
|
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
|
|
118
|
+
return o;
|
|
116
119
|
}
|
|
117
|
-
function
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
|
126
|
-
const
|
|
127
|
-
return { x: (
|
|
128
|
-
},
|
|
129
|
-
for (const
|
|
130
|
-
if (
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
id:
|
|
134
|
-
light:
|
|
135
|
-
color: typeof
|
|
136
|
-
intensity:
|
|
137
|
-
position:
|
|
138
|
-
direction:
|
|
139
|
-
range:
|
|
140
|
-
angle:
|
|
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
|
|
144
|
-
|
|
145
|
-
if (
|
|
146
|
-
const
|
|
147
|
-
if (!
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
if (!
|
|
161
|
-
const
|
|
162
|
-
object:
|
|
163
|
-
prepared: t.prepared.get(
|
|
164
|
-
values: s(
|
|
165
|
-
world:
|
|
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:
|
|
168
|
-
fog:
|
|
169
|
-
width:
|
|
170
|
-
height:
|
|
171
|
-
toScreen:
|
|
181
|
+
lights: $,
|
|
182
|
+
fog: o.fog,
|
|
183
|
+
width: n.width,
|
|
184
|
+
height: n.height,
|
|
185
|
+
toScreen: T
|
|
172
186
|
});
|
|
173
|
-
if (!
|
|
174
|
-
const
|
|
175
|
-
for (const
|
|
176
|
-
for (const
|
|
177
|
-
|
|
178
|
-
objectId:
|
|
179
|
-
objectIndex:
|
|
180
|
-
layer:
|
|
181
|
-
opacity:
|
|
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
|
|
185
|
-
return
|
|
186
|
-
if (
|
|
187
|
-
const
|
|
188
|
-
if (!
|
|
189
|
-
const
|
|
190
|
-
if (
|
|
191
|
-
const
|
|
192
|
-
for (const
|
|
193
|
-
}),
|
|
194
|
-
id:
|
|
195
|
-
width:
|
|
196
|
-
height:
|
|
197
|
-
background:
|
|
198
|
-
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:
|
|
201
|
-
worlds:
|
|
202
|
-
triangles:
|
|
203
|
-
drawables:
|
|
204
|
-
meshes:
|
|
205
|
-
time:
|
|
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
|
|
209
|
-
const
|
|
224
|
+
function ct(t, e) {
|
|
225
|
+
const n = e.get("color"), o = t.kind === "trail";
|
|
210
226
|
return {
|
|
211
|
-
color: typeof
|
|
212
|
-
width:
|
|
213
|
-
taper: t.taper ?? (
|
|
214
|
-
fade: t.fade ?? (
|
|
215
|
-
opacity: (
|
|
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
|
|
220
|
-
const
|
|
221
|
-
return { points:
|
|
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
|
|
224
|
-
if (!
|
|
225
|
-
const s =
|
|
226
|
-
(
|
|
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((
|
|
246
|
+
return r.length >= 2 ? { points: r.map((f) => f.at), ages: r.map((f) => f.age) } : null;
|
|
231
247
|
}
|
|
232
|
-
function
|
|
233
|
-
const
|
|
234
|
-
if (!
|
|
235
|
-
const s =
|
|
236
|
-
return
|
|
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
|
|
239
|
-
const
|
|
240
|
-
for (let
|
|
241
|
-
const
|
|
242
|
-
|
|
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
|
|
245
|
-
for (let
|
|
246
|
-
const [
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
|
|
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
|
|
252
|
-
for (let
|
|
253
|
-
const
|
|
254
|
-
if (!
|
|
255
|
-
const
|
|
256
|
-
if (
|
|
257
|
-
const
|
|
258
|
-
if (
|
|
259
|
-
const
|
|
260
|
-
if (
|
|
261
|
-
for (const
|
|
262
|
-
const
|
|
263
|
-
(
|
|
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
|
|
266
|
-
|
|
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:
|
|
272
|
-
part:
|
|
273
|
-
screen: [
|
|
274
|
-
depth:
|
|
275
|
-
centroid:
|
|
276
|
-
normal:
|
|
277
|
-
vertexNormals:
|
|
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:
|
|
281
|
-
outline:
|
|
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
|
|
305
|
+
class mt {
|
|
287
306
|
ctx;
|
|
288
307
|
constructor(e) {
|
|
289
308
|
this.ctx = e;
|
|
290
309
|
}
|
|
291
310
|
render(e) {
|
|
292
|
-
|
|
311
|
+
J(this.ctx, e);
|
|
293
312
|
}
|
|
294
313
|
}
|
|
295
|
-
function
|
|
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
|
|
298
|
-
const
|
|
299
|
-
for (;
|
|
300
|
-
const
|
|
301
|
-
if (
|
|
302
|
-
t.save(),
|
|
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
|
|
309
|
-
for (const
|
|
310
|
-
r && r.objectId ===
|
|
311
|
-
s =
|
|
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),
|
|
315
|
-
const { color:
|
|
316
|
-
t.globalAlpha =
|
|
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(),
|
|
337
|
+
a(), o(1 / 0, -1 / 0), t.restore();
|
|
319
338
|
}
|
|
320
|
-
const
|
|
321
|
-
function
|
|
322
|
-
const
|
|
323
|
-
t.globalAlpha = e.opacity, t.strokeStyle =
|
|
324
|
-
for (const [
|
|
325
|
-
t.moveTo(
|
|
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
|
|
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,
|
|
337
|
-
this.renderer = e, this.width =
|
|
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,
|
|
347
|
-
this.width = e, this.height =
|
|
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(
|
|
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
|
|
359
|
-
const s =
|
|
360
|
-
|
|
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
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
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
|
};
|