Skip to content

Commit

Permalink
support updating positions and normals for mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
wlgys8 committed Jan 28, 2024
1 parent a6cddda commit f1a3bc6
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/renderer/geometry/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,37 @@ impl Mesh {
pub fn set_animation(&mut self, animation: impl Fn(f32) -> Mat4 + Send + Sync + 'static) {
self.animation = Some(Box::new(animation));
}

/// Updates the vertex positions of the mesh.
///
/// # Panics
///
/// Panics if the number of positions does not match the number of vertices in the mesh.
pub fn update_positions(&mut self, positions: &[Vector3<f32>]) {
assert_eq!(
positions.len() as u32,
self.base_mesh.positions.vertex_count()
);
self.base_mesh.positions.fill(positions);
}

///
/// Updates the vertex normals of the mesh.
///
/// # Panics
///
/// Panics if the number of normals does not match the number of vertices in the mesh.
pub fn update_normals(&mut self, normals: &[Vector3<f32>]) {
assert_eq!(
normals.len() as u32,
self.base_mesh.positions.vertex_count()
);
if self.base_mesh.normals.is_none() {
self.base_mesh.normals = Some(VertexBuffer::new_with_data(&self.context, normals));
} else {
self.base_mesh.normals.as_mut().unwrap().fill(normals);
}
}
}

impl<'a> IntoIterator for &'a Mesh {
Expand Down

0 comments on commit f1a3bc6

Please sign in to comment.