pixelkiln 0.105.0 → 0.106.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5710,7 +5710,7 @@
5710
5710
  addLoopRow({ id: "idle", what: "breathing-idle", directions: ["south"] });
5711
5711
  }
5712
5712
  updatePrice();
5713
- setTimeout(() => baseId.focus(), 0);
5713
+ baseId.focus();
5714
5714
  }
5715
5715
 
5716
5716
  // src/gallery/client/src/keys.ts
@@ -16,7 +16,12 @@ Last updated 16 November 2026.
16
16
  | 6 | Triangulate a 3D skeleton from 2D joints | PixelLab skeleton estimate + our script | 18 joints, 1.3 px mean error | Keep. This is a rig. |
17
17
  | 7 | Build the body from tubes around the bones | Our script | 79% | Drop. Carving is better. |
18
18
  | 8 | Generate a mesh from four views | Hunyuan3D-2mv in ComfyUI, RTX 3060 12 GB | About two minutes a mesh; 70 to 83% | Cleaner geometry, looser match. Needs its own texture step. |
19
- | 9 | Unwrap the mesh and texture it from the sprites | Not built yet | | Next. See [What is next](#what-is-next). |
19
+ | 9 | Unwrap the mesh and texture it from the sprites, in stages | Our script, with xatlas for the unwrap | Colour error down by a fifth to a half against one-pass colouring, on all five | Keep. The texture is now a picture that can be repaired. |
20
+ | 10 | Let the views vote on each texel's colour | Our script | Colour error down another 1 to 4 on every subject and shape | Keep, as the default. |
21
+ | 11 | Texture the carved shape the same way | Our script, marching cubes | Better than the mesh on the character and torch, worse on the two swords | Keep both shapes. Which is better depends on the object. |
22
+ | 12 | Carved shape cut back to the mesh | Our script | No better than carving alone | Drop. |
23
+ | 13 | Have an image model redraw the model's rough renders | PixelLab `edit_image`, `inpaint_image`, `correct_pixelart` | Clean sprites at angles the generator never drew: sixteen directions from eight, for 10 generations | Keep. This is the best result so far, and it changes what the 3D model is for. |
24
+ | 14 | Paint the redrawn views back onto the model | Our script | Smoother, still muddy | Drop for now. The model is a guide, not the final picture. |
20
25
 
21
26
  **How the percentages are measured.** The model is projected back to each of the eight camera positions and its outline is compared with the sprite's outline. The score is the area the two share divided by the area either covers, averaged over the views. 100% means the model casts exactly the sprite's shadow from every side. It measures shape only, not colour. It also favours carving, which is built from those same outlines.
22
27
 
@@ -174,20 +179,205 @@ Tubes matched 79% against carving's 95%. The result is a blob with limbs: no han
174
179
 
175
180
  **Verdict.** Use it when clean geometry matters more than matching the sprite exactly. It needs a texture step of its own.
176
181
 
177
- ## What is next
182
+ ## 9. Texturing in stages
183
+
184
+ **Question.** Steps 4 and 8 coloured the model in one pass, straight from the sprites onto voxels. Does splitting the work into stages (fit, unwrap, project, fill, render) give a better result on the Hunyuan3D meshes?
185
+
186
+ **Setup.** Script: [`scripts/texture.py`](../research/scripts/texture.py). It takes about six seconds a mesh on a laptop. Libraries: trimesh, xatlas, fast-simplification, numpy, scipy.
187
+
188
+ 1. **Fit.** The mesh is simplified to 30,000 triangles, then lined up with the sprites' cameras by searching for the turn, the camera height, a scale for each of the three axes, and a one or two pixel shift per view that make its outline match the sprites best. Step 8 only tried quarter turns and one scale.
189
+ 2. **Unwrap.** xatlas flattens the surface into a 256×256 texture.
190
+ 3. **Project.** Every texel is given the colour of the sprite pixel it lands on, from the one view that faces it most squarely and can see it. Outline pixels are never used. Texels then agree with their neighbours on which view to use, so the surface does not speckle where two views meet.
191
+ 4. **Fill.** A texel no view could see takes the colour of the nearest texel that was seen, measured across the surface in 3D.
192
+ 5. **Render.** Unlit, at sprite size, each pixel taking the most common colour among the texels in front, with a drawn outline.
193
+
194
+ It also writes a textured `.glb` that opens in Blender or any glTF viewer.
195
+
196
+ **Result.** Four rows per subject: the sprites; the same mesh coloured in one pass (step 8); the mesh textured in stages; and the staged model from the eight directions in between.
197
+
198
+ ![Sprites, one-pass colouring, staged texture, and staged texture from between views, for five subjects](../website/public/research/3d/texture-staged.png)
199
+
200
+ The texture itself, for the chest. Left: the unwrapped texture. Right: which of the eight sprites each texel took its colour from, one colour per view; dark grey was seen by none and filled in.
201
+
202
+ ![The chest's unwrapped texture and its view map](../website/public/research/3d/texture-atlas-chest.png)
203
+
204
+ Three numbers per method. *Shape* is the outline match used throughout. *Colour error* is the mean difference per colour channel, out of 255, over the pixels where model and sprite overlap; lower is better. *Close* is the share of those pixels within 24 of the sprite's colour on every channel. All three are measured on the rendered pictures by [`scripts/score.py`](../research/scripts/score.py), which first slides each render to where it overlaps its sprite best, so the shape numbers here are a little lower than the ones in the earlier steps.
205
+
206
+ | Subject | Method | Shape | Colour error | Close |
207
+ |---|---|---|---|---|
208
+ | Character | Carved, one pass | 92% | 40.5 | 42% |
209
+ | | Mesh, one pass | 85% | 49.4 | 37% |
210
+ | | Mesh, staged | 88% | 42.9 | 46% |
211
+ | Chest | Carved, one pass | 92% | 42.3 | 41% |
212
+ | | Mesh, one pass | 85% | 49.2 | 30% |
213
+ | | Mesh, staged | 90% | 32.0 | 54% |
214
+ | Sword | Carved, one pass | 91% | 36.3 | 50% |
215
+ | | Mesh, one pass | 79% | 52.2 | 37% |
216
+ | | Mesh, staged | 89% | 31.3 | 60% |
217
+ | Torch | Carved, one pass | 89% | 35.4 | 48% |
218
+ | | Mesh, one pass | 76% | 53.3 | 25% |
219
+ | | Mesh, staged | 83% | 28.6 | 59% |
220
+ | Greatsword | Carved, one pass | 94% | 18.4 | 72% |
221
+ | | Mesh, one pass | 71% | 22.3 | 70% |
222
+ | | Mesh, staged | 89% | 13.9 | 81% |
223
+
224
+ - **The better fit closed most of the shape gap.** The meshes went from 71 to 85% to 83 to 90%, with no change to the meshes themselves. Carving is still ahead on shape by 2 to 6 points.
225
+ - **Staged texturing beat one-pass colouring on every subject,** and beat the carved model's colour on four of five. The character is the exception: the mesh's hands, head and chest are a different shape from the sprite's, so muscle lines land in the wrong place.
226
+ - **The torch has a flame again.** The mesh has no flame, but the sprite's flame pixels land on the top of the basket.
227
+ - **The greatsword's two tilted views were left out,** and the model is upright from those directions with the runes in place.
228
+ - **A mirror image cannot be told apart by outline.** For every subject the mirrored fit scored within a tenth of a point of the true one. The script assumes the mesh is not mirrored, which held for all five. Front and back are nearly as close on symmetric objects (83.2 against 83.1 for the chest), so the result should be looked at, not trusted.
229
+
230
+ **Tried and dropped,** on the character, none of which moved the colour error by more than a point or two:
231
+
232
+ - Blending views by weight and snapping to the palette, instead of one view per texel: 48% close against 54%. Blending muddies the pixel art.
233
+ - Letting a texel that lands just outside the sprite take the nearest pixel inside it: slightly worse.
234
+ - Refusing colour from pixels beside a jump in the mesh's depth (its outer edge, an arm in front of the body): no better, and a quarter of the texels left to fill.
235
+
236
+ The remaining error on the character is the mesh's shape, not the texturing.
237
+
238
+ **Verdict.** Keep. Staging is the better way to colour a mesh, and it leaves a texture file that can be repaired as an ordinary picture.
239
+
240
+ ## 10. Letting the views vote
241
+
242
+ **Question.** After step 9 the remaining flaws are dark specks where one sprite has a contour line and its neighbour has plain colour. The eight sprites are eight separate drawings and do not agree. Can the texture take the consensus instead of trusting one view?
243
+
244
+ **Setup.** Three rules for choosing a texel's colour, all in `texture.py`:
245
+
246
+ - `MODE=best` (step 9): the one view that faces the texel most squarely.
247
+ - `MODE=vote`: when three or more views can see the texel, take the colour closest to the middle of what they all say, leaning toward views that face it. Colours still come straight from a sprite, so the palette is kept.
248
+ - `DESPECKLE`: after colouring, replace any texel much darker than the surface around it.
249
+
250
+ **Result.** Voting lowered the colour error on all five subjects, on both shapes, by 1 to 4 points (table under step 11). It loses a little crispness on a face seen head-on. Despeckling made the numbers slightly worse at every threshold tried (25, 40, 60) and removed wanted detail with the specks.
251
+
252
+ **Verdict.** Vote is the better default. Despeckle is dropped.
253
+
254
+ ## 11. Texturing the carved shape
255
+
256
+ **Question.** Carving matches the sprite's outline best and staged texturing colours best. Do they combine?
257
+
258
+ **Setup.** `carve.ts` with `DUMP=1` writes its voxels and its fitted camera. `texture.py` with `VOX` and `CAMERA` turns the voxels into a mesh with marching cubes and runs the same unwrap, project, fill and render on it, using the carve's camera so nothing needs fitting.
259
+
260
+ Two things had to be right before the numbers meant anything, and both are easy to get wrong again:
261
+
262
+ - **Where the surface is cut.** The carve treats each voxel as a point at its centre. A mesh cut half a voxel outside those centres (the usual setting) renders a pixel fatter than the sprite all round. The surface is cut through the outermost centres instead (`LEVEL=0.9`).
263
+ - **Half a pixel.** The carve drops a voxel into a pixel by rounding down. In views whose centre falls on a half pixel, that puts every voxel half a pixel to the right of where its cube really is. The camera is corrected for this on import. Before the fix the carved sword scored 86%; after, 89%.
264
+
265
+ **Result.** Four rows per subject: the sprites; the Hunyuan3D mesh with one view per texel (step 9); the same mesh with voting (step 10); the carved shape with voting.
266
+
267
+ ![Sprites, mesh with one view per texel, mesh with voting, and carved shape with voting](../website/public/research/3d/texture-shapes.png)
268
+
269
+ These numbers come from `texture.py` itself, which scores its render in place, so they differ by a point or two from the table in step 9.
270
+
271
+ | Subject | Shape and rule | Shape | Colour error | Close |
272
+ |---|---|---|---|---|
273
+ | Character | Mesh, one view | 88.0% | 37.7 | 54% |
274
+ | | Mesh, vote | 88.0% | 35.9 | 56% |
275
+ | | Carved, vote | 90.5% | 34.5 | 53% |
276
+ | Chest | Mesh, one view | 91.2% | 31.1 | 56% |
277
+ | | Mesh, vote | 91.2% | 28.5 | 56% |
278
+ | | Carved, vote | 91.0% | 28.1 | 57% |
279
+ | Sword | Mesh, one view | 89.6% | 32.7 | 56% |
280
+ | | Mesh, vote | 89.6% | 29.1 | 58% |
281
+ | | Carved, vote | 88.6% | 32.7 | 52% |
282
+ | Torch | Mesh, one view | 82.2% | 28.2 | 59% |
283
+ | | Mesh, vote | 82.2% | 25.7 | 60% |
284
+ | | Carved, vote | 88.0% | 25.6 | 58% |
285
+ | Greatsword | Mesh, one view | 88.7% | 14.4 | 79% |
286
+ | | Mesh, vote | 88.7% | 13.5 | 81% |
287
+ | | Carved, vote | 86.9% | 21.9 | 70% |
288
+
289
+ - **Carving wins where the object is bulky or not solid.** The character gains 2.5 points of shape and the best colour so far. The torch gains 6 points of shape and gets its whole flame back, because carving keeps anything the sprites show.
290
+ - **The mesh wins on thin, flat objects.** Both swords are better as Hunyuan3D meshes. A blade two voxels thick is at the limit of what a 64-voxel grid can hold, and the greatsword was carved from only six views.
291
+ - **The chest is a tie.**
292
+ - Neither shape is better everywhere, so the choice should be made per object, by score.
178
293
 
179
- Step 9 is to stop colouring the model in one pass and split the work into stages, the way the pipeline in the Discord thread does:
294
+ **Verdict.** Keep both. The useful rule so far: carve characters, soft or hollow things and anything with parts that are not solid; use a generated mesh for thin rigid objects.
180
295
 
181
- 1. **Shape.** A carved model or a Hunyuan3D mesh.
182
- 2. **Unwrap.** Flatten the surface into a 2D texture, like unfolding a paper model.
183
- 3. **Project.** Paint each sprite onto the texture from its own direction, blending where views overlap, leaving out outline pixels and baked-in shading.
184
- 4. **Fix the texture as a picture.** The texture is now an ordinary image: snap it to the sprite's palette, fill the gaps no view could see, and repaint seams. This is where an image model can help, since repairing a 2D image is what they are good at.
185
- 5. **Render.** Flat lighting and a drawn outline, at sprite size.
296
+ ## 12. Carved shape, cut back to the mesh
186
297
 
187
- Open questions for that work:
298
+ **Question.** Carving cannot see a gap that no view looks through, such as between the legs. The generated mesh has those gaps. Does keeping only the carved voxels that are near the mesh give the best of both?
188
299
 
189
- - Does a better fit of the mesh to the sprites (a proper search over scale, turn and shift) bring the Hunyuan3D match up to carving's?
190
- - Does projecting onto a texture at a higher resolution than the sprite avoid the stretching seen between views in step 4?
300
+ **Setup.** `HYBRID=2`: the Hunyuan3D mesh is fitted into the carve's camera and filled in, grown by two voxels, and intersected with the carved voxels. Also tried at one and three voxels.
301
+
302
+ **Result.** No gain. On the character it changed the scores by a tenth of a point. On both swords the grown mesh covered the whole carved shape, so the result was identical to carving. On the torch it cut part of the flame away (shape 86.3% against 88.0%).
303
+
304
+ **Verdict.** Drop. The gaps it was meant to open are small at this size, and the mesh does not line up closely enough with the sprite to cut safely.
305
+
306
+ ## 13. Redrawing the rough renders with an image model
307
+
308
+ **Question.** Everything up to step 12 tries to make the textured model look right by itself. What if the model only has to be roughly right, and an image model draws the final sprite from it?
309
+
310
+ **Setup.** The carved, vote-textured character from step 11, rendered from sixteen directions: the eight the generator drew and the eight halfway between. Four ways of repairing the sixteen rough renders, all through PixelLab:
311
+
312
+ | Method | Call | Cost |
313
+ |---|---|---|
314
+ | Tidy | `correct_pixelart`, strength 0.4, 16 frames | 0.1 |
315
+ | Edit by instruction | `edit_image`, 16 frames in one call, told to remove specks and torn patches and keep pose and direction | 10 |
316
+ | Edit by reference | `edit_image` with the true south sprite as the reference, 15 frames | 10 |
317
+ | Guide sheet | `inpaint_image` on a 256×256 sheet: each true sprite beside the rough view next to it, only the rough ones masked open | 10 |
318
+
319
+ **Result.** Ten rows. 1: the true sprites. 2 to 5: the model at those same eight directions, as rendered, tidied, edited by instruction, edited by reference (which has no first frame; it was the reference). 6 to 10: the eight directions in between, as rendered, tidied, edited by instruction, edited by reference, and from the guide sheet.
320
+
321
+ ![Four repair methods on the character, at the drawn directions and between them](../website/public/research/3d/repair-methods.png)
322
+
323
+ - **Tidying does nothing useful.** It is built for stray pixels, not for a torn surface.
324
+ - **The two edits and the guide sheet all return clean sprites,** at directions the generator never drew, in the same style and proportions as the eight it did. These are the first in-between views in this note that look like finished art.
325
+ - **The outline survives.** Each redraw kept 93 to 100% of the rough render's outline, so the model is deciding the pose and the image model the surface.
326
+ - **Edits move the figure.** `edit_image` re-centred some frames by up to six pixels; the guide sheet moved none. A redrawn frame has to be slid back to where its render was.
327
+ - **The score does not see the improvement.** Against the true sprites, the instruction edit scores 36.3 colour error where the rough render scores 37.6, and fewer pixels within tolerance (39% against 49%), because the image model picks its own shades. The number says "no better"; the picture says otherwise. Colour error against one drawing was the wrong measure for this step.
328
+
329
+ **A dressed character.** The same thing on a clothed one: the bare base with greaves, plate, cape and helm composited from the paperdoll layers, on an 80px canvas. It carved at 92%. Held items had to be left off: a sword is held at a different angle in every view, so the carve removes it.
330
+
331
+ Top pair of rows: directions 1 to 8 as rendered from the model, then after `edit_image` by instruction. Bottom pair: directions 9 to 16. Every second figure is one the generator drew; the ones between are new.
332
+
333
+ ![The dressed knight in sixteen directions, rough and redrawn](../website/public/research/3d/repair-knight-turnaround.png)
334
+
335
+ The redrawn in-between views are a clean, recognisable knight. They are also a little squat next to the drawn ones: the carve loses some of the horns' height and the head sits lower, and the redraw keeps the model's proportions. Editing by reference cleaned less than editing by instruction here.
336
+
337
+ The sixteen directions are on the website as a viewer that turns the character, on the [paperdoll page](https://pixelkiln.griffen.codes/paperdoll#turnaround), with a switch to the raw model.
338
+
339
+ **Verdict.** Keep, and change direction. The 3D model does not have to look good. It has to put the right shapes and rough colours in the right place from any angle, and an image model does the drawing. Eight new directions cost 10 generations.
340
+
341
+ ## 14. Painting the redrawn views back onto the model
342
+
343
+ **Question.** If the redrawn in-between views are clean, does projecting all sixteen onto the model give a clean texture?
344
+
345
+ **Setup.** `EXTRA` in `texture.py` adds the eight redrawn views as extra cameras, so each texel has sixteen views to vote among.
346
+
347
+ **Result.** Pairs of rows (drawn directions, then between): the eight-view texture; with the guide-sheet views added; with the instruction edits added; with the reference edits added.
348
+
349
+ ![The model textured from eight views and from sixteen](../website/public/research/3d/repair-reprojected.png)
350
+
351
+ Slightly smoother, still blotchy, and the score against the sprites got worse (colour error 39 against 34.5), since the new views bring their own shades.
352
+
353
+ **Verdict.** Drop for now. Sixteen separate drawings disagree as much as eight did. A texture stitched from separate drawings of a 64-pixel figure comes out muddy however the stitching is done, which is the lesson of steps 9 to 14 together.
354
+
355
+ ## What has not worked, in one place
356
+
357
+ So nobody repeats them:
358
+
359
+ - Tubes around a skeleton as the body (step 7).
360
+ - Blending colours between views (step 9).
361
+ - Reaching inward for a colour when a texel lands just outside the sprite (step 9).
362
+ - Refusing colour near jumps in depth (step 9).
363
+ - Despeckling the texture by darkness (step 10).
364
+ - Rounding the carved voxels more before meshing: no effect on the scores.
365
+ - Intersecting the carved shape with the generated mesh (step 12).
366
+ - `correct_pixelart` on a torn render (step 13).
367
+ - Projecting image-model redraws back onto the model (step 14).
368
+
369
+ Two bugs worth remembering, because both produced plausible wrong pictures: glTF's axes turned into ours by swapping two of them is a mirror image, which silhouettes cannot detect; and a mesh whose faces point inward gets no texture at all, only fill.
370
+
371
+ ## What is next
372
+
373
+ - **More directions, and animation.** Step 13 gives sixteen directions. Thirty-two would spin smoothly, and the same trick on a walk cycle would give walks in the in-between directions, which the generator does not offer.
374
+ - **Fix the squat proportions.** Carve at a finer grid, or let the redraw see a true neighbour at full height (the guide sheet does this and kept proportions better on the bare character).
375
+ - **Held items.** Carve them separately, upright, and place them on the model the way the paperdoll layers place them on the sprite.
376
+ - **A score that sees cleanliness.** Colour error against one drawing cannot tell a clean redraw from a torn render.
377
+ - **Fewer, larger pieces in the unwrap.** The chest unwraps into a few large pieces, but the character comes out in hundreds of small ones, which is fine for a program and poor for a person or an image model to paint on. One piece per view, like a folded paper model, would make the texture a sprite sheet.
378
+ - **Carve at a finer grid** than one voxel per pixel, so thin objects survive.
379
+ - **Remove baked shading.** The sprites are drawn lit from one side, and that light is now painted on the model.
380
+ - **Use the rig.** The skeleton from step 6 has not been attached to a mesh.
191
381
  - Can the eight-view input of the hosted Hunyuan3D 3.1 use all eight sprites? (Unverified; see below.)
192
382
 
193
383
  ## What other people are doing
@@ -218,7 +408,7 @@ No report was found of any of these being tested on pixel art.
218
408
  - [Voxify3D](https://arxiv.org/abs/2512.07834). Turns a mesh into voxel art with a small palette.
219
409
  - [Blender to Pixels](https://astropulse.itch.io/blender-to-pixels). Renders a 3D scene as pixel art.
220
410
 
221
- **The Discord pipeline.** The thread that started this described: build the character from tubes or capsules, or generate a mesh with Hunyuan or Meshy; unwrap it "as a folded piece of paper"; retexture the unwrapped image with an image model; carve hair and clothes as separate pieces; remove baked shadows and highlights; render with a toon or pixel shader. None of it could be checked against a public source. Step 7 here tested the tubes part, and step 9 is the unwrap-and-retexture part.
411
+ **The Discord pipeline.** The thread that started this described: build the character from tubes or capsules, or generate a mesh with Hunyuan or Meshy; unwrap it "as a folded piece of paper"; retexture the unwrapped image with an image model; carve hair and clothes as separate pieces; remove baked shadows and highlights; render with a toon or pixel shader. None of it could be checked against a public source. Step 7 here tested the tubes part, steps 9 to 11 the unwrap and texture part, and step 13 the image model, on the rendered views and not on the unwrapped texture.
222
412
 
223
413
  No public tool was found that takes several directional pixel sprites and returns a mesh.
224
414
 
@@ -227,6 +417,8 @@ No public tool was found that takes several directional pixel sprites and return
227
417
  - Six upright objects at 10 generations each: 60 PixelLab generations.
228
418
  - Carving, tilt check, skeleton and rendering: nothing. They run locally in seconds.
229
419
  - Hunyuan3D: nothing but about two minutes of GPU time per mesh, after a 4.93 GB download.
420
+ - Staged texturing: nothing. About six seconds a mesh on a laptop.
421
+ - Image-model redraws in steps 13 and 14: 50.1 generations for six calls.
230
422
 
231
423
  ## Running the scripts
232
424
 
@@ -247,4 +439,14 @@ python3 research/scripts/tilt.py <folder> <name>
247
439
 
248
440
  # Four views to a mesh, through a ComfyUI server (address at the top of the script).
249
441
  python3 research/scripts/hunyuan3d.py <folder> <name> <out-folder>
442
+
443
+ # Fit, unwrap, texture and render a mesh from the sprites. Writes the texture, a textured .glb and a sheet.
444
+ python3 research/scripts/texture.py <folder> <name> <mesh.glb> <out-folder>
445
+
446
+ # The same stages on the carved shape: export the carve, then texture it. MODE=vote lets the views vote.
447
+ DUMP=1 node --experimental-strip-types research/scripts/carve.ts <folder> <name> <out-folder>
448
+ MODE=vote VOX=<out-folder>/<name>.vox CAMERA=<out-folder>/<name>.camera.json python3 research/scripts/texture.py <folder> <name> - <out-folder>
449
+
450
+ # Score the second row of a sheet against the first.
451
+ python3 research/scripts/score.py <sheet.png>
250
452
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixelkiln",
3
- "version": "0.105.0",
3
+ "version": "0.106.0",
4
4
  "description": "Manifest-driven pixel-art generation, review, recovery, and packaging with deterministic provenance.",
5
5
  "type": "module",
6
6
  "sideEffects": false,