wavefront_world/
wavefront-world.rs

1extern crate mash;
2
3use mash::load;
4
5type Vertex = mash::Vector;
6type Index = u32;
7type Model = mash::Model<Vertex, Index>;
8
9fn main() {
10    // Load the shape into a wavefront-specific data structure.
11    let world = load::wavefront::from_path("res/world.obj").unwrap();
12
13    // Rather than converting the entire world into a single model, let's extract
14    // every object labelled 'door'.
15    let doors: Vec<Model> = world.objects().filter(|o| o.name().contains("door")).map(|object| {
16        // Convert each object into its own mesh.
17        Model::new(object).unwrap()
18    }).collect();
19
20    for door in doors {
21        println!("door model: {:?}", door);
22    }
23
24    // We can also load the entire world into a single model if we wanted.
25    let entire_world = Model::new(world).unwrap();
26
27    // Skip every second triangle if that's your kind of thing.
28    let half_triangles = entire_world.mesh.triangles().enumerate().filter(|&(idx,_)| idx%2 == 0).map(|(_,t)| t);
29    let half_world: Model = Model { mesh: half_triangles.collect() };
30
31    println!("half world: {:?}", half_world);
32}
33