Recompute normals if they are invalid

This commit is contained in:
Connor Slade
2025-02-10 11:39:04 -05:00
parent 5edbc23c2b
commit 21d3edf6a2
2 changed files with 12 additions and 7 deletions

View File

@@ -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?

View File

@@ -180,7 +180,7 @@ impl App {
}
pub fn load_mesh<T: BufRead + Seek>(&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);
}
}