6 use glium::{self, Display};
7 use glium::vertex::VertexBufferAny;
17 pub fn start_loop<F>(mut callback: F) where F: FnMut() -> Action {
20 Action::Stop => break,
21 Action::Continue => ()
26 /// Returns a vertex buffer that should be rendered as `TrianglesList`.
27 pub fn load_wavefront(display: &Display, data: &[u8]) -> VertexBufferAny {
28 #[derive(Copy, Clone)]
35 implement_vertex!(Vertex, position, normal, texture);
37 let mut data = ::std::io::BufReader::new(data);
38 let data = obj::Obj::load(&mut data);
40 let mut vertex_data = Vec::new();
42 for object in data.object_iter() {
43 for shape in object.group_iter().flat_map(|g| g.indices().iter()) {
45 &genmesh::Polygon::PolyTri(genmesh::Triangle { x: v1, y: v2, z: v3 }) => {
46 for v in [v1, v2, v3].iter() {
47 let position = data.position()[v.0];
48 let texture = v.1.map(|index| data.texture()[index]);
49 let normal = v.2.map(|index| data.normal()[index]);
51 let texture = texture.unwrap_or([0.0, 0.0]);
52 let normal = normal.unwrap_or([0.0, 0.0, 0.0]);
54 vertex_data.push(Vertex {
66 glium::vertex::VertexBuffer::new(display, &vertex_data).unwrap().into_vertex_buffer_any()