mirror of
https://codeberg.org/icewind/vbsp.git
synced 2026-06-03 10:44:07 +02:00
basic triangulation for faces
This commit is contained in:
parent
fc945c828b
commit
e348934ec5
1 changed files with 16 additions and 0 deletions
16
src/lib.rs
16
src/lib.rs
|
|
@ -361,6 +361,22 @@ impl<'a> Handle<'a, Face> {
|
|||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Triangulate the face
|
||||
///
|
||||
/// Triangulation only works for faces that can be turned into a triangle fan trivially
|
||||
pub fn triangulate(&self) -> impl Iterator<Item = [Vector; 3]> + 'a {
|
||||
let mut vertices = self.vertices();
|
||||
|
||||
let a = vertices.next().expect("face with <3 points");
|
||||
let mut b = vertices.next().expect("face with <3 points");
|
||||
|
||||
vertices.map(move |c| {
|
||||
let points = [a.position, b.position, c.position];
|
||||
b = c;
|
||||
points
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Handle<'_, Node> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue