@kodax-ai/botui 0.1.1 → 0.1.3
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/README.md +140 -113
- package/core/identity.js +46 -0
- package/{themes/solids → core}/motion.js +114 -114
- package/core/registry.js +26 -18
- package/docs/usage.md +202 -0
- package/element.js +5 -0
- package/index.d.ts +2 -0
- package/index.js +11 -5
- package/package.json +38 -2
- package/themes/caret/README.md +43 -0
- package/themes/caret/avatar.js +10 -0
- package/themes/caret/engine.js +143 -0
- package/themes/caret/index.d.ts +24 -0
- package/themes/caret/index.js +35 -0
- package/themes/critter/README.md +43 -0
- package/themes/critter/avatar.js +12 -0
- package/themes/critter/engine.js +113 -0
- package/themes/critter/index.d.ts +28 -0
- package/themes/critter/index.js +35 -0
- package/themes/doodle/README.md +43 -0
- package/themes/doodle/avatar.js +10 -0
- package/themes/doodle/engine.js +149 -0
- package/themes/doodle/index.d.ts +24 -0
- package/themes/doodle/index.js +36 -0
- package/themes/dots/README.md +42 -0
- package/themes/dots/avatar.js +15 -0
- package/themes/dots/engine.js +179 -0
- package/themes/dots/index.d.ts +24 -0
- package/themes/dots/index.js +35 -0
- package/themes/kaomoji/README.md +42 -0
- package/themes/kaomoji/avatar.js +10 -0
- package/themes/kaomoji/engine.js +110 -0
- package/themes/kaomoji/index.d.ts +24 -0
- package/themes/kaomoji/index.js +35 -0
- package/themes/liquid/README.md +47 -0
- package/themes/liquid/avatar.js +10 -0
- package/themes/liquid/engine.js +161 -0
- package/themes/liquid/index.d.ts +24 -0
- package/themes/liquid/index.js +35 -0
- package/themes/matrix/README.md +48 -0
- package/themes/matrix/avatar.js +227 -0
- package/themes/matrix/engine.js +479 -0
- package/themes/matrix/index.d.ts +47 -0
- package/themes/matrix/index.js +34 -0
- package/themes/orb/README.md +44 -0
- package/themes/orb/avatar.js +10 -0
- package/themes/orb/engine.js +130 -0
- package/themes/orb/index.d.ts +24 -0
- package/themes/orb/index.js +36 -0
- package/themes/solids/README.md +2 -2
- package/themes/solids/avatar.js +561 -579
- package/themes/solids/face.js +52 -56
- package/themes/solids/index.js +34 -28
package/README.md
CHANGED
|
@@ -1,113 +1,140 @@
|
|
|
1
|
-
# BotUI
|
|
2
|
-
|
|
3
|
-
收录各种类型 Bot 形象的专门项目。RSIBot 采用其中一套主题。
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-

|
|
8
|
-
|
|
9
|
-
同一个 Bot 在不同状态下的样子(每格换了一个立体和颜色):
|
|
10
|
-
|
|
11
|
-

|
|
12
|
-
|
|
13
|
-
以上是引擎自己导出的静止帧(`docs/make.html` 生成);动起来的样子见下面的“本地查看”。
|
|
14
|
-
|
|
15
|
-
## 使用
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npm install @kodax-ai/botui
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
```js
|
|
22
|
-
import {createAvatar} from '@kodax-ai/botui';
|
|
23
|
-
|
|
24
|
-
const bot = createAvatar({identity: 'research-bot', size: 36});
|
|
25
|
-
sidebar.append(bot.el);
|
|
26
|
-
bot.setState('thinking');
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
或者不写 JS、不用构建,直接从 CDN 引用:
|
|
30
|
-
|
|
31
|
-
```html
|
|
32
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/@kodax-ai/botui@0.1/element.js"></script>
|
|
33
|
-
<bot-avatar identity="research-bot" size="36" state="thinking"></bot-avatar>
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
-
|
|
46
|
-
|
|
47
|
-
##
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
|
52
|
-
|
|
53
|
-
| `
|
|
54
|
-
| `
|
|
55
|
-
| `
|
|
56
|
-
| `
|
|
57
|
-
| `
|
|
58
|
-
| `
|
|
59
|
-
| `
|
|
60
|
-
|
|
61
|
-
##
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
79
|
-
| `
|
|
80
|
-
| `
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
1
|
+
# BotUI
|
|
2
|
+
|
|
3
|
+
收录各种类型 Bot 形象的专门项目。RSIBot 采用其中一套主题。
|
|
4
|
+
|
|
5
|
+
共 9 个主题,零依赖。推荐系列是“立体家族”(带眼睛的立体):36 个立体、16 种颜色、3 种眼型、55 个状态、17 个动作、21 种眼神。另外 8 个主题共用点阵主题的引擎(见下面的“主题”),颜色、眼型、状态、动作、眼神与立体家族一致,同一个 Bot ID 在每个主题里是同一种颜色和眼型。早期草图的对比板在 `avatar-lab/directions.html`。
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
同一个 Bot 在不同状态下的样子(每格换了一个立体和颜色):
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
以上是引擎自己导出的静止帧(`docs/make.html` 生成);动起来的样子见下面的“本地查看”。
|
|
14
|
+
|
|
15
|
+
## 使用
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @kodax-ai/botui
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import {createAvatar} from '@kodax-ai/botui';
|
|
23
|
+
|
|
24
|
+
const bot = createAvatar({identity: 'research-bot', size: 36});
|
|
25
|
+
sidebar.append(bot.el);
|
|
26
|
+
bot.setState('thinking');
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
或者不写 JS、不用构建,直接从 CDN 引用:
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@kodax-ai/botui@0.1/element.js"></script>
|
|
33
|
+
<bot-avatar identity="research-bot" size="36" state="thinking"></bot-avatar>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
总入口只带默认主题立体家族,其他主题按需引入,不用的不会进你的包:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import {createAvatar} from '@kodax-ai/botui';
|
|
40
|
+
import '@kodax-ai/botui/themes/kaomoji'; // 引入即注册
|
|
41
|
+
|
|
42
|
+
const bot = createAvatar({theme: 'kaomoji', identity: 'research-bot'});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
只用一个主题时也可以直接 `import {createAvatar} from '@kodax-ai/botui/themes/<主题名>'`。CDN 用法同理:先加载 `themes/<主题名>/index.js`,再写 `<bot-avatar theme="<主题名>">`。也可以不经 npm,按版本标签引用本仓库:`npm install github:icetomoyo/BotUI#v0.1.3`。接入说明(选主题、React / Vue / 纯 HTML、状态映射、包体积、水印)见 [docs/usage.md](docs/usage.md),它也随 npm 包发布。完整的选项和方法见 [themes/solids/README.md](themes/solids/README.md)。
|
|
46
|
+
|
|
47
|
+
## 主题
|
|
48
|
+
|
|
49
|
+
| 主题 | `theme` | 样子 | 说明 |
|
|
50
|
+
|---|---|---|---|
|
|
51
|
+
| 立体家族 | `solids` | 带眼睛的立体(默认) | [themes/solids](themes/solids/README.md) |
|
|
52
|
+
| 点阵 | `matrix` | 彩色方块上的 5×5 点阵屏 | [themes/matrix](themes/matrix/README.md) |
|
|
53
|
+
| 活点 | `dots` | 五颗带弹簧的点,拉长、分裂、合并成表情 | [themes/dots](themes/dots/README.md) |
|
|
54
|
+
| 字符脸 | `kaomoji` | 打出来的字符脸 `o_o` `^_^` | [themes/kaomoji](themes/kaomoji/README.md) |
|
|
55
|
+
| 光标 | `caret` | 一个文本光标,弯成各种字形 | [themes/caret](themes/caret/README.md) |
|
|
56
|
+
| 光晕 | `orb` | 流动的柔光,加立体家族的眼睛 | [themes/orb](themes/orb/README.md) |
|
|
57
|
+
| 液面 | `liquid` | 玻璃杯里的液体,液面就是脸 | [themes/liquid](themes/liquid/README.md) |
|
|
58
|
+
| 像素生物 | `critter` | 像素画小生物,猫耳 / 熊耳 / 兔耳 / 天线 | [themes/critter](themes/critter/README.md) |
|
|
59
|
+
| 手绘 | `doodle` | 抖动的墨线手绘,带嘴 | [themes/doodle](themes/doodle/README.md) |
|
|
60
|
+
|
|
61
|
+
## 许可
|
|
62
|
+
|
|
63
|
+
源码公开,但不是开源软件。本项目采用 [KodaX-AI BotUI License 1.0](LICENSE),版权归张伟(Wei Zhang,icetomoyo)/ KodaX-AI 所有。要点(以 LICENSE 原文为准):
|
|
64
|
+
|
|
65
|
+
- **任何使用**都必须保留 `LICENSE`、`NOTICE` 和代码、SVG 里的版权信息,并在产品的“关于”、文档或致谢处写明:`Bot avatars by BotUI © icetomoyo / KodaX-AI`。
|
|
66
|
+
- **个人、学习、非商业使用**:免费,可以用 `watermark: false` 关掉水印。
|
|
67
|
+
- **商业或组织内使用**(公司、学校、机构内部使用也算):免费,但必须保持水印开启、清晰可见、不被遮挡或改动。形象在 48 px 及以上时右下角显示 `KodaX-AI`。
|
|
68
|
+
- **商用去水印**:需要与 KodaX-AI 另签书面授权。联系方式见 LICENSE。
|
|
69
|
+
|
|
70
|
+
## 结构
|
|
71
|
+
|
|
72
|
+
一个核心加每主题一个渲染器,零依赖的原生 ES 模块,不需要构建。
|
|
73
|
+
|
|
74
|
+
| 路径 | 内容 |
|
|
75
|
+
|---|---|
|
|
76
|
+
| `core/` | 各主题共用:帧循环、身份哈希、指针、状态词表(`states.js`)、主题注册(`registry.js`)、姿态和动作(`motion.js`)、颜色眼型水印(`identity.js`) |
|
|
77
|
+
| `themes/solids/` | 推荐系列“立体家族”:带眼睛的立体。用法见 [themes/solids/README.md](themes/solids/README.md) |
|
|
78
|
+
| `themes/matrix/` | 点阵:彩色方块上的 5×5 点阵屏,颜色和眼型与立体家族一致。用法见 [themes/matrix/README.md](themes/matrix/README.md) |
|
|
79
|
+
| `themes/dots/` | 活点:同一块方块上五颗带弹簧的点,拉长、分裂、合并成每种表情。用法见 [themes/dots/README.md](themes/dots/README.md) |
|
|
80
|
+
| `themes/kaomoji/` … `themes/doodle/` | 字符脸、光标、光晕、液面、像素生物、手绘,都建在点阵上,各自目录有 README |
|
|
81
|
+
| `index.js` | 总入口:`createAvatar({theme, ...})`,只带立体家族,其他主题引入后自动注册 |
|
|
82
|
+
| `element.js` | 自定义元素 `<bot-avatar>` |
|
|
83
|
+
| `index.d.ts` | 类型声明 |
|
|
84
|
+
| `tests/check.html` | 自检页:把每个主题的所有外形、状态、动作、眼神、颜色和选项跑一遍 |
|
|
85
|
+
| `docs/usage.md` | 给使用方的接入说明(随 npm 包发布) |
|
|
86
|
+
| `avatar-lab/` | 早期草图存档 |
|
|
87
|
+
|
|
88
|
+
## 本地查看
|
|
89
|
+
|
|
90
|
+
ES 模块不能从 `file://` 加载。双击根目录的 `serve.cmd` 会起本地服务并打开试玩页 `themes/solids/playground.html`(其他主题在各自目录下,如 `themes/matrix/playground.html`)。立体家族目录里的 `sheet.html`(全家福)和 `filmstrip.html`(连续帧)用来核对造型和动作。
|
|
91
|
+
|
|
92
|
+
自检:服务起来后打开 `http://127.0.0.1:8765/tests/check.html`,页面显示 `PASS` 或失败清单。
|
|
93
|
+
|
|
94
|
+
## 发布到 npm(维护者)
|
|
95
|
+
|
|
96
|
+
包名 `@kodax-ai/botui`,发布方式照搬 KodaX:仓库里的 `package.json` 始终是 `private: true`,直接 `npm publish` 会被拒绝。只有 `scripts/release.mjs` 会在打包那一刻把它改成 false,打完包立即还原。
|
|
97
|
+
|
|
98
|
+
在仓库根目录运行 `npm run release`(与 `node scripts/release.mjs` 完全等同,后面的版本词和 `--dry-run`、`--otp=...` 等参数两种写法都一样)。
|
|
99
|
+
|
|
100
|
+
最简单的用法:自己把 `package.json` 的 `version` 改好并提交,然后不带参数运行 `npm run release`。dist-tag 按版本号自动决定,和 KodaX 一样:
|
|
101
|
+
|
|
102
|
+
| package.json version | dist-tag |
|
|
103
|
+
|---|---|
|
|
104
|
+
| `0.2.0-alpha.3` | `alpha` |
|
|
105
|
+
| `0.2.0-beta.9` | `beta` |
|
|
106
|
+
| `0.2.0-rc.4` | `rc` |
|
|
107
|
+
| `0.2.0` | `latest` |
|
|
108
|
+
|
|
109
|
+
也可以让脚本帮你改版本号,按 alpha → beta → rc → 正式版走:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
npm run release alpha minor # 0.1.0 -> 0.2.0-alpha.0(从正式版开新一轮;minor 可换成 patch / major,省略时是 patch)
|
|
113
|
+
npm run release alpha # 0.2.0-alpha.0 -> 0.2.0-alpha.1
|
|
114
|
+
npm run release beta # 0.2.0-alpha.1 -> 0.2.0-beta.0
|
|
115
|
+
npm run release rc # 0.2.0-beta.N -> 0.2.0-rc.0
|
|
116
|
+
npm run release final # 0.2.0-rc.N -> 0.2.0
|
|
117
|
+
npm run release patch # 0.2.0 -> 0.2.1(不走预发布的小修)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
每一行都会:跑检查 → 打包审计 → 提交 `Release v<版本>` 并打标签 → 发布 → 推送。任何一行后面加 `--dry-run` 就是演练,不提交、不打标签,也不真发布。alpha / beta / rc 分别发到 npm 的 `alpha` / `beta` / `rc` 标签,只有正式版发到 `latest`,所以 `npm install @kodax-ai/botui` 永远拿到正式版,想试 beta 的人用 `npm install @kodax-ai/botui@beta`。新版本必须比当前版本高,写反了会直接报错。
|
|
121
|
+
|
|
122
|
+
也支持 `minor`、`major`、`prerelease` 和直接写版本号(如 `npm run release 0.3.0-beta.0`)。
|
|
123
|
+
|
|
124
|
+
不带参数时,HEAD 还没打标签的话脚本会自动打上 `v<版本>`。参数写错(比如 `--dryrun`)时,用 `node` 运行会直接报错;用 `npm run` 运行时 npm 会把它吞掉,脚本就当成真发布。和 KodaX 一样,真发布不会再问确认,没把握时先加 `--dry-run` 演练。
|
|
125
|
+
|
|
126
|
+
`release.mjs` 依次做这些事,任何一步失败都会停下:
|
|
127
|
+
|
|
128
|
+
1. 检查 `package.json`:包名、`files` 白名单、`exports`、LICENSE,以及目标版本在 npm 上还不存在。
|
|
129
|
+
2. 检查 git:已跟踪的文件没有未提交的改动(与包无关的未跟踪文件不影响);目标版本的标签状态正确。演练和 `--pack-only` 只给警告。
|
|
130
|
+
3. 用无头 Chrome 跑 `tests/check.html`,必须显示 `PASS`(单独跑:`npm run check`)。
|
|
131
|
+
4. 按目标版本打包到 `.release/`,然后审计:必需文件都在;测试、草图、截图之类的开发文件没有混进去;进包的每个文件都已提交且未修改;每个相对 import 都能在包里找到;最后把包按使用方的方式装进临时目录,在 Node 里按包名 import 一遍。
|
|
132
|
+
5. 改版本号、提交 `Release v<版本>`、打标签。前面所有可能失败的步骤都已经跑完,所以审计失败不会留下半截的版本提交。
|
|
133
|
+
6. `npm publish` 到 `registry.npmjs.org`,不受本机 `.npmrc` 镜像设置影响。dist-tag 按上面的表自动决定,预发布版本不会覆盖 `latest`。
|
|
134
|
+
7. `git push origin <分支> v<版本>`。
|
|
135
|
+
|
|
136
|
+
其他参数:`--otp=123456`(npm 两步验证)、`--no-push`(不推送)、`--tag=next`(指定 dist-tag)、`--skip-check`(跳过 Chrome 自检)。
|
|
137
|
+
|
|
138
|
+
如果发布这一步失败了(常见原因是 OTP 过期),版本提交和标签已经留在本地,修好之后不带版本参数再跑一次就行:`npm run release --otp=123456`。
|
|
139
|
+
|
|
140
|
+
`npm run release --pack-only` 只打包不发布,生成的 tgz 可以在别的项目里 `npm install <路径>` 试用。
|
package/core/identity.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// What a Bot looks like in every theme: its colour, its eye style and the
|
|
2
|
+
// attribution it carries. A theme adds its own shapes on top, so the same Bot ID
|
|
3
|
+
// keeps its colour and eyes whichever theme draws it.
|
|
4
|
+
|
|
5
|
+
import {hash} from './core.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Body colours. `chroma`, `base` and `span` default to a saturated mid tone; `eye`
|
|
9
|
+
* overrides the eye colour; `dark` holds what changes on a dark background
|
|
10
|
+
* (without it the colour is simply a little lighter there).
|
|
11
|
+
*/
|
|
12
|
+
export const COLORS = {
|
|
13
|
+
red: {hue: 25}, orange: {hue: 55}, amber: {hue: 85}, lime: {hue: 120}, green: {hue: 150}, teal: {hue: 175},
|
|
14
|
+
cyan: {hue: 200}, sky: {hue: 235}, blue: {hue: 265}, violet: {hue: 290}, magenta: {hue: 330}, pink: {hue: 0, chroma: 0.13, base: 0.68},
|
|
15
|
+
brown: {hue: 60, chroma: 0.06, base: 0.5, dark: {base: 0.58}}, gray: {hue: 260, chroma: 0.012, base: 0.58, dark: {base: 0.67}},
|
|
16
|
+
black: {hue: 260, chroma: 0.012, base: 0.3, span: 0.15, dark: {base: 0.45, span: 0.17, chroma: 0.02}},
|
|
17
|
+
white: {hue: 260, chroma: 0.006, base: 0.83, span: 0.13, eye: 'oklch(0.3 0.03 260)', dark: {}},
|
|
18
|
+
};
|
|
19
|
+
/** The colours a Bot ID can be born with: the twelve saturated ones. */
|
|
20
|
+
export const BIRTH_COLORS = Object.keys(COLORS).slice(0, 12);
|
|
21
|
+
export const HUES = BIRTH_COLORS.map(name => COLORS[name].hue);
|
|
22
|
+
|
|
23
|
+
/** The eye style a Bot is born with, as the solids draw it. `gap` is half the distance between eyes. */
|
|
24
|
+
export const EYE_STYLES = {
|
|
25
|
+
bar: {h: 0.2, w: 0.3, gap: 0.4},
|
|
26
|
+
dot: {h: 0.03, w: 0.42, gap: 0.42},
|
|
27
|
+
tall: {h: 0.27, w: 0.2, gap: 0.34},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** Names from `given` that pass `test`, or all of `all` when none do. */
|
|
31
|
+
export const pick = (given, test, all) => { const kept = (given || []).filter(test); return kept.length ? kept : all; };
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The colour and eye style a Bot ID maps to, the same in every theme. `pool` can
|
|
35
|
+
* limit the choice: {colors, eyes}, each a list of names.
|
|
36
|
+
*/
|
|
37
|
+
export function bornLook(identity, pool) {
|
|
38
|
+
const h = hash(identity), colors = pick(pool?.colors, name => COLORS[name], BIRTH_COLORS), eyes = pick(pool?.eyes, name => EYE_STYLES[name], Object.keys(EYE_STYLES));
|
|
39
|
+
return {color: colors[(h >>> 8) % colors.length], eyes: eyes[(h >>> 16) % eyes.length]};
|
|
40
|
+
}
|
|
41
|
+
/** A theme's shape for a Bot ID, from `shapes` (names), honouring pool.shapes. */
|
|
42
|
+
export const shapeFor = (identity, shapes, pool) => { const list = pick(pool?.shapes, name => shapes.includes(name), shapes); return list[hash(identity + '/shape') % list.length]; };
|
|
43
|
+
|
|
44
|
+
// Attribution carried by every avatar: invisibly in the SVG, and as a visible mark from WATERMARK_FROM pixels up.
|
|
45
|
+
export const WATERMARK = 'KodaX-AI', WATERMARK_FROM = 48;
|
|
46
|
+
export const CREDIT = 'BotUI. Copyright (c) 2026 Wei Zhang (icetomoyo) / KodaX-AI. KodaX-AI BotUI License 1.0. https://github.com/icetomoyo/BotUI';
|
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
// How
|
|
2
|
-
//
|
|
3
|
-
// A pose is `(avatar, t, look) => targets`, returning only what differs from
|
|
4
|
-
// REST. `look` is where the avatar's attention is, each axis about -1..1.
|
|
5
|
-
// Targets: yaw, pitch, roll (radians); sy (vertical stretch); lift (down is
|
|
6
|
-
// positive); scale; gx, gy (eyes sliding on the face); expr; sat; blush;
|
|
7
|
-
// rate and stiff (how fast it gets there); orbit (speed of circling dots);
|
|
8
|
-
// mark (a glyph beside the head); ring ('progress' or 'spin'); bars (sound
|
|
9
|
-
// bars); still (no blinking).
|
|
10
|
-
|
|
11
|
-
import {TAU, smooth, bump} from '
|
|
12
|
-
|
|
13
|
-
// The resting turn and tilt every pose is built on. A page may change it to try other angles.
|
|
14
|
-
export const BASE = {yaw: 0.3, pitch: -0.26};
|
|
15
|
-
export const REST = {get yaw() { return BASE.yaw; }, get pitch() { return BASE.pitch; }, roll: 0, sy: 1, lift: 0, scale: 1, gx: 0, gy: 0, expr: 'neutral', sat: 1, blush: 0, rate: 9, stiff: 260, orbit: 0, mark: null, ring: null, bars: false, still: false};
|
|
16
|
-
|
|
17
|
-
const sin = Math.sin;
|
|
18
|
-
const beat = (t, f) => Math.abs(sin(t * f));
|
|
19
|
-
const talk = t => Math.abs(sin(t * 4.2) * Math.cos(t * 1.7));
|
|
20
|
-
const float = t => 2 * sin(t * 1.7);
|
|
21
|
-
// Positive yaw turns the face to the viewer's left and negative pitch tilts it up, so a look to the right or down subtracts yaw and adds pitch.
|
|
22
|
-
// The rest pose already tilts up, so looking up gets less travel than looking down.
|
|
23
|
-
const facing = (l, yaw = BASE.yaw, pitch = BASE.pitch) => ({yaw: yaw - l.x * 0.9, pitch: pitch + l.y * (l.y < 0 ? 0.4 : 0.6), gx: l.x * 0.16, gy: l.y * 0.16});
|
|
24
|
-
const SHOW = ['nod', 'spin', 'wink', 'jump', 'wobble', 'tilt', 'flip', 'dance', 'glance', 'stretch'];
|
|
25
|
-
const PLAY = ['wink', 'wobble', 'spin', 'dance'];
|
|
26
|
-
|
|
27
|
-
export const POSES = {
|
|
28
|
-
// ---- the working day ----
|
|
29
|
-
idle: {pose: (a, t, l) => ({...facing(l), lift: float(t)})},
|
|
30
|
-
listening: {enter: a => a.hop(60), pose: (a, t, l) => ({...facing(l, 0, -0.4), scale: 1.06, roll: 0.07 * sin(t * 0.9), lift: 1.5 * sin(t * 2.4), expr: 'wide'})},
|
|
31
|
-
thinking: {pose: (a, t) => ({yaw: 0.75 * sin(t * 1.15), pitch: 0.2 + 0.08 * sin(t * 2.3), roll: 0.1 * sin(t * 0.8), gx: 0.16 * sin(t * 1.15), gy: -0.2, lift: float(t), rate: 6, orbit: 1})},
|
|
32
|
-
streaming: {pose: (a, t) => ({yaw: 0.25 + 0.3 * sin(t * 1.3), sy: 0.8 + 0.42 * talk(t), lift: float(t), rate: 20, stiff: 700, mark: 'dots'})},
|
|
33
|
-
searching: {pose: (a, t) => { if (a.every(1.1)) a.pulse(); return {yaw: 0.9 * sin(t * 1.6), pitch: -0.2 + 0.12 * sin(t * 0.9), gx: 0.14 * sin(t * 1.6), gy: 0.05 * sin(t * 2.7), lift: float(t), expr: 'inspecting', mark: 'search', rate: 7}; }},
|
|
34
|
-
reading: {pose: (a, t) => { const u = (t * 0.9) % 1, line = Math.floor(t * 0.9) % 3; return {yaw: 0.5 * (u - 0.5), pitch: -0.44 + 0.06 * line, gx: 0.2 * (u - 0.5), gy: 0.1 + 0.04 * line, lift: float(t) * 0.5, rate: 10}; }},
|
|
35
|
-
working: {pose: (a, t) => ({yaw: BASE.yaw + 0.14 * sin(t * 2.2), pitch: -0.5, roll: 0.07 * sin(t * 7), lift: -2.5 * beat(t, 7), gx: 0.14 * sin(t * 3.1), gy: 0.12, expr: 'focus'})},
|
|
36
|
-
coding: {pose: (a, t) => ({yaw: BASE.yaw + 0.1 * sin(t * 1.9), pitch: -0.45, lift: -1.8 * beat(t, 9), sy: 1 - 0.04 * beat(t, 9), gx: 0.1 * sin(t * 2.3), gy: 0.12, expr: 'focus', mark: 'code'})},
|
|
37
|
-
running: {pose: (a, t) => { if (a.every(0.26)) a.emit('dust'); return {yaw: 0.55, pitch: -0.2, roll: 0.14 + 0.05 * sin(t * 14), lift: -7 * beat(t, 7), sy: 1 + 0.08 * sin(t * 14), gx: 0.12, expr: 'focus', rate: 12}; }},
|
|
38
|
-
computing: {pose: (a, t) => ({yaw: BASE.yaw + 0.25 * sin(t * 2), pitch: -0.05, roll: 0.05 * sin(t * 3.3), gy: -0.16, gx: 0.1 * sin(t * 4), lift: float(t), expr: 'focus', orbit: 2.3})},
|
|
39
|
-
controlling: {pose: (a, t) => { if (a.every(0.77)) a.nudge(); const k = Math.floor(t * 1.3), x = sin(k * 12.9898) * 0.9, y = sin(k * 78.233) * 0.6; return {yaw: BASE.yaw + x * 0.7, pitch: -0.26 - y * 0.4, gx: x * 0.15, gy: y * 0.12, lift: float(t), expr: 'focus', mark: 'cursor', rate: 14}; }},
|
|
40
|
-
asking: {enter: a => a.play('tilt'), pose: (a, t, l) => { if (a.every(3.2)) a.hop(70); return {...facing(l, 0.1, -0.3), roll: 0.2 * Math.sign(sin(t * 1.1)), lift: float(t), expr: 'wide', mark: 'ask'}; }},
|
|
41
|
-
blocked: {pose: () => ({yaw: 0.3, pitch: -0.22, sy: 0.55, lift: 12, expr: 'closed', sat: 0.25, rate: 5, stiff: 120})},
|
|
42
|
-
finished: {enter: a => { a.play('spin'); a.hop(150); a.burst('spark', 8); }, pose: (a, t) => ({yaw: 0.3, pitch: -0.3, lift: float(t), expr: 'happy'})},
|
|
43
|
-
error: {enter: a => { a.play('shake'); a.express('cross', 1300); }, pose: () => ({yaw: 0.15, pitch: -0.2, roll: 0.12, sy: 0.9, lift: 5, gy: 0.1, expr: 'sad', sat: 0.6})},
|
|
44
|
-
sleeping: {pose: (a, t) => { if (a.every(1.3)) a.emit('z'); return {yaw: 0.35, pitch: -0.42, roll: 0.14, sy: 0.88 + 0.05 * sin(t * 1.2), lift: 8, expr: 'sleep', sat: 0.85, rate: 3, stiff: 60}; }},
|
|
45
|
-
waking: {enter: a => { a.express('sleepy', 1100); a.play('stretch'); }, pose: (a, t, l) => ({...facing(l), lift: float(t), expr: 'wide'})},
|
|
46
|
-
|
|
47
|
-
// ---- moods ----
|
|
48
|
-
happy: {pose: (a, t, l) => ({...facing(l), lift: -3 * beat(t, 3.2), roll: 0.08 * sin(t * 3.2), expr: 'happy', blush: 0.5})},
|
|
49
|
-
excited: {enter: a => a.hop(120), pose: (a, t, l) => { if (a.every(1.6)) a.burst('spark', 4); return {...facing(l, 0.2, -0.32), lift: -7 * beat(t, 6), sy: 1 + 0.07 * sin(t * 12), scale: 1.06, expr: 'sparkle', blush: 0.4}; }},
|
|
50
|
-
laughing: {pose: (a, t) => ({yaw: BASE.yaw, pitch: -0.5, lift: -2.5 * beat(t, 11), sy: 1 + 0.07 * sin(t * 22), roll: 0.06 * sin(t * 5), expr: 'happy', blush: 0.6, stiff: 700, rate: 14})},
|
|
51
|
-
proud: {pose: (a, t) => { if (a.every(2.2)) a.burst('spark', 3); return {yaw: 0.35, pitch: -0.55, sy: 1.07, scale: 1.06, lift: float(t) * 0.5, expr: 'calm', blush: 0.3}; }},
|
|
52
|
-
curious: {pose: (a, t, l) => ({...facing(l, 0.1, -0.3), roll: 0.22 * Math.sign(sin(t * 0.8)), scale: 1.07, lift: float(t), expr: 'inspecting'})},
|
|
53
|
-
playful: {pose: (a, t, l) => { if (a.every(2.4)) a.play(PLAY[a.beat++ % PLAY.length]); return {...facing(l), roll: 0.16 * sin(t * 2.6), lift: -4 * beat(t, 2.6), expr: 'happy'}; }},
|
|
54
|
-
shy: {pose: (a, t) => ({yaw: 0.75, pitch: 0.05, roll: -0.08, scale: 0.94, gx: 0.12, gy: 0.14, lift: 3 + float(t) * 0.4, expr: 'shy', blush: 1, rate: 5})},
|
|
55
|
-
surprised: {enter: a => a.play('startle'), pose: (a, t, l) => ({...facing(l, 0.2, -0.4), scale: 1.08, sy: 1.06, lift: -2, expr: 'surprised'})},
|
|
56
|
-
suspicious: {pose: (a, t) => ({yaw: 0.6, pitch: -0.2, roll: -0.1, gx: -0.16, gy: 0.02 * sin(t), lift: float(t) * 0.5, expr: 'skeptic', rate: 4})},
|
|
57
|
-
angry: {pose: (a, t, l) => { if (a.every(1.5)) a.squash(2); return {...facing(l, 0.15, -0.2), roll: 0.035 * sin(t * 38), sy: 0.94, scale: 1.04, lift: 2, expr: 'angry', mark: 'anger', rate: 12}; }},
|
|
58
|
-
confused: {pose: (a, t) => ({yaw: 0.5 * sin(t * 0.9), pitch: -0.2, roll: 0.2 * sin(t * 0.9 + 1), gx: 0.1 * sin(t * 1.8), lift: float(t), expr: 'confused', mark: 'ask'})},
|
|
59
|
-
sad: {pose: a => { if (a.every(2.4)) a.emit('tear'); return {yaw: 0.15, pitch: 0.12, sy: 0.92, lift: 6, gy: 0.14, roll: -0.06, expr: 'sad', sat: 0.7, rate: 4, stiff: 120}; }},
|
|
60
|
-
drowsy: {pose: (a, t) => { const u = (t * 0.35) % 1, nod = u < 0.8 ? smooth(u / 0.8) : 1 - smooth((u - 0.8) / 0.2); return {yaw: 0.25, pitch: -0.3 + 0.5 * nod, roll: 0.12 * nod, lift: 3 + 4 * nod, expr: 'sleepy', sat: 0.9, rate: 8}; }},
|
|
61
|
-
bored: {pose: (a, t) => { if (a.every(4)) a.squash(1.5); return {yaw: 0.5, pitch: -0.15, roll: 0.2, sy: 0.94 + 0.03 * sin(t * 0.8), lift: 5, gx: 0.15 * sin(t * 0.4), gy: -0.1, expr: 'sleepy', rate: 3, stiff: 80}; }},
|
|
62
|
-
scared: {pose: (a, t) => ({yaw: -0.3, pitch: -0.38, roll: 0.03 * sin(t * 45), sy: 0.9, scale: 0.92, lift: 3, gx: 0.1 * sin(t * 7), gy: -0.05, expr: 'surprised', sat: 0.8, mark: 'sweat', rate: 14})},
|
|
63
|
-
celebrating: {enter: a => { a.play('jump'); a.burst('confetti', 14); }, pose: (a, t) => { if (a.every(1.15)) { a.play(a.beat++ % 2 ? 'jump' : 'spin'); a.burst('confetti', 10); } return {yaw: 0.25, pitch: -0.3, lift: float(t), expr: 'sparkle'}; }},
|
|
64
|
-
approving: {enter: a => a.play('nod'), pose: (a, t, l) => { if (a.every(1.7)) a.play('nod'); return {...facing(l), lift: float(t), expr: 'happy', mark: 'check'}; }},
|
|
65
|
-
loving: {pose: (a, t, l) => { if (a.every(0.9)) a.emit('heart'); return {...facing(l, 0.15, -0.3), roll: 0.1 * sin(t * 2), lift: -2 * beat(t, 2), scale: 1.04, expr: 'love', blush: 0.8}; }},
|
|
66
|
-
|
|
67
|
-
// ---- signals: what is going on, shown with something around the body ----
|
|
68
|
-
orbit: {pose: (a, t) => ({yaw: BASE.yaw + 0.3 * sin(t * 1.3), gx: 0.14 * Math.cos(t * 2.6), gy: 0.08 * sin(t * 2.6), lift: float(t), orbit: 1.6})},
|
|
69
|
-
radar: {pose: (a, t) => { if (a.every(0.9)) a.pulse(); return {yaw: 1.0 * sin(t * 1.1), pitch: -0.3, lift: float(t), expr: 'wide', rate: 8}; }},
|
|
70
|
-
progress: {pose: (a, t, l) => ({...facing(l, 0.2, -0.3), lift: float(t) * 0.5, expr: 'focus', ring: 'progress'})},
|
|
71
|
-
loading: {pose: (a, t) => ({yaw: BASE.yaw + 0.15 * sin(t * 2), lift: float(t), gy: -0.08, ring: 'spin'})},
|
|
72
|
-
spawning: {enter: a => { a.p.scale = 0.15; a.vel.scale = 0; for (let i = 0; i < 8; i++) a.emit('in'); }, pose: (a, t) => { if (a.every(0.2) && a.since < 2.4) a.emit('in'); return {scale: Math.min(1, 0.3 + a.since * 0.32), yaw: BASE.yaw + Math.max(0, 2.4 - a.since) * 1.2, lift: float(t), expr: a.since < 1.6 ? 'closed' : 'wide', rate: 12}; }},
|
|
73
|
-
dictating: {pose: (a, t) => ({yaw: BASE.yaw + 0.2 * sin(t * 1.1), sy: 0.92 + 0.2 * talk(t), lift: float(t), expr: 'calm', bars: true, rate: 20, stiff: 700})},
|
|
74
|
-
sending: {pose: (a, t) => { if (a.every(0.2)) a.emit('out'); return {yaw: 0.45, pitch: -0.45, lift: float(t) - 2, gx: 0.1, gy: -0.15, expr: 'focus'}; }},
|
|
75
|
-
receiving: {pose: (a, t) => { if (a.every(0.13)) a.emit('in'); return {yaw: BASE.yaw + 0.1 * sin(t * 2), pitch: -0.35, scale: 1 + 0.03 * sin(t * 9), lift: float(t), expr: 'wide'}; }},
|
|
76
|
-
uploading: {pose: (a, t) => { if (a.every(0.28)) a.emit('up'); return {yaw: BASE.yaw, pitch: -0.5, gy: -0.18, sy: 1.05, lift: -2 + float(t), mark: 'up'}; }},
|
|
77
|
-
writing: {pose: (a, t) => { const u = (t * 0.7) % 1; return {yaw: -0.15 + 0.4 * u, pitch: -0.5, gx: 0.18 * (u - 0.5), gy: 0.15, lift: -1.2 * beat(t, 8), expr: 'focus', mark: 'pen'}; }},
|
|
78
|
-
alerting: {enter: a => a.play('startle'), pose: (a, t, l) => { if (a.every(1.3)) a.play('startle'); return {...facing(l, 0.2, -0.3), scale: 1.05, lift: float(t), expr: 'wide', mark: 'bang'}; }},
|
|
79
|
-
bouncing: {enter: a => a.play('jump'), pose: (a, t, l) => { if (a.every(0.85)) a.play('jump'); return {...facing(l), expr: 'happy'}; }},
|
|
80
|
-
'powering-down': {pose: () => ({yaw: 0.3, pitch: 0.1, sy: 0.7, scale: 0.82, lift: 14, expr: 'closed', sat: 0.12, rate: 2, stiff: 40, still: true})},
|
|
81
|
-
|
|
82
|
-
// ---- product moments ----
|
|
83
|
-
humming: {pose: (a, t) => { if (a.every(0.6)) a.emit('note'); return {yaw: BASE.yaw + 0.25 * sin(t * 1.5), roll: 0.14 * sin(t * 3), lift: -2 * beat(t, 3), expr: 'calm', blush: 0.3}; }},
|
|
84
|
-
notifying: {enter: a => a.hop(110), pose: (a, t, l) => { if (a.every(2)) a.hop(110); return {...facing(l), scale: 1.03, lift: float(t), expr: 'wide', mark: 'badge'}; }},
|
|
85
|
-
dragging: {pose: (a, t) => ({yaw: BASE.yaw + 0.3 * sin(t * 2.3), pitch: -0.1, roll: 0.25 * sin(t * 3.1), sy: 1.16, lift: -8, expr: 'surprised', stiff: 120})},
|
|
86
|
-
greeting: {enter: a => { a.hop(120); a.play('wave'); }, pose: (a, t, l) => { if (a.every(2.6)) a.play('wave'); return {...facing(l, 0.1, -0.3), lift: float(t), scale: 1.04, expr: 'happy'}; }},
|
|
87
|
-
|
|
88
|
-
// ---- showing it off ----
|
|
89
|
-
logo: {pose: () => ({yaw: 0.5, pitch: -0.32, rate: 6, still: true})},
|
|
90
|
-
showcase: {pose: (a, t, l) => { if (a.every(1.8)) a.play(SHOW[a.beat++ % SHOW.length]); return {...facing(l), lift: float(t)}; }},
|
|
91
|
-
turntable: {pose: (a, t) => ({yaw: t * 1.3, pitch: -0.3, rate: 30})},
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
// `move(u, g)` adds this gesture's offsets at progress u (0..1) to g.
|
|
95
|
-
export const GESTURES = {
|
|
96
|
-
nod: {zh: '点头', dur: 0.7, move: (u, g) => { g.pitch -= 0.38 * sin(u * TAU * 2) * (1 - u); }},
|
|
97
|
-
shake: {zh: '摇头', dur: 0.75, move: (u, g) => { g.yaw += 0.55 * sin(u * TAU * 2.5) * (1 - u); }},
|
|
98
|
-
tilt: {zh: '歪头', dur: 1.3, move: (u, g) => { g.roll += 0.32 * smooth(Math.min(1, u * 4)) * smooth(Math.min(1, (1 - u) * 4)); }},
|
|
99
|
-
glance: {zh: '张望', dur: 1.6, move: (u, g) => { g.yaw += 0.8 * sin(u * TAU) * Math.sqrt(bump(u)); g.gx += 0.12 * sin(u * TAU); }},
|
|
100
|
-
wink: {zh: '眨眼', dur: 0.6, expr: 'wink', move: (u, g) => { g.roll += 0.12 * bump(u); }},
|
|
101
|
-
wave: {zh: '招手', dur: 1.1, expr: 'happy', move: (u, g) => { g.roll += 0.3 * sin(u * TAU * 3) * Math.sqrt(bump(u)); g.lift -= 4 * bump(u); }},
|
|
102
|
-
bow: {zh: '鞠躬', dur: 1.2, expr: 'closed', move: (u, g) => { g.pitch += 0.75 * bump(u) ** 2; g.sy -= 0.08 * bump(u); }},
|
|
103
|
-
spin: {zh: '转圈', dur: 0.75, move: (u, g) => { g.yaw += TAU * smooth(u); g.sy += 0.1 * bump(u); }},
|
|
104
|
-
flip: {zh: '空翻', dur: 0.85, expr: 'happy', move: (u, g) => { g.pitch -= TAU * smooth(u); g.lift -= 13 * bump(u); }, end: a => a.squash(3)},
|
|
105
|
-
roll: {zh: '侧翻', dur: 0.9, expr: 'happy', move: (u, g) => { g.roll += TAU * smooth(u); g.lift -= 9 * bump(u); }, end: a => a.squash(2)},
|
|
106
|
-
jump: {zh: '跳', dur: 0.8, expr: 'happy', move: (u, g) => { if (u < 0.22) { g.sy -= 0.28 * bump(u / 0.22); return; } const v = (u - 0.22) / 0.78; g.lift -= 72 * v * (1 - v); g.sy += 0.14 * bump(v * 2); }, end: a => a.squash(4)},
|
|
107
|
-
bounce: {zh: '弹一下', dur: 0.5, start: a => { a.hop(170); a.squash(3); }, move: () => {}},
|
|
108
|
-
wobble: {zh: '果冻', dur: 0.9, start: a => a.squash(5), move: (u, g) => { g.roll += 0.16 * sin(u * TAU * 3) * (1 - u); }},
|
|
109
|
-
shiver: {zh: '发抖', dur: 0.9, expr: 'squint', move: (u, g) => { g.roll += 0.05 * sin(u * 60) * bump(u); g.sy -= 0.06 * bump(u); }},
|
|
110
|
-
startle: {zh: '一惊', dur: 0.5, expr: 'surprised', move: (u, g) => { g.lift -= 9 * (1 - u) ** 2; g.scale += 0.14 * (1 - u); }},
|
|
111
|
-
stretch: {zh: '伸懒腰', dur: 1.2, expr: 'closed', move: (u, g) => { g.sy += 0.36 * bump(u) ** 2 - 0.12 * bump(Math.min(1, u * 5)); g.pitch += 0.25 * bump(u); g.roll += 0.08 * sin(u * TAU); }},
|
|
112
|
-
dance: {zh: '跳舞', dur: 2.4, expr: 'happy', move: (u, g) => { const e = Math.sqrt(bump(u)); g.roll += 0.22 * sin(u * TAU * 4) * e; g.lift -= 6 * Math.abs(sin(u * TAU * 4)) * e; g.yaw += 0.5 * sin(u * TAU * 2) * e; }},
|
|
113
|
-
};
|
|
114
|
-
export const FIDGETS = ['tilt', 'glance', 'wink', 'stretch', 'nod'];
|
|
1
|
+
// How every theme acts out each state, and the one-shot gestures. Drawn first for the solids.
|
|
2
|
+
//
|
|
3
|
+
// A pose is `(avatar, t, look) => targets`, returning only what differs from
|
|
4
|
+
// REST. `look` is where the avatar's attention is, each axis about -1..1.
|
|
5
|
+
// Targets: yaw, pitch, roll (radians); sy (vertical stretch); lift (down is
|
|
6
|
+
// positive); scale; gx, gy (eyes sliding on the face); expr; sat; blush;
|
|
7
|
+
// rate and stiff (how fast it gets there); orbit (speed of circling dots);
|
|
8
|
+
// mark (a glyph beside the head); ring ('progress' or 'spin'); bars (sound
|
|
9
|
+
// bars); still (no blinking).
|
|
10
|
+
|
|
11
|
+
import {TAU, smooth, bump} from './core.js';
|
|
12
|
+
|
|
13
|
+
// The resting turn and tilt every pose is built on. A page may change it to try other angles.
|
|
14
|
+
export const BASE = {yaw: 0.3, pitch: -0.26};
|
|
15
|
+
export const REST = {get yaw() { return BASE.yaw; }, get pitch() { return BASE.pitch; }, roll: 0, sy: 1, lift: 0, scale: 1, gx: 0, gy: 0, expr: 'neutral', sat: 1, blush: 0, rate: 9, stiff: 260, orbit: 0, mark: null, ring: null, bars: false, still: false};
|
|
16
|
+
|
|
17
|
+
const sin = Math.sin;
|
|
18
|
+
const beat = (t, f) => Math.abs(sin(t * f));
|
|
19
|
+
const talk = t => Math.abs(sin(t * 4.2) * Math.cos(t * 1.7));
|
|
20
|
+
const float = t => 2 * sin(t * 1.7);
|
|
21
|
+
// Positive yaw turns the face to the viewer's left and negative pitch tilts it up, so a look to the right or down subtracts yaw and adds pitch.
|
|
22
|
+
// The rest pose already tilts up, so looking up gets less travel than looking down.
|
|
23
|
+
const facing = (l, yaw = BASE.yaw, pitch = BASE.pitch) => ({yaw: yaw - l.x * 0.9, pitch: pitch + l.y * (l.y < 0 ? 0.4 : 0.6), gx: l.x * 0.16, gy: l.y * 0.16});
|
|
24
|
+
const SHOW = ['nod', 'spin', 'wink', 'jump', 'wobble', 'tilt', 'flip', 'dance', 'glance', 'stretch'];
|
|
25
|
+
const PLAY = ['wink', 'wobble', 'spin', 'dance'];
|
|
26
|
+
|
|
27
|
+
export const POSES = {
|
|
28
|
+
// ---- the working day ----
|
|
29
|
+
idle: {pose: (a, t, l) => ({...facing(l), lift: float(t)})},
|
|
30
|
+
listening: {enter: a => a.hop(60), pose: (a, t, l) => ({...facing(l, 0, -0.4), scale: 1.06, roll: 0.07 * sin(t * 0.9), lift: 1.5 * sin(t * 2.4), expr: 'wide'})},
|
|
31
|
+
thinking: {pose: (a, t) => ({yaw: 0.75 * sin(t * 1.15), pitch: 0.2 + 0.08 * sin(t * 2.3), roll: 0.1 * sin(t * 0.8), gx: 0.16 * sin(t * 1.15), gy: -0.2, lift: float(t), rate: 6, orbit: 1})},
|
|
32
|
+
streaming: {pose: (a, t) => ({yaw: 0.25 + 0.3 * sin(t * 1.3), sy: 0.8 + 0.42 * talk(t), lift: float(t), rate: 20, stiff: 700, mark: 'dots'})},
|
|
33
|
+
searching: {pose: (a, t) => { if (a.every(1.1)) a.pulse(); return {yaw: 0.9 * sin(t * 1.6), pitch: -0.2 + 0.12 * sin(t * 0.9), gx: 0.14 * sin(t * 1.6), gy: 0.05 * sin(t * 2.7), lift: float(t), expr: 'inspecting', mark: 'search', rate: 7}; }},
|
|
34
|
+
reading: {pose: (a, t) => { const u = (t * 0.9) % 1, line = Math.floor(t * 0.9) % 3; return {yaw: 0.5 * (u - 0.5), pitch: -0.44 + 0.06 * line, gx: 0.2 * (u - 0.5), gy: 0.1 + 0.04 * line, lift: float(t) * 0.5, rate: 10}; }},
|
|
35
|
+
working: {pose: (a, t) => ({yaw: BASE.yaw + 0.14 * sin(t * 2.2), pitch: -0.5, roll: 0.07 * sin(t * 7), lift: -2.5 * beat(t, 7), gx: 0.14 * sin(t * 3.1), gy: 0.12, expr: 'focus'})},
|
|
36
|
+
coding: {pose: (a, t) => ({yaw: BASE.yaw + 0.1 * sin(t * 1.9), pitch: -0.45, lift: -1.8 * beat(t, 9), sy: 1 - 0.04 * beat(t, 9), gx: 0.1 * sin(t * 2.3), gy: 0.12, expr: 'focus', mark: 'code'})},
|
|
37
|
+
running: {pose: (a, t) => { if (a.every(0.26)) a.emit('dust'); return {yaw: 0.55, pitch: -0.2, roll: 0.14 + 0.05 * sin(t * 14), lift: -7 * beat(t, 7), sy: 1 + 0.08 * sin(t * 14), gx: 0.12, expr: 'focus', rate: 12}; }},
|
|
38
|
+
computing: {pose: (a, t) => ({yaw: BASE.yaw + 0.25 * sin(t * 2), pitch: -0.05, roll: 0.05 * sin(t * 3.3), gy: -0.16, gx: 0.1 * sin(t * 4), lift: float(t), expr: 'focus', orbit: 2.3})},
|
|
39
|
+
controlling: {pose: (a, t) => { if (a.every(0.77)) a.nudge(); const k = Math.floor(t * 1.3), x = sin(k * 12.9898) * 0.9, y = sin(k * 78.233) * 0.6; return {yaw: BASE.yaw + x * 0.7, pitch: -0.26 - y * 0.4, gx: x * 0.15, gy: y * 0.12, lift: float(t), expr: 'focus', mark: 'cursor', rate: 14}; }},
|
|
40
|
+
asking: {enter: a => a.play('tilt'), pose: (a, t, l) => { if (a.every(3.2)) a.hop(70); return {...facing(l, 0.1, -0.3), roll: 0.2 * Math.sign(sin(t * 1.1)), lift: float(t), expr: 'wide', mark: 'ask'}; }},
|
|
41
|
+
blocked: {pose: () => ({yaw: 0.3, pitch: -0.22, sy: 0.55, lift: 12, expr: 'closed', sat: 0.25, rate: 5, stiff: 120})},
|
|
42
|
+
finished: {enter: a => { a.play('spin'); a.hop(150); a.burst('spark', 8); }, pose: (a, t) => ({yaw: 0.3, pitch: -0.3, lift: float(t), expr: 'happy'})},
|
|
43
|
+
error: {enter: a => { a.play('shake'); a.express('cross', 1300); }, pose: () => ({yaw: 0.15, pitch: -0.2, roll: 0.12, sy: 0.9, lift: 5, gy: 0.1, expr: 'sad', sat: 0.6})},
|
|
44
|
+
sleeping: {pose: (a, t) => { if (a.every(1.3)) a.emit('z'); return {yaw: 0.35, pitch: -0.42, roll: 0.14, sy: 0.88 + 0.05 * sin(t * 1.2), lift: 8, expr: 'sleep', sat: 0.85, rate: 3, stiff: 60}; }},
|
|
45
|
+
waking: {enter: a => { a.express('sleepy', 1100); a.play('stretch'); }, pose: (a, t, l) => ({...facing(l), lift: float(t), expr: 'wide'})},
|
|
46
|
+
|
|
47
|
+
// ---- moods ----
|
|
48
|
+
happy: {pose: (a, t, l) => ({...facing(l), lift: -3 * beat(t, 3.2), roll: 0.08 * sin(t * 3.2), expr: 'happy', blush: 0.5})},
|
|
49
|
+
excited: {enter: a => a.hop(120), pose: (a, t, l) => { if (a.every(1.6)) a.burst('spark', 4); return {...facing(l, 0.2, -0.32), lift: -7 * beat(t, 6), sy: 1 + 0.07 * sin(t * 12), scale: 1.06, expr: 'sparkle', blush: 0.4}; }},
|
|
50
|
+
laughing: {pose: (a, t) => ({yaw: BASE.yaw, pitch: -0.5, lift: -2.5 * beat(t, 11), sy: 1 + 0.07 * sin(t * 22), roll: 0.06 * sin(t * 5), expr: 'happy', blush: 0.6, stiff: 700, rate: 14})},
|
|
51
|
+
proud: {pose: (a, t) => { if (a.every(2.2)) a.burst('spark', 3); return {yaw: 0.35, pitch: -0.55, sy: 1.07, scale: 1.06, lift: float(t) * 0.5, expr: 'calm', blush: 0.3}; }},
|
|
52
|
+
curious: {pose: (a, t, l) => ({...facing(l, 0.1, -0.3), roll: 0.22 * Math.sign(sin(t * 0.8)), scale: 1.07, lift: float(t), expr: 'inspecting'})},
|
|
53
|
+
playful: {pose: (a, t, l) => { if (a.every(2.4)) a.play(PLAY[a.beat++ % PLAY.length]); return {...facing(l), roll: 0.16 * sin(t * 2.6), lift: -4 * beat(t, 2.6), expr: 'happy'}; }},
|
|
54
|
+
shy: {pose: (a, t) => ({yaw: 0.75, pitch: 0.05, roll: -0.08, scale: 0.94, gx: 0.12, gy: 0.14, lift: 3 + float(t) * 0.4, expr: 'shy', blush: 1, rate: 5})},
|
|
55
|
+
surprised: {enter: a => a.play('startle'), pose: (a, t, l) => ({...facing(l, 0.2, -0.4), scale: 1.08, sy: 1.06, lift: -2, expr: 'surprised'})},
|
|
56
|
+
suspicious: {pose: (a, t) => ({yaw: 0.6, pitch: -0.2, roll: -0.1, gx: -0.16, gy: 0.02 * sin(t), lift: float(t) * 0.5, expr: 'skeptic', rate: 4})},
|
|
57
|
+
angry: {pose: (a, t, l) => { if (a.every(1.5)) a.squash(2); return {...facing(l, 0.15, -0.2), roll: 0.035 * sin(t * 38), sy: 0.94, scale: 1.04, lift: 2, expr: 'angry', mark: 'anger', rate: 12}; }},
|
|
58
|
+
confused: {pose: (a, t) => ({yaw: 0.5 * sin(t * 0.9), pitch: -0.2, roll: 0.2 * sin(t * 0.9 + 1), gx: 0.1 * sin(t * 1.8), lift: float(t), expr: 'confused', mark: 'ask'})},
|
|
59
|
+
sad: {pose: a => { if (a.every(2.4)) a.emit('tear'); return {yaw: 0.15, pitch: 0.12, sy: 0.92, lift: 6, gy: 0.14, roll: -0.06, expr: 'sad', sat: 0.7, rate: 4, stiff: 120}; }},
|
|
60
|
+
drowsy: {pose: (a, t) => { const u = (t * 0.35) % 1, nod = u < 0.8 ? smooth(u / 0.8) : 1 - smooth((u - 0.8) / 0.2); return {yaw: 0.25, pitch: -0.3 + 0.5 * nod, roll: 0.12 * nod, lift: 3 + 4 * nod, expr: 'sleepy', sat: 0.9, rate: 8}; }},
|
|
61
|
+
bored: {pose: (a, t) => { if (a.every(4)) a.squash(1.5); return {yaw: 0.5, pitch: -0.15, roll: 0.2, sy: 0.94 + 0.03 * sin(t * 0.8), lift: 5, gx: 0.15 * sin(t * 0.4), gy: -0.1, expr: 'sleepy', rate: 3, stiff: 80}; }},
|
|
62
|
+
scared: {pose: (a, t) => ({yaw: -0.3, pitch: -0.38, roll: 0.03 * sin(t * 45), sy: 0.9, scale: 0.92, lift: 3, gx: 0.1 * sin(t * 7), gy: -0.05, expr: 'surprised', sat: 0.8, mark: 'sweat', rate: 14})},
|
|
63
|
+
celebrating: {enter: a => { a.play('jump'); a.burst('confetti', 14); }, pose: (a, t) => { if (a.every(1.15)) { a.play(a.beat++ % 2 ? 'jump' : 'spin'); a.burst('confetti', 10); } return {yaw: 0.25, pitch: -0.3, lift: float(t), expr: 'sparkle'}; }},
|
|
64
|
+
approving: {enter: a => a.play('nod'), pose: (a, t, l) => { if (a.every(1.7)) a.play('nod'); return {...facing(l), lift: float(t), expr: 'happy', mark: 'check'}; }},
|
|
65
|
+
loving: {pose: (a, t, l) => { if (a.every(0.9)) a.emit('heart'); return {...facing(l, 0.15, -0.3), roll: 0.1 * sin(t * 2), lift: -2 * beat(t, 2), scale: 1.04, expr: 'love', blush: 0.8}; }},
|
|
66
|
+
|
|
67
|
+
// ---- signals: what is going on, shown with something around the body ----
|
|
68
|
+
orbit: {pose: (a, t) => ({yaw: BASE.yaw + 0.3 * sin(t * 1.3), gx: 0.14 * Math.cos(t * 2.6), gy: 0.08 * sin(t * 2.6), lift: float(t), orbit: 1.6})},
|
|
69
|
+
radar: {pose: (a, t) => { if (a.every(0.9)) a.pulse(); return {yaw: 1.0 * sin(t * 1.1), pitch: -0.3, lift: float(t), expr: 'wide', rate: 8}; }},
|
|
70
|
+
progress: {pose: (a, t, l) => ({...facing(l, 0.2, -0.3), lift: float(t) * 0.5, expr: 'focus', ring: 'progress'})},
|
|
71
|
+
loading: {pose: (a, t) => ({yaw: BASE.yaw + 0.15 * sin(t * 2), lift: float(t), gy: -0.08, ring: 'spin'})},
|
|
72
|
+
spawning: {enter: a => { a.p.scale = 0.15; a.vel.scale = 0; for (let i = 0; i < 8; i++) a.emit('in'); }, pose: (a, t) => { if (a.every(0.2) && a.since < 2.4) a.emit('in'); return {scale: Math.min(1, 0.3 + a.since * 0.32), yaw: BASE.yaw + Math.max(0, 2.4 - a.since) * 1.2, lift: float(t), expr: a.since < 1.6 ? 'closed' : 'wide', rate: 12}; }},
|
|
73
|
+
dictating: {pose: (a, t) => ({yaw: BASE.yaw + 0.2 * sin(t * 1.1), sy: 0.92 + 0.2 * talk(t), lift: float(t), expr: 'calm', bars: true, rate: 20, stiff: 700})},
|
|
74
|
+
sending: {pose: (a, t) => { if (a.every(0.2)) a.emit('out'); return {yaw: 0.45, pitch: -0.45, lift: float(t) - 2, gx: 0.1, gy: -0.15, expr: 'focus'}; }},
|
|
75
|
+
receiving: {pose: (a, t) => { if (a.every(0.13)) a.emit('in'); return {yaw: BASE.yaw + 0.1 * sin(t * 2), pitch: -0.35, scale: 1 + 0.03 * sin(t * 9), lift: float(t), expr: 'wide'}; }},
|
|
76
|
+
uploading: {pose: (a, t) => { if (a.every(0.28)) a.emit('up'); return {yaw: BASE.yaw, pitch: -0.5, gy: -0.18, sy: 1.05, lift: -2 + float(t), mark: 'up'}; }},
|
|
77
|
+
writing: {pose: (a, t) => { const u = (t * 0.7) % 1; return {yaw: -0.15 + 0.4 * u, pitch: -0.5, gx: 0.18 * (u - 0.5), gy: 0.15, lift: -1.2 * beat(t, 8), expr: 'focus', mark: 'pen'}; }},
|
|
78
|
+
alerting: {enter: a => a.play('startle'), pose: (a, t, l) => { if (a.every(1.3)) a.play('startle'); return {...facing(l, 0.2, -0.3), scale: 1.05, lift: float(t), expr: 'wide', mark: 'bang'}; }},
|
|
79
|
+
bouncing: {enter: a => a.play('jump'), pose: (a, t, l) => { if (a.every(0.85)) a.play('jump'); return {...facing(l), expr: 'happy'}; }},
|
|
80
|
+
'powering-down': {pose: () => ({yaw: 0.3, pitch: 0.1, sy: 0.7, scale: 0.82, lift: 14, expr: 'closed', sat: 0.12, rate: 2, stiff: 40, still: true})},
|
|
81
|
+
|
|
82
|
+
// ---- product moments ----
|
|
83
|
+
humming: {pose: (a, t) => { if (a.every(0.6)) a.emit('note'); return {yaw: BASE.yaw + 0.25 * sin(t * 1.5), roll: 0.14 * sin(t * 3), lift: -2 * beat(t, 3), expr: 'calm', blush: 0.3}; }},
|
|
84
|
+
notifying: {enter: a => a.hop(110), pose: (a, t, l) => { if (a.every(2)) a.hop(110); return {...facing(l), scale: 1.03, lift: float(t), expr: 'wide', mark: 'badge'}; }},
|
|
85
|
+
dragging: {pose: (a, t) => ({yaw: BASE.yaw + 0.3 * sin(t * 2.3), pitch: -0.1, roll: 0.25 * sin(t * 3.1), sy: 1.16, lift: -8, expr: 'surprised', stiff: 120})},
|
|
86
|
+
greeting: {enter: a => { a.hop(120); a.play('wave'); }, pose: (a, t, l) => { if (a.every(2.6)) a.play('wave'); return {...facing(l, 0.1, -0.3), lift: float(t), scale: 1.04, expr: 'happy'}; }},
|
|
87
|
+
|
|
88
|
+
// ---- showing it off ----
|
|
89
|
+
logo: {pose: () => ({yaw: 0.5, pitch: -0.32, rate: 6, still: true})},
|
|
90
|
+
showcase: {pose: (a, t, l) => { if (a.every(1.8)) a.play(SHOW[a.beat++ % SHOW.length]); return {...facing(l), lift: float(t)}; }},
|
|
91
|
+
turntable: {pose: (a, t) => ({yaw: t * 1.3, pitch: -0.3, rate: 30})},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// `move(u, g)` adds this gesture's offsets at progress u (0..1) to g.
|
|
95
|
+
export const GESTURES = {
|
|
96
|
+
nod: {zh: '点头', dur: 0.7, move: (u, g) => { g.pitch -= 0.38 * sin(u * TAU * 2) * (1 - u); }},
|
|
97
|
+
shake: {zh: '摇头', dur: 0.75, move: (u, g) => { g.yaw += 0.55 * sin(u * TAU * 2.5) * (1 - u); }},
|
|
98
|
+
tilt: {zh: '歪头', dur: 1.3, move: (u, g) => { g.roll += 0.32 * smooth(Math.min(1, u * 4)) * smooth(Math.min(1, (1 - u) * 4)); }},
|
|
99
|
+
glance: {zh: '张望', dur: 1.6, move: (u, g) => { g.yaw += 0.8 * sin(u * TAU) * Math.sqrt(bump(u)); g.gx += 0.12 * sin(u * TAU); }},
|
|
100
|
+
wink: {zh: '眨眼', dur: 0.6, expr: 'wink', move: (u, g) => { g.roll += 0.12 * bump(u); }},
|
|
101
|
+
wave: {zh: '招手', dur: 1.1, expr: 'happy', move: (u, g) => { g.roll += 0.3 * sin(u * TAU * 3) * Math.sqrt(bump(u)); g.lift -= 4 * bump(u); }},
|
|
102
|
+
bow: {zh: '鞠躬', dur: 1.2, expr: 'closed', move: (u, g) => { g.pitch += 0.75 * bump(u) ** 2; g.sy -= 0.08 * bump(u); }},
|
|
103
|
+
spin: {zh: '转圈', dur: 0.75, move: (u, g) => { g.yaw += TAU * smooth(u); g.sy += 0.1 * bump(u); }},
|
|
104
|
+
flip: {zh: '空翻', dur: 0.85, expr: 'happy', move: (u, g) => { g.pitch -= TAU * smooth(u); g.lift -= 13 * bump(u); }, end: a => a.squash(3)},
|
|
105
|
+
roll: {zh: '侧翻', dur: 0.9, expr: 'happy', move: (u, g) => { g.roll += TAU * smooth(u); g.lift -= 9 * bump(u); }, end: a => a.squash(2)},
|
|
106
|
+
jump: {zh: '跳', dur: 0.8, expr: 'happy', move: (u, g) => { if (u < 0.22) { g.sy -= 0.28 * bump(u / 0.22); return; } const v = (u - 0.22) / 0.78; g.lift -= 72 * v * (1 - v); g.sy += 0.14 * bump(v * 2); }, end: a => a.squash(4)},
|
|
107
|
+
bounce: {zh: '弹一下', dur: 0.5, start: a => { a.hop(170); a.squash(3); }, move: () => {}},
|
|
108
|
+
wobble: {zh: '果冻', dur: 0.9, start: a => a.squash(5), move: (u, g) => { g.roll += 0.16 * sin(u * TAU * 3) * (1 - u); }},
|
|
109
|
+
shiver: {zh: '发抖', dur: 0.9, expr: 'squint', move: (u, g) => { g.roll += 0.05 * sin(u * 60) * bump(u); g.sy -= 0.06 * bump(u); }},
|
|
110
|
+
startle: {zh: '一惊', dur: 0.5, expr: 'surprised', move: (u, g) => { g.lift -= 9 * (1 - u) ** 2; g.scale += 0.14 * (1 - u); }},
|
|
111
|
+
stretch: {zh: '伸懒腰', dur: 1.2, expr: 'closed', move: (u, g) => { g.sy += 0.36 * bump(u) ** 2 - 0.12 * bump(Math.min(1, u * 5)); g.pitch += 0.25 * bump(u); g.roll += 0.08 * sin(u * TAU); }},
|
|
112
|
+
dance: {zh: '跳舞', dur: 2.4, expr: 'happy', move: (u, g) => { const e = Math.sqrt(bump(u)); g.roll += 0.22 * sin(u * TAU * 4) * e; g.lift -= 6 * Math.abs(sin(u * TAU * 4)) * e; g.yaw += 0.5 * sin(u * TAU * 2) * e; }},
|
|
113
|
+
};
|
|
114
|
+
export const FIDGETS = ['tilt', 'glance', 'wink', 'stretch', 'nod'];
|