Turn one illustration into an animated 2D mesh avatar with a coding agent and a local editor
feat(runtime): add optional rig.view.irisTravel
IkeaSourPatchesacde8e8e69eb
diff --git a/.changeset/iris-travel.md b/.changeset/iris-travel.mdnew file mode 100644index 0000000..be0925c--- /dev/null+++ b/.changeset/iris-travel.md@@ -0,0 +1,5 @@+---+"mesh-avatar": minor+---++Add optional `rig.view.irisTravel` to set how far the irises move at full gaze. Avatars without it keep the previous 7 px.diff --git a/docs/rig-fields.md b/docs/rig-fields.mdindex 42c42e2..f9abfc0 100644--- a/docs/rig-fields.md+++ b/docs/rig-fields.md@@ -10,7 +10,7 @@ radii and mesh cell sizes must be positive. Mesh cell sizes and fine-mesh rectancoordinates must be integers. Accessory boxes must be integer rectangles inside the image. A band is `[start, end]` with `start < end`.Ellipses are smooth influence regions, not hard cut-out boundaries.-Only `buns`, `strands`, `accessories`, `hand` and `view.gazeCenter` are optional. Omit absent+Only `buns`, `strands`, `accessories`, `hand`, `view.gazeCenter` and `view.irisTravel` are optional. Omit absentoptional groups. Required regions must still be placed even if their animation will be small.The initial draft has empty eye polygons and is intentionally invalid until they are traced.See [agent-guide.md](agent-guide.md) for the process and [rig-mapping.md](rig-mapping.md) for@@ -146,6 +146,7 @@ the engine mapping. Do not copy the example illustration's coordinates into a ne| `view.padTop` | Top viewport margin as fraction of source height; negative crops crown, must be between -1 and 1. || `view.padSide` | Each side viewport margin as fraction of source width; start at `0`, must exceed -0.5. || `view.gazeCenter` | Optional pointer-follow origin `[x,y]`, px; between eyes; defaults to head centre. |+| `view.irisTravel` | Optional iris travel at full gaze, px; defaults to `7`. Raise it for large eyes, around 15% of the eye opening width. |Draft validation accepts omitted `x0/x1/top/bot` only as a complete group; supplying some ofthe four fields is an error. Complete rigs always require all four. Changing eye geometrydiff --git a/docs/rig-mapping.md b/docs/rig-mapping.mdindex a9f16c9..4dcc63b 100644--- a/docs/rig-mapping.md+++ b/docs/rig-mapping.md@@ -19,6 +19,7 @@ spring/motion tuning remain engine behavior constants.| mesh | createMeshAvatar.js layer cell sizes and fine rectangle; sprites.js sprite cell || view | createMeshAvatar.js padTop/padSide defaults || view.gazeCenter (optional) | motion.js pointer-follow origin; defaults to head center when omitted |+| view.irisTravel (optional) | createMeshAvatar.js iris offset in px at gaze ±1; defaults to 7 when omitted |The anatomical centers used by the deformation formulas (brow, eyes and chest) also comefrom the matching rig Gaussian centers. Bun spring anchors use their Gaussian centers.diff --git a/packages/runtime/src/engine/createMeshAvatar.js b/packages/runtime/src/engine/createMeshAvatar.jsindex f9cc301..b6b6e4a 100644--- a/packages/runtime/src/engine/createMeshAvatar.js+++ b/packages/runtime/src/engine/createMeshAvatar.js@@ -236,7 +236,7 @@ export async function createMeshAvatarImpl(canvas, options) {physics.chains.forEach((ch, k) => deformTassel(ch, tassels[k].mesh));if (CLOTH.length) { cloth.step(P, dt, phys); cloth.deform(); }- const ball = 7; // px of iris travel+ const ball = rig.view.irisTravel ?? 7; // px of iris travel; rig.view.irisTravel scales it for large eyesR.draw({angleX: P.angleX, angleY: P.angleY, angleZ: P.angleZ,eyes: [diff --git a/packages/runtime/src/rig/types.ts b/packages/runtime/src/rig/types.tsindex 834ffa3..91a3b25 100644--- a/packages/runtime/src/rig/types.ts+++ b/packages/runtime/src/rig/types.ts@@ -138,5 +138,5 @@ export interface Rig {handCell: number; tasselCell: number; eyeBallCell: number;eyeCell: number; spriteCell: number; clothCell?: number;};- view: { padTop: number; padSide: number; gazeCenter?: Point };+ view: { padTop: number; padSide: number; gazeCenter?: Point; irisTravel?: number };}diff --git a/packages/runtime/src/rig/validate.ts b/packages/runtime/src/rig/validate.tsindex ae36e6b..c175a93 100644--- a/packages/runtime/src/rig/validate.ts+++ b/packages/runtime/src/rig/validate.ts@@ -93,7 +93,7 @@ const schema = (draft: boolean) => object({y0: wholeNumber, y1: wholeNumber, cell: integer }), handCell: integer,tasselCell: integer, eyeBallCell: integer, eyeCell: integer, spriteCell: integer,clothCell: integer }, ['clothCell']),- view: object({ padTop: number, padSide: number, gazeCenter: point }, ['gazeCenter']),+ view: object({ padTop: number, padSide: number, gazeCenter: point, irisTravel: positive }, ['gazeCenter', 'irisTravel']),}, ['buns', 'strands', 'accessories', 'hand', 'cloth', 'legs', 'arms']);export function validateRig(value: unknown, options: { draft?: boolean } = {}): string[] {diff --git a/tests/rig.test.ts b/tests/rig.test.tsindex df6bb3e..ebf08f4 100644--- a/tests/rig.test.ts+++ b/tests/rig.test.ts@@ -53,3 +53,13 @@ test('rejects fractional and out-of-image accessory boxes and fractional mesh vaconst rig = parseRig(fixture); rig.mesh.fine.x0 = 340.2; rig.mesh.fine.cell = 7.2;expect(validateRig(rig).join()).toContain('rig.mesh.fine.x0'); expect(validateRig(rig).join()).toContain('rig.mesh.fine.cell');});++test('accepts an optional positive iris travel and rejects other values', () => {+ const rig = parseRig(fixture);+ rig.view.irisTravel = 17;+ expect(validateRig(rig)).toEqual([]);+ for (const bad of [0, -3, NaN]) {+ rig.view.irisTravel = bad;+ expect(validateRig(rig).join()).toContain('rig.view.irisTravel');+ }+});