cgmath = "*"
glium = "0.16.0"
glutin = "0.7.4"
-genmesh = "0.4.1"
image = { version = "0.14.0", features = ["png_codec"], optional = true }
libxm = "1.0.0"
-obj = { version = "0.5", features = ["usegenmesh"] }
rust-rocket = { path = "rust-rocket", optional = true }
rand = "*"
sdl2 = "*"
#![allow(dead_code)]
-extern crate genmesh;
-extern crate obj;
-
use glium::{self, Display};
use glium::vertex::VertexBufferAny;
};
}
}
-
-/// Returns a vertex buffer that should be rendered as `TrianglesList`.
-pub fn load_wavefront(display: &Display, data: &[u8]) -> VertexBufferAny {
- #[derive(Copy, Clone)]
- struct Vertex {
- position: [f32; 3],
- normal: [f32; 3],
- texture: [f32; 2],
- }
-
- implement_vertex!(Vertex, position, normal, texture);
-
- let mut data = ::std::io::BufReader::new(data);
- let data = obj::Obj::load(&mut data);
-
- let mut vertex_data = Vec::new();
-
- for object in data.object_iter() {
- for shape in object.group_iter().flat_map(|g| g.indices().iter()) {
- match shape {
- &genmesh::Polygon::PolyTri(genmesh::Triangle { x: v1, y: v2, z: v3 }) => {
- for v in [v1, v2, v3].iter() {
- let position = data.position()[v.0];
- let texture = v.1.map(|index| data.texture()[index]);
- let normal = v.2.map(|index| data.normal()[index]);
-
- let texture = texture.unwrap_or([0.0, 0.0]);
- let normal = normal.unwrap_or([0.0, 0.0, 0.0]);
-
- vertex_data.push(Vertex {
- position: position,
- normal: normal,
- texture: texture,
- })
- }
- },
- _ => unimplemented!()
- }
- }
- }
-
- glium::vertex::VertexBuffer::new(display, &vertex_data).unwrap().into_vertex_buffer_any()
-}