forked from 1b-agent/opencadstudio-upstream
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:
1 parent
b66b5100bd
commit
4c1ddec646
2 files changed
+35
-6
No files matched your search
+10
-1
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user