[Bf-blender-cvs] [a6730c6995f] greasepencil-object: Fix problem with merge down

Antonio Vazquez noreply at git.blender.org
Mon Dec 18 17:29:49 CET 2017


Commit: a6730c6995fbe81b6a4f9cef58ddeb42815653aa
Author: Antonio Vazquez
Date:   Mon Dec 18 17:29:09 2017 +0100
Branches: greasepencil-object
https://developer.blender.org/rBa6730c6995fbe81b6a4f9cef58ddeb42815653aa

Fix problem with merge down

The problem was if the layer below had animation in frames not present in top layer. As the active frame of top layer was the previous keyframe, after merging, the draw of bottom layer replaced the draw of top layer and the result was that some drawings were missing.

The solution was to duplicate the active frame in top layer before merge the bottom layer.

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/editors/gpencil/gpencil_data.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index af2bf4ad8b1..92f983595bd 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -80,6 +80,7 @@ struct bGPdata   *BKE_gpencil_data_addnew(struct Main *bmain, const char name[])
 struct bGPDframe *BKE_gpencil_frame_duplicate(const struct bGPDframe *gpf_src);
 struct bGPDframe *BKE_gpencil_frame_color_duplicate(const struct bContext *C, const struct bGPDframe *gpf_src);
 struct bGPDlayer *BKE_gpencil_layer_duplicate(const struct bGPDlayer *gpl_src);
+void BKE_gpencil_frame_copy_strokes(struct bGPDframe *gpf_src, struct bGPDframe *gpf_dst);
 
 void BKE_gpencil_copy_data(struct Main *bmain, struct bGPdata *gpd_dst, const struct bGPdata *gpd_src, const int flag);
 struct bGPdata   *BKE_gpencil_copy(struct Main *bmain, const struct bGPdata *gpd);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index bbc0e1ed325..9b17dcafb00 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -934,6 +934,29 @@ bGPDframe *BKE_gpencil_frame_duplicate(const bGPDframe *gpf_src)
 	return gpf_dst;
 }
 
+/* make a copy of strokes between gpencil frames */
+void BKE_gpencil_frame_copy_strokes(bGPDframe *gpf_src, struct bGPDframe *gpf_dst)
+{
+	bGPDstroke *gps_dst;
+	/* error checking */
+	if ((gpf_src == NULL) || (gpf_dst == NULL)) {
+		return;
+	}
+
+	/* copy strokes */
+	BLI_listbase_clear(&gpf_dst->strokes);
+	for (bGPDstroke *gps_src = gpf_src->strokes.first; gps_src; gps_src = gps_src->next) {
+		/* make copy of source stroke, then adjust pointer to points too */
+		gps_dst = MEM_dupallocN(gps_src);
+		gps_dst->points = MEM_dupallocN(gps_src->points);
+		BKE_gpencil_stroke_weights_duplicate(gps_src, gps_dst);
+
+		gps_dst->triangles = MEM_dupallocN(gps_src->triangles);
+		gps_dst->flag |= GP_STROKE_RECALC_CACHES;
+		BLI_addtail(&gpf_dst->strokes, gps_dst);
+	}
+}
+
 /* fix any null value in palettes (this must be removed in the future) */
 static void gpencil_fix_null_palette(const bContext *C, bGPDstroke *gps_src)
 {
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 1174527928c..2566dda3b3d 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -673,17 +673,22 @@ static int gp_merge_layer_exec(bContext *C, wmOperator *op)
 		BLI_ghash_insert(gh_frames_cur, SET_INT_IN_POINTER(gpf->framenum), gpf);
 	}
 
-	/* read all frames from next layer */
+	/* read all frames from next layer and add any missing in current layer */
 	for (bGPDframe *gpf = gpl_next->frames.first; gpf; gpf = gpf->next) {
-		/* try to find frame in active layer */
+		/* try to find frame in current layer */
 		bGPDframe *frame = BLI_ghash_lookup(gh_frames_cur, SET_INT_IN_POINTER(gpf->framenum));
 		if (!frame) {
-			/* nothing found, create new */
+			bGPDframe *actframe = BKE_gpencil_layer_getframe(gpl_current, gpf->framenum, GP_GETFRAME_USE_PREV);
 			frame = BKE_gpencil_frame_addnew(gpl_current, gpf->framenum);
+			/* duplicate strokes of current active frame */
+			if (actframe) {
+				BKE_gpencil_frame_copy_strokes(actframe, frame);
+			}
 		}
 		/* add to tail all strokes */
 		BLI_movelisttolist(&frame->strokes, &gpf->strokes);
 	}
+
 	/* Now delete next layer */
 	BKE_gpencil_layer_delete(gpd, gpl_next);
 	BLI_ghash_free(gh_frames_cur, NULL, NULL);



More information about the Bf-blender-cvs mailing list