* Removed tablet pressure sensitive number field widget scrubbing, wasn't that useful...
authorMatt Ebb <matt@mke3.net>
Fri, 20 Nov 2009 01:39:27 +0000 (01:39 +0000)
committerMatt Ebb <matt@mke3.net>
Fri, 20 Nov 2009 01:39:27 +0000 (01:39 +0000)
* Added tablet pressure support (size/strength) for weight paint and vertex paint

* Added tablet eraser support for weight paint and vertex paint (inverts the effect of the current tool)

* Removed the old 'soft' option, now weight paint and vertex paint use the influence curve

* Made the default brush use a smooth influence curve, rather than sharp

release/scripts/ui/space_view3d_toolbar.py
source/blender/blenkernel/intern/brush.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/sculpt_paint/paint_stroke.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/rna_sculpt_paint.c

index 5f44f253f2f4b2b64b28a0f7dce2413e05ca8ecb..99da99b79bf48d1e0a65344755fd813e653365a6 100644 (file)
@@ -753,8 +753,6 @@ class VIEW3D_PT_tools_weightpaint_options(View3DPanel):
         col.itemR(wpaint, "all_faces")
         col.itemR(wpaint, "normals")
         col.itemR(wpaint, "spray")
-        col.itemR(wpaint, "vertex_dist", text="Distance")
-
 
         data = context.weight_paint_object.data
         if type(data) == bpy.types.Mesh:
@@ -787,7 +785,7 @@ class VIEW3D_PT_tools_vertexpaint(View3DPanel):
         col.itemR(vpaint, "all_faces")
         col.itemR(vpaint, "normals")
         col.itemR(vpaint, "spray")
-        col.itemR(vpaint, "vertex_dist", text="Distance")
+
 # Commented out because the Apply button isn't an operator yet, making these settings useless
 #              col.itemL(text="Gamma:")
 #              col.itemR(vpaint, "gamma", text="")
index ccee5a266f29e9e951e53da5f9f2cc31242d6c56..46bdcb8de70af2b7a1b0117f4da477aec8a0498c 100644 (file)
@@ -83,7 +83,7 @@ Brush *add_brush(const char *name)
        brush->clone.alpha= 0.5;
        brush->sculpt_tool = SCULPT_TOOL_DRAW;
 
-       brush_curve_preset(brush, BRUSH_PRESET_SHARP);
+       brush_curve_preset(brush, BRUSH_PRESET_SMOOTH);
 
        /* enable fake user by default */
        brush->id.flag |= LIB_FAKEUSER;
index 67e14aa377a4d23f50d14be0d36061a8fd2ec55b..fb4438455bdcef7f3cae68e6e7662641e3301ba9 100644 (file)
@@ -2224,14 +2224,6 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
                        fac= 1.0f;
                        if(event->shift) fac /= 10.0f;
                        if(event->alt) fac /= 20.0f;
-
-                       if(event->custom == EVT_DATA_TABLET) {
-                               wmTabletData *wmtab= event->customdata;
-
-                               /* de-sensitise based on tablet pressure */
-                               if (wmtab->Active != EVT_TABLET_NONE)
-                                       fac *= wmtab->Pressure;
-                       }
                        
                        snap= (event->ctrl)? (event->shift)? 2: 1: 0;
 
index 0b86034958fbf5cc49618456dd035e962257112f..8e795c5542ec8eb0778af4d8529ac01a73904757 100644 (file)
@@ -120,6 +120,7 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *ev
        PointerRNA itemptr;
        float cur_depth, pressure = 1;
        float center[3];
+       int flip= event->shift?1:0;
        PaintStroke *stroke = op->customdata;
 
        cur_depth = read_cached_depth(&stroke->vc, mouse[0], mouse[1]);
@@ -130,13 +131,15 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *ev
                wmTabletData *wmtab= event->customdata;
                if(wmtab->Active != EVT_TABLET_NONE)
                        pressure= wmtab->Pressure;
+               if(wmtab->Active == EVT_TABLET_ERASER)
+                       flip = 1;
        }
                                
        /* Add to stroke */
        RNA_collection_add(op->ptr, "stroke", &itemptr);
        RNA_float_set_array(&itemptr, "location", center);
        RNA_float_set_array(&itemptr, "mouse", mouse);
-       RNA_boolean_set(&itemptr, "flip", event->shift);
+       RNA_boolean_set(&itemptr, "flip", flip);
        RNA_float_set(&itemptr, "pressure", pressure);
 
        stroke->last_mouse_position[0] = mouse[0];
index 35723769f884be129f153dd0116ac2976d5e3300..2512ecbc2488d76ab3b02179dff29c561bacff9c 100644 (file)
@@ -154,12 +154,10 @@ static VPaint *new_vpaint(int wpaint)
 {
        VPaint *vp= MEM_callocN(sizeof(VPaint), "VPaint");
        
-       vp->gamma= vp->mul= 1.0f;
-       
-       vp->flag= VP_AREA+VP_SOFT+VP_SPRAY;
+       vp->flag= VP_AREA+VP_SPRAY;
        
        if(wpaint)
-               vp->flag= VP_AREA+VP_SOFT;
+               vp->flag= VP_AREA;
 
        return vp;
 }
@@ -468,7 +466,8 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight)
        DAG_id_flush_update(&me->id, OB_RECALC_DATA);
 }
 
-
+/* XXX: should be re-implemented as a vertex/weight paint 'colour correct' operator
 void vpaint_dogamma(Scene *scene)
 {
        VPaint *vp= scene->toolsettings->vpaint;
@@ -508,6 +507,7 @@ void vpaint_dogamma(Scene *scene)
                cp+= 4;
        }
 }
+ */
 
 static unsigned int mcol_blend(unsigned int col1, unsigned int col2, int fac)
 {
@@ -739,65 +739,83 @@ static int sample_backbuf_area(ViewContext *vc, int *indexar, int totface, int x
        return tot;
 }
 
-static int calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, float vpimat[][3], float *vert_nor, float *mval)
+static float calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, float vpimat[][3], float *vert_nor, float *mval, float pressure)
 {
        Brush *brush = paint_brush(&vp->paint);
-       float fac, dx, dy;
-       int alpha;
+       float fac, fac_2, size, dx, dy;
+       float alpha;
        short vertco[2];
        
-       if(vp->flag & VP_SOFT) {
-               project_short_noclip(vc->ar, vert_nor, vertco);
-               dx= mval[0]-vertco[0];
-               dy= mval[1]-vertco[1];
+       project_short_noclip(vc->ar, vert_nor, vertco);
+       dx= mval[0]-vertco[0];
+       dy= mval[1]-vertco[1];
+       
+       if (brush->flag & BRUSH_SIZE_PRESSURE)
+               size = pressure * brush->size;
+       else
+               size = brush->size;
+       
+       fac_2= dx*dx + dy*dy;
+       if(fac_2 > size*size) return 0.f;
+       fac = sqrtf(fac_2);
+       
+       alpha= brush->alpha * brush_curve_strength_clamp(brush, fac, size);
+       
+       if (brush->flag & BRUSH_ALPHA_PRESSURE)
+               alpha *= pressure;
                
-               fac= sqrt(dx*dx + dy*dy);
-               if(fac > brush->size) return 0;
-               if(vp->flag & VP_HARD)
-                       alpha= 255;
-               else
-                       alpha= 255.0*brush->alpha*(1.0-fac/brush->size);
-       }
-       else {
-               alpha= 255.0*brush->alpha;
-       }
-
        if(vp->flag & VP_NORMALS) {
                float *no= vert_nor+3;
                
-                       /* transpose ! */
+               /* transpose ! */
                fac= vpimat[2][0]*no[0]+vpimat[2][1]*no[1]+vpimat[2][2]*no[2];
                if(fac>0.0) {
                        dx= vpimat[0][0]*no[0]+vpimat[0][1]*no[1]+vpimat[0][2]*no[2];
                        dy= vpimat[1][0]*no[0]+vpimat[1][1]*no[1]+vpimat[1][2]*no[2];
                        
-                       alpha*= fac/sqrt(dx*dx + dy*dy + fac*fac);
+                       alpha*= fac/sqrtf(dx*dx + dy*dy + fac*fac);
                }
-               else return 0;
+               else return 0.f;
        }
        
        return alpha;
 }
 
-static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float alpha, float paintval)
+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;
        
        if(dw==NULL || uw==NULL) return;
        
-       if(wp->mode==VP_MIX || wp->mode==VP_BLUR)
+       if (flip) {
+               switch(mode) {
+                       case VP_MIX:
+                               paintval = 1.f - paintval; break;
+                       case VP_ADD:
+                               mode= VP_SUB; break;
+                       case VP_SUB:
+                               mode= VP_ADD; break;
+                       case VP_LIGHTEN:
+                               mode= VP_DARKEN; break;
+                       case VP_DARKEN:
+                               mode= VP_LIGHTEN; break;
+               }
+       }
+       
+       if(mode==VP_MIX || mode==VP_BLUR)
                dw->weight = paintval*alpha + dw->weight*(1.0-alpha);
-       else if(wp->mode==VP_ADD)
+       else if(mode==VP_ADD)
                dw->weight += paintval*alpha;
-       else if(wp->mode==VP_SUB) 
+       else if(mode==VP_SUB) 
                dw->weight -= paintval*alpha;
-       else if(wp->mode==VP_MUL) 
+       else if(mode==VP_MUL) 
                /* first mul, then blend the fac */
                dw->weight = ((1.0-alpha) + alpha*paintval)*dw->weight;
-       else if(wp->mode==VP_LIGHTEN) {
+       else if(mode==VP_LIGHTEN) {
                if (dw->weight < paintval)
                        dw->weight = paintval*alpha + dw->weight*(1.0-alpha);
-       } else if(wp->mode==VP_DARKEN) {
+       } else if(mode==VP_DARKEN) {
                if (dw->weight > paintval)
                        dw->weight = paintval*alpha + dw->weight*(1.0-alpha);
        }
@@ -808,21 +826,21 @@ static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float
                float testw=0.0f;
                
                alpha= brush->alpha;
-               if(wp->mode==VP_MIX || wp->mode==VP_BLUR)
+               if(mode==VP_MIX || mode==VP_BLUR)
                        testw = paintval*alpha + uw->weight*(1.0-alpha);
-               else if(wp->mode==VP_ADD)
+               else if(mode==VP_ADD)
                        testw = uw->weight + paintval*alpha;
-               else if(wp->mode==VP_SUB) 
+               else if(mode==VP_SUB) 
                        testw = uw->weight - paintval*alpha;
-               else if(wp->mode==VP_MUL) 
+               else if(mode==VP_MUL) 
                        /* first mul, then blend the fac */
                        testw = ((1.0-alpha) + alpha*paintval)*uw->weight;              
-               else if(wp->mode==VP_LIGHTEN) {
+               else if(mode==VP_LIGHTEN) {
                        if (uw->weight < paintval)
                                testw = paintval*alpha + uw->weight*(1.0-alpha);
                        else
                                testw = uw->weight;
-               } else if(wp->mode==VP_DARKEN) {
+               } else if(mode==VP_DARKEN) {
                        if (uw->weight > paintval)
                                testw = paintval*alpha + uw->weight*(1.0-alpha);
                        else
@@ -1023,7 +1041,7 @@ static void do_weight_paint_auto_normalize(MDeformVert *dvert,
 }
 
 static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, 
-                                  int alpha, float paintweight
+                                  float alpha, float paintweight, int flip
                                   int vgroup_mirror, char *validmap)
 {
        Mesh *me= ob->data;
@@ -1041,7 +1059,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index,
        if(dw==NULL || uw==NULL)
                return;
        
-       wpaint_blend(wp, dw, uw, (float)alpha/255.0, paintweight);
+       wpaint_blend(wp, dw, uw, alpha, paintweight, flip);
        do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap);
 
        if(me->editflag & ME_EDIT_MIRROR_X) {   /* x mirror painting */
@@ -1423,8 +1441,9 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
        float mat[4][4];
        float paintweight= ts->vgroup_weight;
        int *indexar= wpd->indexar;
-       int totindex, index, alpha, totw;
-       float mval[2];
+       int totindex, index, totw, flip;
+       float alpha;
+       float mval[2], pressure;
 
        view3d_operator_needs_opengl(C);
                        
@@ -1433,6 +1452,8 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
        wmGetSingleMatrix(mat);
        wmLoadMatrix(wpd->vc.rv3d->viewmat);
 
+       flip = RNA_boolean_get(itemptr, "flip");
+       pressure = RNA_float_get(itemptr, "pressure");
        RNA_float_get_array(itemptr, "mouse", mval);
        mval[0]-= vc->ar->winrct.xmin;
        mval[1]-= vc->ar->winrct.ymin;
@@ -1457,7 +1478,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
                                if(mface->mat_nr!=ob->actcol-1) {
                                        indexar[index]= 0;
                                }
-                       }                                       
+                       }
                }
        }
                        
@@ -1519,30 +1540,30 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
                        MFace *mface= me->mface + (indexar[index]-1);
                                        
                        if((me->dvert+mface->v1)->flag) {
-                               alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v1, mval);
+                               alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v1, mval, pressure);
                                if(alpha) {
                                        do_weight_paint_vertex(wp, ob, mface->v1, 
-                                               alpha, paintweight, wpd->vgroup_mirror, 
+                                               alpha, paintweight, flip, wpd->vgroup_mirror, 
                                                wpd->vgroup_validmap);
                                }
                                (me->dvert+mface->v1)->flag= 0;
                        }
                                        
                        if((me->dvert+mface->v2)->flag) {
-                               alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v2, mval);
+                               alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v2, mval, pressure);
                                if(alpha) {
                                        do_weight_paint_vertex(wp, ob, mface->v2, 
-                                               alpha, paintweight, wpd->vgroup_mirror, 
+                                               alpha, paintweight, flip, wpd->vgroup_mirror, 
                                                wpd->vgroup_validmap);
                                }
                                (me->dvert+mface->v2)->flag= 0;
                        }
                                        
                        if((me->dvert+mface->v3)->flag) {
-                               alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v3, mval);
+                               alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v3, mval, pressure);
                                if(alpha) {
                                        do_weight_paint_vertex(wp, ob, mface->v3, 
-                                               alpha, paintweight, wpd->vgroup_mirror, 
+                                               alpha, paintweight, flip, wpd->vgroup_mirror, 
                                                wpd->vgroup_validmap);
                                }
                                (me->dvert+mface->v3)->flag= 0;
@@ -1550,10 +1571,10 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
                                        
                        if((me->dvert+mface->v4)->flag) {
                                if(mface->v4) {
-                                       alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v4, mval);
+                                       alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v4, mval, pressure);
                                        if(alpha) {
                                                do_weight_paint_vertex(wp, ob, mface->v4, 
-                                                       alpha, paintweight, wpd->vgroup_mirror,
+                                                       alpha, paintweight, flip, wpd->vgroup_mirror,
                                                        wpd->vgroup_validmap);
                                        }
                                        (me->dvert+mface->v4)->flag= 0;
@@ -1802,14 +1823,15 @@ static int vpaint_stroke_test_start(bContext *C, struct wmOperator *op, wmEvent
        return 1;
 }
 
-static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, int index, float mval[2])
+static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, int index, float mval[2], float pressure, int flip)
 {
        ViewContext *vc = &vpd->vc;
        Mesh *me = get_mesh(ob);
        MFace *mface= ((MFace*)me->mface) + index;
        unsigned int *mcol= ((unsigned int*)me->mcol) + 4*index;
        unsigned int *mcolorig= ((unsigned int*)vp->vpaint_prev) + 4*index;
-       int alpha, i;
+       float alpha;
+       int i;
        
        if((vp->flag & VP_COLINDEX && mface->mat_nr!=ob->actcol-1) ||
           ((me->editflag & ME_EDIT_PAINT_MASK) && !(mface->flag & ME_FACE_SEL)))
@@ -1828,9 +1850,9 @@ static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, int index
        }
 
        for(i = 0; i < (mface->v4 ? 4 : 3); ++i) {
-               alpha= calc_vp_alpha_dl(vp, vc, vpd->vpimat, vpd->vertexcosnos+6*(&mface->v1)[i], mval);
+               alpha= calc_vp_alpha_dl(vp, vc, vpd->vpimat, vpd->vertexcosnos+6*(&mface->v1)[i], mval, pressure);
                if(alpha)
-                       vpaint_blend(vp, mcol+i, mcolorig+i, vpd->paintcol, alpha);
+                       vpaint_blend(vp, mcol+i, mcolorig+i, vpd->paintcol, (int)(alpha*255.0));
        }
 }
 
@@ -1845,10 +1867,12 @@ static void vpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
        Mesh *me= ob->data;
        float mat[4][4];
        int *indexar= vpd->indexar;
-       int totindex, index;
-       float mval[2];
+       int totindex, index, flip;
+       float pressure, mval[2];
 
        RNA_float_get_array(itemptr, "mouse", mval);
+       flip = RNA_boolean_get(itemptr, "flip");
+       pressure = RNA_float_get(itemptr, "pressure");
                        
        view3d_operator_needs_opengl(C);
                        
@@ -1875,7 +1899,7 @@ static void vpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
                        
        for(index=0; index<totindex; index++) {                         
                if(indexar[index] && indexar[index]<=me->totface)
-                       vpaint_paint_face(vp, vpd, ob, indexar[index]-1, mval);
+                       vpaint_paint_face(vp, vpd, ob, indexar[index]-1, mval, pressure, flip);
        }
                                                
        swap_m4m4(vc->rv3d->persmat, mat);
index b041227110bd01316749370f2bf4a9b85c9283b4..d4c8aead5135ce81792981c709ff0bb0068613c3 100644 (file)
@@ -542,7 +542,6 @@ typedef struct Sculpt {
 typedef struct VPaint {
        Paint paint;
 
-       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 */
@@ -554,11 +553,10 @@ typedef struct VPaint {
 /* VPaint flag */
 #define VP_COLINDEX    1
 #define VP_AREA                2
-#define VP_SOFT                4
+
 #define VP_NORMALS     8
 #define VP_SPRAY       16
 // #define VP_MIRROR_X 32 // depricated in 2.5x use (me->editflag & ME_EDIT_MIRROR_X)
-#define VP_HARD                64
 #define VP_ONLYVGROUP  128
 
 
index 667633b4d90a45f8032b2e7bcd3feb48eb7075df..db100c38257ac80437b13563f031c853ddcaeefa 100644 (file)
@@ -256,11 +256,7 @@ static void rna_def_vertex_paint(BlenderRNA *brna)
        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.");
-       
-       prop= RNA_def_property(srna, "vertex_dist", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "flag", VP_SOFT);
-       RNA_def_property_ui_text(prop, "Vertex Dist", "Use distances to vertices (instead of paint entire faces).");
-       
+               
        prop= RNA_def_property(srna, "normals", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag", VP_NORMALS);
        RNA_def_property_ui_text(prop, "Normals", "Applies the vertex normal before painting.");
@@ -268,14 +264,6 @@ static void rna_def_vertex_paint(BlenderRNA *brna)
        prop= RNA_def_property(srna, "spray", PROP_BOOLEAN, PROP_NONE);
        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, "gamma", PROP_FLOAT, PROP_NONE);
-       RNA_def_property_range(prop, 0.1f, 5.0f);
-       RNA_def_property_ui_text(prop, "Gamma", "Vertex paint Gamma.");
-       
-       prop= RNA_def_property(srna, "mul", PROP_FLOAT, PROP_NONE);
-       RNA_def_property_range(prop, 0.1f, 50.0f);
-       RNA_def_property_ui_text(prop, "Mul", "Vertex paint Mul.");
 }
 
 static void rna_def_image_paint(BlenderRNA *brna)