[Bf-blender-cvs] [11ba9eec701] master: GPencil: Show only first frame if current frame is equals or greater than current frame

Antonio Vazquez noreply at git.blender.org
Mon Jun 8 09:05:50 CEST 2020


Commit: 11ba9eec70175b39e34943c8ffacb54c35cbb897
Author: Antonio Vazquez
Date:   Mon Jun 8 09:01:07 2020 +0200
Branches: master
https://developer.blender.org/rB11ba9eec70175b39e34943c8ffacb54c35cbb897

GPencil: Show only first frame if current frame is equals or greater than current frame

Previously, the first frame was displayed from frame 0, but now, the first frame is only displayed when the current frame is equal or greater than the keyframe number.

The previous system was logical when the grease pencil was not an object, but now it seems more logical to display the keyframe if the current frame is equal to or greater than the keyframe number.

Reviewed By: mendio, pepeland

Differential Revision: https://developer.blender.org/D7851

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

M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_primitive.c

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

diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 1e24d61380c..284aa57f43a 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1011,6 +1011,12 @@ bGPDframe *BKE_gpencil_layer_frame_get(bGPDlayer *gpl, int cframe, eGP_GetFrame_
     }
   }
 
+  /* Don't select first frame if greater than current frame. */
+  if ((gpl->actframe != NULL) && (gpl->actframe == gpl->frames.first) &&
+      (gpl->actframe->framenum > cframe)) {
+    gpl->actframe = NULL;
+  }
+
   /* return */
   return gpl->actframe;
 }
@@ -1878,6 +1884,7 @@ void BKE_gpencil_visible_stroke_iter(ViewLayer *view_layer,
   bGPdata *gpd = (bGPdata *)ob->data;
   const bool is_multiedit = GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
   const bool is_onion = do_onion && ((gpd->flag & GP_DATA_STROKE_WEIGHTMODE) == 0);
+  const bool is_drawing = (gpd->runtime.sbuffer_used > 0);
 
   /* Onion skinning. */
   const bool onion_mode_abs = (gpd->onion_mode == GP_ONION_MODE_ABSOLUTE);
@@ -1886,6 +1893,8 @@ void BKE_gpencil_visible_stroke_iter(ViewLayer *view_layer,
   const short onion_keytype = gpd->onion_keytype;
 
   LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+    /* Reset by layer. */
+    bool is_before_first = false;
 
     bGPDframe *act_gpf = gpl->actframe;
     bGPDframe *sta_gpf = act_gpf;
@@ -1924,6 +1933,16 @@ void BKE_gpencil_visible_stroke_iter(ViewLayer *view_layer,
       }
     }
     else if (is_onion && (gpl->onion_flag & GP_LAYER_ONIONSKIN)) {
+      /* Special cases when cframe is before first frame. */
+      bGPDframe *gpf_first = gpl->frames.first;
+      if ((gpf_first != NULL) && (act_gpf != NULL) && (gpf_first->framenum > act_gpf->framenum)) {
+        is_before_first = true;
+      }
+      if ((gpf_first != NULL) && (act_gpf == NULL)) {
+        act_gpf = gpf_first;
+        is_before_first = true;
+      }
+
       if (act_gpf) {
         bGPDframe *last_gpf = gpl->frames.last;
 
@@ -1938,6 +1957,10 @@ void BKE_gpencil_visible_stroke_iter(ViewLayer *view_layer,
           int delta = (onion_mode_abs) ? (gpf->framenum - cfra) :
                                          (gpf->runtime.frameid - act_gpf->runtime.frameid);
 
+          if (is_before_first) {
+            delta++;
+          }
+
           if (onion_mode_sel) {
             is_in_range = (gpf->flag & GP_FRAME_SELECT) != 0;
           }
@@ -1957,7 +1980,9 @@ void BKE_gpencil_visible_stroke_iter(ViewLayer *view_layer,
           gpf->runtime.onion_id = (is_wrong_keytype || !is_in_range) ? INT_MAX : delta;
         }
         /* Active frame is always shown. */
-        act_gpf->runtime.onion_id = 0;
+        if (!is_before_first || is_drawing) {
+          act_gpf->runtime.onion_id = 0;
+        }
       }
 
       sta_gpf = gpl->frames.first;
@@ -1977,10 +2002,15 @@ void BKE_gpencil_visible_stroke_iter(ViewLayer *view_layer,
 
     /* Draw multiedit/onion skinning first */
     for (bGPDframe *gpf = sta_gpf; gpf && gpf != end_gpf; gpf = gpf->next) {
-      if (gpf->runtime.onion_id == INT_MAX || gpf == act_gpf) {
+      if ((gpf->runtime.onion_id == INT_MAX || gpf == act_gpf) && (!is_before_first)) {
         continue;
       }
 
+      /* Only do once for frame before first. */
+      if (is_before_first && gpf == act_gpf) {
+        is_before_first = false;
+      }
+
       if (layer_cb) {
         layer_cb(gpl, gpf, NULL, thunk);
       }
@@ -1995,8 +2025,8 @@ void BKE_gpencil_visible_stroke_iter(ViewLayer *view_layer,
     /* Draw Active frame on top. */
     /* Use evaluated frame (with modifiers for active stroke)/ */
     act_gpf = gpl->actframe;
-    act_gpf->runtime.onion_id = 0;
     if (act_gpf) {
+      act_gpf->runtime.onion_id = 0;
       if (layer_cb) {
         layer_cb(gpl, act_gpf, NULL, thunk);
       }
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 06079c34d12..a9eb94498ad 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -2127,7 +2127,12 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps
       add_frame_mode = GP_GETFRAME_ADD_NEW;
     }
 
+    bool need_tag = p->gpl->actframe == NULL;
     p->gpf = BKE_gpencil_layer_frame_get(p->gpl, CFRA, add_frame_mode);
+    /* Only if there wasn't an active frame, need update. */
+    if (need_tag) {
+      DEG_id_tag_update(&p->gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
+    }
 
     if (p->gpf == NULL) {
       p->status = GP_STATUS_ERROR;
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index 875a6265497..82ae99b30be 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -1308,7 +1308,12 @@ static void gpencil_primitive_interaction_end(bContext *C,
     add_frame_mode = GP_GETFRAME_ADD_NEW;
   }
 
+  bool need_tag = tgpi->gpl->actframe == NULL;
   gpf = BKE_gpencil_layer_frame_get(tgpi->gpl, tgpi->cframe, add_frame_mode);
+  /* Only if there wasn't an active frame, need update. */
+  if (need_tag) {
+    DEG_id_tag_update(&tgpi->gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
+  }
 
   /* prepare stroke to get transferred */
   gps = tgpi->gpf->strokes.first;



More information about the Bf-blender-cvs mailing list