[Bf-blender-cvs] [ab20e3d9cb1] greasepencil-object: GPencil: New Thickness and Angle params in Convert Mesh

Antonio Vazquez noreply at git.blender.org
Tue Mar 31 16:49:28 CEST 2020


Commit: ab20e3d9cb198aae53d59ac38e4370c4bc469135
Author: Antonio Vazquez
Date:   Tue Mar 31 16:07:41 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rBab20e3d9cb198aae53d59ac38e4370c4bc469135

GPencil: New Thickness and Angle params in Convert Mesh

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

M	source/blender/blenkernel/BKE_gpencil_geom.h
M	source/blender/blenkernel/intern/gpencil_geom.c
M	source/blender/editors/object/object_add.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil_geom.h b/source/blender/blenkernel/BKE_gpencil_geom.h
index 25841e35b9c..9d1f422e16b 100644
--- a/source/blender/blenkernel/BKE_gpencil_geom.h
+++ b/source/blender/blenkernel/BKE_gpencil_geom.h
@@ -112,7 +112,9 @@ void BKE_gpencil_convert_mesh(struct Main *bmain,
                               struct Object *ob_gp,
                               struct Object *ob_mesh,
                               const bool gpencil_lines,
-                              const bool only_stroke);
+                              const bool only_stroke,
+                              const float angle,
+                              const int thickness);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c
index f89b5851664..cb0c1843009 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.c
+++ b/source/blender/blenkernel/intern/gpencil_geom.c
@@ -1991,11 +1991,11 @@ typedef struct GpEdge {
   int flag;
 } GpEdge;
 
-static int gpencil_next_edge(GpEdge *gp_edges, int totedges, GpEdge *gped_init, const bool reverse)
+static int gpencil_next_edge(
+    GpEdge *gp_edges, int totedges, GpEdge *gped_init, const float threshold, const bool reverse)
 {
   int edge = -1;
   float last_angle = 999999.0f;
-  const float threshold = DEG2RADF(70.0f);
   for (int i = 0; i < totedges; i++) {
     GpEdge *gped = &gp_edges[i];
     if (gped->flag != 0) {
@@ -2027,13 +2027,14 @@ static int gpencil_walk_edge(GHash *v_table,
                              int totedges,
                              uint *stroke_array,
                              int init_idx,
+                             const float angle,
                              const bool reverse)
 {
   GpEdge *gped_init = &gp_edges[init_idx];
   int idx = 1;
   int edge = 0;
   while (edge > -1) {
-    edge = gpencil_next_edge(gp_edges, totedges, gped_init, reverse);
+    edge = gpencil_next_edge(gp_edges, totedges, gped_init, angle, reverse);
     if (edge > -1) {
       GpEdge *gped = &gp_edges[edge];
       stroke_array[idx] = edge;
@@ -2064,7 +2065,10 @@ static int gpencil_walk_edge(GHash *v_table,
   return idx;
 }
 
-static void gpencil_generate_edgeloops(Object *ob, bGPDframe *gpf_stroke)
+static void gpencil_generate_edgeloops(Object *ob,
+                                       bGPDframe *gpf_stroke,
+                                       const float angle,
+                                       const int thickness)
 {
   Mesh *me = (Mesh *)ob->data;
   if (me->totedge == 0) {
@@ -2119,9 +2123,9 @@ static void gpencil_generate_edgeloops(Object *ob, bGPDframe *gpf_stroke)
     /* Hash used to avoid loop over same vertice. */
     GHash *v_table = BLI_ghash_int_new(__func__);
     /* Look forward edges. */
-    int totedges = gpencil_walk_edge(v_table, gp_edges, me->totedge, stroke_fw, e, false);
+    int totedges = gpencil_walk_edge(v_table, gp_edges, me->totedge, stroke_fw, e, angle, false);
     /* Look backward edges. */
-    int totbw = gpencil_walk_edge(v_table, gp_edges, me->totedge, stroke_bw, e, true);
+    int totbw = gpencil_walk_edge(v_table, gp_edges, me->totedge, stroke_bw, e, angle, false);
 
     BLI_ghash_free(v_table, NULL, NULL);
 
@@ -2137,7 +2141,8 @@ static void gpencil_generate_edgeloops(Object *ob, bGPDframe *gpf_stroke)
     }
 
     /* Create Stroke. */
-    bGPDstroke *gps_stroke = BKE_gpencil_stroke_add(gpf_stroke, 0, array_len + 1, 5, false);
+    bGPDstroke *gps_stroke = BKE_gpencil_stroke_add(
+        gpf_stroke, 0, array_len + 1, thickness, false);
 
     /* Create first segment. */
     uint v = stroke[0];
@@ -2183,6 +2188,8 @@ static void gpencil_generate_edgeloops(Object *ob, bGPDframe *gpf_stroke)
  * \param gpencil_lines: Use lines for strokes.
  * \param use_collections: Create layers using collection names.
  * \param only_stroke: The material must be only stroke without fill.
+ * \param angle: Limit angle to consider a edgeloop ends.
+ * \param thickness: Thickness of the strokes.
  */
 void BKE_gpencil_convert_mesh(Main *bmain,
                               Depsgraph *depsgraph,
@@ -2190,7 +2197,9 @@ void BKE_gpencil_convert_mesh(Main *bmain,
                               Object *ob_gp,
                               Object *ob_mesh,
                               const bool gpencil_lines,
-                              const bool only_stroke)
+                              const bool only_stroke,
+                              const float angle,
+                              const int thickness)
 {
   if (ELEM(NULL, ob_gp, ob_mesh) || (ob_gp->type != OB_GPENCIL) || (ob_gp->data == NULL)) {
     return;
@@ -2262,12 +2271,11 @@ void BKE_gpencil_convert_mesh(Main *bmain,
   /* Create stroke from edges. */
   bGPDlayer *gpl_stroke = BKE_gpencil_layer_addnew(gpd, DATA_("Lines"), true);
   bGPDframe *gpf_stroke = BKE_gpencil_layer_frame_get(gpl_stroke, CFRA, GP_GETFRAME_ADD_COPY);
-  gpencil_generate_edgeloops(ob_eval, gpf_stroke);
+  gpencil_generate_edgeloops(ob_eval, gpf_stroke, angle, thickness);
 
   /* Tag for recalculation */
   DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
 }
-
 /* Apply Transforms */
 void BKE_gpencil_transform(bGPdata *gpd, float mat[4][4])
 {
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index fab0641d709..12fdf1f128c 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -96,6 +96,8 @@
 #include "RNA_define.h"
 #include "RNA_enum_types.h"
 
+#include "UI_interface.h"
+
 #include "WM_api.h"
 #include "WM_types.h"
 
@@ -2220,6 +2222,9 @@ static int convert_exec(bContext *C, wmOperator *op)
   Object *gpencil_ob = NULL;
   const short target = RNA_enum_get(op->ptr, "target");
   bool keep_original = RNA_boolean_get(op->ptr, "keep_original");
+  const float angle = RNA_float_get(op->ptr, "angle");
+  const int thickness = RNA_int_get(op->ptr, "thickness");
+
   int a, mballConverted = 0;
   bool gpencilConverted = false;
 
@@ -2345,7 +2350,8 @@ static int convert_exec(bContext *C, wmOperator *op)
       copy_v3_v3(gpencil_ob->rot, eul);
       copy_v3_v3(gpencil_ob->scale, size);
 
-      BKE_gpencil_convert_mesh(bmain, depsgraph, scene, gpencil_ob, ob, false, true);
+      BKE_gpencil_convert_mesh(
+          bmain, depsgraph, scene, gpencil_ob, ob, false, true, angle, thickness);
       gpencilConverted = true;
     }
     else if (ob->type == OB_MESH) {
@@ -2625,8 +2631,25 @@ static int convert_exec(bContext *C, wmOperator *op)
   return OPERATOR_FINISHED;
 }
 
+static void convert_ui(bContext *C, wmOperator *op)
+{
+  uiLayout *layout = op->layout;
+  PointerRNA ptr;
+
+  RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
+  uiItemR(layout, &ptr, "target", 0, NULL, ICON_NONE);
+  uiItemR(layout, &ptr, "keep_original", 0, NULL, ICON_NONE);
+
+  if (RNA_enum_get(&ptr, "target") == OB_GPENCIL) {
+    uiItemR(layout, &ptr, "angle", 0, NULL, ICON_NONE);
+    uiItemR(layout, &ptr, "thickness", 0, NULL, ICON_NONE);
+  }
+}
+
 void OBJECT_OT_convert(wmOperatorType *ot)
 {
+  PropertyRNA *prop;
+
   /* identifiers */
   ot->name = "Convert to";
   ot->description = "Convert selected objects to another type";
@@ -2636,6 +2659,7 @@ void OBJECT_OT_convert(wmOperatorType *ot)
   ot->invoke = WM_menu_invoke;
   ot->exec = convert_exec;
   ot->poll = convert_poll;
+  ot->ui = convert_ui;
 
   /* flags */
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -2648,6 +2672,20 @@ void OBJECT_OT_convert(wmOperatorType *ot)
                   0,
                   "Keep Original",
                   "Keep original objects instead of replacing them");
+
+  prop = RNA_def_float_rotation(ot->srna,
+                                "angle",
+                                0,
+                                NULL,
+                                DEG2RADF(0.0f),
+                                DEG2RADF(180.0f),
+                                "Angle",
+                                "",
+                                DEG2RADF(0.0f),
+                                DEG2RADF(180.0f));
+  RNA_def_property_float_default(prop, DEG2RADF(70.0f));
+
+  RNA_def_int(ot->srna, "thickness", 5, 1, 10000, "Thickness", "", 1, 200);
 }
 
 /** \} */



More information about the Bf-blender-cvs mailing list