use crate::types::Triangle;
use std::io::{BufWriter, Result, Write};
pub fn write_stl<T, W, I>(writer: &mut W, mesh: I) -> Result<()>
where
W: Write,
I: ExactSizeIterator<Item = T>,
T: std::borrow::Borrow<Triangle>,
{
let mut writer = BufWriter::new(writer);
writer.write_all(&[0u8; 80])?;
writer.write_all(&(mesh.len() as u32).to_le_bytes())?;
for t in mesh {
let t = t.borrow();
for f in &t.normal.0 {
writer.write_all(&f.to_le_bytes())?;
}
for p in &t.vertices {
for c in &p.0 {
writer.write_all(&c.to_le_bytes())?;
}
}
writer.write_all(&0u16.to_le_bytes())?;
}
writer.flush()
}