Anim: versioning, also bone create collections for empty bone groups

Change the versioning code so that all bone groups are converted to bone
collections, so also the ones that did not have any bones assigned.

As Demeter[1] put it: While bone groups with 0 bones assigned are
usually unintended, versioning should still preserve them I feel like,
just to be on the safe side. If there was an update to the vertex group
system, I would also expect empty vertex groups to survive, even though
they are strictly speaking pretty much pointless.

[1]: https://projects.blender.org/blender/blender/issues/111711#issuecomment-1013159
This commit is contained in:
Sybren A. Stüvel
2023-09-05 15:12:36 +02:00
parent 5250ae156e
commit bcd0198a46

View File

@@ -186,6 +186,21 @@ static void version_bonegroups_to_bonecollections(Main *bmain)
/* Convert the bone groups on a bone-by-bone basis. */
bArmature *arm = reinterpret_cast<bArmature *>(ob->data);
bPose *pose = ob->pose;
blender::Map<const bActionGroup *, BoneCollection *> collections_by_group;
/* Convert all bone groups, regardless of whether they contain any bones. */
LISTBASE_FOREACH (bActionGroup *, bgrp, &pose->agroups) {
BoneCollection *bcoll = ANIM_armature_bonecoll_new(arm, bgrp->name);
collections_by_group.add_new(bgrp, bcoll);
/* Before now, bone visibility was determined by armature layers, and bone
* groups did not have any impact on this. To retain the behavior, that
* hiding all layers a bone is on hides the bone, the
* bone-group-collections should be created hidden. */
ANIM_bonecoll_hide(bcoll);
}
/* Assign the bones to their bone group based collection. */
LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) {
/* Find the bone group of this pose channel. */
const bActionGroup *bgrp = (const bActionGroup *)BLI_findlink(&pose->agroups,
@@ -194,15 +209,8 @@ static void version_bonegroups_to_bonecollections(Main *bmain)
continue;
}
/* Get or create the bone collection. */
BoneCollection *bcoll = ANIM_armature_bonecoll_get_by_name(arm, bgrp->name);
if (!bcoll) {
bcoll = ANIM_armature_bonecoll_new(arm, bgrp->name);
ANIM_bonecoll_hide(bcoll);
}
/* Assign the bone. */
BoneCollection *bcoll = collections_by_group.lookup(bgrp);
ANIM_armature_bonecoll_assign(bcoll, pchan->bone);
}