textures!!!

This commit is contained in:
2019-08-02 23:50:37 +02:00
parent c582af5138
commit 4f261fa708
5 changed files with 108 additions and 27 deletions

View File

@@ -16,7 +16,7 @@ struct TestGame {
input: InputState,
cam_position: Vector3<f32>,
cam_rotation: Quaternion<f32>,
cube_mesh: Option<MeshHandle>,
test_meshes: Vec<(MeshHandle, usize)>,
cubes: Vec<GameObjectHandle>,
log_config: LogConfig,
}
@@ -29,8 +29,16 @@ impl Game for TestGame {
impl TestGame {
fn game_start(self: &mut Self, renderer: &mut VulkanRenderer) {
self.cube_mesh = Some(renderer.upload_mesh(mesh::load_mesh("models/box.gltf", self.log_config.mesh_load_info).unwrap().into_iter().nth(0).unwrap()));
println!("Game started.");
let (meshes, textures) = mesh::load_mesh("models/iski51.gltf", self.log_config.mesh_load_info).unwrap();
self.test_meshes = meshes.into_iter().map(|m| {
let id = match m.texture_index {
Some(tex_id) => tex_id + 1,
None => 0,
};
(renderer.upload_mesh(m), id)
}).collect();
textures.iter().for_each(|tex| renderer.upload_texture(tex));
println!("Game loaded!");
}
fn update(self: &mut Self, renderer: &mut VulkanRenderer) {
@@ -55,7 +63,7 @@ impl TestGame {
if self.input.button_just_pressed("test") {
println!("test");
self.cubes.push(renderer.add_game_object(GameObject::new(self.cube_mesh.unwrap())));
self.cubes = self.test_meshes.iter().map(|(mesh, tex_id)| renderer.add_game_object(GameObject::new(*mesh, *tex_id, renderer))).collect();
}
self.cam_rotation = self.cam_rotation * Quaternion::from_angle_z(Deg(self.input.get_axis("look_horizontal") * 0.05));
@@ -93,7 +101,7 @@ fn main() {
input: InputState::new("config/input.toml", log_config),
cam_rotation: Quaternion::one(),
cam_position: Vector3::new(0.0, 0.0, -10.0),
cube_mesh: None,
test_meshes: vec![],
cubes: vec![],
log_config
};