pub struct CpuMesh {
pub positions: Positions,
pub indices: Indices,
pub normals: Option<Vec<Vector3<f32>>>,
pub tangents: Option<Vec<Vector4<f32>>>,
pub uvs: Option<Vec<Vector2<f32>>>,
pub colors: Option<Vec<Srgba>>,
}
Expand description
A CPU-side version of a triangle mesh.
Fields§
§positions: Positions
The positions of the vertices. If there is no indices associated with this mesh, three contiguous positions defines a triangle, in that case, the length must be divisable by 3.
indices: Indices
The indices into the positions, normals, uvs and colors arrays which defines the three vertices of a triangle. Three contiguous indices defines a triangle, therefore the length must be divisable by 3.
normals: Option<Vec<Vector3<f32>>>
The normals of the vertices.
tangents: Option<Vec<Vector4<f32>>>
The tangents of the vertices, orthogonal direction to the normal. The fourth value specifies the handedness (either -1.0 or 1.0).
uvs: Option<Vec<Vector2<f32>>>
The uv coordinates of the vertices.
colors: Option<Vec<Srgba>>
The colors of the vertices.
Implementations§
source§impl TriMesh
impl TriMesh
sourcepub fn vertex_count(&self) -> usize
pub fn vertex_count(&self) -> usize
Returns the number of vertices in this mesh.
sourcepub fn triangle_count(&self) -> usize
pub fn triangle_count(&self) -> usize
Returns the number of triangles in this mesh.
sourcepub fn transform(&mut self, transform: &Matrix4<f32>) -> Result<(), Error>
pub fn transform(&mut self, transform: &Matrix4<f32>) -> Result<(), Error>
Transforms the mesh by the given transformation.
sourcepub fn square() -> TriMesh
pub fn square() -> TriMesh
Returns a square mesh spanning the xy-plane with positions in the range [-1..1]
in the x and y axes.
sourcepub fn circle(angle_subdivisions: u32) -> TriMesh
pub fn circle(angle_subdivisions: u32) -> TriMesh
Returns a circle mesh spanning the xy-plane with radius 1 and center in (0, 0, 0)
.
sourcepub fn sphere(angle_subdivisions: u32) -> TriMesh
pub fn sphere(angle_subdivisions: u32) -> TriMesh
Returns a sphere mesh with radius 1 and center in (0, 0, 0)
.
sourcepub fn cube() -> TriMesh
pub fn cube() -> TriMesh
Returns an axis aligned unconnected cube mesh with positions in the range [-1..1]
in all axes.
sourcepub fn cylinder(angle_subdivisions: u32) -> TriMesh
pub fn cylinder(angle_subdivisions: u32) -> TriMesh
Returns a cylinder mesh around the x-axis in the range [0..1]
and with radius 1.
sourcepub fn cone(angle_subdivisions: u32) -> TriMesh
pub fn cone(angle_subdivisions: u32) -> TriMesh
Returns a cone mesh around the x-axis in the range [0..1]
and with radius 1 at -1.0.
sourcepub fn arrow(
tail_length: f32,
tail_radius: f32,
angle_subdivisions: u32
) -> TriMesh
pub fn arrow( tail_length: f32, tail_radius: f32, angle_subdivisions: u32 ) -> TriMesh
Returns an arrow mesh around the x-axis in the range [0..1]
and with radius 1.
The tail length and radius should be in the range ]0..1[
.
sourcepub fn compute_normals(&mut self)
pub fn compute_normals(&mut self)
Computes the per vertex normals and updates the normals of the mesh. It will override the current normals if they already exist.
sourcepub fn compute_tangents(&mut self)
pub fn compute_tangents(&mut self)
Computes the per vertex tangents and updates the tangents of the mesh. It will override the current tangents if they already exist.
sourcepub fn for_each_vertex(&self, callback: impl FnMut(usize))
pub fn for_each_vertex(&self, callback: impl FnMut(usize))
Iterates over all vertices in this mesh and calls the callback function with the index for each vertex.
sourcepub fn for_each_triangle(&self, callback: impl FnMut(usize, usize, usize))
pub fn for_each_triangle(&self, callback: impl FnMut(usize, usize, usize))
Iterates over all triangles in this mesh and calls the callback function with the three indices, one for each vertex in the triangle.
sourcepub fn compute_aabb(&self) -> AxisAlignedBoundingBox
pub fn compute_aabb(&self) -> AxisAlignedBoundingBox
Computes the AxisAlignedBoundingBox for this triangle mesh.