@babylonjs-toolkit/agent 1.2.0 → 1.2.2

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.
Files changed (44) hide show
  1. package/README.md +31 -21
  2. package/lib/claude-settings.js +146 -1
  3. package/lib/doctor.js +21 -4
  4. package/lib/install.js +67 -4
  5. package/package.json +1 -1
  6. package/scripts/hooks/block-sleep.js +138 -0
  7. package/skills/bt-atlas/SKILL.md +22 -5
  8. package/skills/bt-design/references/3d-hero-docs.md +10 -3
  9. package/skills/bt-design/references/3d-hero-scroll.md +30 -5
  10. package/skills/bt-execute/SKILL.md +89 -120
  11. package/skills/bt-execute/scripts/dashboard.mjs +279 -19
  12. package/skills/bt-execute/templates/dashboard/data-schema.md +36 -15
  13. package/skills/bt-gauntlet/SKILL.md +4 -4
  14. package/skills/bt-gauntlet/references/spec-composition.md +4 -2
  15. package/skills/bt-gauntlet/references/target-images.md +28 -4
  16. package/skills/bt-gauntlet/references/unity-pipeline.md +30 -8
  17. package/skills/bt-hero/SKILL.md +3 -3
  18. package/skills/bt-landing/SKILL.md +1 -1
  19. package/skills/bt-plan/SKILL.md +52 -62
  20. package/skills/bt-prototype/SKILL.md +3 -3
  21. package/skills/bt-unwrap/SKILL.md +396 -0
  22. package/skills/bt-unwrap/scripts/blender/__pycache__/bt_unwrap.cpython-313.pyc +0 -0
  23. package/skills/bt-unwrap/scripts/blender/__pycache__/image_utils.cpython-313.pyc +0 -0
  24. package/skills/bt-unwrap/scripts/blender/__pycache__/mesh_tools.cpython-313.pyc +0 -0
  25. package/skills/bt-unwrap/scripts/blender/__pycache__/model_io.cpython-313.pyc +0 -0
  26. package/skills/bt-unwrap/scripts/blender/__pycache__/previews.cpython-313.pyc +0 -0
  27. package/skills/bt-unwrap/scripts/blender/__pycache__/rasterizer.cpython-313.pyc +0 -0
  28. package/skills/bt-unwrap/scripts/blender/__pycache__/reference_views.cpython-313.pyc +0 -0
  29. package/skills/bt-unwrap/scripts/blender/__pycache__/reference_warp.cpython-313.pyc +0 -0
  30. package/skills/bt-unwrap/scripts/blender/__pycache__/texture_bake.cpython-313.pyc +0 -0
  31. package/skills/bt-unwrap/scripts/blender/__pycache__/texture_compose.cpython-313.pyc +0 -0
  32. package/skills/bt-unwrap/scripts/blender/__pycache__/uv_layout.cpython-313.pyc +0 -0
  33. package/skills/bt-unwrap/scripts/blender/bt_unwrap.py +678 -0
  34. package/skills/bt-unwrap/scripts/blender/image_utils.py +264 -0
  35. package/skills/bt-unwrap/scripts/blender/mesh_tools.py +508 -0
  36. package/skills/bt-unwrap/scripts/blender/model_io.py +135 -0
  37. package/skills/bt-unwrap/scripts/blender/previews.py +205 -0
  38. package/skills/bt-unwrap/scripts/blender/rasterizer.py +217 -0
  39. package/skills/bt-unwrap/scripts/blender/reference_views.py +945 -0
  40. package/skills/bt-unwrap/scripts/blender/reference_warp.py +571 -0
  41. package/skills/bt-unwrap/scripts/blender/texture_bake.py +390 -0
  42. package/skills/bt-unwrap/scripts/blender/texture_compose.py +596 -0
  43. package/skills/bt-unwrap/scripts/blender/uv_layout.py +605 -0
  44. package/skills/bt-unwrap/scripts/bt-unwrap.mjs +165 -0
@@ -0,0 +1,396 @@
1
+ ---
2
+ name: bt-unwrap
3
+ description: "The Babylon Toolkit Unwrap Skill turns a rough AI-generated (or any) 3D model into a clean, game-ready asset in one headless Blender run, and rebuilds its texture so it is crisp instead of smeared. It repairs the geometry (duplicate vertices, floating debris, holes, flipped normals, broken shading), decimates to a face budget while re-baking the lost detail into a normal map, turns the model to the glTF / BabylonJS forward direction (detected from reference silhouettes) at real-world scale with a sensible origin, and gives it a new UV layout of large, undistorted islands, with less texture spent on surfaces nobody can see. It bakes the source color, metallic-roughness and normal maps onto that layout with Cycles, then paints sharp reference images back on: straight views and three-quarter views alike, each with its camera solved from the silhouette (direction, perspective, scale, offset) and warped smoothly onto the mesh. Every face takes its color from the one view that sees it best — or keeps the model's own texture where the images disagree with the geometry, as they do on engines and cockpits — with seams steered away from logos and the lighting of every view evened out, so there are no ghosts, smears or collages. It ships web-ready output: one single-sided PBR material, 2048 WebP textures supersampled from 4096 (4096 on request), MikkTSpace tangents, optional Draco and LODs, plus before/after renders, coverage and clutter maps that show why each surface got its paint, the UV island map bt-atlas uses for new skins, and a JSON report an agent can check. Reads GLB, glTF, FBX, OBJ, USD/USDZ, PLY, STL, Alembic and .blend; writes GLB, glTF, FBX, OBJ, USD/USDZ and .blend. Use when a model from Tripo / Meshy / Hunyuan / Higgsfield image-to-3D (or a scan) has a melted or blurry texture, a fragmented UV atlas, too many faces, or the wrong orientation or scale (e.g. `/bt-unwrap models/kart.glb --refs kart_refs --faces 100000 --length 1.8`, `/bt-unwrap creature.fbx --unwrap smart --texture-size 4096`)."
4
+ allowed-tools: Read, Write, Edit, Glob, Grep, Bash
5
+ ---
6
+
7
+ You are an EXPERT Babylon Toolkit technical artist who owns the asset pipeline end to end. Always adhere to any rules or requirements set out in the project's agent instructions (AGENTS.md / CLAUDE.md / .github/copilot-instructions.md).
8
+
9
+ Use the user's message after the skill name as the `arguments`.
10
+
11
+ ---
12
+
13
+ # Invocation
14
+
15
+ ```
16
+ /bt-unwrap <model> [--refs <folder>] [--ref <view>=<image>]... [--output <file> | --format <fmt>] [--out-dir <dir>]
17
+ [--faces <n>] [--length <m> | --height <m> | --width <m>] [--origin bottom|center|keep]
18
+ [--forward auto|keep|+x|-x|+y|-y] [--rotate <x,y,z>]
19
+ [--unwrap views|smart|keep] [--projections 6|10|14] [--view-density <view=x,...>] [--hidden-density <x>]
20
+ [--texture-size <px>] [--maps auto|color,metallic_roughness,normal] [--roughness <v>] [--metallic <v>]
21
+ [--image-format webp|png|jpeg] [--draco] [--double-sided] [--lods <ratios>] [--analyze] [--no-preview]
22
+ ```
23
+
24
+ - **`<model>`**: the model to clean up: `.glb .gltf .fbx .obj .usd .usda .usdc .usdz .ply .stl .abc .blend`.
25
+ If it is missing, ask for it. Never guess a path.
26
+ - Plain words in the request map to flags. Translate them yourself: "100k faces" → `--faces 100000`,
27
+ "1.8 m long" → `--length 1.8`, "hero asset" / "close-ups" → `--texture-size 4096`, "make the side panels
28
+ sharper" → `--view-density left=1.5,right=1.5`, "as FBX" → `--format fbx`.
29
+
30
+ **Output**
31
+ - **`--output <file>`**: the output model; its extension picks the format (`.glb .gltf .fbx .obj .usd .usda .usdc .usdz .blend`).
32
+ Default `<out-dir>/<name>.glb`.
33
+ - **`--out-dir <dir>`**: where everything goes. Default `<input folder>/<name>_unwrap/`. The input model is never
34
+ modified, and an `--output` that would overwrite it is refused.
35
+ - **`--format <fmt>`**: `glb` (default), `gltf`, `fbx`, `obj`, `usd`, `usdz` or `blend`, used when `--output` is not given.
36
+ - **`--lods <ratios>`**: extra decimated copies that share the textures, e.g. `0.5,0.25` → `<name>_lod1.glb`, `<name>_lod2.glb`.
37
+ - **`--draco`**: Draco-compress the glTF / GLB geometry (several times smaller; BabylonJS needs its Draco decoder at
38
+ load time).
39
+ - **`--analyze`**: detect the orientation and solve the reference cameras only. Writes the overlays and the
40
+ report, no model. Seconds instead of minutes.
41
+ - **`--no-preview`** / **`--preview-size <px>`** (1024): skip, or size, the renders, check images and UV images.
42
+
43
+ **Geometry cleanup**
44
+ - **`--faces <n>`**: decimate to about n triangles (default: keep). A full-detail copy is kept for baking, so the detail
45
+ survives in the normal map.
46
+ - **`--merge-distance <m>`**: merge vertices closer than this. Default: 0.001% of the model diagonal, which rejoins the
47
+ vertices AI exporters split along UV seams.
48
+ - **`--debris-faces <n>`** (8): delete loose parts with fewer faces. `0` keeps everything.
49
+ - **`--fill-holes <n>`** (off): fill open holes bounded by up to n edges.
50
+ - **`--no-fix-normals`**: keep the original face winding (normally recalculated to point outward).
51
+ - **`--shading auto|smooth|flat|keep`** (auto) and **`--smooth-angle <deg>`** (30): `auto` = smooth with hard edges above
52
+ the angle. Every mode except `keep` clears broken custom normals first.
53
+ - **`--keep-objects`**: keep separate objects and pivots (wheels, doors) instead of joining into one mesh. They still
54
+ share one texture. Forced on for rigged models.
55
+
56
+ **Orientation and size.** The result always faces glTF +Z (Blender -Y), the glTF / BabylonJS forward direction.
57
+ - **`--forward auto|keep|+x|-x|+y|-y`** (auto): the Blender axis the model's front faces after import. `auto` detects
58
+ it from the straight reference views (a side view, plus a front or rear view, settle it). Without them, the
59
+ imported heading is kept.
60
+ - **`--rotate <x,y,z>`**: extra rotation in degrees applied first, for models imported lying down.
61
+ - **`--length <m>`**, **`--height <m>`**, **`--width <m>`**: scale to a real size; checked in that order, the first one given wins.
62
+ - **`--origin bottom|center|keep`** (bottom): `bottom` = centre of the footprint at floor level.
63
+
64
+ **UV layout**
65
+ - **`--unwrap views|smart|keep`** (views):
66
+ - `views` lays every face out from the front, rear, left, right, top or bottom it faces most, for hard-surface
67
+ models (vehicles, props, buildings, weapons);
68
+ - `smart` is Blender Smart UV Project, for organic models (characters, creatures, rocks);
69
+ - `keep` keeps the existing UVs.
70
+ - **`--projections 6|10|14`** (6): `views` directions: the box, plus horizontal diagonals (10), or plus corners (14).
71
+ More directions mean less stretch on rounded bodies, but more islands.
72
+ - **`--hidden-density <x>`** (0.4): texel density of surfaces that none of 26 directions around the model can see
73
+ (insides, undersides of covers), relative to visible surfaces. The space saved goes to what players see.
74
+ `1` = uniform density.
75
+ - **`--view-density <view=x,...>`**: give chosen views more texture space, e.g. `left=1.5,right=1.5` for livery side
76
+ panels, `bottom=0.5` for floors.
77
+ - **`--label-smoothing <n>`** (6), **`--min-island-faces <n>`** (24), **`--max-facing-angle <deg>`** (65): how noisy face
78
+ groups merge into clean islands. Islands under the minimum are absorbed by their largest neighbour.
79
+ - **`--smart-angle <deg>`** (66): angle limit for `smart`.
80
+ - **`--pack-rotate any|cardinal|none`** (any): island rotation while packing. Islands render correctly at any angle;
81
+ `any` packs tightest, `cardinal` turns in 90° steps, `none` keeps every island upright for painting by hand.
82
+ - **`--padding <px>`** (texture size / 512, at least 2): gap between islands, and edge padding, in output pixels.
83
+ - **`--no-fix-overlaps`**: don't repair folds. By default, where a surface doubles back inside its own island, the
84
+ faces that see the island's view only at a grazing angle move to their next-best view. The report's
85
+ `unwrap.fold_repair` says how many moved.
86
+
87
+ **Texture**
88
+ - **`--texture-size <px>`** (2048): output texture size. Textures are built at twice this (up to 4096, or
89
+ `--work-size <px>`) and filtered down, so edges and text are as crisp as the size allows. 2048 suits game
90
+ assets; use 4096 for hero assets seen in close-up.
91
+ - **`--image-format webp|png|jpeg`** (webp) and **`--image-quality <0..100>`** (90): how glTF / GLB stores its textures.
92
+ WebP (`EXT_texture_webp`, which BabylonJS reads) keeps a 100K-triangle model with its 2048 maps around 5–7 MB.
93
+ The files in `textures/` are always lossless PNG masters.
94
+ - **`--double-sided`**: render both sides of faces. Off by default, because a closed model never shows its back
95
+ faces and culling them halves the shading work. Use it only for open, single-sheet surfaces.
96
+ - **`--maps auto|<list>`** (auto): `auto` bakes:
97
+ - color, when the source has a color texture or vertex colors, or when references are given;
98
+ - metallic-roughness, when the source has it;
99
+ - a normal map, when the mesh was decimated: the shape detail the decimation removed, baked from the
100
+ full-detail surface (exported with MikkTSpace tangents).
101
+
102
+ A bare mesh (an STL, an untextured OBJ) with no references bakes nothing: it keeps its constant colour and gets
103
+ the clean layout plus its island map, ready for painting. Or list the maps from `color,metallic_roughness,normal`.
104
+ - **`--roughness <0..1>`** / **`--metallic <0..1>`**: constants instead of the baked maps (AI metal/rough maps are often noise).
105
+ - **`--no-normal-map`**: never produce a normal map.
106
+ - **`--keep-source-normal-map`**: carry the source's own normal map over too. Off by default: a generator's normal
107
+ map is mostly relief guessed from its own texture — logos embossed where it painted them, noise on smooth
108
+ panels — and under real lighting it draws ghost logos and crumpled panels next to the repainted texture. Turn
109
+ it on for a source whose normal map is genuine (a sculpt bake, a photogrammetry scan).
110
+ - **`--bake-distance <fraction>`** (0.004 of the diagonal), **`--bake-samples <n>`** (4), **`--device auto|cpu|gpu`** (auto):
111
+ Cycles bake controls.
112
+
113
+ **Reference images**
114
+ - **`--refs <folder>`**: the folder of reference images, matched by file name:
115
+ - straight views: `front`, `rear`/`back`, `left`, `right`, `top`/`plan`, `bottom`/`under`
116
+ (e.g. `01_front_ortho.png`, `car_left_side.jpg`); with two candidates for one view, names containing `ortho` win;
117
+ - angled views: names with `three_quarter`, `3-4`, `iso`, `angle`, `perspective`, or two neighbouring views
118
+ (`front_left`, `top_rear`). All of them are used. Their camera is solved from the silhouette, so the left/right
119
+ in a name does not need to be right (file names often give it from the viewer's side; the report says which
120
+ way it really was). A `front` or `rear` in the name narrows the search;
121
+ - detail, close-up, cutaway and turnaround-sheet images are skipped: they do not show the whole model.
122
+ - **`--ref <view>=<image>`**: name one image (repeatable; paths may contain `=` or `,`): a straight view, an angled
123
+ view such as `front_left` or `top_rear_right`, or `oblique` for an angle to be found anywhere around the model.
124
+ - **`--no-oblique`**: use straight views only.
125
+ - **`--ref-rotate <view>=<deg>`**: fix a straight reference's in-plane rotation. Top and bottom views are detected otherwise.
126
+ - **`--ref-bg-tolerance <0..1>`** (0.08): background separation. Transparent PNGs use their alpha instead.
127
+ - **`--ref-min-iou <0..1>`** (0.80): references whose fitted silhouette matches worse than this are skipped.
128
+ - **`--ref-align fit|refine`** (refine): `refine` also searches small scale and offset corrections. The camera
129
+ direction (a few degrees of tilt for straight views — AI "orthographic" images are often taken from slightly
130
+ above), perspective and rotation are always fitted.
131
+ - **`--no-ref-warp`** / **`--ref-warp-max <fraction>`** (0.04): local alignment. Each reference is matched patch by
132
+ patch against the source texture rendered from the same camera, and a smooth correction is fitted to the
133
+ matches (close to a uniform stretch, so straight edges stay straight). The max caps the shift at a fraction of
134
+ the subject size.
135
+ - **`--ref-consistency <0..1>`** (0.5): how closely, in cluttered parts of the model, a reference's features (part
136
+ edges, letters, stripes) must line up with the model's own texture before it may paint them. Engines, cockpits
137
+ and suspension are where a generated image and a generated mesh draw different parts; there the model keeps its
138
+ own coherent texture instead of a projected collage. Smooth panels take references as decals regardless.
139
+ Higher = stricter; `0` = trust references everywhere.
140
+ - **`--ref-source-score <0..1>`** (0.35): how good a view must be on a face (how head-on × how much of the face it
141
+ sees × its consistency) to replace the model's own texture there. Higher keeps more of the source.
142
+ - **`--ref-seam-smoothness <x>`** (0.12): how strongly neighbouring faces take the same view. Higher = larger
143
+ single-view patches and fewer seams; seams cost more where the two views look different, so they settle in plain
144
+ areas instead of cutting through logos.
145
+ - **`--ref-max-angle <deg>`** (70): surfaces turned further than this from a view get nothing from it.
146
+ - **`--ref-strength <0..1>`** (1.0): overall reference opacity.
147
+ - **`--ref-normal-smoothing <n>`** (8): views are weighed by normals smoothed over n edge rings, so a lumpy AI panel
148
+ is painted evenly from one view instead of in patches.
149
+ - **`--ref-edge-inset <px>`** (3), **`--depth-tolerance <fraction>`** (0.01): edge-fringe and visibility-test slack.
150
+ - **`--no-color-match`**: don't match the source texture's colours to the references.
151
+ - **`--no-exposure-match`**: don't even out the lighting baked into each reference. By default each view gets a
152
+ gain measured against the source texture where both agree (overall brightness kept, at most ×1.8), so a
153
+ backlit rear view does not paint the back of the model darker. The gains are in the report
154
+ (`textures.compose.exposure_gains`).
155
+
156
+ **Launcher only**
157
+ - **`--blender <path>`**: use this Blender (else `$BLENDER`, then PATH, then the usual install folders).
158
+ - **`--verbose`**: show Blender's full log, and the Python traceback behind a `FAILED` line.
159
+ - **`--which-blender`**: print the Blender it would use.
160
+
161
+ ## Examples
162
+
163
+ ```
164
+ /bt-unwrap models/kart.glb --refs f1_kart_refs --faces 100000 --length 1.8
165
+ /bt-unwrap models/kart.glb --refs f1_kart_refs --analyze
166
+ /bt-unwrap models/kart.glb --refs f1_kart_refs --texture-size 4096 --roughness 0.45 --metallic 0
167
+ /bt-unwrap models/kart.glb --ref front=shots/a.png --ref oblique=shots/hero_angle.png --ref left=shots/b.png
168
+ /bt-unwrap hero_highpoly.glb --faces 30000 --lods 0.5,0.25 --draco
169
+ /bt-unwrap creature.fbx --unwrap smart --format fbx
170
+ /bt-unwrap scan.obj --unwrap keep --faces 50000 --no-preview
171
+ ```
172
+
173
+ ---
174
+
175
+ # What it does
176
+
177
+ One command runs the whole clean-up in headless Blender:
178
+
179
+ 1. **Import** any supported format.
180
+ 2. **Orient and size.** Turn the model so its front faces glTF +Z. With straight references, the forward axis is
181
+ **detected** by fitting the model's silhouette into every view. Then scale it to real size and set the origin.
182
+ 3. **Repair geometry.** Merge duplicate vertices, dissolve zero-area faces, delete loose geometry and
183
+ floating debris, optionally fill holes, make normals point outward, and set clean shading.
184
+ 4. **Decimate** to the face budget. A full-detail copy is kept, and its detail is baked into the normal map.
185
+ 5. **New UV layout.** `views` lays every face out flat as seen from the view it faces most: large, undistorted,
186
+ never-mirrored islands, with seams where the facing direction changes. Noisy face groups are smoothed, small
187
+ islands are absorbed, folds are split off, density is evened out, surfaces nobody can see are given less
188
+ space, and everything is packed tightly with padding.
189
+ 6. **Bake** the source base color, metallic-roughness and normal maps onto the new layout with Cycles, at twice
190
+ the output size. The normal map is baked in the new tangent space, so it stays correct.
191
+ 7. **Solve each reference's camera.** Each image is cut out from its background (only background connected
192
+ to the image border counts, so white logos on a light backdrop are kept), then fitted to the mesh by its
193
+ silhouette: camera direction (a small tilt for straight views; a full search around the model for angled
194
+ views), perspective strength (AI "orthographic" images are really perspective renders), in-plane rotation,
195
+ scale and offset. A smooth local warp then lines the image up with the model's own texture.
196
+ 8. **Check consistency.** Each reference is compared with the model's own texture seen from the same camera.
197
+ Where the model's texture shows features, a trustworthy reference shows the same ones in the same places.
198
+ The model also knows where it is cluttered: where much of the surface around a face is hidden from the views
199
+ that face it (engines, cockpits, suspension).
200
+ 9. **Choose one source per face** — the view that sees the face most head-on and most completely, discounted in
201
+ cluttered parts by how far it disagrees with the model's own texture, or that texture itself. Neighbouring
202
+ faces then vote, so panels come from one view, and seams are steered to places where the two candidates look
203
+ alike instead of through logos. Colours blend only across the one ring of faces at a seam, so nothing is
204
+ averaged into a ghost. **Exposure is evened out** between views, the source texture's colours are matched to
205
+ the references, and island edges are padded.
206
+ 10. **Filter down and ship.** The maps are filtered to the output size, and the model gets one single-sided PBR
207
+ material, MikkTSpace tangents when it has a normal map, WebP textures, and optional Draco and LODs. The
208
+ bake reads an untouched copy of the imported model, so its shading is carried over as authored; a
209
+ generator's guessed normal map is left out (see `--keep-source-normal-map`).
210
+ 11. **Proof:** before/after renders from seven views, a comparison sheet, the coverage and clutter maps, one
211
+ alignment overlay, warp check and consistency check per reference, the UV images, and a JSON report.
212
+
213
+ **Why this fixes the "melted" look.** Image-to-3D generators project a few generated views onto the mesh.
214
+ Surfaces no view saw head-on (tops of wings, noses, seats) get stretched or invented pixels, and the texture is
215
+ scattered over thousands of tiny UV fragments. bt-unwrap replaces both: big clean islands, painted from the sharp
216
+ source images at the angle they were drawn from — including the top and three-quarter views generators cannot
217
+ take — and only where those images agree with the geometry.
218
+
219
+ ## Requirements
220
+
221
+ - **Blender 4.2+** (5.x recommended). The launcher finds it on macOS, Windows and Linux.
222
+ - **Node 18+** for the launcher. Nothing to install: the pipeline uses the numpy bundled with Blender.
223
+ - Scripts live in `<skilldir>/scripts/`: the launcher `bt-unwrap.mjs` and the pipeline `blender/*.py`.
224
+ Resolve `<skilldir>` as the folder that holds this SKILL.md. Always copy the whole `scripts/` folder with it.
225
+
226
+ ---
227
+
228
+ # Procedure
229
+
230
+ ### 0. Validate the input
231
+ Confirm the model file exists and has a supported extension. If references were given (a folder, or
232
+ images per view), confirm they exist. Never downscale reference images: full resolution is detail.
233
+
234
+ ### 1. Check the references first (when there are any)
235
+ ```
236
+ node <skilldir>/scripts/bt-unwrap.mjs <model> --refs <folder> --analyze
237
+ ```
238
+ Read the summary lines and open `preview/align_<view>.png`. The red-tinted area is the mesh silhouette as the
239
+ solved camera sees it, and it should cover the subject.
240
+
241
+ - `iou` of **0.90+** is a good fit; **0.80–0.90** is usable, because AI meshes are blobbier than their images.
242
+ - Below `--ref-min-iou`, the image is skipped with a warning.
243
+ - Wrong heading (the outline shows the model's back on the front image): set `--forward`.
244
+ - An oddly rotated top view: `--ref-rotate top=90`.
245
+ - A shadow or floor counted as subject: raise `--ref-bg-tolerance`.
246
+ - The report's `references.notes` lists every skipped file, and every angled view whose name disagreed with
247
+ where its camera really is.
248
+
249
+ ### 2. Run
250
+ ```
251
+ node <skilldir>/scripts/bt-unwrap.mjs <model> [options]
252
+ ```
253
+ Measured on an Apple-silicon laptop with the Metal GPU, with eight references (five straight, three angled):
254
+ - a 100K-triangle model takes about 2 to 2.5 minutes at the default 2048 output (built at 4096);
255
+ - a 1.9M-triangle model decimated to 100K adds about 40 seconds and peaks around 12 GB of memory (Cycles holds
256
+ the full-detail source for the bake). On a 16 GB machine, add `--work-size 2048` for very heavy inputs.
257
+
258
+ The CPU is slower. Run it in the background and wait for it to finish. Exit codes:
259
+ - `0`: done.
260
+ - `1`: failed (the reason follows `FAILED`).
261
+ - `2`: bad options.
262
+
263
+ ### 3. Verify by looking
264
+ 1. `preview/comparison.png`: before (left) and after (right), one row per view (front, left, rear, right,
265
+ top, two three-quarters).
266
+ 2. `preview/coverage_three_quarter_front.png` and `_rear.png`: which view painted what (legend below).
267
+ 3. `textures/<name>_uv_layout.png`: islands packed tightly, none overlapping.
268
+ 4. The summary lines and `<name>_report.json` (thresholds under **Running from a spec or plan**).
269
+
270
+ Judge the after renders honestly. Logos and numbers should be sharp and whole where a reference sees them, top
271
+ surfaces should no longer be smeared, and complex parts should look coherent, not like a collage. Tune (below)
272
+ and run again. Each run takes minutes, so change related options together.
273
+
274
+ ### 4. Deliver
275
+ Report the output paths, the before/after numbers, the file size, and show the comparison image.
276
+
277
+ - For a Babylon Toolkit project, import the GLB into the Unity asset project, or load it straight into BabylonJS
278
+ (it needs no extra loader beyond glTF; `EXT_texture_webp` is built in, and `--draco` models need the Draco
279
+ decoder BabylonJS loads by default).
280
+ - For new skins of the same model, hand `textures/<name>_basecolor.png` and `textures/<name>_uv_islands.png`
281
+ to **bt-atlas**.
282
+
283
+ ---
284
+
285
+ # Running from a spec or plan
286
+
287
+ When a bt-execute task (or any plan) calls for bt-unwrap, run it unattended and prove the result.
288
+
289
+ **What the task should state** (and what to assume when it does not): the input model, the reference folder,
290
+ the face budget (default: keep), the real-world size (`--length` / `--height` / `--width`; default: keep), the
291
+ texture size (default 2048; 4096 for hero assets seen in close-up), the output format (default GLB) and where
292
+ the output goes (default `<input folder>/<name>_unwrap/`, never over the input).
293
+
294
+ **Acceptance checks, all from `<name>_report.json`:**
295
+
296
+ | Check | Pass | If it fails |
297
+ |---|---|---|
298
+ | Exit code | `0` and a `DONE` line | Read the `FAILED` reason; rerun with `--verbose` for the traceback |
299
+ | `steps.references.alignment[].silhouette_iou` | ≥ 0.85 for straight views, ≥ 0.80 for angled ones | Check `align_<view>.png`; fix heading, rotation or background tolerance |
300
+ | `steps.references.alignment[].used` | every image the task relies on | See the warning; a skipped image paints nothing |
301
+ | `steps.unwrap.overlap_percent` | ≤ 0.5 | `--projections 10`, or `--unwrap smart` for organic models |
302
+ | `steps.unwrap.uv_coverage_percent` | ≥ 30 (hard-surface) | `--label-smoothing 10 --min-island-faces 64` |
303
+ | `steps.textures.compose.reference_painted_percent` | the share the references can reach: typically 30–50 % for a vehicle with five to eight views | Open the coverage map: red = hidden (add a view), black = inconsistent (see Tuning) |
304
+ | `steps.export.file_megabytes` | within the task's budget (about 5–7 MB for 100K triangles at 2048 WebP) | `--draco`, `--texture-size 1024`, or `--faces` |
305
+ | `warnings` | empty, or each one understood and reported | — |
306
+
307
+ Then look at `preview/comparison.png` and the two three-quarter coverage renders before calling the task done —
308
+ numbers alone do not prove a texture looks right. Report the final paths, the checks above with their values,
309
+ and the comparison image. Never ask the user to pick options: choose them from the task and this document, state
310
+ the assumption, and iterate (each run takes minutes; change related options together, at most three runs).
311
+
312
+ ---
313
+
314
+ # Outputs
315
+
316
+ ```
317
+ <out-dir>/
318
+ <name>.glb the model (or .gltf/.fbx/.obj/.usd*/.blend)
319
+ <name>_lod1.glb … with --lods
320
+ <name>_report.json every step's numbers, the options used, warnings, timings
321
+ textures/
322
+ <name>_basecolor.png sRGB base color (lossless master; the model stores --image-format)
323
+ <name>_metallic_roughness.png glTF packing: G = roughness, B = metallic (when baked)
324
+ <name>_normal.png tangent-space normal map (when the mesh was decimated, or with --keep-source-normal-map)
325
+ <name>_uv_islands.png white islands on black: bt-atlas's <uv-layout> input
326
+ <name>_uv_layout.png island outlines over the base color
327
+ preview/
328
+ comparison.png before (left) | after (right), one row per view
329
+ before_<view>.png, after_<view>.png
330
+ align_<view>.png the solved camera's view of the mesh over each reference
331
+ warp_<view>.png source render | reference as fitted | reference after the smooth warp
332
+ consistency_<view>.png source render | warped reference | reference with disagreeing features in red
333
+ coverage_<view>.png the coverage map on the model (legend below), and coverage_texture.png
334
+ clutter_<view>.png the clutter map on the model, and clutter_texture.png
335
+ ```
336
+
337
+ **Coverage map legend.** Each colour names the view that painted the texel; brighter means fuller coverage:
338
+ front blue, rear yellow, left green, right cyan, top magenta, bottom orange; angled views front_left white,
339
+ front_right lime, rear_left brown, rear_right navy (other angles get olive, teal, lavender or salmon — the report's
340
+ `textures.compose.coverage.legend` lists every colour). Texels that kept the model's own texture show why:
341
+ - **red**: the view facing it could not see it (hidden behind other geometry);
342
+ - **pink**: it projected outside the reference's subject;
343
+ - **black**: the part is cluttered and the view's features disagree with the model's own texture there;
344
+ - **dark grey**: no view faces it closely enough, or the model's own texture scored higher.
345
+
346
+ **Clutter map legend.** Blue = open surface (references paint it as a decal), orange = cluttered (a reference
347
+ must agree with the model's own texture to paint it). The report's `textures.compose.cluttered_face_percent`
348
+ gives the share of faces.
349
+
350
+ # Reference images that work
351
+
352
+ - **The same design as the model.** The images the model was generated from are ideal.
353
+ - **The whole subject in frame**, on a plain or transparent background.
354
+ - **Straight views and three-quarter views.** Straight views (front, rear, sides, top) paint most of the surface;
355
+ three-quarter views fill what they cannot see head-on (seat fronts, 45° panels, inner sides). Name angled
356
+ images with `three_quarter` or a view pair; the camera is solved, so the exact angle does not matter.
357
+ - **Flat, even lighting** gives the cleanest albedo. Reflections in a reference are painted in as colour.
358
+ Ask the image generator for "flat even studio lighting, no reflections, no shadows".
359
+ - **A top view matters most for vehicles.** Generators can't take one, and it fixes wings, noses, seats and roofs.
360
+ - **Full resolution.** Never downscale references.
361
+
362
+ # Tuning
363
+
364
+ | Symptom | Fix |
365
+ |---|---|
366
+ | Where did the references paint, and why not elsewhere? | Open `preview/coverage_<view>.png` (legend under Outputs) |
367
+ | Complex parts (engine, cockpit) still look like a collage | Stricter consistency: `--ref-consistency 0.7`; check `clutter_<view>.png` marks them orange |
368
+ | A logo on a panel is missing or cut | `consistency_<view>.png` shows it red: lower `--ref-consistency` (0.3); or larger patches: `--ref-seam-smoothness 0.2` |
369
+ | Too much of the model keeps its blurry own texture | Lower `--ref-source-score` (0.25) |
370
+ | Lots of pink on the coverage map | The subject cut-out is wrong: raise or lower `--ref-bg-tolerance`; check `align_<view>.png` |
371
+ | Logos land slightly off | Open `warp_<view>.png`: the third panel should line up with the first. If a whole region is off, raise `--ref-warp-max` (0.06) |
372
+ | A reference is SKIPPED (low iou) | Check `align_<view>.png`. Wrong heading: `--forward`. Rotated image: `--ref-rotate`. Background leaking into the subject: `--ref-bg-tolerance`. A genuinely different design: accept the skip, or lower `--ref-min-iou` slightly |
373
+ | An angled view solved to the wrong side | Name it with its true side (`--ref rear_left=…`); a `front` / `rear` in the name narrows the search |
374
+ | Visible seam where reference paint hands over to the source | Raise `--ref-max-angle` (80), or lower `--ref-source-score` |
375
+ | Texture soft in close-ups | `--texture-size 4096`; or `--view-density left=1.5,right=1.5,top=1.3` for key panels |
376
+ | GLB too big for the web | `--draco`; `--texture-size 1024`; `--faces` |
377
+ | Too many small islands | `--label-smoothing 10 --min-island-faces 64` |
378
+ | Stretching on rounded bodies | `--projections 10` or `14` |
379
+ | Organic model, messy layout | `--unwrap smart` |
380
+ | Black specks in the bake after heavy decimation | `--bake-distance 0.01` (up to 0.02) |
381
+ | Reflections painted into the colour | Flat-lit references, or a lower `--ref-strength` |
382
+ | Holes when seen from behind (open sheets: leaves, cards) | `--double-sided` |
383
+ | Lit in an engine, panels look crumpled or logos have embossed ghosts | Leave `--keep-source-normal-map` off (the default) |
384
+ | Lit in an engine, fine sculpted detail went missing | `--keep-source-normal-map` when the source's normal map is genuine; `--faces` decimation bakes lost shape automatically |
385
+ | Wrong heading, no references | `--forward +x` / `-x` / `+y` / `-y` |
386
+
387
+ # Limits
388
+
389
+ - It re-lays and re-paints. It does not retopologise to quads, or split a fused mesh into parts (wheels that
390
+ spin, doors that open). Separate those in Blender, keeping the shared texture.
391
+ - References paint colour only. Metallic and roughness come from the source model, and normal detail from its
392
+ geometry (and its own normal map, with `--keep-source-normal-map`).
393
+ - A reference can only paint what it shows. Surfaces no view sees keep the colour-matched source texture.
394
+ - Where the generated images and the generated mesh disagree, the model's own (softer) texture is kept on
395
+ purpose: a sharp projection of the wrong part looks worse than a soft right one.
396
+ - Interactive Babylon Toolkit components still come from Unity: import the GLB into the Unity asset project.