[Bf-blender-cvs] [fe570a2fea1] greasepencil-object: GP: Fill: Add Resolution multiplier

Charlie Jolly noreply at git.blender.org
Mon Jan 14 20:04:08 CET 2019


Commit: fe570a2fea1bc6f96970762c41f0a1cba0cbb8dc
Author: Charlie Jolly
Date:   Mon Jan 14 19:03:47 2019 +0000
Branches: greasepencil-object
https://developer.blender.org/rBfe570a2fea1bc6f96970762c41f0a1cba0cbb8dc

GP: Fill: Add Resolution multiplier

Default is 1, no change. Increasing this number improves accuracy at the expense of processing time and memory usage.

This value multiplies the resolution of the buffer image generated used to calculate the flood fill.

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

M	release/scripts/startup/bl_ui/properties_paint_common.py
M	source/blender/blenkernel/intern/brush.c
M	source/blender/editors/gpencil/gpencil_fill.c
M	source/blender/makesdna/DNA_brush_types.h
M	source/blender/makesrna/intern/rna_brush.c

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

diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index ec12aa6c99f..d2ac6d5888f 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -413,6 +413,9 @@ def brush_basic_gpencil_paint_settings(layout, context, brush, *, compact=False)
         row.prop(gp_settings, "fill_leak", text="Leak Size")
         row.separator()
         row = layout.column(align=True)
+        row.prop(gp_settings, "fill_factor", text="Resolution")
+        row.separator()
+        row = layout.column(align=True)
         row.prop(brush, "size", text="Thickness")
         row = layout.column(align=True)
         row.prop(gp_settings, "fill_simplify_level", text="Simplify")
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index f9ba8765d04..dfc07314c06 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -473,6 +473,7 @@ void BKE_brush_gpencil_presets(bContext *C)
 	brush->gpencil_settings->fill_leak = 3;
 	brush->gpencil_settings->fill_threshold = 0.1f;
 	brush->gpencil_settings->fill_simplylvl = 1;
+	brush->gpencil_settings->fill_factor = 1;
 	brush->gpencil_settings->icon_id = GP_BRUSH_ICON_FILL;
 	brush->gpencil_tool = GPAINT_TOOL_FILL;
 
diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c
index aa1a3a6cc76..e4ce6a4d469 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -116,6 +116,7 @@ typedef struct tGPDfill {
 	float fill_threshold;               /* factor for transparency */
 	int fill_simplylvl;                 /* number of simplify steps */
 	int fill_draw_mode;                 /* boundary limits drawing mode */
+	short fill_factor;                    /* scaling factor */
 
 	short sbuffer_size;                 /* number of elements currently in cache */
 	void *sbuffer;                      /* temporary points */
@@ -124,6 +125,11 @@ typedef struct tGPDfill {
 	Image *ima;                         /* temp image */
 	BLI_Stack *stack;                   /* temp points data */
 	void *draw_handle_3d;               /* handle for drawing strokes while operator is running 3d stuff */
+
+	int bwinx;                          /* tmp size */
+	int bwiny;
+	rcti brect;
+
 } tGPDfill;
 
 
@@ -286,6 +292,29 @@ static void gp_render_offscreen(tGPDfill *tgpf)
 	if (!tgpf->gpd) {
 		return;
 	}
+	
+	/* set temporary new size */
+	tgpf->bwinx = tgpf->ar->winx;
+	tgpf->bwiny = tgpf->ar->winy;
+	tgpf->brect = tgpf->ar->winrct;
+
+	/* resize ar */
+	tgpf->ar->winrct.xmin = 0;
+	tgpf->ar->winrct.ymin = 0;
+	tgpf->ar->winrct.xmax = (int)tgpf->ar->winx * tgpf->fill_factor - 1;
+	tgpf->ar->winrct.ymax = (int)tgpf->ar->winy * tgpf->fill_factor - 1;
+	tgpf->ar->winx = (short)abs(tgpf->ar->winrct.xmax - tgpf->ar->winrct.xmin);
+	tgpf->ar->winy = (short)abs(tgpf->ar->winrct.ymax - tgpf->ar->winrct.ymin);
+
+	/* save new size */
+	tgpf->sizex = (int)tgpf->ar->winx;
+	tgpf->sizey = (int)tgpf->ar->winy;
+
+	/* adjust center */
+	float center[2];
+	center[0] = (float)tgpf->center[0] * ((float)tgpf->ar->winx / (float)tgpf->bwinx);
+	center[1] = (float)tgpf->center[1] * ((float)tgpf->ar->winy / (float)tgpf->bwiny);
+	round_v2i_v2fl(tgpf->center, center);
 
 	char err_out[256] = "unknown";
 	GPUOffScreen *offscreen = GPU_offscreen_create(tgpf->sizex, tgpf->sizey, 0, true, false, err_out);
@@ -304,18 +333,6 @@ static void gp_render_offscreen(tGPDfill *tgpf)
 		perspective_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
 	}
 
-	/* set temporary new size */
-	int bwinx = tgpf->ar->winx;
-	int bwiny = tgpf->ar->winy;
-	rcti brect = tgpf->ar->winrct;
-
-	tgpf->ar->winx = (short)tgpf->sizex;
-	tgpf->ar->winy = (short)tgpf->sizey;
-	tgpf->ar->winrct.xmin = 0;
-	tgpf->ar->winrct.ymin = 0;
-	tgpf->ar->winrct.xmax = tgpf->sizex;
-	tgpf->ar->winrct.ymax = tgpf->sizey;
-
 	GPU_matrix_push_projection();
 	GPU_matrix_identity_set();
 	GPU_matrix_push();
@@ -335,11 +352,6 @@ static void gp_render_offscreen(tGPDfill *tgpf)
 	float ink[4] = {1.0f, 0.0f, 0.0f, 1.0f};
 	gp_draw_datablock(tgpf, ink);
 
-	/* restore size */
-	tgpf->ar->winx = (short)bwinx;
-	tgpf->ar->winy = (short)bwiny;
-	tgpf->ar->winrct = brect;
-
 	GPU_matrix_pop_projection();
 	GPU_matrix_pop();
 
@@ -1052,7 +1064,8 @@ static tGPDfill *gp_session_init_fill(bContext *C, wmOperator *UNUSED(op))
 	tgpf->fill_threshold = brush->gpencil_settings->fill_threshold;
 	tgpf->fill_simplylvl = brush->gpencil_settings->fill_simplylvl;
 	tgpf->fill_draw_mode = brush->gpencil_settings->fill_draw_mode;
-
+	tgpf->fill_factor = (short)max_ii(1, min_ii((int)brush->gpencil_settings->fill_factor,8));
+	
 	/* get color info */
 	Material *ma = BKE_gpencil_get_material_from_brush(brush);
 	/* if no brush defaults, get material and color info */
@@ -1214,14 +1227,11 @@ static int gpencil_fill_modal(bContext *C, wmOperator *op, const wmEvent *event)
 					in_bounds = BLI_rcti_isect_pt(&ar->winrct, event->x, event->y);
 
 					if ((in_bounds) && (ar->regiontype == RGN_TYPE_WINDOW)) {
+
 						/* TODO GPXX: Verify the mouse click is right for any window size */
 						tgpf->center[0] = event->mval[0];
 						tgpf->center[1] = event->mval[1];
 
-						/* save size */
-						tgpf->sizex = ar->winx;
-						tgpf->sizey = ar->winy;
-
 						/* render screen to temp image */
 						gp_render_offscreen(tgpf);
 
@@ -1243,6 +1253,11 @@ static int gpencil_fill_modal(bContext *C, wmOperator *op, const wmEvent *event)
 						/* create stroke and reproject */
 						gpencil_stroke_from_buffer(tgpf);
 
+						/* restore size */
+						tgpf->ar->winx = (short)tgpf->bwinx;
+						tgpf->ar->winy = (short)tgpf->bwiny;
+						tgpf->ar->winrct = tgpf->brect;
+
 						/* free temp stack data */
 						if (tgpf->stack) {
 							BLI_stack_free(tgpf->stack);
diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h
index 61306fc8d21..c5b8b6aeebd 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -91,30 +91,32 @@ typedef struct BrushGpencilSettings {
 	float fill_threshold;
 	/** Number of pixel to consider the leak is too small (x 2). */
 	short fill_leak;
-	char pad_1[6];
+	/** Fill zoom factor */
+	short fill_factor;
+	char _pad_1[4];
 
 	/** Number of simplify steps. */
-	int   fill_simplylvl;
+	int fill_simplylvl;
 	/** Type of control lines drawing mode. */
-	int   fill_draw_mode;
+	int fill_draw_mode;
 	/** Icon identifier. */
-	int   icon_id;
+	int icon_id;
 
 	/** Maximum distance before generate new point for very fast mouse movements. */
-	int   input_samples;
+	int input_samples;
 	/** Random factor for UV rotation. */
 	float uv_random;
 	/** Moved to 'Brush.gpencil_tool'. */
-	int   brush_type DNA_DEPRECATED;
+	int brush_type DNA_DEPRECATED;
 	/** Soft, hard or stroke. */
-	int   eraser_mode;
+	int eraser_mode;
 	/** Smooth while drawing factor. */
 	float active_smooth;
 	/** Factor to apply to strength for soft eraser. */
 	float era_strength_f;
 	/** Factor to apply to thickness for soft eraser. */
 	float era_thickness_f;
-	char pad_2[4];
+	char _pad_2[4];
 
 	struct CurveMapping *curve_sensitivity;
 	struct CurveMapping *curve_strength;
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index 79350b57708..55086cc6570 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -1115,6 +1115,15 @@ static void rna_def_gpencil_options(BlenderRNA *brna)
 	RNA_def_parameter_clear_flags(prop, PROP_ANIMATABLE, 0);
 	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
 
+	/* fill factor size */
+	prop = RNA_def_property(srna, "fill_factor", PROP_INT, PROP_NONE);
+	RNA_def_property_int_sdna(prop, NULL, "fill_factor");
+	RNA_def_property_range(prop, 1, 8);
+	RNA_def_property_ui_text(prop, "Resolution",
+		"Multiplier for fill resolution, higher resolution is more accurate but slower");
+	RNA_def_parameter_clear_flags(prop, PROP_ANIMATABLE, 0);
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
+
 	/* fill simplify steps */
 	prop = RNA_def_property(srna, "fill_simplify_level", PROP_INT, PROP_NONE);
 	RNA_def_property_int_sdna(prop, NULL, "fill_simplylvl");



More information about the Bf-blender-cvs mailing list