use axiolid_core::Point3;
use crate::TriMesh;
pub trait MeshView {
fn positions(&self) -> &[Point3];
fn indices(&self) -> &[u32];
}
impl MeshView for TriMesh {
fn positions(&self) -> &[Point3] {
&self.positions
}
fn indices(&self) -> &[u32] {
&self.indices
}
}
pub trait TriangleMeshView {
fn position_count(&self) -> usize;
fn position(&self, index: usize) -> Point3;
fn triangle_count(&self) -> usize;
fn triangle(&self, index: usize) -> [u64; 3];
}
impl TriangleMeshView for TriMesh {
fn position_count(&self) -> usize {
self.positions.len()
}
fn position(&self, index: usize) -> Point3 {
self.positions[index]
}
fn triangle_count(&self) -> usize {
self.triangle_count()
}
fn triangle(&self, index: usize) -> [u64; 3] {
let triangle: [u32; 3] = self.indices[index * 3..index * 3 + 3]
.try_into()
.expect("triangle_count only exposes complete triples");
triangle.map(u64::from)
}
}