[Bf-blender-cvs] [2985a745bb0] master: GPencil: Add new parameter to set caps in Cutter

Antonio Vazquez noreply at git.blender.org
Thu Oct 22 17:44:22 CEST 2020


Commit: 2985a745bb016c43e837b908fbd873e2daff3440
Author: Antonio Vazquez
Date:   Thu Oct 22 17:35:48 2020 +0200
Branches: master
https://developer.blender.org/rB2985a745bb016c43e837b908fbd873e2daff3440

GPencil: Add new parameter to set caps in Cutter

The new parameter allows to define if after cutting the stroke the cap of the cut side will be set as flat. 

Before, the cap shape of the cut side always was equal to the original stroke, and in some situations, the rounded cap was visible.

Note: If the angle of the join is very extreme,  it's still possible to view some sections of the cut stroke.,

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

M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	source/blender/editors/gpencil/gpencil_edit.c

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

diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index ebe00668474..b3f4757d10a 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -1814,6 +1814,11 @@ class _defs_gpencil_paint:
 
     @ToolDef.from_fn
     def cutter():
+        def draw_settings(context, layout, tool):
+            props = tool.operator_properties("gpencil.stroke_cutter")
+            row = layout.row()
+            row.use_property_split = False
+            row.prop(props, "flat_caps")
         return dict(
             idname="builtin.cutter",
             label="Cutter",
@@ -1821,6 +1826,7 @@ class _defs_gpencil_paint:
             cursor='KNIFE',
             widget=None,
             keymap=(),
+            draw_settings=draw_settings,
         )
 
     @ToolDef.from_fn
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index d54bdf552eb..7d79e748f75 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -4678,7 +4678,9 @@ typedef bool (*GPencilTestFn)(bGPDstroke *gps,
                               const float diff_mat[4][4],
                               void *user_data);
 
-static void gpencil_cutter_dissolve(bGPDlayer *hit_layer, bGPDstroke *hit_stroke)
+static void gpencil_cutter_dissolve(bGPDlayer *hit_layer,
+                                    bGPDstroke *hit_stroke,
+                                    const bool flat_caps)
 {
   bGPDspoint *pt = NULL;
   bGPDspoint *pt1 = NULL;
@@ -4722,6 +4724,17 @@ static void gpencil_cutter_dissolve(bGPDlayer *hit_layer, bGPDstroke *hit_stroke
         pt->flag &= ~GP_SPOINT_TAG;
       }
     }
+    /* If flat caps mode check extremes. */
+    if (flat_caps) {
+      if (hit_stroke->points[0].flag & GP_SPOINT_TAG) {
+        hit_stroke->caps[0] = GP_STROKE_CAP_FLAT;
+      }
+
+      if (hit_stroke->points[hit_stroke->totpoints - 1].flag & GP_SPOINT_TAG) {
+        hit_stroke->caps[1] = GP_STROKE_CAP_FLAT;
+      }
+    }
+
     gpencil_stroke_delete_tagged_points(
         hit_layer->actframe, hit_stroke, gpsn, GP_SPOINT_TAG, false, 1);
   }
@@ -4736,6 +4749,7 @@ static int gpencil_cutter_lasso_select(bContext *C,
   ScrArea *area = CTX_wm_area(C);
   ToolSettings *ts = CTX_data_tool_settings(C);
   const float scale = ts->gp_sculpt.isect_threshold;
+  const bool flat_caps = RNA_boolean_get(op->ptr, "flat_caps");
 
   bGPDspoint *pt;
   GP_SpaceConversion gsc = {NULL};
@@ -4810,7 +4824,7 @@ static int gpencil_cutter_lasso_select(bContext *C,
     }
     LISTBASE_FOREACH_MUTABLE (bGPDstroke *, gps, &gpf->strokes) {
       if (gps->flag & GP_STROKE_SELECT) {
-        gpencil_cutter_dissolve(gpl, gps);
+        gpencil_cutter_dissolve(gpl, gps, flat_caps);
       }
     }
   }
@@ -4884,6 +4898,8 @@ void GPENCIL_OT_stroke_cutter(wmOperatorType *ot)
 
   /* properties */
   WM_operator_properties_gesture_lasso(ot);
+
+  RNA_def_boolean(ot->srna, "flat_caps", 0, "Flat Caps", "");
 }
 
 bool ED_object_gpencil_exit(struct Main *bmain, Object *ob)



More information about the Bf-blender-cvs mailing list