From 467360cc1ecbed634706f0ceb0cf808f62307b86 Mon Sep 17 00:00:00 2001 From: white-axe Date: Thu, 23 Nov 2023 17:37:51 -0500 Subject: [PATCH] Remove extra vertices from collision shader --- crates/graphics/src/collision/instance.rs | 127 +++++++++++----------- 1 file changed, 62 insertions(+), 65 deletions(-) diff --git a/crates/graphics/src/collision/instance.rs b/crates/graphics/src/collision/instance.rs index fc20651d..cf2c1455 100644 --- a/crates/graphics/src/collision/instance.rs +++ b/crates/graphics/src/collision/instance.rs @@ -47,7 +47,7 @@ impl Instances { usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST, }); - let vertices = Self::calculate_vertices(passages.xsize(), passages.ysize()); + let vertices = Self::calculate_vertices(); let vertex_buffer = render_state .device @@ -107,70 +107,67 @@ impl Instances { .collect_vec() } - fn calculate_vertices(width: usize, height: usize) -> Vec { - let mut vertices = Vec::with_capacity(width * height * 12); - - for (y, x) in (0..height).cartesian_product(0..width) { - let rect = - egui::Rect::from_min_size(egui::pos2(x as f32, y as f32), egui::vec2(32., 32.)); - let center = glam::vec3(rect.center().x, rect.center().y, 0.); - let top_left = glam::vec3(rect.left_top().x, rect.left_top().y, 0.); - let top_right = glam::vec3(rect.right_top().x, rect.right_top().y, 0.); - let bottom_left = glam::vec3(rect.left_bottom().x, rect.left_bottom().y, 0.); - let bottom_right = glam::vec3(rect.right_bottom().x, rect.right_bottom().y, 0.); - - vertices.push(Vertex { - position: center, - direction: 1, - }); - vertices.push(Vertex { - position: bottom_left, - direction: 1, - }); - vertices.push(Vertex { - position: bottom_right, - direction: 1, - }); - - vertices.push(Vertex { - position: center, - direction: 2, - }); - vertices.push(Vertex { - position: top_left, - direction: 2, - }); - vertices.push(Vertex { - position: bottom_left, - direction: 2, - }); - - vertices.push(Vertex { - position: center, - direction: 4, - }); - vertices.push(Vertex { - position: bottom_right, - direction: 4, - }); - vertices.push(Vertex { - position: top_right, - direction: 4, - }); - - vertices.push(Vertex { - position: center, - direction: 8, - }); - vertices.push(Vertex { - position: top_right, - direction: 8, - }); - vertices.push(Vertex { - position: top_left, - direction: 8, - }); - } + fn calculate_vertices() -> Vec { + let mut vertices = Vec::with_capacity(12); + + let rect = egui::Rect::from_min_size(egui::pos2(0., 0.), egui::vec2(32., 32.)); + let center = glam::vec3(rect.center().x, rect.center().y, 0.); + let top_left = glam::vec3(rect.left_top().x, rect.left_top().y, 0.); + let top_right = glam::vec3(rect.right_top().x, rect.right_top().y, 0.); + let bottom_left = glam::vec3(rect.left_bottom().x, rect.left_bottom().y, 0.); + let bottom_right = glam::vec3(rect.right_bottom().x, rect.right_bottom().y, 0.); + + vertices.push(Vertex { + position: center, + direction: 1, + }); + vertices.push(Vertex { + position: bottom_left, + direction: 1, + }); + vertices.push(Vertex { + position: bottom_right, + direction: 1, + }); + + vertices.push(Vertex { + position: center, + direction: 2, + }); + vertices.push(Vertex { + position: top_left, + direction: 2, + }); + vertices.push(Vertex { + position: bottom_left, + direction: 2, + }); + + vertices.push(Vertex { + position: center, + direction: 4, + }); + vertices.push(Vertex { + position: bottom_right, + direction: 4, + }); + vertices.push(Vertex { + position: top_right, + direction: 4, + }); + + vertices.push(Vertex { + position: center, + direction: 8, + }); + vertices.push(Vertex { + position: top_right, + direction: 8, + }); + vertices.push(Vertex { + position: top_left, + direction: 8, + }); vertices }