parry3d/transformation/to_trimesh/
heightfield_to_trimesh.rs

1use crate::math::Vector3;
2use crate::shape::HeightField;
3use alloc::vec::Vec;
4
5impl HeightField {
6    /// Discretize the boundary of this heightfield as a triangle-mesh.
7    pub fn to_trimesh(&self) -> (Vec<Vector3>, Vec<[u32; 3]>) {
8        let mut vertices = Vec::new();
9        let mut indices = Vec::new();
10
11        for (i, tri) in self.triangles().enumerate() {
12            vertices.push(tri.a);
13            vertices.push(tri.b);
14            vertices.push(tri.c);
15
16            let i = i as u32;
17            indices.push([i * 3, i * 3 + 1, i * 3 + 2])
18        }
19
20        (vertices, indices)
21    }
22}