Skip to content

bevy panics when spawning GLTF Mesh asset without associated bones/armature #10810

@dmlary

Description

@dmlary

Bevy version

v0.12

What you did

Bevy panics when you spawn a Mesh from a GLTF asset that has an attached armature. The GLTF file I'm working with contains a single cube, with a single bone inside it. When I spawn it as #Scene0 it works fine, but when I only want to spawn the #Mesh0/Primitive0 it panics.

When I spawn it, the application crashes with:

2023-11-29T22:44:06.310929Z ERROR log: Handling wgpu errors as fatal by default thread '<unnamed>' panicked at /Users/dmlary/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-0.17.2/src/backend/direct.rs:3056:5: wgpu error: Validation Error

Caused by:
    In a RenderPass
      note: encoder = `<CommandBuffer-(0, 2, Metal)>`
    In a draw command, indexed:true indirect:false
      note: render pipeline = `pbr_opaque_mesh_pipeline`
    The pipeline layout, associated with the current render pipeline, contains a bind group layout at index 2 which is incompatible with the bind group layout associated with the bind group at 2

Source code used to load the asset.

use bevy::prelude::*;

fn main() {
    let mut app = App::new();

    app.add_plugins((DefaultPlugins,))
        .add_systems(Startup, setup)
        .run();
}

fn setup(
    mut commands: Commands,
    mut materials: ResMut<Assets<StandardMaterial>>,
    asset_server: Res<AssetServer>,
) {
    // XXX works fine
    // let scene = asset_server.load("cube-with-bone.glb#Scene0");
    // commands.spawn(SceneBundle { scene, ..default() });

    // XXX panics during render
    let mesh_handle: Handle<Mesh> = asset_server.load("cube-with-bone.glb#Mesh0/Primitive0");
    commands.spawn(MaterialMeshBundle {
        mesh: mesh_handle,
        material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
        ..default()
    });

    // camera
    commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(10.0, 12.0, 16.0).looking_at(Vec3::ZERO, Vec3::Y),
        ..default()
    });
}

Questions

  • Is there a way to spawn a Mesh from a GLTF without its Armature?
  • How would we spawn the Mesh with its Armature?
    • Example: How is a GltfNode connected to the Armature?
    • Is there an AssetServer::load() path that encompasses Mesh and Armature?
  • Is there any way to get a better error message when this happens?

Additional information

Zip file of both .blender and .glb files (thanks for the idea @alice-i-cecile): cube-with-bone.zip

blender file screenshot (because github no support gltf/blender files):
Screenshot 2023-11-29 at 4 51 51 PM

gltf file loaded in gltf viewer:
Screenshot 2023-11-29 at 5 01 38 PM

full-panic-output.txt

Another person brought up this issue in the discord recently: https://discord.com/channels/691052431525675048/1179374309882462239

Further background

The wider context for this is I'm working on a scene-less blender workflow for spawning objects, characters, etc from a GLTF file. I'm able to spawn the hierarchy from GltfNode1, but it panics if any Mesh had bones attached. Unless I'm missing something obvious, the Armature have been removed from the GltfNode, so I don't know that it should be spawned.

Footnotes

  1. spawn code in discord

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AnimationMake things move and change over timeA-glTFRelated to the glTF 3D scene/model formatC-BugAn unexpected or incorrect behaviorP-CrashA sudden unexpected crash

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions