From c4cb393e450bbd103fbb3d355af5d2286f92bd49 Mon Sep 17 00:00:00 2001 From: Andrew Wiggin Date: Fri, 14 Oct 2011 09:05:20 +0000 Subject: [PATCH] Fix vertex paint face selection --- source/blender/blenloader/intern/writefile.c | 1 + source/blender/bmesh/intern/bmesh_interp.c | 55 ++++++++++---------- source/blender/editors/mesh/editface.c | 50 +++++++++++++----- 3 files changed, 64 insertions(+), 42 deletions(-) diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 992bf05679b..18e7c0f2fa7 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -1667,6 +1667,7 @@ static void write_meshs(WriteData *wd, ListBase *idbase) write_customdata(wd, &mesh->id, mesh->pv->totvert, &mesh->vdata, -1, 0); write_customdata(wd, &mesh->id, mesh->pv->totedge, &mesh->edata, CD_MEDGE, mesh->totedge); + /* BMESH_TODO: probably need to deal with polys here */ write_customdata(wd, &mesh->id, mesh->pv->totface, &mesh->fdata, CD_MFACE, mesh->totface); } diff --git a/source/blender/bmesh/intern/bmesh_interp.c b/source/blender/bmesh/intern/bmesh_interp.c index 23a079b5c1a..e936616eed1 100644 --- a/source/blender/bmesh/intern/bmesh_interp.c +++ b/source/blender/bmesh/intern/bmesh_interp.c @@ -360,14 +360,13 @@ static int isect_point_quad_v2_d(double pt[2], double v1[2], double v2[2], doubl mdisps is a grid of displacements, ordered thus: -v1/center -- v4/next -> x -| | -| | -v2/prev ---- v3/cur -| -V - -y + v1/center----v4/next -> x + | | + | | + v2/prev------v3/cur + | + V + y */ static int compute_mdisp_quad(BMLoop *l, double v1[3], double v2[3], double v3[3], double v4[3], double e1[3], double e2[3]) @@ -611,15 +610,15 @@ void BM_multires_smooth_bounds(BMesh *bm, BMFace *f) /***** mdisps is a grid of displacements, ordered thus: - v4/next - | - | v1/cent-mid2 ---> x - | | | - | | | - v2/prev--mid1--v3/cur - | - V - y + v4/next + | + | v1/cent-----mid2 ---> x + | | | + | | | + v2/prev---mid1-----v3/cur + | + V + y *****/ sides = sqrt(mdp->totdisp); @@ -642,15 +641,15 @@ void BM_multires_smooth_bounds(BMesh *bm, BMFace *f) /***** mdisps is a grid of displacements, ordered thus: - v4/next - | - | v1/cent-mid2 ---> x - | | | - | | | - v2/prev--mid1--v3/cur - | - V - y + v4/next + | + | v1/cent-----mid2 ---> x + | | | + | | | + v2/prev---mid1-----v3/cur + | + V + y *****/ if (l->radial_next == l) @@ -737,8 +736,8 @@ void BM_loop_interp_from_face(BMesh *bm, BMLoop *target, BMFace *source, else if(yn>=xn && yn>=zn) {ax= 0; ay= 2;} else {ax= 1; ay= 2;} - /*scale source face coordinates a bit, so points sitting directonly on an - edge will work.*/ + /* scale source face coordinates a bit, so points sitting directonly on an + edge will work.*/ mul_v3_fl(cent, 1.0f/(float)source->len); for (i=0; ilen; i++) { float vec[3], tmp[3]; diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c index d7734867bbb..3b63262ae87 100644 --- a/source/blender/editors/mesh/editface.c +++ b/source/blender/editors/mesh/editface.c @@ -69,27 +69,49 @@ /* copy the face flags, most importantly selection from the mesh to the final derived mesh, * use in object mode when selecting faces (while painting) */ + void paintface_flush_flags(Object *ob) { - Mesh *me= get_mesh(ob); - DerivedMesh *dm= ob->derivedFinal; - MPoly *mf_orig, *mp; - int *index = NULL; - int totface; + Mesh *me = get_mesh(ob); + DerivedMesh *dm = ob->derivedFinal; + MPoly *polys, *mp_orig; + MFace *faces, *mf; + int *index_array = NULL; + int totface, totpoly; int i; - if(me==NULL || dm==NULL) + if (me==NULL || dm==NULL) { return; + } - totface = dm->getNumFaces(dm); - index = DM_get_face_data_layer(dm, CD_ORIGINDEX); - mp = dm->getPolyArray(dm); - for (i=0; inumPolyData; i++, index++, mp++) { - if (!index) - break; + /* + * Try to push updated mesh poly flags to two other data sets: + * - Mesh polys => Mesh tess faces + * - Mesh polys => Final derived mesh polys + */ - mf_orig = me->mpoly + *index; - mp->flag = mf_orig->flag; + if (index_array = CustomData_get_layer(&me->fdata, CD_ORIGINDEX)) { + faces = me->mface; + totface = me->totface; + + /* loop over tessfaces */ + for (i= 0; impoly + index_array[i]; + faces[i].flag = mp_orig->flag; + } + } + + if (index_array = CustomData_get_layer(&dm->polyData, CD_ORIGINDEX)) { + polys = dm->getPolyArray(dm); + totpoly = dm->getNumFaces(dm); + + /* loop over final derived polys */ + for (i= 0; impoly + index_array[i]; + polys[i].flag = mp_orig->flag; + } } }