svn merge -r41715:41722 ^/trunk/blender
authorCampbell Barton <ideasman42@gmail.com>
Fri, 11 Nov 2011 05:52:46 +0000 (05:52 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 11 Nov 2011 05:52:46 +0000 (05:52 +0000)
1  2 
source/blender/editors/sculpt_paint/paint_vertex.c

index 4d024113cf88c10e04f06d0167baa9d577bd1a2c,7144ae3e31a536e74943e0c8bb1564b29f258768..04239ab950808e49f6fd1692a80c80168af458c0
@@@ -43,7 -43,6 +43,7 @@@
  
  #include "BLI_blenlib.h"
  #include "BLI_math.h"
 +#include "BLI_memarena.h"
  #include "BLI_utildefines.h"
  #include "BLI_ghash.h"
  
@@@ -198,7 -197,7 +198,7 @@@ unsigned int vpaint_get_current_col(VPa
        return rgba_to_mcol(brush->rgb[0], brush->rgb[1], brush->rgb[2], 1.0f);
  }
  
 -static void do_shared_vertexcol(Mesh *me)
 +static void do_shared_vertex_tesscol(Mesh *me)
  {
        /* if no mcol: do not do */
        /* if tface: only the involved faces, otherwise all */
        MEM_freeN(scolmain);
  }
  
 +void do_shared_vertexcol(Mesh *me)
 +{
 +      MLoop *ml = me->mloop;
 +      MLoopCol *lcol = me->mloopcol;
 +      MTexPoly *mtp = me->mtpoly;
 +      MPoly *mp = me->mpoly;
 +      float (*scol)[5];
 +      int i, has_shared = 0;
 +
 +      /* if no mloopcol: do not do */
 +      /* if mtexpoly: only the involved faces, otherwise all */
 +
 +      if(me->mloopcol==0 || me->totvert==0 || me->totpoly==0) return;
 +
 +      scol = MEM_callocN(sizeof(float)*me->totvert*5, "scol");
 +
 +      for (i=0; i<me->totloop; i++, ml++, lcol++) {
 +              if (i >= mp->loopstart + mp->totloop) {
 +                      mp++;
 +                      if (mtp) mtp++;
 +              }
 +
 +              if (!(mtp && (mtp->mode & TF_SHAREDCOL)) && (me->editflag & ME_EDIT_PAINT_MASK)!=0)
 +                      continue;
 +
 +              scol[ml->v][0] += lcol->r;
 +              scol[ml->v][1] += lcol->g;
 +              scol[ml->v][2] += lcol->b;
 +              scol[ml->v][3] += lcol->a;
 +              scol[ml->v][4] += 1.0;
 +              has_shared = 1;
 +      }
 +      
 +      if (has_shared) {
 +              for (i=0; i<me->totvert; i++) {
 +                      if (!scol[i][4]) continue;
 +
 +                      scol[i][0] /= scol[i][4];
 +                      scol[i][1] /= scol[i][4];
 +                      scol[i][2] /= scol[i][4];
 +                      scol[i][3] /= scol[i][4];
 +              }
 +      
 +              ml = me->mloop;
 +              lcol = me->mloopcol;
 +              for (i=0; i<me->totloop; i++, ml++, lcol++) {
 +                      if (!scol[ml->v][4]) continue;
 +
 +                      lcol->r = scol[ml->v][0];
 +                      lcol->g = scol[ml->v][1];
 +                      lcol->b = scol[ml->v][2];
 +                      lcol->a = scol[ml->v][3];
 +              }
 +      }
 +
 +      MEM_freeN(scol);
 +
 +      if (has_shared) {
 +              do_shared_vertex_tesscol(me);
 +      }
 +}
 +
  static void make_vertexcol(Object *ob)        /* single ob */
  {
        Mesh *me;
        if(!ob || ob->id.lib) return;
        me= get_mesh(ob);
        if(me==NULL) return;
 -      if(me->edit_mesh) return;
 +      if(me->edit_btmesh) return;
  
        /* copies from shadedisplist to mcol */
 -      if(!me->mcol) {
 -              CustomData_add_layer(&me->fdata, CD_MCOL, CD_CALLOC, NULL, me->totface);
 -              mesh_update_customdata_pointers(me);
 -      }
 +      if(!me->mcol)
 +              CustomData_add_layer(&me->fdata, CD_MCOL, CD_DEFAULT, NULL, me->totface);
 +      if (!me->mloopcol)
 +              CustomData_add_layer(&me->ldata, CD_MLOOPCOL, CD_DEFAULT, NULL, me->totloop);
 +      
 +      mesh_update_customdata_pointers(me);
  
        //if(shade)
        //      shadeMeshMCol(scene, ob, me);
@@@ -388,7 -323,7 +388,7 @@@ static int wpaint_mirror_vgroup_ensure(
        return -1;
  }
  
 -static void copy_vpaint_prev(VPaint *vp, unsigned int *mcol, int tot)
 +static void copy_vpaint_prev(VPaint *vp, unsigned int *lcol, int tot)
  {
        if(vp->vpaint_prev) {
                MEM_freeN(vp->vpaint_prev);
        }
        vp->tot= tot;   
        
 -      if(mcol==NULL || tot==0) return;
 +      if(lcol==NULL || tot==0) return;
        
 -      vp->vpaint_prev= MEM_mallocN(4*sizeof(int)*tot, "vpaint_prev");
 -      memcpy(vp->vpaint_prev, mcol, 4*sizeof(int)*tot);
 +      vp->vpaint_prev= MEM_mallocN(sizeof(int)*tot, "vpaint_prev");
 +      memcpy(vp->vpaint_prev, lcol, sizeof(int)*tot);
        
  }
  
@@@ -422,17 -357,16 +422,18 @@@ static void copy_wpaint_prev (VPaint *w
  void vpaint_fill(Object *ob, unsigned int paintcol)
  {
        Mesh *me;
 -      MFace *mf;
 +      MFace *mf;
 +      MPoly *mp;
 +      MLoopCol *lcol;
        unsigned int *mcol;
 -      int i, selected;
 +      int i, j, selected;
  
        me= get_mesh(ob);
        if(me==NULL || me->totface==0) return;
  
-       if(!me->mcol)
-               make_vertexcol(ob);
+       if(!me->mcol) make_vertexcol(ob);
+       if(!me->mcol) return; /* possible we can't make mcol's */
  
        selected= (me->editflag & ME_EDIT_PAINT_MASK);
  
                        mcol[3] = paintcol;
                }
        }
 +
 +      mp = me->mpoly;
 +      lcol = me->mloopcol;
 +      for (i=0; i<me->totpoly; i++, mp++) {
 +              if (!(!selected || mp->flag & ME_FACE_SEL))
 +                      continue;
 +
 +              lcol = me->mloopcol + mp->loopstart;
 +              for (j=0; j<mp->totloop; j++, lcol++) {
 +                      *(int*)lcol = paintcol;
 +              }
 +      }
        
        DAG_id_tag_update(&me->id, 0);
  }
  void wpaint_fill(VPaint *wp, Object *ob, float paintweight)
  {
        Mesh *me= ob->data;
 -      MFace *mf;
 +      MPoly *mf;
        MDeformWeight *dw, *uw;
        int vgroup, vgroup_mirror= -1;
        unsigned int index;
        /* mutually exclusive, could be made into a */
        const short paint_selmode= ME_EDIT_PAINT_SEL_MODE(me);
  
 -      if(me->totface==0 || me->dvert==NULL || !me->mface) return;
 +      if(me->totpoly==0 || me->dvert==NULL || !me->mpoly) return;
        
        vgroup= ob->actdef-1;
  
        
        copy_wpaint_prev(wp, me->dvert, me->totvert);
        
 -      for(index=0, mf= me->mface; index < me->totface; index++, mf++) {
 -              unsigned int fidx= mf->v4 ? 3:2;
 +      for(index=0, mf= me->mpoly; index < me->totpoly; index++, mf++) {
 +              unsigned int fidx= mf->totloop - 1;
  
                if ((paint_selmode == SCE_SELECT_FACE) && !(mf->flag & ME_FACE_SEL)) {
                        continue;
                }
  
                do {
 -                      unsigned int vidx= *(&mf->v1 + fidx);
 +                      unsigned int vidx= me->mloop[mf->loopstart + fidx].v;
  
                        if(!me->dvert[vidx].flag) {
                                if((paint_selmode == SCE_SELECT_VERTEX) && !(me->mvert[vidx].flag & SELECT)) {
@@@ -960,14 -882,14 +961,14 @@@ static int weight_sample_invoke(bContex
  
                index= view3d_sample_backbuf(&vc, event->mval[0], event->mval[1]);
  
 -              if(index && index<=me->totface) {
 +              if(index && index<=me->totpoly) {
                        DerivedMesh *dm= mesh_get_derived_final(vc.scene, vc.obact, CD_MASK_BAREMESH);
  
                        if(dm->getVertCo==NULL) {
                                BKE_report(op->reports, RPT_WARNING, "The modifier used does not support deformed locations");
                        }
                        else {
 -                              MFace *mf= ((MFace *)me->mface) + index-1;
 +                              MPoly *mf= ((MPoly *)me->mpoly) + index-1;
                                const int vgroup= vc.obact->actdef - 1;
                                ToolSettings *ts= vc.scene->toolsettings;
                                float mval_f[2];
                                mval_f[0]= (float)event->mval[0];
                                mval_f[1]= (float)event->mval[1];
  
 -                              fidx= mf->v4 ? 3:2;
 +                              fidx= mf->totloop - 1;
                                do {
                                        float co[3], sco[3], len;
 -                                      const int v_idx= (*(&mf->v1 + fidx));
 +                                      const int v_idx= me->mloop[mf->loopstart + fidx].v;
                                        dm->getVertCo(dm, v_idx, co);
                                        project_float_noclip(vc.ar, co, sco);
                                        len= len_squared_v2v2(mval_f, sco);
@@@ -1047,13 -969,13 +1048,13 @@@ static EnumPropertyItem *weight_paint_s
                                if(index && index<=me->totface) {
                                        const int totgroup= BLI_countlist(&vc.obact->defbase);
                                        if(totgroup) {
 -                                              MFace *mf= ((MFace *)me->mface) + index-1;
 -                                              unsigned int fidx= mf->v4 ? 3:2;
 +                                              MPoly *mf= ((MPoly *)me->mpoly) + index-1;
 +                                              unsigned int fidx= mf->totloop - 1;
                                                int *groups= MEM_callocN(totgroup*sizeof(int), "groups");
                                                int found= FALSE;
  
                                                do {
 -                                                      MDeformVert *dvert= me->dvert + (*(&mf->v1 + fidx));
 +                                                      MDeformVert *dvert= me->dvert + me->mloop[mf->loopstart + fidx].v;
                                                        int i= dvert->totweight;
                                                        MDeformWeight *dw;
                                                        for(dw= dvert->dw; i > 0; dw++, i--) {
@@@ -1758,8 -1680,14 +1759,14 @@@ static void do_weight_paint_vertex( /* 
                if(dv_copy.dw) {
                        MEM_freeN(dv_copy.dw);
                }
+ #if 0
                /* dv may have been altered greatly */
                dw = defvert_find_index(dv, vgroup);
+ #else
+               dw = NULL; /* UNUSED after assignment, set to NULL to ensuyre we don't
+                               * use again, we thats needed un-ifdef the line above */
+               (void)dw;  /* quiet warnigns */
+ #endif
  
                if(me->editflag & ME_EDIT_MIRROR_X) {   /* x mirror painting */
                        int index_mirr= mesh_get_x_mirror_vert(ob, index);
@@@ -1941,13 -1869,6 +1948,13 @@@ static int wpaint_stroke_test_start(bCo
        me= get_mesh(ob);
        if(me==NULL || me->totface==0) return OPERATOR_PASS_THROUGH;
        
 +      /*we can't assume mfaces have a correct origindex layer that indices to mpolys.
 +        so instead we have to regenerate the tesselation faces altogether.*/
 +      me->totface = mesh_recalcTesselation(&me->fdata, &me->ldata, &me->pdata, 
 +              me->mvert, me->totface, me->totloop, me->totpoly, 1, 0);
 +      mesh_update_customdata_pointers(me);
 +      makeDerivedMesh(scene, ob, NULL, CD_MASK_BAREMESH, 0);
 +
        /* if nothing was added yet, we make dverts and a vertex deform group */
        if (!me->dvert) {
                ED_vgroup_data_create(&me->id);
@@@ -2090,22 -2011,22 +2097,22 @@@ static void wpaint_stroke_update_step(b
                        
        if(wp->flag & VP_COLINDEX) {
                for(index=0; index<totindex; index++) {
 -                      if(indexar[index] && indexar[index]<=me->totface) {
 -                              MFace *mface= ((MFace *)me->mface) + (indexar[index]-1);
 +                      if(indexar[index] && indexar[index]<=me->totpoly) {
 +                              MPoly *mpoly= ((MPoly *)me->mpoly) + (indexar[index]-1);
                                                
 -                              if(mface->mat_nr!=ob->actcol-1) {
 +                              if(mpoly->mat_nr!=ob->actcol-1) {
                                        indexar[index]= 0;
                                }
                        }
                }
        }
                        
 -      if((me->editflag & ME_EDIT_PAINT_MASK) && me->mface) {
 +      if((me->editflag & ME_EDIT_PAINT_MASK) && me->mpoly) {
                for(index=0; index<totindex; index++) {
 -                      if(indexar[index] && indexar[index]<=me->totface) {
 -                              MFace *mface= ((MFace *)me->mface) + (indexar[index]-1);
 +                      if(indexar[index] && indexar[index]<=me->totpoly) {
 +                              MPoly *mpoly= ((MPoly *)me->mpoly) + (indexar[index]-1);
                                                
 -                              if((mface->flag & ME_FACE_SEL)==0) {
 +                              if((mpoly->flag & ME_FACE_SEL)==0) {
                                        indexar[index]= 0;
                                }
                        }                                       
                paintweight= ts->vgroup_weight;
                        
        for(index=0; index<totindex; index++) {
 -              if(indexar[index] && indexar[index]<=me->totface) {
 -                      MFace *mface= me->mface + (indexar[index]-1);
 +              if(indexar[index] && indexar[index]<=me->totpoly) {
 +                      MPoly *mpoly= me->mpoly + (indexar[index]-1);
 +                      MLoop *ml = me->mloop + mpoly->loopstart;
 +                      int i;
  
                        if(use_vert_sel) {
 -                              me->dvert[mface->v1].flag = (me->mvert[mface->v1].flag & SELECT);
 -                              me->dvert[mface->v2].flag = (me->mvert[mface->v2].flag & SELECT);
 -                              me->dvert[mface->v3].flag = (me->mvert[mface->v3].flag & SELECT);
 -                              if(mface->v4) me->dvert[mface->v4].flag = (me->mvert[mface->v4].flag & SELECT);
 +                              for (i=0; i<mpoly->totloop; i++, ml++) {
 +                                      me->dvert[ml->v].flag = (me->mvert[ml->v].flag & SELECT);
 +                              }
                        }
                        else {
 -                              me->dvert[mface->v1].flag= 1;
 -                              me->dvert[mface->v2].flag= 1;
 -                              me->dvert[mface->v3].flag= 1;
 -                              if(mface->v4) me->dvert[mface->v4].flag= 1;
 +                              for (i=0; i<mpoly->totloop; i++, ml++) {
 +                                      me->dvert[ml->v].flag = 1;
 +                              }
                        }
                                        
                        if(brush->vertexpaint_tool==VP_BLUR) {
                                MDeformWeight *dw, *(*dw_func)(MDeformVert *, const int);
 -                              unsigned int fidx= mface->v4 ? 3:2;
                                                
                                if(wp->flag & VP_ONLYVGROUP)
                                        dw_func= (MDeformWeight *(*)(MDeformVert *, const int))defvert_find_index;
                                else
                                        dw_func= defvert_verify_index;
 -
 -                              do {
 -                                      unsigned int vidx= *(&mface->v1 + fidx);
 -
 -                                      dw= dw_func(me->dvert+vidx, ob->actdef-1);
 -                                      if(dw) {
 -                                              paintweight+= dw->weight;
 +                                              
 +                              ml = me->mloop + mpoly->loopstart;
 +                              for (i=0; i<mpoly->totloop; i++, ml++) {
 +                                      dw = dw_func(me->dvert+ml->v, ob->actdef-1);
 +                                      if (dw) {
 +                                              paintweight += dw->weight;
                                                totw++;
                                        }
 -
 -                              } while (fidx--);
 -
 +                              }
                        }
                }
        }
                paintweight/= (float)totw;
                        
        for(index=0; index<totindex; index++) {
 -                              
 -              if(indexar[index] && indexar[index]<=me->totface) {
 -                      MFace *mf= me->mface + (indexar[index]-1);
 -                      unsigned int fidx= mf->v4 ? 3:2;
 -                      do {
 -                              unsigned int vidx= *(&mf->v1 + fidx);
 -
 -                              if(me->dvert[vidx].flag) {
 +              if(indexar[index] && indexar[index]<=me->totpoly) {
 +                      MPoly *mpoly= me->mpoly + (indexar[index]-1);
 +                      MLoop *ml=me->mloop+mpoly->loopstart;
 +                      int i;
 +
 +                      for (i=0; i<mpoly->totloop; i++, ml++) {
 +                              unsigned int vidx= ml->v;
 +                              if (me->dvert[vidx].flag) {
                                        alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*vidx, mval, pressure);
                                        if(alpha) {
                                                do_weight_paint_vertex(wp, ob, &wpi, vidx, alpha, paintweight);
                                        }
                                        me->dvert[vidx].flag= 0;
                                }
 -                      } while (fidx--);
 +                      }
                }
        }
  
@@@ -2315,7 -2240,7 +2322,7 @@@ static int set_vpaint(bContext *C, wmOp
                return OPERATOR_PASS_THROUGH;
        }
        
 -      if(me && me->mcol==NULL) make_vertexcol(ob);
 +      if(me && me->mloopcol==NULL) make_vertexcol(ob);
        
        /* toggle: end vpaint */
        if(ob->mode & OB_MODE_VERTEX_PAINT) {
@@@ -2383,60 -2308,14 +2390,60 @@@ For future
  
  */
  
 +typedef struct polyfacemap_e {
 +      struct polyfacemap_e *next, *prev;
 +      int facenr;
 +} polyfacemap_e;
 +
  typedef struct VPaintData {
        ViewContext vc;
        unsigned int paintcol;
        int *indexar;
        float *vertexcosnos;
        float vpimat[3][3];
 +      
 +      /*mpoly -> mface mapping*/
 +      MemArena *arena;
 +      ListBase *polyfacemap;
  } VPaintData;
  
 +static void vpaint_build_poly_facemap(struct VPaintData *vd, Mesh *me,
 +                                    Object *ob, Scene *scene)
 +{
 +      MFace *mf;
 +      polyfacemap_e *e;
 +      int *origIndex;
 +      int i;
 +
 +      vd->arena = BLI_memarena_new(1<<13, "vpaint tmp");
 +      BLI_memarena_use_calloc(vd->arena);
 +
 +      vd->polyfacemap = BLI_memarena_alloc(vd->arena, sizeof(ListBase)*me->totpoly);
 +
 +      /*we can't assume mfaces have a correct origindex layer that indices to mpolys.
 +        so instead we have to regenerate the tesselation faces altogether.*/
 +      me->totface = mesh_recalcTesselation(&me->fdata, &me->ldata, &me->pdata, 
 +              me->mvert, me->totface, me->totloop, me->totpoly, 1, 0);
 +      mesh_update_customdata_pointers(me);
 +      makeDerivedMesh(scene, ob, NULL, CD_MASK_BAREMESH, 0);
 +
 +      origIndex = CustomData_get_layer(&me->fdata, CD_ORIGINDEX);
 +      mf = me->mface;
 +
 +      if (!origIndex)
 +              return;
 +
 +      for (i=0; i<me->totface; i++, mf++, origIndex++) {
 +              if (*origIndex == ORIGINDEX_NONE)
 +                      continue;
 +
 +              e = BLI_memarena_alloc(vd->arena, sizeof(polyfacemap_e));
 +              e->facenr = i;
 +              
 +              BLI_addtail(&vd->polyfacemap[*origIndex], e);
 +      }
 +}
 +
  static int vpaint_stroke_test_start(bContext *C, struct wmOperator *op, wmEvent *UNUSED(event))
  {
        ToolSettings *ts= CTX_data_tool_settings(C);
        VPaint *vp= ts->vpaint;
        struct VPaintData *vpd;
        Object *ob= CTX_data_active_object(C);
 +      Scene *scene = CTX_data_scene(C);
        Mesh *me;
        float mat[4][4], imat[4][4];
  
        /* context checks could be a poll() */
        me= get_mesh(ob);
 -      if(me==NULL || me->totface==0) return OPERATOR_PASS_THROUGH;
 +      if(me==NULL || me->totpoly==0)
 +              return OPERATOR_PASS_THROUGH;
        
 -      if(me->mcol==NULL) make_vertexcol(ob);
 -      if(me->mcol==NULL) return OPERATOR_CANCELLED;
 +      if(me->mloopcol==NULL)
 +              make_vertexcol(ob);
 +      if(me->mloopcol==NULL)
 +              return OPERATOR_CANCELLED;
        
        /* make mode data storage */
        vpd= MEM_callocN(sizeof(struct VPaintData), "VPaintData");
        vpd->vertexcosnos= mesh_get_mapped_verts_nors(vpd->vc.scene, ob);
        vpd->indexar= get_indexarray(me);
        vpd->paintcol= vpaint_get_current_col(vp);
 +      vpaint_build_poly_facemap(vpd, me, ob, scene);
        
        /* for filtering */
 -      copy_vpaint_prev(vp, (unsigned int *)me->mcol, me->totface);
 +      copy_vpaint_prev(vp, (unsigned int *)me->mloopcol, me->totloop);
        
        /* some old cruft to sort out later */
        mul_m4_m4m4(mat, ob->obmat, vpd->vc.rv3d->viewmat);
        return 1;
  }
  
 -static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, const unsigned int index, const float mval[2], float pressure, int UNUSED(flip))
 +#if 0
 +static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, int index, const float mval[2], float pressure, int UNUSED(flip))
  {
        ViewContext *vc = &vpd->vc;
        Brush *brush = paint_brush(&vp->paint);
                        vpaint_blend(vp, mcol+i, mcolorig+i, vpd->paintcol, (int)(alpha*255.0f));
        }
  }
 +#endif
  
  static void vpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, PointerRNA *itemptr)
  {
        Brush *brush = paint_brush(&vp->paint);
        ViewContext *vc= &vpd->vc;
        Object *ob= vc->obact;
 +      polyfacemap_e *e;
        Mesh *me= ob->data;
        float mat[4][4];
        int *indexar= vpd->indexar;
                        
        /* which faces are involved */
        if(vp->flag & VP_AREA) {
 -              totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], brush_size(brush));
 +              totindex= sample_backbuf_area(vc, indexar, me->totpoly, mval[0], mval[1], brush_size(brush));
        }
        else {
                indexar[0]= view3d_sample_backbuf(vc, mval[0], mval[1]);
                        
        swap_m4m4(vc->rv3d->persmat, mat);
                        
 -      for(index=0; index<totindex; index++) {                         
 -              if(indexar[index] && indexar[index]<=me->totface)
 -                      vpaint_paint_face(vp, vpd, ob, indexar[index]-1, mval, pressure, flip);
 +      if(vp->flag & VP_COLINDEX) {
 +              for(index=0; index<totindex; index++) {
 +                      if(indexar[index] && indexar[index]<=me->totpoly) {
 +                              MPoly *mpoly= ((MPoly *)me->mpoly) + (indexar[index]-1);
 +                                              
 +                              if(mpoly->mat_nr!=ob->actcol-1) {
 +                                      indexar[index]= 0;
 +                              }
 +                      }                                       
 +              }
        }
 +
 +      if((me->editflag & ME_EDIT_PAINT_MASK) && me->mpoly) {
 +              for(index=0; index<totindex; index++) {
 +                      if(indexar[index] && indexar[index]<=me->totpoly) {
 +                              MPoly *mpoly= ((MPoly *)me->mpoly) + (indexar[index]-1);
                                                
 +                              if((mpoly->flag & ME_FACE_SEL)==0)
 +                                      indexar[index]= 0;
 +                      }                                       
 +              }
 +      }
 +      
        swap_m4m4(vc->rv3d->persmat, mat);
  
        /* was disabled because it is slow, but necessary for blur */
        if(brush->vertexpaint_tool == VP_BLUR)
                do_shared_vertexcol(me);
                        
 -      ED_region_tag_redraw(vc->ar);
 +      for(index=0; index<totindex; index++) {
 +                              
 +              if(indexar[index] && indexar[index]<=me->totpoly) {
 +                      MPoly *mpoly= ((MPoly *)me->mpoly) + (indexar[index]-1);
 +                      MFace *mf;
 +                      MCol *mc;
 +                      MLoop *ml;
 +                      MLoopCol *mlc;
 +                      unsigned int *lcol = ((unsigned int*)me->mloopcol) + mpoly->loopstart;
 +                      unsigned int *lcolorig = ((unsigned int*)vp->vpaint_prev) + mpoly->loopstart;
 +                      float alpha;
 +                      int i, j;
 +                                      
 +                      if(brush->vertexpaint_tool==VP_BLUR) {
 +                              unsigned int blend[5] = {0};
 +                              char *col;
 +
 +                              for (j=0; j<mpoly->totloop; j += 2) {
 +                                      col = (char*)(lcol + j);
 +                                      blend[0] += col[0];
 +                                      blend[1] += col[1];
 +                                      blend[2] += col[2];
 +                                      blend[3] += col[3];
 +                              }
 +
 +                              blend[0] /= mpoly->totloop;
 +                              blend[1] /= mpoly->totloop;
 +                              blend[2] /= mpoly->totloop;
 +                              blend[3] /= mpoly->totloop;
 +                              col = (char*)(blend + 4);
 +                              col[0] = blend[0];
 +                              col[1] = blend[1];
 +                              col[2] = blend[2];
 +                              col[3] = blend[3];
 +
 +                              vpd->paintcol = *((unsigned int*)col);
 +                      }
 +
 +                      ml = me->mloop + mpoly->loopstart;
 +                      for (i=0; i<mpoly->totloop; i++, ml++) {
 +                              alpha= calc_vp_alpha_dl(vp, vc, vpd->vpimat, 
 +                                         vpd->vertexcosnos+6*ml->v, mval, pressure);
 +                              if(alpha > 0.0f) vpaint_blend(vp, lcol+i, lcolorig+i, vpd->paintcol, (int)(alpha*255.0f));
 +                      }
 +      
 +                      #ifdef CPYCOL
 +                      #undef CPYCOL
 +                      #endif
 +                      #define CPYCOL(c, l) (c)->a = (l)->a, (c)->r = (l)->r, (c)->g = (l)->g, (c)->b = (l)->b
 +
 +                      /*update vertex colors for tesselations incrementally,
 +                        rather then regenerating the tesselation altogether.*/
 +                      for (e=vpd->polyfacemap[(indexar[index]-1)].first; e; e=e->next) {
 +                              mf = me->mface + e->facenr;
 +                              mc = me->mcol + e->facenr*4;
 +                              
 +                              ml = me->mloop + mpoly->loopstart;
 +                              mlc = me->mloopcol + mpoly->loopstart;
 +                              for (j=0; j<mpoly->totloop; j++, ml++, mlc++) {
 +                                      if (ml->v == mf->v1)
 +                                              CPYCOL(mc, mlc);
 +                                      else if (ml->v == mf->v2)
 +                                              CPYCOL(mc+1, mlc);
 +                                      else if (ml->v == mf->v3)
 +                                              CPYCOL(mc+2, mlc);
 +                                      else if (mf->v4 && ml->v == mf->v4)
 +                                              CPYCOL(mc+3, mlc);
 +
 +                              }
 +                      }
 +                      #undef CPYCOL
 +              }
 +      }
 +              
 +      swap_m4m4(vc->rv3d->persmat, mat);
                        
 +      /* was disabled because it is slow, but necessary for blur */
 +      if(brush->vertexpaint_tool == VP_BLUR) {
 +              do_shared_vertexcol(me);
 +      }
 +
 +      ED_region_tag_redraw(vc->ar);           
        DAG_id_tag_update(ob->data, 0);
  }
  
@@@ -2680,8 -2453,7 +2687,8 @@@ static void vpaint_stroke_done(bContex
        
        /* frees prev buffer */
        copy_vpaint_prev(ts->vpaint, NULL, 0);
 -      
 +      BLI_memarena_free(vpd->arena);
 +
        MEM_freeN(vpd);
  }