From 3e3297ac03dc31bd8453239e52b5d2ee526926ba Mon Sep 17 00:00:00 2001 From: Ben Reeves Date: Sat, 12 Feb 2022 20:09:03 -0600 Subject: [PATCH 1/3] bevy_render: Add `attributes` and `attributes_mut` methods to `Mesh`. --- crates/bevy_render/src/mesh/mesh/mod.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/bevy_render/src/mesh/mesh/mod.rs b/crates/bevy_render/src/mesh/mesh/mod.rs index 8f891ec0e7e48..742b57d8abc99 100644 --- a/crates/bevy_render/src/mesh/mesh/mod.rs +++ b/crates/bevy_render/src/mesh/mesh/mod.rs @@ -141,6 +141,22 @@ impl Mesh { .map(|data| &mut data.values) } + /// Returns an iterator that yields references to the data of each vertex attribute. + pub fn attributes(&self) -> impl Iterator + '_ { + self.attributes + .iter() + .map(|(name, values)| (name.as_ref(), values)) + } + + /// Returns an iterator that yields mutable references to the data of each vertex attribute. + pub fn attributes_mut( + &mut self, + ) -> impl Iterator { + self.attributes + .iter_mut() + .map(|(name, values)| (name.as_ref(), values)) + } + /// 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. From 65d1e947394f533c132a6e1118333e343adaffe9 Mon Sep 17 00:00:00 2001 From: Ben Reeves Date: Sat, 12 Feb 2022 21:12:37 -0600 Subject: [PATCH 2/3] Eschew lifetimes :-) --- crates/bevy_render/src/mesh/mesh/mod.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/bevy_render/src/mesh/mesh/mod.rs b/crates/bevy_render/src/mesh/mesh/mod.rs index 742b57d8abc99..2f76ca0c7421c 100644 --- a/crates/bevy_render/src/mesh/mesh/mod.rs +++ b/crates/bevy_render/src/mesh/mesh/mod.rs @@ -142,16 +142,14 @@ impl Mesh { } /// Returns an iterator that yields references to the data of each vertex attribute. - pub fn attributes(&self) -> impl Iterator + '_ { + pub fn attributes(&self) -> impl Iterator { self.attributes .iter() .map(|(name, values)| (name.as_ref(), values)) } /// Returns an iterator that yields mutable references to the data of each vertex attribute. - pub fn attributes_mut( - &mut self, - ) -> impl Iterator { + pub fn attributes_mut(&mut self) -> impl Iterator { self.attributes .iter_mut() .map(|(name, values)| (name.as_ref(), values)) From 7e4f535b633082f70e891a71bf85aa215044d0a0 Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Tue, 14 Jun 2022 23:29:09 -0700 Subject: [PATCH 3/3] update to use new apis --- crates/bevy_render/src/mesh/mesh/mod.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/bevy_render/src/mesh/mesh/mod.rs b/crates/bevy_render/src/mesh/mesh/mod.rs index 2f76ca0c7421c..3193ebb5d1a09 100644 --- a/crates/bevy_render/src/mesh/mesh/mod.rs +++ b/crates/bevy_render/src/mesh/mesh/mod.rs @@ -142,17 +142,19 @@ impl Mesh { } /// Returns an iterator that yields references to the data of each vertex attribute. - pub fn attributes(&self) -> impl Iterator { - self.attributes - .iter() - .map(|(name, values)| (name.as_ref(), values)) + pub fn attributes( + &self, + ) -> impl Iterator { + self.attributes.iter().map(|(id, data)| (*id, &data.values)) } /// Returns an iterator that yields mutable references to the data of each vertex attribute. - pub fn attributes_mut(&mut self) -> impl Iterator { + pub fn attributes_mut( + &mut self, + ) -> impl Iterator { self.attributes .iter_mut() - .map(|(name, values)| (name.as_ref(), values)) + .map(|(id, data)| (*id, &mut data.values)) } /// Sets the vertex indices of the mesh. They describe how triangles are constructed out of the