[Bf-blender-cvs] [7a471d08205] greasepencil-object: GPencil: More work in trace
Antonio Vazquez
noreply at git.blender.org
Thu Apr 9 18:56:32 CEST 2020
Commit: 7a471d082052b1702fbdf40e47ec9922580d923a
Author: Antonio Vazquez
Date: Wed Apr 8 16:49:19 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB7a471d082052b1702fbdf40e47ec9922580d923a
GPencil: More work in trace
===================================================================
M source/blender/editors/gpencil/gpencil_convert.c
M source/blender/editors/gpencil/gpencil_trace_ops.c
M source/blender/editors/gpencil/gpencil_trace_utils.c
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_convert.c b/source/blender/editors/gpencil/gpencil_convert.c
index 5c224090a41..6c1e2db2818 100644
--- a/source/blender/editors/gpencil/gpencil_convert.c
+++ b/source/blender/editors/gpencil/gpencil_convert.c
@@ -1845,7 +1845,7 @@ void GPENCIL_OT_image_to_grease_pencil(wmOperatorType *ot)
0.0001f,
10.0f,
"Point Size",
- "Size used for graese pencil points",
+ "Size used for grease pencil points",
0.001f,
1.0f);
RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE);
diff --git a/source/blender/editors/gpencil/gpencil_trace_ops.c b/source/blender/editors/gpencil/gpencil_trace_ops.c
index a6a62231fe4..39770be2232 100644
--- a/source/blender/editors/gpencil/gpencil_trace_ops.c
+++ b/source/blender/editors/gpencil/gpencil_trace_ops.c
@@ -75,6 +75,7 @@ static bool gp_trace_image_poll(bContext *C)
static int gp_trace_image_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
SpaceImage *sima = CTX_wm_space_image(C);
Object *ob_gpencil = NULL;
@@ -128,8 +129,8 @@ static int gp_trace_image_exec(bContext *C, wmOperator *op)
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;
+ gp_style->flag |= GP_MATERIAL_STROKE_SHOW;
+ gp_style->flag &= ~GP_MATERIAL_FILL_SHOW;
}
/* Create Layer and frame. */
@@ -167,6 +168,13 @@ static int gp_trace_image_exec(bContext *C, wmOperator *op)
BKE_image_release_ibuf(sima->image, ibuf, lock);
}
+ /* notifiers */
+ DEG_id_tag_update(&scene->id, ID_RECALC_SELECT);
+ DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
+
+ WM_event_add_notifier(C, NC_OBJECT | NA_ADDED, NULL);
+ WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
+
return OPERATOR_FINISHED;
}
@@ -187,7 +195,7 @@ void GPENCIL_OT_trace_image(wmOperatorType *ot)
/* properties */
RNA_def_string(ot->srna,
"target",
- "Target",
+ "*NEW",
64,
"",
"Target grease pencil object name. Leave empty for new object");
diff --git a/source/blender/editors/gpencil/gpencil_trace_utils.c b/source/blender/editors/gpencil/gpencil_trace_utils.c
index a71b94a5518..04a010c87a7 100644
--- a/source/blender/editors/gpencil/gpencil_trace_utils.c
+++ b/source/blender/editors/gpencil/gpencil_trace_utils.c
@@ -29,6 +29,8 @@
#include "BLI_math.h"
+#include "BKE_gpencil.h"
+#include "BKE_gpencil_geom.h"
#include "BKE_image.h"
#include "DNA_gpencil_types.h"
@@ -179,6 +181,19 @@ static void write_line(FILE *fptr, char *line)
fprintf(fptr, "%s\n", line);
}
+static void add_point(bGPDstroke *gps, int idx, float scale, float x, float y)
+{
+ gps->points = MEM_recallocN(gps->points, sizeof(bGPDspoint) * gps->totpoints + 1);
+ bGPDspoint *pt = &gps->points[idx];
+ pt->x = x * scale;
+ pt->y = 0;
+ pt->z = y * scale;
+ pt->pressure = 1.0f;
+ pt->strength = 1.0f;
+
+ gps->totpoints++;
+}
+
/**
* Convert Potrace Bitmap to Grease Pencil strokes
* \param st: Data with traced data
@@ -187,30 +202,34 @@ static void write_line(FILE *fptr, char *line)
*/
void ED_gpencil_trace_data_to_gp(potrace_state_t *st, Object *ob, bGPDframe *gpf)
{
- potrace_path_t *p = st->plist;
+ potrace_path_t *path = st->plist;
int n, *tag;
potrace_dpoint_t(*c)[3];
FILE *fout = stderr;
char txt[256];
+ const float scale = 0.005f;
/* Draw each curve. */
- p = st->plist;
- while (p != NULL) {
- n = p->curve.n;
- tag = p->curve.tag;
- c = p->curve.c;
+ path = st->plist;
+ while (path != NULL) {
+ n = path->curve.n;
+ tag = path->curve.tag;
+ c = path->curve.c;
+ /* Create a new stroke. */
+ bGPDstroke *gps = BKE_gpencil_stroke_add(gpf, 0, 1, 10, false);
+ int pt_idx = 0;
/* Move to last point that is equals to start point. */
- sprintf_s(txt, 256, "%f %f moveto", c[n - 1][2].x, c[n - 1][2].y);
- write_line(fout, txt);
+ add_point(gps, pt_idx, scale, c[n - 1][2].x, c[n - 1][2].y);
+ pt_idx++;
for (int i = 0; i < n; i++) {
switch (tag[i]) {
case POTRACE_CORNER:
- sprintf_s(txt, 256, "%f %f lineto", c[i][1].x, c[i][1].y);
- write_line(fout, txt);
+ add_point(gps, pt_idx, scale, c[i][1].x, c[i][1].y);
+ pt_idx++;
- sprintf_s(txt, 256, "%f %f lineto", c[i][2].x, c[i][2].y);
- write_line(fout, txt);
+ add_point(gps, pt_idx, scale, c[i][2].x, c[i][2].y);
+ pt_idx++;
break;
case POTRACE_CURVETO:
sprintf_s(txt,
@@ -226,14 +245,17 @@ void ED_gpencil_trace_data_to_gp(potrace_state_t *st, Object *ob, bGPDframe *gpf
break;
}
}
+ /* Update geometry. */
+ BKE_gpencil_stroke_geometry_update(gps);
+
/* At the end of a group of a positive path and its negative
* children, fill.
* Sign is the char +(43) or -(45) */
- printf("%c\n", p->sign);
- if (p->next == NULL || p->next->sign == '+') {
- write_line(fout, "0 setgray fill");
- printf("-------\n");
+#if 0
+ if (path->next == NULL || path->next->sign == '+') {
+ printf("-- End of group ---\n");
}
- p = p->next;
+#endif
+ path = path->next;
}
}
More information about the Bf-blender-cvs
mailing list