Skip to content

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

Move the engine into a mesh-avatar runtime package

shinshin86f306ce75387a
diff --git a/e2e/engine.spec.ts b/e2e/engine.spec.ts
index 5315fa3..99cfabe 100644
--- a/e2e/engine.spec.ts
+++ b/e2e/engine.spec.ts
@@ -11,3 +11,18 @@ test('renders the data-driven engine without browser errors', async ({ page }) =
await page.screenshot({ path: 'docs/screenshots/shell.png' });
expect(errors).toEqual([]);
});
+
+test('sample views load without the local project server', async ({ page }) => {
+ test.skip(!samplePresent, sampleSkipReason);
+ const errors: string[] = [];
+ page.on('pageerror', error => errors.push(error.message));
+ await page.route('**/__studio/projects', route => route.fulfill({ status: 404, body: 'Not found' }));
+ await page.goto('/');
+ await dismissGuide(page);
+ await expect(page.getByTestId('preview-status')).toHaveAttribute('data-state', 'ready');
+ for (const path of ['/live.html?idle=0', '/stream.html?idle=0']) {
+ await page.goto(path);
+ await expect(page.locator('canvas')).toHaveAttribute('data-state', 'ready');
+ }
+ expect(errors).toEqual([]);
+});
diff --git a/e2e/lighting.spec.ts b/e2e/lighting.spec.ts
index 72c44e1..dbdbdac 100644
--- a/e2e/lighting.spec.ts
+++ b/e2e/lighting.spec.ts
@@ -52,14 +52,14 @@ test('lighting is lazy, changes brightness with position, preserves alpha, shado
await page.goto('/stream.html?idle=0'); await expect(page.locator('canvas')).toHaveAttribute('data-state', 'ready');
await page.evaluate(async () => {
const path = '/src/live/avatar-view.ts', { createAvatarView, neutralParameters } = await import(path);
- const settingsPath = '/src/lighting/settings.ts', { DEFAULT_LIGHTING } = await import(settingsPath);
+ const settingsPath = '/packages/runtime/src/index.ts', { DEFAULT_LIGHTING } = await import(settingsPath);
const canvas = document.createElement('canvas'); canvas.id = 'test-avatar'; canvas.style.cssText = 'width:640px;height:640px'; document.body.append(canvas);
const view = await createAvatarView(canvas, { project: 'sample-miko-qipao', fit: 'contain', idle: false });
view.avatar.setParameters(neutralParameters); view.avatar.advance(1);
Object.assign(window, { testAvatar: view.avatar, defaultLight: DEFAULT_LIGHTING });
});
const light = (settings: Record<string, unknown>) => page.evaluate(settings => {
- const w = window as unknown as { testAvatar: import('../src/engine').MeshAvatar; defaultLight: import('../src/lighting/settings').LightingSettings };
+ const w = window as unknown as { testAvatar: import('mesh-avatar').MeshAvatar; defaultLight: import('mesh-avatar').LightingSettings };
w.testAvatar.setLighting({ ...w.defaultLight, ...settings }); w.testAvatar.advance(0); return w.testAvatar.getLightingStats();
}, settings);
const off = await image(page, '#test-avatar');
diff --git a/package-lock.json b/package-lock.json
index 05dc174..35d2ab8 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -7,8 +7,12 @@
"": {
"name": "mesh-avatar-studio",
"version": "0.1.0",
+ "workspaces": [
+ "packages/*"
+ ],
"dependencies": {
"@mediapipe/tasks-vision": "0.10.21",
+ "mesh-avatar": "*",
"react": "^19.1.0",
"react-dom": "^19.1.0"
},
@@ -2577,6 +2581,12 @@
}
}
},
+ "node_modules/fflate": {
+ "version": "0.8.3",
+ "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.3.tgz",
+ "integrity": "sha512-tbZNuJrLwGUp3zshBtdy4W+ORxZuIh8a5ilyIEQDC5rY1f3U20JMry0Ll3WBzU58EZKsEuJFXhb5gwv8CsPvgA==",
+ "license": "MIT"
+ },
"node_modules/file-entry-cache": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz",
@@ -2907,6 +2917,10 @@
"@jridgewell/sourcemap-codec": "^1.5.5"
}
},
+ "node_modules/mesh-avatar": {
+ "resolved": "packages/runtime",
+ "link": true
+ },
"node_modules/minimatch": {
"version": "3.1.5",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz",
@@ -3780,6 +3794,14 @@
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
+ },
+ "packages/runtime": {
+ "name": "mesh-avatar",
+ "version": "0.1.0",
+ "license": "MIT",
+ "dependencies": {
+ "fflate": "^0.8.3"
+ }
}
}
}
diff --git a/package.json b/package.json
index b503d4e..9bd994f 100644
--- a/package.json
+++ b/package.json
@@ -3,11 +3,12 @@
"version": "0.1.0",
"private": true,
"type": "module",
+ "workspaces": ["packages/*"],
"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",
+ "lint": "eslint src tests e2e tools/*.mjs packages/runtime/src packages/runtime/tests",
"build": "tsc --noEmit && vite build",
"e2e": "playwright test",
"validate-rig": "node --experimental-strip-types tools/validate-rig.mjs",
@@ -15,6 +16,7 @@
},
"dependencies": {
"@mediapipe/tasks-vision": "0.10.21",
+ "mesh-avatar": "*",
"react": "^19.1.0",
"react-dom": "^19.1.0"
},
diff --git a/packages/runtime/LICENSE b/packages/runtime/LICENSE
new file mode 100644
index 0000000..8b20d89
--- /dev/null
+++ b/packages/runtime/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2026 Yuki Shindo
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/packages/runtime/package.json b/packages/runtime/package.json
new file mode 100644
index 0000000..3e52ef9
--- /dev/null
+++ b/packages/runtime/package.json
@@ -0,0 +1,16 @@
+{
+ "name": "mesh-avatar",
+ "version": "0.1.0",
+ "type": "module",
+ "license": "MIT",
+ "files": ["dist", "README.md", "LICENSE"],
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/index.js"
+ }
+ },
+ "dependencies": {
+ "fflate": "^0.8.3"
+ }
+}
diff --git a/src/engine/createMeshAvatar.js b/packages/runtime/src/engine/createMeshAvatar.js
similarity index 97%
rename from src/engine/createMeshAvatar.js
rename to packages/runtime/src/engine/createMeshAvatar.js
index a3cffab..beb3e2b 100644
--- a/src/engine/createMeshAvatar.js
+++ b/packages/runtime/src/engine/createMeshAvatar.js
@@ -1,4 +1,4 @@
-// Mesh avatar engine: turns a pre-split single illustration (see public/avatar/miko-qipao/) into a
+// Mesh avatar engine: turns a pre-split single illustration into a
// 2D mesh avatar animated on a WebGL2 canvas. No UI and no framework: the app drives it
// through the small API returned by createMeshAvatar().
import { createRig } from './rig.js';
@@ -62,6 +62,9 @@ function deformTassel(ch, mesh) {
/** @param {HTMLCanvasElement} canvas
* @param {import('./index').MeshAvatarOptions} options */
export async function createMeshAvatarImpl(canvas, options) {
+ if (!options.assets && options.assetsBase === undefined) {
+ throw new Error('createMeshAvatar requires assets or assetsBase.');
+ }
const rig = options.rig;
const engine = createRig(rig);
const { IMG, EYES, baseWeights, deformBase, eyePartY, eyePartAlpha,
@@ -69,7 +72,7 @@ export async function createMeshAvatarImpl(canvas, options) {
const { Renderer, buildGrid } = createRenderer(engine, rig);
const { Physics } = createPhysics(engine, rig);
const { createSprites } = createSpriteModule(engine, rig);
- const base = (options.assetsBase ?? '/miko-qipao/built/').replace(/\/?$/, '/');
+ const base = (options.assetsBase ?? '').replace(/\/?$/, '/');
const asset = (name, build) => {
if (options.assets) {
if (!options.assets[name]) throw new Error(`Missing project asset: ${name}`);
diff --git a/src/engine/expression-overlay.js b/packages/runtime/src/engine/expression-overlay.js
similarity index 100%
rename from src/engine/expression-overlay.js
rename to packages/runtime/src/engine/expression-overlay.js
diff --git a/src/engine/index.ts b/packages/runtime/src/engine/index.ts
similarity index 100%
rename from src/engine/index.ts
rename to packages/runtime/src/engine/index.ts
diff --git a/src/engine/kana.js b/packages/runtime/src/engine/kana.js
similarity index 100%
rename from src/engine/kana.js
rename to packages/runtime/src/engine/kana.js
diff --git a/src/engine/motion.js b/packages/runtime/src/engine/motion.js
similarity index 100%
rename from src/engine/motion.js
rename to packages/runtime/src/engine/motion.js
diff --git a/src/engine/motions.js b/packages/runtime/src/engine/motions.js
similarity index 100%
rename from src/engine/motions.js
rename to packages/runtime/src/engine/motions.js
diff --git a/src/engine/physics.js b/packages/runtime/src/engine/physics.js
similarity index 100%
rename from src/engine/physics.js
rename to packages/runtime/src/engine/physics.js
diff --git a/src/engine/renderer.js b/packages/runtime/src/engine/renderer.js
similarity index 100%
rename from src/engine/renderer.js
rename to packages/runtime/src/engine/renderer.js
diff --git a/src/engine/rig.js b/packages/runtime/src/engine/rig.js
similarity index 100%
rename from src/engine/rig.js
rename to packages/runtime/src/engine/rig.js
diff --git a/src/engine/sprites.js b/packages/runtime/src/engine/sprites.js
similarity index 98%
rename from src/engine/sprites.js
rename to packages/runtime/src/engine/sprites.js
index 34db3ce..9e77312 100644
--- a/src/engine/sprites.js
+++ b/packages/runtime/src/engine/sprites.js
@@ -2,7 +2,7 @@
* @param {import('../rig/types').Rig} rig */
export function createSpriteModule(engine, rig) {
const { baseWeights, deformBase, MOUTH } = engine;
- // Drawn eye / mouth variants (public/avatar/miko-qipao/sprites/, cut from full-size drawings) laid over the
+ // Drawn eye / mouth variants (built/sprites/, cut from full-size drawings) laid over the
// face. Closed eyes and open mouths are what the single image does not contain, so instead of
// faking them with shaders these are swapped in like the frames of an anime blink / lip flap.
// The sprite meshes follow the same head / body deformation as the face.
diff --git a/packages/runtime/src/index.ts b/packages/runtime/src/index.ts
new file mode 100644
index 0000000..85564f1
--- /dev/null
+++ b/packages/runtime/src/index.ts
@@ -0,0 +1,7 @@
+export { createMeshAvatar, LIVE_EXPRESSIONS } from './engine';
+export type { MeshAvatar, MeshAvatarOptions, LiveExpression } from './engine';
+export type { Rig, Eye, Strand, Accessory, Hand, Ellipse, Point, Band } from './rig/types';
+export { validateRig, parseRig } from './rig/validate';
+export { PARAMS } from './engine/rig.js';
+export type { LightingSettings } from './lighting/settings';
+export { DEFAULT_LIGHTING, parseLighting, colorHex } from './lighting/settings';
diff --git a/src/lighting/normals.ts b/packages/runtime/src/lighting/normals.ts
similarity index 100%
rename from src/lighting/normals.ts
rename to packages/runtime/src/lighting/normals.ts
diff --git a/packages/runtime/src/lighting/settings.ts b/packages/runtime/src/lighting/settings.ts
new file mode 100644
index 0000000..6b430fd
--- /dev/null
+++ b/packages/runtime/src/lighting/settings.ts
@@ -0,0 +1,28 @@
+export interface LightingSettings {
+ enabled: boolean; x: number; y: number; z: number; color: number;
+ strength: number; intensity: number; ambient: number; mode: 'soft' | 'cel'; shadow: boolean;
+ reach: number; ambientColor: number; softness: number; specular: number; rim: number; detail: number;
+}
+export const DEFAULT_LIGHTING: Readonly<LightingSettings> = Object.freeze({
+ enabled: false, x: 0.2, y: 0.2, z: 0.45, color: 0xffffff,
+ strength: 0.8, intensity: 0.8, ambient: 0.4, mode: 'soft', shadow: false,
+ reach: 1.2, ambientColor: 0xeef0f8, softness: 0.45, specular: 0.12, rim: 0.3, detail: 0.4,
+});
+const ranges = { x: [0, 1], y: [0, 1], z: [0.1, 2], color: [0, 0xffffff], strength: [0, 1], intensity: [0, 2], ambient: [0, 1],
+ reach: [0.2, 3], ambientColor: [0, 0xffffff], softness: [0, 1], specular: [0, 1], rim: [0, 1], detail: [0, 1] } as const;
+const colors = new Set(['color', 'ambientColor']);
+// Strict wire format: only finite numbers and enumerated strings; no arbitrary payloads.
+export function parseLighting(input: unknown): LightingSettings | null {
+ if (!input || typeof input !== 'object' || Array.isArray(input)) return null;
+ const data = input as Record<string, unknown>;
+ if (Object.keys(data).length !== Object.keys(DEFAULT_LIGHTING).length || Object.keys(data).some(k => !(k in DEFAULT_LIGHTING))) return null;
+ if (![true, false].includes(data.enabled as boolean) || ![true, false].includes(data.shadow as boolean) || !['soft', 'cel'].includes(data.mode as string)) return null;
+ const result = { ...DEFAULT_LIGHTING, enabled: data.enabled, shadow: data.shadow, mode: data.mode } as LightingSettings;
+ for (const key of Object.keys(ranges) as (keyof typeof ranges)[]) {
+ const value = data[key], [min, max] = ranges[key];
+ if (typeof value !== 'number' || !Number.isFinite(value) || (colors.has(key) && !Number.isInteger(value))) return null;
+ result[key] = Math.max(min, Math.min(max, value));
+ }
+ return result;
+}
+export function colorHex(color: number) { return `#${color.toString(16).padStart(6, '0')}`; }
diff --git a/src/lighting/shading.ts b/packages/runtime/src/lighting/shading.ts
similarity index 100%
rename from src/lighting/shading.ts
rename to packages/runtime/src/lighting/shading.ts
diff --git a/src/lighting/shadow.js b/packages/runtime/src/lighting/shadow.js
similarity index 100%
rename from src/lighting/shadow.js
rename to packages/runtime/src/lighting/shadow.js
diff --git a/src/rig/numeric.ts b/packages/runtime/src/rig/numeric.ts
similarity index 100%
rename from src/rig/numeric.ts
rename to packages/runtime/src/rig/numeric.ts
diff --git a/src/rig/types.ts b/packages/runtime/src/rig/types.ts
similarity index 100%
rename from src/rig/types.ts
rename to packages/runtime/src/rig/types.ts
diff --git a/src/rig/validate.ts b/packages/runtime/src/rig/validate.ts
similarity index 100%
rename from src/rig/validate.ts
rename to packages/runtime/src/rig/validate.ts
diff --git a/packages/runtime/tests/assets.test.ts b/packages/runtime/tests/assets.test.ts
new file mode 100644
index 0000000..254cf78
--- /dev/null
+++ b/packages/runtime/tests/assets.test.ts
@@ -0,0 +1,15 @@
+import { expect, test, vi } from 'vitest';
+import { createMeshAvatar, parseRig } from 'mesh-avatar';
+import fixture from '../../../samples/miko-qipao/rig.json';
+
+test('missing asset sources fail before attempting a request or accessing the canvas', async () => {
+ const fetch = vi.fn();
+ vi.stubGlobal('fetch', fetch);
+ try {
+ await expect(createMeshAvatar({} as HTMLCanvasElement, { rig: parseRig(fixture) }))
+ .rejects.toThrow('createMeshAvatar requires assets or assetsBase.');
+ expect(fetch).not.toHaveBeenCalled();
+ } finally {
+ vi.unstubAllGlobals();
+ }
+});
diff --git a/src/editor/App.tsx b/src/editor/App.tsx
index 16aa2c8..9d0223c 100644
--- a/src/editor/App.tsx
+++ b/src/editor/App.tsx
@@ -2,8 +2,7 @@ import { useEffect, useRef, useState } from 'react';
import fixture from 'virtual:sample-rig';
import { EditorCanvas } from './EditorCanvas';
import { setAt } from './model';
-import type { Rig } from '../rig/types';
-import { parseRig, validateRig } from '../rig/validate';
+import { type Rig, parseRig, validateRig } from 'mesh-avatar';
import { Preview } from './Preview';
import { RigHistory, downloadRig } from './history';
import { openProjectFolder, openLocalProject, copySample, localProjects, projectAction, sampleImagesAvailable, repositoryContext, runProjectJob, ProjectJobError, type ProjectJob, type LocalProject, type LocalProjectEntry } from './project';
diff --git a/src/editor/EditorCanvas.tsx b/src/editor/EditorCanvas.tsx
index 5c0c836..a058509 100644
--- a/src/editor/EditorCanvas.tsx
+++ b/src/editor/EditorCanvas.tsx
@@ -1,5 +1,5 @@
import { useEffect, useMemo, useRef, useState } from 'react';
-import type { Point, Rig } from '../rig/types';
+import type { Point, Rig } from 'mesh-avatar';
import { buildOverlay, changeVertex, imagePoint, moveHandle, nearestEdge, nearestHandle, screen, type Handle, type Viewport } from './model';
import { useI18n, type PartGroup } from './i18n';
import { PART_COLORS } from './parts';
diff --git a/src/editor/JobFeedback.tsx b/src/editor/JobFeedback.tsx
index 6137950..6c7b412 100644
--- a/src/editor/JobFeedback.tsx
+++ b/src/editor/JobFeedback.tsx
@@ -1,4 +1,4 @@
-import type { Rig } from '../rig/types';
+import type { Rig } from 'mesh-avatar';
import { jobReason } from './job-reason';
import { useI18n } from './i18n';
import { ProjectJobError } from './project';
diff --git a/src/editor/NumericField.tsx b/src/editor/NumericField.tsx
index 44735c3..adbd0df 100644
--- a/src/editor/NumericField.tsx
+++ b/src/editor/NumericField.tsx
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
-import { editorNumber, isIntegerField } from '../rig/numeric';
+import { editorNumber, isIntegerField } from '../../packages/runtime/src/rig/numeric';
export function NumericField({ path, value, label, onChange }: {
path: string; label?: string; value: number; onChange: (value: number) => void;
diff --git a/src/editor/PartList.tsx b/src/editor/PartList.tsx
index 8390d5b..79a2481 100644
--- a/src/editor/PartList.tsx
+++ b/src/editor/PartList.tsx
@@ -1,4 +1,4 @@
-import type { Rig } from '../rig/types';
+import type { Rig } from 'mesh-avatar';
import { useI18n, type PartGroup } from './i18n';
import { PART_COLORS, partPresent, SECTIONS } from './parts';
import { Icon } from './Icon';
diff --git a/src/editor/Preview.tsx b/src/editor/Preview.tsx
index 84ceb0e..ac274c0 100644
--- a/src/editor/Preview.tsx
+++ b/src/editor/Preview.tsx
@@ -1,10 +1,8 @@
import { LightingControls, LightHandle, lightingText } from '../lighting/Controls';
-import { loadLighting, saveLighting } from '../lighting/settings';
+import { loadLighting, saveLighting } from '../lighting/storage';
import { useEffect, useRef, useState } from 'react';
-import { createMeshAvatar, type MeshAvatar } from '../engine';
-import { PARAMS } from '../engine/rig.js';
-import { VOWELS, skippedKanaCharacters } from '../engine/kana.js';
-import type { Rig } from '../rig/types';
+import { createMeshAvatar, type MeshAvatar, PARAMS, type Rig } from 'mesh-avatar';
+import { VOWELS, skippedKanaCharacters } from '../../packages/runtime/src/engine/kana.js';
import { useI18n } from './i18n';
import { Icon } from './Icon';
diff --git a/src/editor/RigFields.tsx b/src/editor/RigFields.tsx
index 2b37111..4813eb5 100644
--- a/src/editor/RigFields.tsx
+++ b/src/editor/RigFields.tsx
@@ -1,4 +1,4 @@
-import type { Rig } from '../rig/types';
+import type { Rig } from 'mesh-avatar';
import { getAt } from './model';
import { NumericField } from './NumericField';
import { useI18n } from './i18n';
diff --git a/src/editor/history.ts b/src/editor/history.ts
index 12204be..5c011d8 100644
--- a/src/editor/history.ts
+++ b/src/editor/history.ts
@@ -1,4 +1,4 @@
-import type { Rig } from '../rig/types';
+import type { Rig } from 'mesh-avatar';
export class RigHistory {
present: Rig;
diff --git a/src/editor/job-reason.ts b/src/editor/job-reason.ts
index f5bdb89..8af46d7 100644
--- a/src/editor/job-reason.ts
+++ b/src/editor/job-reason.ts
@@ -1,4 +1,4 @@
-import type { Rig } from '../rig/types';
+import type { Rig } from 'mesh-avatar';
type Messages = Record<'accessory' | 'jobBoxOutside' | 'jobBoxEmpty' | 'jobBoxInvalid' | 'jobAccessoryPixels' | 'jobEyeRegion' | 'jobHandRegion' | 'jobFaceRegion' | 'jobImageSize' | 'jobMeshRegion', string>;
export function jobReason(log: string, t: Messages, rig?: Rig, fieldTitle: (field: string) => string = field => field): string | undefined {
diff --git a/src/editor/model.ts b/src/editor/model.ts
index 3c17c77..a52ea20 100644
--- a/src/editor/model.ts
+++ b/src/editor/model.ts
@@ -1,5 +1,5 @@
-import { editorNumber, isIntegerField } from '../rig/numeric';
-import type { Point, Rig } from '../rig/types';
+import { editorNumber, isIntegerField } from '../../packages/runtime/src/rig/numeric';
+import type { Point, Rig } from 'mesh-avatar';
export interface Viewport { scale: number; x: number; y: number }
export interface Handle {
diff --git a/src/editor/parts.ts b/src/editor/parts.ts
index 56da560..abc8315 100644
--- a/src/editor/parts.ts
+++ b/src/editor/parts.ts
@@ -1,4 +1,4 @@
-import type { Rig } from '../rig/types';
+import type { Rig } from 'mesh-avatar';
import type { PartGroup } from './i18n';
export const GROUPS: PartGroup[] = ['head', 'eyes', 'mouth', 'face', 'cheeks', 'strands', 'buns', 'accessories', 'body', 'hand', 'mesh', 'view'];
export const PART_COLORS: Record<PartGroup, string> = {
diff --git a/src/editor/project.ts b/src/editor/project.ts
index 2a437b9..67d7362 100644
--- a/src/editor/project.ts
+++ b/src/editor/project.ts
@@ -1,5 +1,4 @@
-import { parseRig } from '../rig/validate';
-import type { Rig } from '../rig/types';
+import { parseRig, type Rig } from 'mesh-avatar';
import type { LocalProject, LocalProjectEntry } from '../project-types';
import { FolderOpenError } from './folder-errors';
export type { LocalProject, LocalProjectEntry } from '../project-types';
diff --git a/src/editor/stale.ts b/src/editor/stale.ts
index 759d4f2..79d463b 100644
--- a/src/editor/stale.ts
+++ b/src/editor/stale.ts
@@ -1,4 +1,4 @@
-import type { Rig } from '../rig/types';
+import type { Rig } from 'mesh-avatar';
export function layerSignature(rig: Rig) {
return JSON.stringify({
diff --git a/src/editor/viewport.ts b/src/editor/viewport.ts
index 9d531d2..332ab47 100644
--- a/src/editor/viewport.ts
+++ b/src/editor/viewport.ts
@@ -1,4 +1,4 @@
-import type { Point } from '../rig/types';
+import type { Point } from 'mesh-avatar';
import type { Viewport, Shape, Handle } from './model';
export const MIN_SCALE = 0.1, MAX_SCALE = 16;
diff --git a/src/lighting/Controls.tsx b/src/lighting/Controls.tsx
index d74a2dd..b8711df 100644
--- a/src/lighting/Controls.tsx
+++ b/src/lighting/Controls.tsx
@@ -1,5 +1,5 @@
import { useLayoutEffect, useRef, useState, type KeyboardEvent, type PointerEvent } from 'react';
-import { colorHex, DEFAULT_LIGHTING, type LightingSettings } from './settings';
+import { colorHex, DEFAULT_LIGHTING, type LightingSettings } from 'mesh-avatar';
import './lighting.css';
export const lightingText = {
diff --git a/src/lighting/presets.ts b/src/lighting/presets.ts
index 313d55c..3b66e2e 100644
--- a/src/lighting/presets.ts
+++ b/src/lighting/presets.ts
@@ -1,4 +1,5 @@
-import { DEFAULT_LIGHTING, parseLighting, type LightingSettings } from './settings';
+// Vite bundles its config before applying aliases, so use the public source entry here.
+import { DEFAULT_LIGHTING, parseLighting, type LightingSettings } from '../../packages/runtime/src/index';
export const LIGHTING_PRESET_COUNT = 8;
/** Slot i holds preset number i + 1; empty slots are null. */
diff --git a/src/lighting/protocol.ts b/src/lighting/protocol.ts
index 0959195..e4c0f20 100644
--- a/src/lighting/protocol.ts
+++ b/src/lighting/protocol.ts
@@ -1,4 +1,5 @@
-import { parseLighting, type LightingSettings } from './settings';
+// Vite bundles its config before applying aliases, so use the public source entry here.
+import { parseLighting, type LightingSettings } from '../../packages/runtime/src/index';
export const LIGHTING_EVENT = 'studio:lighting';
export interface LightingMessage { project: string; lighting: Omit<LightingSettings, 'enabled' | 'shadow'> & { enabled: 0 | 1; shadow: 0 | 1 } }
export function lightingMessage(input: unknown): LightingMessage | null {
diff --git a/src/lighting/settings.ts b/src/lighting/storage.ts
similarity index 50%
rename from src/lighting/settings.ts
rename to src/lighting/storage.ts
index 409f2c5..c5ad1e2 100644
--- a/src/lighting/settings.ts
+++ b/src/lighting/storage.ts
@@ -1,33 +1,8 @@
-export interface LightingSettings {
- enabled: boolean; x: number; y: number; z: number; color: number;
- strength: number; intensity: number; ambient: number; mode: 'soft' | 'cel'; shadow: boolean;
- reach: number; ambientColor: number; softness: number; specular: number; rim: number; detail: number;
-}
-export const DEFAULT_LIGHTING: Readonly<LightingSettings> = Object.freeze({
- enabled: false, x: 0.2, y: 0.2, z: 0.45, color: 0xffffff,
- strength: 0.8, intensity: 0.8, ambient: 0.4, mode: 'soft', shadow: false,
- reach: 1.2, ambientColor: 0xeef0f8, softness: 0.45, specular: 0.12, rim: 0.3, detail: 0.4,
-});
-const ranges = { x: [0, 1], y: [0, 1], z: [0.1, 2], color: [0, 0xffffff], strength: [0, 1], intensity: [0, 2], ambient: [0, 1],
- reach: [0.2, 3], ambientColor: [0, 0xffffff], softness: [0, 1], specular: [0, 1], rim: [0, 1], detail: [0, 1] } as const;
-const colors = new Set(['color', 'ambientColor']);
+import { colorHex, DEFAULT_LIGHTING, parseLighting, type LightingSettings } from 'mesh-avatar';
+
// URL parameter names; colours are six hex digits without '#'.
const params = { x: 'lx', y: 'ly', z: 'lz', strength: 'ls', intensity: 'li', ambient: 'la',
reach: 'lr', softness: 'lf', specular: 'lsp', rim: 'lrim', detail: 'ld' } as const;
-// Strict wire format: only finite numbers and enumerated strings; no arbitrary payloads.
-export function parseLighting(input: unknown): LightingSettings | null {
- if (!input || typeof input !== 'object' || Array.isArray(input)) return null;
- const data = input as Record<string, unknown>;
- if (Object.keys(data).length !== Object.keys(DEFAULT_LIGHTING).length || Object.keys(data).some(k => !(k in DEFAULT_LIGHTING))) return null;
- if (![true, false].includes(data.enabled as boolean) || ![true, false].includes(data.shadow as boolean) || !['soft', 'cel'].includes(data.mode as string)) return null;
- const result = { ...DEFAULT_LIGHTING, enabled: data.enabled, shadow: data.shadow, mode: data.mode } as LightingSettings;
- for (const key of Object.keys(ranges) as (keyof typeof ranges)[]) {
- const value = data[key], [min, max] = ranges[key];
- if (typeof value !== 'number' || !Number.isFinite(value) || (colors.has(key) && !Number.isInteger(value))) return null;
- result[key] = Math.max(min, Math.min(max, value));
- }
- return result;
-}
export function lightingFromQuery(query: URLSearchParams): LightingSettings {
const value = { ...DEFAULT_LIGHTING, enabled: query.get('light') === '1', shadow: query.get('shadow') === '1', mode: query.get('lm') === 'cel' ? 'cel' : 'soft' } as LightingSettings;
for (const [key, param] of Object.entries(params)) {
@@ -46,7 +21,6 @@ export function writeLightingQuery(query: URLSearchParams, value: LightingSettin
query.set('lc', colorHex(value.color).slice(1)); query.set('lac', colorHex(value.ambientColor).slice(1));
query.set('lm', value.mode); query.set('shadow', value.shadow ? '1' : '0');
}
-export function colorHex(color: number) { return `#${color.toString(16).padStart(6, '0')}`; }
export function loadLighting(project: string): LightingSettings {
try {
const stored = JSON.parse(localStorage.getItem(`mesh-avatar:lighting:${project}`) ?? 'null');
diff --git a/src/live/LiveApp.tsx b/src/live/LiveApp.tsx
index 6fd5727..45ac6cf 100644
--- a/src/live/LiveApp.tsx
+++ b/src/live/LiveApp.tsx
@@ -1,7 +1,7 @@
import { LightingControls, LightHandle, lightingText } from '../lighting/Controls';
-import { colorHex, loadLighting, saveLighting } from '../lighting/settings';
+import { colorHex, LIVE_EXPRESSIONS, type LiveExpression, type MeshAvatar } from 'mesh-avatar';
+import { loadLighting, saveLighting } from '../lighting/storage';
import { loadLightingPresets, sameLighting, saveLightingPresets } from '../lighting/presets';
-import { LIVE_EXPRESSIONS, type LiveExpression, type MeshAvatar } from '../engine';
import { useEffect, useRef, useState } from 'react';
import { useI18n } from '../editor/i18n';
import { createAvatarView } from './avatar-view';
diff --git a/src/live/avatar-view.ts b/src/live/avatar-view.ts
index b67ce29..5581596 100644
--- a/src/live/avatar-view.ts
+++ b/src/live/avatar-view.ts
@@ -1,5 +1,4 @@
-import { createMeshAvatar, type MeshAvatar } from '../engine';
-import { PARAMS } from '../engine/rig.js';
+import { createMeshAvatar, type MeshAvatar, PARAMS } from 'mesh-avatar';
import { localProjects, openLocalProject } from '../editor/project';
import fixture from 'virtual:sample-rig';
import { SAMPLE_PROJECT, type ViewSettings } from './settings';
@@ -13,7 +12,7 @@ export async function createAvatarView(canvas: HTMLCanvasElement, settings: View
const projects = await localProjects(), project = projects?.find(entry => entry.name === settings.project);
if (project?.error || (!project && settings.project !== SAMPLE_PROJECT)) throw new Error('Project unavailable');
const loaded = project ? await openLocalProject(project) : { rig: fixture, assets: undefined };
- const avatar = await createMeshAvatar(canvas, { rig: loaded.rig!, assets: loaded.assets, manual: true, fit: settings.fit, preserveMouthForm: true });
+ const avatar = await createMeshAvatar(canvas, { rig: loaded.rig!, assets: loaded.assets, assetsBase: '/miko-qipao/built/', manual: true, fit: settings.fit, preserveMouthForm: true });
if (settings.lighting) avatar.setLighting(settings.lighting);
avatar.setAutoIdle(settings.idle); avatar.setAutoMotion(settings.idle);
if (!settings.idle) avatar.setParameters(neutralParameters);
diff --git a/src/live/relay.ts b/src/live/relay.ts
index ec5cd6d..c3455d5 100644
--- a/src/live/relay.ts
+++ b/src/live/relay.ts
@@ -1,5 +1,5 @@
import { LIGHTING_EVENT, lightingWire, lightingMessage, lightingValue } from '../lighting/protocol';
-import type { LightingSettings } from '../lighting/settings';
+import type { LightingSettings } from 'mesh-avatar';
import { LIVE_EVENT, liveMessage } from './protocol';
import { EXPRESSION_EVENT, LIGHTING_PRESET_EVENT, expressionMessage, lightingPresetMessage, type RemoteExpression } from './expression-protocol';
diff --git a/src/live/settings.ts b/src/live/settings.ts
index b09d7c2..4e6b015 100644
--- a/src/live/settings.ts
+++ b/src/live/settings.ts
@@ -1,4 +1,5 @@
-import { lightingFromQuery, writeLightingQuery, type LightingSettings } from '../lighting/settings';
+import type { LightingSettings } from 'mesh-avatar';
+import { lightingFromQuery, writeLightingQuery } from '../lighting/storage';
export const SAMPLE_PROJECT = 'sample-miko-qipao';
export interface ViewSettings {
project: string;
diff --git a/src/live/stream.ts b/src/live/stream.ts
index 59ea361..4bd2bea 100644
--- a/src/live/stream.ts
+++ b/src/live/stream.ts
@@ -8,7 +8,7 @@ const settings = viewSettings(location.search);
document.documentElement.style.background = settings.background;
const canvas = document.querySelector<HTMLCanvasElement>('#avatar')!;
const pose = new LivePose(settings.project);
-let avatarInstance: import('../engine').MeshAvatar | undefined;
+let avatarInstance: import('mesh-avatar').MeshAvatar | undefined;
const unsubscribeLighting = receiveLighting(settings.project, value => { settings.lighting = value; avatarInstance?.setLighting(value); });
const unsubscribe = receiveLiveParameters(data => pose.receive(data, performance.now()));
void createAvatarView(canvas, settings, (avatar, now, dt) => {
diff --git a/src/live/tracking.ts b/src/live/tracking.ts
index 9617404..251ad66 100644
--- a/src/live/tracking.ts
+++ b/src/live/tracking.ts
@@ -1,4 +1,5 @@
-import { PARAMS } from '../engine/rig.js';
+// Vite bundles its config before applying aliases, so use the public source entry here.
+import { PARAMS } from '../../packages/runtime/src/index';
export interface FaceResult {
faceLandmarks: unknown[][];
diff --git a/src/sample-rig.d.ts b/src/sample-rig.d.ts
index e19285b..dc7a308 100644
--- a/src/sample-rig.d.ts
+++ b/src/sample-rig.d.ts
@@ -1,4 +1,4 @@
declare module 'virtual:sample-rig' {
- const rig: import('./rig/types').Rig;
+ const rig: import('mesh-avatar').Rig;
export default rig;
}
diff --git a/src/server/local-projects.ts b/src/server/local-projects.ts
index d8c4d8e..6f47838 100644
--- a/src/server/local-projects.ts
+++ b/src/server/local-projects.ts
@@ -5,7 +5,8 @@ import { readFile, readdir, realpath, stat, writeFile, rename, unlink, mkdir, cp
import { resolve, relative, extname, sep, isAbsolute } from 'node:path';
import type { IncomingMessage, ServerResponse } from 'node:http';
import type { Plugin } from 'vite';
-import { validateRig } from '../rig/validate';
+// Vite bundles its config before applying aliases, so use the public source entry here.
+import { validateRig } from '../../packages/runtime/src/index';
import type { LocalProject, LocalProjectEntry } from '../project-types';
import { decodeVariants, JobError, projectJob, runTool, variantState, VARIANTS, type Runner } from './project-jobs';
diff --git a/tests/editor.test.ts b/tests/editor.test.ts
index 795ff2a..7247e64 100644
--- a/tests/editor.test.ts
+++ b/tests/editor.test.ts
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest';
import fixture from '../samples/miko-qipao/rig.json';
-import { parseRig, validateRig } from '../src/rig/validate';
+import { parseRig, validateRig } from 'mesh-avatar';
import { buildOverlay, changeVertex, moveHandle, nearestHandle, getAt, setAt } from '../src/editor/model';
const view = { scale: 0.5, x: 20, y: 10 };
diff --git a/tests/engine.test.ts b/tests/engine.test.ts
index a679a9b..aac5c67 100644
--- a/tests/engine.test.ts
+++ b/tests/engine.test.ts
@@ -1,8 +1,8 @@
import { expect, test } from 'vitest';
import fixture from '../samples/miko-qipao/rig.json';
-import { parseRig } from '../src/rig/validate';
-import { createRig, PARAMS } from '../src/engine/rig.js';
-import { createPhysics } from '../src/engine/physics.js';
+import { parseRig, PARAMS } from 'mesh-avatar';
+import { createRig } from '../packages/runtime/src/engine/rig.js';
+import { createPhysics } from '../packages/runtime/src/engine/physics.js';
test('rig instances have isolated coordinates and physics state', () => {
const a = parseRig(fixture);
diff --git a/tests/expression-overlay.test.ts b/tests/expression-overlay.test.ts
index d682606..c38f952 100644
--- a/tests/expression-overlay.test.ts
+++ b/tests/expression-overlay.test.ts
@@ -1,5 +1,5 @@
import { expect, test } from 'vitest';
-import { ExpressionOverlay, OVERLAY_EXPRESSIONS, applyOverlay, overlayTarget } from '../src/engine/expression-overlay.js';
+import { ExpressionOverlay, OVERLAY_EXPRESSIONS, applyOverlay, overlayTarget } from '../packages/runtime/src/engine/expression-overlay.js';
const tracked = { angleY: 0, eyeLOpen: 1, eyeROpen: 1, eyeSmile: 0, eyeSmileL: 0, mouthOpen: 0.7, mouthForm: 0.4, browY: 0.1, browAngle: 0, blush: 0, gazeX: 0.2, gazeY: 0 };
diff --git a/tests/expression-remote.test.ts b/tests/expression-remote.test.ts
index 5e4d943..8135b3a 100644
--- a/tests/expression-remote.test.ts
+++ b/tests/expression-remote.test.ts
@@ -6,9 +6,9 @@ import { Readable } from 'node:stream';
import type { IncomingMessage, ServerResponse } from 'node:http';
import { expressionRemote } from '../src/server/expression-remote';
import { REMOTE_EXPRESSIONS, expressionMessage, lightingPresetMessage } from '../src/live/expression-protocol';
-import { DEFAULT_LIGHTING } from '../src/lighting/settings';
+import { DEFAULT_LIGHTING } from 'mesh-avatar';
import { parseLightingPresets, sameLighting } from '../src/lighting/presets';
-import { OVERLAY_EXPRESSIONS } from '../src/engine/expression-overlay.js';
+import { OVERLAY_EXPRESSIONS } from '../packages/runtime/src/engine/expression-overlay.js';
async function call(handler: ReturnType<typeof expressionRemote>, method: string, url: string, headers: Record<string, string> = {}, body = '') {
const req = Object.assign(Readable.from(body ? [Buffer.from(body)] : []), { method, url, headers }) as unknown as IncomingMessage;
diff --git a/tests/history.test.ts b/tests/history.test.ts
index 2f593b0..0c70abe 100644
--- a/tests/history.test.ts
+++ b/tests/history.test.ts
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest';
import fixture from '../samples/miko-qipao/rig.json';
-import { parseRig } from '../src/rig/validate';
+import { parseRig } from 'mesh-avatar';
import { RigHistory } from '../src/editor/history';
import { setAt } from '../src/editor/model';
diff --git a/tests/job-reason.test.ts b/tests/job-reason.test.ts
index 7c23be9..8d6cd07 100644
--- a/tests/job-reason.test.ts
+++ b/tests/job-reason.test.ts
@@ -3,7 +3,7 @@ import fixture from '../samples/miko-qipao/rig.json';
import { jobReason } from '../src/editor/job-reason';
import { workflowEn, workflowJa } from '../src/editor/workflow-i18n';
import { runProjectJob, type LocalProject } from '../src/editor/project';
-import { parseRig } from '../src/rig/validate';
+import { parseRig } from 'mesh-avatar';
test('tool geometry failures name the part and correction in each language, ignoring successful rounding logs', () => {
const rig = parseRig(fixture), en = { ...workflowEn, accessory: 'Accessory' }, ja = { ...workflowJa, accessory: '飾り' };
diff --git a/tests/lighting.test.ts b/tests/lighting.test.ts
index 0df2e61..aea327d 100644
--- a/tests/lighting.test.ts
+++ b/tests/lighting.test.ts
@@ -1,7 +1,8 @@
import { expect, test } from 'vitest';
-import { DEFAULT_LIGHTING, lightingFromQuery, loadLighting, parseLighting, writeLightingQuery } from '../src/lighting/settings';
-import { detailGradient, generateNormals, silhouetteDistance } from '../src/lighting/normals';
-import { attenuation, diffuseTerm, shadedColor, headRotation, rimTerm, shadowOffset } from '../src/lighting/shading';
+import { DEFAULT_LIGHTING, parseLighting } from 'mesh-avatar';
+import { lightingFromQuery, loadLighting, writeLightingQuery } from '../src/lighting/storage';
+import { detailGradient, generateNormals, silhouetteDistance } from '../packages/runtime/src/lighting/normals';
+import { attenuation, diffuseTerm, shadedColor, headRotation, rimTerm, shadowOffset } from '../packages/runtime/src/lighting/shading';
import { lightingMessage, lightingValue, lightingWire } from '../src/lighting/protocol';
import { viewSettings, streamUrl } from '../src/live/settings';
diff --git a/tests/lip-sync.test.ts b/tests/lip-sync.test.ts
index cce2ad7..15192a9 100644
--- a/tests/lip-sync.test.ts
+++ b/tests/lip-sync.test.ts
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest';
-import { Motion } from '../src/engine/motion.js';
-import { kanaToMoras, sampleMoras, skippedKanaCharacters } from '../src/engine/kana.js';
+import { Motion } from '../packages/runtime/src/engine/motion.js';
+import { kanaToMoras, sampleMoras, skippedKanaCharacters } from '../packages/runtime/src/engine/kana.js';
test('held vowels share speech smoothing, preserve the preceding form for ん, and release', () => {
const motion = new Motion([0, 0]); motion.mode = 'manual';
diff --git a/tests/regression.test.ts b/tests/regression.test.ts
index 4b57980..a0263e0 100644
--- a/tests/regression.test.ts
+++ b/tests/regression.test.ts
@@ -8,12 +8,11 @@ import * as reference from '../reference/engine/rig.js';
import { buildGrid as rawReferenceGrid } from '../reference/engine/renderer.js';
import { createSprites as rawReferenceSprites } from '../reference/engine/sprites.js';
import { Physics as ReferencePhysics } from '../reference/engine/physics.js';
-import type { Rig } from '../src/rig/types';
-import { parseRig } from '../src/rig/validate';
-import { createRig, PARAMS } from '../src/engine/rig.js';
-import { createRenderer } from '../src/engine/renderer.js';
-import { createSpriteModule } from '../src/engine/sprites.js';
-import { createPhysics } from '../src/engine/physics.js';
+import { type Rig, parseRig, PARAMS } from 'mesh-avatar';
+import { createRig } from '../packages/runtime/src/engine/rig.js';
+import { createRenderer } from '../packages/runtime/src/engine/renderer.js';
+import { createSpriteModule } from '../packages/runtime/src/engine/sprites.js';
+import { createPhysics } from '../packages/runtime/src/engine/physics.js';
const rig = parseRig(fixture);
const engine = createRig(rig);
diff --git a/tests/rig.test.ts b/tests/rig.test.ts
index 30359e1..df6bb3e 100644
--- a/tests/rig.test.ts
+++ b/tests/rig.test.ts
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest';
import fixture from '../samples/miko-qipao/rig.json';
-import { parseRig, validateRig } from '../src/rig/validate';
+import { parseRig, validateRig } from 'mesh-avatar';
test('accepts the reference fixture and optional groups', () => {
expect(validateRig(fixture)).toEqual([]);
diff --git a/tests/sensitivity.test.ts b/tests/sensitivity.test.ts
index 879e6aa..4718610 100644
--- a/tests/sensitivity.test.ts
+++ b/tests/sensitivity.test.ts
@@ -1,9 +1,8 @@
import { expect, test } from 'vitest';
import fixture from '../samples/miko-qipao/rig.json';
-import { parseRig } from '../src/rig/validate';
-import type { Rig } from '../src/rig/types';
-import { createRig, PARAMS } from '../src/engine/rig.js';
-import { Motion } from '../src/engine/motion.js';
+import { parseRig, type Rig, PARAMS } from 'mesh-avatar';
+import { createRig } from '../packages/runtime/src/engine/rig.js';
+import { Motion } from '../packages/runtime/src/engine/motion.js';
const parameters: Record<string, number> = Object.fromEntries(PARAMS.map(p => [p.id, p.def]));
const physics = {
diff --git a/tests/stale.test.ts b/tests/stale.test.ts
index 49babc0..f9f68cf 100644
--- a/tests/stale.test.ts
+++ b/tests/stale.test.ts
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest';
import fixture from '../samples/miko-qipao/rig.json';
-import { parseRig } from '../src/rig/validate';
+import { parseRig } from 'mesh-avatar';
import { layerSignature } from '../src/editor/stale';
test('cut-out changes mark layers stale without altering precut eye curves', () => {
diff --git a/tests/viewport.test.ts b/tests/viewport.test.ts
index ebced4b..35f83c0 100644
--- a/tests/viewport.test.ts
+++ b/tests/viewport.test.ts
@@ -1,7 +1,7 @@
import { test, expect } from 'vitest';
import fixture from '../samples/miko-qipao/rig.json';
import { buildOverlay, imagePoint, nearestHandle, screen } from '../src/editor/model';
-import { parseRig } from '../src/rig/validate';
+import { parseRig } from 'mesh-avatar';
import { zoomAt, fitBounds, partBounds } from '../src/editor/viewport';
test('zoom keeps the image coordinate under the cursor even at both scale limits', () => {
diff --git a/tools/render-poses.mjs b/tools/render-poses.mjs
index 344a129..12986a0 100644
--- a/tools/render-poses.mjs
+++ b/tools/render-poses.mjs
@@ -3,7 +3,7 @@ import { resolve, relative, dirname, basename } from 'node:path';
import { fileURLToPath } from 'node:url';
import { createServer } from 'vite';
import { chromium } from '@playwright/test';
-import { validateRig } from '../src/rig/validate.ts';
+import { validateRig } from '../packages/runtime/src/rig/validate.ts';
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const poses = [
@@ -70,8 +70,7 @@ async function main() {
await page.route('**/*', route => new URL(route.request().url()).origin === origin ? route.continue() : route.abort());
await page.goto(`${origin}/__pose_review__`);
const result = await page.evaluate(async ({ rig, assets, poses }) => {
- const { createMeshAvatar } = await import('/src/engine/index.ts');
- const { PARAMS } = await import('/src/engine/rig.js');
+ const { createMeshAvatar, PARAMS } = await import('/packages/runtime/src/index.ts');
const canvas = document.getElementById('avatar');
const width = Math.ceil(rig.image.width * 1.2), height = Math.ceil(rig.image.height * 1.1);
canvas.style.width = `${width}px`; canvas.style.height = `${height}px`;
diff --git a/tools/validate-rig.mjs b/tools/validate-rig.mjs
index 7a37ba5..0055e08 100644
--- a/tools/validate-rig.mjs
+++ b/tools/validate-rig.mjs
@@ -1,6 +1,6 @@
import { readFile } from 'node:fs/promises';
import { basename } from 'node:path';
-import { validateRig } from '../src/rig/validate.ts';
+import { validateRig } from '../packages/runtime/src/rig/validate.ts';
const args = process.argv.slice(2);
const files = args.filter(arg => arg !== '--draft');
diff --git a/tsconfig.json b/tsconfig.json
index dbc997f..388274d 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -8,6 +8,9 @@
],
"module": "ESNext",
"moduleResolution": "Bundler",
+ "paths": {
+ "mesh-avatar": ["./packages/runtime/src/index.ts"]
+ },
"jsx": "react-jsx",
"strict": true,
"allowJs": true,
@@ -19,6 +22,8 @@
},
"include": [
"src",
+ "packages/runtime/src",
+ "packages/runtime/tests",
"tests",
"e2e",
"vite.config.ts",
diff --git a/vite.config.ts b/vite.config.ts
index 9000e56..eb1eca0 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -6,6 +6,7 @@ import { localProjectsPlugin } from './src/server/local-projects';
import { mediapipeAssets } from './src/server/mediapipe-assets';
import { liveRelay } from './src/server/live-relay';
export default defineConfig({
+ resolve: { alias: { 'mesh-avatar': fileURLToPath(new URL('./packages/runtime/src/index.ts', import.meta.url)) } },
server: { host: '127.0.0.1' },
plugins: [react(), localProjectsPlugin(fileURLToPath(new URL('.', import.meta.url))), mediapipeAssets(fileURLToPath(new URL('.', import.meta.url))), liveRelay(fileURLToPath(new URL('.', import.meta.url))), {
name: 'sample-rig',
@@ -21,5 +22,5 @@ export default defineConfig({
}],
publicDir: 'samples',
build: { rollupOptions: { input: { editor: 'index.html', stream: 'stream.html', live: 'live.html' } } },
- test: { include: ['tests/**/*.test.ts'] },
+ test: { include: ['tests/**/*.test.ts', 'packages/runtime/tests/**/*.test.ts'] },
});