Skip to content

snippets: Unreal glTF preset scales meshes 100x but leaves object locations in meters #297

Description

@TMHSDigital

Why it matters

export_preset_unreal_gltf is sold as the Unreal centimeter preset. It multiplies each mesh's scale by 100 and applies it, but never scales object locations. A single object at the origin exports correctly. Any real scene with more than one object comes out with centimeter-sized geometry laid out at meter spacing: objects overlap or collapse together in Unreal.

Readers copy this snippet as-is, and the engine-export-presets skill points at it.

Evidence

snippets/export_preset_unreal.py:30-36 (HEAD 54e7f71):

def export_preset_unreal_gltf(filepath, selected_only=True, draco=False):
    apply_selected_mesh_transforms()
    for obj in list(bpy.context.selected_objects):
        if obj.type != "MESH":
            continue
        obj.scale = (obj.scale[0] * 100.0, obj.scale[1] * 100.0, obj.scale[2] * 100.0)
    apply_selected_mesh_transforms()   # transform_apply(location=False, ...)

obj.location is never touched, so the distance between objects stays in meters while mesh extents grow 100x.

Reproduced headless on .scratch/5.2/blender-5.2.1-windows-x64/blender.exe (reports Blender 5.2.1 LTS): three cubes placed 3 m apart, selected, then export_preset_unreal_gltf(...) was called:

PROBE2 inter-object distance 3.000 -> 3.000; cube width 4.000 -> 400.000

Mesh extents grew ×100, spacing stayed ×1.

Suggested approach

Pick one:

  • Scale obj.location by 100 alongside obj.scale. Parented objects need care: only scale roots, or use matrix_world.
  • Parent the selection under a temporary root empty, scale the root 100x, apply, then unparent.

Also check whether the existing examples/ export-preset smoke only uses a single object at the origin, which would explain why CI never saw this.

Done when

  • Multi-object selections keep their relative layout, measured in centimeters.
  • A smoke check (catalog row or example assertion) exports at least two objects placed apart and asserts the inter-object distance grows ×100. The check has a recorded falsifier run against the current code.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions