1use axiolid_core::Point3;
4
5use crate::TriMesh;
6
7pub trait MeshView {
12 fn positions(&self) -> &[Point3];
14 fn indices(&self) -> &[u32];
16}
17
18impl MeshView for TriMesh {
19 fn positions(&self) -> &[Point3] {
20 &self.positions
21 }
22
23 fn indices(&self) -> &[u32] {
24 &self.indices
25 }
26}
27
28pub trait TriangleMeshView {
34 fn position_count(&self) -> usize;
36 fn position(&self, index: usize) -> Point3;
38 fn triangle_count(&self) -> usize;
40 fn triangle(&self, index: usize) -> [u64; 3];
42}
43
44impl TriangleMeshView for TriMesh {
45 fn position_count(&self) -> usize {
46 self.positions.len()
47 }
48
49 fn position(&self, index: usize) -> Point3 {
50 self.positions[index]
51 }
52
53 fn triangle_count(&self) -> usize {
54 self.triangle_count()
55 }
56
57 fn triangle(&self, index: usize) -> [u64; 3] {
58 let triangle: [u32; 3] = self.indices[index * 3..index * 3 + 3]
59 .try_into()
60 .expect("triangle_count only exposes complete triples");
61 triangle.map(u64::from)
62 }
63}