@plupin/character 0.0.0-stage → 0.3.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.
Files changed (53) hide show
  1. package/dist/anime-face.d.ts +42 -0
  2. package/dist/anime-face.js +14 -0
  3. package/dist/blob.d.ts +32 -0
  4. package/dist/blob.js +18 -0
  5. package/dist/body-presets.d.ts +85 -0
  6. package/dist/canvas.d.ts +79 -0
  7. package/dist/canvas.js +315 -0
  8. package/dist/chunk-09c5tps4.js +337 -0
  9. package/dist/chunk-60p135hw.js +103 -0
  10. package/dist/chunk-aa5nstet.js +39 -0
  11. package/dist/chunk-dpb0rnw9.js +37 -0
  12. package/dist/chunk-g1c0wdcj.js +825 -0
  13. package/dist/chunk-kber92gm.js +415 -0
  14. package/dist/chunk-sa2r1cxz.js +342 -0
  15. package/dist/chunk-yd5zzkkg.js +313 -0
  16. package/dist/clip-bake.d.ts +48 -0
  17. package/dist/clip-bake.js +132 -0
  18. package/dist/clips.d.ts +40 -0
  19. package/dist/dress.d.ts +4 -0
  20. package/dist/emote.d.ts +25 -0
  21. package/dist/faces.d.ts +10 -0
  22. package/dist/faces.js +12 -0
  23. package/dist/gaze.d.ts +81 -0
  24. package/dist/gaze.js +113 -0
  25. package/dist/hair3d.d.ts +3 -0
  26. package/dist/index.d.ts +19 -0
  27. package/dist/index.js +176 -0
  28. package/dist/listing.d.ts +195 -0
  29. package/dist/listing.js +763 -0
  30. package/dist/named-faces.d.ts +22 -0
  31. package/dist/platform-body-data.d.ts +9 -0
  32. package/dist/platform-body.d.ts +91 -0
  33. package/dist/plup2d.d.ts +29 -0
  34. package/dist/plup3d.d.ts +121 -0
  35. package/dist/png.d.ts +78 -0
  36. package/dist/pose.d.ts +49 -0
  37. package/dist/pose.js +18 -0
  38. package/dist/proportions.d.ts +31 -0
  39. package/dist/ragdoll.d.ts +51 -0
  40. package/dist/resolution.d.ts +21 -0
  41. package/dist/rig.d.ts +29 -0
  42. package/dist/skin-map.d.ts +155 -0
  43. package/dist/skin-map.js +55 -0
  44. package/dist/skin-native.d.ts +301 -0
  45. package/dist/skin.d.ts +35 -0
  46. package/dist/texture.d.ts +8 -0
  47. package/dist/three.d.ts +25 -0
  48. package/dist/three.js +2302 -0
  49. package/dist/wear3d.d.ts +99 -0
  50. package/dist/wearables.d.ts +203 -0
  51. package/dist/wearables.js +26 -0
  52. package/package.json +78 -4
  53. package/README.md +0 -3
@@ -0,0 +1,22 @@
1
+ export declare const NAMED_FACE_STAMPS: {
2
+ readonly sparkle: readonly [".ew..we.", ".ee..ee.", "p..mm..p", "........"];
3
+ readonly shock: readonly [".ee..ee.", ".ew..we.", "...mm...", "...mm..."];
4
+ readonly yell: readonly ["..e..e..", ".ew..we.", ".mmmmmm.", ".mttttm."];
5
+ readonly pain: readonly [".ee..ee.", "........", ".m.mm.m.", "..mmmm.."];
6
+ readonly dead: readonly ["www..www", "www..www", "..mmmm..", "........"];
7
+ readonly rage: readonly ["ee....ee", ".ee..ee.", ".mwwwwm.", "..mmmm.."];
8
+ readonly speechless: readonly ["........", ".e....e.", "........", "...mm..."];
9
+ readonly idea: readonly [".ee..ee.", ".ew..ew.", "..m..m..", "...mm..."];
10
+ readonly smug: readonly ["........", "eee..eee", "........", "..mmmm.."];
11
+ readonly cry: readonly ["eee..eee", "c......c", "c.mmmm.c", "..mttm.."];
12
+ readonly smirk: readonly [".ee..ee.", "........", "....mmm.", "........"];
13
+ readonly tongue: readonly ["........", ".ee..ee.", "...mm...", "...tt..."];
14
+ readonly cool: readonly ["eeeeeeee", ".ee..ee.", "..m..m..", "...mm..."];
15
+ readonly serious: readonly ["eee..eee", "ewe..ewe", "........", "..mmmm.."];
16
+ readonly stars: readonly [".y....y.", "yyy..yyy", "..mmmm..", "..mttm.."];
17
+ readonly licik: readonly [".ee..ee.", "........", ".mm..mm.", "..mmmm.."];
18
+ readonly tidur: readonly ["........", ".ee..ee.", "...mm...", "...mm..."];
19
+ readonly teriak: readonly ["..e..e..", ".e....e.", ".mmmmmm.", "..mttm.."];
20
+ readonly ngomel: readonly ["ee....ee", ".e....e.", "...mm...", "..m..m.."];
21
+ };
22
+ export type NamedFace = keyof typeof NAMED_FACE_STAMPS;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Generated by `bun run platform:bodies`. Do not edit by hand.
3
+ *
4
+ * Each value is the 512 x 256 native-grid PNG of a platform body model as the data URL a listing
5
+ * manifest stores. `paintPlatformBody()` in `platform-body.ts` is the code that draws it and
6
+ * `tests/platform-body.test.ts` re-encodes that painter and refuses a mismatch, so these strings
7
+ * cannot drift from the art by hand-editing either one.
8
+ */
9
+ export declare const PLATFORM_BODY_SHEETS: Readonly<Record<string, string>>;
@@ -0,0 +1,91 @@
1
+ import type { PngImage } from "./png";
2
+ import type { CanonicalBone } from "./rig";
3
+ import type { FaceName } from "./skin";
4
+ /**
5
+ * The platform's own body models: the one place a character's height comes from.
6
+ *
7
+ * Owner direction (20 Nov): a player does not type a stature. Height is a property of the body you
8
+ * are wearing, the way a Roblox body bundle decides proportions — you equip the kid-sized model to
9
+ * be small, and the tall model to be tall. So the three models below are ordinary outfit listings
10
+ * (`slot: "outfit"`, free starter rows, seeded by `00NN_platform_body_variants.sql` and by
11
+ * `ensureStarterCatalog`), each carrying a native-grid sheet and one authored `scale.stature`:
12
+ * 0.5 (bocil), 1.0 (normal) and 1.5 (tall), which is the whole usable range in
13
+ * `BODY_SCALE_LIMITS.stature`.
14
+ *
15
+ * The sheet is painted here as pixels and encoded by `png.ts`, so the bytes are reproducible from
16
+ * this file: `platform-body-data.ts` holds the stored data URL, `paintPlatformBody()` is the code
17
+ * that produces it, and a test compares the two. Nothing is fetched and nothing is hand-drawn in an
18
+ * image editor, so a change to a colour or a detail is a source change with a diff.
19
+ *
20
+ * The head is deliberately not one of the painted parts. A variant that listed the head would own
21
+ * the face rect and hide the player's face stamp; the platform body changes the body, and the face
22
+ * stays the player's.
23
+ */
24
+ /** What one model is: its listing id, the label a player reads, and the stature it draws at. */
25
+ export interface PlatformBody {
26
+ /** The `cosmetic_item.id` this model is seeded as. */
27
+ id: string;
28
+ /** The listing name, in the platform's Indonesian item-copy style. */
29
+ name: string;
30
+ /** The authored `scale.stature`: the only knob that differs between the three models. */
31
+ stature: number;
32
+ /** Base cloth, the trim on cuffs/belt/boots, and the shade stripe on each front. */
33
+ colors: {
34
+ base: Rgb;
35
+ trim: Rgb;
36
+ shade: Rgb;
37
+ highlight: Rgb;
38
+ };
39
+ }
40
+ type Rgb = readonly [number, number, number];
41
+ /**
42
+ * The three models. The colours differ so the size is not the only signal: a kid in mint, the
43
+ * canonical body in the platform blue, the tall one in ochre. Nothing here is a stat.
44
+ */
45
+ export declare const PLATFORM_BODIES: readonly PlatformBody[];
46
+ /**
47
+ * The model as a 512 x 256 native-grid raster: every face of every painted part filled with its
48
+ * cloth, a belt on the torso, cuffs on the arms, boots on the legs, and one shade stripe down each
49
+ * front and back so a flat box still reads as a box. The head's rects stay transparent — the rig
50
+ * paints them at the player's skin tone.
51
+ */
52
+ export declare function paintPlatformBody(body: PlatformBody): PngImage;
53
+ /** The manifest parts: every painted part, all six faces, no head. */
54
+ export declare function platformBodyParts(): {
55
+ part: CanonicalBone;
56
+ faces: FaceName[];
57
+ }[];
58
+ /** The proportion profile a model authors: one number, the rest canonical. */
59
+ export declare function platformBodyScale(body: PlatformBody): {
60
+ stature: number;
61
+ };
62
+ /** A seedable platform body as a `cosmetic_item` row: free, a starter, worn on the outfit slot. */
63
+ export interface PlatformBodyItem {
64
+ id: string;
65
+ slot: "outfit";
66
+ name: string;
67
+ /** The listing manifest the wardrobe and the renderer read. */
68
+ assetConfig: {
69
+ /** The generated sheet, as `data:image/png;base64,…`: the native grid itself. */
70
+ variant: string;
71
+ parts: {
72
+ part: CanonicalBone;
73
+ faces: FaceName[];
74
+ }[];
75
+ scale: {
76
+ stature: number;
77
+ };
78
+ };
79
+ }
80
+ /**
81
+ * Every platform body as the catalogue row it is seeded as. The three rows are ordinary free
82
+ * outfit listings, which is why a player picks a size by equipping one: `ensureStarterCatalog`
83
+ * inserts them and the starter flag owns them for everyone, so nothing is bought and nothing is a
84
+ * slider. The same list is what the migration `0068_platform_body_variants.sql` inserts, and
85
+ * `tests/platform-body.test.ts` compares the two.
86
+ *
87
+ * Built on first use rather than at import: a few kilobytes of base64 are not worth an API isolate's
88
+ * cold start, and a test that only reads `PLATFORM_BODIES` should not pay for the sheets.
89
+ */
90
+ export declare function platformBodyItems(): readonly PlatformBodyItem[];
91
+ export {};
@@ -0,0 +1,29 @@
1
+ import { type NamedFace } from "./faces";
2
+ import type { ClipRef, Pose } from "./pose";
3
+ /**
4
+ * Plup, flat and pixel-drawn: the 2D counterpart of `createPlup` (three.js). A round toon body with a
5
+ * paler belly, a highlight, an ink outline, a stamped face, stub arms and feet, a ground shadow.
6
+ * Poses come from `planCharacter2D` on the `plup` rig, so any clip or emote moves it. Shapes are
7
+ * drawn small, snapped to opaque or empty pixels and scaled up unfiltered, so the edges are pixels.
8
+ */
9
+ export interface PlupOptions2D {
10
+ color: string;
11
+ face?: NamedFace;
12
+ x: number;
13
+ y: number;
14
+ /** Canvas pixels per stud (Plup is 3.4 studs tall). */
15
+ scale: number;
16
+ clip?: ClipRef;
17
+ seconds?: number;
18
+ pose?: Pose;
19
+ /** Squash and stretch about the feet, for idle breathing. */
20
+ squash?: {
21
+ x: number;
22
+ y: number;
23
+ };
24
+ flip?: boolean;
25
+ shadow?: boolean;
26
+ /** Drawn pixels per stud. Fewer is chunkier. Default 12. */
27
+ ppu?: number;
28
+ }
29
+ export declare function drawPlup2D(ctx: CanvasRenderingContext2D, options: PlupOptions2D): void;
@@ -0,0 +1,121 @@
1
+ import { Group, type Object3D, ShaderMaterial, type Texture } from "three";
2
+ import { type Emote } from "./emote";
3
+ import { type NamedFace } from "./faces";
4
+ import { type ClipRef, type Pose } from "./pose";
5
+ import { type RagdollMode } from "./ragdoll";
6
+ import { BODY_SHAPES, type BodyShapeId } from "./skin-map";
7
+ import { type BodyScale, type PlupBody } from "./skin-native";
8
+ import { type WearKey } from "./wearables";
9
+ /**
10
+ * Plup in three.js: the round mascot the lobby shows, as a plain scene object any game can add.
11
+ *
12
+ * What makes it Plup and not a box: a bottom-heavy blob body wearing a 48 x 24 pixel map (sampled
13
+ * with no filtering, so the pixels stay pixels), a hard-banded toon shader with a rim, a dark ink
14
+ * outline and a neon edge from inverted hulls, rubber stub arms with round hands, flat round feet and
15
+ * a face stamped from the same named faces the films and the emotes use. Poses come from the same
16
+ * clips as every rig (a built-in, an emote's keyframes, a CC0 bake), so one animation moves it.
17
+ *
18
+ * Feet stand at y = 0, it faces +z, and the body is about 1.1 units tall: scale the group to taste.
19
+ */
20
+ /** The expressions a face rule shows (the 8 x 4 stamp is built by `faceStamp` in skin-map, shared with the app). */
21
+ export type Expression = "idle" | "blink" | "happy" | "surprised" | "sad" | "wee";
22
+ export type PlupFace = NamedFace | Expression;
23
+ export type { BodyShapeId, FaceType } from "./skin-map";
24
+ export { BODY_SHAPES };
25
+ export interface ToonOptions {
26
+ map?: Texture;
27
+ color?: string;
28
+ /** Seen from both sides (an open shell). */
29
+ double?: boolean;
30
+ /** The inside's colour, for a lined cape; the outside's by default. */
31
+ back?: string;
32
+ /** How many times the map repeats across the surface. */
33
+ repeat?: readonly [number, number];
34
+ /** 0 cloth, ~0.5 satin, ~0.8 metal and glass. */
35
+ sheen?: number;
36
+ /** Anime hair: the skull's centre the shading wraps round, and how strong its angel ring is. */
37
+ anime?: {
38
+ center: readonly [number, number, number];
39
+ ring?: number;
40
+ /** The colour the hair runs to at the tips. */
41
+ tip?: string;
42
+ /** The underside of a lock, seen where it twists. */
43
+ inner?: string;
44
+ };
45
+ }
46
+ export declare function toon(options: ToonOptions): ShaderMaterial;
47
+ /** A player's drawn skin: 24 rows of 48 palette letters and the face type they chose. */
48
+ export interface PlupSkin {
49
+ body: readonly string[];
50
+ faceType?: string;
51
+ }
52
+ export interface PlupOptions {
53
+ /** The body colour. Default Plup blue. */
54
+ color?: string;
55
+ /** A named face or an expression. Default `smug`. */
56
+ face?: PlupFace;
57
+ /** The player's own pixel skin (the platform's look). Without one the default Plup is drawn. */
58
+ skin?: PlupSkin;
59
+ /** The face type (dot, sparkle, sleepy, derp, anime) when no drawn skin is given. Default dot. */
60
+ faceType?: string;
61
+ /** The iris colour of the anime face. Default violet. */
62
+ eyeColor?: string;
63
+ /** The body proportions the player picked. Default `plup`. */
64
+ shape?: BodyShapeId;
65
+ /**
66
+ * An unusual body: stature, how thick the belly, arms and legs are, how big the head. The clips keep their
67
+ * angles and adapt (arms clear a wide belly, a heavy body jumps lower), see `plupProportions`.
68
+ */
69
+ bodyScale?: Partial<BodyScale> | null;
70
+ /** A soft contact shadow under the feet. Default true. */
71
+ shadow?: boolean;
72
+ /**
73
+ * A body of a different shape. The 48 x 24 pixel map, the blob and the stub limbs are only the
74
+ * default Plup: pass any scene object (a glTF scene, a hand-built mesh) and it is posed instead.
75
+ * Nodes named `armL`, `armR`, `legL`, `legR` follow the clips; a model with none still gets the
76
+ * clip's lift and sway, so any animation plays on any shape.
77
+ */
78
+ model?: Object3D;
79
+ /**
80
+ * The outline and limbs: broad shoulders, a pinched waist, full hips, long legs, thick arms. With
81
+ * `shape` and `bodyScale` this is how a muscular, a curvy or a tall-and-slim Plup is made; see
82
+ * `BODY_PRESETS`. Everything it wears is fitted to it.
83
+ */
84
+ body?: Partial<PlupBody> | null;
85
+ /** What it has on: real 3D pieces (`WEARABLES`), hair, headwear and clothes at once. */
86
+ wear?: readonly WearKey[];
87
+ /**
88
+ * A floppy body (see `ragdoll.ts`): `wobbly` limbs lag and overshoot like Human: Fall Flat, `limp`
89
+ * falls over. Default `off`: the clip is played exactly. A game can switch it any time with `ragdoll`.
90
+ */
91
+ ragdoll?: RagdollMode;
92
+ }
93
+ export interface PlupHandle {
94
+ /** Add this to a scene. Feet at y = 0, facing +z, about 1.1 units tall. */
95
+ object: Group;
96
+ /** Set the current clip (a name or keyframes). Call `update` every frame. */
97
+ play: (clip: ClipRef) => void;
98
+ /** Play an emote by name and pull its face. Returns it so the game can show its glyph. */
99
+ emote: (name: string, custom?: Emote) => Emote | undefined;
100
+ /** Hold a joint on top of the clip, e.g. `{ armR: { x: -1.2 } }`. Pass `{}` to let go. */
101
+ pose: (pose: Pose) => void;
102
+ /** A joint to attach things to (`armR`, `armL`, `legR`, `legL`) or the lifted body (`body`). */
103
+ bone: (name: string) => Object3D | undefined;
104
+ setFace: (face: PlupFace) => void;
105
+ /** Switch the floppy body: `off`, `wobbly` (active ragdoll) or `limp` (falls over). */
106
+ ragdoll: (mode: RagdollMode) => void;
107
+ /**
108
+ * Shove it, in world units per second. A small push makes a wobbly body stagger; a big one (over about
109
+ * 2.5) knocks any body over. A body knocked over while `off` stays down until `ragdoll("off")`; a
110
+ * wobbly one gets back up by itself.
111
+ */
112
+ push: (x: number, y: number, z: number) => void;
113
+ /** Lying on the ground after a fall. */
114
+ isDown: () => boolean;
115
+ setColor: (color: string) => void;
116
+ /** Put these on (and take off anything else). */
117
+ setWear: (wear: readonly WearKey[]) => void;
118
+ update: (deltaSeconds: number) => void;
119
+ dispose: () => void;
120
+ }
121
+ export declare function createPlup(options?: PlupOptions): PlupHandle;
package/dist/png.d.ts ADDED
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The PNG reader and writer the listing kinds and the platform's own body models need.
3
+ *
4
+ * A body variant is a sprite sheet the platform clips to its part rects, so the server has to do
5
+ * two things the browser would otherwise do for it: know the sheet's dimensions *before* it trusts
6
+ * them, and be able to draw the art into the stored preview the moderator decides on. Both mean
7
+ * reading the file's bytes on the Worker, where there is no canvas — hence this module. The writer
8
+ * is its mirror image: the seeded platform bodies are painted from `platform-body.ts` as pixels, so
9
+ * a PNG has to be produced without a canvas too, and a fixture can then be the same bytes the
10
+ * migration stores.
11
+ *
12
+ * It is deliberately strict about the format the caps describe (`NATIVE_SHEET_CAPS`,
13
+ * `LISTING_ASSET_CAPS`): 8-bit truecolour with or without 8-bit alpha, non-interlaced, no palette.
14
+ * A palette PNG or a 16-bit one is a different picture than the one the moderator approved once a
15
+ * second decoder is involved, so it is refused instead of converted.
16
+ *
17
+ * Inflate is `fflate`'s synchronous one: the renderer is a pure function (`renderListingPreview`)
18
+ * that four surfaces already call without awaiting, and a `DecompressionStream` would have made it
19
+ * async and every caller with it.
20
+ *
21
+ * It checks structure and pixels, not chunk CRCs: zlib's own Adler-32 rejects a damaged IDAT, and
22
+ * the one thing a checksum would add here — "this file was edited after it was written" — is not a
23
+ * property the caps care about. The bytes are hashed as uploaded either way.
24
+ */
25
+ /** RGBA, row-major, straight alpha: the same shape `tests/support/raster.ts` rasterises into. */
26
+ export interface PngImage {
27
+ width: number;
28
+ height: number;
29
+ data: Uint8Array;
30
+ }
31
+ export type PngProblem = "not_png" | "truncated" | "bad_header" | "unsupported_format" | "interlaced" | "corrupt" | "too_large";
32
+ export interface PngHeader {
33
+ width: number;
34
+ height: number;
35
+ /** 1 (greyscale), 2 (truecolour), 3 (palette), 4 (greyscale+alpha), 6 (truecolour+alpha). */
36
+ colorType: number;
37
+ bitDepth: number;
38
+ interlaced: boolean;
39
+ }
40
+ /** The dimensions and format, without inflating anything: what the caps are checked against. */
41
+ export declare function readPngHeader(bytes: Uint8Array): {
42
+ ok: true;
43
+ header: PngHeader;
44
+ } | {
45
+ ok: false;
46
+ reason: PngProblem;
47
+ };
48
+ /**
49
+ * The pixels, as RGBA. A caller that has already checked the caps has bounded the work here: the
50
+ * largest sheet the platform accepts is 585 x 559, so the buffer is at most 1.3 MB.
51
+ */
52
+ export declare function decodePng(bytes: Uint8Array): {
53
+ ok: true;
54
+ image: PngImage;
55
+ } | {
56
+ ok: false;
57
+ reason: PngProblem;
58
+ };
59
+ /** Base64 without a DOM: the manifest's data URL is built on the Worker as well as in a test. */
60
+ export declare function encodeBase64(bytes: Uint8Array): string;
61
+ /**
62
+ * Strict base64, because the manifest is a string a reader may have edited: `atob` accepts
63
+ * whitespace and silently ignores what it does not understand, and two spellings of one image would
64
+ * then hash differently. Anything that is not `A-Za-z0-9+/` padded to a multiple of four is refused.
65
+ */
66
+ export declare function decodeBase64(value: string): Uint8Array<ArrayBuffer> | null;
67
+ /**
68
+ * The mirror of `decodePng`: an RGBA raster as PNG-24 with an alpha channel, 8 bits per channel,
69
+ * filter 0. That is exactly the format `NATIVE_SHEET_CAPS` describes, so the bytes a platform body
70
+ * model is seeded with are the bytes a creator could have uploaded — the same reader, the same
71
+ * clip-to-rect renderer, the same cap.
72
+ *
73
+ * `level` exists for the one caller that wants the smallest file it can get (a manifest stored in a
74
+ * SQL migration); the default matches `fflate`'s own.
75
+ */
76
+ export declare function encodePng(image: PngImage, options?: {
77
+ level?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
78
+ }): Uint8Array<ArrayBuffer>;
package/dist/pose.d.ts ADDED
@@ -0,0 +1,49 @@
1
+ import { type AuthoredClipName } from "./clips";
2
+ import { type CanonicalBone, type RigId } from "./rig";
3
+ /** Euler rotation in radians, applied at the joint. */
4
+ export interface Rotation {
5
+ x?: number;
6
+ y?: number;
7
+ z?: number;
8
+ }
9
+ /** Keys are canonical names (armL) or a rig's own bone names (LeftLowerArm). */
10
+ export type Pose = Readonly<Record<string, Rotation>>;
11
+ /**
12
+ * Every clip the rig has by name. The first six are procedural loops; the rest are the authored
13
+ * keyframe library in `clips.ts`, which is why a game and a creator emote can name a real motion
14
+ * (`sneak`, `topple`) instead of borrowing `idle`.
15
+ */
16
+ export type ClipName = "idle" | "walk" | "run" | "jump" | "wave" | "dance" | AuthoredClipName;
17
+ type Clip = (t: number) => Partial<Record<CanonicalBone, Rotation>> & {
18
+ lift?: number;
19
+ };
20
+ export declare const CLIPS: Readonly<Record<ClipName, Clip>>;
21
+ /**
22
+ * A clip a creator ships instead of naming one the rig already has: keyframes, sampled linearly.
23
+ *
24
+ * `bones` names the canonical bones the clip drives; every frame is `[x, y, z]` per bone in that
25
+ * order and then one `lift`, so a frame is `bones.length * 3 + 1` numbers. Radians and studs, the
26
+ * same units the built-in clips return, which is what lets one renderer play both. Bones a clip does
27
+ * not name keep the rest pose.
28
+ */
29
+ export interface CustomClip {
30
+ fps: number;
31
+ loop: boolean;
32
+ bones: readonly CanonicalBone[];
33
+ frames: readonly (readonly number[])[];
34
+ }
35
+ /** A clip the rig has by name, or one that arrived as keyframes. */
36
+ export type ClipRef = ClipName | CustomClip;
37
+ export declare const isCustomClip: (clip: ClipRef) => clip is CustomClip;
38
+ /** Seconds a custom clip runs once. */
39
+ export declare const customDuration: (clip: CustomClip) => number;
40
+ /** One clip at one moment, as a pose. */
41
+ export declare function sampleClip(clip: ClipRef, seconds: number): Pose & {
42
+ lift?: never;
43
+ };
44
+ export declare function clipLift(clip: ClipRef, seconds: number): number;
45
+ /** Later poses win per axis. Use it to layer an aim or a wave on top of a walk. */
46
+ export declare function mergePoses(...poses: readonly Pose[]): Pose;
47
+ /** Resolves canonical names, and folds every joint a rig does not have into its nearest parent. */
48
+ export declare function resolvePose(rigId: RigId, pose: Pose): ReadonlyMap<string, Rotation>;
49
+ export {};
package/dist/pose.js ADDED
@@ -0,0 +1,18 @@
1
+ import {
2
+ CLIPS,
3
+ clipLift,
4
+ customDuration,
5
+ isCustomClip,
6
+ mergePoses,
7
+ resolvePose,
8
+ sampleClip
9
+ } from "./chunk-g1c0wdcj.js";
10
+ export {
11
+ sampleClip,
12
+ resolvePose,
13
+ mergePoses,
14
+ isCustomClip,
15
+ customDuration,
16
+ clipLift,
17
+ CLIPS
18
+ };
@@ -0,0 +1,31 @@
1
+ import { type BodyScale } from "./skin-native";
2
+ /**
3
+ * How a Plup's size changes what its motion has to do. A clip is authored on the normal body: angles for the
4
+ * arms and legs, a lift for a jump. A big, wide, tall or small body keeps those angles but needs three things
5
+ * adjusted so the same clip still reads as the same move (ADR 0024):
6
+ *
7
+ * - the arms start further out on a wide belly, and swing out a little more so they do not sink into it;
8
+ * - a jump's height scales with the stature, and a heavier (wider) body jumps a bit lower and squashes more;
9
+ * - limbs get thicker or thinner with their own width, without changing the clip.
10
+ *
11
+ * Pure numbers, no three, so the rules are tested and every surface (app, games, films) reads the same ones.
12
+ */
13
+ export interface PlupProportions {
14
+ /** The whole figure's scale (stature). */
15
+ stature: number;
16
+ /** Girth of the belly across and front to back, shape included. 1 is the normal Plup. */
17
+ girth: number;
18
+ /** Arm and leg thickness factors, left then right. */
19
+ armWidth: readonly [number, number];
20
+ legWidth: readonly [number, number];
21
+ /** Radians the arms swing outward on top of the clip, so a wide belly is cleared. */
22
+ armClear: readonly [number, number];
23
+ /** Multiplier on a clip's lift: the jump of this body. */
24
+ lift: number;
25
+ /** Multiplier on the breathing squash: a heavier body moves more. */
26
+ squash: number;
27
+ }
28
+ export declare function plupProportions(shape: {
29
+ x: number;
30
+ y: number;
31
+ }, scale?: Partial<BodyScale> | null): PlupProportions;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * An optional floppy body, the way Human: Fall Flat and Gang Beasts feel: an **active ragdoll**. The clip
3
+ * still says where every joint should be, but each joint is pulled there by a damped spring instead of
4
+ * being set, so limbs lag, overshoot and wobble when the body speeds up, stops or is pushed. Push hard
5
+ * enough (or call `limp`) and the springs let go: the body tips over under gravity, lands, bounces and lies
6
+ * there with its limbs flopped out until it gets up again.
7
+ *
8
+ * No physics engine: per-joint springs and a position-based fall (Verlet style), cheap enough for a crowd.
9
+ * Sources and the rules taken from them are in docs/product/research-anime-hair-and-bodies.md.
10
+ *
11
+ * Angles are radians in the body's own frame: `x` tips forward (+z), `z` rolls sideways.
12
+ */
13
+ export type RagdollMode = "off" | "wobbly" | "limp";
14
+ export declare const RAGDOLL_JOINTS: readonly ["armL", "armR", "legL", "legR"];
15
+ export type RagdollJoint = (typeof RAGDOLL_JOINTS)[number];
16
+ export interface Tilt {
17
+ x: number;
18
+ z: number;
19
+ }
20
+ /** What the clip wants this frame, and how the game moved the body. */
21
+ export interface RagdollInput {
22
+ joints: Record<RagdollJoint, Tilt>;
23
+ body: Tilt;
24
+ lift: number;
25
+ /** The body's velocity in its own frame (x sideways, z forward), from how the game moved it. */
26
+ velocity: {
27
+ x: number;
28
+ z: number;
29
+ };
30
+ }
31
+ export interface RagdollOutput {
32
+ joints: Record<RagdollJoint, Tilt>;
33
+ body: Tilt;
34
+ lift: number;
35
+ /** How far the fall carried the body from where the game put it, in its own frame. */
36
+ offset: {
37
+ x: number;
38
+ z: number;
39
+ };
40
+ /** Lying on the ground (or on the way there). */
41
+ down: boolean;
42
+ }
43
+ export interface Ragdoll {
44
+ mode: () => RagdollMode;
45
+ set: (mode: RagdollMode) => void;
46
+ /** Shove the body: `x` sideways, `z` forward, `y` up, in its own frame (units per second). */
47
+ push: (x: number, y: number, z: number) => void;
48
+ step: (dt: number, input: RagdollInput) => RagdollOutput;
49
+ }
50
+ /** `radius`: how far the body's middle sits from its base, so it lies on the ground, not in it. */
51
+ export declare function createRagdoll(initial?: RagdollMode, radius?: number): Ragdoll;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * How many pixels Plup is drawn with, for every surface (ADR 0024). Plup is pixel art: the pixel grid
3
+ * must scale with Plup, not with the page. A fixed render scale gave a big Plup a fine grid and a small
4
+ * one a handful of coarse pixels, so a Plup in a header or a section slot lost its face. Here the
5
+ * render scale follows the size Plup is shown at, so Plup keeps about the same number of pixels from
6
+ * the landing hero down to a lobby rail, and never more than the screen has.
7
+ */
8
+ /** Render pixels from Plup's feet to the top of its head, at any size on screen. */
9
+ export declare const PLUP_PIXELS = 120;
10
+ /**
11
+ * Device pixels per CSS pixel to render a Plup that is `plupCssHeight` CSS pixels tall with, so it is
12
+ * drawn with about `pixels` rows: chunky when it is big, the screen's full resolution when it is small.
13
+ */
14
+ export declare function plupPixelRatio(plupCssHeight: number, devicePixelRatio: number, pixels?: number): number;
15
+ /**
16
+ * Draws pixel art onto a canvas of any size, the way the eye expects it: every source pixel becomes a
17
+ * whole block (nearest neighbour up to the next whole multiple), then that is filtered down to the
18
+ * target, so a source pixel never comes out one or two device pixels wide at random and a small
19
+ * headshot averages its pixels instead of dropping every other row (an eye of two rows lost one).
20
+ */
21
+ export declare function drawPixelArt(context: CanvasRenderingContext2D, source: HTMLCanvasElement, width: number, height: number): void;
package/dist/rig.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Rigs. A rig is a tree of named boxes. Sizes use Roblox studs, so a skin made for a Roblox avatar
3
+ * lands on the same proportions here. Every rig answers to the same six names (head, torso, armL,
4
+ * armR, legL, legR), so a pose or a clip written once drives all of them.
5
+ */
6
+ export type Vec3 = readonly [number, number, number];
7
+ export interface Bone {
8
+ name: string;
9
+ parent: string | null;
10
+ /** Joint position relative to the parent's joint, in studs. */
11
+ joint: Vec3;
12
+ /** Box size in studs. */
13
+ size: Vec3;
14
+ /** Box centre relative to this bone's joint. */
15
+ center: Vec3;
16
+ }
17
+ export interface Rig {
18
+ id: RigId;
19
+ bones: readonly Bone[];
20
+ /** Canonical limb name to the bone that a clip rotates. */
21
+ aliases: Readonly<Record<CanonicalBone, string>>;
22
+ /** Second segment of a limb: bends at the elbow or knee, when the rig has one. */
23
+ lower: Partial<Readonly<Record<CanonicalBone, string>>>;
24
+ height: number;
25
+ }
26
+ export type RigId = "plup" | "r6" | "r15";
27
+ export type CanonicalBone = "head" | "torso" | "armL" | "armR" | "legL" | "legR";
28
+ export declare const RIGS: Readonly<Record<RigId, Rig>>;
29
+ export declare function boneOf(rig: Rig, name: string): Bone | undefined;