diff options
author | Nicholas Bishop <nicholasbishop@gmail.com> | 2009-03-11 03:43:08 +0300 |
---|---|---|
committer | Nicholas Bishop <nicholasbishop@gmail.com> | 2009-03-11 03:43:08 +0300 |
commit | 33509e851077fa108bfb1e8934098d67e6b1b16f (patch) | |
tree | 1c464e1fcb10b4549eb90cb4becd77c3531d269b | |
parent | 47311475ba16b59b7e5751cc63d5800bdd971586 (diff) |
Changed vertexpaint and weightpaint to use the standard Brush struct, so they too work with the brush panel.
Note: these modes are only using color/alpha/size from Brush, so there's more integration work todo yet.
-rw-r--r-- | source/blender/blenkernel/BKE_brush.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/brush.c | 13 | ||||
-rw-r--r-- | source/blender/editors/mesh/editdeform.c | 4 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_utils.c | 21 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_vertex.c | 60 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 8 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_buttons.c | 32 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_scene_types.h | 7 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_vpaint.c | 14 |
9 files changed, 67 insertions, 94 deletions
diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h index 4146d313d41..9eb0b15aed4 100644 --- a/source/blender/blenkernel/BKE_brush.h +++ b/source/blender/blenkernel/BKE_brush.h @@ -34,6 +34,7 @@ struct ID; struct Brush; struct ImBuf; +struct Scene; struct wmOperator; /* datablock functions */ @@ -43,6 +44,7 @@ void make_local_brush(struct Brush *brush); void free_brush(struct Brush *brush); /* brush library operations used by different paint panels */ +struct Brush **current_brush_source(struct Scene *sce); int brush_set_nr(struct Brush **current_brush, int nr); int brush_delete(struct Brush **current_brush); void brush_check_exists(struct Brush **brush); diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 398993be1a4..30a35cbe91c 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -185,6 +185,19 @@ void make_local_brush(Brush *brush) /* Library Operations */ +Brush **current_brush_source(Scene *sce) +{ + if(G.f & G_SCULPTMODE) + return &sce->toolsettings->sculpt->brush; + else if(G.f & G_VERTEXPAINT) + return &sce->toolsettings->vpaint->brush; + else if(G.f & G_WEIGHTPAINT) + return &sce->toolsettings->wpaint->brush; + else if(G.f & G_TEXTUREPAINT) + return &sce->toolsettings->imapaint.brush; + return NULL; +} + int brush_set_nr(Brush **current_brush, int nr) { ID *idtest, *id; diff --git a/source/blender/editors/mesh/editdeform.c b/source/blender/editors/mesh/editdeform.c index 83668400708..ca6415d8b76 100644 --- a/source/blender/editors/mesh/editdeform.c +++ b/source/blender/editors/mesh/editdeform.c @@ -1007,11 +1007,11 @@ void vgroup_assign_with_menu(Scene *scene, Object *ob) switch (mode) { case 1: /* add to new group */ add_defgroup(ob); - assign_verts_defgroup(ob, wp->weight); + assign_verts_defgroup(ob, wp->brush->alpha); BIF_undo_push("Assign to vertex group"); break; case 2: /* add to current group */ - assign_verts_defgroup(ob, wp->weight); + assign_verts_defgroup(ob, wp->brush->alpha); BIF_undo_push("Assign to vertex group"); break; case 3: /* remove from current group */ diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index e0ac3c94109..85ea55331dc 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -11,6 +11,7 @@ #include "BLI_arithb.h" +#include "BKE_brush.h" #include "BKE_DerivedMesh.h" #include "BKE_global.h" #include "BKE_utildefines.h" @@ -159,7 +160,7 @@ int imapaint_pick_face(ViewContext *vc, Mesh *me, int *mval, unsigned int *index /* used for both 3d view and image window */ void paint_sample_color(Scene *scene, ARegion *ar, int x, int y) /* frontbuf */ { - VPaint *vp= scene->toolsettings->vpaint; + Brush **br = current_brush_source(scene); unsigned int col; char *cp; @@ -172,20 +173,10 @@ void paint_sample_color(Scene *scene, ARegion *ar, int x, int y) /* frontbuf */ cp = (char *)&col; - if(G.f & (G_VERTEXPAINT|G_WEIGHTPAINT)) { - vp->r= cp[0]/255.0f; - vp->g= cp[1]/255.0f; - vp->b= cp[2]/255.0f; - } - else { - Brush *brush= scene->toolsettings->imapaint.brush; - - if(brush) { - brush->rgb[0]= cp[0]/255.0f; - brush->rgb[1]= cp[1]/255.0f; - brush->rgb[2]= cp[2]/255.0f; - - } + if(br && *br) { + (*br)->rgb[0]= cp[0]/255.0f; + (*br)->rgb[1]= cp[1]/255.0f; + (*br)->rgb[2]= cp[2]/255.0f; } } diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index a9860402f74..60b1fc04064 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -64,6 +64,7 @@ #include "RNA_access.h" #include "BKE_armature.h" +#include "BKE_brush.h" #include "BKE_DerivedMesh.h" #include "BKE_cloth.h" #include "BKE_context.h" @@ -74,7 +75,6 @@ #include "BKE_global.h" #include "BKE_mesh.h" #include "BKE_modifier.h" -#include "BKE_multires.h" #include "BKE_object.h" #include "BKE_utildefines.h" @@ -143,7 +143,7 @@ static void vp_drawcursor(bContext *C, int x, int y, void *customdata) glColor4ub(255, 255, 255, 128); glEnable( GL_LINE_SMOOTH ); glEnable(GL_BLEND); - glutil_draw_lined_arc(0.0, M_PI*2.0, ts->vpaint->size, 40); + glutil_draw_lined_arc(0.0, M_PI*2.0, ts->vpaint->brush->size, 40); glDisable(GL_BLEND); glDisable( GL_LINE_SMOOTH ); @@ -159,7 +159,7 @@ static void wp_drawcursor(bContext *C, int x, int y, void *customdata) glColor4ub(200, 200, 255, 128); glEnable( GL_LINE_SMOOTH ); glEnable(GL_BLEND); - glutil_draw_lined_arc(0.0, M_PI*2.0, ts->wpaint->size, 40); + glutil_draw_lined_arc(0.0, M_PI*2.0, ts->wpaint->brush->size, 40); glDisable(GL_BLEND); glDisable( GL_LINE_SMOOTH ); @@ -186,20 +186,13 @@ static VPaint *new_vpaint(int wpaint) { VPaint *vp= MEM_callocN(sizeof(VPaint), "VPaint"); - vp->r= 1.0f; - vp->g= 1.0f; - vp->b= 1.0f; - vp->a= 0.2f; - vp->size= 25.0f; vp->gamma= vp->mul= 1.0f; vp->flag= VP_AREA+VP_SOFT+VP_SPRAY; - if(wpaint) { - vp->weight= 1.0f; - vp->a= 1.0f; + if(wpaint) vp->flag= VP_AREA+VP_SOFT; - } + return vp; } @@ -239,7 +232,7 @@ unsigned int rgba_to_mcol(float r, float g, float b, float a) static unsigned int vpaint_get_current_col(VPaint *vp) { - return rgba_to_mcol(vp->r, vp->g, vp->b, 1.0f); + return rgba_to_mcol(vp->brush->rgb[0], vp->brush->rgb[1], vp->brush->rgb[2], 1.0f); } void do_shared_vertexcol(Mesh *me) @@ -334,8 +327,6 @@ void make_vertexcol(Scene *scene, int shade) /* single ob */ else memset(me->mcol, 255, 4*sizeof(MCol)*me->totface); -// XXX if (me->mr) multires_load_cols(me); - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); } @@ -434,7 +425,7 @@ void clear_vpaint_selectedfaces(Scene *scene) void clear_wpaint_selectedfaces(Scene *scene) { VPaint *wp= scene->toolsettings->wpaint; - float paintweight= wp->weight; + float paintweight= wp->brush->alpha; Mesh *me; MFace *mface; Object *ob; @@ -742,7 +733,7 @@ static void vpaint_blend(VPaint *vp, unsigned int *col, unsigned int *colorig, u unsigned int testcol=0, a; char *cp, *ct, *co; - alpha= (int)(255.0*vp->a); + alpha= (int)(255.0*vp->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); @@ -818,14 +809,14 @@ static int calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, float vpimat[][3], floa dy= mval[1]-vertco[1]; fac= sqrt(dx*dx + dy*dy); - if(fac > vp->size) return 0; + if(fac > vp->brush->size) return 0; if(vp->flag & VP_HARD) alpha= 255; else - alpha= 255.0*vp->a*(1.0-fac/vp->size); + alpha= 255.0*vp->brush->alpha*(1.0-fac/vp->brush->size); } else { - alpha= 255.0*vp->a; + alpha= 255.0*vp->brush->alpha; } if(vp->flag & VP_NORMALS) { @@ -872,7 +863,7 @@ static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float if((wp->flag & VP_SPRAY)==0) { float testw=0.0f; - alpha= wp->a; + alpha= wp->brush->alpha; if(wp->mode==VP_MIX || wp->mode==VP_BLUR) testw = paintval*alpha + uw->weight*(1.0-alpha); else if(wp->mode==VP_ADD) @@ -1028,20 +1019,20 @@ void sample_wpaint(Scene *scene, ARegion *ar, View3D *v3d, int mode) fac= MIN4(w1, w2, w3, w4); if(w1==fac) { dw= get_defweight(me->dvert+mface->v1, ob->actdef-1); - if(dw) wp->weight= dw->weight; else wp->weight= 0.0f; + if(dw) wp->brush->alpha= dw->weight; else wp->brush->alpha= 0.0f; } else if(w2==fac) { dw= get_defweight(me->dvert+mface->v2, ob->actdef-1); - if(dw) wp->weight= dw->weight; else wp->weight= 0.0f; + if(dw) wp->brush->alpha= dw->weight; else wp->brush->alpha= 0.0f; } else if(w3==fac) { dw= get_defweight(me->dvert+mface->v3, ob->actdef-1); - if(dw) wp->weight= dw->weight; else wp->weight= 0.0f; + if(dw) wp->brush->alpha= dw->weight; else wp->brush->alpha= 0.0f; } else if(w4==fac) { if(mface->v4) { dw= get_defweight(me->dvert+mface->v4, ob->actdef-1); - if(dw) wp->weight= dw->weight; else wp->weight= 0.0f; + if(dw) wp->brush->alpha= dw->weight; else wp->brush->alpha= 0.0f; } } } @@ -1120,6 +1111,8 @@ static int set_wpaint(bContext *C, wmOperator *op) /* toggle */ if(wp==NULL) wp= scene->toolsettings->wpaint= new_vpaint(1); + + brush_check_exists(&wp->brush); toggle_paint_cursor(C, 1); @@ -1184,9 +1177,9 @@ void paint_radial_control_invoke(wmOperator *op, VPaint *vp) float original_value; if(mode == WM_RADIALCONTROL_SIZE) - original_value = vp->size; + original_value = vp->brush->size; else if(mode == WM_RADIALCONTROL_STRENGTH) - original_value = vp->a; + original_value = vp->brush->alpha; RNA_float_set(op->ptr, "initial_value", original_value); } @@ -1197,9 +1190,9 @@ static int paint_radial_control_exec(wmOperator *op, VPaint *vp) float new_value = RNA_float_get(op->ptr, "new_value"); if(mode == WM_RADIALCONTROL_SIZE) - vp->size = new_value; + vp->brush->size = new_value; else if(mode == WM_RADIALCONTROL_STRENGTH) - vp->a = new_value; + vp->brush->alpha = new_value; return OPERATOR_FINISHED; } @@ -1347,7 +1340,7 @@ static int wpaint_modal(bContext *C, wmOperator *op, wmEvent *event) Object *ob= vc->obact; Mesh *me= ob->data; float mat[4][4]; - float paintweight= wp->weight; + float paintweight= wp->brush->alpha; int *indexar= wpd->indexar; int totindex, index, alpha, totw; short mval[2]; @@ -1366,7 +1359,7 @@ static int wpaint_modal(bContext *C, wmOperator *op, wmEvent *event) /* which faces are involved */ if(wp->flag & VP_AREA) { - totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], wp->size); + totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], wp->brush->size); } else { indexar[0]= view3d_sample_backbuf(vc, mval[0], mval[1]); @@ -1404,7 +1397,7 @@ static int wpaint_modal(bContext *C, wmOperator *op, wmEvent *event) if(wp->mode==VP_BLUR) paintweight= 0.0f; else - paintweight= wp->weight; + paintweight= wp->brush->alpha; for(index=0; index<totindex; index++) { if(indexar[index] && indexar[index]<=me->totface) { @@ -1655,6 +1648,7 @@ static int set_vpaint(bContext *C, wmOperator *op) /* toggle */ vp= scene->toolsettings->vpaint= new_vpaint(0); toggle_paint_cursor(C, 0); + brush_check_exists(&scene->toolsettings->vpaint->brush); } if (me) @@ -1765,7 +1759,7 @@ static int vpaint_modal(bContext *C, wmOperator *op, wmEvent *event) /* which faces are involved */ if(vp->flag & VP_AREA) { - totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], vp->size); + totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], vp->brush->size); } else { indexar[0]= view3d_sample_backbuf(vc, mval[0], mval[1]); diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 40aaee758b9..d9616f95a05 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -1662,12 +1662,10 @@ static int sculpt_toggle_mode(bContext *C, wmOperator *op) toggle_paint_cursor(C); + /* If there's no brush, create one */ + brush_check_exists(&ts->sculpt->brush); - - /* XXX: testing */ - /* Needed for testing, if there's no brush then create one */ - ts->sculpt->brush = add_brush("test brush"); - /* Also for testing, set the brush texture to the first available one */ + /* XXX: testing: set the brush texture to the first available one */ if(G.main->tex.first) { Tex *tex = G.main->tex.first; if(tex->type) { diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c index 413cb79c7cc..d3af8a05faf 100644 --- a/source/blender/editors/space_view3d/view3d_buttons.c +++ b/source/blender/editors/space_view3d/view3d_buttons.c @@ -641,7 +641,6 @@ static void do_view3d_region_buttons(bContext *C, void *arg, int event) BoundBox *bb; Object *ob= OBACT; TransformProperties *tfp= v3d->properties_storage; - VPaint *wpaint= scene->toolsettings->wpaint; switch(event) { @@ -847,6 +846,7 @@ static void do_view3d_region_buttons(bContext *C, void *arg, int event) BIF_clearTransformOrientation(C); break; +#if 0 // XXX case B_WEIGHT0_0: wpaint->weight = 0.0f; break; @@ -879,6 +879,7 @@ static void do_view3d_region_buttons(bContext *C, void *arg, int event) case B_OPA1_0: wpaint->a = 1.0f; break; +#endif case B_CLR_WPAINT: // if(!multires_level1_test()) { { @@ -1004,7 +1005,8 @@ static void weight_paint_buttons(Scene *scene, uiBlock *block) ob= OBACT; if(ob==NULL || ob->type!=OB_MESH) return; - + + /* XXX uiBlockBeginAlign(block); uiDefButF(block, NUMSLI, B_REDR, "Weight:",10,170,225,19, &wpaint->weight, 0, 1, 10, 0, "Sets the current vertex group's bone deformation strength"); @@ -1033,6 +1035,7 @@ static void weight_paint_buttons(Scene *scene, uiBlock *block) uiDefButS(block, ROW, B_NOP, "Lighter", 250, 80,60,17, &wpaint->mode, 1.0, 5.0, 0, 0, "Paint over darker areas only"); uiDefButS(block, ROW, B_NOP, "Darker", 250, 62,60,17, &wpaint->mode, 1.0, 6.0, 0, 0, "Paint over lighter areas only"); uiBlockEndAlign(block); + */ /* draw options same as below */ uiBlockBeginAlign(block); @@ -1063,18 +1066,9 @@ static void weight_paint_buttons(Scene *scene, uiBlock *block) } } -static Brush **get_brush_source(const bContext *C) -{ - if(G.f & G_SCULPTMODE) - return &CTX_data_scene(C)->toolsettings->sculpt->brush; - else if(G.f & G_TEXTUREPAINT) - return &CTX_data_scene(C)->toolsettings->imapaint.brush; - return NULL; -} - static void brush_idpoin_handle(bContext *C, ID *id, int event) { - Brush **br = get_brush_source(C); + Brush **br = current_brush_source(CTX_data_scene(C)); if(!br) return; @@ -1106,7 +1100,7 @@ static void brush_idpoin_handle(bContext *C, ID *id, int event) static void view3d_panel_brush(const bContext *C, ARegion *ar, short cntrl) { uiBlock *block; - Brush **brp = get_brush_source(C), *br; + Brush **brp = current_brush_source(CTX_data_scene(C)), *br; short w = 268, h = 400, cx = 10, cy = h; rctf rect; @@ -1274,16 +1268,12 @@ static void view3d_panel_object(const bContext *C, ARegion *ar, short cntrl) // } else if(G.f & (G_VERTEXPAINT|G_TEXTUREPAINT)) { static float hsv[3], old[3]; // used as temp mem for picker - float *rgb= NULL; - ToolSettings *settings= scene->toolsettings; + Brush **br = current_brush_source(scene); - if(G.f & G_VERTEXPAINT) rgb= &settings->vpaint->r; - else if(settings->imapaint.brush) rgb= settings->imapaint.brush->rgb; - uiNewPanelTitle(block, "Paint Properties"); - if (rgb) + if(br && *br) /* 'f' is for floating panel */ - uiBlockPickerButtons(block, rgb, hsv, old, hexcol, 'f', B_REDR); + uiBlockPickerButtons(block, (*br)->rgb, hsv, old, hexcol, 'f', B_REDR); } else if(G.f & G_SCULPTMODE) { uiNewPanelTitle(block, "Sculpt Properties"); @@ -1574,7 +1564,7 @@ void view3d_buttons_area_defbuts(const bContext *C, ARegion *ar) view3d_panel_object(C, ar, 0); view3d_panel_properties(C, ar, 0); view3d_panel_background(C, ar, 0); - if(G.f & (G_SCULPTMODE|G_TEXTUREPAINT)) + if(G.f & (G_SCULPTMODE|G_TEXTUREPAINT|G_VERTEXPAINT|G_WEIGHTPAINT)) view3d_panel_brush(C, ar, 0); // XXX view3d_panel_preview(C, ar, 0); view3d_panel_transform_spaces(C, ar, 0); diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 0dff3cdb43d..067e3d0c2d0 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -401,10 +401,9 @@ typedef struct Sculpt } Sculpt; typedef struct VPaint { - float r, g, b, a; /* paint color */ - float weight; /* weight paint */ - float size; /* of brush */ - float gamma, mul; + struct Brush *brush; + + float gamma, mul; /* should become part of struct Brush? */ short mode, flag; int tot; /* allocation size of prev buffers */ unsigned int *vpaint_prev; /* previous mesh colors */ diff --git a/source/blender/makesrna/intern/rna_vpaint.c b/source/blender/makesrna/intern/rna_vpaint.c index ae3491e857e..44219f032e7 100644 --- a/source/blender/makesrna/intern/rna_vpaint.c +++ b/source/blender/makesrna/intern/rna_vpaint.c @@ -72,20 +72,6 @@ void RNA_def_vpaint(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "flag", VP_SPRAY); RNA_def_property_ui_text(prop, "Spray", "Keep applying paint effect while holding mouse."); - prop= RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR); - RNA_def_property_float_sdna(prop, NULL, "r"); - RNA_def_property_array(prop, 3); - RNA_def_property_ui_text(prop, "Color", "Brush color."); - - prop= RNA_def_property(srna, "opacity", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "a"); - RNA_def_property_range(prop, 0.0f, 1.0f); - RNA_def_property_ui_text(prop, "Opacity", "Brush Opacity."); - - prop= RNA_def_property(srna, "size", PROP_FLOAT, PROP_NONE); - RNA_def_property_range(prop, 2.0f, 64.0f); - RNA_def_property_ui_text(prop, "Size", "Brush Size."); - prop= RNA_def_property(srna, "gamma", PROP_FLOAT, PROP_NONE); RNA_def_property_range(prop, 0.1f, 5.0f); RNA_def_property_ui_text(prop, "Gamma", "Vpaint Gamma."); |