bevy/examples/3d/load_model.rs

49 lines
1.2 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(
2020-07-10 04:18:35 +00:00
mut commands: Commands,
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-07-10 04:18:35 +00:00
commands
2020-04-20 02:29:33 +00:00
// mesh
2020-07-10 04:18:35 +00:00
.spawn(PbrComponents {
2020-04-20 02:29:33 +00:00
mesh: mesh_handle,
material: material_handle,
..Default::default()
})
// light
2020-07-10 04:18:35 +00:00
.spawn(LightComponents {
translation: Translation::new(4.0, 5.0, 4.0),
2020-04-20 02:29:33 +00:00
..Default::default()
})
// camera
.spawn(Camera3dComponents {
transform: Transform::new_sync_disabled(Mat4::face_toward(
Vec3::new(-2.0, 2.0, 6.0),
2020-04-20 02:29:33 +00:00
Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, 1.0, 0.0),
2020-04-20 02:29:33 +00:00
)),
..Default::default()
});
2020-01-11 09:59:39 +00:00
}