@klex/mascot 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/LICENSE-TWEMOJI.txt +393 -0
- package/README.md +160 -2
- package/package.json +67 -3
- package/src/activity.ts +144 -0
- package/src/calling.ts +85 -0
- package/src/emotes.ts +582 -0
- package/src/extras.css +50 -0
- package/src/extras.tsx +241 -0
- package/src/eyes.tsx +179 -0
- package/src/gaze.ts +48 -0
- package/src/geometry.ts +103 -0
- package/src/glide.ts +848 -0
- package/src/ground-grid.tsx +51 -0
- package/src/idle.ts +61 -0
- package/src/index.ts +32 -0
- package/src/klex.tsx +460 -0
- package/src/laptop.tsx +41 -0
- package/src/name-tag.css +26 -0
- package/src/observe-visibility.ts +42 -0
- package/src/presets.ts +247 -0
- package/src/speech.css +21 -0
- package/src/speech.tsx +129 -0
- package/src/svg.ts +56 -0
- package/src/transitions.ts +5 -0
- package/src/working.ts +99 -0
package/src/emotes.ts
ADDED
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
import type { Extra } from './extras';
|
|
2
|
+
import type { Expression } from './eyes';
|
|
3
|
+
|
|
4
|
+
const LAND_RECOVERY_START = 0.3;
|
|
5
|
+
|
|
6
|
+
const BODY_ACTIONS = [
|
|
7
|
+
{ id: 'jump', name: 'Jump', duration: 1.05 },
|
|
8
|
+
{ id: 'shiver', name: 'Shiver', duration: 0.85 },
|
|
9
|
+
{ id: 'nod', name: 'Nod', duration: 0.9 },
|
|
10
|
+
{ id: 'squish', name: 'Squish', duration: 0.9 },
|
|
11
|
+
{ id: 'celebrate', name: 'Celebrate', duration: 2.5 },
|
|
12
|
+
{ id: 'startle', name: 'Startle', duration: 1.4 },
|
|
13
|
+
{ id: 'headshake', name: 'Shake head', duration: 1.15 },
|
|
14
|
+
{ id: 'bow', name: 'Bow', duration: 1.6 },
|
|
15
|
+
{ id: 'recoil', name: 'Recoil', duration: 1.35 },
|
|
16
|
+
{ id: 'puff', name: 'Puff up', duration: 1.5 },
|
|
17
|
+
{ id: 'slump', name: 'Slump', duration: 1.8 },
|
|
18
|
+
{ id: 'melt', name: 'Melt', duration: 2.5 },
|
|
19
|
+
{ id: 'pop', name: 'Pop', duration: 1.25 },
|
|
20
|
+
{ id: 'jelly', name: 'Jiggle', duration: 1.9 },
|
|
21
|
+
{ id: 'fall', name: 'Fall over', duration: 2.7 },
|
|
22
|
+
{ id: 'recover', name: 'Get back up', duration: 2.6 },
|
|
23
|
+
{ id: 'land', name: 'Land and get up', duration: 2.5 },
|
|
24
|
+
{ id: 'dance', name: 'Dance', duration: 2.4 },
|
|
25
|
+
{ id: 'spin', name: 'Spin', duration: 1.6 },
|
|
26
|
+
{ id: 'peek', name: 'Peek forward', duration: 1.8 },
|
|
27
|
+
{ id: 'hide', name: 'Hide', duration: 1.9 },
|
|
28
|
+
{ id: 'impatient', name: 'Rock impatiently', duration: 2 },
|
|
29
|
+
{ id: 'sulk', name: 'Turn away', duration: 1.9 },
|
|
30
|
+
] as const;
|
|
31
|
+
const EYE_ACTIONS = [
|
|
32
|
+
{ id: 'blink', name: 'Blink', duration: 0.35 },
|
|
33
|
+
{ id: 'slow-blink', name: 'Slow blink', duration: 1.5 },
|
|
34
|
+
{ id: 'wink', name: 'Wink', duration: 0.85 },
|
|
35
|
+
{ id: 'eye-roll', name: 'Roll eyes', duration: 2.1 },
|
|
36
|
+
{ id: 'glance', name: 'Look around', duration: 2.8 },
|
|
37
|
+
{ id: 'look-left', name: 'Look left', duration: 1.7 },
|
|
38
|
+
{ id: 'look-right', name: 'Look right', duration: 1.7 },
|
|
39
|
+
{ id: 'look-up', name: 'Look up', duration: 1.7 },
|
|
40
|
+
{ id: 'look-down', name: 'Look down', duration: 1.7 },
|
|
41
|
+
] as const;
|
|
42
|
+
type Gesture = (typeof BODY_ACTIONS | typeof EYE_ACTIONS)[number]['id'];
|
|
43
|
+
export type EmoteLook = { expression?: Expression; extra?: Extra };
|
|
44
|
+
type ReactionStep = EmoteLook & { gesture: Gesture; duration: number };
|
|
45
|
+
const REACTIONS = [
|
|
46
|
+
{
|
|
47
|
+
id: 'happy-nod',
|
|
48
|
+
name: 'Happy nod',
|
|
49
|
+
steps: [{ gesture: 'nod', duration: 0.9, expression: 'happy' }],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: 'hello',
|
|
53
|
+
name: 'Hello!',
|
|
54
|
+
steps: [
|
|
55
|
+
{ gesture: 'nod', duration: 2.2, expression: 'happy', extra: 'wave' },
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: 'huh',
|
|
60
|
+
name: 'Huh?',
|
|
61
|
+
steps: [
|
|
62
|
+
{
|
|
63
|
+
gesture: 'peek',
|
|
64
|
+
duration: 1.8,
|
|
65
|
+
expression: 'unsure',
|
|
66
|
+
extra: 'question',
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: 'okay',
|
|
72
|
+
name: 'Okay …',
|
|
73
|
+
steps: [{ gesture: 'nod', duration: 1.6, expression: 'skeptical' }],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: 'nope',
|
|
77
|
+
name: 'Nope.',
|
|
78
|
+
steps: [
|
|
79
|
+
{ gesture: 'headshake', duration: 1, expression: 'annoyed' },
|
|
80
|
+
{ gesture: 'sulk', duration: 1.3, expression: 'annoyed' },
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: 'oops',
|
|
85
|
+
name: 'Oops.',
|
|
86
|
+
steps: [
|
|
87
|
+
{
|
|
88
|
+
gesture: 'recoil',
|
|
89
|
+
duration: 0.65,
|
|
90
|
+
expression: 'surprised',
|
|
91
|
+
extra: 'sweat',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
gesture: 'slump',
|
|
95
|
+
duration: 1.3,
|
|
96
|
+
expression: 'embarrassed',
|
|
97
|
+
extra: 'sweat',
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: 'thanks',
|
|
103
|
+
name: 'Thanks!',
|
|
104
|
+
steps: [
|
|
105
|
+
{ gesture: 'bow', duration: 1.7, expression: 'happy', extra: 'blush' },
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: 'innocent',
|
|
110
|
+
name: "It wasn't me.",
|
|
111
|
+
steps: [
|
|
112
|
+
{
|
|
113
|
+
gesture: 'glance',
|
|
114
|
+
duration: 1.8,
|
|
115
|
+
expression: 'surprised',
|
|
116
|
+
extra: 'sweat',
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: 'finally',
|
|
122
|
+
name: 'Finally!',
|
|
123
|
+
steps: [
|
|
124
|
+
{ gesture: 'slump', duration: 1.1, expression: 'sleepy' },
|
|
125
|
+
{
|
|
126
|
+
gesture: 'celebrate',
|
|
127
|
+
duration: 2.3,
|
|
128
|
+
expression: 'happy',
|
|
129
|
+
extra: 'sparkles',
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
id: 'exhausted',
|
|
135
|
+
name: "I'm exhausted.",
|
|
136
|
+
steps: [{ gesture: 'melt', duration: 2.6, expression: 'x-eyes' }],
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: 'leave-me',
|
|
140
|
+
name: 'Leave me alone.',
|
|
141
|
+
steps: [
|
|
142
|
+
{ gesture: 'hide', duration: 2.1, expression: 'annoyed', extra: 'steam' },
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
id: 'look',
|
|
147
|
+
name: 'Look!',
|
|
148
|
+
steps: [
|
|
149
|
+
{ gesture: 'puff', duration: 0.8, expression: 'stars' },
|
|
150
|
+
{
|
|
151
|
+
gesture: 'jump',
|
|
152
|
+
duration: 1.05,
|
|
153
|
+
expression: 'stars',
|
|
154
|
+
extra: 'sparkles',
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
] as const satisfies readonly {
|
|
159
|
+
id: string;
|
|
160
|
+
name: string;
|
|
161
|
+
steps: readonly ReactionStep[];
|
|
162
|
+
}[];
|
|
163
|
+
|
|
164
|
+
export const EMOTE_CATEGORIES = [
|
|
165
|
+
{ id: 'body', name: 'Body' },
|
|
166
|
+
{ id: 'eyes', name: 'Eyes' },
|
|
167
|
+
{ id: 'reactions', name: 'Reactions' },
|
|
168
|
+
] as const;
|
|
169
|
+
export const EMOTES = [
|
|
170
|
+
...BODY_ACTIONS.map((action) => ({ ...action, category: 'body' as const })),
|
|
171
|
+
...EYE_ACTIONS.map((action) => ({ ...action, category: 'eyes' as const })),
|
|
172
|
+
...REACTIONS.map((action) => ({
|
|
173
|
+
...action,
|
|
174
|
+
category: 'reactions' as const,
|
|
175
|
+
duration: action.steps.reduce((sum, step) => sum + step.duration, 0),
|
|
176
|
+
})),
|
|
177
|
+
];
|
|
178
|
+
export type Emote = (typeof EMOTES)[number];
|
|
179
|
+
export const REST_EMOTE = {
|
|
180
|
+
lift: 0,
|
|
181
|
+
shake: 0,
|
|
182
|
+
compression: 0,
|
|
183
|
+
nod: 0,
|
|
184
|
+
headSway: 0,
|
|
185
|
+
headTilt: 0,
|
|
186
|
+
turn: 0,
|
|
187
|
+
hideEyes: 0,
|
|
188
|
+
melt: 0,
|
|
189
|
+
puff: 0,
|
|
190
|
+
wave: 0,
|
|
191
|
+
ripple: 0,
|
|
192
|
+
ripplePhase: 0,
|
|
193
|
+
roll: 0,
|
|
194
|
+
impact: 0,
|
|
195
|
+
lookX: 0,
|
|
196
|
+
lookY: 0,
|
|
197
|
+
gazeHeadX: 0,
|
|
198
|
+
gazeHeadY: 0,
|
|
199
|
+
blinkLeft: 0,
|
|
200
|
+
blinkRight: 0,
|
|
201
|
+
};
|
|
202
|
+
const clamp = (value: number) => Math.max(0, Math.min(1, value));
|
|
203
|
+
const smooth = (value: number) => {
|
|
204
|
+
const t = clamp(value);
|
|
205
|
+
return t * t * (3 - 2 * t);
|
|
206
|
+
};
|
|
207
|
+
const pulse = (t: number, attack = 0.3, release = 0.7) =>
|
|
208
|
+
smooth(t / attack) * (1 - smooth((t - release) / (1 - release)));
|
|
209
|
+
|
|
210
|
+
// The easing belongs to the arriving key. Sharp reactions accelerate into
|
|
211
|
+
// an impact; slower holds and returns make the action readable afterwards.
|
|
212
|
+
function track(
|
|
213
|
+
t: number,
|
|
214
|
+
keys: readonly (readonly [number, number, ('in' | 'out')?])[],
|
|
215
|
+
) {
|
|
216
|
+
let previous = keys[0] ?? [0, 0];
|
|
217
|
+
for (const next of keys.slice(1)) {
|
|
218
|
+
if (t <= next[0]) {
|
|
219
|
+
const u = clamp((t - previous[0]) / (next[0] - previous[0]));
|
|
220
|
+
const ease =
|
|
221
|
+
next[2] === 'in'
|
|
222
|
+
? u ** 3
|
|
223
|
+
: next[2] === 'out'
|
|
224
|
+
? 1 - (1 - u) ** 3
|
|
225
|
+
: smooth(u);
|
|
226
|
+
return previous[1] + (next[1] - previous[1]) * ease;
|
|
227
|
+
}
|
|
228
|
+
previous = next;
|
|
229
|
+
}
|
|
230
|
+
return previous[1];
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Time-based, reusable gestures. The rig anchors their deformation at the sole.
|
|
234
|
+
function gesturePose(kind: Gesture, t: number): typeof REST_EMOTE {
|
|
235
|
+
if (t < 0 || t >= 1 || (t === 0 && kind !== 'land')) return REST_EMOTE;
|
|
236
|
+
const e = Math.sin(Math.PI * t) ** 2;
|
|
237
|
+
const wave = Math.sin(t * Math.PI * 4);
|
|
238
|
+
switch (kind) {
|
|
239
|
+
case 'jump': {
|
|
240
|
+
const air = clamp((t - 0.2) / 0.56);
|
|
241
|
+
return {
|
|
242
|
+
...REST_EMOTE,
|
|
243
|
+
lift: 4 * 56 * air * (1 - air),
|
|
244
|
+
compression:
|
|
245
|
+
t < 0.2
|
|
246
|
+
? 0.22 * Math.sin((Math.PI * t) / 0.2)
|
|
247
|
+
: t < 0.76
|
|
248
|
+
? -0.09 * Math.sin(Math.PI * air)
|
|
249
|
+
: 0.18 * Math.sin((Math.PI * (t - 0.76)) / 0.24),
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
case 'celebrate': {
|
|
253
|
+
const hop = gesturePose('jump', (t * 3) % 1);
|
|
254
|
+
return { ...hop, lift: hop.lift * (t < 2 / 3 ? 0.5 : 1.15) };
|
|
255
|
+
}
|
|
256
|
+
case 'startle': {
|
|
257
|
+
const landing = pulse(clamp((t - 0.3) / 0.25), 0.18, 0.25);
|
|
258
|
+
return {
|
|
259
|
+
...REST_EMOTE,
|
|
260
|
+
// A reflex, not another voluntary jump with a long wind-up.
|
|
261
|
+
lift: track(t, [
|
|
262
|
+
[0, 0],
|
|
263
|
+
[0.07, 5, 'in'],
|
|
264
|
+
[0.18, 34, 'out'],
|
|
265
|
+
[0.32, 0, 'in'],
|
|
266
|
+
[1, 0],
|
|
267
|
+
]),
|
|
268
|
+
compression: track(t, [
|
|
269
|
+
[0, 0],
|
|
270
|
+
[0.07, -0.17, 'out'],
|
|
271
|
+
[0.27, -0.17],
|
|
272
|
+
[0.34, 0.22, 'out'],
|
|
273
|
+
[0.46, -0.04],
|
|
274
|
+
[0.62, 0],
|
|
275
|
+
[1, 0],
|
|
276
|
+
]),
|
|
277
|
+
headSway: -9 * pulse(t, 0.055, 0.58),
|
|
278
|
+
headTilt: -9 * pulse(t, 0.06, 0.58),
|
|
279
|
+
shake:
|
|
280
|
+
-3 * pulse(t, 0.12, 0.6) + 2 * landing * Math.sin(t * Math.PI * 30),
|
|
281
|
+
lookY: -1.5 * pulse(t, 0.08, 0.65),
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
case 'shiver':
|
|
285
|
+
return { ...REST_EMOTE, shake: 3.5 * e * Math.sin(t * Math.PI * 18) };
|
|
286
|
+
case 'nod':
|
|
287
|
+
return { ...REST_EMOTE, nod: e * wave };
|
|
288
|
+
case 'squish':
|
|
289
|
+
return { ...REST_EMOTE, compression: 0.28 * e };
|
|
290
|
+
case 'headshake':
|
|
291
|
+
return {
|
|
292
|
+
...REST_EMOTE,
|
|
293
|
+
headSway: 11 * e * Math.sin(t * Math.PI * 6),
|
|
294
|
+
headTilt: 4 * e * Math.sin(t * Math.PI * 6 - 0.3),
|
|
295
|
+
lookX: 1.5 * e * Math.sin(t * Math.PI * 6),
|
|
296
|
+
};
|
|
297
|
+
case 'bow':
|
|
298
|
+
return {
|
|
299
|
+
...REST_EMOTE,
|
|
300
|
+
nod: 2.8 * pulse(t),
|
|
301
|
+
compression: 0.12 * pulse(t),
|
|
302
|
+
lookY: 1.5 * e,
|
|
303
|
+
};
|
|
304
|
+
case 'recoil':
|
|
305
|
+
return {
|
|
306
|
+
...REST_EMOTE,
|
|
307
|
+
headSway: track(t, [
|
|
308
|
+
[0, 0],
|
|
309
|
+
[0.1, -18, 'out'],
|
|
310
|
+
[0.36, -18],
|
|
311
|
+
[0.68, 4, 'out'],
|
|
312
|
+
[0.85, -1.5],
|
|
313
|
+
[1, 0],
|
|
314
|
+
]),
|
|
315
|
+
headTilt: track(t, [
|
|
316
|
+
[0, 0],
|
|
317
|
+
[0.09, -14, 'out'],
|
|
318
|
+
[0.35, -14],
|
|
319
|
+
[0.7, 4],
|
|
320
|
+
[1, 0],
|
|
321
|
+
]),
|
|
322
|
+
shake: -4 * pulse(t, 0.22, 0.38),
|
|
323
|
+
compression: 0.09 * pulse(t, 0.24, 0.42),
|
|
324
|
+
lookX: 2 * pulse(t, 0.12, 0.6),
|
|
325
|
+
blinkLeft: 0.7 * pulse(clamp(t / 0.25), 0.24, 0.4),
|
|
326
|
+
blinkRight: 0.7 * pulse(clamp(t / 0.25), 0.24, 0.4),
|
|
327
|
+
};
|
|
328
|
+
case 'puff':
|
|
329
|
+
return { ...REST_EMOTE, puff: pulse(t), compression: -0.06 * e };
|
|
330
|
+
case 'slump':
|
|
331
|
+
return {
|
|
332
|
+
...REST_EMOTE,
|
|
333
|
+
compression: 0.4 * pulse(t, 0.45, 0.75),
|
|
334
|
+
nod: 0.7 * e,
|
|
335
|
+
lookY: 1.5 * e,
|
|
336
|
+
};
|
|
337
|
+
case 'melt':
|
|
338
|
+
return { ...REST_EMOTE, melt: pulse(t, 0.42, 0.72) };
|
|
339
|
+
case 'pop':
|
|
340
|
+
return {
|
|
341
|
+
...REST_EMOTE,
|
|
342
|
+
melt: track(t, [
|
|
343
|
+
[0, 0],
|
|
344
|
+
[0.2, 0.82],
|
|
345
|
+
[0.36, 0.82],
|
|
346
|
+
[0.49, 0, 'out'],
|
|
347
|
+
[1, 0],
|
|
348
|
+
]),
|
|
349
|
+
compression: track(t, [
|
|
350
|
+
[0, 0],
|
|
351
|
+
[0.3, 0.18],
|
|
352
|
+
[0.49, -0.2, 'out'],
|
|
353
|
+
[0.63, 0.17],
|
|
354
|
+
[0.77, -0.07],
|
|
355
|
+
[1, 0],
|
|
356
|
+
]),
|
|
357
|
+
blinkLeft: pulse(clamp(t / 0.52), 0.35, 0.68),
|
|
358
|
+
blinkRight: pulse(clamp(t / 0.52), 0.35, 0.68),
|
|
359
|
+
};
|
|
360
|
+
case 'jelly':
|
|
361
|
+
return {
|
|
362
|
+
...REST_EMOTE,
|
|
363
|
+
ripple: pulse(t, 0.12, 0.72),
|
|
364
|
+
ripplePhase: t * Math.PI * 4,
|
|
365
|
+
};
|
|
366
|
+
case 'fall':
|
|
367
|
+
return {
|
|
368
|
+
...REST_EMOTE,
|
|
369
|
+
roll: track(t, [
|
|
370
|
+
[0, 0],
|
|
371
|
+
[0.16, -12],
|
|
372
|
+
[0.28, 18],
|
|
373
|
+
[0.43, 108, 'in'],
|
|
374
|
+
[0.51, 94, 'out'],
|
|
375
|
+
[0.6, 103, 'in'],
|
|
376
|
+
[0.77, 103],
|
|
377
|
+
[0.94, -4],
|
|
378
|
+
[1, 0],
|
|
379
|
+
]),
|
|
380
|
+
headTilt: track(t, [
|
|
381
|
+
[0, 0],
|
|
382
|
+
[0.22, -12],
|
|
383
|
+
[0.4, 10],
|
|
384
|
+
[0.6, 0],
|
|
385
|
+
[1, 0],
|
|
386
|
+
]),
|
|
387
|
+
impact: track(t, [
|
|
388
|
+
[0, 0],
|
|
389
|
+
[0.42, 0],
|
|
390
|
+
[0.46, 0.28, 'out'],
|
|
391
|
+
[0.53, 0],
|
|
392
|
+
[0.61, 0.1],
|
|
393
|
+
[0.72, 0],
|
|
394
|
+
[1, 0],
|
|
395
|
+
]),
|
|
396
|
+
blinkLeft: pulse(clamp((t - 0.39) / 0.28), 0.16, 0.6),
|
|
397
|
+
blinkRight: pulse(clamp((t - 0.39) / 0.28), 0.16, 0.6),
|
|
398
|
+
};
|
|
399
|
+
case 'land':
|
|
400
|
+
return {
|
|
401
|
+
...REST_EMOTE,
|
|
402
|
+
roll: track(t, [
|
|
403
|
+
[0, 90],
|
|
404
|
+
[0.12, 103, 'in'],
|
|
405
|
+
[LAND_RECOVERY_START, 103],
|
|
406
|
+
[0.84, -10, 'out'],
|
|
407
|
+
[0.93, 5],
|
|
408
|
+
[1, 0],
|
|
409
|
+
]),
|
|
410
|
+
impact: track(t, [
|
|
411
|
+
[0, 0],
|
|
412
|
+
[0.025, 0.3, 'out'],
|
|
413
|
+
[0.13, 0],
|
|
414
|
+
[1, 0],
|
|
415
|
+
]),
|
|
416
|
+
headTilt: track(t, [
|
|
417
|
+
[0, 0],
|
|
418
|
+
[0.35, -8],
|
|
419
|
+
[0.6, -12],
|
|
420
|
+
[0.85, 6],
|
|
421
|
+
[1, 0],
|
|
422
|
+
]),
|
|
423
|
+
};
|
|
424
|
+
case 'recover':
|
|
425
|
+
return {
|
|
426
|
+
...REST_EMOTE,
|
|
427
|
+
roll: track(t, [
|
|
428
|
+
[0, 0],
|
|
429
|
+
[0.13, 103],
|
|
430
|
+
[0.21, 103],
|
|
431
|
+
[0.32, 68, 'out'],
|
|
432
|
+
[0.4, 105, 'in'],
|
|
433
|
+
[0.47, 105],
|
|
434
|
+
[0.72, -13, 'out'],
|
|
435
|
+
[0.84, 6],
|
|
436
|
+
[1, 0],
|
|
437
|
+
]),
|
|
438
|
+
impact: track(t, [
|
|
439
|
+
[0, 0],
|
|
440
|
+
[0.16, 0.15],
|
|
441
|
+
[0.3, 0],
|
|
442
|
+
[0.43, 0.22],
|
|
443
|
+
[0.53, 0],
|
|
444
|
+
[0.76, 0.1],
|
|
445
|
+
[1, 0],
|
|
446
|
+
]),
|
|
447
|
+
headTilt: track(t, [
|
|
448
|
+
[0, 0],
|
|
449
|
+
[0.26, -9],
|
|
450
|
+
[0.4, 4],
|
|
451
|
+
[0.57, -16],
|
|
452
|
+
[0.78, 7],
|
|
453
|
+
[1, 0],
|
|
454
|
+
]),
|
|
455
|
+
compression: track(t, [
|
|
456
|
+
[0, 0],
|
|
457
|
+
[0.47, 0.12],
|
|
458
|
+
[0.7, -0.12],
|
|
459
|
+
[0.85, 0.07],
|
|
460
|
+
[1, 0],
|
|
461
|
+
]),
|
|
462
|
+
};
|
|
463
|
+
case 'dance':
|
|
464
|
+
return {
|
|
465
|
+
...REST_EMOTE,
|
|
466
|
+
nod: 0.8 * e * wave,
|
|
467
|
+
wave: 7 * e * Math.sin(t * Math.PI * 6),
|
|
468
|
+
compression: 0.09 * e * (1 - Math.cos(t * Math.PI * 8)),
|
|
469
|
+
};
|
|
470
|
+
case 'spin':
|
|
471
|
+
return { ...REST_EMOTE, turn: e };
|
|
472
|
+
case 'peek':
|
|
473
|
+
return { ...REST_EMOTE, nod: 1.4 * pulse(t), lookX: 2 * e, lookY: -e };
|
|
474
|
+
case 'hide':
|
|
475
|
+
return { ...REST_EMOTE, melt: 0.65 * pulse(t), compression: 0.12 * e };
|
|
476
|
+
case 'impatient':
|
|
477
|
+
return {
|
|
478
|
+
...REST_EMOTE,
|
|
479
|
+
compression: 0.09 * e * (1 - Math.cos(t * Math.PI * 10)),
|
|
480
|
+
lookX: e,
|
|
481
|
+
};
|
|
482
|
+
case 'sulk':
|
|
483
|
+
return {
|
|
484
|
+
...REST_EMOTE,
|
|
485
|
+
turn: pulse(t),
|
|
486
|
+
hideEyes: clamp((pulse(t) - 0.45) / 0.25),
|
|
487
|
+
nod: -0.4 * e,
|
|
488
|
+
};
|
|
489
|
+
case 'blink':
|
|
490
|
+
case 'slow-blink':
|
|
491
|
+
return {
|
|
492
|
+
...REST_EMOTE,
|
|
493
|
+
blinkLeft: pulse(t, 0.38, 0.55),
|
|
494
|
+
blinkRight: pulse(t, 0.38, 0.55),
|
|
495
|
+
};
|
|
496
|
+
case 'wink':
|
|
497
|
+
return { ...REST_EMOTE, blinkRight: pulse(t, 0.3, 0.55), nod: 0.2 * e };
|
|
498
|
+
case 'eye-roll': {
|
|
499
|
+
const arc = Math.PI * smooth((t - 0.18) / 0.56);
|
|
500
|
+
const hold = pulse(t, 0.14, 0.76);
|
|
501
|
+
return {
|
|
502
|
+
...REST_EMOTE,
|
|
503
|
+
lookX: -5.5 * Math.cos(arc) * hold,
|
|
504
|
+
lookY: (-0.7 - 6.3 * Math.sin(arc)) * hold,
|
|
505
|
+
blinkLeft: 0.2 * pulse(t, 0.18, 0.7),
|
|
506
|
+
blinkRight: 0.2 * pulse(t, 0.18, 0.7),
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
case 'glance':
|
|
510
|
+
return {
|
|
511
|
+
...REST_EMOTE,
|
|
512
|
+
lookX: track(t, [
|
|
513
|
+
[0, 0],
|
|
514
|
+
[0.14, -8, 'out'],
|
|
515
|
+
[0.32, -8],
|
|
516
|
+
[0.47, 8, 'out'],
|
|
517
|
+
[0.65, 8],
|
|
518
|
+
[0.8, 0],
|
|
519
|
+
[1, 0],
|
|
520
|
+
]),
|
|
521
|
+
lookY: track(t, [
|
|
522
|
+
[0, 0],
|
|
523
|
+
[0.32, 0.5],
|
|
524
|
+
[0.47, -1],
|
|
525
|
+
[0.65, -1],
|
|
526
|
+
[0.8, -5],
|
|
527
|
+
[0.88, -5],
|
|
528
|
+
[1, 0],
|
|
529
|
+
]),
|
|
530
|
+
};
|
|
531
|
+
case 'look-left':
|
|
532
|
+
case 'look-right':
|
|
533
|
+
return {
|
|
534
|
+
...REST_EMOTE,
|
|
535
|
+
lookX: (kind === 'look-left' ? -7 : 7) * pulse(t, 0.18, 0.76),
|
|
536
|
+
};
|
|
537
|
+
case 'look-up':
|
|
538
|
+
case 'look-down':
|
|
539
|
+
return {
|
|
540
|
+
...REST_EMOTE,
|
|
541
|
+
lookY: (kind === 'look-up' ? -7 : 6) * pulse(t, 0.18, 0.76),
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function sample(
|
|
547
|
+
kind: Emote['id'],
|
|
548
|
+
progress: number,
|
|
549
|
+
): { pose: typeof REST_EMOTE; look: EmoteLook } {
|
|
550
|
+
if (progress < 0 || progress >= 1 || (progress === 0 && kind !== 'land'))
|
|
551
|
+
return { pose: REST_EMOTE, look: {} };
|
|
552
|
+
const action = EMOTES.find((entry) => entry.id === kind);
|
|
553
|
+
if (!action) return { pose: REST_EMOTE, look: {} };
|
|
554
|
+
if (action.category !== 'reactions')
|
|
555
|
+
return {
|
|
556
|
+
pose: gesturePose(action.id, progress),
|
|
557
|
+
look:
|
|
558
|
+
action.id === 'startle' && progress < 0.78
|
|
559
|
+
? { expression: 'surprised' }
|
|
560
|
+
: action.id === 'land' &&
|
|
561
|
+
progress > 0 &&
|
|
562
|
+
progress < LAND_RECOVERY_START
|
|
563
|
+
? { expression: 'pained' }
|
|
564
|
+
: {},
|
|
565
|
+
};
|
|
566
|
+
let time = progress * action.duration;
|
|
567
|
+
for (const step of action.steps as readonly ReactionStep[]) {
|
|
568
|
+
if (time < step.duration)
|
|
569
|
+
return {
|
|
570
|
+
pose: gesturePose(step.gesture, time / step.duration),
|
|
571
|
+
look: { expression: step.expression, extra: step.extra },
|
|
572
|
+
};
|
|
573
|
+
time -= step.duration;
|
|
574
|
+
}
|
|
575
|
+
return { pose: REST_EMOTE, look: {} };
|
|
576
|
+
}
|
|
577
|
+
export function emotePose(kind: Emote['id'], progress: number) {
|
|
578
|
+
return sample(kind, progress).pose;
|
|
579
|
+
}
|
|
580
|
+
export function emoteLook(kind: Emote['id'], progress: number) {
|
|
581
|
+
return sample(kind, progress).look;
|
|
582
|
+
}
|
package/src/extras.css
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
.klex-sleep-letters {
|
|
2
|
+
animation: klex-sleep-appear 0.45s ease-out both;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.klex-sleep-letter {
|
|
6
|
+
animation: klex-sleep-rise 3.6s linear infinite;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
@keyframes klex-sleep-appear {
|
|
10
|
+
from {
|
|
11
|
+
opacity: 0;
|
|
12
|
+
}
|
|
13
|
+
to {
|
|
14
|
+
opacity: 1;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@keyframes klex-sleep-rise {
|
|
19
|
+
0% {
|
|
20
|
+
opacity: 0;
|
|
21
|
+
transform: translate(0, 10px) rotate(-12deg) scale(0.45);
|
|
22
|
+
}
|
|
23
|
+
12% {
|
|
24
|
+
opacity: 0.85;
|
|
25
|
+
transform: translate(4px, 1px) rotate(-4deg) scale(0.65);
|
|
26
|
+
}
|
|
27
|
+
42% {
|
|
28
|
+
opacity: 1;
|
|
29
|
+
transform: translate(12px, -18px) rotate(9deg) scale(0.9);
|
|
30
|
+
}
|
|
31
|
+
72% {
|
|
32
|
+
opacity: 0.8;
|
|
33
|
+
transform: translate(28px, -37px) rotate(-6deg) scale(1.15);
|
|
34
|
+
}
|
|
35
|
+
100% {
|
|
36
|
+
opacity: 0;
|
|
37
|
+
transform: translate(42px, -60px) rotate(8deg) scale(1.4);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@media (prefers-reduced-motion: reduce) {
|
|
42
|
+
.klex-sleep-letters,
|
|
43
|
+
.klex-sleep-letter {
|
|
44
|
+
animation: none;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.klex-sleep-letter {
|
|
48
|
+
opacity: 0.8;
|
|
49
|
+
}
|
|
50
|
+
}
|