@plupin/character 0.2.0 → 0.4.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 +70 -0
- package/dist/blob.js +46 -0
- package/dist/body-presets.d.ts +153 -0
- package/dist/canvas.js +27 -8
- package/dist/chunk-7ry0n8cw.js +1209 -0
- package/dist/{chunk-k5gwaq6t.js → chunk-ew73g2v7.js} +36 -3
- package/dist/chunk-ewkkvpte.js +448 -0
- package/dist/chunk-kf7f1tdx.js +207 -0
- package/dist/chunk-nx2wbkfn.js +421 -0
- package/dist/chunk-rqenm9tn.js +487 -0
- package/dist/chunk-vy9w8as2.js +196 -0
- package/dist/clips.d.ts +40 -0
- package/dist/dress.d.ts +4 -0
- package/dist/emote.d.ts +5 -3
- 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 +9 -2
- package/dist/index.js +46 -10
- package/dist/listing.d.ts +1 -1
- package/dist/listing.js +52 -16
- package/dist/platform-body-data.d.ts +9 -0
- package/dist/platform-body.d.ts +91 -0
- package/dist/plup3d.d.ts +43 -44
- package/dist/png.d.ts +23 -5
- package/dist/pose.d.ts +7 -1
- package/dist/pose.js +1 -1
- package/dist/proportions.d.ts +31 -0
- package/dist/ragdoll.d.ts +51 -0
- package/dist/resolution.d.ts +21 -0
- package/dist/skin-map.d.ts +156 -0
- package/dist/skin-map.js +57 -0
- package/dist/skin-native.d.ts +73 -6
- package/dist/texture.d.ts +8 -0
- package/dist/three.d.ts +11 -1
- package/dist/three.js +2820 -205
- package/dist/wear3d.d.ts +118 -0
- package/dist/wearables.d.ts +307 -0
- package/dist/wearables.js +26 -0
- package/package.json +21 -1
- package/dist/chunk-ae7gp5cc.js +0 -101
- package/dist/chunk-wpbgtn0y.js +0 -179
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RIGS
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7ry0n8cw.js";
|
|
4
4
|
|
|
5
5
|
// src/skin.ts
|
|
6
6
|
var rect = (x, y, w, h) => ({ x, y, w, h });
|
|
@@ -175,10 +175,43 @@ function nativeFaceRect(bone, face) {
|
|
|
175
175
|
return rect2(base.x, top, base.w, bottom - top);
|
|
176
176
|
}
|
|
177
177
|
var BODY_SCALE_LIMITS = {
|
|
178
|
-
stature: { min: 0.5, max: 1.
|
|
178
|
+
stature: { min: 0.5, max: 1.5 },
|
|
179
179
|
width: { min: 0.9, max: 1.3 },
|
|
180
180
|
head: { min: 0.9, max: 1.25 }
|
|
181
181
|
};
|
|
182
|
+
var PLUP_BODY_LIMITS = {
|
|
183
|
+
shoulders: { min: 0.65, max: 1.6 },
|
|
184
|
+
waist: { min: 0.48, max: 1.25 },
|
|
185
|
+
hips: { min: 0.75, max: 1.55 },
|
|
186
|
+
bust: { min: 0, max: 1.4 },
|
|
187
|
+
legLength: { min: 1, max: 3 },
|
|
188
|
+
armLength: { min: 0.8, max: 1.8 },
|
|
189
|
+
muscle: { min: 0.7, max: 2.2 },
|
|
190
|
+
shoulderHeight: { min: 0.2, max: 0.55 },
|
|
191
|
+
headSize: { min: 0.55, max: 1.25 },
|
|
192
|
+
figure: { min: 0, max: 1 }
|
|
193
|
+
};
|
|
194
|
+
var CANONICAL_PLUP_BODY = {
|
|
195
|
+
shoulders: 1,
|
|
196
|
+
waist: 1,
|
|
197
|
+
hips: 1,
|
|
198
|
+
bust: 0,
|
|
199
|
+
legLength: 1,
|
|
200
|
+
armLength: 1,
|
|
201
|
+
muscle: 1,
|
|
202
|
+
shoulderHeight: 0.34,
|
|
203
|
+
headSize: 1,
|
|
204
|
+
figure: 0
|
|
205
|
+
};
|
|
206
|
+
function clampPlupBody(body) {
|
|
207
|
+
const out = { ...CANONICAL_PLUP_BODY };
|
|
208
|
+
for (const key of Object.keys(PLUP_BODY_LIMITS)) {
|
|
209
|
+
const value = body?.[key];
|
|
210
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
211
|
+
out[key] = Math.min(PLUP_BODY_LIMITS[key].max, Math.max(PLUP_BODY_LIMITS[key].min, value));
|
|
212
|
+
}
|
|
213
|
+
return out;
|
|
214
|
+
}
|
|
182
215
|
var CANONICAL_BODY_SCALE = { stature: 1, width: {}, head: 1 };
|
|
183
216
|
var WIDTH_PARTS = ["torso", "armL", "armR", "legL", "legR"];
|
|
184
217
|
var clamp = (value, limit) => typeof value === "number" && Number.isFinite(value) ? Math.min(limit.max, Math.max(limit.min, value)) : 1;
|
|
@@ -312,4 +345,4 @@ var CLASSIC_TO_NATIVE = CLASSIC_SOURCES.flatMap(({ part, bone }) => {
|
|
|
312
345
|
}));
|
|
313
346
|
});
|
|
314
347
|
|
|
315
|
-
export { CLASSIC_WIDTH, CLASSIC_HEIGHT, CLASSIC_TORSO, CLASSIC_RIGHT_LIMB, CLASSIC_LEFT_LIMB, CLASSIC_BONES, classicFaceRect, validateClassicTemplate, NATIVE_PX_PER_STUD, NATIVE_WIDTH, NATIVE_HEIGHT, NATIVE_TORSO, NATIVE_HEAD, NATIVE_ARM_LEFT, NATIVE_ARM_RIGHT, NATIVE_LEG_LEFT, NATIVE_LEG_RIGHT, NATIVE_PARTS, NATIVE_BONES, nativePartOf, nativeFaceRect, BODY_SCALE_LIMITS, CANONICAL_BODY_SCALE, clampBodyScale, scaleBone, canonicalFootprint, visualEnvelope, NATIVE_SHEET_CAPS, validateVariantSheet, boneSkin, CLASSIC_TO_NATIVE };
|
|
348
|
+
export { CLASSIC_WIDTH, CLASSIC_HEIGHT, CLASSIC_TORSO, CLASSIC_RIGHT_LIMB, CLASSIC_LEFT_LIMB, CLASSIC_BONES, classicFaceRect, validateClassicTemplate, NATIVE_PX_PER_STUD, NATIVE_WIDTH, NATIVE_HEIGHT, NATIVE_TORSO, NATIVE_HEAD, NATIVE_ARM_LEFT, NATIVE_ARM_RIGHT, NATIVE_LEG_LEFT, NATIVE_LEG_RIGHT, NATIVE_PARTS, NATIVE_BONES, nativePartOf, nativeFaceRect, BODY_SCALE_LIMITS, PLUP_BODY_LIMITS, CANONICAL_PLUP_BODY, clampPlupBody, CANONICAL_BODY_SCALE, clampBodyScale, scaleBone, canonicalFootprint, visualEnvelope, NATIVE_SHEET_CAPS, validateVariantSheet, boneSkin, CLASSIC_TO_NATIVE };
|
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
// src/anime-face.ts
|
|
2
|
+
var ANIME_FACE_SIZE = { width: 512, height: 256 };
|
|
3
|
+
var ANIME_FACE_UV = { u0: 0.1, u1: 0.4, v0: 0.27, v1: 0.61 };
|
|
4
|
+
var PARTS = {
|
|
5
|
+
idle: { eyes: "open", mouth: "smile", brows: "calm", blush: 0.55 },
|
|
6
|
+
blink: { eyes: "closed", mouth: "smile", brows: "calm", blush: 0.55 },
|
|
7
|
+
happy: { eyes: "happy", mouth: "open", brows: "up", blush: 0.85 },
|
|
8
|
+
surprised: { eyes: "wide", mouth: "o", brows: "up", blush: 0.4 },
|
|
9
|
+
sad: { eyes: "sad", mouth: "frown", brows: "sad", blush: 0.3 },
|
|
10
|
+
wee: { eyes: "happy", mouth: "o", brows: "up", blush: 0.9 },
|
|
11
|
+
sparkle: { eyes: "stars", mouth: "open", brows: "up", blush: 0.9 },
|
|
12
|
+
shock: { eyes: "wide", mouth: "o", brows: "up", blush: 0.2 },
|
|
13
|
+
yell: { eyes: "angry", mouth: "yell", brows: "angry", blush: 0.3 },
|
|
14
|
+
pain: { eyes: "closed", mouth: "frown", brows: "sad", blush: 0.2 },
|
|
15
|
+
dead: { eyes: "dead", mouth: "flat", brows: "none", blush: 0 },
|
|
16
|
+
rage: { eyes: "angry", mouth: "grin", brows: "angry", blush: 0.2 },
|
|
17
|
+
speechless: { eyes: "half", mouth: "flat", brows: "calm", blush: 0.2 },
|
|
18
|
+
idea: { eyes: "wide", mouth: "smile", brows: "up", blush: 0.5 },
|
|
19
|
+
smug: { eyes: "half", mouth: "cat", brows: "calm", blush: 0.6 },
|
|
20
|
+
cry: { eyes: "cry", mouth: "frown", brows: "sad", blush: 0.5, tears: true },
|
|
21
|
+
smirk: { eyes: "wink", mouth: "smirk", brows: "calm", blush: 0.55 },
|
|
22
|
+
tongue: { eyes: "wink", mouth: "tongue", brows: "up", blush: 0.7 },
|
|
23
|
+
cool: { eyes: "half", mouth: "smirk", brows: "calm", blush: 0.15 },
|
|
24
|
+
serious: { eyes: "angry", mouth: "flat", brows: "angry", blush: 0 },
|
|
25
|
+
stars: { eyes: "stars", mouth: "grin", brows: "up", blush: 0.9 },
|
|
26
|
+
licik: { eyes: "half", mouth: "grin", brows: "angry", blush: 0.3 },
|
|
27
|
+
tidur: { eyes: "closed", mouth: "o", brows: "calm", blush: 0.5 },
|
|
28
|
+
teriak: { eyes: "angry", mouth: "yell", brows: "angry", blush: 0.3 },
|
|
29
|
+
ngomel: { eyes: "angry", mouth: "frown", brows: "angry", blush: 0.3 }
|
|
30
|
+
};
|
|
31
|
+
var INK = "#221633";
|
|
32
|
+
var LASH = "#1c1229";
|
|
33
|
+
function animeFaceParts(face) {
|
|
34
|
+
return PARTS[face] ?? PARTS.idle ?? { eyes: "open", mouth: "smile", brows: "calm", blush: 0.5 };
|
|
35
|
+
}
|
|
36
|
+
var W = ANIME_FACE_SIZE.width;
|
|
37
|
+
var H = ANIME_FACE_SIZE.height;
|
|
38
|
+
var EYE_Y = 122;
|
|
39
|
+
var EYE_X = 82;
|
|
40
|
+
var EYE_W = 84;
|
|
41
|
+
var EYE_H = 92;
|
|
42
|
+
var MOUTH_Y = 198;
|
|
43
|
+
var ANIME_EYE_LINE = EYE_Y / H;
|
|
44
|
+
var mix = (a, b, t) => {
|
|
45
|
+
const ch = (hex, i) => Number.parseInt(hex.slice(1 + i * 2, 3 + i * 2), 16);
|
|
46
|
+
return `#${[0, 1, 2].map((i) => Math.max(0, Math.min(255, Math.round(ch(a, i) + (ch(b, i) - ch(a, i)) * t))).toString(16).padStart(2, "0")).join("")}`;
|
|
47
|
+
};
|
|
48
|
+
function ellipse(ctx, x, y, rx, ry, rot = 0) {
|
|
49
|
+
ctx.beginPath();
|
|
50
|
+
ctx.ellipse(x, y, Math.max(0.5, rx), Math.max(0.5, ry), rot, 0, Math.PI * 2);
|
|
51
|
+
}
|
|
52
|
+
function eyeShape(ctx, x, y, side, style) {
|
|
53
|
+
const isIkemen = style === "ikemen";
|
|
54
|
+
const w = (isIkemen ? EYE_W * 1.04 : EYE_W) / 2;
|
|
55
|
+
const h = (isIkemen ? EYE_H * 0.66 : EYE_H) / 2;
|
|
56
|
+
const outer = side;
|
|
57
|
+
ctx.beginPath();
|
|
58
|
+
if (isIkemen) {
|
|
59
|
+
ctx.moveTo(x - outer * w * 1.02, y + h * 0.08);
|
|
60
|
+
ctx.bezierCurveTo(x - outer * w * 0.55, y - h * 1.06, x + outer * w * 0.62, y - h * 1.15, x + outer * w * 1.08, y - h * 0.36);
|
|
61
|
+
ctx.bezierCurveTo(x + outer * w * 0.85, y + h * 0.72, x + outer * w * 0.25, y + h * 1.02, x - outer * w * 0.28, y + h * 0.88);
|
|
62
|
+
ctx.bezierCurveTo(x - outer * w * 0.72, y + h * 0.72, x - outer * w * 0.96, y + h * 0.36, x - outer * w * 1.02, y + h * 0.08);
|
|
63
|
+
} else {
|
|
64
|
+
ctx.moveTo(x - outer * w * 0.98, y - h * 0.05);
|
|
65
|
+
ctx.bezierCurveTo(x - outer * w * 0.82, y - h * 1.08, x + outer * w * 0.78, y - h * 1.12, x + outer * w * 1.04, y - h * 0.22);
|
|
66
|
+
ctx.bezierCurveTo(x + outer * w * 1.02, y + h * 0.76, x + outer * w * 0.45, y + h * 1.02, x, y + h * 1);
|
|
67
|
+
ctx.bezierCurveTo(x - outer * w * 0.52, y + h * 0.98, x - outer * w * 0.98, y + h * 0.68, x - outer * w * 0.98, y - h * 0.05);
|
|
68
|
+
}
|
|
69
|
+
ctx.closePath();
|
|
70
|
+
}
|
|
71
|
+
function lashes(ctx, x, y, side, style, lift = 0) {
|
|
72
|
+
const isIkemen = style === "ikemen";
|
|
73
|
+
const w = (isIkemen ? EYE_W * 1.04 : EYE_W) / 2;
|
|
74
|
+
const h = (isIkemen ? EYE_H * 0.66 : EYE_H) / 2;
|
|
75
|
+
const outer = side;
|
|
76
|
+
ctx.fillStyle = LASH;
|
|
77
|
+
ctx.beginPath();
|
|
78
|
+
if (isIkemen) {
|
|
79
|
+
ctx.moveTo(x - outer * w * 1.06, y + h * 0.08 + lift);
|
|
80
|
+
ctx.bezierCurveTo(x - outer * w * 0.55, y - h * 1.18 + lift, x + outer * w * 0.65, y - h * 1.32 + lift, x + outer * w * 1.18, y - h * 0.52 + lift);
|
|
81
|
+
ctx.lineTo(x + outer * w * 1.06, y - h * 0.22 + lift);
|
|
82
|
+
ctx.bezierCurveTo(x + outer * w * 0.58, y - h * 0.88 + lift, x - outer * w * 0.52, y - h * 0.78 + lift, x - outer * w * 1.06, y + h * 0.08 + lift);
|
|
83
|
+
} else {
|
|
84
|
+
ctx.moveTo(x - outer * w * 1.02, y - h * 0.04 + lift);
|
|
85
|
+
ctx.bezierCurveTo(x - outer * w * 0.84, y - h * 1.16 + lift, x + outer * w * 0.75, y - h * 1.24 + lift, x + outer * w * 1.16, y - h * 0.42 + lift);
|
|
86
|
+
ctx.quadraticCurveTo(x + outer * w * 1.32, y - h * 0.62 + lift, x + outer * w * 1.38, y - h * 0.78 + lift);
|
|
87
|
+
ctx.quadraticCurveTo(x + outer * w * 1.24, y - h * 0.38 + lift, x + outer * w * 1.05, y - h * 0.14 + lift);
|
|
88
|
+
ctx.bezierCurveTo(x + outer * w * 0.72, y - h * 0.86 + lift, x - outer * w * 0.74, y - h * 0.82 + lift, x - outer * w * 1.02, y - h * 0.04 + lift);
|
|
89
|
+
}
|
|
90
|
+
ctx.closePath();
|
|
91
|
+
ctx.fill();
|
|
92
|
+
if (!isIkemen) {
|
|
93
|
+
ctx.strokeStyle = LASH;
|
|
94
|
+
ctx.lineWidth = 2.6;
|
|
95
|
+
ctx.lineCap = "round";
|
|
96
|
+
ctx.beginPath();
|
|
97
|
+
ctx.moveTo(x + outer * w * 0.96, y - h * 0.3 + lift);
|
|
98
|
+
ctx.quadraticCurveTo(x + outer * w * 1.18, y - h * 0.34 + lift, x + outer * w * 1.3, y - h * 0.48 + lift);
|
|
99
|
+
ctx.moveTo(x + outer * w * 0.78, y - h * 0.7 + lift);
|
|
100
|
+
ctx.quadraticCurveTo(x + outer * w * 0.98, y - h * 0.92 + lift, x + outer * w * 1.12, y - h * 1.06 + lift);
|
|
101
|
+
ctx.stroke();
|
|
102
|
+
}
|
|
103
|
+
ctx.strokeStyle = isIkemen ? "rgba(45, 30, 62, 0.5)" : "rgba(75, 42, 78, 0.45)";
|
|
104
|
+
ctx.lineWidth = isIkemen ? 2.2 : 2;
|
|
105
|
+
ctx.lineCap = "round";
|
|
106
|
+
ctx.beginPath();
|
|
107
|
+
ctx.moveTo(x - outer * w * 0.65, y - h * (isIkemen ? 1.18 : 1.06) + lift);
|
|
108
|
+
ctx.quadraticCurveTo(x + outer * w * 0.1, y - h * (isIkemen ? 1.48 : 1.38) + lift, x + outer * w * 0.85, y - h * (isIkemen ? 1.24 : 1.06) + lift);
|
|
109
|
+
ctx.stroke();
|
|
110
|
+
}
|
|
111
|
+
function lowerLash(ctx, x, y, side, style) {
|
|
112
|
+
const isIkemen = style === "ikemen";
|
|
113
|
+
const w = (isIkemen ? EYE_W * 1.04 : EYE_W) / 2;
|
|
114
|
+
const h = (isIkemen ? EYE_H * 0.66 : EYE_H) / 2;
|
|
115
|
+
ctx.strokeStyle = isIkemen ? "rgba(28, 18, 41, 0.75)" : "rgba(44, 24, 58, 0.65)";
|
|
116
|
+
ctx.lineWidth = isIkemen ? 2.4 : 2.2;
|
|
117
|
+
ctx.lineCap = "round";
|
|
118
|
+
ctx.beginPath();
|
|
119
|
+
ctx.moveTo(x + side * w * 0.92, y + h * 0.36);
|
|
120
|
+
ctx.quadraticCurveTo(x + side * w * 0.52, y + h * 0.96, x - side * w * 0.1, y + h * 0.98);
|
|
121
|
+
ctx.stroke();
|
|
122
|
+
if (!isIkemen) {
|
|
123
|
+
ctx.strokeStyle = "rgba(235, 130, 165, 0.32)";
|
|
124
|
+
ctx.lineWidth = 3;
|
|
125
|
+
ctx.beginPath();
|
|
126
|
+
ctx.moveTo(x - side * w * 0.4, y + h * 1.18);
|
|
127
|
+
ctx.quadraticCurveTo(x + side * w * 0.1, y + h * 1.32, x + side * w * 0.65, y + h * 1.12);
|
|
128
|
+
ctx.stroke();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function openEye(ctx, x, y, side, iris, style, { pupil = 1, wet = false, catchlights = 3, squint = 0 } = {}) {
|
|
132
|
+
const isIkemen = style === "ikemen";
|
|
133
|
+
const h = (isIkemen ? EYE_H * 0.66 : EYE_H) / 2;
|
|
134
|
+
ctx.save();
|
|
135
|
+
eyeShape(ctx, x, y, side, style);
|
|
136
|
+
const sclera = ctx.createLinearGradient(0, y - h, 0, y + h);
|
|
137
|
+
sclera.addColorStop(0, "#e2dced");
|
|
138
|
+
sclera.addColorStop(0.32, "#fffdff");
|
|
139
|
+
sclera.addColorStop(1, "#fff8fb");
|
|
140
|
+
ctx.fillStyle = sclera;
|
|
141
|
+
ctx.fill();
|
|
142
|
+
ctx.clip();
|
|
143
|
+
const ix = x + side * 2;
|
|
144
|
+
const iy = y + (isIkemen ? 1 : 4);
|
|
145
|
+
const irx = isIkemen ? EYE_W * 0.34 : EYE_W * 0.38;
|
|
146
|
+
const iry = isIkemen ? EYE_H * 0.32 : EYE_H * 0.44;
|
|
147
|
+
const gradient = ctx.createLinearGradient(0, iy - iry, 0, iy + iry);
|
|
148
|
+
gradient.addColorStop(0, mix(iris, "#0e061a", 0.68));
|
|
149
|
+
gradient.addColorStop(0.38, mix(iris, "#1c0e30", 0.25));
|
|
150
|
+
gradient.addColorStop(0.68, iris);
|
|
151
|
+
gradient.addColorStop(1, mix(iris, "#fff5ff", 0.62));
|
|
152
|
+
ellipse(ctx, ix, iy, irx, iry);
|
|
153
|
+
ctx.fillStyle = gradient;
|
|
154
|
+
ctx.fill();
|
|
155
|
+
ctx.lineWidth = isIkemen ? 2.6 : 3;
|
|
156
|
+
ctx.strokeStyle = mix(iris, "#0c0516", 0.72);
|
|
157
|
+
ctx.stroke();
|
|
158
|
+
ctx.save();
|
|
159
|
+
ellipse(ctx, ix, iy + iry * 0.42, irx * 0.68, iry * 0.34);
|
|
160
|
+
ctx.fillStyle = `${mix(iris, "#ffffff", 0.75)}aa`;
|
|
161
|
+
ctx.fill();
|
|
162
|
+
ellipse(ctx, ix, iy + iry * 0.5, irx * 0.46, iry * 0.2);
|
|
163
|
+
ctx.fillStyle = `${mix(iris, "#fff8ff", 0.88)}cc`;
|
|
164
|
+
ctx.fill();
|
|
165
|
+
ctx.restore();
|
|
166
|
+
ellipse(ctx, ix, iy + 1, irx * (isIkemen ? 0.36 : 0.4) * pupil, iry * 0.42 * pupil);
|
|
167
|
+
ctx.fillStyle = mix(iris, "#080312", 0.85);
|
|
168
|
+
ctx.fill();
|
|
169
|
+
if (pupil > 0.7 && !isIkemen) {
|
|
170
|
+
ellipse(ctx, ix, iy + iry * 0.14, irx * 0.16, iry * 0.12);
|
|
171
|
+
ctx.fillStyle = `${mix(iris, "#ffffff", 0.5)}88`;
|
|
172
|
+
ctx.fill();
|
|
173
|
+
}
|
|
174
|
+
const shadowGrad = ctx.createLinearGradient(0, y - h, 0, y - h * 0.05 + squint);
|
|
175
|
+
shadowGrad.addColorStop(0, "rgba(28, 14, 52, 0.52)");
|
|
176
|
+
shadowGrad.addColorStop(0.7, "rgba(38, 18, 68, 0.24)");
|
|
177
|
+
shadowGrad.addColorStop(1, "rgba(38, 18, 68, 0)");
|
|
178
|
+
ctx.fillStyle = shadowGrad;
|
|
179
|
+
ctx.fillRect(x - EYE_W, y - EYE_H, EYE_W * 2, EYE_H * 0.65 + squint);
|
|
180
|
+
ctx.restore();
|
|
181
|
+
ctx.fillStyle = "#ffffff";
|
|
182
|
+
if (catchlights > 0) {
|
|
183
|
+
ellipse(ctx, ix - side * irx * 0.38, iy - iry * 0.36, irx * (isIkemen ? 0.25 : 0.32), iry * (isIkemen ? 0.22 : 0.24), -side * 0.35);
|
|
184
|
+
ctx.fill();
|
|
185
|
+
}
|
|
186
|
+
if (catchlights > 1) {
|
|
187
|
+
ellipse(ctx, ix + side * irx * 0.38, iy + iry * 0.36, irx * 0.14, iry * 0.12);
|
|
188
|
+
ctx.fill();
|
|
189
|
+
}
|
|
190
|
+
if (catchlights > 2 && !isIkemen) {
|
|
191
|
+
ellipse(ctx, ix + side * irx * 0.28, iy - iry * 0.44, irx * 0.09, iry * 0.09);
|
|
192
|
+
ctx.fill();
|
|
193
|
+
}
|
|
194
|
+
if (wet) {
|
|
195
|
+
ctx.globalAlpha = 0.85;
|
|
196
|
+
ellipse(ctx, ix, iy + iry * 0.62, irx * 0.72, iry * 0.13);
|
|
197
|
+
ctx.fill();
|
|
198
|
+
ctx.globalAlpha = 1;
|
|
199
|
+
}
|
|
200
|
+
lashes(ctx, x, y, side, style, squint * 0.8);
|
|
201
|
+
lowerLash(ctx, x, y, side, style);
|
|
202
|
+
}
|
|
203
|
+
function closedEye(ctx, x, y, side, happy, style) {
|
|
204
|
+
const w = EYE_W / 2;
|
|
205
|
+
ctx.strokeStyle = LASH;
|
|
206
|
+
ctx.lineWidth = style === "ikemen" ? 5.5 : 6.5;
|
|
207
|
+
ctx.lineCap = "round";
|
|
208
|
+
ctx.beginPath();
|
|
209
|
+
if (happy) {
|
|
210
|
+
ctx.moveTo(x - w * 0.9, y + 8);
|
|
211
|
+
ctx.quadraticCurveTo(x, y - (style === "ikemen" ? 16 : 24), x + w * 0.9, y + 8);
|
|
212
|
+
} else {
|
|
213
|
+
ctx.moveTo(x - w * 0.9, y + 2);
|
|
214
|
+
ctx.quadraticCurveTo(x, y + 18, x + w * 0.9, y + 2);
|
|
215
|
+
if (style === "anime") {
|
|
216
|
+
ctx.moveTo(x + side * w * 0.85, y + 3);
|
|
217
|
+
ctx.lineTo(x + side * w * 1.18, y - 5);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
ctx.stroke();
|
|
221
|
+
}
|
|
222
|
+
function star(ctx, x, y, r, color) {
|
|
223
|
+
ctx.beginPath();
|
|
224
|
+
for (let i = 0;i < 8; i += 1) {
|
|
225
|
+
const a = i / 8 * Math.PI * 2 - Math.PI / 2;
|
|
226
|
+
const k = i % 2 ? r * 0.36 : r;
|
|
227
|
+
ctx.lineTo(x + Math.cos(a) * k, y + Math.sin(a) * k);
|
|
228
|
+
}
|
|
229
|
+
ctx.closePath();
|
|
230
|
+
ctx.fillStyle = color;
|
|
231
|
+
ctx.fill();
|
|
232
|
+
}
|
|
233
|
+
function eye(ctx, side, parts, iris, style) {
|
|
234
|
+
const x = W / 2 + side * EYE_X;
|
|
235
|
+
const y = EYE_Y;
|
|
236
|
+
switch (parts.eyes) {
|
|
237
|
+
case "closed":
|
|
238
|
+
return closedEye(ctx, x, y, side, false, style);
|
|
239
|
+
case "happy":
|
|
240
|
+
return closedEye(ctx, x, y, side, true, style);
|
|
241
|
+
case "wink":
|
|
242
|
+
return side > 0 ? closedEye(ctx, x, y, side, true, style) : openEye(ctx, x, y, side, iris, style);
|
|
243
|
+
case "wide":
|
|
244
|
+
return openEye(ctx, x, y, side, iris, style, { pupil: 0.45, catchlights: 1 });
|
|
245
|
+
case "sad":
|
|
246
|
+
case "cry":
|
|
247
|
+
return openEye(ctx, x, y, side, iris, style, { wet: true, pupil: 1.08 });
|
|
248
|
+
case "half":
|
|
249
|
+
openEye(ctx, x, y, side, iris, style, { squint: style === "ikemen" ? 14 : 20 });
|
|
250
|
+
return;
|
|
251
|
+
case "angry":
|
|
252
|
+
openEye(ctx, x, y, side, iris, style, { catchlights: 1, squint: 12, pupil: 0.72 });
|
|
253
|
+
return;
|
|
254
|
+
case "stars":
|
|
255
|
+
openEye(ctx, x, y, side, iris, style, { catchlights: 1 });
|
|
256
|
+
star(ctx, x + side * 2, y + 4, 19, "#fff6b0");
|
|
257
|
+
return;
|
|
258
|
+
case "dead": {
|
|
259
|
+
ctx.strokeStyle = LASH;
|
|
260
|
+
ctx.lineWidth = 6;
|
|
261
|
+
ctx.lineCap = "round";
|
|
262
|
+
ctx.beginPath();
|
|
263
|
+
ctx.moveTo(x - 18, y - 18);
|
|
264
|
+
ctx.lineTo(x + 18, y + 18);
|
|
265
|
+
ctx.moveTo(x + 18, y - 18);
|
|
266
|
+
ctx.lineTo(x - 18, y + 18);
|
|
267
|
+
ctx.stroke();
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
default:
|
|
271
|
+
openEye(ctx, x, y, side, iris, style);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function brow(ctx, side, brows, style) {
|
|
275
|
+
if (brows === "none")
|
|
276
|
+
return;
|
|
277
|
+
const isIkemen = style === "ikemen";
|
|
278
|
+
const x = W / 2 + side * EYE_X;
|
|
279
|
+
const y = EYE_Y - EYE_H * (isIkemen ? 0.56 : 0.72);
|
|
280
|
+
const tilt = brows === "angry" ? 14 : brows === "sad" ? -11 : isIkemen ? 4 : 0;
|
|
281
|
+
const lift = brows === "up" ? -7 : 0;
|
|
282
|
+
ctx.strokeStyle = isIkemen ? LASH : mix(LASH, "#6b4a62", 0.3);
|
|
283
|
+
ctx.lineWidth = isIkemen ? 5.2 : 3.2;
|
|
284
|
+
ctx.lineCap = "round";
|
|
285
|
+
ctx.beginPath();
|
|
286
|
+
if (isIkemen) {
|
|
287
|
+
ctx.moveTo(x - side * 28, y + lift + tilt);
|
|
288
|
+
ctx.quadraticCurveTo(x + side * 4, y + lift - 7, x + side * 30, y + lift - tilt * 0.25);
|
|
289
|
+
} else {
|
|
290
|
+
ctx.moveTo(x - side * 22, y + lift + tilt);
|
|
291
|
+
ctx.quadraticCurveTo(x, y + lift - 6, x + side * 22, y + lift - tilt * 0.2);
|
|
292
|
+
}
|
|
293
|
+
ctx.stroke();
|
|
294
|
+
}
|
|
295
|
+
function nose(ctx, style) {
|
|
296
|
+
const x = W / 2;
|
|
297
|
+
const y = EYE_Y + 34;
|
|
298
|
+
if (style === "ikemen") {
|
|
299
|
+
ctx.strokeStyle = "rgba(80, 52, 74, 0.36)";
|
|
300
|
+
ctx.lineWidth = 2.4;
|
|
301
|
+
ctx.lineCap = "round";
|
|
302
|
+
ctx.beginPath();
|
|
303
|
+
ctx.moveTo(x - 2, y - 12);
|
|
304
|
+
ctx.lineTo(x - 4, y + 4);
|
|
305
|
+
ctx.lineTo(x + 2, y + 6);
|
|
306
|
+
ctx.stroke();
|
|
307
|
+
} else {
|
|
308
|
+
ctx.fillStyle = "rgba(150, 82, 98, 0.42)";
|
|
309
|
+
ellipse(ctx, x, y, 3.2, 2.2);
|
|
310
|
+
ctx.fill();
|
|
311
|
+
ctx.fillStyle = "rgba(255, 255, 255, 0.55)";
|
|
312
|
+
ellipse(ctx, x - 2, y - 3, 2, 1.4);
|
|
313
|
+
ctx.fill();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
function mouth(ctx, shape, style) {
|
|
317
|
+
const x = W / 2;
|
|
318
|
+
const y = MOUTH_Y;
|
|
319
|
+
const isIkemen = style === "ikemen";
|
|
320
|
+
ctx.strokeStyle = INK;
|
|
321
|
+
ctx.lineWidth = isIkemen ? 3.4 : 3.2;
|
|
322
|
+
ctx.lineCap = "round";
|
|
323
|
+
ctx.lineJoin = "round";
|
|
324
|
+
const fillOpen = (w, h, round = false) => {
|
|
325
|
+
ctx.beginPath();
|
|
326
|
+
if (round)
|
|
327
|
+
ctx.ellipse(x, y + h / 2, w, h / 2 + 2, 0, 0, Math.PI * 2);
|
|
328
|
+
else {
|
|
329
|
+
ctx.moveTo(x - w, y);
|
|
330
|
+
ctx.quadraticCurveTo(x, y + h * 1.9, x + w, y);
|
|
331
|
+
ctx.closePath();
|
|
332
|
+
}
|
|
333
|
+
ctx.fillStyle = "#8a2a42";
|
|
334
|
+
ctx.fill();
|
|
335
|
+
ctx.stroke();
|
|
336
|
+
ctx.save();
|
|
337
|
+
ctx.clip();
|
|
338
|
+
ellipse(ctx, x, y + h * 1, w * 0.62, h * 0.5);
|
|
339
|
+
ctx.fillStyle = "#f27e9c";
|
|
340
|
+
ctx.fill();
|
|
341
|
+
ctx.restore();
|
|
342
|
+
};
|
|
343
|
+
ctx.beginPath();
|
|
344
|
+
switch (shape) {
|
|
345
|
+
case "smile":
|
|
346
|
+
if (isIkemen) {
|
|
347
|
+
ctx.moveTo(x - 13, y + 2);
|
|
348
|
+
ctx.quadraticCurveTo(x + 2, y + 6, x + 15, y - 2);
|
|
349
|
+
ctx.stroke();
|
|
350
|
+
} else {
|
|
351
|
+
ctx.fillStyle = "rgba(245, 130, 160, 0.35)";
|
|
352
|
+
ellipse(ctx, x, y + 6, 9, 3.2);
|
|
353
|
+
ctx.fill();
|
|
354
|
+
ctx.beginPath();
|
|
355
|
+
ctx.moveTo(x - 10, y);
|
|
356
|
+
ctx.quadraticCurveTo(x, y + 7, x + 10, y);
|
|
357
|
+
ctx.stroke();
|
|
358
|
+
}
|
|
359
|
+
return;
|
|
360
|
+
case "cat":
|
|
361
|
+
ctx.moveTo(x - 13, y - 2);
|
|
362
|
+
ctx.quadraticCurveTo(x - 6, y + 8, x, y);
|
|
363
|
+
ctx.quadraticCurveTo(x + 6, y + 8, x + 13, y - 2);
|
|
364
|
+
ctx.stroke();
|
|
365
|
+
return;
|
|
366
|
+
case "open":
|
|
367
|
+
return fillOpen(12, 10);
|
|
368
|
+
case "grin":
|
|
369
|
+
return fillOpen(16, 11);
|
|
370
|
+
case "yell":
|
|
371
|
+
return fillOpen(15, 20, true);
|
|
372
|
+
case "o":
|
|
373
|
+
return fillOpen(7, 12, true);
|
|
374
|
+
case "frown":
|
|
375
|
+
ctx.moveTo(x - 10, y + 6);
|
|
376
|
+
ctx.quadraticCurveTo(x, y - 3, x + 10, y + 6);
|
|
377
|
+
ctx.stroke();
|
|
378
|
+
return;
|
|
379
|
+
case "smirk":
|
|
380
|
+
ctx.moveTo(x - 10, y + 3);
|
|
381
|
+
ctx.quadraticCurveTo(x + 6, y + 5, x + 16, y - 5);
|
|
382
|
+
ctx.stroke();
|
|
383
|
+
return;
|
|
384
|
+
case "tongue":
|
|
385
|
+
ctx.moveTo(x - 12, y);
|
|
386
|
+
ctx.quadraticCurveTo(x, y + 8, x + 12, y);
|
|
387
|
+
ctx.stroke();
|
|
388
|
+
ellipse(ctx, x + 4, y + 7, 6.5, 7.5);
|
|
389
|
+
ctx.fillStyle = "#f27e9c";
|
|
390
|
+
ctx.fill();
|
|
391
|
+
ctx.stroke();
|
|
392
|
+
return;
|
|
393
|
+
default:
|
|
394
|
+
ctx.moveTo(x - 10, y + 2);
|
|
395
|
+
ctx.lineTo(x + 10, y + 2);
|
|
396
|
+
ctx.stroke();
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function blush(ctx, amount, style) {
|
|
400
|
+
const eff = style === "ikemen" ? amount * 0.25 : amount;
|
|
401
|
+
if (eff <= 0.05)
|
|
402
|
+
return;
|
|
403
|
+
for (const side of [-1, 1]) {
|
|
404
|
+
const x = W / 2 + side * (EYE_X + 10);
|
|
405
|
+
const y = EYE_Y + EYE_H * 0.62;
|
|
406
|
+
const glow = ctx.createRadialGradient(x, y, 2, x, y, 36);
|
|
407
|
+
glow.addColorStop(0, `rgba(255, 115, 148, ${0.52 * eff})`);
|
|
408
|
+
glow.addColorStop(0.6, `rgba(255, 140, 168, ${0.22 * eff})`);
|
|
409
|
+
glow.addColorStop(1, "rgba(255, 140, 168, 0)");
|
|
410
|
+
ctx.fillStyle = glow;
|
|
411
|
+
ctx.fillRect(x - 42, y - 28, 84, 56);
|
|
412
|
+
if (style === "anime" && eff > 0.35) {
|
|
413
|
+
ctx.fillStyle = `rgba(255, 255, 255, ${0.55 * eff})`;
|
|
414
|
+
ellipse(ctx, x + side * 6, y - 4, 4.2, 2.6, -side * 0.25);
|
|
415
|
+
ctx.fill();
|
|
416
|
+
ellipse(ctx, x + side * 14, y - 1, 2.2, 1.5);
|
|
417
|
+
ctx.fill();
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
function tears(ctx) {
|
|
422
|
+
for (const side of [-1, 1]) {
|
|
423
|
+
const x = W / 2 + side * (EYE_X - 8);
|
|
424
|
+
const y = EYE_Y + EYE_H * 0.45;
|
|
425
|
+
ctx.fillStyle = "rgba(140, 220, 255, 0.85)";
|
|
426
|
+
ctx.beginPath();
|
|
427
|
+
ctx.moveTo(x, y);
|
|
428
|
+
ctx.quadraticCurveTo(x + side * 9, y + 26, x, y + 40);
|
|
429
|
+
ctx.quadraticCurveTo(x - side * 7, y + 26, x, y);
|
|
430
|
+
ctx.fill();
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
function drawAnimeFace(ctx, face, iris, style = "anime") {
|
|
434
|
+
const eyeTint = iris ?? (style === "ikemen" ? "#3b6ef0" : "#7c52ff");
|
|
435
|
+
ctx.clearRect(0, 0, W, H);
|
|
436
|
+
const parts = animeFaceParts(face);
|
|
437
|
+
blush(ctx, parts.blush, style);
|
|
438
|
+
for (const side of [-1, 1]) {
|
|
439
|
+
eye(ctx, side, parts, eyeTint, style);
|
|
440
|
+
brow(ctx, side, parts.brows, style);
|
|
441
|
+
}
|
|
442
|
+
nose(ctx, style);
|
|
443
|
+
if (parts.tears)
|
|
444
|
+
tears(ctx);
|
|
445
|
+
mouth(ctx, parts.mouth, style);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
export { ANIME_FACE_SIZE, ANIME_FACE_UV, animeFaceParts, ANIME_EYE_LINE, drawAnimeFace };
|