use crate::{ResourceLoader, LoaderError, Mesh}; impl From for LoaderError { fn from(value: gltf::Error) -> Self { LoaderError::DecodingError(value.into()) } } #[derive(Default)] pub struct ModelLoader; impl ModelLoader { fn process_node(&self, views: Vec>, node: gltf::Node<'_>) -> Vec { let mut meshes = vec![]; if let Some(mesh) = node.mesh() { for prim in mesh.primitives() { let pos_accessor = prim.get(&gltf::Semantic::Positions).unwrap(); let mut new_mesh = Mesh::default(); assert_eq!(pos_accessor.dimensions(), gltf::accessor::Dimensions::Vec3); // TODO: dont do this let view = pos_accessor.view().unwrap(); // TODO: handle sparse Accessor let stride = view.stride().unwrap_or(0); // if stride is None, its tightly packed let offset = view.offset(); let buffer = view.buffer(); let buf_len = buffer.length(); let view = views.iter().next().unwrap(); //gltf.views() //vertices.data_type() == gltf:: //new_mesh.vertices = vertices.; if let Some(indicies) = prim.indices() { } } //meshes.push(mesh); } for child in node.children() { let mut child_meshes = self.process_node(node); meshes.append(&mut child_meshes); } todo!() } } impl ResourceLoader for ModelLoader { fn extensions(&self) -> &[&str] { &[ "gltf" ] } fn load(&self, path: &str) -> Result, crate::LoaderError> { // check if the file is supported by this loader if !self.does_support_file(path) { return Err(LoaderError::UnsupportedExtension(path.to_string())); } let gltf = gltf::Gltf::open(path)?; let buffers: Vec> = gltf.buffers().collect(); // TODO: Read in multiple scenes let scene = gltf.scenes().next().unwrap(); for node in scene.nodes() { } todo!() } }