@@ -30,15 +30,35 @@ directly.
3030 ```
3131 (glTF branch: ` bpy.ops.export_scene.gltf(filepath=out_glb, export_format='GLB') ` .)
32323 . ** 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 = 2 f ; // intended size in meters
50+ if (maxDim > 0 . 0001 f ) go .transform .localScale *= target / maxDim ;
51+ ```
38525 . ** 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.
0 commit comments