procedural-bot-animations 0.1.0 → 0.2.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 +167 -47
- package/dist/animation.d.ts +90 -0
- package/dist/animation.js +396 -0
- package/dist/brain.d.ts +194 -35
- package/dist/brain.js +578 -54
- package/dist/character.d.ts +123 -0
- package/dist/character.js +916 -0
- package/dist/characters/berry.d.ts +2 -0
- package/dist/characters/berry.js +38 -0
- package/dist/characters/flame.d.ts +2 -0
- package/dist/characters/flame.js +46 -0
- package/dist/delta.d.ts +16 -0
- package/dist/delta.js +146 -0
- package/dist/examples.d.ts +4 -0
- package/dist/examples.js +208 -0
- package/dist/focus.d.ts +46 -0
- package/dist/focus.js +284 -0
- package/dist/gaze.d.ts +41 -53
- package/dist/gaze.js +125 -82
- package/dist/index.d.ts +18 -11
- package/dist/index.js +18 -11
- package/dist/interactions.d.ts +30 -0
- package/dist/interactions.js +100 -0
- package/dist/library.d.ts +18 -0
- package/dist/library.js +14 -0
- package/dist/moods.d.ts +78 -46
- package/dist/moods.js +48 -73
- package/dist/motion.d.ts +93 -0
- package/dist/motion.js +167 -0
- package/dist/mount.d.ts +90 -0
- package/dist/mount.js +707 -0
- package/dist/parts.d.ts +36 -0
- package/dist/parts.js +131 -0
- package/dist/reactions.d.ts +184 -44
- package/dist/reactions.js +1851 -116
- package/dist/rig.d.ts +119 -0
- package/dist/rig.js +59 -0
- package/dist/scroll-traveler.js +1 -1
- package/dist/ticker.d.ts +10 -0
- package/dist/ticker.js +42 -0
- package/dist/transformations.d.ts +21 -0
- package/dist/transformations.js +306 -0
- package/package.json +7 -11
- package/dist/bind.d.ts +0 -27
- package/dist/bind.js +0 -42
- package/dist/blink.d.ts +0 -25
- package/dist/blink.js +0 -48
- package/dist/fake3d.d.ts +0 -20
- package/dist/fake3d.js +0 -24
- package/dist/noise.d.ts +0 -16
- package/dist/noise.js +0 -17
- package/dist/render.d.ts +0 -29
- package/dist/render.js +0 -97
- package/dist/rng.d.ts +0 -10
- package/dist/rng.js +0 -18
- package/dist/spring.d.ts +0 -21
- package/dist/spring.js +0 -33
- package/dist/types.d.ts +0 -63
- package/dist/types.js +0 -46
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { PathCommand } from "./parts.js";
|
|
2
|
+
import type { EyeShape, EyeStyle, Rig } from "./rig.js";
|
|
3
|
+
export interface CharacterDefinition {
|
|
4
|
+
version: 1;
|
|
5
|
+
/** Lowercase slug, 1 to 40 chars: `[a-z0-9-]`, starting with a letter or digit. */
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
/** Outline in a 0..100 box. */
|
|
9
|
+
body: {
|
|
10
|
+
path: string;
|
|
11
|
+
};
|
|
12
|
+
eyes: {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
spacing: number;
|
|
16
|
+
scale: number;
|
|
17
|
+
};
|
|
18
|
+
/** Optional extension (ignored by Open Bot Avatar itself). All coordinates in the same 0..100 box. */
|
|
19
|
+
rig?: {
|
|
20
|
+
parts?: Array<{
|
|
21
|
+
role: "C" | "L" | "R";
|
|
22
|
+
path: string;
|
|
23
|
+
pivot: [number, number];
|
|
24
|
+
tip: [number, number];
|
|
25
|
+
}>;
|
|
26
|
+
/** w/h/dx/dy in 0..100 units, tilt in degrees. */
|
|
27
|
+
eyeStyles?: Partial<Record<EyeStyle, Partial<EyeShape>>>;
|
|
28
|
+
/** Part sway multipliers, default 1/1. */
|
|
29
|
+
idle?: {
|
|
30
|
+
amp?: number;
|
|
31
|
+
freq?: number;
|
|
32
|
+
};
|
|
33
|
+
/** 0..1, default 0. */
|
|
34
|
+
flicker?: number;
|
|
35
|
+
/** Suggested body colour (#rgb or #rrggbb), informational. */
|
|
36
|
+
color?: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export type ValidationResult<T> = {
|
|
40
|
+
ok: true;
|
|
41
|
+
value: T;
|
|
42
|
+
warnings: string[];
|
|
43
|
+
} | {
|
|
44
|
+
ok: false;
|
|
45
|
+
errors: string[];
|
|
46
|
+
};
|
|
47
|
+
/** Scale from the 0..100 box to the engine's drawing space (Flame was made with the same 9.5). */
|
|
48
|
+
export declare const CHARACTER_SCALE = 9.5;
|
|
49
|
+
export declare const CHARACTER_LIMITS: {
|
|
50
|
+
readonly pathChars: 6000;
|
|
51
|
+
readonly pathSegments: 400;
|
|
52
|
+
readonly pathSubpaths: 16;
|
|
53
|
+
readonly coordMin: -20;
|
|
54
|
+
readonly coordMax: 120;
|
|
55
|
+
/** Hard limits for the body bounding box (error). */
|
|
56
|
+
readonly bodyHardMin: 6;
|
|
57
|
+
readonly bodyHardMax: 94;
|
|
58
|
+
/** Soft limits (warning). */
|
|
59
|
+
readonly bodySoftMin: 8;
|
|
60
|
+
readonly bodySoftMax: 92;
|
|
61
|
+
readonly bodyMinSize: 30;
|
|
62
|
+
readonly eyeScale: readonly [0.4, 3];
|
|
63
|
+
readonly eyeSpacing: readonly [4, 60];
|
|
64
|
+
readonly eyeMargin: 0.8;
|
|
65
|
+
readonly nameMax: 60;
|
|
66
|
+
readonly pivotSlack: 3;
|
|
67
|
+
readonly minPartLength: 4;
|
|
68
|
+
};
|
|
69
|
+
export declare class PathError extends Error {
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Parses the full SVG path grammar (M L H V C S Q T A Z, absolute and
|
|
73
|
+
* relative, implicit repeats, several subpaths) into ABSOLUTE commands using
|
|
74
|
+
* only M, L, C and Z: the format `parsePath` / `bendPath` / `mixPath` read.
|
|
75
|
+
* Q, T and S become exact cubics; arcs become cubic segments of at most 90°.
|
|
76
|
+
* `segments` is the number of commands in the source (for the limits).
|
|
77
|
+
* With `closeOpen`, unclosed subpaths get a `Z` and `closed` lists their (1-based) numbers.
|
|
78
|
+
* Throws `PathError` on malformed input.
|
|
79
|
+
*/
|
|
80
|
+
export declare function normalizeWithStats(d: string, closeOpen?: boolean): {
|
|
81
|
+
cmds: PathCommand[];
|
|
82
|
+
segments: number;
|
|
83
|
+
closed: number[];
|
|
84
|
+
};
|
|
85
|
+
/** Absolute M/L/C/Z commands for any SVG path (see `normalizeWithStats`). */
|
|
86
|
+
export declare function normalizePath(d: string, closeOpen?: boolean): PathCommand[];
|
|
87
|
+
/** Writes commands back as `M x,y C x,y x,y x,y L x,y Z` (no exponents: `parsePath` cannot read them). */
|
|
88
|
+
export declare function serializePath(cmds: readonly PathCommand[]): string;
|
|
89
|
+
export type Poly = Array<[number, number]>;
|
|
90
|
+
/** Flattens into one polygon per subpath (cubics sampled within 0.02 units of the curve). */
|
|
91
|
+
export declare function flattenPath(cmds: readonly PathCommand[]): Poly[];
|
|
92
|
+
export type Bounds = {
|
|
93
|
+
minX: number;
|
|
94
|
+
minY: number;
|
|
95
|
+
maxX: number;
|
|
96
|
+
maxY: number;
|
|
97
|
+
};
|
|
98
|
+
export declare function polyBounds(polys: readonly Poly[]): Bounds;
|
|
99
|
+
/** Checks a definition (any JSON value). Collects every problem; warnings never block. */
|
|
100
|
+
export declare function validateCharacter(input: unknown): ValidationResult<CharacterDefinition>;
|
|
101
|
+
/**
|
|
102
|
+
* Compiles a validated definition into a `Rig`. Derivations (S = CHARACTER_SCALE):
|
|
103
|
+
* - transform: x' = 627 + (x − bboxCenterX)·S, y' = 960 + (y − bboxBottom)·S, where the bbox is that of
|
|
104
|
+
* the flattened body outline. Parts, pivots, tips and eyes use the same transform.
|
|
105
|
+
* - eyes.left/right = (eyes.x ∓ spacing/2, eyes.y) transformed.
|
|
106
|
+
* - eyeStyles.classic = a pill: h = 11·scale·S and w = h / 2 (Berry's ratio; deliberately wider than Open Bot Avatar's 4-wide pill), so w = 5.5·scale·S, tilt 0, dx 0, dy 0.
|
|
107
|
+
* - pumpy / big = classic × Berry's ratios (w, h multiples; dx as a fraction of classic w, dy of classic h;
|
|
108
|
+
* tilt copied), built from the classic AFTER its override; then each style's own `rig.eyeStyles`
|
|
109
|
+
* override (w/h/dx/dy × S) is applied.
|
|
110
|
+
* - ground = (627, 960); anchor = (627, 660); center = bbox centre (transformed).
|
|
111
|
+
* - shadow = (627, 988), rx = 0.41 × body width, ry = 22 (Berry: 250 / 614 ≈ 0.41).
|
|
112
|
+
* - accessory: x = bboxRight − 0.088 × body width; y = min(topOfEverything + 0.068 × total height,
|
|
113
|
+
* bodyTop − 0.16 × body height), never above 100 (Berry's proportions: 880,300).
|
|
114
|
+
* - baseHeight = 960 − mean pivot y, or 0.6 × body height with no parts.
|
|
115
|
+
* - idleAppendage = rig.idle (default 1/1); flicker = rig.flicker (default 0); no core.
|
|
116
|
+
* Throws if the definition is invalid; run `validateCharacter` first.
|
|
117
|
+
*/
|
|
118
|
+
export declare function characterToRig(def: CharacterDefinition): Rig;
|
|
119
|
+
/** JSON text → validated definition plus rig. Never throws. */
|
|
120
|
+
export declare function parseCharacter(json: string): ValidationResult<{
|
|
121
|
+
definition: CharacterDefinition;
|
|
122
|
+
rig: Rig;
|
|
123
|
+
}>;
|