[Bf-blender-cvs] [ea330229835] greasepencil-object: GPencil: New Vertex Paint Average Brush
Antonio Vazquez
noreply at git.blender.org
Sat Nov 9 13:45:49 CET 2019
Commit: ea3302298358b2bd0e1b4764c9b7572981aaeea8
Author: Antonio Vazquez
Date: Sat Nov 9 13:45:41 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rBea3302298358b2bd0e1b4764c9b7572981aaeea8
GPencil: New Vertex Paint Average Brush
This brush tint the points with the average of the colors below the cursor.
===================================================================
M release/scripts/startup/bl_ui/space_view3d.py
M release/scripts/startup/bl_ui/space_view3d_toolbar.py
M source/blender/editors/gpencil/gpencil_vertex_paint.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index ef810cca0b3..bb9c6ed3c9e 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -432,12 +432,14 @@ class _draw_tool_settings_context_mode:
settings = tool_settings.gpencil_vertex_paint
row.template_ID_preview(settings, "brush", rows=3, cols=8, hide_buttons=True)
- row.separator(factor=0.4)
- row.prop(brush, "color", text="")
- row.popover(
- panel="TOPBAR_PT_gpencil_vertexcolor",
- text="Vertex Color",
- )
+ if brush.gpencil_vertex_tool != 'AVERAGE':
+ row.separator(factor=0.4)
+ row.prop(brush, "color", text="")
+
+ row.popover(
+ panel="TOPBAR_PT_gpencil_vertexcolor",
+ text="Vertex Color",
+ )
from bl_ui.properties_paint_common import (
brush_basic_gpencil_vertex_settings,
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index fc4ad59feee..fc49be8a82d 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -2289,8 +2289,8 @@ class VIEW3D_PT_tools_grease_pencil_brush_vertex(View3DPanel, Panel):
if ob is None or brush is None:
return False
-
- if context.region.type == 'TOOL_HEADER':
+
+ if context.region.type == 'TOOL_HEADER' or brush.gpencil_vertex_tool == 'AVERAGE':
return False
return True
@@ -2334,7 +2334,10 @@ class VIEW3D_PT_tools_grease_pencil_brush_vertex_palette(View3DPanel, Panel):
if ob is None or brush is None:
return False
-
+
+ if brush.gpencil_vertex_tool == 'AVERAGE':
+ return False
+
return True
def draw(self, context):
diff --git a/source/blender/editors/gpencil/gpencil_vertex_paint.c b/source/blender/editors/gpencil/gpencil_vertex_paint.c
index 137749b682a..805aeb59933 100644
--- a/source/blender/editors/gpencil/gpencil_vertex_paint.c
+++ b/source/blender/editors/gpencil/gpencil_vertex_paint.c
@@ -313,6 +313,54 @@ static bool brush_replace_apply(tGP_BrushVertexpaintData *gso,
return true;
}
+/* Average Brush */
+static bool brush_average_apply(tGP_BrushVertexpaintData *gso,
+ bGPDstroke *gps,
+ int pt_index,
+ const int radius,
+ const int co[2],
+ float average_color[3])
+{
+ Brush *brush = gso->brush;
+ float final_color[3];
+ copy_v3_v3(final_color, average_color);
+
+ /* Attenuate factor to get a smoother tinting. */
+ float inf = (brush_influence_calc(gso, radius, co) * brush->gpencil_settings->draw_strength) /
+ 100.0f;
+ float inf_fill = (gso->pressure * brush->gpencil_settings->draw_strength) / 1000.0f;
+
+ bGPDspoint *pt = &gps->points[pt_index];
+
+ float alpha = pt->mix_color[3];
+ float alpha_fill = gps->mix_color_fill[3];
+
+ if (brush_invert_check(gso)) {
+ alpha -= inf;
+ alpha_fill -= inf_fill;
+ }
+ else {
+ alpha += inf;
+ alpha_fill += inf_fill;
+ }
+
+ /* Apply color to Stroke point. */
+ if (GPENCIL_TINT_VERTEX_COLOR_STROKE(brush)) {
+ CLAMP(alpha, 0.0f, 1.0f);
+ interp_v3_v3v3(pt->mix_color, pt->mix_color, final_color, inf);
+ pt->mix_color[3] = alpha;
+ }
+
+ /* Apply color to Fill area (all with same color and factor). */
+ if (GPENCIL_TINT_VERTEX_COLOR_FILL(brush)) {
+ CLAMP(alpha_fill, 0.0f, 1.0f);
+ copy_v3_v3(gps->mix_color_fill, final_color);
+ gps->mix_color_fill[3] = alpha_fill;
+ }
+
+ return true;
+}
+
/* ************************************************ */
/* Header Info */
static void gp_vertexpaint_brush_header_set(bContext *C, tGP_BrushVertexpaintData *UNUSED(gso))
@@ -563,6 +611,8 @@ static bool gp_vertexpaint_brush_do_frame(bContext *C,
const int radius = (gso->brush->flag & GP_BRUSH_USE_PRESSURE) ?
gso->brush->size * gso->pressure :
gso->brush->size;
+ tGP_selected *selected = NULL;
+ int i;
/*---------------------------------------------------------------------
* First step: select the points affected. This step is required to have
@@ -583,12 +633,40 @@ static bool gp_vertexpaint_brush_do_frame(bContext *C,
gp_vertexpaint_select_stroke(gso, gps, diff_mat);
}
+ /* For Average tool, need calculate the average resulting color from all colors
+ * under the brush. */
+ float average_color[3] = {0};
+ int totcol = 0;
+ if ((tool == GPVERTEX_TOOL_AVERAGE) && (gso->pbuffer_used > 0)) {
+ for (i = 0; i < gso->pbuffer_used; i++) {
+ selected = &gso->pbuffer[i];
+ bGPDstroke *gps = selected->gps;
+ bGPDspoint *pt = &gps->points[selected->pt_index];
+
+ /* Add stroke mix color (only if used). */
+ if (pt->mix_color[3] > 0.0f) {
+ add_v3_v3(average_color, pt->mix_color);
+ totcol++;
+ }
+
+ /* If Fill color mix, add to average. */
+ if (gps->mix_color_fill[3] > 0.0f) {
+ add_v3_v3(average_color, gps->mix_color_fill);
+ totcol++;
+ }
+ }
+
+ /* Get average. */
+ if (totcol > 0) {
+ mul_v3_fl(average_color, (1.0f / (float)totcol));
+ }
+ }
+
/*---------------------------------------------------------------------
* Second step: Apply effect.
*--------------------------------------------------------------------- */
bool changed = false;
- tGP_selected *selected = NULL;
- for (int i = 0; i < gso->pbuffer_used; i++) {
+ for (i = 0; i < gso->pbuffer_used; i++) {
changed = true;
selected = &gso->pbuffer[i];
@@ -604,6 +682,12 @@ static bool gp_vertexpaint_brush_do_frame(bContext *C,
changed |= true;
break;
}
+ case GPVERTEX_TOOL_AVERAGE: {
+ brush_average_apply(
+ gso, selected->gps, selected->pt_index, radius, selected->pc, average_color);
+ changed |= true;
+ break;
+ }
default:
printf("ERROR: Unknown type of GPencil Vertex Paint brush\n");
More information about the Bf-blender-cvs
mailing list