Skip to content

Commit e243e30

Browse files
committed
feat(asset-gen): blender-to-unity skill — deterministic scale normalization + scale note
Blender FBX imports ~100x oversized; import_model_file target_size only acts when Auto-normalize is on and is unreliable for Blender FBX (target_size=2 measured 200m in a live test). Step 4 now measures the placed model's world bounds and sets localScale to hit the target size deterministically. Adds a Scale note + checklist item. Claude-Session: https://claude.ai/code/session_01NoHk4f7N1vUFs7gu817ihm
1 parent 125c97d commit e243e30

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

.claude/skills/blender-to-unity/SKILL.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,35 @@ directly.
3030
```
3131
(glTF branch: `bpy.ops.export_scene.gltf(filepath=out_glb, export_format='GLB')`.)
3232
3. **Import into Unity** with `import_model_file`:
33-
`import_model_file(source_path=<temp path>, name=<asset name>, target_size=<meters, optional>)`.
34-
It returns `{ asset_path, asset_guid }`.
35-
4. **Place it in the scene.** Ensure the scene has a camera + directional light
36-
(`manage_scene` / `manage_gameobject`). Instantiate the imported model into the open scene
37-
at the chosen position via `manage_gameobject(action="create", prefab_path=<asset_path>, ...)`.
33+
`import_model_file(source_path=<temp path>, name=<asset name>, target_size=<final size in meters>)`.
34+
It returns `{ asset_path, asset_guid }`. Pass `target_size` as the intended final size, but treat
35+
it only as a hint: it rescales at import solely when the project's **Auto-normalize** pref is on,
36+
and even then is unreliable for Blender FBX (see the **Scale** note). Step 4 does the reliable
37+
normalization.
38+
4. **Place it in the scene, normalized to size.** Ensure the scene has a camera + directional
39+
light (`manage_scene` / `manage_gameobject`). Instantiate the model at the chosen position via
40+
`manage_gameobject(action="create", prefab_path=<asset_path>, name=<asset name>, position=[x,y,z])`.
41+
Then normalize its size deterministically — Blender FBX commonly imports ~100× too large — by
42+
measuring the placed model's world bounds and scaling so its largest dimension equals your target
43+
size. Run via `execute_code` (substitute your object name and target meters):
44+
```csharp
45+
var go = GameObject.Find("<asset name>");
46+
var rs = go.GetComponentsInChildren<Renderer>();
47+
var b = rs[0].bounds; for (int i = 1; i < rs.Length; i++) b.Encapsulate(rs[i].bounds);
48+
float maxDim = Mathf.Max(b.size.x, Mathf.Max(b.size.y, b.size.z));
49+
float target = 2f; // intended size in meters
50+
if (maxDim > 0.0001f) go.transform.localScale *= target / maxDim;
51+
```
3852
5. **Verify** with `manage_camera(action="screenshot", include_image=true)` and report the
3953
asset path + a screenshot.
4054

4155
## Notes
56+
- **Scale.** Models from Blender almost always arrive at the wrong scale — its FBX unit handling
57+
makes them land ~100× too large in Unity. `import_model_file`'s `target_size` only rescales at
58+
import when the project's Auto-normalize pref is enabled, and its importer-level normalization is
59+
unreliable for Blender FBX (it can over- or under-shoot, e.g. a `target_size=2` model measured 200 m).
60+
The robust fix is the Step 4 measure-bounds-then-set-`localScale` routine, which hits the target
61+
size deterministically regardless of the import scale or the Auto-normalize pref.
4262
- FBX is the default because glTFast is optional in MCP for Unity. If the import errors with
4363
"GLB import requires glTFast", re-export as FBX (or install glTFast from the Dependencies tab).
4464
- Keep one model per handoff; for batches, repeat the loop with distinct names.

.claude/skills/blender-to-unity/manual-verify.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Run against a live Blender (BlenderMCP) + Unity (MCP for Unity) pair.
77
- [ ] `import_model_file` returns `success: true` with `asset_path` under `Assets/` and a non-empty `asset_guid`.
88
- [ ] The imported model appears in the Project window at `asset_path`.
99
- [ ] The model is instantiated in the open scene and visible in a `manage_camera` screenshot.
10+
- [ ] Scale: after the Step 4 measure-bounds-then-`localScale` routine, the placed model's largest
11+
world dimension ≈ the target size (Blender FBX imports ~100× too large until normalized).
1012
- [ ] glTF path: with glTFast installed, a `.glb` export imports successfully; without it,
1113
the error names glTFast/the Dependencies tab (and FBX still works).
1214
- [ ] No API keys or file bytes appear in any bridge payload (handoff is filesystem-only).

0 commit comments

Comments
 (0)