Skip to content

Turn one illustration into an animated 2D mesh avatar with a coding agent and a local editor

Document mouth-movement settings and refresh screenshots

shinshin8653e5edd2096b
diff --git a/README.ja.md b/README.ja.md
index 256c12c..d87cf73 100644
--- a/README.ja.md
+++ b/README.ja.md
@@ -54,7 +54,7 @@ npm run dev
### 2. プロジェクトを開いて確認する
-エディタを起動し(`npm run dev`)、「プロジェクトを開く」の一覧から作ったプロジェクトを選びます。プレビューの「ポーズ確認」で顔の向きや傾き、目の開閉を、「口の動き」で母音ごとの口の形を確かめます。
+エディタを起動し(`npm run dev`)、「プロジェクトを開く」の一覧から作ったプロジェクトを選びます。「ポーズ確認」で顔の向きや傾き、目の開閉を確かめ、「口の動き」では「ゆったり」「キビキビ」などを選んで口パクを試します。「細かく調整する」で口の大きさや閉じ方を調整し、音声ファイルでも確認できます。
![口の動きの確認](docs/images/ja/03-lip-sync.png)
diff --git a/README.md b/README.md
index f154adf..7ceabce 100644
--- a/README.md
+++ b/README.md
@@ -75,8 +75,9 @@ Recommended setups:
### 2. Open the project and check it
Start the editor (`npm run dev`), choose **Open project** and pick your project from the list.
-In the preview, use **Pose test** to turn and tilt the head and close the eyes, and
-**Lip sync** to check the vowel mouth shapes.
+In the preview, use **Pose test** to turn and tilt the head and close the eyes. In **Lip sync**,
+choose a mouth style and try it with kana text. Open **Fine-tune** to adjust movement, size
+and closing, or preview a local audio file.
![Lip sync check](docs/images/en/03-lip-sync.png)
diff --git a/docs/images/en/01-overview.png b/docs/images/en/01-overview.png
index 1aa7f2d..9e44b11 100644
Binary files a/docs/images/en/01-overview.png and b/docs/images/en/01-overview.png differ
diff --git a/docs/images/en/02-edit-handles.png b/docs/images/en/02-edit-handles.png
index 35d1c4d..58e7c8d 100644
Binary files a/docs/images/en/02-edit-handles.png and b/docs/images/en/02-edit-handles.png differ
diff --git a/docs/images/en/03-lip-sync.png b/docs/images/en/03-lip-sync.png
index 23da4c0..2877104 100644
Binary files a/docs/images/en/03-lip-sync.png and b/docs/images/en/03-lip-sync.png differ
diff --git a/docs/images/en/04-rebuild.png b/docs/images/en/04-rebuild.png
index f8f61cf..19af4bc 100644
Binary files a/docs/images/en/04-rebuild.png and b/docs/images/en/04-rebuild.png differ
diff --git a/docs/images/en/05-variants.png b/docs/images/en/05-variants.png
index 62d6f26..ecc2c28 100644
Binary files a/docs/images/en/05-variants.png and b/docs/images/en/05-variants.png differ
diff --git a/docs/images/en/06-new-project.png b/docs/images/en/06-new-project.png
index f04545f..3a254de 100644
Binary files a/docs/images/en/06-new-project.png and b/docs/images/en/06-new-project.png differ
diff --git a/docs/images/ja/01-overview.png b/docs/images/ja/01-overview.png
index b267ddb..1fbfabf 100644
Binary files a/docs/images/ja/01-overview.png and b/docs/images/ja/01-overview.png differ
diff --git a/docs/images/ja/02-edit-handles.png b/docs/images/ja/02-edit-handles.png
index 02f0359..6a8ead2 100644
Binary files a/docs/images/ja/02-edit-handles.png and b/docs/images/ja/02-edit-handles.png differ
diff --git a/docs/images/ja/03-lip-sync.png b/docs/images/ja/03-lip-sync.png
index 932bcd5..fbf0839 100644
Binary files a/docs/images/ja/03-lip-sync.png and b/docs/images/ja/03-lip-sync.png differ
diff --git a/docs/images/ja/04-rebuild.png b/docs/images/ja/04-rebuild.png
index 62dcfa8..7f50be5 100644
Binary files a/docs/images/ja/04-rebuild.png and b/docs/images/ja/04-rebuild.png differ
diff --git a/docs/images/ja/05-variants.png b/docs/images/ja/05-variants.png
index 9bebfeb..4836bae 100644
Binary files a/docs/images/ja/05-variants.png and b/docs/images/ja/05-variants.png differ
diff --git a/docs/images/ja/06-new-project.png b/docs/images/ja/06-new-project.png
index 16b9f80..e2bdd54 100644
Binary files a/docs/images/ja/06-new-project.png and b/docs/images/ja/06-new-project.png differ
diff --git a/e2e/embed-demo.spec.ts b/e2e/embed-demo.spec.ts
index c3d525f..a266065 100644
--- a/e2e/embed-demo.spec.ts
+++ b/e2e/embed-demo.spec.ts
@@ -25,6 +25,38 @@ test.beforeEach(async ({ context, page }) => {
});
test.afterEach(({ page }) => { expect(outside.get(page) ?? []).toEqual([]); });
+async function checkMouthStyles(page: Page, language = 'en') {
+ const selector = page.getByRole('combobox', { name: language === 'ja' ? '口の動きのタイプ' : 'Mouth style', exact: true });
+ await expect(selector).toHaveValue('default');
+ await expect(selector.locator('option:not([disabled])')).toHaveText(language === 'ja'
+ ? ['ゆったり', '標準', 'キビキビ', '控えめ', 'はっきり']
+ : ['Relaxed', 'Standard', 'Snappy', 'Subtle', 'Expressive']);
+ expect(await page.evaluate(() => document.querySelector('mesh-avatar')!.lipSync)).toEqual({});
+ const styles = {
+ calm: { granularity: 0, openness: 0.5, closeSpeed: 0 },
+ default: { granularity: 0.5, openness: 0.5, closeSpeed: 0.5 },
+ lively: { granularity: 1, openness: 0.5, closeSpeed: 1 },
+ subtle: { granularity: 0.5, openness: 0, closeSpeed: 0.5 },
+ big: { granularity: 0.5, openness: 1, closeSpeed: 0.5 },
+ };
+ for (const [name, settings] of Object.entries(styles)) {
+ await selector.selectOption(name);
+ expect(await page.evaluate(() => document.querySelector('mesh-avatar')!.lipSync)).toEqual(settings);
+ if (name === 'subtle' || name === 'big') {
+ const opening = await page.evaluate(() => {
+ const el = document.querySelector('mesh-avatar')!, avatar = el.avatar!;
+ el.paused = true; avatar.holdMouth('a');
+ for (let i = 0; i < 60; i++) avatar.advance(1 / 60);
+ const value = avatar.getParameters().mouthOpen;
+ avatar.stopLipSync(); el.paused = false;
+ return value;
+ });
+ if (name === 'subtle') { expect(opening).toBeGreaterThan(0.45); expect(opening).toBeLessThan(0.55); }
+ else expect(opening).toBeGreaterThan(0.95);
+ }
+ }
+}
+
for (const language of ['en', 'ja']) {
test(`embed demo works in ${language} without outside requests`, async ({ page }) => {
const errors: string[] = [];
@@ -32,6 +64,8 @@ for (const language of ['en', 'ja']) {
await page.goto(`${site}${language === 'ja' ? 'ja/' : ''}embed/`);
await expect(page.locator('#status')).toHaveAttribute('data-state', 'ready');
await expect(page.locator('html')).toHaveAttribute('lang', language);
+ await checkMouthStyles(page, language);
+ await expect(page.locator('#mouth-style-code')).toContainText('el.setLipSync({ granularity: 0.5, openness: 1, closeSpeed: 0.5 });');
const image = PNG.sync.read(await page.locator('mesh-avatar canvas').screenshot({ omitBackground: true }));
expect(image.data.some((value, index) => index % 4 === 3 && value > 0)).toBe(true);
await page.locator('[data-expression="smile"]').click();
@@ -58,6 +92,7 @@ for (const language of ['en', 'ja']) {
});
await expect(page.locator('#status')).toHaveAttribute('data-state', 'ready');
await expect(page.locator('#source-name')).toHaveText('chosen.mavatar');
+ await expect(page.locator('#mouth-style')).toHaveValue('big');
await expect(page.locator('#selected-file')).toContainText('chosen.mavatar');
await expect(page.locator('#file-code')).toHaveText('<mesh-avatar src="/path/to/your-avatar.mavatar"></mesh-avatar>');
expect(await page.evaluate(() => document.querySelector('mesh-avatar')!.avatar !== Reflect.get(window, 'previousAvatar'))).toBe(true);
@@ -94,6 +129,7 @@ for (const example of ['basic', 'playground']) {
await expect.poll(() => page.evaluate(() => !!document.querySelector('mesh-avatar')?.avatar)).toBe(true);
if (example === 'playground') {
await expect(page.locator('#status')).toHaveAttribute('data-state', 'ready');
+ await checkMouthStyles(page);
await page.locator('[data-expression="wink"]').click();
expect(await page.evaluate(() => document.querySelector('mesh-avatar')!.avatar!.getExpression().name)).toBe('wink');
await page.locator('#avatar-file').setInputFiles({ name: 'chosen.mavatar', mimeType: 'application/octet-stream', buffer: archive });
diff --git a/packages/element/README.md b/packages/element/README.md
index 864d889..a6dcd57 100644
--- a/packages/element/README.md
+++ b/packages/element/README.md
@@ -88,6 +88,8 @@ el.avatar.setExpression('smile');
| `load(source)` | Loads a File, Blob, ArrayBuffer, Uint8Array, URL or URL string without changing `src`. Returns the loading promise and emits `load` or `error`. The `AvatarSource` type is re-exported from `mesh-avatar`. |
| `ready` | Promise resolving with the avatar for the current source, rejecting on loading failure. A new load after completion creates a new promise; overlapping pending loads resolve with the latest avatar. |
| `src`, `fit`, `expression`, `emotion`, `paused` | Properties reflecting their corresponding attributes. Use attributes for `no-idle` and `label`. |
+| `lipSync` | Get a copy of explicit mouth-movement overrides, or assign a partial `LipSyncSettings` object. Overrides survive avatar reloads. |
+| `setLipSync(settings)` | Partially updates mouth movement: `granularity`, `openness`, `closeSpeed` (0–1). Omitted fields keep their values. |
| `setVoiceLevel(value)` | Mouth opening from loudness, 0–1. Retains the value until loading finishes. |
| `speak(text, options?)` | Calls `speakKana` after loading. Japanese text animates the mouth without generating audio. Options: `speed`, `loop`. |
| `play(id)` | Plays a runtime motion after loading. Available IDs are in `el.avatar.motions`. |
@@ -135,6 +137,23 @@ Download either HTML example and open it directly, or serve it on your site. Bot
Each example below assumes the CDN script and a `<mesh-avatar>` element are on your page. Run JavaScript as a module.
+### Mouth movement
+
+Use `lipSync` or `setLipSync` to adjust syllable separation, mouth size and closing speed.
+Each setting accepts 0–1; 0.5 keeps the original behavior. Settings saved in Studio apply
+automatically when the avatar loads. Explicit overrides work before loading and survive
+source or fit changes. `LipSyncSettings` is exported as a TypeScript type.
+
+```js
+await customElements.whenDefined('mesh-avatar');
+const el = document.querySelector('mesh-avatar');
+el.lipSync = { granularity: 0, closeSpeed: 0 };
+el.setLipSync({ openness: 0.75 }); // Retains the other settings.
+```
+
+See the [runtime style table](https://github.com/shinshin86/mesh-avatar-studio/tree/main/packages/runtime#mouth-movement)
+for the five Studio styles. These settings apply to text and audio lip sync below.
+
### Audio file or TTS audio
Replace `/voice.mp3` with an audio file or a URL returned by your TTS service. Cross-origin audio needs CORS headers. Click the button to start playback.
diff --git a/packages/element/examples/playground.html b/packages/element/examples/playground.html
index 81e65dc..e1101da 100644
--- a/packages/element/examples/playground.html
+++ b/packages/element/examples/playground.html
@@ -98,6 +98,12 @@ footer { padding-block: 24px; font-size: 13px; line-height: 1.7; }
</section>
<section class="control-panel">
<h2>Text lip sync</h2>
+ <label for="mouth-style">Mouth style</label>
+ <select id="mouth-style">
+ <option value="" disabled hidden>Custom</option>
+ <option value="calm">Relaxed</option><option value="default" selected>Standard</option>
+ <option value="lively">Snappy</option><option value="subtle">Subtle</option><option value="big">Expressive</option>
+ </select>
<form id="speech-form">
<label for="speech-text">Japanese text</label>
<input id="speech-text" type="text" value="こんにちは" maxlength="300">
@@ -125,6 +131,15 @@ import 'https://cdn.jsdelivr.net/npm/mesh-avatar-element@0/dist/standalone.js';
// Kept inline in the standalone example so it can also open directly from disk.
function setupPlayground(root, { sampleURL }) {
const el = root.querySelector('mesh-avatar');
+ const mouthStyles = {
+ calm: { granularity: 0, openness: 0.5, closeSpeed: 0 },
+ default: { granularity: 0.5, openness: 0.5, closeSpeed: 0.5 },
+ lively: { granularity: 1, openness: 0.5, closeSpeed: 1 },
+ subtle: { granularity: 0.5, openness: 0, closeSpeed: 0.5 },
+ big: { granularity: 0.5, openness: 1, closeSpeed: 0.5 },
+ };
+ const mouthStyle = root.querySelector('#mouth-style');
+
const status = root.querySelector('#status');
const sourceName = root.querySelector('#source-name');
const controls = root.querySelector('#avatar-controls');
@@ -188,6 +203,11 @@ function setupPlayground(root, { sampleURL }) {
}
function ready() {
+ const settings = { granularity: 0.5, openness: 0.5, closeSpeed: 0.5,
+ ...el.avatar?.package?.manifest.lipSync, ...el.lipSync };
+ mouthStyle.value = Object.keys(mouthStyles).find(name =>
+ Object.keys(mouthStyles[name]).every(key => mouthStyles[name][key] === settings[key])) ?? '';
+
status.textContent = root.dataset.ready;
status.dataset.state = 'ready';
controls.disabled = false;
@@ -210,6 +230,9 @@ function setupPlayground(root, { sampleURL }) {
}
});
}
+ mouthStyle.addEventListener('change', () => {
+ el.setLipSync(mouthStyles[mouthStyle.value]);
+ });
root.querySelector('#emotion').addEventListener('change', event => {
el.emotion = event.target.value || null;
});
diff --git a/packages/react/README.md b/packages/react/README.md
index 7262d38..05f9489 100644
--- a/packages/react/README.md
+++ b/packages/react/README.md
@@ -87,6 +87,7 @@ export function SpeakingCharacter() {
return <>
<MeshAvatar ref={ref} style={{ width: 320 }} />
<button onClick={() => ref.current?.avatar?.setExpression('smile')}>Smile</button>
+ <button onClick={() => ref.current?.setLipSync({ granularity: 1, openness: 0.5, closeSpeed: 1 })}>Snappy mouth</button>
<button onClick={() => void ref.current?.speak('こんにちは').catch(console.error)}>Animate speech</button>
</>;
}
@@ -94,6 +95,12 @@ export function SpeakingCharacter() {
`speak(text, { speed, loop })` animates Japanese mouth shapes without generating audio. `play(id)` plays a motion and waits for loading. `load(source)` loads an imperative source, returning the loading promise.
+Use `ref.current?.setLipSync(...)` for mouth-movement settings; there is no separate prop.
+`granularity` controls syllable separation, `openness` controls mouth size and `closeSpeed`
+controls closing speed (each 0–1, default 0.5). Updates retain omitted values and survive
+avatar reloads. Settings saved in Studio are applied automatically. See the
+[runtime style table](https://github.com/shinshin86/mesh-avatar-studio/tree/main/packages/runtime#mouth-movement).
+
### Audio file or TTS audio
Use `setVoiceLevel` through the ref for per-frame mouth movement. Replace `/voice.mp3` with an audio file or a TTS audio URL. Cross-origin audio needs CORS headers. This example starts playback from a button and cleans up on unmount.
diff --git a/packages/runtime/README.md b/packages/runtime/README.md
index 54a1bad..7b0140b 100644
--- a/packages/runtime/README.md
+++ b/packages/runtime/README.md
@@ -88,6 +88,38 @@ Emotion tags are `happy`, `sad`, `angry`, `surprised`, `relaxed` and `neutral` (
For custom loading or tooling, the package also exports `createMeshAvatar`, `openAvatar`, `packAvatar`, `unpackAvatar`, `validateAvatarFiles`, `parseManifest`, `parseRig`, `validateRig` and lighting settings. See the [avatar format reference](https://github.com/shinshin86/mesh-avatar-studio/blob/main/docs/format.md) for archive contents, validation and compatibility rules.
+## Mouth movement
+
+Three optional settings control audio loudness lip sync and kana previews. `granularity`
+changes how readily the mouth separates syllables, `openness` changes the opening amount,
+and `closeSpeed` changes how quickly it closes. Each accepts a finite value from 0 to 1;
+0.5 preserves the existing behavior.
+
+The Studio's five styles use these values:
+
+| Style | `granularity` | `openness` | `closeSpeed` |
+| --- | --- | --- | --- |
+| Relaxed | 0 | 0.5 | 0 |
+| Standard | 0.5 | 0.5 | 0.5 |
+| Snappy | 1 | 0.5 | 1 |
+| Subtle | 0.5 | 0 | 0.5 |
+| Expressive | 0.5 | 1 | 0.5 |
+
+If your app already supplies a rig and built assets, pass `lipSync` when creating the avatar:
+
+```ts
+import { createMeshAvatar, type LipSyncSettings } from 'mesh-avatar';
+
+const lipSync: LipSyncSettings = { granularity: 0, openness: 0.5, closeSpeed: 0 };
+const avatar = await createMeshAvatar(canvas, { rig, assets, lipSync });
+avatar.setLipSync({ openness: 0.75 }); // Other settings keep their current values.
+```
+
+Avatars saved or exported in Studio carry these settings in `avatar.json.lipSync`.
+`loadMeshAvatar` applies them automatically; explicit `options.lipSync` fields override the
+saved values. `setLipSync` is a partial update and works during playback. The optional
+`preset` field records the editor selection only; playback uses the three numbers.
+
## License
The runtime is MIT licensed; see [LICENSE](./LICENSE). The browser bundle includes [fflate](https://github.com/101arrowz/fflate), with its MIT notice retained in the bundle.
diff --git a/site/embed/index.html b/site/embed/index.html
index 2da8d11..cf2cbe6 100644
--- a/site/embed/index.html
+++ b/site/embed/index.html
@@ -65,6 +65,17 @@
<pre tabindex="0"><code id="expression-code">&lt;mesh-avatar&gt;&lt;/mesh-avatar&gt;</code></pre>
</div>
</section>
+ <section class="control-panel">
+ <div class="embed-demo-controls">
+ <h2 id="mouth-style-label"></h2>
+ <select id="mouth-style" aria-labelledby="mouth-style-label" aria-describedby="mouth-style-hint"></select>
+ <p id="mouth-style-hint" class="hint"></p>
+ </div>
+ <div class="code-card">
+ <div class="code-heading"><h3>JavaScript</h3><button type="button" class="copy-button" data-copy="mouth-style-code" data-copied="Copied">Copy</button></div>
+ <pre tabindex="0"><code id="mouth-style-code"></code></pre>
+ </div>
+ </section>
<section class="control-panel">
<div class="embed-demo-controls">
<h2>Text lip sync</h2>
diff --git a/site/index.html b/site/index.html
index 07a38c3..bed57b2 100644
--- a/site/index.html
+++ b/site/index.html
@@ -137,10 +137,10 @@
<div class="step-copy">
<span class="step-number" aria-hidden="true">02</span>
<h3>Review the motion</h3>
- <p>Open the project in Studio. Use <strong>Pose test</strong> to turn the head and close the eyes, then <strong>Lip sync</strong> to check the mouth shapes.</p>
+ <p>Open the project in Studio. Use <strong>Pose test</strong> to turn the head and close the eyes, then choose a mouth style in <strong>Lip sync</strong>. Open <strong>Fine-tune</strong> to adjust it or try an audio file.</p>
</div>
<figure class="screenshot">
- <a class="screenshot-link" aria-label="View the lip sync screenshot at full size"><img data-screenshot="lipSync" width="1440" height="900" loading="lazy" decoding="async" alt="The editor’s Lip sync panel with vowel buttons and the avatar’s mouth open in the preview." /></a>
+ <a class="screenshot-link" aria-label="View the lip sync screenshot at full size"><img data-screenshot="lipSync" width="1440" height="900" loading="lazy" decoding="async" alt="The editor’s Lip sync tab with five mouth styles, Expressive selected and the avatar’s mouth open in the preview." /></a>
<figcaption>Check poses and speech before exporting.</figcaption>
</figure>
</li>
diff --git a/site/ja/embed/index.html b/site/ja/embed/index.html
index 1d6ad07..c03646f 100644
--- a/site/ja/embed/index.html
+++ b/site/ja/embed/index.html
@@ -65,6 +65,17 @@
<pre tabindex="0"><code id="expression-code">&lt;mesh-avatar&gt;&lt;/mesh-avatar&gt;</code></pre>
</div>
</section>
+ <section class="control-panel">
+ <div class="embed-demo-controls">
+ <h2 id="mouth-style-label"></h2>
+ <select id="mouth-style" aria-labelledby="mouth-style-label" aria-describedby="mouth-style-hint"></select>
+ <p id="mouth-style-hint" class="hint"></p>
+ </div>
+ <div class="code-card">
+ <div class="code-heading"><h3>JavaScript</h3><button type="button" class="copy-button" data-copy="mouth-style-code" data-copied="コピー済み">コピー</button></div>
+ <pre tabindex="0"><code id="mouth-style-code"></code></pre>
+ </div>
+ </section>
<section class="control-panel">
<div class="embed-demo-controls">
<h2>文章で口を動かす</h2>
diff --git a/site/ja/index.html b/site/ja/index.html
index 8d15a48..04106e6 100644
--- a/site/ja/index.html
+++ b/site/ja/index.html
@@ -137,10 +137,10 @@
<div class="step-copy">
<span class="step-number" aria-hidden="true">02</span>
<h3>動きを確認する</h3>
- <p>Studio でプロジェクトを開きます。<strong>「ポーズ確認」</strong>で顔の向きや目の開閉を、<strong>「口の動き」</strong>で母音ごとの口の形を確かめます。</p>
+ <p>Studio でプロジェクトを開きます。<strong>「ポーズ確認」</strong>で顔の向きや目の開閉を、<strong>「口の動き」</strong>でタイプを選んで口パクを試します。「細かく調整する」で調整したり、音声ファイルで試したりできます。</p>
</div>
<figure class="screenshot">
- <a class="screenshot-link" aria-label="口の動きを確認する画面を原寸で開く"><img data-screenshot="lipSync" width="1440" height="900" loading="lazy" decoding="async" alt="母音のボタンが並ぶ「口の動き」の欄と、口を開けたアバターのプレビュー。" /></a>
+ <a class="screenshot-link" aria-label="口の動きを確認する画面を原寸で開く"><img data-screenshot="lipSync" width="1440" height="900" loading="lazy" decoding="async" alt="5つのタイプから「はっきり」を選んだ「口の動き」の欄と、口を開けたアバターのプレビュー。" /></a>
<figcaption>書き出す前に、ポーズと口の形を確認します。</figcaption>
</figure>
</li>
diff --git a/site/src/embed/main.ts b/site/src/embed/main.ts
index 35a4994..ad1bbea 100644
--- a/site/src/embed/main.ts
+++ b/site/src/embed/main.ts
@@ -2,6 +2,7 @@ import '../../../packages/element/src/index';
import { DEFAULT_SRC } from '../../../packages/element/src/attributes';
import '../style.css';
import './style.css';
+import { copy } from '../messages';
import { setupPlayground } from './playground.js';
-setupPlayground(document.querySelector('#embed-playground')!, { sampleURL: DEFAULT_SRC });
+setupPlayground(document.querySelector('#embed-playground')!, { sampleURL: DEFAULT_SRC, messages: copy });
diff --git a/site/src/embed/playground.js b/site/src/embed/playground.js
index de51980..9dfb9af 100644
--- a/site/src/embed/playground.js
+++ b/site/src/embed/playground.js
@@ -1,5 +1,14 @@
-export function setupPlayground(root, { sampleURL }) {
+export function setupPlayground(root, { sampleURL, messages }) {
const el = root.querySelector('mesh-avatar');
+ const mouthStyles = {
+ calm: { granularity: 0, openness: 0.5, closeSpeed: 0 },
+ default: { granularity: 0.5, openness: 0.5, closeSpeed: 0.5 },
+ lively: { granularity: 1, openness: 0.5, closeSpeed: 1 },
+ subtle: { granularity: 0.5, openness: 0, closeSpeed: 0.5 },
+ big: { granularity: 0.5, openness: 1, closeSpeed: 0.5 },
+ };
+ const mouthStyle = root.querySelector('#mouth-style');
+
const status = root.querySelector('#status');
const sourceName = root.querySelector('#source-name');
const selectedFile = root.querySelector('#selected-file');
@@ -9,6 +18,21 @@ export function setupPlayground(root, { sampleURL }) {
const speechText = root.querySelector('#speech-text');
const fileInput = root.querySelector('#avatar-file');
+ root.querySelector('#mouth-style-label').textContent = messages.mouthStyle;
+ root.querySelector('#mouth-style-hint').textContent = messages.mouthStyleHint;
+ const custom = new Option(messages.customMouthStyle, ''); custom.disabled = true; custom.hidden = true;
+ mouthStyle.add(custom);
+ for (const name of Object.keys(mouthStyles)) mouthStyle.add(new Option(messages.mouthStyles[name], name));
+
+ function mouthStyleCode(settings) {
+ const fields = ['granularity', 'openness', 'closeSpeed'].map(key => `${key}: ${settings[key]}`).join(', ');
+ updateCode('mouth-style-code', `const el = document.querySelector('mesh-avatar');\nel.setLipSync({ ${fields} });`);
+ }
+ mouthStyle.addEventListener('change', () => {
+ const settings = mouthStyles[mouthStyle.value];
+ el.setLipSync(settings); mouthStyleCode(settings);
+ });
+
function updateCode(id, text) {
root.querySelector(`#${id}`).textContent = text;
const copy = root.querySelector(`[data-copy="${id}"]`);
@@ -25,6 +49,12 @@ export function setupPlayground(root, { sampleURL }) {
}
function ready() {
+ const settings = { granularity: 0.5, openness: 0.5, closeSpeed: 0.5,
+ ...el.avatar?.package?.manifest.lipSync, ...el.lipSync };
+ mouthStyle.value = Object.keys(mouthStyles).find(name =>
+ Object.keys(mouthStyles[name]).every(key => mouthStyles[name][key] === settings[key])) ?? '';
+ mouthStyleCode(settings);
+
status.textContent = root.dataset.ready;
status.dataset.state = 'ready';
controls.disabled = false;
@@ -36,7 +66,6 @@ export function setupPlayground(root, { sampleURL }) {
status.dataset.state = 'error';
controls.disabled = true;
});
- if (el.avatar) ready();
for (const button of root.querySelectorAll('[data-expression]')) {
button.addEventListener('click', () => {
@@ -96,4 +125,5 @@ export function setupPlayground(root, { sampleURL }) {
}
});
}
+ if (el.avatar) ready();
}
diff --git a/site/src/embed/style.css b/site/src/embed/style.css
index eff861d..81e2d16 100644
--- a/site/src/embed/style.css
+++ b/site/src/embed/style.css
@@ -20,7 +20,7 @@
.control-panel h3 { margin: 0; font-size: 12px; font-weight: 500; }
.control-panel pre { white-space: pre-wrap; overflow-wrap: anywhere; padding-inline: 12px; }
.control-panel label { display: block; margin-block: 12px 8px; font-size: 14px; }
-.control-panel input[type='text'] { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; background: white; color: var(--ink); }
+.control-panel input[type='text'], .control-panel select { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; background: white; color: var(--ink); }
.control-panel button:not(.copy-button), .control-panel .file-button { min-height: 40px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: white; color: var(--ink); cursor: pointer; font: inherit; font-size: 14px; }
.control-panel button:hover:not(:disabled), .control-panel button[aria-pressed='true'], .file-button:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.control-panel button:disabled { opacity: .5; cursor: default; }
@@ -33,7 +33,7 @@
.file-actions { display: flex; flex-wrap: wrap; gap: 8px; position: relative; }
.control-panel .file-button { display: inline-flex; align-items: center; margin: 0; }
.file-input { position: absolute; width: 1px; height: 1px; padding: 0; border: 0; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }
-.file-input:focus-visible + .file-button, .embed-page input[type='text']:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
+.file-input:focus-visible + .file-button, .embed-page input[type='text']:focus-visible, .embed-page select:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
@media (max-width: 1000px) {
.embed-layout { grid-template-columns: minmax(240px, .7fr) minmax(0, 1fr); }
.control-panel { grid-template-columns: 1fr; }
diff --git a/site/src/messages.ts b/site/src/messages.ts
index c405937..d2b4a00 100644
--- a/site/src/messages.ts
+++ b/site/src/messages.ts
@@ -2,6 +2,10 @@ import type { LiveExpression } from 'mesh-avatar';
interface Messages {
expressions: Record<LiveExpression, string>;
+ mouthStyle: string;
+ mouthStyleHint: string;
+ customMouthStyle: string;
+ mouthStyles: Record<'calm' | 'default' | 'lively' | 'subtle' | 'big', string>;
pointerHint: string;
expressionHint: string;
loading: string;
@@ -18,6 +22,10 @@ const messages: Record<'en' | 'ja', Messages> = {
neutral: 'Neutral', smile: 'Smile', shy: 'Shy', surprise: 'Surprise',
halfLidded: 'Half-lidded', angry: 'Angry', sad: 'Sad', wink: 'Wink',
},
+ mouthStyle: 'Mouth style',
+ mouthStyleHint: 'Choose a style, then animate the text below to compare.',
+ customMouthStyle: 'Custom',
+ mouthStyles: { calm: 'Relaxed', default: 'Standard', lively: 'Snappy', subtle: 'Subtle', big: 'Expressive' },
pointerHint: 'Move your pointer and she turns to face it.',
expressionHint: 'Pick an expression to try it.',
loading: 'Loading the live preview…',
@@ -32,6 +40,10 @@ const messages: Record<'en' | 'ja', Messages> = {
neutral: '通常', smile: '笑顔', shy: '照れ', surprise: '驚き',
halfLidded: '半目', angry: '怒り', sad: '悲しみ', wink: 'ウインク',
},
+ mouthStyle: '口の動きのタイプ',
+ mouthStyleHint: 'タイプを選んで、下の文章で口の動きを試せます。',
+ customMouthStyle: 'カスタム',
+ mouthStyles: { calm: 'ゆったり', default: '標準', lively: 'キビキビ', subtle: '控えめ', big: 'はっきり' },
pointerHint: 'ポインターを動かすと、その方向へ顔を向けます。',
expressionHint: 'ボタンで表情を切り替えられます。',
loading: 'プレビューを読み込んでいます…',
diff --git a/tools/capture-readme-screenshots.mjs b/tools/capture-readme-screenshots.mjs
index b1199e3..81734c5 100644
--- a/tools/capture-readme-screenshots.mjs
+++ b/tools/capture-readme-screenshots.mjs
@@ -128,9 +128,15 @@ async function prepare(page, language, scene) {
await expect(page.getByTestId('editor')).toHaveAttribute('data-focus-group', 'eyes');
} else if (scene === '03-lip-sync') {
await page.getByRole('tab', { name: ja ? '口の動き' : 'Lip sync', exact: true }).click();
+ const style = page.getByTestId('audio-lip-settings').getByRole('button', { name: ja ? 'はっきり' : 'Expressive', exact: true });
+ await style.click();
+ await expect(style).toHaveAttribute('aria-pressed', 'true');
await page.getByRole('button', { name: 'あ', exact: true }).click();
await expect(page.getByRole('button', { name: 'あ', exact: true })).toHaveAttribute('aria-pressed', 'true');
- await expect.poll(async () => Number(await page.getByRole('slider', { name: ja ? '口の開き' : 'Mouth open', exact: true }).inputValue())).toBeGreaterThan(0.8);
+ await expect.poll(async () => Number(await page.getByRole('slider', { name: ja ? '口の開き' : 'Mouth open', exact: true }).inputValue())).toBeGreaterThan(0.98);
+ await page.locator('#lip-panel').evaluate(element => { element.scrollTop = 0; });
+ await expect(page.locator('.lip-text-row')).toBeInViewport();
+ await expect(style).toBeInViewport();
} else if (scene === '04-rebuild') {
await page.getByTestId('part-eyes').click();
await page.locator('summary').filter({ hasText: ja ? /^1 · 開口部 \(\d+\)$/ : /^1 · Opening \(\d+\)$/ }).click();