meshopt_rs/vertex/
mod.rs

1pub mod buffer;
2pub mod cache;
3pub mod fetch;
4pub mod filter;
5
6#[derive(Debug)]
7pub enum DecodeError {
8    InvalidHeader,
9    UnsupportedVersion,
10    ExtraBytes,
11    UnexpectedEof,
12}
13
14pub enum VertexEncodingVersion {
15    /// Decodable by all versions
16    V0,
17}
18
19impl Default for VertexEncodingVersion {
20    fn default() -> Self {
21        Self::V0
22    }
23}
24
25impl Into<u8> for VertexEncodingVersion {
26    fn into(self) -> u8 {
27        match self {
28            Self::V0 => 0,
29        }
30    }
31}
32
33pub trait Position {
34    fn pos(&self) -> [f32; 3];
35}
36
37impl Position for [f32; 3] {
38    #[inline]
39    fn pos(&self) -> [f32; 3] {
40        *self
41    }
42}
43
44pub(crate) fn calc_pos_extents<Vertex>(vertices: &[Vertex]) -> ([f32; 3], f32)
45where
46    Vertex: Position,
47{
48    let mut minv = [f32::MAX; 3];
49    let mut maxv = [-f32::MAX; 3];
50
51    for vertex in vertices {
52        let v = vertex.pos();
53
54        for j in 0..3 {
55            minv[j] = minv[j].min(v[j]);
56            maxv[j] = maxv[j].max(v[j]);
57        }
58    }
59
60    let extent = (maxv[0] - minv[0]).max(maxv[1] - minv[1]).max(maxv[2] - minv[2]);
61
62    (minv, extent)
63}