Struct easy_gltf::model::Model

source ·
pub struct Model { /* private fields */ }
Expand description

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§

source§

impl Model

source

pub fn primitive_index(&self) -> usize

Index of the Primitive of the Mesh that this Model corresponds to.

source

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

Material to apply to the whole model.

source

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

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.

source

pub fn indices(&self) -> Option<&Vec<u32>>

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.

source

pub fn mode(&self) -> Mode

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.
source

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

List of triangles ready to be rendered.

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

source

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

List of lines ready to be rendered.

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

source

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

List of points ready to be renderer.

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

source

pub fn has_normals(&self) -> bool

Indicate if the vertices contains normal information.

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

source

pub fn has_tangents(&self) -> bool

Indicate if the vertices contains tangents information.

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

source

pub fn has_tex_coords(&self) -> bool

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§

source§

impl Clone for Model

source§

fn clone(&self) -> Model

Returns a copy 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 Debug for Model

source§

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

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

impl Default for Model

source§

fn default() -> Model

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Model

§

impl RefUnwindSafe for Model

§

impl Send for Model

§

impl Sync for Model

§

impl Unpin for Model

§

impl UnwindSafe for Model

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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
source§

impl<T> ToOwned for T
where T: Clone,

§

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

§

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

§

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.