til apply your transforms!

everything looks broken until you do this

2024-09-22
#bevy#3d#blender

For goodness' sake, apply your damn transforms! Exporting a Scene0 from Blender in GLTF works rather well, but if you attempt to load just a Mesh0/Primitive0 like so:

fn init(
    asset_server: Res<AssetServer>,
    mut commands: Commands,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    let mesh = asset_server.load(
        GltfAssetLabel::Primitive {
            mesh: 0,
            primitive: 0,
        }
        .from_asset("models/ship.glb"),
    );
    let material = materials.add(StandardMaterial {
        base_color: Color::srgb(0.6, 0.8, 0.6),
        ..default()
    });
    commands.spawn((
        Name::new("Ship"),
        Ship,
        MaterialMeshBundle {
            material,
            mesh,
            transform: Transform::from_translation(Vec3::ZERO),
            ..default()
        },
        StateScoped(Screen::Playing),
    ));
}

you're in for a bad time if you don't first apply your transforms (location, rotation, scale) prior to exporting the .glb. It's the difference between this:

broken, everything's broken

and this:

broken, everything's broken

Granted, the second isn't a massive improvement on the first, but at least it looks as intended. Here's the LLM's explanation of this stuff:

What Does Applying Transforms Mean?

Applying transforms (Ctrl + A in Blender) "bakes" the location, rotation, and scale into the object's mesh data. This means the transformations are no longer stored separately as metadata but are incorporated directly into the vertices of the mesh.

Without applying transforms, the mesh's local coordinates are still considered to be at its original scale, location, and orientation. After applying transforms, the object's geometry itself is adjusted to match the transformations.