Skip to content

Commit

Permalink
Merge pull request #1862 from hannobraun/viewer
Browse files Browse the repository at this point in the history
Remove vestigial debug rendering code
  • Loading branch information
hannobraun authored Jun 6, 2023
2 parents 259ee38 + 5b748ea commit d478f9c
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 73 deletions.
4 changes: 0 additions & 4 deletions crates/fj-viewer/src/graphics/draw_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ pub struct DrawConfig {

/// Toggle for displaying the wireframe model
pub draw_mesh: bool,

/// Toggle for displaying model debug information
pub draw_debug: bool,
}

impl Default for DrawConfig {
fn default() -> Self {
Self {
draw_model: true,
draw_mesh: false,
draw_debug: false,
}
}
}
4 changes: 1 addition & 3 deletions crates/fj-viewer/src/graphics/drawables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ use super::{
pub struct Drawables<'r> {
pub model: Drawable<'r>,
pub mesh: Drawable<'r>,
pub lines: Drawable<'r>,
}

impl<'r> Drawables<'r> {
pub fn new(geometries: &'r Geometries, pipelines: &'r Pipelines) -> Self {
let model = Drawable::new(&geometries.mesh, &pipelines.model);
let mesh = Drawable::new(&geometries.mesh, &pipelines.mesh);
let lines = Drawable::new(&geometries.lines, &pipelines.lines);

Self { model, mesh, lines }
Self { model, mesh }
}
}

Expand Down
11 changes: 2 additions & 9 deletions crates/fj-viewer/src/graphics/geometries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@ use super::vertices::{Vertex, Vertices};
#[derive(Debug)]
pub struct Geometries {
pub mesh: Geometry,
pub lines: Geometry,
}

impl Geometries {
pub fn new(
device: &wgpu::Device,
mesh: &Vertices,
debug_info: &Vertices,
) -> Self {
pub fn new(device: &wgpu::Device, mesh: &Vertices) -> Self {
let mesh = Geometry::new(device, mesh.vertices(), mesh.indices());
let lines =
Geometry::new(device, debug_info.vertices(), debug_info.indices());

Self { mesh, lines }
Self { mesh }
}
}

Expand Down
16 changes: 5 additions & 11 deletions crates/fj-viewer/src/graphics/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ impl Renderer {
label: None,
});

let geometries =
Geometries::new(&device, &Vertices::empty(), &Vertices::empty());
let geometries = Geometries::new(&device, &Vertices::empty());
let pipelines =
Pipelines::new(&device, &bind_group_layout, color_format);

Expand Down Expand Up @@ -213,8 +212,8 @@ impl Renderer {
}

/// Updates the geometry of the model being rendered.
pub fn update_geometry(&mut self, mesh: Vertices, lines: Vertices) {
self.geometries = Geometries::new(&self.device, &mesh, &lines);
pub fn update_geometry(&mut self, mesh: Vertices) {
self.geometries = Geometries::new(&self.device, &mesh);
}

/// Resizes the render surface.
Expand Down Expand Up @@ -310,13 +309,8 @@ impl Renderer {
drawables.model.draw(&mut render_pass);
}

if self.is_line_drawing_available() {
if config.draw_mesh {
drawables.mesh.draw(&mut render_pass);
}
if config.draw_debug {
drawables.lines.draw(&mut render_pass);
}
if self.is_line_drawing_available() && config.draw_mesh {
drawables.mesh.draw(&mut render_pass);
}
}

Expand Down
35 changes: 1 addition & 34 deletions crates/fj-viewer/src/graphics/vertices.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use bytemuck::{Pod, Zeroable};
use fj_interop::{
debug::DebugInfo,
mesh::{Index, Mesh},
};
use fj_interop::mesh::{Index, Mesh};
use fj_math::{Point, Vector};

#[derive(Debug)]
Expand Down Expand Up @@ -102,36 +99,6 @@ impl From<&Mesh<fj_math::Point<3>>> for Vertices {
}
}

impl From<&DebugInfo> for Vertices {
fn from(debug_info: &DebugInfo) -> Self {
let mut self_ = Self::empty();

for triangle_edge_check in &debug_info.triangle_edge_checks {
let normal = [0.; 3];

let red = [1., 0., 0., 1.];
let green = [0., 1., 0., 1.];

let color = if triangle_edge_check.hits.len() % 2 == 0 {
red
} else {
green
};

self_.push_cross(triangle_edge_check.origin, normal, color);

for &hit in &triangle_edge_check.hits {
let line = hit.points();
let color = [0., 0., 0., 1.];

self_.push_line(line, normal, color);
}
}

self_
}
}

#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
#[repr(C)]
pub struct Vertex {
Expand Down
10 changes: 1 addition & 9 deletions crates/fj-viewer/src/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,9 @@ impl Viewer {
}
}

/// Toggle the "draw debug" setting
pub fn toggle_draw_debug(&mut self) {
if self.renderer.is_line_drawing_available() {
self.draw_config.draw_debug = !self.draw_config.draw_debug;
}
}

/// Handle the shape being updated
pub fn handle_shape_update(&mut self, shape: ProcessedShape) {
self.renderer
.update_geometry((&shape.mesh).into(), (&shape.debug_info).into());
self.renderer.update_geometry((&shape.mesh).into());

let aabb = shape.aabb;
if self.shape.replace(shape).is_none() {
Expand Down
3 changes: 0 additions & 3 deletions crates/fj-window/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ pub fn display(mesh: Mesh<Point<3>>, invert_zoom: bool) -> Result<(), Error> {
VirtualKeyCode::Key2 => {
viewer.toggle_draw_mesh();
}
VirtualKeyCode::Key3 => {
viewer.toggle_draw_debug();
}
_ => {}
},
Event::WindowEvent {
Expand Down

0 comments on commit d478f9c

Please sign in to comment.