diff options
Diffstat (limited to 'source/blender/editors/mesh/editface.c')
-rw-r--r-- | source/blender/editors/mesh/editface.c | 695 |
1 files changed, 290 insertions, 405 deletions
diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c index 9107b30d928..bec1403a8dd 100644 --- a/source/blender/editors/mesh/editface.c +++ b/source/blender/editors/mesh/editface.c @@ -34,12 +34,11 @@ #include "MEM_guardedalloc.h" +#include "BLI_utildefines.h" #include "BLI_blenlib.h" #include "BLI_math.h" -#include "BLI_heap.h" #include "BLI_edgehash.h" #include "BLI_editVert.h" -#include "BLI_utildefines.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" @@ -52,6 +51,7 @@ #include "BKE_global.h" #include "BKE_mesh.h" #include "BKE_context.h" +#include "BKE_tessmesh.h" #include "BIF_gl.h" @@ -69,42 +69,75 @@ * use in object mode when selecting faces (while painting) */ void paintface_flush_flags(Object *ob) { - Mesh *me= get_mesh(ob); - DerivedMesh *dm= ob->derivedFinal; - MFace *faces, *mf, *mf_orig; + Mesh *me = get_mesh(ob); + DerivedMesh *dm = ob->derivedFinal; + MPoly *polys, *mp_orig; + MFace *faces; int *index_array = NULL; - int totface; + int totface, totpoly; int i; if(me==NULL || dm==NULL) return; - index_array = dm->getFaceDataArray(dm, CD_ORIGINDEX); + /* + * Try to push updated mesh poly flags to three other data sets: + * - Mesh polys => Mesh tess faces + * - Mesh polys => Final derived polys + * - Final derived polys => Final derived tessfaces + */ - if(!index_array) - return; - - faces = dm->getFaceArray(dm); - totface = dm->getNumFaces(dm); - - mf= faces; - - for (i= 0; i<totface; i++, mf++) { /* loop over derived mesh faces */ - mf_orig= me->mface + index_array[i]; - mf->flag= mf_orig->flag; + if ((index_array = CustomData_get_layer(&me->fdata, CD_POLYINDEX))) { + faces = me->mface; + totface = me->totface; + + /* loop over tessfaces */ + for (i= 0; i<totface; i++) { + /* Copy flags onto the original tessface from its original poly */ + mp_orig = me->mpoly + 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->getNumPolys(dm); + + /* loop over final derived polys */ + for (i= 0; i<totpoly; i++) { + /* Copy flags onto the final derived poly from the original mesh poly */ + mp_orig = me->mpoly + index_array[i]; + polys[i].flag = mp_orig->flag; + } + } + + if ((index_array = CustomData_get_layer(&dm->faceData, CD_POLYINDEX))) { + polys = dm->getPolyArray(dm); + faces = dm->getTessFaceArray(dm);; + totface = dm->getNumTessFaces(dm); + + /* loop over tessfaces */ + for (i= 0; i<totface; i++) { + /* Copy flags onto the final tessface from its final poly */ + mp_orig = polys + index_array[i]; + faces[i].flag = mp_orig->flag; + } } } /* returns 0 if not found, otherwise 1 */ -static int facesel_face_pick(struct bContext *C, Mesh *me, const int mval[2], unsigned int *index, short rect) +static int facesel_face_pick(struct bContext *C, Mesh *me, Object *ob, const int mval[2], unsigned int *index, short rect) { + Scene *scene = CTX_data_scene(C); ViewContext vc; view3d_set_viewcontext(C, &vc); - if (!me || me->totface==0) + if (!me || me->totpoly==0) return 0; -// XXX if (v3d->flag & V3D_INVALID_BACKBUF) { + makeDerivedMesh(scene, ob, NULL, CD_MASK_BAREMESH, 0); + + // XXX if (v3d->flag & V3D_INVALID_BACKBUF) { // XXX drawview.c! check_backbuf(); // XXX persp(PERSP_VIEW); // XXX } @@ -114,14 +147,14 @@ static int facesel_face_pick(struct bContext *C, Mesh *me, const int mval[2], un on an edge in the backbuf, we can still select a face */ int dist; - *index = view3d_sample_backbuf_rect(&vc, mval, 3, 1, me->totface+1, &dist,0,NULL, NULL); + *index = view3d_sample_backbuf_rect(&vc, mval, 3, 1, me->totpoly+1, &dist,0,NULL, NULL); } else { /* sample only on the exact position */ *index = view3d_sample_backbuf(&vc, mval[0], mval[1]); } - if ((*index)<=0 || (*index)>(unsigned int)me->totface) + if ((*index)<=0 || (*index)>(unsigned int)me->totpoly) return 0; (*index)--; @@ -129,43 +162,17 @@ static int facesel_face_pick(struct bContext *C, Mesh *me, const int mval[2], un return 1; } -/* last_sel, use em->act_face otherwise get the last selected face in the editselections - * at the moment, last_sel is mainly useful for gaking sure the space image dosnt flicker */ -MTFace *EM_get_active_mtface(EditMesh *em, EditFace **act_efa, MCol **mcol, int sloppy) -{ - EditFace *efa = NULL; - - if(!EM_texFaceCheck(em)) - return NULL; - - efa = EM_get_actFace(em, sloppy); - - if (efa) { - if (mcol) { - if (CustomData_has_layer(&em->fdata, CD_MCOL)) - *mcol = CustomData_em_get(&em->fdata, efa->data, CD_MCOL); - else - *mcol = NULL; - } - if (act_efa) *act_efa = efa; - return CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); - } - if (act_efa) *act_efa= NULL; - if(mcol) *mcol = NULL; - return NULL; -} - void paintface_hide(Object *ob, const int unselected) { Mesh *me; - MFace *mface; + MPoly *mface; int a; me= get_mesh(ob); - if(me==NULL || me->totface==0) return; + if(me==NULL || me->totpoly==0) return; - mface= me->mface; - a= me->totface; + mface= me->mpoly; + a= me->totpoly; while(a--) { if((mface->flag & ME_HIDE) == 0) { if(unselected) { @@ -187,14 +194,14 @@ void paintface_hide(Object *ob, const int unselected) void paintface_reveal(Object *ob) { Mesh *me; - MFace *mface; + MPoly *mface; int a; me= get_mesh(ob); - if(me==NULL || me->totface==0) return; + if(me==NULL || me->totpoly==0) return; - mface= me->mface; - a= me->totface; + mface= me->mpoly; + a= me->totpoly; while(a--) { if(mface->flag & ME_HIDE) { mface->flag |= ME_FACE_SEL; @@ -208,30 +215,29 @@ void paintface_reveal(Object *ob) /* Set tface seams based on edge data, uses hash table to find seam edges. */ -static void hash_add_face(EdgeHash *ehash, MFace *mf) +static void hash_add_face(EdgeHash *ehash, MPoly *mp, MLoop *mloop) { - BLI_edgehash_insert(ehash, mf->v1, mf->v2, NULL); - BLI_edgehash_insert(ehash, mf->v2, mf->v3, NULL); - if(mf->v4) { - BLI_edgehash_insert(ehash, mf->v3, mf->v4, NULL); - BLI_edgehash_insert(ehash, mf->v4, mf->v1, NULL); + MLoop *ml; + int i; + + for (i=0, ml=mloop; i<mp->totloop; i++, ml++) { + BLI_edgehash_insert(ehash, ml->v, ME_POLY_LOOP_NEXT(mloop, mp, i)->v, NULL); } - else - BLI_edgehash_insert(ehash, mf->v3, mf->v1, NULL); } static void select_linked_tfaces_with_seams(int mode, Mesh *me, unsigned int index) { - MFace *mf; - int a, doit=1, mark=0; - char *linkflag; EdgeHash *ehash, *seamhash; + MPoly *mf; + MLoop *ml; MEdge *med; + char *linkflag; + int a, b, doit=1, mark=0; ehash= BLI_edgehash_new(); seamhash = BLI_edgehash_new(); - linkflag= MEM_callocN(sizeof(char)*me->totface, "linkflaguv"); + linkflag= MEM_callocN(sizeof(char)*me->totpoly, "linkflaguv"); for(med=me->medge, a=0; a < me->totedge; a++, med++) if(med->flag & ME_SEAM) @@ -239,17 +245,17 @@ static void select_linked_tfaces_with_seams(int mode, Mesh *me, unsigned int ind if (mode==0 || mode==1) { /* only put face under cursor in array */ - mf= ((MFace*)me->mface) + index; - hash_add_face(ehash, mf); + mf= ((MPoly*)me->mpoly) + index; + hash_add_face(ehash, mf, me->mloop + mf->loopstart); linkflag[index]= 1; } else { /* fill array by selection */ - mf= me->mface; - for(a=0; a<me->totface; a++, mf++) { + mf= me->mpoly; + for(a=0; a<me->totpoly; a++, mf++) { if(mf->flag & ME_HIDE); else if(mf->flag & ME_FACE_SEL) { - hash_add_face(ehash, mf); + hash_add_face(ehash, mf, me->mloop + mf->loopstart); linkflag[a]= 1; } } @@ -259,35 +265,26 @@ static void select_linked_tfaces_with_seams(int mode, Mesh *me, unsigned int ind doit= 0; /* expand selection */ - mf= me->mface; - for(a=0; a<me->totface; a++, mf++) { + mf= me->mpoly; + for(a=0; a<me->totpoly; a++, mf++) { if(mf->flag & ME_HIDE) continue; if(!linkflag[a]) { + MLoop *mnextl; mark= 0; - if(!BLI_edgehash_haskey(seamhash, mf->v1, mf->v2)) - if(BLI_edgehash_haskey(ehash, mf->v1, mf->v2)) - mark= 1; - if(!BLI_edgehash_haskey(seamhash, mf->v2, mf->v3)) - if(BLI_edgehash_haskey(ehash, mf->v2, mf->v3)) - mark= 1; - if(mf->v4) { - if(!BLI_edgehash_haskey(seamhash, mf->v3, mf->v4)) - if(BLI_edgehash_haskey(ehash, mf->v3, mf->v4)) - mark= 1; - if(!BLI_edgehash_haskey(seamhash, mf->v4, mf->v1)) - if(BLI_edgehash_haskey(ehash, mf->v4, mf->v1)) - mark= 1; + ml = me->mloop + mf->loopstart; + for (b=0; b<mf->totloop; b++, ml++) { + mnextl = b < mf->totloop-1 ? ml - 1 : me->mloop + mf->loopstart; + if (!BLI_edgehash_haskey(seamhash, ml->v, mnextl->v)) + if (!BLI_edgehash_haskey(ehash, ml->v, mnextl->v)) + mark = 1; } - else if(!BLI_edgehash_haskey(seamhash, mf->v3, mf->v1)) - if(BLI_edgehash_haskey(ehash, mf->v3, mf->v1)) - mark = 1; if(mark) { linkflag[a]= 1; - hash_add_face(ehash, mf); + hash_add_face(ehash, mf, me->mloop + mf->loopstart); doit= 1; } } @@ -299,24 +296,24 @@ static void select_linked_tfaces_with_seams(int mode, Mesh *me, unsigned int ind BLI_edgehash_free(seamhash, NULL); if(mode==0 || mode==2) { - for(a=0, mf=me->mface; a<me->totface; a++, mf++) + for(a=0, mf=me->mpoly; a<me->totpoly; a++, mf++) if(linkflag[a]) mf->flag |= ME_FACE_SEL; else mf->flag &= ~ME_FACE_SEL; } else if(mode==1) { - for(a=0, mf=me->mface; a<me->totface; a++, mf++) + for(a=0, mf=me->mpoly; a<me->totpoly; a++, mf++) if(linkflag[a] && (mf->flag & ME_FACE_SEL)) break; - if (a<me->totface) { - for(a=0, mf=me->mface; a<me->totface; a++, mf++) + if (a<me->totpoly) { + for(a=0, mf=me->mpoly; a<me->totpoly; a++, mf++) if(linkflag[a]) mf->flag &= ~ME_FACE_SEL; } else { - for(a=0, mf=me->mface; a<me->totface; a++, mf++) + for(a=0, mf=me->mpoly; a<me->totpoly; a++, mf++) if(linkflag[a]) mf->flag |= ME_FACE_SEL; } @@ -331,7 +328,7 @@ void paintface_select_linked(bContext *UNUSED(C), Object *ob, int UNUSED(mval[2] unsigned int index=0; me = get_mesh(ob); - if(me==NULL || me->totface==0) return; + if(me==NULL || me->totpoly==0) return; if (mode==0 || mode==1) { // XXX - Causes glitches, not sure why @@ -349,15 +346,15 @@ void paintface_select_linked(bContext *UNUSED(C), Object *ob, int UNUSED(mval[2] void paintface_deselect_all_visible(Object *ob, int action, short flush_flags) { Mesh *me; - MFace *mface; + MPoly *mface; int a; me= get_mesh(ob); if(me==NULL) return; if(action == SEL_INVERT) { - mface= me->mface; - a= me->totface; + mface= me->mpoly; + a= me->totpoly; while(a--) { if((mface->flag & ME_HIDE) == 0) { mface->flag ^= ME_FACE_SEL; @@ -369,8 +366,8 @@ void paintface_deselect_all_visible(Object *ob, int action, short flush_flags) if (action == SEL_TOGGLE) { action = SEL_SELECT; - mface= me->mface; - a= me->totface; + mface= me->mpoly; + a= me->totpoly; while(a--) { if((mface->flag & ME_HIDE) == 0 && mface->flag & ME_FACE_SEL) { action = SEL_DESELECT; @@ -380,8 +377,8 @@ void paintface_deselect_all_visible(Object *ob, int action, short flush_flags) } } - mface= me->mface; - a= me->totface; + mface= me->mpoly; + a= me->totpoly; while(a--) { if((mface->flag & ME_HIDE) == 0) { switch (action) { @@ -407,270 +404,65 @@ void paintface_deselect_all_visible(Object *ob, int action, short flush_flags) int paintface_minmax(Object *ob, float *min, float *max) { - Mesh *me= get_mesh(ob); - MFace *mf; - MVert *mv; - int a, ok=0; - float vec[3]; - - if(me==NULL) - return ok; - - mv= me->mvert; - mf= me->mface; - for (a=me->totface; a>0; a--, mf++) { - if ((mf->flag & ME_HIDE || !(mf->flag & ME_FACE_SEL)) == 0) { - int i= mf->v4 ? 3:2; - do { - mul_v3_m4v3(vec, ob->obmat, (mv + (*(&mf->v1 + i)))->co); - DO_MINMAX(vec, min, max); - } while (i--); - ok= 1; - } - } - return ok; -} - -/* ******************** edge loop shortest path ********************* */ - -#define ME_SEAM_DONE 2 /* reuse this flag */ - -static float edgetag_cut_cost(int e1, int e2, int vert) -{ - EditVert *v = EM_get_vert_for_index(vert); - EditEdge *eed1 = EM_get_edge_for_index(e1), *eed2 = EM_get_edge_for_index(e2); - EditVert *v1 = EM_get_vert_for_index( (eed1->v1->tmp.l == vert)? eed1->v2->tmp.l: eed1->v1->tmp.l ); - EditVert *v2 = EM_get_vert_for_index( (eed2->v1->tmp.l == vert)? eed2->v2->tmp.l: eed2->v1->tmp.l ); - float cost, d1[3], d2[3]; - - cost = len_v3v3(v1->co, v->co); - cost += len_v3v3(v->co, v2->co); - - sub_v3_v3v3(d1, v->co, v1->co); - sub_v3_v3v3(d2, v2->co, v->co); - - cost = cost + 0.5f*cost*(2.0f - fabsf(d1[0]*d2[0] + d1[1]*d2[1] + d1[2]*d2[2])); - - return cost; -} - -static void edgetag_add_adjacent(Heap *heap, int mednum, int vertnum, int *nedges, int *edges, int *prevedge, float *cost) -{ - int startadj, endadj = nedges[vertnum+1]; - - for (startadj = nedges[vertnum]; startadj < endadj; startadj++) { - int adjnum = edges[startadj]; - EditEdge *eedadj = EM_get_edge_for_index(adjnum); - float newcost; - - if (eedadj->f2 & ME_SEAM_DONE) - continue; - - newcost = cost[mednum] + edgetag_cut_cost(mednum, adjnum, vertnum); - - if (cost[adjnum] > newcost) { - cost[adjnum] = newcost; - prevedge[adjnum] = mednum; - BLI_heap_insert(heap, newcost, SET_INT_IN_POINTER(adjnum)); - } - } -} - -void edgetag_context_set(Scene *scene, EditEdge *eed, int val) -{ - - switch (scene->toolsettings->edge_mode) { - case EDGE_MODE_SELECT: - EM_select_edge(eed, val); - break; - case EDGE_MODE_TAG_SEAM: - if (val) {eed->seam = 255;} - else {eed->seam = 0;} - break; - case EDGE_MODE_TAG_SHARP: - if (val) {eed->sharp = 1;} - else {eed->sharp = 0;} - break; - case EDGE_MODE_TAG_CREASE: - if (val) {eed->crease = 1.0f;} - else {eed->crease = 0.0f;} - break; - case EDGE_MODE_TAG_BEVEL: - if (val) {eed->bweight = 1.0f;} - else {eed->bweight = 0.0f;} - break; - case EDGE_MODE_TAG_FREESTYLE: - if (val) {eed->freestyle = 1;} - else {eed->freestyle = 0;} - break; - } -} - -int edgetag_context_check(Scene *scene, EditEdge *eed) -{ - switch (scene->toolsettings->edge_mode) { - case EDGE_MODE_SELECT: - return (eed->f & SELECT) ? 1 : 0; - case EDGE_MODE_TAG_SEAM: - return eed->seam ? 1 : 0; - case EDGE_MODE_TAG_SHARP: - return eed->sharp ? 1 : 0; - case EDGE_MODE_TAG_CREASE: - return eed->crease ? 1 : 0; - case EDGE_MODE_TAG_BEVEL: - return eed->bweight ? 1 : 0; - case EDGE_MODE_TAG_FREESTYLE: - return eed->freestyle ? 1 : 0; - } - return 0; -} - + Mesh *me; + MPoly *mf; + MTexPoly *tf; + MLoop *ml; + MVert *mvert; + int a, b, ok=0; + float vec[3], bmat[3][3]; -int edgetag_shortest_path(Scene *scene, EditMesh *em, EditEdge *source, EditEdge *target) -{ - EditEdge *eed; - EditVert *ev; + me= get_mesh(ob); + if(!me || !me->mtpoly) return ok; - Heap *heap; - float *cost; - int a, totvert=0, totedge=0, *nedges, *edges, *prevedge, mednum = -1, nedgeswap = 0; - + copy_m3_m4(bmat, ob->obmat); - /* we need the vert */ - for (ev= em->verts.first, totvert=0; ev; ev= ev->next) { - ev->tmp.l = totvert; - totvert++; - } - - for (eed= em->edges.first; eed; eed = eed->next) { - eed->f2 = 0; - if (eed->h) { - eed->f2 |= ME_SEAM_DONE; - } - eed->tmp.l = totedge; - totedge++; - } - - /* alloc */ - nedges = MEM_callocN(sizeof(*nedges)*totvert+1, "SeamPathNEdges"); - edges = MEM_mallocN(sizeof(*edges)*totedge*2, "SeamPathEdges"); - prevedge = MEM_mallocN(sizeof(*prevedge)*totedge, "SeamPathPrevious"); - cost = MEM_mallocN(sizeof(*cost)*totedge, "SeamPathCost"); - - /* count edges, compute adjacent edges offsets and fill adjacent edges */ - for (eed= em->edges.first; eed; eed = eed->next) { - nedges[eed->v1->tmp.l+1]++; - nedges[eed->v2->tmp.l+1]++; - } - - for (a=1; a<totvert; a++) { - int newswap = nedges[a+1]; - nedges[a+1] = nedgeswap + nedges[a]; - nedgeswap = newswap; - } - nedges[0] = nedges[1] = 0; - - for (a=0, eed= em->edges.first; eed; a++, eed = eed->next) { - edges[nedges[eed->v1->tmp.l+1]++] = a; - edges[nedges[eed->v2->tmp.l+1]++] = a; - - cost[a] = 1e20f; - prevedge[a] = -1; - } - - /* regular dijkstra shortest path, but over edges instead of vertices */ - heap = BLI_heap_new(); - BLI_heap_insert(heap, 0.0f, SET_INT_IN_POINTER(source->tmp.l)); - cost[source->tmp.l] = 0.0f; - - EM_init_index_arrays(em, 1, 1, 0); - - - while (!BLI_heap_empty(heap)) { - mednum = GET_INT_FROM_POINTER(BLI_heap_popmin(heap)); - eed = EM_get_edge_for_index( mednum ); - - if (mednum == target->tmp.l) - break; - - if (eed->f2 & ME_SEAM_DONE) + mvert= me->mvert; + mf= me->mpoly; + tf= me->mtpoly; + for (a=me->totpoly; a>0; a--, mf++, tf++) { + if (mf->flag & ME_HIDE || !(mf->flag & ME_FACE_SEL)) continue; - eed->f2 |= ME_SEAM_DONE; - - edgetag_add_adjacent(heap, mednum, eed->v1->tmp.l, nedges, edges, prevedge, cost); - edgetag_add_adjacent(heap, mednum, eed->v2->tmp.l, nedges, edges, prevedge, cost); - } - - - MEM_freeN(nedges); - MEM_freeN(edges); - MEM_freeN(cost); - BLI_heap_free(heap, NULL); - - for (eed= em->edges.first; eed; eed = eed->next) { - eed->f2 &= ~ME_SEAM_DONE; - } - - if (mednum != target->tmp.l) { - MEM_freeN(prevedge); - EM_free_index_arrays(); - return 0; - } - - /* follow path back to source and mark as seam */ - if (mednum == target->tmp.l) { - short allseams = 1; + ml = me->mloop + mf->totloop; + for (b=0; b<mf->totloop; b++, ml++) { + copy_v3_v3(vec, (mvert[ml->v].co)); + mul_m3_v3(bmat, vec); + add_v3_v3v3(vec, vec, ob->obmat[3]); + DO_MINMAX(vec, min, max); + } - mednum = target->tmp.l; - do { - eed = EM_get_edge_for_index( mednum ); - if (!edgetag_context_check(scene, eed)) { - allseams = 0; - break; - } - mednum = prevedge[mednum]; - } while (mednum != source->tmp.l); - - mednum = target->tmp.l; - do { - eed = EM_get_edge_for_index( mednum ); - if (allseams) - edgetag_context_set(scene, eed, 0); - else - edgetag_context_set(scene, eed, 1); - mednum = prevedge[mednum]; - } while (mednum != -1); + ok= 1; } - MEM_freeN(prevedge); - EM_free_index_arrays(); - return 1; + return ok; } /* *************************************** */ #if 0 -static void seam_edgehash_insert_face(EdgeHash *ehash, MFace *mf) +static void seam_edgehash_insert_face(EdgeHash *ehash, MPoly *mf, MLoop *loopstart) { - BLI_edgehash_insert(ehash, mf->v1, mf->v2, NULL); - BLI_edgehash_insert(ehash, mf->v2, mf->v3, NULL); - if (mf->v4) { - BLI_edgehash_insert(ehash, mf->v3, mf->v4, NULL); - BLI_edgehash_insert(ehash, mf->v4, mf->v1, NULL); + MLoop *ml1, *ml2; + int a; + + for (a=0; a<mf->totloop; a++) { + ml1 = loopstart + a; + ml2 = loopstart + (a+1) % mf->totloop; + + BLI_edgehash_insert(ehash, ml1->v, ml2->v, NULL); } - else - BLI_edgehash_insert(ehash, mf->v3, mf->v1, NULL); } void seam_mark_clear_tface(Scene *scene, short mode) { Mesh *me; - MFace *mf; + MPoly *mf; + MLoop *ml1, *ml2; MEdge *med; - int a; + int a, b; me= get_mesh(OBACT); - if(me==0 || me->totface==0) return; + if(me==0 || me->totpoly==0) return; if (mode == 0) mode = pupmenu("Seams%t|Mark Border Seam %x1|Clear Seam %x2"); @@ -681,9 +473,9 @@ void seam_mark_clear_tface(Scene *scene, short mode) if (mode == 2) { EdgeHash *ehash = BLI_edgehash_new(); - for (a=0, mf=me->mface; a<me->totface; a++, mf++) + for (a=0, mf=me->mpoly; a<me->totpoly; a++, mf++) if (!(mf->flag & ME_HIDE) && (mf->flag & ME_FACE_SEL)) - seam_edgehash_insert_face(ehash, mf); + seam_edgehash_insert_face(ehash, mf, me->mloop + mf->loopstart); for (a=0, med=me->medge; a<me->totedge; a++, med++) if (BLI_edgehash_haskey(ehash, med->v1, med->v2)) @@ -696,11 +488,11 @@ void seam_mark_clear_tface(Scene *scene, short mode) EdgeHash *ehash1 = BLI_edgehash_new(); EdgeHash *ehash2 = BLI_edgehash_new(); - for (a=0, mf=me->mface; a<me->totface; a++, mf++) { + for (a=0, mf=me->mpoly; a<me->totpoly; a++, mf++) { if ((mf->flag & ME_HIDE) || !(mf->flag & ME_FACE_SEL)) - seam_edgehash_insert_face(ehash1, mf); + seam_edgehash_insert_face(ehash1, mf, me->mloop + mf->loopstart); else - seam_edgehash_insert_face(ehash2, mf); + seam_edgehash_insert_face(ehash2, mf, me->mloop + mf->loopstart); } for (a=0, med=me->medge; a<me->totedge; a++, med++) @@ -722,21 +514,24 @@ void seam_mark_clear_tface(Scene *scene, short mode) int paintface_mouse_select(struct bContext *C, Object *ob, const int mval[2], int extend) { Mesh *me; - MFace *mface, *msel; + MPoly *mface, *msel; unsigned int a, index; /* Get the face under the cursor */ me = get_mesh(ob); - if (!facesel_face_pick(C, me, mval, &index, 1)) + if (!facesel_face_pick(C, me, ob, mval, &index, 1)) return 0; - msel= (((MFace*)me->mface)+index); + if (index >= me->totpoly || index < 0) + return 0; + + msel= me->mpoly + index; if (msel->flag & ME_HIDE) return 0; /* clear flags */ - mface = me->mface; - a = me->totface; + mface = me->mpoly; + a = me->totpoly; if (!extend) { while (a--) { mface->flag &= ~ME_FACE_SEL; @@ -764,25 +559,34 @@ int paintface_mouse_select(struct bContext *C, Object *ob, const int mval[2], in int do_paintface_box_select(ViewContext *vc, rcti *rect, int select, int extend) { + Object *ob = vc->obact; Mesh *me; - MFace *mface; + MPoly *mface; struct ImBuf *ibuf; unsigned int *rt; - int a, index; char *selar; + int a, index; int sx= rect->xmax-rect->xmin+1; int sy= rect->ymax-rect->ymin+1; + + me= get_mesh(ob); - me= get_mesh(vc->obact); - - if(me==NULL || me->totface==0 || sx*sy <= 0) + if(me==NULL || me->totpoly==0 || sx*sy <= 0) return OPERATOR_CANCELLED; - selar= MEM_callocN(me->totface+1, "selar"); + selar= MEM_callocN(me->totpoly+1, "selar"); if (extend == 0 && select) paintface_deselect_all_visible(vc->obact, SEL_DESELECT, FALSE); + if (extend == 0 && select) { + mface= me->mpoly; + for(a=1; a<=me->totpoly; a++, mface++) { + if((mface->flag & ME_HIDE) == 0) + mface->flag &= ~ME_FACE_SEL; + } + } + view3d_validate_backbuf(vc); ibuf = IMB_allocImBuf(sx,sy,32,IB_rect); @@ -794,13 +598,13 @@ int do_paintface_box_select(ViewContext *vc, rcti *rect, int select, int extend) while(a--) { if(*rt) { index= WM_framebuffer_to_index(*rt); - if(index<=me->totface) selar[index]= 1; + if(index<=me->totpoly) selar[index]= 1; } rt++; } - mface= me->mface; - for(a=1; a<=me->totface; a++, mface++) { + mface= me->mpoly; + for(a=1; a<=me->totpoly; a++, mface++) { if(selar[a]) { if(mface->flag & ME_HIDE); else { @@ -823,6 +627,104 @@ int do_paintface_box_select(ViewContext *vc, rcti *rect, int select, int extend) } +/* (similar to void paintface_flush_flags(Object *ob)) + * copy the vertex flags, most importantly selection from the mesh to the final derived mesh, + * use in object mode when selecting vertices (while painting) */ +void paintvert_flush_flags(Object *ob) +{ + Mesh *me= get_mesh(ob); + DerivedMesh *dm= ob->derivedFinal; + MVert *dm_mvert, *dm_mv; + int *index_array = NULL; + int totvert; + int i; + + if(me==NULL || dm==NULL) + return; + + index_array = dm->getVertDataArray(dm, CD_ORIGINDEX); + + dm_mvert = dm->getVertArray(dm); + totvert = dm->getNumVerts(dm); + + dm_mv= dm_mvert; + + if(index_array) { + int orig_index; + for (i= 0; i<totvert; i++, dm_mv++) { + orig_index= index_array[i]; + if(orig_index != ORIGINDEX_NONE) { + dm_mv->flag= me->mvert[index_array[i]].flag; + } + } + } + else { + for (i= 0; i<totvert; i++, dm_mv++) { + dm_mv->flag= me->mvert[i].flag; + } + } +} +/* note: if the caller passes FALSE to flush_flags, then they will need to run paintvert_flush_flags(ob) themselves */ +void paintvert_deselect_all_visible(Object *ob, int action, short flush_flags) +{ + Mesh *me; + MVert *mvert; + int a; + + me= get_mesh(ob); + if(me==NULL) return; + + if(action == SEL_INVERT) { + mvert= me->mvert; + a= me->totvert; + while(a--) { + if((mvert->flag & ME_HIDE) == 0) { + mvert->flag ^= SELECT; + } + mvert++; + } + } + else { + if (action == SEL_TOGGLE) { + action = SEL_SELECT; + + mvert= me->mvert; + a= me->totvert; + while(a--) { + if((mvert->flag & ME_HIDE) == 0 && mvert->flag & SELECT) { + action = SEL_DESELECT; + break; + } + mvert++; + } + } + + mvert= me->mvert; + a= me->totvert; + while(a--) { + if((mvert->flag & ME_HIDE) == 0) { + switch (action) { + case SEL_SELECT: + mvert->flag |= SELECT; + break; + case SEL_DESELECT: + mvert->flag &= ~SELECT; + break; + case SEL_INVERT: + mvert->flag ^= SELECT; + break; + } + } + mvert++; + } + } + + if(flush_flags) { + paintvert_flush_flags(ob); + } +} + + /* ********************* MESH VERTEX MIRR TOPO LOOKUP *************** */ /* note, this is not the best place for the function to be but moved * here to for the purpose of syncing with bmesh */ @@ -853,9 +755,9 @@ int ED_mesh_mirrtopo_recalc_check(Mesh *me, const int ob_mode, MirrTopoStore_t * int totvert; int totedge; - if (me->edit_mesh) { - totvert = me->edit_mesh->totvert; - totedge = me->edit_mesh->totedge; + if (me->edit_btmesh) { + totvert = me->edit_btmesh->bm->totvert; + totedge = me->edit_btmesh->bm->totedge; } else { totvert = me->totvert; @@ -879,11 +781,11 @@ void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_to const short skip_em_vert_array_init) { MEdge *medge; - EditMesh *em = me->edit_mesh; - void **eve_tmp_back = NULL; /* some of the callers are using eve->tmp so restore after */ + BMEditMesh *em = me->edit_btmesh; /* editmode*/ - EditEdge *eed; + BMEdge *eed; + BMIter iter; int a, last; int totvert, totedge; @@ -901,13 +803,9 @@ void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_to mesh_topo_store->prev_ob_mode = ob_mode; if(em) { - EditVert *eve; - totvert = 0; - eve_tmp_back = MEM_mallocN(em->totvert * sizeof(void *), "TopoMirr"); - for(eve = em->verts.first; eve; eve = eve->next) { - eve_tmp_back[totvert]= eve->tmp.p; - eve->tmp.l = totvert++; - } + BM_mesh_elem_index_ensure(em->bm, BM_VERT); + + totvert = em->bm->totvert; } else { totvert = me->totvert; @@ -917,11 +815,11 @@ void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_to /* Initialize the vert-edge-user counts used to detect unique topology */ if(em) { - totedge = 0; + totedge = me->edit_btmesh->bm->totedge; - for(eed=em->edges.first; eed; eed = eed->next, totedge++) { - topo_hash[eed->v1->tmp.l]++; - topo_hash[eed->v2->tmp.l]++; + BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { + topo_hash[BM_elem_index_get(eed->v1)]++; + topo_hash[BM_elem_index_get(eed->v2)]++; } } else { @@ -940,9 +838,9 @@ void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_to /* use the number of edges per vert to give verts unique topology IDs */ if(em) { - for(eed=em->edges.first; eed; eed = eed->next) { - topo_hash[eed->v1->tmp.l] += topo_hash_prev[eed->v2->tmp.l]; - topo_hash[eed->v2->tmp.l] += topo_hash_prev[eed->v1->tmp.l]; + BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { + topo_hash[BM_elem_index_get(eed->v1)] += topo_hash_prev[BM_elem_index_get(eed->v2)]; + topo_hash[BM_elem_index_get(eed->v2)] += topo_hash_prev[BM_elem_index_get(eed->v1)]; } } else { @@ -976,19 +874,6 @@ void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_to memcpy(topo_hash_prev, topo_hash, sizeof(MirrTopoHash_t) * totvert); } - /* restore eve->tmp.* */ - if(eve_tmp_back) { - EditVert *eve; - totvert = 0; - for(eve = em->verts.first; eve; eve = eve->next) { - eve->tmp.p = eve_tmp_back[totvert++]; - } - - MEM_freeN(eve_tmp_back); - eve_tmp_back = NULL; - } - - /* Hash/Index pairs are needed for sorting to find index pairs */ topo_pairs = MEM_callocN( sizeof(MirrTopoVert_t) * totvert, "MirrTopoPairs"); @@ -997,7 +882,7 @@ void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_to if(em) { if (skip_em_vert_array_init == FALSE) { - EM_init_index_arrays(em, 1, 0, 0); + EDBM_init_index_arrays(em,1, 0, 0); } } @@ -1018,12 +903,12 @@ void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_to /* Get the pairs out of the sorted hashes, note, totvert+1 means we can use the previous 2, * but you cant ever access the last 'a' index of MirrTopoPairs */ for(a=2; a <= totvert; a++) { - /* printf("I %d %ld %d\n", (a-last), MirrTopoPairs[a ].hash, MirrTopoPairs[a ].vIndex ); */ + /* printf("I %d %ld %d\n", (a-last), MirrTopoPairs[a ].hash, MirrTopoPairs[a ].v_index ); */ if ((a==totvert) || (topo_pairs[a-1].hash != topo_pairs[a].hash)) { if (a-last==2) { if(em) { - index_lookup[topo_pairs[a-1].v_index] = (intptr_t)EM_get_vert_for_index(topo_pairs[a-2].v_index); - index_lookup[topo_pairs[a-2].v_index] = (intptr_t)EM_get_vert_for_index(topo_pairs[a-1].v_index); + index_lookup[topo_pairs[a-1].v_index] = (intptr_t)EDBM_get_vert_for_index(em, topo_pairs[a-2].v_index); + index_lookup[topo_pairs[a-2].v_index] = (intptr_t)EDBM_get_vert_for_index(em, topo_pairs[a-1].v_index); } else { index_lookup[topo_pairs[a-1].v_index] = topo_pairs[a-2].v_index; @@ -1035,7 +920,7 @@ void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_to } if(em) { if (skip_em_vert_array_init == FALSE) { - EM_free_index_arrays(); + EDBM_free_index_arrays(em); } } |