Add support for removing attributes from meshes. (#5254)

# Objective

Support removing attributes from meshes. For an example use case, meshes created using the bevy::predule::shape types or loaded from external files may have attributes that are not needed for the materials they will be rendered with.

This was extracted from PR #5222.

## Solution

Implement Mesh::remove_attribute().
This commit is contained in:
Robin KAY 2022-07-08 21:18:32 +00:00
parent 3c51ad2764
commit e6faf993b0

View file

@ -116,6 +116,16 @@ impl Mesh {
);
}
/// Removes the data for a vertex attribute
pub fn remove_attribute(
&mut self,
attribute: impl Into<MeshVertexAttributeId>,
) -> Option<VertexAttributeValues> {
self.attributes
.remove(&attribute.into())
.map(|data| data.values)
}
#[inline]
pub fn contains_attribute(&self, id: impl Into<MeshVertexAttributeId>) -> bool {
self.attributes.contains_key(&id.into())