Check-in before switching to raw buffers

This commit is contained in:
Dane Johnson 2022-04-08 13:31:02 -05:00
parent c8a030de46
commit 3c7d6ad2f4

View File

@ -11,28 +11,22 @@ implement_vertex!(Vertex, position);
pub struct Model {
vb: VertexBuffer<Vertex>,
ib: IndexBuffer<u16>,
ib: IndexBuffer<u32>,
}
impl Model {
pub fn new(display: &glium::Display, file: &str) -> Self {
let (document, buffers, _images) = gltf::import(file).expect("Could not load gltf file");
let mesh = document.meshes().next().expect("Could not find mesh");
let primitive = mesh.primitives().next().expect("Could not find primitive");
let mesh = document.meshes().next().unwrap();
let primitive = mesh.primitives().next().unwrap();
let reader = primitive.reader(|buffer| Some(&buffers[buffer.index()]));
let vertices = reader
.read_positions()
.unwrap()
.map(|position| Vertex { position })
.collect::<Vec<Vertex>>();
let vertices: Vec<Vertex> = reader.read_positions().unwrap().map(|position| Vertex{ position }).collect();
let vb = VertexBuffer::new(display, &vertices).unwrap();
let indices = reader
.read_indices()
.unwrap()
.into_u32()
.map(|x| x as u16)
.collect::<Vec<u16>>();
let indices: Vec<u32> = reader.read_indices().unwrap().into_u32().collect();
let ib = IndexBuffer::new(display, glium::index::PrimitiveType::TrianglesList, &indices).unwrap();
Model { vb, ib }
}