[PR #7549] [MERGED] feat(avatars): 2D avatars — PNGTuber sprites and mesh avatars #7788

Closed
opened 2026-10-24 04:07:30 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7549
Author: @SpicyMarinara
Created: 10/13/2026
Status: ✅ Merged
Merged: 10/13/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/avatars-2d


📝 Commits (9)

  • 7eaf27c feat(avatars): import PNGTuber Plus saves and mesh avatars
  • 28e6ed4 Merge remote-tracking branch 'origin/feat/avatars-contract' into feat/avatars-2d
  • 9b76a2c feat(avatars): PNGTuber and mesh avatar renderers and setup panels
  • 0e3cdee test(avatars): import PNGTuber Plus's own default avatar save
  • 0ffb732 Merge remote-tracking branch 'origin/feat/avatars-contract' into feat/avatars-2d
  • 8216ed4 fix(avatars): keep an imported PNGTuber setup when sprites change
  • 5d1ec08 fix(avatars): mesh avatars load under the CSP and stop leaking; PNGTuber mouths flap
  • d2051dd fix(avatars): bound what a hostile 2D avatar import can cost
  • cdbb281 Merge branch 'staging' into feat/avatars-2d

📊 Changes

16 files changed (+4319 additions, -51 deletions)

View changed files

📝 docs/agents/avatars.md (+29 -1)
➕ e2e/avatar-2d.e2e.ts (+553 -0)
📝 packages/client/src/features/avatars/renderers/mesh-avatar/MeshAvatarSetupPanel.tsx (+170 -4)
➕ packages/client/src/features/avatars/renderers/mesh-avatar/mesh-avatar-face.ts (+133 -0)
📝 packages/client/src/features/avatars/renderers/mesh-avatar/mesh-avatar-renderer.ts (+341 -10)
📝 packages/client/src/features/avatars/renderers/pngtuber/PngtuberSetupPanel.tsx (+339 -4)
➕ packages/client/src/features/avatars/renderers/pngtuber/pngtuber-layers.ts (+215 -0)
📝 packages/client/src/features/avatars/renderers/pngtuber/pngtuber-renderer.ts (+234 -9)
➕ packages/client/src/features/avatars/renderers/pngtuber/use-avatar-kind-actions.ts (+39 -0)
📝 packages/client/src/localization/locales/en.json (+59 -0)
📝 packages/server/src/services/avatars/formats/mavatar.ts (+548 -13)
📝 packages/server/src/services/avatars/formats/pngtuber.ts (+691 -10)
➕ scripts/regressions/avatar-2d-importers.regression.ts (+465 -0)
➕ scripts/regressions/avatar-2d-renderers.regression.ts (+289 -0)
➕ scripts/regressions/fixtures/avatar-2d-fixtures.ts (+213 -0)
➕ scripts/regressions/fixtures/pngtuber-plus-default-avatar.save (+1 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Refs #7537 (lane: 2D)

Depended on https://github.com/Pasta-Devs/Marinara-Engine/pull/7539 ("feat(avatars): shared contract for the 2D and 3D avatar agents", Refs #7537), which merged into staging on 2026-10-13 (13d796e1e). This branch merges current staging (56fd7b6c9), so the diff now shows only this lane's files.

Why this change

  • The 2D Avatars agent shows two kinds of avatar, PNGTuber sprites and mesh avatars. The contract left their renderers, setup panels and importers as inert stubs; this lane fills them in.
  • Mari wants an owner with expression sprites to get a talking avatar with no setup, PNGTuber Plus saves and Mesh Avatar Studio files to import without new size limits, and mesh avatars to stay cheap on phones (one WebGL context, lazy chunk, sprites as the fallback).

What changed

Nothing that worked before changes: these files were inert stubs, and nothing in the app mounts the stage or the setup until the base lane lands.

  • PNGTuber renderer (renderers/pngtuber/): draws an owner's faces on a 2D canvas. With no PNGTuber setup it builds one from the owner's expression sprites, portraits before full-body, with _talk / _blink sprites (and their spelling variants) as the mouth-open and eyes-closed pictures. A frame shows the exact sprite label first (an Expression Engine or Game Master pick), then the face bound to its emotion, then the resting face. The mouth opens on vowels and closes on consonants (hysteresis band 0.42 / 0.30), so it flaps with the director's speech clock and with text-to-speech levels. Blinks come every 3 to 6 seconds (or when the director says), faces crossfade in 120 ms, the avatar hops while talking and breathes while idle. Reduced motion keeps the face and mouth but drops the hop, breathing and thinking tilt. Paused renderers do nothing, decoded pictures are capped per avatar, and a resize redraws at once (also while paused).
  • Mesh avatar renderer (renderers/mesh-avatar/): drives mesh-avatar 0.1.1 with manual: true from the stage's loop. Emotions map to setEmotion (or a live expression the user picked), visemes to holdMouth, TTS loudness to setVoiceLevel, director blinks and gaze to parameter overrides that keep each feeling's own eye shape, and reduced motion holds the head still.
    • All mesh avatars draw through one shared, detached WebGL2 canvas, held at the largest avatar size in use and scaled onto each avatar's own canvas in the same task, so avatars of different sizes never reallocate it and the context needs no preserveDrawingBuffer.
    • Each owner's .mavatar is opened once and every mount reuses its URLs. mesh-avatar caches pictures and JSON by URL in module-level maps it never clears, so reopening per mount kept every mount's pictures alive.
    • No CSP change. mesh-avatar reads the package's layers.json and sprites.json with fetch(blob:), which the server's connect-src refuses. While an avatar loads, fetch answers exactly those two blob URLs from memory and passes every other request through (marked ponytail: with its upgrade path). Pictures load as images, which img-src already allows.
    • Without WebGL2, when the file cannot be played, or on context loss, the avatar falls back to the PNGTuber renderer with the owner's sprites. A resize redraws at once, also while paused.
  • PNGTuber Plus .save import (services/avatars/formats/pngtuber.ts): each distinct costume becomes one layer set, flattened at rest with PNGTuber Plus's own rules (parent offsets, relative z-order, talk/blink visibility, clipping, costume switches; main.gd and spriteObject.gd). Costumes map to feelings by the names of the pictures only that costume shows. The file is treated as hostile: every field is type-checked, sprites are capped at 512 and animation frames at 256, PNGs are checked by signature and header (up to sharp's own 16383 px bound) before sharp decodes them, and a far-flung layout is scaled to 2048 px instead of refused. A clipping sprite's descendants are drawn and cut inside its own rectangle in one pass, so nested clipping costs what its pictures cost.
  • .mavatar import (services/avatars/formats/mavatar.ts): read with the strict openZipArchive and AVATAR_IMPORT_MAX_BYTES per entry. The kept files also share that same 256 MiB cap once unpacked, as .marinara packages do in import.routes.ts; this is not a limit below the upload cap, it only stops an archive that inflates past it. The file is checked against the format's version 1 rules (the rig mirrors the runtime's validateRig; every listed PNG must exist and fit the rig's image). A rig whose mesh would exceed 500,000 points (counted the way the runtime's buildGrid lays them; a 2048 px rig at Studio's example cell sizes has about 70,000) is refused because it would freeze the chat. The kept files are repacked with only what the player reads, as stored entries the runtime opens. Emotions bind to the runtime presets; mouths and blinks report whether drawn sprites exist. packMeshAvatarArchive is exported for the generation lane.
  • Setup panels: the PNGTuber panel shows the faces, lets the user pick a face per feeling, the hop and the blink rate, saves the sprites as a setup, imports a .save and shows its import notes. Update from sprites only shows for a setup built from sprites, so it never replaces an imported or generated one (Remove goes back to the sprites). The mesh avatar panel imports or replaces a .mavatar, says whether it has drawn mouth shapes, and lets the user pick a look per feeling (the six feelings plus Smile, Shy, Half-closed eyes and Wink). Copy is in en.json under avatars.pngtuber.* and avatars.meshAvatar.*.
  • Guide: docs/agents/avatars.md, section "2D avatars: PNGTuber sprites and mesh avatars". The translation follow-up is #7540.

Review fixes (5d1ec08a8, d2051dd85)

Each finding was reproduced first, and each now has a proof. The before numbers are from the previous head (8216ed41d):

  • Mesh avatars fell back to sprites under the production CSP (connect-src has no blob:). The new e2e serves the page with the server's own connect-src / img-src from securityHeadersHook: the old renderer painted nothing, and the new one paints with no CSP violations.
  • Every mesh mount kept all of the avatar's pictures alive through mesh-avatar's URL caches (the review measured 13 kept per mount of the fixture). The e2e now counts new Image() over three remounts and expects none after the first mount.
  • Mesh avatars of different sizes reallocated the shared canvas on every draw: 124 reallocations in 30 frames before, 0 now.
  • Both renderers left a blank canvas after a resize, and while paused until unpaused. They now redraw at once (e2e for both).
  • With Blink off, mesh avatars lost each feeling's eye shape. The override now uses the preset's eye openness (happy 0.8, angry 0.72, sad 0.78, relaxed 0.82, surprised 1.18), eased at the runtime's rate; pinned in the regression.
  • The PNGTuber mouth hung open for whole sentences with the speech clock. On the same speech trace, the old band gave 0.77 flaps/s, open 93% of the time and a 2.5 s stretch; the new band gives 2.31 flaps/s, 52% and 533 ms. Pinned in the regression.
  • A 268 KB deflated .mavatar was stored as 270 MB. It is now refused before anything is held or stored.
  • A 4.4 KB rig with 1 px cells on a 4096 px image was accepted. It is now refused as too detailed.
  • 248 nested clipping sprites on a 2041 px canvas took 23.6 s to import; they now take 0.6 s.

Notes for the other lanes (no contract change)

  • Base: the panels call PUT /api/avatar-models/:ownerType/:ownerId, POST …/import (multipart kind then file) and DELETE …/kinds/:kind, and set activeKind to pngtuber on the first PNGTuber save when none is set. resolveImage for a sprite ref should prefer the portrait over a full_ sprite with the same key; the PNGTuber renderer falls back to its own resolvePngtuberImage when resolveImage returns null. The stage can pass createAvatarConfig(owner, now) for an owner with sprites but no avatar.json: the PNGTuber renderer then builds the setup from the sprites. Import errors are AvatarImportError with plain messages; unsupported-format also covers "image processing is not available" (no sharp). Calling resize() from a ResizeObserver is safe: both renderers redraw there.
  • Director: the PNGTuber mouth band assumes the speech clock's levels (consonants 0.2, vowels 0.5 or more); if those change, nextPngtuberMouthOpen in pngtuber-layers.ts is the one place to retune.
  • Until the stage imports the contract, Vite's dev server first meets mesh-avatar when something imports the renderer and reloads the page once; the e2e waits that out. Once the stage imports contract.ts, Vite's scan finds it at startup.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Commands run by the agent on cdbb2813d (results as reported, not ticked):

  • pnpm check: passed. The one react-hooks/exhaustive-deps warning is existing, in a file this PR does not touch.
  • pnpm localization:check (part of pnpm check): passed.
  • node scripts/run-regressions.mjs --filter avatar-: 8/8 passed. This includes avatar-2d-importers (now also the unpacked-size cap, the mesh density check against a Studio-sized rig, and the clip chain) and avatar-2d-renderers (now also the speech-trace mouth flapping, eye overrides per feeling, and the shared-canvas copy rectangle).
  • --filter agent-activation, --filter spatial-context, --filter open-issues, --filter zip-reader: all passed (after pnpm build:shared for the staging merge).
  • npx playwright test e2e/avatar-2d.e2e.ts on desktop-chromium (9/9, re-run on the merged head), mobile-chromium and mobile-webkit (18/18). That is 9 tests per project, 4 of them new: the server CSP with picture reuse, different slot sizes plus resize while paused for mesh avatars, and resize while paused for PNGTuber. The three new renderer tests fail on the previous head, as listed above.
  • Lazy chunks: the renderer imports only mesh-avatar (its openAvatar, unpackAvatar, loadMeshAvatar) inside renderers/mesh-avatar/. The avatar-contract bundle guard passes.
  • Local CodeRabbit CLI review (coderabbit review --agent --committed --base-commit 56fd7b6c9, merge base with staging): completed with 0 findings on all 16 lane files. The earlier run on 8216ed41d had one minor finding, fixed in 8216ed41d.
  • Real file: PNGTuber Plus's own autoload/defaultAvatar.save (The Unlicense, commit ece4ffd1) still flattens into the expected base, talk, blink and blink-talk pictures (pinned in the regression).

Manual verification needed

These need the base lane's setup and stage; until then the panels and renderers are not reachable in the app.

  • Production build (CSP): run pnpm build and start the Engine server (not the Vite dev server). Import a .mavatar, then open the agent page and a Roleplay chat in desktop Chrome, Firefox and Safari. Check that the mesh avatar itself shows (not the sprites) and that DevTools shows no Content-Security-Policy violation.
  • Desktop Chrome, Firefox and Safari: on the 2D Avatars agent page, pick a character with expression sprites. Check that the PNGTuber panel lists the faces, marks faces that have _talk / _blink sprites, and that Use my sprites, a face per feeling and the hop and blink settings save and survive a reload.
  • Same browsers: import a real PNGTuber Plus .save (one with several costumes, talk/blink layers and a clipped layer). Compare each flattened costume with how PNGTuber Plus shows it at rest, quiet, talking and blinking.
  • Same browsers: import a .mavatar exported from Mesh Avatar Studio, then in a Roleplay chat check that the face follows the reply, the mouth moves while streaming and with TTS, and the face stays after the reply ends. With Blink off, check that a happy or surprised face keeps its narrowed or wide eyes.
  • Same browsers: in a Roleplay reply, check that a PNGTuber avatar's talk picture flaps with the words rather than staying open for the whole sentence.
  • Same browsers: open and switch between chats with mesh avatars ten or more times. In DevTools Memory, check that memory does not keep climbing.
  • Desktop: drag the window edge and change sprite scale while avatars show. Check that they never blank out, also while Appearance settings are open.
  • Android Chrome and the Android app WebView: open a chat with two mesh avatars of different sprite scales and two PNGTuber avatars. Check the frame rate, that only the budgeted number draw, and that switching away from the app and back resumes them. Rotate the phone and check that the avatars stay visible.
  • iOS Safari: the same chat. Check that the mesh avatars draw (WebGL2), and that turning on Reduce Motion stops the hop and head sway while the mouth still moves.
  • Light and dark themes, phone width: check the panels' layout, the import notes and the remove confirmation.
  • Termux (no sharp): importing a .save shows the plain "Image processing isn't available on this device" message; .mavatar imports still work.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

docs/agents/avatars.md gains its 2D section, which now also says what the mesh avatar import refuses. Translations follow in #7540.

UI evidence (if applicable)

Screenshots were taken locally from the e2e harness (panels in light and dark, desktop and phone width, and a mesh avatar drawn through the shared context) and checked by eye; they are not attached, to keep uploads private.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7549 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/13/2026 **Status:** ✅ Merged **Merged:** 10/13/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/avatars-2d` --- ### 📝 Commits (9) - [`7eaf27c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7eaf27ccdf3735a9bb6db3440f646f183b8cb193) feat(avatars): import PNGTuber Plus saves and mesh avatars - [`28e6ed4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/28e6ed41d58eaf5ce414324855146db893f1e8e0) Merge remote-tracking branch 'origin/feat/avatars-contract' into feat/avatars-2d - [`9b76a2c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9b76a2caa91eebd619d64e1c3bacb2aa9cc4e60c) feat(avatars): PNGTuber and mesh avatar renderers and setup panels - [`0e3cdee`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0e3cdee74bf5a9806c044c1ca505d2a129b00ec4) test(avatars): import PNGTuber Plus's own default avatar save - [`0ffb732`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0ffb73264df69fe6a91c68016501e2dd1fcd8029) Merge remote-tracking branch 'origin/feat/avatars-contract' into feat/avatars-2d - [`8216ed4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8216ed41d238aaefb4bf284e31bf14d4e8dab8c2) fix(avatars): keep an imported PNGTuber setup when sprites change - [`5d1ec08`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5d1ec08a8413cdcecf1331f2e639b3f558f6f004) fix(avatars): mesh avatars load under the CSP and stop leaking; PNGTuber mouths flap - [`d2051dd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d2051dd8596b2997f520555b96198c9945ab1960) fix(avatars): bound what a hostile 2D avatar import can cost - [`cdbb281`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cdbb2813d3db3f9764c281a6f823666d9302a02a) Merge branch 'staging' into feat/avatars-2d ### 📊 Changes **16 files changed** (+4319 additions, -51 deletions) <details> <summary>View changed files</summary> 📝 `docs/agents/avatars.md` (+29 -1) ➕ `e2e/avatar-2d.e2e.ts` (+553 -0) 📝 `packages/client/src/features/avatars/renderers/mesh-avatar/MeshAvatarSetupPanel.tsx` (+170 -4) ➕ `packages/client/src/features/avatars/renderers/mesh-avatar/mesh-avatar-face.ts` (+133 -0) 📝 `packages/client/src/features/avatars/renderers/mesh-avatar/mesh-avatar-renderer.ts` (+341 -10) 📝 `packages/client/src/features/avatars/renderers/pngtuber/PngtuberSetupPanel.tsx` (+339 -4) ➕ `packages/client/src/features/avatars/renderers/pngtuber/pngtuber-layers.ts` (+215 -0) 📝 `packages/client/src/features/avatars/renderers/pngtuber/pngtuber-renderer.ts` (+234 -9) ➕ `packages/client/src/features/avatars/renderers/pngtuber/use-avatar-kind-actions.ts` (+39 -0) 📝 `packages/client/src/localization/locales/en.json` (+59 -0) 📝 `packages/server/src/services/avatars/formats/mavatar.ts` (+548 -13) 📝 `packages/server/src/services/avatars/formats/pngtuber.ts` (+691 -10) ➕ `scripts/regressions/avatar-2d-importers.regression.ts` (+465 -0) ➕ `scripts/regressions/avatar-2d-renderers.regression.ts` (+289 -0) ➕ `scripts/regressions/fixtures/avatar-2d-fixtures.ts` (+213 -0) ➕ `scripts/regressions/fixtures/pngtuber-plus-default-avatar.save` (+1 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Refs #7537 (lane: 2D) Depended on https://github.com/Pasta-Devs/Marinara-Engine/pull/7539 ("feat(avatars): shared contract for the 2D and 3D avatar agents", Refs #7537), which merged into `staging` on 2026-10-13 (13d796e1e). This branch merges current `staging` (56fd7b6c9), so the diff now shows only this lane's files. ## Why this change - The **2D Avatars** agent shows two kinds of avatar, PNGTuber sprites and mesh avatars. The contract left their renderers, setup panels and importers as inert stubs; this lane fills them in. - Mari wants an owner with expression sprites to get a talking avatar with no setup, PNGTuber Plus saves and Mesh Avatar Studio files to import without new size limits, and mesh avatars to stay cheap on phones (one WebGL context, lazy chunk, sprites as the fallback). ## What changed Nothing that worked before changes: these files were inert stubs, and nothing in the app mounts the stage or the setup until the base lane lands. - **PNGTuber renderer** (`renderers/pngtuber/`): draws an owner's faces on a 2D canvas. With no PNGTuber setup it builds one from the owner's expression sprites, portraits before full-body, with `_talk` / `_blink` sprites (and their spelling variants) as the mouth-open and eyes-closed pictures. A frame shows the exact sprite label first (an Expression Engine or Game Master pick), then the face bound to its emotion, then the resting face. The mouth opens on vowels and closes on consonants (hysteresis band 0.42 / 0.30), so it flaps with the director's speech clock and with text-to-speech levels. Blinks come every 3 to 6 seconds (or when the director says), faces crossfade in 120 ms, the avatar hops while talking and breathes while idle. Reduced motion keeps the face and mouth but drops the hop, breathing and thinking tilt. Paused renderers do nothing, decoded pictures are capped per avatar, and a resize redraws at once (also while paused). - **Mesh avatar renderer** (`renderers/mesh-avatar/`): drives `mesh-avatar` 0.1.1 with `manual: true` from the stage's loop. Emotions map to `setEmotion` (or a live expression the user picked), visemes to `holdMouth`, TTS loudness to `setVoiceLevel`, director blinks and gaze to parameter overrides that keep each feeling's own eye shape, and reduced motion holds the head still. - All mesh avatars draw through **one shared, detached WebGL2 canvas**, held at the largest avatar size in use and scaled onto each avatar's own canvas in the same task, so avatars of different sizes never reallocate it and the context needs no `preserveDrawingBuffer`. - Each owner's `.mavatar` is opened **once** and every mount reuses its URLs. mesh-avatar caches pictures and JSON by URL in module-level maps it never clears, so reopening per mount kept every mount's pictures alive. - **No CSP change.** mesh-avatar reads the package's `layers.json` and `sprites.json` with `fetch(blob:)`, which the server's `connect-src` refuses. While an avatar loads, `fetch` answers exactly those two blob URLs from memory and passes every other request through (marked `ponytail:` with its upgrade path). Pictures load as images, which `img-src` already allows. - Without WebGL2, when the file cannot be played, or on context loss, the avatar falls back to the PNGTuber renderer with the owner's sprites. A resize redraws at once, also while paused. - **PNGTuber Plus `.save` import** (`services/avatars/formats/pngtuber.ts`): each distinct costume becomes one layer set, flattened at rest with PNGTuber Plus's own rules (parent offsets, relative z-order, talk/blink visibility, clipping, costume switches; main.gd and spriteObject.gd). Costumes map to feelings by the names of the pictures only that costume shows. The file is treated as hostile: every field is type-checked, sprites are capped at 512 and animation frames at 256, PNGs are checked by signature and header (up to sharp's own 16383 px bound) before sharp decodes them, and a far-flung layout is scaled to 2048 px instead of refused. A clipping sprite's descendants are drawn and cut inside its own rectangle in one pass, so nested clipping costs what its pictures cost. - **`.mavatar` import** (`services/avatars/formats/mavatar.ts`): read with the strict `openZipArchive` and `AVATAR_IMPORT_MAX_BYTES` per entry. The kept files also share that same 256 MiB cap once unpacked, as `.marinara` packages do in `import.routes.ts`; this is not a limit below the upload cap, it only stops an archive that inflates past it. The file is checked against the format's version 1 rules (the rig mirrors the runtime's `validateRig`; every listed PNG must exist and fit the rig's image). A rig whose mesh would exceed 500,000 points (counted the way the runtime's `buildGrid` lays them; a 2048 px rig at Studio's example cell sizes has about 70,000) is refused because it would freeze the chat. The kept files are repacked with only what the player reads, as stored entries the runtime opens. Emotions bind to the runtime presets; mouths and blinks report whether drawn sprites exist. `packMeshAvatarArchive` is exported for the generation lane. - **Setup panels**: the PNGTuber panel shows the faces, lets the user pick a face per feeling, the hop and the blink rate, saves the sprites as a setup, imports a `.save` and shows its import notes. **Update from sprites** only shows for a setup built from sprites, so it never replaces an imported or generated one (Remove goes back to the sprites). The mesh avatar panel imports or replaces a `.mavatar`, says whether it has drawn mouth shapes, and lets the user pick a look per feeling (the six feelings plus Smile, Shy, Half-closed eyes and Wink). Copy is in `en.json` under `avatars.pngtuber.*` and `avatars.meshAvatar.*`. - **Guide**: `docs/agents/avatars.md`, section "2D avatars: PNGTuber sprites and mesh avatars". The translation follow-up is #7540. ### Review fixes (5d1ec08a8, d2051dd85) Each finding was reproduced first, and each now has a proof. The before numbers are from the previous head (8216ed41d): - Mesh avatars fell back to sprites under the production CSP (`connect-src` has no `blob:`). The new e2e serves the page with the server's own `connect-src` / `img-src` from `securityHeadersHook`: the old renderer painted nothing, and the new one paints with no CSP violations. - Every mesh mount kept all of the avatar's pictures alive through mesh-avatar's URL caches (the review measured 13 kept per mount of the fixture). The e2e now counts `new Image()` over three remounts and expects none after the first mount. - Mesh avatars of different sizes reallocated the shared canvas on every draw: 124 reallocations in 30 frames before, 0 now. - Both renderers left a blank canvas after a resize, and while paused until unpaused. They now redraw at once (e2e for both). - With Blink off, mesh avatars lost each feeling's eye shape. The override now uses the preset's eye openness (happy 0.8, angry 0.72, sad 0.78, relaxed 0.82, surprised 1.18), eased at the runtime's rate; pinned in the regression. - The PNGTuber mouth hung open for whole sentences with the speech clock. On the same speech trace, the old band gave 0.77 flaps/s, open 93% of the time and a 2.5 s stretch; the new band gives 2.31 flaps/s, 52% and 533 ms. Pinned in the regression. - A 268 KB deflated `.mavatar` was stored as 270 MB. It is now refused before anything is held or stored. - A 4.4 KB rig with 1 px cells on a 4096 px image was accepted. It is now refused as too detailed. - 248 nested clipping sprites on a 2041 px canvas took 23.6 s to import; they now take 0.6 s. ### Notes for the other lanes (no contract change) - **Base**: the panels call `PUT /api/avatar-models/:ownerType/:ownerId`, `POST …/import` (multipart `kind` then `file`) and `DELETE …/kinds/:kind`, and set `activeKind` to `pngtuber` on the first PNGTuber save when none is set. `resolveImage` for a sprite ref should prefer the portrait over a `full_` sprite with the same key; the PNGTuber renderer falls back to its own `resolvePngtuberImage` when `resolveImage` returns null. The stage can pass `createAvatarConfig(owner, now)` for an owner with sprites but no `avatar.json`: the PNGTuber renderer then builds the setup from the sprites. Import errors are `AvatarImportError` with plain messages; `unsupported-format` also covers "image processing is not available" (no sharp). Calling `resize()` from a ResizeObserver is safe: both renderers redraw there. - **Director**: the PNGTuber mouth band assumes the speech clock's levels (consonants 0.2, vowels 0.5 or more); if those change, `nextPngtuberMouthOpen` in `pngtuber-layers.ts` is the one place to retune. - **Until the stage imports the contract**, Vite's dev server first meets `mesh-avatar` when something imports the renderer and reloads the page once; the e2e waits that out. Once the stage imports `contract.ts`, Vite's scan finds it at startup. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Commands run by the agent on cdbb2813d (results as reported, not ticked): - `pnpm check`: passed. The one `react-hooks/exhaustive-deps` warning is existing, in a file this PR does not touch. - `pnpm localization:check` (part of `pnpm check`): passed. - `node scripts/run-regressions.mjs --filter avatar-`: 8/8 passed. This includes `avatar-2d-importers` (now also the unpacked-size cap, the mesh density check against a Studio-sized rig, and the clip chain) and `avatar-2d-renderers` (now also the speech-trace mouth flapping, eye overrides per feeling, and the shared-canvas copy rectangle). - `--filter agent-activation`, `--filter spatial-context`, `--filter open-issues`, `--filter zip-reader`: all passed (after `pnpm build:shared` for the staging merge). - `npx playwright test e2e/avatar-2d.e2e.ts` on desktop-chromium (9/9, re-run on the merged head), mobile-chromium and mobile-webkit (18/18). That is 9 tests per project, 4 of them new: the server CSP with picture reuse, different slot sizes plus resize while paused for mesh avatars, and resize while paused for PNGTuber. The three new renderer tests fail on the previous head, as listed above. - Lazy chunks: the renderer imports only `mesh-avatar` (its `openAvatar`, `unpackAvatar`, `loadMeshAvatar`) inside `renderers/mesh-avatar/`. The `avatar-contract` bundle guard passes. - Local CodeRabbit CLI review (`coderabbit review --agent --committed --base-commit 56fd7b6c9`, merge base with staging): completed with 0 findings on all 16 lane files. The earlier run on 8216ed41d had one minor finding, fixed in 8216ed41d. - Real file: PNGTuber Plus's own `autoload/defaultAvatar.save` (The Unlicense, commit ece4ffd1) still flattens into the expected base, talk, blink and blink-talk pictures (pinned in the regression). ### Manual verification needed These need the base lane's setup and stage; until then the panels and renderers are not reachable in the app. - **Production build (CSP)**: run `pnpm build` and start the Engine server (not the Vite dev server). Import a `.mavatar`, then open the agent page and a Roleplay chat in desktop Chrome, Firefox and Safari. Check that the mesh avatar itself shows (not the sprites) and that DevTools shows no Content-Security-Policy violation. - Desktop Chrome, Firefox and Safari: on the 2D Avatars agent page, pick a character with expression sprites. Check that the PNGTuber panel lists the faces, marks faces that have `_talk` / `_blink` sprites, and that **Use my sprites**, a face per feeling and the hop and blink settings save and survive a reload. - Same browsers: import a real PNGTuber Plus `.save` (one with several costumes, talk/blink layers and a clipped layer). Compare each flattened costume with how PNGTuber Plus shows it at rest, quiet, talking and blinking. - Same browsers: import a `.mavatar` exported from Mesh Avatar Studio, then in a Roleplay chat check that the face follows the reply, the mouth moves while streaming and with TTS, and the face stays after the reply ends. With **Blink** off, check that a happy or surprised face keeps its narrowed or wide eyes. - Same browsers: in a Roleplay reply, check that a PNGTuber avatar's talk picture flaps with the words rather than staying open for the whole sentence. - Same browsers: open and switch between chats with mesh avatars ten or more times. In DevTools Memory, check that memory does not keep climbing. - Desktop: drag the window edge and change sprite scale while avatars show. Check that they never blank out, also while Appearance settings are open. - Android Chrome and the Android app WebView: open a chat with two mesh avatars of different sprite scales and two PNGTuber avatars. Check the frame rate, that only the budgeted number draw, and that switching away from the app and back resumes them. Rotate the phone and check that the avatars stay visible. - iOS Safari: the same chat. Check that the mesh avatars draw (WebGL2), and that turning on Reduce Motion stops the hop and head sway while the mouth still moves. - Light and dark themes, phone width: check the panels' layout, the import notes and the remove confirmation. - Termux (no sharp): importing a `.save` shows the plain "Image processing isn't available on this device" message; `.mavatar` imports still work. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) `docs/agents/avatars.md` gains its 2D section, which now also says what the mesh avatar import refuses. Translations follow in #7540. ## UI evidence (if applicable) Screenshots were taken locally from the e2e harness (panels in light and dark, desktop and phone width, and a mesh avatar drawn through the shared context) and checked by eye; they are not attached, to keep uploads private. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:07:30 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7788
No description provided.