bevy/examples/3d/load_model.rs

50 lines
1.3 KiB
Rust
Raw Normal View History

use bevy::prelude::*;
2020-01-08 07:03:09 +00:00
fn main() {
2020-04-20 02:29:33 +00:00
App::build()
.add_default_plugins()
2020-05-14 00:31:56 +00:00
.add_startup_system(setup.system())
2020-04-20 02:29:33 +00:00
.run();
}
2020-05-14 00:31:56 +00:00
fn setup(
command_buffer: &mut CommandBuffer,
2020-05-18 01:09:29 +00:00
asset_server: Res<AssetServer>,
2020-05-14 00:52:47 +00:00
mut materials: ResMut<Assets<StandardMaterial>>,
2020-05-14 00:31:56 +00:00
) {
2020-04-20 05:31:14 +00:00
// load the mesh
let mesh_handle = asset_server
2020-05-16 00:22:45 +00:00
.load("assets/models/monkey/Monkey.gltf")
.unwrap();
2020-04-20 02:29:33 +00:00
2020-04-20 05:31:14 +00:00
// create a material for the mesh
2020-05-13 23:42:27 +00:00
let material_handle = materials.add(StandardMaterial {
2020-04-20 02:29:33 +00:00
albedo: Color::rgb(0.5, 0.4, 0.3),
..Default::default()
});
// add entities to the world
2020-05-14 00:31:56 +00:00
command_buffer
2020-04-20 02:29:33 +00:00
.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(PerspectiveCameraEntity {
transform: Transform::new_sync_disabled(Mat4::look_at_rh(
2020-04-20 02:29:33 +00:00
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
}