@algorisys/tinyfly 0.101.0 → 0.102.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/bin/tinyfly.mjs +9 -3
- package/docs/editor-guide.md +1 -1
- package/docs/examples.md +1 -1
- package/docs/getting-started.md +1 -1
- package/docs/gsap-compat.md +1 -1
- package/docs/llm-guide.md +8 -2
- package/docs/maps.md +2 -2
- package/docs/scene-3d.md +117 -5
- package/docs/teaching.md +1 -1
- package/docs/video-rendering.md +44 -1
- package/lib/addons/adapters.js +168 -123
- package/lib/addons/characters.js +4663 -4566
- package/lib/addons/scene-3d-webgl.js +30 -30
- package/lib/addons/scene-3d.js +650 -341
- package/lib/browser/tinyfly-scene-3d-webgl.iife.js +2 -2
- package/lib/browser/tinyfly-scene-3d.iife.js +2 -2
- package/lib/browser/tinyfly.iife.js +13 -13
- package/lib/browser/tinyfly.js +4105 -3973
- package/lib/browser/tinyfly.umd.js +13 -13
- package/lib/engine/tinyfly-engine.js +1207 -1172
- package/lib/engine/tinyfly-engine.umd.cjs +2 -2
- package/lib/headless/headless.js +150 -6
- package/lib/types/adapters/canvas/framing.d.ts +27 -0
- package/lib/types/adapters/canvas/index.d.ts +1 -0
- package/lib/types/characters/character-script-3d.d.ts +21 -1
- package/lib/types/characters/index.d.ts +2 -1
- package/lib/types/characters/staging-3d.d.ts +56 -0
- package/lib/types/engine/authoring/framing.d.ts +48 -0
- package/lib/types/engine/authoring/index.d.ts +1 -0
- package/lib/types/headless/audio-mix.d.ts +40 -0
- package/lib/types/headless/ffmpeg-args.d.ts +2 -0
- package/lib/types/headless/frame-renderer.d.ts +7 -1
- package/lib/types/headless/index.d.ts +1 -0
- package/lib/types/headless/node-audio.d.ts +19 -0
- package/lib/types/headless/node-video.d.ts +2 -0
- package/lib/types/headless/video-scene.d.ts +12 -0
- package/lib/types/scene-3d/index.d.ts +3 -0
- package/lib/types/scene-3d/lighting.d.ts +58 -0
- package/lib/types/scene-3d/resolve-scene.d.ts +5 -1
- package/lib/types/scene-3d/scene-3d-adapter.d.ts +2 -0
- package/lib/types/scene-3d/scene-types.d.ts +14 -2
- package/lib/types/scene-3d/shots.d.ts +162 -0
- package/lib/types/scene-3d/software-renderer.d.ts +40 -0
- package/llms-full.txt +177 -16
- package/llms.txt +29 -29
- package/package.json +1 -1
- package/skills/tinyfly/SKILL.md +4 -1
package/lib/addons/scene-3d.js
CHANGED
|
@@ -1,350 +1,484 @@
|
|
|
1
|
-
import { M as
|
|
2
|
-
import { vec3 as
|
|
3
|
-
import { p as
|
|
4
|
-
import { l as
|
|
5
|
-
function
|
|
6
|
-
const
|
|
7
|
-
return
|
|
8
|
-
}
|
|
9
|
-
function
|
|
10
|
-
return
|
|
11
|
-
}
|
|
12
|
-
function
|
|
13
|
-
const
|
|
14
|
-
return [t[0] +
|
|
15
|
-
}
|
|
16
|
-
function
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
const a = Math.max(1e-3,
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
function
|
|
23
|
-
if (t.projection === "perspective") return
|
|
24
|
-
const
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
function
|
|
28
|
-
const { camera:
|
|
29
|
-
let
|
|
30
|
-
const
|
|
31
|
-
for (let
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
1
|
+
import { M as sn, b as rn, c as an, a as cn, e as ln, g as dn, l as hn, m as fn, p as un, d as gn, f as pn, r as yn, s as mn, h as kn, t as wn, i as Mn, v as vn } from "./load-scene-oWNsYYC1.js";
|
|
2
|
+
import { vec3 as A, mat4 as P, quat as F, ribbon as dt, ribbonHeadCap as ht, trailSamples as ft, getEasingFunction as ut, loopNoise as gt } from "@algorisys/tinyfly";
|
|
3
|
+
import { p as N, f as pt, s as q, i as j } from "./shading-0lPgnXmD.js";
|
|
4
|
+
import { l as xn } from "./shading-0lPgnXmD.js";
|
|
5
|
+
function yt(t, n, o = {}) {
|
|
6
|
+
const e = A.normalize(A.subtract(n, t)), i = o.up ?? (Math.abs(e[1]) > 0.9999 ? [0, 0, -1] : [0, 1, 0]);
|
|
7
|
+
return tt(P.lookAt(t, n, i), o.roll ?? 0);
|
|
8
|
+
}
|
|
9
|
+
function tt(t, n) {
|
|
10
|
+
return n ? P.multiply(P.fromQuat(F.fromAxisAngle([0, 0, 1], -n)), t) : t;
|
|
11
|
+
}
|
|
12
|
+
function L(t, n, o, e) {
|
|
13
|
+
const i = n * Math.PI / 180, a = o * Math.PI / 180;
|
|
14
|
+
return [t[0] + e * Math.cos(a) * Math.sin(i), t[1] + e * Math.sin(a), t[2] + e * Math.cos(a) * Math.cos(i)];
|
|
15
|
+
}
|
|
16
|
+
function Rt(t, n, o) {
|
|
17
|
+
const e = A.subtract(t, n), i = A.length(e);
|
|
18
|
+
if (i === 0) return t;
|
|
19
|
+
const a = Math.max(1e-3, i - o);
|
|
20
|
+
return A.add(n, A.scale(e, a / i));
|
|
21
|
+
}
|
|
22
|
+
function J(t, n) {
|
|
23
|
+
if (t.projection === "perspective") return P.perspective(t.fov, n, t.near, t.far);
|
|
24
|
+
const o = t.height / 2;
|
|
25
|
+
return P.orthographic(-o * n, o * n, -o, o, t.near, t.far);
|
|
26
|
+
}
|
|
27
|
+
function mt(t, n, o, e) {
|
|
28
|
+
const { camera: i } = e, a = i.near, r = t.map((p) => P.transformPoint(i.view, p)), l = i.projection[5] * e.height / 2, c = (p, h) => o.width * (1 - o.taper * p) * l / (i.orthographic ? 1 : Math.max(h, a)), u = N(o.color), g = [];
|
|
29
|
+
let m = [];
|
|
30
|
+
const v = (p) => -p[2] >= a;
|
|
31
|
+
for (let p = 0; p < r.length; p++) {
|
|
32
|
+
const h = r[p];
|
|
33
|
+
v(h) ? (m.length === 0 && p > 0 && !v(r[p - 1]) && m.push(K(r[p - 1], h, n[p - 1], n[p], a)), m.push({ view: h, age: n[p] })) : m.length > 0 && (m.push(K(r[p - 1], h, n[p - 1], n[p], a)), g.push(m), m = []);
|
|
34
|
+
}
|
|
35
|
+
m.length > 0 && g.push(m);
|
|
36
36
|
const $ = [];
|
|
37
|
-
for (const
|
|
38
|
-
if (
|
|
39
|
-
const
|
|
40
|
-
for (let
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
let
|
|
44
|
-
const
|
|
45
|
-
let
|
|
46
|
-
if (
|
|
47
|
-
if (
|
|
37
|
+
for (const p of g) {
|
|
38
|
+
if (p.length < 2) continue;
|
|
39
|
+
const h = p.map((f) => -f.view[2]), b = p.map((f) => e.toScreen(f.view)).map((f, w) => ({ x: f.x, y: f.y, width: c(p[w].age, h[w]) })), s = dt(b), d = p[p.length - 1].age === 0 ? ht(b) : null;
|
|
40
|
+
for (let f = 0; f + 1 < p.length; f++) {
|
|
41
|
+
const w = (h[f] + h[f + 1]) / 2;
|
|
42
|
+
if (w > i.far) continue;
|
|
43
|
+
let x = o.opacity * (1 - o.fade * ((p[f].age + p[f + 1].age) / 2));
|
|
44
|
+
const k = A.lerp(p[f].view, p[f + 1].view, 0.5), I = pt(e.fog, A.length(k));
|
|
45
|
+
let T = u;
|
|
46
|
+
if (e.fog && I > 0)
|
|
47
|
+
if (o.additive) x *= 1 - I;
|
|
48
48
|
else {
|
|
49
|
-
const
|
|
50
|
-
|
|
49
|
+
const y = N(e.fog.color);
|
|
50
|
+
T = [u[0] + (y[0] - u[0]) * I, u[1] + (y[1] - u[1]) * I, u[2] + (y[2] - u[2]) * I];
|
|
51
51
|
}
|
|
52
|
-
if (
|
|
53
|
-
const
|
|
52
|
+
if (x <= 0) continue;
|
|
53
|
+
const D = `rgb(${T.map((y) => Math.round(Math.min(1, Math.max(0, y)) * 255)).join(", ")})`, S = [s.left[f], s.left[f + 1], s.right[f + 1], s.right[f]], E = f + 2 === p.length ? d : null;
|
|
54
54
|
$.push({
|
|
55
|
-
depth:
|
|
56
|
-
draw(
|
|
57
|
-
|
|
55
|
+
depth: w,
|
|
56
|
+
draw(y) {
|
|
57
|
+
o.additive && (y.globalCompositeOperation = "lighter"), y.globalAlpha = Math.min(1, x), y.fillStyle = D, y.beginPath(), y.moveTo(S[0].x, S[0].y), y.lineTo(S[1].x, S[1].y), E && y.arc(E.x, E.y, E.radius, E.start, E.start - Math.PI, !0), y.lineTo(S[2].x, S[2].y), y.lineTo(S[3].x, S[3].y), y.closePath(), y.fill(), !o.additive && x >= 1 && (y.strokeStyle = D, y.lineWidth = 0.75, y.stroke());
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
return $;
|
|
63
63
|
}
|
|
64
|
-
function
|
|
65
|
-
const a = (-
|
|
66
|
-
return { view:
|
|
64
|
+
function K(t, n, o, e, i) {
|
|
65
|
+
const a = (-i - t[2]) / (n[2] - t[2]);
|
|
66
|
+
return { view: A.lerp(t, n, a), age: o + (e - o) * a };
|
|
67
67
|
}
|
|
68
|
-
const
|
|
69
|
-
function
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
const kt = Math.cos(30 * Math.PI / 180), nt = /* @__PURE__ */ new Map(), C = (t) => typeof t == "number" ? t : void 0, W = (t, n) => Array.isArray(t) && t.length === n ? t : void 0;
|
|
69
|
+
function ot(t, n) {
|
|
70
|
+
const o = t.position ?? [0, 0, 0], e = W(n.get("position"), 3) ?? [
|
|
71
|
+
C(n.get("x")) ?? o[0],
|
|
72
|
+
C(n.get("y")) ?? o[1],
|
|
73
|
+
C(n.get("z")) ?? o[2]
|
|
74
74
|
];
|
|
75
|
-
let
|
|
76
|
-
const a =
|
|
77
|
-
if (a)
|
|
78
|
-
else if (r.some((
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
} else t.quaternion ?
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
let i;
|
|
76
|
+
const a = W(n.get("quaternion"), 4), r = ["rotateX", "rotateY", "rotateZ"].map((g) => C(n.get(g)));
|
|
77
|
+
if (a) i = F.normalize(a);
|
|
78
|
+
else if (r.some((g) => g !== void 0)) {
|
|
79
|
+
const g = t.rotation ?? [0, 0, 0];
|
|
80
|
+
i = F.fromEuler(r[0] ?? g[0], r[1] ?? g[1], r[2] ?? g[2]);
|
|
81
|
+
} else t.quaternion ? i = F.normalize(t.quaternion) : i = t.rotation ? F.fromEuler(...t.rotation) : F.identity();
|
|
82
|
+
const l = typeof t.scale == "number" ? [t.scale, t.scale, t.scale] : t.scale ?? [1, 1, 1], c = C(n.get("scale")), u = [
|
|
83
|
+
C(n.get("scaleX")) ?? c ?? l[0],
|
|
84
|
+
C(n.get("scaleY")) ?? c ?? l[1],
|
|
85
|
+
C(n.get("scaleZ")) ?? c ?? l[2]
|
|
86
86
|
];
|
|
87
|
-
return
|
|
87
|
+
return P.compose(e, i, u);
|
|
88
88
|
}
|
|
89
|
-
const
|
|
90
|
-
function
|
|
91
|
-
const
|
|
89
|
+
const Z = (t) => [t[12], t[13], t[14]];
|
|
90
|
+
function wt(t, n, o, e) {
|
|
91
|
+
const i = Z(n), a = W(o.get("lookAt"), 3) ?? t.lookAt, r = C(o.get("roll")) ?? t.roll ?? 0, l = a ? yt(i, a, { up: t.up, roll: r }) : tt(P.invert(n) ?? P.identity(), r), c = t.projection === "perspective" ? J({ ...t, fov: C(o.get("fov")) ?? t.fov }, e) : J({ ...t, height: C(o.get("height")) ?? t.height }, e);
|
|
92
92
|
return {
|
|
93
93
|
id: t.id,
|
|
94
|
-
view:
|
|
95
|
-
projection:
|
|
96
|
-
position:
|
|
97
|
-
forward:
|
|
94
|
+
view: l,
|
|
95
|
+
projection: c,
|
|
96
|
+
position: i,
|
|
97
|
+
forward: A.normalize([-l[2], -l[6], -l[10]]),
|
|
98
98
|
orthographic: t.projection === "orthographic",
|
|
99
99
|
near: t.near,
|
|
100
100
|
far: t.far
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
-
function
|
|
104
|
-
return
|
|
103
|
+
function Q(t) {
|
|
104
|
+
return P.transpose(P.invert(t) ?? P.identity());
|
|
105
105
|
}
|
|
106
|
-
function
|
|
107
|
-
return
|
|
106
|
+
function Mt(t, n, o, e) {
|
|
107
|
+
return A.normalize([t[0] * n + t[4] * o + t[8] * e, t[1] * n + t[5] * o + t[9] * e, t[2] * n + t[6] * o + t[10] * e]);
|
|
108
108
|
}
|
|
109
|
-
function
|
|
110
|
-
const
|
|
111
|
-
for (let
|
|
112
|
-
const a = t[
|
|
113
|
-
if (
|
|
114
|
-
const
|
|
115
|
-
|
|
109
|
+
function vt(t, n) {
|
|
110
|
+
const o = (i) => -i[2] >= n, e = [];
|
|
111
|
+
for (let i = 0; i < t.length; i++) {
|
|
112
|
+
const a = t[i], r = t[(i + 1) % t.length];
|
|
113
|
+
if (o(a) && e.push(a), o(a) !== o(r)) {
|
|
114
|
+
const l = (-n - a[2]) / (r[2] - a[2]);
|
|
115
|
+
e.push(A.lerp(a, r, l));
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
return
|
|
118
|
+
return e;
|
|
119
|
+
}
|
|
120
|
+
function bt(t, n, o, e = 16) {
|
|
121
|
+
const i = [t[0], t[1], t[2]], a = [0, 1, 0], r = [];
|
|
122
|
+
for (let c = 0; c < e; c++) {
|
|
123
|
+
const u = c / e * Math.PI * 2;
|
|
124
|
+
i.push(t[0] + Math.cos(u) * n, t[1], t[2] + Math.sin(u) * o), a.push(0, 1, 0);
|
|
125
|
+
}
|
|
126
|
+
for (let c = 0; c < e; c++) r.push(0, 1 + (c + 1) % e, 1 + c);
|
|
127
|
+
const l = Array.from({ length: e }, () => []);
|
|
128
|
+
return { positions: i, normals: a, indices: r, faceEdges: l };
|
|
119
129
|
}
|
|
120
|
-
function
|
|
121
|
-
const
|
|
122
|
-
return
|
|
130
|
+
function xt(t, n) {
|
|
131
|
+
const o = C(n.get("outlineWidth")) ?? t.outline?.width, e = n.get("outlineColor"), i = (typeof e == "string" ? e : void 0) ?? t.outline?.color ?? "#000000";
|
|
132
|
+
return o !== void 0 && o > 0 ? { width: o, color: i } : void 0;
|
|
123
133
|
}
|
|
124
|
-
function
|
|
125
|
-
return !t || t.to <= t.from ? 1 : Math.min(1, Math.max(0, (
|
|
134
|
+
function At(t, n) {
|
|
135
|
+
return !t || t.to <= t.from ? 1 : Math.min(1, Math.max(0, (n - t.from) / (t.to - t.from)));
|
|
126
136
|
}
|
|
127
|
-
function
|
|
128
|
-
const { scene:
|
|
129
|
-
for (const
|
|
130
|
-
const
|
|
131
|
-
r.set(
|
|
132
|
-
const
|
|
133
|
-
|
|
137
|
+
function et(t, n = /* @__PURE__ */ new Map(), o) {
|
|
138
|
+
const { scene: e } = t, i = (s) => n.get(`${e.id}/${s}`) ?? nt, a = o.nearFade ?? e.nearFade, r = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
|
|
139
|
+
for (const s of e.objects) {
|
|
140
|
+
const d = i(s.id), f = ot(s, d), w = s.parent ? r.get(s.parent) : void 0;
|
|
141
|
+
r.set(s.id, w ? P.multiply(w, f) : f);
|
|
142
|
+
const x = C(d.get("visible")) !== void 0 ? C(d.get("visible")) > 0.5 : s.visible !== !1;
|
|
143
|
+
l.set(s.id, x && (s.parent ? l.get(s.parent) !== !1 : !0));
|
|
134
144
|
}
|
|
135
|
-
const
|
|
136
|
-
const
|
|
137
|
-
return { x: (
|
|
145
|
+
const c = n.get(e.id)?.get("activeCamera"), u = typeof c == "string" && e.objects.some((s) => s.id === c && s.kind === "camera") ? c : e.camera, g = e.objects.find((s) => s.id === u), m = wt(g, r.get(u), i(u), o.width / o.height), v = (s) => {
|
|
146
|
+
const d = P.transformPoint(m.projection, s);
|
|
147
|
+
return { x: (d[0] + 1) / 2 * o.width, y: (1 - d[1]) / 2 * o.height };
|
|
138
148
|
}, $ = [];
|
|
139
|
-
for (const
|
|
140
|
-
if (
|
|
141
|
-
const
|
|
149
|
+
for (const s of e.objects) {
|
|
150
|
+
if (s.kind !== "light" || !l.get(s.id)) continue;
|
|
151
|
+
const d = i(s.id), f = Z(r.get(s.id)), w = W(d.get("target"), 3) ?? s.target ?? [0, 0, 0], x = d.get("color");
|
|
142
152
|
$.push({
|
|
143
|
-
id:
|
|
144
|
-
light:
|
|
145
|
-
color: typeof
|
|
146
|
-
intensity:
|
|
147
|
-
position:
|
|
148
|
-
direction:
|
|
149
|
-
range:
|
|
150
|
-
angle:
|
|
153
|
+
id: s.id,
|
|
154
|
+
light: s.light,
|
|
155
|
+
color: typeof x == "string" ? x : s.color,
|
|
156
|
+
intensity: C(d.get("intensity")) ?? s.intensity,
|
|
157
|
+
position: f,
|
|
158
|
+
direction: A.normalize(A.subtract(w, f)),
|
|
159
|
+
range: s.range,
|
|
160
|
+
angle: s.angle ?? 30
|
|
151
161
|
});
|
|
152
162
|
}
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
if (
|
|
156
|
-
const
|
|
157
|
-
if (!
|
|
158
|
-
const
|
|
159
|
-
if (
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
objectId:
|
|
163
|
-
objectIndex:
|
|
164
|
-
layer:
|
|
165
|
-
color: typeof
|
|
166
|
-
opacity:
|
|
167
|
-
ink:
|
|
163
|
+
const p = [], h = [];
|
|
164
|
+
e.objects.forEach((s, d) => {
|
|
165
|
+
if (s.kind !== "mesh" || !l.get(s.id)) return;
|
|
166
|
+
const f = t.meshes.get(s.id), w = e.materials?.[s.material];
|
|
167
|
+
if (!f || !w) return;
|
|
168
|
+
const x = i(s.id), k = r.get(s.id), I = Q(k), T = x.get("color"), D = (C(x.get("opacity")) ?? 1) * (w.opacity ?? 1);
|
|
169
|
+
if (D <= 0) return;
|
|
170
|
+
const S = xt(w, x), E = S === w.outline || S && w.outline && S.width === w.outline.width && S.color === w.outline.color ? w : { ...w, outline: S };
|
|
171
|
+
h.push({ objectId: s.id, objectIndex: d, mesh: f, world: k, material: E, color: typeof T == "string" ? T : void 0, opacity: D }), p.push(..._(f, k, I, m, v, E, {
|
|
172
|
+
objectId: s.id,
|
|
173
|
+
objectIndex: d,
|
|
174
|
+
layer: s.layer ?? 0,
|
|
175
|
+
color: typeof T == "string" ? T : void 0,
|
|
176
|
+
opacity: D,
|
|
177
|
+
ink: S,
|
|
178
|
+
nearFade: a
|
|
179
|
+
}));
|
|
180
|
+
}), e.objects.forEach((s, d) => {
|
|
181
|
+
if (s.kind !== "mesh" || !s.shadow || !l.get(s.id)) return;
|
|
182
|
+
const f = t.meshes.get(s.id);
|
|
183
|
+
if (!f) return;
|
|
184
|
+
const w = i(s.id);
|
|
185
|
+
if ((C(w.get("opacity")) ?? 1) <= 0) return;
|
|
186
|
+
const x = r.get(s.id), k = s.shadow === !0 ? {} : s.shadow, I = k.ground ?? e.ground ?? 0;
|
|
187
|
+
let T = 1 / 0, D = -1 / 0, S = 1 / 0, E = 1 / 0, y = -1 / 0;
|
|
188
|
+
for (let O = 0; O < f.positions.length; O += 3) {
|
|
189
|
+
const R = P.transformPoint(x, [f.positions[O], f.positions[O + 1], f.positions[O + 2]]);
|
|
190
|
+
T = Math.min(T, R[0]), D = Math.max(D, R[0]), S = Math.min(S, R[1]), E = Math.min(E, R[2]), y = Math.max(y, R[2]);
|
|
191
|
+
}
|
|
192
|
+
const z = Math.max(D - T, y - E);
|
|
193
|
+
if (!(z > 0)) return;
|
|
194
|
+
const X = Math.max(0, S - I), Y = Math.min(1, X / (2 * z)), H = (k.opacity ?? 0.22) * (1 - Y * 0.8);
|
|
195
|
+
if (H <= 0.01) return;
|
|
196
|
+
const G = 1.1 + Y * 0.4, ct = bt([(T + D) / 2, I + 2e-3, (E + y) / 2], (D - T) / 2 * G, (y - E) / 2 * G), lt = { color: "#000000", shading: "unlit", opacity: H };
|
|
197
|
+
p.push(..._(ct, P.identity(), P.identity(), m, v, lt, {
|
|
198
|
+
objectId: `${s.id}:shadow`,
|
|
199
|
+
objectIndex: d - 0.5,
|
|
200
|
+
layer: s.layer ?? 0,
|
|
201
|
+
opacity: H,
|
|
168
202
|
nearFade: a
|
|
169
203
|
}));
|
|
170
204
|
});
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
if (!
|
|
175
|
-
const
|
|
176
|
-
object:
|
|
177
|
-
prepared: t.prepared.get(
|
|
178
|
-
values: s
|
|
179
|
-
world: r.get(
|
|
180
|
-
camera:
|
|
205
|
+
const M = [];
|
|
206
|
+
e.objects.forEach((s, d) => {
|
|
207
|
+
const f = t.kinds.get(s.kind);
|
|
208
|
+
if (!f || !l.get(s.id)) return;
|
|
209
|
+
const w = f.resolve({
|
|
210
|
+
object: s,
|
|
211
|
+
prepared: t.prepared.get(s.id),
|
|
212
|
+
values: i(s.id),
|
|
213
|
+
world: r.get(s.id),
|
|
214
|
+
camera: m,
|
|
181
215
|
lights: $,
|
|
182
|
-
fog:
|
|
183
|
-
width:
|
|
184
|
-
height:
|
|
185
|
-
toScreen:
|
|
216
|
+
fog: e.fog,
|
|
217
|
+
width: o.width,
|
|
218
|
+
height: o.height,
|
|
219
|
+
toScreen: v
|
|
186
220
|
});
|
|
187
|
-
if (!
|
|
188
|
-
const
|
|
189
|
-
for (const
|
|
190
|
-
for (const
|
|
191
|
-
|
|
192
|
-
objectId:
|
|
193
|
-
objectIndex:
|
|
194
|
-
layer:
|
|
195
|
-
opacity:
|
|
196
|
-
ink:
|
|
221
|
+
if (!w) return;
|
|
222
|
+
const x = s.layer ?? 0;
|
|
223
|
+
for (const k of w.drawables ?? []) M.push({ ...k, objectId: s.id, objectIndex: d, layer: x });
|
|
224
|
+
for (const k of w.meshes ?? [])
|
|
225
|
+
h.push({ objectId: s.id, objectIndex: d, mesh: k.mesh, world: k.world, material: k.material, opacity: k.material.opacity ?? 1 }), p.push(..._(k.mesh, k.world, Q(k.world), m, v, k.material, {
|
|
226
|
+
objectId: s.id,
|
|
227
|
+
objectIndex: d,
|
|
228
|
+
layer: x,
|
|
229
|
+
opacity: k.material.opacity ?? 1,
|
|
230
|
+
ink: k.material.outline,
|
|
197
231
|
nearFade: a
|
|
198
232
|
}));
|
|
199
233
|
});
|
|
200
|
-
const
|
|
201
|
-
return
|
|
202
|
-
if (
|
|
203
|
-
const
|
|
204
|
-
if (!
|
|
205
|
-
const
|
|
206
|
-
if (
|
|
207
|
-
const
|
|
208
|
-
for (const
|
|
209
|
-
}),
|
|
210
|
-
id:
|
|
211
|
-
width:
|
|
212
|
-
height:
|
|
213
|
-
background:
|
|
214
|
-
fog:
|
|
215
|
-
camera:
|
|
234
|
+
const b = { camera: m, height: o.height, fog: e.fog, toScreen: v };
|
|
235
|
+
return e.objects.forEach((s, d) => {
|
|
236
|
+
if (s.kind !== "line" && s.kind !== "trail" || !l.get(s.id)) return;
|
|
237
|
+
const f = i(s.id), w = s.kind === "line" ? It(s, r.get(s.id)) : St(s, e, n, o);
|
|
238
|
+
if (!w) return;
|
|
239
|
+
const x = $t(s, f);
|
|
240
|
+
if (x.opacity <= 0 || x.width <= 0) return;
|
|
241
|
+
const k = s.layer ?? 0;
|
|
242
|
+
for (const I of mt(w.points, w.ages, x, b)) M.push({ ...I, objectId: s.id, objectIndex: d, layer: k });
|
|
243
|
+
}), M.sort((s, d) => s.layer - d.layer || d.depth - s.depth || s.objectIndex - d.objectIndex), p.sort((s, d) => s.layer - d.layer || d.depth - s.depth || s.objectIndex - d.objectIndex || s.face - d.face || s.part - d.part), {
|
|
244
|
+
id: e.id,
|
|
245
|
+
width: o.width,
|
|
246
|
+
height: o.height,
|
|
247
|
+
background: e.background,
|
|
248
|
+
fog: e.fog,
|
|
249
|
+
camera: m,
|
|
216
250
|
lights: $,
|
|
217
251
|
worlds: r,
|
|
218
|
-
triangles:
|
|
219
|
-
drawables:
|
|
220
|
-
meshes:
|
|
221
|
-
time:
|
|
252
|
+
triangles: p,
|
|
253
|
+
drawables: M,
|
|
254
|
+
meshes: h,
|
|
255
|
+
time: o.time ?? 0
|
|
222
256
|
};
|
|
223
257
|
}
|
|
224
|
-
function
|
|
225
|
-
const
|
|
258
|
+
function $t(t, n) {
|
|
259
|
+
const o = n.get("color"), e = t.kind === "trail";
|
|
226
260
|
return {
|
|
227
|
-
color: typeof
|
|
228
|
-
width:
|
|
229
|
-
taper: t.taper ?? (
|
|
230
|
-
fade: t.fade ?? (
|
|
231
|
-
opacity: (
|
|
261
|
+
color: typeof o == "string" ? o : t.color,
|
|
262
|
+
width: C(n.get("width")) ?? t.width ?? 0.05,
|
|
263
|
+
taper: t.taper ?? (e ? 1 : 0),
|
|
264
|
+
fade: t.fade ?? (e ? 1 : 0),
|
|
265
|
+
opacity: (C(n.get("opacity")) ?? 1) * (t.opacity ?? 1),
|
|
232
266
|
additive: t.blend === "add"
|
|
233
267
|
};
|
|
234
268
|
}
|
|
235
|
-
function
|
|
236
|
-
const
|
|
237
|
-
return { points:
|
|
269
|
+
function It(t, n) {
|
|
270
|
+
const e = (t.closed ? [...t.points, t.points[0]] : t.points).map((i) => P.transformPoint(n, i));
|
|
271
|
+
return { points: e, ages: e.map((i, a) => 1 - a / (e.length - 1)) };
|
|
238
272
|
}
|
|
239
|
-
function
|
|
240
|
-
if (!
|
|
241
|
-
const
|
|
242
|
-
(
|
|
243
|
-
|
|
244
|
-
{ length: a, samples: t.samples ?? 32, period: t.period ??
|
|
273
|
+
function St(t, n, o, e) {
|
|
274
|
+
if (!e.valuesAt) return null;
|
|
275
|
+
const i = e.time ?? 0, a = C(o.get(`${n.id}/${t.id}`)?.get("length")) ?? t.length, r = ft(
|
|
276
|
+
(l) => Z(it(n, t.follow, l === i ? o : e.valuesAt(l))),
|
|
277
|
+
i,
|
|
278
|
+
{ length: a, samples: t.samples ?? 32, period: t.period ?? e.period }
|
|
245
279
|
);
|
|
246
|
-
return r.length >= 2 ? { points: r.map((
|
|
247
|
-
}
|
|
248
|
-
function
|
|
249
|
-
const
|
|
250
|
-
if (!
|
|
251
|
-
const
|
|
252
|
-
return
|
|
253
|
-
}
|
|
254
|
-
function _(t,
|
|
255
|
-
const
|
|
256
|
-
for (let
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
const
|
|
261
|
-
for (let
|
|
262
|
-
const [
|
|
263
|
-
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
const $ = (
|
|
268
|
-
for (let
|
|
269
|
-
const
|
|
270
|
-
if (!
|
|
271
|
-
const
|
|
272
|
-
if (
|
|
273
|
-
const
|
|
274
|
-
if (
|
|
275
|
-
const
|
|
276
|
-
if (r.ink &&
|
|
277
|
-
for (const
|
|
278
|
-
const
|
|
279
|
-
(
|
|
280
|
+
return r.length >= 2 ? { points: r.map((l) => l.at), ages: r.map((l) => l.age) } : null;
|
|
281
|
+
}
|
|
282
|
+
function it(t, n, o) {
|
|
283
|
+
const e = t.objects.find((a) => a.id === n);
|
|
284
|
+
if (!e) return P.identity();
|
|
285
|
+
const i = ot(e, o.get(`${t.id}/${n}`) ?? nt);
|
|
286
|
+
return e.parent ? P.multiply(it(t, e.parent, o), i) : i;
|
|
287
|
+
}
|
|
288
|
+
function _(t, n, o, e, i, a, r) {
|
|
289
|
+
const l = t.positions.length / 3, c = [], u = [];
|
|
290
|
+
for (let h = 0; h < l; h++) {
|
|
291
|
+
const M = P.transformPoint(n, [t.positions[h * 3], t.positions[h * 3 + 1], t.positions[h * 3 + 2]]);
|
|
292
|
+
c.push(M), u.push(P.transformPoint(e.view, M));
|
|
293
|
+
}
|
|
294
|
+
const g = t.indices.length / 3, m = [], v = [];
|
|
295
|
+
for (let h = 0; h < g; h++) {
|
|
296
|
+
const [M, b, s] = [0, 1, 2].map((w) => c[t.indices[h * 3 + w]]), d = A.normalize(A.cross(A.subtract(b, M), A.subtract(s, M)));
|
|
297
|
+
m.push(d);
|
|
298
|
+
const f = e.orthographic ? A.scale(e.forward, -1) : A.subtract(e.position, M);
|
|
299
|
+
v.push(A.dot(d, f) > 0);
|
|
300
|
+
}
|
|
301
|
+
const $ = (h) => -u[h][2] >= e.near, p = [];
|
|
302
|
+
for (let h = 0; h < g; h++) {
|
|
303
|
+
const M = v[h];
|
|
304
|
+
if (!M && !a.doubleSided) continue;
|
|
305
|
+
const b = [t.indices[h * 3], t.indices[h * 3 + 1], t.indices[h * 3 + 2]], s = b.map((y) => u[y]);
|
|
306
|
+
if (s.every((y) => -y[2] > e.far)) continue;
|
|
307
|
+
const d = vt(s, e.near);
|
|
308
|
+
if (d.length < 3) continue;
|
|
309
|
+
const f = M ? 1 : -1, w = A.scale(m[h], f), x = b.map((y) => A.scale(Mt(o, t.normals[y * 3], t.normals[y * 3 + 1], t.normals[y * 3 + 2]), f)), k = A.scale(A.add(A.add(c[b[0]], c[b[1]]), c[b[2]]), 1 / 3), I = -(s[0][2] + s[1][2] + s[2][2]) / 3, T = [], D = [];
|
|
310
|
+
if (r.ink && M)
|
|
311
|
+
for (const y of t.faceEdges[h]) {
|
|
312
|
+
const z = y.across, X = z === -1 || !v[z], Y = a.creases !== !1 && !X && h < z && A.dot(m[h], m[z]) < kt;
|
|
313
|
+
(X || Y) && $(y.a) && $(y.b) && (T.push([i(u[y.a]), i(u[y.b])]), D.push([-u[y.a][2], -u[y.b][2]]));
|
|
280
314
|
}
|
|
281
|
-
const
|
|
282
|
-
if (
|
|
283
|
-
const
|
|
284
|
-
for (let
|
|
285
|
-
|
|
315
|
+
const S = r.opacity * At(r.nearFade, I);
|
|
316
|
+
if (S <= 0) continue;
|
|
317
|
+
const E = d.map(i);
|
|
318
|
+
for (let y = 1; y + 1 < E.length; y++)
|
|
319
|
+
p.push({
|
|
286
320
|
objectId: r.objectId,
|
|
287
321
|
objectIndex: r.objectIndex,
|
|
288
322
|
layer: r.layer,
|
|
289
|
-
face:
|
|
290
|
-
part:
|
|
291
|
-
screen: [
|
|
292
|
-
depth:
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
323
|
+
face: h,
|
|
324
|
+
part: y - 1,
|
|
325
|
+
screen: [E[0], E[y], E[y + 1]],
|
|
326
|
+
depth: I,
|
|
327
|
+
depths: [-d[0][2], -d[y][2], -d[y + 1][2]],
|
|
328
|
+
centroid: k,
|
|
329
|
+
normal: w,
|
|
330
|
+
vertexNormals: x,
|
|
296
331
|
material: a,
|
|
297
|
-
color: r.color ?? t.faceColors?.[
|
|
298
|
-
opacity:
|
|
299
|
-
outline:
|
|
332
|
+
color: r.color ?? t.faceColors?.[h],
|
|
333
|
+
opacity: S,
|
|
334
|
+
outline: y === 1 ? T : [],
|
|
335
|
+
outlineDepths: y === 1 ? D : [],
|
|
300
336
|
ink: r.ink
|
|
301
337
|
});
|
|
302
338
|
}
|
|
303
|
-
return
|
|
339
|
+
return p;
|
|
304
340
|
}
|
|
305
|
-
class
|
|
341
|
+
class Xt {
|
|
306
342
|
ctx;
|
|
307
|
-
constructor(
|
|
308
|
-
this.ctx =
|
|
343
|
+
constructor(n) {
|
|
344
|
+
this.ctx = n;
|
|
309
345
|
}
|
|
310
|
-
render(
|
|
311
|
-
|
|
346
|
+
render(n) {
|
|
347
|
+
st(this.ctx, n);
|
|
312
348
|
}
|
|
313
349
|
}
|
|
314
|
-
function
|
|
315
|
-
t.save(),
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
350
|
+
function st(t, n) {
|
|
351
|
+
if (t.save(), n.background && n.background !== "transparent") {
|
|
352
|
+
if (typeof n.background == "string") t.fillStyle = n.background;
|
|
353
|
+
else {
|
|
354
|
+
const r = t.createLinearGradient(0, 0, 0, n.height);
|
|
355
|
+
r.addColorStop(0, n.background.top), r.addColorStop(1, n.background.bottom), t.fillStyle = r;
|
|
356
|
+
}
|
|
357
|
+
t.fillRect(0, 0, n.width, n.height);
|
|
358
|
+
}
|
|
359
|
+
t.lineJoin = "round", t.lineCap = "round";
|
|
360
|
+
let o = 0;
|
|
361
|
+
const e = (r, l) => {
|
|
362
|
+
for (; o < n.drawables.length; ) {
|
|
363
|
+
const c = n.drawables[o];
|
|
364
|
+
if (c.layer > r || c.layer === r && c.depth <= l) break;
|
|
365
|
+
t.save(), c.draw(t, n), t.restore(), o++;
|
|
322
366
|
}
|
|
323
367
|
};
|
|
324
|
-
let
|
|
368
|
+
let i = [];
|
|
325
369
|
const a = (r) => {
|
|
326
|
-
if (
|
|
327
|
-
const
|
|
328
|
-
for (const
|
|
329
|
-
r && r.objectId ===
|
|
330
|
-
|
|
370
|
+
if (i.length === 0) return;
|
|
371
|
+
const l = [];
|
|
372
|
+
for (const c of i)
|
|
373
|
+
r && r.objectId === c.objectId && r.layer === c.layer && c.depth - r.depth <= Pt * c.depth ? l.push(c) : Tt(t, c.triangle, n);
|
|
374
|
+
i = l;
|
|
331
375
|
};
|
|
332
|
-
for (const r of
|
|
333
|
-
a(r),
|
|
334
|
-
const { color:
|
|
335
|
-
t.globalAlpha =
|
|
336
|
-
}
|
|
337
|
-
a(),
|
|
338
|
-
}
|
|
339
|
-
const
|
|
340
|
-
function
|
|
341
|
-
const
|
|
342
|
-
t.globalAlpha =
|
|
343
|
-
for (const [
|
|
344
|
-
t.moveTo(
|
|
376
|
+
for (const r of n.triangles) {
|
|
377
|
+
a(r), e(r.layer, r.depth);
|
|
378
|
+
const { color: l, alpha: c } = q(r, n.lights, n.camera, n.fog), [u, g, m] = r.screen;
|
|
379
|
+
t.globalAlpha = c, t.beginPath(), t.moveTo(u.x, u.y), t.lineTo(g.x, g.y), t.lineTo(m.x, m.y), t.closePath(), t.fillStyle = l, t.fill(), c >= 1 && (t.strokeStyle = l, t.lineWidth = 0.75, t.stroke()), r.ink && r.outline.length > 0 && i.push({ objectId: r.objectId, layer: r.layer, depth: r.depth, triangle: r });
|
|
380
|
+
}
|
|
381
|
+
a(), e(1 / 0, -1 / 0), t.restore();
|
|
382
|
+
}
|
|
383
|
+
const Pt = 0.04;
|
|
384
|
+
function Tt(t, n, o) {
|
|
385
|
+
const e = n.ink;
|
|
386
|
+
t.globalAlpha = n.opacity, t.strokeStyle = j(e.color, o.fog, A.distance(n.centroid, o.camera.position)), t.lineWidth = e.width, t.beginPath();
|
|
387
|
+
for (const [i, a] of n.outline)
|
|
388
|
+
t.moveTo(i.x, i.y), t.lineTo(a.x, a.y);
|
|
345
389
|
t.stroke();
|
|
346
390
|
}
|
|
347
|
-
|
|
391
|
+
function Et(t, n = {}) {
|
|
392
|
+
const o = t.width, e = t.height, i = new Uint8ClampedArray(o * e * 4), a = new Float32Array(o * e).fill(1 / 0);
|
|
393
|
+
if (n.under && n.under.length === i.length) i.set(n.under);
|
|
394
|
+
else if (t.background && t.background !== "transparent") {
|
|
395
|
+
const g = N(typeof t.background == "string" ? t.background : t.background.top), m = N(typeof t.background == "string" ? t.background : t.background.bottom);
|
|
396
|
+
for (let v = 0; v < e; v++) {
|
|
397
|
+
const $ = e > 1 ? v / (e - 1) : 0, p = Math.round((g[0] + (m[0] - g[0]) * $) * 255), h = Math.round((g[1] + (m[1] - g[1]) * $) * 255), M = Math.round((g[2] + (m[2] - g[2]) * $) * 255);
|
|
398
|
+
for (let b = 0; b < o; b++) {
|
|
399
|
+
const s = v * o + b;
|
|
400
|
+
i[s * 4] = p, i[s * 4 + 1] = h, i[s * 4 + 2] = M, i[s * 4 + 3] = 255;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
const r = { width: o, height: e, data: i, depth: a };
|
|
405
|
+
let l = -1 / 0;
|
|
406
|
+
const c = [], u = () => {
|
|
407
|
+
for (const g of c) U(r, t, g, !1);
|
|
408
|
+
c.length = 0;
|
|
409
|
+
};
|
|
410
|
+
for (const g of t.triangles)
|
|
411
|
+
g.layer !== l && (u(), l = g.layer, a.fill(1 / 0)), g.opacity < 1 ? c.push(g) : U(r, t, g, !0);
|
|
412
|
+
return u(), r;
|
|
413
|
+
}
|
|
414
|
+
function U(t, n, o, e) {
|
|
415
|
+
const { color: i, alpha: a } = q(o, n.lights, n.camera, n.fog), r = N(i).map((l) => Math.round(l * 255));
|
|
416
|
+
if (Dt(t, o.screen, o.depths, r, a, e), o.ink && o.outline.length > 0) {
|
|
417
|
+
const l = N(j(o.ink.color, n.fog, A.distance(o.centroid, n.camera.position))).map((c) => Math.round(c * 255));
|
|
418
|
+
o.outline.forEach((c, u) => {
|
|
419
|
+
const g = o.outlineDepths[u] ?? [o.depth, o.depth];
|
|
420
|
+
zt(t, c[0], c[1], g, o.ink.width, l, a);
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
function rt(t, n, o, e) {
|
|
425
|
+
const i = n * 4;
|
|
426
|
+
if (e >= 1) {
|
|
427
|
+
t[i] = o[0], t[i + 1] = o[1], t[i + 2] = o[2], t[i + 3] = 255;
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
const a = t[i + 3] / 255, r = e + a * (1 - e);
|
|
431
|
+
if (!(r <= 0)) {
|
|
432
|
+
for (let l = 0; l < 3; l++) t[i + l] = Math.round((o[l] * e + t[i + l] * a * (1 - e)) / r);
|
|
433
|
+
t[i + 3] = Math.round(r * 255);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
const Ct = 4e-3;
|
|
437
|
+
function Dt(t, n, o, e, i, a) {
|
|
438
|
+
const [r, l, c] = n, u = (l.x - r.x) * (c.y - r.y) - (l.y - r.y) * (c.x - r.x);
|
|
439
|
+
if (u === 0) return;
|
|
440
|
+
const g = Math.max(0, Math.floor(Math.min(r.x, l.x, c.x))), m = Math.min(t.width - 1, Math.ceil(Math.max(r.x, l.x, c.x))), v = Math.max(0, Math.floor(Math.min(r.y, l.y, c.y))), $ = Math.min(t.height - 1, Math.ceil(Math.max(r.y, l.y, c.y)));
|
|
441
|
+
if (g > m || v > $) return;
|
|
442
|
+
const p = [1 / Math.max(1e-9, o[0]), 1 / Math.max(1e-9, o[1]), 1 / Math.max(1e-9, o[2])], h = u > 0 ? 1 : -1;
|
|
443
|
+
for (let M = v; M <= $; M++) {
|
|
444
|
+
const b = M + 0.5;
|
|
445
|
+
for (let s = g; s <= m; s++) {
|
|
446
|
+
const d = s + 0.5, f = ((l.x - d) * (c.y - b) - (l.y - b) * (c.x - d)) * h, w = ((c.x - d) * (r.y - b) - (c.y - b) * (r.x - d)) * h, x = ((r.x - d) * (l.y - b) - (r.y - b) * (l.x - d)) * h;
|
|
447
|
+
if (f < 0 || w < 0 || x < 0) continue;
|
|
448
|
+
const I = (f + w + x) / (f * p[0] + w * p[1] + x * p[2]), T = M * t.width + s;
|
|
449
|
+
I >= t.depth[T] || (rt(t.data, T, e, i), a && (t.depth[T] = I));
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
function zt(t, n, o, e, i, a, r) {
|
|
454
|
+
const l = Math.max(0.5, i / 2), c = Math.max(0, Math.floor(Math.min(n.x, o.x) - l)), u = Math.min(t.width - 1, Math.ceil(Math.max(n.x, o.x) + l)), g = Math.max(0, Math.floor(Math.min(n.y, o.y) - l)), m = Math.min(t.height - 1, Math.ceil(Math.max(n.y, o.y) + l)), v = o.x - n.x, $ = o.y - n.y, p = v * v + $ * $, h = l * l;
|
|
455
|
+
for (let M = g; M <= m; M++) {
|
|
456
|
+
const b = M + 0.5;
|
|
457
|
+
for (let s = c; s <= u; s++) {
|
|
458
|
+
const d = s + 0.5, f = p > 0 ? Math.min(1, Math.max(0, ((d - n.x) * v + (b - n.y) * $) / p)) : 0, w = n.x + v * f, x = n.y + $ * f;
|
|
459
|
+
if ((d - w) ** 2 + (b - x) ** 2 > h) continue;
|
|
460
|
+
const k = (e[0] + (e[1] - e[0]) * f) * (1 - Ct), I = M * t.width + s;
|
|
461
|
+
k > t.depth[I] || rt(t.data, I, a, r);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
function at(t, n) {
|
|
466
|
+
const e = !n.background || n.background === "transparent" ? t.getImageData(0, 0, n.width, n.height).data : void 0, i = Et(n, { under: e }), a = t.createImageData(n.width, n.height);
|
|
467
|
+
a.data.set(i.data), t.putImageData(a, 0, 0), t.save(), t.lineJoin = "round", t.lineCap = "round";
|
|
468
|
+
for (const r of n.drawables)
|
|
469
|
+
t.save(), r.draw(t, n), t.restore();
|
|
470
|
+
t.restore();
|
|
471
|
+
}
|
|
472
|
+
class Yt {
|
|
473
|
+
ctx;
|
|
474
|
+
constructor(n) {
|
|
475
|
+
this.ctx = n;
|
|
476
|
+
}
|
|
477
|
+
render(n) {
|
|
478
|
+
at(this.ctx, n);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
class Wt {
|
|
348
482
|
renderer;
|
|
349
483
|
width;
|
|
350
484
|
height;
|
|
@@ -352,87 +486,262 @@ class vt {
|
|
|
352
486
|
values = /* @__PURE__ */ new Map();
|
|
353
487
|
valuesAt;
|
|
354
488
|
/** `valuesAt`: the values at another time (`(t) => timeline.getStateAtTime(t).values`), for trails */
|
|
355
|
-
constructor(
|
|
356
|
-
this.renderer =
|
|
489
|
+
constructor(n, o) {
|
|
490
|
+
this.renderer = n, this.width = o.width, this.height = o.height, this.valuesAt = o.valuesAt;
|
|
357
491
|
}
|
|
358
492
|
/** Add a scene; its tracks address `<scene.id>/<objectId>`. */
|
|
359
|
-
registerScene(
|
|
360
|
-
this.scenes.set(
|
|
493
|
+
registerScene(n) {
|
|
494
|
+
this.scenes.set(n.scene.id, n);
|
|
361
495
|
}
|
|
362
|
-
unregisterScene(
|
|
363
|
-
this.scenes.delete(
|
|
496
|
+
unregisterScene(n) {
|
|
497
|
+
this.scenes.delete(n);
|
|
364
498
|
}
|
|
365
|
-
resize(
|
|
366
|
-
this.width =
|
|
499
|
+
resize(n, o) {
|
|
500
|
+
this.width = n, this.height = o;
|
|
367
501
|
}
|
|
368
|
-
applyState(
|
|
369
|
-
this.values =
|
|
502
|
+
applyState(n) {
|
|
503
|
+
this.values = n.values, this.time = n.currentTime ?? this.time;
|
|
370
504
|
}
|
|
371
505
|
time = 0;
|
|
372
506
|
render() {
|
|
373
|
-
for (const
|
|
374
|
-
this.renderer.render(
|
|
507
|
+
for (const n of this.scenes.values())
|
|
508
|
+
this.renderer.render(et(n, this.values, { width: this.width, height: this.height, time: this.time, valuesAt: this.valuesAt }));
|
|
375
509
|
}
|
|
376
510
|
}
|
|
377
|
-
function
|
|
378
|
-
const
|
|
379
|
-
|
|
511
|
+
function Ht(t, n, o, e) {
|
|
512
|
+
const i = e.stateAt, a = e.valuesAt ?? (i && ((l) => i(l).values)), r = et(n, o ?? /* @__PURE__ */ new Map(), { width: e.width, height: e.height, time: e.time, period: e.period, valuesAt: a });
|
|
513
|
+
e.depthBuffer ? at(t, r) : st(t, r);
|
|
380
514
|
}
|
|
381
|
-
function
|
|
382
|
-
const
|
|
383
|
-
id: `${
|
|
515
|
+
function Lt(t = {}) {
|
|
516
|
+
const n = t.id ?? "penrose", o = t.length ?? 4, e = t.thickness ?? 0.8, i = t.material ?? "penrose", [a, r, l] = t.position ?? [0, 0, 0], c = e / 2, u = (p, h, M) => ({
|
|
517
|
+
id: `${n}-${p}`,
|
|
384
518
|
kind: "mesh",
|
|
385
|
-
geometry: { type: "box", size: [
|
|
386
|
-
material:
|
|
387
|
-
position: [a + (
|
|
388
|
-
}),
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
],
|
|
393
|
-
id: `${
|
|
519
|
+
geometry: { type: "box", size: [M[0] - h[0], M[1] - h[1], M[2] - h[2]] },
|
|
520
|
+
material: i,
|
|
521
|
+
position: [a + (h[0] + M[0]) / 2, r + (h[1] + M[1]) / 2, l + (h[2] + M[2]) / 2]
|
|
522
|
+
}), g = [
|
|
523
|
+
u("x", [-c, -c, -c], [o - c, c, c]),
|
|
524
|
+
u("y", [o - c, -c, -c], [o + c, o - c, c]),
|
|
525
|
+
u("z", [o - c, o - c, -c], [o + c, o + c, o])
|
|
526
|
+
], m = [a + 2 * o / 3, r + o / 3, l + o / 3], v = (t.distance ?? 20) / Math.sqrt(3), $ = {
|
|
527
|
+
id: `${n}-camera`,
|
|
394
528
|
kind: "camera",
|
|
395
529
|
projection: "orthographic",
|
|
396
|
-
height:
|
|
530
|
+
height: o * 1.6,
|
|
397
531
|
near: 0.1,
|
|
398
532
|
far: (t.distance ?? 20) * 3,
|
|
399
|
-
position: [
|
|
400
|
-
lookAt:
|
|
533
|
+
position: [m[0] + v, m[1] + v, m[2] + v],
|
|
534
|
+
lookAt: m
|
|
535
|
+
};
|
|
536
|
+
return { objects: g, camera: $ };
|
|
537
|
+
}
|
|
538
|
+
function _t(t, n) {
|
|
539
|
+
let o;
|
|
540
|
+
for (const e of [...t].sort((i, a) => i.start - a.start)) e.start <= n && (o = e);
|
|
541
|
+
return o;
|
|
542
|
+
}
|
|
543
|
+
function Bt(t) {
|
|
544
|
+
const n = [], o = [...t].sort((i, a) => i.start - a.start), e = /* @__PURE__ */ new Set();
|
|
545
|
+
return o.forEach((i, a) => {
|
|
546
|
+
e.has(i.id) && n.push(`two shots share the id "${i.id}"`), e.add(i.id), i.end > i.start || n.push(`shot "${i.id}" ends before it starts`), a > 0 && i.start < o[a - 1].end && n.push(`shot "${i.id}" starts before "${o[a - 1].id}" ends`), i.transition && a === 0 && n.push(`shot "${i.id}" is first: nothing to transition from`), i.transition && i.transition.duration > i.end - i.start && n.push(`shot "${i.id}": its transition is longer than the shot`);
|
|
547
|
+
}), n;
|
|
548
|
+
}
|
|
549
|
+
function Vt(t, n) {
|
|
550
|
+
const o = [...t].sort((i, a) => i.start - a.start);
|
|
551
|
+
if (o.length === 0) return [];
|
|
552
|
+
const e = o.map((i) => ({ time: i.start, value: i.camera }));
|
|
553
|
+
return [{ id: `${n}-shots`, target: n, property: "activeCamera", keyframes: e }];
|
|
554
|
+
}
|
|
555
|
+
function Zt(t) {
|
|
556
|
+
return [...t].sort((n, o) => n.start - o.start).map((n) => ({ id: n.id, time: n.start, label: n.label ?? n.id }));
|
|
557
|
+
}
|
|
558
|
+
function Gt(t, n) {
|
|
559
|
+
const o = [...t].sort((e, i) => e.start - i.start);
|
|
560
|
+
for (let e = 1; e < o.length; e++) {
|
|
561
|
+
const i = o[e], a = i.transition;
|
|
562
|
+
if (!(!a || a.kind === "cut" || !(a.duration > 0)) && n >= i.start && n < i.start + a.duration)
|
|
563
|
+
return { kind: a.kind, progress: (n - i.start) / a.duration, from: o[e - 1], to: i, direction: a.direction ?? "left", color: a.color ?? "#000000" };
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
function Jt(t, n) {
|
|
567
|
+
const o = 6e4 / n.bpm, e = (a) => n.offset + Math.round((a - n.offset) / o) * o, i = [...t].sort((a, r) => a.start - r.start).map((a) => ({ ...a }));
|
|
568
|
+
for (let a = 1; a < i.length; a++) {
|
|
569
|
+
const r = Math.max(i[a - 1].start + 1, e(i[a].start));
|
|
570
|
+
i[a - 1].end = r, i[a].start = r;
|
|
571
|
+
}
|
|
572
|
+
return i;
|
|
573
|
+
}
|
|
574
|
+
function Kt(t, n, o) {
|
|
575
|
+
const e = new Map(t ?? []), i = new Map(e.get(n) ?? []);
|
|
576
|
+
return i.set("activeCamera", o), e.set(n, i), e;
|
|
577
|
+
}
|
|
578
|
+
const B = (t, n, o) => [t[0] + (n[0] - t[0]) * o, t[1] + (n[1] - t[1]) * o, t[2] + (n[2] - t[2]) * o];
|
|
579
|
+
function Ft(t, n, o) {
|
|
580
|
+
const e = { target: [0, 0, 0], yaw: 0, pitch: 15, distance: 8, ...t }, i = { ...e, ...n }, a = B(e.target, i.target, o), r = e.position || i.position ? B(e.position ?? L(e.target, e.yaw, e.pitch, e.distance), i.position ?? L(i.target, i.yaw, i.pitch, i.distance), o) : L(a, e.yaw + (i.yaw - e.yaw) * o, e.pitch + (i.pitch - e.pitch) * o, e.distance + (i.distance - e.distance) * o), l = B(e.lookAt ?? e.target, i.lookAt ?? i.target, o), c = e.fov !== void 0 || i.fov !== void 0 ? (e.fov ?? i.fov) + ((i.fov ?? e.fov) - (e.fov ?? i.fov)) * o : void 0;
|
|
581
|
+
return { position: r, lookAt: l, fov: c };
|
|
582
|
+
}
|
|
583
|
+
function Qt(t) {
|
|
584
|
+
const n = Math.max(1, t.every ?? 33), o = ut(t.easing ?? "ease-in-out"), e = `${t.scene}/${t.camera}`, i = [], a = [], r = [];
|
|
585
|
+
for (let c = t.start; ; c = Math.min(t.end, c + n)) {
|
|
586
|
+
const u = t.end > t.start ? o((c - t.start) / (t.end - t.start)) : 1, g = Ft(t.from, t.to, u);
|
|
587
|
+
if (i.push({ time: c, value: g.position }), a.push({ time: c, value: g.lookAt }), g.fov !== void 0 && r.push({ time: c, value: g.fov }), c >= t.end) break;
|
|
588
|
+
}
|
|
589
|
+
const l = [
|
|
590
|
+
{ id: `${e}-move-position`, target: e, property: "position", keyframes: i },
|
|
591
|
+
{ id: `${e}-move-lookAt`, target: e, property: "lookAt", keyframes: a }
|
|
592
|
+
];
|
|
593
|
+
return r.length > 0 && l.push({ id: `${e}-move-fov`, target: e, property: "fov", keyframes: r }), l;
|
|
594
|
+
}
|
|
595
|
+
function Ut(t) {
|
|
596
|
+
const n = Math.max(1, t.every ?? 33), o = t.offset ?? [0, 2, 6], e = t.lag ?? 0, i = `${t.scene}/${t.camera}`, a = [], r = [];
|
|
597
|
+
for (let l = t.start; ; l = Math.min(t.end, l + n)) {
|
|
598
|
+
const c = t.subjectAt(l), u = t.subjectAt(Math.max(t.start, l - e));
|
|
599
|
+
if (a.push({ time: l, value: [u[0] + o[0], u[1] + o[1], u[2] + o[2]] }), r.push({ time: l, value: c }), l >= t.end) break;
|
|
600
|
+
}
|
|
601
|
+
return [
|
|
602
|
+
{ id: `${i}-follow-position`, target: i, property: "position", keyframes: a },
|
|
603
|
+
{ id: `${i}-follow-lookAt`, target: i, property: "lookAt", keyframes: r }
|
|
604
|
+
];
|
|
605
|
+
}
|
|
606
|
+
function qt(t, n) {
|
|
607
|
+
const o = `${n.scene}/${n.camera}`, e = n.amount ?? 0.04, i = n.aim ?? 0.08, a = n.rate ?? 1.2, r = Math.max(1, n.every ?? 33), l = n.end - n.start, c = Math.max(1, l), u = Math.max(1, Math.round(c / 1e3 * a)), g = typeof n.seed == "string" ? n.seed : `handheld-${n.seed ?? 0}`, m = (s, d) => gt(s - n.start, { period: c, seed: `${g}-${d}`, cycles: u, octaves: 2 }), v = t.filter((s) => s.target === o), $ = t.filter((s) => s.target !== o), p = (s, d, f) => {
|
|
608
|
+
const w = v.find((k) => k.property === s), x = [];
|
|
609
|
+
if (w)
|
|
610
|
+
for (const k of w.keyframes) {
|
|
611
|
+
const I = k.value;
|
|
612
|
+
x.push({ time: k.time, value: [I[0] + m(k.time, `${s}x`) * d, I[1] + m(k.time, `${s}y`) * d, I[2] + m(k.time, `${s}z`) * d * 0.5], easing: k.easing });
|
|
613
|
+
}
|
|
614
|
+
else if (f)
|
|
615
|
+
for (let k = n.start; x.push({ time: k, value: [f[0] + m(k, `${s}x`) * d, f[1] + m(k, `${s}y`) * d, f[2] + m(k, `${s}z`) * d * 0.5] }), !(k >= n.end); k = Math.min(n.end, k + r))
|
|
616
|
+
;
|
|
617
|
+
else return;
|
|
618
|
+
return { id: w?.id ?? `${o}-handheld-${s}`, target: o, property: s, keyframes: x };
|
|
619
|
+
}, h = [...$, ...v.filter((s) => s.property !== "position" && s.property !== "lookAt")], M = p("position", e, n.base?.position), b = p("lookAt", i, n.base?.lookAt);
|
|
620
|
+
return M && h.push(M), b && h.push(b), h;
|
|
621
|
+
}
|
|
622
|
+
const V = {
|
|
623
|
+
day: {
|
|
624
|
+
lights: [
|
|
625
|
+
{ id: "key", kind: "light", light: "directional", color: "#fff6e0", intensity: 0.95, position: [4, 8, 3] },
|
|
626
|
+
{ id: "fill", kind: "light", light: "directional", color: "#cfe3ff", intensity: 0.3, position: [-5, 3, -2] },
|
|
627
|
+
{ id: "sky", kind: "light", light: "ambient", color: "#bcd4ea", intensity: 0.4 }
|
|
628
|
+
],
|
|
629
|
+
background: { top: "#5aa9e6", bottom: "#dff1ff" },
|
|
630
|
+
fog: { color: "#dff1ff", near: 14, far: 40 }
|
|
631
|
+
},
|
|
632
|
+
dusk: {
|
|
633
|
+
lights: [
|
|
634
|
+
{ id: "key", kind: "light", light: "directional", color: "#ffb067", intensity: 0.8, position: [6, 2.5, 2] },
|
|
635
|
+
{ id: "fill", kind: "light", light: "directional", color: "#7b6bd6", intensity: 0.25, position: [-4, 3, -3] },
|
|
636
|
+
{ id: "sky", kind: "light", light: "ambient", color: "#b58ab3", intensity: 0.3 }
|
|
637
|
+
],
|
|
638
|
+
background: { top: "#4a3a7a", bottom: "#ff9a62" },
|
|
639
|
+
fog: { color: "#d9826f", near: 10, far: 30 }
|
|
640
|
+
},
|
|
641
|
+
night: {
|
|
642
|
+
lights: [
|
|
643
|
+
{ id: "key", kind: "light", light: "directional", color: "#9db7ff", intensity: 0.35, position: [-3, 7, 2] },
|
|
644
|
+
{ id: "fill", kind: "light", light: "directional", color: "#3b4a7a", intensity: 0.12, position: [4, 2, -3] },
|
|
645
|
+
{ id: "sky", kind: "light", light: "ambient", color: "#243357", intensity: 0.25 }
|
|
646
|
+
],
|
|
647
|
+
background: { top: "#060a1c", bottom: "#1b2650" },
|
|
648
|
+
fog: { color: "#101a3a", near: 6, far: 22 }
|
|
649
|
+
},
|
|
650
|
+
stage: {
|
|
651
|
+
lights: [
|
|
652
|
+
{ id: "key", kind: "light", light: "directional", color: "#ffffff", intensity: 0.15, position: [2, 6, 4] },
|
|
653
|
+
{ id: "fill", kind: "light", light: "directional", color: "#402040", intensity: 0.08, position: [-4, 3, -2] },
|
|
654
|
+
{ id: "sky", kind: "light", light: "ambient", color: "#1a1020", intensity: 0.2 },
|
|
655
|
+
{ id: "spot", kind: "light", light: "spot", color: "#ffe9b0", intensity: 1.1, position: [0, 7, 2], target: [0, 0, 0], angle: 22, range: 16 }
|
|
656
|
+
],
|
|
657
|
+
background: { top: "#05030a", bottom: "#120a1c" },
|
|
658
|
+
fog: { color: "#0a0612", near: 8, far: 24 }
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
function jt(t, n = {}) {
|
|
662
|
+
const o = V[t];
|
|
663
|
+
if (!o) throw new Error(`lightingPreset: unknown mood "${t}" (day, dusk, night, stage)`);
|
|
664
|
+
const e = n.prefix ? `${n.prefix}-` : "";
|
|
665
|
+
return {
|
|
666
|
+
objects: o.lights.map((i) => ({ ...i, id: `${e}${i.id}`, position: i.position ? [...i.position] : void 0, target: i.target ? [...i.target] : void 0 })),
|
|
667
|
+
background: { ...o.background },
|
|
668
|
+
fog: { ...o.fog }
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
function tn(t, n, o) {
|
|
672
|
+
const e = V[t], i = V[n];
|
|
673
|
+
if (!e || !i) throw new Error(`lightingTracks: unknown mood "${e ? n : t}" (day, dusk, night, stage)`);
|
|
674
|
+
const a = o.prefix ? `${o.prefix}-` : "", r = /* @__PURE__ */ new Set([...e.lights.map((c) => c.id), ...i.lights.map((c) => c.id)]), l = [];
|
|
675
|
+
for (const c of r) {
|
|
676
|
+
const u = e.lights.find((b) => b.id === c), g = i.lights.find((b) => b.id === c), m = `${o.scene}/${a}${c}`, v = (b, s, d) => {
|
|
677
|
+
const f = [{ time: o.start, value: s }, { time: o.end, value: d, easing: o.easing ?? "ease-in-out" }];
|
|
678
|
+
l.push({ id: `${m}-${b}`, target: m, property: b, keyframes: f });
|
|
679
|
+
};
|
|
680
|
+
v("intensity", u?.intensity ?? 0, g?.intensity ?? 0), v("color", u?.color ?? g.color, g?.color ?? u.color);
|
|
681
|
+
const $ = u?.position ?? g?.position, p = g?.position ?? u?.position;
|
|
682
|
+
$ && p && v("position", [...$], [...p]);
|
|
683
|
+
const h = u?.target ?? g?.target, M = g?.target ?? u?.target;
|
|
684
|
+
h && M && v("target", [...h], [...M]);
|
|
685
|
+
}
|
|
686
|
+
return l;
|
|
687
|
+
}
|
|
688
|
+
function nn(t = {}) {
|
|
689
|
+
const n = t.id ?? "ground", o = t.size ?? 24;
|
|
690
|
+
return {
|
|
691
|
+
objects: [{ id: n, kind: "mesh", layer: -1, geometry: { type: "plane", size: [o, o], segments: t.segments ?? 24 }, material: n, position: [0, t.y ?? 0, 0] }],
|
|
692
|
+
materials: { [n]: { color: t.color ?? "#3b4252", shading: "flat" } }
|
|
401
693
|
};
|
|
402
|
-
return { objects: A, camera: $ };
|
|
403
694
|
}
|
|
404
695
|
export {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
696
|
+
Xt as Canvas2DRenderer,
|
|
697
|
+
V as LIGHTING_PRESETS,
|
|
698
|
+
sn as MeshBuilder,
|
|
699
|
+
Wt as Scene3DAdapter,
|
|
700
|
+
Yt as SoftwareRenderer,
|
|
701
|
+
rn as boxMesh,
|
|
702
|
+
Ut as cameraFollowTracks,
|
|
703
|
+
qt as cameraHandheldTracks,
|
|
704
|
+
Qt as cameraMoveTracks,
|
|
705
|
+
Ft as cameraPoseAt,
|
|
706
|
+
Bt as checkShots,
|
|
707
|
+
an as coneMesh,
|
|
708
|
+
cn as cylinderMesh,
|
|
709
|
+
Rt as dollyPosition,
|
|
710
|
+
st as drawResolvedScene,
|
|
711
|
+
at as drawResolvedSceneWithDepth,
|
|
712
|
+
Ht as drawScene3D,
|
|
713
|
+
ln as extrudeMesh,
|
|
714
|
+
pt as fogAmount,
|
|
715
|
+
dn as geometryMesh,
|
|
716
|
+
nn as ground,
|
|
717
|
+
j as inkColor,
|
|
718
|
+
xn as lightAt,
|
|
719
|
+
jt as lightingPreset,
|
|
720
|
+
tn as lightingTracks,
|
|
721
|
+
hn as loadScene3D,
|
|
722
|
+
yt as lookAtView,
|
|
723
|
+
fn as meshEdges,
|
|
724
|
+
L as orbitPosition,
|
|
725
|
+
N as parseColor,
|
|
726
|
+
Lt as penroseTriangle3D,
|
|
727
|
+
un as planeMesh,
|
|
728
|
+
gn as pointInPolygon,
|
|
729
|
+
pn as prepareMesh,
|
|
730
|
+
J as projectionMatrix,
|
|
731
|
+
Et as rasterizeResolvedScene,
|
|
732
|
+
yn as rawMesh,
|
|
733
|
+
et as resolveScene3D,
|
|
734
|
+
tt as rollView,
|
|
735
|
+
q as shadeTriangle,
|
|
736
|
+
_t as shotAt,
|
|
737
|
+
Zt as shotMarkers,
|
|
738
|
+
Vt as shotTracks,
|
|
739
|
+
mn as signedArea,
|
|
740
|
+
Jt as snapShotsToBeats,
|
|
741
|
+
kn as sphereMesh,
|
|
742
|
+
wn as torusMesh,
|
|
743
|
+
Gt as transitionAt,
|
|
744
|
+
Mn as triangulate,
|
|
745
|
+
vn as validateScene3D,
|
|
746
|
+
Kt as withActiveCamera
|
|
438
747
|
};
|