Mesh

Struct Mesh 

Source
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

Source

pub fn validate(&self) -> Result<(), MeshValidationError>

Validates that all vertex attributes have the same length.

Source

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.

Source

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.

Source

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.

Source

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.
Source

pub fn double_side(&mut self)

Converts the mesh from single sided to double sided.

Source

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.

Trait Implementations§

Source§

impl Clone for Mesh

Source§

fn clone(&self) -> Self

Returns a duplicate 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 Debug for Mesh

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Mesh

§

impl RefUnwindSafe for Mesh

§

impl Send for Mesh

§

impl Sync for Mesh

§

impl Unpin for Mesh

§

impl UnwindSafe for Mesh

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.