Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix invalid bone weights #8316

Merged
merged 3 commits into from
Apr 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion crates/bevy_render/src/mesh/mesh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl Mesh {
attribute: MeshVertexAttribute,
values: impl Into<VertexAttributeValues>,
) {
let values = values.into();
let mut values = values.into();
let values_format = VertexFormat::from(&values);
if values_format != attribute.format {
panic!(
Expand All @@ -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 });
}
Expand Down