Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2019-12-17 17:20:11 +0300
committerSybren A. Stüvel <sybren@blender.org>2019-12-17 17:22:29 +0300
commit7830ea29c2ea6c30cec1dcd6d6c11a1f228e9cd7 (patch)
tree969bbfaf42037b93996c08bff3ca75211e515a53 /source/blender/blenkernel/intern/action.c
parent3a5562151fdfc3c1531350ffd99534b50fbb0f37 (diff)
Fix T68665: FCurve group disappear on Curve/Surface object data
When going from EDIT to OBJECT mode, Blender updates the object data from the edit-mode data. This took care of renaming FCurves that animate Curve control points when control points are added/removed, but this didn't keep the FCurve groups intact. Since the FCurve groups are tightly connected to the Action channels, it's hard to keep the group pointers intact during this process. Instead of making the code even more complex in an attempt to do that, I implemented a function (`BKE_action_groups_reconstruct()`) that rebuilds the group channel pointers. The call to `action_groups_add_channel()` had to be removed because it updates the the next/prev pointers of the FCurve while we're looping over them, causing infinite loops.
Diffstat (limited to 'source/blender/blenkernel/intern/action.c')
-rw-r--r--source/blender/blenkernel/intern/action.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index ad6c696b655..b474e3f5ec5 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -343,6 +343,43 @@ void action_groups_add_channel(bAction *act, bActionGroup *agrp, FCurve *fcurve)
fcurve->grp = agrp;
}
+/* Reconstruct group channel pointers.
+ * Assumes that the channels are still in the proper order, i.e. that channels of the same group
+ * are adjacent in the act->channels list. It also assumes that the groups
+ * referred to by the FCurves are already in act->groups.
+ */
+void BKE_action_groups_reconstruct(bAction *act)
+{
+ /* Sanity check. */
+ if (ELEM(NULL, act, act->groups.first)) {
+ return;
+ }
+
+ /* Clear out all group channels. Channels that are actually in use are
+ * reconstructed below; this step is necessary to clear out unused groups. */
+ LISTBASE_FOREACH (bActionGroup *, group, &act->groups) {
+ BLI_listbase_clear(&group->channels);
+ }
+
+ bActionGroup *grp;
+ bActionGroup *last_grp = NULL;
+ LISTBASE_FOREACH (FCurve *, fcurve, &act->curves) {
+ if (fcurve->grp == NULL) {
+ continue;
+ }
+
+ grp = fcurve->grp;
+ if (last_grp != grp) {
+ /* If this is the first time we see this group, this must be the first channel. */
+ grp->channels.first = fcurve;
+ }
+
+ /* This is the last channel, until it's overwritten by a later iteration. */
+ grp->channels.last = fcurve;
+ last_grp = grp;
+ }
+}
+
/* Remove the given channel from all groups */
void action_groups_remove_channel(bAction *act, FCurve *fcu)
{