block_mesh/
buffer.rs

1use crate::{UnorientedQuad, UnorientedUnitQuad};
2
3#[derive(Default)]
4pub struct QuadBuffer {
5    /// A group of quads for each block face. We rely on [`OrientedBlockFace`]
6    /// metadata to interpret them.
7    pub groups: [Vec<UnorientedQuad>; 6],
8}
9
10impl QuadBuffer {
11    pub fn new() -> Self {
12        const EMPTY: Vec<UnorientedQuad> = Vec::new();
13        Self { groups: [EMPTY; 6] }
14    }
15
16    pub fn reset(&mut self) {
17        for group in self.groups.iter_mut() {
18            group.clear();
19        }
20    }
21
22    /// Returns the total count of quads across all groups.
23    pub fn num_quads(&self) -> usize {
24        let mut sum = 0;
25        for group in self.groups.iter() {
26            sum += group.len();
27        }
28        sum
29    }
30}
31
32#[derive(Default)]
33pub struct UnitQuadBuffer {
34    /// A group of quads for each block face. We rely on [`OrientedBlockFace`]
35    /// metadata to interpret them.
36    ///
37    /// When using these values for materials and lighting, you can access them
38    /// using either the quad's minimum voxel coordinates or the vertex
39    /// coordinates given by [`OrientedBlockFace::quad_corners`].
40    pub groups: [Vec<UnorientedUnitQuad>; 6],
41}
42
43impl UnitQuadBuffer {
44    pub fn new() -> Self {
45        const EMPTY: Vec<UnorientedUnitQuad> = Vec::new();
46        Self { groups: [EMPTY; 6] }
47    }
48
49    /// Clears the buffer.
50    pub fn reset(&mut self) {
51        for group in self.groups.iter_mut() {
52            group.clear();
53        }
54    }
55
56    /// Returns the total count of quads across all groups.
57    pub fn num_quads(&self) -> usize {
58        let mut sum = 0;
59        for group in self.groups.iter() {
60            sum += group.len();
61        }
62        sum
63    }
64}