[Bf-blender-cvs] [8d097f7194e] greasepencil-object: GPencil: Add option to disable Faces conversion from mesh

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


Commit: 8d097f7194e02e98a2cdb2c3771701fa25163111
Author: Antonio Vazquez
Date:   Tue Mar 31 16:49:16 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB8d097f7194e02e98a2cdb2c3771701fa25163111

GPencil: Add option to disable Faces conversion from 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 658b4d3e673..19de8155cc9 100644
--- a/source/blender/blenkernel/BKE_gpencil_geom.h
+++ b/source/blender/blenkernel/BKE_gpencil_geom.h
@@ -113,7 +113,8 @@ void BKE_gpencil_convert_mesh(struct Main *bmain,
                               struct Object *ob_mesh,
                               const float angle,
                               const int thickness,
-                              const bool use_seams);
+                              const bool use_seams,
+                              const bool use_faces);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c
index 4c01e9788d1..ced14e21b1c 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.c
+++ b/source/blender/blenkernel/intern/gpencil_geom.c
@@ -2193,7 +2193,8 @@ static void gpencil_generate_edgeloops(Object *ob,
  * \param ob_mesh: Mesh to convert.
  * \param angle: Limit angle to consider a edgeloop ends.
  * \param thickness: Thickness of the strokes.
- * \param only_seams: Only export seam edges.
+ * \param use_seams: Only export seam edges.
+ * \param use_seams: Export faces as filled strokes.
  */
 void BKE_gpencil_convert_mesh(Main *bmain,
                               Depsgraph *depsgraph,
@@ -2202,7 +2203,8 @@ void BKE_gpencil_convert_mesh(Main *bmain,
                               Object *ob_mesh,
                               const float angle,
                               const int thickness,
-                              const bool use_seams)
+                              const bool use_seams,
+                              const bool use_faces)
 {
   if (ELEM(NULL, ob_gp, ob_mesh) || (ob_gp->type != OB_GPENCIL) || (ob_gp->data == NULL)) {
     return;
@@ -2230,44 +2232,47 @@ void BKE_gpencil_convert_mesh(Main *bmain,
   /* Create stroke material. */
   gpencil_add_material(bmain, ob_gp, "Stroke", default_colors[0], true, false, &r_idx);
 
-  /* If no materials, create a simple fill. */
-  if (ob_mesh->totcol == 0) {
-    gpencil_add_material(bmain, ob_gp, "Fill", default_colors[1], false, true, &r_idx);
-  }
-  else {
-    /* Create all materials for fill. */
-    for (int i = 0; i < ob_mesh->totcol; i++) {
-      Material *ma = BKE_object_material_get(ob_mesh, i + 1);
-      float color[4];
-      copy_v3_v3(color, &ma->r);
-      color[3] = 1.0f;
-      gpencil_add_material(bmain, ob_gp, ma->id.name + 2, color, false, true, &r_idx);
-    }
-  }
-
-  /* Read all polygons and create fill for each. */
-  if (mpoly_len > 0) {
-    bGPDlayer *gpl_fill = BKE_gpencil_layer_addnew(gpd, DATA_("Fills"), true);
-    bGPDframe *gpf_fill = BKE_gpencil_layer_frame_get(gpl_fill, CFRA, GP_GETFRAME_ADD_COPY);
-    for (i = 0, mp = mpoly; i < mpoly_len; i++, mp++) {
-      MLoop *ml = &mloop[mp->loopstart];
-      /* Create fill stroke. */
-      bGPDstroke *gps_fill = BKE_gpencil_stroke_add(
-          gpf_fill, mp->mat_nr + 1, mp->totloop, 10, false);
-      gps_fill->flag |= GP_STROKE_CYCLIC;
-
-      /* Add points to strokes. */
-      int j;
-      for (j = 0; j < mp->totloop; j++, ml++) {
-        MVert *mv = &me->mvert[ml->v];
-
-        bGPDspoint *pt = &gps_fill->points[j];
-        copy_v3_v3(&pt->x, mv->co);
-        pt->pressure = 1.0f;
-        pt->strength = 1.0f;
+  /* Export faces as filled strokes. */
+  if (use_faces) {
+    /* If no materials, create a simple fill. */
+    if (ob_mesh->totcol == 0) {
+      gpencil_add_material(bmain, ob_gp, "Fill", default_colors[1], false, true, &r_idx);
+    }
+    else {
+      /* Create all materials for fill. */
+      for (int i = 0; i < ob_mesh->totcol; i++) {
+        Material *ma = BKE_object_material_get(ob_mesh, i + 1);
+        float color[4];
+        copy_v3_v3(color, &ma->r);
+        color[3] = 1.0f;
+        gpencil_add_material(bmain, ob_gp, ma->id.name + 2, color, false, true, &r_idx);
       }
+    }
+
+    /* Read all polygons and create fill for each. */
+    if (mpoly_len > 0) {
+      bGPDlayer *gpl_fill = BKE_gpencil_layer_addnew(gpd, DATA_("Fills"), true);
+      bGPDframe *gpf_fill = BKE_gpencil_layer_frame_get(gpl_fill, CFRA, GP_GETFRAME_ADD_COPY);
+      for (i = 0, mp = mpoly; i < mpoly_len; i++, mp++) {
+        MLoop *ml = &mloop[mp->loopstart];
+        /* Create fill stroke. */
+        bGPDstroke *gps_fill = BKE_gpencil_stroke_add(
+            gpf_fill, mp->mat_nr + 1, mp->totloop, 10, false);
+        gps_fill->flag |= GP_STROKE_CYCLIC;
+
+        /* Add points to strokes. */
+        int j;
+        for (j = 0; j < mp->totloop; j++, ml++) {
+          MVert *mv = &me->mvert[ml->v];
+
+          bGPDspoint *pt = &gps_fill->points[j];
+          copy_v3_v3(&pt->x, mv->co);
+          pt->pressure = 1.0f;
+          pt->strength = 1.0f;
+        }
 
-      BKE_gpencil_stroke_geometry_update(gps_fill);
+        BKE_gpencil_stroke_geometry_update(gps_fill);
+      }
     }
   }
 
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index 089f59ea220..f30b1cf6679 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -2226,6 +2226,7 @@ static int convert_exec(bContext *C, wmOperator *op)
   const float angle = RNA_float_get(op->ptr, "angle");
   const int thickness = RNA_int_get(op->ptr, "thickness");
   const bool use_seams = RNA_boolean_get(op->ptr, "seams");
+  const bool use_faces = RNA_boolean_get(op->ptr, "faces");
 
   int a, mballConverted = 0;
   bool gpencilConverted = false;
@@ -2353,7 +2354,7 @@ static int convert_exec(bContext *C, wmOperator *op)
       copy_v3_v3(gpencil_ob->scale, size);
 
       BKE_gpencil_convert_mesh(
-          bmain, depsgraph, scene, gpencil_ob, ob, angle, thickness, use_seams);
+          bmain, depsgraph, scene, gpencil_ob, ob, angle, thickness, use_seams, use_faces);
       gpencilConverted = true;
     }
     else if (ob->type == OB_MESH) {
@@ -2645,6 +2646,7 @@ static void convert_ui(bContext *C, wmOperator *op)
   if (RNA_enum_get(&ptr, "target") == OB_GPENCIL) {
     uiItemR(layout, &ptr, "angle", 0, NULL, ICON_NONE);
     uiItemR(layout, &ptr, "thickness", 0, NULL, ICON_NONE);
+    uiItemR(layout, &ptr, "faces", 0, NULL, ICON_NONE);
     uiItemR(layout, &ptr, "seams", 0, NULL, ICON_NONE);
   }
 }
@@ -2690,6 +2692,7 @@ void OBJECT_OT_convert(wmOperatorType *ot)
 
   RNA_def_int(ot->srna, "thickness", 5, 1, 10000, "Thickness", "", 1, 200);
   RNA_def_boolean(ot->srna, "seams", 0, "Only Seams", "Convert only seam edges");
+  RNA_def_boolean(ot->srna, "faces", 1, "Export Faces", "Export faces as filled strokes");
 }
 
 /** \} */



More information about the Bf-blender-cvs mailing list