-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
normalize joint weights #10539
normalize joint weights #10539
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking suggestion: could we add a check that the joint weights are normalized when running in debug mode?
i can do this, but the warning becomes unavoidable ... if you load a gltf and once loaded you call up to you? |
Hmm 🤔 I think we can leave it. The real requirement here is for a general-purpose mesh-validation asset preprocessor IMO. |
}; | ||
|
||
for weights in joints.iter_mut() { | ||
let sum: f32 = weights.iter().sum(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth verifying the weights are positive first? If someone accidentally uses with_inserted_attribute
with a mixture of positive and negative floats, this will do weird things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
negative weights are technically not allowed in the spec, whereas not summing to precisely 1 is allowed due to rounding issues.
but sure, no reason not to. i arbitrarily chose to clamp negatives to zero, i guess other treatments might be better (like if all are negative, maybe you should just flip the sign?) but since we're in invalid-data territory there's probably no perfect answer. if someone wants a different treatment they can always write their own normalize function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
# Objective allow automatic fixing of bad joint weights. fix bevyengine#10447 ## Solution - remove automatic normalization of vertexes with all zero joint weights. - add `Mesh::normalize_joint_weights` which fixes zero joint weights, and also ensures that all weights sum to 1. this is a manual call as it may be slow to apply to large skinned meshes, and is unnecessary if you have control over the source assets. note: this became a more significant problem with 0.12, as weights that are close to, but not exactly 1 now seem to use `Vec3::ZERO` for the unspecified weight, where previously they used the entity translation.
Objective
allow automatic fixing of bad joint weights.
fix #10447
Solution
Mesh::normalize_joint_weights
which fixes zero joint weights, and also ensures that all weights sum to 1. this is a manual call as it may be slow to apply to large skinned meshes, and is unnecessary if you have control over the source assets.note: this became a more significant problem with 0.12, as weights that are close to, but not exactly 1 now seem to use
Vec3::ZERO
for the unspecified weight, where previously they used the entity translation.