@algorisys/tinyfly 0.76.0 → 0.77.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 +6 -6
- package/lib/addons/adapters.js +2 -2
- package/lib/addons/characters.js +1205 -416
- package/lib/addons/{sketch-CB6VNfnR.js → sketch-CA8ZXhxI.js} +2 -2
- package/lib/browser/tinyfly.iife.js +4 -4
- package/lib/browser/tinyfly.js +3715 -2927
- package/lib/browser/tinyfly.umd.js +4 -4
- package/lib/types/characters/character.d.ts +165 -0
- package/lib/types/characters/head/face.d.ts +17 -0
- package/lib/types/characters/index.d.ts +5 -0
- package/lib/types/characters/look/curves.d.ts +7 -0
- package/lib/types/characters/look/pen.d.ts +59 -0
- package/lib/types/characters/look/tapered-line.d.ts +13 -0
- package/lib/types/characters/rig/body-plan.d.ts +89 -0
- package/lib/types/characters/rig/reach.d.ts +11 -0
- package/lib/types/characters/rig/skeleton.d.ts +71 -0
- package/lib/types/characters/species/human.d.ts +59 -0
- package/lib/types/characters/stick-figure.d.ts +6 -13
- package/lib/types/characters/wardrobe/basic-outfit.d.ts +14 -0
- package/package.json +1 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { CustomTarget } from '../adapters/canvas';
|
|
2
|
+
import type { EasingType, Track } from '../engine/types';
|
|
3
|
+
import type { Point } from '../adapters/canvas/sketch';
|
|
4
|
+
import type { FrameInfo } from '../headless/video-scene';
|
|
5
|
+
import type { BodyPlan, Pose, Vec3 } from './rig/body-plan';
|
|
6
|
+
import { type SolvedHead } from './rig/skeleton';
|
|
7
|
+
import { type Look, type Pen, type PencilOptions } from './look/pen';
|
|
8
|
+
import { type HumanPoseName } from './species/human';
|
|
9
|
+
/**
|
|
10
|
+
* Characters (v2): any body plan, posed by numbers, turned in 3D, drawn flat
|
|
11
|
+
* in a look (clean, pencil, silhouette) and a figure style (fluid, stick).
|
|
12
|
+
*
|
|
13
|
+
* The v1 stick figure (`stickFigureTarget`, `drawStickFigure`) is separate
|
|
14
|
+
* and unchanged. See docs/character-system-m1.md.
|
|
15
|
+
*/
|
|
16
|
+
/** `stick`: the traditional (Pencilmation) stick figure. `fluid`: tapered limbs, hands, feet, shoulders. */
|
|
17
|
+
export type FigureStyle = 'fluid' | 'stick';
|
|
18
|
+
/**
|
|
19
|
+
* Draws part of a character: clothes, hair, a prop. The context is in the
|
|
20
|
+
* character's drawing space (feet at 0, 0), saved and restored around the
|
|
21
|
+
* call. Draw with `pen` so it matches the look.
|
|
22
|
+
*/
|
|
23
|
+
export type CharacterLayer = (ctx: CanvasRenderingContext2D, joints: CharacterJoints, pen: Pen, time: number) => void;
|
|
24
|
+
export interface CharacterLayers {
|
|
25
|
+
/** Before anything (a shadow, a cape) */
|
|
26
|
+
behind?: CharacterLayer;
|
|
27
|
+
/** Around a part ('leg.left', 'spine', 'neck', 'arm.right', 'head'…): drawn at that part's depth */
|
|
28
|
+
parts?: Record<string, {
|
|
29
|
+
under?: CharacterLayer;
|
|
30
|
+
over?: CharacterLayer;
|
|
31
|
+
}>;
|
|
32
|
+
/** After everything (a prop in front) */
|
|
33
|
+
front?: CharacterLayer;
|
|
34
|
+
}
|
|
35
|
+
export interface CharacterOptions {
|
|
36
|
+
/** Body plan (default: human, built from the options below) */
|
|
37
|
+
plan?: BodyPlan;
|
|
38
|
+
figure?: FigureStyle;
|
|
39
|
+
look?: Look;
|
|
40
|
+
/** Feet to top of head, px (default 300) */
|
|
41
|
+
height?: number;
|
|
42
|
+
/** `bold` (default): head 30% of the height, line 4.5%. `thin`: head 24%, line 2.2%, as the reference sheets */
|
|
43
|
+
proportions?: 'bold' | 'thin';
|
|
44
|
+
/** Head diameter, fraction of the height (overrides the proportions) */
|
|
45
|
+
headSize?: number;
|
|
46
|
+
/** Line width, px (overrides the proportions) */
|
|
47
|
+
lineWidth?: number;
|
|
48
|
+
/** Half the shoulder width, fraction of the height (fluid only; default 0.06) */
|
|
49
|
+
shoulderWidth?: number;
|
|
50
|
+
/** Half the hip width, fraction of the height (fluid only; default 0.022) */
|
|
51
|
+
hipWidth?: number;
|
|
52
|
+
/** Line colour (default slate, or graphite in pencil) */
|
|
53
|
+
ink?: string;
|
|
54
|
+
/** Head fill; `none` leaves it see-through (default white, or none in pencil) */
|
|
55
|
+
skin?: string;
|
|
56
|
+
/** Seed for the pencil's wobble, so two characters do not boil in step (default 1) */
|
|
57
|
+
seed?: number;
|
|
58
|
+
pencil?: PencilOptions;
|
|
59
|
+
layers?: CharacterLayers;
|
|
60
|
+
/** 'ground' (default) rests the lowest contact point on the ground; 'none' leaves the figure where its pose puts it */
|
|
61
|
+
contact?: 'ground' | 'none';
|
|
62
|
+
}
|
|
63
|
+
/** A character, with every option resolved. Plain data plus its plan. */
|
|
64
|
+
export interface Character {
|
|
65
|
+
plan: BodyPlan;
|
|
66
|
+
figure: FigureStyle;
|
|
67
|
+
look: Look;
|
|
68
|
+
height: number;
|
|
69
|
+
lineWidth: number;
|
|
70
|
+
ink: string;
|
|
71
|
+
skin: string;
|
|
72
|
+
seed: number;
|
|
73
|
+
pencil: PencilOptions;
|
|
74
|
+
layers: CharacterLayers;
|
|
75
|
+
contact: 'ground' | 'none';
|
|
76
|
+
}
|
|
77
|
+
export declare function character(options?: CharacterOptions): Character;
|
|
78
|
+
/** Where every part of a character is, as drawn, in its drawing space (feet at 0, 0; up is -y). */
|
|
79
|
+
export interface CharacterJoints {
|
|
80
|
+
height: number;
|
|
81
|
+
lineWidth: number;
|
|
82
|
+
turn: number;
|
|
83
|
+
/** Named points: `hip`, `neck`, `shoulder.left`, `hand.right`, `knee.left`, `toe.right`… */
|
|
84
|
+
points: Record<string, Point>;
|
|
85
|
+
/** Every chain's joints */
|
|
86
|
+
chains: Record<string, Point[]>;
|
|
87
|
+
/** Every part's centre line as drawn, and its depth toward the viewer (px) */
|
|
88
|
+
parts: Record<string, {
|
|
89
|
+
points: Point[];
|
|
90
|
+
depth: number;
|
|
91
|
+
}>;
|
|
92
|
+
/** The head: centre, radii, screen angle and its own axes (use `pointOnHead`) */
|
|
93
|
+
head: SolvedHead;
|
|
94
|
+
/** Screen y of the lowest contact point: the ground, 0 when standing */
|
|
95
|
+
groundY: number;
|
|
96
|
+
/** Which named points rest on the ground (within 1% of the height) */
|
|
97
|
+
grounded: Record<string, boolean>;
|
|
98
|
+
}
|
|
99
|
+
/** A point on the head from head coordinates: x toward its left, y up, z forward (-1..1 of a radius). */
|
|
100
|
+
export declare function pointOnHead(head: SolvedHead, x: number, y: number, z: number): {
|
|
101
|
+
point: Point;
|
|
102
|
+
facing: number;
|
|
103
|
+
};
|
|
104
|
+
/** Where every part of a character is for a pose, as `drawCharacter` would draw it. */
|
|
105
|
+
export declare function characterJoints(character: Character, pose: Pose): CharacterJoints;
|
|
106
|
+
/**
|
|
107
|
+
* Draw a character in a pose with its feet at (0, 0). `time` (ms) picks the
|
|
108
|
+
* pencil's boil frame and is passed to layer hooks.
|
|
109
|
+
*/
|
|
110
|
+
export declare function drawCharacter(ctx: CanvasRenderingContext2D, character: Character, pose: Pose, time?: number): void;
|
|
111
|
+
/** A full blend of two poses: `t` 0 is `from`, 1 is `to`. Fields in only one keep its value. */
|
|
112
|
+
export declare function mixPoses(from: Pose, to: Pose, t: number): Pose;
|
|
113
|
+
/**
|
|
114
|
+
* The pose with a limb reaching for `target`: a point in the character's own
|
|
115
|
+
* 3D space (px; +x its left, +y up from the ground under its hips, +z forward),
|
|
116
|
+
* or a point in its drawing space with a `depth` toward the viewer.
|
|
117
|
+
*/
|
|
118
|
+
export declare function reachCharacter(character: Character, pose: Pose, chain: string, target: Vec3 | {
|
|
119
|
+
x: number;
|
|
120
|
+
y: number;
|
|
121
|
+
depth?: number;
|
|
122
|
+
}): Pose;
|
|
123
|
+
export interface CharacterTargetOptions {
|
|
124
|
+
/** Where the feet stand */
|
|
125
|
+
x: number;
|
|
126
|
+
y: number;
|
|
127
|
+
character: Character;
|
|
128
|
+
/** Starting pose (default rest) */
|
|
129
|
+
pose?: Pose;
|
|
130
|
+
}
|
|
131
|
+
/** A `custom` target made by {@link characterTarget}. */
|
|
132
|
+
export interface CharacterTarget extends CustomTarget {
|
|
133
|
+
readonly character: Character;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* A `custom` canvas target that draws a character. Every pose field is a
|
|
137
|
+
* prop, so timeline tracks pose, turn and roll it. `x`/`y` are the feet.
|
|
138
|
+
*/
|
|
139
|
+
export declare function characterTarget(options: CharacterTargetOptions): CharacterTarget;
|
|
140
|
+
/** Joints moved from a character's drawing space to a scene where its feet stand at (x, y). */
|
|
141
|
+
export declare function jointsInScene(joints: CharacterJoints, x: number, y: number): CharacterJoints;
|
|
142
|
+
/**
|
|
143
|
+
* A character target's pose and scene-space joints in a frame, for
|
|
144
|
+
* immediate-mode drawing that follows it. `id` is its key in the scene's
|
|
145
|
+
* `targets`. Its `x`/`y` tracks are followed; `rotate`/`scale` on the target
|
|
146
|
+
* itself are not.
|
|
147
|
+
*/
|
|
148
|
+
export declare function characterAt(target: CustomTarget, frame: Pick<FrameInfo, 'time' | 'state'>, id: string): {
|
|
149
|
+
pose: Pose;
|
|
150
|
+
joints: CharacterJoints;
|
|
151
|
+
};
|
|
152
|
+
export interface CharacterPoseKey {
|
|
153
|
+
time: number;
|
|
154
|
+
/** A named pose, or fields that change from the previous key (default: no change) */
|
|
155
|
+
pose?: HumanPoseName | Pose;
|
|
156
|
+
/** Easing into this key */
|
|
157
|
+
easing?: EasingType;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Keyframe tracks that move a character target through a sequence of poses.
|
|
161
|
+
* Each key is a named pose or changes from the previous key (the first builds
|
|
162
|
+
* on rest). Only fields that leave rest in some key get a track, so the JSON
|
|
163
|
+
* stays small and the timeline shows only what moves.
|
|
164
|
+
*/
|
|
165
|
+
export declare function characterPoseTracks(target: string, keys: CharacterPoseKey[], rest?: Pose): Track[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Point } from '../../adapters/canvas/sketch';
|
|
2
|
+
import type { Pose } from '../rig/body-plan';
|
|
3
|
+
import { type SolvedHead } from '../rig/skeleton';
|
|
4
|
+
import type { Pen } from '../look/pen';
|
|
5
|
+
/**
|
|
6
|
+
* Face coordinates to the screen. Cartoon faces slide less than a sphere
|
|
7
|
+
* would: the whole face shifts toward the side the head faces, the spacing of
|
|
8
|
+
* features narrows (to a minimum) and each feature's own shape narrows less, so
|
|
9
|
+
* a profile still shows an eye and a mouth inside the head. Points are given
|
|
10
|
+
* around a feature's `centre`; `facing` comes from the real surface at that
|
|
11
|
+
* centre, so features on the far side are hidden.
|
|
12
|
+
*/
|
|
13
|
+
export declare function faceToScreen(head: SolvedHead, points: Point[], centre: Point): {
|
|
14
|
+
points: Point[];
|
|
15
|
+
facing: number;
|
|
16
|
+
};
|
|
17
|
+
export declare function drawFace(pen: Pen, head: SolvedHead, pose: Pose, lineWidth: number): void;
|
|
@@ -9,3 +9,8 @@ export * from '../adapters/canvas/sketch';
|
|
|
9
9
|
export * from './erase';
|
|
10
10
|
export * from '../adapters/canvas/polyline';
|
|
11
11
|
export * from './hand';
|
|
12
|
+
export * from './character';
|
|
13
|
+
export { humanPlan, humanPose, humanFieldLabel, HUMAN_REST, HUMAN_POSES, HUMAN_EXPRESSIONS, type HumanBuild, type HumanPoseName } from './species/human';
|
|
14
|
+
export type { BodyPlan, ChainSpec, BoneSpec, BoneAngles, ContactSpec, HeadSpec, Pose as CharacterPose, Vec3 } from './rig/body-plan';
|
|
15
|
+
export { createPen, ellipsePoints, type Pen, type Look, type PencilOptions, type PenOptions } from './look/pen';
|
|
16
|
+
export { basicOutfit, type BasicOutfitOptions } from './wardrobe/basic-outfit';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Point } from '../../adapters/canvas/sketch';
|
|
2
|
+
/**
|
|
3
|
+
* Points along a limb, blending the jointed shape (two straight segments) into
|
|
4
|
+
* a rubber-hose curve by `rubber` 0..1. The curve is the quadratic that passes
|
|
5
|
+
* through the joint halfway along, so a bent limb keeps its bend, rounded.
|
|
6
|
+
*/
|
|
7
|
+
export declare function rubberLimb(root: Point, joint: Point, end: Point, rubber: number, samples?: number): Point[];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type Point } from '../../adapters/canvas/sketch';
|
|
2
|
+
/**
|
|
3
|
+
* The pen every part of a character is drawn with: its body, face, hair,
|
|
4
|
+
* clothes and props. A look is a pen, so whatever draws through it (the
|
|
5
|
+
* figure, or a costume hook) matches the look.
|
|
6
|
+
*
|
|
7
|
+
* - `clean`: filled tapered strokes and plain canvas lines.
|
|
8
|
+
* - `pencil`: Pencilmation. Graphite strokes in passes, a wobble that boils a
|
|
9
|
+
* few times a second, pressure that thins and thickens along each stroke,
|
|
10
|
+
* faint construction guides, and the odd rubbed-out earlier attempt.
|
|
11
|
+
* - `silhouette`: everything filled solid in the ink, for a readability check.
|
|
12
|
+
*
|
|
13
|
+
* Deterministic: the pencil's wobble and pressure are seeded by the seed, the
|
|
14
|
+
* boil frame and the stroke's place in the drawing order, never Math.random.
|
|
15
|
+
*/
|
|
16
|
+
export type Look = 'clean' | 'pencil' | 'silhouette';
|
|
17
|
+
export interface PencilOptions {
|
|
18
|
+
/** Largest wobble, px (default: 12% of the line width, at least 1) */
|
|
19
|
+
roughness?: number;
|
|
20
|
+
/** Redraws per second; 0 holds still (default 8) */
|
|
21
|
+
boil?: number;
|
|
22
|
+
/** Strokes per line (default 2) */
|
|
23
|
+
passes?: number;
|
|
24
|
+
/** How much pressure varies along a stroke, 0..1 (default 0.25) */
|
|
25
|
+
pressure?: number;
|
|
26
|
+
/** Draw faint construction guides under the figure (default true) */
|
|
27
|
+
construction?: boolean;
|
|
28
|
+
/** Share of strokes with a rubbed-out earlier attempt beside them, 0..1 (default 0.15) */
|
|
29
|
+
rubbedOut?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface Pen {
|
|
32
|
+
readonly look: Look;
|
|
33
|
+
readonly ink: string;
|
|
34
|
+
/** A stroke through `points` whose width runs from `from` to `to` px */
|
|
35
|
+
limb(points: Point[], from: number, to: number): void;
|
|
36
|
+
/** An even stroke */
|
|
37
|
+
line(points: Point[], width: number): void;
|
|
38
|
+
/** A closed shape: filled with `fill` (none when null) and outlined (not when `outline` is 0) */
|
|
39
|
+
shape(points: Point[], fill: string | null, outline: number): void;
|
|
40
|
+
/** An ellipse: filled with `fill` (none when null) and outlined */
|
|
41
|
+
ellipse(cx: number, cy: number, rx: number, ry: number, angle: number, fill: string | null, outline: number): void;
|
|
42
|
+
/** A filled dot in the ink */
|
|
43
|
+
dot(x: number, y: number, r: number): void;
|
|
44
|
+
/** A faint construction line (pencil only) */
|
|
45
|
+
guide(points: Point[]): void;
|
|
46
|
+
/** A faint construction ellipse (pencil only) */
|
|
47
|
+
guideEllipse(cx: number, cy: number, rx: number, ry: number, angle: number): void;
|
|
48
|
+
}
|
|
49
|
+
export interface PenOptions {
|
|
50
|
+
look: Look;
|
|
51
|
+
ink: string;
|
|
52
|
+
lineWidth: number;
|
|
53
|
+
seed: number;
|
|
54
|
+
time: number;
|
|
55
|
+
pencil?: PencilOptions;
|
|
56
|
+
}
|
|
57
|
+
/** Points around an ellipse, from `start` radians, `turns` of a full turn. */
|
|
58
|
+
export declare function ellipsePoints(cx: number, cy: number, rx: number, ry: number, angle: number, start?: number, turns?: number, samples?: number): Point[];
|
|
59
|
+
export declare function createPen(ctx: CanvasRenderingContext2D, options: PenOptions): Pen;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Point } from '../../adapters/canvas/sketch';
|
|
2
|
+
/**
|
|
3
|
+
* The outline of a line through `points` whose width runs from `startWidth` to
|
|
4
|
+
* `endWidth`: up one side and back down the other, square to the line at each
|
|
5
|
+
* point. A sleeve or trouser leg along a limb is this shape, filled.
|
|
6
|
+
*/
|
|
7
|
+
export declare function taperedOutline(points: Point[], startWidth: number, endWidth: number): Point[];
|
|
8
|
+
/**
|
|
9
|
+
* Fill a line through `points` whose width runs from `startWidth` to
|
|
10
|
+
* `endWidth`, with round ends: a limb that tapers, or a sleeve or trouser leg
|
|
11
|
+
* along a joint polyline. Uses the context's fill style.
|
|
12
|
+
*/
|
|
13
|
+
export declare function taperedLine(ctx: CanvasRenderingContext2D, points: Point[], startWidth: number, endWidth: number): void;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Body plans: what a character is made of, as data.
|
|
3
|
+
*
|
|
4
|
+
* A body plan is a set of bone chains (a spine, a neck, arms, legs; later
|
|
5
|
+
* tails, wings, trunks) hanging from one another, a head, and the points that
|
|
6
|
+
* can touch a surface. Lengths and widths are fractions of the character's
|
|
7
|
+
* height, so one plan draws at any size.
|
|
8
|
+
*
|
|
9
|
+
* Space: +x is the character's left, +y is up, +z is the way it faces. The
|
|
10
|
+
* hips sit on the y axis; the ground under them is y = 0.
|
|
11
|
+
*/
|
|
12
|
+
export type Vec3 = [number, number, number];
|
|
13
|
+
export interface BoneSpec {
|
|
14
|
+
/** Length, fraction of the height */
|
|
15
|
+
length: number;
|
|
16
|
+
/** Drawn width at each end, in line widths (the fluid figure tapers) */
|
|
17
|
+
width: [number, number];
|
|
18
|
+
}
|
|
19
|
+
export interface ChainSpec {
|
|
20
|
+
id: string;
|
|
21
|
+
/** Chain it hangs from; null hangs from the hips */
|
|
22
|
+
parent: string | null;
|
|
23
|
+
/** Joint of the parent it starts at (default: the parent's last joint) */
|
|
24
|
+
at?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Offset from that joint, fraction of the height, in the parent bone's own
|
|
27
|
+
* frame (so shoulders turn with the spine)
|
|
28
|
+
*/
|
|
29
|
+
offset?: Vec3;
|
|
30
|
+
/** Direction of the first bone at rest (a unit vector) */
|
|
31
|
+
rest: Vec3;
|
|
32
|
+
bones: BoneSpec[];
|
|
33
|
+
/** -1 the right side, +1 the left: which way a positive spread goes (default +1) */
|
|
34
|
+
side?: -1 | 1;
|
|
35
|
+
/**
|
|
36
|
+
* Which way the middle joint bends when the chain reaches for a point, in
|
|
37
|
+
* the parent bone's frame (default: elbows back and down, knees forward)
|
|
38
|
+
*/
|
|
39
|
+
pole?: Vec3;
|
|
40
|
+
}
|
|
41
|
+
/** A bone's angles in degrees, relative to the bone before it (or the parent chain). */
|
|
42
|
+
export interface BoneAngles {
|
|
43
|
+
/** Forward and back: a hanging bone's end moves forward (+z) as swing grows */
|
|
44
|
+
swing: number;
|
|
45
|
+
/** Away from the body (+) and across it (-), toward the chain's side */
|
|
46
|
+
spread: number;
|
|
47
|
+
/** Turn about the vertical, for this bone only (a foot turned out) */
|
|
48
|
+
yaw?: number;
|
|
49
|
+
}
|
|
50
|
+
/** A point that can rest on a surface: a joint of a chain, or the top of the head. */
|
|
51
|
+
export type ContactSpec = {
|
|
52
|
+
chain: string;
|
|
53
|
+
joint: number;
|
|
54
|
+
} | {
|
|
55
|
+
head: 'top';
|
|
56
|
+
};
|
|
57
|
+
export interface HeadSpec {
|
|
58
|
+
/** Chain the head sits on the end of */
|
|
59
|
+
on: string;
|
|
60
|
+
/** Diameter, fraction of the height */
|
|
61
|
+
size: number;
|
|
62
|
+
}
|
|
63
|
+
/** A pose: every value a number, so any two poses blend and each field can be a track. */
|
|
64
|
+
export type Pose = Record<string, number>;
|
|
65
|
+
export interface BodyPlan {
|
|
66
|
+
id: string;
|
|
67
|
+
/** In drawing order for ties: when two parts are at the same depth, the earlier is drawn first */
|
|
68
|
+
chains: ChainSpec[];
|
|
69
|
+
head: HeadSpec;
|
|
70
|
+
contacts: ContactSpec[];
|
|
71
|
+
/** The angles of each bone of a chain, from a pose */
|
|
72
|
+
angles(pose: Pose, chain: ChainSpec): BoneAngles[];
|
|
73
|
+
/** How much a chain's bones are scaled (squash and stretch); `null` asks for the hip height. Default 1 */
|
|
74
|
+
boneScale?(pose: Pose, chain: ChainSpec | null): number;
|
|
75
|
+
/** The head's own turn, nod and tilt (degrees) and its radii as multiples of the plan's. Default: still, round */
|
|
76
|
+
headPose?(pose: Pose): {
|
|
77
|
+
yaw: number;
|
|
78
|
+
nod: number;
|
|
79
|
+
tilt: number;
|
|
80
|
+
sx: number;
|
|
81
|
+
sy: number;
|
|
82
|
+
};
|
|
83
|
+
/** The pose with a chain's bone angles set (the inverse of `angles`), for reaching */
|
|
84
|
+
withAngles?(pose: Pose, chain: ChainSpec, angles: BoneAngles[]): Pose;
|
|
85
|
+
/** Named points: [chain, joint], e.g. `'hand.left': ['arm.left', 2]` */
|
|
86
|
+
landmarks?: Record<string, [string, number]>;
|
|
87
|
+
/** Height of the hips above the ground at rest, fraction of the height (where a figure in the air keeps them) */
|
|
88
|
+
hipHeight: number;
|
|
89
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BodyPlan, Pose, Vec3 } from './body-plan';
|
|
2
|
+
export interface ReachOptions {
|
|
3
|
+
/** Height in px the character is drawn at */
|
|
4
|
+
height: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The pose with chain `chainId` reaching for `target`, a point in the
|
|
8
|
+
* character's 3D space in px (+x its left, +y up from the ground under its
|
|
9
|
+
* hips, +z forward). The chain must hang down at rest (arms, legs).
|
|
10
|
+
*/
|
|
11
|
+
export declare function reachPose(plan: BodyPlan, pose: Pose, chainId: string, target: Vec3, options: ReachOptions): Pose;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Point } from '../../adapters/canvas/sketch';
|
|
2
|
+
import type { BodyPlan, ContactSpec, Pose, Vec3 } from './body-plan';
|
|
3
|
+
/** Turn about x: a hanging vector's end moves forward (+z) as the angle grows. */
|
|
4
|
+
export declare function rotX([x, y, z]: Vec3, a: number): Vec3;
|
|
5
|
+
/** Turn about z: a hanging vector's end moves toward +x (the character's left) as the angle grows. */
|
|
6
|
+
export declare function rotZ([x, y, z]: Vec3, a: number): Vec3;
|
|
7
|
+
/** Turn about y (the vertical): forward (+z) turns toward +x as the angle grows. */
|
|
8
|
+
export declare function rotY([x, y, z]: Vec3, a: number): Vec3;
|
|
9
|
+
/** A bone's absolute orientation: summed swing and (signed) spread, radians. */
|
|
10
|
+
export interface BoneFrame {
|
|
11
|
+
swing: number;
|
|
12
|
+
spread: number;
|
|
13
|
+
}
|
|
14
|
+
/** Turn a vector by a bone frame, as its bones are turned: spread after swing. */
|
|
15
|
+
export declare const orient: (v: Vec3, frame: BoneFrame) => Vec3;
|
|
16
|
+
export interface SolvedChain {
|
|
17
|
+
id: string;
|
|
18
|
+
/** Joints in the character's 3D space, px */
|
|
19
|
+
joints3: Vec3[];
|
|
20
|
+
/** Each bone's frame */
|
|
21
|
+
frames: BoneFrame[];
|
|
22
|
+
/** Joints on screen (projected, rolled, placed) */
|
|
23
|
+
points: Point[];
|
|
24
|
+
/** Each joint's depth toward the viewer, px */
|
|
25
|
+
depths: number[];
|
|
26
|
+
}
|
|
27
|
+
export interface SolvedHead {
|
|
28
|
+
center: Point;
|
|
29
|
+
depth: number;
|
|
30
|
+
rx: number;
|
|
31
|
+
ry: number;
|
|
32
|
+
/** Screen rotation of the head ellipse, radians */
|
|
33
|
+
angle: number;
|
|
34
|
+
/**
|
|
35
|
+
* The head's own axes (its left, up and forward) in view space: x to the
|
|
36
|
+
* right of the screen, y up the screen, z toward the viewer. A point on the
|
|
37
|
+
* head is center + its coordinates along these axes.
|
|
38
|
+
*/
|
|
39
|
+
axes: [Vec3, Vec3, Vec3];
|
|
40
|
+
}
|
|
41
|
+
export interface Skeleton {
|
|
42
|
+
height: number;
|
|
43
|
+
/** View angle, radians: turn × 90° */
|
|
44
|
+
view: number;
|
|
45
|
+
chains: Record<string, SolvedChain>;
|
|
46
|
+
head: SolvedHead;
|
|
47
|
+
/** The hips on screen */
|
|
48
|
+
hip: Point;
|
|
49
|
+
/** Every contact point on screen, and which one is lowest */
|
|
50
|
+
contacts: Array<{
|
|
51
|
+
spec: ContactSpec;
|
|
52
|
+
point: Point;
|
|
53
|
+
}>;
|
|
54
|
+
/** Screen y of the lowest contact point (0 when the figure stands on the ground) */
|
|
55
|
+
groundY: number;
|
|
56
|
+
}
|
|
57
|
+
export interface SolveOptions {
|
|
58
|
+
/** Height in px */
|
|
59
|
+
height: number;
|
|
60
|
+
/** 'ground' (default) rests the lowest contact point on y = 0; 'none' keeps the hips at standing height */
|
|
61
|
+
contact?: 'ground' | 'none';
|
|
62
|
+
}
|
|
63
|
+
export declare function solveSkeleton(plan: BodyPlan, pose: Pose, options: SolveOptions): Skeleton;
|
|
64
|
+
/** A point on the head from head coordinates: x to its left, y up, z forward, each -1..1 of a radius. */
|
|
65
|
+
export declare function headPoint(head: SolvedHead, [x, y, z]: Vec3): {
|
|
66
|
+
point: Point;
|
|
67
|
+
depth: number;
|
|
68
|
+
facing: number;
|
|
69
|
+
};
|
|
70
|
+
/** Which chains a plan has, in order: for drawing and for tests. */
|
|
71
|
+
export declare const chainIds: (plan: BodyPlan) => string[];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { BodyPlan, Pose } from '../rig/body-plan';
|
|
2
|
+
import { type ExpressionName } from '../stick-figure';
|
|
3
|
+
/**
|
|
4
|
+
* The human body plan for the v2 character system: a two-bone spine, a neck,
|
|
5
|
+
* two arms and two legs with feet, and a head.
|
|
6
|
+
*
|
|
7
|
+
* Pose fields (degrees unless noted):
|
|
8
|
+
* - `turn`: 0 faces the viewer, 1 faces screen-right, 2 shows the back, 3 faces screen-left
|
|
9
|
+
* - `lean` (forward +), `side` (toward the character's left +): the upper body
|
|
10
|
+
* - `head.turn` (toward its left +), `head.nod` (down +), `head.tilt` (toward its left shoulder +)
|
|
11
|
+
* - `arm.left.swing` (forward +), `arm.left.spread` (out +), `arm.left.elbow`
|
|
12
|
+
* (forearm forward +), `arm.left.bend` (forearm out +), and the same for `.right`
|
|
13
|
+
* - `leg.left.swing` (forward +), `leg.left.spread` (out +), `leg.left.knee`
|
|
14
|
+
* (shin back +), `leg.left.ankle` (toes up +), and the same for `.right`
|
|
15
|
+
* - `stretch` (1 normal), `lift` (fraction of height above the ground), `roll` (whole-figure roll, degrees)
|
|
16
|
+
* - the face: `mouth`, `smile`, `mouthWidth`, `blink`, `eye.left`, `eye.right`,
|
|
17
|
+
* `brow.left`, `brow.right`, `browTilt`, `lookX`, `lookY` (as the v1 stick figure)
|
|
18
|
+
*
|
|
19
|
+
* The character's left is +x: facing the viewer its left arm is on screen-right.
|
|
20
|
+
*/
|
|
21
|
+
export interface HumanBuild {
|
|
22
|
+
/** Head diameter, fraction of the height (default 0.3, the bold look) */
|
|
23
|
+
headSize?: number;
|
|
24
|
+
/** Half the shoulder width, fraction of the height (0: both arms from one point) */
|
|
25
|
+
shoulderWidth?: number;
|
|
26
|
+
/** Half the hip width, fraction of the height (0: both legs from one point) */
|
|
27
|
+
hipWidth?: number;
|
|
28
|
+
}
|
|
29
|
+
export declare const HUMAN_REST: Pose;
|
|
30
|
+
/** A full human pose from the fields that differ from rest. */
|
|
31
|
+
export declare function humanPose(changes?: Pose): Pose;
|
|
32
|
+
/**
|
|
33
|
+
* Ready-made human poses. Several rest on something other than the feet (a
|
|
34
|
+
* knee, the hands, the back): the figure is set down on whatever is lowest.
|
|
35
|
+
*/
|
|
36
|
+
export declare const HUMAN_POSES: {
|
|
37
|
+
rest: Pose;
|
|
38
|
+
wave: Pose;
|
|
39
|
+
cheer: Pose;
|
|
40
|
+
point: Pose;
|
|
41
|
+
handsOnHips: Pose;
|
|
42
|
+
think: Pose;
|
|
43
|
+
shrug: Pose;
|
|
44
|
+
sit: Pose;
|
|
45
|
+
kneel: Pose;
|
|
46
|
+
crouch: Pose;
|
|
47
|
+
crawl: Pose;
|
|
48
|
+
lieDown: Pose;
|
|
49
|
+
};
|
|
50
|
+
export type HumanPoseName = keyof typeof HUMAN_POSES;
|
|
51
|
+
/** A human body plan; the same pose fields work on every build. */
|
|
52
|
+
export declare function humanPlan(build?: HumanBuild): BodyPlan;
|
|
53
|
+
/** Plain-language names for the human pose fields, for timelines and property panels. */
|
|
54
|
+
export declare function humanFieldLabel(field: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* The ready-made faces (happy, sad, surprised, angry…), as human pose fields.
|
|
57
|
+
* Each sets every face field, so applying one replaces the whole face.
|
|
58
|
+
*/
|
|
59
|
+
export declare const HUMAN_EXPRESSIONS: Record<ExpressionName, Pose>;
|
|
@@ -200,7 +200,10 @@ export type SleeveLayer = (ctx: CanvasRenderingContext2D, joints: StickJoints, s
|
|
|
200
200
|
*
|
|
201
201
|
* The left arm is always the back arm, drawn first. The figure faces the
|
|
202
202
|
* viewer and is mirrored as a whole for `facing`, so its left side is always
|
|
203
|
-
* the one away from the way it looks.
|
|
203
|
+
* the one away from the way it looks. Turned more than a quarter of the way
|
|
204
|
+
* (`turn` above 0.25), the back arm and its sleeve move behind the body:
|
|
205
|
+
*
|
|
206
|
+
* behind → legs → back arm → sleeve(back) → torso → body → front arm → …
|
|
204
207
|
*/
|
|
205
208
|
export interface FigureLayers {
|
|
206
209
|
/** Before anything: long hair at the back, a cape, a shadow */
|
|
@@ -282,12 +285,7 @@ export interface StickJoints {
|
|
|
282
285
|
* seated (`sit` 1): put the top of a bench, log or charpai here.
|
|
283
286
|
*/
|
|
284
287
|
export declare function seatHeight(height: number, stretch?: number): number;
|
|
285
|
-
|
|
286
|
-
* Points along a limb, blending the jointed shape (two straight segments) into
|
|
287
|
-
* a rubber-hose curve by `rubber` 0..1. The curve is the quadratic that passes
|
|
288
|
-
* through the joint halfway along, so a bent limb keeps its bend, rounded.
|
|
289
|
-
*/
|
|
290
|
-
export declare function rubberLimb(root: Point, joint: Point, end: Point, rubber: number, samples?: number): Point[];
|
|
288
|
+
export { rubberLimb } from './look/curves';
|
|
291
289
|
/**
|
|
292
290
|
* Where every joint of a figure is, without drawing it: the same numbers
|
|
293
291
|
* {@link drawStickFigure} draws with. `figure` is the pose as drawn (use
|
|
@@ -303,12 +301,7 @@ export declare function stickFigureJoints(figure: StickPose, style?: StickStyle)
|
|
|
303
301
|
export declare function headPoint(head: StickHead, x: number, y: number): Point;
|
|
304
302
|
/** Joints moved from the figure's space to a scene where its feet stand at (x, y). */
|
|
305
303
|
export declare function jointsToScene(joints: StickJoints, x: number, y: number): StickJoints;
|
|
306
|
-
|
|
307
|
-
* Fill a line through `points` whose width runs from `startWidth` to
|
|
308
|
-
* `endWidth`, with round ends: a limb that tapers, or a sleeve or trouser leg
|
|
309
|
-
* along a joint polyline. Uses the context's fill style.
|
|
310
|
-
*/
|
|
311
|
-
export declare function taperedLine(ctx: CanvasRenderingContext2D, points: Point[], startWidth: number, endWidth: number): void;
|
|
304
|
+
export { taperedLine, taperedOutline } from './look/tapered-line';
|
|
312
305
|
/**
|
|
313
306
|
* Draw a figure with its feet at (0, 0). `time` (ms) matters for a sketched
|
|
314
307
|
* style (it picks which boil frame of the wobble shows) and is passed to any
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CharacterLayers } from '../character';
|
|
2
|
+
/**
|
|
3
|
+
* A first outfit for the human character: a T-shirt and trousers, drawn as
|
|
4
|
+
* layers on the body's parts, through the character's pen (so it matches the
|
|
5
|
+
* look). The sleeves grow out of the shirt's shoulders with no seam. The full
|
|
6
|
+
* wardrobe is a later milestone; this is the shape every garment will follow.
|
|
7
|
+
*/
|
|
8
|
+
export interface BasicOutfitOptions {
|
|
9
|
+
/** Shirt colour (default red) */
|
|
10
|
+
shirt?: string;
|
|
11
|
+
/** Trouser colour (default navy) */
|
|
12
|
+
trousers?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function basicOutfit(options?: BasicOutfitOptions): CharacterLayers;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@algorisys/tinyfly",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.77.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Lightweight, API-driven animation engine and editor. The engine is framework-agnostic and runs in browsers, Web Workers, and Node.",
|
|
6
6
|
"license": "MIT",
|