bevy/examples/simple.rs

69 lines
2.1 KiB
Rust
Raw Normal View History

2020-01-13 19:20:58 -08:00
use bevy::prelude::*;
2019-11-12 19:36:02 -08:00
fn main() {
2020-02-07 23:17:51 -08:00
AppBuilder::new()
.add_defaults_legacy()
.setup_world(setup)
.run();
}
2019-12-03 00:30:30 -08:00
fn setup(world: &mut World) {
2019-12-02 10:48:08 -08:00
let cube = Mesh::load(MeshType::Cube);
2020-01-11 01:59:39 -08:00
let plane = Mesh::load(MeshType::Plane { size: 10.0 });
2019-12-02 10:48:08 -08:00
let (cube_handle, plane_handle) = {
2020-01-11 15:21:31 -08:00
let mut mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
(mesh_storage.add(cube), mesh_storage.add(plane))
};
2020-02-07 23:17:51 -08:00
world
.build()
2020-01-20 20:10:40 -08:00
// plane
.add_archetype(MeshEntity {
2020-01-20 20:10:40 -08:00
mesh: plane_handle.clone(),
material: Material::new(Albedo::Color(math::vec4(0.1, 0.2, 0.1, 1.0))),
local_to_world: LocalToWorld::identity(),
translation: Translation::new(0.0, 0.0, 0.0),
})
// cube
.add_archetype(MeshEntity {
2020-01-20 20:10:40 -08:00
mesh: cube_handle,
material: Material::new(Albedo::Color(math::vec4(0.5, 0.3, 0.3, 1.0))),
local_to_world: LocalToWorld::identity(),
translation: Translation::new(0.0, 0.0, 1.0),
})
// light
.add_archetype(LightEntity {
2020-01-20 20:10:40 -08:00
light: Light {
color: wgpu::Color {
2019-12-03 19:01:48 -08:00
r: 0.8,
g: 0.8,
b: 0.5,
a: 1.0,
},
fov: f32::to_radians(60.0),
2020-01-11 01:59:39 -08:00
depth: 0.1..50.0,
target_view: None,
},
2020-01-20 20:10:40 -08:00
local_to_world: LocalToWorld::identity(),
translation: Translation::new(4.0, -4.0, 5.0),
rotation: Rotation::from_euler_angles(0.0, 0.0, 0.0),
})
// camera
.add_archetype(CameraEntity {
2020-01-20 20:10:40 -08:00
camera: Camera::new(CameraType::Projection {
2019-12-04 00:11:14 -08:00
fov: std::f32::consts::PI / 4.0,
near: 1.0,
2019-12-04 00:11:14 -08:00
far: 1000.0,
aspect_ratio: 1.0,
}),
2020-01-20 20:10:40 -08:00
active_camera: ActiveCamera,
local_to_world: LocalToWorld(Mat4::look_at_rh(
2020-01-12 22:26:07 -08:00
Vec3::new(3.0, 8.0, 5.0),
2019-12-04 00:11:14 -08:00
Vec3::new(0.0, 0.0, 0.0),
2020-01-11 01:59:39 -08:00
Vec3::new(0.0, 0.0, 1.0),
)),
2020-01-20 20:10:40 -08:00
})
2020-02-07 23:17:51 -08:00
.build();
2020-01-11 01:59:39 -08:00
}