[Bf-blender-cvs] [3411a44581c] temp-gpencil-fill: GGPencil: Enable multiframe en Draw and use in Eraser

Antonio Vazquez noreply at git.blender.org
Thu Jan 28 19:27:08 CET 2021


Commit: 3411a44581c582caf5186e1d9985c6493418ebdc
Author: Antonio Vazquez
Date:   Thu Jan 28 19:27:04 2021 +0100
Branches: temp-gpencil-fill
https://developer.blender.org/rB3411a44581c582caf5186e1d9985c6493418ebdc

GGPencil: Enable multiframe en Draw and use in Eraser

This is the first step to add the multiframe option in Draw mode.

Now, only the Eraser and the display frames is working .

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/makesdna/DNA_gpencil_types.h

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index e653ead21bb..c84294b7143 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -695,6 +695,10 @@ class VIEW3D_HT_header(Header):
                 row.prop(tool_settings, "use_gpencil_vertex_select_mask_stroke", text="")
                 row.prop(tool_settings, "use_gpencil_vertex_select_mask_segment", text="")
 
+            if gpd.is_stroke_paint_mode:
+                row = layout.row(align=True)
+                row.prop(gpd, "use_multiedit", text="", icon='GP_MULTIFRAME_EDITING')
+
             if (
                     gpd.use_stroke_edit_mode or
                     gpd.is_stroke_sculpt_mode or
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index b55e47d74f3..93d1ad63f8b 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1323,10 +1323,8 @@ static float view3d_point_depth(const RegionView3D *rv3d, const float co[3])
 }
 
 /* only erase stroke points that are visible */
-static bool gpencil_stroke_eraser_is_occluded(tGPsdata *p,
-                                              const bGPDspoint *pt,
-                                              const int x,
-                                              const int y)
+static bool gpencil_stroke_eraser_is_occluded(
+    tGPsdata *p, bGPDlayer *gpl, const bGPDspoint *pt, const int x, const int y)
 {
   Object *obact = (Object *)p->ownerPtr.data;
   Brush *brush = p->brush;
@@ -1343,7 +1341,6 @@ static bool gpencil_stroke_eraser_is_occluded(tGPsdata *p,
   if ((gp_settings != NULL) && (p->area->spacetype == SPACE_VIEW3D) &&
       (gp_settings->flag & GP_BRUSH_OCCLUDE_ERASER)) {
     RegionView3D *rv3d = p->region->regiondata;
-    bGPDlayer *gpl = p->gpl;
 
     const int mval_i[2] = {x, y};
     float mval_3d[3];
@@ -1454,6 +1451,7 @@ static void gpencil_stroke_soft_refine(bGPDstroke *gps)
 
 /* eraser tool - evaluation per stroke */
 static void gpencil_stroke_eraser_dostroke(tGPsdata *p,
+                                           bGPDlayer *gpl,
                                            bGPDframe *gpf,
                                            bGPDstroke *gps,
                                            const float mval[2],
@@ -1579,9 +1577,9 @@ static void gpencil_stroke_eraser_dostroke(tGPsdata *p,
          * - this assumes that linewidth is irrelevant
          */
         if (gpencil_stroke_inside_circle(mval, radius, pc0[0], pc0[1], pc2[0], pc2[1])) {
-          if ((gpencil_stroke_eraser_is_occluded(p, pt0, pc0[0], pc0[1]) == false) ||
-              (gpencil_stroke_eraser_is_occluded(p, pt1, pc1[0], pc1[1]) == false) ||
-              (gpencil_stroke_eraser_is_occluded(p, pt2, pc2[0], pc2[1]) == false)) {
+          if ((gpencil_stroke_eraser_is_occluded(p, gpl, pt0, pc0[0], pc0[1]) == false) ||
+              (gpencil_stroke_eraser_is_occluded(p, gpl, pt1, pc1[0], pc1[1]) == false) ||
+              (gpencil_stroke_eraser_is_occluded(p, gpl, pt2, pc2[0], pc2[1]) == false)) {
             /* Point is affected: */
             /* Adjust thickness
              *  - Influence of eraser falls off with distance from the middle of the eraser
@@ -1683,6 +1681,8 @@ static void gpencil_stroke_eraser_dostroke(tGPsdata *p,
 /* erase strokes which fall under the eraser strokes */
 static void gpencil_stroke_doeraser(tGPsdata *p)
 {
+  const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(p->gpd);
+
   rcti rect;
   Brush *brush = p->brush;
   Brush *eraser = p->eraser;
@@ -1723,40 +1723,53 @@ static void gpencil_stroke_doeraser(tGPsdata *p)
    * on multiple layers...
    */
   LISTBASE_FOREACH (bGPDlayer *, gpl, &p->gpd->layers) {
-    bGPDframe *gpf = gpl->actframe;
-
     /* only affect layer if it's editable (and visible) */
     if (BKE_gpencil_layer_is_editable(gpl) == false) {
       continue;
     }
-    if (gpf == NULL) {
+
+    bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
+    if (init_gpf == NULL) {
       continue;
     }
-    /* calculate difference matrix */
-    BKE_gpencil_layer_transform_matrix_get(p->depsgraph, p->ob, gpl, p->diff_mat);
 
-    /* loop over strokes, checking segments for intersections */
-    LISTBASE_FOREACH_MUTABLE (bGPDstroke *, gps, &gpf->strokes) {
-      /* check if the color is editable */
-      if (ED_gpencil_stroke_material_editable(p->ob, gpl, gps) == false) {
-        continue;
-      }
+    for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
+      if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
+        if (gpf == NULL) {
+          continue;
+        }
+        /* calculate difference matrix */
+        BKE_gpencil_layer_transform_matrix_get(p->depsgraph, p->ob, gpl, p->diff_mat);
+
+        /* loop over strokes, checking segments for intersections */
+        LISTBASE_FOREACH_MUTABLE (bGPDstroke *, gps, &gpf->strokes) {
+          /* check if the color is editable */
+          if (ED_gpencil_stroke_material_editable(p->ob, gpl, gps) == false) {
+            continue;
+          }
 
-      /* Check if the stroke collide with mouse. */
-      if (!ED_gpencil_stroke_check_collision(&p->gsc, gps, p->mval, calc_radius, p->diff_mat)) {
-        continue;
-      }
+          /* Check if the stroke collide with mouse. */
+          if (!ED_gpencil_stroke_check_collision(
+                  &p->gsc, gps, p->mval, calc_radius, p->diff_mat)) {
+            continue;
+          }
 
-      /* Not all strokes in the datablock may be valid in the current editor/context
-       * (e.g. 2D space strokes in the 3D view, if the same datablock is shared)
-       */
-      if (ED_gpencil_stroke_can_use_direct(p->area, gps)) {
-        gpencil_stroke_eraser_dostroke(p, gpf, gps, p->mval, calc_radius, &rect);
+          /* Not all strokes in the datablock may be valid in the current editor/context
+           * (e.g. 2D space strokes in the 3D view, if the same datablock is shared)
+           */
+          if (ED_gpencil_stroke_can_use_direct(p->area, gps)) {
+            gpencil_stroke_eraser_dostroke(p, gpl, gpf, gps, p->mval, calc_radius, &rect);
+          }
+        }
+
+        /* if not multiedit, exit loop*/
+        if (!is_multiedit) {
+          break;
+        }
       }
     }
   }
 }
-
 /* ******************************************* */
 /* Sketching Operator */
 
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 1dbfd547673..9a9f449f9b3 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -809,8 +809,9 @@ typedef enum eGP_DrawMode {
 /* Check if 'multiedit sessions' is enabled */
 #define GPENCIL_MULTIEDIT_SESSIONS_ON(gpd) \
   ((gpd) && \
-   ((gpd)->flag & (GP_DATA_STROKE_EDITMODE | GP_DATA_STROKE_SCULPTMODE | \
-                   GP_DATA_STROKE_WEIGHTMODE | GP_DATA_STROKE_VERTEXMODE)) && \
+   ((gpd)->flag & \
+    (GP_DATA_STROKE_PAINTMODE | GP_DATA_STROKE_EDITMODE | GP_DATA_STROKE_SCULPTMODE | \
+     GP_DATA_STROKE_WEIGHTMODE | GP_DATA_STROKE_VERTEXMODE)) && \
    ((gpd)->flag & GP_DATA_STROKE_MULTIEDIT))
 
 #define GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd) \



More information about the Bf-blender-cvs mailing list