diff --git a/crates/bevy_render/src/mesh/mesh/mod.rs b/crates/bevy_render/src/mesh/mesh/mod.rs index d58c5e2cf7..6e407510f2 100644 --- a/crates/bevy_render/src/mesh/mesh/mod.rs +++ b/crates/bevy_render/src/mesh/mesh/mod.rs @@ -110,7 +110,7 @@ impl Mesh { attribute: MeshVertexAttribute, values: impl Into, ) { - let values = values.into(); + let mut values = values.into(); let values_format = VertexFormat::from(&values); if values_format != attribute.format { panic!( @@ -119,6 +119,17 @@ impl Mesh { ); } + // validate attributes + if attribute.id == Self::ATTRIBUTE_JOINT_WEIGHT.id { + let VertexAttributeValues::Float32x4(ref mut values) = values else { + unreachable!() // we confirmed the format above + }; + for value in values.iter_mut().filter(|v| *v == &[0.0, 0.0, 0.0, 0.0]) { + // zero weights are invalid + value[0] = 1.0; + } + } + self.attributes .insert(attribute.id, MeshAttributeData { attribute, values }); }