use oxideav_mesh3d::{Mesh3DDecoder, Result, Scene3D};
use crate::{mtl, obj};
#[derive(Debug, Default)]
pub struct ObjDecoder {
curve_tessellation_samples: u32,
}
impl ObjDecoder {
pub fn new() -> Self {
Self::default()
}
pub fn with_curve_tessellation(mut self, samples: u32) -> Self {
self.curve_tessellation_samples = samples;
self
}
}
impl Mesh3DDecoder for ObjDecoder {
fn decode(&mut self, bytes: &[u8]) -> Result<Scene3D> {
let text = std::str::from_utf8(bytes)
.map_err(|_| oxideav_mesh3d::Error::invalid("OBJ input contained non-UTF-8 bytes"))?;
let options = obj::ParseOptions {
curve_tessellation_samples: self.curve_tessellation_samples,
};
obj::parse_obj_with_options(text, &options, |_path| Ok(Vec::new()))
}
}
#[derive(Debug, Default)]
pub struct MtlDecoder {
_private: (),
}
impl MtlDecoder {
pub fn new() -> Self {
Self::default()
}
}
impl Mesh3DDecoder for MtlDecoder {
fn decode(&mut self, bytes: &[u8]) -> Result<Scene3D> {
let text = std::str::from_utf8(bytes)
.map_err(|_| oxideav_mesh3d::Error::invalid("MTL input contained non-UTF-8 bytes"))?;
mtl::parse_mtl_with_scene(text)
}
}