Skip to content

Commit bf8c26c

Browse files
feat: add engine-export-presets skill and Unity/Godot/Unreal snippets
glTF axis is export_yup; FBX is axis_forward/axis_up plus centimeter scale. The presets compose ai-mesh-cleanup and depsgraph-and-evaluated-data instead of restating them. Signed-off-by: TMHSDigital <154358121+TMHSDigital@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 5f3d4c4 commit bf8c26c

4 files changed

Lines changed: 300 additions & 0 deletions

File tree

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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

‎snippets/export_preset_godot.py‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Godot glTF preset: Z-up (Blender-native), meter scale, selected objects only.
2+
# export_yup=False writes raw Z-up POSITION. glTF RNA has no axis_forward /
3+
# axis_up. Draco is opt-in; see snippets/gltf_draco_export.py for the
4+
# compression-only helper this does not duplicate.
5+
#
6+
# Assumption: scene units are meters (scale_length == 1.0). This preset is
7+
# the Z-up interop path; it is intentionally not the Unity Y-up kwargs.
8+
#
9+
# Reference:
10+
# https://docs.blender.org/api/current/bpy.ops.export_scene.html#bpy.ops.export_scene.gltf
11+
12+
import tempfile
13+
14+
import bpy
15+
16+
17+
def apply_selected_mesh_transforms():
18+
for obj in list(bpy.context.selected_objects):
19+
if obj.type != "MESH":
20+
continue
21+
with bpy.context.temp_override(
22+
object=obj, active_object=obj, selected_objects=[obj]
23+
):
24+
bpy.ops.object.transform_apply(
25+
location=False, rotation=True, scale=True
26+
)
27+
28+
29+
def export_preset_godot(filepath, selected_only=True, draco=False):
30+
apply_selected_mesh_transforms()
31+
bpy.ops.export_scene.gltf(
32+
filepath=filepath,
33+
use_selection=selected_only,
34+
export_yup=False,
35+
export_apply=True,
36+
export_draco_mesh_compression_enable=draco,
37+
export_animations=False,
38+
)
39+
40+
41+
if __name__ == "__main__":
42+
obj = bpy.context.active_object
43+
if obj is not None and obj.type == "MESH":
44+
obj.select_set(True)
45+
path = tempfile.NamedTemporaryFile(suffix=".glb", delete=False).name
46+
export_preset_godot(path)
47+
print(f"wrote {path}")

‎snippets/export_preset_unity.py‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Unity glTF preset: Y-up, meter scale, selected objects only.
2+
# Apply object rotation and scale before export so they do not land on the
3+
# glTF node. Axis is export_yup=True. glTF RNA has no axis_forward / axis_up.
4+
# Draco is opt-in; see snippets/gltf_draco_export.py for the compression-only
5+
# helper this does not duplicate.
6+
#
7+
# Assumption: scene units are meters (scale_length == 1.0).
8+
#
9+
# Reference:
10+
# https://docs.blender.org/api/current/bpy.ops.export_scene.html#bpy.ops.export_scene.gltf
11+
12+
import tempfile
13+
14+
import bpy
15+
16+
17+
def apply_selected_mesh_transforms():
18+
for obj in list(bpy.context.selected_objects):
19+
if obj.type != "MESH":
20+
continue
21+
with bpy.context.temp_override(
22+
object=obj, active_object=obj, selected_objects=[obj]
23+
):
24+
bpy.ops.object.transform_apply(
25+
location=False, rotation=True, scale=True
26+
)
27+
28+
29+
def export_preset_unity(filepath, selected_only=True, draco=False):
30+
apply_selected_mesh_transforms()
31+
bpy.ops.export_scene.gltf(
32+
filepath=filepath,
33+
use_selection=selected_only,
34+
export_yup=True,
35+
export_apply=True,
36+
export_draco_mesh_compression_enable=draco,
37+
export_animations=False,
38+
)
39+
40+
41+
if __name__ == "__main__":
42+
obj = bpy.context.active_object
43+
if obj is not None and obj.type == "MESH":
44+
obj.select_set(True)
45+
path = tempfile.NamedTemporaryFile(suffix=".glb", delete=False).name
46+
export_preset_unity(path)
47+
print(f"wrote {path}")

‎snippets/export_preset_unreal.py‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Unreal presets: centimeter scale. glTF has no global_scale and no
2+
# axis_forward / axis_up; bake 100x then export_yup=True. FBX uses
3+
# global_scale=100.0 plus axis_forward='-Z' and axis_up='Y'. That RNA
4+
# split is the contract. glTF bake mutates selected mesh objects.
5+
# Draco is glTF-only and opt-in; see snippets/gltf_draco_export.py.
6+
#
7+
# Assumption: scene units are meters before the 100x bake / FBX scale.
8+
#
9+
# Reference:
10+
# https://docs.blender.org/api/current/bpy.ops.export_scene.html#bpy.ops.export_scene.gltf
11+
# https://docs.blender.org/api/current/bpy.ops.export_scene.html#bpy.ops.export_scene.fbx
12+
13+
import tempfile
14+
15+
import bpy
16+
17+
18+
def apply_selected_mesh_transforms():
19+
for obj in list(bpy.context.selected_objects):
20+
if obj.type != "MESH":
21+
continue
22+
with bpy.context.temp_override(
23+
object=obj, active_object=obj, selected_objects=[obj]
24+
):
25+
bpy.ops.object.transform_apply(
26+
location=False, rotation=True, scale=True
27+
)
28+
29+
30+
def export_preset_unreal_gltf(filepath, selected_only=True, draco=False):
31+
apply_selected_mesh_transforms()
32+
for obj in list(bpy.context.selected_objects):
33+
if obj.type != "MESH":
34+
continue
35+
obj.scale = (obj.scale[0] * 100.0, obj.scale[1] * 100.0, obj.scale[2] * 100.0)
36+
apply_selected_mesh_transforms()
37+
bpy.ops.export_scene.gltf(
38+
filepath=filepath,
39+
use_selection=selected_only,
40+
export_yup=True,
41+
export_apply=True,
42+
export_draco_mesh_compression_enable=draco,
43+
export_animations=False,
44+
)
45+
46+
47+
def export_preset_unreal_fbx(filepath, selected_only=True):
48+
apply_selected_mesh_transforms()
49+
bpy.ops.export_scene.fbx(
50+
filepath=filepath,
51+
use_selection=selected_only,
52+
axis_forward="-Z",
53+
axis_up="Y",
54+
global_scale=100.0,
55+
apply_unit_scale=False,
56+
use_mesh_modifiers=True,
57+
bake_anim=False,
58+
)
59+
60+
61+
if __name__ == "__main__":
62+
obj = bpy.context.active_object
63+
if obj is not None and obj.type == "MESH":
64+
obj.select_set(True)
65+
path = tempfile.NamedTemporaryFile(suffix=".fbx", delete=False).name
66+
export_preset_unreal_fbx(path)
67+
print(f"wrote {path}")

0 commit comments

Comments
 (0)