parry3d/transformation/to_trimesh/
convex_polyhedron_to_trimesh.rs

1use crate::math::Vector3;
2use crate::shape::ConvexPolyhedron;
3use alloc::vec::Vec;
4
5impl ConvexPolyhedron {
6    /// Discretize the boundary of this convex polyhedron as a triangle-mesh.
7    pub fn to_trimesh(&self) -> (Vec<Vector3>, Vec<[u32; 3]>) {
8        let mut indices = Vec::new();
9
10        for face in self.faces() {
11            let i1 = face.first_vertex_or_edge;
12            let i2 = i1 + face.num_vertices_or_edges;
13            let first_id = self.vertices_adj_to_face()[i1 as usize];
14
15            for idx in self.vertices_adj_to_face()[i1 as usize + 1..i2 as usize].windows(2) {
16                indices.push([first_id, idx[0], idx[1]]);
17            }
18        }
19
20        (self.points().to_vec(), indices)
21    }
22}