diff --git a/lyra-resource/src/loader/model.rs b/lyra-resource/src/loader/model.rs index 83197fc..9b2bc92 100644 --- a/lyra-resource/src/loader/model.rs +++ b/lyra-resource/src/loader/model.rs @@ -1,4 +1,4 @@ -use crate::{ResourceLoader, LoaderError}; +use crate::{ResourceLoader, LoaderError, Mesh}; impl From for LoaderError { fn from(value: gltf::Error) -> Self { @@ -9,6 +9,44 @@ impl From for LoaderError { #[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] { &[ @@ -24,6 +62,14 @@ impl ResourceLoader for ModelLoader { 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!() } } \ No newline at end of file diff --git a/lyra-resource/src/model.rs b/lyra-resource/src/model.rs index f8c0344..1f8d40d 100644 --- a/lyra-resource/src/model.rs +++ b/lyra-resource/src/model.rs @@ -6,7 +6,7 @@ pub struct Vertex { pub tex_coords: [f32; 2] } -#[derive(Clone)] +#[derive(Clone, Default)] pub struct Mesh { pub vertices: Vec, pub indices: Option>,