Mysteryem / Miscellaneous

Random scripts and programs that don't have a better home
MIT License
0 stars 0 forks source link

Blender addon to extend Vertex Group Limit Total behaviour to dissolve removed weights into parents #2

Open Mysteryem opened 2 years ago

Mysteryem commented 2 years ago

The purpose of doing this is so that removing the smallest weights doesn't increase the relative weights of bones other than those bones' parents.

As an implementation note, due to the fact that there could be multiple armature modifiers, with the same bones, but different hierarchies: the order we should check for a bone's parent is that we should start with the current context.pose_object if it is set, otherwise iterate through the armature modifiers in order until one of them has the bone we're looking for and that that bone has a parent bone.

This would of course only work with Deform Pose Bones.

If the weight to be dissolved has no parent bone we could give a user option:

Despite these options, there could still be more than the desired number of groups, e.g., multiple bones with no parents or children, in which case, then go through the weights again and simply delete the smallest weights. When doing this, we should record how many failed as we iterate initially, but then use Blender's existing Vertex Group Limit Total operator. A force limit option could be provided for toggling whether this is enabled or not.

Realistically, the case of no parent bone would only usually happen for when the Hip weight is the smallest weight on a vertex.

If the weight to be dissolved does have a parent bone, but it's not assigned to the vertex we could:

A rarer case might be where there is a chain of bones that go around a corner like \_/ a vertex could be assigned to the first and last bones of the chain, but not the middle bone, in which case, dissolving the weight of the last bone would have nowhere to go. We would need to decide whether such a bone is allowed to be dissolved into the first bone, despite it not being its direct parent, we could call this the 'closest parent group assigned to the vertex'.

The existing Vertex Group Limit Total operator also provides the ability to operate on only the selected pose bones, it may be useful to also implement for this subset.