Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle hidden-line drawing with the X key in the viewer app #162

Merged
merged 1 commit into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions crates/viewer/src/edge_drawer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct EdgeDrawer {
bind_groups: BindGroups,
screen_width: u32,
screen_height: u32,
draw_back_edges: bool,
}

impl EdgeDrawer {
Expand Down Expand Up @@ -61,6 +62,7 @@ impl EdgeDrawer {
bind_groups,
screen_width,
screen_height,
draw_back_edges: false,
}
}

Expand All @@ -69,6 +71,10 @@ impl EdgeDrawer {
self.screen_height = screen_height;
}

pub fn toggle_back_edge_drawing(&mut self) {
self.draw_back_edges = !self.draw_back_edges;
}

#[allow(clippy::too_many_arguments)]
pub fn draw(
&self,
Expand Down Expand Up @@ -125,19 +131,22 @@ impl EdgeDrawer {
timestamp_writes: None,
});

// Render dashed line strips
render_pass.set_pipeline(&self.dashed_line_strip_pipeline);
render_pass.set_vertex_buffer(0, self.buffers.round_strip_geometry.slice(..));
render_pass.set_vertex_buffer(1, rendered_line.vertex_buf.slice(..));
render_pass.set_bind_group(0, &self.bind_groups.dashed_vertex_uniform, &[]);

let mut offset = 0usize;
let vertex_count = self.buffers.round_strip_geometry_len as u32;

for line_strip_size in &rendered_line.line_sizes {
let range = (offset as u32)..(offset + line_strip_size - 1) as u32;
offset += line_strip_size;
render_pass.draw(0..vertex_count, range);
// Render dashed line strips
if self.draw_back_edges {
render_pass.set_pipeline(&self.dashed_line_strip_pipeline);
render_pass.set_bind_group(0, &self.bind_groups.dashed_vertex_uniform, &[]);

let mut offset = 0usize;
let vertex_count = self.buffers.round_strip_geometry_len as u32;

for line_strip_size in &rendered_line.line_sizes {
let range = (offset as u32)..(offset + line_strip_size - 1) as u32;
offset += line_strip_size;
render_pass.draw(0..vertex_count, range);
}
}

// Render solid line strips
Expand Down
8 changes: 7 additions & 1 deletion crates/viewer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,18 @@ impl GameApp for ViewerApp {
self.camera.zoom(-zoom_delta);
},
WindowEvent::KeyboardInput {
event: KeyEvent { physical_key: PhysicalKey::Code(key_code), .. },
event:
KeyEvent {
physical_key: PhysicalKey::Code(key_code),
state: ElementState::Pressed,
..
},
..
} => match key_code {
KeyCode::Escape => window_target.exit(),
KeyCode::KeyP => self.camera.use_perspective(),
KeyCode::KeyO => self.camera.use_orthographic(),
KeyCode::KeyX => self.line_drawer.toggle_back_edge_drawing(),
_ => {},
},
_ => {},
Expand Down