From e6faf993b00c44e50e4c08e0ec3235954bd0c1f6 Mon Sep 17 00:00:00 2001 From: Robin KAY Date: Fri, 8 Jul 2022 21:18:32 +0000 Subject: [PATCH] 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(). --- crates/bevy_render/src/mesh/mesh/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/bevy_render/src/mesh/mesh/mod.rs b/crates/bevy_render/src/mesh/mesh/mod.rs index b4fecc066d..fde82287d1 100644 --- a/crates/bevy_render/src/mesh/mesh/mod.rs +++ b/crates/bevy_render/src/mesh/mesh/mod.rs @@ -116,6 +116,16 @@ impl Mesh { ); } + /// Removes the data for a vertex attribute + pub fn remove_attribute( + &mut self, + attribute: impl Into, + ) -> Option { + self.attributes + .remove(&attribute.into()) + .map(|data| data.values) + } + #[inline] pub fn contains_attribute(&self, id: impl Into) -> bool { self.attributes.contains_key(&id.into())