From 671ab311908f0b501f98684748e74c3e76598eef Mon Sep 17 00:00:00 2001 From: Torstein Grindvik <52322338+torsteingrindvik@users.noreply.github.com> Date: Wed, 25 Oct 2023 21:03:05 +0200 Subject: [PATCH] Make mesh attr vertex count mismatch warn more readable (#10259) # Objective When a mesh vertex attribute has a vertex count mismatch, a warning message is printed with the index of the attribute which did not match. Change to name the attribute, or fall back to the old behaviour if it was not a known attribute. Before: ``` MeshVertexAttributeId(2) has a different vertex count (32) than other attributes (64) in this mesh, all attributes will be truncated to match the smallest. ``` After: ``` Vertex_Uv has a different vertex count (32) than other attributes (64) in this mesh, all attributes will be truncated to match the smallest. ``` ## Solution Name the mesh attribute which had a count mismatch. ## Changelog - If a mesh vertex attribute has a different count than other vertex attributes, name the offending attribute using a human readable name Signed-off-by: Torstein Grindvik Co-authored-by: Torstein Grindvik --- crates/bevy_render/src/mesh/mesh/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/bevy_render/src/mesh/mesh/mod.rs b/crates/bevy_render/src/mesh/mesh/mod.rs index 7f92c3bcd19f8..b304d1b0f2f99 100644 --- a/crates/bevy_render/src/mesh/mesh/mod.rs +++ b/crates/bevy_render/src/mesh/mesh/mod.rs @@ -385,7 +385,13 @@ impl Mesh { let attribute_len = attribute_data.values.len(); if let Some(previous_vertex_count) = vertex_count { if previous_vertex_count != attribute_len { - warn!("{attribute_id:?} has a different vertex count ({attribute_len}) than other attributes ({previous_vertex_count}) in this mesh, \ + let name = self + .attributes + .get(attribute_id) + .map(|data| data.attribute.name.to_string()) + .unwrap_or_else(|| format!("{attribute_id:?}")); + + warn!("{name} has a different vertex count ({attribute_len}) than other attributes ({previous_vertex_count}) in this mesh, \ all attributes will be truncated to match the smallest."); vertex_count = Some(std::cmp::min(previous_vertex_count, attribute_len)); }