fix(obj): concave OBJ faces are triangulated, not fanned

A fan only covers convex faces; architectural n-gons filled well outside
their outline (the sample's faces covered 63% extra area).

Fixes #680

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Hakan SevenandClaude Opus 5.5 committed 2026-09-28 19:33:40 +03:00
1 parent b66b5100bd
commit 4c1ddec646
2 files changed
+35 -6

No files matched your search

+10 -1
View File
@@ -16,6 +16,15 @@ use crate::t;
/// Triangulate a planar polygon through the kernel.
pub(crate) fn triangulate_planar(poly: &[[f64; 3]]) -> Vec<[f64; 3]> {
triangulate_planar_indices(poly)
.into_iter()
.flat_map(|triangle| triangle.map(|index| poly[index]))
.collect()
}
/// Triangles of a planar polygon as indices into `poly` — for callers that
/// carry per-vertex data (normals) alongside the positions.
pub(crate) fn triangulate_planar_indices(poly: &[[f64; 3]]) -> Vec<[usize; 3]> {
if poly.len() < 3 {
return Vec::new();
}
@@ -51,7 +60,7 @@ pub(crate) fn triangulate_planar(poly: &[[f64; 3]]) -> Vec<[f64; 3]> {
}
triangles
.into_iter()
.flat_map(|triangle| triangle.map(|index| poly[source[index]]))
.map(|triangle| triangle.map(|index| source[index]))
.collect()
}