Make use of Vertices more explicit

This commit is contained in:
Hanno Braun 2025-03-19 20:44:24 +01:00
parent b3e765373e
commit 3a21d86393
3 changed files with 13 additions and 13 deletions

View File

@ -18,6 +18,7 @@ pub use self::{
device::DeviceError,
draw_config::DrawConfig,
renderer::{Renderer, RendererInitError},
vertices::Vertices,
};
pub const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float;

View File

@ -17,17 +17,7 @@ impl Vertices {
}
}
pub fn vertices(&self) -> &[Vertex] {
self.vertices.as_slice()
}
pub fn indices(&self) -> &[Index] {
self.indices.as_slice()
}
}
impl From<&Mesh<fj_math::Point<3>>> for Vertices {
fn from(mesh: &Mesh<fj_math::Point<3>>) -> Self {
pub fn from_mesh(mesh: &Mesh<fj_math::Point<3>>) -> Self {
let mut vertices = Vec::new();
let mut indices = Vec::new();
let mut indices_by_vertex = BTreeMap::new();
@ -59,6 +49,14 @@ impl From<&Mesh<fj_math::Point<3>>> for Vertices {
Self { vertices, indices }
}
pub fn vertices(&self) -> &[Vertex] {
self.vertices.as_slice()
}
pub fn indices(&self) -> &[Index] {
self.indices.as_slice()
}
}
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]

View File

@ -5,7 +5,7 @@ use tracing::warn;
use crate::{
RendererInitError,
camera::{Camera, FocusPoint},
graphics::{DrawConfig, Renderer},
graphics::{DrawConfig, Renderer, Vertices},
input::{
CameraTuningConfig, DEFAULT_CAMERA_TUNING_CONFIG, InputEvent,
MouseButton,
@ -58,7 +58,8 @@ impl Viewer {
/// Handle the model being updated
pub fn handle_model_update(&mut self, model: Model) {
self.renderer.update_geometry((&model.mesh).into());
self.renderer
.update_geometry(Vertices::from_mesh(&model.mesh));
let aabb = model.mesh.aabb();
if self.model.replace((model, aabb)).is_none() {