Check-in before switching to raw buffers
This commit is contained in:
parent
c8a030de46
commit
3c7d6ad2f4
22
src/model.rs
22
src/model.rs
@ -11,28 +11,22 @@ implement_vertex!(Vertex, position);
|
|||||||
|
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
vb: VertexBuffer<Vertex>,
|
vb: VertexBuffer<Vertex>,
|
||||||
ib: IndexBuffer<u16>,
|
ib: IndexBuffer<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Model {
|
impl Model {
|
||||||
pub fn new(display: &glium::Display, file: &str) -> Self {
|
pub fn new(display: &glium::Display, file: &str) -> Self {
|
||||||
let (document, buffers, _images) = gltf::import(file).expect("Could not load gltf file");
|
let (document, buffers, _images) = gltf::import(file).expect("Could not load gltf file");
|
||||||
let mesh = document.meshes().next().expect("Could not find mesh");
|
let mesh = document.meshes().next().unwrap();
|
||||||
let primitive = mesh.primitives().next().expect("Could not find primitive");
|
let primitive = mesh.primitives().next().unwrap();
|
||||||
let reader = primitive.reader(|buffer| Some(&buffers[buffer.index()]));
|
let reader = primitive.reader(|buffer| Some(&buffers[buffer.index()]));
|
||||||
let vertices = reader
|
|
||||||
.read_positions()
|
let vertices: Vec<Vertex> = reader.read_positions().unwrap().map(|position| Vertex{ position }).collect();
|
||||||
.unwrap()
|
|
||||||
.map(|position| Vertex { position })
|
|
||||||
.collect::<Vec<Vertex>>();
|
|
||||||
let vb = VertexBuffer::new(display, &vertices).unwrap();
|
let vb = VertexBuffer::new(display, &vertices).unwrap();
|
||||||
let indices = reader
|
|
||||||
.read_indices()
|
let indices: Vec<u32> = reader.read_indices().unwrap().into_u32().collect();
|
||||||
.unwrap()
|
|
||||||
.into_u32()
|
|
||||||
.map(|x| x as u16)
|
|
||||||
.collect::<Vec<u16>>();
|
|
||||||
let ib = IndexBuffer::new(display, glium::index::PrimitiveType::TrianglesList, &indices).unwrap();
|
let ib = IndexBuffer::new(display, glium::index::PrimitiveType::TrianglesList, &indices).unwrap();
|
||||||
|
|
||||||
Model { vb, ib }
|
Model { vb, ib }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user