[][src]Struct easy_gltf::Model

pub struct Model { /* fields omitted */ }

Geometry to be rendered with the given material.

Examples

Classic rendering

In most cases you want to use triangles(), lines() and points() to get the geometry of the model.

match model.mode() {
  Mode::Triangles | Mode::TriangleFan | Mode::TriangleStrip => {
    let triangles = model.triangles().unwrap();
    // Render triangles...
  },
  Mode::Lines | Mode::LineLoop | Mode::LineStrip => {
    let lines = model.lines().unwrap();
    // Render lines...
  }
  Mode::Points => {
    let points = model.points().unwrap();
    // Render points...
  }
}

OpenGL style rendering

You will need the vertices and the indices if existing.

let vertices = model. vertices();
let indices = model.indices();
match model.mode() {
  Mode::Triangles => {
    if let Some(indices) = indices.as_ref() {
      // glDrawElements(GL_TRIANGLES, indices.len(), GL_UNSIGNED_INT, 0);
    } else {
      // glDrawArrays(GL_TRIANGLES, 0, vertices.len());
    }
  },
  // ...
}

Implementations

impl Model[src]

pub fn material(&self) -> Arc<Material>[src]

Material to apply to the whole model.

pub fn vertices(&self) -> &Vec<Vertex>[src]

List of raw vertices of the model. You might have to use the indices to render the model.

Note: If you're not rendering with OpenGL you probably want to use triangles(), lines() or points() instead.

pub fn indices(&self) -> Option<&Vec<usize>>[src]

Potential list of indices to render the model using raw vertices.

Note: If you're not rendering with OpenGL you probably want to use triangles(), lines() or points() instead.

pub fn mode(&self) -> Mode[src]

The type of primitive to render. You have to check the mode to render the model correctly.

Then you can either use:

  • vertices() and indices() to arrange the data yourself (useful for OpenGL).
  • triangles() or lines() or points() according to the returned mode.

pub fn triangles(&self) -> Result<Vec<Triangle>, BadMode>[src]

List of triangles ready to be rendered.

Note: This function will return an error if the mode isn't Triangles, TriangleFan or TriangleStrip.

pub fn lines(&self) -> Result<Vec<Line>, BadMode>[src]

List of lines ready to be rendered.

Note: This function will return an error if the mode isn't Lines, LineLoop or LineStrip.

pub fn points(&self) -> Result<&Vec<Vertex>, BadMode>[src]

List of points ready to be renderer.

Note: This function will return an error if the mode isn't Points.

pub fn has_normals(&self) -> bool[src]

Indicate if the vertices contains normal information.

Note: If this function return false all vertices has a normal field initialized to zero.

pub fn has_tangents(&self) -> bool[src]

Indicate if the vertices contains tangents information.

Note: If this function return false all vertices has a tangent field initialized to zero.

pub fn has_tex_coords(&self) -> bool[src]

Indicate if the vertices contains texture coordinates information.

Note: If this function return false all vertices has a tex_coord field initialized to zero.

Trait Implementations

impl Clone for Model[src]

impl Debug for Model[src]

impl Default for Model[src]

Auto Trait Implementations

impl RefUnwindSafe for Model

impl Send for Model

impl Sync for Model

impl Unpin for Model

impl UnwindSafe for Model

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.