@algorisys/tinyfly 0.108.0 → 0.109.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 -4
- package/docs/cricket.md +127 -0
- package/docs/editor-guide.md +1 -1
- package/docs/examples.md +1 -1
- package/docs/getting-started.md +1 -1
- package/docs/gsap-compat.md +1 -1
- package/docs/llm-guide.md +23 -0
- package/docs/maps.md +2 -2
- package/docs/teaching.md +1 -1
- package/lib/addons/characters.js +4821 -8840
- package/lib/addons/cricket-camera-BWByoNgz.js +4205 -0
- package/lib/addons/scene-3d.js +436 -540
- package/lib/addons/shots-DR_ViiAC.js +125 -0
- package/lib/addons/sports.js +390 -0
- package/lib/browser/tinyfly.iife.js +12 -12
- package/lib/browser/tinyfly.js +7945 -7470
- package/lib/browser/tinyfly.umd.js +12 -12
- package/lib/types/browser/index.d.ts +1 -0
- package/lib/types/characters/capabilities.d.ts +12 -0
- package/lib/types/sports/ball-flight.d.ts +22 -0
- package/lib/types/sports/cricket/cricket-action.d.ts +7 -0
- package/lib/types/sports/cricket/cricket-camera.d.ts +13 -0
- package/lib/types/sports/cricket/cricket-field.d.ts +13 -0
- package/lib/types/sports/cricket/cricket-motion.d.ts +36 -0
- package/lib/types/sports/cricket/cricket-types.d.ts +84 -0
- package/lib/types/sports/cricket/index.d.ts +5 -0
- package/lib/types/sports/index.d.ts +3 -0
- package/llms-full.txt +186 -8
- package/llms.txt +30 -29
- package/package.json +5 -1
- package/skills/tinyfly/SKILL.md +19 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { vec3 as v, mat4 as k, quat as z, getEasingFunction as C, loopNoise as S } from "@algorisys/tinyfly";
|
|
2
|
+
function q(e, s, n = {}) {
|
|
3
|
+
const r = v.normalize(v.subtract(s, e)), t = n.up ?? (Math.abs(r[1]) > 0.9999 ? [0, 0, -1] : [0, 1, 0]);
|
|
4
|
+
return E(k.lookAt(e, s, t), n.roll ?? 0);
|
|
5
|
+
}
|
|
6
|
+
function E(e, s) {
|
|
7
|
+
return s ? k.multiply(k.fromQuat(z.fromAxisAngle([0, 0, 1], -s)), e) : e;
|
|
8
|
+
}
|
|
9
|
+
function A(e, s, n, r) {
|
|
10
|
+
const t = s * Math.PI / 180, o = n * Math.PI / 180;
|
|
11
|
+
return [e[0] + r * Math.cos(o) * Math.sin(t), e[1] + r * Math.sin(o), e[2] + r * Math.cos(o) * Math.cos(t)];
|
|
12
|
+
}
|
|
13
|
+
function B(e, s, n) {
|
|
14
|
+
const r = v.subtract(e, s), t = v.length(r);
|
|
15
|
+
if (t === 0) return e;
|
|
16
|
+
const o = Math.max(1e-3, t - n);
|
|
17
|
+
return v.add(s, v.scale(r, o / t));
|
|
18
|
+
}
|
|
19
|
+
function H(e, s) {
|
|
20
|
+
if (e.projection === "perspective") return k.perspective(e.fov, s, e.near, e.far);
|
|
21
|
+
const n = e.height / 2;
|
|
22
|
+
return k.orthographic(-n * s, n * s, -n, n, e.near, e.far);
|
|
23
|
+
}
|
|
24
|
+
function N(e, s) {
|
|
25
|
+
let n;
|
|
26
|
+
for (const r of [...e].sort((t, o) => t.start - o.start)) r.start <= s && (n = r);
|
|
27
|
+
return n;
|
|
28
|
+
}
|
|
29
|
+
function Q(e) {
|
|
30
|
+
const s = [], n = [...e].sort((t, o) => t.start - o.start), r = /* @__PURE__ */ new Set();
|
|
31
|
+
return n.forEach((t, o) => {
|
|
32
|
+
r.has(t.id) && s.push(`two shots share the id "${t.id}"`), r.add(t.id), t.end > t.start || s.push(`shot "${t.id}" ends before it starts`), o > 0 && t.start < n[o - 1].end && s.push(`shot "${t.id}" starts before "${n[o - 1].id}" ends`), t.transition && o === 0 && s.push(`shot "${t.id}" is first: nothing to transition from`), t.transition && t.transition.duration > t.end - t.start && s.push(`shot "${t.id}": its transition is longer than the shot`);
|
|
33
|
+
}), s;
|
|
34
|
+
}
|
|
35
|
+
function D(e, s) {
|
|
36
|
+
const n = [...e].sort((t, o) => t.start - o.start);
|
|
37
|
+
if (n.length === 0) return [];
|
|
38
|
+
const r = n.map((t) => ({ time: t.start, value: t.camera }));
|
|
39
|
+
return [{ id: `${s}-shots`, target: s, property: "activeCamera", keyframes: r }];
|
|
40
|
+
}
|
|
41
|
+
function G(e) {
|
|
42
|
+
return [...e].sort((s, n) => s.start - n.start).map((s) => ({ id: s.id, time: s.start, label: s.label ?? s.id }));
|
|
43
|
+
}
|
|
44
|
+
function I(e, s) {
|
|
45
|
+
const n = [...e].sort((r, t) => r.start - t.start);
|
|
46
|
+
for (let r = 1; r < n.length; r++) {
|
|
47
|
+
const t = n[r], o = t.transition;
|
|
48
|
+
if (!(!o || o.kind === "cut" || !(o.duration > 0)) && s >= t.start && s < t.start + o.duration)
|
|
49
|
+
return { kind: o.kind, progress: (s - t.start) / o.duration, from: n[r - 1], to: t, direction: o.direction ?? "left", color: o.color ?? "#000000" };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function J(e, s) {
|
|
53
|
+
const n = 6e4 / s.bpm, r = (o) => s.offset + Math.round((o - s.offset) / n) * n, t = [...e].sort((o, c) => o.start - c.start).map((o) => ({ ...o }));
|
|
54
|
+
for (let o = 1; o < t.length; o++) {
|
|
55
|
+
const c = Math.max(t[o - 1].start + 1, r(t[o].start));
|
|
56
|
+
t[o - 1].end = c, t[o].start = c;
|
|
57
|
+
}
|
|
58
|
+
return t;
|
|
59
|
+
}
|
|
60
|
+
function K(e, s, n) {
|
|
61
|
+
const r = new Map(e ?? []), t = new Map(r.get(s) ?? []);
|
|
62
|
+
return t.set("activeCamera", n), r.set(s, t), r;
|
|
63
|
+
}
|
|
64
|
+
const w = (e, s, n) => [e[0] + (s[0] - e[0]) * n, e[1] + (s[1] - e[1]) * n, e[2] + (s[2] - e[2]) * n];
|
|
65
|
+
function F(e, s, n) {
|
|
66
|
+
const r = { target: [0, 0, 0], yaw: 0, pitch: 15, distance: 8, ...e }, t = { ...r, ...s }, o = w(r.target, t.target, n), c = r.position || t.position ? w(r.position ?? A(r.target, r.yaw, r.pitch, r.distance), t.position ?? A(t.target, t.yaw, t.pitch, t.distance), n) : A(o, r.yaw + (t.yaw - r.yaw) * n, r.pitch + (t.pitch - r.pitch) * n, r.distance + (t.distance - r.distance) * n), f = w(r.lookAt ?? r.target, t.lookAt ?? t.target, n), u = r.fov !== void 0 || t.fov !== void 0 ? (r.fov ?? t.fov) + ((t.fov ?? r.fov) - (r.fov ?? t.fov)) * n : void 0;
|
|
67
|
+
return { position: c, lookAt: f, fov: u };
|
|
68
|
+
}
|
|
69
|
+
function L(e) {
|
|
70
|
+
const s = Math.max(1, e.every ?? 33), n = C(e.easing ?? "ease-in-out"), r = `${e.scene}/${e.camera}`, t = [], o = [], c = [];
|
|
71
|
+
for (let u = e.start; ; u = Math.min(e.end, u + s)) {
|
|
72
|
+
const h = e.end > e.start ? n((u - e.start) / (e.end - e.start)) : 1, l = F(e.from, e.to, h);
|
|
73
|
+
if (t.push({ time: u, value: l.position }), o.push({ time: u, value: l.lookAt }), l.fov !== void 0 && c.push({ time: u, value: l.fov }), u >= e.end) break;
|
|
74
|
+
}
|
|
75
|
+
const f = [
|
|
76
|
+
{ id: `${r}-move-position`, target: r, property: "position", keyframes: t },
|
|
77
|
+
{ id: `${r}-move-lookAt`, target: r, property: "lookAt", keyframes: o }
|
|
78
|
+
];
|
|
79
|
+
return c.length > 0 && f.push({ id: `${r}-move-fov`, target: r, property: "fov", keyframes: c }), f;
|
|
80
|
+
}
|
|
81
|
+
function O(e) {
|
|
82
|
+
const s = Math.max(1, e.every ?? 33), n = e.offset ?? [0, 2, 6], r = e.lag ?? 0, t = `${e.scene}/${e.camera}`, o = [], c = [];
|
|
83
|
+
for (let f = e.start; ; f = Math.min(e.end, f + s)) {
|
|
84
|
+
const u = e.subjectAt(f), h = e.subjectAt(Math.max(e.start, f - r));
|
|
85
|
+
if (o.push({ time: f, value: [h[0] + n[0], h[1] + n[1], h[2] + n[2]] }), c.push({ time: f, value: u }), f >= e.end) break;
|
|
86
|
+
}
|
|
87
|
+
return [
|
|
88
|
+
{ id: `${t}-follow-position`, target: t, property: "position", keyframes: o },
|
|
89
|
+
{ id: `${t}-follow-lookAt`, target: t, property: "lookAt", keyframes: c }
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
function R(e, s) {
|
|
93
|
+
const n = `${s.scene}/${s.camera}`, r = s.amount ?? 0.04, t = s.aim ?? 0.08, o = s.rate ?? 1.2, c = Math.max(1, s.every ?? 33), f = s.end - s.start, u = Math.max(1, f), h = Math.max(1, Math.round(u / 1e3 * o)), l = typeof s.seed == "string" ? s.seed : `handheld-${s.seed ?? 0}`, m = (a, d) => S(a - s.start, { period: u, seed: `${l}-${d}`, cycles: h, octaves: 2 }), b = e.filter((a) => a.target === n), T = e.filter((a) => a.target !== n), x = (a, d, g) => {
|
|
94
|
+
const y = b.find((i) => i.property === a), M = [];
|
|
95
|
+
if (y)
|
|
96
|
+
for (const i of y.keyframes) {
|
|
97
|
+
const p = i.value;
|
|
98
|
+
M.push({ time: i.time, value: [p[0] + m(i.time, `${a}x`) * d, p[1] + m(i.time, `${a}y`) * d, p[2] + m(i.time, `${a}z`) * d * 0.5], easing: i.easing });
|
|
99
|
+
}
|
|
100
|
+
else if (g)
|
|
101
|
+
for (let i = s.start; M.push({ time: i, value: [g[0] + m(i, `${a}x`) * d, g[1] + m(i, `${a}y`) * d, g[2] + m(i, `${a}z`) * d * 0.5] }), !(i >= s.end); i = Math.min(s.end, i + c))
|
|
102
|
+
;
|
|
103
|
+
else return;
|
|
104
|
+
return { id: y?.id ?? `${n}-handheld-${a}`, target: n, property: a, keyframes: M };
|
|
105
|
+
}, $ = [...T, ...b.filter((a) => a.property !== "position" && a.property !== "lookAt")], j = x("position", r, s.base?.position), P = x("lookAt", t, s.base?.lookAt);
|
|
106
|
+
return j && $.push(j), P && $.push(P), $;
|
|
107
|
+
}
|
|
108
|
+
export {
|
|
109
|
+
R as a,
|
|
110
|
+
L as b,
|
|
111
|
+
O as c,
|
|
112
|
+
F as d,
|
|
113
|
+
Q as e,
|
|
114
|
+
B as f,
|
|
115
|
+
G as g,
|
|
116
|
+
D as h,
|
|
117
|
+
J as i,
|
|
118
|
+
q as l,
|
|
119
|
+
A as o,
|
|
120
|
+
H as p,
|
|
121
|
+
E as r,
|
|
122
|
+
N as s,
|
|
123
|
+
I as t,
|
|
124
|
+
K as w
|
|
125
|
+
};
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { c as L, C as he, S as ye, o as Se, a as Oe, s as xe, H as S, b as Re, r as Ie, d as He, e as qe, f as le, g as se, h as ze, i as Be } from "./cricket-camera-BWByoNgz.js";
|
|
2
|
+
import { j as nt, k as ot, l as st } from "./cricket-camera-BWByoNgz.js";
|
|
3
|
+
import { vec3 as k, quat as ve } from "@algorisys/tinyfly";
|
|
4
|
+
function pe(t, i) {
|
|
5
|
+
if (!Array.isArray(t) || t.length !== 3 || !t.every(Number.isFinite)) throw new Error(`${i}: expected three finite coordinates`);
|
|
6
|
+
}
|
|
7
|
+
function Ae(t, i, e = 40, n = []) {
|
|
8
|
+
if (!Number.isFinite(t) || !Number.isFinite(i) || t < 0 || i < t) throw new Error("sampleTimes: expected finite ordered nonnegative times");
|
|
9
|
+
if (!Number.isFinite(e) || e < 16 || e > 1e3) throw new Error("sampleTimes: every must be between 16 and 1000 ms");
|
|
10
|
+
if ((i - t) / e > 2e4) throw new Error("sampleTimes: too many samples");
|
|
11
|
+
const o = /* @__PURE__ */ new Set([t, i, ...n.filter((s) => s >= t && s <= i && Number.isFinite(s))]);
|
|
12
|
+
for (let s = t + e; s < i; s += e) o.add(s);
|
|
13
|
+
return [...o].sort((s, c) => s - c);
|
|
14
|
+
}
|
|
15
|
+
function Ee(t, i) {
|
|
16
|
+
if (Ce(t), !Number.isFinite(i)) throw new Error("ballFlightPoint: time must be finite");
|
|
17
|
+
const e = Math.max(0, Math.min(1, (i - t.start) / (t.end - t.start))), n = 4 * e * (1 - e), o = t.to[0] - t.from[0], s = t.to[2] - t.from[2], c = Math.hypot(o, s) || 1;
|
|
18
|
+
return [
|
|
19
|
+
t.from[0] + o * e - s / c * (t.curve ?? 0) * n,
|
|
20
|
+
t.from[1] + (t.to[1] - t.from[1]) * e + (t.arc ?? 0) * n,
|
|
21
|
+
t.from[2] + s * e + o / c * (t.curve ?? 0) * n
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
function Ce(t) {
|
|
25
|
+
if (!t.target?.trim()) throw new Error("ballFlight: target is required");
|
|
26
|
+
if (pe(t.from, "ballFlight.from"), pe(t.to, "ballFlight.to"), !Number.isFinite(t.start) || !Number.isFinite(t.end) || t.start < 0 || t.end <= t.start) throw new Error("ballFlight: end must be greater than start, both finite and nonnegative");
|
|
27
|
+
if (!Number.isFinite(t.arc ?? 0) || (t.arc ?? 0) < 0 || !Number.isFinite(t.curve ?? 0)) throw new Error("ballFlight: arc must be finite and nonnegative; curve must be finite");
|
|
28
|
+
}
|
|
29
|
+
function Xe(t) {
|
|
30
|
+
Ce(t);
|
|
31
|
+
const i = Ae(t.start, t.end, t.every), e = i.map((n) => Ee(t, n));
|
|
32
|
+
return ["x", "y", "z"].map((n, o) => ({
|
|
33
|
+
id: `${t.id ?? "flight"}-${n}`,
|
|
34
|
+
target: t.target,
|
|
35
|
+
property: n,
|
|
36
|
+
keyframes: i.map((s, c) => ({ time: s, value: e[c][o] }))
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
const P = Object.freeze({ length: 20.12, width: 3.05, poppingCrease: 1.22, returnCrease: 1.32, stumpHeight: 0.711, wicketWidth: 0.2286 });
|
|
40
|
+
function _e(t) {
|
|
41
|
+
if (!t.id?.trim()) throw new Error("cricketPlayer: id is required");
|
|
42
|
+
L({ batter: 1, bowler: 1, keeper: 1, fielder: 1, umpire: 1 }, t.role, "cricketPlayer.role");
|
|
43
|
+
const i = L(ye, t.preset ?? "youngMan", "cricketPlayer.preset"), e = L(he, t.format ?? "t20", "cricketPlayer.format"), n = L({ none: 1, cap: 1, "sun-hat": 1 }, t.headwear ?? "none", "cricketPlayer.headwear"), o = i === "childBoy" || i === "childGirl", s = t.height ?? (o ? 1.24 : 1.78);
|
|
44
|
+
if (!Number.isFinite(s) || s < 0.5 || s > 3) throw new Error("cricketPlayer: height must be between .5 and 3 metres");
|
|
45
|
+
pe(t.position ?? [0, 0, 0], "cricketPlayer.position");
|
|
46
|
+
const c = t.role === "umpire" ? "#f5ebd5" : e === "test" ? "#f5f0df" : t.color ?? "#3577b5", g = JSON.parse(JSON.stringify({
|
|
47
|
+
...ye[i],
|
|
48
|
+
...t.appearance,
|
|
49
|
+
outfit: Se("casual", { top: "shirt", shirt: c, trousers: t.role === "umpire" ? "#405058" : c, bottom: "trousers", trouserStyle: "plain", sleeves: "short", collar: !0, tie: null, shoes: "boots", shoeColor: "#f3ead7" }),
|
|
50
|
+
hat: n === "none" ? null : { style: n === "sun-hat" ? "sunHat" : "cap", color: c }
|
|
51
|
+
}));
|
|
52
|
+
return { id: t.id, name: t.role, kind: "character", look: "pen", height: s, position: [...t.position ?? [0, 0, 0]], character: g, pose: { turn: t.role === "batter" || t.role === "keeper" ? 2 : 0 } };
|
|
53
|
+
}
|
|
54
|
+
function ce(t, i, e, n, o = 0) {
|
|
55
|
+
return { id: t, kind: "mesh", position: i, geometry: { type: "box", size: e }, material: n, layer: o };
|
|
56
|
+
}
|
|
57
|
+
function We(t, i) {
|
|
58
|
+
const e = P.stumpHeight, n = (P.wicketWidth - 0.036) / 2;
|
|
59
|
+
return [
|
|
60
|
+
...[-1, 0, 1].map((o, s) => ({ id: `${t}-stump-${s}`, kind: "mesh", position: [o * n, e / 2, i], geometry: { type: "cylinder", radius: 0.018, height: e, segments: 10 }, material: "wicket" })),
|
|
61
|
+
...[-1, 1].map((o, s) => ce(`${t}-bail-${s}`, [o * n / 2, e + 0.015, i], [0.105, 0.025, 0.035], "bail"))
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
function $e(t, i) {
|
|
65
|
+
return [
|
|
66
|
+
{ id: t, kind: "group", scale: i, visible: !1 },
|
|
67
|
+
ce(`${t}-grip`, [0, 0.1, 0], [0.036, 0.28, 0.036], "bat-grip"),
|
|
68
|
+
ce(`${t}-blade`, [0, 0.51, 0], [0.108, 0.54, 0.055], "bat-blade"),
|
|
69
|
+
ce(`${t}-label`, [0, 0.41, 0.029], [0.07, 0.16, 4e-3], "bat-label")
|
|
70
|
+
].map((n, o) => o === 0 ? n : { ...n, parent: t });
|
|
71
|
+
}
|
|
72
|
+
function Le(t = {}) {
|
|
73
|
+
const i = L(he, t.format ?? "t20", "cricketField.format"), e = L({ adults: 1, children: 1, mixed: 1 }, t.cast ?? "adults", "cricketField.cast"), n = t.boundaryRadius ?? 64;
|
|
74
|
+
if (!Number.isFinite(n) || n < 24 || n > 250) throw new Error("cricketField: boundaryRadius must be between 24 and 250 metres");
|
|
75
|
+
const o = t.id ?? "cricket";
|
|
76
|
+
if (!o.trim()) throw new Error("cricketField: id is required");
|
|
77
|
+
const s = P.length / 2, c = {
|
|
78
|
+
"striker-wicket": [0, 0, s],
|
|
79
|
+
"bowler-wicket": [0, 0, -s],
|
|
80
|
+
"striker-crease": [0, 0, s - P.poppingCrease],
|
|
81
|
+
"bowler-crease": [0, 0, -s + P.poppingCrease]
|
|
82
|
+
}, g = [
|
|
83
|
+
{ id: "camera", kind: "camera", projection: "perspective", position: [25, 9, 6], lookAt: [0, 0.65, 0], fov: 48, near: 0.02, far: Math.max(600, n * 4) },
|
|
84
|
+
{ id: "sun", kind: "light", light: "directional", position: [4, 8, 5], intensity: 0.8, color: "#fff2dd" },
|
|
85
|
+
{ id: "ambient", kind: "light", light: "ambient", intensity: 0.85, color: "#eaf6f4" },
|
|
86
|
+
{ id: "outfield", kind: "mesh", layer: -4, position: [0, -0.04, 0], geometry: { type: "cylinder", radius: n + 1, height: 0.06, segments: 80 }, material: "grass" },
|
|
87
|
+
{ id: "square", kind: "mesh", layer: -3, geometry: { type: "plane", size: [8, 25] }, position: [0, 3e-3, 0], material: "square" },
|
|
88
|
+
{ id: "pitch", kind: "mesh", layer: -2, geometry: { type: "plane", size: [P.width, P.length] }, position: [0, 8e-3, 0], material: "pitch" },
|
|
89
|
+
{ id: "boundary", kind: "line", layer: -1, closed: !0, width: 0.15, color: "#f8f2db", points: Array.from({ length: 96 }, (h, v) => [Math.cos(v * Math.PI / 48) * n, 0.022, Math.sin(v * Math.PI / 48) * n]) }
|
|
90
|
+
];
|
|
91
|
+
i !== "test" && g.push({ id: "fielding-circle", kind: "line", layer: -1, closed: !0, width: 0.06, color: "#d6e4c8", points: Array.from({ length: 80 }, (h, v) => [Math.cos(v * Math.PI / 40) * 27.43, 0.018, Math.sin(v * Math.PI / 40) * 27.43]) });
|
|
92
|
+
for (const h of [-1, 1]) {
|
|
93
|
+
const v = h > 0 ? "striker" : "bowler", M = h * s, H = M - h * P.poppingCrease;
|
|
94
|
+
g.push(...We(v, M));
|
|
95
|
+
const q = (z, G) => g.push({ id: `${v}-${z}`, kind: "line", layer: -1, color: "#fffdf0", width: 0.045, points: G });
|
|
96
|
+
q("popping-line", [[-1.83, 0.02, H], [1.83, 0.02, H]]), q("bowling-line", [[-1.32, 0.02, M], [1.32, 0.02, M]]);
|
|
97
|
+
for (const z of [-1, 1]) q(`return-line-${z < 0 ? "left" : "right"}`, [[z * 1.32, 0.02, H], [z * 1.32, 0.02, M + h * 2.5]]);
|
|
98
|
+
}
|
|
99
|
+
[
|
|
100
|
+
["batter", "batter", [0.38, 0, 9.3]],
|
|
101
|
+
["non-striker", "batter", [-0.85, 0, -9.3]],
|
|
102
|
+
["bowler", "bowler", [0.68, 0, -17]],
|
|
103
|
+
["keeper", "keeper", [0, 0, 11.25]],
|
|
104
|
+
["fielder", "fielder", [12, 0, -3]],
|
|
105
|
+
["slip", "fielder", [3.5, 0, 12]],
|
|
106
|
+
["point", "fielder", [20, 0, 6]],
|
|
107
|
+
["cover", "fielder", [22, 0, -16]],
|
|
108
|
+
["mid-off", "fielder", [9, 0, -25]],
|
|
109
|
+
["mid-on", "fielder", [-9, 0, -25]],
|
|
110
|
+
["square-leg", "fielder", [-20, 0, 7]],
|
|
111
|
+
["fine-leg", "fielder", [-20, 0, 35]],
|
|
112
|
+
["third-man", "fielder", [23, 0, 35]],
|
|
113
|
+
["umpire", "umpire", [0, 0, -12.4]],
|
|
114
|
+
["square-umpire", "umpire", [-15, 0, 8.84]]
|
|
115
|
+
].forEach(([h, v, M], H) => {
|
|
116
|
+
const z = e === "children" || e === "mixed" && H % 3 === 0 ? H % 2 ? "childGirl" : "childBoy" : H % 2 ? "youngWoman" : "youngMan", G = Math.hypot(M[0], M[2]), B = G > n * 0.88 ? [M[0] * n * 0.88 / G, 0, M[2] * n * 0.88 / G] : [...M];
|
|
117
|
+
c[h] = [...B];
|
|
118
|
+
const j = _e({ id: h, role: v, preset: z, format: i, position: B, color: v === "batter" ? t.battingColor ?? "#397cb9" : t.fieldingColor ?? "#bf604e" });
|
|
119
|
+
h === "non-striker" && (j.pose = { turn: 0 }), g.push(j);
|
|
120
|
+
});
|
|
121
|
+
const d = (h) => g.find((v) => v.id === h).height / 1.78;
|
|
122
|
+
g.push(...$e("bat", d("batter")), ...$e("non-striker-bat", d("non-striker"))), g.push({ id: "ball", kind: "mesh", position: [0, 0.075, 0], geometry: { type: "sphere", radius: 0.075, segments: 12 }, material: "ball" }), g.push({ id: "lbw-guide", kind: "group", visible: !1 }, { id: "lbw-projection", kind: "line", parent: "lbw-guide", points: [[0, 0, 0], [0, 1, 0]], width: 0.04, color: "#e9ae38" });
|
|
123
|
+
const b = (h) => ({ color: h, shading: "toon", outline: { color: "#69513a", width: 0.8 } });
|
|
124
|
+
return { format: i, boundaryRadius: n, landmarks: c, scene: {
|
|
125
|
+
id: o,
|
|
126
|
+
formatVersion: 1,
|
|
127
|
+
camera: "camera",
|
|
128
|
+
background: { top: "#c8e5ef", bottom: "#e9efcc" },
|
|
129
|
+
ground: 0,
|
|
130
|
+
objects: g,
|
|
131
|
+
materials: {
|
|
132
|
+
grass: { color: "#81a95c", shading: "unlit" },
|
|
133
|
+
square: { color: "#a6b76a", shading: "unlit", doubleSided: !0 },
|
|
134
|
+
pitch: { color: "#ddbd85", shading: "unlit", doubleSided: !0 },
|
|
135
|
+
wicket: b("#edd99e"),
|
|
136
|
+
bail: b("#bd8c4d"),
|
|
137
|
+
"bat-grip": b("#385b5c"),
|
|
138
|
+
"bat-blade": b("#e8c58d"),
|
|
139
|
+
"bat-label": b("#c34d4c"),
|
|
140
|
+
ball: { color: i === "test" ? "#b32d36" : "#fff9e7", shading: "toon", outline: { color: "#9b3840", width: 1 } }
|
|
141
|
+
}
|
|
142
|
+
} };
|
|
143
|
+
}
|
|
144
|
+
const C = (t, i, e) => Math.max(0, Math.min(1, (t - i) / (e - i))), F = (t) => t * t * (3 - 2 * t), y = (t, i) => k.add(t, i), we = (t, i) => k.scale(t, i);
|
|
145
|
+
function Ge(t, i) {
|
|
146
|
+
const e = t.objects.find((n) => n.id === i);
|
|
147
|
+
if (!e || e.kind !== "character") throw new Error(`cricketAction: required character '${i}' is missing`);
|
|
148
|
+
if (e.parent || e.rotation?.some((n) => n !== 0) || e.quaternion || e.scale !== void 0) throw new Error(`cricketAction: '${i}' must use position and pose.turn, without a transformed parent, scale or object rotation`);
|
|
149
|
+
return { object: e, who: Oe({ ...e.character, height: e.height ?? 1.78 }) };
|
|
150
|
+
}
|
|
151
|
+
function Ke(t) {
|
|
152
|
+
return { position: [...t.object.position ?? [0, 0, 0]], pose: { ...S, ...t.object.pose } };
|
|
153
|
+
}
|
|
154
|
+
function ee(t, i, e, n) {
|
|
155
|
+
const o = xe(t.who.plan, i.pose, { height: t.who.height, contact: t.who.contact });
|
|
156
|
+
return y(i.position, o.chains[e][n]);
|
|
157
|
+
}
|
|
158
|
+
function te(t, i, e) {
|
|
159
|
+
const n = ee(t, i, `arm.${e}`, 2), o = ee(t, i, `arm.${e}`, 1);
|
|
160
|
+
return y(n, we(k.normalize(k.subtract(n, o)), t.who.lineWidth * 0.5));
|
|
161
|
+
}
|
|
162
|
+
function W(t, i, e, n, o = "hold") {
|
|
163
|
+
let s = { ...i.pose };
|
|
164
|
+
for (let c = 0; c < 10; c++) {
|
|
165
|
+
const g = { ...i, pose: s }, p = xe(t.who.plan, s, { height: t.who.height, contact: t.who.contact }), d = Re(t.who.plan, s, t.who.height), b = k.subtract(te(t, g, e), ee(t, g, `arm.${e}`, 2)), h = k.subtract(k.subtract(k.subtract(n, b), i.position), p.hip), v = Ie(h, (s.roll ?? 0) * Math.PI / 180), M = y(d.root, He(v, -(s.turn ?? 0) * Math.PI / 2));
|
|
166
|
+
s = qe(t.who.plan, s, `arm.${e}`, M, { height: t.who.height });
|
|
167
|
+
}
|
|
168
|
+
for (const [c, g] of Object.entries(le[o])) s[`hand.${e}.${c}`] = g;
|
|
169
|
+
return { ...i, pose: s };
|
|
170
|
+
}
|
|
171
|
+
function Ve(t, i, e, n) {
|
|
172
|
+
const o = k.normalize(n), s = t.who.height / 1.78;
|
|
173
|
+
let c = W(t, i, "right", e);
|
|
174
|
+
return c = W(t, c, "left", y(te(t, c, "right"), we(o, 0.105 * s))), { ...c, bat: { grip: te(t, c, "right"), axis: o, scale: s } };
|
|
175
|
+
}
|
|
176
|
+
function Je(t) {
|
|
177
|
+
return y(t.grip, we(t.axis, 0.51 * t.scale));
|
|
178
|
+
}
|
|
179
|
+
function Me(t) {
|
|
180
|
+
const i = k.normalize(t), e = Math.max(-1, Math.min(1, i[1]));
|
|
181
|
+
return e > 0.999999 ? [0, 0, 0, 1] : e < -0.999999 ? ve.fromAxisAngle([1, 0, 0], 180) : ve.fromAxisAngle(k.normalize(k.cross([0, 1, 0], i)), Math.acos(e) * 180 / Math.PI).map((n) => n === 0 ? 0 : n);
|
|
182
|
+
}
|
|
183
|
+
function ue(t, i, e) {
|
|
184
|
+
const n = {};
|
|
185
|
+
for (const o of Object.keys({ ...t, ...i })) {
|
|
186
|
+
const s = t[o] ?? S[o] ?? 0;
|
|
187
|
+
n[o] = s + ((i[o] ?? S[o] ?? 0) - s) * e;
|
|
188
|
+
}
|
|
189
|
+
return n;
|
|
190
|
+
}
|
|
191
|
+
function Te(t, i) {
|
|
192
|
+
if (t <= i[0][0]) return { ...S, ...i[0][1] };
|
|
193
|
+
for (let e = 1; e < i.length; e++)
|
|
194
|
+
if (t <= i[e][0]) return ue({ ...S, ...i[e - 1][1] }, { ...S, ...i[e][1] }, F(C(t, i[e - 1][0], i[e][0])));
|
|
195
|
+
return { ...S, ...i.at(-1)[1] };
|
|
196
|
+
}
|
|
197
|
+
const I = 1900, Q = 2450, m = 2900, X = 4100, _ = 4200, U = 4600, ae = 5300, fe = 5500;
|
|
198
|
+
function ge(t, i, e, n, o, s) {
|
|
199
|
+
const c = C(i, e, n), g = k.distance(o, s), p = Math.atan2(s[0] - o[0], s[2] - o[2]) * 2 / Math.PI, d = { ...S, ...t.object.pose, turn: p }, b = ze("run", t.who.height, 1, t.object.character?.legLength ?? 1), h = Be("run", g * c / b, d), v = Math.min(c * 12, (1 - c) * 12, 1);
|
|
200
|
+
return { position: k.lerp(o, s, c), pose: ue(d, h, Math.max(0, v)) };
|
|
201
|
+
}
|
|
202
|
+
function be(t, i, e) {
|
|
203
|
+
const n = (t.pose.turn ?? 0) * Math.PI / 2;
|
|
204
|
+
return y(t.position, [Math.sin(n) * i, e, Math.cos(n) * i]);
|
|
205
|
+
}
|
|
206
|
+
function Ue(t, i, e, n, o) {
|
|
207
|
+
const s = `${i}/${e.object.id}`, c = { ...S, ...e.object.pose }, g = new Set(o.flatMap((p) => Object.keys(p.pose)));
|
|
208
|
+
for (const p of g) {
|
|
209
|
+
const d = c[p] ?? 0;
|
|
210
|
+
o.some((b) => b.pose[p] !== d) && t.push({ id: `${e.object.id}-${p}`, target: s, property: p, keyframes: n.map((b, h) => ({ time: b, value: o[h].pose[p] ?? d })) });
|
|
211
|
+
}
|
|
212
|
+
for (const [p, d] of ["x", "y", "z"].entries())
|
|
213
|
+
o.some((b) => b.position[p] !== (e.object.position?.[p] ?? 0)) && t.push({ id: `${e.object.id}-${d}`, target: s, property: d, keyframes: n.map((b, h) => ({ time: b, value: o[h].position[p] })) });
|
|
214
|
+
if (o[0].bat) {
|
|
215
|
+
const p = e.object.id === "batter" ? "bat" : "non-striker-bat", d = `${i}/${p}`;
|
|
216
|
+
t.push({ id: `${p}-visible`, target: d, property: "visible", keyframes: [{ time: 0, value: 1 }] }), t.push({ id: `${p}-position`, target: d, property: "position", keyframes: n.map((b, h) => ({ time: b, value: [...o[h].bat.grip] })) }), t.push({ id: `${p}-rotation`, target: d, property: "quaternion", interpolation: "slerp", keyframes: n.map((b, h) => ({ time: b, value: Me(o[h].bat.axis) })) });
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function De(t, i) {
|
|
220
|
+
const e = { runs: 0, extras: 0, wickets: 0, legalBall: !0, freeHitNext: !1 };
|
|
221
|
+
t === "running" && (e.runs = 1), t === "four" && (e.runs = 4), t === "six" && (e.runs = 6), (t === "wide" || t === "no-ball") && (e.extras = 1, e.legalBall = !1), t === "no-ball" && (e.freeHitNext = he[i].freeHitAfterNoBall);
|
|
222
|
+
const o = { catch: "caught", bowled: "bowled", lbw: "lbw", stumping: "stumped", "run-out": "run-out" }[t];
|
|
223
|
+
return o && (e.wickets = 1, e.dismissal = o), e;
|
|
224
|
+
}
|
|
225
|
+
function Ye(t, i = {}) {
|
|
226
|
+
const e = L(se, i.action ?? "bowling", "cricketAction.action");
|
|
227
|
+
L(he, t.format, "cricketAction.format");
|
|
228
|
+
const n = i.duration ?? 6e3;
|
|
229
|
+
if (!Number.isFinite(n) || n < 4e3 || n > 6e4) throw new Error("cricketAction: duration must be between 4000 and 60000 ms");
|
|
230
|
+
const o = t.scene.id;
|
|
231
|
+
for (const r of ["ball", "bat", "non-striker-bat", "lbw-guide", "striker-bail-0", "striker-bail-1", "bowler-bail-0", "bowler-bail-1"])
|
|
232
|
+
if (!t.scene.objects.some((l) => l.id === r)) throw new Error(`cricketAction: required equipment '${r}' is missing`);
|
|
233
|
+
const s = Object.fromEntries(["batter", "non-striker", "bowler", "keeper", "fielder", "umpire"].map((r) => [r, Ge(t.scene, r)])), c = (r) => s[r].who.height, g = (r) => Ke(s[r]), p = (r) => Math.round(r * 6e3 / n * 1e9) / 1e9, d = (r) => r * n / 6e3, b = ["batting", "defend", "running", "four", "six", "catch", "fielding", "throw", "run-out"].includes(e), h = ["bowling", "spin", "no-ball", "stumping"].includes(e), v = ["catch", "fielding", "throw", "run-out", "batting", "running"].includes(e), M = e === "running" || e === "run-out", H = /* @__PURE__ */ new Map(), q = [g("bowler").position[0], 0, e === "no-ball" ? -8.25 : -9.55], z = e === "fielding" ? [10.5, 0, 2] : [9, 0, -1], G = g("fielder").position, B = (r, l) => {
|
|
234
|
+
let x = H.get(r);
|
|
235
|
+
x || (x = /* @__PURE__ */ new Map(), H.set(r, x));
|
|
236
|
+
const f = x.get(l);
|
|
237
|
+
if (f) return f;
|
|
238
|
+
const w = s[r];
|
|
239
|
+
let a = g(r);
|
|
240
|
+
if (r === "bowler") {
|
|
241
|
+
const u = a.position;
|
|
242
|
+
if (l < 1400) {
|
|
243
|
+
const E = y(q, [0, 0, -0.65]);
|
|
244
|
+
a = ge(w, l, 0, 1400, u, E), a.pose["arm.right.swing"] = 45, a.pose["arm.right.elbow"] = 80;
|
|
245
|
+
} else
|
|
246
|
+
a.position = l <= I ? k.lerp(y(q, [0, 0, -0.65]), q, F(C(l, 1400, I))) : y(q, [0, 0, 0.8 * F(C(l, I, 2600))]), a.pose = Te(l, [
|
|
247
|
+
[1400, { turn: 0, "arm.right.swing": 285, "arm.right.elbow": 8, "arm.left.swing": 115, "leg.right.swing": 15, "leg.left.knee": 45 }],
|
|
248
|
+
[1800, { turn: 0, "arm.right.swing": 180, "arm.right.elbow": 0, "arm.left.swing": 80, "leg.right.swing": 25, "leg.right.knee": 0, "leg.left.swing": -25, "leg.left.knee": 60 }],
|
|
249
|
+
[I, { turn: 0, lean: 8, "arm.right.swing": 155, "arm.right.elbow": 0, "arm.left.swing": 45, "leg.right.swing": 25, "leg.right.knee": 0, "leg.left.swing": -25, "leg.left.knee": 60 }],
|
|
250
|
+
[2250, { turn: 0, lean: 26, bend: 12, "arm.right.swing": 40, "arm.right.elbow": 0, "arm.left.swing": -35, "leg.left.swing": -35, "leg.left.knee": 55 }],
|
|
251
|
+
[3e3, { turn: 0, "head.turn": 10 }],
|
|
252
|
+
[6e3, { turn: 0, "head.turn": 10 }]
|
|
253
|
+
]);
|
|
254
|
+
e === "spin" && (a.pose = { ...a.pose, "arm.right.spread": 18, "head.tilt": -5 });
|
|
255
|
+
for (const [E, N] of Object.entries(l < I ? le.hold : le.open)) a.pose[`hand.right.${E}`] = N;
|
|
256
|
+
} else if (r === "batter" || r === "non-striker") {
|
|
257
|
+
const u = c(r);
|
|
258
|
+
if (e === "lbw" && r === "batter" && (a.position[0] = 0), e === "stumping" && r === "batter" && (a.position[2] -= 1.1 * F(C(l, 2150, 2800))), M && l > 3050) {
|
|
259
|
+
const E = a.position;
|
|
260
|
+
a = ge(w, l, 3050, e === "run-out" ? 6e3 : fe, E, r === "batter" ? [1, 0, -9.5] : [-1, 0, 9.5]);
|
|
261
|
+
const J = te(w, a, "right");
|
|
262
|
+
a.bat = { grip: J, axis: k.normalize([0.7, -0.35, 0.5]), scale: u / 1.78 };
|
|
263
|
+
} else {
|
|
264
|
+
a.pose = { ...a.pose, "leg.left.spread": 10, "leg.right.spread": 10, "leg.left.knee": 10, "leg.right.knee": 8, "head.turn": r === "batter" ? 12 : -12 };
|
|
265
|
+
const E = r === "batter" ? -1 : 1, N = [0, -1, E * 0.12];
|
|
266
|
+
let R = N, J = y(a.position, [-0.18, u * 0.49, E * 0.22 * u]);
|
|
267
|
+
if (r === "batter") {
|
|
268
|
+
const Y = F(C(l, 2100, 2600)) * (1 - F(C(l, 2600, m))), oe = F(C(l, 2600, m)) * (1 - F(C(l, m, 3800))), Z = F(C(l, m, 3250)) * (1 - F(C(l, 3250, 4e3)));
|
|
269
|
+
b ? (J = y(a.position, [-0.18 - 0.08 * oe - 0.13 * Z, u * (0.49 + 0.12 * Y + 0.13 * Z), u * (-0.22 + 0.18 * Y - 0.035 * oe)]), R = k.normalize([0.45 * Y - 0.85 * Z, -1 + 1.9 * Y + 0.8 * Z, -0.12 + 0.8 * Y - 0.4 * oe - 0.45 * Z]), e === "defend" && (R = N, J = y(a.position, [-0.18, u * 0.49, -0.27 * u])), a.pose.lean = 5 + 8 * oe) : ["stumping", "bowled", "lbw"].includes(e) && (R = k.normalize([-0.5, 0.7, 0.4]), J = y(a.position, [-0.1, u * 0.64, -0.1 * u]));
|
|
270
|
+
}
|
|
271
|
+
a = Ve(w, a, J, R);
|
|
272
|
+
}
|
|
273
|
+
} else if (r === "keeper") {
|
|
274
|
+
a.pose = { ...a.pose, turn: 2, lean: 20, "leg.left.swing": 22, "leg.right.swing": 22, "leg.left.knee": 50, "leg.right.knee": 50 }, e === "wide" && (a.position[0] = 2.15 * F(C(l, 2900, 3500))), e === "stumping" && (a.position[2] -= 0.85 * F(C(l, 3400, 3900)));
|
|
275
|
+
const u = be(a, c(r) * 0.27, c(r) * 0.44);
|
|
276
|
+
if (e === "stumping" && l >= 3500) {
|
|
277
|
+
const E = be({ ...a, position: g(r).position }, c(r) * 0.27, c(r) * 0.44), N = [0, P.stumpHeight, P.length / 2], R = k.lerp(E, N, F(C(l, 3500, 3900)));
|
|
278
|
+
a = W(w, a, "right", R), a = W(w, a, "left", y(R, [0.045, 0, 0]));
|
|
279
|
+
} else
|
|
280
|
+
a = W(w, a, "right", u), a = W(w, a, "left", y(u, [0.045, 0, 0]));
|
|
281
|
+
} else if (r === "fielder" && v) {
|
|
282
|
+
if (a = ge(w, l, 3050, e === "catch" ? 3800 : 3950, G, z), a.pose.turn = -0.55, l >= 3800) {
|
|
283
|
+
const u = { ...S, turn: -0.55, lean: e === "catch" ? 5 : 42, bend: e === "catch" ? 0 : 18, "leg.left.swing": e === "catch" ? 0 : 45, "leg.right.swing": e === "catch" ? 0 : 45, "leg.left.knee": e === "catch" ? 0 : 85, "leg.right.knee": e === "catch" ? 0 : 85, smile: 0.7 };
|
|
284
|
+
a.pose = ue(a.pose, u, F(C(l, 3800, _)));
|
|
285
|
+
const E = be(a, c(r) * 0.22, c(r) * (e === "catch" ? 0.73 : 0.2));
|
|
286
|
+
if (a = W(w, a, "right", E), a = W(w, a, "left", y(E, [0.035, 0, 0])), (e === "throw" || e === "run-out") && l > _) {
|
|
287
|
+
const N = { ...S, turn: e === "throw" ? -0.75 : -1.5, "arm.right.swing": 225, "arm.right.elbow": 60, "arm.left.spread": 70, "leg.left.swing": 15 }, R = { ...N, "arm.right.swing": 110, "arm.right.elbow": 0, lean: 15 };
|
|
288
|
+
a.pose = Te(l, [[_, a.pose], [4450, N], [U, R], [4900, { ...S, turn: N.turn, "arm.right.swing": 25, lean: 22 }], [6e3, { ...S, turn: N.turn }]]);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
} else if (r === "umpire") {
|
|
292
|
+
let u = { ...S };
|
|
293
|
+
const E = e === "stumping" ? 4150 : e === "run-out" ? 5150 : e === "bowled" || e === "lbw" ? 3500 : e === "catch" ? 4350 : 5100;
|
|
294
|
+
if (e === "no-ball") u = { ...u, "arm.right.spread": 90, "arm.right.elbow": 0 };
|
|
295
|
+
else if (e === "wide") u = { ...u, "arm.right.spread": 90, "arm.left.spread": 90, "arm.right.elbow": 0, "arm.left.elbow": 0 };
|
|
296
|
+
else if (e === "six") u = { ...u, "arm.right.spread": 180, "arm.left.spread": 180, "arm.right.elbow": 0, "arm.left.elbow": 0 };
|
|
297
|
+
else if (e === "four") u = { ...u, "arm.right.spread": 90 - 70 * (0.5 + Math.sin((l - 5100) / 180) * 0.5), "arm.right.elbow": 12 };
|
|
298
|
+
else if (["catch", "bowled", "lbw", "stumping", "run-out"].includes(e)) {
|
|
299
|
+
u = { ...u, "arm.right.swing": 165, "arm.right.elbow": 0 };
|
|
300
|
+
for (const [N, R] of Object.entries(le.point)) u[`hand.right.${N}`] = R;
|
|
301
|
+
}
|
|
302
|
+
a.pose = ue(a.pose, u, F(C(l, e === "no-ball" ? I : e === "wide" ? 3100 : E, (e === "no-ball" ? I : e === "wide" ? 3100 : E) + 350)));
|
|
303
|
+
}
|
|
304
|
+
return x.set(l, a), a;
|
|
305
|
+
}, j = (r, l) => te(s[r], B(r, l), "right"), A = b ? Je(B("batter", m).bat) : e === "lbw" ? k.lerp(ee(s.batter, B("batter", m), "leg.right", 1), ee(s.batter, B("batter", m), "leg.right", 2), 0.6) : [h ? -(P.wicketWidth / 2 + 0.075 + 0.15) : 0, 0.45, 9.25], Fe = j("bowler", I), me = [e === "wide" ? 0.85 : e === "spin" ? -0.35 : e === "lbw" ? A[0] * 0.6 : 0, 0.075, 3.9], re = j("keeper", e === "stumping" ? 3400 : 3500), Pe = j("fielder", X), ke = j("fielder", _), de = e === "run-out" ? "bowler" : "striker", O = e === "run-out" ? 5e3 : e === "stumping" ? 3900 : 3200, ie = [t.boundaryRadius * 0.8, e === "six" ? 2.1 : 0.075, -t.boundaryRadius * 0.6], $ = (r, l, x, f, w, a = 0, u = 0) => Ee({ target: `${o}/ball`, start: l, end: x, from: f, to: w, arc: a, curve: u }, r), je = (r) => {
|
|
306
|
+
if (r <= I) return j("bowler", r);
|
|
307
|
+
if (r <= Q) return $(r, I, Q, Fe, me, 0.15, e === "spin" ? 0.35 : 0);
|
|
308
|
+
const l = e === "wide" ? y(re, [0, 0, -0.6]) : A;
|
|
309
|
+
if (r <= m) return $(r, Q, m, me, l, 0.08);
|
|
310
|
+
if (e === "bowled") {
|
|
311
|
+
const f = [0, 0.36, P.length / 2];
|
|
312
|
+
return r <= O ? $(r, m, O, A, f) : $(r, O, 4100, f, [0, 0.075, 12.5], 0.2);
|
|
313
|
+
}
|
|
314
|
+
if (e === "lbw") return [...A];
|
|
315
|
+
if (["bowling", "spin", "no-ball", "wide", "stumping"].includes(e)) {
|
|
316
|
+
const f = e === "stumping" ? 3400 : 3500;
|
|
317
|
+
if (h && r <= f) {
|
|
318
|
+
const w = [l[0], re[1], P.length / 2 + 0.2];
|
|
319
|
+
return r <= 3200 ? $(r, m, 3200, l, w, 0.04) : $(r, 3200, f, w, re, 0.04);
|
|
320
|
+
}
|
|
321
|
+
return r <= f ? $(r, m, f, l, re, 0.04) : j("keeper", r);
|
|
322
|
+
}
|
|
323
|
+
if (e === "defend") return $(r, m, 3400, A, y(A, [-0.5, -A[1] + 0.075, -0.7]), 0.12);
|
|
324
|
+
if (e === "four" || e === "six") {
|
|
325
|
+
if (e === "six") return r <= 5e3 ? $(r, m, 5e3, A, ie, 12) : $(r, 5e3, 5700, ie, y(ie, [2, -2.025, -1.5]));
|
|
326
|
+
const f = [5, 0.075, 5];
|
|
327
|
+
return r <= 3300 ? $(r, m, 3300, A, f, 0.5) : $(r, 3300, 5e3, f, ie);
|
|
328
|
+
}
|
|
329
|
+
if (e === "catch") return r <= X ? $(r, m, X, A, Pe, 5) : j("fielder", r);
|
|
330
|
+
const x = [4, 0.075, 5];
|
|
331
|
+
if (r <= 3300) return $(r, m, 3300, A, x, 0.8);
|
|
332
|
+
if (r <= _) return $(r, 3300, _, x, ke);
|
|
333
|
+
if (e === "throw" || e === "run-out") {
|
|
334
|
+
if (r <= U) return j("fielder", r);
|
|
335
|
+
const f = j("fielder", U), w = e === "run-out" ? [0, 0.42, -P.length / 2] : j("keeper", ae), a = e === "run-out" ? O : ae;
|
|
336
|
+
return r <= a ? $(r, U, a, f, w, 1.2) : e === "run-out" ? $(r, a, 5700, w, [0, 0.075, -12], 0.18) : j("keeper", r);
|
|
337
|
+
}
|
|
338
|
+
return [...ke];
|
|
339
|
+
}, D = [], T = (r, l, x, f, w) => D.push({ id: r, time: d(l), kind: x, label: f, caption: w });
|
|
340
|
+
T("setup", 0, "setup", se[e].name, se[e].summary), T("release", I, "release", "Ball released", e === "no-ball" ? "The front foot has landed beyond the popping crease. No-ball." : "The bowler releases the ball; the front foot is behind the popping crease."), T("bounce", Q, "bounce", "Pitch bounce", e === "spin" ? "The curved flight is illustrative. Spin can change the ball’s path after it bounces." : "The delivery bounces on the pitch on its way to the striker."), b ? T("contact", m, "contact", "Bat contact", "The ball meets the blade. The bat is keyed from the same two hand grips.") : e === "lbw" ? T("pad-contact", m, "contact", "Pad contact", "The highlighted path illustrates a ball that would hit the stumps. This is an authored LBW example.") : T("miss", m, "contact", e === "wide" ? "Beyond normal reach" : "The batter misses", e === "wide" ? "The untouched ball is too far away for a normal stroke. The umpire calls Wide." : "The untouched delivery passes the striker."), e === "catch" && T("catch", X, "collect", "Catch controlled", "The fielder controls the ball before it touches the ground: caught."), ["fielding", "throw", "run-out", "batting", "running"].includes(e) && T("gather", _, "collect", "Ground ball gathered", "The ball has touched the ground. Gathering it is fielding, not a catch dismissal."), ["bowling", "spin", "wide", "no-ball", "stumping"].includes(e) && T("keeper", e === "stumping" ? 3400 : 3500, "collect", "Keeper gathers", "The keeper controls the ball behind the striker’s wicket."), (e === "throw" || e === "run-out") && T("throw", U, "throw", "Throw released", "The fielder releases the gathered ball toward the wicket."), e === "throw" && T("return", ae, "collect", "Return received", "The keeper receives and controls the return throw."), e === "stumping" && T("wicket", O, "wicket", "Stumped", "Holding the ball, the keeper removes a bail. The striker is out of ground and is not attempting a run."), e === "run-out" && T("wicket", O, "wicket", "Run out", "The direct throw removes a bail before the running batter makes this ground."), e === "bowled" && T("wicket", O, "wicket", "Bowled", "The legal delivery hits the wicket and removes a bail."), (e === "four" || e === "six") && T("boundary", 5e3, "boundary", e === "four" ? "Four runs" : "Six runs", e === "four" ? "The struck ball reaches the boundary after touching the ground: four." : "The struck ball clears the boundary without touching the ground: six."), e === "running" && T("run", fe, "result", "One run completed", "Both batters have reached the opposite ground. One run is completed.");
|
|
341
|
+
const K = De(e, t.format);
|
|
342
|
+
T("result", 5700, "result", "Illustrated result", e === "no-ball" ? `One no-ball extra; it does not count in the over.${K.freeHitNext ? " The next legitimate delivery is a free hit." : " Test cricket has no automatic free hit."}` : e === "wide" ? "One wide extra; the delivery does not count in the over." : e === "lbw" ? "LBW is declared for this illustrated legal delivery. A full decision also checks pitching, impact and any bat contact." : `${K.runs} bat runs · ${K.extras} extras · ${K.wickets} wicket${K.wickets === 1 ? "" : "s"}.`), D.sort((r, l) => r.time - l.time);
|
|
343
|
+
const ne = Ae(0, n, i.every, [1400, 1800, I, 2100, 2150, 2250, Q, 2600, 2800, m, 3050, 3100, 3200, 3250, 3300, 3400, 3500, 3800, 3900, 3950, 4e3, X, _, 4350, 4450, U, 4900, 5e3, 5100, 5150, ae, fe, 5700].map(d)), V = [];
|
|
344
|
+
for (const [r, l] of Object.entries(s)) Ue(V, o, l, ne, ne.map((x) => B(r, p(x))));
|
|
345
|
+
const Ne = ne.map((r) => je(p(r)));
|
|
346
|
+
for (const [r, l] of ["x", "y", "z"].entries()) V.push({ id: `ball-${l}`, target: `${o}/ball`, property: l, keyframes: ne.map((x, f) => ({ time: x, value: Ne[f][r] })) });
|
|
347
|
+
if (["bowled", "stumping", "run-out"].includes(e))
|
|
348
|
+
for (let r = 0; r < 2; r++) {
|
|
349
|
+
const l = `${de}-bail-${r}`, f = t.scene.objects.find((w) => w.id === l).position;
|
|
350
|
+
V.push({ id: `${l}-fall`, target: `${o}/${l}`, property: "position", keyframes: [{ time: 0, value: [...f] }, { time: d(O), value: [...f] }, { time: d(O + 180), value: y(f, [r ? 0.25 : -0.25, 0.22, de === "striker" ? 0.22 : -0.22]), easing: "ease-out" }, { time: d(O + 650), value: [f[0] + (r ? 0.4 : -0.4), 0.035, f[2] + (de === "striker" ? 0.45 : -0.45)], easing: "ease-in" }] }), V.push({ id: `${l}-spin`, target: `${o}/${l}`, property: "rotateZ", keyframes: [{ time: 0, value: 0 }, { time: d(O), value: 0 }, { time: d(O + 650), value: r ? 145 : -145 }] });
|
|
351
|
+
}
|
|
352
|
+
if (e === "lbw") {
|
|
353
|
+
const r = [A[0] * 0.8, A[1], P.length / 2], l = k.subtract(r, A);
|
|
354
|
+
V.push(
|
|
355
|
+
{ id: "lbw-position", target: `${o}/lbw-guide`, property: "position", keyframes: [{ time: 0, value: [...A] }] },
|
|
356
|
+
{ id: "lbw-rotation", target: `${o}/lbw-guide`, property: "quaternion", interpolation: "slerp", keyframes: [{ time: 0, value: Me(l) }] },
|
|
357
|
+
{ id: "lbw-length", target: `${o}/lbw-guide`, property: "scaleY", keyframes: [{ time: 0, value: k.distance(A, r) }] },
|
|
358
|
+
{ id: "lbw-visible", target: `${o}/lbw-guide`, property: "visible", keyframes: [{ time: 0, value: 0 }, { time: d(m) - 1e-3, value: 0 }, { time: d(m), value: 1 }] }
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
return { action: e, duration: n, events: D, result: K, timeline: { id: `${o}-${e}`, formatVersion: 2, name: se[e].name, config: { duration: n, markers: D.map((r) => ({ id: r.id, time: r.time, label: r.label })) }, captions: { en: Object.fromEntries(D.map((r) => [r.id, r.caption])) }, tracks: V } };
|
|
362
|
+
}
|
|
363
|
+
function et(t = {}) {
|
|
364
|
+
const i = Le(t);
|
|
365
|
+
return { ...i, ...Ye(i, t) };
|
|
366
|
+
}
|
|
367
|
+
function tt(t, i) {
|
|
368
|
+
if (!Number.isFinite(i)) throw new Error("cricketEventAt: time must be finite");
|
|
369
|
+
let e;
|
|
370
|
+
for (const n of t) {
|
|
371
|
+
if (n.time > i) break;
|
|
372
|
+
e = n;
|
|
373
|
+
}
|
|
374
|
+
return e;
|
|
375
|
+
}
|
|
376
|
+
export {
|
|
377
|
+
se as CRICKET_ACTIONS,
|
|
378
|
+
nt as CRICKET_CAMERA_ANGLES,
|
|
379
|
+
he as CRICKET_FORMATS,
|
|
380
|
+
P as CRICKET_PITCH,
|
|
381
|
+
ot as CRICKET_VIEWS,
|
|
382
|
+
Ee as ballFlightPoint,
|
|
383
|
+
Xe as ballFlightTracks,
|
|
384
|
+
Ye as cricketAction,
|
|
385
|
+
st as cricketCameraTracks,
|
|
386
|
+
et as cricketClip,
|
|
387
|
+
tt as cricketEventAt,
|
|
388
|
+
Le as cricketField,
|
|
389
|
+
_e as cricketPlayer
|
|
390
|
+
};
|