@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
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
// src/body-presets.ts
|
|
2
|
+
var BODY_PRESETS = {
|
|
3
|
+
round: { name: "Round", shape: "plup", body: { figure: 0, headSize: 1 } },
|
|
4
|
+
curvy: {
|
|
5
|
+
name: "Curvy",
|
|
6
|
+
shape: "plup",
|
|
7
|
+
body: {
|
|
8
|
+
figure: 1,
|
|
9
|
+
headSize: 0.78,
|
|
10
|
+
shoulders: 0.86,
|
|
11
|
+
bust: 0.9,
|
|
12
|
+
waist: 0.54,
|
|
13
|
+
hips: 1.4,
|
|
14
|
+
legLength: 2.35,
|
|
15
|
+
armLength: 1.35,
|
|
16
|
+
muscle: 0.82
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
glam: {
|
|
20
|
+
name: "Hourglass",
|
|
21
|
+
shape: "plup",
|
|
22
|
+
body: {
|
|
23
|
+
figure: 1,
|
|
24
|
+
headSize: 0.74,
|
|
25
|
+
shoulders: 0.84,
|
|
26
|
+
bust: 1.32,
|
|
27
|
+
waist: 0.48,
|
|
28
|
+
hips: 1.54,
|
|
29
|
+
legLength: 2.55,
|
|
30
|
+
armLength: 1.38,
|
|
31
|
+
muscle: 0.8
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
ikemen: {
|
|
35
|
+
name: "Ikemen",
|
|
36
|
+
shape: "plup",
|
|
37
|
+
body: {
|
|
38
|
+
figure: 1,
|
|
39
|
+
headSize: 0.72,
|
|
40
|
+
shoulders: 1.28,
|
|
41
|
+
bust: 0,
|
|
42
|
+
waist: 0.74,
|
|
43
|
+
hips: 0.92,
|
|
44
|
+
legLength: 2.6,
|
|
45
|
+
armLength: 1.48,
|
|
46
|
+
muscle: 1.22
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
muscular: {
|
|
50
|
+
name: "Muscular",
|
|
51
|
+
shape: "plup",
|
|
52
|
+
body: {
|
|
53
|
+
figure: 1,
|
|
54
|
+
headSize: 0.7,
|
|
55
|
+
shoulders: 1.56,
|
|
56
|
+
bust: 0,
|
|
57
|
+
waist: 0.72,
|
|
58
|
+
hips: 0.96,
|
|
59
|
+
legLength: 2.25,
|
|
60
|
+
armLength: 1.52,
|
|
61
|
+
muscle: 2.15
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"tall-slim": {
|
|
65
|
+
name: "Tall & Slim",
|
|
66
|
+
shape: "plup",
|
|
67
|
+
body: {
|
|
68
|
+
figure: 1,
|
|
69
|
+
headSize: 0.76,
|
|
70
|
+
shoulders: 0.9,
|
|
71
|
+
bust: 0.28,
|
|
72
|
+
waist: 0.66,
|
|
73
|
+
hips: 0.98,
|
|
74
|
+
legLength: 2.5,
|
|
75
|
+
armLength: 1.38,
|
|
76
|
+
muscle: 0.8
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
athletic: {
|
|
80
|
+
name: "Athletic",
|
|
81
|
+
shape: "plup",
|
|
82
|
+
body: {
|
|
83
|
+
figure: 1,
|
|
84
|
+
headSize: 0.75,
|
|
85
|
+
shoulders: 1.32,
|
|
86
|
+
bust: 0.12,
|
|
87
|
+
waist: 0.74,
|
|
88
|
+
hips: 1,
|
|
89
|
+
legLength: 2.3,
|
|
90
|
+
armLength: 1.44,
|
|
91
|
+
muscle: 1.55
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
chibi: {
|
|
95
|
+
name: "Chibi",
|
|
96
|
+
shape: "plup",
|
|
97
|
+
body: {
|
|
98
|
+
figure: 1,
|
|
99
|
+
headSize: 1.16,
|
|
100
|
+
shoulders: 0.78,
|
|
101
|
+
bust: 0.15,
|
|
102
|
+
waist: 0.84,
|
|
103
|
+
hips: 1.06,
|
|
104
|
+
legLength: 1.25,
|
|
105
|
+
armLength: 0.92,
|
|
106
|
+
muscle: 0.82
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
chubby: {
|
|
110
|
+
name: "Chubby",
|
|
111
|
+
shape: "wide",
|
|
112
|
+
body: {
|
|
113
|
+
figure: 0,
|
|
114
|
+
headSize: 1,
|
|
115
|
+
shoulders: 1,
|
|
116
|
+
waist: 1.15,
|
|
117
|
+
hips: 1.25,
|
|
118
|
+
legLength: 1,
|
|
119
|
+
armLength: 1,
|
|
120
|
+
muscle: 1.2
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
tiny: { name: "Tiny", shape: "mini", body: { figure: 0, headSize: 1 } },
|
|
124
|
+
bean: { name: "Bean", shape: "bean", body: { figure: 0, headSize: 1, legLength: 1.3 } }
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/emote.ts
|
|
128
|
+
var EMOTES = [
|
|
129
|
+
{
|
|
130
|
+
id: "emote-ngakak",
|
|
131
|
+
label: "Ngakak",
|
|
132
|
+
glyph: "(≧▽≦)",
|
|
133
|
+
face: "teriak",
|
|
134
|
+
clip: "laugh",
|
|
135
|
+
sigmaPrice: 0
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
id: "emote-semangat",
|
|
139
|
+
label: "Semangat",
|
|
140
|
+
glyph: "٩(ˊᗜˋ)و",
|
|
141
|
+
face: "yell",
|
|
142
|
+
clip: "cheer",
|
|
143
|
+
sigmaPrice: 0
|
|
144
|
+
},
|
|
145
|
+
{ id: "emote-keren", label: "Keren", glyph: "(⌐■_■)", face: "cool", clip: "pose", sigmaPrice: 0 },
|
|
146
|
+
{
|
|
147
|
+
id: "emote-marah",
|
|
148
|
+
label: "Marah",
|
|
149
|
+
glyph: "(╬ Ò﹏Ó)",
|
|
150
|
+
face: "rage",
|
|
151
|
+
clip: "rage",
|
|
152
|
+
sigmaPrice: 0
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
id: "emote-nangis",
|
|
156
|
+
label: "Nangis",
|
|
157
|
+
glyph: "(╥﹏╥)",
|
|
158
|
+
face: "cry",
|
|
159
|
+
clip: "sob",
|
|
160
|
+
sigmaPrice: 0
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
id: "emote-kaget",
|
|
164
|
+
label: "Kaget",
|
|
165
|
+
glyph: "(⊙_⊙)",
|
|
166
|
+
face: "shock",
|
|
167
|
+
clip: "recoil",
|
|
168
|
+
sigmaPrice: 0
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
id: "emote-suka",
|
|
172
|
+
label: "Suka",
|
|
173
|
+
glyph: "(♡˙︶˙♡)",
|
|
174
|
+
face: "sparkle",
|
|
175
|
+
clip: "cheer",
|
|
176
|
+
sigmaPrice: 0
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
id: "emote-mantap",
|
|
180
|
+
label: "Mantap",
|
|
181
|
+
glyph: "(•̀ᴗ•́)و",
|
|
182
|
+
face: "smug",
|
|
183
|
+
clip: "cheer",
|
|
184
|
+
sigmaPrice: 0
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
id: "emote-meledek",
|
|
188
|
+
label: "Meledek",
|
|
189
|
+
glyph: "(^_-)",
|
|
190
|
+
face: "tongue",
|
|
191
|
+
clip: "wave",
|
|
192
|
+
sigmaPrice: 15
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
id: "emote-ide",
|
|
196
|
+
label: "Ide Cemerlang",
|
|
197
|
+
glyph: "(!_!)",
|
|
198
|
+
face: "idea",
|
|
199
|
+
clip: "jump",
|
|
200
|
+
sigmaPrice: 20
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
id: "emote-licik",
|
|
204
|
+
label: "Licik",
|
|
205
|
+
glyph: "(¬‿¬)",
|
|
206
|
+
face: "licik",
|
|
207
|
+
clip: "sneak",
|
|
208
|
+
sigmaPrice: 25
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
id: "emote-tewas",
|
|
212
|
+
label: "Tewas",
|
|
213
|
+
glyph: "(x_x)",
|
|
214
|
+
face: "dead",
|
|
215
|
+
clip: "collapse",
|
|
216
|
+
sigmaPrice: 30
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
id: "emote-bintang",
|
|
220
|
+
label: "Mata Bintang",
|
|
221
|
+
glyph: "(*_*)",
|
|
222
|
+
face: "stars",
|
|
223
|
+
clip: "dance",
|
|
224
|
+
sigmaPrice: 40
|
|
225
|
+
},
|
|
226
|
+
{ id: "emote-aduh", label: "Aduh", glyph: "(>_<)", face: "pain", clip: "recoil", sigmaPrice: 50 },
|
|
227
|
+
{
|
|
228
|
+
id: "emote-serius",
|
|
229
|
+
label: "Serius Banget",
|
|
230
|
+
glyph: "(-_-)",
|
|
231
|
+
face: "serious",
|
|
232
|
+
clip: "nod",
|
|
233
|
+
sigmaPrice: 60
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
id: "emote-brazil-funk",
|
|
237
|
+
label: "Brazil Funk",
|
|
238
|
+
glyph: "♪(┌・。・)┌",
|
|
239
|
+
face: "cool",
|
|
240
|
+
clip: "brazil-funk",
|
|
241
|
+
sigmaPrice: 25
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
id: "emote-pacu-jalur",
|
|
245
|
+
label: "Pacu Jalur",
|
|
246
|
+
glyph: "ᕙ(•̀ᴗ•́)ᕗ",
|
|
247
|
+
face: "smug",
|
|
248
|
+
clip: "pacu-jalur",
|
|
249
|
+
sigmaPrice: 20
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
id: "emote-velocity",
|
|
253
|
+
label: "Jedag Jedug",
|
|
254
|
+
glyph: "✧(•̀ᴗ•́)✧",
|
|
255
|
+
face: "stars",
|
|
256
|
+
clip: "velocity",
|
|
257
|
+
sigmaPrice: 35
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
id: "emote-griddy",
|
|
261
|
+
label: "Griddy",
|
|
262
|
+
glyph: "(⌐■_■)ノ",
|
|
263
|
+
face: "smirk",
|
|
264
|
+
clip: "griddy",
|
|
265
|
+
sigmaPrice: 45
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
id: "emote-floss",
|
|
269
|
+
label: "Floss",
|
|
270
|
+
glyph: "ヾ(•̀_•́)ノ",
|
|
271
|
+
face: "sparkle",
|
|
272
|
+
clip: "floss",
|
|
273
|
+
sigmaPrice: 40
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
id: "emote-caramel",
|
|
277
|
+
label: "Idol Bounce",
|
|
278
|
+
glyph: "(♡˙︶˙♡)♪",
|
|
279
|
+
face: "sparkle",
|
|
280
|
+
clip: "caramel",
|
|
281
|
+
sigmaPrice: 55
|
|
282
|
+
}
|
|
283
|
+
];
|
|
284
|
+
function emoteOf(name) {
|
|
285
|
+
const id = name.startsWith("emote-") ? name : `emote-${name}`;
|
|
286
|
+
return EMOTES.find((emote) => emote.id === id);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// src/ragdoll.ts
|
|
290
|
+
var RAGDOLL_JOINTS = ["armL", "armR", "legL", "legR"];
|
|
291
|
+
var spring = () => ({ at: { x: 0, z: 0 }, speed: { x: 0, z: 0 } });
|
|
292
|
+
function pull(s, target, stiffness, damping, dt) {
|
|
293
|
+
for (const axis of ["x", "z"]) {
|
|
294
|
+
const force = (target[axis] - s.at[axis]) * stiffness - s.speed[axis] * damping;
|
|
295
|
+
s.speed[axis] += force * dt;
|
|
296
|
+
s.at[axis] += s.speed[axis] * dt;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
var TUNE = {
|
|
300
|
+
wobbly: { joint: [70, 7], body: [45, 6.5], kick: 0.09 },
|
|
301
|
+
limp: { joint: [18, 2.6] },
|
|
302
|
+
recover: { joint: [90, 19], body: [40, 12.6] },
|
|
303
|
+
gravity: 9.8,
|
|
304
|
+
topple: 14,
|
|
305
|
+
fallAt: 0.95,
|
|
306
|
+
lying: 1.45,
|
|
307
|
+
bounce: 0.32,
|
|
308
|
+
friction: 5,
|
|
309
|
+
getUp: 1.8
|
|
310
|
+
};
|
|
311
|
+
function createRagdoll(initial = "off", radius = 0.5) {
|
|
312
|
+
let mode = initial;
|
|
313
|
+
let after = initial === "limp" ? "off" : initial;
|
|
314
|
+
const joints = Object.fromEntries(RAGDOLL_JOINTS.map((name) => [name, spring()]));
|
|
315
|
+
const body = spring();
|
|
316
|
+
let lift = 0;
|
|
317
|
+
let liftSpeed = 0;
|
|
318
|
+
const offset = { x: 0, z: 0 };
|
|
319
|
+
const slide = { x: 0, z: 0 };
|
|
320
|
+
let fallen = 0;
|
|
321
|
+
let rising = false;
|
|
322
|
+
let fresh = true;
|
|
323
|
+
let lastVelocity = { x: 0, z: 0 };
|
|
324
|
+
const flop = {
|
|
325
|
+
armL: { x: -0.4, z: -1.25 },
|
|
326
|
+
armR: { x: 0.3, z: 1.1 },
|
|
327
|
+
legL: { x: 0.5, z: -0.35 },
|
|
328
|
+
legR: { x: -0.2, z: 0.45 }
|
|
329
|
+
};
|
|
330
|
+
const fall = () => {
|
|
331
|
+
if (mode === "limp")
|
|
332
|
+
return;
|
|
333
|
+
after = mode;
|
|
334
|
+
mode = "limp";
|
|
335
|
+
fallen = 0;
|
|
336
|
+
};
|
|
337
|
+
return {
|
|
338
|
+
mode: () => mode,
|
|
339
|
+
set(next) {
|
|
340
|
+
if (next === "limp") {
|
|
341
|
+
fall();
|
|
342
|
+
if (Math.hypot(body.speed.x, body.speed.z) < 0.5)
|
|
343
|
+
body.speed.x -= 1.2;
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
after = next;
|
|
347
|
+
if (mode !== "limp")
|
|
348
|
+
mode = next;
|
|
349
|
+
else if (next === "off") {
|
|
350
|
+
mode = "off";
|
|
351
|
+
rising = true;
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
push(x, y, z) {
|
|
355
|
+
body.speed.x += z * 1.6;
|
|
356
|
+
body.speed.z -= x * 1.6;
|
|
357
|
+
slide.x += x * 0.6;
|
|
358
|
+
slide.z += z * 0.6;
|
|
359
|
+
liftSpeed += Math.max(0, y);
|
|
360
|
+
for (const name of RAGDOLL_JOINTS) {
|
|
361
|
+
joints[name].speed.x -= z * 4;
|
|
362
|
+
joints[name].speed.z += x * 4;
|
|
363
|
+
}
|
|
364
|
+
if (mode === "off")
|
|
365
|
+
after = "off";
|
|
366
|
+
if (Math.hypot(x, z) > 2.5 || y > 2.5 || mode === "limp")
|
|
367
|
+
fall();
|
|
368
|
+
},
|
|
369
|
+
step(dt, input) {
|
|
370
|
+
dt = Math.min(dt, 1 / 20);
|
|
371
|
+
if (fresh) {
|
|
372
|
+
for (const name of RAGDOLL_JOINTS)
|
|
373
|
+
joints[name].at = { ...input.joints[name] };
|
|
374
|
+
body.at = { ...input.body };
|
|
375
|
+
lift = input.lift;
|
|
376
|
+
fresh = false;
|
|
377
|
+
}
|
|
378
|
+
const accel = {
|
|
379
|
+
x: (input.velocity.x - lastVelocity.x) / Math.max(dt, 0.001),
|
|
380
|
+
z: (input.velocity.z - lastVelocity.z) / Math.max(dt, 0.001)
|
|
381
|
+
};
|
|
382
|
+
lastVelocity = { ...input.velocity };
|
|
383
|
+
const clampAccel = (v) => Math.max(-30, Math.min(30, v));
|
|
384
|
+
accel.x = clampAccel(accel.x);
|
|
385
|
+
accel.z = clampAccel(accel.z);
|
|
386
|
+
if (mode === "limp") {
|
|
387
|
+
fallen += dt;
|
|
388
|
+
const lean = Math.hypot(body.at.x, body.at.z);
|
|
389
|
+
const dir = lean > 0.001 ? { x: body.at.x / lean, z: body.at.z / lean } : { x: -Math.sign(body.speed.x || 1), z: 0 };
|
|
390
|
+
const torque = TUNE.topple * Math.sin(Math.min(lean, Math.PI / 2) + 0.05);
|
|
391
|
+
body.speed.x += dir.x * torque * dt - body.speed.x * 0.6 * dt;
|
|
392
|
+
body.speed.z += dir.z * torque * dt - body.speed.z * 0.6 * dt;
|
|
393
|
+
body.at.x += body.speed.x * dt;
|
|
394
|
+
body.at.z += body.speed.z * dt;
|
|
395
|
+
const next = Math.hypot(body.at.x, body.at.z);
|
|
396
|
+
if (next > TUNE.lying) {
|
|
397
|
+
const k2 = TUNE.lying / next;
|
|
398
|
+
body.at.x *= k2;
|
|
399
|
+
body.at.z *= k2;
|
|
400
|
+
const into = body.speed.x * dir.x + body.speed.z * dir.z;
|
|
401
|
+
if (into > 0) {
|
|
402
|
+
body.speed.x -= (1 + TUNE.bounce) * into * dir.x;
|
|
403
|
+
body.speed.z -= (1 + TUNE.bounce) * into * dir.z;
|
|
404
|
+
for (const name of RAGDOLL_JOINTS) {
|
|
405
|
+
joints[name].speed.x += into * flop[name].x * 2.2;
|
|
406
|
+
joints[name].speed.z += into * flop[name].z * 2.2;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
liftSpeed -= TUNE.gravity * dt;
|
|
411
|
+
lift += liftSpeed * dt;
|
|
412
|
+
const floor = radius * Math.sin(Math.min(Math.hypot(body.at.x, body.at.z), Math.PI / 2));
|
|
413
|
+
if (lift < floor) {
|
|
414
|
+
lift = floor;
|
|
415
|
+
liftSpeed = Math.max(0, -liftSpeed * TUNE.bounce);
|
|
416
|
+
slide.x -= slide.x * TUNE.friction * dt;
|
|
417
|
+
slide.z -= slide.z * TUNE.friction * dt;
|
|
418
|
+
}
|
|
419
|
+
offset.x += slide.x * dt;
|
|
420
|
+
offset.z += slide.z * dt;
|
|
421
|
+
const [k, c] = TUNE.limp.joint;
|
|
422
|
+
for (const name of RAGDOLL_JOINTS) {
|
|
423
|
+
const target = {
|
|
424
|
+
x: -body.at.x * 0.6 + flop[name].x,
|
|
425
|
+
z: -body.at.z * 0.6 + flop[name].z
|
|
426
|
+
};
|
|
427
|
+
pull(joints[name], target, k, c, dt);
|
|
428
|
+
}
|
|
429
|
+
if (after === "wobbly" && fallen > TUNE.getUp) {
|
|
430
|
+
mode = "wobbly";
|
|
431
|
+
rising = true;
|
|
432
|
+
}
|
|
433
|
+
return output(true);
|
|
434
|
+
}
|
|
435
|
+
const wobbly = mode === "wobbly" && !rising;
|
|
436
|
+
if (rising && Math.hypot(body.at.x - input.body.x, body.at.z - input.body.z) < 0.15)
|
|
437
|
+
rising = false;
|
|
438
|
+
const [jk, jc] = wobbly ? TUNE.wobbly.joint : TUNE.recover.joint;
|
|
439
|
+
const [bk, bc] = wobbly ? TUNE.wobbly.body : TUNE.recover.body;
|
|
440
|
+
const kick = wobbly ? TUNE.wobbly.kick : 0;
|
|
441
|
+
for (const name of RAGDOLL_JOINTS) {
|
|
442
|
+
joints[name].speed.x -= accel.z * kick * 3 * dt * 10;
|
|
443
|
+
joints[name].speed.z += accel.x * kick * 3 * dt * 10;
|
|
444
|
+
pull(joints[name], input.joints[name], jk, jc, dt);
|
|
445
|
+
}
|
|
446
|
+
body.speed.x -= accel.z * kick * dt * 10;
|
|
447
|
+
body.speed.z += accel.x * kick * dt * 10;
|
|
448
|
+
pull(body, input.body, bk, bc, dt);
|
|
449
|
+
lift += (input.lift - lift) * Math.min(1, dt * 6);
|
|
450
|
+
liftSpeed = 0;
|
|
451
|
+
offset.x -= offset.x * Math.min(1, dt * 3);
|
|
452
|
+
offset.z -= offset.z * Math.min(1, dt * 3);
|
|
453
|
+
slide.x = slide.z = 0;
|
|
454
|
+
if (wobbly && Math.hypot(body.at.x - input.body.x, body.at.z - input.body.z) > TUNE.fallAt)
|
|
455
|
+
fall();
|
|
456
|
+
if (mode === "off" && settled(input))
|
|
457
|
+
return passthrough(input);
|
|
458
|
+
return output(false);
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
function settled(input) {
|
|
462
|
+
const close = (s, t) => Math.abs(s.at.x - t.x) + Math.abs(s.at.z - t.z) < 0.01 && Math.abs(s.speed.x) + Math.abs(s.speed.z) < 0.05;
|
|
463
|
+
return close(body, input.body) && RAGDOLL_JOINTS.every((name) => close(joints[name], input.joints[name])) && Math.abs(offset.x) + Math.abs(offset.z) < 0.005;
|
|
464
|
+
}
|
|
465
|
+
function passthrough(input) {
|
|
466
|
+
for (const name of RAGDOLL_JOINTS) {
|
|
467
|
+
joints[name].at = { ...input.joints[name] };
|
|
468
|
+
joints[name].speed = { x: 0, z: 0 };
|
|
469
|
+
}
|
|
470
|
+
body.at = { ...input.body };
|
|
471
|
+
body.speed = { x: 0, z: 0 };
|
|
472
|
+
lift = input.lift;
|
|
473
|
+
offset.x = offset.z = 0;
|
|
474
|
+
return { ...input, joints: { ...input.joints }, offset: { x: 0, z: 0 }, down: false };
|
|
475
|
+
}
|
|
476
|
+
function output(down) {
|
|
477
|
+
return {
|
|
478
|
+
joints: Object.fromEntries(RAGDOLL_JOINTS.map((name) => [name, { ...joints[name].at }])),
|
|
479
|
+
body: { ...body.at },
|
|
480
|
+
lift,
|
|
481
|
+
offset: { ...offset },
|
|
482
|
+
down
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
export { BODY_PRESETS, EMOTES, emoteOf, RAGDOLL_JOINTS, createRagdoll };
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// src/blob.ts
|
|
2
|
+
import { SphereGeometry } from "three";
|
|
3
|
+
var BLOB_RADIUS = { x: 0.6, y: 0.56, z: 0.58 };
|
|
4
|
+
var BLOB_HEIGHT = BLOB_RADIUS.y * (1 + 0.62 + (1 - 0.62) * 0.3);
|
|
5
|
+
var ROUND = { shoulders: 1, waist: 1, hips: 1, bust: 0, muscle: 1, figure: 0 };
|
|
6
|
+
var bump = (at, centre, spread) => Math.exp(-(((at - centre) / spread) ** 2));
|
|
7
|
+
var clamp01 = (v) => Math.max(0, Math.min(1, v));
|
|
8
|
+
var smoothstep = (e0, e1, x) => {
|
|
9
|
+
const t = clamp01((x - e0) / (e1 - e0));
|
|
10
|
+
return t * t * (3 - 2 * t);
|
|
11
|
+
};
|
|
12
|
+
function silhouetteAt(unitY, silhouette = ROUND) {
|
|
13
|
+
const shoulders = bump(unitY, -0.2, 0.2);
|
|
14
|
+
const waist = bump(unitY, -0.42, 0.12);
|
|
15
|
+
const hips = bump(unitY, -0.58, 0.14);
|
|
16
|
+
const rest = 0.35;
|
|
17
|
+
return (rest + shoulders * silhouette.shoulders + waist * silhouette.waist + hips * silhouette.hips) / (rest + shoulders + waist + hips);
|
|
18
|
+
}
|
|
19
|
+
var BLOB_SEAT = BLOB_RADIUS.y * (0.62 + (1 - 0.62) * 0.3);
|
|
20
|
+
function blobRadiusAt(y, silhouette = ROUND) {
|
|
21
|
+
const unit = Math.max(-0.62, Math.min(1, (y - BLOB_SEAT) / BLOB_RADIUS.y));
|
|
22
|
+
return Math.sqrt(Math.max(0, 1 - unit * unit)) * (1 + 0.16 * -unit) * BLOB_RADIUS.x * silhouetteAt(unit, silhouette);
|
|
23
|
+
}
|
|
24
|
+
function buildBlobGeometry(silhouette = ROUND) {
|
|
25
|
+
const geometry = new SphereGeometry(1, 44, 30);
|
|
26
|
+
const position = geometry.attributes.position;
|
|
27
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
28
|
+
const bust = Math.max(0, silhouette.bust ?? 0);
|
|
29
|
+
for (let i = 0;i < position.count; i += 1) {
|
|
30
|
+
const ux = position.getX(i);
|
|
31
|
+
let y = position.getY(i);
|
|
32
|
+
const uz = position.getZ(i);
|
|
33
|
+
const spread = (1 + 0.16 * -y) * silhouetteAt(y, silhouette);
|
|
34
|
+
const rx = ux * spread * BLOB_RADIUS.x;
|
|
35
|
+
let rz = uz * spread * BLOB_RADIUS.z;
|
|
36
|
+
if (bust > 0 && uz > 0) {
|
|
37
|
+
const phi = Math.atan2(ux, uz);
|
|
38
|
+
const chestY = bump(y, -0.22, 0.18);
|
|
39
|
+
const twin = bump(Math.abs(phi), 0.38, 0.42);
|
|
40
|
+
rz += bust * 0.11 * chestY * twin * uz;
|
|
41
|
+
}
|
|
42
|
+
if (y < -0.62)
|
|
43
|
+
y = -0.62 + (y + 0.62) * 0.3;
|
|
44
|
+
position.setXYZ(i, rx, y * BLOB_RADIUS.y, rz);
|
|
45
|
+
minY = Math.min(minY, y * BLOB_RADIUS.y);
|
|
46
|
+
}
|
|
47
|
+
geometry.translate(0, -minY, 0);
|
|
48
|
+
geometry.computeBoundingBox();
|
|
49
|
+
geometry.computeVertexNormals();
|
|
50
|
+
return geometry;
|
|
51
|
+
}
|
|
52
|
+
var FIGURE_TORSO_MIN_Y = 0.04;
|
|
53
|
+
var FIGURE_TORSO_MAX_Y = 0.84;
|
|
54
|
+
var FIGURE_TORSO_CENTER_Y = (FIGURE_TORSO_MIN_Y + FIGURE_TORSO_MAX_Y) / 2;
|
|
55
|
+
var FIGURE_TORSO_HALF_H = (FIGURE_TORSO_MAX_Y - FIGURE_TORSO_MIN_Y) / 2;
|
|
56
|
+
var FIGURE_HEAD_BASE_SCALE = 0.46;
|
|
57
|
+
var FIGURE_NECK_TOP_Y = 0.8;
|
|
58
|
+
var FIGURE_SHOULDER_Y = 0.64;
|
|
59
|
+
var FIGURE_HIP_Y = 0.17;
|
|
60
|
+
function figureHeadMetrics(headSize = 0.78) {
|
|
61
|
+
const scale = FIGURE_HEAD_BASE_SCALE * headSize;
|
|
62
|
+
const originY = FIGURE_NECK_TOP_Y - 0.03 * scale;
|
|
63
|
+
return { scale, originY, centerY: originY + BLOB_SEAT * scale };
|
|
64
|
+
}
|
|
65
|
+
var smin = (a, b, k) => {
|
|
66
|
+
const h = clamp01(0.5 + 0.5 * (b - a) / k);
|
|
67
|
+
return b * (1 - h) + a * h - k * h * (1 - h);
|
|
68
|
+
};
|
|
69
|
+
function figureTorsoPoint(y, phi, silhouette = ROUND) {
|
|
70
|
+
const u = Math.max(-0.985, Math.min(0.985, (y - FIGURE_TORSO_CENTER_Y) / FIGURE_TORSO_HALF_H));
|
|
71
|
+
const ux = Math.sin(phi);
|
|
72
|
+
const uz = Math.cos(phi);
|
|
73
|
+
const sh = silhouette.shoulders ?? 1;
|
|
74
|
+
const wa = silhouette.waist ?? 1;
|
|
75
|
+
const hi = silhouette.hips ?? 1;
|
|
76
|
+
const bust = Math.max(0, silhouette.bust ?? 0);
|
|
77
|
+
const muscle = Math.max(0.7, silhouette.muscle ?? 1);
|
|
78
|
+
const mExtra = Math.max(0, muscle - 1.05);
|
|
79
|
+
const neckT = smoothstep(0.68, 0.92, u);
|
|
80
|
+
const shoulderW = bump(u, 0.56, 0.28);
|
|
81
|
+
const ribW = bump(u, 0.28, 0.26);
|
|
82
|
+
const waistW = bump(u, -0.06, 0.25);
|
|
83
|
+
const hipW = bump(u, -0.58, 0.36);
|
|
84
|
+
const pelvisRound = u < -0.74 ? Math.sqrt(clamp01((1 + u) / 0.26)) : 1;
|
|
85
|
+
const neckRx = 0.068 + mExtra * 0.036;
|
|
86
|
+
const shoulderRx = 0.205 * sh + mExtra * 0.04;
|
|
87
|
+
const ribRx = 0.165 * (0.52 + 0.48 * sh) + mExtra * 0.025;
|
|
88
|
+
const waistRx = 0.175 * wa;
|
|
89
|
+
const hipRx = 0.205 * hi;
|
|
90
|
+
const wSum = shoulderW + ribW + waistW + hipW + 0.08;
|
|
91
|
+
let rx = (shoulderW * shoulderRx + ribW * ribRx + waistW * waistRx + hipW * hipRx + 0.08 * 0.14) / wSum;
|
|
92
|
+
rx = rx * (1 - neckT) + neckRx * neckT;
|
|
93
|
+
rx *= pelvisRound;
|
|
94
|
+
const neckRz = 0.066 + mExtra * 0.024;
|
|
95
|
+
const shoulderRz = 0.13 + mExtra * 0.032;
|
|
96
|
+
const ribRz = 0.132 + mExtra * 0.024;
|
|
97
|
+
const waistRz = 0.122 * Math.min(1, wa * 0.88 + 0.1);
|
|
98
|
+
const hipRz = 0.155 * (0.5 + 0.5 * hi);
|
|
99
|
+
let rz = (shoulderW * shoulderRz + ribW * ribRz + waistW * waistRz + hipW * hipRz + 0.08 * 0.12) / wSum;
|
|
100
|
+
rz = rz * (1 - neckT) + neckRz * neckT;
|
|
101
|
+
rz *= pelvisRound;
|
|
102
|
+
let x = ux * rx;
|
|
103
|
+
let z = uz * rz;
|
|
104
|
+
if (bust > 0.01 && uz > -0.1) {
|
|
105
|
+
const domeR = 0.095 + Math.min(1.4, bust) * 0.038;
|
|
106
|
+
const cx = 0.082 + Math.min(1.4, bust) * 0.01;
|
|
107
|
+
const cy = FIGURE_TORSO_CENTER_Y + 0.34 * FIGURE_TORSO_HALF_H;
|
|
108
|
+
const cz = 0.075 + Math.min(1.4, bust) * 0.024;
|
|
109
|
+
const bx = Math.abs(x) - cx;
|
|
110
|
+
const by = (y - cy) * 1.05;
|
|
111
|
+
const d2 = bx * bx + by * by;
|
|
112
|
+
if (d2 < domeR * domeR * 1.45) {
|
|
113
|
+
const inner = Math.max(0, domeR * domeR - d2);
|
|
114
|
+
const sphereZ = cz + Math.sqrt(inner) * (0.95 + Math.min(1.4, bust) * 0.25);
|
|
115
|
+
const edgeFade = smoothstep(domeR * 1.2, domeR * 0.45, Math.sqrt(d2)) * smoothstep(-0.05, 0.28, uz);
|
|
116
|
+
const targetZ = -smin(-z, -sphereZ, 0.035);
|
|
117
|
+
z = z + (targetZ - z) * edgeFade;
|
|
118
|
+
if (Math.abs(x) > cx * 0.5) {
|
|
119
|
+
x += Math.sign(x) * 0.022 * Math.min(1.4, bust) * edgeFade;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (mExtra > 0.05) {
|
|
124
|
+
if (uz > 0) {
|
|
125
|
+
const pecVert = bump(u, 0.42, 0.22);
|
|
126
|
+
const pecWidth = Math.max(0, uz) ** 0.7 * (1 - 0.25 * bump(Math.abs(phi), 0, 0.16));
|
|
127
|
+
z += mExtra * 0.068 * pecVert * pecWidth;
|
|
128
|
+
const coreVert = bump(u, 0, 0.24);
|
|
129
|
+
z += mExtra * 0.02 * coreVert * Math.max(0, uz) ** 0.8;
|
|
130
|
+
}
|
|
131
|
+
const latVert = bump(u, 0.42, 0.25);
|
|
132
|
+
x += Math.sign(ux) * mExtra * 0.038 * latVert * Math.abs(ux);
|
|
133
|
+
}
|
|
134
|
+
const hipExtra = Math.max(0, hi - 0.94);
|
|
135
|
+
if (hipExtra > 0.01 && uz < 0.1) {
|
|
136
|
+
const gluteVert = bump(u, -0.58, 0.3);
|
|
137
|
+
const backFactor = smoothstep(0.1, -0.45, uz);
|
|
138
|
+
const gluteTwin = 0.65 + 0.35 * bump(Math.abs(Math.PI - Math.abs(phi)), 0.42, 0.52);
|
|
139
|
+
z -= hipExtra * 0.115 * gluteVert * gluteTwin * backFactor * pelvisRound;
|
|
140
|
+
}
|
|
141
|
+
return { x, z };
|
|
142
|
+
}
|
|
143
|
+
function figureTorsoRadiusAt(y, silhouette = ROUND, phi = Math.PI / 2) {
|
|
144
|
+
const p = figureTorsoPoint(y, phi, silhouette);
|
|
145
|
+
return Math.hypot(p.x, p.z);
|
|
146
|
+
}
|
|
147
|
+
function buildFigureHeadGeometry() {
|
|
148
|
+
const geometry = new SphereGeometry(1, 48, 32);
|
|
149
|
+
const position = geometry.attributes.position;
|
|
150
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
151
|
+
for (let i = 0;i < position.count; i += 1) {
|
|
152
|
+
const ux = position.getX(i);
|
|
153
|
+
let y = position.getY(i);
|
|
154
|
+
const uz = position.getZ(i);
|
|
155
|
+
const cheek = 1 + 0.035 * bump(y, -0.22, 0.32);
|
|
156
|
+
const chinTaper = y < -0.2 ? 1 - 0.28 * clamp01((-0.2 - y) / 0.8) ** 1.3 : 1;
|
|
157
|
+
const chinForward = y < -0.35 && uz > 0 ? 0.035 * clamp01((-0.35 - y) / 0.65) * uz : 0;
|
|
158
|
+
if (y < -0.82)
|
|
159
|
+
y = -0.82 + (y + 0.82) * 0.5;
|
|
160
|
+
const rx = ux * cheek * chinTaper * 0.54;
|
|
161
|
+
const ry = y * 0.59;
|
|
162
|
+
const rz = (uz * cheek * chinTaper + chinForward) * 0.54;
|
|
163
|
+
position.setXYZ(i, rx, ry, rz);
|
|
164
|
+
minY = Math.min(minY, ry);
|
|
165
|
+
}
|
|
166
|
+
geometry.translate(0, -minY, 0);
|
|
167
|
+
geometry.computeBoundingBox();
|
|
168
|
+
geometry.computeVertexNormals();
|
|
169
|
+
return geometry;
|
|
170
|
+
}
|
|
171
|
+
function figureHeadRadiusAt(y) {
|
|
172
|
+
const minY = (-0.82 + -0.18 * 0.5) * 0.59;
|
|
173
|
+
const rawY = y + minY;
|
|
174
|
+
const unit = Math.max(-0.98, Math.min(0.995, rawY / 0.59));
|
|
175
|
+
const cheek = 1 + 0.035 * bump(unit, -0.22, 0.32);
|
|
176
|
+
const chinTaper = unit < -0.2 ? 1 - 0.28 * clamp01((-0.2 - unit) / 0.8) ** 1.3 : 1;
|
|
177
|
+
return Math.sqrt(Math.max(0.001, 1 - unit * unit)) * cheek * chinTaper * 0.54;
|
|
178
|
+
}
|
|
179
|
+
function buildFigureTorsoGeometry(silhouette = ROUND) {
|
|
180
|
+
const geometry = new SphereGeometry(1, 56, 44);
|
|
181
|
+
const position = geometry.attributes.position;
|
|
182
|
+
for (let i = 0;i < position.count; i += 1) {
|
|
183
|
+
const ux = position.getX(i);
|
|
184
|
+
const uy = position.getY(i);
|
|
185
|
+
const uz = position.getZ(i);
|
|
186
|
+
const y = FIGURE_TORSO_CENTER_Y + uy * FIGURE_TORSO_HALF_H;
|
|
187
|
+
const phi = Math.atan2(ux, uz);
|
|
188
|
+
const pt = figureTorsoPoint(y, phi, silhouette);
|
|
189
|
+
position.setXYZ(i, pt.x, y, pt.z);
|
|
190
|
+
}
|
|
191
|
+
geometry.computeBoundingBox();
|
|
192
|
+
geometry.computeVertexNormals();
|
|
193
|
+
return geometry;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export { BLOB_RADIUS, BLOB_HEIGHT, ROUND, silhouetteAt, BLOB_SEAT, blobRadiusAt, buildBlobGeometry, FIGURE_TORSO_MIN_Y, FIGURE_TORSO_MAX_Y, FIGURE_TORSO_CENTER_Y, FIGURE_TORSO_HALF_H, FIGURE_HEAD_BASE_SCALE, FIGURE_NECK_TOP_Y, FIGURE_SHOULDER_Y, FIGURE_HIP_Y, figureHeadMetrics, figureTorsoPoint, figureTorsoRadiusAt, buildFigureHeadGeometry, figureHeadRadiusAt, buildFigureTorsoGeometry };
|