Continue working on gltf loader
This commit is contained in:
parent
38e7b543c0
commit
dddf6123c4
|
@ -1,4 +1,4 @@
|
|||
use crate::{ResourceLoader, LoaderError};
|
||||
use crate::{ResourceLoader, LoaderError, Mesh};
|
||||
|
||||
impl From<gltf::Error> for LoaderError {
|
||||
fn from(value: gltf::Error) -> Self {
|
||||
|
@ -9,6 +9,44 @@ impl From<gltf::Error> for LoaderError {
|
|||
#[derive(Default)]
|
||||
pub struct ModelLoader;
|
||||
|
||||
impl ModelLoader {
|
||||
fn process_node(&self, views: Vec<gltf::buffer::View<'_>>, node: gltf::Node<'_>) -> Vec<Mesh> {
|
||||
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::Buffer<'_>> = gltf.buffers().collect();
|
||||
|
||||
// TODO: Read in multiple scenes
|
||||
let scene = gltf.scenes().next().unwrap();
|
||||
for node in scene.nodes() {
|
||||
|
||||
}
|
||||
|
||||
todo!()
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ pub struct Vertex {
|
|||
pub tex_coords: [f32; 2]
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Mesh {
|
||||
pub vertices: Vec<Vertex>,
|
||||
pub indices: Option<Vec<u16>>,
|
||||
|
|
Loading…
Reference in New Issue