Struct Object

Source
pub struct Object<'a> { /* private fields */ }
Expand description

A named object in a Wavefront file.

Implementations§

Source§

impl<'a> Object<'a>

Source

pub fn name(&self) -> &str

Gets the name of the object.

Examples found in repository?
examples/wavefront-lighthouse.rs (line 11)
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
Hide additional examples
examples/wavefront-texturing.rs (line 20)
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 15)
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}
Source

pub fn material(&self) -> Option<Material<'_>>

Gets the material associated with the object.

Examples found in repository?
examples/wavefront-texturing.rs (line 22)
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}

Trait Implementations§

Source§

impl<'a> BuildModel for Object<'a>

Source§

type Vertex = Vertex

The vertex type that we need to convert from.
Source§

fn build_model<V, I>(self) -> Result<Model<V, I>, Error>
where V: Vertex + From<Vertex>, I: Index,

Auto Trait Implementations§

§

impl<'a> Freeze for Object<'a>

§

impl<'a> RefUnwindSafe for Object<'a>

§

impl<'a> Send for Object<'a>

§

impl<'a> Sync for Object<'a>

§

impl<'a> Unpin for Object<'a>

§

impl<'a> UnwindSafe for Object<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.