Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-11-06 10:06:33 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-11-06 10:06:33 +0300
commit80109c976cf1f43e1f1730cb827130aa270abaaa (patch)
tree93932897c425ea9f062f6960bc50f1f265a53e32 /source/blender/editors/sculpt_paint/paint_vertex.c
parent900c562b71b6efcf68d649cb639cc8bc246d5899 (diff)
Brush: split out vertex paint tool & blend mode
- Vertex & weight paint now use the 'blend' setting. - Weight paint now has it's own tool setting, since weight paint doesn't deal with color - we'll likely support different tools eventually.
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_vertex.c')
-rw-r--r--source/blender/editors/sculpt_paint/paint_vertex.c93
1 files changed, 51 insertions, 42 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index 103cb6b5f2f..bf20146f195 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -76,6 +76,9 @@
#include "ED_screen.h"
#include "ED_view3d.h"
+/* For IMB_BlendMode only. */
+#include "IMB_imbuf.h"
+
#include "bmesh.h"
#include "BKE_ccg.h"
@@ -153,9 +156,17 @@ static bool vwpaint_use_normal(const VPaint *vp)
((vp->paint.brush->flag & BRUSH_FRONTFACE_FALLOFF) != 0);
}
-static bool brush_use_accumulate(const Brush *brush)
+static bool brush_use_accumulate_ex(const Brush *brush, const int ob_mode)
+{
+ return ((brush->flag & BRUSH_ACCUMULATE) != 0 ||
+ (ob_mode == OB_MODE_VERTEX_PAINT ?
+ (brush->vertexpaint_tool == VPAINT_TOOL_SMEAR) :
+ (brush->weightpaint_tool == WPAINT_TOOL_SMEAR)));
+}
+
+static bool brush_use_accumulate(const VPaint *vp)
{
- return (brush->flag & BRUSH_ACCUMULATE) != 0 || brush->vertexpaint_tool == PAINT_BLEND_SMEAR;
+ return brush_use_accumulate_ex(vp->paint.brush, vp->paint.runtime.ob_mode);
}
static MDeformVert *defweight_prev_init(MDeformVert *dvert_prev, MDeformVert *dvert_curr, int index)
@@ -291,16 +302,16 @@ static uint vpaint_blend(
const int brush_alpha_value_i)
{
const Brush *brush = vp->paint.brush;
- const int tool = brush->vertexpaint_tool;
+ const IMB_BlendMode blend = brush->blend;
- uint color_blend = ED_vpaint_blend_tool(tool, color_curr, color_paint, alpha_i);
+ uint color_blend = ED_vpaint_blend_tool(blend, color_curr, color_paint, alpha_i);
/* if no accumulate, clip color adding with colorig & orig alpha */
- if (!brush_use_accumulate(brush)) {
+ if (!brush_use_accumulate(vp)) {
uint color_test, a;
char *cp, *ct, *co;
- color_test = ED_vpaint_blend_tool(tool, color_orig, color_paint, brush_alpha_value_i);
+ color_test = ED_vpaint_blend_tool(blend, color_orig, color_paint, brush_alpha_value_i);
cp = (char *)&color_blend;
ct = (char *)&color_test;
@@ -319,7 +330,7 @@ static uint vpaint_blend(
}
if ((brush->flag & BRUSH_LOCK_ALPHA) &&
- !ELEM(tool, PAINT_BLEND_ALPHA_SUB, PAINT_BLEND_ALPHA_ADD))
+ !ELEM(blend, IMB_BLEND_ERASE_ALPHA, IMB_BLEND_ADD_ALPHA))
{
char *cp, *cc;
cp = (char *)&color_blend;
@@ -363,24 +374,25 @@ static float wpaint_blend(
const short do_flip)
{
const Brush *brush = wp->paint.brush;
- int tool = brush->vertexpaint_tool;
+ IMB_BlendMode blend = brush->blend;
if (do_flip) {
- switch (tool) {
- case PAINT_BLEND_MIX:
+ switch (blend) {
+ case IMB_BLEND_MIX:
paintval = 1.f - paintval; break;
- case PAINT_BLEND_ADD:
- tool = PAINT_BLEND_SUB; break;
- case PAINT_BLEND_SUB:
- tool = PAINT_BLEND_ADD; break;
- case PAINT_BLEND_LIGHTEN:
- tool = PAINT_BLEND_DARKEN; break;
- case PAINT_BLEND_DARKEN:
- tool = PAINT_BLEND_LIGHTEN; break;
+ case IMB_BLEND_ADD:
+ blend = IMB_BLEND_SUB; break;
+ case IMB_BLEND_SUB:
+ blend = IMB_BLEND_ADD; break;
+ case IMB_BLEND_LIGHTEN:
+ blend = IMB_BLEND_DARKEN; break;
+ case IMB_BLEND_DARKEN:
+ blend = IMB_BLEND_LIGHTEN; break;
+ default: break;
}
}
- weight = ED_wpaint_blend_tool(tool, weight, paintval, alpha);
+ weight = ED_wpaint_blend_tool(blend, weight, paintval, alpha);
CLAMP(weight, 0.0f, 1.0f);
@@ -759,7 +771,7 @@ static void do_weight_paint_vertex_single(
dw_mirr = NULL;
}
- if (!brush_use_accumulate(wp->paint.brush)) {
+ if (!brush_use_accumulate(wp)) {
MDeformVert *dvert_prev = ob->sculpt->mode.wpaint.dvert_prev;
MDeformVert *dv_prev = defweight_prev_init(dvert_prev, me->dvert, index);
if (index_mirr != -1) {
@@ -875,7 +887,7 @@ static void do_weight_paint_vertex_multi(
return;
}
- if (!brush_use_accumulate(wp->paint.brush)) {
+ if (!brush_use_accumulate(wp)) {
MDeformVert *dvert_prev = ob->sculpt->mode.wpaint.dvert_prev;
MDeformVert *dv_prev = defweight_prev_init(dvert_prev, me->dvert, index);
if (index_mirr != -1) {
@@ -978,15 +990,12 @@ static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob)
{
/* Create maps */
struct SculptVertexPaintGeomMap *gmap = NULL;
- const Brush *brush = NULL;
if (ob->mode == OB_MODE_VERTEX_PAINT) {
gmap = &ob->sculpt->mode.vpaint.gmap;
- brush = BKE_paint_brush(&ts->vpaint->paint);
BLI_assert(ob->sculpt->mode_type == OB_MODE_VERTEX_PAINT);
}
else if (ob->mode == OB_MODE_WEIGHT_PAINT) {
gmap = &ob->sculpt->mode.wpaint.gmap;
- brush = BKE_paint_brush(&ts->wpaint->paint);
BLI_assert(ob->sculpt->mode_type == OB_MODE_WEIGHT_PAINT);
}
else {
@@ -1014,7 +1023,7 @@ static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob)
/* Create average brush arrays */
if (ob->mode == OB_MODE_VERTEX_PAINT) {
- if (!brush_use_accumulate(brush)) {
+ if (!brush_use_accumulate(ts->vpaint)) {
if (ob->sculpt->mode.vpaint.previous_color == NULL) {
ob->sculpt->mode.vpaint.previous_color =
MEM_callocN(me->totloop * sizeof(uint), __func__);
@@ -1025,7 +1034,7 @@ static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob)
}
}
else if (ob->mode == OB_MODE_WEIGHT_PAINT) {
- if (!brush_use_accumulate(brush)) {
+ if (!brush_use_accumulate(ts->wpaint)) {
if (ob->sculpt->mode.wpaint.alpha_weight == NULL) {
ob->sculpt->mode.wpaint.alpha_weight =
MEM_callocN(me->totvert * sizeof(float), __func__);
@@ -1544,7 +1553,7 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo
wpd->mirror.lock = tmpflags;
}
- if (ELEM(vp->paint.brush->vertexpaint_tool, PAINT_BLEND_SMEAR, PAINT_BLEND_BLUR)) {
+ if (ELEM(vp->paint.brush->weightpaint_tool, WPAINT_TOOL_SMEAR, WPAINT_TOOL_BLUR)) {
wpd->precomputed_weight = MEM_mallocN(sizeof(float) * me->totvert, __func__);
}
@@ -1612,7 +1621,7 @@ static void do_wpaint_precompute_weight_cb_ex(
static void precompute_weight_values(
bContext *C, Object *ob, Brush *brush, struct WPaintData *wpd, WeightPaintInfo *wpi, Mesh *me)
{
- if (wpd->precomputed_weight_ready && !brush_use_accumulate(brush))
+ if (wpd->precomputed_weight_ready && !brush_use_accumulate_ex(brush, ob->mode))
return;
/* threaded loop over vertices */
@@ -2006,8 +2015,8 @@ static void wpaint_paint_leaves(
/* NOTE: current mirroring code cannot be run in parallel */
settings.use_threading = !(me->editflag & ME_EDIT_MIRROR_X);
- switch (brush->vertexpaint_tool) {
- case PAINT_BLEND_AVERAGE:
+ switch ((eBrushWeightPaintTool)brush->weightpaint_tool) {
+ case WPAINT_TOOL_AVERAGE:
calculate_average_weight(&data, nodes, totnode);
BLI_task_parallel_range(
0, totnode,
@@ -2015,21 +2024,21 @@ static void wpaint_paint_leaves(
do_wpaint_brush_draw_task_cb_ex,
&settings);
break;
- case PAINT_BLEND_SMEAR:
+ case WPAINT_TOOL_SMEAR:
BLI_task_parallel_range(
0, totnode,
&data,
do_wpaint_brush_smear_task_cb_ex,
&settings);
break;
- case PAINT_BLEND_BLUR:
+ case WPAINT_TOOL_BLUR:
BLI_task_parallel_range(
0, totnode,
&data,
do_wpaint_brush_blur_task_cb_ex,
&settings);
break;
- default:
+ case WPAINT_TOOL_DRAW:
BLI_task_parallel_range(
0, totnode,
&data,
@@ -2512,7 +2521,7 @@ static bool vpaint_stroke_test_start(bContext *C, struct wmOperator *op, const f
vpd->paintcol = vpaint_get_current_col(scene, vp, (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_INVERT));
- vpd->is_texbrush = !(brush->vertexpaint_tool == PAINT_BLEND_BLUR) && brush->mtex.tex;
+ vpd->is_texbrush = !(brush->vertexpaint_tool == VPAINT_TOOL_BLUR) && brush->mtex.tex;
/* are we painting onto a modified mesh?,
* if not we can skip face map trickiness */
@@ -2526,11 +2535,11 @@ static bool vpaint_stroke_test_start(bContext *C, struct wmOperator *op, const f
}
/* to keep tracked of modified loops for shared vertex color blending */
- if (brush->vertexpaint_tool == PAINT_BLEND_BLUR) {
+ if (brush->vertexpaint_tool == VPAINT_TOOL_BLUR) {
vpd->mlooptag = MEM_mallocN(sizeof(bool) * me->totloop, "VPaintData mlooptag");
}
- if (brush->vertexpaint_tool == PAINT_BLEND_SMEAR) {
+ if (brush->vertexpaint_tool == VPAINT_TOOL_SMEAR) {
vpd->smear.color_prev = MEM_mallocN(sizeof(uint) * me->totloop, __func__);
memcpy(vpd->smear.color_prev, me->mloopcol, sizeof(uint) * me->totloop);
vpd->smear.color_curr = MEM_dupallocN(vpd->smear.color_prev);
@@ -3009,8 +3018,8 @@ static void vpaint_paint_leaves(
};
ParallelRangeSettings settings;
BLI_parallel_range_settings_defaults(&settings);
- switch (brush->vertexpaint_tool) {
- case PAINT_BLEND_AVERAGE:
+ switch ((eBrushVertexPaintTool)brush->vertexpaint_tool) {
+ case VPAINT_TOOL_AVERAGE:
calculate_average_color(&data, nodes, totnode);
BLI_task_parallel_range(
0, totnode,
@@ -3018,21 +3027,21 @@ static void vpaint_paint_leaves(
do_vpaint_brush_draw_task_cb_ex,
&settings);
break;
- case PAINT_BLEND_BLUR:
+ case VPAINT_TOOL_BLUR:
BLI_task_parallel_range(
0, totnode,
&data,
do_vpaint_brush_blur_task_cb_ex,
&settings);
break;
- case PAINT_BLEND_SMEAR:
+ case VPAINT_TOOL_SMEAR:
BLI_task_parallel_range(
0, totnode,
&data,
do_vpaint_brush_smear_task_cb_ex,
&settings);
break;
- default:
+ case VPAINT_TOOL_DRAW:
BLI_task_parallel_range(
0, totnode,
&data,
@@ -3144,7 +3153,7 @@ static void vpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
BKE_mesh_batch_cache_dirty_tag(ob->data, BKE_MESH_BATCH_DIRTY_ALL);
- if (vp->paint.brush->vertexpaint_tool == PAINT_BLEND_SMEAR) {
+ if (vp->paint.brush->vertexpaint_tool == PAINT_TOOL_SMEAR) {
memcpy(vpd->smear.color_prev, vpd->smear.color_curr, sizeof(uint) * ((Mesh *)ob->data)->totloop);
}