[Bf-blender-cvs] [57f900e4efd] master: Fix T83705: GPencil - Duplicate strokes of destination layer when merge layer

Antonio Vazquez noreply at git.blender.org
Sat Dec 12 18:50:09 CET 2020


Commit: 57f900e4efdaa0e4daba8e3c52684acb52a67a2e
Author: Antonio Vazquez
Date:   Sat Dec 12 18:40:48 2020 +0100
Branches: master
https://developer.blender.org/rB57f900e4efdaa0e4daba8e3c52684acb52a67a2e

Fix T83705: GPencil -  Duplicate strokes of destination layer when merge layer

If the destination layer hadn't keyframe, a new keyframe was added and later the merge layer strokes were added, but this could change the animation because the new frame replaced the old drawings of the target layer.

Now, before merge the layer, all keyframes are added in the target layer in order to keep the drawings.

===================================================================

M	source/blender/editors/gpencil/gpencil_data.c

===================================================================

diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 33a1469beab..203e86e9e15 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -1330,19 +1330,24 @@ static int gpencil_merge_layer_exec(bContext *C, wmOperator *op)
     BLI_ghash_insert(gh_frames_dst, POINTER_FROM_INT(gpf_dst->framenum), gpf_dst);
   }
 
-  /* Read all frames from merge layer and add any missing in destination layer. */
+  /* Read all frames from merge layer and add any missing in destination layer,
+   * copying all previous strokes to keep the image equals. Need to do it in a separated
+   * loop to avoid strokes acumulation. */
   LISTBASE_FOREACH (bGPDframe *, gpf_src, &gpl_src->frames) {
     /* Try to find frame in destination layer hash table. */
     bGPDframe *gpf_dst = BLI_ghash_lookup(gh_frames_dst, POINTER_FROM_INT(gpf_src->framenum));
     if (!gpf_dst) {
-      gpf_dst = BKE_gpencil_frame_addnew(gpl_dst, gpf_src->framenum);
-      /* Duplicate strokes into destination frame. */
-      if (gpf_dst) {
-        BKE_gpencil_frame_copy_strokes(gpf_src, gpf_dst);
-      }
+      gpf_dst = BKE_gpencil_layer_frame_get(gpl_dst, gpf_src->framenum, GP_GETFRAME_ADD_COPY);
+      BLI_ghash_insert(gh_frames_dst, POINTER_FROM_INT(gpf_src->framenum), gpf_dst);
     }
-    else {
-      /* Add to tail all strokes. */
+  }
+
+  /* Read all frames from merge layer and add strokes. */
+  LISTBASE_FOREACH (bGPDframe *, gpf_src, &gpl_src->frames) {
+    /* Try to find frame in destination layer hash table. */
+    bGPDframe *gpf_dst = BLI_ghash_lookup(gh_frames_dst, POINTER_FROM_INT(gpf_src->framenum));
+    /* Add to tail all strokes. */
+    if (gpf_dst) {
       BLI_movelisttolist(&gpf_dst->strokes, &gpf_src->strokes);
     }
   }



More information about the Bf-blender-cvs mailing list