mod face;
mod inclusion;
mod obj;
mod ply;
mod stl;
mod units;
#[cfg(test)]
pub mod fixtures;
#[cfg(test)]
pub use self::obj::{parse_obj_mesh, parse_obj_noted};
pub use self::{
inclusion::{
NOT_A_MESH_ROUGH, add_inclusion, including_text, inclusion_in_rough_frame, inclusion_parts,
inclusion_row_text, parse_margin_mm,
},
units::MeshUnit,
};
use glam::DVec3;
use indicatrix_cut_core::rough_plan::MeshError;
pub type NotedMesh = (Vec<DVec3>, Vec<[u32; 3]>, Option<String>);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MeshFormat {
Obj,
Stl,
Ply,
}
pub fn too_many_triangles_note(count: usize) -> String {
format!(
"The mesh could not be used as it is ({}); its convex outline is used instead.",
MeshError::TooManyTriangles(count)
)
}
pub fn detect_format(bytes: &[u8], extension: Option<&str>) -> MeshFormat {
if bytes.starts_with(b"ply\n") || bytes.starts_with(b"ply\r") {
return MeshFormat::Ply;
}
match extension.map(str::to_ascii_lowercase).as_deref() {
Some("obj") => MeshFormat::Obj,
Some("stl") => MeshFormat::Stl,
Some("ply") => MeshFormat::Ply,
_ if stl::looks_like_stl(bytes) => MeshFormat::Stl,
_ => MeshFormat::Obj,
}
}
pub fn parse_mesh(bytes: &[u8], extension: Option<&str>) -> Result<NotedMesh, String> {
match detect_format(bytes, extension) {
MeshFormat::Obj => obj::parse_obj_noted(&String::from_utf8_lossy(bytes)),
MeshFormat::Stl => stl::parse_stl(bytes),
MeshFormat::Ply => ply::parse_ply(bytes),
}
}
#[cfg(test)]
mod tests;