You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
martian-chess/examples/gltf-inspector.rs

59 lines
1.5 KiB
Rust

use bevy::{gltf::Gltf, prelude::*};
fn main() {
App::new()
.add_plugins((DefaultPlugins,))
.add_systems(Startup, startup)
.add_systems(Update, inspect)
.add_systems(Update)
.run();
}
#[derive(Debug, Resource)]
struct AssetRegistry {
gltfs: Vec<Handle<Gltf>>,
}
fn startup(server: Res<AssetServer>, mut commands: Commands) {
commands.insert_resource(AssetRegistry {
gltfs: vec![server.load("gltf/Martian Chess.glb")],
});
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<AssetEvent<Gltf>>,
gltfs: Res<Assets<Gltf>>,
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("Board")
.expect("Fetch board scene")
.clone(),
..default()
});
}
_ => (),
});
}
fn track_named(events: Query<&Name, Added<Name>>) {
events.iter().for_each(|name| {
info!("named entity: {:?}", name);
});
}