@babylonjs-toolkit/agent 1.2.16 → 1.2.21
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 +448 -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 +724 -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 +637 -0
- package/skills/bt-blender/scripts/blender/__pycache__/construction_kit.cpython-313.pyc +0 -0
- package/skills/bt-blender/scripts/blender/__pycache__/geometry_nodes_builders.cpython-313.pyc +0 -0
- package/skills/bt-blender/scripts/blender/__pycache__/image_measure.cpython-313.pyc +0 -0
- package/skills/bt-blender/scripts/blender/__pycache__/reference_traces.cpython-313.pyc +0 -0
- package/skills/bt-blender/scripts/blender/assembly_check.py +420 -0
- package/skills/bt-blender/scripts/blender/blueprint.py +293 -0
- package/skills/bt-blender/scripts/blender/character_blockout.py +462 -0
- package/skills/bt-blender/scripts/blender/construction_kit.py +1770 -0
- package/skills/bt-blender/scripts/blender/coverage_check.py +221 -0
- package/skills/bt-blender/scripts/blender/environment_kit.py +525 -0
- package/skills/bt-blender/scripts/blender/evidence_sheet.py +243 -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 +917 -0
- package/skills/bt-blender/scripts/blender/materials_pbr.py +439 -0
- package/skills/bt-blender/scripts/blender/measure_stations.py +496 -0
- package/skills/bt-blender/scripts/blender/ortho_views.py +309 -0
- package/skills/bt-blender/scripts/blender/overlay_sheet.py +238 -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/reference_traces.py +344 -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/trace.py +283 -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 +231 -0
- package/skills/bt-blender/scripts/bt-blender.mjs +333 -0
- package/skills/bt-blender/scripts/validate_gltf.mjs +204 -0
- package/skills/bt-execute/SKILL.md +2 -1
- package/skills/bt-gauntlet/SKILL.md +30 -20
- package/skills/bt-gauntlet/references/critic-rubrics.md +106 -7
- package/skills/bt-gauntlet/references/loop-templates.md +23 -3
- package/skills/bt-gauntlet/references/spec-composition.md +20 -1
- package/skills/bt-gauntlet/references/target-images.md +27 -0
- package/skills/bt-gauntlet/references/unity-pipeline.md +41 -4
- package/skills/bt-gauntlet/references/workspace.md +90 -6
- 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,284 @@
|
|
|
1
|
+
# Game-engine export: FBX for Unity, glTF for BabylonJS, LODs, collision and validation
|
|
2
|
+
|
|
3
|
+
**Load this when** a Blender asset leaves Blender for an engine:
|
|
4
|
+
- an FBX going into a Unity project, new or replaced in place;
|
|
5
|
+
- a GLB going straight to BabylonJS;
|
|
6
|
+
- an LOD set;
|
|
7
|
+
- collision proxies;
|
|
8
|
+
- compressed geometry or textures;
|
|
9
|
+
- a file that loads wrong in the engine (rotated, scaled, missing parts, dark, flat-shaded, too many draws).
|
|
10
|
+
|
|
11
|
+
**What it assumes.** The Agent Reference's Blender guide (`references/unity-blender-cli.md`) covers the
|
|
12
|
+
baseline, and this file goes deeper without repeating it:
|
|
13
|
+
- §3: which import and export operators exist;
|
|
14
|
+
- §7.1: the 5.3 glTF option renames;
|
|
15
|
+
- §8.1–8.3: in-place vs new models, importer settings carried across;
|
|
16
|
+
- §8.2a: the Unity FBX preset, the `bake_space_transform` table by case, the FBX root-transform check and leaf
|
|
17
|
+
bones;
|
|
18
|
+
- §8.4a: packed float images shipping too dark;
|
|
19
|
+
- §8.5: components come only from Unity.
|
|
20
|
+
|
|
21
|
+
Sibling references:
|
|
22
|
+
- the skill's `SKILL.md` §7: the `export` tool;
|
|
23
|
+
- `environments.md` §7 (collision in a Unity level) and §9 (draw calls and instancing);
|
|
24
|
+
- `uv-and-pbr-materials.md` (UV2, texture sets);
|
|
25
|
+
- `geometry-nodes.md` §6 (instances).
|
|
26
|
+
|
|
27
|
+
**Helpers.**
|
|
28
|
+
- The `export` and `validate-gltf` tools.
|
|
29
|
+
- `scripts/blender/procedural_game_ready.py`: `lod_chain`, `normal_deviation`, `convex_hull_collider`,
|
|
30
|
+
`box_collider`, `triangle_count`.
|
|
31
|
+
- `scripts/blender/geometry_nodes_builders.py`: `realize_to_mesh`, `instances_to_objects`.
|
|
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. Choose the route
|
|
38
|
+
|
|
39
|
+
| The asset needs | Route | Why |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| Unity components (Rigidbody, colliders, Animator, scripts, audio), baked lightmaps, light probes, LOD Groups with screen coverages | **Blender -> FBX -> Unity -> Toolkit -> glTF** | Only Unity adds `extras.metadata.components` (§8.5); the Toolkit carries LOD Groups and physics under a Pro licence (`unity-authoring-recipes.md` §11, §17) |
|
|
42
|
+
| Geometry, materials, skinning or animation only (a prop, a scatter set, a clip) | **Blender -> GLB -> BabylonJS** | One step, no licence; LODs and physics are then set up in code (sections 4–5) |
|
|
43
|
+
| A model that already lives in the Unity project | **In place**: same path, same names (§8.1–8.2) | Keeps the GUID, the importer settings and every scene reference |
|
|
44
|
+
|
|
45
|
+
**FBX settings per case** (the preset is §8.2a's; these are the choices on top):
|
|
46
|
+
|
|
47
|
+
| Case | `bake_space_transform` | `mesh_smooth_type` | `use_tspace` | `bake_anim` | Notes |
|
|
48
|
+
|---|---|---|---|---|---|
|
|
49
|
+
| New static mesh authored in Blender | `True` | `OFF` (normals only) | off | off | Root at 0°. The skill's `export` tool does exactly this |
|
|
50
|
+
| New rigged or animated asset | **`False`** | `OFF` | off | on | Baking is broken for rigs (§8.2a). The `export` tool always bakes, so call `bpy.ops.export_scene.fbx` yourself for rigs |
|
|
51
|
+
| An FBX from the Unity project, edited in place | **`False`** | `OFF` | off | as the source | Check root transforms against the backup (§8.2a) before overwriting |
|
|
52
|
+
| An LOD set (`<Name>_LOD0..n`) | as the case above | `OFF` | off | off | Unity builds the LOD Group from the names (section 4) |
|
|
53
|
+
| A mesh with a baked tangent-space normal map | as above | `OFF` | optional | — | Unity recalculates tangents (MikkTSpace) by default, matching Blender's bake; triangulate before the bake so both see the same triangles |
|
|
54
|
+
|
|
55
|
+
`mesh_smooth_type='OFF'` writes the corner normals as they are, custom normals included. Measured: an LOD set
|
|
56
|
+
exported to FBX and re-imported deviated from the source normals by under 0.001° on average, 0.016° at most.
|
|
57
|
+
`'FACE'` or `'EDGE'` instead write smoothing groups, which Unity turns back into normals of its own.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 2. glTF / GLB for BabylonJS on 5.3
|
|
62
|
+
|
|
63
|
+
| Option | Set | Why (measured on 5.3.0 where marked) |
|
|
64
|
+
|---|---|---|
|
|
65
|
+
| `export_apply` | `True` | Modifiers applied. Geometry Nodes **instances are dropped** unless realised or converted (`geometry-nodes.md` §6) |
|
|
66
|
+
| `export_yup` | `True` | glTF is +Y up; Blender's -Y forward becomes glTF +Z forward, the spec's front. BabylonJS's loader adds a `__root__` node that converts to its left-handed system |
|
|
67
|
+
| `export_tangents` | `True` with any normal map | Default **False**. Without tangents the engine derives its own, which may not match the bake's MikkTSpace. The `export` tool writes them by default (`--tangents on`; `auto` = only with a normal map, `off`): +22 to +47 % file size measured |
|
|
68
|
+
| `export_image_format` | `AUTO` (PNG/JPEG as the source), or `WEBP` for size | Measured on a 512 px crate set: PNG 339 KB; WebP quality 90 39 KB, written with `EXT_texture_webp` in `extensionsRequired` (no fallback) |
|
|
69
|
+
| `export_image_add_compressed_images` + `export_compressed_images_type='KTX2'` | Only when GPU memory matters more than download | Measured: a PNG fallback was written with every KTX2 image, even with `export_compressed_images_fallback=False`: 877 KB (527 KB with `export_use_ktx_compression` zstd) vs 339 KB PNG alone. For KTX2-only files, export through the Toolkit (`TextureImageFormat` 3) or post-process with a glTF tool |
|
|
70
|
+
| `export_draco_mesh_compression_enable` | For heavy geometry | Measured on a 7,320-face realised scatter: 726 KB -> 113 KB (level 6), 109 KB (level 10). `KHR_draco_mesh_compression` is required; BabylonJS needs its Draco decoder. `export --draco [LEVEL]` (default 6) |
|
|
71
|
+
| `export_meshopt_compression_enable` + `export_meshopt_extension='EXT_meshopt_compression'` | Alternative to Draco: decodes faster, compresses less | Measured: 726 KB -> 258 KB. BabylonJS's loader lists `EXT_meshopt_compression`, **not** the `KHR_` variant. `export --meshopt`; its positions are quantised (2.2 mm on a 10 m piece), which the tool's round trip allows for |
|
|
72
|
+
| `export_gpu_instances` | `True` for scatter shipped as linked duplicates | `EXT_mesh_gpu_instancing` -> BabylonJS thin instances (`geometry-nodes.md` §6). `export --gpu-instances` converts Geometry Nodes instances and sets it; `--realize` bakes them into the mesh instead; with neither, the tool fails an object whose instances would be dropped |
|
|
73
|
+
| `export_animation_mode` | `ACTIONS` (one glTF animation per action) or `NLA_TRACKS` | Each glTF animation becomes one BabylonJS `AnimationGroup`; name actions as the game will call them |
|
|
74
|
+
| `export_influence_nb` | 4 | BabylonJS and the guide's §4.4 rules: ≤ 4 influences, normalised |
|
|
75
|
+
| `export_extras` | `True` to carry custom properties | Node extras reach BabylonJS as `metadata.gltf.extras` |
|
|
76
|
+
| `export_attributes` | `True` for custom vertex attributes | Only attributes whose names start with `_` are exported |
|
|
77
|
+
| `use_selection` / `use_visible` | Select exactly what ships | Unselected helper objects (variant sources, profiles) otherwise come along |
|
|
78
|
+
|
|
79
|
+
Every extension written was checked with the Khronos validator: 0 errors. The validator reports
|
|
80
|
+
`UNSUPPORTED_EXTENSION` as an info for Draco, meshopt and basisu (it cannot decode them), which is expected.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## 3. Names, pivots, units
|
|
85
|
+
|
|
86
|
+
| Rule | Why |
|
|
87
|
+
|---|---|
|
|
88
|
+
| Object names are the node names; mesh data names the glTF mesh names and Unity's sub-asset names | Code finds nodes by name; Unity references mesh sub-assets by name |
|
|
89
|
+
| No `.001` suffixes | Blender adds them on a clash; a renamed mesh breaks Unity references even with the same GUID (§8.2a) |
|
|
90
|
+
| Origin where the object is placed or pivots: bottom centre for props, the hinge for doors, the wheel centre for wheels | Engines rotate and place about the origin |
|
|
91
|
+
| Metres, scale applied (1, 1, 1), rotation applied for static meshes | Non-uniform scale on a normal-mapped mesh breaks its tangent frame; the Toolkit warns against it |
|
|
92
|
+
| -Y forward, +Z up in Blender | Becomes +Z forward, +Y up in glTF, and the FBX preset lands it at 0° in Unity |
|
|
93
|
+
| Helpers prefixed and excluded: `UCX_`/`UBX_` collision, `_LOD<n>` levels, no stray cameras or lights | Loaders and importers key on these names |
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## 4. LODs
|
|
98
|
+
|
|
99
|
+
`lod_chain(obj, ratios=(0.5, 0.25))`:
|
|
100
|
+
- applies the object's modifiers;
|
|
101
|
+
- renames it `<Name>_LOD0`;
|
|
102
|
+
- adds `<Name>_LOD1..n` by collapse decimation to the triangle ratios;
|
|
103
|
+
- parents the set to an Empty `<Name>`.
|
|
104
|
+
|
|
105
|
+
**Each level gets LOD0's shading by a Data Transfer of custom normals** (`POLYINTERP_NEAREST`: interpolated
|
|
106
|
+
from the nearest LOD0 face). A plain decimate re-smooths the coarser faces, so the light jumps when the level
|
|
107
|
+
switches. The normal layer survives decimation; what goes wrong is the values (the guide's §8 table measured
|
|
108
|
+
30.5° growing to 43.8°).
|
|
109
|
+
|
|
110
|
+
`normal_deviation(lod, lod0)` measures it per corner. Both meshes' shading normals are interpolated at the
|
|
111
|
+
same nudged surface point, so a mesh against itself gives exactly 0.
|
|
112
|
+
|
|
113
|
+
| Asset (measured on 5.3.0) | Level | Plain decimate, mean / p95 | LOD0 normals transferred, mean / p95 |
|
|
114
|
+
|---|---|---|---|
|
|
115
|
+
| Bevelled canister, weighted normals, 764 tris | LOD1 (382) | 9.6° / 30.5° | 7.0° / 29.5° |
|
|
116
|
+
| | LOD2 (190) | 19.8° / 36.5° | 3.0° / 14.1° |
|
|
117
|
+
| Rock, 3,000 tris | LOD1 | 1.10° / 2.81° | 0.53° / 1.32° |
|
|
118
|
+
| | LOD2 | 1.85° / 4.68° | 0.87° / 2.17° |
|
|
119
|
+
|
|
120
|
+
Of the mappings tried, `POLYINTERP_NEAREST` beat `POLYINTERP_LNORPROJ` and `NEAREST_POLYNOR` on both assets.
|
|
121
|
+
Exported and re-imported, the levels kept their normals: GLB mean 0.003°, max 0.021°; FBX mean under 0.001°, max 0.016°.
|
|
122
|
+
|
|
123
|
+
**Where each engine gets its LODs**
|
|
124
|
+
|
|
125
|
+
| Engine | How | Notes |
|
|
126
|
+
|---|---|---|
|
|
127
|
+
| Unity (FBX import) | Meshes named `<Name>_LOD0`, `_LOD1`, … in one file: the importer builds an LOD Group on the root automatically | Up to 8 levels; set the transition heights on the importer or the LOD Group |
|
|
128
|
+
| BabylonJS through the Toolkit | The Unity LOD Group is exported with its screen coverages (Pro) | `unity-authoring-recipes.md` §17; instances follow their source mesh's LOD |
|
|
129
|
+
| BabylonJS from a Blender GLB | No standard LOD in glTF from Blender (the loader reads `MSFT_lod`, which Blender does not write). Load the levels and call `lod0.addLODLevel(distance, lodN)`, or use screen coverage with `useLODScreenCoverage` | Hide LOD1..n themselves; `addLODLevel(distance, null)` culls beyond the last level |
|
|
130
|
+
|
|
131
|
+
Ratios: halve the triangles per level (0.5, 0.25, 0.125). Stop when the silhouette breaks at the distance the
|
|
132
|
+
level is used. Skip LODs on meshes under ~300 triangles; switching costs more than it saves.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## 5. Collision proxies
|
|
137
|
+
|
|
138
|
+
**BabylonJS Physics V2 (Havok) shapes, cheapest first:**
|
|
139
|
+
|
|
140
|
+
| Shape | Use for | From Blender |
|
|
141
|
+
|---|---|---|
|
|
142
|
+
| Sphere, Capsule, Cylinder, Box | Anything a primitive covers: crates, walls, characters, barrels | `box_collider(obj)` -> `UBX_<Name>_00` (its size); or just the size in metadata |
|
|
143
|
+
| ConvexHull | Rocks, props, vehicles' main volume (dynamic bodies allowed) | `convex_hull_collider(obj, max_vertices=64)` -> `UCX_<Name>_NN`; the shape builds its own hull, so the proxy only needs to be the right volume |
|
|
144
|
+
| Container (compound) | A concave object made of convex parts | One hull per loose part (`per_part=True`), each added to a container |
|
|
145
|
+
| Mesh | Static, concave level geometry (a track, a terrain piece) | The render mesh or a simplified copy; **static only** |
|
|
146
|
+
| HeightField | Terrain from a height grid | Unity Terrain through the Toolkit |
|
|
147
|
+
|
|
148
|
+
- **Hull budget.** Unity's convex MeshCollider allows at most 255 triangles, and a hull of V vertices has
|
|
149
|
+
2V - 4 triangles, so stay at or under 129 vertices. `convex_hull_collider` refuses more than that, and reduces
|
|
150
|
+
a bigger hull by farthest-point sampling of its own vertices, which keeps the extremes. Measured: a
|
|
151
|
+
1,200-triangle rock gave a 64-vertex, 124-triangle hull at the default budget. A building block gave four
|
|
152
|
+
8-vertex hulls, one per loose part (the shell and each roof unit).
|
|
153
|
+
- **A hull fills every concavity.** An L-shaped piece needs two boxes, not one hull (`environments.md` §7
|
|
154
|
+
measures how much the hull blocks).
|
|
155
|
+
- **Shipping.** In the Unity route, put colliders on the prefab (Box / Capsule / convex Mesh Collider); the
|
|
156
|
+
Toolkit exports a convex MeshCollider as a convex hull and a non-convex one only for static bodies.
|
|
157
|
+
In the direct route, export the `UCX_`/`UBX_` objects with the asset (no material, no UVs). At load time,
|
|
158
|
+
build a `PhysicsShapeConvexHull` or `PhysicsShapeBox` from each and set `isVisible = false`.
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Recipe: an LOD set with hulls, shipped as FBX for Unity and as GLB for BabylonJS
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
# recipe: ship-lods
|
|
166
|
+
import json, os, sys
|
|
167
|
+
import bpy
|
|
168
|
+
import construction_kit as kit
|
|
169
|
+
import procedural_game_ready as game_ready
|
|
170
|
+
import procedural_generators as procedural
|
|
171
|
+
|
|
172
|
+
out = sys.argv[sys.argv.index("--") + 1]
|
|
173
|
+
kit.clear_default_scene()
|
|
174
|
+
rock = procedural.rock("Boulder", seed=3, size=(2.0, 1.6, 1.2), target_triangles=3000)
|
|
175
|
+
hulls = game_ready.convex_hull_collider(rock, max_vertices=64)
|
|
176
|
+
levels = game_ready.lod_chain(rock, ratios=(0.5, 0.25))
|
|
177
|
+
report = {"triangles": [game_ready.triangle_count(level) for level in levels],
|
|
178
|
+
"deviation": [game_ready.normal_deviation(level, levels[0])["mean"] for level in levels[1:]],
|
|
179
|
+
"hulls": [(hull.name, len(hull.data.vertices)) for hull in hulls]}
|
|
180
|
+
bpy.ops.wm.save_as_mainfile(filepath=os.path.join(out, "boulder.blend"))
|
|
181
|
+
|
|
182
|
+
def select(objects):
|
|
183
|
+
bpy.context.view_layer.update()
|
|
184
|
+
for obj in bpy.context.view_layer.objects:
|
|
185
|
+
obj.select_set(obj in objects)
|
|
186
|
+
|
|
187
|
+
shipped = [levels[0].parent, *levels, *hulls]
|
|
188
|
+
# Unity: a static mesh authored in Blender -> the §8.2a preset with the space transform baked.
|
|
189
|
+
select(shipped)
|
|
190
|
+
assert "FINISHED" in bpy.ops.export_scene.fbx(
|
|
191
|
+
filepath=os.path.join(out, "Boulder.fbx"), use_selection=True, axis_forward="-Z", axis_up="Y",
|
|
192
|
+
apply_scale_options="FBX_SCALE_UNITS", bake_space_transform=True, add_leaf_bones=False,
|
|
193
|
+
mesh_smooth_type="OFF", bake_anim=False)
|
|
194
|
+
# BabylonJS: GLB with Draco geometry (add export_tangents=True when a normal map is used); hide the hulls at load.
|
|
195
|
+
select(shipped)
|
|
196
|
+
assert "FINISHED" in bpy.ops.export_scene.gltf(
|
|
197
|
+
filepath=os.path.join(out, "Boulder.glb"), export_format="GLB", use_selection=True, export_apply=True,
|
|
198
|
+
export_yup=True, export_draco_mesh_compression_enable=True)
|
|
199
|
+
|
|
200
|
+
# Re-import the FBX: the LOD names Unity keys on must survive.
|
|
201
|
+
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
202
|
+
bpy.ops.import_scene.fbx(filepath=os.path.join(out, "Boulder.fbx"))
|
|
203
|
+
report["fbx_objects"] = sorted(obj.name for obj in bpy.data.objects)
|
|
204
|
+
print(json.dumps(report))
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Measured:
|
|
208
|
+
- triangles 3,000 / 1,500 / 750, LOD mean deviation 0.48° / 0.87°;
|
|
209
|
+
- one 64-vertex hull;
|
|
210
|
+
- the FBX re-imports as `Boulder`, `Boulder_LOD0`–`_LOD2` and `UCX_Boulder_00`;
|
|
211
|
+
- the GLB validates with 0 errors and 0 warnings (one `UNSUPPORTED_EXTENSION` info for Draco); 66.8 KB of
|
|
212
|
+
buffer for four meshes.
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## 6. Validate, then look
|
|
217
|
+
|
|
218
|
+
1. `export` runs the Khronos glTF-Validator after every glTF export (`--validator-dir`, or
|
|
219
|
+
`BT_GLTF_VALIDATOR_DIR`; install once with `npm install --prefix <folder> gltf-validator`). It fails on
|
|
220
|
+
any error. `validate-gltf <file>` checks a file on its own. Infos such as `UNSUPPORTED_EXTENSION` for Draco,
|
|
221
|
+
meshopt or basisu are expected.
|
|
222
|
+
2. Read the export summary:
|
|
223
|
+
- triangles (with every instance and LOD level counted as you expect);
|
|
224
|
+
- nodes and materials (one per slot);
|
|
225
|
+
- `TANGENT` when a normal map is used, `TEXCOORD_1` for a lightmap UV;
|
|
226
|
+
- the extensions in `extensions_used`.
|
|
227
|
+
3. The round-trip size check (`export` re-imports and compares world sizes) catches unit and axis mistakes. It
|
|
228
|
+
does **not** catch missing instances inside the bounds, or a missing LOD level.
|
|
229
|
+
4. Load the file in the engine and look through the game camera: orientation, scale against a known object,
|
|
230
|
+
shading at LOD switches, draw calls per pass (`bt-optimize` / the Babylon inspector).
|
|
231
|
+
|
|
232
|
+
**Pre-export checklist**
|
|
233
|
+
|
|
234
|
+
- [ ] Names: no `.001`; LODs `_LOD0..n`; helpers `UCX_`/`UBX_`; mesh data named like its object.
|
|
235
|
+
- [ ] Transforms applied (scale 1, rotation 0 for static meshes); origin at the placement pivot; metres.
|
|
236
|
+
- [ ] No Geometry Nodes instances left unrealised or unconverted (`instance_count` is 0, or they were
|
|
237
|
+
converted to linked duplicates on purpose).
|
|
238
|
+
- [ ] Materials: 1–2 per asset, single-sided for closed meshes, no unused slots, images saved to files (8-bit
|
|
239
|
+
sRGB for colour), colour spaces right.
|
|
240
|
+
- [ ] UV0 present; UV2 present and clean if lightmapped.
|
|
241
|
+
- [ ] Normals: custom normals intended? `mesh_smooth_type='OFF'` for FBX; `normal_deviation` per LOD.
|
|
242
|
+
- [ ] Skinned: ≤ 4 influences, normalised, `add_leaf_bones=False`, `bake_space_transform=False`.
|
|
243
|
+
- [ ] Settings per section 1 (FBX) or section 2 (glTF); validator 0 errors; summary as expected.
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## 7. Pitfalls
|
|
248
|
+
|
|
249
|
+
| Symptom in the engine | Cause | Fix |
|
|
250
|
+
|---|---|---|
|
|
251
|
+
| Scattered objects missing | Geometry Nodes instances dropped by export (no exporter warning; a size round trip passes) | `realize_to_mesh` or `instances_to_objects` before exporting; the `export` tool fails them without `--realize` / `--gpu-instances` |
|
|
252
|
+
| Unity: rig rotated or meshes +90° X after an in-place edit | `bake_space_transform=True` on a rig or a Unity-sourced file | Per-case table (section 1, §8.2a). The `export` tool follows it: True only for a static Blender mesh; rigs get the rig preset, animated objects bake their animation, and `--source unity` never bakes |
|
|
253
|
+
| LOD levels pop in light | Decimated levels re-smoothed | `lod_chain` (normals transferred); check `normal_deviation` |
|
|
254
|
+
| No LOD Group in Unity | Names not `_LOD<n>`, or levels in different files | One FBX, suffixed names |
|
|
255
|
+
| Normal-mapped asset shaded wrong in BabylonJS | No tangents exported (default off) | `export_tangents=True` (the `export` tool writes them by default) |
|
|
256
|
+
| GLB will not load: unsupported extension | Draco, meshopt or WebP required but the decoder or format is not there; or `KHR_meshopt_compression` used | Register Babylon's Draco / meshopt decoders; use `EXT_meshopt_compression`; keep PNG for very old browsers |
|
|
257
|
+
| KTX2 file bigger than the PNG one | Blender 5.3 writes a PNG fallback with every KTX2 image | WebP for download size; KTX2 via the Toolkit or a glTF post-process |
|
|
258
|
+
| Helper objects visible (hull, profile curve, variant source) | Exported without a selection | `use_selection=True` with an explicit list; hide `UCX_`/`UBX_` at load |
|
|
259
|
+
| `export` stops with `'NoneType' object has no attribute 'vertices'` | An exported curve or empty evaluates to no mesh (a 2D profile, an instance-only curve) | `--objects` with only mesh-producing objects, or convert first |
|
|
260
|
+
| Doubled draw calls | Double-sided materials, or one material slot per part | Single-sided closed meshes, shared materials (`uv-and-pbr-materials.md` §8) |
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## Sources
|
|
265
|
+
|
|
266
|
+
- Blender Manual, glTF 2.0 add-on (all export options: GPU instances, Geometry Nodes instances, tangents,
|
|
267
|
+
compression, images, animation modes, extras, attributes) —
|
|
268
|
+
https://docs.blender.org/manual/en/latest/addons/import_export/scene_gltf2.html
|
|
269
|
+
- Khronos, glTF 2.0 specification (units, +Y up, +Z front, tangents, materials) —
|
|
270
|
+
https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html
|
|
271
|
+
- Khronos glTF-Validator — https://github.com/KhronosGroup/glTF-Validator
|
|
272
|
+
- Unity Manual, configuring an LOD Group, with LOD meshes imported by the `_LOD<n>` naming convention —
|
|
273
|
+
https://docs.unity.com/en-us/engine/6000.6/manual/analysis/graphics-performance-profiling/lod/lod-group/lod-group-configure
|
|
274
|
+
- Babylon.js documentation, Levels of Detail (`addLODLevel`, screen coverage, instances) —
|
|
275
|
+
https://doc.babylonjs.com/features/featuresDeepDive/mesh/LOD/
|
|
276
|
+
- Babylon.js documentation, Physics V2 shapes (convex hull, mesh static-only, container, cost order) —
|
|
277
|
+
https://doc.babylonjs.com/features/featuresDeepDive/physics/shapes/
|
|
278
|
+
- Babylon.js glTF loader extensions (EXT_meshopt_compression, KHR_draco_mesh_compression, KHR_texture_basisu,
|
|
279
|
+
EXT_texture_webp, EXT_mesh_gpu_instancing, MSFT_lod) —
|
|
280
|
+
https://github.com/BabylonJS/Babylon.js/tree/master/packages/dev/loaders/src/glTF/2.0/Extensions
|
|
281
|
+
- Epic Games, FBX Static Mesh Pipeline (UCX_/UBX_ collision naming, LOD import) —
|
|
282
|
+
https://docs.unrealengine.com/4.27/en-US/WorkingWithContent/Importing/FBX/StaticMeshes/
|
|
283
|
+
- EL4CTEO/blender-skills (MIT, © 2026 EL4CTEO): its LOD script's overclaim (a plain decimate that drops the
|
|
284
|
+
custom normals) is the case the normal transfer and the deviation measure here answer; no code taken.
|