use crate::vector::Vector3;

mod block_mesher;
mod chunk_mesher;

#[derive(Default, Debug)]
pub struct Mesh {
    positions: Vec<Vector3<f32>>,
    normals: Vec<Vector3<f32>>,
}

#[repr(C)]
pub struct PosNorm {
    pos: [f32; 4],
    norm: [f32; 4],
}

impl PosNorm {
    fn new(pos: Vector3<f32>, norm: Vector3<f32>) -> Self {
        Self {
            pos: [pos.x, pos.y, pos.z, 1.0],
            norm: [norm.x, norm.y, norm.z, 0.0],
        }
    }
}

impl Mesh {
    pub fn to_buffer(self) -> Vec<PosNorm> {
        let Self { positions, normals } = self;
        positions
            .into_iter()
            .zip(normals.into_iter())
            .map(|(p, n)| PosNorm::new(p, n))
            .collect()
    }

    pub fn num_vert(&self) -> usize {
        self.positions.len()
    }
}
