pub struct Mesh {
pub asset_usage: RenderAssetUsages,
/* private fields */
}
Expand description
A 3D object made out of vertices representing triangles, lines, or points, with “attribute” values for each vertex.
Meshes can be automatically generated by a bevy AssetLoader
(generally by loading a Gltf
file),
or by converting a primitive using into
.
It is also possible to create one manually. They can be edited after creation.
Meshes can be rendered with a Mesh2d
and MeshMaterial2d
or Mesh3d
and MeshMaterial3d
for 2D and 3D respectively.
A Mesh
in Bevy is equivalent to a “primitive” in the glTF format, for a
glTF Mesh representation, see GltfMesh
.
§Manual creation
The following function will construct a flat mesh, to be rendered with a
StandardMaterial
or ColorMaterial
:
fn create_simple_parallelogram() -> Mesh {
// Create a new mesh using a triangle list topology, where each set of 3 vertices composes a triangle.
Mesh::new(PrimitiveTopology::TriangleList, RenderAssetUsages::default())
// Add 4 vertices, each with its own position attribute (coordinate in
// 3D space), for each of the corners of the parallelogram.
.with_inserted_attribute(
Mesh::ATTRIBUTE_POSITION,
vec![[0.0, 0.0, 0.0], [1.0, 2.0, 0.0], [2.0, 2.0, 0.0], [1.0, 0.0, 0.0]]
)
// Assign a UV coordinate to each vertex.
.with_inserted_attribute(
Mesh::ATTRIBUTE_UV_0,
vec![[0.0, 1.0], [0.5, 0.0], [1.0, 0.0], [0.5, 1.0]]
)
// Assign normals (everything points outwards)
.with_inserted_attribute(
Mesh::ATTRIBUTE_NORMAL,
vec![[0.0, 0.0, 1.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0]]
)
// After defining all the vertices and their attributes, build each triangle using the
// indices of the vertices that make it up in a counter-clockwise order.
.with_inserted_indices(Indices::U32(vec![
// First triangle
0, 3, 1,
// Second triangle
1, 3, 2
]))
}
You can see how it looks like here,
used in a Mesh3d
with a square bevy logo texture, with added axis, points,
lines and text for clarity.
§Other examples
For further visualization, explanation, and examples, see the built-in Bevy examples,
and the implementation of the built-in shapes.
In particular, generate_custom_mesh
teaches you to access and modify the attributes of a Mesh
after creating it.
§Common points of confusion
- UV maps in Bevy start at the top-left, see
ATTRIBUTE_UV_0
, other APIs can have other conventions,OpenGL
starts at bottom-left. - It is possible and sometimes useful for multiple vertices to have the same position attribute value, it’s a common technique in 3D modeling for complex UV mapping or other calculations.
- Bevy performs frustum culling based on the
Aabb
of meshes, which is calculated and added automatically for new meshes only. If a mesh is modified, the entity’sAabb
needs to be updated manually or deleted so that it is re-calculated.
§Use with StandardMaterial
To render correctly with StandardMaterial
, a mesh needs to have properly defined:
UVs
: Bevy needs to know how to map a texture onto the mesh (also true forColorMaterial
).Normals
: Bevy needs to know how light interacts with your mesh. [0.0, 0.0, 1.0] is very common for simple flat meshes on the XY plane, because simple meshes are smooth and they don’t require complex light calculations.- Vertex winding order: by default,
StandardMaterial.cull_mode
isSome(Face::Back)
, which means that Bevy would only render the “front” of each triangle, which is the side of the triangle from where the vertices appear in a counter-clockwise order.
Fields§
§asset_usage: RenderAssetUsages
Implementations§
Source§impl Mesh
impl Mesh
Sourcepub const ATTRIBUTE_POSITION: MeshVertexAttribute = _
pub const ATTRIBUTE_POSITION: MeshVertexAttribute = _
Where the vertex is located in space. Use in conjunction with Mesh::insert_attribute
or Mesh::with_inserted_attribute
.
The format of this attribute is VertexFormat::Float32x3
.
Sourcepub const ATTRIBUTE_NORMAL: MeshVertexAttribute = _
pub const ATTRIBUTE_NORMAL: MeshVertexAttribute = _
The direction the vertex normal is facing in.
Use in conjunction with Mesh::insert_attribute
or Mesh::with_inserted_attribute
.
The format of this attribute is VertexFormat::Float32x3
.
Sourcepub const ATTRIBUTE_UV_0: MeshVertexAttribute = _
pub const ATTRIBUTE_UV_0: MeshVertexAttribute = _
Texture coordinates for the vertex. Use in conjunction with Mesh::insert_attribute
or Mesh::with_inserted_attribute
.
Generally [0.,0.]
is mapped to the top left of the texture, and [1.,1.]
to the bottom-right.
By default values outside will be clamped per pixel not for the vertex, “stretching” the borders of the texture. This behavior can be useful in some cases, usually when the borders have only one color, for example a logo, and you want to “extend” those borders.
For different mapping outside of 0..=1
range,
see ImageAddressMode
.
The format of this attribute is VertexFormat::Float32x2
.
Sourcepub const ATTRIBUTE_UV_1: MeshVertexAttribute = _
pub const ATTRIBUTE_UV_1: MeshVertexAttribute = _
Alternate texture coordinates for the vertex. Use in conjunction with
Mesh::insert_attribute
or Mesh::with_inserted_attribute
.
Typically, these are used for lightmaps, textures that provide precomputed illumination.
The format of this attribute is VertexFormat::Float32x2
.
Sourcepub const ATTRIBUTE_TANGENT: MeshVertexAttribute = _
pub const ATTRIBUTE_TANGENT: MeshVertexAttribute = _
The direction of the vertex tangent. Used for normal mapping.
Usually generated with generate_tangents
or
with_generated_tangents
.
The format of this attribute is VertexFormat::Float32x4
.
Sourcepub const ATTRIBUTE_COLOR: MeshVertexAttribute = _
pub const ATTRIBUTE_COLOR: MeshVertexAttribute = _
Per vertex coloring. Use in conjunction with Mesh::insert_attribute
or Mesh::with_inserted_attribute
.
The format of this attribute is VertexFormat::Float32x4
.
Sourcepub const ATTRIBUTE_JOINT_WEIGHT: MeshVertexAttribute = _
pub const ATTRIBUTE_JOINT_WEIGHT: MeshVertexAttribute = _
Per vertex joint transform matrix weight. Use in conjunction with Mesh::insert_attribute
or Mesh::with_inserted_attribute
.
The format of this attribute is VertexFormat::Float32x4
.
Sourcepub const ATTRIBUTE_JOINT_INDEX: MeshVertexAttribute = _
pub const ATTRIBUTE_JOINT_INDEX: MeshVertexAttribute = _
Per vertex joint transform matrix index. Use in conjunction with Mesh::insert_attribute
or Mesh::with_inserted_attribute
.
The format of this attribute is VertexFormat::Uint16x4
.
Sourcepub fn new(
primitive_topology: PrimitiveTopology,
asset_usage: RenderAssetUsages,
) -> Mesh
pub fn new( primitive_topology: PrimitiveTopology, asset_usage: RenderAssetUsages, ) -> 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
.
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
.
Aabb
of entities with modified mesh are not updated automatically.
§Panics
Panics when the format of the values does not match the attribute’s format.
Sourcepub fn with_inserted_attribute(
self,
attribute: MeshVertexAttribute,
values: impl Into<VertexAttributeValues>,
) -> Mesh
pub fn with_inserted_attribute( self, attribute: MeshVertexAttribute, values: impl Into<VertexAttributeValues>, ) -> Mesh
Consumes the mesh and returns a mesh with data set for a vertex attribute (position, normal, etc.).
The name will often be one of the associated constants such as Mesh::ATTRIBUTE_POSITION
.
(Alternatively, you can use Mesh::insert_attribute
to mutate an existing mesh in-place)
Aabb
of entities with modified mesh are not updated automatically.
§Panics
Panics when the format of the values does not match the attribute’s format.
Sourcepub fn remove_attribute(
&mut self,
attribute: impl Into<MeshVertexAttributeId>,
) -> Option<VertexAttributeValues>
pub fn remove_attribute( &mut self, attribute: impl Into<MeshVertexAttributeId>, ) -> Option<VertexAttributeValues>
Removes the data for a vertex attribute
Sourcepub fn with_removed_attribute(
self,
attribute: impl Into<MeshVertexAttributeId>,
) -> Mesh
pub fn with_removed_attribute( self, attribute: impl Into<MeshVertexAttributeId>, ) -> Mesh
Consumes the mesh and returns a mesh without the data for a vertex attribute
(Alternatively, you can use Mesh::remove_attribute
to mutate an existing mesh in-place)
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 attributes(
&self,
) -> impl Iterator<Item = (&MeshVertexAttribute, &VertexAttributeValues)>
pub fn attributes( &self, ) -> impl Iterator<Item = (&MeshVertexAttribute, &VertexAttributeValues)>
Returns an iterator that yields references to the data of each vertex attribute.
Sourcepub fn attributes_mut(
&mut self,
) -> impl Iterator<Item = (&MeshVertexAttribute, &mut VertexAttributeValues)>
pub fn attributes_mut( &mut self, ) -> impl Iterator<Item = (&MeshVertexAttribute, &mut VertexAttributeValues)>
Returns an iterator that yields mutable references to the data of each vertex attribute.
Sourcepub fn insert_indices(&mut self, indices: Indices)
pub fn insert_indices(&mut self, indices: 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 with_inserted_indices(self, indices: Indices) -> Mesh
pub fn with_inserted_indices(self, indices: Indices) -> Mesh
Consumes the mesh and returns a mesh with the given vertex indices. They describe how triangles
are constructed out of the vertex attributes and are therefore only useful for the
PrimitiveTopology
variants that use triangles.
(Alternatively, you can use Mesh::insert_indices
to mutate an existing mesh in-place)
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 remove_indices(&mut self) -> Option<Indices>
pub fn remove_indices(&mut self) -> Option<Indices>
Removes the vertex indices
from the mesh and returns them.
Sourcepub fn with_removed_indices(self) -> Mesh
pub fn with_removed_indices(self) -> Mesh
Consumes the mesh and returns a mesh without the vertex indices
of the mesh.
(Alternatively, you can use Mesh::remove_indices
to mutate an existing mesh in-place)
Sourcepub fn get_vertex_size(&self) -> u64
pub fn get_vertex_size(&self) -> u64
Returns the size of a vertex in bytes.
Sourcepub fn get_vertex_buffer_size(&self) -> usize
pub fn get_vertex_buffer_size(&self) -> usize
Returns the size required for the vertex buffer in bytes.
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,
mesh_vertex_buffer_layouts: &mut MeshVertexBufferLayouts,
) -> MeshVertexBufferLayoutRef
pub fn get_mesh_vertex_buffer_layout( &self, mesh_vertex_buffer_layouts: &mut MeshVertexBufferLayouts, ) -> MeshVertexBufferLayoutRef
Get this Mesh
’s MeshVertexBufferLayout
, used in SpecializedMeshPipeline
.
Sourcepub fn count_vertices(&self) -> usize
pub fn count_vertices(&self) -> usize
Counts all vertices of the mesh.
If the attributes have different vertex counts, the smallest is returned.
Sourcepub fn create_packed_vertex_buffer_data(&self) -> Vec<u8> ⓘ
pub fn create_packed_vertex_buffer_data(&self) -> Vec<u8> ⓘ
Computes and returns the vertex data of the mesh as bytes.
Therefore the attributes are located in the order of their MeshVertexAttribute::id
.
This is used to transform the vertex data into a GPU friendly format.
If the vertex attributes have different lengths, they are all truncated to the length of the smallest.
This is a convenience method which allocates a Vec.
Prefer pre-allocating and using Mesh::write_packed_vertex_buffer_data
when possible.
Sourcepub fn write_packed_vertex_buffer_data(&self, slice: &mut [u8])
pub fn write_packed_vertex_buffer_data(&self, slice: &mut [u8])
Computes and write the vertex data of the mesh into a mutable byte slice.
The attributes are located in the order of their MeshVertexAttribute::id
.
This is used to transform the vertex data into a GPU friendly format.
If the vertex attributes have different lengths, they are all truncated to the length of the smallest.
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 with_duplicated_vertices(self) -> Mesh
pub fn with_duplicated_vertices(self) -> Mesh
Consumes the mesh and returns a mesh with no shared vertices.
This can dramatically increase the vertex count, so make sure this is what you want.
Does nothing if no Indices
are set.
(Alternatively, you can use Mesh::duplicate_vertices
to mutate an existing mesh in-place)
Sourcepub fn invert_winding(&mut self) -> Result<(), MeshWindingInvertError>
pub fn invert_winding(&mut self) -> Result<(), MeshWindingInvertError>
Sourcepub fn with_inverted_winding(self) -> Result<Mesh, MeshWindingInvertError>
pub fn with_inverted_winding(self) -> Result<Mesh, MeshWindingInvertError>
Consumes the mesh and returns a mesh with inverted winding of the indices such that all counter-clockwise triangles are now clockwise and vice versa.
Does nothing if no Indices
are set.
Sourcepub fn compute_normals(&mut self)
pub fn compute_normals(&mut self)
Calculates the Mesh::ATTRIBUTE_NORMAL
of a mesh.
If the mesh is indexed, this defaults to smooth normals. Otherwise, it defaults to flat
normals.
§Panics
Panics if Mesh::ATTRIBUTE_POSITION
is not of type float3
.
Panics if the mesh has any other topology than PrimitiveTopology::TriangleList
.
FIXME: This should handle more cases since this is called as a part of gltf mesh loading where we can’t really blame users for loading meshes that might not conform to the limitations here!
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
.
Panics if the mesh has any other topology than PrimitiveTopology::TriangleList
.
Consider calling Mesh::duplicate_vertices
or exporting your mesh with normal
attributes.
FIXME: This should handle more cases since this is called as a part of gltf mesh loading where we can’t really blame users for loading meshes that might not conform to the limitations here!
Sourcepub fn compute_smooth_normals(&mut self)
pub fn compute_smooth_normals(&mut self)
Calculates the Mesh::ATTRIBUTE_NORMAL
of an indexed mesh, smoothing normals for shared
vertices.
§Panics
Panics if Mesh::ATTRIBUTE_POSITION
is not of type float3
.
Panics if the mesh has any other topology than PrimitiveTopology::TriangleList
.
Panics if the mesh does not have indices defined.
FIXME: This should handle more cases since this is called as a part of gltf mesh loading where we can’t really blame users for loading meshes that might not conform to the limitations here!
Sourcepub fn with_computed_normals(self) -> Mesh
pub fn with_computed_normals(self) -> Mesh
Consumes the mesh and returns a mesh with calculated Mesh::ATTRIBUTE_NORMAL
.
If the mesh is indexed, this defaults to smooth normals. Otherwise, it defaults to flat
normals.
(Alternatively, you can use Mesh::compute_normals
to mutate an existing mesh in-place)
§Panics
Panics if Mesh::ATTRIBUTE_POSITION
is not of type float3
.
Panics if the mesh has any other topology than PrimitiveTopology::TriangleList
.
Sourcepub fn with_computed_flat_normals(self) -> Mesh
pub fn with_computed_flat_normals(self) -> Mesh
Consumes the mesh and returns a mesh with calculated Mesh::ATTRIBUTE_NORMAL
.
(Alternatively, you can use Mesh::compute_flat_normals
to mutate an existing mesh in-place)
§Panics
Panics if Mesh::ATTRIBUTE_POSITION
is not of type float3
.
Panics if the mesh has any other topology than PrimitiveTopology::TriangleList
.
Panics if the mesh has indices defined
Sourcepub fn with_computed_smooth_normals(self) -> Mesh
pub fn with_computed_smooth_normals(self) -> Mesh
Consumes the mesh and returns a mesh with calculated Mesh::ATTRIBUTE_NORMAL
.
(Alternatively, you can use Mesh::compute_smooth_normals
to mutate an existing mesh in-place)
§Panics
Panics if Mesh::ATTRIBUTE_POSITION
is not of type float3
.
Panics if the mesh has any other topology than PrimitiveTopology::TriangleList
.
Panics if the mesh does not have indices defined.
Sourcepub fn generate_tangents(&mut self) -> Result<(), GenerateTangentsError>
pub fn generate_tangents(&mut self) -> Result<(), GenerateTangentsError>
Generate tangents for the mesh using the mikktspace
algorithm.
Sets the Mesh::ATTRIBUTE_TANGENT
attribute if successful.
Requires a PrimitiveTopology::TriangleList
topology and the Mesh::ATTRIBUTE_POSITION
, Mesh::ATTRIBUTE_NORMAL
and Mesh::ATTRIBUTE_UV_0
attributes set.
Sourcepub fn with_generated_tangents(self) -> Result<Mesh, GenerateTangentsError>
pub fn with_generated_tangents(self) -> Result<Mesh, GenerateTangentsError>
Consumes the mesh and returns a mesh with tangents generated using the mikktspace
algorithm.
The resulting mesh will have the Mesh::ATTRIBUTE_TANGENT
attribute if successful.
(Alternatively, you can use Mesh::generate_tangents
to mutate an existing mesh in-place)
Requires a PrimitiveTopology::TriangleList
topology and the Mesh::ATTRIBUTE_POSITION
, Mesh::ATTRIBUTE_NORMAL
and Mesh::ATTRIBUTE_UV_0
attributes set.
Sourcepub fn merge(&mut self, other: &Mesh)
pub fn merge(&mut self, other: &Mesh)
Merges the Mesh
data of other
with self
. The attributes and indices of other
will be appended to self
.
Note that attributes of other
that don’t exist on self
will be ignored.
Aabb
of entities with modified mesh are not updated automatically.
§Panics
Panics if the vertex attribute values of other
are incompatible with self
.
For example, VertexAttributeValues::Float32
is incompatible with VertexAttributeValues::Float32x3
.
Sourcepub fn transformed_by(self, transform: Transform) -> Mesh
pub fn transformed_by(self, transform: Transform) -> Mesh
Transforms the vertex positions, normals, and tangents of the mesh by the given Transform
.
Aabb
of entities with modified mesh are not updated automatically.
Sourcepub fn transform_by(&mut self, transform: Transform)
pub fn transform_by(&mut self, transform: Transform)
Transforms the vertex positions, normals, and tangents of the mesh in place by the given Transform
.
Aabb
of entities with modified mesh are not updated automatically.
Sourcepub fn translated_by(self, translation: Vec3) -> Mesh
pub fn translated_by(self, translation: Vec3) -> Mesh
Translates the vertex positions of the mesh by the given Vec3
.
Aabb
of entities with modified mesh are not updated automatically.
Sourcepub fn translate_by(&mut self, translation: Vec3)
pub fn translate_by(&mut self, translation: Vec3)
Translates the vertex positions of the mesh in place by the given Vec3
.
Aabb
of entities with modified mesh are not updated automatically.
Sourcepub fn rotated_by(self, rotation: Quat) -> Mesh
pub fn rotated_by(self, rotation: Quat) -> Mesh
Rotates the vertex positions, normals, and tangents of the mesh by the given Quat
.
Aabb
of entities with modified mesh are not updated automatically.
Sourcepub fn rotate_by(&mut self, rotation: Quat)
pub fn rotate_by(&mut self, rotation: Quat)
Rotates the vertex positions, normals, and tangents of the mesh in place by the given Quat
.
Aabb
of entities with modified mesh are not updated automatically.
Sourcepub fn scaled_by(self, scale: Vec3) -> Mesh
pub fn scaled_by(self, scale: Vec3) -> Mesh
Scales the vertex positions, normals, and tangents of the mesh by the given Vec3
.
Aabb
of entities with modified mesh are not updated automatically.
Sourcepub fn scale_by(&mut self, scale: Vec3)
pub fn scale_by(&mut self, scale: Vec3)
Scales the vertex positions, normals, and tangents of the mesh in place by the given Vec3
.
Aabb
of entities with modified mesh are not updated automatically.
Sourcepub fn has_morph_targets(&self) -> bool
pub fn has_morph_targets(&self) -> bool
Whether this mesh has morph targets.
Sourcepub fn set_morph_targets(&mut self, morph_targets: Handle<Image>)
pub fn set_morph_targets(&mut self, morph_targets: Handle<Image>)
Set morph targets image for this mesh. This requires a “morph target image”. See MorphTargetImage
for info.
pub fn morph_targets(&self) -> Option<&Handle<Image>>
Sourcepub fn with_morph_targets(self, morph_targets: Handle<Image>) -> Mesh
pub fn with_morph_targets(self, morph_targets: Handle<Image>) -> Mesh
Consumes the mesh and returns a mesh with the given morph targets.
This requires a “morph target image”. See MorphTargetImage
for info.
(Alternatively, you can use Mesh::set_morph_targets
to mutate an existing mesh in-place)
Sourcepub fn set_morph_target_names(&mut self, names: Vec<String>)
pub fn set_morph_target_names(&mut self, names: Vec<String>)
Sets the names of each morph target. This should correspond to the order of the morph targets in set_morph_targets
.
Sourcepub fn with_morph_target_names(self, names: Vec<String>) -> Mesh
pub fn with_morph_target_names(self, names: Vec<String>) -> Mesh
Consumes the mesh and returns a mesh with morph target names.
Names should correspond to the order of the morph targets in set_morph_targets
.
(Alternatively, you can use Mesh::set_morph_target_names
to mutate an existing mesh in-place)
Sourcepub fn morph_target_names(&self) -> Option<&[String]>
pub fn morph_target_names(&self) -> Option<&[String]>
Gets a list of all morph target names, if they exist.
Sourcepub fn normalize_joint_weights(&mut self)
pub fn normalize_joint_weights(&mut self)
Normalize joint weights so they sum to 1.
Sourcepub fn triangles(
&self,
) -> Result<impl Iterator<Item = Triangle3d>, MeshTrianglesError>
pub fn triangles( &self, ) -> Result<impl Iterator<Item = Triangle3d>, MeshTrianglesError>
Get a list of this Mesh’s triangles as an iterator if possible.
Returns an error if any of the following conditions are met (see MeshTrianglesError
):
- The Mesh’s primitive topology is not
TriangleList
orTriangleStrip
. - The Mesh is missing position or index data.
- The Mesh’s position data has the wrong format (not
Float32x3
).
Trait Implementations§
Source§impl From<CircularSector> for Mesh
impl From<CircularSector> for Mesh
Source§fn from(sector: CircularSector) -> Mesh
fn from(sector: CircularSector) -> Mesh
Converts this sector into a Mesh
using a default CircularSectorMeshBuilder
.
See the documentation of CircularSectorMeshBuilder
for more details.
Source§impl From<CircularSegment> for Mesh
impl From<CircularSegment> for Mesh
Source§fn from(segment: CircularSegment) -> Mesh
fn from(segment: CircularSegment) -> Mesh
Converts this sector into a Mesh
using a default CircularSegmentMeshBuilder
.
See the documentation of CircularSegmentMeshBuilder
for more details.
Source§impl From<ConicalFrustum> for Mesh
impl From<ConicalFrustum> for Mesh
Source§fn from(frustum: ConicalFrustum) -> Mesh
fn from(frustum: ConicalFrustum) -> Mesh
Source§impl<const N: usize> From<ConvexPolygon<N>> for Mesh
impl<const N: usize> From<ConvexPolygon<N>> for Mesh
Source§fn from(polygon: ConvexPolygon<N>) -> Mesh
fn from(polygon: ConvexPolygon<N>) -> Mesh
Source§impl From<RegularPolygon> for Mesh
impl From<RegularPolygon> for Mesh
Source§fn from(polygon: RegularPolygon) -> Mesh
fn from(polygon: RegularPolygon) -> Mesh
Source§impl<T> From<T> for Meshwhere
T: MeshBuilder,
impl<T> From<T> for Meshwhere
T: MeshBuilder,
Source§impl From<Tetrahedron> for Mesh
impl From<Tetrahedron> for Mesh
Source§fn from(tetrahedron: Tetrahedron) -> Mesh
fn from(tetrahedron: Tetrahedron) -> Mesh
Source§impl From<Triangle2d> for Mesh
impl From<Triangle2d> for Mesh
Source§fn from(triangle: Triangle2d) -> Mesh
fn from(triangle: Triangle2d) -> Mesh
Source§impl From<Triangle3d> for Mesh
impl From<Triangle3d> for Mesh
Source§fn from(triangle: Triangle3d) -> Mesh
fn from(triangle: Triangle3d) -> Mesh
Source§impl FromReflect for Meshwhere
Mesh: Any + Send + Sync,
Option<Indices>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Handle<Image>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Vec<String>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
RenderAssetUsages: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
impl FromReflect for Meshwhere
Mesh: Any + Send + Sync,
Option<Indices>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Handle<Image>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Vec<String>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
RenderAssetUsages: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Source§fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Mesh>
fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Mesh>
Self
from a reflected value.Source§fn take_from_reflect(
reflect: Box<dyn PartialReflect>,
) -> Result<Self, Box<dyn PartialReflect>>
fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>
Self
using,
constructing the value using from_reflect
if that fails. Read moreSource§impl GetTypeRegistration for Meshwhere
Mesh: Any + Send + Sync,
Option<Indices>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Handle<Image>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Vec<String>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
RenderAssetUsages: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
impl GetTypeRegistration for Meshwhere
Mesh: Any + Send + Sync,
Option<Indices>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Handle<Image>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Vec<String>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
RenderAssetUsages: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Source§fn get_type_registration() -> TypeRegistration
fn get_type_registration() -> TypeRegistration
TypeRegistration
for this type.Source§fn register_type_dependencies(registry: &mut TypeRegistry)
fn register_type_dependencies(registry: &mut TypeRegistry)
Source§impl PartialReflect for Meshwhere
Mesh: Any + Send + Sync,
Option<Indices>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Handle<Image>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Vec<String>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
RenderAssetUsages: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
impl PartialReflect for Meshwhere
Mesh: Any + Send + Sync,
Option<Indices>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Handle<Image>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Vec<String>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
RenderAssetUsages: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Source§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
Source§fn clone_value(&self) -> Box<dyn PartialReflect>
fn clone_value(&self) -> Box<dyn PartialReflect>
Reflect
trait object. Read moreSource§fn try_apply(
&mut self,
value: &(dyn PartialReflect + 'static),
) -> Result<(), ApplyError>
fn try_apply( &mut self, value: &(dyn PartialReflect + 'static), ) -> Result<(), ApplyError>
Source§fn reflect_kind(&self) -> ReflectKind
fn reflect_kind(&self) -> ReflectKind
Source§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
Source§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
Source§fn reflect_owned(self: Box<Mesh>) -> ReflectOwned
fn reflect_owned(self: Box<Mesh>) -> ReflectOwned
Source§fn try_into_reflect(
self: Box<Mesh>,
) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
fn try_into_reflect( self: Box<Mesh>, ) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
Source§fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>
fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>
Source§fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>
fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>
Source§fn into_partial_reflect(self: Box<Mesh>) -> Box<dyn PartialReflect>
fn into_partial_reflect(self: Box<Mesh>) -> Box<dyn PartialReflect>
Source§fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)
fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)
Source§fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)
fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)
Source§fn reflect_partial_eq(
&self,
value: &(dyn PartialReflect + 'static),
) -> Option<bool>
fn reflect_partial_eq( &self, value: &(dyn PartialReflect + 'static), ) -> Option<bool>
Source§fn apply(&mut self, value: &(dyn PartialReflect + 'static))
fn apply(&mut self, value: &(dyn PartialReflect + 'static))
Source§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
Source§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Source§fn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
Source§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
Source§impl Reflect for Meshwhere
Mesh: Any + Send + Sync,
Option<Indices>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Handle<Image>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Vec<String>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
RenderAssetUsages: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
impl Reflect for Meshwhere
Mesh: Any + Send + Sync,
Option<Indices>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Handle<Image>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Vec<String>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
RenderAssetUsages: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut dyn Any
. Read moreSource§fn into_reflect(self: Box<Mesh>) -> Box<dyn Reflect>
fn into_reflect(self: Box<Mesh>) -> Box<dyn Reflect>
Source§fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect(&self) -> &(dyn Reflect + 'static)
Source§fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
Source§impl Struct for Meshwhere
Mesh: Any + Send + Sync,
Option<Indices>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Handle<Image>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Vec<String>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
RenderAssetUsages: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
impl Struct for Meshwhere
Mesh: Any + Send + Sync,
Option<Indices>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Handle<Image>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Vec<String>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
RenderAssetUsages: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Source§fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>
fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>
name
as a &dyn PartialReflect
.Source§fn field_mut(
&mut self,
name: &str,
) -> Option<&mut (dyn PartialReflect + 'static)>
fn field_mut( &mut self, name: &str, ) -> Option<&mut (dyn PartialReflect + 'static)>
name
as a
&mut dyn PartialReflect
.Source§fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>
fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>
index
as a
&dyn PartialReflect
.Source§fn field_at_mut(
&mut self,
index: usize,
) -> Option<&mut (dyn PartialReflect + 'static)>
fn field_at_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>
index
as a &mut dyn PartialReflect
.Source§fn name_at(&self, index: usize) -> Option<&str>
fn name_at(&self, index: usize) -> Option<&str>
index
.Source§fn iter_fields(&self) -> FieldIter<'_>
fn iter_fields(&self) -> FieldIter<'_>
Source§fn clone_dynamic(&self) -> DynamicStruct
fn clone_dynamic(&self) -> DynamicStruct
DynamicStruct
.Source§fn get_represented_struct_info(&self) -> Option<&'static StructInfo>
fn get_represented_struct_info(&self) -> Option<&'static StructInfo>
None
if TypeInfo
is not available.Source§impl TypePath for Mesh
impl TypePath for Mesh
Source§fn type_path() -> &'static str
fn type_path() -> &'static str
Source§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
Source§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
Source§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
Source§impl Typed for Meshwhere
Mesh: Any + Send + Sync,
Option<Indices>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Handle<Image>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Vec<String>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
RenderAssetUsages: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
impl Typed for Meshwhere
Mesh: Any + Send + Sync,
Option<Indices>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Handle<Image>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Option<Vec<String>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
RenderAssetUsages: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Source§impl VisitAssetDependencies for Mesh
impl VisitAssetDependencies for Mesh
fn visit_dependencies(&self, visit: &mut impl FnMut(UntypedAssetId))
impl Asset for Mesh
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, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.Source§impl<A> AssetContainer for Awhere
A: Asset,
impl<A> AssetContainer for Awhere
A: Asset,
fn insert(self: Box<A>, id: UntypedAssetId, world: &mut World)
fn asset_type_name(&self) -> &'static str
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere
T: TypePath,
Source§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
TypePath::type_path
.Source§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
Source§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
TypePath::type_ident
.Source§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
TypePath::crate_name
.Source§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
Source§impl<T> DynamicTyped for Twhere
T: Typed,
impl<T> DynamicTyped for Twhere
T: Typed,
Source§fn reflect_type_info(&self) -> &'static TypeInfo
fn reflect_type_info(&self) -> &'static TypeInfo
Typed::type_info
.Source§impl<S> GetField for Swhere
S: Struct,
impl<S> GetField for Swhere
S: Struct,
Source§impl<T> GetPath for T
impl<T> GetPath for T
Source§fn reflect_path<'p>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path<'p>( &self, path: impl ReflectPath<'p>, ) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
path
. Read moreSource§fn reflect_path_mut<'p>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
path
. Read moreSource§fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
path
. Read moreSource§fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
path
. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more