Skip to content

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

Add a script that captures README screenshots from the sample

shinshin86ad0520b7f185
diff --git a/package.json b/package.json
index b28509a..94146a4 100644
--- a/package.json
+++ b/package.json
@@ -5,6 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite --host 127.0.0.1",
+ "screenshots": "node tools/capture-readme-screenshots.mjs",
"test": "vitest run",
"lint": "eslint src tests e2e tools/*.mjs",
"build": "tsc --noEmit && vite build",
diff --git a/src/editor/i18n.tsx b/src/editor/i18n.tsx
index bd792ed..9523e1c 100644
--- a/src/editor/i18n.tsx
+++ b/src/editor/i18n.tsx
@@ -40,7 +40,7 @@ const en = {
shortcutVertex: 'Add / remove a dot', spaceDrag: 'Space + drag', wheel: 'Scroll', vertexKeys: 'Double-click a line / Alt-click a dot',
stale: 'Outlines changed. The preview still uses the previous layers.',
changedParts: 'Changed parts', checking: 'Checking for sample images…', emptyTitle: 'Open a project',
- emptyHelp: 'Choose a project from Open project, or browse for its folder. Sample images are installed separately.',
+ emptyHelp: 'Choose a project from Open project, or browse for its folder.',
newProjectHelp: 'Starting from a new illustration? Ask your agent to prepare a project using the agent guide.',
invalidRig: 'Could not open the rig file. Check the JSON and these field paths:',
invalidFolder: 'Could not open this folder. Include source.png, rig.json, layers.json and every cut-out image.',
@@ -80,7 +80,7 @@ const ja: typeof en = {
shortcutVertex: '点を追加/削除', spaceDrag: 'スペース+ドラッグ', wheel: 'スクロール', vertexKeys: '線をダブルクリック/⌥+点をクリック',
stale: '輪郭が変更されました。プレビューには変更前の画像を使っています。',
changedParts: '変更されたパーツ', checking: 'サンプル画像を確認中…', emptyTitle: 'プロジェクトを開く',
- emptyHelp: '「プロジェクトを開く」の一覧から選ぶか、フォルダを指定してください。サンプル画像は別途用意が必要です。',
+ emptyHelp: '「プロジェクトを開く」の一覧から選ぶか、フォルダを指定してください。',
newProjectHelp: '新しいイラストでは、エージェントに手順書に沿ってプロジェクトを作るよう依頼してください。',
invalidRig: '設定ファイルを開けませんでした。JSONの形式と次の項目を確認してください:',
invalidFolder: 'フォルダーを開けませんでした。source.png、rig.json、layers.json とすべての切り抜き画像を用意してください。',
diff --git a/tools/capture-readme-screenshots.mjs b/tools/capture-readme-screenshots.mjs
new file mode 100644
index 0000000..9cfc4fc
--- /dev/null
+++ b/tools/capture-readme-screenshots.mjs
@@ -0,0 +1,195 @@
+#!/usr/bin/env node
+// Capture only the bundled sample, using disposable copies for writable UI states.
+import { cp, mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
+import { basename, join, relative } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { homedir } from 'node:os';
+import { createServer } from 'vite';
+import { chromium, expect } from '@playwright/test';
+
+const root = fileURLToPath(new URL('../', import.meta.url));
+const sample = join(root, 'samples/miko-qipao');
+const output = join(root, 'docs/images');
+const sampleId = 'sample-miko-qipao';
+const aliases = new Map();
+const temporary = [];
+let server, browser, cleanupPromise;
+
+async function cleanup() {
+ cleanupPromise ??= (async () => {
+ try { await browser?.close(); }
+ finally {
+ try { await server?.close(); }
+ finally { for (const directory of temporary) await rm(directory, { recursive: true, force: true }); }
+ }
+ })();
+ return cleanupPromise;
+}
+for (const [signal, code] of [['SIGINT', 130], ['SIGTERM', 143]]) {
+ process.once(signal, () => { void cleanup().finally(() => process.exit(code)); });
+}
+
+async function sampleCopy(alias, sprites) {
+ const directory = await mkdtemp(join(root, 'projects/.readme-tmp-'));
+ temporary.push(directory);
+ await cp(sample, directory, { recursive: true, filter: source => {
+ const path = relative(sample, source).replaceAll('\\', '/');
+ return !['review', ...(!sprites ? ['built/sprites', 'variants', 'variant-requests', 'variant-masks'] : [])].some(prefix => path === prefix || path.startsWith(`${prefix}/`));
+ } });
+ aliases.set(alias, { directory, sprites });
+}
+function projectEntry(name, sprites, readOnly = false) {
+ return { name, relativePath: readOnly ? 'samples/miko-qipao' : `projects/${name}`,
+ absolutePath: `/path/to/mesh-avatar-studio/projects/${name}`, updatedAt: '2000-01-01T00:00:00Z',
+ hasSprites: sprites, hasVariants: sprites, readOnly, rigFile: 'rig.json' };
+}
+function captureApi() {
+ return { name: 'readme-capture-only', enforce: 'pre', configureServer(vite) {
+ // Intercept before the normal local-project API: never enumerate real projects.
+ vite.middlewares.use((request, response, next) => {
+ if (!request.url?.startsWith('/__studio/')) { next(); return; }
+ const json = (status, value) => { response.writeHead(status, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' }); response.end(JSON.stringify(value)); };
+ if (request.method !== 'GET') { json(403, { error: 'Screenshot capture is read-only.' }); return; }
+ const path = request.url.split('?')[0];
+ if (path === '/__studio/context') { json(200, { rootPath: '/path/to/mesh-avatar-studio' }); return; }
+ if (path === '/__studio/projects') {
+ json(200, [projectEntry(sampleId, true, true), ...[...aliases].map(([name, copy]) => projectEntry(name, copy.sprites))]); return;
+ }
+ const match = path.match(/^\/__studio\/projects\/([^/]+)\//);
+ if (match?.[1] === sampleId) { next(); return; }
+ const copy = aliases.get(match?.[1]);
+ if (copy) {
+ request.url = request.url.replace(`/projects/${match[1]}/`, `/projects/${basename(copy.directory)}/`);
+ next(); return;
+ }
+ json(403, { error: 'Only the bundled sample and screenshot copies are available.' });
+ });
+ } };
+}
+
+// Keep pixel data and structural PNG chunks, excluding text, EXIF, dates and profiles.
+function pixelsOnly(png) {
+ const signature = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
+ if (!png.subarray(0, 8).equals(signature)) throw new Error('Expected a PNG screenshot.');
+ const chunks = [signature];
+ let offset = 8;
+ while (offset < png.length) {
+ const length = png.readUInt32BE(offset), end = offset + length + 12;
+ if (end > png.length) throw new Error('Incomplete PNG screenshot.');
+ const type = png.toString('ascii', offset + 4, offset + 8);
+ if (type === 'IHDR' && (png.readUInt32BE(offset + 8) !== 1440 || png.readUInt32BE(offset + 12) !== 900)) throw new Error('Screenshots must be 1440×900.');
+ if (['IHDR', 'PLTE', 'tRNS', 'IDAT', 'IEND'].includes(type)) chunks.push(png.subarray(offset, end));
+ offset = end;
+ }
+ return Buffer.concat(chunks);
+}
+
+async function open(page, project) {
+ await page.goto(server.resolvedUrls.local[0]);
+ await expect(page.getByTestId('preview-status')).toHaveAttribute('data-state', 'ready');
+ await page.locator('.open-menu > summary').click();
+ await page.getByTestId(`project-${project}`).click();
+ await expect(page.getByTestId('preview-status')).toHaveAttribute('data-state', 'ready');
+ await page.getByTestId('idle-toggle').click();
+ await expect(page.getByTestId('preview-status')).toHaveAttribute('data-state', 'ready');
+}
+async function closeCards(page) {
+ await page.getByTestId('variants-panel').evaluate(element => { element.open = false; });
+ await page.locator('.right-column').evaluate(element => { element.scrollTop = 0; });
+}
+async function prepare(page, language, scene) {
+ const ja = language === 'ja';
+ if (scene === '06-new-project') {
+ await page.route('**/__studio/projects', route => route.fulfill({ contentType: 'application/json', body: '[]' }));
+ for (const path of ['source.png', 'built/base.png']) await page.route(`**/miko-qipao/${path}`, route => route.fulfill({ status: 404, body: '' }));
+ await page.goto(server.resolvedUrls.local[0]);
+ await expect(page.getByTestId('ask-agent-new')).toBeVisible();
+ await expect(page.getByRole('heading', { name: ja ? 'プロジェクトを開く' : 'Open a project', exact: true })).toBeVisible();
+ return;
+ }
+ await open(page, scene === '04-rebuild' ? 'miko-editing' : scene === '05-variants' ? 'miko-variants' : sampleId);
+ await closeCards(page);
+ if (scene === '02-edit-handles') {
+ await page.getByTestId('part-eyes').click();
+ await page.getByRole('button', { name: ja ? '選択中のパーツに合わせる' : 'Fit selected part', exact: true }).click();
+ 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();
+ 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);
+ } else if (scene === '04-rebuild') {
+ await page.getByTestId('part-eyes').click();
+ await page.locator('summary').filter({ hasText: ja ? /^1 · 開口部 \(\d+\)$/ : /^1 · Opening \(\d+\)$/ }).click();
+ await page.getByRole('spinbutton', { name: 'eyes.0.opening.0.0', exact: true }).fill('451');
+ await page.getByRole('button', { name: ja ? '選択中のパーツに合わせる' : 'Fit selected part', exact: true }).click();
+ await expect(page.getByTestId('editor')).toHaveAttribute('data-focus-group', 'eyes');
+ await expect(page.getByTestId('stale-banner').locator('small')).toHaveText(ja ? '変更されたパーツ: 目' : 'Changed parts: Eyes');
+ await expect(page.getByRole('button', { name: ja ? '保存してレイヤーを作り直す' : 'Save and rebuild layers', exact: true })).toBeVisible();
+ await expect(page.getByTestId('preview-status')).toHaveAttribute('data-state', 'ready');
+ } else if (scene === '05-variants') {
+ const panel = page.getByTestId('variants-panel');
+ await panel.evaluate(element => { element.open = true; });
+ await panel.getByRole('checkbox', { name: ja ? '口' : 'Mouth', exact: true }).check();
+ const card = page.getByTestId('ask-agent-variants');
+ await card.getByRole('button', { name: 'Codex', exact: true }).click();
+ await expect(card.getByRole('button', { name: 'Codex', exact: true })).toHaveAttribute('aria-pressed', 'true');
+ await expect(panel.locator('.variant-count').last()).toHaveText(ja ? 'なし' : 'Missing');
+ await page.locator('.right-column').evaluate(element => { element.scrollTop += element.querySelector('.variants-panel').getBoundingClientRect().top - element.getBoundingClientRect().top; });
+ await expect(card.getByRole('button', { name: ja ? '依頼文をコピー' : 'Copy message', exact: true })).toBeInViewport();
+ return;
+ }
+ await page.locator('.right-column').evaluate(element => { element.scrollTop = 0; });
+}
+async function capture(language, scene) {
+ const context = await browser.newContext({ viewport: { width: 1440, height: 900 }, deviceScaleFactor: 1, locale: language === 'ja' ? 'ja-JP' : 'en-US', timezoneId: 'UTC' });
+ try {
+ const page = await context.newPage();
+ const errors = [];
+ page.on('pageerror', error => errors.push(error.message));
+ await page.addInitScript(language => {
+ localStorage.clear();
+ localStorage.setItem('mesh-avatar-language', language);
+ localStorage.setItem('mesh-avatar-guide-seen', '1');
+ localStorage.setItem('mesh-avatar-reopen-project', '0');
+ localStorage.setItem('mesh-avatar-agent-recipient', 'codex');
+ }, language);
+ await prepare(page, language, scene);
+ await page.locator('.open-menu').evaluate(element => { element.open = false; });
+ await expect(page.getByTestId('first-guide')).toHaveCount(0);
+ await expect(page.locator('.save-notice')).toHaveCount(0);
+ await page.mouse.move(1430, 890);
+ await page.evaluate(() => new Promise(done => requestAnimationFrame(() => requestAnimationFrame(done))));
+ if (errors.length) throw new Error(`Browser error: ${errors.join('; ')}`);
+ const visible = await page.locator('main').innerText();
+ for (const forbidden of [root, homedir(), basename(homedir()), '.readme-tmp-', '2000-01-01', 'Updated:', '更新:', '/path/to/', new Date().toISOString().slice(0, 10)]) {
+ if (visible.includes(forbidden)) throw new Error(`Environment-specific text in ${language}/${scene}.`);
+ }
+ const png = pixelsOnly(await page.screenshot({ type: 'png', animations: 'disabled' }));
+ return { language, scene, png };
+ } finally { await context.close(); }
+}
+
+try {
+ await readFile(join(sample, 'source.png')); // Fail before creating any capture files if the sample is absent.
+ await mkdir(join(root, 'projects'), { recursive: true });
+ await sampleCopy('miko-editing', true);
+ await sampleCopy('miko-variants', false);
+ server = await createServer({ root, plugins: [captureApi()], server: { host: '127.0.0.1', port: 0, strictPort: true, open: false } });
+ await server.listen();
+ browser = await chromium.launch();
+ const images = [];
+ const scenes = ['01-overview', '02-edit-handles', '03-lip-sync', '04-rebuild', '05-variants', '06-new-project'];
+ for (const language of ['en', 'ja']) for (const scene of scenes) {
+ images.push(await capture(language, scene));
+ console.log(`Captured ${language}/${scene}.png`);
+ }
+ for (const { language, scene, png } of images) {
+ await mkdir(join(output, language), { recursive: true });
+ await writeFile(join(output, language, `${scene}.png`), png);
+ }
+ console.log('Saved 12 screenshots to docs/images/{en,ja}/ (1440×900, PNG without metadata).');
+} catch (error) {
+ console.error(`screenshots: ${error.message.replaceAll(root, '<repo>/').replaceAll(homedir(), '~')}`);
+ process.exitCode = 1;
+} finally { await cleanup(); }