@babylonjs-toolkit/agent 1.2.16 → 1.2.18

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 (56) hide show
  1. package/README.md +3 -2
  2. package/package.json +1 -1
  3. package/skills/bt-blender/SKILL.md +386 -0
  4. package/skills/bt-blender/THIRD_PARTY_NOTICES.md +141 -0
  5. package/skills/bt-blender/references/art-style-and-genre.md +173 -0
  6. package/skills/bt-blender/references/characters-and-creatures.md +644 -0
  7. package/skills/bt-blender/references/environments.md +478 -0
  8. package/skills/bt-blender/references/game-engine-export.md +284 -0
  9. package/skills/bt-blender/references/geometry-nodes.md +447 -0
  10. package/skills/bt-blender/references/hard-surface.md +720 -0
  11. package/skills/bt-blender/references/procedural-generation.md +358 -0
  12. package/skills/bt-blender/references/rigging-and-animation.md +1080 -0
  13. package/skills/bt-blender/references/sculpting-and-retopology.md +544 -0
  14. package/skills/bt-blender/references/uv-and-pbr-materials.md +381 -0
  15. package/skills/bt-blender/references/vehicles.md +632 -0
  16. package/skills/bt-blender/scripts/blender/assembly_check.py +420 -0
  17. package/skills/bt-blender/scripts/blender/character_blockout.py +462 -0
  18. package/skills/bt-blender/scripts/blender/construction_kit.py +1710 -0
  19. package/skills/bt-blender/scripts/blender/environment_kit.py +525 -0
  20. package/skills/bt-blender/scripts/blender/export_asset.py +623 -0
  21. package/skills/bt-blender/scripts/blender/geometry_nodes_builders.py +575 -0
  22. package/skills/bt-blender/scripts/blender/hard_surface_panels.py +374 -0
  23. package/skills/bt-blender/scripts/blender/hard_surface_trims.py +200 -0
  24. package/skills/bt-blender/scripts/blender/image_measure.py +568 -0
  25. package/skills/bt-blender/scripts/blender/materials_pbr.py +439 -0
  26. package/skills/bt-blender/scripts/blender/measure_stations.py +486 -0
  27. package/skills/bt-blender/scripts/blender/ortho_views.py +309 -0
  28. package/skills/bt-blender/scripts/blender/procedural_game_ready.py +258 -0
  29. package/skills/bt-blender/scripts/blender/procedural_generators.py +842 -0
  30. package/skills/bt-blender/scripts/blender/qa_check.py +729 -0
  31. package/skills/bt-blender/scripts/blender/retopology_tools.py +781 -0
  32. package/skills/bt-blender/scripts/blender/review_render.py +358 -0
  33. package/skills/bt-blender/scripts/blender/rigging_tools.py +1170 -0
  34. package/skills/bt-blender/scripts/blender/style_palette.py +190 -0
  35. package/skills/bt-blender/scripts/blender/tool_common.py +289 -0
  36. package/skills/bt-blender/scripts/blender/uv_layout.py +555 -0
  37. package/skills/bt-blender/scripts/blender/vehicle_parts.py +370 -0
  38. package/skills/bt-blender/scripts/blender/view_consistency.py +133 -0
  39. package/skills/bt-blender/scripts/blender/world_gate.py +219 -0
  40. package/skills/bt-blender/scripts/bt-blender.mjs +329 -0
  41. package/skills/bt-blender/scripts/validate_gltf.mjs +204 -0
  42. package/skills/bt-gauntlet/SKILL.md +6 -6
  43. package/skills/bt-gauntlet/references/critic-rubrics.md +71 -4
  44. package/skills/bt-gauntlet/references/spec-composition.md +13 -0
  45. package/skills/bt-gauntlet/references/unity-pipeline.md +18 -2
  46. package/skills/bt-unwrap/scripts/blender/__pycache__/bt_unwrap.cpython-313.pyc +0 -0
  47. package/skills/bt-unwrap/scripts/blender/__pycache__/image_utils.cpython-313.pyc +0 -0
  48. package/skills/bt-unwrap/scripts/blender/__pycache__/mesh_tools.cpython-313.pyc +0 -0
  49. package/skills/bt-unwrap/scripts/blender/__pycache__/model_io.cpython-313.pyc +0 -0
  50. package/skills/bt-unwrap/scripts/blender/__pycache__/previews.cpython-313.pyc +0 -0
  51. package/skills/bt-unwrap/scripts/blender/__pycache__/rasterizer.cpython-313.pyc +0 -0
  52. package/skills/bt-unwrap/scripts/blender/__pycache__/reference_views.cpython-313.pyc +0 -0
  53. package/skills/bt-unwrap/scripts/blender/__pycache__/reference_warp.cpython-313.pyc +0 -0
  54. package/skills/bt-unwrap/scripts/blender/__pycache__/texture_bake.cpython-313.pyc +0 -0
  55. package/skills/bt-unwrap/scripts/blender/__pycache__/texture_compose.cpython-313.pyc +0 -0
  56. package/skills/bt-unwrap/scripts/blender/__pycache__/uv_layout.cpython-313.pyc +0 -0
@@ -0,0 +1,478 @@
1
+ # Environment modelling: modular kits, trims and tiling, terrain, scatter, collision and lightmaps
2
+
3
+ **Load this when** the asset is part of a place rather than a thing: wall, floor and corner kits, buildings
4
+ built from pieces, track or road pieces, cliffs and terrain tiles, rocks and scatter props, and the collision
5
+ and lightmap UVs those pieces need. Load it before the first piece of a new kit: the footprint, the grid and
6
+ the pivot convention are the decisions that are costly to change later.
7
+
8
+ **What it assumes.** The Agent Reference's Blender guide (`references/unity-blender-cli.md`) covers the basics:
9
+ §8.4b for measuring against references, and §8.4d for the construction kit. `hard-surface.md` covers bevels,
10
+ trims and decals on a single piece. `references/geometry-nodes.md` covers scatter and sweeps along curves. The
11
+ Agent Reference's `unity-authoring-recipes.md` covers what reaches BabylonJS: lightmaps (§4), terrain (§10),
12
+ physics (§11), static flags (§19) and web budgets (§20).
13
+
14
+ **Helpers.** `scripts/blender/environment_kit.py` provides:
15
+ - `prism_piece` and `drop_hidden_faces` for pieces;
16
+ - `box_uv`, `lightmap_resolution`, `lightmap_uv`, `lightmap_report` and `texel_density` for UVs
17
+ (`lightmap_uv` is `uv_layout.add_lightmap_uv` with Smart UV Project, plus the report);
18
+ - `convex_proxy` for collision (one `procedural_game_ready.convex_hull_collider` hull, named `UCX_<piece>_00`);
19
+ - `rolling_hills`, `terrain_tile` and `seam_report` for terrain;
20
+ - `kit_report`, the kit gate.
21
+
22
+ Every recipe below is a complete script. Run it with
23
+ `node <skill>/scripts/bt-blender.mjs run recipe.py <out folder>`.
24
+
25
+ ---
26
+
27
+ ## 1. Who does what: Unity directs the level, Blender makes the pieces
28
+
29
+ In this pipeline the level is composed in Unity and exported to BabylonJS by the Toolkit. Blender's job is the
30
+ pieces, each one correct on its own: on the grid, with its pivot where the kit says, with tiling UVs and a
31
+ lightmap UV set, light on triangles and hidden faces.
32
+
33
+ | Step | Where | What |
34
+ |---|---|---|
35
+ | Footprint, grid, pivot convention, piece list | Brief (written down) | Section 2. Decide before modelling, because late changes "can break hundreds or thousands of layouts" (Burgess). |
36
+ | Pieces, UV0 tiling or trim, UV1 lightmap, LODs | Blender (this file) | One object per piece, named `Kit_Type_Size` (`Wall_2m`, `Floor_2x2`, `Corner_Out`). Each piece passes `kit_report`, `lightmap_report` and qa-check. |
37
+ | Import, prefabs, colliders | Unity | One prefab per piece. Primitive colliders on the prefab (section 7). Lightmap UVs authored, or `generateSecondaryUV` on the importer (section 8). |
38
+ | Layout | Unity | Increment snap = the kit grid. Nested prefabs keep their links, so a re-exported piece updates every placement. |
39
+ | Static flags, bake | Unity | Contribute GI and Batching Static on non-moving pieces. Bake, then wait for `completed` (Agent Reference §4). |
40
+ | Export, draw-call proof | Toolkit, browser | Section 9. Count draws per pass with bt-optimize before tuning anything. |
41
+
42
+ Re-export from Blender with the **same object names and pivots**, and edit models in place (the Agent
43
+ Reference's Blender guide keeps GUIDs and importer settings). Unity then keeps every placement. A changed pivot
44
+ moves every placed copy of the piece.
45
+
46
+ ---
47
+
48
+ ## 2. The grid, the footprint and the pivot
49
+
50
+ **The footprint is the foundation of a kit** (Burgess). Every piece exists inside it, and footprints of
51
+ sub-kits are multiples of each other. A 512-unit room tiles with a 256-unit hallway, while a 384-unit room
52
+ eventually leaves gaps or overlaps.
53
+
54
+ | Decision | Practice |
55
+ |---|---|
56
+ | Scale anchor | The character. Doorways, step height (about 0.2 m) and the narrowest path (two character widths at least) come from it. Fix one door or portal size across all kits. |
57
+ | Footprint | Metres that divide the texture cleanly. At 512 px/m, 4 m = 2048 px, 2 m = 1024 px, 1 m = 512 px and 0.5 m = 256 px (Nazirov). A 3 m module on 2048 px gives fractional splits (37.5 cm = 256 px). Use 3 m only if the kit's textures are planned for it (Ian London: 3 m footprint at about 683 px/m). |
58
+ | Grid snap | As large as possible, usually **half the footprint** (Burgess; Ian London snaps a 3 m kit at 1.5 m). A sub-grid of 0.25 m for props. Avoid 0.125 m or 0.0625 m pieces: they are hard to snap (Nazirov). |
59
+ | Tiling axes | Chosen per sub-kit. Hallways tile on one axis, rooms on two. Vertical tiling is its own fixed-plane sub-kit. Avoid kits that tile on every axis. |
60
+ | Wall and floor thickness | Decided up front, under one grid cell (Ian London: 0.125 m, set in 0.125 m from the footprint edge so perpendicular pieces do not clip). Never stack coplanar pieces: they z-fight. |
61
+ | Pivot height | On the walking surface: Z = 0 where the character stands. Walls stand on it, floor slabs hang below it. |
62
+ | Pivot in plan | One convention for the whole kit (below). |
63
+
64
+ **Corner or centre pivot.** The professional convention is a floor-level pivot centred on the footprint
65
+ (Burgess: "usually at the ground plane and centred"; Ian London: the centre of the footprint box). A centred
66
+ piece turns in place, and the snap step is half the footprint. A corner pivot (the footprint's minimum X and
67
+ Y) puts every placement on a plain grid multiple, which suits tile maps and track pieces laid by code. But a
68
+ corner piece turned 90 degrees must move by its own width to stay in its cell. `kit_report(..., pivot=)` checks
69
+ either convention. The recipe below uses corners, as a tile-placed kit would.
70
+
71
+ **Greebles** (props that attach to a surface) take their pivot on the surface they attach to: a table's
72
+ bottom centre, a switch's back plane, a lamp's top (Ian London).
73
+
74
+ ### The modular checklist
75
+
76
+ - [ ] Footprint, grid, tiling axes, wall and floor thickness, and pivot convention are written in the brief.
77
+ - [ ] Every tiling length is a whole multiple of the grid. Thin sides are under one cell and flush with a cell
78
+ edge (corner kits) or inside the centred footprint (centre kits).
79
+ - [ ] Rotation and scale are applied. No negative scale anywhere: build `_L` and `_R` pieces instead.
80
+ - [ ] Hidden faces are deleted: a wall's underside on the floor, a slab's underside, faces buried in a
81
+ neighbour.
82
+ - [ ] UV0 has the kit's texel density, within 25 % of the kit median. UV1 is a non-overlapping lightmap set
83
+ with a margin of at least 2 texels (4 to survive block compression) at the piece's lightmap size.
84
+ - [ ] Names follow `Kit_Type_Size_Variant`, with `_L` and `_R` for mirrored pieces. Avoid cryptic names
85
+ (Burgess's cautionary example is `UtlBayCorInMidPRTT01L01`).
86
+ - [ ] One visually complete piece is finished before its variants. No hero pieces during the proof stage.
87
+ - [ ] Variation goes into clutter first: players notice repeated detail before repeated architecture.
88
+
89
+ ### Recipe: a three-piece kit on a 1 m grid (the environment test asset)
90
+
91
+ ```python
92
+ """Environment test asset: a floor slab, a wall and an outside corner on a 1 m grid, pivots at the footprint
93
+ corners on the walking surface, world-scaled tiling UV0, a lightmap UV1 packed for each piece's lightmap size,
94
+ and the kit gate. Saves modular_kit.blend and prints the kit and lightmap reports."""
95
+ import json
96
+ import os
97
+ import sys
98
+
99
+ import bpy
100
+
101
+ import construction_kit as kit
102
+ import environment_kit as env
103
+
104
+ out_folder = sys.argv[sys.argv.index("--") + 1]
105
+ GRID = 1.0 # metres: the snap step and the length unit of every piece
106
+ WALL_HEIGHT = 3.0
107
+ WALL_THICKNESS = 0.2 # under one cell, flush with the cell edge at y = 0
108
+ FLOOR_THICKNESS = 0.1 # the slab hangs below the walking surface
109
+ METRES_PER_TILE = 2.0 # a 1024 px tiling texture at 512 px/m
110
+ TEXTURE_PIXELS = 1024
111
+ LIGHTMAP_TEXELS_PER_METRE = 40 # the scene's Lightmap Resolution
112
+ LIGHTMAP_MARGIN_TEXELS = 4 # survives 4 x 4 block compression
113
+ SHEET_SPACING = 3.0 # pieces laid out apart on the grid, as a kit sheet
114
+
115
+ kit.clear_default_scene()
116
+ floor = env.prism_piece("Floor_2x2", [((0, 0), (2, 0), (2, 2), (0, 2))], height=-FLOOR_THICKNESS)
117
+ wall = env.prism_piece("Wall_2m", [((0, 0), (2, 0), (2, WALL_THICKNESS), (0, WALL_THICKNESS))], height=WALL_HEIGHT)
118
+ # The L of an outside corner as three quads: the corner block and one arm along each axis (no n-gon caps).
119
+ corner = env.prism_piece("Corner_Out", [
120
+ ((0, 0), (WALL_THICKNESS, 0), (WALL_THICKNESS, WALL_THICKNESS), (0, WALL_THICKNESS)),
121
+ ((WALL_THICKNESS, 0), (1, 0), (1, WALL_THICKNESS), (WALL_THICKNESS, WALL_THICKNESS)),
122
+ ((0, WALL_THICKNESS), (WALL_THICKNESS, WALL_THICKNESS), (WALL_THICKNESS, 1), (0, 1))], height=WALL_HEIGHT)
123
+
124
+ pieces = [floor, wall, corner]
125
+ removed = {piece.name: env.drop_hidden_faces(piece, below=0.0) for piece in pieces} # undersides nobody sees
126
+ lightmaps = {}
127
+ for index, piece in enumerate(pieces):
128
+ piece.location = (index * SHEET_SPACING, 0.0, 0.0)
129
+ env.box_uv(piece, metres_per_tile=METRES_PER_TILE)
130
+ resolution = env.lightmap_resolution(piece, LIGHTMAP_TEXELS_PER_METRE)
131
+ lightmaps[piece.name] = {"resolution": resolution,
132
+ **env.lightmap_uv(piece, resolution, margin_pixels=LIGHTMAP_MARGIN_TEXELS)}
133
+ piece.data.materials.append(bpy.data.materials.get("Kit_Concrete") or bpy.data.materials.new("Kit_Concrete"))
134
+
135
+ bpy.context.view_layer.update()
136
+ bpy.ops.wm.save_as_mainfile(filepath=os.path.join(out_folder, "modular_kit.blend"))
137
+ print(json.dumps({"hidden_faces_removed": removed, "lightmaps": lightmaps,
138
+ "kit": env.kit_report(pieces, grid=GRID, texture_pixels=TEXTURE_PIXELS, pivot="corner")}))
139
+ ```
140
+
141
+ Then gate it:
142
+ - `kit` passes: every piece has its footprint corner at the pivot, lengths on the 1 m grid, and the same
143
+ texel density (512 px/m).
144
+ - Every `lightmaps` entry passes: charts inside 0..1, no overlapping texel, and every chart at least
145
+ `margin - 1` texels from its neighbours at the piece's own lightmap size.
146
+ - `qa-check --model modular_kit.blend --objects Wall_2m --profile game`, and the same for each piece, passes.
147
+ Use `--profile game` because a tiling UV0 overlaps itself by design. The web profile flags that overlap as an
148
+ error. The lightmap set is gated by `lightmap_report`, because qa-check reads only the active UV map.
149
+
150
+ ---
151
+
152
+ ## 3. Texturing a kit: tiling, trims, unique and blends
153
+
154
+ | Surface | Use | Why |
155
+ |---|---|---|
156
+ | Large flat runs (walls, floors, ground) | A **tiling** material, UV0 at the kit's density (`box_uv`) | Unlimited area at constant density. With the pivot on the grid and the tile size dividing the grid, the pattern continues across piece seams. |
157
+ | Edges, frames, pipes, mouldings, kerbs | A **trim sheet** (`hard_surface_trims.map_quad_strip`) | One material for every edge of the kit. Strips tile along U only. Scale islands at most about 25 % off the target density (Beyond Extent). |
158
+ | Hero pieces seen up close (a gate, a statue) | **Unique** UVs and textures | Only where the piece is singular and inspected. |
159
+ | Repetition breakers | **Vertex colour** blending 2-3 tiling materials, plus **decals** | Keeps the base clean and inconspicuous. Big cracks or colour jumps in a tiling texture reveal the repeat (Roeder). |
160
+
161
+ Rules that keep a kit consistent:
162
+ - **One texel density for the kit**, calibrated on a 1 x 1 m wall. Then pick each tiling texture's repeat from
163
+ it (Beyond Extent). `kit_report` flags any piece more than 25 % off the kit median.
164
+ - **Sheets that share grid lines swap without touching UVs**: a metal trim and a wood trim with the same strip
165
+ layout re-skin the whole kit (Roeder).
166
+ - **Fewer materials, fewer draws.** Each material on a mesh is one draw per pass in BabylonJS. A kit drawn with
167
+ one tiling material, one trim and one decal atlas stays at three draws per merged chunk.
168
+
169
+ ---
170
+
171
+ ## 4. Terrain pieces, roads and cliffs
172
+
173
+ Use **Unity Terrain** for open ground. It reaches BabylonJS as a quadtree-LOD heightfield with up to 16 splat
174
+ layers, thin-instanced trees, instanced details and a Havok heightfield collider (Agent Reference §10). Model
175
+ terrain in Blender only when the terrain is a **kit**: track tiles, island pieces, cliff modules, or terrain
176
+ under a camera that never leaves a corridor.
177
+
178
+ | Need | Practice |
179
+ |---|---|
180
+ | Tiles that meet without cracks | Sample heights from one **world-space** height field (`rolling_hills`, or your own function), so each border vertex gets the same height from both tiles. |
181
+ | Tiles that meet without a shading crease | Set normals from the same field (`terrain_tile` does it). Normals computed from each tile's own faces differ along every border, because the faces beyond the edge are missing. The recipe measures 1.7 degrees of crease on rolling hills; field normals measure 0. |
182
+ | Density | Quads about the size the silhouette needs. A 16 m tile at 1 m quads is 512 triangles. Detail goes into the splat textures and the normal map. |
183
+ | Roads on terrain | Sweep a road profile along a curve (`references/geometry-nodes.md`). Sample the curve's heights from the terrain's height field. Give the road a skirt sunk below the surface, so the terrain never shows through at the edge. Unreal's landscape splines do the reverse: they raise or lower the terrain with a cosine falloff (Raise suits embankments, Lower suits rivers). |
184
+ | Rock-to-ground blend | Without Unreal's runtime virtual textures: a vertex-colour mask on the rock's or the road skirt's bottom, blending to a material that matches the terrain's tiling material. |
185
+ | Cliffs | A cliff kit of 2-4 pieces on the grid, sunk below the terrain at the base. Rotate and scale uniformly to vary them, never mirror (section 9). |
186
+
187
+ ### Recipe: two terrain tiles that meet with no crack and no crease
188
+
189
+ ```python
190
+ """Two 16 m terrain tiles side by side, heights and normals sampled from one world-space height field, and the
191
+ seam proof. A third pair with per-tile normals shows the crease that field normals remove. Saves terrain.blend."""
192
+ import json
193
+ import os
194
+ import sys
195
+
196
+ import bpy
197
+
198
+ import construction_kit as kit
199
+ import environment_kit as env
200
+
201
+ out_folder = sys.argv[sys.argv.index("--") + 1]
202
+ TILE_SIZE = 16.0
203
+ CELLS = 16 # 1 m quads
204
+ hills = env.rolling_hills(amplitude=3.0, wavelength=40.0)
205
+
206
+ kit.clear_default_scene()
207
+ west = env.terrain_tile("Terrain_0_0", (0.0, 0.0), TILE_SIZE, CELLS, hills)
208
+ east = env.terrain_tile("Terrain_1_0", (TILE_SIZE, 0.0), TILE_SIZE, CELLS, hills)
209
+ bpy.context.view_layer.update()
210
+ field_normals = env.seam_report(west, east)
211
+
212
+ # The common mistake, for comparison: the same tiles with normals from their own faces.
213
+ plain_west, plain_east = west.copy(), east.copy()
214
+ for plain in (plain_west, plain_east):
215
+ plain.data = plain.data.copy()
216
+ bpy.context.scene.collection.objects.link(plain)
217
+ plain.data.attributes.remove(plain.data.attributes["custom_normal"])
218
+ plain.location.z = -10.0 # out of the way of the real tiles
219
+ bpy.context.view_layer.update()
220
+ face_normals = env.seam_report(plain_west, plain_east)
221
+ bpy.data.objects.remove(plain_west)
222
+ bpy.data.objects.remove(plain_east)
223
+
224
+ for tile in (west, east):
225
+ tile.data.materials.append(bpy.data.materials.get("Terrain_Grass") or bpy.data.materials.new("Terrain_Grass"))
226
+ kit.smart_unwrap(tile)
227
+ bpy.ops.wm.save_as_mainfile(filepath=os.path.join(out_folder, "terrain.blend"))
228
+ print(json.dumps({"field_normals": field_normals, "face_normals": face_normals}))
229
+ ```
230
+
231
+ `field_normals` passes with 17 shared vertices, a gap of 0 and an angle of 0. `face_normals` fails on the
232
+ angle: that crease is the line a player sees along every tile border.
233
+
234
+ ---
235
+
236
+ ## 5. Props and scatter
237
+
238
+ - **Scatter is a placement problem, not a modelling one.** Build each prop once, with its pivot at its contact
239
+ point (a rock's base, a lamp's foot), then place copies. In Blender, scatter with Geometry Nodes: points on
240
+ faces, a density mask, random rotation and uniform scale, instance on points
241
+ (`references/geometry-nodes.md`). For a level, prefer to place props in Unity, or as Unity Terrain trees and
242
+ details, which become thin instances in BabylonJS (Agent Reference §10).
243
+ - **Rules, not hand placement, at scale.** Horizon Zero Dawn places 500+ asset types and 100,000+ objects from
244
+ paintable density maps, with layered maps settling footprint conflicts (van Muijden, GDC 2017). Scaled down,
245
+ that means density masks plus a few rules: slope, height and distance from paths.
246
+ - **Vary copies by rotation, uniform scale and per-instance colour, never by mirroring.** A negative-scale
247
+ instance renders apart from its group in BabylonJS, and mixed-sign thin instances render wrongly.
248
+ - **Keep variants few and strong**: 3-5 silhouettes per prop family, each read at play size
249
+ (`review-render --pixel-height`).
250
+ - **Let the engine see repetition.** The same mesh with the same material, not lightmapped and with Light
251
+ Probes Off, is one instanced draw per pass (section 9). Ten unique rocks are ten draws.
252
+
253
+ ---
254
+
255
+ ## 6. Hidden faces, closed pieces and z-fighting
256
+
257
+ - Delete faces no camera sees once the piece is placed (`drop_hidden_faces`): wall bottoms on the floor, the
258
+ undersides of slabs, the back of a piece that always stands against another.
259
+ - Two pieces must never share a coplanar face. A wall's bottom face lying on a floor's top is a back-to-back
260
+ pair that qa-check flags and the depth buffer cannot resolve.
261
+ - Keep pieces closed where the player can see round them (pillars, freestanding walls). Open them only where
262
+ a neighbour always hides the side.
263
+
264
+ ---
265
+
266
+ ## 7. Collision proxies
267
+
268
+ | Shape | Collider | Notes |
269
+ |---|---|---|
270
+ | Walls, floors, steps, boxes | **Box** colliders on the Unity prefab | The cheapest and most stable. An L corner takes **two** boxes, one per arm. |
271
+ | Columns, logs, barrels | **Capsule** or **sphere** | Unreal uses about 8 segments for these when they are modelled. |
272
+ | A rock or prop a primitive cannot fit | **Convex mesh** (`convex_proxy`) | Unity limits a convex mesh collider to **255 triangles**. A convex hull fills every concavity: the hull of an L blocks the inside corner. |
273
+ | A concave shape that matters | Several convex pieces, or boxes | A non-convex mesh collider works only on static or kinematic bodies, and costs the most. |
274
+ | Terrain | The Unity TerrainCollider | It becomes a Havok heightfield (Agent Reference §10). |
275
+ | Scatter (grass, pebbles) | None, or one hand-placed primitive | Thin instances share one bounding box for collisions in BabylonJS. |
276
+
277
+ Unreal's naming (`UBX_`, `UCP_`, `USP_` and `UCX_<RenderMesh>_##`) suits FBX pipelines that import collision
278
+ by name. In this pipeline, put collision on the Unity prefab instead. It reaches BabylonJS as a `collision`
279
+ block, a static Havok body when there is no Rigidbody, and two or more colliders become a compound body
280
+ (Agent Reference §11).
281
+
282
+ ### Recipe: why an L corner takes two boxes, not a hull
283
+
284
+ ```python
285
+ """Collision for an outside corner: its convex hull against two box proxies, one per arm. The hull's volume
286
+ shows how much of the walkable inside corner it would block. Saves collision.blend."""
287
+ import json
288
+ import os
289
+ import sys
290
+
291
+ import bmesh
292
+ import bpy
293
+
294
+ import construction_kit as kit
295
+ import environment_kit as env
296
+
297
+ out_folder = sys.argv[sys.argv.index("--") + 1]
298
+ WALL_HEIGHT, WALL_THICKNESS, ARM = 3.0, 0.2, 1.0
299
+
300
+
301
+ def volume(obj: bpy.types.Object) -> float:
302
+ """Volume of a closed mesh, cubic metres."""
303
+ edit_mesh = bmesh.new()
304
+ edit_mesh.from_mesh(obj.data)
305
+ result = edit_mesh.calc_volume(signed=False)
306
+ edit_mesh.free()
307
+ return result
308
+
309
+
310
+ kit.clear_default_scene()
311
+ corner = env.prism_piece("Corner_Out", [
312
+ ((0, 0), (WALL_THICKNESS, 0), (WALL_THICKNESS, WALL_THICKNESS), (0, WALL_THICKNESS)),
313
+ ((WALL_THICKNESS, 0), (ARM, 0), (ARM, WALL_THICKNESS), (WALL_THICKNESS, WALL_THICKNESS)),
314
+ ((0, WALL_THICKNESS), (WALL_THICKNESS, WALL_THICKNESS), (WALL_THICKNESS, ARM), (0, ARM))], height=WALL_HEIGHT)
315
+ hull = env.convex_proxy(corner)
316
+ # Two boxes, one per arm, overlapping in the corner block: what the Unity prefab gets as Box colliders.
317
+ boxes = [env.prism_piece("Corner_Out_Box_X", [((0, 0), (ARM, 0), (ARM, WALL_THICKNESS), (0, WALL_THICKNESS))], WALL_HEIGHT),
318
+ env.prism_piece("Corner_Out_Box_Y", [((0, 0), (WALL_THICKNESS, 0), (WALL_THICKNESS, ARM), (0, ARM))], WALL_HEIGHT)]
319
+ for box in boxes:
320
+ box.display_type, box.hide_render = "WIRE", True
321
+ piece_volume = volume(corner)
322
+ hull_volume = volume(bpy.data.objects[hull["object"]])
323
+ shared_block = WALL_THICKNESS * WALL_THICKNESS * WALL_HEIGHT # where the two boxes overlap
324
+ boxes_volume = sum(volume(box) for box in boxes) - shared_block
325
+ bpy.ops.wm.save_as_mainfile(filepath=os.path.join(out_folder, "collision.blend"))
326
+ print(json.dumps({"hull": hull, "piece_m3": round(piece_volume, 4), "hull_m3": round(hull_volume, 4),
327
+ "boxes_m3": round(boxes_volume, 4), "hull_extra_share": round(hull_volume / piece_volume - 1.0, 2)}))
328
+ ```
329
+
330
+ The hull fits Unity's convex limit (16 triangles), but it holds 89 % more volume than the piece. That extra
331
+ volume is the inside corner, where a player would hit an invisible wall. The two boxes cover exactly the piece
332
+ (`boxes_m3` equals `piece_m3`).
333
+
334
+ ---
335
+
336
+ ## 8. Lightmap UVs
337
+
338
+ Unity bakes from the mesh's second UV set (Unity's UV1, glTF's `TEXCOORD_1`). The Toolkit carries the
339
+ lightmap with each renderer's scale and offset baked into that set (Agent Reference §4).
340
+
341
+ | Decision | Practice |
342
+ |---|---|
343
+ | Who makes UV1 | **Author it in Blender** (`lightmap_uv`) when the piece is reused, curved or seen up close: you control where the splits go. Use Unity's **Generate Lightmap UVs** (`generateSecondaryUV`) for simple, boxy imports. Its defaults are Hard Angle 88, Angle Error 8 %, Area Error 15 %, and a Pack Margin of 4 px "assuming the Mesh fills a 1024 x 1024 lightmap". A mesh without UV2 falls back to UV0, which is wrong for any tiling or overlapping UV0. |
344
+ | Validity | Every chart inside 0..1, no overlapping faces, and chart areas in proportion to the surface (Unity, Epic). `lightmap_report` checks all three by rasterising at the bake size. |
345
+ | Margin | At least **2 full texels** between charts (Unity). **4** survives 4 x 4 block compression (Epic). The margin is in texels **at the piece's own lightmap size**, which is its surface area times the scene's Lightmap Resolution: `lightmap_resolution(piece, texels_per_metre)` computes it, like Unity's *Calculate* margin method. A margin set for a 1024 lightmap bleeds on a piece that gets 64 texels. |
346
+ | Splits | Split only at hard corners, deep recesses and hidden backs. "Any edge split will break the smoothness of the lighting" (Epic). Straighten curved charts: continuity beats exact proportion. |
347
+ | Resolution per piece | Raise Scale In Lightmap on pieces with lighting detail (trim, doorways). Doubling a trim mesh's lightmap from 64 to 128 removed most of its artifacts in Epic's example. Lower it on floors seen at a distance. |
348
+ | Cost in BabylonJS | A lightmapped renderer never shares its mesh: each copy gets its own mesh with its lightmap scale and offset baked in (Agent Reference §4). So lightmap the architecture, but keep repeated small props off lightmaps when they should instance (section 9). |
349
+
350
+ ---
351
+
352
+ ## 9. Draw calls and instancing for BabylonJS
353
+
354
+ The browser is CPU-bound on draws long before the GPU is busy. Every pass multiplies the draws of what it
355
+ renders: each shadow cascade, a depth pass, each camera's post chain (Agent Reference §20).
356
+
357
+ | Situation | What it costs | What to do |
358
+ |---|---|---|
359
+ | The same mesh and material, repeated | One draw per pass for the group, **if** the copies are not lightmapped and have Light Probes Off | glTF mesh instancing is on by default (`ExportMeshInstances`). Lightmapped copies each get their own mesh, and probe-lit nodes are loaded as their own meshes (Agent Reference §20). Decide per prop family: lightmapped (one draw each) or instanced (one draw for all). |
360
+ | Thousands of static copies (grass, pebbles, seats) | One draw for all, with no per-copy culling | Thin instances: Unity terrain trees and details become thin instances automatically. They suit "many static instances" seen together. Regular instances suit copies scattered widely, few visible at once (Babylon docs). |
361
+ | Unique static pieces sharing one material | One draw per mesh per pass | Merge them per area where they are scattered (bt-optimize's MeshCombiner). A level already drawn as one renderer per material gains nothing. `MergeMeshes` sources should share one material. Over 64k vertices needs 32-bit indices. |
362
+ | Mirrored copies (negative scale) | A separate draw; culling flips | Never mirror. Build `_L` and `_R` pieces. A negative-determinant instance renders apart from its group, and mixed-sign thin instances render wrongly. |
363
+ | A piece with N materials | N draws per pass | Trims and atlases: one tiling material, one trim and one decal atlas per kit. |
364
+ | Static pieces | CPU per frame | Mark them Static: frozen world matrices (`freezeworldmatrix`). Never on anything a clip, Timeline or physics body moves. |
365
+ | LODs | — | LOD Groups on heavy meshes. Unity switches by screen height, and the Toolkit runs the same rule. Name levels `<Name>_LOD0`, `_LOD1`. Instances follow LODs automatically in BabylonJS. |
366
+
367
+ **Budgets.** No authoritative web draw-call budget exists. Meta's WebXR guidance shows 1,000 single-triangle
368
+ draws dropping below 72 FPS, and recommends merging small meshes and batching by material. *Starting points*:
369
+ under about 100 draws per pass on mobile, and a few hundred on desktop. Measure with bt-optimize, and count per
370
+ pass and per owning object.
371
+
372
+ ---
373
+
374
+ ## 10. Budgets (web and BabylonJS first)
375
+
376
+ The figures marked *starting point* are working defaults, not published standards.
377
+
378
+ | Item | Web / mobile | Desktop | Source or reason |
379
+ |---|---|---|---|
380
+ | Wall or floor piece | 12-200 tris | 50-1,000 | *Starting point*. Detail lives in the tiling and trim textures |
381
+ | Prop | 100-1,500 tris | 500-5k | *Starting point*. Arm's mobile demo: 360-tri units, 3k-tri towers |
382
+ | Texel density | 256 px/m (top-down, mobile) to 512 px/m (third person) | 512-1024 px/m (1024 for first person) | CryEngine targets 512 px/m. Beyond Extent: highest for first person, lower for third person and top-down |
383
+ | Kit texture | 1024 px tiling, 1024-2048 trim | 2048 | Agent Reference §20: 2048 hero surfaces, 1024 or less for props |
384
+ | Lightmap | Lightmap Resolution 10-20 texels/m, 1024 atlases | 20-40, 2048 atlases | *Starting point*. Agent Reference §20: fewer, fuller atlases are cheaper |
385
+ | Lightmap margin | 4 texels at the piece's size | 4 | Epic (block compression), Unity (2 minimum) |
386
+ | Terrain | 4-8 layers, heightmap 257-513 | 8 layers, 513-1025 | Agent Reference §20 |
387
+ | Convex collider | ≤ 255 tris | ≤ 255 | Unity |
388
+ | Vertices per mesh | < 65,535 (16-bit indices) | same | Arm; Babylon `MergeMeshes` needs 32-bit indices above that |
389
+
390
+ ---
391
+
392
+ ## 11. Pitfalls
393
+
394
+ | Symptom | Cause | Fix |
395
+ |---|---|---|
396
+ | Gaps or overlaps after a few pieces | A footprint that is not a multiple of the others (384 against 512) | Footprints and lengths as grid multiples. `kit_report` |
397
+ | Every placed copy jumped | A pivot changed after layout | Fix pivots in the proof stage. Re-export with the same names and pivots |
398
+ | Flicker where a wall meets the floor | Coplanar faces from two pieces | `drop_hidden_faces`. Keep pieces from stacking faces |
399
+ | A visible seam in texture resolution between pieces | Texel density differs | One kit density. `kit_report` flags more than 25 % off |
400
+ | The pattern jumps at a piece seam | UV0 not world-scaled, or a pivot off the grid | `box_uv` with a tile size that divides the grid |
401
+ | Light bleeds between charts, dark spots at seams | The lightmap margin was set for a bigger lightmap than the piece gets | Pack at `lightmap_resolution(piece, scene texels per metre)`. Check with `lightmap_report` |
402
+ | A line of shading along terrain tile borders | Normals from each tile's own faces | `terrain_tile` (field normals). Check with `seam_report` |
403
+ | An invisible wall in an inside corner | A convex hull on a concave piece | Primitive colliders per arm, or several convex pieces |
404
+ | Draws do not drop although the props repeat | The copies are lightmapped or probe-lit, or mirrored | Keep repeated props off lightmaps with Light Probes Off. Never use negative scale |
405
+ | Repetition is obvious | Repeated detail props | Vary clutter first, then vertex-colour blends and decals |
406
+
407
+ ---
408
+
409
+ ## 12. Verification checklist
410
+
411
+ ```bash
412
+ node <skill>/scripts/bt-blender.mjs run kit.py out # prints kit_report and lightmap reports
413
+ node <skill>/scripts/bt-blender.mjs qa-check --model out/modular_kit.blend --objects Wall_2m --profile game
414
+ node <skill>/scripts/bt-blender.mjs review-render --model out/modular_kit.blend --out review --pixel-height 240
415
+ node <skill>/scripts/bt-blender.mjs measure-stations --spec refs/spec.json --model out/modular_kit.blend # hero pieces with references
416
+ node <skill>/scripts/bt-blender.mjs world-gate --spec refs/spec.json --model out/modular_kit.blend
417
+ ```
418
+
419
+ - [ ] The brief records the footprint, grid, tiling axes, thicknesses, pivot convention, texel density and
420
+ lightmap resolution.
421
+ - [ ] `kit_report` passes for every piece: pivot, grid lengths and placement, applied transforms, density.
422
+ - [ ] `lightmap_report` passes for every piece at its own `lightmap_resolution`.
423
+ - [ ] qa-check passes per piece (`--objects <piece> --profile game`). No hidden coplanar faces.
424
+ - [ ] Terrain tiles pass `seam_report` against each neighbour.
425
+ - [ ] Collision is planned per piece: primitives, or convex hulls of at most 255 triangles.
426
+ - [ ] Repeated props are marked for instancing (no lightmap, Light Probes Off, no negative scale), or
427
+ deliberately lightmapped and counted.
428
+ - [ ] A review render of a test layout at play size shows the seams and the repetition hidden. In Unity, a
429
+ snapped test room exports and its draw count is measured per pass (bt-optimize).
430
+
431
+ ---
432
+
433
+ ## Sources
434
+
435
+ - Joel Burgess, "Skyrim's Modular Approach to Level Design" (GDC 2013, Game Developer) —
436
+ https://www.gamedeveloper.com/design/skyrim-s-modular-approach-to-level-design ; slides:
437
+ https://www.slideshare.net/JoelBurgess/gdc2013-kit-buildingfinal
438
+ - 80.lv, Joel Burgess, "Building Huge Open Worlds: Modularity, Kits & Art Fatigue" —
439
+ https://80.lv/articles/building-huge-open-worlds-modularity-kits-art-fatigue
440
+ - Ian London, "Modular Level Kit Design Considerations" — https://ianlondon.github.io/posts/modular-level-kit-geometry
441
+ - 80.lv, Ruslan Nazirov, "Quick Tip: Texture Planning for Modular Environments" —
442
+ https://80.lv/articles/quick-tip-texture-planning-for-modular-environments
443
+ - 80.lv, Robert Roeder, "Arabian Afternoon: Working with Trim Sheets Efficiently" —
444
+ https://80.lv/articles/arabian-afternoon-working-with-trim-sheets-efficiently
445
+ - Beyond Extent, "Texel Density" deep dive — https://www.beyondextent.com/deep-dives/deepdive-texeldensity
446
+ - GDC Vault, Morten Olsen, "The Ultimate Trim: Texturing Techniques of Sunset Overdrive" —
447
+ https://gdcvault.com/play/1022323/
448
+ - CryEngine documentation, "Texels Per Meter" —
449
+ https://www.cryengine.com/docs/static/engines/cryengine-3/categories/1114113/pages/21267831
450
+ - Epic Games, "Landscape Splines", "Understanding Lightmapping", "Generating Lightmap UVs" and "FBX Static
451
+ Mesh Pipeline" — https://dev.epicgames.com/documentation/en-us/unreal-engine/landscape-splines-in-unreal-engine ,
452
+ https://dev.epicgames.com/documentation/en-us/unreal-engine/understanding-lightmapping-in-unreal-engine ,
453
+ https://dev.epicgames.com/documentation/en-us/unreal-engine/generating-lightmap-uvs-in-unreal-engine ,
454
+ https://dev.epicgames.com/documentation/en-us/unreal-engine/fbx-static-mesh-pipeline-in-unreal-engine
455
+ - Jaap van Muijden, "GPU-Based Procedural Placement in Horizon Zero Dawn" (GDC 2017) —
456
+ https://www.guerrilla-games.com/read/gpu-based-procedural-placement-in-horizon-zero-dawn
457
+ - Unity Manual: "Generating lightmap UVs", "Lightmap UVs settings reference", "Troubleshooting lightmap UVs",
458
+ "Mesh Collider", "Draw call batching", "GPU instancing", "Nested prefabs", "Move, rotate, and scale in
459
+ increments" — https://docs.unity.com/en-us/engine/current/manual/lighting-overview/direct-and-indirect-lighting/lightmapping/lighting-gi-uvs/generating-lightmapping-uvs ,
460
+ https://docs.unity.com/en-us/engine/6000.6/manual/lighting-overview/direct-and-indirect-lighting/lightmapping/lighting-gi-uvs/reference ,
461
+ https://docs.unity3d.com/6/Documentation/Manual/LightingGiUVs-Troubleshooting.html ,
462
+ https://docs.unity.com/en-us/engine/current/manual/physics-section/physics-overview/collision-section/collider-shapes/mesh-colliders/class-mesh-collider ,
463
+ https://docs.unity.com/en-us/engine/6000.0/manual/analysis/graphics-performance-profiling/reduce-draw-calls/draw-call-batching/draw-call-batching ,
464
+ https://docs.unity.com/en-us/engine/6000.0/manual/analysis/graphics-performance-profiling/reduce-draw-calls/gpuinstancing/gpuinstancing ,
465
+ https://docs.unity.com/en-us/engine/current/manual/working-with-gameobjects/prefabs/nested ,
466
+ https://docs.unity.com/en-us/engine/6000.6/manual/working-with-scenes/scenes-manage-gameobjects/grid-snapping/snap-increments
467
+ - BabylonJS documentation: "Instances", "Thin Instances", "Merging Meshes", "Optimizing Your Scene", "Level of
468
+ Detail" — https://doc.babylonjs.com/features/featuresDeepDive/mesh/copies/instances ,
469
+ https://doc.babylonjs.com/features/featuresDeepDive/mesh/copies/thinInstances ,
470
+ https://doc.babylonjs.com/features/featuresDeepDive/mesh/mergeMeshes ,
471
+ https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene ,
472
+ https://doc.babylonjs.com/features/featuresDeepDive/mesh/LOD
473
+ - Meta, "WebXR Performance Optimization Workflow" — https://developers.meta.com/horizon/documentation/web/webxr-perf-workflow/
474
+ - Android Developers / Arm, "Optimize geometry" — https://developer.android.com/games/optimize/geometry
475
+ - Babylon Toolkit Agent Reference, `references/unity-authoring-recipes.md` §4 (lightmaps), §10 (terrain),
476
+ §11 (physics), §19 (static flags) and §20 (web budget).
477
+ - Ideas credited, no code copied: EL4CTEO/blender-skills, `blender-environment-kits` (the grid footprint and
478
+ pivot checks, and texel density within 25 % of the kit median) — https://github.com/EL4CTEO/blender-skills