Moved the image paint tool and the vertex/weight paint tool (blend mode?)

to the Brush data. This now works the same way as sculpt, with named 
preset brushes that retain settings.
This commit is contained in:
Matt Ebb 2010-01-20 08:30:40 +00:00
parent e8b123a1e4
commit 02ca0fda8e
9 changed files with 11077 additions and 9524 deletions

@ -500,13 +500,13 @@ class VIEW3D_PT_tools_brush(PaintPanel):
row = col.row()
if context.sculpt_object and brush:
defaulttools = 8
defaultbrushes = 8
elif context.texture_paint_object and brush:
defaulttools = 4
defaultbrushes = 4
else:
defaulttools = 2
defaultbrushes = 7
row.template_list(settings, "brushes", settings, "active_brush_index", rows=2, maxrows=defaulttools)
row.template_list(settings, "brushes", settings, "active_brush_index", rows=2, maxrows=defaultbrushes)
col.template_ID(settings, "brush", new="brush.add")
@ -657,8 +657,9 @@ class VIEW3D_PT_tools_brush_tool(PaintPanel):
def poll(self, context):
settings = self.paint_settings(context)
return (settings and settings.brush and (context.sculpt_object or
context.texture_paint_object))
return (settings and settings.brush and
(context.sculpt_object or context.texture_paint_object or
context.vertex_paint_object or context.weight_paint_object))
def draw(self, context):
layout = self.layout
@ -673,10 +674,13 @@ class VIEW3D_PT_tools_brush_tool(PaintPanel):
if context.sculpt_object:
col.prop(brush, "sculpt_tool", expand=True)
elif context.texture_paint_object:
col.prop_enum(settings, "tool", 'DRAW')
col.prop_enum(settings, "tool", 'SOFTEN')
col.prop_enum(settings, "tool", 'CLONE')
col.prop_enum(settings, "tool", 'SMEAR')
col.prop(brush, "imagepaint_tool", expand=True)
#col.prop_enum(settings, "tool", 'DRAW')
#col.prop_enum(settings, "tool", 'SOFTEN')
#col.prop_enum(settings, "tool", 'CLONE')
#col.prop_enum(settings, "tool", 'SMEAR')
elif context.vertex_paint_object or context.weight_paint_object:
col.prop(brush, "vertexpaint_tool", expand=True)
class VIEW3D_PT_tools_brush_stroke(PaintPanel):
@ -780,7 +784,6 @@ class VIEW3D_PT_tools_weightpaint(View3DPanel):
layout = self.layout
col = layout.column()
# col.label(text="Blend:")
col.operator("object.vertex_group_normalize_all", text="Normalize All")
col.operator("object.vertex_group_normalize", text="Normalize")
col.operator("object.vertex_group_invert", text="Invert")
@ -798,8 +801,6 @@ class VIEW3D_PT_tools_weightpaint_options(View3DPanel):
wpaint = context.tool_settings.weight_paint
col = layout.column()
col.label(text="Blend:")
col.prop(wpaint, "mode", text="")
col.prop(wpaint, "all_faces")
col.prop(wpaint, "normals")
col.prop(wpaint, "spray")
@ -830,8 +831,7 @@ class VIEW3D_PT_tools_vertexpaint(View3DPanel):
vpaint = context.tool_settings.vertex_paint
col = layout.column()
col.label(text="Blend:")
col.prop(vpaint, "mode", text="")
#col.prop(vpaint, "mode", text="")
col.prop(vpaint, "all_faces")
col.prop(vpaint, "normals")
col.prop(vpaint, "spray")
@ -850,7 +850,7 @@ class VIEW3D_PT_tools_projectpaint(View3DPanel):
bl_label = "Project Paint"
def poll(self, context):
return context.tool_settings.image_paint.tool != 'SMEAR'
return context.tool_settings.image_paint.brush.imagepaint_tool != 'SMEAR'
def draw_header(self, context):
ipaint = context.tool_settings.image_paint
@ -893,7 +893,7 @@ class VIEW3D_PT_tools_projectpaint(View3DPanel):
col = layout.column()
sub = col.column()
row = sub.row()
row.active = (settings.tool == 'CLONE')
row.active = (settings.brush.imagepaint_tool == 'CLONE')
row.prop(ipaint, "use_clone_layer", text="Clone")
row.menu("VIEW3D_MT_tools_projectpaint_clone", text=context.active_object.data.uv_texture_clone.name)

File diff suppressed because it is too large Load Diff

@ -4273,12 +4273,10 @@ static int image_paint_3d_poll(bContext *C)
static int image_paint_2d_clone_poll(bContext *C)
{
Scene *scene= CTX_data_scene(C);
ToolSettings *settings= scene->toolsettings;
Brush *brush= image_paint_brush(C);
if(!CTX_wm_region_view3d(C) && image_paint_poll(C))
if(brush && (settings->imapaint.tool == PAINT_TOOL_CLONE))
if(brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE))
if(brush->clone.image)
return 1;
@ -4386,7 +4384,7 @@ static int texture_paint_init(bContext *C, wmOperator *op)
return 0;
pop->s.brush = brush;
pop->s.tool = settings->imapaint.tool;
pop->s.tool = brush->imagepaint_tool;
if(pop->mode == PAINT_MODE_3D && (pop->s.tool == PAINT_TOOL_CLONE))
pop->s.tool = PAINT_TOOL_DRAW;
pop->s.blend = pop->s.brush->blend;

@ -96,7 +96,7 @@
#include "paint_intern.h"
/* vp->mode */
/* brush->vertexpaint_tool */
#define VP_MIX 0
#define VP_ADD 1
#define VP_SUB 2
@ -662,12 +662,12 @@ static void vpaint_blend(VPaint *vp, unsigned int *col, unsigned int *colorig, u
{
Brush *brush = paint_brush(&vp->paint);
if(vp->mode==VP_MIX || vp->mode==VP_BLUR) *col= mcol_blend( *col, paintcol, alpha);
else if(vp->mode==VP_ADD) *col= mcol_add( *col, paintcol, alpha);
else if(vp->mode==VP_SUB) *col= mcol_sub( *col, paintcol, alpha);
else if(vp->mode==VP_MUL) *col= mcol_mul( *col, paintcol, alpha);
else if(vp->mode==VP_LIGHTEN) *col= mcol_lighten( *col, paintcol, alpha);
else if(vp->mode==VP_DARKEN) *col= mcol_darken( *col, paintcol, alpha);
if(brush->vertexpaint_tool==VP_MIX || brush->vertexpaint_tool==VP_BLUR) *col= mcol_blend( *col, paintcol, alpha);
else if(brush->vertexpaint_tool==VP_ADD) *col= mcol_add( *col, paintcol, alpha);
else if(brush->vertexpaint_tool==VP_SUB) *col= mcol_sub( *col, paintcol, alpha);
else if(brush->vertexpaint_tool==VP_MUL) *col= mcol_mul( *col, paintcol, alpha);
else if(brush->vertexpaint_tool==VP_LIGHTEN) *col= mcol_lighten( *col, paintcol, alpha);
else if(brush->vertexpaint_tool==VP_DARKEN) *col= mcol_darken( *col, paintcol, alpha);
/* if no spray, clip color adding with colorig & orig alpha */
if((vp->flag & VP_SPRAY)==0) {
@ -676,12 +676,12 @@ static void vpaint_blend(VPaint *vp, unsigned int *col, unsigned int *colorig, u
alpha= (int)(255.0*brush->alpha);
if(vp->mode==VP_MIX || vp->mode==VP_BLUR) testcol= mcol_blend( *colorig, paintcol, alpha);
else if(vp->mode==VP_ADD) testcol= mcol_add( *colorig, paintcol, alpha);
else if(vp->mode==VP_SUB) testcol= mcol_sub( *colorig, paintcol, alpha);
else if(vp->mode==VP_MUL) testcol= mcol_mul( *colorig, paintcol, alpha);
else if(vp->mode==VP_LIGHTEN) testcol= mcol_lighten( *colorig, paintcol, alpha);
else if(vp->mode==VP_DARKEN) testcol= mcol_darken( *colorig, paintcol, alpha);
if(brush->vertexpaint_tool==VP_MIX || brush->vertexpaint_tool==VP_BLUR) testcol= mcol_blend( *colorig, paintcol, alpha);
else if(brush->vertexpaint_tool==VP_ADD) testcol= mcol_add( *colorig, paintcol, alpha);
else if(brush->vertexpaint_tool==VP_SUB) testcol= mcol_sub( *colorig, paintcol, alpha);
else if(brush->vertexpaint_tool==VP_MUL) testcol= mcol_mul( *colorig, paintcol, alpha);
else if(brush->vertexpaint_tool==VP_LIGHTEN) testcol= mcol_lighten( *colorig, paintcol, alpha);
else if(brush->vertexpaint_tool==VP_DARKEN) testcol= mcol_darken( *colorig, paintcol, alpha);
cp= (char *)col;
ct= (char *)&testcol;
@ -785,38 +785,38 @@ static float calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, float vpimat[][3], fl
static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float alpha, float paintval, int flip)
{
Brush *brush = paint_brush(&wp->paint);
int mode = wp->mode;
int tool = brush->vertexpaint_tool;
if(dw==NULL || uw==NULL) return;
if (flip) {
switch(mode) {
switch(tool) {
case VP_MIX:
paintval = 1.f - paintval; break;
case VP_ADD:
mode= VP_SUB; break;
tool= VP_SUB; break;
case VP_SUB:
mode= VP_ADD; break;
tool= VP_ADD; break;
case VP_LIGHTEN:
mode= VP_DARKEN; break;
tool= VP_DARKEN; break;
case VP_DARKEN:
mode= VP_LIGHTEN; break;
tool= VP_LIGHTEN; break;
}
}
if(mode==VP_MIX || mode==VP_BLUR)
if(tool==VP_MIX || tool==VP_BLUR)
dw->weight = paintval*alpha + dw->weight*(1.0-alpha);
else if(mode==VP_ADD)
else if(tool==VP_ADD)
dw->weight += paintval*alpha;
else if(mode==VP_SUB)
else if(tool==VP_SUB)
dw->weight -= paintval*alpha;
else if(mode==VP_MUL)
else if(tool==VP_MUL)
/* first mul, then blend the fac */
dw->weight = ((1.0-alpha) + alpha*paintval)*dw->weight;
else if(mode==VP_LIGHTEN) {
else if(tool==VP_LIGHTEN) {
if (dw->weight < paintval)
dw->weight = paintval*alpha + dw->weight*(1.0-alpha);
} else if(mode==VP_DARKEN) {
} else if(tool==VP_DARKEN) {
if (dw->weight > paintval)
dw->weight = paintval*alpha + dw->weight*(1.0-alpha);
}
@ -827,21 +827,21 @@ static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float
float testw=0.0f;
alpha= brush->alpha;
if(mode==VP_MIX || mode==VP_BLUR)
if(tool==VP_MIX || tool==VP_BLUR)
testw = paintval*alpha + uw->weight*(1.0-alpha);
else if(mode==VP_ADD)
else if(tool==VP_ADD)
testw = uw->weight + paintval*alpha;
else if(mode==VP_SUB)
else if(tool==VP_SUB)
testw = uw->weight - paintval*alpha;
else if(mode==VP_MUL)
else if(tool==VP_MUL)
/* first mul, then blend the fac */
testw = ((1.0-alpha) + alpha*paintval)*uw->weight;
else if(mode==VP_LIGHTEN) {
else if(tool==VP_LIGHTEN) {
if (uw->weight < paintval)
testw = paintval*alpha + uw->weight*(1.0-alpha);
else
testw = uw->weight;
} else if(mode==VP_DARKEN) {
} else if(tool==VP_DARKEN) {
if (uw->weight > paintval)
testw = paintval*alpha + uw->weight*(1.0-alpha);
else
@ -1515,7 +1515,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
/* make sure each vertex gets treated only once */
/* and calculate filter weight */
totw= 0;
if(wp->mode==VP_BLUR)
if(brush->vertexpaint_tool==VP_BLUR)
paintweight= 0.0f;
else
paintweight= ts->vgroup_weight;
@ -1529,7 +1529,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
(me->dvert+mface->v3)->flag= 1;
if(mface->v4) (me->dvert+mface->v4)->flag= 1;
if(wp->mode==VP_BLUR) {
if(brush->vertexpaint_tool==VP_BLUR) {
MDeformWeight *dw, *(*dw_func)(MDeformVert *, int) = ED_vgroup_weight_verify;
if(wp->flag & VP_ONLYVGROUP)
@ -1549,7 +1549,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
}
}
if(wp->mode==VP_BLUR)
if(brush->vertexpaint_tool==VP_BLUR)
paintweight/= (float)totw;
for(index=0; index<totindex; index++) {
@ -1844,6 +1844,7 @@ static int vpaint_stroke_test_start(bContext *C, struct wmOperator *op, wmEvent
static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, int index, float mval[2], float pressure, int flip)
{
ViewContext *vc = &vpd->vc;
Brush *brush = paint_brush(&vp->paint);
Mesh *me = get_mesh(ob);
MFace *mface= ((MFace*)me->mface) + index;
unsigned int *mcol= ((unsigned int*)me->mcol) + 4*index;
@ -1855,7 +1856,7 @@ static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, int index
((me->editflag & ME_EDIT_PAINT_MASK) && !(mface->flag & ME_FACE_SEL)))
return;
if(vp->mode==VP_BLUR) {
if(brush->vertexpaint_tool==VP_BLUR) {
unsigned int fcol1= mcol_blend( mcol[0], mcol[1], 128);
if(mface->v4) {
unsigned int fcol2= mcol_blend( mcol[2], mcol[3], 128);
@ -1923,7 +1924,7 @@ static void vpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
swap_m4m4(vc->rv3d->persmat, mat);
/* was disabled because it is slow, but necessary for blur */
if(vp->mode == VP_BLUR)
if(brush->vertexpaint_tool == VP_BLUR)
do_shared_vertexcol(me);
ED_region_tag_redraw(vc->ar);

@ -625,7 +625,7 @@ static void draw_image_paint_helpers(SpaceImage *sima, ARegion *ar, Scene *scene
brush= paint_brush(&scene->toolsettings->imapaint.paint);
if(brush && (scene->toolsettings->imapaint.tool == PAINT_TOOL_CLONE)) {
if(brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE)) {
/* this is not very efficient, but glDrawPixels doesn't allow
drawing with alpha */
clonerect= get_alpha_clone_image(scene, &w, &h);

@ -65,8 +65,10 @@ typedef struct Brush {
float rgb[3]; /* color */
float alpha; /* opacity */
char sculpt_tool; /* active tool */
char pad2[3];
char sculpt_tool; /* active sculpt tool */
char vertexpaint_tool; /* active vertex/weight paint tool/blend mode */
char imagepaint_tool; /* active image paint tool */
char pad2;
} Brush;
/* Brush.flag */

@ -510,7 +510,7 @@ typedef struct Paint {
typedef struct ImagePaintSettings {
Paint paint;
short flag, tool;
short flag, pad;
/* for projection painting only */
short seam_bleed, normal_angle;
@ -565,7 +565,7 @@ typedef struct Sculpt {
typedef struct VPaint {
Paint paint;
short mode, flag;
short flag, pad;
int tot; /* allocation size of prev buffers */
unsigned int *vpaint_prev; /* previous mesh colors */
struct MDeformVert *wpaint_prev; /* previous vertex weights */

@ -35,17 +35,6 @@
#include "IMB_imbuf.h"
#include "WM_types.h"
EnumPropertyItem brush_sculpt_tool_items[] = {
{SCULPT_TOOL_DRAW, "DRAW", 0, "Draw", ""},
{SCULPT_TOOL_SMOOTH, "SMOOTH", 0, "Smooth", ""},
{SCULPT_TOOL_PINCH, "PINCH", 0, "Pinch", ""},
{SCULPT_TOOL_INFLATE, "INFLATE", 0, "Inflate", ""},
{SCULPT_TOOL_GRAB, "GRAB", 0, "Grab", ""},
{SCULPT_TOOL_LAYER, "LAYER", 0, "Layer", ""},
{SCULPT_TOOL_FLATTEN, "FLATTEN", 0, "Flatten", ""},
{SCULPT_TOOL_CLAY, "CLAY", 0, "Clay", ""},
{0, NULL, 0, NULL, NULL}};
#ifdef RNA_RUNTIME
#include "MEM_guardedalloc.h"
@ -121,6 +110,34 @@ static void rna_def_brush(BlenderRNA *brna)
{IMB_BLEND_ADD_ALPHA, "ADD_ALPHA", 0, "Add Alpha", "Add alpha while painting."},
{0, NULL, 0, NULL, NULL}};
static EnumPropertyItem brush_sculpt_tool_items[] = {
{SCULPT_TOOL_DRAW, "DRAW", 0, "Draw", ""},
{SCULPT_TOOL_SMOOTH, "SMOOTH", 0, "Smooth", ""},
{SCULPT_TOOL_PINCH, "PINCH", 0, "Pinch", ""},
{SCULPT_TOOL_INFLATE, "INFLATE", 0, "Inflate", ""},
{SCULPT_TOOL_GRAB, "GRAB", 0, "Grab", ""},
{SCULPT_TOOL_LAYER, "LAYER", 0, "Layer", ""},
{SCULPT_TOOL_FLATTEN, "FLATTEN", 0, "Flatten", ""},
{SCULPT_TOOL_CLAY, "CLAY", 0, "Clay", ""},
{0, NULL, 0, NULL, NULL}};
static EnumPropertyItem brush_vertexpaint_tool_items[] = {
{0, "MIX", 0, "Mix", "Use mix blending mode while painting."},
{1, "ADD", 0, "Add", "Use add blending mode while painting."},
{2, "SUB", 0, "Subtract", "Use subtract blending mode while painting."},
{3, "MUL", 0, "Multiply", "Use multiply blending mode while painting."},
{4, "BLUR", 0, "Blur", "Blur the color with surrounding values"},
{5, "LIGHTEN", 0, "Lighten", "Use lighten blending mode while painting."},
{6, "DARKEN", 0, "Darken", "Use darken blending mode while painting."},
{0, NULL, 0, NULL, NULL}};
static EnumPropertyItem brush_imagepaint_tool_items[] = {
{PAINT_TOOL_DRAW, "DRAW", 0, "Draw", ""},
{PAINT_TOOL_SOFTEN, "SOFTEN", 0, "Soften", ""},
{PAINT_TOOL_SMEAR, "SMEAR", 0, "Smear", ""},
{PAINT_TOOL_CLONE, "CLONE", 0, "Clone", ""},
{0, NULL, 0, NULL, NULL}};
static const EnumPropertyItem prop_flip_direction_items[]= {
{0, "ADD", 0, "Add", "Add effect of brush"},
{BRUSH_DIR_IN, "SUBTRACT", 0, "Subtract", "Subtract effect of brush"},
@ -141,6 +158,16 @@ static void rna_def_brush(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Sculpt Tool", "");
RNA_def_property_update(prop, 0, "rna_Brush_update");
prop= RNA_def_property(srna, "vertexpaint_tool", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, brush_vertexpaint_tool_items);
RNA_def_property_ui_text(prop, "Vertex/Weight Paint Tool", "");
RNA_def_property_update(prop, 0, "rna_Brush_update");
prop= RNA_def_property(srna, "imagepaint_tool", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, brush_imagepaint_tool_items);
RNA_def_property_ui_text(prop, "Image Paint Tool", "");
RNA_def_property_update(prop, 0, "rna_Brush_update");
prop= RNA_def_property(srna, "direction", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
RNA_def_property_enum_items(prop, prop_flip_direction_items);

@ -277,24 +277,11 @@ static void rna_def_vertex_paint(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
static EnumPropertyItem brush_mode_items[] = {
{0, "MIX", 0, "Mix", "Use mix blending mode while painting."},
{1, "ADD", 0, "Add", "Use add blending mode while painting."},
{2, "SUB", 0, "Subtract", "Use subtract blending mode while painting."},
{3, "MUL", 0, "Multiply", "Use multiply blending mode while painting."},
{4, "BLUR", 0, "Blur", "Blur the color with surrounding values"},
{5, "LIGHTEN", 0, "Lighten", "Use lighten blending mode while painting."},
{6, "DARKEN", 0, "Darken", "Use darken blending mode while painting."},
{0, NULL, 0, NULL, NULL}};
srna= RNA_def_struct(brna, "VertexPaint", "Paint");
RNA_def_struct_sdna(srna, "VPaint");
RNA_def_struct_ui_text(srna, "Vertex Paint", "Properties of vertex and weight paint mode.");
prop= RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, brush_mode_items);
RNA_def_property_ui_text(prop, "Brush Mode", "Mode in which color is painted.");
prop= RNA_def_property(srna, "all_faces", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", VP_AREA);
RNA_def_property_ui_text(prop, "All Faces", "Paint on all faces inside brush.");
@ -313,21 +300,10 @@ static void rna_def_image_paint(BlenderRNA *brna)
StructRNA *srna;
PropertyRNA *prop;
static EnumPropertyItem tool_items[] = {
{PAINT_TOOL_DRAW, "DRAW", 0, "Draw", ""},
{PAINT_TOOL_SOFTEN, "SOFTEN", 0, "Soften", ""},
{PAINT_TOOL_SMEAR, "SMEAR", 0, "Smear", ""},
{PAINT_TOOL_CLONE, "CLONE", 0, "Clone", ""},
{0, NULL, 0, NULL, NULL}};
srna= RNA_def_struct(brna, "ImagePaint", "Paint");
RNA_def_struct_sdna(srna, "ImagePaintSettings");
RNA_def_struct_ui_text(srna, "Image Paint", "Properties of image and texture painting mode.");
prop= RNA_def_property(srna, "tool", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, tool_items);
RNA_def_property_ui_text(prop, "Tool", "");
/* booleans */
prop= RNA_def_property(srna, "show_brush_draw", PROP_BOOLEAN, PROP_NONE);