Struct tmf::TMFMesh

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

Representation of a TMF mesh. Can be loaded from disk, imported from diffrent format, saved to disk, and exported to a diffrent format, or created using special functions. Any mesh created at run time should but does not have to be checked before saving with Self::verify call. If the mesh is known to be OK before saving this step can be skipped(even tough it is still advised).

Implementations§

source§

impl TMFMesh

source

pub fn set_vertices(&mut self, vertices: &[Vector3]) -> Option<Box<[Vector3]>>

Sets mesh vertex array and returns old vertex array if present. New mesh data is not checked during this function call, so to ensure mesh is valid call Self::verify before saving.

 // Set the vertices of the mesh
 mesh.set_vertices(&vertices);
 // Change the vertices for some other vertices...
 let old_vertices = mesh.set_vertices(&new_vertices).expect("Mesh had no vertices!");
 // ... and the do something with old vertices
 do_something(&old_vertices);
source

pub fn set_normals(&mut self, normals: &[Vector3]) -> Option<Box<[Vector3]>>

Sets mesh normal array and returns old normal array if present. New mesh data is not checked during this function call, so to ensure mesh is valid call verify before saving.

 // Set the normals of the mesh
 mesh.set_normals(&normals);
 // Change the normals  of this mesh for some other normals...
 let old_normals = mesh.set_normals(&new_normals).expect("Mesh had no normals!");
 // ... and the do something with old normals
 do_something(&old_normals);
source

pub fn set_uvs(&mut self, uvs: &[Vector2]) -> Option<Box<[Vector2]>>

Sets mesh uv array and returns old uv array if present. New mesh daata is not checked during this function call, so to ensure mesh is valid call Self::verify before saving.

 // Set the uvs of the mesh
 mesh.set_uvs(&uvs);
 // Change the uvs  of this mesh for some other normals...
 let old_uvs = mesh.set_uvs(&new_uvs).expect("Mesh had no uvs!");
 // ... and the do something with old uvs
 do_something(&old_uvs);
source

pub fn set_vertex_triangles( &mut self, triangles: &[IndexType] ) -> Option<Box<[IndexType]>>

Sets vertex index array to triangles and returns old triangles if present.

 mesh.set_vertex_triangles(&triangles);
source

pub fn set_normal_triangles( &mut self, triangles: &[IndexType] ) -> Option<Box<[IndexType]>>

Sets normal index array to triangles and returns old triangles if present.

 mesh.set_normal_triangles(&triangles);
source

pub fn set_uv_triangles( &mut self, triangles: &[IndexType] ) -> Option<Box<[IndexType]>>

Sets uv index array to triangles and returns old triangles if present.

 mesh.set_uv_triangles(&triangles);
source

pub fn get_vertices(&self) -> Option<&[Vector3]>

Gets the vertex array of this TMFMesh.

 let vertices = mesh.get_vertices();
source

pub fn get_normals(&self) -> Option<&[Vector3]>

Gets the normal array of this TMFMesh.

 let normals = mesh.get_normals();
source

pub fn get_uvs(&self) -> Option<&[Vector2]>

Gets the uv array of this TMFMesh.

 let uvs = mesh.get_uvs();
source

pub fn get_vertex_triangles(&self) -> Option<&[IndexType]>

Gets the vertex triangle index array of this TMFMesh.

 let vertex_triangles = mesh.get_vertex_triangles();
source

pub fn get_normal_triangles(&self) -> Option<&[IndexType]>

Gets the normal triangle index array of this TMFMesh.

 let normal_triangles = mesh.get_normal_triangles();
source

pub fn get_uv_triangles(&self) -> Option<&[IndexType]>

Gets the uv triangle index array of this TMFMesh.

 let uv_triangles = mesh.get_uv_triangles();
source

pub fn get_vertex_buffer(&self) -> Option<Box<[Vector3]>>

Returns array containing points laid out in such a way that each 3 points create the next triangle. If mesh has no vertex array or no vertex triangle array None is returned.

 let vert_buff = mesh.get_vertex_buffer().expect("Could not create the array of points creating triangles!");
 // The same number of triangles created by points and triangles created by indices
 assert!(vert_buff.len() == vertex_triangles.len());
source

pub fn get_normal_buffer(&self) -> Option<Box<[Vector3]>>

Returns array containing normals laid out in such a way that each 3 normals create the next triangle. If mesh has no normal array or no normal triangle array None is returned.

 let normal_buff = mesh.get_normal_buffer().expect("Could not create the array of normals creating triangles!");
 // The same number of triangles created by points and triangles created by indices
 assert!(normal_buff.len() == normal_triangles.len());
source

pub fn get_uv_buffer(&self) -> Option<Box<[Vector2]>>

Returns array containing UV coridnates laid out in such a way that each 3 cordiantes create the next triangle. If mesh has no UV array or no uv triangle array None is returned.

 let uv_buff = mesh.get_uv_buffer().expect("Could not create the array of uvs creating triangles!");
 // The same number of triangles created by points and triangles created by indices
 assert!(uv_buff.len() == uv_triangles.len());
source

pub fn normalize(&mut self)

Normalizes normal array of the mesh, if it is present.

 // Some mesh with normals which are not normalzed
 mesh.set_normals(&normals);
 // Normalize all normals
 mesh.normalize();
 // All normals are normalised (their magnitude is equal to 1)
 for normal in mesh.get_normals().expect("Mesh has no normals"){
     let mag = magnitude(*normal);
     // Magnitude of the normal is not exactly equal to 1
     // because of imprecision of floating-point numbers.
     assert!(mag > 0.99999 && mag < 1.00001);
 }

Normalising a mesh without normals is a NOP.

 // Mesh has no normals
 assert!(mesh.get_normals().is_none());
 // This does nothing
 mesh.normalize();
source

pub fn verify(&self) -> Result<(), TMFIntegrityStatus>

Checks if mesh is valid and can be saved.

// Get the tmf mesh form somewhere
mesh.verify().expect("Mesh had errors!");
source

pub fn read_from_obj<R: Read>(reader: &mut R) -> Result<Vec<(Self, String)>>

Reads tmf meshes from a .obj file in reader In order to enable triangulation while importing .obj files feature triangulation must be used. It is still highly experimental so read documentation before enabling.

 // Open the file with the .obj model
 let mut file = File::open(dot_obj_path).expect("Could not open .obj file!");
 // And multiple meshes from it
 let meshes = TMFMesh::read_from_obj(&mut file).expect("Could not parse .obj file!");
 for (mesh,name) in meshes{
     // Do something with the mesh and name
     do_something(mesh,name);
 }
source

pub fn read_from_obj_one<R: Read>(reader: &mut R) -> Result<(Self, String)>

Reads a single named tmf mesh from a .obj file in reader, if more than one mesh present an error will be returned. In order to enable triangulation while importing .obj files feature triangulation must be used. It is still highly experimental so read documentation before enabling.

 // Open the file with the .obj model
 let mut file = File::open(dot_obj_path).expect("Could not open .obj file!");
 // And read a mesh from it
 let (mesh,name) = TMFMesh::read_from_obj_one(&mut file).expect("Could not parse .obj file!");
source

pub fn write_obj_one<W: Write>(&self, w: &mut W, name: &str) -> Result<()>

Writes this TMF mesh to a .obj file.

let mut obj_out = File::create(out_path).expect("Could not create obj out file!");
mesh.write_obj_one(&mut obj_out,"mesh name").expect("Could not write the .obj file!");
source

pub fn write_obj<W: Write, S: Borrow<str>>( meshes: &[(TMFMesh, S)], w: &mut W ) -> Result<()>

Writes multiple TMF meshes to a .obj file.

 let mut output = File::create(path).expect("Could not create file!");
 TMFMesh::write_obj(&meshes,&mut output).expect("Could not export to .obj");
source

pub fn write_tmf_one<W: Write, S: Borrow<str>>( &self, w: &mut W, p_info: &TMFPrecisionInfo, name: S ) -> Result<()>

Writes this TMF Mesh to w.

 let mut output = File::create(path).expect("Could not create file!");
 // Settings dictating how to save the mesh
 let precision_info = TMFPrecisionInfo::default();
 mesh.write_tmf_one(&mut output,&precision_info,"mesh_name").expect("Could not save .tmf mesh!");;
source

pub fn write_tmf<W: Write, S: Borrow<str>>( meshes_names: &[(Self, S)], w: &mut W, p_info: &TMFPrecisionInfo ) -> Result<()>

Writes a number of TMF meshes into one file.

let mut output = File::create(path).expect("Could not create file!");
// Settings dictating how to save the mesh
let precision_info = TMFPrecisionInfo::default();
TMFMesh::write_tmf(&meshes,&mut output, &precision_info).expect("Could not save .tmf file!");
source

pub fn empty() -> Self

Creates an empty TMF Mesh(mesh with no data). Equivalent to TMFMesh::default.

// Creates an empty mesh with no data
let mut mesh = TMFMesh::empty();
source

pub fn read_tmf<R: Read>(reader: &mut R) -> Result<Vec<(Self, String)>>

Reads all meshes from a .tmf file.

// Open file containg the meshes
let mut file = File::open(tmf_path).expect("Could not open .tmf file");
// Get meshes and their names
let meshes = TMFMesh::read_tmf(&mut file).expect("Could not load .tmf mesh!");
for (mesh,name) in meshes{
    // Do some thing with each mesh and name(eg. use in game)
    do_something(mesh,name);
}
source

pub fn read_tmf_one<R: Read>(reader: &mut R) -> Result<(Self, String)>

Reads a single mesh from a .tmf file. Returns Err if no meshes present or more than one mesh present.

// Open the file containing the mesh
let mut file = File::open(tmf_path).expect("Could not open .tmf file");
// Read mesh and mesh name form file
let (mesh,name) = TMFMesh::read_tmf_one(&mut file).expect("Could not load .tmf mesh!");

Trait Implementations§

source§

impl Clone for TMFMesh

source§

fn clone(&self) -> TMFMesh

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 Default for TMFMesh

source§

fn default() -> Self

Creates default, empty TMFMesh. Equivalent to TMFMesh::empty call.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.