Struct Model

Source
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>

Source

pub fn empty() -> Self

Creates an empty mesh.

Source

pub fn new<F>(builder: F) -> Result<Self, Error>
where F: BuildModel, V: From<F::Vertex>,

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
Hide additional 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§

Source§

impl<V: Clone + Vertex, I: Clone + Index> Clone for Model<V, I>

Source§

fn clone(&self) -> Model<V, I>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<V: Debug + Vertex, I: Debug + Index> Debug for Model<V, I>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<V: PartialEq + Vertex, I: PartialEq + Index> PartialEq for Model<V, I>

Source§

fn eq(&self, other: &Model<V, I>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<V: Eq + Vertex, I: Eq + Index> Eq for Model<V, I>

Source§

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>

§

impl<V, I> Send for Model<V, I>
where V: Send, I: Send,

§

impl<V, I> Sync for Model<V, I>
where V: Sync, I: Sync,

§

impl<V, I> Unpin for Model<V, I>
where V: Unpin, I: Unpin,

§

impl<V, I> UnwindSafe for Model<V, I>
where V: UnwindSafe, I: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.