some mouse stuff i don't remember

This commit is contained in:
2021-02-18 11:47:31 +01:00
parent dd4eaa13f7
commit d33bceeab8
5 changed files with 48 additions and 8 deletions

View File

@@ -71,6 +71,7 @@ pub struct Mesh {
pub vertex_buffer: Arc<CpuAccessibleBuffer<[Vertex]>>,
pub index_buffer: Arc<CpuAccessibleBuffer<[u32]>>,
pub original_path: String,
pub collision_mesh: mgf::Mesh,
}
#[derive(Debug, Clone)]
@@ -416,9 +417,18 @@ impl VulkanRenderer {
}
pub fn upload_mesh(self: &mut Self, mesh: CPUMesh, original_path: String) -> usize {
let mut collision_mesh = mgf::Mesh::new();
mesh.vertices.iter().for_each(|v| {
collision_mesh.push_vert(v.position.into());
}); // TODO: convert vert pos to world space
for i in (0..mesh.indices.len()).step_by(3) {
collision_mesh.push_face((mesh.indices[i] as usize, mesh.indices[i + 1] as usize, mesh.indices[i + 2] as usize));
}
let vertex_buffer = CpuAccessibleBuffer::from_iter(self.device.clone(), BufferUsage::vertex_buffer(), false, mesh.vertices.into_iter()).unwrap();
let index_buffer = CpuAccessibleBuffer::from_iter(self.device.clone(), BufferUsage::index_buffer(), false, mesh.indices.into_iter()).unwrap();
self.game_data.meshes.push(Mesh { vertex_buffer, index_buffer, original_path });
self.game_data.meshes.push(Mesh { vertex_buffer, index_buffer, original_path, collision_mesh });
self.game_data.meshes.len() - 1
}