mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #7549] [MERGED] feat(avatars): 2D avatars — PNGTuber sprites and mesh avatars #7788
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#7788
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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)
7eaf27cfeat(avatars): import PNGTuber Plus saves and mesh avatars28e6ed4Merge remote-tracking branch 'origin/feat/avatars-contract' into feat/avatars-2d9b76a2cfeat(avatars): PNGTuber and mesh avatar renderers and setup panels0e3cdeetest(avatars): import PNGTuber Plus's own default avatar save0ffb732Merge remote-tracking branch 'origin/feat/avatars-contract' into feat/avatars-2d8216ed4fix(avatars): keep an imported PNGTuber setup when sprites change5d1ec08fix(avatars): mesh avatars load under the CSP and stop leaking; PNGTuber mouths flapd2051ddfix(avatars): bound what a hostile 2D avatar import can costcdbb281Merge 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
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
stagingon 2026-10-13 (13d796e1e). This branch merges currentstaging(56fd7b6c9), so the diff now shows only this lane's files.Why this change
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.
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/_blinksprites (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).renderers/mesh-avatar/): drivesmesh-avatar0.1.1 withmanual: truefrom the stage's loop. Emotions map tosetEmotion(or a live expression the user picked), visemes toholdMouth, TTS loudness tosetVoiceLevel, director blinks and gaze to parameter overrides that keep each feeling's own eye shape, and reduced motion holds the head still.preserveDrawingBuffer..mavataris 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.layers.jsonandsprites.jsonwithfetch(blob:), which the server'sconnect-srcrefuses. While an avatar loads,fetchanswers exactly those two blob URLs from memory and passes every other request through (markedponytail:with its upgrade path). Pictures load as images, whichimg-srcalready allows..saveimport (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..mavatarimport (services/avatars/formats/mavatar.ts): read with the strictopenZipArchiveandAVATAR_IMPORT_MAX_BYTESper entry. The kept files also share that same 256 MiB cap once unpacked, as.marinarapackages do inimport.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'svalidateRig; 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'sbuildGridlays 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.packMeshAvatarArchiveis exported for the generation lane..saveand 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 inen.jsonunderavatars.pngtuber.*andavatars.meshAvatar.*.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):connect-srchas noblob:). The new e2e serves the page with the server's ownconnect-src/img-srcfromsecurityHeadersHook: the old renderer painted nothing, and the new one paints with no CSP violations.new Image()over three remounts and expects none after the first mount..mavatarwas stored as 270 MB. It is now refused before anything is held or stored.Notes for the other lanes (no contract change)
PUT /api/avatar-models/:ownerType/:ownerId,POST …/import(multipartkindthenfile) andDELETE …/kinds/:kind, and setactiveKindtopngtuberon the first PNGTuber save when none is set.resolveImagefor a sprite ref should prefer the portrait over afull_sprite with the same key; the PNGTuber renderer falls back to its ownresolvePngtuberImagewhenresolveImagereturns null. The stage can passcreateAvatarConfig(owner, now)for an owner with sprites but noavatar.json: the PNGTuber renderer then builds the setup from the sprites. Import errors areAvatarImportErrorwith plain messages;unsupported-formatalso covers "image processing is not available" (no sharp). Callingresize()from a ResizeObserver is safe: both renderers redraw there.nextPngtuberMouthOpeninpngtuber-layers.tsis the one place to retune.mesh-avatarwhen something imports the renderer and reloads the page once; the e2e waits that out. Once the stage importscontract.ts, Vite's scan finds it at startup.Validation
pnpm checkpasses locallyCONTRIBUTING.mdCommands run by the agent on
cdbb2813d(results as reported, not ticked):pnpm check: passed. The onereact-hooks/exhaustive-depswarning is existing, in a file this PR does not touch.pnpm localization:check(part ofpnpm check): passed.node scripts/run-regressions.mjs --filter avatar-: 8/8 passed. This includesavatar-2d-importers(now also the unpacked-size cap, the mesh density check against a Studio-sized rig, and the clip chain) andavatar-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 (afterpnpm build:sharedfor the staging merge).npx playwright test e2e/avatar-2d.e2e.tson 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.mesh-avatar(itsopenAvatar,unpackAvatar,loadMeshAvatar) insiderenderers/mesh-avatar/. Theavatar-contractbundle guard passes.coderabbit review --agent --committed --base-commit 56fd7b6c9, merge base with staging): completed with 0 findings on all 16 lane files. The earlier run on8216ed41dhad one minor finding, fixed in8216ed41d.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.
pnpm buildand 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._talk/_blinksprites, and that Use my sprites, a face per feeling and the hop and blink settings save and survive a reload..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..mavatarexported 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..saveshows the plain "Image processing isn't available on this device" message;.mavatarimports still work.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)docs/agents/avatars.mdgains 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.