|
| 1 | +--- |
| 2 | +name: engine-export-presets |
| 3 | +description: Unity, Godot, and Unreal glTF/FBX export presets. glTF uses export_yup; FBX uses axis_forward/axis_up plus centimeter scale. Targets 5.2 LTS with 4.5 LTS fallback. |
| 4 | +standards-version: 1.10.0 |
| 5 | +--- |
| 6 | + |
| 7 | +# Engine Export Presets |
| 8 | + |
| 9 | +## Trigger |
| 10 | + |
| 11 | +Use this skill when the user: |
| 12 | + |
| 13 | +- Needs a Unity, Godot, or Unreal export from Blender Python |
| 14 | +- Mentions Y-up, Z-up, centimeter scale, `export_yup`, `axis_forward`, or `axis_up` |
| 15 | +- Is about to pass FBX axis kwargs to `bpy.ops.export_scene.gltf` |
| 16 | +- Wants a headless preset the later `ai-asset-pipeline-template` can call |
| 17 | + |
| 18 | +This skill is the export layer. It composes `ai-mesh-cleanup` (apply transforms, units), `depsgraph-and-evaluated-data` (`export_apply` ships evaluated mesh), and the `unapplied-scale-gltf` witness (`export_apply` does not bake object scale). It does not generate meshes. |
| 19 | + |
| 20 | +## The core misunderstanding |
| 21 | + |
| 22 | +glTF and FBX do not share axis RNA. `bpy.ops.export_scene.gltf` has `export_yup` (boolean, "+Y Up"). It does not have `axis_forward` or `axis_up`. `bpy.ops.export_scene.fbx` has `axis_forward` and `axis_up` (axis enums) and `global_scale`. It does not have `export_yup`. Passing the other exporter's kwargs is a TypeError or a silent no-op depending on how the call is built. |
| 23 | + |
| 24 | +That split is the contract. Verified on current RNA: |
| 25 | + |
| 26 | +- glTF: https://docs.blender.org/api/current/bpy.ops.export_scene.html#bpy.ops.export_scene.gltf (`export_yup`, no axis enums) |
| 27 | +- FBX: https://docs.blender.org/api/current/bpy.ops.export_scene.html#bpy.ops.export_scene.fbx (`axis_forward`, `axis_up`, `global_scale`) |
| 28 | + |
| 29 | +## Shared prelude |
| 30 | + |
| 31 | +Before any preset: meters in the scene (`scale_length == 1.0`), identity object scale via `transform_apply` through `temp_override`, `export_apply=True` / `use_mesh_modifiers=True` so modifiers ship. See `ai-mesh-cleanup` and `unapplied-scale-gltf`. |
| 32 | + |
| 33 | +```python |
| 34 | +def apply_selected_mesh_transforms(): |
| 35 | + for obj in list(bpy.context.selected_objects): |
| 36 | + if obj.type != "MESH": |
| 37 | + continue |
| 38 | + with bpy.context.temp_override( |
| 39 | + object=obj, active_object=obj, selected_objects=[obj] |
| 40 | + ): |
| 41 | + bpy.ops.object.transform_apply( |
| 42 | + location=False, rotation=True, scale=True |
| 43 | + ) |
| 44 | +``` |
| 45 | + |
| 46 | +`use_selection=True` on every preset. Draco is opt-in on glTF; do not copy `gltf_draco_export.py` wholesale. |
| 47 | + |
| 48 | +## Unity (Y-up, meters, glTF) |
| 49 | + |
| 50 | +```python |
| 51 | +bpy.ops.export_scene.gltf( |
| 52 | + filepath=path, |
| 53 | + use_selection=True, |
| 54 | + export_yup=True, |
| 55 | + export_apply=True, |
| 56 | + export_draco_mesh_compression_enable=draco, |
| 57 | + export_animations=False, |
| 58 | +) |
| 59 | +``` |
| 60 | + |
| 61 | +`export_yup=True` bakes `(x, y, z) -> (x, z, -y)` into POSITION with no node rotation. Witness: `examples/gltf-export-roundtrip/` and `examples/export-preset-axis/`. |
| 62 | + |
| 63 | +Snippet: `snippets/export_preset_unity.py`. |
| 64 | + |
| 65 | +## Godot (Z-up glTF, meters) |
| 66 | + |
| 67 | +```python |
| 68 | +bpy.ops.export_scene.gltf( |
| 69 | + filepath=path, |
| 70 | + use_selection=True, |
| 71 | + export_yup=False, |
| 72 | + export_apply=True, |
| 73 | + export_draco_mesh_compression_enable=draco, |
| 74 | + export_animations=False, |
| 75 | +) |
| 76 | +``` |
| 77 | + |
| 78 | +`export_yup=False` writes Blender Z-up POSITION. This preset is the Z-up interop path. It is not the Unity kwargs; if both used `export_yup=True` the files would match and the axis contract would be untestable. |
| 79 | + |
| 80 | +Snippet: `snippets/export_preset_godot.py`. |
| 81 | + |
| 82 | +## Unreal (centimeters) |
| 83 | + |
| 84 | +glTF has no `global_scale`. Bake 100x (1 m -> 100 cm) onto the selected meshes, apply, then `export_yup=True`. That mutates the objects; copy first if the source must stay in meters. |
| 85 | + |
| 86 | +FBX keeps the meter mesh and scales on the way out: |
| 87 | + |
| 88 | +```python |
| 89 | +bpy.ops.export_scene.fbx( |
| 90 | + filepath=path, |
| 91 | + use_selection=True, |
| 92 | + axis_forward="-Z", |
| 93 | + axis_up="Y", |
| 94 | + global_scale=100.0, |
| 95 | + apply_unit_scale=False, |
| 96 | + use_mesh_modifiers=True, |
| 97 | + bake_anim=False, |
| 98 | +) |
| 99 | +``` |
| 100 | + |
| 101 | +Do not pass `export_yup` to FBX. Do not pass `axis_forward` to glTF. |
| 102 | + |
| 103 | +Snippet: `snippets/export_preset_unreal.py`. |
| 104 | + |
| 105 | +## Common AI mistakes |
| 106 | + |
| 107 | +1. **`export_scene.gltf(..., axis_forward="-Z", axis_up="Y")`.** Those names are FBX. Rule `use-correct-axis-rna-per-exporter`. |
| 108 | +2. **`export_scene.fbx(..., export_yup=True)`.** Same rule, other direction. |
| 109 | +3. **Skipping `transform_apply`.** `export_apply` is modifiers, not object scale. `examples/unapplied-scale-gltf/`. |
| 110 | +4. **Unity and Godot as the same kwargs.** They differ on `export_yup`. `examples/export-preset-axis/` asserts the re-imported orientations diverge. |
| 111 | +5. **Unreal glTF without the 100x bake.** glTF has no `global_scale`. |
| 112 | + |
| 113 | +## Version correctness |
| 114 | + |
| 115 | +Probed on 4.5 LTS, 5.1, and 5.2: `export_yup` on glTF and `axis_forward` / `axis_up` / `global_scale` on FBX are present on all three. No version branch for the axis kwargs. Guard by requiring those names in operator RNA so a future rename fails loudly, as `examples/gltf-export-roundtrip/` does. |
| 116 | + |
| 117 | +`export_format` defaults differ by call site; pass the filepath suffix (`.glb` / `.gltf` / `.fbx`) and let the operator infer, or set `export_format` explicitly on glTF. |
| 118 | + |
| 119 | +## Related |
| 120 | + |
| 121 | +- Skill `ai-mesh-cleanup` |
| 122 | +- Skill `depsgraph-and-evaluated-data` |
| 123 | +- Rule `use-correct-axis-rna-per-exporter` |
| 124 | +- Rule `no-unapplied-modifiers-on-export` |
| 125 | +- Rule `validate-imported-mesh-scale` |
| 126 | +- Snippet `snippets/export_preset_unity.py` |
| 127 | +- Snippet `snippets/export_preset_godot.py` |
| 128 | +- Snippet `snippets/export_preset_unreal.py` |
| 129 | +- Snippet `snippets/gltf_draco_export.py` |
| 130 | +- Example `export-preset-axis` |
| 131 | +- Example `gltf-export-roundtrip` |
| 132 | +- Example `unapplied-scale-gltf` |
| 133 | + |
| 134 | +## References |
| 135 | + |
| 136 | +- `bpy.ops.export_scene.gltf`: https://docs.blender.org/api/current/bpy.ops.export_scene.html#bpy.ops.export_scene.gltf |
| 137 | +- `bpy.ops.export_scene.fbx`: https://docs.blender.org/api/current/bpy.ops.export_scene.html#bpy.ops.export_scene.fbx |
| 138 | +- glTF 5.1: https://docs.blender.org/api/5.1/bpy.ops.export_scene.html#bpy.ops.export_scene.gltf |
| 139 | +- FBX 5.1: https://docs.blender.org/api/5.1/bpy.ops.export_scene.html#bpy.ops.export_scene.fbx |
0 commit comments