#gltf #bevy #edit #material #mesh #customizable #loading

bevy_gltf_trait

Customizable Bevy Engine GLTF loading

4 releases (2 breaking)

0.3.0 Feb 5, 2025
0.2.1 Feb 4, 2025
0.2.0 Dec 10, 2024
0.1.1 Jul 8, 2024
0.1.0 Jul 8, 2024

#369 in Game dev

Download history 3/week @ 2024-10-29 6/week @ 2024-11-05 145/week @ 2024-12-10 1/week @ 2024-12-17 271/week @ 2025-02-04

271 downloads per month

MIT/Apache

160KB
3K SLoC

Bevy glTF Trait

This is a fork of bevy /crates/bevy_gltf, that doesn't change any functionalities, but provides several possibilities to customize the conversion between gltf and bevy interns on load using the trait GltfTrait.

Trait Features

  • set the extensions default: &["gltf", "glb"]
  • Material:
    • change the Material used
    • or just edit the StandardMaterials
  • Meshes:
    • edit any Mesh
    • edit their EntityWorldMut (similar to EntityCommands)
    • edit the Transform and EntityWorldMut of their parent
  • Lights:
    • edit their SpotLight, PointLight or DirectionalLight components
    • edit their EntityWorldMut
    • edit the Transform and EntityWorldMut of their parent
  • edit the App

Notes

  • If you want to insert components through the trait and they are foreign to bevy_gltf:
    • Make sure to use on_app to .register_type() them
  • the provided gltf structs make it possible to react to custom gltf properties

Versions

Bevy This
0.15 0.2
0.14 0.1

Example

The original way of adding the plugin changes to:

fn main(){
    let mut app = App::new();
    app.add_plugins((
        MinimalPlugins,
        GltfPlugin::<()>::default(),
        // ...
    ));
    app.run();
}

..and can be modified with the trait to either replace or extend (using different extensions) scene imports.

#[derive(Reflect,Clone,Default)]
struct WhiteGltf;
impl GltfTrait for WhiteGltf {
    const EXTENSIONS: &'static [&'static str] = &["myglb"];
    type Material = StandardMaterial;        
    fn convert_material (mut convert:GltfTraitMaterial) -> Self::Material {
        convert.material.base_color = Color::WHITE;
        convert.material.base_color_texture = None;
        convert.material
    }
}

fn main(){
    let mut app = App::new();
    app.add_plugins((
        DefaultPlugins,
        GltfPlugin::<WhiteGltf>::default()
    ));
    app.run();
}

Dependencies

~37–69MB
~1M SLoC