svn merge ^/trunk/blender/ -r41453:41458
authorCampbell Barton <ideasman42@gmail.com>
Wed, 2 Nov 2011 06:19:04 +0000 (06:19 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 2 Nov 2011 06:19:04 +0000 (06:19 +0000)
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/transform/transform.c
source/blender/makesdna/DNA_mesh_types.h

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)
 {
-       Mesh *me;
-       MFace *mface;
+       Mesh *me= ob->data;
+       MPoly *mf;
        MDeformWeight *dw, *uw;
-       int *indexar;
-       unsigned int index;
        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;
 
@@ -507,47 +486,47 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight)
        
        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;
                }
        }
-       
-       MEM_freeN(indexar);
+
        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];
 
-                               fidx= mf->totloop;
+                               fidx= mf->totloop - 1;
                                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;
-                                               unsigned int fidx= mf->totloop;
+                                               unsigned int fidx= mf->totloop - 1;
                                                int *groups= MEM_callocN(totgroup*sizeof(int), "groups");
                                                int found= FALSE;
 
index 72a07f1b3c9bc6491a4316c2baf4ba392d1018a0..42f28c9fb7cb2e2d49494976e62df524846d1ea9 100644 (file)
@@ -122,10 +122,22 @@ void setTransformViewMatrices(TransInfo *t)
        calculateCenter2D(t);
 }
 
+static void convertViewVec2D(View2D *v2d, float *vec, int dx, int dy)
+{
+       float divx, divy;
+       
+       divx= v2d->mask.xmax - v2d->mask.xmin;
+       divy= v2d->mask.ymax - v2d->mask.ymin;
+
+       vec[0]= (v2d->cur.xmax - v2d->cur.xmin) * dx / divx;
+       vec[1]= (v2d->cur.ymax - v2d->cur.ymin) * dy / divy;
+       vec[2]= 0.0f;
+}
+
 void convertViewVec(TransInfo *t, float *vec, int dx, int dy)
 {
-       if (t->spacetype==SPACE_VIEW3D) {
-               if (t->ar->regiontype == RGN_TYPE_WINDOW) {
+       if(t->spacetype==SPACE_VIEW3D) {
+               if(t->ar->regiontype == RGN_TYPE_WINDOW) {
                        float mval_f[2];
                        mval_f[0]= dx;
                        mval_f[1]= dy;
@@ -133,50 +145,19 @@ void convertViewVec(TransInfo *t, float *vec, int dx, int dy)
                }
        }
        else if(t->spacetype==SPACE_IMAGE) {
-               View2D *v2d = t->view;
-               float divx, divy, aspx, aspy;
-
-               ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
+               float aspx, aspy;
 
-               divx= v2d->mask.xmax-v2d->mask.xmin;
-               divy= v2d->mask.ymax-v2d->mask.ymin;
+               convertViewVec2D(t->view, vec, dx, dy);
 
-               vec[0]= aspx*(v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
-               vec[1]= aspy*(v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
-               vec[2]= 0.0f;
+               ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
+               vec[0]*= aspx;
+               vec[1]*= aspy;
        }
        else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
-               View2D *v2d = t->view;
-               float divx, divy;
-
-               divx= v2d->mask.xmax-v2d->mask.xmin;
-               divy= v2d->mask.ymax-v2d->mask.ymin;
-
-               vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx) / (divx);
-               vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy) / (divy);
-               vec[2]= 0.0f;
+               convertViewVec2D(t->view, vec, dx, dy);
        }
-       else if(t->spacetype==SPACE_NODE) {
-               View2D *v2d = &t->ar->v2d;
-               float divx, divy;
-
-               divx= v2d->mask.xmax-v2d->mask.xmin;
-               divy= v2d->mask.ymax-v2d->mask.ymin;
-
-               vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
-               vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
-               vec[2]= 0.0f;
-       }
-       else if(t->spacetype==SPACE_SEQ) {
-               View2D *v2d = &t->ar->v2d;
-               float divx, divy;
-
-               divx= v2d->mask.xmax-v2d->mask.xmin;
-               divy= v2d->mask.ymax-v2d->mask.ymin;
-
-               vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
-               vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
-               vec[2]= 0.0f;
+       else if(ELEM(t->spacetype, SPACE_NODE, SPACE_SEQ)) {
+               convertViewVec2D(&t->ar->v2d, vec, dx, dy);
        }
 }
 
index c38e8d02954385af5a1412730aa010bccaf349cb..125c18fa7c4d2146697966e15cc29cf7fa17b9ea 100644 (file)
@@ -142,6 +142,14 @@ typedef struct TFace {
 #define ME_EDIT_MIRROR_TOPO (1 << 4)
 #define ME_EDIT_VERT_SEL (1 << 5)
 
+/* we cant have both flags enabled at once,
+ * flags defined in DNA_scene_types.h */
+#define ME_EDIT_PAINT_SEL_MODE(_me)  (                                        \
+       (_me->editflag & ME_EDIT_PAINT_MASK) ? SCE_SELECT_FACE :                  \
+               (_me->editflag & ME_EDIT_VERT_SEL) ? SCE_SELECT_VERTEX :              \
+                       0                                                                 \
+       )
+
 /* me->flag */
 /* #define ME_ISDONE           1 */
 #define ME_DEPRECATED  2