[Bf-blender-cvs] [62d6adc11b1] greasepencil-object: GPencil: Implement holes for Trace Images
Antonio Vazquez
noreply at git.blender.org
Tue Jul 21 19:14:27 CEST 2020
Commit: 62d6adc11b1a44bb7038c1f488b48b4b97a8fc4d
Author: Antonio Vazquez
Date: Tue Jul 21 19:13:56 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB62d6adc11b1a44bb7038c1f488b48b4b97a8fc4d
GPencil: Implement holes for Trace Images
As the new masking modes are available for materials, now it's possible open holes for negative strokes.
===================================================================
M source/blender/blenkernel/BKE_gpencil.h
M source/blender/blenkernel/intern/gpencil.c
M source/blender/blenkernel/intern/gpencil_geom.c
M source/blender/editors/gpencil/gpencil_trace.h
M source/blender/editors/gpencil/gpencil_trace_ops.c
M source/blender/editors/gpencil/gpencil_trace_utils.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index cd434566e43..598729fc819 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -277,6 +277,8 @@ void BKE_gpencil_parent_matrix_get(const struct Depsgraph *depsgraph,
void BKE_gpencil_update_layer_parent(const struct Depsgraph *depsgraph, struct Object *ob);
+int BKE_gpencil_material_find_index_by_name_prefix(struct Object *ob, const char *name_prefix);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index eeb55c44d6e..18a5a97664c 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -2497,4 +2497,25 @@ void BKE_gpencil_update_layer_parent(const Depsgraph *depsgraph, Object *ob)
}
}
}
+
+/**
+ * Find materil by name prefix.
+ * \param ob: Object pointer
+ * \param name_prefix: Prefix name of the material
+ * \return Index
+ */
+int BKE_gpencil_material_find_index_by_name_prefix(Object *ob, const char *name_prefix)
+{
+ const int name_prefix_len = strlen(name_prefix);
+ for (int i = 0; i < ob->totcol; i++) {
+ Material *ma = BKE_object_material_get(ob, i + 1);
+ if ((ma != NULL) && (ma->gp_style != NULL) &&
+ (STREQLEN(ma->id.name + 2, name_prefix, name_prefix_len))) {
+ return i;
+ }
+ }
+
+ return -1;
+}
+
/** \} */
diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c
index 0b965899689..07181c286f5 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.c
+++ b/source/blender/blenkernel/intern/gpencil_geom.c
@@ -2259,19 +2259,6 @@ static Material *gpencil_add_material(Main *bmain,
return mat_gp;
}
-static int gpencil_material_find_index_by_name_prefix(Object *ob, const char *name_prefix)
-{
- const int name_prefix_len = strlen(name_prefix);
- for (int i = 0; i < ob->totcol; i++) {
- Material *ma = BKE_object_material_get(ob, i + 1);
- if ((ma != NULL) && (ma->gp_style != NULL) &&
- (STREQLEN(ma->id.name + 2, name_prefix, name_prefix_len))) {
- return i;
- }
- }
-
- return -1;
-}
/**
* Convert a mesh object to grease pencil stroke.
*
@@ -2316,8 +2303,8 @@ void BKE_gpencil_convert_mesh(Main *bmain,
MLoop *mloop = me_eval->mloop;
int mpoly_len = me_eval->totpoly;
int i;
- int stroke_mat_index = gpencil_material_find_index_by_name_prefix(ob_gp, "Stroke");
- int fill_mat_index = gpencil_material_find_index_by_name_prefix(ob_gp, "Fill");
+ int stroke_mat_index = BKE_gpencil_material_find_index_by_name_prefix(ob_gp, "Stroke");
+ int fill_mat_index = BKE_gpencil_material_find_index_by_name_prefix(ob_gp, "Fill");
/* If the object has enough materials means it was created in a previous step. */
const bool create_mat = ((ob_gp->totcol > 0) && (ob_gp->totcol >= ob_mesh->totcol)) ? false :
diff --git a/source/blender/editors/gpencil/gpencil_trace.h b/source/blender/editors/gpencil/gpencil_trace.h
index 54a14fd1c38..675674f2c48 100644
--- a/source/blender/editors/gpencil/gpencil_trace.h
+++ b/source/blender/editors/gpencil/gpencil_trace.h
@@ -28,6 +28,7 @@
struct bGPDframe;
struct FILE;
struct ImBuf;
+struct Main;
struct Object;
#include "potracelib.h"
@@ -64,13 +65,15 @@ void ED_gpencil_trace_bm_invert(const potrace_bitmap_t *bm);
void ED_gpencil_trace_image_to_bm(struct ImBuf *ibuf,
const potrace_bitmap_t *bm,
const float threshold);
-void ED_gpencil_trace_data_to_gp(potrace_state_t *st,
- struct Object *ob,
- struct bGPDframe *gpf,
- int offset[2],
- const float scale,
- const float sample,
- const int resolution,
- const int thickness);
+
+void ED_gpencil_trace_data_to_strokes(struct Main *bmain,
+ potrace_state_t *st,
+ struct Object *ob,
+ struct bGPDframe *gpf,
+ int offset[2],
+ const float scale,
+ const float sample,
+ const int resolution,
+ const int thickness);
#endif /* __GPENCIL_TRACE_H__ */
diff --git a/source/blender/editors/gpencil/gpencil_trace_ops.c b/source/blender/editors/gpencil/gpencil_trace_ops.c
index ff30fff54eb..bd08ba17745 100644
--- a/source/blender/editors/gpencil/gpencil_trace_ops.c
+++ b/source/blender/editors/gpencil/gpencil_trace_ops.c
@@ -130,18 +130,6 @@ static int gpencil_trace_image_exec(bContext *C, wmOperator *op)
}
bGPdata *gpd = (bGPdata *)ob_gpencil->data;
- /* If the object has materials means it was created in a previous run. */
- if (ob_gpencil->totcol == 0) {
- const float default_color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
- int r_idx;
- Material *mat_gp = BKE_gpencil_object_material_new(bmain, ob_gpencil, "Material", &r_idx);
- MaterialGPencilStyle *gp_style = mat_gp->gp_style;
-
- linearrgb_to_srgb_v4(gp_style->stroke_rgba, default_color);
- gp_style->flag |= GP_MATERIAL_STROKE_SHOW;
- gp_style->flag &= ~GP_MATERIAL_FILL_SHOW;
- }
-
/* Create Layer and frame. */
bGPDlayer *gpl = NULL;
if (!newob) {
@@ -173,7 +161,8 @@ static int gpencil_trace_image_exec(bContext *C, wmOperator *op)
int offset[2];
offset[0] = ibuf->x / 2;
offset[1] = ibuf->y / 2;
- ED_gpencil_trace_data_to_gp(st, ob_gpencil, gpf, offset, scale, sample, resolution, thickness);
+ ED_gpencil_trace_data_to_strokes(
+ bmain, st, ob_gpencil, gpf, offset, scale, sample, resolution, thickness);
/* Free memory. */
potrace_state_free(st);
diff --git a/source/blender/editors/gpencil/gpencil_trace_utils.c b/source/blender/editors/gpencil/gpencil_trace_utils.c
index a8a3e6c7bb4..b5dce63be84 100644
--- a/source/blender/editors/gpencil/gpencil_trace_utils.c
+++ b/source/blender/editors/gpencil/gpencil_trace_utils.c
@@ -32,9 +32,12 @@
#include "BKE_gpencil.h"
#include "BKE_gpencil_geom.h"
#include "BKE_image.h"
+#include "BKE_main.h"
+#include "BKE_material.h"
#include "DNA_gpencil_types.h"
#include "DNA_image_types.h"
+#include "DNA_material_types.h"
#include "DNA_object_types.h"
#include "IMB_imbuf.h"
@@ -227,6 +230,7 @@ static void add_bezier(bGPDstroke *gps,
/**
* Convert Potrace Bitmap to Grease Pencil strokes
+ * \param bmain: Main pointer
* \param st: Data with traced data
* \param ob: Target grease pencil object
* \param gpf: Currect grease pencil frame
@@ -236,15 +240,48 @@ static void add_bezier(bGPDstroke *gps,
* \param resolution: Resolution of curves
* \param thickness: Thickness of the stroke
*/
-void ED_gpencil_trace_data_to_gp(potrace_state_t *st,
- Object *ob,
- bGPDframe *gpf,
- int offset[2],
- const float scale,
- const float sample,
- const int resolution,
- const int thickness)
+void ED_gpencil_trace_data_to_strokes(Main *bmain,
+ potrace_state_t *st,
+ Object *ob,
+ bGPDframe *gpf,
+ int offset[2],
+ const float scale,
+ const float sample,
+ const int resolution,
+ const int thickness)
{
+ /* If the object has materials means it was created in a previous run.
+ * Check only filled slots. */
+ int mat_fill_idx = BKE_gpencil_material_find_index_by_name_prefix(ob, "Stroke");
+ int mat_mask_idx = BKE_gpencil_material_find_index_by_name_prefix(ob, "Mask");
+
+ const float default_color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+ int r_idx;
+ /* Stroke and Fill material. */
+ if (mat_fill_idx == -1) {
+ Material *mat_gp = BKE_gpencil_object_material_new(bmain, ob, "Stroke", &r_idx);
+ MaterialGPencilStyle *gp_style = mat_gp->gp_style;
+
+ linearrgb_to_srgb_v4(gp_style->stroke_rgba, default_color);
+ gp_style->flag |= GP_MATERIAL_STROKE_SHOW;
+ gp_style->flag |= GP_MATERIAL_FILL_SHOW;
+ mat_fill_idx = ob->totcol - 1;
+ }
+ /* Masking material. */
+ if (mat_mask_idx == -1) {
+ Material *mat_gp = BKE_gpencil_object_material_new(bmain, ob, "Mask", &r_idx);
+ MaterialGPencilStyle *gp_style = mat_gp->gp_style;
+
+ linearrgb_to_srgb_v4(gp_style->stroke_rgba, default_color);
+ gp_style->stroke_rgba[3] = 0.0f;
+ gp_style->fill_rgba[3] = 0.0f;
+ gp_style->flag |= GP_MATERIAL_STROKE_SHOW;
+ gp_style->flag |= GP_MATERIAL_FILL_SHOW;
+ gp_style->flag |= GP_MATERIAL_IS_STROKE_MASK;
+ gp_style->flag |= GP_MATERIAL_IS_FILL_MASK;
+ mat_mask_idx = ob->totcol - 1;
+ }
+
potrace_path_t *path = st->plist;
int n, *tag;
potrace_dpoint_t(*c)[3];
@@ -256,8 +293,9 @@ void ED_gpencil_trace_data_to_gp(potrace_state_t *st,
n = path->curve.n;
tag = path->curve.tag;
c = path->curve.c;
+ int mat_idx = path->sign == '+' ? 0 : 1;
/* Create a new stroke. */
- bGPDstroke *gps = BKE_gpencil_stroke_add(gpf, 0, 0, thickness, false);
+ bGPDstroke *gps = BKE_gpencil_stroke_add(gpf, mat_idx, 0, thickness, false);
/* Last point that is equals to start point. */
float start_point[2], last[2];
start_point[0] = c[n - 1][2].x;
More information about the Bf-blender-cvs
mailing list