@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.
- package/README.md +3 -2
- package/package.json +1 -1
- package/skills/bt-blender/SKILL.md +386 -0
- package/skills/bt-blender/THIRD_PARTY_NOTICES.md +141 -0
- package/skills/bt-blender/references/art-style-and-genre.md +173 -0
- package/skills/bt-blender/references/characters-and-creatures.md +644 -0
- package/skills/bt-blender/references/environments.md +478 -0
- package/skills/bt-blender/references/game-engine-export.md +284 -0
- package/skills/bt-blender/references/geometry-nodes.md +447 -0
- package/skills/bt-blender/references/hard-surface.md +720 -0
- package/skills/bt-blender/references/procedural-generation.md +358 -0
- package/skills/bt-blender/references/rigging-and-animation.md +1080 -0
- package/skills/bt-blender/references/sculpting-and-retopology.md +544 -0
- package/skills/bt-blender/references/uv-and-pbr-materials.md +381 -0
- package/skills/bt-blender/references/vehicles.md +632 -0
- package/skills/bt-blender/scripts/blender/assembly_check.py +420 -0
- package/skills/bt-blender/scripts/blender/character_blockout.py +462 -0
- package/skills/bt-blender/scripts/blender/construction_kit.py +1710 -0
- package/skills/bt-blender/scripts/blender/environment_kit.py +525 -0
- package/skills/bt-blender/scripts/blender/export_asset.py +623 -0
- package/skills/bt-blender/scripts/blender/geometry_nodes_builders.py +575 -0
- package/skills/bt-blender/scripts/blender/hard_surface_panels.py +374 -0
- package/skills/bt-blender/scripts/blender/hard_surface_trims.py +200 -0
- package/skills/bt-blender/scripts/blender/image_measure.py +568 -0
- package/skills/bt-blender/scripts/blender/materials_pbr.py +439 -0
- package/skills/bt-blender/scripts/blender/measure_stations.py +486 -0
- package/skills/bt-blender/scripts/blender/ortho_views.py +309 -0
- package/skills/bt-blender/scripts/blender/procedural_game_ready.py +258 -0
- package/skills/bt-blender/scripts/blender/procedural_generators.py +842 -0
- package/skills/bt-blender/scripts/blender/qa_check.py +729 -0
- package/skills/bt-blender/scripts/blender/retopology_tools.py +781 -0
- package/skills/bt-blender/scripts/blender/review_render.py +358 -0
- package/skills/bt-blender/scripts/blender/rigging_tools.py +1170 -0
- package/skills/bt-blender/scripts/blender/style_palette.py +190 -0
- package/skills/bt-blender/scripts/blender/tool_common.py +289 -0
- package/skills/bt-blender/scripts/blender/uv_layout.py +555 -0
- package/skills/bt-blender/scripts/blender/vehicle_parts.py +370 -0
- package/skills/bt-blender/scripts/blender/view_consistency.py +133 -0
- package/skills/bt-blender/scripts/blender/world_gate.py +219 -0
- package/skills/bt-blender/scripts/bt-blender.mjs +329 -0
- package/skills/bt-blender/scripts/validate_gltf.mjs +204 -0
- package/skills/bt-gauntlet/SKILL.md +6 -6
- package/skills/bt-gauntlet/references/critic-rubrics.md +71 -4
- package/skills/bt-gauntlet/references/spec-composition.md +13 -0
- package/skills/bt-gauntlet/references/unity-pipeline.md +18 -2
- package/skills/bt-unwrap/scripts/blender/__pycache__/bt_unwrap.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/image_utils.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/mesh_tools.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/model_io.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/previews.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/rasterizer.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/reference_views.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/reference_warp.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/texture_bake.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/texture_compose.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/uv_layout.cpython-313.pyc +0 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
# Procedural generation: seeded generators, variation sets and game-ready output
|
|
2
|
+
|
|
3
|
+
**Load this when** you are about to make many related assets from one set of rules, or one asset you will
|
|
4
|
+
regenerate with new numbers:
|
|
5
|
+
- rocks, boulders and cliff chunks;
|
|
6
|
+
- blocks of buildings, rooftops and greebles;
|
|
7
|
+
- trees, shrubs and roots;
|
|
8
|
+
- roads, track centre lines and kerbs;
|
|
9
|
+
- any "give me ten variants".
|
|
10
|
+
|
|
11
|
+
Load it in particular when the output must be reproducible (the same seed gives the same file next month), or
|
|
12
|
+
when generated meshes must pass the same QA as hand-made ones.
|
|
13
|
+
|
|
14
|
+
**What it assumes.** The Agent Reference's Blender guide (`references/unity-blender-cli.md`) covers the rest:
|
|
15
|
+
- §6: data over operators; check every operator's return;
|
|
16
|
+
- §8.4b–d: measure forms against references, and the construction kit's lofts, tubes, bevels and shading;
|
|
17
|
+
- `hard-surface.md`: bevels and normals on manufactured parts;
|
|
18
|
+
- `geometry-nodes.md`: scatter, sweeps and instancing;
|
|
19
|
+
- `uv-and-pbr-materials.md` and `game-engine-export.md`: UVs, LODs and collision in depth.
|
|
20
|
+
|
|
21
|
+
This file goes deeper on generation itself and does not repeat them.
|
|
22
|
+
|
|
23
|
+
**Helpers.**
|
|
24
|
+
- `scripts/blender/procedural_generators.py`:
|
|
25
|
+
- `SeededRandom` (labelled streams);
|
|
26
|
+
- `rock`, `building`;
|
|
27
|
+
- `space_colonization`, `lsystem_expand`, `lsystem_skeleton`, `skin_skeleton`;
|
|
28
|
+
- `closed_track_centerline`, `road_ribbon`;
|
|
29
|
+
- `geometry_fingerprint`, `variation_manifest`.
|
|
30
|
+
- `scripts/blender/procedural_game_ready.py`: `lod_chain`, `normal_deviation`, `convex_hull_collider`,
|
|
31
|
+
`box_collider`.
|
|
32
|
+
|
|
33
|
+
Every recipe below is a complete script: run `node <skill>/scripts/bt-blender.mjs run recipe.py <out folder>`.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 1. The professional workflow
|
|
38
|
+
|
|
39
|
+
1. **Write the parameters before the code.** A generator is a function of named, unit-bearing parameters
|
|
40
|
+
(metres, degrees, counts) plus one integer seed. Ranges, not values, go in the parameters
|
|
41
|
+
(`width_range=(8, 14)`), and the seed picks within them.
|
|
42
|
+
2. **Build from the big form down** (primary, secondary, tertiary), each stage reading its own random stream:
|
|
43
|
+
the rock's cleavage planes, then its surface noise; the building's bay grid, then windows, then roof units.
|
|
44
|
+
3. **Close the determinism contract.** The same parameters and seed give the same geometry in a new process,
|
|
45
|
+
checked by fingerprint (section 2).
|
|
46
|
+
4. **Make it game-ready inside the generator**, not afterwards by hand:
|
|
47
|
+
- origin at the bottom centre;
|
|
48
|
+
- metres;
|
|
49
|
+
- material slots named and shared across variants;
|
|
50
|
+
- UVs;
|
|
51
|
+
- smooth and hard shading by angle.
|
|
52
|
+
|
|
53
|
+
Then LODs and collision (section 5).
|
|
54
|
+
5. **Gate every variant** with `qa-check --model … --objects <one variant>` (profile `game`). Run it per
|
|
55
|
+
object: qa-check treats the objects it is given as one asset, so separate variants report each other as
|
|
56
|
+
floating parts.
|
|
57
|
+
6. **Record the set**: `variation_manifest` (name, seed, size, faces, fingerprint, parameters, Blender and Python
|
|
58
|
+
versions) beside the exported files. The manifest is what lets someone rebuild variant 7 exactly.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 2. Seeded randomness and determinism
|
|
63
|
+
|
|
64
|
+
| Source of randomness | Reproducible? | Use |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| `random.Random(seed).random()` | **Yes, across Python versions**: the only method the Python docs guarantee | The base of `SeededRandom`; derive uniform, integer, choice, vectors from it yourself |
|
|
67
|
+
| `Random.randint`, `choice`, `shuffle`, `gauss`, `sample` | **No guarantee**: their algorithms may change between versions | Avoid in generators |
|
|
68
|
+
| `numpy.random.default_rng(seed)` | Same stream on the same NumPy version; NumPy's compatibility policy allows streams to change between versions | Fine inside one Blender build; record the NumPy version in the manifest |
|
|
69
|
+
| `hash(string)` | **No**: randomised per process (`PYTHONHASHSEED`) | Never seed from it; `SeededRandom.child(label)` uses SHA-256 |
|
|
70
|
+
| `mathutils.noise` (Perlin, fBm) | Yes: a pure function of position | Offset the sample position by a seeded vector to vary it |
|
|
71
|
+
| Geometry Nodes Random Value / Distribute | Yes: hashed from ID or index and the seed | Feed the seed from the group input |
|
|
72
|
+
| Set and dict iteration of Blender objects | Insertion order, but object and mesh names gain `.001` when one exists | Clear the scene first; name everything explicitly |
|
|
73
|
+
|
|
74
|
+
**Independent streams.** One `SeededRandom(seed)` per asset. Each stage calls `child("cuts")`,
|
|
75
|
+
`child("windows")` and so on, which hashes `(seed, label)` with SHA-256 into a new seed. Adding a random call to
|
|
76
|
+
the windows does not move a single roof unit.
|
|
77
|
+
|
|
78
|
+
**Fingerprint.** `geometry_fingerprint(obj)` hashes the evaluated mesh: positions rounded to 1e-7 m, the face
|
|
79
|
+
corner indices and the material indices. Measured on 5.3.0: three seeds gave three different fingerprints, and
|
|
80
|
+
for every rock and building the fingerprint was identical in a second Blender process. Voxel remesh and
|
|
81
|
+
collapse decimation included, nothing drifted.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 3. Generators: what each technique is good for
|
|
86
|
+
|
|
87
|
+
| Asset | Technique | Why it reads right | Helper |
|
|
88
|
+
|---|---|---|---|
|
|
89
|
+
| Boulders, cliff chunks | **Cleave + displace + remesh**: an ellipsoid cut by random planes (fracture facets), fractal noise along the normals, voxel remesh, collapse decimation to a triangle budget | Flat facets with sharp breaks read as rock; noise alone reads as a potato. Remesh makes the topology even and manifold before decimation | `rock` |
|
|
90
|
+
| Low-rise buildings | **Bay grid**: the facade split into bays per floor, a window or a blank per bay by seeded chance, insets for recesses, a parapet, roof units | Real facades are rhythmic. A grid keeps every variant structurally plausible and the UVs world-scaled | `building` |
|
|
91
|
+
| Trees with believable crowns | **Space colonisation** (Runions et al. 2007): attraction points fill the crown; branches grow toward them and compete | Branching follows the crown shape and fills it without crossing; one parameter set gives many species-like variants | `space_colonization` + `skin_skeleton` |
|
|
92
|
+
| Stylised plants, ferns, coral, fractal props | **L-systems**: rewriting rules interpreted by a 3D turtle | Strong, regular structure; stochastic rules vary it | `lsystem_expand` + `lsystem_skeleton` + `skin_skeleton` |
|
|
93
|
+
| Race tracks, roads | **Seeded control polygon + centripetal Catmull-Rom**, then a ribbon with metre UVs | Centripetal parameterisation has no cusps or self-loops on uneven spacing; the ribbon gives exact widths and banking | `closed_track_centerline` + `road_ribbon` |
|
|
94
|
+
| Swept profiles, scatters, arrays | Geometry Nodes | Rule-driven and live; see `geometry-nodes.md` | `geometry_nodes_builders` |
|
|
95
|
+
|
|
96
|
+
### Rocks
|
|
97
|
+
|
|
98
|
+
Parameters that matter:
|
|
99
|
+
- `cuts` (5–9): fewer cuts read as river stones, more as quarried blocks;
|
|
100
|
+
- `cut_depth` (8–30 % of the radius);
|
|
101
|
+
- `noise_scale` (lumps per metre) and `noise_strength` (scaled by the mean radius);
|
|
102
|
+
- `target_triangles`.
|
|
103
|
+
|
|
104
|
+
The voxel size is the smallest dimension / 40: fine enough to keep the facets, coarse enough to stay fast.
|
|
105
|
+
Edges over 50° shade hard (the fracture edges) and the rest smooth, and the unwrap seams follow the same 50°
|
|
106
|
+
angle. Measured: three 1 x 0.8 x 0.6 m rocks in 0.3 s, each exactly 1,200 triangles, all passing qa-check.
|
|
107
|
+
|
|
108
|
+
`rock(…, sink=…)` buries the base. By default the lowest point sits at Z = 0, so a level can place the rock and
|
|
109
|
+
sink it per placement (qa-check flags a base below the ground plane as a warning).
|
|
110
|
+
|
|
111
|
+
### Buildings
|
|
112
|
+
|
|
113
|
+
The facade is one closed shell: perimeter rings on the bay grid, shared corners, a bottom cap, a parapet and a
|
|
114
|
+
recessed roof deck. Windows are `inset_individual` per bay, recessed by `window_depth`, glass in slot 1 and
|
|
115
|
+
frames in slot 2. Roof units are boxes, kept apart from each other, sunk 2 cm into the deck, with their buried
|
|
116
|
+
bottom face deleted. Two bmesh traps cost a full debugging round here (measured on 5.3.0):
|
|
117
|
+
- `bmesh.ops.inset_individual` on freshly created faces did **nothing**: zero-area ring faces, because the
|
|
118
|
+
face normals were not computed yet. Call `bm.normal_update()` first.
|
|
119
|
+
- Without `use_even_offset=True`, an inset of 0.6 m moved the corners 0.6 m diagonally, which is 0.42 m per
|
|
120
|
+
side. A 1.4 x 1.7 m window came out 1.75 x 2.35 m.
|
|
121
|
+
|
|
122
|
+
UVs are world-scale box projection (`uv_layout.box_project`, 4 m per tile), so every variant shares one texel
|
|
123
|
+
density on tiling or trim materials. qa-check then warns that the UV area overlaps 100 %, which is correct for
|
|
124
|
+
tiling and would be wrong for a unique bake or a lightmap (add a lightmap UV, section 5).
|
|
125
|
+
|
|
126
|
+
### Trees by space colonisation
|
|
127
|
+
|
|
128
|
+
| Parameter | Effect | Start at |
|
|
129
|
+
|---|---|---|
|
|
130
|
+
| Attraction points N | Density and fineness of branching (the paper's figures use hundreds to 12,000) | 400–1,000 for real-time |
|
|
131
|
+
| Segment length D | Node spacing; sets the polygon budget | 0.2–0.3 m for a 6 m tree |
|
|
132
|
+
| Influence radius d_i | Large: smooth, open branching; small (≈ 1–2 D): gnarled, wandering tips | 8 D |
|
|
133
|
+
| Kill distance d_k | How close a branch must come to consume a point; larger: sparser twigs | 2 D (the paper's figures) |
|
|
134
|
+
| Crown envelope | The silhouette: an ellipsoid, or any point set you sample | From the reference |
|
|
135
|
+
|
|
136
|
+
Radii follow the pipe model, r_parent^n = Σ r_child^n. n = 2 conserves cross-section (da Vinci's rule); higher
|
|
137
|
+
values thin the tips faster; the helper uses 2.5.
|
|
138
|
+
|
|
139
|
+
`skin_skeleton` turns a skeleton into tubes. A limb runs on through each fork along its thickest child, so a
|
|
140
|
+
trunk is one unbroken tube. Side branches start on the parent's axis at half their own radius, so they leave
|
|
141
|
+
the parent through its wall at an angle, and their buried base cap is deleted. Branches that start at full
|
|
142
|
+
radius on the parent's surface lie along its wall: coplanar overlaps, which qa-check reported as z-fighting.
|
|
143
|
+
|
|
144
|
+
### L-systems
|
|
145
|
+
|
|
146
|
+
`lsystem_expand(axiom, rules, iterations, seed)` rewrites in parallel. A rule is a string, or a weighted list
|
|
147
|
+
for a stochastic system. `lsystem_skeleton` interprets the result:
|
|
148
|
+
|
|
149
|
+
| Symbol | Turtle action |
|
|
150
|
+
|---|---|
|
|
151
|
+
| `F` / `f` | Move forward one step, drawing / not drawing |
|
|
152
|
+
| `+` / `-` | Yaw about the turtle's up axis |
|
|
153
|
+
| `&` / `^` | Pitch down / up |
|
|
154
|
+
| `\` / `/` | Roll about the heading |
|
|
155
|
+
| `|` | Turn around |
|
|
156
|
+
| `[` / `]` | Push / pop the state; each push shortens later steps by `step_decay` |
|
|
157
|
+
|
|
158
|
+
**Turn about the right axis.** The turtle heads along its local Z. If `+` and `-` rotate about Z, they only
|
|
159
|
+
roll. Then `[+X][-X]` grows both branches straight ahead, on top of each other. Measured with that mistake: 42 of
|
|
160
|
+
111 nodes duplicated, and 864 z-fighting triangle pairs in qa-check; with yaw about local Y, 0 and 0.
|
|
161
|
+
|
|
162
|
+
### Roads and race tracks
|
|
163
|
+
|
|
164
|
+
`closed_track_centerline(seed, radius, control_points, irregularity, elevation)` jitters control points on a
|
|
165
|
+
circle, then samples a closed centripetal Catmull-Rom spline through them. `road_ribbon(name, centerline,
|
|
166
|
+
width, lanes, bank_degrees, texture_metres)` builds the surface:
|
|
167
|
+
- one ring across the road per centre-line point;
|
|
168
|
+
- the side direction taken against world up, so the road stays level unless banked;
|
|
169
|
+
- UVs in metres: U = 0..1 over the width, V = distance / `texture_metres`;
|
|
170
|
+
- the closing ring duplicated and welded, so V runs on to the full length and the UV seam stays.
|
|
171
|
+
|
|
172
|
+
For curbs, rails and walls along the same line, sweep profiles with `geometry-nodes.md` §4.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## 4. Variation sets
|
|
177
|
+
|
|
178
|
+
- **Name by kind and seed**: `Rock_007`, `Building_012`. The manifest maps each name to its seed and
|
|
179
|
+
fingerprint.
|
|
180
|
+
- **Share materials across variants** (`assign_slots` reuses materials by name). Variants with one material
|
|
181
|
+
batch; a material per variant does not.
|
|
182
|
+
- **Normalise what the level needs to be uniform**: footprint grid, height range, pivot, texel density. Vary
|
|
183
|
+
the rest.
|
|
184
|
+
- **Reject near-duplicates.** Distinct fingerprints prove only that the bytes differ. For silhouettes, compare
|
|
185
|
+
bounding proportions (`size_m` in the manifest) and reject a variant within a few per cent of another on
|
|
186
|
+
every axis.
|
|
187
|
+
- **3–5 variants per kind** for scatter (each is a draw call per instanced set); more for hero placements.
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## 5. Making generated meshes game-ready
|
|
192
|
+
|
|
193
|
+
| Need | Do | Where |
|
|
194
|
+
|---|---|---|
|
|
195
|
+
| Unique UVs (bakes, unique textures) | Seams from hard edges, unwrap, equal texel density, pack | `uv-and-pbr-materials.md` §2–3 |
|
|
196
|
+
| Tiling UVs | World-scale box projection; the same metres per tile on every variant | `uv_layout.box_project` |
|
|
197
|
+
| Lightmap UV | `uv_layout.add_lightmap_uv` (no overlap, margin at the lightmap's size) | `uv-and-pbr-materials.md` §4, `environments.md` §8 |
|
|
198
|
+
| LODs | `lod_chain(obj, ratios=(0.5, 0.25))`: `<Name>_LOD0..2`, LOD0 normals transferred | `game-engine-export.md` §4 |
|
|
199
|
+
| Collision | `convex_hull_collider` (one hull per loose part, ≤ 64 vertices) or `box_collider` | `game-engine-export.md` §5, `environments.md` §7 |
|
|
200
|
+
| Pivot and scale | Origin at the bottom centre, metres, transforms applied | Every generator here does it |
|
|
201
|
+
|
|
202
|
+
### Recipe: a rock variation set with a manifest, LODs and hulls
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
# recipe: rock-set
|
|
206
|
+
import json, os, sys
|
|
207
|
+
import bpy
|
|
208
|
+
import construction_kit as kit
|
|
209
|
+
import procedural_game_ready as game_ready
|
|
210
|
+
import procedural_generators as procedural
|
|
211
|
+
|
|
212
|
+
out = sys.argv[sys.argv.index("--") + 1]
|
|
213
|
+
kit.clear_default_scene()
|
|
214
|
+
parameters = {"generator": "rock", "size": [1.2, 0.9, 0.7], "cuts": 7, "target_triangles": 1200}
|
|
215
|
+
rocks = []
|
|
216
|
+
for index, seed in enumerate((1, 2, 3)):
|
|
217
|
+
rock = procedural.rock(f"Rock_{seed:03d}", seed, size=parameters["size"], cuts=parameters["cuts"],
|
|
218
|
+
target_triangles=parameters["target_triangles"])
|
|
219
|
+
rock.location.x = index * 2.0
|
|
220
|
+
rocks.append(rock)
|
|
221
|
+
manifest = procedural.variation_manifest(rocks, parameters)
|
|
222
|
+
fingerprints = {variant["name"]: variant["fingerprint"] for variant in manifest["variants"]}
|
|
223
|
+
assert len(set(fingerprints.values())) == len(rocks), "two seeds gave the same rock"
|
|
224
|
+
|
|
225
|
+
# Determinism: rebuild one variant and compare.
|
|
226
|
+
again = procedural.rock("Rock_check", 2, size=parameters["size"], cuts=parameters["cuts"],
|
|
227
|
+
target_triangles=parameters["target_triangles"])
|
|
228
|
+
assert procedural.geometry_fingerprint(again) == fingerprints["Rock_002"]
|
|
229
|
+
bpy.data.objects.remove(again)
|
|
230
|
+
|
|
231
|
+
for rock in rocks:
|
|
232
|
+
hulls = game_ready.convex_hull_collider(rock, max_vertices=48)
|
|
233
|
+
levels = game_ready.lod_chain(rock, ratios=(0.5, 0.25))
|
|
234
|
+
print(levels[0].name, [game_ready.triangle_count(level) for level in levels],
|
|
235
|
+
[hull.name for hull in hulls], game_ready.normal_deviation(levels[2], levels[0]))
|
|
236
|
+
json.dump(manifest, open(os.path.join(out, "rocks.manifest.json"), "w"), indent=2)
|
|
237
|
+
bpy.ops.wm.save_as_mainfile(filepath=os.path.join(out, "rocks.blend"))
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Then gate each variant: `qa-check --model rocks.blend --profile game --objects Rock_001_LOD0`.
|
|
241
|
+
|
|
242
|
+
### Recipe: buildings, a tree and a race track
|
|
243
|
+
|
|
244
|
+
```python
|
|
245
|
+
# recipe: generators
|
|
246
|
+
import os, sys
|
|
247
|
+
import bpy
|
|
248
|
+
import construction_kit as kit
|
|
249
|
+
import procedural_generators as procedural
|
|
250
|
+
|
|
251
|
+
out = sys.argv[sys.argv.index("--") + 1]
|
|
252
|
+
kit.clear_default_scene()
|
|
253
|
+
for index, seed in enumerate((4, 5, 6)):
|
|
254
|
+
block = procedural.building(f"Building_{seed:03d}", seed, floors_range=(2, 5))
|
|
255
|
+
block.location.x = index * 25.0
|
|
256
|
+
print(block.name, len(block.data.polygons), "faces", [m.name for m in block.data.materials])
|
|
257
|
+
|
|
258
|
+
skeleton = procedural.space_colonization(seed=5, crown_center=(0, 0, 4.5), crown_radii=(2.2, 2.2, 1.8),
|
|
259
|
+
attraction_points=600, segment_length=0.25)
|
|
260
|
+
tree = procedural.skin_skeleton("Tree_005", skeleton, sides=6)
|
|
261
|
+
tree.location = (-12, 0, 0)
|
|
262
|
+
print(tree.name, len(skeleton["positions"]), "nodes,", len(tree.data.polygons), "faces, trunk radius",
|
|
263
|
+
round(skeleton["radii"][0], 3))
|
|
264
|
+
|
|
265
|
+
rules = {"X": [(1, "F[+X][-X]FX"), (1, "F[&X][^X]/X")], "F": "FF"}
|
|
266
|
+
plant = procedural.skin_skeleton("Plant_007", procedural.lsystem_skeleton(
|
|
267
|
+
procedural.lsystem_expand("X", rules, 4, seed=7), step=0.15, angle_degrees=25), sides=5)
|
|
268
|
+
plant.location = (-18, 0, 0)
|
|
269
|
+
|
|
270
|
+
line = procedural.closed_track_centerline(seed=4, radius=40.0, control_points=10, elevation=3.0)
|
|
271
|
+
road = procedural.road_ribbon("Track_004", line, width=10.0, lanes=4, bank_degrees=4.0, texture_metres=10.0)
|
|
272
|
+
road.location.y = 70.0
|
|
273
|
+
print(road.name, len(road.data.polygons), "faces,", round(road["bt_road_length_m"], 1), "m")
|
|
274
|
+
bpy.ops.wm.save_as_mainfile(filepath=os.path.join(out, "generators.blend"))
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
Measured on 5.3.0:
|
|
278
|
+
- buildings of 144–321 faces (2–5 floors) with slots Wall, Glass and Trim;
|
|
279
|
+
- a 259-node tree skinned to 1,944 faces in 0.06 s, trunk radius 6.4 cm;
|
|
280
|
+
- a 261 m track ribbon of 480 faces.
|
|
281
|
+
|
|
282
|
+
The buildings and the track pass `qa-check --profile game` per object. The tree and the plant report their
|
|
283
|
+
side branches as floating (26 and 20 parts): a limitation of qa-check's contact test, not of the meshes. With
|
|
284
|
+
the intersection test run for every part, both report 0 (pitfalls). The rock recipe's LODs all pass, and LOD2
|
|
285
|
+
keeps a mean normal deviation of 0.8–1.0° from LOD0.
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
## 6. Budgets
|
|
290
|
+
|
|
291
|
+
| Generated asset | Web / mobile | Desktop | Note |
|
|
292
|
+
|---|---|---|---|
|
|
293
|
+
| Rock, scatter size (< 1 m) | 100–500 tris | 300–1,500 | Many copies: triangles x copies is the real cost |
|
|
294
|
+
| Rock, hero (2–5 m) | 1,000–3,000 | 3,000–8,000 | Silhouette is everything; spend triangles on the outline |
|
|
295
|
+
| Low-rise building block | 300–1,500 tris + roof units | 1,500–5,000 | Detail goes in trims and decals (`hard-surface.md` §6) |
|
|
296
|
+
| Tree skeleton mesh | 1,500–5,000 tris before leaves | 5,000–15,000 | Leaves are cards on a separate alpha-tested material |
|
|
297
|
+
| Track ribbon | 2–4 lanes across, a ring every 1–3 m on straights, closer in corners | same | Ribbons are long: split by sector so each piece culls |
|
|
298
|
+
| Variants per kind | 3–5 | 5–10 | Each variant is a draw call per instanced set |
|
|
299
|
+
|
|
300
|
+
All figures are *starting points*, sized to the web budgets in `hard-surface.md` §8; adjust them to the pixel
|
|
301
|
+
height the asset gets in the game.
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## 7. Pitfalls
|
|
306
|
+
|
|
307
|
+
| Symptom | Cause | Fix |
|
|
308
|
+
|---|---|---|
|
|
309
|
+
| Different geometry from the same seed in a new session | `randint`/`choice`/`shuffle`, `hash()`, or a stream shared between stages | `SeededRandom` with `child(label)` per stage; compare fingerprints across two processes |
|
|
310
|
+
| Inset does nothing, or zero-area faces appear | `bmesh.ops.inset_*` on faces whose normals were never computed | `bm.normal_update()` before insetting |
|
|
311
|
+
| Insets 30 % too thin at corners (window too big) | `use_even_offset` left False | `use_even_offset=True` |
|
|
312
|
+
| All faces on material 0 after assigning materials | `mesh.materials.clear()` resets every face's material index | Fill slots in place (`assign_slots` does) |
|
|
313
|
+
| Decimate misses the budget (a 900 target gave 1,735 faces) | Ratio computed from faces, while Decimate counts triangles | Ratio = target / triangles (`len(vertices) - 2` per face) |
|
|
314
|
+
| Rooftop boxes z-fight | Overlapping greebles share coplanar faces | Reject overlapping placements (clearance), sink into the deck, delete the buried bottom face |
|
|
315
|
+
| L-system branches grow on top of each other | `+`/`-` rotate about the heading (a roll) | Yaw about the turtle's up axis |
|
|
316
|
+
| Tree branches z-fight with their parent | Branches start at full radius on the parent's surface | Start on the parent's axis at half radius |
|
|
317
|
+
| qa-check calls tree branches "floating" | Its contact graph skips the intersection test for a part that already touched another part within tolerance, so siblings meeting at one fork link only to each other | Run per tree with `--allow-floating <Tree>` and check attachment yourself; measured: 26 false "floating" parts with the stock check, 0 when the intersection test runs for every part |
|
|
318
|
+
| Variants report each other as floating | Several variants checked as one asset | `qa-check --objects <one variant>` per variant |
|
|
319
|
+
| Track texture streaks where the loop closes | Parameter UVs, or the last ring welded with its UVs | Metre V and a duplicated, position-welded closing ring (`road_ribbon`) |
|
|
320
|
+
|
|
321
|
+
---
|
|
322
|
+
|
|
323
|
+
## 8. Verification checklist
|
|
324
|
+
|
|
325
|
+
1. Fingerprints of all variants are distinct, and a rebuild of one seed **in a fresh process** matches its
|
|
326
|
+
fingerprint.
|
|
327
|
+
2. The manifest records the seed, parameters, Blender, Python (and NumPy) versions and the fingerprint per
|
|
328
|
+
variant.
|
|
329
|
+
3. `qa-check --profile game --objects <variant>` passes for each variant; the expected warnings are only the
|
|
330
|
+
ones you chose (tiling UV overlap, a deliberate sink).
|
|
331
|
+
4. Triangle counts sit inside the budget per LOD; `normal_deviation(LODn, LOD0)` mean stays a few degrees at
|
|
332
|
+
most.
|
|
333
|
+
5. Pivots at the bottom centre, sizes in metres within the parameter ranges (`size_m` in the manifest).
|
|
334
|
+
6. Materials shared by name across variants (one material list for the set).
|
|
335
|
+
7. A render through the game camera (`review-render`) at play distance: the set reads as one family, and no
|
|
336
|
+
two variants read as the same shape.
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
## Sources
|
|
341
|
+
|
|
342
|
+
- Runions, Lane and Prusinkiewicz, "Modeling Trees with a Space Colonization Algorithm", Eurographics
|
|
343
|
+
Workshop on Natural Phenomena 2007 — http://algorithmicbotany.org/papers/colonization.egwnp2007.html
|
|
344
|
+
- Prusinkiewicz and Lindenmayer, *The Algorithmic Beauty of Plants* (turtle interpretation, bracketed and
|
|
345
|
+
stochastic L-systems) — http://algorithmicbotany.org/papers/#abop ; overview:
|
|
346
|
+
https://en.wikipedia.org/wiki/L-system
|
|
347
|
+
- Python documentation, `random`: Notes on Reproducibility (only `random()` is guaranteed across versions) —
|
|
348
|
+
https://docs.python.org/3/library/random.html
|
|
349
|
+
- NumPy documentation, Random Generator and its compatibility policy —
|
|
350
|
+
https://numpy.org/doc/stable/reference/random/generator.html ,
|
|
351
|
+
https://numpy.org/doc/stable/reference/random/compatibility.html
|
|
352
|
+
- Blender Manual, Remesh and Displace modifiers —
|
|
353
|
+
https://docs.blender.org/manual/en/latest/modeling/modifiers/generate/remesh.html ,
|
|
354
|
+
https://docs.blender.org/manual/en/latest/modeling/modifiers/deform/displace.html
|
|
355
|
+
- Blender Python API, `bmesh.ops` (inset, convex hull, remove doubles) —
|
|
356
|
+
https://docs.blender.org/api/current/bmesh.ops.html
|
|
357
|
+
- Blender Studio, "Geometry Nodes from Scratch: Advanced Rock Scattering" —
|
|
358
|
+
https://studio.blender.org/training/geometry-nodes-from-scratch/example-advanced-rock-scattering/
|