[−][src]Struct tobj::Mesh
A mesh made up of triangles loaded from some OBJ file
It is assumed that all meshes will at least have positions, but normals and texture coordinates
are optional. If no normals or texture coordinates where found then the corresponding vecs for
the mesh will be empty. Values are stored packed as floats in vecs, eg. the positions member of
a loaded mesh will contain [x, y, z, x, y, z, ...]
which you can then use however you like.
Indices are also loaded and may re-use vertices already existing in the mesh, this data is
stored in the indices
member.
Example:
Load the Cornell box and get the attributes of the first vertex. It's assumed all meshes will have positions (required), but normals and texture coordinates are optional, in which case the corresponding Vec will be empty.
let cornell_box = tobj::load_obj("cornell_box.obj"); assert!(cornell_box.is_ok()); let (models, materials) = cornell_box.unwrap(); let mesh = &models[0].mesh; let i = mesh.indices[0] as usize; // pos = [x, y, z] let pos = [mesh.positions[i * 3], mesh.positions[i * 3 + 1], mesh.positions[i * 3 + 2]]; if !mesh.normals.is_empty() { // normal = [x, y, z] let normal = [mesh.normals[i * 3], mesh.normals[i * 3 + 1], mesh.normals[i * 3 + 2]]; } if !mesh.texcoords.is_empty() { // texcoord = [u, v]; let texcoord = [mesh.texcoords[i * 2], mesh.texcoords[i * 2 + 1]]; }
Fields
positions: Vec<f32>
Flattened 3 component floating point vectors, storing positions of vertices in the mesh
normals: Vec<f32>
Flattened 3 component floating point vectors, storing normals of vertices in the mesh. Not all meshes have normals, if no normals are specified this Vec will be empty
texcoords: Vec<f32>
Flattened 2 component floating point vectors, storing texture coordinates of vertices in the mesh. Not all meshes have normals, if no texture coordinates are specified this Vec will be empty
indices: Vec<u32>
Indices for vertices of each triangle. Each face in the mesh is a triangle and the indices specify the position, normal and texture coordinate for each vertex of the face.
material_id: Option<usize>
Optional material id associated with this mesh. The material id indexes into the Vec of Materials loaded from the associated MTL file
Methods
impl Mesh
[src]
pub fn new(
positions: Vec<f32>,
normals: Vec<f32>,
texcoords: Vec<f32>,
indices: Vec<u32>,
material_id: Option<usize>
) -> Mesh
[src]
positions: Vec<f32>,
normals: Vec<f32>,
texcoords: Vec<f32>,
indices: Vec<u32>,
material_id: Option<usize>
) -> Mesh
Create a new mesh specifying the geometry for the mesh
pub fn empty() -> Mesh
[src]
Create a new empty mesh
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Mesh
impl Send for Mesh
impl Sync for Mesh
impl Unpin for Mesh
impl UnwindSafe for Mesh
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,