pub struct CpuMesh {
pub name: String,
pub material_name: Option<String>,
pub positions: Positions,
pub indices: Option<Indices>,
pub normals: Option<Vec<Vec3>>,
pub tangents: Option<Vec<Vec4>>,
pub uvs: Option<Vec<Vec2>>,
pub colors: Option<Vec<Color>>,
}Expand description
A CPU-side version of a triangle mesh. Can be constructed manually or loaded via io or via the utility functions for generating simple triangle meshes.
Fields
name: StringName.
material_name: Option<String>Name of the associated material, use this to match with CpuMaterial::name.
positions: PositionsThe 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: Option<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<Vec3>>The normals of the vertices.
tangents: Option<Vec<Vec4>>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<Vec2>>The uv coordinates of the vertices.
colors: Option<Vec<Color>>The colors of the vertices. The colors are assumed to be in linear space.
Implementations
sourceimpl CpuMesh
impl CpuMesh
sourcepub fn material<'a>(
&self,
materials: &'a [CpuMaterial]
) -> Option<&'a CpuMaterial>
pub fn material<'a>(
&self,
materials: &'a [CpuMaterial]
) -> Option<&'a CpuMaterial>
Returns the material for this mesh in the given list of materials. Returns None if no suitable material can be found.
sourcepub fn transform(&mut self, transform: &Mat4) -> ThreeDResult<()>
pub fn transform(&mut self, transform: &Mat4) -> ThreeDResult<()>
Transforms the mesh by the given transformation.
sourcepub fn square() -> Self
pub fn square() -> Self
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) -> Self
pub fn circle(angle_subdivisions: u32) -> Self
Returns a circle mesh spanning the xy-plane with radius 1 and center in (0, 0, 0).
sourcepub fn sphere(angle_subdivisions: u32) -> Self
pub fn sphere(angle_subdivisions: u32) -> Self
Returns a sphere mesh with radius 1 and center in (0, 0, 0).
sourcepub fn cube() -> Self
pub fn cube() -> Self
Returns an axis aligned unconnected cube mesh with positions in the range [-1..1] in all axes.
sourcepub fn cylinder(angle_subdivisions: u32) -> Self
pub fn cylinder(angle_subdivisions: u32) -> Self
Returns a cylinder mesh around the x-axis in the range [0..1] and with radius 1.
sourcepub fn cone(angle_subdivisions: u32) -> Self
pub fn cone(angle_subdivisions: u32) -> Self
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
) -> Self
pub fn arrow(
tail_length: f32,
tail_radius: f32,
angle_subdivisions: u32
) -> Self
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) -> ThreeDResult<()>
pub fn compute_tangents(&mut self) -> ThreeDResult<()>
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 axis aligned bounding box of the mesh.
sourcepub fn validate(&self) -> ThreeDResult<()>
pub fn validate(&self) -> ThreeDResult<()>
Returns an error if the mesh is not valid.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for CpuMesh
impl Send for CpuMesh
impl Sync for CpuMesh
impl Unpin for CpuMesh
impl UnwindSafe for CpuMesh
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more