2020-04-19 17:08:47 +00:00
|
|
|
use bevy::{gltf, prelude::*};
|
2020-01-08 07:03:09 +00:00
|
|
|
|
|
|
|
fn main() {
|
2020-04-20 02:29:33 +00:00
|
|
|
App::build()
|
|
|
|
.add_default_plugins()
|
|
|
|
.add_startup_system(setup)
|
|
|
|
.add_system_init(bevy::input::system::exit_on_esc_system)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// set up a simple scene
|
|
|
|
fn setup(world: &mut World, resources: &mut Resources) {
|
|
|
|
let mesh = gltf::load_gltf("examples/assets/Monkey.gltf")
|
|
|
|
.unwrap()
|
|
|
|
.unwrap();
|
|
|
|
// create a cube and a plane mesh
|
|
|
|
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
|
|
|
let mesh_handle = mesh_storage.add(mesh);
|
|
|
|
|
|
|
|
// create materials for our cube and plane
|
|
|
|
let mut material_storage = resources
|
|
|
|
.get_mut::<AssetStorage<StandardMaterial>>()
|
|
|
|
.unwrap();
|
|
|
|
let material_handle = material_storage.add(StandardMaterial {
|
|
|
|
albedo: Color::rgb(0.5, 0.4, 0.3),
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
|
|
|
|
// add entities to the world
|
|
|
|
world
|
|
|
|
.build()
|
|
|
|
// mesh
|
|
|
|
.add_entity(MeshEntity {
|
|
|
|
mesh: mesh_handle,
|
|
|
|
material: material_handle,
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
// light
|
|
|
|
.add_entity(LightEntity {
|
|
|
|
translation: Translation::new(4.0, -4.0, 5.0),
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
// camera
|
|
|
|
.add_entity(CameraEntity {
|
|
|
|
local_to_world: LocalToWorld(Mat4::look_at_rh(
|
|
|
|
Vec3::new(2.0, -6.0, 2.0),
|
|
|
|
Vec3::new(0.0, 0.0, 0.0),
|
|
|
|
Vec3::new(0.0, 0.0, 1.0),
|
|
|
|
)),
|
|
|
|
..Default::default()
|
|
|
|
});
|
2020-01-11 09:59:39 +00:00
|
|
|
}
|