parry3d/transformation/to_trimesh/
convex_polyhedron_to_trimesh.rs

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