@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.
- package/dist/anime-face.d.ts +42 -0
- package/dist/anime-face.js +14 -0
- package/dist/blob.d.ts +32 -0
- package/dist/blob.js +18 -0
- package/dist/body-presets.d.ts +85 -0
- package/dist/canvas.d.ts +79 -0
- package/dist/canvas.js +315 -0
- package/dist/chunk-09c5tps4.js +337 -0
- package/dist/chunk-60p135hw.js +103 -0
- package/dist/chunk-aa5nstet.js +39 -0
- package/dist/chunk-dpb0rnw9.js +37 -0
- package/dist/chunk-g1c0wdcj.js +825 -0
- package/dist/chunk-kber92gm.js +415 -0
- package/dist/chunk-sa2r1cxz.js +342 -0
- package/dist/chunk-yd5zzkkg.js +313 -0
- package/dist/clip-bake.d.ts +48 -0
- package/dist/clip-bake.js +132 -0
- package/dist/clips.d.ts +40 -0
- package/dist/dress.d.ts +4 -0
- package/dist/emote.d.ts +25 -0
- package/dist/faces.d.ts +10 -0
- package/dist/faces.js +12 -0
- package/dist/gaze.d.ts +81 -0
- package/dist/gaze.js +113 -0
- package/dist/hair3d.d.ts +3 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +176 -0
- package/dist/listing.d.ts +195 -0
- package/dist/listing.js +763 -0
- package/dist/named-faces.d.ts +22 -0
- package/dist/platform-body-data.d.ts +9 -0
- package/dist/platform-body.d.ts +91 -0
- package/dist/plup2d.d.ts +29 -0
- package/dist/plup3d.d.ts +121 -0
- package/dist/png.d.ts +78 -0
- package/dist/pose.d.ts +49 -0
- package/dist/pose.js +18 -0
- package/dist/proportions.d.ts +31 -0
- package/dist/ragdoll.d.ts +51 -0
- package/dist/resolution.d.ts +21 -0
- package/dist/rig.d.ts +29 -0
- package/dist/skin-map.d.ts +155 -0
- package/dist/skin-map.js +55 -0
- package/dist/skin-native.d.ts +301 -0
- package/dist/skin.d.ts +35 -0
- package/dist/texture.d.ts +8 -0
- package/dist/three.d.ts +25 -0
- package/dist/three.js +2302 -0
- package/dist/wear3d.d.ts +99 -0
- package/dist/wearables.d.ts +203 -0
- package/dist/wearables.js +26 -0
- package/package.json +78 -4
- package/README.md +0 -3
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime eyes for Plup, drawn as vector shapes on a high-resolution face decal (the 48 x 24 body map
|
|
3
|
+
* has 8 x 4 cells for a face, far too few for an anime eye). Rules and their sources are in
|
|
4
|
+
* docs/product/research-anime-hair-and-bodies.md:
|
|
5
|
+
*
|
|
6
|
+
* - Big eyes sitting low on the face, a small mouth, blush on the cheeks (chibi proportions).
|
|
7
|
+
* - A tall oval iris, dark at the top and light at the bottom, shadowed under the upper lid, with a
|
|
8
|
+
* round pupil; two highlights, a big one up and to one side and a small one down and to the other.
|
|
9
|
+
* - A thick upper lash line that flicks out at the outer corner, a thin lower one, thin brows.
|
|
10
|
+
* - Expressions change the eyes first: happy closes them into upward arcs, shock shrinks the pupils,
|
|
11
|
+
* sadness makes the highlights wet, anger loses them and slants the brows.
|
|
12
|
+
*
|
|
13
|
+
* Pure canvas drawing, no three.js: `plup3d.ts` puts the canvas on the body.
|
|
14
|
+
*/
|
|
15
|
+
export declare const ANIME_FACE_SIZE: {
|
|
16
|
+
readonly width: 512;
|
|
17
|
+
readonly height: 256;
|
|
18
|
+
};
|
|
19
|
+
/** Where the decal sits on the body's UV sphere (see `plup3d.ts`): a band round the front. */
|
|
20
|
+
export declare const ANIME_FACE_UV: {
|
|
21
|
+
readonly u0: 0.07;
|
|
22
|
+
readonly u1: 0.43;
|
|
23
|
+
readonly v0: 0.37;
|
|
24
|
+
readonly v1: 0.7;
|
|
25
|
+
};
|
|
26
|
+
type Eyes = "open" | "closed" | "happy" | "wide" | "sad" | "half" | "angry" | "stars" | "dead" | "wink" | "cry";
|
|
27
|
+
type Mouth = "smile" | "open" | "o" | "frown" | "smirk" | "cat" | "flat" | "yell" | "tongue" | "grin";
|
|
28
|
+
type Brows = "calm" | "up" | "angry" | "sad" | "none";
|
|
29
|
+
interface FaceParts {
|
|
30
|
+
eyes: Eyes;
|
|
31
|
+
mouth: Mouth;
|
|
32
|
+
brows: Brows;
|
|
33
|
+
blush: number;
|
|
34
|
+
tears?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/** The parts of a face by its name (unknown names rest). */
|
|
37
|
+
export declare function animeFaceParts(face: string): FaceParts;
|
|
38
|
+
/** How far down the face canvas the eyes sit, for drawing it over a flat icon. */
|
|
39
|
+
export declare const ANIME_EYE_LINE: number;
|
|
40
|
+
/** Draw an anime face for `face` on a canvas of `ANIME_FACE_SIZE`, with irises in `iris`. */
|
|
41
|
+
export declare function drawAnimeFace(ctx: CanvasRenderingContext2D, face: string, iris?: string): void;
|
|
42
|
+
export {};
|
package/dist/blob.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SphereGeometry } from "three";
|
|
2
|
+
/**
|
|
3
|
+
* Plup's body: one round blob, bottom-heavy (a soft triangle), resting on a flat seat. The app's lobby, the
|
|
4
|
+
* games and the films all build it from here (ADR 0024), so the silhouette cannot drift between them.
|
|
5
|
+
* These numbers are the lobby's, which is the look the owner signed off.
|
|
6
|
+
*/
|
|
7
|
+
export declare const BLOB_RADIUS: {
|
|
8
|
+
readonly x: 0.6;
|
|
9
|
+
readonly y: 0.56;
|
|
10
|
+
readonly z: 0.58;
|
|
11
|
+
};
|
|
12
|
+
/** The blob's height with the seat flattened: feet on y = 0. */
|
|
13
|
+
export declare const BLOB_HEIGHT: number;
|
|
14
|
+
/**
|
|
15
|
+
* A body's silhouette on top of the blob: how broad the shoulders are, how much the waist pinches, how
|
|
16
|
+
* wide the hips spread. 1 everywhere is the round Plup; a muscular body is broad on top and narrow below,
|
|
17
|
+
* a curvy one pinched at the waist and full at the hips. Everything that has to fit the body (the
|
|
18
|
+
* wearables, the arms' shoulders) reads the same `silhouetteAt`, so clothes follow the shape.
|
|
19
|
+
*/
|
|
20
|
+
export interface Silhouette {
|
|
21
|
+
shoulders: number;
|
|
22
|
+
waist: number;
|
|
23
|
+
hips: number;
|
|
24
|
+
}
|
|
25
|
+
export declare const ROUND: Silhouette;
|
|
26
|
+
/** The radius multiplier at a height on the unit sphere (-1 bottom, 1 top). */
|
|
27
|
+
export declare function silhouetteAt(unitY: number, silhouette?: Silhouette): number;
|
|
28
|
+
/** How far the seat was raised so the feet stand on y = 0. */
|
|
29
|
+
export declare const BLOB_SEAT: number;
|
|
30
|
+
/** The body's half-width across (x) at a height above the feet, for this silhouette. Front to back is `BLOB_RADIUS.z / BLOB_RADIUS.x` of it. */
|
|
31
|
+
export declare function blobRadiusAt(y: number, silhouette?: Silhouette): number;
|
|
32
|
+
export declare function buildBlobGeometry(silhouette?: Silhouette): SphereGeometry;
|
package/dist/blob.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BLOB_HEIGHT,
|
|
3
|
+
BLOB_RADIUS,
|
|
4
|
+
BLOB_SEAT,
|
|
5
|
+
ROUND,
|
|
6
|
+
blobRadiusAt,
|
|
7
|
+
buildBlobGeometry,
|
|
8
|
+
silhouetteAt
|
|
9
|
+
} from "./chunk-dpb0rnw9.js";
|
|
10
|
+
export {
|
|
11
|
+
silhouetteAt,
|
|
12
|
+
buildBlobGeometry,
|
|
13
|
+
blobRadiusAt,
|
|
14
|
+
ROUND,
|
|
15
|
+
BLOB_SEAT,
|
|
16
|
+
BLOB_RADIUS,
|
|
17
|
+
BLOB_HEIGHT
|
|
18
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bodies a player starts from, then tunes with the sliders: each is a shape (height and girth) and a
|
|
3
|
+
* Plup body (outline, limb length and bulk). Data only, so the app, the games and the films offer the
|
|
4
|
+
* same list. Names are English; the app translates them for display.
|
|
5
|
+
*/
|
|
6
|
+
export declare const BODY_PRESETS: {
|
|
7
|
+
readonly round: {
|
|
8
|
+
readonly name: "Round";
|
|
9
|
+
readonly shape: "plup";
|
|
10
|
+
readonly body: {};
|
|
11
|
+
};
|
|
12
|
+
readonly "tall-slim": {
|
|
13
|
+
readonly name: "Tall & Slim";
|
|
14
|
+
readonly shape: "tall";
|
|
15
|
+
readonly body: {
|
|
16
|
+
readonly shoulders: 0.9;
|
|
17
|
+
readonly waist: 0.84;
|
|
18
|
+
readonly hips: 0.9;
|
|
19
|
+
readonly legLength: 2.6;
|
|
20
|
+
readonly armLength: 1.4;
|
|
21
|
+
readonly muscle: 0.78;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
readonly athletic: {
|
|
25
|
+
readonly name: "Athletic";
|
|
26
|
+
readonly shape: "tall";
|
|
27
|
+
readonly body: {
|
|
28
|
+
readonly shoulders: 1.2;
|
|
29
|
+
readonly waist: 0.84;
|
|
30
|
+
readonly hips: 0.95;
|
|
31
|
+
readonly legLength: 2.1;
|
|
32
|
+
readonly armLength: 1.3;
|
|
33
|
+
readonly muscle: 1.35;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
readonly muscular: {
|
|
37
|
+
readonly name: "Muscular";
|
|
38
|
+
readonly shape: "tall";
|
|
39
|
+
readonly body: {
|
|
40
|
+
readonly shoulders: 1.32;
|
|
41
|
+
readonly waist: 0.82;
|
|
42
|
+
readonly hips: 0.88;
|
|
43
|
+
readonly legLength: 1.7;
|
|
44
|
+
readonly armLength: 1.25;
|
|
45
|
+
readonly muscle: 1.9;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
readonly curvy: {
|
|
49
|
+
readonly name: "Curvy";
|
|
50
|
+
readonly shape: "tall";
|
|
51
|
+
readonly body: {
|
|
52
|
+
readonly shoulders: 0.9;
|
|
53
|
+
readonly waist: 0.66;
|
|
54
|
+
readonly hips: 1.32;
|
|
55
|
+
readonly legLength: 2.4;
|
|
56
|
+
readonly armLength: 1.3;
|
|
57
|
+
readonly muscle: 0.85;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
readonly chubby: {
|
|
61
|
+
readonly name: "Chubby";
|
|
62
|
+
readonly shape: "wide";
|
|
63
|
+
readonly body: {
|
|
64
|
+
readonly shoulders: 1;
|
|
65
|
+
readonly waist: 1.15;
|
|
66
|
+
readonly hips: 1.25;
|
|
67
|
+
readonly legLength: 1;
|
|
68
|
+
readonly armLength: 1;
|
|
69
|
+
readonly muscle: 1.2;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
readonly tiny: {
|
|
73
|
+
readonly name: "Tiny";
|
|
74
|
+
readonly shape: "mini";
|
|
75
|
+
readonly body: {};
|
|
76
|
+
};
|
|
77
|
+
readonly bean: {
|
|
78
|
+
readonly name: "Bean";
|
|
79
|
+
readonly shape: "bean";
|
|
80
|
+
readonly body: {
|
|
81
|
+
readonly legLength: 1.3;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
export type BodyPresetId = keyof typeof BODY_PRESETS;
|
package/dist/canvas.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type NamedFace } from "./faces";
|
|
2
|
+
import { type PlupOptions2D } from "./plup2d";
|
|
3
|
+
export type { PlupOptions2D };
|
|
4
|
+
import { type ClipRef, type Pose } from "./pose";
|
|
5
|
+
import { type RigId } from "./rig";
|
|
6
|
+
import type { Rect } from "./skin";
|
|
7
|
+
import { type BodyScale, type CharacterLook, type SkinImage } from "./skin-native";
|
|
8
|
+
export type View2D = "front" | "side";
|
|
9
|
+
export interface Draw2DOptions {
|
|
10
|
+
/** Default `plup`: the mascot. The Roblox rigs (`r6`, `r15`) are for people who bring a Roblox avatar. */
|
|
11
|
+
rig?: RigId;
|
|
12
|
+
/** The named face Plup wears in 2D. */
|
|
13
|
+
face?: NamedFace;
|
|
14
|
+
look: CharacterLook;
|
|
15
|
+
/**
|
|
16
|
+
* The clamped proportions to draw: stature, per-part width and head size. Visual only, so the
|
|
17
|
+
* same clip drives every scale and `canonicalFootprint` stays what a game collides with.
|
|
18
|
+
*/
|
|
19
|
+
bodyScale?: Partial<BodyScale> | null;
|
|
20
|
+
/** Canvas position of the character's feet. */
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
/** Canvas pixels per stud. */
|
|
24
|
+
scale: number;
|
|
25
|
+
view?: View2D;
|
|
26
|
+
clip?: ClipRef;
|
|
27
|
+
seconds?: number;
|
|
28
|
+
/** Layered over the clip. */
|
|
29
|
+
pose?: Pose;
|
|
30
|
+
flip?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** A 2 x 3 canvas transform in canvas order: x' = a*x + c*y + e, y' = b*x + d*y + f. */
|
|
33
|
+
export type Matrix = readonly [number, number, number, number, number, number];
|
|
34
|
+
export type DrawPaint = {
|
|
35
|
+
kind: "fill";
|
|
36
|
+
color: string;
|
|
37
|
+
} | {
|
|
38
|
+
kind: "image";
|
|
39
|
+
image: SkinImage;
|
|
40
|
+
source: Rect;
|
|
41
|
+
};
|
|
42
|
+
export interface DrawOp {
|
|
43
|
+
/** The bone this op paints. */
|
|
44
|
+
bone: string;
|
|
45
|
+
/** Canvas transform the op paints under, already composed from the rig and the pose. */
|
|
46
|
+
matrix: Matrix;
|
|
47
|
+
/**
|
|
48
|
+
* The part rect in bone-local space. Nothing an op paints lands outside it, which is what keeps
|
|
49
|
+
* a variant's silhouette inside its part and its bones the length the rig says.
|
|
50
|
+
*/
|
|
51
|
+
clip: Rect;
|
|
52
|
+
paint: DrawPaint;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The whole draw, as data: every rectangle a frame paints and under which transform. The 2D
|
|
56
|
+
* canvas renderer is the executor of this list, so a test that rasterises it sees exactly what a
|
|
57
|
+
* screen sees, and each op's clip rect is the ceiling a body variant cannot cross.
|
|
58
|
+
*/
|
|
59
|
+
export declare function planCharacter2D(options: Draw2DOptions): readonly DrawOp[];
|
|
60
|
+
/**
|
|
61
|
+
* Draws a character flat onto a 2D canvas: one call a frame, no scene and no WebGL. The same rig,
|
|
62
|
+
* clips, poses and skins as the 3D renderer.
|
|
63
|
+
*/
|
|
64
|
+
export declare function drawCharacter2D(context: CanvasRenderingContext2D, options: Draw2DOptions): void;
|
|
65
|
+
/**
|
|
66
|
+
* Maps a Roblox classic shirt/pants pair onto the native grid: the image a look passes as
|
|
67
|
+
* `native`. A classic template carries no head skin, so the head faces stay transparent and the
|
|
68
|
+
* rig's skin tone shows through, exactly as it does on Roblox.
|
|
69
|
+
*/
|
|
70
|
+
export declare function convertClassicToNative(images: {
|
|
71
|
+
shirt?: SkinImage | null;
|
|
72
|
+
pants?: SkinImage | null;
|
|
73
|
+
}): HTMLCanvasElement;
|
|
74
|
+
/**
|
|
75
|
+
* A named face (`emote.face`) drawn on a square canvas of `size` px, ready to pass as `look.face`
|
|
76
|
+
* to `createCharacter`. The stamp sits where the app's own face sits; the rest is transparent, so the
|
|
77
|
+
* body colour shows through.
|
|
78
|
+
*/
|
|
79
|
+
export declare function faceCanvas(face: NamedFace, size?: number): HTMLCanvasElement;
|
package/dist/canvas.js
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CLASSIC_TO_NATIVE,
|
|
3
|
+
NATIVE_HEIGHT,
|
|
4
|
+
NATIVE_WIDTH,
|
|
5
|
+
boneSkin,
|
|
6
|
+
clampBodyScale,
|
|
7
|
+
nativePartOf,
|
|
8
|
+
scaleBone
|
|
9
|
+
} from "./chunk-sa2r1cxz.js";
|
|
10
|
+
import {
|
|
11
|
+
RIGS,
|
|
12
|
+
clipLift,
|
|
13
|
+
mergePoses,
|
|
14
|
+
resolvePose,
|
|
15
|
+
sampleClip
|
|
16
|
+
} from "./chunk-g1c0wdcj.js";
|
|
17
|
+
import {
|
|
18
|
+
FACE_STAMP_PALETTE,
|
|
19
|
+
NAMED_FACES,
|
|
20
|
+
NAMED_FACE_STAMPS
|
|
21
|
+
} from "./chunk-aa5nstet.js";
|
|
22
|
+
|
|
23
|
+
// src/plup2d.ts
|
|
24
|
+
var hex = (color) => {
|
|
25
|
+
const value = color.replace("#", "");
|
|
26
|
+
const full = value.length === 3 ? [...value].map((c) => c + c).join("") : value;
|
|
27
|
+
return [0, 2, 4].map((at) => Number.parseInt(full.slice(at, at + 2), 16));
|
|
28
|
+
};
|
|
29
|
+
var mix = (a, b, t) => {
|
|
30
|
+
const [r1, g1, b1] = hex(a);
|
|
31
|
+
const [r2, g2, b2] = hex(b);
|
|
32
|
+
const at = (x, y) => Math.round(x + (y - x) * t);
|
|
33
|
+
return `rgb(${at(r1, r2)},${at(g1, g2)},${at(b1, b2)})`;
|
|
34
|
+
};
|
|
35
|
+
var ORDER = ["LeftLeg", "RightLeg", "Body", "LeftArm", "RightArm"];
|
|
36
|
+
var scratch = null;
|
|
37
|
+
function roundRect(ctx, x, y, w, h, r) {
|
|
38
|
+
const radius = Math.min(r, w / 2, h / 2);
|
|
39
|
+
ctx.beginPath();
|
|
40
|
+
ctx.moveTo(x + radius, y);
|
|
41
|
+
ctx.arcTo(x + w, y, x + w, y + h, radius);
|
|
42
|
+
ctx.arcTo(x + w, y + h, x, y + h, radius);
|
|
43
|
+
ctx.arcTo(x, y + h, x, y, radius);
|
|
44
|
+
ctx.arcTo(x, y, x + w, y, radius);
|
|
45
|
+
ctx.closePath();
|
|
46
|
+
}
|
|
47
|
+
function bodyPath(ctx, x, y, w, h) {
|
|
48
|
+
const cx = x + w / 2;
|
|
49
|
+
ctx.beginPath();
|
|
50
|
+
ctx.moveTo(x + w * 0.04, y + h * 0.82);
|
|
51
|
+
ctx.bezierCurveTo(x - w * 0.02, y + h * 0.2, x + w * 0.2, y, cx, y);
|
|
52
|
+
ctx.bezierCurveTo(x + w * 0.8, y, x + w * 1.02, y + h * 0.2, x + w * 0.96, y + h * 0.82);
|
|
53
|
+
ctx.quadraticCurveTo(x + w * 0.96, y + h, x + w * 0.8, y + h);
|
|
54
|
+
ctx.lineTo(x + w * 0.2, y + h);
|
|
55
|
+
ctx.quadraticCurveTo(x + w * 0.04, y + h, x + w * 0.04, y + h * 0.82);
|
|
56
|
+
ctx.closePath();
|
|
57
|
+
}
|
|
58
|
+
function paintBone(ctx, op, color, ink, face) {
|
|
59
|
+
const { x, y, w, h } = op.clip;
|
|
60
|
+
ctx.save();
|
|
61
|
+
ctx.setTransform(...op.matrix);
|
|
62
|
+
ctx.lineJoin = "round";
|
|
63
|
+
ctx.lineWidth = 0.14;
|
|
64
|
+
if (op.bone === "Body") {
|
|
65
|
+
bodyPath(ctx, x, y, w, h);
|
|
66
|
+
ctx.fillStyle = color;
|
|
67
|
+
ctx.fill();
|
|
68
|
+
ctx.save();
|
|
69
|
+
ctx.clip();
|
|
70
|
+
ctx.fillStyle = mix(color, "#ffffff", 0.45);
|
|
71
|
+
ctx.fillRect(x, y + h * 0.66, w, h * 0.4);
|
|
72
|
+
ctx.fillStyle = mix(color, "#000000", 0.16);
|
|
73
|
+
ctx.beginPath();
|
|
74
|
+
ctx.ellipse(x + w * 1.02, y + h * 0.5, w * 0.22, h * 0.62, 0, 0, Math.PI * 2);
|
|
75
|
+
ctx.fill();
|
|
76
|
+
ctx.fillStyle = mix(color, "#ffffff", 0.7);
|
|
77
|
+
ctx.beginPath();
|
|
78
|
+
ctx.ellipse(x + w * 0.27, y + h * 0.2, w * 0.12, h * 0.07, -0.6, 0, Math.PI * 2);
|
|
79
|
+
ctx.fill();
|
|
80
|
+
ctx.restore();
|
|
81
|
+
bodyPath(ctx, x, y, w, h);
|
|
82
|
+
ctx.strokeStyle = ink;
|
|
83
|
+
ctx.stroke();
|
|
84
|
+
const stamp = faceCanvas(face, 32);
|
|
85
|
+
const faceW = w * 0.82;
|
|
86
|
+
ctx.imageSmoothingEnabled = false;
|
|
87
|
+
ctx.drawImage(stamp, 0, 0, 32, 16, x + (w - faceW) / 2, y + h * 0.2, faceW, faceW / 2);
|
|
88
|
+
} else {
|
|
89
|
+
const arm = op.bone.endsWith("Arm");
|
|
90
|
+
roundRect(ctx, x, y, w, h, arm ? w / 2 : w * 0.42);
|
|
91
|
+
ctx.fillStyle = arm ? color : mix(color, "#000000", 0.08);
|
|
92
|
+
ctx.fill();
|
|
93
|
+
ctx.strokeStyle = ink;
|
|
94
|
+
ctx.stroke();
|
|
95
|
+
}
|
|
96
|
+
ctx.restore();
|
|
97
|
+
}
|
|
98
|
+
function drawPlup2D(ctx, options) {
|
|
99
|
+
const {
|
|
100
|
+
color,
|
|
101
|
+
x,
|
|
102
|
+
y,
|
|
103
|
+
scale,
|
|
104
|
+
clip = "idle",
|
|
105
|
+
seconds = 0,
|
|
106
|
+
shadow = true,
|
|
107
|
+
squash,
|
|
108
|
+
flip = false
|
|
109
|
+
} = options;
|
|
110
|
+
const ppu = options.ppu ?? 12;
|
|
111
|
+
const face = options.face && NAMED_FACES.includes(options.face) ? options.face : "smug";
|
|
112
|
+
const ink = mix(color, "#161923", 0.72);
|
|
113
|
+
const width = Math.ceil((2.6 + 4.4) * ppu);
|
|
114
|
+
const height = Math.ceil((3.4 + 3.4 + 1.2) * ppu);
|
|
115
|
+
scratch ??= document.createElement("canvas");
|
|
116
|
+
if (scratch.width !== width || scratch.height !== height) {
|
|
117
|
+
scratch.width = width;
|
|
118
|
+
scratch.height = height;
|
|
119
|
+
}
|
|
120
|
+
const bctx = scratch.getContext("2d", { willReadFrequently: true });
|
|
121
|
+
if (!bctx)
|
|
122
|
+
return;
|
|
123
|
+
bctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
124
|
+
bctx.clearRect(0, 0, width, height);
|
|
125
|
+
const floor = height - 1.2 * ppu;
|
|
126
|
+
const ops = planCharacter2D({
|
|
127
|
+
rig: "plup",
|
|
128
|
+
look: { bodyColor: color },
|
|
129
|
+
x: width / 2,
|
|
130
|
+
y: floor,
|
|
131
|
+
scale: ppu,
|
|
132
|
+
view: "front",
|
|
133
|
+
clip,
|
|
134
|
+
seconds,
|
|
135
|
+
...options.pose ? { pose: options.pose } : {}
|
|
136
|
+
});
|
|
137
|
+
for (const bone of ORDER) {
|
|
138
|
+
const op = ops.find((candidate) => candidate.bone === bone && candidate.paint.kind === "fill");
|
|
139
|
+
if (op)
|
|
140
|
+
paintBone(bctx, op, color, ink, face);
|
|
141
|
+
}
|
|
142
|
+
const pixels = bctx.getImageData(0, 0, width, height);
|
|
143
|
+
for (let at = 3;at < pixels.data.length; at += 4)
|
|
144
|
+
pixels.data[at] = (pixels.data[at] ?? 0) > 120 ? 255 : 0;
|
|
145
|
+
bctx.putImageData(pixels, 0, 0);
|
|
146
|
+
const zoom = scale / ppu;
|
|
147
|
+
ctx.save();
|
|
148
|
+
ctx.imageSmoothingEnabled = false;
|
|
149
|
+
ctx.translate(x, y);
|
|
150
|
+
if (flip)
|
|
151
|
+
ctx.scale(-1, 1);
|
|
152
|
+
if (shadow) {
|
|
153
|
+
ctx.fillStyle = "rgba(10, 6, 24, 0.32)";
|
|
154
|
+
ctx.beginPath();
|
|
155
|
+
ctx.ellipse(0, 0, scale * 1.35, scale * 0.3, 0, 0, Math.PI * 2);
|
|
156
|
+
ctx.fill();
|
|
157
|
+
}
|
|
158
|
+
if (squash)
|
|
159
|
+
ctx.scale(squash.x, squash.y);
|
|
160
|
+
ctx.drawImage(scratch, -width / 2 * zoom, -floor * zoom, width * zoom, height * zoom);
|
|
161
|
+
ctx.restore();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// src/canvas.ts
|
|
165
|
+
var compose = (m, n) => [
|
|
166
|
+
m[0] * n[0] + m[2] * n[1],
|
|
167
|
+
m[1] * n[0] + m[3] * n[1],
|
|
168
|
+
m[0] * n[2] + m[2] * n[3],
|
|
169
|
+
m[1] * n[2] + m[3] * n[3],
|
|
170
|
+
m[0] * n[4] + m[2] * n[5] + m[4],
|
|
171
|
+
m[1] * n[4] + m[3] * n[5] + m[5]
|
|
172
|
+
];
|
|
173
|
+
var translate = (x, y) => [1, 0, 0, 1, x, y];
|
|
174
|
+
var scale = (x, y) => [x, 0, 0, y, 0, 0];
|
|
175
|
+
var rotate = (radians) => {
|
|
176
|
+
const cos = Math.cos(radians);
|
|
177
|
+
const sin = Math.sin(radians);
|
|
178
|
+
return [cos, sin, -sin, cos, 0, 0];
|
|
179
|
+
};
|
|
180
|
+
var boneColour = (bone, look) => bone === "Head" ? look.headColor ?? look.bodyColor : look.bodyColor;
|
|
181
|
+
function planCharacter2D(options) {
|
|
182
|
+
const {
|
|
183
|
+
rig: rigId = "plup",
|
|
184
|
+
look,
|
|
185
|
+
x,
|
|
186
|
+
y,
|
|
187
|
+
scale: size,
|
|
188
|
+
view = "front",
|
|
189
|
+
clip = "idle",
|
|
190
|
+
seconds = 0
|
|
191
|
+
} = options;
|
|
192
|
+
const rig = RIGS[rigId];
|
|
193
|
+
const body = clampBodyScale(options.bodyScale);
|
|
194
|
+
const pose = resolvePose(rigId, mergePoses(sampleClip(clip, seconds), options.pose ?? {}));
|
|
195
|
+
const lift = clipLift(clip, seconds) * body.stature;
|
|
196
|
+
const root = compose(translate(x, y - lift * size), scale(options.flip ? -size : size, size));
|
|
197
|
+
const children = (parent) => rig.bones.filter((bone) => bone.parent === parent);
|
|
198
|
+
const axis = view === "side" ? "x" : "z";
|
|
199
|
+
const face = view === "side" ? "right" : "front";
|
|
200
|
+
const ops = [];
|
|
201
|
+
const walk = (parent, parentMatrix) => {
|
|
202
|
+
for (const bone of children(parent)) {
|
|
203
|
+
const box = scaleBone(bone, nativePartOf(bone.name), bone.parent ? nativePartOf(bone.parent) : null, body);
|
|
204
|
+
const across = view === "side" ? box.joint[2] : box.joint[0];
|
|
205
|
+
const angle = -(pose.get(bone.name)?.[axis] ?? 0);
|
|
206
|
+
const matrix = compose(compose(parentMatrix, translate(across, -box.joint[1])), rotate(angle));
|
|
207
|
+
const width = view === "side" ? box.size[2] : box.size[0];
|
|
208
|
+
const centerAcross = view === "side" ? box.center[2] : box.center[0];
|
|
209
|
+
const part = {
|
|
210
|
+
x: centerAcross - width / 2,
|
|
211
|
+
y: -box.center[1] - box.size[1] / 2,
|
|
212
|
+
w: width,
|
|
213
|
+
h: box.size[1]
|
|
214
|
+
};
|
|
215
|
+
const skin = boneSkin(bone.name, face, look);
|
|
216
|
+
if (!skin?.redraw)
|
|
217
|
+
ops.push({
|
|
218
|
+
bone: bone.name,
|
|
219
|
+
matrix,
|
|
220
|
+
clip: part,
|
|
221
|
+
paint: { kind: "fill", color: boneColour(bone.name, look) }
|
|
222
|
+
});
|
|
223
|
+
if (skin)
|
|
224
|
+
ops.push({
|
|
225
|
+
bone: bone.name,
|
|
226
|
+
matrix,
|
|
227
|
+
clip: part,
|
|
228
|
+
paint: { kind: "image", image: skin.image, source: skin.source }
|
|
229
|
+
});
|
|
230
|
+
if (look.face && view === "front" && (bone.name === "Head" || bone.name === "Body"))
|
|
231
|
+
ops.push({
|
|
232
|
+
bone: bone.name,
|
|
233
|
+
matrix,
|
|
234
|
+
clip: part,
|
|
235
|
+
paint: { kind: "image", image: look.face, source: { x: 0, y: 0, w: 64, h: 64 } }
|
|
236
|
+
});
|
|
237
|
+
walk(bone.name, matrix);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
walk(null, root);
|
|
241
|
+
return ops;
|
|
242
|
+
}
|
|
243
|
+
function drawCharacter2D(context, options) {
|
|
244
|
+
if ((options.rig ?? "plup") === "plup" && !options.look.native && !options.look.variant) {
|
|
245
|
+
drawPlup2D(context, {
|
|
246
|
+
color: options.look.bodyColor,
|
|
247
|
+
...options.face ? { face: options.face } : {},
|
|
248
|
+
x: options.x,
|
|
249
|
+
y: options.y,
|
|
250
|
+
scale: options.scale,
|
|
251
|
+
...options.clip ? { clip: options.clip } : {},
|
|
252
|
+
...options.seconds === undefined ? {} : { seconds: options.seconds },
|
|
253
|
+
...options.pose ? { pose: options.pose } : {},
|
|
254
|
+
...options.flip ? { flip: true } : {}
|
|
255
|
+
});
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
context.save();
|
|
259
|
+
context.imageSmoothingEnabled = false;
|
|
260
|
+
for (const op of planCharacter2D(options)) {
|
|
261
|
+
context.save();
|
|
262
|
+
context.transform(...op.matrix);
|
|
263
|
+
context.beginPath();
|
|
264
|
+
context.rect(op.clip.x, op.clip.y, op.clip.w, op.clip.h);
|
|
265
|
+
context.clip();
|
|
266
|
+
if (op.paint.kind === "fill") {
|
|
267
|
+
context.fillStyle = op.paint.color;
|
|
268
|
+
context.fillRect(op.clip.x, op.clip.y, op.clip.w, op.clip.h);
|
|
269
|
+
} else
|
|
270
|
+
context.drawImage(op.paint.image, op.paint.source.x, op.paint.source.y, op.paint.source.w, op.paint.source.h, op.clip.x, op.clip.y, op.clip.w, op.clip.h);
|
|
271
|
+
context.restore();
|
|
272
|
+
}
|
|
273
|
+
context.restore();
|
|
274
|
+
}
|
|
275
|
+
function convertClassicToNative(images) {
|
|
276
|
+
const canvas = document.createElement("canvas");
|
|
277
|
+
canvas.width = NATIVE_WIDTH;
|
|
278
|
+
canvas.height = NATIVE_HEIGHT;
|
|
279
|
+
const context = canvas.getContext("2d");
|
|
280
|
+
if (context) {
|
|
281
|
+
context.imageSmoothingEnabled = false;
|
|
282
|
+
for (const op of CLASSIC_TO_NATIVE) {
|
|
283
|
+
const image = images[op.sheet];
|
|
284
|
+
if (!image)
|
|
285
|
+
continue;
|
|
286
|
+
context.drawImage(image, op.source.x, op.source.y, op.source.w, op.source.h, op.dest.x, op.dest.y, op.dest.w, op.dest.h);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return canvas;
|
|
290
|
+
}
|
|
291
|
+
function faceCanvas(face, size = 64) {
|
|
292
|
+
const canvas = document.createElement("canvas");
|
|
293
|
+
canvas.width = canvas.height = size;
|
|
294
|
+
const context = canvas.getContext("2d");
|
|
295
|
+
if (!context)
|
|
296
|
+
return canvas;
|
|
297
|
+
const cell = size / 8;
|
|
298
|
+
const top = (size - cell * 4) / 2;
|
|
299
|
+
NAMED_FACE_STAMPS[face].forEach((row, y) => {
|
|
300
|
+
for (const [x, key] of [...row].entries()) {
|
|
301
|
+
const color = FACE_STAMP_PALETTE[key];
|
|
302
|
+
if (!color)
|
|
303
|
+
continue;
|
|
304
|
+
context.fillStyle = color;
|
|
305
|
+
context.fillRect(x * cell, top + y * cell, cell, cell);
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
return canvas;
|
|
309
|
+
}
|
|
310
|
+
export {
|
|
311
|
+
planCharacter2D,
|
|
312
|
+
faceCanvas,
|
|
313
|
+
drawCharacter2D,
|
|
314
|
+
convertClassicToNative
|
|
315
|
+
};
|