pub struct Mesh { /* private fields */ }
Implementations
impl 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.set_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
}
pub const ATTRIBUTE_COLOR: &'static str
pub const ATTRIBUTE_COLOR: &'static str
Per vertex coloring. Use in conjunction with Mesh::set_attribute
pub const ATTRIBUTE_NORMAL: &'static str
pub const ATTRIBUTE_NORMAL: &'static str
The direction the vertex normal is facing in.
Use in conjunction with Mesh::set_attribute
pub const ATTRIBUTE_TANGENT: &'static str
pub const ATTRIBUTE_TANGENT: &'static str
The direction of the vertex tangent. Used for normal mapping
pub const ATTRIBUTE_POSITION: &'static str
pub const ATTRIBUTE_POSITION: &'static str
Where the vertex is located in space. Use in conjunction with Mesh::set_attribute
pub const ATTRIBUTE_UV_0: &'static str
pub const ATTRIBUTE_UV_0: &'static str
Texture coordinates for the vertex. Use in conjunction with Mesh::set_attribute
pub const ATTRIBUTE_JOINT_WEIGHT: &'static str
pub const ATTRIBUTE_JOINT_WEIGHT: &'static str
Per vertex joint transform matrix weight. Use in conjunction with Mesh::set_attribute
pub const ATTRIBUTE_JOINT_INDEX: &'static str
pub const ATTRIBUTE_JOINT_INDEX: &'static str
Per vertex joint transform matrix index. Use in conjunction with Mesh::set_attribute
pub fn new(primitive_topology: PrimitiveTopology) -> Mesh
pub fn new(primitive_topology: PrimitiveTopology) -> Mesh
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
.
pub fn primitive_topology(&self) -> PrimitiveTopology
pub fn primitive_topology(&self) -> PrimitiveTopology
Returns the topology of the mesh.
pub fn set_attribute(
&mut self,
name: impl Into<Cow<'static, str>>,
values: impl Into<VertexAttributeValues>
)
pub fn set_attribute(
&mut self,
name: impl Into<Cow<'static, str>>,
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 attribute(
&self,
name: impl Into<Cow<'static, str>>
) -> Option<&VertexAttributeValues>
pub fn attribute(
&self,
name: impl Into<Cow<'static, str>>
) -> Option<&VertexAttributeValues>
Retrieves the data currently set to the vertex attribute with the specified name
.
pub fn attribute_mut(
&mut self,
name: impl Into<Cow<'static, str>>
) -> Option<&mut VertexAttributeValues>
pub fn attribute_mut(
&mut self,
name: impl Into<Cow<'static, str>>
) -> Option<&mut VertexAttributeValues>
Retrieves the data currently set to the vertex attribute with the specified name
mutably.
pub 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.
pub 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.
pub 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.
pub fn count_vertices(&self) -> usize
pub fn count_vertices(&self) -> usize
pub fn get_vertex_buffer_data(&self) -> Vec<u8, Global>ⓘ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, Global>ⓘ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.
pub 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.
Panics
If the mesh has any other topology than PrimitiveTopology::TriangleList
.
pub 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
.
Consider calling Mesh::duplicate_vertices or export your mesh with normal attributes.
pub 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
impl RenderAsset for Mesh
impl RenderAsset for Mesh
pub fn extract_asset(&self) -> <Mesh as RenderAsset>::ExtractedAsset
pub fn extract_asset(&self) -> <Mesh as RenderAsset>::ExtractedAsset
Clones the mesh.
pub fn prepare_asset(
mesh: <Mesh as RenderAsset>::ExtractedAsset,
render_device: &mut <<<Mesh as RenderAsset>::Param as SystemParam>::Fetch as SystemParamFetch<'_, '_>>::Item
) -> Result<<Mesh as RenderAsset>::PreparedAsset, PrepareAssetError<<Mesh as RenderAsset>::ExtractedAsset>>
pub fn prepare_asset(
mesh: <Mesh as RenderAsset>::ExtractedAsset,
render_device: &mut <<<Mesh as RenderAsset>::Param as SystemParam>::Fetch as SystemParamFetch<'_, '_>>::Item
) -> Result<<Mesh as RenderAsset>::PreparedAsset, PrepareAssetError<<Mesh as RenderAsset>::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
SystemParams. 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 · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<I, A>impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<I, A>impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
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
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub 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
pub fn as_any(&self) -> &(dyn Any + 'static)
pub 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
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub 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> 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.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> TypeData for T where
T: 'static + Send + Sync + Clone,
impl<T> TypeData for T where
T: 'static + Send + Sync + Clone,
pub fn clone_type_data(&self) -> Box<dyn TypeData + 'static, Global>ⓘNotable traits for Box<I, A>impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
impl<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>,
pub 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