svn merge ^/trunk/blender/ -r41453:41458
[blender.git] / source / blender / editors / sculpt_paint / paint_vertex.c
index 0e0b1ae2bf24c6a597d638b2a804878c5149d5c7..7599cf1117aca32a82486d75f58e34d9d9cf906f 100644 (file)
@@ -466,37 +466,16 @@ void vpaint_fill(Object *ob, unsigned int paintcol)
 /* fills in the selected faces with the current weight and vertex group */
 void wpaint_fill(VPaint *wp, Object *ob, float paintweight)
 {
 /* fills in the selected faces with the current weight and vertex group */
 void wpaint_fill(VPaint *wp, Object *ob, float paintweight)
 {
-       Mesh *me;
-       MFace *mface;
+       Mesh *me= ob->data;
+       MPoly *mf;
        MDeformWeight *dw, *uw;
        MDeformWeight *dw, *uw;
-       int *indexar;
-       unsigned int index;
        int vgroup, vgroup_mirror= -1;
        int vgroup, vgroup_mirror= -1;
-       int selected;
-       
-       int use_vert_sel;
-
-       me= ob->data;
-       if(me==NULL || me->totface==0 || me->dvert==NULL || !me->mface) return;
-       
-       selected= (me->editflag & ME_EDIT_PAINT_MASK);
-       
-       use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0;
+       unsigned int index;
 
 
-       indexar= get_indexarray(me);
+       /* mutually exclusive, could be made into a */
+       const short paint_selmode= ME_EDIT_PAINT_SEL_MODE(me);
 
 
-       if(selected) {
-               for(index=0, mface=me->mface; index<me->totface; index++, mface++) {
-                       if((mface->flag & ME_FACE_SEL)==0)
-                               indexar[index]= 0;
-                       else
-                               indexar[index]= index+1;
-               }
-       }
-       else {
-               for(index=0; index<me->totface; index++)
-                       indexar[index]= index+1;
-       }
+       if(me->totpoly==0 || me->dvert==NULL || !me->mpoly) return;
        
        vgroup= ob->actdef-1;
 
        
        vgroup= ob->actdef-1;
 
@@ -507,47 +486,47 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight)
        
        copy_wpaint_prev(wp, me->dvert, me->totvert);
        
        
        copy_wpaint_prev(wp, me->dvert, me->totvert);
        
-       for(index=0; index<me->totface; index++) {
-               if(indexar[index] && indexar[index]<=me->totface) {
-                       MFace *mf= &me->mface[indexar[index]-1];
-                       unsigned int fidx= mf->v4 ? 3:2;
+       for(index=0, mf= me->mpoly; index < me->totpoly; index++, mf++) {
+               unsigned int fidx= mf->totloop - 1;
 
 
-                       do {
-                               unsigned int vidx= *(&mf->v1 + fidx);
+               if ((paint_selmode == SCE_SELECT_FACE) && !(mf->flag & ME_FACE_SEL)) {
+                       continue;
+               }
 
 
-                               if(!me->dvert[vidx].flag) {
-                                       if(use_vert_sel && !(me->mvert[vidx].flag & SELECT)) {
-                                               continue;
-                                       }
+               do {
+                       unsigned int vidx= me->mloop[mf->loopstart + fidx].v;
 
 
-                                       dw= defvert_verify_index(&me->dvert[vidx], vgroup);
-                                       if(dw) {
-                                               uw= defvert_verify_index(wp->wpaint_prev+vidx, vgroup);
-                                               uw->weight= dw->weight; /* set the undo weight */
-                                               dw->weight= paintweight;
-
-                                               if(me->editflag & ME_EDIT_MIRROR_X) {   /* x mirror painting */
-                                                       int j= mesh_get_x_mirror_vert(ob, vidx);
-                                                       if(j>=0) {
-                                                               /* copy, not paint again */
-                                                               if(vgroup_mirror != -1) {
-                                                                       dw= defvert_verify_index(me->dvert+j, vgroup_mirror);
-                                                                       uw= defvert_verify_index(wp->wpaint_prev+j, vgroup_mirror);
-                                                               } else {
-                                                                       dw= defvert_verify_index(me->dvert+j, vgroup);
-                                                                       uw= defvert_verify_index(wp->wpaint_prev+j, vgroup);
-                                                               }
-                                                               uw->weight= dw->weight; /* set the undo weight */
-                                                               dw->weight= paintweight;
+                       if(!me->dvert[vidx].flag) {
+                               if((paint_selmode == SCE_SELECT_VERTEX) && !(me->mvert[vidx].flag & SELECT)) {
+                                       continue;
+                               }
+
+                               dw= defvert_verify_index(&me->dvert[vidx], vgroup);
+                               if(dw) {
+                                       uw= defvert_verify_index(wp->wpaint_prev+vidx, vgroup);
+                                       uw->weight= dw->weight; /* set the undo weight */
+                                       dw->weight= paintweight;
+
+                                       if(me->editflag & ME_EDIT_MIRROR_X) {   /* x mirror painting */
+                                               int j= mesh_get_x_mirror_vert(ob, vidx);
+                                               if(j>=0) {
+                                                       /* copy, not paint again */
+                                                       if(vgroup_mirror != -1) {
+                                                               dw= defvert_verify_index(me->dvert+j, vgroup_mirror);
+                                                               uw= defvert_verify_index(wp->wpaint_prev+j, vgroup_mirror);
+                                                       } else {
+                                                               dw= defvert_verify_index(me->dvert+j, vgroup);
+                                                               uw= defvert_verify_index(wp->wpaint_prev+j, vgroup);
                                                        }
                                                        }
+                                                       uw->weight= dw->weight; /* set the undo weight */
+                                                       dw->weight= paintweight;
                                                }
                                        }
                                                }
                                        }
-                                       me->dvert[vidx].flag= 1;
                                }
                                }
+                               me->dvert[vidx].flag= 1;
+                       }
 
 
-
-                       } while (fidx--);
-               }
+               } while (fidx--);
        }
 
        {
        }
 
        {
@@ -556,8 +535,7 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight)
                        dv->flag= 0;
                }
        }
                        dv->flag= 0;
                }
        }
-       
-       MEM_freeN(indexar);
+
        copy_wpaint_prev(wp, NULL, 0);
 
        DAG_id_tag_update(&me->id, 0);
        copy_wpaint_prev(wp, NULL, 0);
 
        DAG_id_tag_update(&me->id, 0);
@@ -1000,7 +978,7 @@ static int weight_sample_invoke(bContext *C, wmOperator *op, wmEvent *event)
                                mval_f[0]= (float)event->mval[0];
                                mval_f[1]= (float)event->mval[1];
 
                                mval_f[0]= (float)event->mval[0];
                                mval_f[1]= (float)event->mval[1];
 
-                               fidx= mf->totloop;
+                               fidx= mf->totloop - 1;
                                do {
                                        float co[3], sco[3], len;
                                        const int v_idx= me->mloop[mf->loopstart + fidx].v;
                                do {
                                        float co[3], sco[3], len;
                                        const int v_idx= me->mloop[mf->loopstart + fidx].v;
@@ -1070,7 +1048,7 @@ static EnumPropertyItem *weight_paint_sample_enum_itemf(bContext *C, PointerRNA
                                        const int totgroup= BLI_countlist(&vc.obact->defbase);
                                        if(totgroup) {
                                                MPoly *mf= ((MPoly *)me->mpoly) + index-1;
                                        const int totgroup= BLI_countlist(&vc.obact->defbase);
                                        if(totgroup) {
                                                MPoly *mf= ((MPoly *)me->mpoly) + index-1;
-                                               unsigned int fidx= mf->totloop;
+                                               unsigned int fidx= mf->totloop - 1;
                                                int *groups= MEM_callocN(totgroup*sizeof(int), "groups");
                                                int found= FALSE;
 
                                                int *groups= MEM_callocN(totgroup*sizeof(int), "groups");
                                                int found= FALSE;