Merge pull request #217 from therealprof/hacky-bounding-box

Add a hacky model bounding box info to rendering UI
This commit is contained in:
Hanno Braun 2022-02-20 11:59:30 +01:00 committed by GitHub
commit a2058a9ac9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 9 deletions

View File

@ -6,6 +6,8 @@ use wgpu_glyph::{
GlyphBrush, GlyphBrushBuilder, Section, Text,
};
use crate::math::Aabb;
use super::{draw_config::DrawConfig, COLOR_FORMAT};
#[derive(Debug)]
@ -45,6 +47,7 @@ impl ConfigUi {
encoder: &mut wgpu::CommandEncoder,
view: &wgpu::TextureView,
surface_config: &wgpu::SurfaceConfiguration,
aabb: &Aabb<3>,
draw_config: &DrawConfig,
) -> Result<(), String> {
let mut section = Section::new().with_screen_position((50.0, 50.0));
@ -62,6 +65,19 @@ impl ConfigUi {
section = section.add_text(text);
}
/* Render size of model bounding box */
let bbsize = aabb.size().components();
let info = format!(
"Model bounding box size: {:0.1} {:0.1} {:0.1}",
bbsize[0].into_f32(),
bbsize[1].into_f32(),
bbsize[2].into_f32()
);
let text = Text::new(&info)
.with_color([0.0, 0.0, 0.0, 1.0])
.with_scale(50.0);
section = section.add_text(text);
self.glyph_brush.queue(section);
self.glyph_brush.draw_queued(
device,

View File

@ -1,3 +1,4 @@
use crate::math::Aabb;
use std::convert::TryInto;
use wgpu::util::DeviceExt;
@ -8,6 +9,7 @@ use super::vertices::{Vertex, Vertices};
pub struct Geometries {
pub mesh: Geometry,
pub lines: Geometry,
pub aabb: Aabb<3>,
}
impl Geometries {
@ -15,12 +17,13 @@ impl Geometries {
device: &wgpu::Device,
mesh: &Vertices,
debug_info: &Vertices,
aabb: Aabb<3>,
) -> 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, lines, aabb }
}
}

View File

@ -6,7 +6,7 @@ use wgpu::util::DeviceExt as _;
use wgpu_glyph::ab_glyph::InvalidFont;
use winit::dpi::PhysicalSize;
use crate::{camera::Camera, window::Window};
use crate::{camera::Camera, math::Aabb, math::Point, window::Window};
use super::{
config_ui::ConfigUi, draw_config::DrawConfig, drawables::Drawables,
@ -114,8 +114,15 @@ impl Renderer {
label: None,
});
let geometries =
Geometries::new(&device, &Vertices::empty(), &Vertices::empty());
let geometries = Geometries::new(
&device,
&Vertices::empty(),
&Vertices::empty(),
Aabb {
min: Point::from([0.0, 0.0, 0.0]),
max: Point::from([0.0, 0.0, 0.0]),
},
);
let pipelines = Pipelines::new(&device, &bind_group_layout);
let config_ui = ConfigUi::new(&device)?;
@ -138,8 +145,13 @@ impl Renderer {
})
}
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,
lines: Vertices,
aabb: Aabb<3>,
) {
self.geometries = Geometries::new(&self.device, &mesh, &lines, aabb);
}
pub fn handle_resize(&mut self, size: PhysicalSize<u32>) {
@ -216,6 +228,7 @@ impl Renderer {
&mut encoder,
&color_view,
&self.surface_config,
&self.geometries.aabb,
config,
)
.map_err(|err| DrawError::Text(err))?;

View File

@ -196,7 +196,7 @@ fn main() -> anyhow::Result<()> {
let mut input_handler = input::Handler::new(previous_time);
let mut renderer = block_on(Renderer::new(&window))?;
renderer.update_geometry((&triangles).into(), (&debug_info).into());
renderer.update_geometry((&triangles).into(), (&debug_info).into(), aabb);
let mut draw_config = DrawConfig::default();
let mut camera = Camera::new(&aabb);
@ -218,8 +218,11 @@ fn main() -> anyhow::Result<()> {
aabb = shape.bounding_volume();
faces.triangles(tolerance, &mut triangles, &mut debug_info);
renderer
.update_geometry((&triangles).into(), (&debug_info).into());
renderer.update_geometry(
(&triangles).into(),
(&debug_info).into(),
aabb,
);
}
Err(mpsc::TryRecvError::Empty) => {
// Nothing to receive from the channel. We don't care.