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