Skip to content

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

Add a landing page with a live avatar preview

shinshin86a0579f53ca71
diff --git a/.gitignore b/.gitignore
index 33dec56..39509ca 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
node_modules/
dist/
+site/dist/
.DS_Store
*.log
docs/screenshots/
diff --git a/package.json b/package.json
index 725e5fb..5ec6767 100644
--- a/package.json
+++ b/package.json
@@ -6,9 +6,12 @@
"workspaces": ["packages/*"],
"scripts": {
"dev": "vite --host 127.0.0.1",
+ "dev:site": "vite --config site/vite.config.ts",
+ "build:site": "tsc -p site/tsconfig.json && vite build --config site/vite.config.ts",
+ "preview:site": "vite preview --config site/vite.config.ts",
"screenshots": "node tools/capture-readme-screenshots.mjs",
"test": "vitest run",
- "lint": "eslint src tests e2e tools/*.mjs packages/runtime/src packages/runtime/tests packages/runtime/vite.config.ts packages/runtime/*.mjs",
+ "lint": "eslint src tests e2e tools/*.mjs packages/runtime/src packages/runtime/tests packages/runtime/vite.config.ts packages/runtime/*.mjs site/src site/vite.config.ts",
"build": "tsc --noEmit && vite build",
"build:runtime": "npm run build -w mesh-avatar",
"changeset": "changeset",
diff --git a/site/index.html b/site/index.html
new file mode 100644
index 0000000..21677bc
--- /dev/null
+++ b/site/index.html
@@ -0,0 +1,66 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="UTF-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <meta name="description" content="Turn one illustration into an animated 2D avatar. Create and adjust it in Mesh Avatar Studio, then embed it in your app with the mesh-avatar runtime." />
+ <title>Mesh Avatar Studio — Your illustration, in motion</title>
+ <link rel="icon" href="data:," />
+ <script type="module" src="/src/main.ts"></script>
+ </head>
+ <body>
+ <a class="skip-link" href="#main">Skip to content</a>
+ <header class="site-header shell">
+ <a class="brand" href="./" aria-label="Mesh Avatar Studio home">
+ <svg class="brand-mark" viewBox="0 0 32 32" aria-hidden="true" fill="none">
+ <path d="M5 7 16 3l11 4v18l-11 4-11-4V7Z M5 7l11 10L27 7M5 25l11-8 11 8M16 3v26" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round" />
+ </svg>
+ <span>Mesh Avatar Studio</span>
+ </a>
+ <a class="header-link" href="https://github.com/shinshin86/mesh-avatar-studio">GitHub <span aria-hidden="true">↗</span></a>
+ </header>
+ <main id="main" class="shell">
+ <section class="hero" aria-labelledby="hero-title">
+ <div class="hero-copy">
+ <p class="eyebrow">Your illustration, in motion</p>
+ <h1 id="hero-title">Mesh Avatar<br />Studio</h1>
+ <p class="hero-pitch">Turn one illustration into an animated avatar.</p>
+ <p class="hero-description">Create and adjust it in Studio, then bring it to your app with the <span class="package-name">mesh-avatar</span> runtime.</p>
+ <div class="hero-actions">
+ <a class="button primary" href="https://github.com/shinshin86/mesh-avatar-studio">Get started on GitHub <span aria-hidden="true">↗</span></a>
+ <a class="button secondary" href="https://www.npmjs.com/package/mesh-avatar">Runtime on npm <span aria-hidden="true">↗</span></a>
+ </div>
+ <p class="hero-note">A local editor. An avatar you can embed.</p>
+ </div>
+ <figure class="demo">
+ <div class="demo-panel">
+ <div class="demo-heading">
+ <span class="demo-title">Live preview</span>
+ <span class="demo-character">Miko</span>
+ </div>
+ <div class="avatar-stage" aria-busy="true">
+ <canvas id="avatar" role="img" aria-label="Miko, an animated 2D avatar. Use the controls below to change her expression or try talking." width="960" height="960"></canvas>
+ <p id="avatar-status" class="avatar-status" role="status">Enable JavaScript to try the interactive preview.</p>
+ </div>
+ <div class="demo-controls">
+ <fieldset id="avatar-controls" disabled aria-describedby="demo-hint">
+ <legend class="sr-only">Avatar controls</legend>
+ <div id="expressions" class="expression-chips" role="group" aria-label="Expression"></div>
+ <div class="talk-row">
+ <p id="demo-hint">Move your pointer to catch her eye.</p>
+ <button id="talk" class="talk-toggle" type="button" aria-pressed="false" aria-describedby="talk-hint"><span class="talk-indicator" aria-hidden="true"></span>Talk</button>
+ </div>
+ </fieldset>
+ <p id="talk-hint" class="demo-note">Try talking — this demo has no audio.</p>
+ </div>
+ </div>
+ <figcaption>Running here with <a href="https://www.npmjs.com/package/mesh-avatar">mesh-avatar</a>.</figcaption>
+ </figure>
+ </section>
+ </main>
+ <footer class="site-footer shell">
+ <p>Miko © Yuki Shindo (AITuber OnAir). Used under the <a href="https://miko.aituberonair.com/#terms">Miko Character Usage Guidelines</a>.</p>
+ <p>This is not an official AITuber OnAir product.</p>
+ </footer>
+ </body>
+</html>
diff --git a/site/src/main.ts b/site/src/main.ts
new file mode 100644
index 0000000..156b5fd
--- /dev/null
+++ b/site/src/main.ts
@@ -0,0 +1,154 @@
+import { LIVE_EXPRESSIONS, loadMeshAvatar, type LiveExpression, type MeshAvatar } from 'mesh-avatar';
+import './style.css';
+
+const hero = document.querySelector<HTMLElement>('.hero')!;
+const canvas = document.querySelector<HTMLCanvasElement>('#avatar')!;
+const stage = document.querySelector<HTMLElement>('.avatar-stage')!;
+const status = document.querySelector<HTMLElement>('#avatar-status')!;
+const controls = document.querySelector<HTMLFieldSetElement>('#avatar-controls')!;
+const expressions = document.querySelector<HTMLElement>('#expressions')!;
+const talk = document.querySelector<HTMLButtonElement>('#talk')!;
+const hint = document.querySelector<HTMLElement>('#demo-hint')!;
+const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
+const finePointer = window.matchMedia('(any-hover: hover) and (any-pointer: fine)');
+const shownExpressions: LiveExpression[] = ['neutral', 'smile', 'surprise', 'wink'];
+
+let avatar: MeshAvatar | undefined;
+let speaking = false;
+let inView = false;
+let pageVisible = true;
+let disposed = false;
+let frameId = 0;
+let lastFrame = 0;
+let elapsed = 0;
+const pointer = { active: false, x: 0, y: 0, smoothX: 0, smoothY: 0, weight: 0 };
+
+for (const name of shownExpressions.filter(name => LIVE_EXPRESSIONS.includes(name))) {
+ const button = document.createElement('button');
+ button.type = 'button';
+ button.textContent = name[0].toUpperCase() + name.slice(1);
+ button.dataset.expression = name;
+ button.setAttribute('aria-pressed', String(name === 'neutral'));
+ button.addEventListener('click', () => {
+ avatar?.setExpression(name);
+ for (const chip of expressions.querySelectorAll('button')) {
+ chip.setAttribute('aria-pressed', String(chip === button));
+ }
+ });
+ expressions.append(button);
+}
+
+function updateMotionPreference() {
+ avatar?.setAutoMotion(!reducedMotion.matches);
+ avatar?.setSwayGain(reducedMotion.matches ? 0.35 : 1);
+ pointer.active = false;
+ pointer.weight = 0;
+ avatar?.setParameters({});
+ hint.textContent = reducedMotion.matches || !finePointer.matches
+ ? 'Pick an expression to try it.'
+ : 'Move your pointer to catch her eye.';
+}
+reducedMotion.addEventListener('change', updateMotionPreference);
+finePointer.addEventListener('change', updateMotionPreference);
+updateMotionPreference();
+
+hero.addEventListener('pointermove', event => {
+ if (event.pointerType === 'touch' || reducedMotion.matches || !finePointer.matches) return;
+ const rect = hero.getBoundingClientRect();
+ pointer.x = Math.max(-1, Math.min(1, (event.clientX - rect.left) / rect.width * 2 - 1));
+ pointer.y = Math.max(-1, Math.min(1, 1 - (event.clientY - rect.top) / rect.height * 2));
+ pointer.active = true;
+});
+const releasePointer = () => { pointer.active = false; };
+hero.addEventListener('pointerleave', releasePointer);
+hero.addEventListener('pointercancel', releasePointer);
+window.addEventListener('blur', releasePointer);
+
+talk.addEventListener('click', () => {
+ speaking = !speaking;
+ talk.setAttribute('aria-pressed', String(speaking));
+ avatar?.setSpeaking(speaking);
+ if (!speaking) avatar?.setVoiceLevel(0);
+});
+
+function frame(now: number) {
+ if (!avatar) return;
+ const dt = Math.min(0.05, Math.max(0.001, (now - lastFrame) / 1000));
+ lastFrame = now;
+ elapsed += dt;
+ const ease = 1 - Math.exp(-dt * 9);
+ pointer.smoothX += (pointer.x - pointer.smoothX) * ease;
+ pointer.smoothY += (pointer.y - pointer.smoothY) * ease;
+ pointer.weight += ((pointer.active ? 1 : 0) - pointer.weight) * ease;
+ if (pointer.weight > 0.001 && !reducedMotion.matches) {
+ avatar.setParameters({
+ angleX: pointer.smoothX * 12,
+ angleY: pointer.smoothY * 8,
+ gazeX: pointer.smoothX * 0.7,
+ gazeY: pointer.smoothY * 0.55,
+ }, pointer.weight);
+ } else {
+ avatar.setParameters({});
+ }
+ if (speaking) {
+ const phrase = Math.max(0, Math.sin(elapsed * 2.4));
+ const syllable = 0.25 + 0.75 * Math.abs(Math.sin(elapsed * 13) * Math.cos(elapsed * 7));
+ avatar.setVoiceLevel(phrase * syllable);
+ }
+ // One simulation step per visible frame; the renderer also caps devicePixelRatio at 2.
+ avatar.advance(dt, 1 / dt);
+ frameId = requestAnimationFrame(frame);
+}
+
+function updateLoop() {
+ const shouldRender = avatar && inView && pageVisible && !document.hidden && !disposed;
+ if (shouldRender && !frameId) {
+ lastFrame = performance.now();
+ frameId = requestAnimationFrame(frame);
+ } else if (!shouldRender && frameId) {
+ cancelAnimationFrame(frameId);
+ frameId = 0;
+ pointer.active = false;
+ }
+}
+
+const visibility = new IntersectionObserver(entries => {
+ inView = entries[0].isIntersecting;
+ updateLoop();
+});
+visibility.observe(stage);
+document.addEventListener('visibilitychange', updateLoop);
+window.addEventListener('pagehide', event => {
+ pageVisible = false;
+ updateLoop();
+ if (!event.persisted) {
+ disposed = true;
+ visibility.disconnect();
+ avatar?.destroy();
+ }
+});
+window.addEventListener('pageshow', () => { pageVisible = true; updateLoop(); });
+
+async function start() {
+ status.textContent = 'Loading the live preview…';
+ canvas.dataset.state = 'loading';
+ try {
+ const loaded = await loadMeshAvatar(canvas, `${import.meta.env.BASE_URL}miko.mavatar`, { manual: true });
+ if (disposed) { loaded.destroy(); return; }
+ avatar = loaded;
+ avatar.setAutoIdle(true);
+ updateMotionPreference();
+ avatar.advance(0);
+ canvas.dataset.state = 'ready';
+ stage.setAttribute('aria-busy', 'false');
+ status.hidden = true;
+ controls.disabled = false;
+ updateLoop();
+ } catch {
+ canvas.dataset.state = 'error';
+ stage.setAttribute('aria-busy', 'false');
+ status.textContent = 'The live preview couldn’t load. Try reloading in a browser with WebGL enabled. You can still explore the project on GitHub or npm.';
+ }
+}
+
+void start();
diff --git a/site/src/style.css b/site/src/style.css
new file mode 100644
index 0000000..ffdb7fa
--- /dev/null
+++ b/site/src/style.css
@@ -0,0 +1,105 @@
+:root {
+ --ink: #243348;
+ --muted: #64758a;
+ --canvas: #edf1f5;
+ --surface: #fff;
+ --line: #d7dfe8;
+ --accent: #2563eb;
+ --accent-soft: #edf3ff;
+ --radius: 12px;
+ font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
+ color: var(--ink);
+ background: var(--canvas);
+ font-synthesis: none;
+ text-rendering: optimizeLegibility;
+ -webkit-font-smoothing: antialiased;
+}
+
+* { box-sizing: border-box; }
+body { margin: 0; }
+a { color: inherit; text-underline-offset: 3px; }
+button { font: inherit; }
+button, a { -webkit-tap-highlight-color: transparent; }
+button:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
+[hidden] { display: none !important; }
+.shell { width: min(1120px, calc(100% - 64px)); margin-inline: auto; }
+.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
+.skip-link { position: fixed; top: 12px; left: 12px; z-index: 10; padding: 12px 16px; border-radius: 8px; background: var(--surface); transform: translateY(-160%); }
+.skip-link:focus { transform: translateY(0); }
+.site-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 96px; border-bottom: 1px solid var(--line); }
+.brand { display: inline-flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 650; letter-spacing: -.4px; text-decoration: none; }
+.brand-mark { width: 32px; height: 32px; color: var(--accent); flex-shrink: 0; }
+.header-link { padding-block: 12px; font-size: 14px; text-decoration: none; }
+.header-link:hover { color: var(--accent); }
+.header-link span { margin-left: 4px; }
+.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 480px); gap: 64px; align-items: center; padding-block: 64px 48px; }
+.hero-copy { padding-bottom: 28px; }
+.eyebrow { margin: 0 0 20px; font-size: 13px; font-weight: 650; letter-spacing: 1.5px; text-transform: uppercase; color: var(--accent); }
+h1 { margin: 0; font-size: clamp(44px, 4.5vw, 64px); line-height: 1.06; font-weight: 650; letter-spacing: -2.8px; }
+.hero-pitch { max-width: 420px; margin: 28px 0 14px; font-size: 24px; line-height: 1.4; letter-spacing: -.5px; }
+.hero-description { max-width: 420px; margin: 0; font-size: 17px; line-height: 1.7; color: var(--muted); }
+.package-name { color: var(--ink); white-space: nowrap; }
+.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 30px; }
+.button { display: inline-flex; align-items: center; justify-content: center; gap: 12px; min-height: 48px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; font-weight: 600; text-decoration: none; }
+.button.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
+.button.primary:hover { background: #1d4ed8; }
+.button.secondary { background: var(--surface); }
+.button.secondary:hover { border-color: var(--accent); color: var(--accent); }
+.hero-note { margin: 16px 0 0; font-size: 13px; color: var(--muted); }
+.demo { min-width: 0; margin: 0; }
+.demo-panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; box-shadow: 0 8px 28px #24334808; }
+.demo-heading { display: flex; justify-content: space-between; align-items: center; min-height: 48px; padding: 12px 20px; border-bottom: 1px solid var(--line); font-size: 13px; }
+.demo-title { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
+.demo-title::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
+.demo-character { color: var(--muted); }
+.avatar-stage { position: relative; height: 430px; background: #f7f9fc; }
+#avatar { display: block; width: 100%; height: 100%; }
+.avatar-status { position: absolute; inset: 0; display: grid; place-content: center; margin: 0; padding: 32px; background: #f7f9fc; color: var(--muted); font-size: 14px; line-height: 1.7; text-align: center; }
+.demo-controls { padding: 16px 20px; border-top: 1px solid var(--line); }
+fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
+.expression-chips { display: flex; flex-wrap: wrap; gap: 6px; }
+.expression-chips button, .talk-toggle { min-height: 40px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font-size: 12px; font-weight: 550; cursor: pointer; }
+.expression-chips button:hover:not(:disabled), .talk-toggle:hover:not(:disabled) { border-color: var(--accent); }
+.expression-chips button[aria-pressed='true'], .talk-toggle[aria-pressed='true'] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
+fieldset:disabled button { opacity: .5; cursor: default; }
+.talk-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
+.talk-row p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
+.talk-toggle { display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0; }
+.talk-indicator { width: 7px; height: 7px; border: 1px solid currentColor; border-radius: 50%; }
+.talk-toggle[aria-pressed='true'] .talk-indicator { background: currentColor; }
+.demo-note { margin: 10px 0 0; font-size: 11px; line-height: 1.5; color: var(--muted); }
+figcaption { margin-top: 14px; color: var(--muted); text-align: center; font-size: 12px; line-height: 1.6; }
+figcaption a:hover, .site-footer a:hover { color: var(--accent); }
+.site-footer { border-top: 1px solid var(--line); padding-block: 24px 32px; color: var(--muted); font-size: 11px; line-height: 1.7; }
+.site-footer p { margin: 0; }
+
+@media (max-width: 960px) {
+ .hero { gap: 32px; grid-template-columns: minmax(0, 1fr) minmax(0, 420px); }
+ h1 { font-size: 48px; }
+ .hero-pitch { font-size: 22px; }
+}
+
+@media (max-width: 760px) {
+ .shell { width: min(520px, calc(100% - 40px)); }
+ .site-header { min-height: 72px; }
+ .brand { font-size: 15px; gap: 8px; }
+ .brand-mark { width: 26px; height: 26px; }
+ .header-link { font-size: 12px; }
+ .hero { grid-template-columns: minmax(0, 1fr); gap: 28px; padding-block: 36px 32px; }
+ .hero-copy { padding-bottom: 0; }
+ .eyebrow { margin-bottom: 16px; font-size: 11px; letter-spacing: 1.2px; }
+ h1 { font-size: 48px; letter-spacing: -2px; }
+ .hero-pitch { margin-top: 20px; font-size: 21px; }
+ .hero-description { font-size: 15px; line-height: 1.6; }
+ .hero-actions { gap: 8px; margin-top: 24px; }
+ .button { padding: 12px; font-size: 12px; gap: 8px; }
+ .hero-note { font-size: 12px; }
+ .avatar-stage { height: 310px; }
+ .demo-heading { padding-inline: 16px; }
+ .demo-controls { padding: 14px 16px; }
+ .expression-chips button { flex: 1; padding-inline: 8px; }
+}
+
+@media (prefers-reduced-motion: reduce) {
+ *, *::before, *::after { scroll-behavior: auto; }
+}
diff --git a/site/tsconfig.json b/site/tsconfig.json
new file mode 100644
index 0000000..d4db33f
--- /dev/null
+++ b/site/tsconfig.json
@@ -0,0 +1,7 @@
+{
+ "extends": "../tsconfig.json",
+ "compilerOptions": {
+ "types": ["vite/client", "node"]
+ },
+ "include": ["src", "vite.config.ts"]
+}
diff --git a/site/vite.config.ts b/site/vite.config.ts
new file mode 100644
index 0000000..2c8adf0
--- /dev/null
+++ b/site/vite.config.ts
@@ -0,0 +1,74 @@
+import { existsSync, readFileSync } from 'node:fs';
+import { createRequire } from 'node:module';
+import { dirname, join } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { defineConfig, type Plugin } from 'vite';
+import { packProjectAvatar } from '../packages/runtime/src/format/project-archive';
+import { readAvatarFolder } from '../tools/avatar-files.mjs';
+
+const fromHere = (path: string) => fileURLToPath(new URL(path, import.meta.url));
+const base = '/mesh-avatar-studio/';
+const avatarFile = 'miko.mavatar';
+
+function sampleAvatar(): Plugin {
+ const pack = () => packProjectAvatar(
+ paths => readAvatarFolder(fromHere('../samples/miko-qipao'), paths),
+ { name: 'Miko', includeSource: false },
+ );
+
+ return {
+ name: 'site-sample-avatar',
+ configureServer(server) {
+ server.middlewares.use((request, response, next) => {
+ if (request.url?.split('?')[0] !== `${base}${avatarFile}`) return next();
+ if (request.method !== 'GET' && request.method !== 'HEAD') {
+ response.writeHead(405, { Allow: 'GET, HEAD' });
+ response.end();
+ return;
+ }
+ void pack().then(bytes => {
+ response.writeHead(200, {
+ 'Content-Type': 'application/octet-stream',
+ 'Content-Length': bytes.byteLength,
+ 'Cache-Control': 'no-store',
+ });
+ response.end(request.method === 'HEAD' ? undefined : bytes);
+ }).catch(next);
+ });
+ },
+ async generateBundle() {
+ this.emitFile({ type: 'asset', fileName: avatarFile, source: await pack() });
+ },
+ };
+}
+
+// Retain the license of the archive library bundled into the browser script.
+const require = createRequire(import.meta.url);
+const fflateLicense = readFileSync(join(dirname(require.resolve('fflate/package.json')), 'LICENSE'), 'utf8');
+
+export default defineConfig({
+ root: fromHere('./'),
+ base,
+ publicDir: false,
+ plugins: [sampleAvatar()],
+ resolve: { alias: { 'mesh-avatar': fromHere('../packages/runtime/src/index.ts') } },
+ server: {
+ host: '127.0.0.1',
+ fs: {
+ // Only the packed avatar is served; raw sample and private project files stay local.
+ deny: ['.env', '.env.*', '*.{crt,pem}', '**/.git/**', '**/samples/**', '**/projects/**', '**/work/**', '**/_plan/**', '**/reference/**'],
+ },
+ },
+ preview: { host: '127.0.0.1' },
+ esbuild: { legalComments: 'inline' },
+ build: {
+ outDir: 'dist',
+ rollupOptions: {
+ input: {
+ en: fromHere('./index.html'),
+ ...(existsSync(fromHere('./ja/index.html')) ? { ja: fromHere('./ja/index.html') } : {}),
+ },
+ output: { banner: `/*! fflate\n${fflateLicense}\n*/` },
+ },
+ },
+});