1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use crate::math::Vect;
use rapier::parry::shape::{TopologyError, TriMesh, TriMeshFlags};
pub struct TriMeshView<'a> {
pub raw: &'a TriMesh,
}
macro_rules! impl_ref_methods(
($View: ident) => {
impl<'a> $View<'a> {
pub fn num_triangles(&self) -> usize {
self.raw.num_triangles()
}
pub fn triangles(&self) -> impl ExactSizeIterator<Item = (Vect, Vect, Vect)> + '_ {
self.raw
.triangles()
.map(|tri| (tri.a.into(), tri.b.into(), tri.c.into()))
}
pub fn triangle(&self, i: u32) -> (Vect, Vect, Vect) {
let tri = self.raw.triangle(i);
(tri.a.into(), tri.b.into(), tri.c.into())
}
pub fn vertices(&self) -> impl ExactSizeIterator<Item = Vect> + '_ {
self.raw.vertices().iter().map(|pt| (*pt).into())
}
pub fn indices(&self) -> &[[u32; 3]] {
self.raw.indices()
}
pub fn flat_indices(&self) -> &[u32] {
self.raw.flat_indices()
}
}
}
);
impl_ref_methods!(TriMeshView);
pub struct TriMeshViewMut<'a> {
pub raw: &'a mut TriMesh,
}
impl_ref_methods!(TriMeshViewMut);
impl<'a> TriMeshViewMut<'a> {
pub fn set_flags(&mut self, flags: TriMeshFlags) -> Result<(), TopologyError> {
self.raw.set_flags(flags)
}
}