Struct bevy::render::mesh::Mesh

pub struct Mesh { /* private fields */ }

Implementations

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
}

Where the vertex is located in space. Use in conjunction with Mesh::insert_attribute

The direction the vertex normal is facing in. Use in conjunction with Mesh::insert_attribute

Texture coordinates for the vertex. Use in conjunction with Mesh::insert_attribute

The direction of the vertex tangent. Used for normal mapping

Per vertex coloring. Use in conjunction with Mesh::insert_attribute

Per vertex joint transform matrix weight. Use in conjunction with Mesh::insert_attribute

Per vertex joint transform matrix index. Use in conjunction with Mesh::insert_attribute

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.

Returns the topology of the mesh.

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.

Panics

Panics when the format of the values does not match the attribute’s format.

Removes the data for a vertex attribute

Retrieves the data currently set to the vertex attribute with the specified name.

Retrieves the data currently set to the vertex attribute with the specified name mutably.

Returns an iterator that yields references to the data of each vertex attribute.

Returns an iterator that yields mutable references to the data of each vertex attribute.

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.

Retrieves the vertex indices of the mesh.

Retrieves the vertex indices of the mesh mutably.

Computes and returns the index data of the mesh as bytes. This is used to transform the index data into a GPU friendly format.

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.

Counts all vertices of the mesh.

Panics

Panics if the attributes have different vertex counts.

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.

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.

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.

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.

Compute the Axis-Aligned Bounding Box of the mesh vertices in model space

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

Clones the mesh.

Converts the extracted mesh a into GpuMesh.

The representation of the asset in the “render world”.
The GPU-representation of the asset.
Specifies all ECS data required by RenderAsset::prepare_asset. For convenience use the lifetimeless SystemParam. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
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
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
Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more
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
Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

Returns the UUID associated with this value’s type.

Returns the type name of this value’s type.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more