pub struct Model<V: Vertex, I: Index> {
pub mesh: TriangularMesh<V, I>,
}
Expand description
A 3D model.
Fields§
§mesh: TriangularMesh<V, I>
The mesh that makes up the model.
Implementations§
Source§impl<V: Vertex, I: Index> Model<V, I>
impl<V: Vertex, I: Index> Model<V, I>
Sourcepub fn new<F>(builder: F) -> Result<Self, Error>
pub fn new<F>(builder: F) -> Result<Self, Error>
Creates a new model.
Examples found in repository?
examples/wavefront-lighthouse.rs (line 14)
8fn main() {
9 let wavefront = mash::load::wavefront::from_path("res/lighthouse.obj").unwrap();
10
11 let pylon_obj = wavefront.objects().find(|o| o.name() == "pylon_rectangle").unwrap();
12 let lights_obj = wavefront.objects().find(|o| o.name() == "rotating_lights_cylinder").unwrap();
13
14 let pylon = Model::new(pylon_obj).unwrap();
15 let lights = Model::new(lights_obj).unwrap();
16
17 print_information("pylon", &pylon);
18 print_information("lights", &lights);
19}
More examples
examples/wavefront-texturing.rs (line 29)
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}
examples/wavefront-world.rs (line 17)
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}
Trait Implementations§
impl<V: Eq + Vertex, I: Eq + Index> Eq for Model<V, I>
impl<V: Vertex, I: Index> StructuralPartialEq for Model<V, I>
Auto Trait Implementations§
impl<V, I> Freeze for Model<V, I>
impl<V, I> RefUnwindSafe for Model<V, I>where
V: RefUnwindSafe,
I: RefUnwindSafe,
impl<V, I> Send for Model<V, I>
impl<V, I> Sync for Model<V, I>
impl<V, I> Unpin for Model<V, I>
impl<V, I> UnwindSafe for Model<V, I>where
V: UnwindSafe,
I: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more