wavefront_texturing/
wavefront-texturing.rs

1extern crate mash;
2
3type Vertex = mash::Vector;
4type Index = u32;
5
6type Model = mash::Model<Vertex, Index>;
7
8/// All information needed to render a door.
9pub struct Door {
10    name: String,
11    ambient_color: mash::Color,
12    model: Model,
13}
14
15fn main() {
16    let wavefront = mash::load::wavefront::from_path("res/world.obj").unwrap();
17
18    // Collect all doors from the model.
19    let doors: Vec<_> = wavefront.objects().filter_map(|obj| {
20        if obj.name().contains("door") {
21            let ambient_color = {
22                let material = obj.material().expect("object has no material");
23                material.ambient_color()
24            };
25
26            Some(Door {
27                ambient_color: ambient_color,
28                name: obj.name().to_owned(),
29                model: Model::new(obj).unwrap(),
30            })
31        } else {
32            None
33        }
34    }).collect();
35
36    for door in doors {
37        println!("found door named '{}' with ambient color {:?} and {} triangles",
38                 door.name, door.ambient_color, door.model.mesh.triangles().count());
39    }
40}
41