@plupin/character 0.0.0-stage → 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/dist/canvas.d.ts +79 -0
- package/dist/canvas.js +315 -0
- package/dist/chunk-aa5nstet.js +39 -0
- package/dist/chunk-ae7gp5cc.js +101 -0
- package/dist/chunk-k5gwaq6t.js +315 -0
- package/dist/chunk-wpbgtn0y.js +179 -0
- package/dist/clip-bake.d.ts +48 -0
- package/dist/clip-bake.js +132 -0
- package/dist/emote.d.ts +23 -0
- package/dist/faces.d.ts +10 -0
- package/dist/faces.js +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +102 -0
- package/dist/listing.d.ts +195 -0
- package/dist/listing.js +753 -0
- package/dist/named-faces.d.ts +22 -0
- package/dist/plup2d.d.ts +29 -0
- package/dist/plup3d.d.ts +73 -0
- package/dist/png.d.ts +61 -0
- package/dist/pose.d.ts +43 -0
- package/dist/pose.js +18 -0
- package/dist/rig.d.ts +29 -0
- package/dist/skin-native.d.ts +252 -0
- package/dist/skin.d.ts +35 -0
- package/dist/three.d.ts +22 -0
- package/dist/three.js +581 -0
- package/package.json +58 -4
- 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;
|
package/dist/plup2d.d.ts
ADDED
|
@@ -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;
|
package/dist/plup3d.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Group, type Object3D } from "three";
|
|
2
|
+
import { type Emote } from "./emote";
|
|
3
|
+
import { type NamedFace } from "./faces";
|
|
4
|
+
import { type ClipRef, type Pose } from "./pose";
|
|
5
|
+
/** Bodies a Plup can have: the same skeleton, only the blob's proportions change. */
|
|
6
|
+
export declare const BODY_SHAPES: {
|
|
7
|
+
readonly plup: {
|
|
8
|
+
readonly x: 1;
|
|
9
|
+
readonly y: 1;
|
|
10
|
+
};
|
|
11
|
+
readonly tall: {
|
|
12
|
+
readonly x: 0.88;
|
|
13
|
+
readonly y: 1.25;
|
|
14
|
+
};
|
|
15
|
+
readonly wide: {
|
|
16
|
+
readonly x: 1.2;
|
|
17
|
+
readonly y: 0.85;
|
|
18
|
+
};
|
|
19
|
+
readonly mini: {
|
|
20
|
+
readonly x: 0.82;
|
|
21
|
+
readonly y: 0.82;
|
|
22
|
+
};
|
|
23
|
+
readonly bean: {
|
|
24
|
+
readonly x: 0.72;
|
|
25
|
+
readonly y: 1.35;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export type BodyShapeId = keyof typeof BODY_SHAPES;
|
|
29
|
+
/** The face types a player draws with, and the expressions they show (the stamp is 8 x 4). */
|
|
30
|
+
export type FaceType = "dot" | "sparkle" | "sleepy" | "derp";
|
|
31
|
+
export type Expression = "idle" | "blink" | "happy" | "surprised" | "sad" | "wee";
|
|
32
|
+
export type PlupFace = NamedFace | Expression;
|
|
33
|
+
/** A player's drawn skin: 24 rows of 48 palette letters and the face type they chose. */
|
|
34
|
+
export interface PlupSkin {
|
|
35
|
+
body: readonly string[];
|
|
36
|
+
faceType?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface PlupOptions {
|
|
39
|
+
/** The body colour. Default Plup blue. */
|
|
40
|
+
color?: string;
|
|
41
|
+
/** A named face or an expression. Default `smug`. */
|
|
42
|
+
face?: PlupFace;
|
|
43
|
+
/** The player's own pixel skin (the platform's look). Without one the default Plup is drawn. */
|
|
44
|
+
skin?: PlupSkin;
|
|
45
|
+
/** The body proportions the player picked. Default `plup`. */
|
|
46
|
+
shape?: BodyShapeId;
|
|
47
|
+
/** A soft contact shadow under the feet. Default true. */
|
|
48
|
+
shadow?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* A body of a different shape. The 48 x 24 pixel map, the blob and the stub limbs are only the
|
|
51
|
+
* default Plup: pass any scene object (a glTF scene, a hand-built mesh) and it is posed instead.
|
|
52
|
+
* Nodes named `armL`, `armR`, `legL`, `legR` follow the clips; a model with none still gets the
|
|
53
|
+
* clip's lift and sway, so any animation plays on any shape.
|
|
54
|
+
*/
|
|
55
|
+
model?: Object3D;
|
|
56
|
+
}
|
|
57
|
+
export interface PlupHandle {
|
|
58
|
+
/** Add this to a scene. Feet at y = 0, facing +z, about 1.1 units tall. */
|
|
59
|
+
object: Group;
|
|
60
|
+
/** Set the current clip (a name or keyframes). Call `update` every frame. */
|
|
61
|
+
play: (clip: ClipRef) => void;
|
|
62
|
+
/** Play an emote by name and pull its face. Returns it so the game can show its glyph. */
|
|
63
|
+
emote: (name: string, custom?: Emote) => Emote | undefined;
|
|
64
|
+
/** Hold a joint on top of the clip, e.g. `{ armR: { x: -1.2 } }`. Pass `{}` to let go. */
|
|
65
|
+
pose: (pose: Pose) => void;
|
|
66
|
+
/** A joint to attach things to (`armR`, `armL`, `legR`, `legL`) or the lifted body (`body`). */
|
|
67
|
+
bone: (name: string) => Object3D | undefined;
|
|
68
|
+
setFace: (face: PlupFace) => void;
|
|
69
|
+
setColor: (color: string) => void;
|
|
70
|
+
update: (deltaSeconds: number) => void;
|
|
71
|
+
dispose: () => void;
|
|
72
|
+
}
|
|
73
|
+
export declare function createPlup(options?: PlupOptions): PlupHandle;
|
package/dist/png.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The PNG reader the listing kinds need, and nothing more.
|
|
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.
|
|
8
|
+
*
|
|
9
|
+
* It is deliberately strict about the format the caps describe (`NATIVE_SHEET_CAPS`,
|
|
10
|
+
* `LISTING_ASSET_CAPS`): 8-bit truecolour with or without 8-bit alpha, non-interlaced, no palette.
|
|
11
|
+
* A palette PNG or a 16-bit one is a different picture than the one the moderator approved once a
|
|
12
|
+
* second decoder is involved, so it is refused instead of converted.
|
|
13
|
+
*
|
|
14
|
+
* Inflate is `fflate`'s synchronous one: the renderer is a pure function (`renderListingPreview`)
|
|
15
|
+
* that four surfaces already call without awaiting, and a `DecompressionStream` would have made it
|
|
16
|
+
* async and every caller with it.
|
|
17
|
+
*
|
|
18
|
+
* It checks structure and pixels, not chunk CRCs: zlib's own Adler-32 rejects a damaged IDAT, and
|
|
19
|
+
* the one thing a checksum would add here — "this file was edited after it was written" — is not a
|
|
20
|
+
* property the caps care about. The bytes are hashed as uploaded either way.
|
|
21
|
+
*/
|
|
22
|
+
/** RGBA, row-major, straight alpha: the same shape `tests/support/raster.ts` rasterises into. */
|
|
23
|
+
export interface PngImage {
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
data: Uint8Array;
|
|
27
|
+
}
|
|
28
|
+
export type PngProblem = "not_png" | "truncated" | "bad_header" | "unsupported_format" | "interlaced" | "corrupt" | "too_large";
|
|
29
|
+
export interface PngHeader {
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
/** 1 (greyscale), 2 (truecolour), 3 (palette), 4 (greyscale+alpha), 6 (truecolour+alpha). */
|
|
33
|
+
colorType: number;
|
|
34
|
+
bitDepth: number;
|
|
35
|
+
interlaced: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** The dimensions and format, without inflating anything: what the caps are checked against. */
|
|
38
|
+
export declare function readPngHeader(bytes: Uint8Array): {
|
|
39
|
+
ok: true;
|
|
40
|
+
header: PngHeader;
|
|
41
|
+
} | {
|
|
42
|
+
ok: false;
|
|
43
|
+
reason: PngProblem;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* The pixels, as RGBA. A caller that has already checked the caps has bounded the work here: the
|
|
47
|
+
* largest sheet the platform accepts is 585 x 559, so the buffer is at most 1.3 MB.
|
|
48
|
+
*/
|
|
49
|
+
export declare function decodePng(bytes: Uint8Array): {
|
|
50
|
+
ok: true;
|
|
51
|
+
image: PngImage;
|
|
52
|
+
} | {
|
|
53
|
+
ok: false;
|
|
54
|
+
reason: PngProblem;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Strict base64, because the manifest is a string a reader may have edited: `atob` accepts
|
|
58
|
+
* whitespace and silently ignores what it does not understand, and two spellings of one image would
|
|
59
|
+
* then hash differently. Anything that is not `A-Za-z0-9+/` padded to a multiple of four is refused.
|
|
60
|
+
*/
|
|
61
|
+
export declare function decodeBase64(value: string): Uint8Array<ArrayBuffer> | null;
|
package/dist/pose.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type CanonicalBone, type RigId } from "./rig";
|
|
2
|
+
/** Euler rotation in radians, applied at the joint. */
|
|
3
|
+
export interface Rotation {
|
|
4
|
+
x?: number;
|
|
5
|
+
y?: number;
|
|
6
|
+
z?: number;
|
|
7
|
+
}
|
|
8
|
+
/** Keys are canonical names (armL) or a rig's own bone names (LeftLowerArm). */
|
|
9
|
+
export type Pose = Readonly<Record<string, Rotation>>;
|
|
10
|
+
export type ClipName = "idle" | "walk" | "run" | "jump" | "wave" | "dance";
|
|
11
|
+
type Clip = (t: number) => Partial<Record<CanonicalBone, Rotation>> & {
|
|
12
|
+
lift?: number;
|
|
13
|
+
};
|
|
14
|
+
export declare const CLIPS: Readonly<Record<ClipName, Clip>>;
|
|
15
|
+
/**
|
|
16
|
+
* A clip a creator ships instead of naming one the rig already has: keyframes, sampled linearly.
|
|
17
|
+
*
|
|
18
|
+
* `bones` names the canonical bones the clip drives; every frame is `[x, y, z]` per bone in that
|
|
19
|
+
* order and then one `lift`, so a frame is `bones.length * 3 + 1` numbers. Radians and studs, the
|
|
20
|
+
* same units the built-in clips return, which is what lets one renderer play both. Bones a clip does
|
|
21
|
+
* not name keep the rest pose.
|
|
22
|
+
*/
|
|
23
|
+
export interface CustomClip {
|
|
24
|
+
fps: number;
|
|
25
|
+
loop: boolean;
|
|
26
|
+
bones: readonly CanonicalBone[];
|
|
27
|
+
frames: readonly (readonly number[])[];
|
|
28
|
+
}
|
|
29
|
+
/** A clip the rig has by name, or one that arrived as keyframes. */
|
|
30
|
+
export type ClipRef = ClipName | CustomClip;
|
|
31
|
+
export declare const isCustomClip: (clip: ClipRef) => clip is CustomClip;
|
|
32
|
+
/** Seconds a custom clip runs once. */
|
|
33
|
+
export declare const customDuration: (clip: CustomClip) => number;
|
|
34
|
+
/** One clip at one moment, as a pose. */
|
|
35
|
+
export declare function sampleClip(clip: ClipRef, seconds: number): Pose & {
|
|
36
|
+
lift?: never;
|
|
37
|
+
};
|
|
38
|
+
export declare function clipLift(clip: ClipRef, seconds: number): number;
|
|
39
|
+
/** Later poses win per axis. Use it to layer an aim or a wave on top of a walk. */
|
|
40
|
+
export declare function mergePoses(...poses: readonly Pose[]): Pose;
|
|
41
|
+
/** Resolves canonical names, and folds every joint a rig does not have into its nearest parent. */
|
|
42
|
+
export declare function resolvePose(rigId: RigId, pose: Pose): ReadonlyMap<string, Rotation>;
|
|
43
|
+
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-wpbgtn0y.js";
|
|
10
|
+
export {
|
|
11
|
+
sampleClip,
|
|
12
|
+
resolvePose,
|
|
13
|
+
mergePoses,
|
|
14
|
+
isCustomClip,
|
|
15
|
+
customDuration,
|
|
16
|
+
clipLift,
|
|
17
|
+
CLIPS
|
|
18
|
+
};
|
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;
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { type Bone, type CanonicalBone, type RigId, type Vec3 } from "./rig";
|
|
2
|
+
import { type FaceName, type PartFaces, type Rect } from "./skin";
|
|
3
|
+
/**
|
|
4
|
+
* The Plupin-native body template: the platform's own part faces over the six canonical bones of
|
|
5
|
+
* `rig.ts`, the caps a body variant has to fit in, and the converter that brings a Roblox classic
|
|
6
|
+
* shirt/pants pair onto this grid. `skin.ts` stays the import format; this is the one the platform
|
|
7
|
+
* authors and renders.
|
|
8
|
+
*
|
|
9
|
+
* Resolutions. One stud is `NATIVE_PX_PER_STUD` = 32 px. The parts are the R6 proportions the rigs
|
|
10
|
+
* already share (torso 2x2x1, head 2x1x1, limb 1x2x1 studs), so a rig that is not R6 only scales
|
|
11
|
+
* the same faces: bone lengths and proportions live in `rig.ts` and nothing here restates them.
|
|
12
|
+
*
|
|
13
|
+
* Why 32 px per stud:
|
|
14
|
+
* - The 24 x 24 headshot `listing.ts` draws (`GRID`) must not upscale the skin. The smallest head
|
|
15
|
+
* face here is a 32 x 32 side, so a 24 px preview still samples 1.33 source texels per preview
|
|
16
|
+
* pixel; 16 px per stud would make the head side 32 x 16 and upscale it 1.5x vertically.
|
|
17
|
+
* - 32 is a power of two, so the sheet halves to 16 px per stud and quarters to 8 without landing
|
|
18
|
+
* on fractional pixels, and the classic template's 64 px per stud limb face lands on this grid
|
|
19
|
+
* by an exact 2:1 downscale.
|
|
20
|
+
* - The whole sheet is 512 x 256 px, a quarter of the proposed 512 x 512 ceiling. The layer is
|
|
21
|
+
* what keeps a variant small, and 32 px per stud is the resolution that buys it.
|
|
22
|
+
*/
|
|
23
|
+
export declare const NATIVE_PX_PER_STUD = 32;
|
|
24
|
+
export declare const NATIVE_WIDTH = 512;
|
|
25
|
+
export declare const NATIVE_HEIGHT = 256;
|
|
26
|
+
export interface NativePart {
|
|
27
|
+
/** The block this part's net occupies on the sheet, for layout assertions. */
|
|
28
|
+
block: Rect;
|
|
29
|
+
/** Canonical size in studs, w x h x d, as `rig.ts`'s R6 pins it. */
|
|
30
|
+
studs: readonly [number, number, number];
|
|
31
|
+
faces: PartFaces;
|
|
32
|
+
}
|
|
33
|
+
export declare const NATIVE_TORSO: PartFaces;
|
|
34
|
+
export declare const NATIVE_HEAD: PartFaces;
|
|
35
|
+
export declare const NATIVE_ARM_LEFT: PartFaces;
|
|
36
|
+
export declare const NATIVE_ARM_RIGHT: PartFaces;
|
|
37
|
+
export declare const NATIVE_LEG_LEFT: PartFaces;
|
|
38
|
+
export declare const NATIVE_LEG_RIGHT: PartFaces;
|
|
39
|
+
export declare const NATIVE_PARTS: Readonly<Record<CanonicalBone, NativePart>>;
|
|
40
|
+
/** Which grid part a rig's bone draws from, and which slice of it. */
|
|
41
|
+
export interface NativeMapping {
|
|
42
|
+
part: CanonicalBone;
|
|
43
|
+
/** Vertical slice of the part's face this bone shows: R15 splits one R6 limb into segments. */
|
|
44
|
+
slice?: readonly [number, number];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Bone name to grid part. The names are `rig.ts`'s own, so every rig's bones resolve: R6 and R15
|
|
48
|
+
* cover the six canonical names, and Plup's single body box becomes the torso face (its `head`
|
|
49
|
+
* alias points at the same box, and a box is drawn once).
|
|
50
|
+
*/
|
|
51
|
+
export declare const NATIVE_BONES: Readonly<Record<string, NativeMapping>>;
|
|
52
|
+
export declare function nativePartOf(bone: string): CanonicalBone | null;
|
|
53
|
+
/**
|
|
54
|
+
* The rectangle of one face of one bone, with any R15 slice applied. Sides slice vertically only:
|
|
55
|
+
* the top face belongs to the first segment, the bottom face to the last, like the classic map.
|
|
56
|
+
* Slice boundaries are rounded once and each slice starts where the previous one ended, so the
|
|
57
|
+
* segments of one part always tile its face with no gap and no overlap.
|
|
58
|
+
*/
|
|
59
|
+
export declare function nativeFaceRect(bone: string, face: FaceName): Rect | null;
|
|
60
|
+
/**
|
|
61
|
+
* The image type the renderers accept: anything a canvas can draw.
|
|
62
|
+
*
|
|
63
|
+
* The DOM calls this `CanvasImageSource`, and that name only exists in a program compiled with the
|
|
64
|
+
* DOM lib. `@plupin/api` and `apps/server` type-check this package without it (they validate and
|
|
65
|
+
* serve listings; they never draw one), so the type is owned here instead of borrowed.
|
|
66
|
+
*
|
|
67
|
+
* It is deliberately `object`: every DOM image source, every canvas element and every test raster is
|
|
68
|
+
* one, and nothing in this package reads a property off it — the canvas renderer and the three.js
|
|
69
|
+
* renderer hand it straight to their own `drawImage`, which is where the real contract lives.
|
|
70
|
+
*/
|
|
71
|
+
export type SkinImage = object;
|
|
72
|
+
/**
|
|
73
|
+
* The clamps every proportion change passes through. Owner direction (20 Nov): proportions are
|
|
74
|
+
* bounded, not fixed, because a kid-sized ("bocil") and a tall character are the same rig at a
|
|
75
|
+
* different stature, and a muscular arm is the same bone with a wider box.
|
|
76
|
+
*
|
|
77
|
+
* - stature 0.5-1.15: the whole body, uniformly. 0.5 is "bocil" — half size, still the same
|
|
78
|
+
* creature — and it is the floor because at 32 px per stud the smallest screen a character is
|
|
79
|
+
* drawn on still gets one device pixel per native texel at 0.5; below it the 32 x 64 limb faces
|
|
80
|
+
* and the face stamp stop reading as art. 1.15 is the tall end: above it the head leaves the
|
|
81
|
+
* 24 x 24 headshot's framing.
|
|
82
|
+
* - width 0.9-1.3: across the body only (x in the front view, z in the side view), so an arm can
|
|
83
|
+
* be 30% thicker without getting 30% longer. 0.9 is the thinnest silhouette that still covers the
|
|
84
|
+
* native face rect's edges; 1.3 is the widest a limb may be before it reads as a different part.
|
|
85
|
+
* - head 0.9-1.25: a big head is a style, and 1.25 is where it stops swallowing the torso.
|
|
86
|
+
*
|
|
87
|
+
* These are the numbers later cards (listing kinds, the free stature control) must import. A
|
|
88
|
+
* copied clamp is a second balance rule; there is one.
|
|
89
|
+
*/
|
|
90
|
+
export declare const BODY_SCALE_LIMITS: {
|
|
91
|
+
readonly stature: {
|
|
92
|
+
readonly min: 0.5;
|
|
93
|
+
readonly max: 1.15;
|
|
94
|
+
};
|
|
95
|
+
readonly width: {
|
|
96
|
+
readonly min: 0.9;
|
|
97
|
+
readonly max: 1.3;
|
|
98
|
+
};
|
|
99
|
+
readonly head: {
|
|
100
|
+
readonly min: 0.9;
|
|
101
|
+
readonly max: 1.25;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
export interface BodyScale {
|
|
105
|
+
/** Uniform stature: every joint offset, bone length, pixel and the clip's lift. 0.5 is bocil. */
|
|
106
|
+
stature: number;
|
|
107
|
+
/** Across-the-body thickness of a part: the muscular-arm path. The head has its own knob. */
|
|
108
|
+
width: Partial<Readonly<Record<Exclude<CanonicalBone, "head">, number>>>;
|
|
109
|
+
/** Extra multiplier on the head box only. */
|
|
110
|
+
head: number;
|
|
111
|
+
}
|
|
112
|
+
/** No change: the proportions `rig.ts` declares. */
|
|
113
|
+
export declare const CANONICAL_BODY_SCALE: BodyScale;
|
|
114
|
+
/**
|
|
115
|
+
* The one place a proportion becomes a number: anything a player, a listing or a game sends lands
|
|
116
|
+
* inside the clamps above, and a missing or non-finite value falls back to canonical rather than
|
|
117
|
+
* to a limit.
|
|
118
|
+
*/
|
|
119
|
+
export declare function clampBodyScale(scale?: Partial<BodyScale> | null): BodyScale;
|
|
120
|
+
export interface ScaledBone {
|
|
121
|
+
joint: Vec3;
|
|
122
|
+
size: Vec3;
|
|
123
|
+
center: Vec3;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* One bone's box after a clamped scale. Size and centre multiply around the joint, so a part grows
|
|
127
|
+
* away from its pivot and the joint itself never moves; the joint's across offset also follows the
|
|
128
|
+
* parent's width, so a limb stays on the edge of a wider torso instead of sinking into it.
|
|
129
|
+
*
|
|
130
|
+
* Rotations are not touched here. That is why one clip drives every stature, every width and every
|
|
131
|
+
* head size: the renderer changes boxes, never angles.
|
|
132
|
+
*/
|
|
133
|
+
export declare function scaleBone(bone: Bone, part: CanonicalBone | null, parentPart: CanonicalBone | null, scale: BodyScale): ScaledBone;
|
|
134
|
+
export interface CanonicalBox {
|
|
135
|
+
size: Vec3;
|
|
136
|
+
/** Centre in studs relative to the character's feet, facing +z. */
|
|
137
|
+
center: Vec3;
|
|
138
|
+
}
|
|
139
|
+
export interface CanonicalFootprint {
|
|
140
|
+
width: number;
|
|
141
|
+
height: number;
|
|
142
|
+
depth: number;
|
|
143
|
+
bones: Readonly<Record<string, CanonicalBox>>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* What a game may rely on, and the answer to "the game stays balanced": the box is read from
|
|
147
|
+
* `rig.ts` only. There is no `BodyScale` parameter, so a player's visual stature, arms or head can
|
|
148
|
+
* never widen the box a game collides with. Visual scale is cosmetic; this is the identity.
|
|
149
|
+
*/
|
|
150
|
+
export declare function canonicalFootprint(rigId: RigId): CanonicalFootprint;
|
|
151
|
+
/**
|
|
152
|
+
* The largest box a fully clamped character may draw, in studs: the canonical footprint times the
|
|
153
|
+
* clamp maxima. A loose upper bound on purpose — a renderer may draw inside it and never outside.
|
|
154
|
+
*/
|
|
155
|
+
export declare function visualEnvelope(rigId: RigId): {
|
|
156
|
+
width: number;
|
|
157
|
+
height: number;
|
|
158
|
+
depth: number;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* The caps a body-variant sheet is measured against before it can be listed. `wardrobe` and the
|
|
162
|
+
* moderation queue read one answer from `validateVariantSheet`; the renderer only ever draws the
|
|
163
|
+
* part rects above, so a sheet inside these caps cannot reach past them.
|
|
164
|
+
*
|
|
165
|
+
* - PNG-24: 8-bit truecolour, optional 8-bit alpha, no palette and no 16-bit channel. Pixel art is
|
|
166
|
+
* the house style and `imageSmoothingEnabled = false` is the renderer's only path, so a sheet
|
|
167
|
+
* the browser decodes as 16-bit or through a palette is a different picture than the moderator
|
|
168
|
+
* approved.
|
|
169
|
+
* - 512 x 256: the native grid itself, not a resized copy. A variant is authored on these
|
|
170
|
+
* coordinates, so every face rect in this file is also the variant's rect, and a sheet of
|
|
171
|
+
* another size is refused rather than resampled.
|
|
172
|
+
* - 64 KiB: the sheet is 131072 px, which is 384 KiB at 8 bits per channel, so the cap asks for
|
|
173
|
+
* 1.4 bits per sheet pixel. Flat pixel art clears it by a wide margin (the largest block, the
|
|
174
|
+
* torso net, is 24576 px and stays under 8 KiB), so the cap only bites on noisy or photographic
|
|
175
|
+
* art, which is what it is for. It also bounds the wardrobe: eight variants download at most
|
|
176
|
+
* half a megabyte.
|
|
177
|
+
*/
|
|
178
|
+
export declare const NATIVE_SHEET_CAPS: {
|
|
179
|
+
readonly format: "png-24";
|
|
180
|
+
readonly width: 512;
|
|
181
|
+
readonly height: 256;
|
|
182
|
+
readonly maxBytes: number;
|
|
183
|
+
};
|
|
184
|
+
export interface VariantSheetFacts {
|
|
185
|
+
width: number;
|
|
186
|
+
height: number;
|
|
187
|
+
bytes: number;
|
|
188
|
+
}
|
|
189
|
+
export type VariantSheetProblem = "wrong_size" | "over_byte_cap";
|
|
190
|
+
export type VariantSheetCheck = {
|
|
191
|
+
ok: true;
|
|
192
|
+
} | {
|
|
193
|
+
ok: false;
|
|
194
|
+
reason: VariantSheetProblem;
|
|
195
|
+
};
|
|
196
|
+
/** The one check every writer runs on a decoded variant sheet, before the digest or the queue. */
|
|
197
|
+
export declare function validateVariantSheet(facts: VariantSheetFacts): VariantSheetCheck;
|
|
198
|
+
/**
|
|
199
|
+
* One part of a body variant: the whole native sheet, painted only where this part's faces are.
|
|
200
|
+
* The renderer samples this part's rects, so art outside them is never drawn.
|
|
201
|
+
*/
|
|
202
|
+
export interface VariantPart {
|
|
203
|
+
image: SkinImage;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* A body variant is cosmetic only: it carries art and nothing else. There is no stat, no height,
|
|
207
|
+
* no reach and no gameplay field a variant could add, and the renderer never reads the id.
|
|
208
|
+
*/
|
|
209
|
+
export interface BodyVariant {
|
|
210
|
+
/** The listing id the creator bought; the renderer only carries it. */
|
|
211
|
+
id: string;
|
|
212
|
+
/** One sheet per part this variant redraws. An absent part keeps the skin's own art. */
|
|
213
|
+
parts: Partial<Readonly<Record<CanonicalBone, VariantPart>>>;
|
|
214
|
+
}
|
|
215
|
+
export interface CharacterLook {
|
|
216
|
+
/** Skin tone of bare parts, one per region, or a single colour for all. */
|
|
217
|
+
bodyColor: string;
|
|
218
|
+
headColor?: string;
|
|
219
|
+
/** Classic template images. Any image type the renderer can draw. */
|
|
220
|
+
shirt?: SkinImage | null;
|
|
221
|
+
pants?: SkinImage | null;
|
|
222
|
+
/** Drawn on the front of the head, or on Plup's body. */
|
|
223
|
+
face?: SkinImage | null;
|
|
224
|
+
/** A whole body on the native grid, as `convertClassicToNative` produces. */
|
|
225
|
+
native?: SkinImage | null;
|
|
226
|
+
/** Per-part art that replaces a part's own art. Cosmetic only: the rig never reads it. */
|
|
227
|
+
variant?: BodyVariant | null;
|
|
228
|
+
}
|
|
229
|
+
export interface BoneSkin {
|
|
230
|
+
image: SkinImage;
|
|
231
|
+
/** The source rect of this face, already sliced for an R15 segment. */
|
|
232
|
+
source: Rect;
|
|
233
|
+
/** A variant owns the part, so the renderer must not paint the skin tone behind it. */
|
|
234
|
+
redraw: boolean;
|
|
235
|
+
}
|
|
236
|
+
/** Which image and which rect one bone's face reads, in the renderers' order of preference. */
|
|
237
|
+
export declare function boneSkin(bone: string, face: FaceName, look: CharacterLook): BoneSkin | null;
|
|
238
|
+
/** One draw the classic converter performs: a classic face rect into its native face rect. */
|
|
239
|
+
export interface ClassicConversion {
|
|
240
|
+
part: CanonicalBone;
|
|
241
|
+
face: FaceName;
|
|
242
|
+
sheet: "shirt" | "pants";
|
|
243
|
+
source: Rect;
|
|
244
|
+
dest: Rect;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* The classic template mapped onto the native grid, one entry per face, in a fixed order. Head
|
|
248
|
+
* faces are absent on purpose: a Roblox classic shirt/pants pair carries no head skin (Roblox
|
|
249
|
+
* paints the head with a separate face), so the converter leaves the head rects empty and the
|
|
250
|
+
* rig's skin tone shows through.
|
|
251
|
+
*/
|
|
252
|
+
export declare const CLASSIC_TO_NATIVE: readonly ClassicConversion[];
|
package/dist/skin.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A skin is an image plus a map of where each face of each part sits on it. The maps below are the
|
|
3
|
+
* Roblox classic clothing template, so a shirt or pants PNG made for Roblox works unchanged.
|
|
4
|
+
*/
|
|
5
|
+
export interface Rect {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
w: number;
|
|
9
|
+
h: number;
|
|
10
|
+
}
|
|
11
|
+
export type FaceName = "front" | "back" | "left" | "right" | "up" | "down";
|
|
12
|
+
export type PartFaces = Readonly<Record<FaceName, Rect>>;
|
|
13
|
+
export declare const CLASSIC_WIDTH = 585;
|
|
14
|
+
export declare const CLASSIC_HEIGHT = 559;
|
|
15
|
+
export declare const CLASSIC_TORSO: PartFaces;
|
|
16
|
+
/** The block on the template's left: right arm on a shirt, right leg on pants. */
|
|
17
|
+
export declare const CLASSIC_RIGHT_LIMB: PartFaces;
|
|
18
|
+
/** The block on the template's right: left arm on a shirt, left leg on pants. */
|
|
19
|
+
export declare const CLASSIC_LEFT_LIMB: PartFaces;
|
|
20
|
+
/** Where a rig's bone reads from in a classic template, and from which image. */
|
|
21
|
+
export interface ClassicMapping {
|
|
22
|
+
sheet: "shirt" | "pants";
|
|
23
|
+
faces: PartFaces;
|
|
24
|
+
/** Which vertical slice of the part this bone shows: R15 splits one R6 limb into segments. */
|
|
25
|
+
slice?: readonly [number, number];
|
|
26
|
+
}
|
|
27
|
+
export declare const CLASSIC_BONES: Readonly<Record<string, ClassicMapping>>;
|
|
28
|
+
/** The rectangle of one face of one bone, with any R15 slice applied. Sides slice vertically only. */
|
|
29
|
+
export declare function classicFaceRect(bone: string, face: FaceName): Rect | null;
|
|
30
|
+
export interface ClassicValidation {
|
|
31
|
+
ok: boolean;
|
|
32
|
+
reason?: "wrong_size";
|
|
33
|
+
}
|
|
34
|
+
/** Roblox rejects a classic template of any other size, and a mapped one would land wrong. */
|
|
35
|
+
export declare function validateClassicTemplate(width: number, height: number): ClassicValidation;
|
package/dist/three.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Group } from "three";
|
|
2
|
+
import { type Emote } from "./emote";
|
|
3
|
+
import { type ClipRef, type Pose } from "./pose";
|
|
4
|
+
export { type BodyShapeId, createPlup, type Expression, type PlupFace, type PlupHandle, type PlupOptions, type PlupSkin, } from "./plup3d";
|
|
5
|
+
import { type RigId } from "./rig";
|
|
6
|
+
import { type BodyScale, type CharacterLook } from "./skin-native";
|
|
7
|
+
export interface CharacterHandle {
|
|
8
|
+
/** Add this to a scene. Feet stand at y = 0, facing +z, one unit is one stud. */
|
|
9
|
+
object: Group;
|
|
10
|
+
/** Set the current clip. Call `update` every frame. */
|
|
11
|
+
play: (clip: ClipRef) => void;
|
|
12
|
+
/** Play an emote by name (`"ngakak"` or `"emote-ngakak"`): its clip, now. Returns it so the game can show its face and glyph; undefined for an unknown name. */
|
|
13
|
+
emote: (name: string) => Emote | undefined;
|
|
14
|
+
/** Hold a joint, for example `{ armR: { x: -1.2 } }` to aim. Pass `{}` to let go. */
|
|
15
|
+
pose: (pose: Pose) => void;
|
|
16
|
+
update: (deltaSeconds: number) => void;
|
|
17
|
+
/** The joint itself, to attach a hat or a sword: `bone("armR").add(sword)`. */
|
|
18
|
+
bone: (name: string) => Group | undefined;
|
|
19
|
+
dispose: () => void;
|
|
20
|
+
}
|
|
21
|
+
/** Builds a skinned, posable character. Everything a game needs is on the returned handle. */
|
|
22
|
+
export declare function createCharacter(rigId?: RigId, look?: CharacterLook, bodyScale?: Partial<BodyScale> | null): CharacterHandle;
|