svn merge ^/trunk/blender -r43381:43392
authorCampbell Barton <ideasman42@gmail.com>
Sun, 15 Jan 2012 10:33:41 +0000 (10:33 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 15 Jan 2012 10:33:41 +0000 (10:33 +0000)
1  2 
release/scripts/startup/bl_ui/space_view3d.py
source/blender/editors/mesh/mesh_ops.c
source/blender/editors/object/object_ops.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/sculpt_paint/sculpt.c
source/blender/makesrna/intern/rna_scene.c

index cdb82426473032a4d93ac364ecdc47e0f521bad1,c9a60236d0774df581fb8043bf62573bfb428850..ca16e8dfc7cdb9a7015e7c818460bf0f458f9617
@@@ -1818,13 -1762,12 +1843,12 @@@ static void do_weight_paint_vertex(/* v
                MDeformVert dv_copy= {NULL};
  
                oldw = dw->weight;
-               wpaint_blend(wp, dw, dw_prev, alpha, paintweight, wpi->do_flip, wpi->do_multipaint && wpi->defbase_tot_sel >1);
-               neww = dw->weight;
-               dw->weight = oldw;
+               neww = wpaint_blend(wp, dw->weight, dw_prev->weight, alpha, paintweight,
+                                   wpi->brush_alpha_value, wpi->do_flip, do_multipaint_totsel);
                
                /* setup multi-paint */
-               if(wpi->defbase_tot_sel > 1 && wpi->do_multipaint) {
+               if (do_multipaint_totsel) {
 -                      dv_copy.dw= MEM_dupallocN(dv->dw);
 +                      dv_copy.dw= BLI_cellalloc_dupalloc(dv->dw);
                        dv_copy.flag = dv->flag;
                        dv_copy.totweight = dv->totweight;
                        tdw = dw;
@@@ -2235,7 -2180,7 +2261,7 @@@ static void wpaint_stroke_update_step(b
        if(wp->flag & VP_AREA) {
                /* Ugly hack, to avoid drawing vertex index when getting the face index buffer - campbell */
                me->editflag &= ~ME_EDIT_VERT_SEL;
-               totindex= sample_backbuf_area(vc, indexar, me->totpoly, mval[0], mval[1], brush_size_final);
 -              totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], brush_size_pressure);
++              totindex= sample_backbuf_area(vc, indexar, me->totpoly, mval[0], mval[1], brush_size_pressure);
                me->editflag |= use_vert_sel ? ME_EDIT_VERT_SEL : 0;
        }
        else {
                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) {
+                       if (brush->vertexpaint_tool == PAINT_BLEND_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);
 -                                      const float fac = calc_vp_strength_dl(wp, vc, wpd->vertexcosnos+6*vidx, mval, brush_size_pressure);
 +                                              
 +                              ml = me->mloop + mpoly->loopstart;
 +                              for (i=0; i<mpoly->totloop; i++, ml++) {
-                                       const float fac = calc_vp_strength_dl(wp, vc, wpd->vertexcosnos+6*ml->v, mval, brush_size_final);
++                                      const float fac = calc_vp_strength_dl(wp, vc, wpd->vertexcosnos+6*ml->v, mval, brush_size_pressure);
                                        if (fac > 0.0f) {
 -                                              dw = dw_func(&me->dvert[vidx], wpi.vgroup_active);
 +                                              dw = dw_func(&me->dvert[ml->v], wpi.vgroup_active);
                                                paintweight += dw ? (dw->weight * fac) : 0.0f;
                                                totw += fac;
                                        }
        }
  
        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, brush_size_final, brush_alpha_final);
+                                                               mval, brush_size_pressure, brush_alpha_pressure);
                                        if(alpha) {
                                                do_weight_paint_vertex(wp, ob, &wpi, vidx, alpha, paintweight);
                                        }
@@@ -2629,10 -2535,9 +2655,10 @@@ static int vpaint_stroke_test_start(bCo
        return 1;
  }
  
 +#if 0
  static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob,
                                const unsigned int index, const float mval[2],
-                               const float brush_size_final, const float brush_alpha_final,
+                               const float brush_size_pressure, const float brush_alpha_pressure,
                                int UNUSED(flip))
  {
        ViewContext *vc = &vpd->vc;
@@@ -2687,14 -2594,12 +2717,16 @@@ static void vpaint_stroke_update_step(b
        float mval[2];
  
        const float pressure = RNA_float_get(itemptr, "pressure");
-       const float brush_size_final = brush_size(brush) * (brush_use_size_pressure(scene, brush) ? pressure : 1.0f);
-       const float brush_alpha_final = brush_alpha(brush) * (brush_use_alpha_pressure(scene, brush) ? pressure : 1.0f);
+       const float brush_size_pressure = brush_size(scene, brush) * (brush_use_size_pressure(scene, brush) ? pressure : 1.0f);
+       const float brush_alpha_pressure = brush_alpha(scene, brush) * (brush_use_alpha_pressure(scene, brush) ? pressure : 1.0f);
++      int brush_alpha_pressure_i = (int)(brush_alpha_pressure*255.0f);
 +
        RNA_float_get_array(itemptr, "mouse", mval);
        flip = RNA_boolean_get(itemptr, "pen_flip");
 -                      
 +
 +      (void)flip; /* BMESH_TODO */
 +
        view3d_operator_needs_opengl(C);
                        
        /* load projection matrix */
                        
        /* which faces are involved */
        if(vp->flag & VP_AREA) {
-               totindex= sample_backbuf_area(vc, indexar, me->totpoly, mval[0], mval[1], brush_size_final);
 -              totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], brush_size_pressure);
++              totindex= sample_backbuf_area(vc, indexar, me->totpoly, mval[0], mval[1], brush_size_pressure);
        }
        else {
                indexar[0]= view3d_sample_backbuf(vc, mval[0], mval[1]);
        swap_m4m4(vc->rv3d->persmat, mat);
  
        /* was disabled because it is slow, but necessary for blur */
-       if(brush->vertexpaint_tool == VP_BLUR)
+       if (brush->vertexpaint_tool == PAINT_BLEND_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) {
++                      if(brush->vertexpaint_tool == PAINT_BLEND_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,
-                                                       brush_size_final, brush_alpha_final);
-                               if(alpha > 0.0f) vpaint_blend(vp, lcol+i, lcolorig+i, vpd->paintcol, (int)(alpha*255.0f));
++                                                      brush_size_pressure, brush_alpha_pressure);
++                              if(alpha > 0.0f) {
++                                      const int alpha_i = (int)(alpha*255.0f);
++                                      lcol[i] = vpaint_blend(vp, lcol[i], lcolorig[i], vpd->paintcol, alpha_i, brush_alpha_pressure_i);
++                              }
 +                      }
 +      
 +                      #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);
                        
-       if(brush->vertexpaint_tool == VP_BLUR) {
 +      /* was disabled because it is slow, but necessary for blur */
++      if(brush->vertexpaint_tool == PAINT_BLEND_BLUR) {
 +              do_shared_vertexcol(me);
 +      }
 +
 +      ED_region_tag_redraw(vc->ar);           
        DAG_id_tag_update(ob->data, 0);
  }