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
impl Model
sourcepub fn primitive_index(&self) -> usize
pub fn primitive_index(&self) -> usize
Index of the Primitive of the Mesh that this Model
corresponds to.
sourcepub fn vertices(&self) -> &Vec<Vertex>
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.
sourcepub fn indices(&self) -> Option<&Vec<u32>>
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.
sourcepub fn mode(&self) -> Mode
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()
andindices()
to arrange the data yourself (useful for OpenGL).triangles()
orlines()
orpoints()
according to the returned mode.
sourcepub fn triangles(&self) -> Result<Vec<Triangle>, BadMode>
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
.
sourcepub fn lines(&self) -> Result<Vec<Line>, BadMode>
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
.
sourcepub fn points(&self) -> Result<&Vec<Vertex>, BadMode>
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
.
sourcepub fn has_normals(&self) -> bool
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
.
sourcepub fn has_tangents(&self) -> bool
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
.
sourcepub fn has_tex_coords(&self) -> bool
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.