pub struct Mesh {
pub vertex_positions: Vec<Vec3>,
pub vertex_normals: Vec<Vec3>,
pub vertex_tangents: Vec<Vec3>,
pub vertex_uv0: Vec<Vec2>,
pub vertex_uv1: Vec<Vec2>,
pub vertex_colors: Vec<[u8; 4]>,
pub vertex_joint_indices: Vec<[u16; 4]>,
pub vertex_joint_weights: Vec<Vec4>,
pub indices: Vec<u32>,
}
Expand description
A mesh that may be used by many objects.
Meshes are in Structure of Array format and must have all the vertex_*
arrays be the same length. This condition can be checked with the
Mesh::validate
function.
These can be annoying to construct, so use the MeshBuilder
to make it
easier.
Fields§
§vertex_positions: Vec<Vec3>
§vertex_normals: Vec<Vec3>
§vertex_tangents: Vec<Vec3>
§vertex_uv0: Vec<Vec2>
§vertex_uv1: Vec<Vec2>
§vertex_colors: Vec<[u8; 4]>
§vertex_joint_indices: Vec<[u16; 4]>
§vertex_joint_weights: Vec<Vec4>
§indices: Vec<u32>
Implementations§
Source§impl Mesh
impl Mesh
Sourcepub fn validate(&self) -> Result<(), MeshValidationError>
pub fn validate(&self) -> Result<(), MeshValidationError>
Validates that all vertex attributes have the same length.
Sourcepub unsafe fn calculate_normals(&mut self, handedness: Handedness, zeroed: bool)
pub unsafe fn calculate_normals(&mut self, handedness: Handedness, zeroed: bool)
Calculate normals for the given mesh, assuming smooth shading and per-vertex normals.
It is sound to call this function with the wrong handedness, it will just result in flipped normals.
If zeroed is true, the normals will not be zeroed before hand. If this is falsely set, it is sound, just returns incorrect results.
§Safety
The following must be true:
- Normals and positions must be the same length.
- All indices must be in-bounds for the buffers.
If a mesh has passed a call to validate, it is sound to call this function.
Sourcepub unsafe fn calculate_normals_for_buffers<const LEFT_HANDED: bool>(
normals: &mut [Vec3],
positions: &[Vec3],
indices: &[u32],
zeroed: bool,
)
pub unsafe fn calculate_normals_for_buffers<const LEFT_HANDED: bool>( normals: &mut [Vec3], positions: &[Vec3], indices: &[u32], zeroed: bool, )
Calculate normals for the given buffers representing a mesh, assuming smooth shading and per-vertex normals.
It is sound to call this function with the wrong handedness, it will just result in flipped normals.
If zeroed is true, the normals will not be zeroed before hand. If this is falsely set, it is safe, just returns incorrect results.
§Safety
The following must be true:
- Normals and positions must be the same length.
- All indices must be in-bounds for the buffers.
If a mesh has passed a call to validate, it is sound to call this function.
Sourcepub unsafe fn calculate_tangents(&mut self, zeroed: bool)
pub unsafe fn calculate_tangents(&mut self, zeroed: bool)
Calculate tangents for the given mesh, based on normals and texture coordinates.
If zeroed is true, the normals will not be zeroed before hand. If this is falsely set, it is safe, just returns incorrect results.
§Safety
The following must be true:
- Tangents, positions, normals, and uvs must be the same length.
- All indices must be in-bounds for the buffers.
If a mesh has passed a call to validate, it is sound to call this function.
Sourcepub unsafe fn calculate_tangents_for_buffers(
tangents: &mut [Vec3],
positions: &[Vec3],
normals: &[Vec3],
uvs: &[Vec2],
indices: &[u32],
zeroed: bool,
)
pub unsafe fn calculate_tangents_for_buffers( tangents: &mut [Vec3], positions: &[Vec3], normals: &[Vec3], uvs: &[Vec2], indices: &[u32], zeroed: bool, )
Calculate tangents for the given set of buffers, based on normals and texture coordinates.
If zeroed is true, the normals will not be zeroed before hand. If this is falsely set, it is safe, just returns incorrect results.
§Safety
The following must be true:
- Tangents, positions, normals, and uvs must be the same length.
- All indices must be in-bounds for the buffers.
Sourcepub fn double_side(&mut self)
pub fn double_side(&mut self)
Converts the mesh from single sided to double sided.
Sourcepub fn flip_winding_order(&mut self)
pub fn flip_winding_order(&mut self)
Inverts the winding order of a mesh. This is useful if you have meshes which are designed for right-handed (Counter-Clockwise) winding order for use in OpenGL or VK.
This does not change vertex location, so does not change coordinate
system. This will also not change the vertex normals. Calling
Mesh::calculate_normals
is advised after calling this function.