Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Muse Reskin

Drop a 3D model into the browser, type a theme, and get the model back retextured, as a GLB.

Muse Reskin reads a glTF/GLB model's texture atlas and UV layout. It then asks Meta Muse to repaint the atlas in the theme you typed, while keeping every UV island where it was so the new texture still wraps the model. It also rebuilds the normal and roughness maps to match. The result can be exported as a new .glb.

Live demo: https://modstorm.github.io/MS_MetaAIContest2026/ (Click Sample model, pick a theme, press Reskin. Without a key, choose the Offline backend in ⚙ Settings.)


Quick start (local)

Requires Node.js 20 or newer.

git clone https://github.com/modstorm/MS_MetaAIContest2026.git
cd MS_MetaAIContest2026
npm install
cp .env.example .env        # then put your Meta Model API key in MUSE_API_KEY
npm run dev                 # opens http://localhost:5173

You can get a key at dev.meta.ai. Without one, the harness falls back to the offline procedural backend, so the whole pipeline (analysis, maps, export) still runs.

Command What it does
npm run dev Harness dev server with the local Muse proxy
npm run build Static build of the harness into harness/dist/ (no key is ever included)
npm test Plugin unit tests (Vitest)
npm run test:e2e Browser tests with Playwright: offline backend, mocked Muse API, drag-and-drop

How it works

GLB ──► load (GLTFLoader, Draco + meshopt)
     ──► analyze: group meshes by base color texture → UV islands, coverage, overlap, tiling
     ──► suggest: renders six axis views (±X ±Y ±Z); muse-spark-1.3 looks at them + the UV atlases,
                  says what the object is, and recommends a stronger part-by-part prompt
                  and a per-region paint plan → shown to the user to review and edit
     ──► plan:    (without suggest) muse-spark-1.3 reads the atlas + UV wireframe and names each region
     ──► paint:   muse-image-1.0 /images/edits repaints the atlas in the theme, layout locked
               (untextured or tiled materials: /images/generations makes a seamless texture)
     ──► post:    resize to the source size, keep a little of the original shading,
                  derive normal + roughness maps from the new albedo (glTF ORM packing kept)
     ──► apply:   swap textures on the live three.js materials (original kept for compare)
     ──► export:  GLTFExporter → .glb

Edge cases handled:

  • Which patch is which part: each mesh's UV area is drawn in its own color and named (Hair, Head, Body…) in a part map sent to Muse, so details land on the right part.

  • Part by part: when a texture is shared by several named meshes (head, shirt, pants, shoes…), each part is cut out of the atlas on its own, turned upright, greyed outside its islands and painted with its own prompt (up to 4 Muse calls at once). The result is pasted back only inside that part's islands, so a design can't drift onto the wrong part or leave stripes of the old texture. paintMode: 'atlas' paints the whole atlas in one call instead.

  • Front, back and sides: each area also gets a facing map from the 3D normals (green front, blue back, yellow/orange sides, magenta top, cyan bottom), so front details such as buttons or a pocket watch stay on the front.

  • Asset classes: avatar, creature, vehicle, tool, furniture, building, terrain, vegetation, sky, prop or generic. Each adds its own prompt rules. The class is detected by the art-director step or from part names, can be overridden in the popup, and new classes are one registerAssetClass({...}) call.

  • ID map: the ID map button shows every texture area in its own flat color on the model (same colors as the atlas area map). The suggestion step also sends these renders to Muse.

  • Zone locks: the Zones panel lists every area with its ID color. Lock the ones you like (🔒, or plugin.setLocked(name)) and the next prompt repaints only the unlocked zones; locked zones keep their current paint.

  • Strand hair: hair built from many strands (cards or spikes, each its own UV island) is not painted as one pattern. Each strand is shaded on its own in the hair color Muse picked: dark at the root, light at the tip, with fine streaks along the strand and a slight shift per strand. Hair that is one solid cap keeps Muse's paint.

  • Skin leftovers: on avatars, small skin-colored patches that Muse leaves in clothing (sleeve sides, trouser side strips, gloves, shoes) are filled from the surrounding paint. Areas that are mostly skin (short sleeves, bare hands) are left alone.

  • Variations, history, compare: paint 1 to 3 variations at once (painted in parallel) and pick a favorite. Every result goes into a History strip with undo/redo (Ctrl+Z). Compare shows a before/after slider, and the model spins on a turntable until you grab it. While painting part by part, each area appears on the model as soon as Muse returns it.

  • Learned tips: review passes also write short general lessons ("keep chest details on front-facing areas"), stored per asset type in the browser and added to future prompts. You can view, edit, import or export them under Advanced.

  • Review & fix: after painting, the result is rendered from 8 angles (the six axis views plus 45° front and back), stacked with the same views as an ID map in one image. Muse Spark lists problems per area and only those areas are repainted (postReview({ passes })).

  • Upside-down, sideways or mirrored islands: the plugin works out from the 3D data which way "up" points in the texture. It turns the atlas upright before painting (head/face first) and turns the result back. The texture's own flipY and KHR_texture_transform are applied first, and the popup has a manual orientation override.

  • Safety filter rejections: a plainer retry runs automatically, the popup shows a clear error with Retry, and a filter probe shows which input was rejected.

  • Meshes with no UVs get box-projected UVs and a seamless texture.

  • Materials with no texture get a generated seamless texture.

  • Stacked or mirrored UVs and tiled UVs (outside 0..1) are detected and reported.

  • Shared atlases: a texture used by many meshes or materials is repainted once.

  • Multi-file .gltf: drop the .gltf together with its .bin and image files.

Repository layout

plugin/            the reskin plugin (plain ES modules, depends only on three)
  src/
    ReskinPlugin.js        the class a host uses: post functions + update listener
    muse/MuseClient.js     Meta Model API client (images, chat/completions, SAM via responses, asr/transcribe)
    muse/pricing.js        model prices, usage tally and cost estimate
    muse/prompts.js        all prompts sent to Muse
    providers/             MuseProvider, ProceduralProvider (offline), provider contract
    analysis/              UV islands, coverage/overlap, texture layout, UV generation
    texture/               canvas helpers, UV guide rendering, normal/roughness derivation
    io/modelIO.js          GLB/glTF loading and GLB export
    server/index.js        optional Node proxy that adds the API key server-side
  test/                    unit tests
harness/           browser test harness (three.js viewer, drag-and-drop, prompt popup)
  src/                     main.js, viewer.js, sampleModel.js, styles.css
  tests/e2e.mjs            Playwright end-to-end tests

Using the plugin in your own app

The plugin is a single class. You post inputs to it and listen for updates. It owns every Muse call and all mesh and texture processing.

import { ReskinPlugin } from '@metaai26/reskin-plugin';

const plugin = new ReskinPlugin({ muse: { apiKey: 'YOUR_KEY' } }); // or { muse: { baseUrl: '/api/muse' } } behind a proxy

plugin.onUpdate(({ type, data }) => console.log(type, data));   // every event
plugin.on('textureUpdated', ({ kind, canvas }) => { /* preview */ });

const { model, layout } = await plugin.postModel(file);          // File, File[], Blob, ArrayBuffer or URL
scene.add(model.scene);

const suggestion = await plugin.postSuggest('haunted Halloween pumpkin armor'); // optional: review suggestion.prompt
await plugin.postPrompt(suggestion.prompt, { suggestion, detailPreserve: 0.35 });
const { glb, filename } = await plugin.postExport();             // ArrayBuffer
Method Purpose
postModel(input, opts?) Load and analyze a model. Emits loaded.
postSuggest(theme, opts?) Art-director step: six-view renders + atlases → Muse Spark recommends a prompt and region plan. Emits views, suggestion. Nothing is painted.
postPrompt(prompt, opts?) Reskin the current model. Emits progress, plan, textureUpdated, reskinned.
postExport(filename?) Export a GLB. Emits exported.
on(type, cb) / onUpdate(cb) Subscribe to one event type or to all events. Both return an unsubscribe function.
showOriginal(bool), revert(), cancel() Compare before and after, undo, or stop a running reskin.
setProvider(provider) Swap the backend (MuseProvider, ProceduralProvider, or your own).
summary(), slotPreview(id) JSON layout summary, plus atlas and UV preview canvases.

postPrompt options: suggestion (from postSuggest), fast (default on: no Muse web search, low reasoning, smaller uploads), detailPreserve (0..1), useVisionPlanning, normalMaps, roughnessMaps, maxTextureSize, extraInstructions, slotIds, signal.

A custom backend is any object with reskinAtlas(req) and generateTexture(req). It may also have planLayout(req) and reskinAuxMap(req). See plugin/src/providers/types.js.

API keys and security

  • Keys go in .env. Only .env.example is committed, and .env is git-ignored.
  • In npm run dev, the key from .env is given to the browser so it can call https://api.meta.ai/v1 directly. If the browser call is blocked (for example by CORS), the request is retried through the dev server's proxy at /api/muse, which adds the key on the server side.
  • npm run build never embeds the key. On the hosted demo, you paste your own key in ⚙ Settings, and it is stored only in that browser's localStorage.
  • For production, put plugin/src/server/index.js (createMuseMiddleware) in front of the API and point the plugin at it with baseUrl.

Meta models used

Muse Reskin uses five of Meta's models, each for its own job:

  • Muse Spark (muse-spark-1.3) is the brain. It looks at six rendered views of the model and works out what it is (avatar, vehicle, prop, sky…) and which part is which. It turns your short idea like "steampunk" into a detailed paint plan, splits that plan into a theme for each part, and at the end reviews the painted result from 8 angles so only the problem areas get repainted. Each review also saves a few lessons that improve later reskins.
  • Muse Wonder (muse-wonder-1.0, Preview) is an optional deeper-thinking version of Spark for the suggestion and review steps, picked in Settings. If Wonder turns a request down, that step falls back to Spark.
  • Muse Image (muse-image-1.0) is the painter. It repaints each part of the texture using a mask and a style reference, so the colours stay consistent across parts. It also makes seamless tiled materials, gloves and hands, transparent images (it paints on a flat colour that the plugin then strips out, like the fences and the mountain ring), and normal and roughness maps if you want them.
  • SAM 3.1 (sam-3.1) is the inspector. After each part is painted, it checks for things that landed in the wrong place, like a face on the trousers. If it finds one, only the pixels SAM marked get repainted.
  • Muse Voice Transcribe (muse-voice-transcribe-1.0) lets you say the theme out loud. The words fill the Theme box, and Spark reviews them the same as typed text.
Model Endpoint Price (dev.meta.ai, 2026-11)
muse-spark-1.3 /v1/chat/completions $1.25 / $4.25 per 1M tokens in / out ($0.15 cached)
muse-wonder-1.0 /v1/chat/completions $4 / $20 per 1M tokens in / out
muse-image-1.0 /v1/images/edits, /v1/images/generations $0.01 per image
sam-3.1 /v1/responses (streamed masks) $2.50 per 1,000 images
muse-voice-transcribe-1.0 /v1/asr/transcribe $3 per 1,000 audio minutes

Every call's usage is counted. The harness shows the cost of the current reskin and of the session, and an estimate before you paint (plugin/src/muse/pricing.js). To use other model versions, set imageModel, visionModel, samModel or transcribeModel in the muse options.

Request formats, from dev.meta.ai/docs:

  • POST /v1/images/edits: JSON body { model, prompt, images: [{ image_url }], size, output_format }
  • POST /v1/images/generations: { model, prompt, size, output_format }
  • POST /v1/chat/completions: OpenAI-style messages with image_url parts
  • POST /v1/responses (SAM 3.1): a short noun phrase (input_text) and an input_image; the masks stream back and are decoded with @meta-sam/parser
  • POST /v1/asr/transcribe: a multipart audio upload

License

MIT. See LICENSE.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages