Struct TriangularMesh

Source
pub struct TriangularMesh<V: Vertex, I: Index> {
    pub vertices: Vec<V>,
    pub indices: Vec<I>,
}
Expand description

A triangular mesh.

Fields§

§vertices: Vec<V>

The vertex list.

§indices: Vec<I>

The index list.

Implementations§

Source§

impl<V: Vertex, I: Index> TriangularMesh<V, I>

Source

pub fn empty() -> Self

Creates an empty triangular mesh.

Source

pub fn triangles(&self) -> Triangles<'_, V, I>

Gets all of the triangles in a mesh.

Examples found in repository?
examples/wavefront-lighthouse.rs (line 26)
21fn print_information(name: &str, model: &Model) {
22    println!("{}", name);
23    println!("-----------------------------");
24    println!("vertices: {}", model.mesh.vertices.len());
25    println!("indices: {}", model.mesh.indices.len());
26    println!("triangles: {}", model.mesh.triangles().count());
27    println!("");
28}
More examples
Hide additional examples
examples/wavefront-texturing.rs (line 38)
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 28)
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 TriangularMesh<V, I>

Source§

fn clone(&self) -> TriangularMesh<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: Vertex, I: Index> Debug for TriangularMesh<V, I>

Source§

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

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

impl<V, I> FromIterator<Triangle<V>> for TriangularMesh<V, I>
where V: Vertex, I: Index,

Source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = Triangle<V>>,

Creates a value from an iterator. Read more
Source§

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

Source§

fn eq(&self, other: &TriangularMesh<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 TriangularMesh<V, I>

Source§

impl<V: Vertex, I: Index> StructuralPartialEq for TriangularMesh<V, I>

Auto Trait Implementations§

§

impl<V, I> Freeze for TriangularMesh<V, I>

§

impl<V, I> RefUnwindSafe for TriangularMesh<V, I>

§

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

§

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

§

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

§

impl<V, I> UnwindSafe for TriangularMesh<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.