Struct bevy_render::mesh::Mesh
source · [−]pub struct Mesh { /* private fields */ }Implementations
sourceimpl Mesh
impl Mesh
Contains geometry in the form of a mesh.
Often meshes are automatically generated by bevy’s asset loaders or primitives, such as
shape::Cube or shape::Box, but you can also construct
one yourself.
Example of constructing a mesh:
fn create_triangle() -> Mesh {
let mut mesh = Mesh::new(PrimitiveTopology::TriangleList);
mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, vec![[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 1.0, 0.0]]);
mesh.set_indices(Some(Indices::U32(vec![0,1,2])));
mesh
}sourcepub const ATTRIBUTE_POSITION: MeshVertexAttribute = MeshVertexAttribute::new("Vertex_Position", 0, VertexFormat::Float32x3)
pub const ATTRIBUTE_POSITION: MeshVertexAttribute = MeshVertexAttribute::new("Vertex_Position", 0, VertexFormat::Float32x3)
Where the vertex is located in space. Use in conjunction with Mesh::insert_attribute
sourcepub const ATTRIBUTE_NORMAL: MeshVertexAttribute = MeshVertexAttribute::new("Vertex_Normal", 1, VertexFormat::Float32x3)
pub const ATTRIBUTE_NORMAL: MeshVertexAttribute = MeshVertexAttribute::new("Vertex_Normal", 1, VertexFormat::Float32x3)
The direction the vertex normal is facing in.
Use in conjunction with Mesh::insert_attribute
sourcepub const ATTRIBUTE_UV_0: MeshVertexAttribute = MeshVertexAttribute::new("Vertex_Uv", 2, VertexFormat::Float32x2)
pub const ATTRIBUTE_UV_0: MeshVertexAttribute = MeshVertexAttribute::new("Vertex_Uv", 2, VertexFormat::Float32x2)
Texture coordinates for the vertex. Use in conjunction with Mesh::insert_attribute
sourcepub const ATTRIBUTE_TANGENT: MeshVertexAttribute = MeshVertexAttribute::new("Vertex_Tangent", 3, VertexFormat::Float32x4)
pub const ATTRIBUTE_TANGENT: MeshVertexAttribute = MeshVertexAttribute::new("Vertex_Tangent", 3, VertexFormat::Float32x4)
The direction of the vertex tangent. Used for normal mapping
sourcepub const ATTRIBUTE_COLOR: MeshVertexAttribute = MeshVertexAttribute::new("Vertex_Color", 4, VertexFormat::Uint32)
pub const ATTRIBUTE_COLOR: MeshVertexAttribute = MeshVertexAttribute::new("Vertex_Color", 4, VertexFormat::Uint32)
Per vertex coloring. Use in conjunction with Mesh::insert_attribute
sourcepub const ATTRIBUTE_JOINT_WEIGHT: MeshVertexAttribute = MeshVertexAttribute::new("Vertex_JointWeight", 5, VertexFormat::Float32x4)
pub const ATTRIBUTE_JOINT_WEIGHT: MeshVertexAttribute = MeshVertexAttribute::new("Vertex_JointWeight", 5, VertexFormat::Float32x4)
Per vertex joint transform matrix weight. Use in conjunction with Mesh::insert_attribute
sourcepub const ATTRIBUTE_JOINT_INDEX: MeshVertexAttribute = MeshVertexAttribute::new("Vertex_JointIndex", 6, VertexFormat::Uint16x4)
pub const ATTRIBUTE_JOINT_INDEX: MeshVertexAttribute = MeshVertexAttribute::new("Vertex_JointIndex", 6, VertexFormat::Uint16x4)
Per vertex joint transform matrix index. Use in conjunction with Mesh::insert_attribute
sourcepub fn new(primitive_topology: PrimitiveTopology) -> Self
pub fn new(primitive_topology: PrimitiveTopology) -> Self
Construct a new mesh. You need to provide a PrimitiveTopology so that the
renderer knows how to treat the vertex data. Most of the time this will be
PrimitiveTopology::TriangleList.
sourcepub fn primitive_topology(&self) -> PrimitiveTopology
pub fn primitive_topology(&self) -> PrimitiveTopology
Returns the topology of the mesh.
sourcepub fn insert_attribute(
&mut self,
attribute: MeshVertexAttribute,
values: impl Into<VertexAttributeValues>
)
pub fn insert_attribute(
&mut self,
attribute: MeshVertexAttribute,
values: impl Into<VertexAttributeValues>
)
Sets the data for a vertex attribute (position, normal etc.). The name will
often be one of the associated constants such as Mesh::ATTRIBUTE_POSITION.
pub fn contains_attribute(&self, id: impl Into<MeshVertexAttributeId>) -> bool
sourcepub fn attribute(
&self,
id: impl Into<MeshVertexAttributeId>
) -> Option<&VertexAttributeValues>
pub fn attribute(
&self,
id: impl Into<MeshVertexAttributeId>
) -> Option<&VertexAttributeValues>
Retrieves the data currently set to the vertex attribute with the specified name.
sourcepub fn attribute_mut(
&mut self,
id: impl Into<MeshVertexAttributeId>
) -> Option<&mut VertexAttributeValues>
pub fn attribute_mut(
&mut self,
id: impl Into<MeshVertexAttributeId>
) -> Option<&mut VertexAttributeValues>
Retrieves the data currently set to the vertex attribute with the specified name mutably.
sourcepub fn set_indices(&mut self, indices: Option<Indices>)
pub fn set_indices(&mut self, indices: Option<Indices>)
Sets the vertex indices of the mesh. They describe how triangles are constructed out of the
vertex attributes and are therefore only useful for the PrimitiveTopology variants
that use triangles.
sourcepub fn indices_mut(&mut self) -> Option<&mut Indices>
pub fn indices_mut(&mut self) -> Option<&mut Indices>
Retrieves the vertex indices of the mesh mutably.
sourcepub fn get_index_buffer_bytes(&self) -> Option<&[u8]>
pub fn get_index_buffer_bytes(&self) -> Option<&[u8]>
Computes and returns the index data of the mesh as bytes. This is used to transform the index data into a GPU friendly format.
sourcepub fn get_mesh_vertex_buffer_layout(&self) -> MeshVertexBufferLayout
pub fn get_mesh_vertex_buffer_layout(&self) -> MeshVertexBufferLayout
For a given descriptor returns a VertexBufferLayout compatible with this mesh. If this
mesh is not compatible with the given descriptor (ex: it is missing vertex attributes), None will
be returned.
sourcepub fn count_vertices(&self) -> usize
pub fn count_vertices(&self) -> usize
sourcepub fn get_vertex_buffer_data(&self) -> Vec<u8>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn get_vertex_buffer_data(&self) -> Vec<u8>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Computes and returns the vertex data of the mesh as bytes. Therefore the attributes are located in alphabetical order. This is used to transform the vertex data into a GPU friendly format.
Panics
Panics if the attributes have different vertex counts.
sourcepub fn duplicate_vertices(&mut self)
pub fn duplicate_vertices(&mut self)
Duplicates the vertex attributes so that no vertices are shared.
This can dramatically increase the vertex count, so make sure this is what you want. Does nothing if no Indices are set.
sourcepub fn compute_flat_normals(&mut self)
pub fn compute_flat_normals(&mut self)
Calculates the Mesh::ATTRIBUTE_NORMAL of a mesh.
Panics
Panics if Indices are set or Mesh::ATTRIBUTE_POSITION is not of type float3 or
if the mesh has any other topology than PrimitiveTopology::TriangleList.
Consider calling Mesh::duplicate_vertices or export your mesh with normal attributes.
sourcepub fn compute_aabb(&self) -> Option<Aabb>
pub fn compute_aabb(&self) -> Option<Aabb>
Compute the Axis-Aligned Bounding Box of the mesh vertices in model space
Trait Implementations
sourceimpl RenderAsset for Mesh
impl RenderAsset for Mesh
sourcefn extract_asset(&self) -> Self::ExtractedAsset
fn extract_asset(&self) -> Self::ExtractedAsset
Clones the mesh.
sourcefn prepare_asset(
mesh: Self::ExtractedAsset,
render_device: &mut SystemParamItem<'_, '_, Self::Param>
) -> Result<Self::PreparedAsset, PrepareAssetError<Self::ExtractedAsset>>
fn prepare_asset(
mesh: Self::ExtractedAsset,
render_device: &mut SystemParamItem<'_, '_, Self::Param>
) -> Result<Self::PreparedAsset, PrepareAssetError<Self::ExtractedAsset>>
Converts the extracted mesh a into GpuMesh.
type ExtractedAsset = Mesh
type ExtractedAsset = Mesh
The representation of the the asset in the “render world”.
type PreparedAsset = GpuMesh
type PreparedAsset = GpuMesh
The GPU-representation of the the asset.
type Param = Res<'static, RenderDevice>
type Param = Res<'static, RenderDevice>
Specifies all ECS data required by RenderAsset::prepare_asset.
For convenience use the lifetimeless SystemParam. Read more
Auto Trait Implementations
impl RefUnwindSafe for Mesh
impl Send for Mesh
impl Sync for Mesh
impl Unpin for Mesh
impl UnwindSafe for Mesh
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> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
sourcefn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<F, A>impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<F, A>impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more
sourcefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more
sourcefn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s. Read more
sourcefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s. Read more
sourceimpl<T> DowncastSync for T where
T: Any + Send + Sync,
impl<T> DowncastSync for T where
T: Any + Send + Sync,
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourcefn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> TypeData for T where
T: 'static + Send + Sync + Clone,
impl<T> TypeData for T where
T: 'static + Send + Sync + Clone,
fn clone_type_data(&self) -> Box<dyn TypeData + 'static, Global>ⓘNotable traits for Box<F, A>impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
sourceimpl<T> TypeUuidDynamic for T where
T: TypeUuid,
impl<T> TypeUuidDynamic for T where
T: TypeUuid,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output; where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output; where
S: Into<Dispatch>,
T: Future, type Output = <T as Future>::Output;
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more