Fix axis layout and implement click raytracing

This commit is contained in:
2021-07-30 22:41:05 +02:00
parent 4c2409dbd0
commit 02ba2bb95a
8 changed files with 167 additions and 98 deletions

View File

@@ -70,7 +70,6 @@ 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)]
@@ -245,7 +244,7 @@ impl VulkanRenderer {
let pipelines: Vec<Box<dyn Drawcall>> = vec![
Box::new(DefaultShader::new(device.clone(), render_pass.clone())),
Box::new(LineShader::new(device.clone(), render_pass.clone(), line_vertex_buffer.clone())),
// Box::new(LineShader::new(device.clone(), render_pass.clone(), line_vertex_buffer.clone())),
];
// Dynamic viewports allow us to recreate just the viewport when the window is resized
@@ -344,7 +343,7 @@ impl VulkanRenderer {
self.pipelines = vec![
Box::new(DefaultShader::new(self.device.clone(), self.render_pass.clone())),
Box::new(LineShader::new(self.device.clone(), self.render_pass.clone(), self.line_vertex_buffer.clone())),
// Box::new(LineShader::new(self.device.clone(), self.render_pass.clone(), self.line_vertex_buffer.clone())),
];
self.swapchain = new_swapchain;
@@ -413,18 +412,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 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, collision_mesh });
self.game_data.meshes.push(Mesh { vertex_buffer, index_buffer, original_path });
self.game_data.meshes.len() - 1
}