diff --git a/TODO.md b/TODO.md index 9a4ff76..b6f5eb1 100644 --- a/TODO.md +++ b/TODO.md @@ -89,6 +89,6 @@ - [ ] Make post processing async - [ ] Instance meshes in save files / rendering - [x] Allow recalculating normals -- [ ] Alert when model with invalid normals is loaded - [ ] Cleanup self intersection resolution - [ ] Dont fail to load an stl without normals +- [ ] Dont clone all verts and faces to recompute normals. Just add another Arc? diff --git a/mslicer/src/app/mod.rs b/mslicer/src/app/mod.rs index 374c2cc..8e8d625 100644 --- a/mslicer/src/app/mod.rs +++ b/mslicer/src/app/mod.rs @@ -180,7 +180,7 @@ impl App { } pub fn load_mesh(&mut self, buf: &mut T, format: &str, name: String) { - let model = match slicer::mesh::load_mesh(buf, format) { + let mut model = match slicer::mesh::load_mesh(buf, format) { Ok(model) => model, Err(err) => { self.popup.open(Popup::simple( @@ -193,11 +193,16 @@ impl App { }; info!("Loaded model `{name}` with {} faces", model.face_count()); - self.meshes.write().push( - RenderedMesh::from_mesh(model) - .with_name(name) - .with_random_color(), - ); + if model.normals().iter().any(|x| x.magnitude_squared() == 0.0) { + warn!("Model `{name}` has invalid normals. Recomputing."); + model.recompute_normals(); + } + + let rendered_mesh = RenderedMesh::from_mesh(model) + .with_name(name.clone()) + .with_random_color(); + + self.meshes.write().push(rendered_mesh); } }