@oxy.so/bloom 19.10.3 → 19.11.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/docs/adoption-matrix.mdx +4 -4
- package/docs/agent-avatar.mdx +22 -0
- package/docs/empty-state.mdx +20 -1
- package/docs/task-catalog.json +1 -1
- package/docs/task-catalog.mdx +1 -1
- package/lib/commonjs/agent-avatar/VectorCharacterAvatar.js +36 -17
- package/lib/commonjs/agent-avatar/VectorCharacterAvatar.js.map +1 -1
- package/lib/commonjs/agent-avatar/vector-mood.js +129 -0
- package/lib/commonjs/agent-avatar/vector-mood.js.map +1 -0
- package/lib/commonjs/empty-state/constants.js +2 -0
- package/lib/commonjs/empty-state/constants.js.map +1 -1
- package/lib/module/agent-avatar/VectorCharacterAvatar.js +36 -17
- package/lib/module/agent-avatar/VectorCharacterAvatar.js.map +1 -1
- package/lib/module/agent-avatar/vector-mood.js +117 -0
- package/lib/module/agent-avatar/vector-mood.js.map +1 -0
- package/lib/module/empty-state/constants.js +2 -0
- package/lib/module/empty-state/constants.js.map +1 -1
- package/lib/typescript/commonjs/agent-avatar/VectorCharacterAvatar.d.ts.map +1 -1
- package/lib/typescript/commonjs/agent-avatar/index.d.ts +1 -1
- package/lib/typescript/commonjs/agent-avatar/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/agent-avatar/types.d.ts +14 -0
- package/lib/typescript/commonjs/agent-avatar/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/agent-avatar/vector-mood.d.ts +61 -0
- package/lib/typescript/commonjs/agent-avatar/vector-mood.d.ts.map +1 -0
- package/lib/typescript/commonjs/empty-state/constants.d.ts +5 -0
- package/lib/typescript/commonjs/empty-state/constants.d.ts.map +1 -1
- package/lib/typescript/module/agent-avatar/VectorCharacterAvatar.d.ts.map +1 -1
- package/lib/typescript/module/agent-avatar/index.d.ts +1 -1
- package/lib/typescript/module/agent-avatar/index.d.ts.map +1 -1
- package/lib/typescript/module/agent-avatar/types.d.ts +14 -0
- package/lib/typescript/module/agent-avatar/types.d.ts.map +1 -1
- package/lib/typescript/module/agent-avatar/vector-mood.d.ts +61 -0
- package/lib/typescript/module/agent-avatar/vector-mood.d.ts.map +1 -0
- package/lib/typescript/module/empty-state/constants.d.ts +5 -0
- package/lib/typescript/module/empty-state/constants.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/agent-avatar/VectorCharacterAvatar.tsx +39 -10
- package/src/agent-avatar/index.ts +1 -1
- package/src/agent-avatar/types.ts +15 -0
- package/src/agent-avatar/vector-mood.ts +140 -0
- package/src/empty-state/constants.ts +7 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { VectorLook } from './vector-face.js';
|
|
2
|
+
import type { VectorMotionPose } from './vector-motion.js';
|
|
3
|
+
import type { VectorData } from './vector-types.js';
|
|
4
|
+
import type { AgentAvatarMood } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* How a mood is laid over whatever the character is doing. It is procedural, like gaze and
|
|
7
|
+
* blinking: every body, preset or edited, has its authored clips and none of them a "no", so the
|
|
8
|
+
* mood moves the pose those clips produce rather than adding a clip that only some bodies would
|
|
9
|
+
* have.
|
|
10
|
+
*/
|
|
11
|
+
export type VectorMoodState = {
|
|
12
|
+
/** How far into its mood the character is: 0 neutral, 1 fully sad. Eases, never jumps. */
|
|
13
|
+
sadness: number;
|
|
14
|
+
/** Seconds into the head shake that starts a sad mood. Past `VECTOR_DECLINE_SECONDS`, none. */
|
|
15
|
+
declineTime: number;
|
|
16
|
+
};
|
|
17
|
+
/** The shake that says "no": three turns, the first the widest, coming to rest. */
|
|
18
|
+
export declare const VECTOR_DECLINE_SECONDS = 1.4;
|
|
19
|
+
/** A neutral pose that a mood can be laid on: no turn, no droop, eyes open. */
|
|
20
|
+
export declare const VECTOR_REST_MOTION: Readonly<VectorMotionPose>;
|
|
21
|
+
/** The state a character starts in, with or without the mood. Starting sad shakes the head. */
|
|
22
|
+
export declare function initialVectorMood(mood: AgentAvatarMood | undefined): VectorMoodState;
|
|
23
|
+
/** The mood the character is now asked for. Becoming sad shakes the head once. */
|
|
24
|
+
export declare function setVectorMood(state: VectorMoodState, mood: AgentAvatarMood | undefined, previous: AgentAvatarMood | undefined): void;
|
|
25
|
+
/** One frame of a running character: the shake moves on and the droop eases towards the mood. */
|
|
26
|
+
export declare function advanceVectorMood(state: VectorMoodState, mood: AgentAvatarMood | undefined, delta: number): void;
|
|
27
|
+
/** A still character (paused, reduced motion) shows the mood's settled pose and never shakes. */
|
|
28
|
+
export declare function settleVectorMood(state: VectorMoodState, mood: AgentAvatarMood | undefined): void;
|
|
29
|
+
/** Whether the mood moves the pose at all; a neutral character draws exactly as it did without one. */
|
|
30
|
+
export declare function vectorMoodActive(state: VectorMoodState): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* The head turn of the shake, in radians, at `time` seconds into it: zero before and after, and
|
|
33
|
+
* it starts and ends at rest with no jump in speed. The swings shrink as the head gives up.
|
|
34
|
+
*/
|
|
35
|
+
export declare function sampleVectorDecline(time: number): number;
|
|
36
|
+
/**
|
|
37
|
+
* `pose` with the mood laid over it. Sad looks down and a little aside, sinks and deflates
|
|
38
|
+
* slightly, tilts the head and lets the lids fall; the shake turns the head and rocks it a little
|
|
39
|
+
* with each turn. Blinks and breathing carry on underneath.
|
|
40
|
+
*/
|
|
41
|
+
export declare function applyVectorMood(pose: VectorMotionPose, state: VectorMoodState): VectorMotionPose;
|
|
42
|
+
export type VectorMoodFrame = {
|
|
43
|
+
/** The turn of the whole drawing (and of a reference face without a rest basis). */
|
|
44
|
+
yaw: number;
|
|
45
|
+
pitch: number;
|
|
46
|
+
motion?: VectorMotionPose;
|
|
47
|
+
/** A reference face's head direction. */
|
|
48
|
+
look?: VectorLook;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* What `renderVectorFrame` draws a character with, the mood laid on. `procedural` is a reference
|
|
52
|
+
* face's sampled motion (undefined for other bodies) and `turn` the pointer's turn. The mood's
|
|
53
|
+
* turn goes everywhere a head can turn: a reference face's `look`, and the frame's own turn, which
|
|
54
|
+
* is how a body with no head of its own (and a face fitted without a rest basis) shakes. A neutral
|
|
55
|
+
* character draws exactly as it did without a mood.
|
|
56
|
+
*/
|
|
57
|
+
export declare function vectorMoodFrame(asset: VectorData, procedural: VectorMotionPose | undefined, turn: {
|
|
58
|
+
yaw: number;
|
|
59
|
+
pitch: number;
|
|
60
|
+
}, mood: VectorMoodState | undefined): VectorMoodFrame;
|
|
61
|
+
//# sourceMappingURL=vector-mood.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-mood.d.ts","sourceRoot":"","sources":["../../../../src/agent-avatar/vector-mood.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAe,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAiB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAS,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,0FAA0F;IAC1F,OAAO,EAAE,MAAM,CAAC;IAChB,+FAA+F;IAC/F,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,mFAAmF;AACnF,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAK1C,+EAA+E;AAC/E,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,gBAAgB,CAOzD,CAAC;AAQF,+FAA+F;AAC/F,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,eAAe,GAAG,SAAS,GAAG,eAAe,CAEpF;AAED,kFAAkF;AAClF,wBAAgB,aAAa,CAC3B,KAAK,EAAE,eAAe,EACtB,IAAI,EAAE,eAAe,GAAG,SAAS,EACjC,QAAQ,EAAE,eAAe,GAAG,SAAS,QAGtC;AAED,iGAAiG;AACjG,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,eAAe,EACtB,IAAI,EAAE,eAAe,GAAG,SAAS,EACjC,KAAK,EAAE,MAAM,QAMd;AAED,iGAAiG;AACjG,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,eAAe,GAAG,SAAS,QAGzF;AAED,uGAAuG;AACvG,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAEhE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIxD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,eAAe,GAAG,gBAAgB,CAWhG;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,oFAAoF;IACpF,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,yCAAyC;IACzC,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,UAAU,EACjB,UAAU,EAAE,gBAAgB,GAAG,SAAS,EACxC,IAAI,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EACpC,IAAI,EAAE,eAAe,GAAG,SAAS,GAChC,eAAe,CAajB"}
|
|
@@ -5,6 +5,11 @@ export interface EmptyStateGeometry {
|
|
|
5
5
|
glyph: number;
|
|
6
6
|
/** `IconCircle`'s rung. `lg` is 52, `xl` is 64. */
|
|
7
7
|
circle: 'lg' | 'xl';
|
|
8
|
+
/**
|
|
9
|
+
* The box for a figure passed as `illustration`: an agent's avatar, a picture. Larger than the
|
|
10
|
+
* disc because a character has to be read (its face, its gesture), not just recognised.
|
|
11
|
+
*/
|
|
12
|
+
illustration: number;
|
|
8
13
|
/** Above and below the block. */
|
|
9
14
|
paddingVertical: number;
|
|
10
15
|
/** Between the mark, the text block, the children, the actions and the footer. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/empty-state/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAS,CAAC;AAEjD,MAAM,WAAW,kBAAkB;IACjC,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,MAAM,EAAE,IAAI,GAAG,IAAI,CAAC;IACpB,iCAAiC;IACjC,eAAe,EAAE,MAAM,CAAC;IACxB,kFAAkF;IAClF,GAAG,EAAE,MAAM,CAAC;IACZ,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,gBAAgB,CAAC;IACxB,WAAW,EAAE,gBAAgB,CAAC;CAC/B;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,iBAAiB,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/empty-state/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAS,CAAC;AAEjD,MAAM,WAAW,kBAAkB;IACjC,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,MAAM,EAAE,IAAI,GAAG,IAAI,CAAC;IACpB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB,iCAAiC;IACjC,eAAe,EAAE,MAAM,CAAC;IACxB,kFAAkF;IAClF,GAAG,EAAE,MAAM,CAAC;IACZ,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,gBAAgB,CAAC;IACxB,WAAW,EAAE,gBAAgB,CAAC;CAC/B;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,iBAAiB,EAAE,kBAAkB,CAuB9E,CAAC;AAEF,iFAAiF;AACjF,eAAO,MAAM,sBAAsB,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -18,6 +18,14 @@ import { CHARACTER_COLORS } from './character-colors';
|
|
|
18
18
|
import { vectorWorkLook } from './vector-work-look';
|
|
19
19
|
import { sampleVectorPose, blendVectorPose, type VectorPose } from './vector-pose';
|
|
20
20
|
import { sampleVectorMotion, referenceWorkTime, type VectorMotionPose } from './vector-motion';
|
|
21
|
+
import {
|
|
22
|
+
advanceVectorMood,
|
|
23
|
+
initialVectorMood,
|
|
24
|
+
setVectorMood,
|
|
25
|
+
settleVectorMood,
|
|
26
|
+
vectorMoodActive,
|
|
27
|
+
vectorMoodFrame,
|
|
28
|
+
} from './vector-mood';
|
|
21
29
|
import {
|
|
22
30
|
useCallback,
|
|
23
31
|
useContext,
|
|
@@ -83,7 +91,7 @@ export function VectorCharacterAvatar(props: Props) {
|
|
|
83
91
|
return <AnimatedVectorCharacterAvatar {...props} />;
|
|
84
92
|
}
|
|
85
93
|
function AnimatedVectorCharacterAvatar(props: Props) {
|
|
86
|
-
const { character, size = 64, paused, portrait, interactive, previewPart } = props;
|
|
94
|
+
const { character, size = 64, paused, portrait, interactive, previewPart, mood } = props;
|
|
87
95
|
const { messages } = useMessages(AGENT_AVATAR_MESSAGES, props.locale);
|
|
88
96
|
const catalog = useVectorAssetLoader(props.catalog);
|
|
89
97
|
const reduced = usePrefersReducedMotion(),
|
|
@@ -166,13 +174,17 @@ function AnimatedVectorCharacterAvatar(props: Props) {
|
|
|
166
174
|
motionFrom: undefined as VectorMotionPose | undefined,
|
|
167
175
|
transitionStarted: 0,
|
|
168
176
|
transitionDuration: VECTOR_TRANSITION_SECONDS,
|
|
177
|
+
mood: initialVectorMood(mood),
|
|
169
178
|
});
|
|
170
179
|
const previous = useRef({
|
|
171
180
|
idle: props.idleKey,
|
|
172
181
|
reaction: props.reactionKey,
|
|
173
182
|
work: props.workingKey,
|
|
174
183
|
entrance: props.entranceKey,
|
|
184
|
+
mood,
|
|
175
185
|
});
|
|
186
|
+
const latestMood = useRef(mood);
|
|
187
|
+
latestMood.current = mood;
|
|
176
188
|
const cycles = useRef(props.workingCycles);
|
|
177
189
|
cycles.current = props.workingCycles;
|
|
178
190
|
const play = useCallback((action: VectorAction) => {
|
|
@@ -253,6 +265,13 @@ function AnimatedVectorCharacterAvatar(props: Props) {
|
|
|
253
265
|
play('idle');
|
|
254
266
|
}
|
|
255
267
|
}, [props.idleKey, props.reactionKey, props.workingKey, props.entranceKey, play]);
|
|
268
|
+
useEffect(() => {
|
|
269
|
+
if (mood === previous.current.mood) return;
|
|
270
|
+
setVectorMood(state.current.mood, mood, previous.current.mood);
|
|
271
|
+
previous.current.mood = mood;
|
|
272
|
+
// A still character repaints into the new mood; a running one restarts its frame loop.
|
|
273
|
+
setRevision((value) => value + 1);
|
|
274
|
+
}, [mood]);
|
|
256
275
|
useEffect(() => {
|
|
257
276
|
if (Platform.OS !== 'web' || typeof IntersectionObserver === 'undefined' || !host.current)
|
|
258
277
|
return;
|
|
@@ -289,7 +308,8 @@ function AnimatedVectorCharacterAvatar(props: Props) {
|
|
|
289
308
|
motion.yaw += (motion.targetYaw - motion.yaw) * follow;
|
|
290
309
|
motion.pitch += (motion.targetPitch - motion.pitch) * follow;
|
|
291
310
|
motion.lookMix += ((motion.pointerActive ? 1 : 0) - motion.lookMix) * follow;
|
|
292
|
-
|
|
311
|
+
advanceVectorMood(motion.mood, latestMood.current, delta);
|
|
312
|
+
} else settleVectorMood(motion.mood, latestMood.current);
|
|
293
313
|
if (!painted || stopped || now - painted >= 1000 / 30) {
|
|
294
314
|
painted = painted ? now - ((now - painted) % (1000 / 30)) : now;
|
|
295
315
|
const action = portrait ? 'idle' : motion.action,
|
|
@@ -299,6 +319,7 @@ function AnimatedVectorCharacterAvatar(props: Props) {
|
|
|
299
319
|
Math.max(0, (motion.clock - motion.transitionStarted) / motion.transitionDuration),
|
|
300
320
|
);
|
|
301
321
|
const eased = transition * transition * (3 - 2 * transition);
|
|
322
|
+
const feeling = !portrait && vectorMoodActive(motion.mood) ? { ...motion.mood } : undefined;
|
|
302
323
|
const sharedKey = JSON.stringify([
|
|
303
324
|
latestFrameRecipe.current,
|
|
304
325
|
action,
|
|
@@ -312,10 +333,12 @@ function AnimatedVectorCharacterAvatar(props: Props) {
|
|
|
312
333
|
motion.transitionDuration,
|
|
313
334
|
vectorStateIdentity(motion.poseFrom),
|
|
314
335
|
vectorStateIdentity(motion.motionFrom),
|
|
336
|
+
feeling?.sadness,
|
|
337
|
+
feeling?.declineTime,
|
|
315
338
|
portrait,
|
|
316
339
|
previewPart,
|
|
317
340
|
]);
|
|
318
|
-
const { pose, procedural, drawing } = shareVectorFrame(sharedKey, () => {
|
|
341
|
+
const { pose, procedural, gaze, drawing } = shareVectorFrame(sharedKey, () => {
|
|
319
342
|
const poseTime =
|
|
320
343
|
asset.referenceFace && action === 'work' ? referenceWorkTime(time) : time;
|
|
321
344
|
const targetPose = sampleVectorPose(asset, action, poseTime);
|
|
@@ -346,17 +369,22 @@ function AnimatedVectorCharacterAvatar(props: Props) {
|
|
|
346
369
|
: undefined,
|
|
347
370
|
})
|
|
348
371
|
: undefined;
|
|
372
|
+
// The mood goes over the blended motion, never into it: a transition captures the
|
|
373
|
+
// motion without the mood, which carries on through the transition on its own clock.
|
|
374
|
+
const framed = vectorMoodFrame(
|
|
375
|
+
asset,
|
|
376
|
+
procedural,
|
|
377
|
+
{ yaw: portrait ? 0 : motion.yaw, pitch: portrait ? 0 : motion.pitch },
|
|
378
|
+
feeling,
|
|
379
|
+
);
|
|
349
380
|
const drawing = renderVectorFrame(asset, {
|
|
350
381
|
action,
|
|
351
382
|
time,
|
|
352
|
-
|
|
353
|
-
pitch: portrait ? 0 : motion.pitch,
|
|
383
|
+
...framed,
|
|
354
384
|
eyesOnly: previewPart === 'eyes',
|
|
355
385
|
pose,
|
|
356
|
-
motion: procedural,
|
|
357
|
-
look: procedural ? { yaw: procedural.yaw, pitch: procedural.pitch, mix: 1 } : undefined,
|
|
358
386
|
});
|
|
359
|
-
return { pose, procedural, drawing };
|
|
387
|
+
return { pose, procedural, gaze: framed.look ?? framed, drawing };
|
|
360
388
|
});
|
|
361
389
|
motion.lastPose = pose;
|
|
362
390
|
motion.lastMotion = procedural;
|
|
@@ -372,8 +400,8 @@ function AnimatedVectorCharacterAvatar(props: Props) {
|
|
|
372
400
|
time,
|
|
373
401
|
count: motion.count,
|
|
374
402
|
entrance: stopped ? 1 : motion.entrance,
|
|
375
|
-
gazeYaw:
|
|
376
|
-
gazePitch:
|
|
403
|
+
gazeYaw: gaze.yaw,
|
|
404
|
+
gazePitch: gaze.pitch,
|
|
377
405
|
tracking: motion.lookMix,
|
|
378
406
|
});
|
|
379
407
|
}
|
|
@@ -424,6 +452,7 @@ function AnimatedVectorCharacterAvatar(props: Props) {
|
|
|
424
452
|
gazeYaw: String(display?.gazeYaw ?? 0),
|
|
425
453
|
gazePitch: String(display?.gazePitch ?? 0),
|
|
426
454
|
tracking: String(display?.tracking ?? 0),
|
|
455
|
+
mood: mood ?? 'neutral',
|
|
427
456
|
},
|
|
428
457
|
}
|
|
429
458
|
: {})}
|
|
@@ -2,7 +2,7 @@ export { AgentAvatar } from './AgentAvatar';
|
|
|
2
2
|
export { AgentAvatarProvider } from './AgentAvatarProvider';
|
|
3
3
|
export { BLOOM_CHARACTER_RUNTIME_URL } from './context';
|
|
4
4
|
export { useAvatarRendererCapabilities } from './use-avatar-renderer-capabilities';
|
|
5
|
-
export type { AgentAvatarProps, AgentAvatarProviderProps } from './types';
|
|
5
|
+
export type { AgentAvatarMood, AgentAvatarProps, AgentAvatarProviderProps } from './types';
|
|
6
6
|
|
|
7
7
|
// One model: a character. `resolveAvatarCharacter` fills it in, `parseAvatarCharacter`
|
|
8
8
|
// checks saved JSON, `characterFromLegacy` migrates an avatar saved before 10.
|
|
@@ -4,6 +4,14 @@ import type { BloomThemeStorage } from '../theme/persistence';
|
|
|
4
4
|
import type { AvatarCharacter } from './character';
|
|
5
5
|
import type { VectorAssetLoader } from './vector-types';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* How the character feels, held for as long as it is set. `neutral` is its usual idle. `sad` is
|
|
9
|
+
* for an empty or not-found state, a refusal, something that could not be done: the character
|
|
10
|
+
* shakes its head "no" once as the mood starts, then stays dejected (looking down, drooping, lids
|
|
11
|
+
* heavy) on top of its idle until the mood changes.
|
|
12
|
+
*/
|
|
13
|
+
export type AgentAvatarMood = 'neutral' | 'sad';
|
|
14
|
+
|
|
7
15
|
export type AgentAvatarProps = {
|
|
8
16
|
/** @deprecated All characters use SVG. The legacy selector is accepted but has no effect. */
|
|
9
17
|
renderer?: 'svg' | 'webgl';
|
|
@@ -24,6 +32,13 @@ export type AgentAvatarProps = {
|
|
|
24
32
|
entranceKey?: number;
|
|
25
33
|
workingKey?: number;
|
|
26
34
|
workingCycles?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Default `neutral`. Becoming `sad` (or mounting sad) shakes the head "no" once, then holds a
|
|
37
|
+
* dejected idle; back to `neutral` the droop eases out. Reactions, work and pointer gaze still
|
|
38
|
+
* play on top. Reduced motion and `paused` show the settled pose with no shake; a `portrait`
|
|
39
|
+
* still is always neutral.
|
|
40
|
+
*/
|
|
41
|
+
mood?: AgentAvatarMood;
|
|
27
42
|
/** The first picture of the character has been painted. Fires once per mounted renderer. */
|
|
28
43
|
onReady?: () => void;
|
|
29
44
|
/** Reports selected geometry preparation; paint-only changes do not reload. */
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { VectorLook } from './vector-face';
|
|
2
|
+
import type { VectorMotionPose } from './vector-motion';
|
|
3
|
+
import type { VectorData } from './vector-types';
|
|
4
|
+
import type { AgentAvatarMood } from './types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* How a mood is laid over whatever the character is doing. It is procedural, like gaze and
|
|
8
|
+
* blinking: every body, preset or edited, has its authored clips and none of them a "no", so the
|
|
9
|
+
* mood moves the pose those clips produce rather than adding a clip that only some bodies would
|
|
10
|
+
* have.
|
|
11
|
+
*/
|
|
12
|
+
export type VectorMoodState = {
|
|
13
|
+
/** How far into its mood the character is: 0 neutral, 1 fully sad. Eases, never jumps. */
|
|
14
|
+
sadness: number;
|
|
15
|
+
/** Seconds into the head shake that starts a sad mood. Past `VECTOR_DECLINE_SECONDS`, none. */
|
|
16
|
+
declineTime: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** The shake that says "no": three turns, the first the widest, coming to rest. */
|
|
20
|
+
export const VECTOR_DECLINE_SECONDS = 1.4;
|
|
21
|
+
/** How quickly the dejected pose sets in and lifts, per second. Settled in about a second. */
|
|
22
|
+
const SADNESS_RATE = 2.5;
|
|
23
|
+
const DECLINE_YAW = 0.6;
|
|
24
|
+
|
|
25
|
+
/** A neutral pose that a mood can be laid on: no turn, no droop, eyes open. */
|
|
26
|
+
export const VECTOR_REST_MOTION: Readonly<VectorMotionPose> = {
|
|
27
|
+
yaw: 0,
|
|
28
|
+
pitch: 0,
|
|
29
|
+
roll: 0,
|
|
30
|
+
bob: 0,
|
|
31
|
+
scale: 1,
|
|
32
|
+
lid: 1,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const unit = (value: number) => (Number.isFinite(value) ? Math.max(0, Math.min(1, value)) : 0);
|
|
36
|
+
const ease = (value: number) => {
|
|
37
|
+
const t = unit(value);
|
|
38
|
+
return t * t * (3 - 2 * t);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** The state a character starts in, with or without the mood. Starting sad shakes the head. */
|
|
42
|
+
export function initialVectorMood(mood: AgentAvatarMood | undefined): VectorMoodState {
|
|
43
|
+
return { sadness: 0, declineTime: mood === 'sad' ? 0 : Number.POSITIVE_INFINITY };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The mood the character is now asked for. Becoming sad shakes the head once. */
|
|
47
|
+
export function setVectorMood(
|
|
48
|
+
state: VectorMoodState,
|
|
49
|
+
mood: AgentAvatarMood | undefined,
|
|
50
|
+
previous: AgentAvatarMood | undefined,
|
|
51
|
+
) {
|
|
52
|
+
if (mood === 'sad' && previous !== 'sad') state.declineTime = 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** One frame of a running character: the shake moves on and the droop eases towards the mood. */
|
|
56
|
+
export function advanceVectorMood(
|
|
57
|
+
state: VectorMoodState,
|
|
58
|
+
mood: AgentAvatarMood | undefined,
|
|
59
|
+
delta: number,
|
|
60
|
+
) {
|
|
61
|
+
const target = mood === 'sad' ? 1 : 0;
|
|
62
|
+
state.declineTime += delta;
|
|
63
|
+
state.sadness += (target - state.sadness) * (1 - Math.exp(-delta * SADNESS_RATE));
|
|
64
|
+
if (Math.abs(target - state.sadness) < 0.001) state.sadness = target;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** A still character (paused, reduced motion) shows the mood's settled pose and never shakes. */
|
|
68
|
+
export function settleVectorMood(state: VectorMoodState, mood: AgentAvatarMood | undefined) {
|
|
69
|
+
state.sadness = mood === 'sad' ? 1 : 0;
|
|
70
|
+
state.declineTime = Number.POSITIVE_INFINITY;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Whether the mood moves the pose at all; a neutral character draws exactly as it did without one. */
|
|
74
|
+
export function vectorMoodActive(state: VectorMoodState): boolean {
|
|
75
|
+
return state.sadness > 0 || state.declineTime < VECTOR_DECLINE_SECONDS;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The head turn of the shake, in radians, at `time` seconds into it: zero before and after, and
|
|
80
|
+
* it starts and ends at rest with no jump in speed. The swings shrink as the head gives up.
|
|
81
|
+
*/
|
|
82
|
+
export function sampleVectorDecline(time: number): number {
|
|
83
|
+
if (!(time > 0 && time < VECTOR_DECLINE_SECONDS)) return 0;
|
|
84
|
+
const u = time / VECTOR_DECLINE_SECONDS;
|
|
85
|
+
return DECLINE_YAW * ease(u / 0.12) * (1 - u) ** 2 * Math.sin(Math.PI * 6 * u);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* `pose` with the mood laid over it. Sad looks down and a little aside, sinks and deflates
|
|
90
|
+
* slightly, tilts the head and lets the lids fall; the shake turns the head and rocks it a little
|
|
91
|
+
* with each turn. Blinks and breathing carry on underneath.
|
|
92
|
+
*/
|
|
93
|
+
export function applyVectorMood(pose: VectorMotionPose, state: VectorMoodState): VectorMotionPose {
|
|
94
|
+
const sad = unit(state.sadness),
|
|
95
|
+
shake = sampleVectorDecline(state.declineTime);
|
|
96
|
+
return {
|
|
97
|
+
yaw: pose.yaw + shake - sad * 0.1,
|
|
98
|
+
pitch: pose.pitch + sad * 0.3,
|
|
99
|
+
roll: pose.roll + shake * 0.12 + sad * 0.06,
|
|
100
|
+
bob: pose.bob - sad * 0.04,
|
|
101
|
+
scale: pose.scale * (1 - sad * 0.03),
|
|
102
|
+
lid: unit(pose.lid * (1 - sad * 0.4)),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type VectorMoodFrame = {
|
|
107
|
+
/** The turn of the whole drawing (and of a reference face without a rest basis). */
|
|
108
|
+
yaw: number;
|
|
109
|
+
pitch: number;
|
|
110
|
+
motion?: VectorMotionPose;
|
|
111
|
+
/** A reference face's head direction. */
|
|
112
|
+
look?: VectorLook;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* What `renderVectorFrame` draws a character with, the mood laid on. `procedural` is a reference
|
|
117
|
+
* face's sampled motion (undefined for other bodies) and `turn` the pointer's turn. The mood's
|
|
118
|
+
* turn goes everywhere a head can turn: a reference face's `look`, and the frame's own turn, which
|
|
119
|
+
* is how a body with no head of its own (and a face fitted without a rest basis) shakes. A neutral
|
|
120
|
+
* character draws exactly as it did without a mood.
|
|
121
|
+
*/
|
|
122
|
+
export function vectorMoodFrame(
|
|
123
|
+
asset: VectorData,
|
|
124
|
+
procedural: VectorMotionPose | undefined,
|
|
125
|
+
turn: { yaw: number; pitch: number },
|
|
126
|
+
mood: VectorMoodState | undefined,
|
|
127
|
+
): VectorMoodFrame {
|
|
128
|
+
const look = (motion: VectorMotionPose | undefined) =>
|
|
129
|
+
asset.referenceFace && motion ? { yaw: motion.yaw, pitch: motion.pitch, mix: 1 } : undefined;
|
|
130
|
+
if (!mood || !vectorMoodActive(mood))
|
|
131
|
+
return { ...turn, motion: procedural, look: look(procedural) };
|
|
132
|
+
const base = procedural ?? VECTOR_REST_MOTION,
|
|
133
|
+
motion = applyVectorMood(base, mood);
|
|
134
|
+
return {
|
|
135
|
+
yaw: turn.yaw + motion.yaw - base.yaw,
|
|
136
|
+
pitch: turn.pitch + motion.pitch - base.pitch,
|
|
137
|
+
motion,
|
|
138
|
+
look: look(motion),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
@@ -6,6 +6,11 @@ export interface EmptyStateGeometry {
|
|
|
6
6
|
glyph: number;
|
|
7
7
|
/** `IconCircle`'s rung. `lg` is 52, `xl` is 64. */
|
|
8
8
|
circle: 'lg' | 'xl';
|
|
9
|
+
/**
|
|
10
|
+
* The box for a figure passed as `illustration`: an agent's avatar, a picture. Larger than the
|
|
11
|
+
* disc because a character has to be read (its face, its gesture), not just recognised.
|
|
12
|
+
*/
|
|
13
|
+
illustration: number;
|
|
9
14
|
/** Above and below the block. */
|
|
10
15
|
paddingVertical: number;
|
|
11
16
|
/** Between the mark, the text block, the children, the actions and the footer. */
|
|
@@ -32,6 +37,7 @@ export const EMPTY_STATE_GEOMETRY: Record<EmptyStateVariant, EmptyStateGeometry>
|
|
|
32
37
|
comfortable: {
|
|
33
38
|
glyph: 32,
|
|
34
39
|
circle: 'xl',
|
|
40
|
+
illustration: 112,
|
|
35
41
|
paddingVertical: 48,
|
|
36
42
|
gap: 16,
|
|
37
43
|
textGap: 6,
|
|
@@ -42,6 +48,7 @@ export const EMPTY_STATE_GEOMETRY: Record<EmptyStateVariant, EmptyStateGeometry>
|
|
|
42
48
|
compact: {
|
|
43
49
|
glyph: 24,
|
|
44
50
|
circle: 'lg',
|
|
51
|
+
illustration: 72,
|
|
45
52
|
paddingVertical: 24,
|
|
46
53
|
gap: 12,
|
|
47
54
|
textGap: 4,
|