From 1f69bc1f9615dbe366516d1307d0142e7700a2cc Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Thu, 31 Oct 2024 17:06:32 +0000 Subject: [PATCH] Mesh::merge: count_vertices instead of initializing positions (#16024) # Objective When merging two meshes, we need to find the offset of indices for the second mesh. Currently it is done by inserting empty positions if positions is not set. Although practically it is not an issue, this does not feel right: - We did not have positions before, then why we have positions after merge? - Moreover, if positions are not set, but uvs are not empty, computed offset will be zero, while it should be equal to the number of uvs. ## Solution Use `Mesh::count_vertices` to find the number of vertices. ## Testing Looking hard. --- crates/bevy_mesh/src/mesh.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/bevy_mesh/src/mesh.rs b/crates/bevy_mesh/src/mesh.rs index 22698c4e68..8a5ac7e37d 100644 --- a/crates/bevy_mesh/src/mesh.rs +++ b/crates/bevy_mesh/src/mesh.rs @@ -793,10 +793,7 @@ impl Mesh { use VertexAttributeValues::*; // The indices of `other` should start after the last vertex of `self`. - let index_offset = self - .attribute(Mesh::ATTRIBUTE_POSITION) - .get_or_insert(&Float32x3(Vec::default())) - .len(); + let index_offset = self.count_vertices(); // Extend attributes of `self` with attributes of `other`. for (attribute, values) in self.attributes_mut() {