pixelkiln 0.123.0 → 0.125.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.
@@ -0,0 +1,280 @@
1
+ # 3D characters from sprites
2
+
3
+ A rigged, animated 3D character built from sprites PixelKiln generates: a bare
4
+ body and each thing it wears as separate meshes on one skeleton, in one `.glb`
5
+ a game engine imports.
6
+
7
+ ![A stocky knight made from small sprites, a bare adult figure, and a tall armoured knight from the front and back](../website/public/models/art.png)
8
+
9
+ **This is an experiment, not a PixelKiln command.** The steps below are
10
+ scripts in [`research/scripts`](../research/README.md). They are rough, take
11
+ paths as arguments, and may change. PixelKiln itself is used for the first
12
+ step only: generating the sprites. The [3D characters page](https://pixelkiln.griffen.codes/3d)
13
+ has the finished models to turn and dress, and the
14
+ [research note](./RESEARCH_3D.md) records every experiment behind this guide,
15
+ in order, with what failed.
16
+
17
+ Everything here was measured in November 2026 on one PixelLab account and one
18
+ machine with a 12 GB RTX 3060.
19
+
20
+ ## What you get
21
+
22
+ - **One file.** A `.glb` with a body, its items, a skeleton and animations.
23
+ - **Parts, not a statue.** The body and each item are separate meshes skinned
24
+ to the same bones, so a game can dress the same body differently.
25
+ - **Skin that hides.** The body is split by what covers it. Each piece lists
26
+ the items that hide it in its node's `extras`, as `"hiddenBy": ["Cuirass"]`.
27
+ Hide a piece while any item in its list is worn, and nothing shows through.
28
+ - **A standard skeleton.** Twenty-one bones under the names Unity's and Godot's
29
+ humanoid profiles use. Godot 4.7's `SkeletonProfileHumanoid` finds every bone
30
+ it requires, by name.
31
+ - **Hands that close,** on the painted path. Where the mesh has a thumb apart
32
+ from the fingers, each hand gets a thumb, one chain for the four fingers
33
+ together, and a point that marks where a grip goes. A hand drawn as a
34
+ closed fist gets the grip point alone, which is enough to hold something.
35
+ - **Stock animations.** Motions from a humanoid library made for another
36
+ skeleton, carried over bone by bone.
37
+
38
+ ## Choose a path
39
+
40
+ The same pipeline runs from small sprites or from large ones. Neither is the
41
+ wrong one.
42
+
43
+ ![The same knight from 64 pixel sprites, above, and from 256 pixel sprites, below](../website/public/research/3d/two-paths.png)
44
+
45
+ | | Pixel path | Painted path |
46
+ |---|---|---|
47
+ | Sprites | 64 pixels: a body, and one layer per item | 256 pixels: a body, and the body wearing each item |
48
+ | Generations | About 53: 2 for the body, 10 a layer, under 1 for joints | About 110: 9 for the body, up to 25 a worn version, under 1 for joints |
49
+ | Before meshing | The sprites, enlarged smoothly | Each sprite redrawn at 1024 pixels by an image model on your own GPU |
50
+ | GPU time, body and four items | About 45 minutes | About two hours |
51
+ | Build | About four heads tall | About seven heads tall |
52
+ | Surface | The sprite's colours, soft up close; meant to be drawn small with a pixel filter | Plates, trim, faces and cloth painted in |
53
+ | The example file | 9,300 triangles, 1.0 MB | 18,000 triangles with a sword, 2.6 MB |
54
+
55
+ **Take the pixel path** when the game is pixel art, the camera is far, and
56
+ cost matters. Its limits are known:
57
+
58
+ - **It is stocky.** A face needs about a dozen pixels, which at 64 pixels is a
59
+ quarter of the figure's height, and the mesh keeps that build.
60
+ - **Thin items can come out ragged,** because a sleeve four pixels wide gives
61
+ the mesh model little to go on.
62
+ - **Detail stops at what 64 pixels hold.** A crest is a blob of gold.
63
+
64
+ **Take the painted path** when the model will be seen close or large. Its
65
+ limits:
66
+
67
+ - **The redrawn directions do not agree on every detail.** Each is redrawn
68
+ alone, and the paint blends them.
69
+ - **Colours can drift from the sprite's.** The redraw holds them; the paint
70
+ stage can still move them.
71
+ - **It costs twice as much** in generations and in time.
72
+
73
+ A model from either path can be drawn pixelated afterwards. The reverse is not
74
+ true: detail that was never painted cannot be added by a filter.
75
+
76
+ ## What you need
77
+
78
+ - **PixelKiln and a PixelLab account,** for the sprites.
79
+ - **A machine with an NVIDIA card of 12 GB or more running ComfyUI,** with
80
+ Hunyuan3D-2mv for meshes and Hunyuan3D's paint stage for textures. The
81
+ painted path also uses an SDXL checkpoint and a tile control model. The
82
+ research note's steps 8 and 17 say how they were installed.
83
+ - **Python with numpy, scipy, pillow, trimesh, xatlas and fast-simplification,**
84
+ and Node 22, on the machine that runs the scripts.
85
+
86
+ ## The steps
87
+
88
+ Each step reads files and writes files. Paths in angle brackets are yours.
89
+
90
+ ### 1. Draw the sprites
91
+
92
+ **Pixel path.** A bare body in eight directions with the arms out, then one
93
+ [`layer`](./PAPERDOLL.md) asset per item over those eight frames:
94
+
95
+ ```json
96
+ "body": {
97
+ "prompt": "blank paperdoll base body: bald adult human figure, slim and lean, no clothing, standing straight with both arms held straight out to the sides"
98
+ },
99
+ "body.plate": {
100
+ "prompt": "Dress every one in the same black steel plate cuirass with gold trim ...",
101
+ "layer": { "of": ["body"], "columns": 4 }
102
+ }
103
+ ```
104
+
105
+ **Painted path.** The same body prompt at 256 pixels, then one state per item
106
+ through PixelLab's character-state tool: "wearing a black steel plate cuirass
107
+ ...". A state redraws all eight directions of the same figure in the same
108
+ pose. There are no separate item layers on this path; where each item is comes
109
+ from comparing the worn figure with the bare one.
110
+
111
+ Arms out to the sides matters on both paths. With arms at the sides the mesh
112
+ model fuses them to the body.
113
+
114
+ ### 2. Redraw large (painted path only)
115
+
116
+ ```bash
117
+ python3 research/scripts/redraw.py <sprites> <name> <redraws> "<what the character is>"
118
+ ```
119
+
120
+ An image model redraws each sprite at 1024 pixels while a control model holds
121
+ the layout, and the sprite's colours are put back under the new detail.
122
+ `OUTLINE=own` keeps the outline the model drew, which is what gives a round
123
+ skull and tapered arms; the sprite's own outline is a staircase.
124
+
125
+ ### 3. Mesh
126
+
127
+ ```bash
128
+ python3 research/scripts/hunyuan3d.py <inputs> <name> <meshes>
129
+ ```
130
+
131
+ Once for the body and once for the body wearing each item. A thin item meshed
132
+ on its own collapses into slabs; meshed on the body, the body gives it shape.
133
+
134
+ ### 4. Fit, paint and bake
135
+
136
+ ```bash
137
+ TURNS=0 CAMERA=<body.camera.json> python3 research/scripts/texture.py <sprites> <name> <mesh.glb> <fitted>
138
+ TOP=45 SPREAD=22 VIEW=768 STAGE=paint python3 research/scripts/hunyuan3d_paint_turn.py <fitted.glb> <pictures> <name> <views>
139
+ python3 research/scripts/bake.py <fitted.glb> <views>/<name>.views.json <baked> <name> 2048
140
+ ```
141
+
142
+ The fit puts every mesh in the body's frame, so items land where they are
143
+ worn. The paint stage paints one direction at a time with that direction's
144
+ picture as its reference, and `TOP=45` adds views from above and below so arm
145
+ tops and shoulders are painted and not left to dark outlines.
146
+
147
+ ### 5. Cut the items out
148
+
149
+ ```bash
150
+ BODY=<body.baked.glb> python3 research/scripts/cut_item.py <worn.baked.glb> <mask.textured.glb> <item.glb>
151
+ ```
152
+
153
+ The mask says roughly where the item is; with `BODY` the paint decides the
154
+ edge, so a strip of hand does not come along and a sleeve does not stop short.
155
+
156
+ ### 6. Thin
157
+
158
+ ```bash
159
+ TEX=512 python3 research/scripts/thin.py <item.glb> <item-light.glb> 3000
160
+ ```
161
+
162
+ Reduces a part to the triangle count given, unwraps it again, and bakes its
163
+ colours and a normal map from the dense mesh. The painted example went from
164
+ 79,819 triangles to 16,496 with no visible loss.
165
+
166
+ ### 7. Rig
167
+
168
+ ```bash
169
+ ITEMS="Helm=<helm.glb>:Head;Cape=<cape.glb>:Hips,Spine,Chest:loose;Cuirass=<cuirass.glb>" JPEG=90 \
170
+ python3 research/scripts/rig.py <body-light.glb> <body.rig.json> - - <character.glb>
171
+ ```
172
+
173
+ Puts the skeleton in from joints found in the sprites (the same 18 joints the
174
+ [skeletons guide](./SKELETONS.md#rig-a-3d-model) covers, estimated in each
175
+ direction and combined into positions in space), moves each item to just
176
+ above the skin, gives it the bone weights of the body under it, and splits the
177
+ body by what covers it. A name after the colon limits an item to those bones;
178
+ `loose` marks one that hides no skin.
179
+
180
+ Hands are measured on the mesh here too. A hand with a thumb standing apart
181
+ gets seven more bones: `LeftThumbMetacarpal`, `LeftThumbProximal`,
182
+ `LeftThumbDistal`, `LeftMiddleProximal`, `LeftMiddleIntermediate`,
183
+ `LeftMiddleDistal` (the four fingers move as one, under the middle finger's
184
+ names) and `LeftGrip`, which carries no skin and marks where a grip goes. A
185
+ hand with no thumb to find, which is every 64 pixel hand and any hand drawn as
186
+ a fist, gets no finger bones. If it is a fist (a ball wider than the wrist
187
+ behind it), it gets its wrist moved to the narrowest place and `LeftGrip` or
188
+ `RightGrip` in the middle of the fist. The script says which it found for each
189
+ hand. `FINGERS=0` turns all of this off.
190
+
191
+ ### 8. Animate
192
+
193
+ ```bash
194
+ python3 research/scripts/retarget.py <character.glb> <library.glb> <animated.glb>
195
+ ```
196
+
197
+ Carries animations over from a humanoid library. The example uses
198
+ [Quaternius's Universal Animation Library](https://quaternius.com/packs/universalanimationlibrary.html),
199
+ which is CC0 and is not included in this repository.
200
+
201
+ ### 9. Swing what hangs
202
+
203
+ ```bash
204
+ python3 research/scripts/sway.py <animated.glb> <out.glb>
205
+ ```
206
+
207
+ With `CHAINS="Cape=3x4"` at the rig step, the cape hangs from three columns of
208
+ four bones. This simulates them through every animation and stores the swing
209
+ as keys, so the cape moves in any engine with no physics to set up.
210
+
211
+ ### 10. Dress another body
212
+
213
+ ```bash
214
+ ONLY=Head python3 research/scripts/refit.py <helm.glb> <first.skin.npz> <second.skin.npz> <helm-for-second.glb>
215
+ ```
216
+
217
+ An item made on one body can be worn by another. Make the second body's own
218
+ mesh and rig (steps 1 to 7, the body only), write each body's bones with
219
+ `SKIN=<file>` at the rig step, and reshape each item from the first to the
220
+ second. Then rig the second body with the reshaped items as usual.
221
+
222
+ ### 11. Put something in a hand
223
+
224
+ ```bash
225
+ ITEMS="Sword=<sword.glb>:RightHand:held;Cuirass=<cuirass.glb>" python3 research/scripts/rig.py <body-light.glb> <body.rig.json> - - <character.glb>
226
+ ```
227
+
228
+ A held thing is made on its own: eight directions of the object upright
229
+ (a PixelLab object, 25 generations at 128 pixels), meshed, coloured from the
230
+ sprites with `texture.py`, and thinned. `held` lays its longest line across
231
+ the palm of the hand named, puts its grip at that hand's grip point, and makes
232
+ it `HELD_LENGTH` of the body's height long (default 0.5). The file's own
233
+ frame does not matter. It needs a hand with a grip point: one with finger
234
+ bones, or a closed fist. In a fist the grip runs through the fist from front
235
+ to back, blade to the front, and the guard is kept clear of the fist's side.
236
+
237
+ Then animate as in step 8. `retarget.py` carries the library's thumb and
238
+ middle finger over, so the hand is a fist in a walk and closed round the grip
239
+ in a sword attack. A fist has no fingers to move and holds as drawn.
240
+
241
+ ## In a game engine
242
+
243
+ The example file was imported into Godot 4.7.2 with no errors: one skeleton of
244
+ 47 bones (21 for the body, 14 for the hands, 12 for the cape), ten skinned meshes, twelve animations, and each body piece's
245
+ `hiddenBy` list in its node metadata. Godot drops a trailing `_Loop` from
246
+ animation names, so the library's `Walk_Loop` arrives as `Walk`.
247
+
248
+ Not tried: Unity and Unreal, Godot's retargeting onto its own humanoid rest
249
+ pose, and how the model looks drawn in any engine but three.js.
250
+
251
+ ## Sprite cards: the other answer
252
+
253
+ A character can also be shown as its own sprites, cut into a piece per bone
254
+ and carried on the skeleton as flat cards that face the camera. The pixels on
255
+ screen are the drawn ones, so nothing is lost to painting. It needs no mesh
256
+ texture at all, only the mesh to say which pixel belongs to which bone.
257
+
258
+ ```bash
259
+ SKIN=<skin.npz> python3 research/scripts/rig.py <body.textured.glb> <body.rig.json> - - <skeleton.glb>
260
+ LAYERS="Body=<body>;Cape=<cape>:Spine:behind;Helm=<helm>:Head" python3 research/scripts/cards.py <skin.npz> <body.camera.json> <sprites> <out-prefix>
261
+ ```
262
+
263
+ It has eight directions and no lighting, and joints open a little as limbs
264
+ swing. See step 31 of the research note.
265
+
266
+ ## What is not done
267
+
268
+ - **A command.** None of this is `pixelkiln` yet.
269
+ - **Hand-made topology.** The thinned mesh has no edge loops at the joints and
270
+ its unwrap is dozens of pieces.
271
+ - **Materials.** Colour and a normal map only: no metal or roughness, and the
272
+ redraw's lighting is painted in.
273
+ - **Separate fingers, eyes and a jaw** in the skeleton. The four fingers
274
+ move as one, and only on the painted path.
275
+ - **Held items beyond one sword in the right hand.** The left hand, a shield,
276
+ and two hands on one grip are untried, and the grip is not sized to the
277
+ hand. A fist cannot open, so it cannot let go or change its hold.
278
+ - **Many bodies.** The items have been worn by two: the one they were cut on
279
+ and one much heavier man, after `refit.py` reshaped them for him. Other
280
+ heights and builds are untried.
package/docs/README.md CHANGED
@@ -27,6 +27,7 @@ provider you are using. These Markdown files also render at
27
27
  | [Paperdoll layers](./PAPERDOLL.md) | One bare character and any number of outfits, hats and held items as transparent layers that match every frame: how it works, a base built for it, masks, cleaning loops, measured cost, and limits. |
28
28
  | [Generators](./GENERATORS.md) | Choose between still, tile, character, hosted animation, and ComfyUI frame-set workflows. |
29
29
  | [Environment provider benchmark](./PROVIDER_BENCHMARK.md) | Compare PixelLab, Retro Diffusion, and ComfyUI on buildings, backgrounds, cleanup, and native-grid recovery. |
30
+ | [3D characters from sprites](./CHARACTERS_3D.md) | An experimental pipeline from directional sprites to a rigged, animated 3D character with separate items: a pixel path and a painted path, the steps, and what each costs. Scripts, not a command. |
30
31
  | [Research: 3D models from sprites](./RESEARCH_3D.md) | Every attempt to turn eight directional sprites into a 3D model, with pictures. Research, not a feature. |
31
32
  | [Controlled asset revisions](./REVISIONS.md) | Image-to-image and inpaint edits, PixelLab palette cleanup, animation, skeleton posing, and interpolation from a parent asset; masks, approval gates, side-by-side review, and ComfyUI bindings. |
32
33
  | [Derived artifacts](./ARTIFACTS.md) | Refine, pack, mount, and export; provenance, approval gates, ownership, and crash recovery. |