Recompute normals if they are invalid
This commit is contained in:
2
TODO.md
2
TODO.md
@@ -89,6 +89,6 @@
|
|||||||
- [ ] Make post processing async
|
- [ ] Make post processing async
|
||||||
- [ ] Instance meshes in save files / rendering
|
- [ ] Instance meshes in save files / rendering
|
||||||
- [x] Allow recalculating normals
|
- [x] Allow recalculating normals
|
||||||
- [ ] Alert when model with invalid normals is loaded
|
|
||||||
- [ ] Cleanup self intersection resolution
|
- [ ] Cleanup self intersection resolution
|
||||||
- [ ] Dont fail to load an stl without normals
|
- [ ] Dont fail to load an stl without normals
|
||||||
|
- [ ] Dont clone all verts and faces to recompute normals. Just add another Arc?
|
||||||
|
@@ -180,7 +180,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_mesh<T: BufRead + Seek>(&mut self, buf: &mut T, format: &str, name: String) {
|
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,
|
Ok(model) => model,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.popup.open(Popup::simple(
|
self.popup.open(Popup::simple(
|
||||||
@@ -193,11 +193,16 @@ impl App {
|
|||||||
};
|
};
|
||||||
info!("Loaded model `{name}` with {} faces", model.face_count());
|
info!("Loaded model `{name}` with {} faces", model.face_count());
|
||||||
|
|
||||||
self.meshes.write().push(
|
if model.normals().iter().any(|x| x.magnitude_squared() == 0.0) {
|
||||||
RenderedMesh::from_mesh(model)
|
warn!("Model `{name}` has invalid normals. Recomputing.");
|
||||||
.with_name(name)
|
model.recompute_normals();
|
||||||
.with_random_color(),
|
}
|
||||||
);
|
|
||||||
|
let rendered_mesh = RenderedMesh::from_mesh(model)
|
||||||
|
.with_name(name.clone())
|
||||||
|
.with_random_color();
|
||||||
|
|
||||||
|
self.meshes.write().push(rendered_mesh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user