diff --git a/assets/gltf/Example Flight Helmet.glb b/assets/gltf/Example Flight Helmet.glb new file mode 100644 index 0000000..ea80303 Binary files /dev/null and b/assets/gltf/Example Flight Helmet.glb differ diff --git a/assets/gltf/Martian Chess.glb b/assets/gltf/Martian Chess.glb new file mode 100644 index 0000000..900a7ed Binary files /dev/null and b/assets/gltf/Martian Chess.glb differ diff --git a/examples/gltf-inspector.rs b/examples/gltf-inspector.rs new file mode 100644 index 0000000..69744f5 --- /dev/null +++ b/examples/gltf-inspector.rs @@ -0,0 +1,46 @@ +use bevy::{prelude::*, gltf::Gltf}; + +fn main() { + App::new() + .add_plugins(( + DefaultPlugins, + )) + .add_systems(Startup, startup) + .add_systems(Update, inspect) + .run(); +} + +#[derive(Debug, Resource)] +struct AssetRegistry { + gltfs: Vec>, +} + +fn startup(server: Res, mut commands: Commands) { + commands.insert_resource(AssetRegistry { + gltfs: server.load_folder("gltf").expect("Loading GLTF Assets").into_iter().map(|untyped| untyped.typed::()).collect() + }); + + commands.spawn(SpotLightBundle { + transform: Transform::from_xyz(0.0, 5.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y), + ..default() + }); + + commands.spawn(Camera3dBundle { + transform: Transform::from_xyz(1.0, 1.0, 1.0).looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y), + ..default() }); +} + +fn inspect(mut events: EventReader>, gltfs: Res>, mut commands: Commands) { + events.iter().for_each(|event| { + match event { + AssetEvent::Created { handle } => { + let gltf = gltfs.get(handle).expect("Fetch GLTF data"); + commands.spawn(SceneBundle { + scene: gltf.named_scenes.get("Helmet").expect("Fetch board scene").clone(), + ..default() + }); + }, + _ => () + } + }); +} \ No newline at end of file