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
impl TMFMesh
sourcepub fn set_vertices(&mut self, vertices: &[Vector3]) -> Option<Box<[Vector3]>>
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);sourcepub fn set_normals(&mut self, normals: &[Vector3]) -> Option<Box<[Vector3]>>
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);sourcepub fn set_uvs(&mut self, uvs: &[Vector2]) -> Option<Box<[Vector2]>>
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);sourcepub fn set_vertex_triangles(
&mut self,
triangles: &[IndexType]
) -> Option<Box<[IndexType]>>
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);sourcepub fn set_normal_triangles(
&mut self,
triangles: &[IndexType]
) -> Option<Box<[IndexType]>>
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);sourcepub fn set_uv_triangles(
&mut self,
triangles: &[IndexType]
) -> Option<Box<[IndexType]>>
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);sourcepub fn get_vertices(&self) -> Option<&[Vector3]>
pub fn get_vertices(&self) -> Option<&[Vector3]>
Gets the vertex array of this TMFMesh.
let vertices = mesh.get_vertices();sourcepub fn get_normals(&self) -> Option<&[Vector3]>
pub fn get_normals(&self) -> Option<&[Vector3]>
Gets the normal array of this TMFMesh.
let normals = mesh.get_normals();sourcepub fn get_uvs(&self) -> Option<&[Vector2]>
pub fn get_uvs(&self) -> Option<&[Vector2]>
Gets the uv array of this TMFMesh.
let uvs = mesh.get_uvs();sourcepub fn get_vertex_triangles(&self) -> Option<&[IndexType]>
pub fn get_vertex_triangles(&self) -> Option<&[IndexType]>
Gets the vertex triangle index array of this TMFMesh.
let vertex_triangles = mesh.get_vertex_triangles();sourcepub fn get_normal_triangles(&self) -> Option<&[IndexType]>
pub fn get_normal_triangles(&self) -> Option<&[IndexType]>
Gets the normal triangle index array of this TMFMesh.
let normal_triangles = mesh.get_normal_triangles();sourcepub fn get_uv_triangles(&self) -> Option<&[IndexType]>
pub fn get_uv_triangles(&self) -> Option<&[IndexType]>
Gets the uv triangle index array of this TMFMesh.
let uv_triangles = mesh.get_uv_triangles();sourcepub fn get_vertex_buffer(&self) -> Option<Box<[Vector3]>>
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());sourcepub fn get_normal_buffer(&self) -> Option<Box<[Vector3]>>
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());sourcepub fn get_uv_buffer(&self) -> Option<Box<[Vector2]>>
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());sourcepub fn normalize(&mut self)
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();sourcepub fn verify(&self) -> Result<(), TMFIntegrityStatus>
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!");sourcepub fn read_from_obj<R: Read>(reader: &mut R) -> Result<Vec<(Self, String)>>
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);
}sourcepub fn read_from_obj_one<R: Read>(reader: &mut R) -> Result<(Self, String)>
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!");sourcepub fn write_obj_one<W: Write>(&self, w: &mut W, name: &str) -> Result<()>
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!");sourcepub fn write_obj<W: Write, S: Borrow<str>>(
meshes: &[(TMFMesh, S)],
w: &mut W
) -> Result<()>
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");sourcepub fn write_tmf_one<W: Write, S: Borrow<str>>(
&self,
w: &mut W,
p_info: &TMFPrecisionInfo,
name: S
) -> Result<()>
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!");;sourcepub fn write_tmf<W: Write, S: Borrow<str>>(
meshes_names: &[(Self, S)],
w: &mut W,
p_info: &TMFPrecisionInfo
) -> Result<()>
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!");sourcepub fn empty() -> Self
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();sourcepub fn read_tmf<R: Read>(reader: &mut R) -> Result<Vec<(Self, String)>>
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);
}sourcepub fn read_tmf_one<R: Read>(reader: &mut R) -> Result<(Self, String)>
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!");