diff options
Diffstat (limited to 'source/blender/editors/mesh')
-rw-r--r-- | source/blender/editors/mesh/editface.c | 304 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_add.c | 93 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_bvh.c | 4 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_knife.c | 43 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_loopcut.c | 42 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_select.c | 369 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_tools.c | 767 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_utils.c | 255 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_data.c | 351 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_intern.h | 38 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_navmesh.c | 297 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_ops.c | 42 | ||||
-rw-r--r-- | source/blender/editors/mesh/meshtools.c | 576 |
13 files changed, 1607 insertions, 1574 deletions
diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c index efa5ce0395c..d2446d1ad0e 100644 --- a/source/blender/editors/mesh/editface.c +++ b/source/blender/editors/mesh/editface.c @@ -27,8 +27,6 @@ * \ingroup edmesh */ - - #include <math.h> #include <string.h> @@ -77,7 +75,7 @@ void paintface_flush_flags(Object *ob) int totface, totpoly; int i; - if (me==NULL || dm==NULL) + if (me == NULL || dm == NULL) return; /* @@ -92,7 +90,7 @@ void paintface_flush_flags(Object *ob) totface = me->totface; /* loop over tessfaces */ - for (i= 0; i<totface; i++) { + 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; @@ -104,7 +102,7 @@ void paintface_flush_flags(Object *ob) totpoly = dm->getNumPolys(dm); /* loop over final derived polys */ - for (i= 0; i<totpoly; i++) { + 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; @@ -117,7 +115,7 @@ void paintface_flush_flags(Object *ob) totface = dm->getNumTessFaces(dm); /* loop over tessfaces */ - for (i= 0; i<totface; i++) { + 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; @@ -132,29 +130,29 @@ static int facesel_face_pick(struct bContext *C, Mesh *me, Object *ob, const int ViewContext vc; view3d_set_viewcontext(C, &vc); - if (!me || me->totpoly==0) + if (!me || me->totpoly == 0) return 0; makeDerivedMesh(scene, ob, NULL, CD_MASK_BAREMESH, 0); - // XXX if (v3d->flag & V3D_INVALID_BACKBUF) { + // XXX if (v3d->flag & V3D_INVALID_BACKBUF) { // XXX drawview.c! check_backbuf(); // XXX persp(PERSP_VIEW); -// XXX } +// XXX } if (rect) { /* sample rect to increase changes of selecting, so that when clicking * on an edge in the backbuf, we can still select a face */ int dist; - *index = view3d_sample_backbuf_rect(&vc, mval, 3, 1, me->totpoly+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->totpoly) + if ((*index) <= 0 || (*index) > (unsigned int)me->totpoly) return 0; (*index)--; @@ -168,15 +166,15 @@ void paintface_hide(Object *ob, const int unselected) MPoly *mface; int a; - me= get_mesh(ob); - if (me==NULL || me->totpoly==0) return; + me = get_mesh(ob); + if (me == NULL || me->totpoly == 0) return; - mface= me->mpoly; - a= me->totpoly; + mface = me->mpoly; + a = me->totpoly; while (a--) { if ((mface->flag & ME_HIDE) == 0) { if (unselected) { - if ( (mface->flag & ME_FACE_SEL)==0) mface->flag |= ME_HIDE; + if ( (mface->flag & ME_FACE_SEL) == 0) mface->flag |= ME_HIDE; } else { if ( (mface->flag & ME_FACE_SEL)) mface->flag |= ME_HIDE; @@ -197,11 +195,11 @@ void paintface_reveal(Object *ob) MPoly *mface; int a; - me= get_mesh(ob); - if (me==NULL || me->totpoly==0) return; + me = get_mesh(ob); + if (me == NULL || me->totpoly == 0) return; - mface= me->mpoly; - a= me->totpoly; + mface = me->mpoly; + a = me->totpoly; while (a--) { if (mface->flag & ME_HIDE) { mface->flag |= ME_FACE_SEL; @@ -220,7 +218,7 @@ static void hash_add_face(EdgeHash *ehash, MPoly *mp, MLoop *mloop) MLoop *ml; int i; - for (i=0, ml=mloop; i<mp->totloop; i++, ml++) { + 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); } } @@ -233,59 +231,59 @@ static void select_linked_tfaces_with_seams(int mode, Mesh *me, unsigned int ind MLoop *ml; MEdge *med; char *linkflag; - int a, b, doit=1, mark=0; + int a, b, doit = 1, mark = 0; - ehash= BLI_edgehash_new(); + ehash = BLI_edgehash_new(); seamhash = BLI_edgehash_new(); - linkflag= MEM_callocN(sizeof(char)*me->totpoly, "linkflaguv"); + linkflag = MEM_callocN(sizeof(char) * me->totpoly, "linkflaguv"); - for (med=me->medge, a=0; a < me->totedge; a++, med++) + for (med = me->medge, a = 0; a < me->totedge; a++, med++) if (med->flag & ME_SEAM) BLI_edgehash_insert(seamhash, med->v1, med->v2, NULL); - if (mode==0 || mode==1) { + if (mode == 0 || mode == 1) { /* only put face under cursor in array */ - mf= ((MPoly*)me->mpoly) + index; + mf = ((MPoly *)me->mpoly) + index; hash_add_face(ehash, mf, me->mloop + mf->loopstart); - linkflag[index]= 1; + linkflag[index] = 1; } else { /* fill array by selection */ - mf= me->mpoly; - for (a=0; a<me->totpoly; a++, mf++) { - if (mf->flag & ME_HIDE); + 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, me->mloop + mf->loopstart); - linkflag[a]= 1; + linkflag[a] = 1; } } } while (doit) { - doit= 0; + doit = 0; /* expand selection */ - mf= me->mpoly; - for (a=0; a<me->totpoly; 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; + mark = 0; ml = me->mloop + mf->loopstart; - for (b=0; b<mf->totloop; b++, ml++) { - mnextl = b < mf->totloop-1 ? ml - 1 : 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; } if (mark) { - linkflag[a]= 1; + linkflag[a] = 1; hash_add_face(ehash, mf, me->mloop + mf->loopstart); - doit= 1; + doit = 1; } } } @@ -295,25 +293,25 @@ static void select_linked_tfaces_with_seams(int mode, Mesh *me, unsigned int ind BLI_edgehash_free(ehash, NULL); BLI_edgehash_free(seamhash, NULL); - if (mode==0 || mode==2) { - for (a=0, mf=me->mpoly; a<me->totpoly; a++, mf++) + if (mode == 0 || mode == 2) { + 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->mpoly; a<me->totpoly; a++, mf++) + else if (mode == 1) { + for (a = 0, mf = me->mpoly; a < me->totpoly; a++, mf++) if (linkflag[a] && (mf->flag & ME_FACE_SEL)) break; - if (a<me->totpoly) { - for (a=0, mf=me->mpoly; a<me->totpoly; 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->mpoly; a<me->totpoly; a++, mf++) + for (a = 0, mf = me->mpoly; a < me->totpoly; a++, mf++) if (linkflag[a]) mf->flag |= ME_FACE_SEL; } @@ -325,12 +323,12 @@ static void select_linked_tfaces_with_seams(int mode, Mesh *me, unsigned int ind void paintface_select_linked(bContext *UNUSED(C), Object *ob, int UNUSED(mval[2]), int mode) { Mesh *me; - unsigned int index=0; + unsigned int index = 0; me = get_mesh(ob); - if (me==NULL || me->totpoly==0) return; + if (me == NULL || me->totpoly == 0) return; - if (mode==0 || mode==1) { + if (mode == 0 || mode == 1) { // XXX - Causes glitches, not sure why #if 0 if (!facesel_face_pick(C, me, mval, &index, 1)) @@ -349,12 +347,12 @@ void paintface_deselect_all_visible(Object *ob, int action, short flush_flags) MPoly *mface; int a; - me= get_mesh(ob); - if (me==NULL) return; + me = get_mesh(ob); + if (me == NULL) return; if (action == SEL_INVERT) { - mface= me->mpoly; - a= me->totpoly; + mface = me->mpoly; + a = me->totpoly; while (a--) { if ((mface->flag & ME_HIDE) == 0) { mface->flag ^= ME_FACE_SEL; @@ -366,8 +364,8 @@ void paintface_deselect_all_visible(Object *ob, int action, short flush_flags) if (action == SEL_TOGGLE) { action = SEL_SELECT; - mface= me->mpoly; - a= me->totpoly; + mface = me->mpoly; + a = me->totpoly; while (a--) { if ((mface->flag & ME_HIDE) == 0 && mface->flag & ME_FACE_SEL) { action = SEL_DESELECT; @@ -377,20 +375,20 @@ void paintface_deselect_all_visible(Object *ob, int action, short flush_flags) } } - mface= me->mpoly; - a= me->totpoly; + mface = me->mpoly; + a = me->totpoly; while (a--) { if ((mface->flag & ME_HIDE) == 0) { switch (action) { - case SEL_SELECT: - mface->flag |= ME_FACE_SEL; - break; - case SEL_DESELECT: - mface->flag &= ~ME_FACE_SEL; - break; - case SEL_INVERT: - mface->flag ^= ME_FACE_SEL; - break; + case SEL_SELECT: + mface->flag |= ME_FACE_SEL; + break; + case SEL_DESELECT: + mface->flag &= ~ME_FACE_SEL; + break; + case SEL_INVERT: + mface->flag ^= ME_FACE_SEL; + break; } } mface++; @@ -409,30 +407,30 @@ int paintface_minmax(Object *ob, float *min, float *max) MTexPoly *tf; MLoop *ml; MVert *mvert; - int a, b, ok=0; + int a, b, ok = 0; float vec[3], bmat[3][3]; - me= get_mesh(ob); + me = get_mesh(ob); if (!me || !me->mtpoly) return ok; copy_m3_m4(bmat, ob->obmat); - mvert= me->mvert; - mf= me->mpoly; - tf= me->mtpoly; - for (a=me->totpoly; a>0; a--, mf++, tf++) { + 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; ml = me->mloop + mf->totloop; - for (b=0; b<mf->totloop; b++, ml++) { + 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); } - ok= 1; + ok = 1; } return ok; @@ -445,9 +443,9 @@ static void seam_edgehash_insert_face(EdgeHash *ehash, MPoly *mf, MLoop *loopsta MLoop *ml1, *ml2; int a; - for (a=0; a<mf->totloop; a++) { + for (a = 0; a < mf->totloop; a++) { ml1 = loopstart + a; - ml2 = loopstart + (a+1) % mf->totloop; + ml2 = loopstart + (a + 1) % mf->totloop; BLI_edgehash_insert(ehash, ml1->v, ml2->v, NULL); } @@ -461,8 +459,8 @@ void seam_mark_clear_tface(Scene *scene, short mode) MEdge *med; int a, b; - me= get_mesh(OBACT); - if (me==0 || me->totpoly==0) return; + me = get_mesh(OBACT); + if (me == 0 || me->totpoly == 0) return; if (mode == 0) mode = pupmenu("Seams%t|Mark Border Seam %x1|Clear Seam %x2"); @@ -473,11 +471,11 @@ void seam_mark_clear_tface(Scene *scene, short mode) if (mode == 2) { EdgeHash *ehash = BLI_edgehash_new(); - for (a=0, mf=me->mpoly; a<me->totpoly; 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, me->mloop + mf->loopstart); - for (a=0, med=me->medge; a<me->totedge; a++, med++) + for (a = 0, med = me->medge; a < me->totedge; a++, med++) if (BLI_edgehash_haskey(ehash, med->v1, med->v2)) med->flag &= ~ME_SEAM; @@ -488,16 +486,16 @@ void seam_mark_clear_tface(Scene *scene, short mode) EdgeHash *ehash1 = BLI_edgehash_new(); EdgeHash *ehash2 = BLI_edgehash_new(); - for (a=0, mf=me->mpoly; a<me->totpoly; 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, me->mloop + mf->loopstart); else seam_edgehash_insert_face(ehash2, mf, me->mloop + mf->loopstart); } - for (a=0, med=me->medge; a<me->totedge; a++, med++) + for (a = 0, med = me->medge; a < me->totedge; a++, med++) if (BLI_edgehash_haskey(ehash1, med->v1, med->v2) && - BLI_edgehash_haskey(ehash2, med->v1, med->v2)) + BLI_edgehash_haskey(ehash2, med->v1, med->v2)) med->flag |= ME_SEAM; BLI_edgehash_free(ehash1, NULL); @@ -526,7 +524,7 @@ int paintface_mouse_select(struct bContext *C, Object *ob, const int mval[2], in if (index >= me->totpoly || index < 0) return 0; - msel= me->mpoly + index; + msel = me->mpoly + index; if (msel->flag & ME_HIDE) return 0; /* clear flags */ @@ -552,7 +550,7 @@ int paintface_mouse_select(struct bContext *C, Object *ob, const int mval[2], in /* image window redraw */ paintface_flush_flags(ob); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, ob->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob->data); ED_region_tag_redraw(CTX_wm_region(C)); // XXX - should redraw all 3D views return 1; } @@ -566,21 +564,21 @@ int do_paintface_box_select(ViewContext *vc, rcti *rect, int select, int extend) unsigned int *rt; char *selar; int a, index; - int sx= rect->xmax-rect->xmin+1; - int sy= rect->ymax-rect->ymin+1; + int sx = rect->xmax - rect->xmin + 1; + int sy = rect->ymax - rect->ymin + 1; - me= get_mesh(ob); + me = get_mesh(ob); - if (me==NULL || me->totpoly==0 || sx*sy <= 0) + if (me == NULL || me->totpoly == 0 || sx * sy <= 0) return OPERATOR_CANCELLED; - selar= MEM_callocN(me->totpoly+1, "selar"); + selar = MEM_callocN(me->totpoly + 1, "selar"); if (extend == 0 && select) { paintface_deselect_all_visible(vc->obact, SEL_DESELECT, FALSE); - mface= me->mpoly; - for (a=1; a<=me->totpoly; a++, mface++) { + mface = me->mpoly; + for (a = 1; a <= me->totpoly; a++, mface++) { if ((mface->flag & ME_HIDE) == 0) mface->flag &= ~ME_FACE_SEL; } @@ -588,24 +586,24 @@ int do_paintface_box_select(ViewContext *vc, rcti *rect, int select, int extend) view3d_validate_backbuf(vc); - ibuf = IMB_allocImBuf(sx,sy,32,IB_rect); + ibuf = IMB_allocImBuf(sx, sy, 32, IB_rect); rt = ibuf->rect; - glReadPixels(rect->xmin+vc->ar->winrct.xmin, rect->ymin+vc->ar->winrct.ymin, sx, sy, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); - if (ENDIAN_ORDER==B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf); + glReadPixels(rect->xmin + vc->ar->winrct.xmin, rect->ymin + vc->ar->winrct.ymin, sx, sy, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); + if (ENDIAN_ORDER == B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf); - a= sx*sy; + a = sx * sy; while (a--) { if (*rt) { - index= WM_framebuffer_to_index(*rt); - if (index<=me->totpoly) selar[index]= 1; + index = WM_framebuffer_to_index(*rt); + if (index <= me->totpoly) selar[index] = 1; } rt++; } - mface= me->mpoly; - for (a=1; a<=me->totpoly; a++, mface++) { + mface = me->mpoly; + for (a = 1; a <= me->totpoly; a++, mface++) { if (selar[a]) { - if (mface->flag & ME_HIDE); + if (mface->flag & ME_HIDE) ; else { if (select) mface->flag |= ME_FACE_SEL; else mface->flag &= ~ME_FACE_SEL; @@ -631,14 +629,14 @@ int do_paintface_box_select(ViewContext *vc, rcti *rect, int select, int extend) * use in object mode when selecting vertices (while painting) */ void paintvert_flush_flags(Object *ob) { - Mesh *me= get_mesh(ob); - DerivedMesh *dm= ob->derivedFinal; + 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) + if (me == NULL || dm == NULL) return; index_array = dm->getVertDataArray(dm, CD_ORIGINDEX); @@ -646,20 +644,20 @@ void paintvert_flush_flags(Object *ob) dm_mvert = dm->getVertArray(dm); totvert = dm->getNumVerts(dm); - dm_mv= dm_mvert; + dm_mv = dm_mvert; if (index_array) { int orig_index; - for (i= 0; i<totvert; i++, dm_mv++) { - orig_index= index_array[i]; + 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; + 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; + for (i = 0; i < totvert; i++, dm_mv++) { + dm_mv->flag = me->mvert[i].flag; } } } @@ -670,12 +668,12 @@ void paintvert_deselect_all_visible(Object *ob, int action, short flush_flags) MVert *mvert; int a; - me= get_mesh(ob); - if (me==NULL) return; + me = get_mesh(ob); + if (me == NULL) return; if (action == SEL_INVERT) { - mvert= me->mvert; - a= me->totvert; + mvert = me->mvert; + a = me->totvert; while (a--) { if ((mvert->flag & ME_HIDE) == 0) { mvert->flag ^= SELECT; @@ -687,8 +685,8 @@ void paintvert_deselect_all_visible(Object *ob, int action, short flush_flags) if (action == SEL_TOGGLE) { action = SEL_SELECT; - mvert= me->mvert; - a= me->totvert; + mvert = me->mvert; + a = me->totvert; while (a--) { if ((mvert->flag & ME_HIDE) == 0 && mvert->flag & SELECT) { action = SEL_DESELECT; @@ -698,20 +696,20 @@ void paintvert_deselect_all_visible(Object *ob, int action, short flush_flags) } } - mvert= me->mvert; - a= me->totvert; + 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; + case SEL_SELECT: + mvert->flag |= SELECT; + break; + case SEL_DESELECT: + mvert->flag &= ~SELECT; + break; + case SEL_INVERT: + mvert->flag ^= SELECT; + break; } } mvert++; @@ -731,21 +729,21 @@ void paintvert_deselect_all_visible(Object *ob, int action, short flush_flags) typedef int MirrTopoHash_t; typedef struct MirrTopoVert_t { - MirrTopoHash_t hash; - int v_index; + MirrTopoHash_t hash; + int v_index; } MirrTopoVert_t; static int mirrtopo_hash_sort(const void *l1, const void *l2) { - if ((MirrTopoHash_t)(intptr_t)l1 > (MirrTopoHash_t)(intptr_t)l2 ) return 1; - else if ((MirrTopoHash_t)(intptr_t)l1 < (MirrTopoHash_t)(intptr_t)l2 ) return -1; + if ((MirrTopoHash_t)(intptr_t)l1 > (MirrTopoHash_t)(intptr_t)l2) return 1; + else if ((MirrTopoHash_t)(intptr_t)l1 < (MirrTopoHash_t)(intptr_t)l2) return -1; return 0; } static int mirrtopo_vert_sort(const void *v1, const void *v2) { - if (((MirrTopoVert_t *)v1)->hash > ((MirrTopoVert_t *)v2)->hash ) return 1; - else if (((MirrTopoVert_t *)v1)->hash < ((MirrTopoVert_t *)v2)->hash ) return -1; + if (((MirrTopoVert_t *)v1)->hash > ((MirrTopoVert_t *)v2)->hash) return 1; + else if (((MirrTopoVert_t *)v1)->hash < ((MirrTopoVert_t *)v2)->hash) return -1; return 0; } @@ -763,10 +761,10 @@ int ED_mesh_mirrtopo_recalc_check(Mesh *me, const int ob_mode, MirrTopoStore_t * totedge = me->totedge; } - if ( (mesh_topo_store->index_lookup==NULL) || - (mesh_topo_store->prev_ob_mode != ob_mode) || - (totvert != mesh_topo_store->prev_vert_tot) || - (totedge != mesh_topo_store->prev_edge_tot)) + if ((mesh_topo_store->index_lookup == NULL) || + (mesh_topo_store->prev_ob_mode != ob_mode) || + (totvert != mesh_topo_store->prev_vert_tot) || + (totedge != mesh_topo_store->prev_edge_tot)) { return TRUE; } @@ -824,7 +822,7 @@ void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_to else { totedge = me->totedge; - for (a=0, medge=me->medge; a < me->totedge; a++, medge++) { + for (a = 0, medge = me->medge; a < me->totedge; a++, medge++) { topo_hash[medge->v1]++; topo_hash[medge->v2]++; } @@ -843,7 +841,7 @@ void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_to } } else { - for (a=0, medge=me->medge; a<me->totedge; a++, medge++) { + for (a = 0, medge = me->medge; a < me->totedge; a++, medge++) { /* This can make really big numbers, wrapping around here is fine */ topo_hash[medge->v1] += topo_hash_prev[medge->v2]; topo_hash[medge->v2] += topo_hash_prev[medge->v1]; @@ -855,8 +853,8 @@ void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_to qsort(topo_hash_prev, totvert, sizeof(MirrTopoHash_t), mirrtopo_hash_sort); tot_unique = 1; /* account for skiping the first value */ - for (a=1; a<totvert; a++) { - if (topo_hash_prev[a-1] != topo_hash_prev[a]) { + for (a = 1; a < totvert; a++) { + if (topo_hash_prev[a - 1] != topo_hash_prev[a]) { tot_unique++; } } @@ -874,19 +872,19 @@ void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_to } /* Hash/Index pairs are needed for sorting to find index pairs */ - topo_pairs = MEM_callocN( sizeof(MirrTopoVert_t) * totvert, "MirrTopoPairs"); + topo_pairs = MEM_callocN(sizeof(MirrTopoVert_t) * totvert, "MirrTopoPairs"); /* since we are looping through verts, initialize these values here too */ index_lookup = MEM_mallocN(totvert * sizeof(*index_lookup), "mesh_topo_lookup"); if (em) { if (skip_em_vert_array_init == FALSE) { - EDBM_init_index_arrays(em,1, 0, 0); + EDBM_index_arrays_init(em, 1, 0, 0); } } - for (a=0; a<totvert; a++) { + for (a = 0; a < totvert; a++) { topo_pairs[a].hash = topo_hash[a]; topo_pairs[a].v_index = a; @@ -901,17 +899,17 @@ 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++) { + for (a = 2; a <= totvert; a++) { /* 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 ((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)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); + index_lookup[topo_pairs[a - 1].v_index] = (intptr_t)EDBM_vert_at_index(em, topo_pairs[a - 2].v_index); + index_lookup[topo_pairs[a - 2].v_index] = (intptr_t)EDBM_vert_at_index(em, topo_pairs[a - 1].v_index); } else { - index_lookup[topo_pairs[a-1].v_index] = topo_pairs[a-2].v_index; - index_lookup[topo_pairs[a-2].v_index] = topo_pairs[a-1].v_index; + index_lookup[topo_pairs[a - 1].v_index] = topo_pairs[a - 2].v_index; + index_lookup[topo_pairs[a - 2].v_index] = topo_pairs[a - 1].v_index; } } last = a; @@ -919,7 +917,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) { - EDBM_free_index_arrays(em); + EDBM_index_arrays_free(em); } } diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c index d816d33c9df..c2a97b3ea70 100644 --- a/source/blender/editors/mesh/editmesh_add.c +++ b/source/blender/editors/mesh/editmesh_add.c @@ -51,6 +51,8 @@ #include "ED_screen.h" #include "ED_object.h" +#include "mesh_intern.h" + /* uses context to figure out transform for primitive */ /* returns standard diameter */ static float new_primitive_matrix(bContext *C, float *loc, float *rot, float primmat[][4]) @@ -95,38 +97,29 @@ static void make_prim_init(bContext *C, const char *idname, rename_id((ID *)obedit->data, idname); /* create editmode */ - ED_object_enter_editmode(C, EM_DO_UNDO|EM_IGNORE_LAYER); /* rare cases the active layer is messed up */ + ED_object_enter_editmode(C, EM_DO_UNDO | EM_IGNORE_LAYER); /* rare cases the active layer is messed up */ *state = 1; } - else { - DAG_id_tag_update(&obedit->id, OB_RECALC_DATA); - } - *dia *= new_primitive_matrix(C, loc, rot, mat); + *dia = new_primitive_matrix(C, loc, rot, mat); } static void make_prim_finish(bContext *C, int *state, int enter_editmode) { - Object *obedit; - Mesh *me; - BMEditMesh *em; - - obedit = CTX_data_edit_object(C); - me = obedit->data; - em = me->edit_btmesh; + Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = BMEdit_FromObject(obedit); /* Primitive has all verts selected, use vert select flush * to push this up to edges & faces. */ EDBM_selectmode_flush_ex(em, SCE_SELECT_VERTEX); - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); /* userdef */ if (*state && !enter_editmode) { ED_object_exit_editmode(C, EM_FREEDATA); /* adding EM_DO_UNDO messes up operator redo */ } - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit); + WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); } static int add_primitive_plane_exec(bContext *C, wmOperator *op) @@ -134,7 +127,7 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op) Object *obedit; Mesh *me; BMEditMesh *em; - float loc[3], rot[3], mat[4][4], dia = 1.0f; + float loc[3], rot[3], mat[4][4], dia; int enter_editmode; int state; unsigned int layer; @@ -146,15 +139,15 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op) me = obedit->data; em = me->edit_btmesh; - if (!EDBM_CallAndSelectOpf(em, op, "vertout", - "create_grid xsegments=%i ysegments=%i size=%f mat=%m4", 1, 1, dia, mat)) + if (!EDBM_op_call_and_selectf(em, op, "vertout", + "create_grid xsegments=%i ysegments=%i size=%f mat=%m4", 1, 1, dia, mat)) { return OPERATOR_CANCELLED; } make_prim_finish(C, &state, enter_editmode); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void MESH_OT_primitive_plane_add(wmOperatorType *ot) @@ -170,7 +163,7 @@ void MESH_OT_primitive_plane_add(wmOperatorType *ot) ot->poll = ED_operator_scene_editable; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; ED_object_add_generic_props(ot, TRUE); } @@ -192,7 +185,7 @@ static int add_primitive_cube_exec(bContext *C, wmOperator *op) me = obedit->data; em = me->edit_btmesh; - if (!EDBM_CallAndSelectOpf(em, op, "vertout", "create_cube mat=%m4 size=%f", mat, 2.0f)) { + if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_cube mat=%m4 size=%f", mat, dia * 2.0f)) { return OPERATOR_CANCELLED; } @@ -215,12 +208,12 @@ void MESH_OT_primitive_cube_add(wmOperatorType *ot) ot->poll = ED_operator_scene_editable; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; ED_object_add_generic_props(ot, TRUE); } -static const EnumPropertyItem fill_type_items[]= { +static const EnumPropertyItem fill_type_items[] = { {0, "NOTHING", 0, "Nothing", "Don't fill at all"}, {1, "NGON", 0, "Ngon", "Use ngons"}, {2, "TRIFAN", 0, "Triangle Fan", "Use triangle fans"}, @@ -246,10 +239,10 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op) me = obedit->data; em = me->edit_btmesh; - if (!EDBM_CallAndSelectOpf(em, op, "vertout", - "create_circle segments=%i diameter=%f cap_ends=%b cap_tris=%b mat=%m4", - RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius"), - cap_end, cap_tri, mat)) + if (!EDBM_op_call_and_selectf(em, op, "vertout", + "create_circle segments=%i diameter=%f cap_ends=%b cap_tris=%b mat=%m4", + RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius"), + cap_end, cap_tri, mat)) { return OPERATOR_CANCELLED; } @@ -274,7 +267,7 @@ void MESH_OT_primitive_circle_add(wmOperatorType *ot) ot->poll = ED_operator_scene_editable; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ RNA_def_int(ot->srna, "vertices", 32, 3, INT_MAX, "Vertices", "", 3, 500); @@ -305,7 +298,7 @@ static int add_primitive_cylinder_exec(bContext *C, wmOperator *op) me = obedit->data; em = me->edit_btmesh; - if (!EDBM_CallAndSelectOpf( + if (!EDBM_op_call_and_selectf( em, op, "vertout", "create_cone segments=%i diameter1=%f diameter2=%f cap_ends=%b cap_tris=%b depth=%f mat=%m4", RNA_int_get(op->ptr, "vertices"), @@ -337,10 +330,10 @@ void MESH_OT_primitive_cylinder_add(wmOperatorType *ot) ot->poll = ED_operator_scene_editable; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ - RNA_def_int(ot->srna, "vertices", 32, 2, INT_MAX, "Vertices", "", 2, 500); + RNA_def_int(ot->srna, "vertices", 32, 3, INT_MAX, "Vertices", "", 3, 500); prop = RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00); RNA_def_property_subtype(prop, PROP_DISTANCE); prop = RNA_def_float(ot->srna, "depth", 2.0f, 0.0, FLT_MAX, "Depth", "", 0.001, 100.00); @@ -370,7 +363,7 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op) me = obedit->data; em = me->edit_btmesh; - if (!EDBM_CallAndSelectOpf( + if (!EDBM_op_call_and_selectf( em, op, "vertout", "create_cone segments=%i diameter1=%f diameter2=%f cap_ends=%b cap_tris=%b depth=%f mat=%m4", RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius1"), @@ -399,10 +392,10 @@ void MESH_OT_primitive_cone_add(wmOperatorType *ot) ot->poll = ED_operator_scene_editable; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ - RNA_def_int(ot->srna, "vertices", 32, 2, INT_MAX, "Vertices", "", 2, 500); + RNA_def_int(ot->srna, "vertices", 32, 3, INT_MAX, "Vertices", "", 3, 500); prop = RNA_def_float(ot->srna, "radius1", 1.0f, 0.0, FLT_MAX, "Radius 1", "", 0.001, 100.00); RNA_def_property_subtype(prop, PROP_DISTANCE); prop = RNA_def_float(ot->srna, "radius2", 0.0f, 0.0, FLT_MAX, "Radius 2", "", 0.001, 100.00); @@ -419,7 +412,7 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op) Object *obedit; Mesh *me; BMEditMesh *em; - float loc[3], rot[3], mat[4][4], dia = 1.0f; + float loc[3], rot[3], mat[4][4], dia; int enter_editmode; int state; unsigned int layer; @@ -431,11 +424,11 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op) me = obedit->data; em = me->edit_btmesh; - if (!EDBM_CallAndSelectOpf(em, op, "vertout", - "create_grid xsegments=%i ysegments=%i size=%f mat=%m4", - RNA_int_get(op->ptr, "x_subdivisions"), - RNA_int_get(op->ptr, "y_subdivisions"), - RNA_float_get(op->ptr, "size") * dia, mat)) + if (!EDBM_op_call_and_selectf(em, op, "vertout", + "create_grid xsegments=%i ysegments=%i size=%f mat=%m4", + RNA_int_get(op->ptr, "x_subdivisions"), + RNA_int_get(op->ptr, "y_subdivisions"), + RNA_float_get(op->ptr, "size") * dia, mat)) { return OPERATOR_CANCELLED; } @@ -459,7 +452,7 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot) ot->poll = ED_operator_scene_editable; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ RNA_def_int(ot->srna, "x_subdivisions", 10, 3, INT_MAX, "X Subdivisions", "", 3, 1000); @@ -490,7 +483,7 @@ static int add_primitive_monkey_exec(bContext *C, wmOperator *op) me = obedit->data; em = me->edit_btmesh; - if (!EDBM_CallAndSelectOpf(em, op, "vertout", "create_monkey mat=%m4", mat)) { + if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_monkey mat=%m4", mat)) { return OPERATOR_CANCELLED; } @@ -511,7 +504,7 @@ void MESH_OT_primitive_monkey_add(wmOperatorType *ot) ot->poll = ED_operator_scene_editable; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; ED_object_add_generic_props(ot, TRUE); } @@ -533,10 +526,10 @@ static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op) me = obedit->data; em = me->edit_btmesh; - if (!EDBM_CallAndSelectOpf(em, op, "vertout", - "create_uvsphere segments=%i revolutions=%i diameter=%f mat=%m4", - RNA_int_get(op->ptr, "segments"), RNA_int_get(op->ptr, "ring_count"), - RNA_float_get(op->ptr, "size"), mat)) + if (!EDBM_op_call_and_selectf(em, op, "vertout", + "create_uvsphere segments=%i revolutions=%i diameter=%f mat=%m4", + RNA_int_get(op->ptr, "segments"), RNA_int_get(op->ptr, "ring_count"), + RNA_float_get(op->ptr, "size"), mat)) { return OPERATOR_CANCELLED; } @@ -561,7 +554,7 @@ void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot) ot->poll = ED_operator_scene_editable; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ RNA_def_int(ot->srna, "segments", 32, 3, INT_MAX, "Segments", "", 3, 500); @@ -589,7 +582,7 @@ static int add_primitive_icosphere_exec(bContext *C, wmOperator *op) me = obedit->data; em = me->edit_btmesh; - if (!EDBM_CallAndSelectOpf( + if (!EDBM_op_call_and_selectf( em, op, "vertout", "create_icosphere subdivisions=%i diameter=%f mat=%m4", RNA_int_get(op->ptr, "subdivisions"), @@ -618,7 +611,7 @@ void MESH_OT_primitive_ico_sphere_add(wmOperatorType *ot) ot->poll = ED_operator_scene_editable; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ RNA_def_int(ot->srna, "subdivisions", 2, 1, INT_MAX, "Subdivisions", "", 1, 8); diff --git a/source/blender/editors/mesh/editmesh_bvh.c b/source/blender/editors/mesh/editmesh_bvh.c index 6571af11af5..37c4897cede 100644 --- a/source/blender/editors/mesh/editmesh_bvh.c +++ b/source/blender/editors/mesh/editmesh_bvh.c @@ -70,7 +70,7 @@ typedef struct BMBVHTree { } BMBVHTree; static void cage_mapped_verts_callback(void *userData, int index, float *co, - float *UNUSED(no_f), short *UNUSED(no_s)) + float *UNUSED(no_f), short *UNUSED(no_s)) { void **data = userData; BMEditMesh *em = data[0]; @@ -166,7 +166,7 @@ void BMBVH_FreeBVH(BMBVHTree *tree) /* taken from bvhutils.c */ static float ray_tri_intersection(const BVHTreeRay *ray, const float UNUSED(m_dist), float *v0, - float *v1, float *v2, float *uv, float UNUSED(e)) + float *v1, float *v2, float *uv, float UNUSED(e)) { float dist; diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index f6367779251..0ef6e2b81a8 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -65,7 +65,7 @@ /* this code here is kindof messy. . .I might need to eventually rework it - joeedh */ -#define KMAXDIST 10 /* max mouse distance from edge before not detecting it */ +#define KMAXDIST 10 /* max mouse distance from edge before not detecting it */ /* knifetool operator */ typedef struct KnifeVert { @@ -118,8 +118,8 @@ typedef struct KnifePosData { /* struct for properties used while drawing */ typedef struct knifetool_opdata { - ARegion *ar; /* region that knifetool was activated in */ - void *draw_handle; /* for drawing preview loop */ + ARegion *ar; /* region that knifetool was activated in */ + void *draw_handle; /* for drawing preview loop */ ViewContext vc; bContext *C; @@ -1013,7 +1013,7 @@ static BMEdgeHit *knife_edge_tri_isect(knifetool_opdata *kcd, BMBVHTree *bmtree, /* for comparing distances, error of intersection depends on triangle scale. * need to scale down before squaring for accurate comparison */ - const float depsilon = 50 * FLT_EPSILON * len_v3_tri_side_max(v1, v2, v3); + const float depsilon = 50 * FLT_EPSILON *len_v3_tri_side_max(v1, v2, v3); const float depsilon_squared = depsilon * depsilon; copy_v3_v3(cos + 0, v1); @@ -1269,7 +1269,7 @@ static BMFace *knife_find_closest_face(knifetool_opdata *kcd, float co[3], float if (!f) { /* try to use backbuffer selection method if ray casting failed */ - f = EDBM_findnearestface(&kcd->vc, &dist); + f = EDBM_face_find_nearest(&kcd->vc, &dist); /* cheat for now; just put in the origin instead * of a true coordinate on the face. @@ -1435,7 +1435,7 @@ static KnifeEdge *knife_find_closest_edge(knifetool_opdata *kcd, float p[3], flo /* find a vertex near the mouse cursor, if it exists */ static KnifeVert *knife_find_closest_vert(knifetool_opdata *kcd, float p[3], float cagep[3], BMFace **fptr, - int *is_space) + int *is_space) { BMFace *f; float co[3], cageco[3], sco[3], maxdist = knife_snap_size(kcd, kcd->vthresh); @@ -1580,13 +1580,13 @@ static int knife_update_active(knifetool_opdata *kcd) return 1; } -#define MARK 4 -#define DEL 8 -#define VERT_ON_EDGE 16 -#define VERT_ORIG 32 -#define FACE_FLIP 64 -#define BOUNDARY 128 -#define FACE_NEW 256 +#define MARK 4 +#define DEL 8 +#define VERT_ON_EDGE 16 +#define VERT_ORIG 32 +#define FACE_FLIP 64 +#define BOUNDARY 128 +#define FACE_NEW 256 #define SCANFILL_CUTS 0 #if SCANFILL_CUTS @@ -1849,7 +1849,7 @@ static void knifenet_fill_faces(knifetool_opdata *kcd) ScanFillEdge *eed; eed = BLI_addfilledge(lasteve, eve); if (entry->kfe->oe) - eed->f = FILLBOUNDARY; /* mark as original boundary edge */ + eed->f = FILLBOUNDARY; /* mark as original boundary edge */ BMO_elem_flag_disable(bm, entry->kfe->e->v1, DEL); BMO_elem_flag_disable(bm, entry->kfe->e->v2, DEL); @@ -2023,7 +2023,7 @@ static int find_chain_search(knifetool_opdata *kcd, KnifeVert *kfv, ListBase *fe return FALSE; } -static ListBase * find_chain_from_vertex(knifetool_opdata *kcd, KnifeEdge *kfe, BMVert *v, ListBase *fedges) +static ListBase *find_chain_from_vertex(knifetool_opdata *kcd, KnifeEdge *kfe, BMVert *v, ListBase *fedges) { SmallHash visited_, *visited = &visited_; ListBase *ans; @@ -2053,7 +2053,7 @@ static ListBase * find_chain_from_vertex(knifetool_opdata *kcd, KnifeEdge *kfe, /* Find a chain in fedges from one instantiated vertex to another. * Remove the edges in the chain from fedges and return a separate list of the chain. */ -static ListBase * find_chain(knifetool_opdata *kcd, ListBase *fedges) +static ListBase *find_chain(knifetool_opdata *kcd, ListBase *fedges) { Ref *r, *ref; KnifeEdge *kfe; @@ -2549,7 +2549,7 @@ static void knife_make_cuts(knifetool_opdata *kcd) BLI_mempool_iternew(kcd->kverts, &iter); for (kfv = BLI_mempool_iterstep(&iter); kfv; kfv = BLI_mempool_iterstep(&iter)) { if (kfv->v) - continue; /* already have a BMVert */ + continue; /* already have a BMVert */ for (ref = kfv->edges.first; ref; ref = ref->next) { kfe = ref->ref; e = kfe->e; @@ -2568,7 +2568,8 @@ static void knife_make_cuts(knifetool_opdata *kcd) /* split bmesh edges where needed */ for (lst = BLI_smallhash_iternew(ehash, &hiter, (uintptr_t *)&e); lst; - lst = BLI_smallhash_iternext(&hiter, (uintptr_t *)&e)) { + lst = BLI_smallhash_iternext(&hiter, (uintptr_t *)&e)) + { sort_by_frac_along(lst, e); for (ref = lst->first; ref; ref = ref->next) { kfv = ref->ref; @@ -2579,7 +2580,8 @@ static void knife_make_cuts(knifetool_opdata *kcd) /* do cuts for each face */ for (lst = BLI_smallhash_iternew(fhash, &hiter, (uintptr_t *)&f); lst; - lst = BLI_smallhash_iternext(&hiter, (uintptr_t *)&f)) { + lst = BLI_smallhash_iternext(&hiter, (uintptr_t *)&f)) + { knife_make_face_cuts(kcd, f, lst); } @@ -2599,8 +2601,7 @@ static void knifetool_finish(bContext *C, wmOperator *op) knife_make_cuts(kcd); #endif - DAG_id_tag_update(kcd->ob->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM | ND_DATA, kcd->ob->data); + EDBM_update_generic(C, kcd->em, TRUE); } /* copied from paint_image.c */ diff --git a/source/blender/editors/mesh/editmesh_loopcut.c b/source/blender/editors/mesh/editmesh_loopcut.c index b409ee16e25..638eaabbfd3 100644 --- a/source/blender/editors/mesh/editmesh_loopcut.c +++ b/source/blender/editors/mesh/editmesh_loopcut.c @@ -87,8 +87,8 @@ /* struct for properties used while drawing */ typedef struct tringselOpData { - ARegion *ar; /* region that ringsel was activated in */ - void *draw_handle; /* for drawing preview loop */ + ARegion *ar; /* region that ringsel was activated in */ + void *draw_handle; /* for drawing preview loop */ float (*edges)[2][3]; int totedge; @@ -205,7 +205,8 @@ static void edgering_sel(tringselOpData *lcd, int previewlines, int select) if (select) { BMW_init(&walker, em->bm, BMW_EDGERING, - BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, + BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, + BMW_FLAG_NOP, /* BMESH_TODO - should be BMW_FLAG_TEST_HIDDEN ? */ BMW_NIL_LAY); eed = BMW_begin(&walker, startedge); @@ -218,7 +219,8 @@ static void edgering_sel(tringselOpData *lcd, int previewlines, int select) } BMW_init(&walker, em->bm, BMW_EDGERING, - BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, + BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, + BMW_FLAG_NOP, /* BMESH_TODO - should be BMW_FLAG_TEST_HIDDEN ? */ BMW_NIL_LAY); eed = startedge = BMW_begin(&walker, startedge); @@ -322,24 +324,24 @@ static void ringsel_finish(bContext *C, wmOperator *op) CTX_data_tool_settings(C)->selectmode = em->selectmode; EDBM_selectmode_set(em); - WM_event_add_notifier(C, NC_SCENE|ND_TOOLSETTINGS, CTX_data_scene(C)); + WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, CTX_data_scene(C)); - WM_event_add_notifier(C, NC_SCENE|ND_TOOLSETTINGS, CTX_data_scene(C)); + WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, CTX_data_scene(C)); } - WM_event_add_notifier(C, NC_GEOM|ND_SELECT|ND_DATA, lcd->ob->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT | ND_DATA, lcd->ob->data); DAG_id_tag_update(lcd->ob->data, 0); } else { /* sets as active, useful for other tools */ if (em->selectmode & SCE_SELECT_VERTEX) - EDBM_store_selection(em, lcd->eed->v1); /* low priority TODO, get vertrex close to mouse */ + EDBM_editselection_store(em, &lcd->eed->v1->head); /* low priority TODO, get vertrex close to mouse */ if (em->selectmode & SCE_SELECT_EDGE) - EDBM_store_selection(em, lcd->eed); + EDBM_editselection_store(em, &lcd->eed->head); EDBM_selectmode_flush(lcd->em); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, lcd->ob->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, lcd->ob->data); } } } @@ -363,7 +365,7 @@ static void ringsel_exit(bContext *UNUSED(C), wmOperator *op) } /* called when modal loop selection gets set up... */ -static int ringsel_init (bContext *C, wmOperator *op, int do_cut) +static int ringsel_init(bContext *C, wmOperator *op, int do_cut) { tringselOpData *lcd; @@ -389,14 +391,14 @@ static int ringsel_init (bContext *C, wmOperator *op, int do_cut) return 1; } -static int ringcut_cancel (bContext *C, wmOperator *op) +static int ringcut_cancel(bContext *C, wmOperator *op) { /* this is just a wrapper around exit() */ ringsel_exit(C, op); return OPERATOR_CANCELLED; } -static int ringcut_invoke (bContext *C, wmOperator *op, wmEvent *evt) +static int ringcut_invoke(bContext *C, wmOperator *op, wmEvent *evt) { Object *obedit = CTX_data_edit_object(C); tringselOpData *lcd; @@ -418,7 +420,7 @@ static int ringcut_invoke (bContext *C, wmOperator *op, wmEvent *evt) lcd->vc.mval[0] = evt->mval[0]; lcd->vc.mval[1] = evt->mval[1]; - edge = EDBM_findnearestedge(&lcd->vc, &dist); + edge = EDBM_edge_find_nearest(&lcd->vc, &dist); if (edge != lcd->eed) { lcd->eed = edge; ringsel_find_edge(lcd, 1); @@ -428,7 +430,7 @@ static int ringcut_invoke (bContext *C, wmOperator *op, wmEvent *evt) return OPERATOR_RUNNING_MODAL; } -static int loopcut_modal (bContext *C, wmOperator *op, wmEvent *event) +static int loopcut_modal(bContext *C, wmOperator *op, wmEvent *event) { int cuts = RNA_int_get(op->ptr, "number_cuts"); tringselOpData *lcd = op->customdata; @@ -502,7 +504,7 @@ static int loopcut_modal (bContext *C, wmOperator *op, wmEvent *event) lcd->vc.mval[0] = event->mval[0]; lcd->vc.mval[1] = event->mval[1]; - edge = EDBM_findnearestedge(&lcd->vc, &dist); + edge = EDBM_edge_find_nearest(&lcd->vc, &dist); if (edge != lcd->eed) { lcd->eed = edge; @@ -544,7 +546,7 @@ static int loopcut_modal (bContext *C, wmOperator *op, wmEvent *event) /* for bmesh this tool is in bmesh_select.c */ #if 0 -void MESH_OT_edgering_select (wmOperatorType *ot) +void MESH_OT_edgering_select(wmOperatorType *ot) { /* description */ ot->name = "Edge Ring Select"; @@ -556,14 +558,14 @@ void MESH_OT_edgering_select (wmOperatorType *ot) ot->poll = ED_operator_editmesh_region_view3d; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection"); } #endif -void MESH_OT_loopcut (wmOperatorType *ot) +void MESH_OT_loopcut(wmOperatorType *ot) { PropertyRNA *prop; @@ -579,7 +581,7 @@ void MESH_OT_loopcut (wmOperatorType *ot) ot->poll = ED_operator_editmesh_region_view3d; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; /* properties */ prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, INT_MAX, "Number of Cuts", "", 1, 10); diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index d0b39dc5cc8..737506bc73c 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -83,7 +83,7 @@ void EDBM_select_mirrored(Object *UNUSED(obedit), BMEditMesh *em, int extend) } } - EDBM_CacheMirrorVerts(em, TRUE); + EDBM_verts_mirror_cache_begin(em, TRUE); if (!extend) EDBM_flag_disable_all(em, BM_ELEM_SELECT); @@ -92,13 +92,13 @@ void EDBM_select_mirrored(Object *UNUSED(obedit), BMEditMesh *em, int extend) if (!BM_elem_flag_test(v1, BM_ELEM_TAG) || BM_elem_flag_test(v1, BM_ELEM_HIDDEN)) continue; - v2 = EDBM_GetMirrorVert(em, v1); + v2 = EDBM_verts_mirror_get(em, v1); if (v2 && !BM_elem_flag_test(v2, BM_ELEM_HIDDEN)) { BM_elem_select_set(em->bm, v2, TRUE); } } - EDBM_EndMirrorCache(em); + EDBM_verts_mirror_cache_end(em); } void EDBM_automerge(Scene *scene, Object *obedit, int update) @@ -115,13 +115,14 @@ void EDBM_automerge(Scene *scene, Object *obedit, int update) BMO_op_callf(em->bm, "automerge verts=%hv dist=%f", BM_ELEM_SELECT, scene->toolsettings->doublimit); if (update) { DAG_id_tag_update(obedit->data, OB_RECALC_DATA); + BMEdit_RecalcTessellation(em); } } } /* ****************************** SELECTION ROUTINES **************** */ -unsigned int bm_solidoffs = 0, bm_wireoffs = 0, bm_vertoffs = 0; /* set in drawobject.c ... for colorindices */ +unsigned int bm_solidoffs = 0, bm_wireoffs = 0, bm_vertoffs = 0; /* set in drawobject.c ... for colorindices */ /* facilities for border select and circle select */ static char *selbuf = NULL; @@ -174,7 +175,7 @@ static void draw_triangulated(int mcords[][2], short tot) /* reads rect, and builds selection array for quick lookup */ /* returns if all is OK */ -int EDBM_init_backbuf_border(ViewContext *vc, short xmin, short ymin, short xmax, short ymax) +int EDBM_backbuf_border_init(ViewContext *vc, short xmin, short ymin, short xmax, short ymax) { struct ImBuf *buf; unsigned int *dr; @@ -203,7 +204,7 @@ int EDBM_init_backbuf_border(ViewContext *vc, short xmin, short ymin, short xmax return 1; } -int EDBM_check_backbuf(unsigned int index) +int EDBM_backbuf_check(unsigned int index) { if (selbuf == NULL) return 1; if (index > 0 && index <= bm_vertoffs) @@ -211,7 +212,7 @@ int EDBM_check_backbuf(unsigned int index) return 0; } -void EDBM_free_backbuf(void) +void EDBM_backbuf_free(void) { if (selbuf) MEM_freeN(selbuf); selbuf = NULL; @@ -223,7 +224,7 @@ void EDBM_free_backbuf(void) * - grab again and compare * returns 'OK' */ -int EDBM_mask_init_backbuf_border(ViewContext *vc, int mcords[][2], short tot, short xmin, short ymin, short xmax, short ymax) +int EDBM_backbuf_border_mask_init(ViewContext *vc, int mcords[][2], short tot, short xmin, short ymin, short xmax, short ymax) { unsigned int *dr, *drm; struct ImBuf *buf, *bufmask; @@ -260,7 +261,7 @@ int EDBM_mask_init_backbuf_border(ViewContext *vc, int mcords[][2], short tot, s } glEnd(); - glFinish(); /* to be sure readpixels sees mask */ + glFinish(); /* to be sure readpixels sees mask */ /* grab mask */ bufmask = view3d_read_backbuf(vc, xmin, ymin, xmax, ymax); @@ -284,7 +285,7 @@ int EDBM_mask_init_backbuf_border(ViewContext *vc, int mcords[][2], short tot, s } /* circle shaped sample area */ -int EDBM_init_backbuf_circle(ViewContext *vc, short xs, short ys, short rads) +int EDBM_backbuf_circle_init(ViewContext *vc, short xs, short ys, short rads) { struct ImBuf *buf; unsigned int *dr; @@ -371,11 +372,11 @@ static unsigned int findnearestvert__backbufIndextest(void *handle, unsigned int * * dist (in/out): minimal distance to the nearest and at the end, actual distance * sel: selection bias - * if SELECT, selected vertice are given a 5 pixel bias to make them further than unselect verts - * if 0, unselected vertice are given the bias + * if SELECT, selected vertice are given a 5 pixel bias to make them further than unselect verts + * if 0, unselected vertice are given the bias * strict: if 1, the vertice corresponding to the sel parameter are ignored and not just biased */ -BMVert *EDBM_findnearestvert(ViewContext *vc, int *dist, short sel, short strict) +BMVert *EDBM_vert_find_nearest(ViewContext *vc, int *dist, short sel, short strict) { if (vc->v3d->drawtype > OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) { int distance; @@ -493,7 +494,7 @@ static void findnearestedge__doClosest(void *userData, BMEdge *eed, int x0, int } } } -BMEdge *EDBM_findnearestedge(ViewContext *vc, int *dist) +BMEdge *EDBM_edge_find_nearest(ViewContext *vc, int *dist) { if (vc->v3d->drawtype > OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) { @@ -566,7 +567,7 @@ static void findnearestface__doClosest(void *userData, BMFace *efa, int x, int y } } -BMFace *EDBM_findnearestface(ViewContext *vc, int *dist) +BMFace *EDBM_face_find_nearest(ViewContext *vc, int *dist) { if (vc->v3d->drawtype > OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) { @@ -583,12 +584,12 @@ BMFace *EDBM_findnearestface(ViewContext *vc, int *dist) data.mval[0] = vc->mval[0]; data.mval[1] = vc->mval[1]; - data.dist = 0x7FFF; /* largest short */ + data.dist = 0x7FFF; /* largest short */ data.toFace = efa; mesh_foreachScreenFace(vc, findnearestface__getDistance, &data); - if (vc->em->selectmode == SCE_SELECT_FACE || data.dist < *dist) { /* only faces, no dist check */ + if (vc->em->selectmode == SCE_SELECT_FACE || data.dist < *dist) { /* only faces, no dist check */ *dist = data.dist; return efa; } @@ -649,13 +650,13 @@ static int unified_findnearest(ViewContext *vc, BMVert **r_eve, BMEdge **r_eed, view3d_validate_backbuf(vc); if (em->selectmode & SCE_SELECT_VERTEX) - *r_eve = EDBM_findnearestvert(vc, &dist, BM_ELEM_SELECT, 0); + *r_eve = EDBM_vert_find_nearest(vc, &dist, BM_ELEM_SELECT, 0); if (em->selectmode & SCE_SELECT_FACE) - *r_efa = EDBM_findnearestface(vc, &dist); + *r_efa = EDBM_face_find_nearest(vc, &dist); - dist -= 20; /* since edges select lines, we give dots advantage of 20 pix */ + dist -= 20; /* since edges select lines, we give dots advantage of 20 pix */ if (em->selectmode & SCE_SELECT_EDGE) - *r_eed = EDBM_findnearestedge(vc, &dist); + *r_eed = EDBM_edge_find_nearest(vc, &dist); /* return only one of 3 pointers, for frontbuffer redraws */ if (*r_eed) { @@ -708,7 +709,7 @@ static int similar_face_select_exec(bContext *C, wmOperator *op) float thresh = RNA_float_get(op->ptr, "threshold"); /* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ - EDBM_InitOpf(em, &bmop, op, "similarfaces faces=%hf type=%i thresh=%f", BM_ELEM_SELECT, type, thresh); + EDBM_op_init(em, &bmop, op, "similarfaces faces=%hf type=%i thresh=%f", BM_ELEM_SELECT, type, thresh); /* execute the operator */ BMO_op_exec(em->bm, &bmop); @@ -720,13 +721,11 @@ static int similar_face_select_exec(bContext *C, wmOperator *op) BMO_slot_buffer_hflag_enable(em->bm, &bmop, "faceout", BM_ALL, BM_ELEM_SELECT, TRUE); /* finish the operator */ - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } - /* dependencies graph and notification stuff */ - DAG_id_tag_update(ob->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, ob->data); + EDBM_update_generic(C, em, FALSE); /* we succeeded */ return OPERATOR_FINISHED; @@ -748,7 +747,7 @@ static int similar_edge_select_exec(bContext *C, wmOperator *op) float thresh = RNA_float_get(op->ptr, "threshold"); /* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ - EDBM_InitOpf(em, &bmop, op, "similaredges edges=%he type=%i thresh=%f", BM_ELEM_SELECT, type, thresh); + EDBM_op_init(em, &bmop, op, "similaredges edges=%he type=%i thresh=%f", BM_ELEM_SELECT, type, thresh); /* execute the operator */ BMO_op_exec(em->bm, &bmop); @@ -761,13 +760,11 @@ static int similar_edge_select_exec(bContext *C, wmOperator *op) EDBM_selectmode_flush(em); /* finish the operator */ - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } - /* dependencies graph and notification stuff */ - DAG_id_tag_update(ob->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, ob->data); + EDBM_update_generic(C, em, FALSE); /* we succeeded */ return OPERATOR_FINISHED; @@ -791,7 +788,7 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op) float thresh = RNA_float_get(op->ptr, "threshold"); /* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ - EDBM_InitOpf(em, &bmop, op, "similarverts verts=%hv type=%i thresh=%f", BM_ELEM_SELECT, type, thresh); + EDBM_op_init(em, &bmop, op, "similarverts verts=%hv type=%i thresh=%f", BM_ELEM_SELECT, type, thresh); /* execute the operator */ BMO_op_exec(em->bm, &bmop); @@ -803,15 +800,13 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op) BMO_slot_buffer_hflag_enable(em->bm, &bmop, "vertout", BM_ALL, BM_ELEM_SELECT, TRUE); /* finish the operator */ - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } EDBM_selectmode_flush(em); - /* dependencies graph and notification stuff */ - DAG_id_tag_update(ob->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, ob->data); + EDBM_update_generic(C, em, FALSE); /* we succeeded */ return OPERATOR_FINISHED; @@ -833,7 +828,7 @@ static int edbm_select_similar_exec(bContext *C, wmOperator *op) if (type < 100) return similar_vert_select_exec(C, op); else if (type < 200) return similar_edge_select_exec(C, op); - else return similar_face_select_exec(C, op); + else return similar_face_select_exec(C, op); } static EnumPropertyItem *select_similar_type_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), @@ -886,7 +881,7 @@ void MESH_OT_select_similar(wmOperatorType *ot) ot->description = "Select similar vertices, edges or faces by property types"; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ prop = ot->prop = RNA_def_enum(ot->srna, "type", prop_similar_types, SIMVERT_NORMAL, "Type", ""); @@ -906,10 +901,11 @@ static void walker_select(BMEditMesh *em, int walkercode, void *start, int selec BMWalker walker; BMW_init(&walker, bm, walkercode, - BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, + BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, + BMW_FLAG_TEST_HIDDEN, BMW_NIL_LAY); ele = BMW_begin(&walker, start); - for ( ; ele; ele = BMW_step(&walker)) { + for (; ele; ele = BMW_step(&walker)) { if (!select) { BM_select_history_remove(bm, ele); } @@ -931,7 +927,7 @@ static int edbm_loop_multiselect_exec(bContext *C, wmOperator *op) int totedgesel = 0; for (eed = BM_iter_new(&iter, em->bm, BM_EDGES_OF_MESH, NULL); - eed; eed = BM_iter_step(&iter)) { + eed; eed = BM_iter_step(&iter)) { if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { totedgesel++; @@ -970,7 +966,7 @@ static int edbm_loop_multiselect_exec(bContext *C, wmOperator *op) MEM_freeN(edarray); // if (EM_texFaceCheck()) - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); return OPERATOR_FINISHED; } @@ -987,7 +983,7 @@ void MESH_OT_loop_multi_select(wmOperatorType *ot) ot->description = "Select a loop of connected edges by connection type"; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ RNA_def_boolean(ot->srna, "ring", 0, "Ring", ""); @@ -1015,7 +1011,7 @@ static void mouse_mesh_loop(bContext *C, int mval[2], short extend, short ring) /* no afterqueue (yet), so we check it now, otherwise the bm_xxxofs indices are bad */ view3d_validate_backbuf(&vc); - eed = EDBM_findnearestedge(&vc, &dist); + eed = EDBM_edge_find_nearest(&vc, &dist); if (eed) { if (extend == 0) { EDBM_flag_disable_all(em, BM_ELEM_SELECT); @@ -1054,17 +1050,17 @@ static void mouse_mesh_loop(bContext *C, int mval[2], short extend, short ring) /* TODO: would be nice if the edge vertex chosen here * was the one closer to the selection pointer, instead * of arbitrarily selecting the first one */ - EDBM_store_selection(em, eed->v1); + EDBM_editselection_store(em, &eed->v1->head); } else if (em->selectmode & SCE_SELECT_EDGE) { - EDBM_store_selection(em, eed); + EDBM_editselection_store(em, &eed->head); } /* TODO: would be nice if the nearest face that * belongs to the selected edge could be set to * active here in face select mode */ } - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, vc.obedit); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit); } } @@ -1074,7 +1070,7 @@ static int edbm_select_loop_invoke(bContext *C, wmOperator *op, wmEvent *event) view3d_operator_needs_opengl(C); mouse_mesh_loop(C, event->mval, RNA_boolean_get(op->ptr, "extend"), - RNA_boolean_get(op->ptr, "ring")); + RNA_boolean_get(op->ptr, "ring")); /* cannot do tweaks for as long this keymap is after transform map */ return OPERATOR_FINISHED; @@ -1141,15 +1137,15 @@ static float edgetag_cut_cost(BMEditMesh *UNUSED(em), BMEdge *e1, BMEdge *e2, BM } static void edgetag_add_adjacent(BMEditMesh *em, SmallHash *visithash, Heap *heap, int mednum, int vertnum, - int *nedges, int *edges, int *prevedge, float *cost) + int *nedges, int *edges, int *prevedge, float *cost) { - BMEdge *e1 = EDBM_get_edge_for_index(em, mednum); - BMVert *v = EDBM_get_vert_for_index(em, vertnum); + BMEdge *e1 = EDBM_edge_at_index(em, mednum); + BMVert *v = EDBM_vert_at_index(em, vertnum); int startadj, endadj = nedges[vertnum + 1]; for (startadj = nedges[vertnum]; startadj < endadj; startadj++) { int adjnum = edges[startadj]; - BMEdge *e2 = EDBM_get_edge_for_index(em, adjnum); + BMEdge *e2 = EDBM_edge_at_index(em, adjnum); float newcost; float cutcost; @@ -1171,48 +1167,48 @@ static void edgetag_context_set(BMEditMesh *em, Scene *scene, BMEdge *e, int val { switch (scene->toolsettings->edge_mode) { - case EDGE_MODE_SELECT: - BM_elem_select_set(em->bm, e, val); - break; - case EDGE_MODE_TAG_SEAM: - BM_elem_flag_set(e, BM_ELEM_SEAM, val); - break; - case EDGE_MODE_TAG_SHARP: - BM_elem_flag_set(e, BM_ELEM_SMOOTH, !val); - break; - case EDGE_MODE_TAG_FREESTYLE: - BM_elem_flag_set(e, BM_ELEM_FREESTYLE, val); - break; - case EDGE_MODE_TAG_CREASE: - { - float *crease = CustomData_bmesh_get(&em->bm->edata, e->head.data, CD_CREASE); - *crease = (val) ? 1.0f : 0.0f; - break; - } - case EDGE_MODE_TAG_BEVEL: - { - float *bweight = CustomData_bmesh_get(&em->bm->edata, e->head.data, CD_BWEIGHT); - *bweight = (val) ? 1.0f : 0.0f; - break; - } + case EDGE_MODE_SELECT: + BM_elem_select_set(em->bm, e, val); + break; + case EDGE_MODE_TAG_SEAM: + BM_elem_flag_set(e, BM_ELEM_SEAM, val); + break; + case EDGE_MODE_TAG_SHARP: + BM_elem_flag_set(e, BM_ELEM_SMOOTH, !val); + break; + case EDGE_MODE_TAG_FREESTYLE: + BM_elem_flag_set(e, BM_ELEM_FREESTYLE, val); + break; + case EDGE_MODE_TAG_CREASE: + { + float *crease = CustomData_bmesh_get(&em->bm->edata, e->head.data, CD_CREASE); + *crease = (val) ? 1.0f : 0.0f; + break; + } + case EDGE_MODE_TAG_BEVEL: + { + float *bweight = CustomData_bmesh_get(&em->bm->edata, e->head.data, CD_BWEIGHT); + *bweight = (val) ? 1.0f : 0.0f; + break; + } } } static int edgetag_context_check(Scene *scene, BMEditMesh *em, BMEdge *e) { switch (scene->toolsettings->edge_mode) { - case EDGE_MODE_SELECT: - return BM_elem_flag_test(e, BM_ELEM_SELECT) ? 1 : 0; - case EDGE_MODE_TAG_SEAM: - return BM_elem_flag_test(e, BM_ELEM_SEAM); - case EDGE_MODE_TAG_SHARP: - return !BM_elem_flag_test(e, BM_ELEM_SMOOTH); - case EDGE_MODE_TAG_FREESTYLE: - return !BM_elem_flag_test(e, BM_ELEM_FREESTYLE); - case EDGE_MODE_TAG_CREASE: - return BM_elem_float_data_get(&em->bm->edata, e, CD_CREASE) ? 1 : 0; - case EDGE_MODE_TAG_BEVEL: - return BM_elem_float_data_get(&em->bm->edata, e, CD_BWEIGHT) ? 1 : 0; + case EDGE_MODE_SELECT: + return BM_elem_flag_test(e, BM_ELEM_SELECT) ? 1 : 0; + case EDGE_MODE_TAG_SEAM: + return BM_elem_flag_test(e, BM_ELEM_SEAM); + case EDGE_MODE_TAG_SHARP: + return !BM_elem_flag_test(e, BM_ELEM_SMOOTH); + case EDGE_MODE_TAG_FREESTYLE: + return !BM_elem_flag_test(e, BM_ELEM_FREESTYLE); + case EDGE_MODE_TAG_CREASE: + return BM_elem_float_data_get(&em->bm->edata, e, CD_CREASE) ? 1 : 0; + case EDGE_MODE_TAG_BEVEL: + return BM_elem_float_data_get(&em->bm->edata, e, CD_BWEIGHT) ? 1 : 0; } return 0; } @@ -1232,7 +1228,8 @@ static int edgetag_shortest_path(Scene *scene, BMEditMesh *em, BMEdge *source, B /* note, would pass BM_EDGE except we are looping over all edges anyway */ BM_mesh_elem_index_ensure(em->bm, BM_VERT /* | BM_EDGE */); - BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { + BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) + { e->oflags[0].f = 0; /* XXX, whats this for, BMESH_TODO, double check if this is needed */ if (BM_elem_flag_test(e, BM_ELEM_HIDDEN)) { BLI_smallhash_insert(&visithash, (uintptr_t)e, NULL); @@ -1291,7 +1288,7 @@ static int edgetag_shortest_path(Scene *scene, BMEditMesh *em, BMEdge *source, B for (i = 0; i < totvert; i++) { int start = nedges[i], end = nedges[i + 1], cur; for (cur = start; cur < end; cur++) { - BMEdge *e = EDBM_get_edge_for_index(em, edges[cur]); + BMEdge *e = EDBM_edge_at_index(em, edges[cur]); } } #endif @@ -1300,12 +1297,12 @@ static int edgetag_shortest_path(Scene *scene, BMEditMesh *em, BMEdge *source, B heap = BLI_heap_new(); BLI_heap_insert(heap, 0.0f, SET_INT_IN_POINTER(BM_elem_index_get(source))); cost[BM_elem_index_get(source)] = 0.0f; - EDBM_init_index_arrays(em, 1, 1, 0); + EDBM_index_arrays_init(em, 1, 1, 0); targetnum = BM_elem_index_get(target); while (!BLI_heap_empty(heap)) { mednum = GET_INT_FROM_POINTER(BLI_heap_popmin(heap)); - e = EDBM_get_edge_for_index(em, mednum); + e = EDBM_edge_at_index(em, mednum); if (mednum == targetnum) break; @@ -1326,7 +1323,7 @@ static int edgetag_shortest_path(Scene *scene, BMEditMesh *em, BMEdge *source, B * if it is, the tags will be cleared instead of set. */ mednum = targetnum; do { - e = EDBM_get_edge_for_index(em, mednum); + e = EDBM_edge_at_index(em, mednum); if (!edgetag_context_check(scene, em, e)) { allseams = 0; break; @@ -1337,7 +1334,7 @@ static int edgetag_shortest_path(Scene *scene, BMEditMesh *em, BMEdge *source, B /* Follow path back and source and add or remove tags */ mednum = targetnum; do { - e = EDBM_get_edge_for_index(em, mednum); + e = EDBM_edge_at_index(em, mednum); if (allseams) edgetag_context_set(em, scene, e, 0); else @@ -1346,7 +1343,7 @@ static int edgetag_shortest_path(Scene *scene, BMEditMesh *em, BMEdge *source, B } while (mednum != -1); } - EDBM_free_index_arrays(em); + EDBM_index_arrays_free(em); MEM_freeN(nedges); MEM_freeN(edges); MEM_freeN(prevedge); @@ -1362,7 +1359,6 @@ static int edgetag_shortest_path(Scene *scene, BMEditMesh *em, BMEdge *source, B /* since you want to create paths with multiple selects, it doesn't have extend option */ static void mouse_mesh_shortest_path(bContext *C, int mval[2]) { - Object *ob = CTX_data_edit_object(C); ViewContext vc; BMEditMesh *em; BMEdge *e; @@ -1373,7 +1369,7 @@ static void mouse_mesh_shortest_path(bContext *C, int mval[2]) vc.mval[1] = mval[1]; em = vc.em; - e = EDBM_findnearestedge(&vc, &dist); + e = EDBM_edge_find_nearest(&vc, &dist); if (e) { Mesh *me = vc.obedit->data; int path = 0; @@ -1386,7 +1382,7 @@ static void mouse_mesh_shortest_path(bContext *C, int mval[2]) e_act = (BMEdge *)ese->ele; if (e_act != e) { if (edgetag_shortest_path(vc.scene, em, e_act, e)) { - EDBM_remove_selection(em, e_act); + EDBM_editselection_remove(em, &e_act->head); path = 1; } } @@ -1401,9 +1397,9 @@ static void mouse_mesh_shortest_path(bContext *C, int mval[2]) /* even if this is selected it may not be in the selection list */ if (edgetag_context_check(vc.scene, em, e) == 0) - EDBM_remove_selection(em, e); + EDBM_editselection_remove(em, &e->head); else - EDBM_store_selection(em, e); + EDBM_editselection_store(em, &e->head); /* force drawmode for mesh */ switch (CTX_data_tool_settings(C)->edge_mode) { @@ -1425,8 +1421,7 @@ static void mouse_mesh_shortest_path(bContext *C, int mval[2]) break; } - DAG_id_tag_update(ob->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, ob->data); + EDBM_update_generic(C, em, FALSE); } } @@ -1453,7 +1448,7 @@ void MESH_OT_select_shortest_path(wmOperatorType *ot) ot->description = "Select shortest path between two selections"; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); @@ -1483,31 +1478,31 @@ int mouse_mesh(bContext *C, const int mval[2], short extend) BM_active_face_set(vc.em->bm, efa); if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { - EDBM_store_selection(vc.em, efa); + EDBM_editselection_store(vc.em, &efa->head); BM_elem_select_set(vc.em->bm, efa, TRUE); } else if (extend) { - EDBM_remove_selection(vc.em, efa); + EDBM_editselection_remove(vc.em, &efa->head); BM_elem_select_set(vc.em->bm, efa, FALSE); } } else if (eed) { if (!BM_elem_flag_test(eed, BM_ELEM_SELECT)) { - EDBM_store_selection(vc.em, eed); + EDBM_editselection_store(vc.em, &eed->head); BM_elem_select_set(vc.em->bm, eed, TRUE); } else if (extend) { - EDBM_remove_selection(vc.em, eed); + EDBM_editselection_remove(vc.em, &eed->head); BM_elem_select_set(vc.em->bm, eed, FALSE); } } else if (eve) { if (!BM_elem_flag_test(eve, BM_ELEM_SELECT)) { - EDBM_store_selection(vc.em, eve); + EDBM_editselection_store(vc.em, &eve->head); BM_elem_select_set(vc.em->bm, eve, TRUE); } else if (extend) { - EDBM_remove_selection(vc.em, eve); + EDBM_editselection_remove(vc.em, &eve->head); BM_elem_select_set(vc.em->bm, eve, FALSE); } } @@ -1522,14 +1517,14 @@ int mouse_mesh(bContext *C, const int mval[2], short extend) // BIF_preview_changed(ID_MA); } - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, vc.obedit); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit); return 1; } return 0; } -static void EDBM_strip_selections(BMEditMesh *em) +static void edbm_strip_selections(BMEditMesh *em) { BMEditSelection *ese, *nextese; @@ -1570,7 +1565,7 @@ void EDBM_selectmode_set(BMEditMesh *em) em->bm->selectmode = em->selectmode; - EDBM_strip_selections(em); /* strip BMEditSelections from em->selected that are not relevant to new mode */ + edbm_strip_selections(em); /* strip BMEditSelections from em->selected that are not relevant to new mode */ if (em->selectmode & SCE_SELECT_VERTEX) { EDBM_select_flush(em); @@ -1578,10 +1573,10 @@ void EDBM_selectmode_set(BMEditMesh *em) else if (em->selectmode & SCE_SELECT_EDGE) { /* deselect vertices, and select again based on edge select */ eve = BM_iter_new(&iter, em->bm, BM_VERTS_OF_MESH, NULL); - for ( ; eve; eve = BM_iter_step(&iter)) BM_elem_select_set(em->bm, eve, FALSE); + for (; eve; eve = BM_iter_step(&iter)) BM_elem_select_set(em->bm, eve, FALSE); eed = BM_iter_new(&iter, em->bm, BM_EDGES_OF_MESH, NULL); - for ( ; eed; eed = BM_iter_step(&iter)) { + for (; eed; eed = BM_iter_step(&iter)) { if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { BM_elem_select_set(em->bm, eed, TRUE); } @@ -1593,10 +1588,10 @@ void EDBM_selectmode_set(BMEditMesh *em) else if (em->selectmode & SCE_SELECT_FACE) { /* deselect eges, and select again based on face select */ eed = BM_iter_new(&iter, em->bm, BM_EDGES_OF_MESH, NULL); - for ( ; eed; eed = BM_iter_step(&iter)) BM_elem_select_set(em->bm, eed, FALSE); + for (; eed; eed = BM_iter_step(&iter)) BM_elem_select_set(em->bm, eed, FALSE); efa = BM_iter_new(&iter, em->bm, BM_FACES_OF_MESH, NULL); - for ( ; efa; efa = BM_iter_step(&iter)) { + for (; efa; efa = BM_iter_step(&iter)) { if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) { BM_elem_select_set(em->bm, efa, TRUE); } @@ -1604,7 +1599,7 @@ void EDBM_selectmode_set(BMEditMesh *em) } } -void EDBM_convertsel(BMEditMesh *em, short oldmode, short selectmode) +void EDBM_selectmode_convert(BMEditMesh *em, short oldmode, short selectmode) { BMEdge *eed; BMFace *efa; @@ -1615,7 +1610,7 @@ void EDBM_convertsel(BMEditMesh *em, short oldmode, short selectmode) if (selectmode == SCE_SELECT_EDGE) { /* select all edges associated with every selected vertex */ eed = BM_iter_new(&iter, em->bm, BM_EDGES_OF_MESH, NULL); - for ( ; eed; eed = BM_iter_step(&iter)) { + for (; eed; eed = BM_iter_step(&iter)) { if ((BM_elem_flag_test(eed->v1, BM_ELEM_SELECT) || BM_elem_flag_test(eed->v2, BM_ELEM_SELECT))) { @@ -1629,7 +1624,7 @@ void EDBM_convertsel(BMEditMesh *em, short oldmode, short selectmode) /* select all faces associated with every selected vertex */ efa = BM_iter_new(&iter, em->bm, BM_FACES_OF_MESH, NULL); - for ( ; efa; efa = BM_iter_step(&iter)) { + for (; efa; efa = BM_iter_step(&iter)) { l = BM_iter_new(&liter, em->bm, BM_LOOPS_OF_FACE, efa); for (; l; l = BM_iter_step(&liter)) { if (BM_elem_flag_test(l->v, BM_ELEM_SELECT)) { @@ -1648,7 +1643,7 @@ void EDBM_convertsel(BMEditMesh *em, short oldmode, short selectmode) /* select all faces associated with every selected vertex */ efa = BM_iter_new(&iter, em->bm, BM_FACES_OF_MESH, NULL); - for ( ; efa; efa = BM_iter_step(&iter)) { + for (; efa; efa = BM_iter_step(&iter)) { l = BM_iter_new(&liter, em->bm, BM_LOOPS_OF_FACE, efa); for (; l; l = BM_iter_step(&liter)) { if (BM_elem_flag_test(l->v, BM_ELEM_SELECT)) { @@ -1796,7 +1791,7 @@ static int edbm_select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent * /* return warning! */ if (unified_findnearest(&vc, &eve, &eed, &efa) == 0) { - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); return OPERATOR_CANCELLED; } @@ -1817,7 +1812,8 @@ static int edbm_select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent * /* walk */ BMW_init(&walker, bm, BMW_ISLAND, - BMW_MASK_NOP, limit ? BM_ELEM_SELECT : BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, + BMW_MASK_NOP, limit ? BM_ELEM_SELECT : BMW_MASK_NOP, BMW_MASK_NOP, + BMW_FLAG_TEST_HIDDEN, BMW_NIL_LAY); e = BMW_begin(&walker, efa); @@ -1838,17 +1834,20 @@ static int edbm_select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent * } BMW_init(&walker, bm, BMW_SHELL, - BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, + BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, + BMW_FLAG_TEST_HIDDEN, BMW_NIL_LAY); e = BMW_begin(&walker, eed->v1); - for ( ; e; e = BMW_step(&walker)) { + for (; e; e = BMW_step(&walker)) { BM_elem_select_set(bm, e, sel); } BMW_end(&walker); + + BM_mesh_select_mode_flush(bm); } - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); return OPERATOR_FINISHED; } @@ -1864,7 +1863,7 @@ void MESH_OT_select_linked_pick(wmOperatorType *ot) ot->description = "(De)select all vertices linked to the edge under the mouse cursor"; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", ""); RNA_def_boolean(ot->srna, "limit", 0, "Limit by Seams", ""); @@ -1903,7 +1902,8 @@ static int edbm_select_linked_exec(bContext *C, wmOperator *op) } BMW_init(&walker, bm, BMW_ISLAND, - BMW_MASK_NOP, limit ? BM_ELEM_SELECT : BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, + BMW_MASK_NOP, limit ? BM_ELEM_SELECT : BMW_MASK_NOP, BMW_MASK_NOP, + BMW_FLAG_NOP, /* BMESH_TODO - should be BMW_FLAG_TEST_HIDDEN ? */ BMW_NIL_LAY); BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { @@ -1927,8 +1927,10 @@ static int edbm_select_linked_exec(bContext *C, wmOperator *op) } BMW_init(&walker, em->bm, BMW_SHELL, - BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, + BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, + BMW_FLAG_NOP, /* BMESH_TODO - should be BMW_FLAG_TEST_HIDDEN ? */ BMW_NIL_LAY); + BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { if (BM_elem_flag_test(v, BM_ELEM_TAG)) { e = BMW_begin(&walker, v); @@ -1942,7 +1944,7 @@ static int edbm_select_linked_exec(bContext *C, wmOperator *op) } EDBM_selectmode_flush_ex(em, SCE_SELECT_VERTEX); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); return OPERATOR_FINISHED; } @@ -1959,7 +1961,7 @@ void MESH_OT_select_linked(wmOperatorType *ot) ot->description = "Select all vertices linked to the active mesh"; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_boolean(ot->srna, "limit", 0, "Limit by Seams", ""); } @@ -1973,7 +1975,7 @@ static int edbm_select_more_exec(bContext *C, wmOperator *UNUSED(op)) EDBM_select_more(em); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); return OPERATOR_FINISHED; } @@ -1989,7 +1991,7 @@ void MESH_OT_select_more(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int edbm_select_less_exec(bContext *C, wmOperator *UNUSED(op)) @@ -1999,7 +2001,7 @@ static int edbm_select_less_exec(bContext *C, wmOperator *UNUSED(op)) EDBM_select_less(em); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); return OPERATOR_FINISHED; } @@ -2015,7 +2017,7 @@ void MESH_OT_select_less(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* Walk all reachable elements of the same type as h_act in breadth-first @@ -2028,7 +2030,7 @@ static void walker_deselect_nth(BMEditMesh *em, int nth, int offset, BMHeader *h BMWalker walker; BMIter iter; int walktype = 0, itertype = 0, flushtype = 0; - short mask_vert = 0, mask_edge = 0, mask_loop = 0, mask_face = 0; + short mask_vert = 0, mask_edge = 0, mask_face = 0; /* No active element from which to start - nothing to do */ if (h_act == NULL) { @@ -2038,30 +2040,31 @@ static void walker_deselect_nth(BMEditMesh *em, int nth, int offset, BMHeader *h /* Determine which type of iter, walker, and select flush to use * based on type of the elements being deselected */ switch (h_act->htype) { - case BM_VERT: - itertype = BM_VERTS_OF_MESH; - walktype = BMW_CONNECTED_VERTEX; - flushtype = SCE_SELECT_VERTEX; - mask_vert = BM_ELEM_SELECT; - break; - case BM_EDGE: - itertype = BM_EDGES_OF_MESH; - walktype = BMW_SHELL; - flushtype = SCE_SELECT_EDGE; - mask_edge = BM_ELEM_SELECT; - break; - case BM_FACE: - itertype = BM_FACES_OF_MESH; - walktype = BMW_ISLAND; - flushtype = SCE_SELECT_FACE; - mask_face = BM_ELEM_SELECT; - break; + case BM_VERT: + itertype = BM_VERTS_OF_MESH; + walktype = BMW_CONNECTED_VERTEX; + flushtype = SCE_SELECT_VERTEX; + mask_vert = BM_ELEM_SELECT; + break; + case BM_EDGE: + itertype = BM_EDGES_OF_MESH; + walktype = BMW_SHELL; + flushtype = SCE_SELECT_EDGE; + mask_edge = BM_ELEM_SELECT; + break; + case BM_FACE: + itertype = BM_FACES_OF_MESH; + walktype = BMW_ISLAND; + flushtype = SCE_SELECT_FACE; + mask_face = BM_ELEM_SELECT; + break; } /* Walker restrictions uses BMO flags, not header flags, * so transfer BM_ELEM_SELECT from HFlags onto a BMO flag layer. */ BMO_push(bm, NULL); - BM_ITER(ele, &iter, bm, itertype, NULL) { + BM_ITER(ele, &iter, bm, itertype, NULL) + { if (BM_elem_flag_test(ele, BM_ELEM_SELECT)) { /* BMESH_TODO, don't use 'BM_ELEM_SELECT' here, its a HFLAG only! */ BMO_elem_flag_enable(bm, (BMElemF *)ele, BM_ELEM_SELECT); @@ -2070,7 +2073,8 @@ static void walker_deselect_nth(BMEditMesh *em, int nth, int offset, BMHeader *h /* Walk over selected elements starting at active */ BMW_init(&walker, bm, walktype, - mask_vert, mask_edge, mask_loop, mask_face, + mask_vert, mask_edge, mask_face, + BMW_FLAG_NOP, /* BMESH_TODO - should be BMW_FLAG_TEST_HIDDEN ? */ BMW_NIL_LAY); BLI_assert(walker.order == BMW_BREADTH_FIRST); @@ -2105,15 +2109,15 @@ static void deselect_nth_active(BMEditMesh *em, BMVert **r_eve, BMEdge **r_eed, if (ese) { switch (ese->htype) { - case BM_VERT: - *r_eve = (BMVert *)ese->ele; - return; - case BM_EDGE: - *r_eed = (BMEdge *)ese->ele; - return; - case BM_FACE: - *r_efa = (BMFace *)ese->ele; - return; + case BM_VERT: + *r_eve = (BMVert *)ese->ele; + return; + case BM_EDGE: + *r_eed = (BMEdge *)ese->ele; + return; + case BM_FACE: + *r_efa = (BMFace *)ese->ele; + return; } } @@ -2142,7 +2146,7 @@ static void deselect_nth_active(BMEditMesh *em, BMVert **r_eve, BMEdge **r_eed, } } -static int EM_deselect_nth(BMEditMesh *em, int nth, int offset) +static int edbm_deselect_nth(BMEditMesh *em, int nth, int offset) { BMVert *v; BMEdge *e; @@ -2175,13 +2179,12 @@ static int edbm_select_nth_exec(bContext *C, wmOperator *op) offset = MIN2(nth, offset); - if (EM_deselect_nth(em, nth, offset) == 0) { + if (edbm_deselect_nth(em, nth, offset) == 0) { BKE_report(op->reports, RPT_ERROR, "Mesh has no active vert/edge/face"); return OPERATOR_CANCELLED; } - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, FALSE); return OPERATOR_FINISHED; } @@ -2199,7 +2202,7 @@ void MESH_OT_select_nth(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_int(ot->srna, "nth", 2, 2, 100, "Nth Selection", "", 1, INT_MAX); RNA_def_int(ot->srna, "offset", 0, 0, 100, "Offset", "", 0, INT_MAX); @@ -2259,7 +2262,7 @@ static int edbm_select_sharp_edges_exec(bContext *C, wmOperator *op) } - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -2276,7 +2279,7 @@ void MESH_OT_edges_select_sharp(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ RNA_def_float(ot->srna, "sharpness", 1.0f, 0.01f, FLT_MAX, "sharpness", "", 1.0f, 180.0f); @@ -2340,7 +2343,7 @@ static int edbm_select_linked_flat_faces_exec(bContext *C, wmOperator *op) BLI_array_free(stack); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -2357,7 +2360,7 @@ void MESH_OT_faces_select_linked_flat(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ RNA_def_float(ot->srna, "sharpness", 1.0f, 0.01f, FLT_MAX, "sharpness", "", 1.0f, 180.0f); @@ -2392,7 +2395,7 @@ static int edbm_select_non_manifold_exec(bContext *C, wmOperator *op) } } - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -2409,7 +2412,7 @@ void MESH_OT_select_non_manifold(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int edbm_select_random_exec(bContext *C, wmOperator *op) @@ -2452,7 +2455,7 @@ static int edbm_select_random_exec(bContext *C, wmOperator *op) EDBM_selectmode_flush(em); } - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -2469,7 +2472,7 @@ void MESH_OT_select_random(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, @@ -2508,7 +2511,7 @@ static int edbm_select_next_loop_exec(bContext *C, wmOperator *UNUSED(op)) } } - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); return OPERATOR_FINISHED; } @@ -2524,7 +2527,7 @@ void MESH_OT_select_next_loop(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } @@ -2575,7 +2578,7 @@ static int edbm_region_to_loop_exec(bContext *C, wmOperator *UNUSED(op)) EDBM_selectmode_to_scene(C); } - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -2591,7 +2594,7 @@ void MESH_OT_region_to_loop(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int loop_find_region(BMEditMesh *em, BMLoop *l, int flag, @@ -2757,7 +2760,7 @@ static int edbm_loop_to_region_exec(bContext *C, wmOperator *op) } } - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -2772,7 +2775,7 @@ void MESH_OT_loop_to_region(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_boolean(ot->srna, "select_bigger", 0, "Select Bigger", "Select bigger regions instead of smaller ones"); } diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 323dae7163b..a0cffd42668 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -102,13 +102,12 @@ static int edbm_subdivide_exec(bContext *C, wmOperator *op) BM_mesh_esubdivideflag(obedit, em->bm, BM_ELEM_SELECT, smooth, fractal, - ts->editbutflag|flag, + ts->editbutflag | flag, cuts, 0, RNA_enum_get(op->ptr, "quadcorner"), RNA_boolean_get(op->ptr, "quadtri"), TRUE, RNA_int_get(op->ptr, "seed")); - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -136,7 +135,7 @@ void MESH_OT_subdivide(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, INT_MAX, "Number of Cuts", "", 1, 10); @@ -160,7 +159,7 @@ void EMBM_project_snap_verts(bContext *C, ARegion *ar, Object *obedit, BMEditMes BMIter iter; BMVert *eve; - BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { + BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { float mval[2], vec[3], no_dummy[3]; int dist_dummy; @@ -184,7 +183,7 @@ static short edbm_extrude_face_indiv(BMEditMesh *em, wmOperator *op, const char BMLoop *l; BMOperator bmop; - EDBM_InitOpf(em, &bmop, op, "extrude_face_indiv faces=%hf", hflag); + EDBM_op_init(em, &bmop, op, "extrude_face_indiv faces=%hf", hflag); /* deselect original verts */ EDBM_flag_disable_all(em, BM_ELEM_SELECT); @@ -200,7 +199,7 @@ static short edbm_extrude_face_indiv(BMEditMesh *em, wmOperator *op, const char } } - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return 0; } @@ -212,15 +211,15 @@ static short edbm_extrude_edges_indiv(BMEditMesh *em, wmOperator *op, const char { BMOperator bmop; - EDBM_InitOpf(em, &bmop, op, "extrude_edge_only edges=%he", hflag); + EDBM_op_init(em, &bmop, op, "extrude_edge_only edges=%he", hflag); /* deselect original verts */ EDBM_flag_disable_all(em, BM_ELEM_SELECT); BMO_op_exec(em->bm, &bmop); - BMO_slot_buffer_hflag_enable(em->bm, &bmop, "geomout", BM_VERT|BM_EDGE, BM_ELEM_SELECT, TRUE); + BMO_slot_buffer_hflag_enable(em->bm, &bmop, "geomout", BM_VERT | BM_EDGE, BM_ELEM_SELECT, TRUE); - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return 0; } @@ -232,7 +231,7 @@ static short edbm_extrude_verts_indiv(BMEditMesh *em, wmOperator *op, const char { BMOperator bmop; - EDBM_InitOpf(em, &bmop, op, "extrude_vert_indiv verts=%hv", hflag); + EDBM_op_init(em, &bmop, op, "extrude_vert_indiv verts=%hv", hflag); /* deselect original verts */ BMO_slot_buffer_hflag_disable(em->bm, &bmop, "verts", BM_VERT, BM_ELEM_SELECT, TRUE); @@ -240,7 +239,7 @@ static short edbm_extrude_verts_indiv(BMEditMesh *em, wmOperator *op, const char BMO_op_exec(em->bm, &bmop); BMO_slot_buffer_hflag_enable(em->bm, &bmop, "vertout", BM_VERT, BM_ELEM_SELECT, TRUE); - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return 0; } @@ -259,7 +258,7 @@ static short edbm_extrude_edge(Object *obedit, BMEditMesh *em, const char hflag, BMElem *ele; BMO_op_init(bm, &extop, "extrude_face_region"); - BMO_slot_buffer_from_hflag(bm, &extop, "edgefacein", BM_VERT|BM_EDGE|BM_FACE, hflag); + BMO_slot_buffer_from_enabled_hflag(bm, &extop, "edgefacein", BM_VERT | BM_EDGE | BM_FACE, hflag); /* If a mirror modifier with clipping is on, we need to adjust some * of the cases above to handle edges on the line of symmetry. @@ -297,21 +296,21 @@ static short edbm_extrude_edge(Object *obedit, BMEditMesh *em, const char hflag, if (mmd->flag & MOD_MIR_AXIS_X) { if ((fabsf(co1[0]) < mmd->tolerance) && - (fabsf(co2[0]) < mmd->tolerance)) + (fabsf(co2[0]) < mmd->tolerance)) { BMO_slot_map_ptr_insert(bm, &extop, "exclude", edge, NULL); } } if (mmd->flag & MOD_MIR_AXIS_Y) { if ((fabsf(co1[1]) < mmd->tolerance) && - (fabsf(co2[1]) < mmd->tolerance)) + (fabsf(co2[1]) < mmd->tolerance)) { BMO_slot_map_ptr_insert(bm, &extop, "exclude", edge, NULL); } } if (mmd->flag & MOD_MIR_AXIS_Z) { if ((fabsf(co1[2]) < mmd->tolerance) && - (fabsf(co2[2]) < mmd->tolerance)) + (fabsf(co2[2]) < mmd->tolerance)) { BMO_slot_map_ptr_insert(bm, &extop, "exclude", edge, NULL); } @@ -405,10 +404,9 @@ static int edbm_extrude_repeat_exec(bContext *C, wmOperator *op) //translateflag(em, SELECT, dvec); } - EDBM_RecalcNormals(em); + EDBM_mesh_normals_update(em); - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -425,7 +423,7 @@ void MESH_OT_extrude_repeat(wmOperatorType *ot) ot->poll = ED_operator_editmesh_view3d; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ RNA_def_float(ot->srna, "offset", 2.0f, 0.0f, 100.0f, "Offset", "", 0.0f, FLT_MAX); @@ -446,11 +444,11 @@ static int edbm_extrude_mesh(Scene *scene, Object *obedit, BMEditMesh *em, wmOpe else if (em->bm->totvertsel == 1) nr = 4; else if (em->bm->totedgesel == 0) nr = 4; else if (em->bm->totfacesel == 0) - nr = 3; // pupmenu("Extrude %t|Only Edges%x3|Only Vertices%x4"); + nr = 3; // pupmenu("Extrude %t|Only Edges%x3|Only Vertices%x4"); else if (em->bm->totfacesel == 1) - nr = 1; // pupmenu("Extrude %t|Region %x1|Only Edges%x3|Only Vertices%x4"); + nr = 1; // pupmenu("Extrude %t|Region %x1|Only Edges%x3|Only Vertices%x4"); else - nr = 1; // pupmenu("Extrude %t|Region %x1||Individual Faces %x2|Only Edges%x3|Only Vertices%x4"); + nr = 1; // pupmenu("Extrude %t|Region %x1||Individual Faces %x2|Only Edges%x3|Only Vertices%x4"); } else if (em->selectmode & SCE_SELECT_EDGE) { if (em->bm->totedgesel == 0) nr = 0; @@ -460,16 +458,16 @@ static int edbm_extrude_mesh(Scene *scene, Object *obedit, BMEditMesh *em, wmOpe else if (em->totedgesel == 1) nr = 3; else if (em->totfacesel == 0) nr = 3; else if (em->totfacesel == 1) - nr = 1; // pupmenu("Extrude %t|Region %x1|Only Edges%x3"); + nr = 1; // pupmenu("Extrude %t|Region %x1|Only Edges%x3"); else - nr = 1; // pupmenu("Extrude %t|Region %x1||Individual Faces %x2|Only Edges%x3"); + nr = 1; // pupmenu("Extrude %t|Region %x1||Individual Faces %x2|Only Edges%x3"); #endif } else { if (em->bm->totfacesel == 0) nr = 0; else if (em->bm->totfacesel == 1) nr = 1; else - nr = 1; // pupmenu("Extrude %t|Region %x1||Individual Faces %x2"); + nr = 1; // pupmenu("Extrude %t|Region %x1||Individual Faces %x2"); } if (nr < 1) return 'g'; @@ -527,10 +525,9 @@ static int edbm_extrude_region_exec(bContext *C, wmOperator *op) /* This normally happens when pushing undo but modal operators * like this one don't push undo data until after modal mode is * done.*/ - EDBM_RecalcNormals(em); - BMEdit_RecalcTessellation(em); + EDBM_mesh_normals_update(em); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -547,7 +544,7 @@ void MESH_OT_extrude_region(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); } @@ -560,7 +557,7 @@ static int edbm_extrude_verts_exec(bContext *C, wmOperator *op) edbm_extrude_verts_indiv(em, op, BM_ELEM_SELECT, nor); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); return OPERATOR_FINISHED; } @@ -576,7 +573,7 @@ void MESH_OT_extrude_verts_indiv(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* to give to transform */ RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); @@ -590,7 +587,7 @@ static int edbm_extrude_edges_exec(bContext *C, wmOperator *op) edbm_extrude_edges_indiv(em, op, BM_ELEM_SELECT, nor); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); return OPERATOR_FINISHED; } @@ -606,7 +603,7 @@ void MESH_OT_extrude_edges_indiv(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* to give to transform */ RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); @@ -620,7 +617,7 @@ static int edbm_extrude_faces_exec(bContext *C, wmOperator *op) edbm_extrude_face_indiv(em, op, BM_ELEM_SELECT, nor); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); return OPERATOR_FINISHED; } @@ -636,7 +633,7 @@ void MESH_OT_extrude_faces_indiv(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); } @@ -650,21 +647,21 @@ static int edbm_select_all_exec(bContext *C, wmOperator *op) int action = RNA_enum_get(op->ptr, "action"); switch (action) { - case SEL_TOGGLE: - EDBM_select_toggle_all(em); - break; - case SEL_SELECT: - EDBM_flag_enable_all(em, BM_ELEM_SELECT); - break; - case SEL_DESELECT: - EDBM_flag_disable_all(em, BM_ELEM_SELECT); - break; - case SEL_INVERT: - EDBM_select_swap(em); - break; + case SEL_TOGGLE: + EDBM_select_toggle_all(em); + break; + case SEL_SELECT: + EDBM_flag_enable_all(em, BM_ELEM_SELECT); + break; + case SEL_DESELECT: + EDBM_flag_disable_all(em, BM_ELEM_SELECT); + break; + case SEL_INVERT: + EDBM_select_swap(em); + break; } - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); return OPERATOR_FINISHED; } @@ -681,7 +678,7 @@ void MESH_OT_select_all(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; WM_operator_properties_select_all(ot); } @@ -692,7 +689,7 @@ static int edbm_faces_select_interior_exec(bContext *C, wmOperator *UNUSED(op)) BMEditMesh *em = BMEdit_FromObject(obedit); if (EDBM_select_interior_faces(em)) { - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); return OPERATOR_FINISHED; } @@ -714,7 +711,7 @@ void MESH_OT_select_interior_faces(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* *************** add-click-mesh (extrude) operator ************** */ @@ -729,7 +726,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent em_setup_viewcontext(C, &vc); - use_proj = (vc.scene->toolsettings->snap_flag & SCE_SNAP) && (vc.scene->toolsettings->snap_mode == SCE_SNAP_MODE_FACE); + use_proj = (vc.scene->toolsettings->snap_flag & SCE_SNAP) && (vc.scene->toolsettings->snap_mode == SCE_SNAP_MODE_FACE); INIT_MINMAX(min, max); @@ -799,7 +796,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent mid_v3_v3v3(cent, min, max); copy_v3_v3(min, cent); - mul_m4_v3(vc.obedit->obmat, min); // view space + mul_m4_v3(vc.obedit->obmat, min); /* view space */ view3d_get_view_aligned_coordinate(&vc, min, event->mval, TRUE); mul_m4_v3(vc.obedit->imat, min); // back in object space @@ -808,35 +805,29 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent /* calculate rotation */ unit_m3(mat); if (done) { - float dot; + float angle; - copy_v3_v3(vec, min); - normalize_v3(vec); - dot = dot_v3v3(vec, nor); + normalize_v3_v3(vec, min); - if (fabsf(dot) < 0.999f) { - float cross[3], si, q1[4]; + angle = angle_normalized_v3v3(vec, nor); - cross_v3_v3v3(cross, nor, vec); - normalize_v3(cross); - dot = 0.5f * saacos(dot); + if (angle != 0.0f) { + float axis[3]; + + cross_v3_v3v3(axis, nor, vec); /* halve the rotation if its applied twice */ - if (rot_src) dot *= 0.5f; - - si = sinf(dot); - q1[0] = cosf(dot); - q1[1] = cross[0] * si; - q1[2] = cross[1] * si; - q1[3] = cross[2] * si; - normalize_qt(q1); - quat_to_mat3(mat, q1); + if (rot_src) { + angle *= 0.5f; + } + + axis_angle_to_mat3(mat, axis, angle); } } if (rot_src) { - EDBM_CallOpf(vc.em, op, "rotate verts=%hv cent=%v mat=%m3", - BM_ELEM_SELECT, cent, mat); + EDBM_op_callf(vc.em, op, "rotate verts=%hv cent=%v mat=%m3", + BM_ELEM_SELECT, cent, mat); /* also project the source, for retopo workflow */ if (use_proj) @@ -844,10 +835,10 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent } edbm_extrude_edge(vc.obedit, vc.em, BM_ELEM_SELECT, nor); - EDBM_CallOpf(vc.em, op, "rotate verts=%hv cent=%v mat=%m3", - BM_ELEM_SELECT, cent, mat); - EDBM_CallOpf(vc.em, op, "translate verts=%hv vec=%v", - BM_ELEM_SELECT, min); + EDBM_op_callf(vc.em, op, "rotate verts=%hv cent=%v mat=%m3", + BM_ELEM_SELECT, cent, mat); + EDBM_op_callf(vc.em, op, "translate verts=%hv vec=%v", + BM_ELEM_SELECT, min); } else { float *curs = give_cursor(vc.scene, vc.v3d); @@ -860,14 +851,14 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent invert_m4_m4(vc.obedit->imat, vc.obedit->obmat); mul_m4_v3(vc.obedit->imat, min); // back in object space - EDBM_InitOpf(vc.em, &bmop, op, "makevert co=%v", min); + EDBM_op_init(vc.em, &bmop, op, "makevert co=%v", min); BMO_op_exec(vc.em->bm, &bmop); BMO_ITER(v1, &oiter, vc.em->bm, &bmop, "newvertout", BM_VERT) { BM_elem_select_set(vc.em->bm, v1, TRUE); } - if (!EDBM_FinishOp(vc.em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(vc.em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } } @@ -878,12 +869,10 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent /* This normally happens when pushing undo but modal operators * like this one don't push undo data until after modal mode is * done. */ - EDBM_RecalcNormals(vc.em); - BMEdit_RecalcTessellation(vc.em); + EDBM_mesh_normals_update(vc.em); + + EDBM_update_generic(C, vc.em, TRUE); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, vc.obedit->data); - DAG_id_tag_update(vc.obedit->data, OB_RECALC_DATA); - return OPERATOR_FINISHED; } @@ -899,7 +888,7 @@ void MESH_OT_dupli_extrude_cursor(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_boolean(ot->srna, "rotate_source", 1, "Rotate Source", "Rotate initial selection giving better shape"); } @@ -920,36 +909,32 @@ static int edbm_delete_exec(bContext *C, wmOperator *op) BMEditMesh *em = BMEdit_FromObject(obedit); int type = RNA_enum_get(op->ptr, "type"); - BMEditMesh *bem = BMEdit_FromObject(obedit); - if (type == 0) { - if (!EDBM_CallOpf(bem, op, "del geom=%hv context=%i", BM_ELEM_SELECT, DEL_VERTS)) /* Erase Vertices */ + if (!EDBM_op_callf(em, op, "del geom=%hv context=%i", BM_ELEM_SELECT, DEL_VERTS)) /* Erase Vertices */ return OPERATOR_CANCELLED; } else if (type == 1) { - if (!EDBM_CallOpf(bem, op, "del geom=%he context=%i", BM_ELEM_SELECT, DEL_EDGES)) /* Erase Edges */ + if (!EDBM_op_callf(em, op, "del geom=%he context=%i", BM_ELEM_SELECT, DEL_EDGES)) /* Erase Edges */ return OPERATOR_CANCELLED; } else if (type == 2) { - if (!EDBM_CallOpf(bem, op, "del geom=%hf context=%i", BM_ELEM_SELECT, DEL_FACES)) /* Erase Faces */ + if (!EDBM_op_callf(em, op, "del geom=%hf context=%i", BM_ELEM_SELECT, DEL_FACES)) /* Erase Faces */ return OPERATOR_CANCELLED; } else if (type == 3) { - if (!EDBM_CallOpf(bem, op, "del geom=%hef context=%i", BM_ELEM_SELECT, DEL_EDGESFACES)) /* Edges and Faces */ + if (!EDBM_op_callf(em, op, "del geom=%hef context=%i", BM_ELEM_SELECT, DEL_EDGESFACES)) /* Edges and Faces */ return OPERATOR_CANCELLED; } else if (type == 4) { //"Erase Only Faces"; - if (!EDBM_CallOpf(bem, op, "del geom=%hf context=%i", - BM_ELEM_SELECT, DEL_ONLYFACES)) + if (!EDBM_op_callf(em, op, "del geom=%hf context=%i", + BM_ELEM_SELECT, DEL_ONLYFACES)) return OPERATOR_CANCELLED; } EDBM_flag_disable_all(em, BM_ELEM_SELECT); - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - - WM_event_add_notifier(C, NC_GEOM|ND_DATA|ND_SELECT, obedit); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -968,7 +953,7 @@ void MESH_OT_delete(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ ot->prop = RNA_def_enum(ot->srna, "type", prop_mesh_delete_types, 0, "Type", "Method used for deleting mesh data"); @@ -979,11 +964,10 @@ static int edbm_collapse_edge_exec(bContext *C, wmOperator *op) Object *obedit = CTX_data_edit_object(C); BMEditMesh *em = BMEdit_FromObject(obedit); - if (!EDBM_CallOpf(em, op, "collapse edges=%he", BM_ELEM_SELECT)) + if (!EDBM_op_callf(em, op, "collapse edges=%he", BM_ELEM_SELECT)) return OPERATOR_CANCELLED; - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA|ND_SELECT, obedit); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -1000,7 +984,7 @@ void MESH_OT_edge_collapse(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int edbm_collapse_edge_loop_exec(bContext *C, wmOperator *op) @@ -1008,11 +992,10 @@ static int edbm_collapse_edge_loop_exec(bContext *C, wmOperator *op) Object *obedit = CTX_data_edit_object(C); BMEditMesh *em = BMEdit_FromObject(obedit); - if (!EDBM_CallOpf(em, op, "dissolve_edge_loop edges=%he", BM_ELEM_SELECT)) + if (!EDBM_op_callf(em, op, "dissolve_edge_loop edges=%he", BM_ELEM_SELECT)) return OPERATOR_CANCELLED; - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA|ND_SELECT, obedit); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -1029,7 +1012,7 @@ void MESH_OT_edge_collapse_loop(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int edbm_add_edge_face_exec(bContext *C, wmOperator *op) @@ -1038,18 +1021,17 @@ static int edbm_add_edge_face_exec(bContext *C, wmOperator *op) Object *obedit = CTX_data_edit_object(C); BMEditMesh *em = BMEdit_FromObject(obedit); - if (!EDBM_InitOpf(em, &bmop, op, "contextual_create geom=%hfev", BM_ELEM_SELECT)) + if (!EDBM_op_init(em, &bmop, op, "contextual_create geom=%hfev", BM_ELEM_SELECT)) return OPERATOR_CANCELLED; BMO_op_exec(em->bm, &bmop); BMO_slot_buffer_hflag_enable(em->bm, &bmop, "faceout", BM_FACE, BM_ELEM_SELECT, TRUE); - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -1066,7 +1048,7 @@ void MESH_OT_edge_face_add(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ************************* SEAMS AND EDGES **************** */ @@ -1102,8 +1084,7 @@ static int edbm_mark_seam(bContext *C, wmOperator *op) } } - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -1120,7 +1101,7 @@ void MESH_OT_mark_seam(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_boolean(ot->srna, "clear", 0, "Clear", ""); } @@ -1157,9 +1138,7 @@ static int edbm_mark_sharp(bContext *C, wmOperator *op) } } - - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -1176,7 +1155,7 @@ void MESH_OT_mark_sharp(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_boolean(ot->srna, "clear", 0, "Clear", ""); } @@ -1190,17 +1169,16 @@ static int edbm_vert_connect(bContext *C, wmOperator *op) BMOperator bmop; int len = 0; - if (!EDBM_InitOpf(em, &bmop, op, "connectverts verts=%hv", BM_ELEM_SELECT)) { + if (!EDBM_op_init(em, &bmop, op, "connectverts verts=%hv", BM_ELEM_SELECT)) { return OPERATOR_CANCELLED; } BMO_op_exec(bm, &bmop); len = BMO_slot_get(&bmop, "edgeout")->len; - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return len ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } @@ -1216,7 +1194,7 @@ void MESH_OT_vert_connect(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int edbm_edge_split_exec(bContext *C, wmOperator *op) @@ -1227,19 +1205,16 @@ static int edbm_edge_split_exec(bContext *C, wmOperator *op) BMOperator bmop; int len = 0; - if (!EDBM_InitOpf(em, &bmop, op, "edgesplit edges=%he", - BM_ELEM_SELECT)) - { + if (!EDBM_op_init(em, &bmop, op, "edgesplit edges=%he", BM_ELEM_SELECT)) { return OPERATOR_CANCELLED; } BMO_op_exec(bm, &bmop); len = BMO_slot_get(&bmop, "edgeout")->len; - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return len ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } @@ -1255,7 +1230,7 @@ void MESH_OT_edge_split(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /****************** add duplicate operator ***************/ @@ -1266,19 +1241,18 @@ static int edbm_duplicate_exec(bContext *C, wmOperator *op) BMEditMesh *em = BMEdit_FromObject(ob); BMOperator bmop; - EDBM_InitOpf(em, &bmop, op, "dupe geom=%hvef", BM_ELEM_SELECT); + EDBM_op_init(em, &bmop, op, "dupe geom=%hvef", BM_ELEM_SELECT); BMO_op_exec(em->bm, &bmop); EDBM_flag_disable_all(em, BM_ELEM_SELECT); BMO_slot_buffer_hflag_enable(em->bm, &bmop, "newout", BM_ALL, BM_ELEM_SELECT, TRUE); - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } - DAG_id_tag_update(ob->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -1314,11 +1288,10 @@ static int edbm_flip_normals_exec(bContext *C, wmOperator *op) Object *obedit = CTX_data_edit_object(C); BMEditMesh *em = BMEdit_FromObject(obedit); - if (!EDBM_CallOpf(em, op, "reversefaces faces=%hf", BM_ELEM_SELECT)) + if (!EDBM_op_callf(em, op, "reversefaces faces=%hf", BM_ELEM_SELECT)) return OPERATOR_CANCELLED; - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -1335,7 +1308,7 @@ void MESH_OT_flip_normals(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static const EnumPropertyItem direction_items[] = { @@ -1382,7 +1355,7 @@ static int edbm_edge_rotate_selected_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - EDBM_InitOpf(em, &bmop, op, "edgerotate edges=%he ccw=%b", BM_ELEM_TAG, do_ccw); + EDBM_op_init(em, &bmop, op, "edgerotate edges=%he ccw=%b", BM_ELEM_TAG, do_ccw); /* avoids leaving old verts selected which can be a problem running multiple times, * since this means the edges become selected around the face which then attempt to rotate */ @@ -1394,12 +1367,11 @@ static int edbm_edge_rotate_selected_exec(bContext *C, wmOperator *op) BMO_slot_buffer_hflag_enable(em->bm, &bmop, "edgeout", BM_EDGE, BM_ELEM_SELECT, TRUE); EDBM_selectmode_flush(em); - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -1416,7 +1388,7 @@ void MESH_OT_edge_rotate(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ RNA_def_enum(ot->srna, "direction", direction_items, DIRECTION_CW, "Direction", "Direction to rotate edge around"); @@ -1428,10 +1400,9 @@ static int edbm_hide_exec(bContext *C, wmOperator *op) Object *obedit = CTX_data_edit_object(C); BMEditMesh *em = BMEdit_FromObject(obedit); - EDBM_hide_mesh(em, RNA_boolean_get(op->ptr, "unselected")); - - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_mesh_hide(em, RNA_boolean_get(op->ptr, "unselected")); + + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -1445,10 +1416,10 @@ void MESH_OT_hide(wmOperatorType *ot) /* api callbacks */ ot->exec = edbm_hide_exec; ot->poll = ED_operator_editmesh; - ot->description = "Hide (un)selected vertices, edges or faces"; + ot->description = "Hide (un)selected vertices, edges or faces"; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected"); @@ -1459,10 +1430,9 @@ static int edbm_reveal_exec(bContext *C, wmOperator *UNUSED(op)) Object *obedit = CTX_data_edit_object(C); BMEditMesh *em = BMEdit_FromObject(obedit); - EDBM_reveal_mesh(em); + EDBM_mesh_reveal(em); - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -1479,7 +1449,7 @@ void MESH_OT_reveal(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int edbm_normals_make_consistent_exec(bContext *C, wmOperator *op) @@ -1489,14 +1459,13 @@ static int edbm_normals_make_consistent_exec(bContext *C, wmOperator *op) /* doflip has to do with bmesh_rationalize_normals, it's an internal * thing */ - if (!EDBM_CallOpf(em, op, "righthandfaces faces=%hf do_flip=%b", BM_ELEM_SELECT, TRUE)) + if (!EDBM_op_callf(em, op, "righthandfaces faces=%hf do_flip=%b", BM_ELEM_SELECT, TRUE)) return OPERATOR_CANCELLED; if (RNA_boolean_get(op->ptr, "inside")) - EDBM_CallOpf(em, op, "reversefaces faces=%hf", BM_ELEM_SELECT); + EDBM_op_callf(em, op, "reversefaces faces=%hf", BM_ELEM_SELECT); - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -1513,7 +1482,7 @@ void MESH_OT_normals_make_consistent(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_boolean(ot->srna, "inside", 0, "Inside", ""); } @@ -1531,7 +1500,7 @@ static int edbm_do_smooth_vertex_exec(bContext *C, wmOperator *op) /* mirror before smooth */ if (((Mesh *)obedit->data)->editflag & ME_EDIT_MIRROR_X) { - EDBM_CacheMirrorVerts(em, TRUE); + EDBM_verts_mirror_cache_begin(em, TRUE); } /* if there is a mirror modifier with clipping, flag the verts that @@ -1559,9 +1528,9 @@ static int edbm_do_smooth_vertex_exec(bContext *C, wmOperator *op) repeat = 1; for (i = 0; i < repeat; i++) { - if (!EDBM_CallOpf(em, op, - "vertexsmooth verts=%hv mirror_clip_x=%b mirror_clip_y=%b mirror_clip_z=%b clipdist=%f", - BM_ELEM_SELECT, mirrx, mirry, mirrz, clipdist)) + if (!EDBM_op_callf(em, op, + "vertexsmooth verts=%hv mirror_clip_x=%b mirror_clip_y=%b mirror_clip_z=%b clipdist=%f", + BM_ELEM_SELECT, mirrx, mirry, mirrz, clipdist)) { return OPERATOR_CANCELLED; } @@ -1569,12 +1538,11 @@ static int edbm_do_smooth_vertex_exec(bContext *C, wmOperator *op) /* apply mirror */ if (((Mesh *)obedit->data)->editflag & ME_EDIT_MIRROR_X) { - EDBM_ApplyMirrorCache(em, BM_ELEM_SELECT, 0); - EDBM_EndMirrorCache(em); + EDBM_verts_mirror_apply(em, BM_ELEM_SELECT, 0); + EDBM_verts_mirror_cache_end(em); } - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -1591,7 +1559,7 @@ void MESH_OT_vertices_smooth(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_int(ot->srna, "repeat", 1, 1, 100, "Number of times to smooth the mesh", "", 1, INT_MAX); } @@ -1619,8 +1587,7 @@ static int edbm_faces_shade_smooth_exec(bContext *C, wmOperator *UNUSED(op)) mesh_set_smooth_faces(em, 1); - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, FALSE); return OPERATOR_FINISHED; } @@ -1629,7 +1596,7 @@ void MESH_OT_faces_shade_smooth(wmOperatorType *ot) { /* identifiers */ ot->name = "Shade Smooth"; - ot->description = "Display faces smooth (using vertex normals)"; + ot->description = "Display faces smooth (using vertex normals)"; ot->idname = "MESH_OT_faces_shade_smooth"; /* api callbacks */ @@ -1637,7 +1604,7 @@ void MESH_OT_faces_shade_smooth(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int edbm_faces_shade_flat_exec(bContext *C, wmOperator *UNUSED(op)) @@ -1647,8 +1614,7 @@ static int edbm_faces_shade_flat_exec(bContext *C, wmOperator *UNUSED(op)) mesh_set_smooth_faces(em, 0); - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, FALSE); return OPERATOR_FINISHED; } @@ -1665,7 +1631,7 @@ void MESH_OT_faces_shade_flat(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } @@ -1681,19 +1647,17 @@ static int edbm_rotate_uvs_exec(bContext *C, wmOperator *op) int dir = RNA_enum_get(op->ptr, "direction"); /* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ - EDBM_InitOpf(em, &bmop, op, "face_rotateuvs faces=%hf dir=%i", BM_ELEM_SELECT, dir); + EDBM_op_init(em, &bmop, op, "face_rotateuvs faces=%hf dir=%i", BM_ELEM_SELECT, dir); /* execute the operator */ BMO_op_exec(em->bm, &bmop); /* finish the operator */ - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } - /* dependencies graph and notification stuff */ - DAG_id_tag_update(ob->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + EDBM_update_generic(C, em, FALSE); /* we succeeded */ return OPERATOR_FINISHED; @@ -1706,19 +1670,17 @@ static int edbm_reverse_uvs_exec(bContext *C, wmOperator *op) BMOperator bmop; /* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ - EDBM_InitOpf(em, &bmop, op, "face_reverseuvs faces=%hf", BM_ELEM_SELECT); + EDBM_op_init(em, &bmop, op, "face_reverseuvs faces=%hf", BM_ELEM_SELECT); /* execute the operator */ BMO_op_exec(em->bm, &bmop); /* finish the operator */ - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } - /* dependencies graph and notification stuff */ - DAG_id_tag_update(ob->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + EDBM_update_generic(C, em, FALSE); /* we succeeded */ return OPERATOR_FINISHED; @@ -1734,22 +1696,19 @@ static int edbm_rotate_colors_exec(bContext *C, wmOperator *op) int dir = RNA_enum_get(op->ptr, "direction"); /* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ - EDBM_InitOpf(em, &bmop, op, "face_rotatecolors faces=%hf dir=%i", BM_ELEM_SELECT, dir); + EDBM_op_init(em, &bmop, op, "face_rotatecolors faces=%hf dir=%i", BM_ELEM_SELECT, dir); /* execute the operator */ BMO_op_exec(em->bm, &bmop); /* finish the operator */ - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } /* dependencies graph and notification stuff */ - DAG_id_tag_update(ob->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); -/* DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - * WM_event_add_notifier(C, NC_OBJECT | ND_GEOM_SELECT, ob); - */ + EDBM_update_generic(C, em, FALSE); + /* we succeeded */ return OPERATOR_FINISHED; } @@ -1762,18 +1721,17 @@ static int edbm_reverse_colors_exec(bContext *C, wmOperator *op) BMOperator bmop; /* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ - EDBM_InitOpf(em, &bmop, op, "face_reversecolors faces=%hf", BM_ELEM_SELECT); + EDBM_op_init(em, &bmop, op, "face_reversecolors faces=%hf", BM_ELEM_SELECT); /* execute the operator */ BMO_op_exec(em->bm, &bmop); /* finish the operator */ - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } - DAG_id_tag_update(ob->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + EDBM_update_generic(C, em, FALSE); /* we succeeded */ return OPERATOR_FINISHED; @@ -1790,7 +1748,7 @@ void MESH_OT_uvs_rotate(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ RNA_def_enum(ot->srna, "direction", direction_items, DIRECTION_CW, "Direction", "Direction to rotate UVs around"); @@ -1808,7 +1766,7 @@ void MESH_OT_uvs_reverse(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ //RNA_def_enum(ot->srna, "axis", axis_items, DIRECTION_CW, "Axis", "Axis to mirror UVs around"); @@ -1825,7 +1783,7 @@ void MESH_OT_colors_rotate(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ RNA_def_enum(ot->srna, "direction", direction_items, DIRECTION_CCW, "Direction", "Direction to rotate edge around"); @@ -1842,7 +1800,7 @@ void MESH_OT_colors_reverse(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ //RNA_def_enum(ot->srna, "axis", axis_items, DIRECTION_CW, "Axis", "Axis to mirror colors around"); @@ -1868,11 +1826,11 @@ static int merge_firstlast(BMEditMesh *em, int first, int uvmerge, wmOperator *w return OPERATOR_CANCELLED; if (uvmerge) { - if (!EDBM_CallOpf(em, wmop, "pointmerge_facedata verts=%hv snapv=%e", BM_ELEM_SELECT, mergevert)) + if (!EDBM_op_callf(em, wmop, "pointmerge_facedata verts=%hv snapv=%e", BM_ELEM_SELECT, mergevert)) return OPERATOR_CANCELLED; } - if (!EDBM_CallOpf(em, wmop, "pointmerge verts=%hv mergeco=%v", BM_ELEM_SELECT, mergevert->co)) + if (!EDBM_op_callf(em, wmop, "pointmerge verts=%hv mergeco=%v", BM_ELEM_SELECT, mergevert->co)) return OPERATOR_CANCELLED; return OPERATOR_FINISHED; @@ -1913,11 +1871,11 @@ static int merge_target(BMEditMesh *em, Scene *scene, View3D *v3d, Object *ob, return OPERATOR_CANCELLED; if (uvmerge) { - if (!EDBM_CallOpf(em, wmop, "vert_average_facedata verts=%hv", BM_ELEM_SELECT)) + if (!EDBM_op_callf(em, wmop, "vert_average_facedata verts=%hv", BM_ELEM_SELECT)) return OPERATOR_CANCELLED; } - if (!EDBM_CallOpf(em, wmop, "pointmerge verts=%hv mergeco=%v", BM_ELEM_SELECT, co)) + if (!EDBM_op_callf(em, wmop, "pointmerge verts=%hv mergeco=%v", BM_ELEM_SELECT, co)) return OPERATOR_CANCELLED; return OPERATOR_FINISHED; @@ -1946,7 +1904,7 @@ static int edbm_merge_exec(bContext *C, wmOperator *op) break; case 5: status = 1; - if (!EDBM_CallOpf(em, op, "collapse edges=%he", BM_ELEM_SELECT)) + if (!EDBM_op_callf(em, op, "collapse edges=%he", BM_ELEM_SELECT)) status = 0; break; } @@ -1954,8 +1912,7 @@ static int edbm_merge_exec(bContext *C, wmOperator *op) if (!status) return OPERATOR_CANCELLED; - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -2014,6 +1971,7 @@ void MESH_OT_merge(wmOperatorType *ot) { /* identifiers */ ot->name = "Merge"; + ot->description = "Merge selected vertices"; ot->idname = "MESH_OT_merge"; /* api callbacks */ @@ -2022,7 +1980,7 @@ void MESH_OT_merge(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ ot->prop = RNA_def_enum(ot->srna, "type", merge_type_items, 3, "Type", "Merge method to use"); @@ -2038,25 +1996,23 @@ static int edbm_remove_doubles_exec(bContext *C, wmOperator *op) BMOperator bmop; int count; - EDBM_InitOpf(em, &bmop, op, "finddoubles verts=%hv dist=%f", BM_ELEM_SELECT, RNA_float_get(op->ptr, "mergedist")); + EDBM_op_init(em, &bmop, op, "finddoubles verts=%hv dist=%f", BM_ELEM_SELECT, RNA_float_get(op->ptr, "mergedist")); BMO_op_exec(em->bm, &bmop); count = BMO_slot_map_count(em->bm, &bmop, "targetmapout"); - if (!EDBM_CallOpf(em, op, "weldverts targetmap=%s", &bmop, "targetmapout")) { + if (!EDBM_op_callf(em, op, "weldverts targetmap=%s", &bmop, "targetmapout")) { BMO_op_finish(em->bm, &bmop); return OPERATOR_CANCELLED; } - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } BKE_reportf(op->reports, RPT_INFO, "Removed %d vert%s", count, (count == 1) ? "ex" : "ices"); - - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -2065,6 +2021,7 @@ void MESH_OT_remove_doubles(wmOperatorType *ot) { /* identifiers */ ot->name = "Remove Doubles"; + ot->description= "Remove duplicate vertices"; ot->idname = "MESH_OT_remove_doubles"; /* api callbacks */ @@ -2072,11 +2029,11 @@ void MESH_OT_remove_doubles(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_float(ot->srna, "mergedist", 0.0001f, 0.000001f, 50.0f, - "Merge Distance", - "Minimum distance between elements to merge", 0.00001, 10.0); + "Merge Distance", + "Minimum distance between elements to merge", 0.00001, 10.0); } /************************ Vertex Path Operator *************************/ @@ -2116,7 +2073,7 @@ static int edbm_select_vertex_path_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; /* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ - EDBM_InitOpf(em, &bmop, op, "vertexshortestpath startv=%e endv=%e type=%i", sv->ele, ev->ele, type); + EDBM_op_init(em, &bmop, op, "vertexshortestpath startv=%e endv=%e type=%i", sv->ele, ev->ele, type); /* execute the operator */ BMO_op_exec(em->bm, &bmop); @@ -2128,19 +2085,13 @@ static int edbm_select_vertex_path_exec(bContext *C, wmOperator *op) BMO_slot_buffer_hflag_enable(em->bm, &bmop, "vertout", BM_ALL, BM_ELEM_SELECT, TRUE); /* finish the operator */ - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } EDBM_selectmode_flush(em); - /* dependencies graph and notification stuff */ -/* DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - * WM_event_add_notifier(C, NC_OBJECT | ND_GEOM_SELECT, ob); - */ - DAG_id_tag_update(ob->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); - + EDBM_update_generic(C, em, FALSE); /* we succeeded */ return OPERATOR_FINISHED; @@ -2151,7 +2102,8 @@ void MESH_OT_select_vertex_path(wmOperatorType *ot) static const EnumPropertyItem type_items[] = { {VPATH_SELECT_EDGE_LENGTH, "EDGE_LENGTH", 0, "Edge Length", NULL}, {VPATH_SELECT_TOPOLOGICAL, "TOPOLOGICAL", 0, "Topological", NULL}, - {0, NULL, 0, NULL, NULL}}; + {0, NULL, 0, NULL, NULL} + }; /* identifiers */ ot->name = "Select Vertex Path"; @@ -2162,7 +2114,7 @@ void MESH_OT_select_vertex_path(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ RNA_def_enum(ot->srna, "type", type_items, VPATH_SELECT_EDGE_LENGTH, "Type", "Method to compute distance"); @@ -2198,6 +2150,7 @@ static int edbm_rip_invoke(bContext *C, wmOperator *op, wmEvent *event) float projectMat[4][4], fmval[3] = {event->mval[0], event->mval[1]}; float dist = FLT_MAX; float d; + const int totedge_orig = bm->totedge; /* note on selection: * When calling edge split we operate on tagged edges rather then selected @@ -2224,7 +2177,7 @@ static int edbm_rip_invoke(bContext *C, wmOperator *op, wmEvent *event) singlesel = TRUE; /* find selected vert - same some time and check history first */ - if (EDBM_get_actSelection(em, &ese) && ese.htype == BM_VERT) { + if (EDBM_editselection_active_get(em, &ese) && ese.htype == BM_VERT) { v = (BMVert *)ese.ele; } else { @@ -2238,23 +2191,26 @@ static int edbm_rip_invoke(bContext *C, wmOperator *op, wmEvent *event) if (!v) return OPERATOR_CANCELLED; - if (!v->e || !v->e->l) { - BKE_report(op->reports, RPT_ERROR, "Selected vertex has no faces"); - return OPERATOR_CANCELLED; - } - - /* find closest edge to mouse cursor */ e2 = NULL; - BM_ITER(e, &iter, bm, BM_EDGES_OF_VERT, v) { - d = mesh_rip_edgedist(ar, projectMat, e->v1->co, e->v2->co, fmval); - if (d < dist) { - dist = d; - e2 = e; + + if (v->e) { + /* find closest edge to mouse cursor */ + BM_ITER(e, &iter, bm, BM_EDGES_OF_VERT, v) { + if (!BM_elem_flag_test(e, BM_ELEM_HIDDEN) && BM_edge_face_count(e) == 2) { + d = mesh_rip_edgedist(ar, projectMat, e->v1->co, e->v2->co, fmval); + if (d < dist) { + dist = d; + e2 = e; + } + } } + } - if (!e2) + if (!e2) { + BKE_report(op->reports, RPT_ERROR, "Selected vertex has no edge/face pairs attached"); return OPERATOR_CANCELLED; + } /* rip two adjacent edges */ if (BM_edge_face_count(e2) == 1 || BM_vert_face_count(v) == 2) { @@ -2304,12 +2260,20 @@ static int edbm_rip_invoke(bContext *C, wmOperator *op, wmEvent *event) } } - if (!EDBM_InitOpf(em, &bmop, op, "edgesplit edges=%he", BM_ELEM_TAG)) { + if (!EDBM_op_init(em, &bmop, op, "edgesplit edges=%he verts=%hv use_verts=%b", + BM_ELEM_TAG, BM_ELEM_SELECT, TRUE)) { return OPERATOR_CANCELLED; } BMO_op_exec(bm, &bmop); + if (totedge_orig == bm->totedge) { + EDBM_op_finish(em, &bmop, op, TRUE); + + BKE_report(op->reports, RPT_ERROR, "No edges could be ripped"); + return OPERATOR_CANCELLED; + } + BMO_ITER(e, &siter, bm, &bmop, "edgeout", BM_EDGE) { float cent[3] = {0, 0, 0}, mid[3]; @@ -2402,16 +2366,15 @@ static int edbm_rip_invoke(bContext *C, wmOperator *op, wmEvent *event) BLI_assert(singlesel ? (bm->totvertsel > 0) : (bm->totedgesel > 0)); - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } if (bm->totvertsel == 0) { return OPERATOR_CANCELLED; } - - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -2427,7 +2390,7 @@ void MESH_OT_rip(wmOperatorType *ot) ot->poll = EM_view3d_poll; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* to give to transform */ Transform_Properties(ot, P_PROPORTIONAL); @@ -2437,7 +2400,7 @@ void MESH_OT_rip(wmOperatorType *ot) /************************ Shape Operators *************************/ /* BMESH_TODO this should be properly encapsulated in a bmop. but later.*/ -static void shape_propagate(Object *obedit, BMEditMesh *em, wmOperator *op) +static void shape_propagate(BMEditMesh *em, wmOperator *op) { BMIter iter; BMVert *eve = NULL; @@ -2467,8 +2430,6 @@ static void shape_propagate(Object *obedit, BMEditMesh *em, wmOperator *op) } } #endif - - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); } @@ -2478,10 +2439,9 @@ static int edbm_shape_propagate_to_all_exec(bContext *C, wmOperator *op) Mesh *me = obedit->data; BMEditMesh *em = me->edit_btmesh; - shape_propagate(obedit, em, op); + shape_propagate(em, op); - DAG_id_tag_update(&me->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); + EDBM_update_generic(C, em, FALSE); return OPERATOR_FINISHED; } @@ -2499,7 +2459,7 @@ void MESH_OT_shape_propagate_to_all(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* BMESH_TODO this should be properly encapsulated in a bmop. but later.*/ @@ -2540,8 +2500,7 @@ static int edbm_blend_from_shape_exec(bContext *C, wmOperator *op) copy_v3_v3(sco, co); } - DAG_id_tag_update(&me->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -2567,9 +2526,8 @@ static EnumPropertyItem *shape_itemf(bContext *C, PointerRNA *UNUSED(ptr), Prop tmp.value = totitem; tmp.identifier = em->bm->vdata.layers[a].name; tmp.name = em->bm->vdata.layers[a].name; + /* RNA_enum_item_add sets totitem itself! */ RNA_enum_item_add(&item, &totitem, &tmp); - - totitem++; } } @@ -2595,7 +2553,7 @@ void MESH_OT_blend_from_shape(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ prop = RNA_def_enum(ot->srna, "shape", shape_items, 0, "Shape", "Shape key to use for blending"); @@ -2631,25 +2589,25 @@ static int edbm_select_axis_exec(bContext *C, wmOperator *op) BM_ITER(ev, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { if (!BM_elem_flag_test(ev, BM_ELEM_HIDDEN)) { switch (mode) { - case -1: /* aligned */ - if (fabs(ev->co[axis] - value) < limit) - BM_elem_select_set(em->bm, ev, TRUE); - break; - case 0: /* neg */ - if (ev->co[axis] > value) - BM_elem_select_set(em->bm, ev, TRUE); - break; - case 1: /* pos */ - if (ev->co[axis] < value) - BM_elem_select_set(em->bm, ev, TRUE); - break; + case -1: /* aligned */ + if (fabs(ev->co[axis] - value) < limit) + BM_elem_select_set(em->bm, ev, TRUE); + break; + case 0: /* neg */ + if (ev->co[axis] > value) + BM_elem_select_set(em->bm, ev, TRUE); + break; + case 1: /* pos */ + if (ev->co[axis] < value) + BM_elem_select_set(em->bm, ev, TRUE); + break; } } } } EDBM_selectmode_flush(em); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); return OPERATOR_FINISHED; } @@ -2678,7 +2636,7 @@ void MESH_OT_select_axis(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ RNA_def_enum(ot->srna, "mode", axis_mode_items, 0, "Axis Mode", "Axis side to use when selecting"); @@ -2695,7 +2653,7 @@ static int edbm_solidify_exec(bContext *C, wmOperator *op) float thickness = RNA_float_get(op->ptr, "thickness"); - if (!EDBM_InitOpf(em, &bmop, op, "solidify geom=%hf thickness=%f", BM_ELEM_SELECT, thickness)) { + if (!EDBM_op_init(em, &bmop, op, "solidify geom=%hf thickness=%f", BM_ELEM_SELECT, thickness)) { return OPERATOR_CANCELLED; } @@ -2710,12 +2668,11 @@ static int edbm_solidify_exec(bContext *C, wmOperator *op) /* select the newly generated faces */ BMO_slot_buffer_hflag_enable(bm, &bmop, "geomout", BM_FACE, BM_ELEM_SELECT, TRUE); - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -2734,7 +2691,7 @@ void MESH_OT_solidify(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; prop = RNA_def_float(ot->srna, "thickness", 0.01f, -FLT_MAX, FLT_MAX, "thickness", "", -10.0f, 10.0f); RNA_def_property_ui_range(prop, -10, 10, 0.1, 4); @@ -2744,11 +2701,11 @@ void MESH_OT_solidify(wmOperatorType *ot) #define TRAIL_FREEHAND 2 #define TRAIL_MIXED 3 /* (1|2) */ #define TRAIL_AUTO 4 -#define TRAIL_MIDPOINTS 8 +#define TRAIL_MIDPOINTS 8 typedef struct CutCurve { - float x; - float y; + float x; + float y; } CutCurve; /* ******************************************************************** */ @@ -2771,9 +2728,9 @@ typedef struct CutCurve { * bmesh port version */ -#define KNIFE_EXACT 1 -#define KNIFE_MIDPOINT 2 -#define KNIFE_MULTICUT 3 +#define KNIFE_EXACT 1 +#define KNIFE_MIDPOINT 2 +#define KNIFE_MULTICUT 3 static EnumPropertyItem knife_items[] = { {KNIFE_EXACT, "EXACT", 0, "Exact", ""}, @@ -2788,13 +2745,13 @@ static float bm_edge_seg_isect(BMEdge *e, CutCurve *c, int len, char mode, struct GHash *gh, int *isected) { #define MAXSLOPE 100000 - float x11, y11, x12 = 0, y12 = 0, x2max, x2min, y2max; - float y2min, dist, lastdist = 0, xdiff2, xdiff1; - float m1, b1, m2, b2, x21, x22, y21, y22, xi; - float yi, x1min, x1max, y1max, y1min, perc = 0; + float x11, y11, x12 = 0, y12 = 0, x2max, x2min, y2max; + float y2min, dist, lastdist = 0, xdiff2, xdiff1; + float m1, b1, m2, b2, x21, x22, y21, y22, xi; + float yi, x1min, x1max, y1max, y1min, perc = 0; float *scr; - float threshold = 0.0; - int i; + float threshold = 0.0; + int i; //threshold = 0.000001; /* tolerance for vertex intersection */ // XXX threshold = scene->toolsettings->select_thresh / 100; @@ -2863,8 +2820,8 @@ static float bm_edge_seg_isect(BMEdge *e, CutCurve *c, int len, char mode, y12 = c[i].y; /* Perp. Distance from point to line */ - if (m2 != MAXSLOPE) dist = (y12 - m2 * x12 - b2);/* /sqrt(m2 * m2 + 1); Only looking for */ - /* change in sign. Skip extra math */ + if (m2 != MAXSLOPE) dist = (y12 - m2 * x12 - b2); /* /sqrt(m2 * m2 + 1); Only looking for */ + /* change in sign. Skip extra math */ else dist = x22 - x12; if (i == 0) lastdist = dist; @@ -2929,7 +2886,7 @@ static float bm_edge_seg_isect(BMEdge *e, CutCurve *c, int len, char mode, } } if ((m2 <= 1.0f) && (m2 >= -1.0f)) perc = (xi - x21) / (x22 - x21); - else perc = (yi - y21) / (y22 - y21); /* lower slope more accurate */ + else perc = (yi - y21) / (y22 - y21); /* lower slope more accurate */ //isect = 32768.0 * (perc + 0.0000153); /* Percentage in 1 / 32768ths */ break; @@ -2970,7 +2927,6 @@ static int edbm_knife_cut_exec(bContext *C, wmOperator *op) /* get the cut curve */ RNA_BEGIN(op->ptr, itemptr, "path") { - RNA_float_get_array(&itemptr, "loc", (float *)&curve[len]); len++; if (len >= MAX_CUTS) { @@ -2994,7 +2950,7 @@ static int edbm_knife_cut_exec(bContext *C, wmOperator *op) BLI_ghash_insert(gh, bv, scr); } - if (!EDBM_InitOpf(em, &bmop, op, "esubd")) { + if (!EDBM_op_init(em, &bmop, op, "esubd")) { return OPERATOR_CANCELLED; } @@ -3006,8 +2962,8 @@ static int edbm_knife_cut_exec(bContext *C, wmOperator *op) if (isect != 0.0f) { if (mode != KNIFE_MULTICUT && mode != KNIFE_MIDPOINT) { BMO_slot_map_float_insert(bm, &bmop, - "edgepercents", - be, isect); + "edgepercents", + be, isect); } BMO_elem_flag_enable(bm, be, 1); @@ -3021,7 +2977,7 @@ static int edbm_knife_cut_exec(bContext *C, wmOperator *op) } } - BMO_slot_buffer_from_flag(bm, &bmop, "edges", BM_EDGE, 1); + BMO_slot_buffer_from_enabled_flag(bm, &bmop, "edges", BM_EDGE, 1); if (mode == KNIFE_MIDPOINT) numcuts = 1; BMO_slot_int_set(&bmop, "numcuts", numcuts); @@ -3034,14 +2990,13 @@ static int edbm_knife_cut_exec(bContext *C, wmOperator *op) BMO_slot_float_set(&bmop, "radius", 0); BMO_op_exec(bm, &bmop); - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } BLI_ghash_free(gh, NULL, (GHashValFreeFP)MEM_freeN); - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -3061,7 +3016,7 @@ void MESH_OT_knife_cut(wmOperatorType *ot) ot->poll = EM_view3d_poll; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_enum(ot->srna, "type", knife_items, KNIFE_EXACT, "Type", ""); prop = RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE); @@ -3096,13 +3051,13 @@ static int mesh_separate_selected(Main *bmain, Scene *scene, Base *editbase, wmO CustomData_bmesh_init_pool(&bm_new->ldata, bm_mesh_allocsize_default.totloop, BM_LOOP); CustomData_bmesh_init_pool(&bm_new->pdata, bm_mesh_allocsize_default.totface, BM_FACE); - basenew = ED_object_add_duplicate(bmain, scene, editbase, USER_DUP_MESH); /* 0 = fully linked */ + basenew = ED_object_add_duplicate(bmain, scene, editbase, USER_DUP_MESH); /* 0 = fully linked */ assign_matarar(basenew->object, give_matarar(obedit), *give_totcolp(obedit)); /* new in 2.5 */ ED_base_object_select(basenew, BA_DESELECT); - EDBM_CallOpf(em, wmop, "dupe geom=%hvef dest=%p", BM_ELEM_SELECT, bm_new); - EDBM_CallOpf(em, wmop, "del geom=%hvef context=%i", BM_ELEM_SELECT, DEL_FACES); + EDBM_op_callf(em, wmop, "dupe geom=%hvef dest=%p", BM_ELEM_SELECT, bm_new); + EDBM_op_callf(em, wmop, "del geom=%hvef context=%i", BM_ELEM_SELECT, DEL_FACES); /* clean up any loose edges */ BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { @@ -3113,7 +3068,7 @@ static int mesh_separate_selected(Main *bmain, Scene *scene, Base *editbase, wmO BM_elem_select_set(em->bm, e, FALSE); } } - EDBM_CallOpf(em, wmop, "del geom=%hvef context=%i", BM_ELEM_SELECT, DEL_EDGES); + EDBM_op_callf(em, wmop, "del geom=%hvef context=%i", BM_ELEM_SELECT, DEL_EDGES); /* clean up any loose verts */ BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { @@ -3125,11 +3080,11 @@ static int mesh_separate_selected(Main *bmain, Scene *scene, Base *editbase, wmO } } - EDBM_CallOpf(em, wmop, "del geom=%hvef context=%i", BM_ELEM_SELECT, DEL_VERTS); + EDBM_op_callf(em, wmop, "del geom=%hvef context=%i", BM_ELEM_SELECT, DEL_VERTS); BM_mesh_normals_update(bm_new, TRUE); - BMO_op_callf(bm_new, "bmesh_to_mesh mesh=%p object=%p notessellation=%b", - basenew->object->data, basenew->object, TRUE); + + BM_mesh_bm_to_me(bm_new, basenew->object->data, FALSE); BM_mesh_free(bm_new); ((Mesh *)basenew->object->data)->edit_btmesh = NULL; @@ -3191,7 +3146,8 @@ static int mesh_separate_loose(Main *bmain, Scene *scene, Base *editbase, wmOper /* Walk from the single vertex, selecting everything connected * to it */ BMW_init(&walker, bm, BMW_SHELL, - BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, + BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, + BMW_FLAG_NOP, /* BMESH_TODO - should be BMW_FLAG_TEST_HIDDEN ? */ BMW_NIL_LAY); e = BMW_begin(&walker, v_seed); @@ -3230,10 +3186,11 @@ static int edbm_separate_exec(bContext *C, wmOperator *op) retval = mesh_separate_material(bmain, scene, base, op); else if (type == 2) retval = mesh_separate_loose(bmain, scene, base, op); - + if (retval) { - DAG_id_tag_update(base->object->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, base->object->data); + BMEditMesh *em = BMEdit_FromObject(base->object); + EDBM_update_generic(C, em, TRUE); + return OPERATOR_FINISHED; } @@ -3274,21 +3231,20 @@ static int edbm_fill_exec(bContext *C, wmOperator *op) BMEditMesh *em = BMEdit_FromObject(obedit); BMOperator bmop; - if (!EDBM_InitOpf(em, &bmop, op, "triangle_fill edges=%he", BM_ELEM_SELECT)) { + if (!EDBM_op_init(em, &bmop, op, "triangle_fill edges=%he", BM_ELEM_SELECT)) { return OPERATOR_CANCELLED; } BMO_op_exec(em->bm, &bmop); /* select new geometry */ - BMO_slot_buffer_hflag_enable(em->bm, &bmop, "geomout", BM_FACE|BM_EDGE, BM_ELEM_SELECT, TRUE); + BMO_slot_buffer_hflag_enable(em->bm, &bmop, "geomout", BM_FACE | BM_EDGE, BM_ELEM_SELECT, TRUE); - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } - - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; @@ -3305,7 +3261,7 @@ void MESH_OT_fill(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int edbm_beautify_fill_exec(bContext *C, wmOperator *op) @@ -3313,11 +3269,10 @@ static int edbm_beautify_fill_exec(bContext *C, wmOperator *op) Object *obedit = CTX_data_edit_object(C); BMEditMesh *em = BMEdit_FromObject(obedit); - if (!EDBM_CallOpf(em, op, "beautify_fill faces=%hf", BM_ELEM_SELECT)) + if (!EDBM_op_callf(em, op, "beautify_fill faces=%hf", BM_ELEM_SELECT)) return OPERATOR_CANCELLED; - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -3333,7 +3288,7 @@ void MESH_OT_beautify_fill(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /********************** Quad/Tri Operators *************************/ @@ -3344,11 +3299,10 @@ static int edbm_quads_convert_to_tris_exec(bContext *C, wmOperator *op) BMEditMesh *em = BMEdit_FromObject(obedit); int use_beauty = RNA_boolean_get(op->ptr, "use_beauty"); - if (!EDBM_CallOpf(em, op, "triangulate faces=%hf use_beauty=%b", BM_ELEM_SELECT, use_beauty)) + if (!EDBM_op_callf(em, op, "triangulate faces=%hf use_beauty=%b", BM_ELEM_SELECT, use_beauty)) return OPERATOR_CANCELLED; - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -3364,7 +3318,7 @@ void MESH_OT_quads_convert_to_tris(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_boolean(ot->srna, "use_beauty", 1, "Beauty", "Use best triangulation division (currently quads only)"); } @@ -3381,15 +3335,14 @@ static int edbm_tris_convert_to_quads_exec(bContext *C, wmOperator *op) dovcols = RNA_boolean_get(op->ptr, "vcols"); domaterials = RNA_boolean_get(op->ptr, "materials"); - if (!EDBM_CallOpf(em, op, - "join_triangles faces=%hf limit=%f cmp_sharp=%b cmp_uvs=%b cmp_vcols=%b cmp_materials=%b", - BM_ELEM_SELECT, limit, dosharp, douvs, dovcols, domaterials)) + if (!EDBM_op_callf(em, op, + "join_triangles faces=%hf limit=%f cmp_sharp=%b cmp_uvs=%b cmp_vcols=%b cmp_materials=%b", + BM_ELEM_SELECT, limit, dosharp, douvs, dovcols, domaterials)) { return OPERATOR_CANCELLED; } - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -3407,7 +3360,7 @@ void MESH_OT_tris_convert_to_quads(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; prop = RNA_def_float_rotation(ot->srna, "limit", 0, NULL, 0.0f, DEG2RADF(180.0f), "Max Angle", "Angle Limit", 0.0f, DEG2RADF(180.0f)); @@ -3427,21 +3380,19 @@ static int edbm_dissolve_exec(bContext *C, wmOperator *op) int use_verts = RNA_boolean_get(op->ptr, "use_verts"); if (em->selectmode & SCE_SELECT_FACE) { - if (!EDBM_CallOpf(em, op, "dissolve_faces faces=%hf use_verts=%b", BM_ELEM_SELECT, use_verts)) + if (!EDBM_op_callf(em, op, "dissolve_faces faces=%hf use_verts=%b", BM_ELEM_SELECT, use_verts)) return OPERATOR_CANCELLED; } else if (em->selectmode & SCE_SELECT_EDGE) { - if (!EDBM_CallOpf(em, op, "dissolve_edges edges=%he use_verts=%b", BM_ELEM_SELECT, use_verts)) + if (!EDBM_op_callf(em, op, "dissolve_edges edges=%he use_verts=%b", BM_ELEM_SELECT, use_verts)) return OPERATOR_CANCELLED; } else if (em->selectmode & SCE_SELECT_VERTEX) { - if (!EDBM_CallOpf(em, op, "dissolve_verts verts=%hv", BM_ELEM_SELECT)) + if (!EDBM_op_callf(em, op, "dissolve_verts verts=%hv", BM_ELEM_SELECT)) return OPERATOR_CANCELLED; } - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - - WM_event_add_notifier(C, NC_GEOM|ND_DATA|ND_SELECT, obedit); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -3458,7 +3409,7 @@ void MESH_OT_dissolve(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* TODO, move dissolve into its own operator so this doesnt confuse non-dissolve options */ RNA_def_boolean(ot->srna, "use_verts", 0, "Dissolve Verts", @@ -3471,15 +3422,14 @@ static int edbm_dissolve_limited_exec(bContext *C, wmOperator *op) BMEditMesh *em = BMEdit_FromObject(obedit); float angle_limit = RNA_float_get(op->ptr, "angle_limit"); - if (!EDBM_CallOpf(em, op, - "dissolve_limit edges=%he verts=%hv angle_limit=%f", - BM_ELEM_SELECT, BM_ELEM_SELECT, angle_limit)) + if (!EDBM_op_callf(em, op, + "dissolve_limit edges=%he verts=%hv angle_limit=%f", + BM_ELEM_SELECT, BM_ELEM_SELECT, angle_limit)) { return OPERATOR_CANCELLED; } - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -3498,7 +3448,7 @@ void MESH_OT_dissolve_limited(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; prop = RNA_def_float_rotation(ot->srna, "angle_limit", 0, NULL, 0.0f, DEG2RADF(180.0f), "Max Angle", "Angle Limit in Degrees", 0.0f, DEG2RADF(180.0f)); @@ -3511,20 +3461,18 @@ static int edbm_split_exec(bContext *C, wmOperator *op) BMEditMesh *em = BMEdit_FromObject(ob); BMOperator bmop; - EDBM_InitOpf(em, &bmop, op, "split geom=%hvef use_only_faces=%b", BM_ELEM_SELECT, FALSE); + EDBM_op_init(em, &bmop, op, "split geom=%hvef use_only_faces=%b", BM_ELEM_SELECT, FALSE); BMO_op_exec(em->bm, &bmop); BM_mesh_elem_flag_disable_all(em->bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT); BMO_slot_buffer_hflag_enable(em->bm, &bmop, "geomout", BM_ALL, BM_ELEM_SELECT, TRUE); - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } /* Geometry has changed, need to recalc normals and looptris */ - BMEdit_RecalcTessellation(em); - EDBM_RecalcNormals(em); + EDBM_mesh_normals_update(em); - DAG_id_tag_update(ob->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -3540,7 +3488,7 @@ void MESH_OT_split(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } @@ -3569,7 +3517,7 @@ static int edbm_spin_exec(bContext *C, wmOperator *op) mul_m3_v3(imat, cent); mul_m3_v3(imat, axis); - if (!EDBM_InitOpf(em, &spinop, op, + if (!EDBM_op_init(em, &spinop, op, "spin geom=%hvef cent=%v axis=%v dvec=%v steps=%i ang=%f do_dupli=%b", BM_ELEM_SELECT, cent, axis, d, steps, degr, dupli)) { @@ -3578,12 +3526,11 @@ static int edbm_spin_exec(bContext *C, wmOperator *op) BMO_op_exec(bm, &spinop); EDBM_flag_disable_all(em, BM_ELEM_SELECT); BMO_slot_buffer_hflag_enable(bm, &spinop, "lastout", BM_ALL, BM_ELEM_SELECT, TRUE); - if (!EDBM_FinishOp(em, &spinop, op, TRUE)) { + if (!EDBM_op_finish(em, &spinop, op, TRUE)) { return OPERATOR_CANCELLED; } - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -3605,6 +3552,7 @@ void MESH_OT_spin(wmOperatorType *ot) { /* identifiers */ ot->name = "Spin"; + ot->description = "Extrude selected vertices in a circle around the cursor in indicated viewport"; ot->idname = "MESH_OT_spin"; /* api callbacks */ @@ -3613,7 +3561,7 @@ void MESH_OT_spin(wmOperatorType *ot) ot->poll = EM_view3d_poll; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, INT_MAX); @@ -3655,13 +3603,11 @@ static int edbm_screw_exec(bContext *C, wmOperator *op) /* find two vertices with valence count == 1, more or less is wrong */ v1 = NULL; v2 = NULL; - for (eve = BM_iter_new(&iter, em->bm, BM_VERTS_OF_MESH, NULL); - eve; eve = BM_iter_step(&iter)) { + for (eve = BM_iter_new(&iter, em->bm, BM_VERTS_OF_MESH, NULL); eve; eve = BM_iter_step(&iter)) { valence = 0; - for (eed = BM_iter_new(&eiter, em->bm, BM_EDGES_OF_VERT, eve); - eed; eed = BM_iter_step(&eiter)) { + for (eed = BM_iter_new(&eiter, em->bm, BM_EDGES_OF_VERT, eve); eed; eed = BM_iter_step(&eiter)) { if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { valence++; @@ -3695,7 +3641,7 @@ static int edbm_screw_exec(bContext *C, wmOperator *op) if (dot_v3v3(nor, dvec) > 0.000f) negate_v3(dvec); - if (!EDBM_InitOpf(em, &spinop, op, + if (!EDBM_op_init(em, &spinop, op, "spin geom=%hvef cent=%v axis=%v dvec=%v steps=%i ang=%f do_dupli=%b", BM_ELEM_SELECT, cent, axis, dvec, turns * steps, 360.0f * turns, FALSE)) { @@ -3704,12 +3650,11 @@ static int edbm_screw_exec(bContext *C, wmOperator *op) BMO_op_exec(bm, &spinop); EDBM_flag_disable_all(em, BM_ELEM_SELECT); BMO_slot_buffer_hflag_enable(bm, &spinop, "lastout", BM_ALL, BM_ELEM_SELECT, TRUE); - if (!EDBM_FinishOp(em, &spinop, op, TRUE)) { + if (!EDBM_op_finish(em, &spinop, op, TRUE)) { return OPERATOR_CANCELLED; } - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -3731,6 +3676,7 @@ void MESH_OT_screw(wmOperatorType *ot) { /* identifiers */ ot->name = "Screw"; + ot->description = "Extrude selected vertices in screw-shaped rotation around the cursor in indicated viewport"; ot->idname = "MESH_OT_screw"; /* api callbacks */ @@ -3739,7 +3685,7 @@ void MESH_OT_screw(wmOperatorType *ot) ot->poll = EM_view3d_poll; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, 256); @@ -3761,7 +3707,7 @@ static int edbm_select_by_number_vertices_exec(bContext *C, wmOperator *op) int type = RNA_enum_get(op->ptr, "type"); for (efa = BM_iter_new(&iter, em->bm, BM_FACES_OF_MESH, NULL); - efa; efa = BM_iter_step(&iter)) { + efa; efa = BM_iter_step(&iter)) { int select = 0; @@ -3785,19 +3731,18 @@ static int edbm_select_by_number_vertices_exec(bContext *C, wmOperator *op) EDBM_selectmode_flush(em); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } void MESH_OT_select_by_number_vertices(wmOperatorType *ot) { static const EnumPropertyItem type_items[] = { - {0, "LESS", 0, "Less Than", ""}, - {1, "EQUAL", 0, "Equal To", ""}, - {2, "GREATER", 0, "Greater Than", ""}, - {3, "NOTEQUAL", 0, "Not Equal To", ""}, - {0, NULL, 0, NULL, NULL} - }; + {0, "LESS", 0, "Less Than", ""}, + {1, "EQUAL", 0, "Equal To", ""}, + {2, "GREATER", 0, "Greater Than", ""}, + {3, "NOTEQUAL", 0, "Not Equal To", ""}, + {0, NULL, 0, NULL, NULL}}; /* identifiers */ ot->name = "Select by Number of Vertices"; @@ -3809,7 +3754,7 @@ void MESH_OT_select_by_number_vertices(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ RNA_def_int(ot->srna, "number", 4, 3, INT_MAX, "Number of Vertices", "", 3, INT_MAX); @@ -3825,7 +3770,7 @@ static int edbm_select_loose_verts_exec(bContext *C, wmOperator *UNUSED(op)) BMIter iter; for (eve = BM_iter_new(&iter, em->bm, BM_VERTS_OF_MESH, NULL); - eve; eve = BM_iter_step(&iter)) { + eve; eve = BM_iter_step(&iter)) { if (!eve->e) { BM_elem_select_set(em->bm, eve, TRUE); @@ -3833,7 +3778,7 @@ static int edbm_select_loose_verts_exec(bContext *C, wmOperator *UNUSED(op)) } for (eed = BM_iter_new(&iter, em->bm, BM_EDGES_OF_MESH, NULL); - eed; eed = BM_iter_step(&iter)) { + eed; eed = BM_iter_step(&iter)) { if (!eed->l) { BM_elem_select_set(em->bm, eed, TRUE); @@ -3842,7 +3787,7 @@ static int edbm_select_loose_verts_exec(bContext *C, wmOperator *UNUSED(op)) EDBM_selectmode_flush(em); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -3858,7 +3803,7 @@ void MESH_OT_select_loose_verts(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int edbm_select_mirror_exec(bContext *C, wmOperator *op) @@ -3869,7 +3814,7 @@ static int edbm_select_mirror_exec(bContext *C, wmOperator *op) EDBM_select_mirrored(obedit, em, extend); EDBM_selectmode_flush(em); - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -3886,7 +3831,7 @@ void MESH_OT_select_mirror(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the existing selection"); @@ -3908,8 +3853,8 @@ static int vergxco(const void *v1, const void *v2) { const xvertsort *x1 = v1, *x2 = v2; - if (x1->x > x2->x) return 1; - else if (x1->x < x2->x) return -1; + if (x1->x > x2->x) return 1; + else if (x1->x < x2->x) return -1; return 0; } @@ -3922,8 +3867,8 @@ static int vergface(const void *v1, const void *v2) { const struct facesort *x1 = v1, *x2 = v2; - if (x1->x > x2->x) return 1; - else if (x1->x < x2->x) return -1; + if (x1->x > x2->x) return 1; + else if (x1->x < x2->x) return -1; return 0; } #endif @@ -3957,7 +3902,8 @@ static void xsortvert_flag(bContext *UNUSED(C), int UNUSED(flag)) amount = em->bm->totvert; sortblock = MEM_callocN(sizeof(xvertsort) * amount, "xsort"); - BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { + BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) + { if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) sortblock[i].v1 = eve; } @@ -3967,7 +3913,7 @@ static void xsortvert_flag(bContext *UNUSED(C), int UNUSED(flag)) qsort(sortblock, amount, sizeof(xvertsort), vergxco); - /* make temporal listbase */ + /* make temporal listbase */ tbase.first = tbase.last = 0; for (i = 0; i < amount; i++) { eve = sortblock[i].v1; @@ -4004,7 +3950,7 @@ void MESH_OT_vertices_sort(wmOperatorType *ot) ot->poll = EM_view3d_poll; /* uses view relative X axis to sort verts */ /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ********************** SORT FACES ******************* */ @@ -4100,7 +4046,7 @@ static int edbm_sort_faces_exec(bContext *C, wmOperator *op) float cur[3]; if (event == 1) - mult_m4_m4m4(mat, rv3d->viewmat, OBACT->obmat); /* apply the view matrix to the object matrix */ + mult_m4_m4m4(mat, rv3d->viewmat, OBACT->obmat); /* apply the view matrix to the object matrix */ else if (event == 2) { /* sort from cursor */ if (v3d && v3d->localvd) { copy_v3_v3(cur, v3d->cursor); @@ -4183,7 +4129,7 @@ void MESH_OT_sort_faces(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", ""); @@ -4274,7 +4220,7 @@ void MESH_OT_vertices_randomize(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /******end of qsort stuff ****/ @@ -4326,10 +4272,9 @@ static int edbm_noise_exec(bContext *C, wmOperator *op) } } - EDBM_RecalcNormals(em); + EDBM_mesh_normals_update(em); - DAG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -4346,7 +4291,7 @@ void MESH_OT_noise(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_float(ot->srna, "factor", 0.1f, -FLT_MAX, FLT_MAX, "Factor", "", 0.0f, 1.0f); } @@ -4399,7 +4344,7 @@ static int edbm_bevel_exec(bContext *C, wmOperator *op) for (i = 0; i < recursion; i++) { float fac = w[recursion - i - 1] * factor; - if (!EDBM_InitOpf(em, &bmop, op, + if (!EDBM_op_init(em, &bmop, op, "bevel geom=%hev percent=%f lengthlayer=%i use_lengths=%b use_even=%b use_dist=%b", BM_ELEM_SELECT, fac, li, TRUE, use_even, use_dist)) { @@ -4407,7 +4352,7 @@ static int edbm_bevel_exec(bContext *C, wmOperator *op) } BMO_op_exec(em->bm, &bmop); - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) + if (!EDBM_op_finish(em, &bmop, op, TRUE)) return OPERATOR_CANCELLED; } @@ -4415,10 +4360,9 @@ static int edbm_bevel_exec(bContext *C, wmOperator *op) MEM_freeN(w); - EDBM_RecalcNormals(em); + EDBM_mesh_normals_update(em); - DAG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -4435,7 +4379,7 @@ void MESH_OT_bevel(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_float(ot->srna, "percent", 0.5f, -FLT_MAX, FLT_MAX, "Percentage", "", 0.0f, 1.0f); RNA_def_int(ot->srna, "recursion", 1, 1, 50, "Recursion Level", "Recursion Level", 1, 8); @@ -4450,11 +4394,10 @@ static int edbm_bridge_edge_loops_exec(bContext *C, wmOperator *op) Object *obedit = CTX_data_edit_object(C); BMEditMesh *em = BMEdit_FromObject(obedit); - if (!EDBM_CallOpf(em, op, "bridge_loops edges=%he", BM_ELEM_SELECT)) + if (!EDBM_op_callf(em, op, "bridge_loops edges=%he", BM_ELEM_SELECT)) return OPERATOR_CANCELLED; - DAG_id_tag_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } @@ -4471,7 +4414,7 @@ void MESH_OT_bridge_edge_loops(wmOperatorType *ot) ot->poll = ED_operator_editmesh; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_boolean(ot->srna, "inside", 0, "Inside", ""); } @@ -4489,7 +4432,7 @@ static int edbm_inset_exec(bContext *C, wmOperator *op) const float thickness = RNA_float_get(op->ptr, "thickness"); const int use_outset = RNA_boolean_get(op->ptr, "use_outset"); - EDBM_InitOpf(em, &bmop, op, + EDBM_op_init(em, &bmop, op, "inset faces=%hf use_boundary=%b use_even_offset=%b use_relative_offset=%b thickness=%f use_outset=%b", BM_ELEM_SELECT, use_boundary, use_even_offset, use_relative_offset, thickness, use_outset); @@ -4500,13 +4443,11 @@ static int edbm_inset_exec(bContext *C, wmOperator *op) BMO_slot_buffer_hflag_enable(em->bm, &bmop, "faceout", BM_FACE, BM_ELEM_SELECT, TRUE); - if (!EDBM_FinishOp(em, &bmop, op, TRUE)) { + if (!EDBM_op_finish(em, &bmop, op, TRUE)) { return OPERATOR_CANCELLED; } else { - DAG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); - + EDBM_update_generic(C, em, TRUE); return OPERATOR_FINISHED; } } @@ -4525,7 +4466,7 @@ void MESH_OT_inset(wmOperatorType *ot) ot->description = ""; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ // RNA_def_boolean(ot->srna, "use_boundary", TRUE, "Boundary", "Inset face boundries"); @@ -4536,7 +4477,7 @@ void MESH_OT_inset(wmOperatorType *ot) /* use 1 rather then 10 for max else dragging the button moves too far */ RNA_def_property_ui_range(prop, 0.0, 1.0, 0.01, 4); - RNA_def_boolean(ot->srna, "use_outset", FALSE, "Outset", "outset rather then inset"); + RNA_def_boolean(ot->srna, "use_outset", FALSE, "Outset", "Outset rather than inset"); } static int edbm_mark_freestyle_edge(bContext *C, wmOperator *op) diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c index bf37dbbea2e..f824a9062c9 100644 --- a/source/blender/editors/mesh/editmesh_utils.c +++ b/source/blender/editors/mesh/editmesh_utils.c @@ -41,6 +41,7 @@ #include "BKE_DerivedMesh.h" #include "BKE_bmesh.h" #include "BKE_context.h" +#include "BKE_depsgraph.h" #include "BKE_key.h" #include "BKE_library.h" #include "BKE_mesh.h" @@ -55,12 +56,14 @@ #include "bmesh.h" -void EDBM_RecalcNormals(BMEditMesh *em) +#include "mesh_intern.h" + +void EDBM_mesh_normals_update(BMEditMesh *em) { BM_mesh_normals_update(em->bm, TRUE); } -void EDBM_ClearMesh(BMEditMesh *em) +void EDBM_mesh_clear(BMEditMesh *em) { /* clear bmesh */ BM_mesh_clear(em->bm); @@ -110,7 +113,7 @@ void EDBM_stats_update(BMEditMesh *em) } } -int EDBM_InitOpf(BMEditMesh *em, BMOperator *bmop, wmOperator *op, const char *fmt, ...) +int EDBM_op_init(BMEditMesh *em, BMOperator *bmop, wmOperator *op, const char *fmt, ...) { BMesh *bm = em->bm; va_list list; @@ -134,7 +137,7 @@ int EDBM_InitOpf(BMEditMesh *em, BMOperator *bmop, wmOperator *op, const char *f /* returns 0 on error, 1 on success. executes and finishes a bmesh operator */ -int EDBM_FinishOp(BMEditMesh *em, BMOperator *bmop, wmOperator *op, const int report) +int EDBM_op_finish(BMEditMesh *em, BMOperator *bmop, wmOperator *op, const int report) { const char *errmsg; @@ -143,16 +146,24 @@ int EDBM_FinishOp(BMEditMesh *em, BMOperator *bmop, wmOperator *op, const int re if (BMO_error_get(em->bm, &errmsg, NULL)) { BMEditMesh *emcopy = em->emcopy; - if (report) BKE_report(op->reports, RPT_ERROR, errmsg); + if (report) { + BKE_report(op->reports, RPT_ERROR, errmsg); + } BMEdit_Free(em); *em = *emcopy; - BMEdit_RecalcTessellation(em); MEM_freeN(emcopy); em->emcopyusers = 0; em->emcopy = NULL; - return 0; + + /* when copying, tessellation isn't to for faster copying, + * but means we need to re-tessellate here */ + if (em->looptris == NULL) { + BMEdit_RecalcTessellation(em); + } + + return FALSE; } else { em->emcopyusers--; @@ -165,12 +176,12 @@ int EDBM_FinishOp(BMEditMesh *em, BMOperator *bmop, wmOperator *op, const int re MEM_freeN(em->emcopy); em->emcopy = NULL; } - } - return 1; + return TRUE; + } } -int EDBM_CallOpf(BMEditMesh *em, wmOperator *op, const char *fmt, ...) +int EDBM_op_callf(BMEditMesh *em, wmOperator *op, const char *fmt, ...) { BMesh *bm = em->bm; BMOperator bmop; @@ -191,10 +202,10 @@ int EDBM_CallOpf(BMEditMesh *em, wmOperator *op, const char *fmt, ...) BMO_op_exec(bm, &bmop); va_end(list); - return EDBM_FinishOp(em, &bmop, op, TRUE); + return EDBM_op_finish(em, &bmop, op, TRUE); } -int EDBM_CallAndSelectOpf(BMEditMesh *em, wmOperator *op, const char *selectslot, const char *fmt, ...) +int EDBM_op_call_and_selectf(BMEditMesh *em, wmOperator *op, const char *selectslot, const char *fmt, ...) { BMesh *bm = em->bm; BMOperator bmop; @@ -214,15 +225,15 @@ int EDBM_CallAndSelectOpf(BMEditMesh *em, wmOperator *op, const char *selectslot BMO_op_exec(bm, &bmop); - BM_mesh_elem_flag_disable_all(em->bm, BM_VERT|BM_EDGE|BM_FACE, BM_ELEM_SELECT); + BM_mesh_elem_flag_disable_all(em->bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT); BMO_slot_buffer_hflag_enable(em->bm, &bmop, selectslot, BM_ALL, BM_ELEM_SELECT, TRUE); va_end(list); - return EDBM_FinishOp(em, &bmop, op, TRUE); + return EDBM_op_finish(em, &bmop, op, TRUE); } -int EDBM_CallOpfSilent(BMEditMesh *em, const char *fmt, ...) +int EDBM_op_call_silentf(BMEditMesh *em, const char *fmt, ...) { BMesh *bm = em->bm; BMOperator bmop; @@ -242,7 +253,7 @@ int EDBM_CallOpfSilent(BMEditMesh *em, const char *fmt, ...) BMO_op_exec(bm, &bmop); va_end(list); - return EDBM_FinishOp(em, &bmop, NULL, FALSE); + return EDBM_op_finish(em, &bmop, NULL, FALSE); } void EDBM_selectmode_to_scene(bContext *C) @@ -257,24 +268,20 @@ void EDBM_selectmode_to_scene(bContext *C) scene->toolsettings->selectmode = em->selectmode; /* Request redraw of header buttons (to show new select mode) */ - WM_event_add_notifier(C, NC_SCENE|ND_TOOLSETTINGS, scene); + WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, scene); } -void EDBM_MakeEditBMesh(ToolSettings *ts, Scene *UNUSED(scene), Object *ob) +void EDBM_mesh_make(ToolSettings *ts, Scene *UNUSED(scene), Object *ob) { Mesh *me = ob->data; BMesh *bm; - if (!me->mpoly && me->totface) { - fprintf(stderr, "%s: bmesh conversion issue! may lose lots of geometry! (bmesh internal error)\n", __func__); - - /* BMESH_TODO need to write smarter code here */ - bm = BKE_mesh_to_bmesh(me, ob); - } - else { - bm = BKE_mesh_to_bmesh(me, ob); + if (UNLIKELY(!me->mpoly && me->totface)) { + BKE_mesh_convert_mfaces_to_mpolys(me); } + bm = BKE_mesh_to_bmesh(me, ob); + if (me->edit_btmesh) { /* this happens when switching shape keys */ BMEdit_Free(me->edit_btmesh); @@ -294,12 +301,12 @@ void EDBM_MakeEditBMesh(ToolSettings *ts, Scene *UNUSED(scene), Object *ob) me->edit_btmesh->ob = ob; } -void EDBM_LoadEditBMesh(Scene *scene, Object *ob) +void EDBM_mesh_load(Object *ob) { Mesh *me = ob->data; BMesh *bm = me->edit_btmesh->bm; - BMO_op_callf(bm, "object_load_bmesh scene=%p object=%p", scene, ob); + BM_mesh_bm_to_me(bm, me, FALSE); #ifdef USE_TESSFACE_DEFAULT BKE_mesh_tessface_calc(me); @@ -307,14 +314,14 @@ void EDBM_LoadEditBMesh(Scene *scene, Object *ob) } -void EDBM_FreeEditBMesh(BMEditMesh *tm) +void EDBM_mesh_free(BMEditMesh *tm) { BMEdit_Free(tm); } -void EDBM_init_index_arrays(BMEditMesh *tm, int forvert, int foredge, int forface) +void EDBM_index_arrays_init(BMEditMesh *tm, int forvert, int foredge, int forface) { - EDBM_free_index_arrays(tm); + EDBM_index_arrays_free(tm); if (forvert) { BMIter iter; @@ -356,7 +363,7 @@ void EDBM_init_index_arrays(BMEditMesh *tm, int forvert, int foredge, int forfac } } -void EDBM_free_index_arrays(BMEditMesh *tm) +void EDBM_index_arrays_free(BMEditMesh *tm) { if (tm->vert_index) { MEM_freeN(tm->vert_index); @@ -374,17 +381,17 @@ void EDBM_free_index_arrays(BMEditMesh *tm) } } -BMVert *EDBM_get_vert_for_index(BMEditMesh *tm, int index) +BMVert *EDBM_vert_at_index(BMEditMesh *tm, int index) { - return tm->vert_index && index < tm->bm->totvert ?tm->vert_index[index]:NULL; + return tm->vert_index && index < tm->bm->totvert ? tm->vert_index[index] : NULL; } -BMEdge *EDBM_get_edge_for_index(BMEditMesh *tm, int index) +BMEdge *EDBM_edge_at_index(BMEditMesh *tm, int index) { - return tm->edge_index && index < tm->bm->totedge ?tm->edge_index[index]:NULL; + return tm->edge_index && index < tm->bm->totedge ? tm->edge_index[index] : NULL; } -BMFace *EDBM_get_face_for_index(BMEditMesh *tm, int index) +BMFace *EDBM_face_at_index(BMEditMesh *tm, int index) { return (tm->face_index && index < tm->bm->totface && index >= 0) ? tm->face_index[index] : NULL; } @@ -448,7 +455,7 @@ void EDBM_select_less(BMEditMesh *em) EDBM_selectmode_flush(em); } -int EDBM_get_actSelection(BMEditMesh *em, BMEditSelection *ese) +int EDBM_editselection_active_get(BMEditMesh *em, BMEditSelection *ese) { BMEditSelection *ese_last = em->bm->selected.last; BMFace *efa = BM_active_face_get(em->bm, FALSE); @@ -483,12 +490,12 @@ int EDBM_get_actSelection(BMEditMesh *em, BMEditSelection *ese) void EDBM_flag_disable_all(BMEditMesh *em, const char hflag) { - BM_mesh_elem_flag_disable_all(em->bm, BM_VERT|BM_EDGE|BM_FACE, hflag); + BM_mesh_elem_flag_disable_all(em->bm, BM_VERT | BM_EDGE | BM_FACE, hflag); } void EDBM_flag_enable_all(BMEditMesh *em, const char hflag) { - BM_mesh_elem_flag_enable_all(em->bm, BM_VERT|BM_EDGE|BM_FACE, hflag); + BM_mesh_elem_flag_enable_all(em->bm, BM_VERT | BM_EDGE | BM_FACE, hflag); } /**************-------------- Undo ------------*****************/ @@ -505,11 +512,11 @@ static void *getEditMesh(bContext *C) return NULL; } -typedef struct undomesh { +typedef struct UndoMesh { Mesh me; int selectmode; char obname[MAX_ID_NAME - 2]; -} undomesh; +} UndoMesh; /* undo simply makes copies of a bmesh */ static void *editbtMesh_to_undoMesh(void *emv, void *obdata) @@ -517,33 +524,26 @@ static void *editbtMesh_to_undoMesh(void *emv, void *obdata) BMEditMesh *em = emv; Mesh *obme = obdata; - undomesh *um = MEM_callocN(sizeof(undomesh), "undo Mesh"); + UndoMesh *um = MEM_callocN(sizeof(UndoMesh), "undo Mesh"); BLI_strncpy(um->obname, em->ob->id.name + 2, sizeof(um->obname)); /* make sure shape keys work */ um->me.key = obme->key ? copy_key_nolib(obme->key) : NULL; -#ifdef BMESH_EM_UNDO_RECALC_TESSFACE_WORKAROUND - - /* we recalc the tessellation here, to avoid seeding calls to - * BMEdit_RecalcTessellation throughout the code. */ - BMEdit_RecalcTessellation(em); - -#endif - /* BM_mesh_validate(em->bm); */ /* for troubleshooting */ - BMO_op_callf(em->bm, "bmesh_to_mesh mesh=%p notessellation=%b", &um->me, TRUE); + BM_mesh_bm_to_me(em->bm, &um->me, FALSE); + um->selectmode = em->selectmode; return um; } -static void undoMesh_to_editbtMesh(void *umv, void *emv, void *UNUSED(obdata)) +static void undoMesh_to_editbtMesh(void *umv, void *em_v, void *UNUSED(obdata)) { - BMEditMesh *em = emv, *em2; + BMEditMesh *em = em_v, *em_tmp; Object *ob; - undomesh *um = umv; + UndoMesh *um = umv; BMesh *bm; /* BMESH_TODO - its possible the name wont be found right?, should fallback */ @@ -553,26 +553,31 @@ static void undoMesh_to_editbtMesh(void *umv, void *emv, void *UNUSED(obdata)) BMEdit_Free(em); bm = BM_mesh_create(&bm_mesh_allocsize_default); - BMO_op_callf(bm, "mesh_to_bmesh mesh=%p object=%p set_shapekey=%b", &um->me, ob, FALSE); - em2 = BMEdit_Create(bm, TRUE); - *em = *em2; + BM_mesh_bm_from_me(bm, &um->me, FALSE, ob->shapenr); + + /* face normals need recalculation since we are not calling through an operator */ + BM_mesh_normals_update(bm, TRUE); + + em_tmp = BMEdit_Create(bm, TRUE); + *em = *em_tmp; em->selectmode = um->selectmode; + em->ob = ob; - MEM_freeN(em2); + MEM_freeN(em_tmp); } - -static void free_undo(void *umv) +static void free_undo(void *me_v) { - if (((Mesh *)umv)->key) { - free_key(((Mesh *)umv)->key); - MEM_freeN(((Mesh *)umv)->key); + Mesh *me = me_v; + if (me->key) { + free_key(me->key); + MEM_freeN(me->key); } - - free_mesh(umv, 0); - MEM_freeN(umv); + + free_mesh(me, FALSE); + MEM_freeN(me); } /* and this is all the undo system needs to know */ @@ -589,7 +594,7 @@ void undo_push_mesh(bContext *C, const char *name) } /* write comment here */ -UvVertMap *EDBM_make_uv_vert_map(BMEditMesh *em, int selected, int do_face_idx_array, float *limit) +UvVertMap *EDBM_uv_vert_map_create(BMEditMesh *em, int selected, int do_face_idx_array, float *limit) { BMVert *ev; BMFace *efa; @@ -604,7 +609,7 @@ UvVertMap *EDBM_make_uv_vert_map(BMEditMesh *em, int selected, int do_face_idx_a int totverts, i, totuv; if (do_face_idx_array) - EDBM_init_index_arrays(em, 0, 0, 1); + EDBM_index_arrays_init(em, 0, 0, 1); BM_mesh_elem_index_ensure(em->bm, BM_VERT); @@ -619,13 +624,13 @@ UvVertMap *EDBM_make_uv_vert_map(BMEditMesh *em, int selected, int do_face_idx_a if (totuv == 0) { if (do_face_idx_array) - EDBM_free_index_arrays(em); + EDBM_index_arrays_free(em); return NULL; } vmap = (UvVertMap *)MEM_callocN(sizeof(*vmap), "UvVertMap"); if (!vmap) { if (do_face_idx_array) - EDBM_free_index_arrays(em); + EDBM_index_arrays_free(em); return NULL; } @@ -635,7 +640,7 @@ UvVertMap *EDBM_make_uv_vert_map(BMEditMesh *em, int selected, int do_face_idx_a if (!vmap->vert || !vmap->buf) { free_uv_vert_map(vmap); if (do_face_idx_array) - EDBM_free_index_arrays(em); + EDBM_index_arrays_free(em); return NULL; } @@ -672,7 +677,7 @@ UvVertMap *EDBM_make_uv_vert_map(BMEditMesh *em, int selected, int do_face_idx_a v->next = newvlist; newvlist = v; - efa = EDBM_get_face_for_index(em, v->f); + efa = EDBM_face_at_index(em, v->f); /* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */ l = BM_iter_at_index(em->bm, BM_LOOPS_OF_FACE, efa, v->tfindex); @@ -684,7 +689,7 @@ UvVertMap *EDBM_make_uv_vert_map(BMEditMesh *em, int selected, int do_face_idx_a while (iterv) { next = iterv->next; - efa = EDBM_get_face_for_index(em, iterv->f); + efa = EDBM_face_at_index(em, iterv->f); /* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */ l = BM_iter_at_index(em->bm, BM_LOOPS_OF_FACE, efa, iterv->tfindex); @@ -714,13 +719,13 @@ UvVertMap *EDBM_make_uv_vert_map(BMEditMesh *em, int selected, int do_face_idx_a } if (do_face_idx_array) - EDBM_free_index_arrays(em); + EDBM_index_arrays_free(em); return vmap; } -UvMapVert *EDBM_get_uv_map_vert(UvVertMap *vmap, unsigned int v) +UvMapVert *EDBM_uv_vert_map_at_index(UvVertMap *vmap, unsigned int v) { return vmap->vert[v]; } @@ -729,7 +734,7 @@ UvMapVert *EDBM_get_uv_map_vert(UvVertMap *vmap, unsigned int v) /* A specialized vert map used by stitch operator */ -UvElementMap *EDBM_make_uv_element_map(BMEditMesh *em, int selected, int do_islands) +UvElementMap *EDBM_uv_element_map_create(BMEditMesh *em, int selected, int do_islands) { BMVert *ev; BMFace *efa; @@ -779,7 +784,7 @@ UvElementMap *EDBM_make_uv_element_map(BMEditMesh *em, int selected, int do_isla buf = element_map->buf = (UvElement *)MEM_callocN(sizeof(*element_map->buf) * totuv, "UvElement"); if (!element_map->vert || !element_map->buf) { - EDBM_free_uv_element_map(element_map); + EDBM_uv_element_map_free(element_map); MEM_freeN(island_number); return NULL; } @@ -918,7 +923,7 @@ UvElementMap *EDBM_make_uv_element_map(BMEditMesh *em, int selected, int do_isla MEM_freeN(islandbuf); MEM_freeN(stack); MEM_freeN(map); - EDBM_free_uv_element_map(element_map); + EDBM_uv_element_map_free(element_map); MEM_freeN(island_number); } @@ -948,13 +953,7 @@ UvElementMap *EDBM_make_uv_element_map(BMEditMesh *em, int selected, int do_isla return element_map; } - -UvMapVert *EM_get_uv_map_vert(UvVertMap *vmap, unsigned int v) -{ - return vmap->vert[v]; -} - -void EDBM_free_uv_vert_map(UvVertMap *vmap) +void EDBM_uv_vert_map_free(UvVertMap *vmap) { if (vmap) { if (vmap->vert) MEM_freeN(vmap->vert); @@ -963,7 +962,7 @@ void EDBM_free_uv_vert_map(UvVertMap *vmap) } } -void EDBM_free_uv_element_map(UvElementMap *element_map) +void EDBM_uv_element_map_free(UvElementMap *element_map) { if (element_map) { if (element_map->vert) MEM_freeN(element_map->vert); @@ -975,11 +974,11 @@ void EDBM_free_uv_element_map(UvElementMap *element_map) /* last_sel, use em->act_face otherwise get the last selected face in the editselections * at the moment, last_sel is mainly useful for making sure the space image dosnt flicker */ -MTexPoly *EDBM_get_active_mtexpoly(BMEditMesh *em, BMFace **r_act_efa, int sloppy) +MTexPoly *EDBM_mtexpoly_active_get(BMEditMesh *em, BMFace **r_act_efa, int sloppy) { BMFace *efa = NULL; - if (!EDBM_texFaceCheck(em)) + if (!EDBM_mtexpoly_check(em)) return NULL; efa = BM_active_face_get(em->bm, sloppy); @@ -994,14 +993,14 @@ MTexPoly *EDBM_get_active_mtexpoly(BMEditMesh *em, BMFace **r_act_efa, int slopp } /* can we edit UV's for this mesh?*/ -int EDBM_texFaceCheck(BMEditMesh *em) +int EDBM_mtexpoly_check(BMEditMesh *em) { /* some of these checks could be a touch overkill */ return em && em->bm->totface && CustomData_has_layer(&em->bm->pdata, CD_MTEXPOLY) && - CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV); + CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV); } -int EDBM_vertColorCheck(BMEditMesh *em) +int EDBM_vert_color_check(BMEditMesh *em) { /* some of these checks could be a touch overkill */ return em && em->bm->totface && CustomData_has_layer(&em->bm->ldata, CD_MLOOPCOL); @@ -1013,11 +1012,31 @@ static BMVert *cache_mirr_intptr_as_bmvert(intptr_t *index_lookup, int index) return (eve_i == -1) ? NULL : (BMVert *)eve_i; } +/** + * [note: I've decided to use ideasman's code for non-editmode stuff, but since + * it has a big "not for editmode!" disclaimer, I'm going to keep what I have here + * - joeedh] + * + * x-mirror editing api. usage: + * + * EDBM_verts_mirror_cache_begin(em); + * ... + * ... + * BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { + * mirrorv = EDBM_verts_mirror_get(em, v); + * } + * ... + * ... + * EDBM_verts_mirror_cache_end(em); + * + * \note why do we only allow x axis mirror editing? + */ + /* BM_SEARCH_MAXDIST is too big, copied from 2.6x MOC_THRESH, should become a * preference */ #define BM_SEARCH_MAXDIST_MIRR 0.00002f #define BM_CD_LAYER_ID "__mirror_index" -void EDBM_CacheMirrorVerts(BMEditMesh *em, const short use_select) +void EDBM_verts_mirror_cache_begin(BMEditMesh *em, const short use_select) { Mesh *me = em->me; BMesh *bm = em->bm; @@ -1034,7 +1053,7 @@ void EDBM_CacheMirrorVerts(BMEditMesh *em, const short use_select) } if (!em->vert_index) { - EDBM_init_index_arrays(em, 1, 0, 0); + EDBM_index_arrays_init(em, 1, 0, 0); em->mirr_free_arrays = 1; } @@ -1052,7 +1071,7 @@ void EDBM_CacheMirrorVerts(BMEditMesh *em, const short use_select) ED_mesh_mirrtopo_init(me, -1, &mesh_topo_store, TRUE); } else { - tree = BMBVH_NewBVH(em, 0, NULL, NULL); + tree = BMBVH_NewBVH(em, 0, NULL, NULL); } BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) { @@ -1096,7 +1115,7 @@ void EDBM_CacheMirrorVerts(BMEditMesh *em, const short use_select) em->mirror_cdlayer = li; } -BMVert *EDBM_GetMirrorVert(BMEditMesh *em, BMVert *v) +BMVert *EDBM_verts_mirror_get(BMEditMesh *em, BMVert *v) { int *mirr = CustomData_bmesh_get_layer_n(&em->bm->vdata, v->head.data, em->mirror_cdlayer); @@ -1105,7 +1124,7 @@ BMVert *EDBM_GetMirrorVert(BMEditMesh *em, BMVert *v) if (mirr && *mirr >= 0 && *mirr < em->bm->totvert) { if (!em->vert_index) { printf("err: should only be called between " - "EDBM_CacheMirrorVerts and EDBM_EndMirrorCache"); + "EDBM_verts_mirror_cache_begin and EDBM_verts_mirror_cache_end"); return NULL; } @@ -1115,7 +1134,7 @@ BMVert *EDBM_GetMirrorVert(BMEditMesh *em, BMVert *v) return NULL; } -void EDBM_ClearMirrorVert(BMEditMesh *em, BMVert *v) +void EDBM_verts_mirror_cache_clear(BMEditMesh *em, BMVert *v) { int *mirr = CustomData_bmesh_get_layer_n(&em->bm->vdata, v->head.data, em->mirror_cdlayer); @@ -1126,7 +1145,7 @@ void EDBM_ClearMirrorVert(BMEditMesh *em, BMVert *v) } } -void EDBM_EndMirrorCache(BMEditMesh *em) +void EDBM_verts_mirror_cache_end(BMEditMesh *em) { if (em->mirr_free_arrays) { MEM_freeN(em->vert_index); @@ -1136,7 +1155,7 @@ void EDBM_EndMirrorCache(BMEditMesh *em) em->mirror_cdlayer = -1; } -void EDBM_ApplyMirrorCache(BMEditMesh *em, const int sel_from, const int sel_to) +void EDBM_verts_mirror_apply(BMEditMesh *em, const int sel_from, const int sel_to) { BMIter iter; BMVert *v; @@ -1145,7 +1164,7 @@ void EDBM_ApplyMirrorCache(BMEditMesh *em, const int sel_from, const int sel_to) BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { if (BM_elem_flag_test(v, BM_ELEM_SELECT) == sel_from) { - BMVert *mirr = EDBM_GetMirrorVert(em, v); + BMVert *mirr = EDBM_verts_mirror_get(em, v); if (mirr) { if (BM_elem_flag_test(mirr, BM_ELEM_SELECT) == sel_to) { copy_v3_v3(mirr->co, v->co); @@ -1158,7 +1177,7 @@ void EDBM_ApplyMirrorCache(BMEditMesh *em, const int sel_from, const int sel_to) /* swap is 0 or 1, if 1 it hides not selected */ -void EDBM_hide_mesh(BMEditMesh *em, int swap) +void EDBM_mesh_hide(BMEditMesh *em, int swap) { BMIter iter; BMElem *ele; @@ -1190,7 +1209,7 @@ void EDBM_hide_mesh(BMEditMesh *em, int swap) } -void EDBM_reveal_mesh(BMEditMesh *em) +void EDBM_mesh_reveal(BMEditMesh *em) { const char iter_types[3] = {BM_VERTS_OF_MESH, BM_EDGES_OF_MESH, @@ -1198,8 +1217,7 @@ void EDBM_reveal_mesh(BMEditMesh *em) int sels[3] = {(em->selectmode & SCE_SELECT_VERTEX), (em->selectmode & SCE_SELECT_EDGE), - (em->selectmode & SCE_SELECT_FACE), - }; + (em->selectmode & SCE_SELECT_FACE), }; BMIter iter; BMElem *ele; @@ -1230,6 +1248,23 @@ void EDBM_reveal_mesh(BMEditMesh *em) } EDBM_selectmode_flush(em); + + /* hidden faces can have invalid normals */ + EDBM_mesh_normals_update(em); +} + +/* so many tools call these that we better make it a generic function. + */ +void EDBM_update_generic(bContext *C, BMEditMesh *em, const short do_tessface) +{ + Object *ob = em->ob; + /* order of calling isn't important */ + DAG_id_tag_update(ob->data, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); + + if (do_tessface) { + BMEdit_RecalcTessellation(em); + } } /* * Selection History ***************************************************** */ @@ -1256,17 +1291,17 @@ void EDBM_editselection_plane(BMEditMesh *em, float *plane, BMEditSelection *ese BM_editselection_plane(em->bm, plane, ese); } -void EDBM_remove_selection(BMEditMesh *em, BMElem *ele) +void EDBM_editselection_remove(BMEditMesh *em, BMHeader *ele) { - BM_select_history_remove(em->bm, ele); + BM_select_history_remove(em->bm, (BMElem *)ele); } -void EDBM_store_selection(BMEditMesh *em, BMElem *ele) +void EDBM_editselection_store(BMEditMesh *em, BMHeader *ele) { - BM_select_history_store(em->bm, ele); + BM_select_history_store(em->bm, (BMElem *)ele); } -void EDBM_validate_selections(BMEditMesh *em) +void EDBM_editselection_validate(BMEditMesh *em) { BM_select_history_validate(em->bm); } diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 770fd68079a..69aeee48a4b 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -79,8 +79,8 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la { Mesh *me = ob->data; CustomData *data; - void *actlayerdata, *rndlayerdata, *clonelayerdata, *stencillayerdata, *layerdata=layer->data; - int type= layer->type; + void *actlayerdata, *rndlayerdata, *clonelayerdata, *stencillayerdata, *layerdata = layer->data; + int type = layer->type; int index; int i, actindex, rndindex, cloneindex, stencilindex, tot; @@ -135,7 +135,7 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la if (actlayerdata != layerdata) { /* find index */ actindex = CustomData_get_layer_index(data, type); - for (i=actindex; i<data->totlayer; i++) { + for (i = actindex; i < data->totlayer; i++) { if (data->layers[i].data == actlayerdata) { actindex = i - actindex; break; @@ -149,7 +149,7 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la if (rndlayerdata != layerdata) { /* find index */ rndindex = CustomData_get_layer_index(data, type); - for (i=rndindex; i<data->totlayer; i++) { + for (i = rndindex; i < data->totlayer; i++) { if (data->layers[i].data == rndlayerdata) { rndindex = i - rndindex; break; @@ -163,7 +163,7 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la if (clonelayerdata != layerdata) { /* find index */ cloneindex = CustomData_get_layer_index(data, type); - for (i=cloneindex; i<data->totlayer; i++) { + for (i = cloneindex; i < data->totlayer; i++) { if (data->layers[i].data == clonelayerdata) { cloneindex = i - cloneindex; break; @@ -177,7 +177,7 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la if (stencillayerdata != layerdata) { /* find index */ stencilindex = CustomData_get_layer_index(data, type); - for (i=stencilindex; i<data->totlayer; i++) { + for (i = stencilindex; i < data->totlayer; i++) { if (data->layers[i].data == stencillayerdata) { stencilindex = i - stencilindex; break; @@ -189,26 +189,45 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la } } -static void copy_editface_active_customdata(BMEditMesh *em, int type, int index) +/* copies from active to 'index' */ +static void editmesh_face_copy_customdata(BMEditMesh *em, int type, int index) { -#if 1 /*BMESH_TODO*/ - (void)em; - (void)type; - (void)index; -#else - EditFace *efa; - int n= CustomData_get_active_layer(&em->fdata, type); + BMesh *bm = em->bm; + CustomData *pdata = &bm->pdata; + BMIter iter; + BMFace *efa; + const int n = CustomData_get_active_layer(pdata, type); + + /* ensure all current elements follow new customdata layout */ + BM_ITER(efa, &iter, bm, BM_FACES_OF_MESH, NULL) { + void *data = CustomData_bmesh_get_n(pdata, efa->head.data, type, n); + CustomData_bmesh_set_n(pdata, efa->head.data, type, index, data); + } +} - for (efa= em->faces.first; efa; efa= efa->next) { - void *data= CustomData_em_get_n(&em->fdata, efa->data, type, n); - CustomData_em_set_n(&em->fdata, efa->data, type, index, data); +/* copies from active to 'index' */ +static void editmesh_loop_copy_customdata(BMEditMesh *em, int type, int index) +{ + BMesh *bm = em->bm; + CustomData *ldata = &bm->ldata; + BMIter iter; + BMIter liter; + BMFace *efa; + BMLoop *loop; + const int n = CustomData_get_active_layer(ldata, type); + + /* ensure all current elements follow new customdata layout */ + BM_ITER(efa, &iter, bm, BM_FACES_OF_MESH, NULL) { + BM_ITER(loop, &liter, bm, BM_LOOPS_OF_FACE, efa) { + void *data = CustomData_bmesh_get_n(ldata, loop->head.data, type, n); + CustomData_bmesh_set_n(ldata, loop->head.data, type, index, data); + } } -#endif } -int ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me) +int ED_mesh_uv_loop_reset_ex(struct bContext *C, struct Mesh *me, const int layernum) { - BMEditMesh *em= me->edit_btmesh; + BMEditMesh *em = me->edit_btmesh; MLoopUV *luv; BLI_array_declare(polylengths); int *polylengths = NULL; @@ -232,7 +251,7 @@ int ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me) i = 0; BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { - luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get_n(&em->bm->ldata, l->head.data, CD_MLOOPUV, layernum); BLI_array_append(uvs, luv->uv); i++; } @@ -244,14 +263,16 @@ int ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me) /* Collect Mesh UVs */ MPoly *mp; + MLoopUV *mloouv; BLI_assert(CustomData_has_layer(&me->ldata, CD_MLOOPUV)); + mloouv = CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, layernum); for (j = 0; j < me->totpoly; j++) { mp = &me->mpoly[j]; for (i = 0; i < mp->totloop; i++) { - luv = &me->mloopuv[mp->loopstart + i]; + luv = &mloouv[mp->loopstart + i]; BLI_array_append(uvs, luv->uv); } @@ -285,12 +306,12 @@ int ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me) fuvs[3][0] = 0.0; fuvs[3][1] = 1.0; - /*make sure we ignore 2-sided faces*/ + /*make sure we ignore 2-sided faces*/ } else if (len > 2) { float fac = 0.0f, dfac = 1.0f / (float)len; - dfac *= M_PI*2; + dfac *= M_PI * 2; for (i = 0; i < len; i++) { fuvs[i][0] = 0.5f * sin(fac) + 0.5f; @@ -303,45 +324,55 @@ int ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me) fuvs += len; } - /* BMESH_TODO: Copy poly UVs onto CD_MTFACE layer for tessellated faces */ - BLI_array_free(uvs); BLI_array_free(polylengths); DAG_id_tag_update(&me->id, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); return 1; } +int ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me) +{ + /* could be ldata or pdata */ + CustomData *pdata = GET_CD_DATA(me, pdata); + const int layernum = CustomData_get_active_layer_index(pdata, CD_MTEXPOLY); + return ED_mesh_uv_loop_reset_ex(C, me, layernum); +} + +/* note: keep in sync with ED_mesh_color_add */ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_set) { BMEditMesh *em; int layernum; + short is_init = FALSE; + if (me->edit_btmesh) { - em= me->edit_btmesh; + em = me->edit_btmesh; layernum = CustomData_number_of_layers(&em->bm->pdata, CD_MTEXPOLY); if (layernum >= MAX_MTFACE) return -1; - BM_data_layer_add(em->bm, &em->bm->pdata, CD_MTEXPOLY); - CustomData_set_layer_active(&em->bm->pdata, CD_MTEXPOLY, layernum); - CustomData_set_layer_name(&em->bm->pdata, CD_MTEXPOLY, layernum, name); - + /* CD_MTEXPOLY */ + BM_data_layer_add_named(em->bm, &em->bm->pdata, CD_MTEXPOLY, name); /* copy data from active UV */ - if (layernum) - copy_editface_active_customdata(em, CD_MTFACE, layernum); - + if (layernum) { + editmesh_face_copy_customdata(em, CD_MTEXPOLY, layernum); + } if (active_set || layernum == 0) { CustomData_set_layer_active(&em->bm->pdata, CD_MTEXPOLY, layernum); } - BM_data_layer_add(em->bm, &em->bm->ldata, CD_MLOOPUV); - CustomData_set_layer_name(&em->bm->ldata, CD_MLOOPUV, layernum, name); - - CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPUV, layernum); + /* CD_MLOOPUV */ + BM_data_layer_add_named(em->bm, &em->bm->ldata, CD_MLOOPUV, name); + /* copy data from active UV */ + if (layernum) { + editmesh_loop_copy_customdata(em, CD_MLOOPUV, layernum); + is_init = TRUE; + } if (active_set || layernum == 0) { CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPUV, layernum); } @@ -355,6 +386,7 @@ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_s CustomData_add_layer_named(&me->pdata, CD_MTEXPOLY, CD_DUPLICATE, me->mtpoly, me->totpoly, name); CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_DUPLICATE, me->mloopuv, me->totloop, name); CustomData_add_layer_named(&me->fdata, CD_MTFACE, CD_DUPLICATE, me->mtface, me->totface, name); + is_init = TRUE; } else { CustomData_add_layer_named(&me->pdata, CD_MTEXPOLY, CD_DEFAULT, NULL, me->totpoly, name); @@ -372,10 +404,13 @@ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_s mesh_update_customdata_pointers(me, TRUE); } - ED_mesh_uv_loop_reset(C, me); + /* don't overwrite our copied coords */ + if (is_init == FALSE) { + ED_mesh_uv_loop_reset_ex(C, me, layernum); + } DAG_id_tag_update(&me->id, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); return layernum; } @@ -386,11 +421,11 @@ int ED_mesh_uv_texture_remove(bContext *C, Object *ob, Mesh *me) CustomDataLayer *cdlp, *cdlu; int index; - index= CustomData_get_active_layer_index(pdata, CD_MTEXPOLY); - cdlp= (index == -1)? NULL: &pdata->layers[index]; + index = CustomData_get_active_layer_index(pdata, CD_MTEXPOLY); + cdlp = (index == -1) ? NULL : &pdata->layers[index]; - index= CustomData_get_active_layer_index(ldata, CD_MLOOPUV); - cdlu= (index == -1)? NULL: &ldata->layers[index]; + index = CustomData_get_active_layer_index(ldata, CD_MLOOPUV); + cdlu = (index == -1) ? NULL : &ldata->layers[index]; if (!cdlp || !cdlu) return 0; @@ -399,38 +434,37 @@ int ED_mesh_uv_texture_remove(bContext *C, Object *ob, Mesh *me) delete_customdata_layer(C, ob, cdlu); DAG_id_tag_update(&me->id, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); return 1; } +/* note: keep in sync with ED_mesh_uv_texture_add */ int ED_mesh_color_add(bContext *C, Scene *UNUSED(scene), Object *UNUSED(ob), Mesh *me, const char *name, int active_set) { BMEditMesh *em; int layernum; if (me->edit_btmesh) { - em= me->edit_btmesh; + em = me->edit_btmesh; - layernum= CustomData_number_of_layers(&em->bm->ldata, CD_MLOOPCOL); + layernum = CustomData_number_of_layers(&em->bm->ldata, CD_MLOOPCOL); if (layernum >= MAX_MCOL) { return -1; } - BM_data_layer_add(em->bm, &em->bm->ldata, CD_MLOOPCOL); - CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPCOL, layernum); - + /* CD_MLOOPCOL */ + BM_data_layer_add_named(em->bm, &em->bm->ldata, CD_MLOOPCOL, name); /* copy data from active vertex color layer */ if (layernum) { - copy_editface_active_customdata(em, CD_MLOOPCOL, layernum); + editmesh_loop_copy_customdata(em, CD_MLOOPCOL, layernum); } - if (active_set || layernum == 0) { CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPCOL, layernum); } } else { - layernum= CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL); + layernum = CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL); if (layernum >= CD_MLOOPCOL) { return -1; } @@ -444,7 +478,7 @@ int ED_mesh_color_add(bContext *C, Scene *UNUSED(scene), Object *UNUSED(ob), Mes CustomData_add_layer_named(&me->fdata, CD_MCOL, CD_DEFAULT, NULL, me->totface, name); } - if (active_set || layernum==0) { + if (active_set || layernum == 0) { CustomData_set_layer_active(&me->ldata, CD_MLOOPCOL, layernum); CustomData_set_layer_active(&me->fdata, CD_MCOL, layernum); } @@ -453,7 +487,7 @@ int ED_mesh_color_add(bContext *C, Scene *UNUSED(scene), Object *UNUSED(ob), Mes } DAG_id_tag_update(&me->id, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); return layernum; } @@ -464,15 +498,15 @@ int ED_mesh_color_remove(bContext *C, Object *ob, Mesh *me) CustomDataLayer *cdl; int index; - index= CustomData_get_active_layer_index(ldata, CD_MLOOPCOL); - cdl= (index == -1)? NULL: &ldata->layers[index]; + index = CustomData_get_active_layer_index(ldata, CD_MLOOPCOL); + cdl = (index == -1) ? NULL : &ldata->layers[index]; if (!cdl) return 0; delete_customdata_layer(C, ob, cdl); DAG_id_tag_update(&me->id, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); return 1; } @@ -483,7 +517,7 @@ int ED_mesh_color_remove_named(bContext *C, Object *ob, Mesh *me, const char *na CustomDataLayer *cdl; int index; - index= CustomData_get_named_layer_index(ldata, CD_MLOOPCOL, name); + index = CustomData_get_named_layer_index(ldata, CD_MLOOPCOL, name); cdl = (index == -1) ? NULL : &ldata->layers[index]; if (!cdl) @@ -491,7 +525,7 @@ int ED_mesh_color_remove_named(bContext *C, Object *ob, Mesh *me, const char *na delete_customdata_layer(C, ob, cdl); DAG_id_tag_update(&me->id, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); return 1; } @@ -500,15 +534,15 @@ int ED_mesh_color_remove_named(bContext *C, Object *ob, Mesh *me, const char *na static int layers_poll(bContext *C) { - Object *ob= ED_object_context(C); - ID *data= (ob)? ob->data: NULL; - return (ob && !ob->id.lib && ob->type==OB_MESH && data && !data->lib); + Object *ob = ED_object_context(C); + ID *data = (ob) ? ob->data : NULL; + return (ob && !ob->id.lib && ob->type == OB_MESH && data && !data->lib); } static int mesh_uv_texture_add_exec(bContext *C, wmOperator *UNUSED(op)) { - Object *ob= ED_object_context(C); - Mesh *me= ob->data; + Object *ob = ED_object_context(C); + Mesh *me = ob->data; if (ED_mesh_uv_texture_add(C, me, NULL, TRUE) == -1) return OPERATOR_CANCELLED; @@ -528,23 +562,23 @@ void MESH_OT_uv_texture_add(wmOperatorType *ot) ot->exec = mesh_uv_texture_add_exec; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int drop_named_image_invoke(bContext *C, wmOperator *op, wmEvent *event) { - Main *bmain= CTX_data_main(C); - Scene *scene= CTX_data_scene(C); - View3D *v3d= CTX_wm_view3d(C); - Base *base= ED_view3d_give_base_under_cursor(C, event->mval); - Image *ima= NULL; + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + View3D *v3d = CTX_wm_view3d(C); + Base *base = ED_view3d_give_base_under_cursor(C, event->mval); + Image *ima = NULL; Mesh *me; Object *obedit; - int exitmode= 0; - char name[MAX_ID_NAME-2]; + int exitmode = 0; + char name[MAX_ID_NAME - 2]; /* Check context */ - if (base==NULL || base->object->type!=OB_MESH) { + if (base == NULL || base->object->type != OB_MESH) { BKE_report(op->reports, RPT_ERROR, "Not an Object or Mesh"); return OPERATOR_CANCELLED; } @@ -554,11 +588,11 @@ static int drop_named_image_invoke(bContext *C, wmOperator *op, wmEvent *event) char path[FILE_MAX]; RNA_string_get(op->ptr, "filepath", path); - ima= BKE_add_image_file(path); + ima = BKE_add_image_file(path); } else { RNA_string_get(op->ptr, "name", name); - ima= (Image *)find_id("IM", name); + ima = (Image *)find_id("IM", name); } if (!ima) { @@ -568,22 +602,22 @@ static int drop_named_image_invoke(bContext *C, wmOperator *op, wmEvent *event) /* put mesh in editmode */ - obedit= base->object; - me= obedit->data; - if (me->edit_btmesh==NULL) { - EDBM_MakeEditBMesh(scene->toolsettings, scene, obedit); - exitmode= 1; + obedit = base->object; + me = obedit->data; + if (me->edit_btmesh == NULL) { + EDBM_mesh_make(scene->toolsettings, scene, obedit); + exitmode = 1; } - if (me->edit_btmesh==NULL) + if (me->edit_btmesh == NULL) return OPERATOR_CANCELLED; ED_uvedit_assign_image(bmain, scene, obedit, ima, NULL); if (exitmode) { - EDBM_LoadEditBMesh(scene, obedit); - EDBM_FreeEditBMesh(me->edit_btmesh); + EDBM_mesh_load(obedit); + EDBM_mesh_free(me->edit_btmesh); MEM_freeN(me->edit_btmesh); - me->edit_btmesh= NULL; + me->edit_btmesh = NULL; /* load_editMesh free's pointers used by CustomData layers which might be used by DerivedMesh too, * so signal to re-create DerivedMesh here (sergey) */ @@ -594,7 +628,7 @@ static int drop_named_image_invoke(bContext *C, wmOperator *op, wmEvent *event) if (v3d) v3d->flag2 |= V3D_SOLID_TEX; - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); return OPERATOR_FINISHED; } @@ -614,14 +648,14 @@ void MESH_OT_drop_named_image(wmOperatorType *ot) ot->flag = OPTYPE_UNDO; /* properties */ - RNA_def_string(ot->srna, "name", "Image", MAX_ID_NAME-2, "Name", "Image name to assign"); + RNA_def_string(ot->srna, "name", "Image", MAX_ID_NAME - 2, "Name", "Image name to assign"); RNA_def_string(ot->srna, "filepath", "Path", FILE_MAX, "Filepath", "Path to image file"); } static int mesh_uv_texture_remove_exec(bContext *C, wmOperator *UNUSED(op)) { - Object *ob= ED_object_context(C); - Mesh *me= ob->data; + Object *ob = ED_object_context(C); + Mesh *me = ob->data; if (!ED_mesh_uv_texture_remove(C, ob, me)) return OPERATOR_CANCELLED; @@ -641,16 +675,16 @@ void MESH_OT_uv_texture_remove(wmOperatorType *ot) ot->exec = mesh_uv_texture_remove_exec; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /*********************** vertex color operators ************************/ static int mesh_vertex_color_add_exec(bContext *C, wmOperator *UNUSED(op)) { - Scene *scene= CTX_data_scene(C); - Object *ob= ED_object_context(C); - Mesh *me= ob->data; + Scene *scene = CTX_data_scene(C); + Object *ob = ED_object_context(C); + Mesh *me = ob->data; if (ED_mesh_color_add(C, scene, ob, me, NULL, TRUE) == -1) return OPERATOR_CANCELLED; @@ -670,13 +704,13 @@ void MESH_OT_vertex_color_add(wmOperatorType *ot) ot->exec = mesh_vertex_color_add_exec; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int mesh_vertex_color_remove_exec(bContext *C, wmOperator *UNUSED(op)) { - Object *ob= ED_object_context(C); - Mesh *me= ob->data; + Object *ob = ED_object_context(C); + Mesh *me = ob->data; if (!ED_mesh_color_remove(C, ob, me)) return OPERATOR_CANCELLED; @@ -696,17 +730,17 @@ void MESH_OT_vertex_color_remove(wmOperatorType *ot) ot->poll = layers_poll; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /*********************** sticky operators ************************/ static int mesh_sticky_add_exec(bContext *C, wmOperator *UNUSED(op)) { - Scene *scene= CTX_data_scene(C); - View3D *v3d= CTX_wm_view3d(C); - Object *ob= ED_object_context(C); - Mesh *me= ob->data; + Scene *scene = CTX_data_scene(C); + View3D *v3d = CTX_wm_view3d(C); + Object *ob = ED_object_context(C); + Mesh *me = ob->data; /* why is this commented out? */ #if 0 @@ -717,7 +751,7 @@ static int mesh_sticky_add_exec(bContext *C, wmOperator *UNUSED(op)) RE_make_sticky(scene, v3d); DAG_id_tag_update(&me->id, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); return OPERATOR_FINISHED; } @@ -734,22 +768,22 @@ void MESH_OT_sticky_add(wmOperatorType *ot) ot->exec = mesh_sticky_add_exec; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int mesh_sticky_remove_exec(bContext *C, wmOperator *UNUSED(op)) { - Object *ob= ED_object_context(C); - Mesh *me= ob->data; + Object *ob = ED_object_context(C); + Mesh *me = ob->data; if (!me->msticky) return OPERATOR_CANCELLED; CustomData_free_layer_active(&me->vdata, CD_MSTICKY, me->totvert); - me->msticky= NULL; + me->msticky = NULL; DAG_id_tag_update(&me->id, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); return OPERATOR_FINISHED; } @@ -766,7 +800,7 @@ void MESH_OT_sticky_remove(wmOperatorType *ot) ot->exec = mesh_sticky_remove_exec; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /************************** Add Geometry Layers *************************/ @@ -778,7 +812,7 @@ void ED_mesh_update(Mesh *mesh, bContext *C, int calc_edges, int calc_tessface) int tessface_input = FALSE; if (mesh->totface > 0 && mesh->totpoly == 0) { - convert_mfaces_to_mpolys(mesh); + BKE_mesh_convert_mfaces_to_mpolys(mesh); /* would only be converting back again, don't bother */ tessface_input = TRUE; @@ -824,7 +858,7 @@ void ED_mesh_update(Mesh *mesh, bContext *C, int calc_edges, int calc_tessface) #endif DAG_id_tag_update(&mesh->id, 0); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, mesh); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, mesh); } static void mesh_add_verts(Mesh *mesh, int len) @@ -836,7 +870,7 @@ static void mesh_add_verts(Mesh *mesh, int len) if (len == 0) return; - totvert= mesh->totvert + len; + totvert = mesh->totvert + len; CustomData_copy(&mesh->vdata, &vdata, CD_MASK_MESH, CD_DEFAULT, totvert); CustomData_copy_data(&mesh->vdata, &vdata, 0, 0, mesh->totvert); @@ -844,25 +878,25 @@ static void mesh_add_verts(Mesh *mesh, int len) CustomData_add_layer(&vdata, CD_MVERT, CD_CALLOC, NULL, totvert); CustomData_free(&mesh->vdata, mesh->totvert); - mesh->vdata= vdata; + mesh->vdata = vdata; mesh_update_customdata_pointers(mesh, FALSE); /* scan the input list and insert the new vertices */ - mvert= &mesh->mvert[mesh->totvert]; - for (i=0; i<len; i++, mvert++) + mvert = &mesh->mvert[mesh->totvert]; + for (i = 0; i < len; i++, mvert++) mvert->flag |= SELECT; /* set final vertex list size */ - mesh->totvert= totvert; + mesh->totvert = totvert; } void ED_mesh_transform(Mesh *me, float *mat) { int i; - MVert *mvert= me->mvert; + MVert *mvert = me->mvert; - for (i= 0; i < me->totvert; i++, mvert++) + for (i = 0; i < me->totvert; i++, mvert++) mul_m4_v3((float (*)[4])mat, mvert->co); mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL); @@ -877,7 +911,7 @@ static void mesh_add_edges(Mesh *mesh, int len) if (len == 0) return; - totedge= mesh->totedge+len; + totedge = mesh->totedge + len; /* update customdata */ CustomData_copy(&mesh->edata, &edata, CD_MASK_MESH, CD_DEFAULT, totedge); @@ -887,18 +921,18 @@ static void mesh_add_edges(Mesh *mesh, int len) CustomData_add_layer(&edata, CD_MEDGE, CD_CALLOC, NULL, totedge); CustomData_free(&mesh->edata, mesh->totedge); - mesh->edata= edata; + mesh->edata = edata; mesh_update_customdata_pointers(mesh, FALSE); /* new edges don't change tessellation */ /* set default flags */ - medge= &mesh->medge[mesh->totedge]; - for (i=0; i<len; i++, medge++) - medge->flag= ME_EDGEDRAW|ME_EDGERENDER|SELECT; + medge = &mesh->medge[mesh->totedge]; + for (i = 0; i < len; i++, medge++) + medge->flag = ME_EDGEDRAW | ME_EDGERENDER | SELECT; - mesh->totedge= totedge; + mesh->totedge = totedge; } -static void mesh_add_faces(Mesh *mesh, int len) +static void mesh_add_tessfaces(Mesh *mesh, int len) { CustomData fdata; MFace *mface; @@ -907,7 +941,7 @@ static void mesh_add_faces(Mesh *mesh, int len) if (len == 0) return; - totface= mesh->totface + len; /* new face count */ + totface = mesh->totface + len; /* new face count */ /* update customdata */ CustomData_copy(&mesh->fdata, &fdata, CD_MASK_MESH, CD_DEFAULT, totface); @@ -917,15 +951,15 @@ static void mesh_add_faces(Mesh *mesh, int len) CustomData_add_layer(&fdata, CD_MFACE, CD_CALLOC, NULL, totface); CustomData_free(&mesh->fdata, mesh->totface); - mesh->fdata= fdata; + mesh->fdata = fdata; mesh_update_customdata_pointers(mesh, TRUE); /* set default flags */ - mface= &mesh->mface[mesh->totface]; - for (i=0; i<len; i++, mface++) - mface->flag= ME_FACE_SEL; + mface = &mesh->mface[mesh->totface]; + for (i = 0; i < len; i++, mface++) + mface->flag = ME_FACE_SEL; - mesh->totface= totface; + mesh->totface = totface; } static void mesh_add_loops(Mesh *mesh, int len) @@ -936,7 +970,7 @@ static void mesh_add_loops(Mesh *mesh, int len) if (len == 0) return; - totloop= mesh->totloop + len; /* new face count */ + totloop = mesh->totloop + len; /* new face count */ /* update customdata */ CustomData_copy(&mesh->ldata, &ldata, CD_MASK_MESH, CD_DEFAULT, totloop); @@ -946,10 +980,10 @@ static void mesh_add_loops(Mesh *mesh, int len) CustomData_add_layer(&ldata, CD_MLOOP, CD_CALLOC, NULL, totloop); CustomData_free(&mesh->ldata, mesh->totloop); - mesh->ldata= ldata; + mesh->ldata = ldata; mesh_update_customdata_pointers(mesh, TRUE); - mesh->totloop= totloop; + mesh->totloop = totloop; } static void mesh_add_polys(Mesh *mesh, int len) @@ -961,7 +995,7 @@ static void mesh_add_polys(Mesh *mesh, int len) if (len == 0) return; - totpoly= mesh->totpoly + len; /* new face count */ + totpoly = mesh->totpoly + len; /* new face count */ /* update customdata */ CustomData_copy(&mesh->pdata, &pdata, CD_MASK_MESH, CD_DEFAULT, totpoly); @@ -971,15 +1005,15 @@ static void mesh_add_polys(Mesh *mesh, int len) CustomData_add_layer(&pdata, CD_MPOLY, CD_CALLOC, NULL, totpoly); CustomData_free(&mesh->pdata, mesh->totpoly); - mesh->pdata= pdata; + mesh->pdata = pdata; mesh_update_customdata_pointers(mesh, TRUE); /* set default flags */ - mpoly= &mesh->mpoly[mesh->totpoly]; - for (i=0; i<len; i++, mpoly++) - mpoly->flag= ME_FACE_SEL; + mpoly = &mesh->mpoly[mesh->totpoly]; + for (i = 0; i < len; i++, mpoly++) + mpoly->flag = ME_FACE_SEL; - mesh->totpoly= totpoly; + mesh->totpoly = totpoly; } static void mesh_remove_verts(Mesh *mesh, int len) @@ -989,11 +1023,11 @@ static void mesh_remove_verts(Mesh *mesh, int len) if (len == 0) return; - totvert= mesh->totvert - len; + totvert = mesh->totvert - len; CustomData_free_elem(&mesh->vdata, totvert, len); /* set final vertex list size */ - mesh->totvert= totvert; + mesh->totvert = totvert; } static void mesh_remove_edges(Mesh *mesh, int len) @@ -1003,10 +1037,10 @@ static void mesh_remove_edges(Mesh *mesh, int len) if (len == 0) return; - totedge= mesh->totedge - len; + totedge = mesh->totedge - len; CustomData_free_elem(&mesh->edata, totedge, len); - mesh->totedge= totedge; + mesh->totedge = totedge; } static void mesh_remove_faces(Mesh *mesh, int len) @@ -1016,10 +1050,10 @@ static void mesh_remove_faces(Mesh *mesh, int len) if (len == 0) return; - totface= mesh->totface - len; /* new face count */ + totface = mesh->totface - len; /* new face count */ CustomData_free_elem(&mesh->fdata, totface, len); - mesh->totface= totface; + mesh->totface = totface; } #if 0 @@ -1039,21 +1073,26 @@ void ED_mesh_geometry_add(Mesh *mesh, ReportList *reports, int verts, int edges, } #endif -void ED_mesh_faces_add(Mesh *mesh, ReportList *reports, int count) +void ED_mesh_tessfaces_add(Mesh *mesh, ReportList *reports, int count) { if (mesh->edit_btmesh) { - BKE_report(reports, RPT_ERROR, "Can't add faces in edit mode"); + BKE_report(reports, RPT_ERROR, "Can't add tessfaces in edit mode"); + return; + } + + if (mesh->mpoly) { + BKE_report(reports, RPT_ERROR, "Can't add tessfaces to a mesh that already has polygons"); return; } - mesh_add_faces(mesh, count); + mesh_add_tessfaces(mesh, count); } void ED_mesh_edges_add(Mesh *mesh, ReportList *reports, int count) { if (mesh->edit_btmesh) { BKE_report(reports, RPT_ERROR, "Can't add edges in edit mode"); - return; + return; } mesh_add_edges(mesh, count); @@ -1115,7 +1154,7 @@ void ED_mesh_loops_add(Mesh *mesh, ReportList *reports, int count) { if (mesh->edit_btmesh) { BKE_report(reports, RPT_ERROR, "Can't add loops in edit mode."); - return; + return; } mesh_add_loops(mesh, count); @@ -1143,3 +1182,13 @@ void ED_mesh_calc_normals(Mesh *mesh) NULL); #endif } + +void ED_mesh_calc_tessface(Mesh *mesh) +{ + if (mesh->edit_btmesh) { + BMEdit_RecalcTessellation(mesh->edit_btmesh); + } + else { + BKE_mesh_tessface_calc(mesh); + } +} diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h index fe5ab4d554e..70f6db97c28 100644 --- a/source/blender/editors/mesh/mesh_intern.h +++ b/source/blender/editors/mesh/mesh_intern.h @@ -35,18 +35,19 @@ #ifndef __MESH_INTERN_H__ #define __MESH_INTERN_H__ -struct bContext; -struct wmOperatorType; -struct ViewContext; -struct BMEditMesh; -struct BMesh; struct BMEdge; +struct BMEditMesh; struct BMFace; +struct BMHeader; struct BMOperator; -struct wmOperator; -struct wmKeyMap; -struct wmKeyConfig; +struct BMesh; struct EnumPropertyItem; +struct ViewContext; +struct bContext; +struct wmKeyConfig; +struct wmKeyMap; +struct wmOperator; +struct wmOperatorType; /* ******************** bmeshutils.c */ @@ -57,26 +58,29 @@ struct EnumPropertyItem; */ /*calls a bmesh op, reporting errors to the user, etc*/ -int EDBM_CallOpf(struct BMEditMesh *em, struct wmOperator *op, const char *fmt, ...); +int EDBM_op_callf(struct BMEditMesh *em, struct wmOperator *op, const char *fmt, ...); + +int EDBM_op_call_and_selectf(struct BMEditMesh *em, struct wmOperator *op, + const char *selectslot, const char *fmt, ...); /* same as above, but doesn't report errors.*/ -int EDBM_CallOpfSilent(struct BMEditMesh *em, const char *fmt, ...); +int EDBM_op_call_silentf(struct BMEditMesh *em, const char *fmt, ...); -/* these next two functions are the split version of EDBM_CallOpf, so you can +/* these next two functions are the split version of EDBM_op_callf, so you can * do stuff with a bmesh operator, after initializing it but before executing * it. * * execute the operator with BM_Exec_Op */ -int EDBM_InitOpf(struct BMEditMesh *em, struct BMOperator *bmop, +int EDBM_op_init(struct BMEditMesh *em, struct BMOperator *bmop, struct wmOperator *op, const char *fmt, ...); /*cleans up after a bmesh operator*/ -int EDBM_FinishOp(struct BMEditMesh *em, struct BMOperator *bmop, - struct wmOperator *op, const int report); +int EDBM_op_finish(struct BMEditMesh *em, struct BMOperator *bmop, + struct wmOperator *op, const int report); void EDBM_flag_disable_all(struct BMEditMesh *em, const char hflag); -void EDBM_store_selection(struct BMEditMesh *em, void *data); -void EDBM_validate_selections(struct BMEditMesh *em); -void EDBM_remove_selection(struct BMEditMesh *em, void *data); +void EDBM_editselection_store(struct BMEditMesh *em, struct BMHeader *ele); +void EDBM_editselection_validate(struct BMEditMesh *em); +void EDBM_editselection_remove(struct BMEditMesh *em, struct BMHeader *ele); void EDBM_stats_update(struct BMEditMesh *em); /* TODO, move to math_geometry.c */ diff --git a/source/blender/editors/mesh/mesh_navmesh.c b/source/blender/editors/mesh/mesh_navmesh.c index 02ef1540cc1..f1b0a82b654 100644 --- a/source/blender/editors/mesh/mesh_navmesh.c +++ b/source/blender/editors/mesh/mesh_navmesh.c @@ -85,89 +85,90 @@ static void createVertsTrisData(bContext *C, LinkNode *obs, int *nverts_r, float ntris = 0; /* calculate number of verts and tris */ - for (oblink = obs; oblink; oblink= oblink->next) { - ob= (Object*) oblink->link; - dm= mesh_create_derived_no_virtual(scene, ob, NULL, CD_MASK_MESH); - BLI_linklist_append(&dms, (void*)dm); + for (oblink = obs; oblink; oblink = oblink->next) { + ob = (Object *) oblink->link; + dm = mesh_create_derived_no_virtual(scene, ob, NULL, CD_MASK_MESH); + BLI_linklist_append(&dms, (void *)dm); - nverts+= dm->getNumVerts(dm); - nfaces= dm->getNumTessFaces(dm); - ntris+= nfaces; + nverts += dm->getNumVerts(dm); + nfaces = dm->getNumTessFaces(dm); + ntris += nfaces; /* resolve quad faces */ - mface= dm->getTessFaceArray(dm); - for (i= 0; i<nfaces; i++) { - MFace *mf= &mface[i]; + mface = dm->getTessFaceArray(dm); + for (i = 0; i < nfaces; i++) { + MFace *mf = &mface[i]; if (mf->v4) - ntris+=1; + ntris += 1; } } /* create data */ - verts= MEM_mallocN(sizeof(float)*3*nverts, "createVertsTrisData verts"); - tris= MEM_mallocN(sizeof(int)*3*ntris, "createVertsTrisData faces"); + verts = MEM_mallocN(sizeof(float) * 3 * nverts, "createVertsTrisData verts"); + tris = MEM_mallocN(sizeof(int) * 3 * ntris, "createVertsTrisData faces"); - basenverts= 0; - tri= tris; - for (oblink= obs, dmlink= dms; oblink && dmlink; - oblink= oblink->next, dmlink= dmlink->next) { - ob= (Object*) oblink->link; - dm= (DerivedMesh*) dmlink->link; + basenverts = 0; + tri = tris; + for (oblink = obs, dmlink = dms; oblink && dmlink; + oblink = oblink->next, dmlink = dmlink->next) + { + ob = (Object *) oblink->link; + dm = (DerivedMesh *) dmlink->link; - curnverts= dm->getNumVerts(dm); - mvert= dm->getVertArray(dm); + curnverts = dm->getNumVerts(dm); + mvert = dm->getVertArray(dm); /* copy verts */ - for (i= 0; i<curnverts; i++) { - MVert *v= &mvert[i]; + for (i = 0; i < curnverts; i++) { + MVert *v = &mvert[i]; copy_v3_v3(co, v->co); mul_v3_m4v3(wco, ob->obmat, co); - verts[3*(basenverts+i)+0]= wco[0]; - verts[3*(basenverts+i)+1]= wco[2]; - verts[3*(basenverts+i)+2]= wco[1]; + verts[3 * (basenverts + i) + 0] = wco[0]; + verts[3 * (basenverts + i) + 1] = wco[2]; + verts[3 * (basenverts + i) + 2] = wco[1]; } /* create tris */ - curnfaces= dm->getNumTessFaces(dm); - mface= dm->getTessFaceArray(dm); + curnfaces = dm->getNumTessFaces(dm); + mface = dm->getTessFaceArray(dm); - for (i= 0; i<curnfaces; i++) { - MFace *mf= &mface[i]; + for (i = 0; i < curnfaces; i++) { + MFace *mf = &mface[i]; - tri[0]= basenverts + mf->v1; - tri[1]= basenverts + mf->v3; - tri[2]= basenverts + mf->v2; + tri[0] = basenverts + mf->v1; + tri[1] = basenverts + mf->v3; + tri[2] = basenverts + mf->v2; tri += 3; if (mf->v4) { - tri[0]= basenverts + mf->v1; - tri[1]= basenverts + mf->v4; - tri[2]= basenverts + mf->v3; + tri[0] = basenverts + mf->v1; + tri[1] = basenverts + mf->v4; + tri[2] = basenverts + mf->v3; tri += 3; } } - basenverts+= curnverts; + basenverts += curnverts; } /* release derived mesh */ - for (dmlink= dms; dmlink; dmlink= dmlink->next) { - dm= (DerivedMesh*) dmlink->link; + for (dmlink = dms; dmlink; dmlink = dmlink->next) { + dm = (DerivedMesh *) dmlink->link; dm->release(dm); } BLI_linklist_free(dms, NULL); - *nverts_r= nverts; - *verts_r= verts; - *ntris_r= ntris; - *tris_r= tris; + *nverts_r = nverts; + *verts_r = verts; + *ntris_r = ntris; + *tris_r = tris; } static int buildNavMesh(const RecastData *recastParams, int nverts, float *verts, int ntris, int *tris, - struct recast_polyMesh **pmesh, struct recast_polyMeshDetail **dmesh) + struct recast_polyMesh **pmesh, struct recast_polyMeshDetail **dmesh) { float bmin[3], bmax[3]; struct recast_heightfield *solid; @@ -181,22 +182,22 @@ static int buildNavMesh(const RecastData *recastParams, int nverts, float *verts recast_calcBounds(verts, nverts, bmin, bmax); /* ** Step 1. Initialize build config ** */ - walkableHeight= (int)ceilf(recastParams->agentheight/ recastParams->cellheight); - walkableClimb= (int)floorf(recastParams->agentmaxclimb / recastParams->cellheight); - walkableRadius= (int)ceilf(recastParams->agentradius / recastParams->cellsize); - minRegionArea= (int)(recastParams->regionminsize * recastParams->regionminsize); - mergeRegionArea= (int)(recastParams->regionmergesize * recastParams->regionmergesize); - maxEdgeLen= (int)(recastParams->edgemaxlen/recastParams->cellsize); - detailSampleDist= recastParams->detailsampledist< 0.9f ? 0 : - recastParams->cellsize * recastParams->detailsampledist; - detailSampleMaxError= recastParams->cellheight * recastParams->detailsamplemaxerror; + walkableHeight = (int)ceilf(recastParams->agentheight / recastParams->cellheight); + walkableClimb = (int)floorf(recastParams->agentmaxclimb / recastParams->cellheight); + walkableRadius = (int)ceilf(recastParams->agentradius / recastParams->cellsize); + minRegionArea = (int)(recastParams->regionminsize * recastParams->regionminsize); + mergeRegionArea = (int)(recastParams->regionmergesize * recastParams->regionmergesize); + maxEdgeLen = (int)(recastParams->edgemaxlen / recastParams->cellsize); + detailSampleDist = recastParams->detailsampledist < 0.9f ? 0 : + recastParams->cellsize * recastParams->detailsampledist; + detailSampleMaxError = recastParams->cellheight * recastParams->detailsamplemaxerror; /* Set the area where the navigation will be build. */ recast_calcGridSize(bmin, bmax, recastParams->cellsize, &width, &height); /* ** Step 2: Rasterize input polygon soup ** */ /* Allocate voxel heightfield where we rasterize our input data to */ - solid= recast_newHeightfield(); + solid = recast_newHeightfield(); if (!recast_createHeightfield(solid, width, height, bmin, bmax, recastParams->cellsize, recastParams->cellheight)) { recast_destroyHeightfield(solid); @@ -205,7 +206,7 @@ static int buildNavMesh(const RecastData *recastParams, int nverts, float *verts } /* Allocate array that can hold triangle flags */ - triflags= MEM_callocN(sizeof(unsigned char)*ntris, "buildNavMesh triflags"); + triflags = MEM_callocN(sizeof(unsigned char) * ntris, "buildNavMesh triflags"); /* Find triangles which are walkable based on their slope and rasterize them */ recast_markWalkableTriangles(RAD2DEG(recastParams->agentmaxslope), verts, nverts, tris, ntris, triflags); @@ -219,7 +220,7 @@ static int buildNavMesh(const RecastData *recastParams, int nverts, float *verts /* ** Step 4: Partition walkable surface to simple regions ** */ - chf= recast_newCompactHeightfield(); + chf = recast_newCompactHeightfield(); if (!recast_buildCompactHeightfield(walkableHeight, walkableClimb, solid, chf)) { recast_destroyHeightfield(solid); recast_destroyCompactHeightfield(chf); @@ -252,7 +253,7 @@ static int buildNavMesh(const RecastData *recastParams, int nverts, float *verts /* ** Step 5: Trace and simplify region contours ** */ /* Create contours */ - cset= recast_newContourSet(); + cset = recast_newContourSet(); if (!recast_buildContours(chf, recastParams->edgemaxerror, maxEdgeLen, cset)) { recast_destroyCompactHeightfield(chf); @@ -262,7 +263,7 @@ static int buildNavMesh(const RecastData *recastParams, int nverts, float *verts } /* ** Step 6: Build polygons mesh from contours ** */ - *pmesh= recast_newPolyMesh(); + *pmesh = recast_newPolyMesh(); if (!recast_buildPolyMesh(cset, recastParams->vertsperpoly, *pmesh)) { recast_destroyCompactHeightfield(chf); recast_destroyContourSet(cset); @@ -274,7 +275,7 @@ static int buildNavMesh(const RecastData *recastParams, int nverts, float *verts /* ** Step 7: Create detail mesh which allows to access approximate height on each polygon ** */ - *dmesh= recast_newPolyMeshDetail(); + *dmesh = recast_newPolyMeshDetail(); if (!recast_buildPolyMeshDetail(*pmesh, chf, detailSampleDist, detailSampleMaxError, *dmesh)) { recast_destroyCompactHeightfield(chf); recast_destroyContourSet(cset); @@ -294,12 +295,12 @@ static Object *createRepresentation(bContext *C, struct recast_polyMesh *pmesh, { float co[3], rot[3]; BMEditMesh *em; - int i,j, k; + int i, j, k; unsigned short *v; int face[3]; - Scene *scene= CTX_data_scene(C); + Scene *scene = CTX_data_scene(C); Object *obedit; - int createob= base==NULL; + int createob = base == NULL; int nverts, nmeshes, nvp; unsigned short *verts, *polys; unsigned int *meshes; @@ -311,33 +312,33 @@ static Object *createRepresentation(bContext *C, struct recast_polyMesh *pmesh, if (createob) { /* create new object */ - obedit= ED_object_add_type(C, OB_MESH, co, rot, FALSE, 1); + obedit = ED_object_add_type(C, OB_MESH, co, rot, FALSE, 1); } else { - obedit= base->object; + obedit = base->object; scene_select_base(scene, base); copy_v3_v3(obedit->loc, co); copy_v3_v3(obedit->rot, rot); } - ED_object_enter_editmode(C, EM_DO_UNDO|EM_IGNORE_LAYER); + ED_object_enter_editmode(C, EM_DO_UNDO | EM_IGNORE_LAYER); em = BMEdit_FromObject(obedit); if (!createob) { /* clear */ - EDBM_ClearMesh(em); + EDBM_mesh_clear(em); } /* create verts for polygon mesh */ - verts= recast_polyMeshGetVerts(pmesh, &nverts); + verts = recast_polyMeshGetVerts(pmesh, &nverts); recast_polyMeshGetBoundbox(pmesh, bmin, NULL); recast_polyMeshGetCell(pmesh, &cs, &ch); - for (i= 0; i<nverts; i++) { - v= &verts[3*i]; - co[0]= bmin[0] + v[0]*cs; - co[1]= bmin[1] + v[1]*ch; - co[2]= bmin[2] + v[2]*cs; + for (i = 0; i < nverts; i++) { + v = &verts[3 * i]; + co[0] = bmin[0] + v[0] * cs; + co[1] = bmin[1] + v[1] * ch; + co[2] = bmin[2] + v[2] * cs; SWAP(float, co[1], co[2]); BM_vert_create(em->bm, co, NULL); } @@ -346,74 +347,74 @@ static Object *createRepresentation(bContext *C, struct recast_polyMesh *pmesh, CustomData_add_layer_named(&em->bm->pdata, CD_RECAST, CD_CALLOC, NULL, 0, "createRepresentation recastData"); /* create verts and faces for detailed mesh */ - meshes= recast_polyMeshDetailGetMeshes(dmesh, &nmeshes); - polys= recast_polyMeshGetPolys(pmesh, NULL, &nvp); - dverts= recast_polyMeshDetailGetVerts(dmesh, NULL); - tris= recast_polyMeshDetailGetTris(dmesh, NULL); - - for (i= 0; i<nmeshes; i++) { - int uniquevbase= em->bm->totvert; - unsigned int vbase= meshes[4*i+0]; - unsigned short ndv= meshes[4*i+1]; - unsigned short tribase= meshes[4*i+2]; - unsigned short trinum= meshes[4*i+3]; - const unsigned short *p= &polys[i*nvp*2]; - int nv= 0; - - for (j= 0; j < nvp; ++j) { - if (p[j]==0xffff) break; + meshes = recast_polyMeshDetailGetMeshes(dmesh, &nmeshes); + polys = recast_polyMeshGetPolys(pmesh, NULL, &nvp); + dverts = recast_polyMeshDetailGetVerts(dmesh, NULL); + tris = recast_polyMeshDetailGetTris(dmesh, NULL); + + for (i = 0; i < nmeshes; i++) { + int uniquevbase = em->bm->totvert; + unsigned int vbase = meshes[4 * i + 0]; + unsigned short ndv = meshes[4 * i + 1]; + unsigned short tribase = meshes[4 * i + 2]; + unsigned short trinum = meshes[4 * i + 3]; + const unsigned short *p = &polys[i * nvp * 2]; + int nv = 0; + + for (j = 0; j < nvp; ++j) { + if (p[j] == 0xffff) break; nv++; } /* create unique verts */ - for (j= nv; j<ndv; j++) { - copy_v3_v3(co, &dverts[3*(vbase + j)]); + for (j = nv; j < ndv; j++) { + copy_v3_v3(co, &dverts[3 * (vbase + j)]); SWAP(float, co[1], co[2]); BM_vert_create(em->bm, co, NULL); } - EDBM_init_index_arrays(em, 1, 0, 0); + EDBM_index_arrays_init(em, 1, 0, 0); /* create faces */ - for (j= 0; j<trinum; j++) { - unsigned char *tri= &tris[4*(tribase+j)]; + for (j = 0; j < trinum; j++) { + unsigned char *tri = &tris[4 * (tribase + j)]; BMFace *newFace; int *polygonIdx; - for (k= 0; k<3; k++) { - if (tri[k]<nv) - face[k] = p[tri[k]]; /* shared vertex */ + for (k = 0; k < 3; k++) { + if (tri[k] < nv) + face[k] = p[tri[k]]; /* shared vertex */ else - face[k] = uniquevbase+tri[k]-nv; /* unique vertex */ + face[k] = uniquevbase + tri[k] - nv; /* unique vertex */ } - newFace= BM_face_create_quad_tri(em->bm, - EDBM_get_vert_for_index(em, face[0]), - EDBM_get_vert_for_index(em, face[2]), - EDBM_get_vert_for_index(em, face[1]), NULL, - NULL, FALSE); + newFace = BM_face_create_quad_tri(em->bm, + EDBM_vert_at_index(em, face[0]), + EDBM_vert_at_index(em, face[2]), + EDBM_vert_at_index(em, face[1]), NULL, + NULL, FALSE); /* set navigation polygon idx to the custom layer */ - polygonIdx= (int*)CustomData_bmesh_get(&em->bm->pdata, newFace->head.data, CD_RECAST); - *polygonIdx= i+1; /* add 1 to avoid zero idx */ + polygonIdx = (int *)CustomData_bmesh_get(&em->bm->pdata, newFace->head.data, CD_RECAST); + *polygonIdx = i + 1; /* add 1 to avoid zero idx */ } - EDBM_free_index_arrays(em); + EDBM_index_arrays_free(em); } recast_destroyPolyMesh(pmesh); recast_destroyPolyMeshDetail(dmesh); - DAG_id_tag_update((ID*)obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + DAG_id_tag_update((ID *)obedit->data, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); ED_object_exit_editmode(C, EM_FREEDATA); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit); + WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); if (createob) { - obedit->gameflag&= ~OB_COLLISION; - obedit->gameflag|= OB_NAVMESH; - obedit->body_type= OB_BODY_TYPE_NAVMESH; + obedit->gameflag &= ~OB_COLLISION; + obedit->gameflag |= OB_NAVMESH; + obedit->body_type = OB_BODY_TYPE_NAVMESH; rename_id((ID *)obedit, "Navmesh"); } @@ -424,31 +425,31 @@ static Object *createRepresentation(bContext *C, struct recast_polyMesh *pmesh, static int navmesh_create_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); - LinkNode *obs= NULL; - Base *navmeshBase= NULL; + Scene *scene = CTX_data_scene(C); + LinkNode *obs = NULL; + Base *navmeshBase = NULL; CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { if (base->object->type == OB_MESH) { - if (base->object->body_type==OB_BODY_TYPE_NAVMESH) { + if (base->object->body_type == OB_BODY_TYPE_NAVMESH) { if (!navmeshBase || base == scene->basact) { - navmeshBase= base; + navmeshBase = base; } } else { - BLI_linklist_append(&obs, (void*)base->object); + BLI_linklist_append(&obs, (void *)base->object); } } } CTX_DATA_END; if (obs) { - struct recast_polyMesh *pmesh= NULL; - struct recast_polyMeshDetail *dmesh= NULL; + struct recast_polyMesh *pmesh = NULL; + struct recast_polyMeshDetail *dmesh = NULL; - int nverts= 0, ntris= 0; - int *tris= 0; - float *verts= NULL; + int nverts = 0, ntris = 0; + int *tris = 0; + float *verts = NULL; createVertsTrisData(C, obs, &nverts, &verts, &ntris, &tris); BLI_linklist_free(obs, NULL); @@ -478,7 +479,7 @@ void MESH_OT_navmesh_make(wmOperatorType *ot) ot->exec = navmesh_create_exec; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int navmesh_face_copy_exec(bContext *C, wmOperator *op) @@ -487,20 +488,20 @@ static int navmesh_face_copy_exec(bContext *C, wmOperator *op) BMEditMesh *em = BMEdit_FromObject(obedit); /* do work here */ - BMFace *efa_act= BM_active_face_get(em->bm, FALSE); + BMFace *efa_act = BM_active_face_get(em->bm, FALSE); if (efa_act) { if (CustomData_has_layer(&em->bm->pdata, CD_RECAST)) { BMFace *efa; BMIter iter; - int targetPolyIdx= *(int*)CustomData_bmesh_get(&em->bm->pdata, efa_act->head.data, CD_RECAST); - targetPolyIdx= targetPolyIdx>=0? targetPolyIdx : -targetPolyIdx; + int targetPolyIdx = *(int *)CustomData_bmesh_get(&em->bm->pdata, efa_act->head.data, CD_RECAST); + targetPolyIdx = targetPolyIdx >= 0 ? targetPolyIdx : -targetPolyIdx; if (targetPolyIdx > 0) { /* set target poly idx to other selected faces */ BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && efa != efa_act) { - int *recastDataBlock = (int*)CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_RECAST); + int *recastDataBlock = (int *)CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_RECAST); *recastDataBlock = targetPolyIdx; } } @@ -511,8 +512,8 @@ static int navmesh_face_copy_exec(bContext *C, wmOperator *op) } } - DAG_id_tag_update((ID*)obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + DAG_id_tag_update((ID *)obedit->data, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); return OPERATOR_FINISHED; } @@ -529,27 +530,27 @@ void MESH_OT_navmesh_face_copy(struct wmOperatorType *ot) ot->exec = navmesh_face_copy_exec; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } -static int compare(const void * a, const void * b) +static int compare(const void *a, const void *b) { - return ( *(int*)a - *(int*)b ); + return (*(int *)a - *(int *)b); } static int findFreeNavPolyIndex(BMEditMesh *em) { /* construct vector of indices */ int numfaces = em->bm->totface; - int *indices = MEM_callocN(sizeof(int)*numfaces, "findFreeNavPolyIndex(indices)"); + int *indices = MEM_callocN(sizeof(int) * numfaces, "findFreeNavPolyIndex(indices)"); BMFace *ef; BMIter iter; - int i, idx = em->bm->totface-1, freeIdx = 1; + int i, idx = em->bm->totface - 1, freeIdx = 1; /*XXX this originally went last to first, but that isn't possible anymore*/ BM_ITER(ef, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - int polyIdx = *(int*)CustomData_bmesh_get(&em->bm->pdata, ef->head.data, CD_RECAST); - indices[idx]= polyIdx; + int polyIdx = *(int *)CustomData_bmesh_get(&em->bm->pdata, ef->head.data, CD_RECAST); + indices[idx] = polyIdx; idx--; } @@ -557,10 +558,10 @@ static int findFreeNavPolyIndex(BMEditMesh *em) /* search first free index */ freeIdx = 1; - for (i = 0; i<numfaces; i++) { - if (indices[i]==freeIdx) + for (i = 0; i < numfaces; i++) { + if (indices[i] == freeIdx) freeIdx++; - else if (indices[i]>freeIdx) + else if (indices[i] > freeIdx) break; } @@ -579,21 +580,21 @@ static int navmesh_face_add_exec(bContext *C, wmOperator *UNUSED(op)) if (CustomData_has_layer(&em->bm->pdata, CD_RECAST)) { int targetPolyIdx = findFreeNavPolyIndex(em); - if (targetPolyIdx>0) { + if (targetPolyIdx > 0) { /* set target poly idx to selected faces */ /*XXX this originally went last to first, but that isn't possible anymore*/ BM_ITER(ef, &iter, em->bm, BM_FACES_OF_MESH, NULL) { if (BM_elem_flag_test(ef, BM_ELEM_SELECT)) { - int *recastDataBlock = (int*)CustomData_bmesh_get(&em->bm->pdata, ef->head.data, CD_RECAST); + int *recastDataBlock = (int *)CustomData_bmesh_get(&em->bm->pdata, ef->head.data, CD_RECAST); *recastDataBlock = targetPolyIdx; } } } } - DAG_id_tag_update((ID*)obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + DAG_id_tag_update((ID *)obedit->data, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); return OPERATOR_FINISHED; } @@ -610,7 +611,7 @@ void MESH_OT_navmesh_face_add(struct wmOperatorType *ot) ot->exec = navmesh_face_add_exec; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int navmesh_obmode_data_poll(bContext *C) @@ -642,7 +643,7 @@ static int navmesh_reset_exec(bContext *C, wmOperator *UNUSED(op)) BKE_mesh_ensure_navmesh(me); DAG_id_tag_update(&me->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, &me->id); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, &me->id); return OPERATOR_FINISHED; } @@ -659,7 +660,7 @@ void MESH_OT_navmesh_reset(struct wmOperatorType *ot) ot->exec = navmesh_reset_exec; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int navmesh_clear_exec(bContext *C, wmOperator *UNUSED(op)) @@ -670,7 +671,7 @@ static int navmesh_clear_exec(bContext *C, wmOperator *UNUSED(op)) CustomData_free_layers(&me->pdata, CD_RECAST, me->totpoly); DAG_id_tag_update(&me->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, &me->id); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, &me->id); return OPERATOR_FINISHED; } @@ -687,5 +688,5 @@ void MESH_OT_navmesh_clear(struct wmOperatorType *ot) ot->exec = navmesh_clear_exec; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c index 6a0fa0cf7c9..c048728a288 100644 --- a/source/blender/editors/mesh/mesh_ops.c +++ b/source/blender/editors/mesh/mesh_ops.c @@ -179,8 +179,8 @@ void ED_operatortypes_mesh(void) #if 0 /* UNUSED, remove? */ static int ED_operator_editmesh_face_select(bContext *C) { - Object *obedit= CTX_data_edit_object(C); - if (obedit && obedit->type==OB_MESH) { + Object *obedit = CTX_data_edit_object(C); + if (obedit && obedit->type == OB_MESH) { BMEditMesh *em = BMEdit_FromObject(obedit); if (em && em->selectmode & SCE_SELECT_FACE) { return 1; @@ -195,48 +195,48 @@ void ED_operatormacros_mesh(void) wmOperatorType *ot; wmOperatorTypeMacro *otmacro; - ot = WM_operatortype_append_macro("MESH_OT_loopcut_slide", "Loop Cut and Slide", OPTYPE_UNDO|OPTYPE_REGISTER); + ot = WM_operatortype_append_macro("MESH_OT_loopcut_slide", "Loop Cut and Slide", OPTYPE_UNDO | OPTYPE_REGISTER); ot->description = "Cut mesh loop and slide it"; WM_operatortype_macro_define(ot, "MESH_OT_loopcut"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_edge_slide"); RNA_struct_idprops_unset(otmacro->ptr, "release_confirm"); - ot = WM_operatortype_append_macro("MESH_OT_duplicate_move", "Add Duplicate", OPTYPE_UNDO|OPTYPE_REGISTER); + ot = WM_operatortype_append_macro("MESH_OT_duplicate_move", "Add Duplicate", OPTYPE_UNDO | OPTYPE_REGISTER); ot->description = "Duplicate mesh and move"; WM_operatortype_macro_define(ot, "MESH_OT_duplicate"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); RNA_enum_set(otmacro->ptr, "proportional", 0); RNA_boolean_set(otmacro->ptr, "mirror", FALSE); - ot = WM_operatortype_append_macro("MESH_OT_rip_move", "Rip", OPTYPE_UNDO|OPTYPE_REGISTER); + ot = WM_operatortype_append_macro("MESH_OT_rip_move", "Rip", OPTYPE_UNDO | OPTYPE_REGISTER); ot->description = "Rip polygons and move the result"; WM_operatortype_macro_define(ot, "MESH_OT_rip"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); RNA_enum_set(otmacro->ptr, "proportional", 0); RNA_boolean_set(otmacro->ptr, "mirror", FALSE); - ot = WM_operatortype_append_macro("MESH_OT_extrude_region_move", "Extrude Region and Move", OPTYPE_UNDO|OPTYPE_REGISTER); + ot = WM_operatortype_append_macro("MESH_OT_extrude_region_move", "Extrude Region and Move", OPTYPE_UNDO | OPTYPE_REGISTER); ot->description = "Extrude region and move result"; otmacro = WM_operatortype_macro_define(ot, "MESH_OT_extrude_region"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); RNA_enum_set(otmacro->ptr, "proportional", 0); RNA_boolean_set(otmacro->ptr, "mirror", FALSE); - ot = WM_operatortype_append_macro("MESH_OT_extrude_faces_move", "Extrude Individual Faces and Move", OPTYPE_UNDO|OPTYPE_REGISTER); + ot = WM_operatortype_append_macro("MESH_OT_extrude_faces_move", "Extrude Individual Faces and Move", OPTYPE_UNDO | OPTYPE_REGISTER); ot->description = "Extrude faces and move result"; otmacro = WM_operatortype_macro_define(ot, "MESH_OT_extrude_faces_indiv"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_shrink_fatten"); RNA_enum_set(otmacro->ptr, "proportional", 0); RNA_boolean_set(otmacro->ptr, "mirror", FALSE); - ot = WM_operatortype_append_macro("MESH_OT_extrude_edges_move", "Extrude Only Edges and Move", OPTYPE_UNDO|OPTYPE_REGISTER); + ot = WM_operatortype_append_macro("MESH_OT_extrude_edges_move", "Extrude Only Edges and Move", OPTYPE_UNDO | OPTYPE_REGISTER); ot->description = "Extrude edges and move result"; otmacro = WM_operatortype_macro_define(ot, "MESH_OT_extrude_edges_indiv"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); RNA_enum_set(otmacro->ptr, "proportional", 0); RNA_boolean_set(otmacro->ptr, "mirror", FALSE); - ot = WM_operatortype_append_macro("MESH_OT_extrude_vertices_move", "Extrude Only Vertices and Move", OPTYPE_UNDO|OPTYPE_REGISTER); + ot = WM_operatortype_append_macro("MESH_OT_extrude_vertices_move", "Extrude Only Vertices and Move", OPTYPE_UNDO | OPTYPE_REGISTER); ot->description = "Extrude vertices and move result"; otmacro = WM_operatortype_macro_define(ot, "MESH_OT_extrude_verts_indiv"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); @@ -260,12 +260,12 @@ void ED_keymap_mesh(wmKeyConfig *keyconf) /* standard mouse selection goes via space_view3d */ kmi = WM_keymap_add_item(keymap, "MESH_OT_loop_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0); RNA_boolean_set(kmi->ptr, "extend", FALSE); - kmi = WM_keymap_add_item(keymap, "MESH_OT_loop_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_ALT, 0); + kmi = WM_keymap_add_item(keymap, "MESH_OT_loop_select", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_ALT, 0); RNA_boolean_set(kmi->ptr, "extend", TRUE); - kmi = WM_keymap_add_item(keymap, "MESH_OT_edgering_select", SELECTMOUSE, KM_PRESS, KM_ALT|KM_CTRL, 0); + kmi = WM_keymap_add_item(keymap, "MESH_OT_edgering_select", SELECTMOUSE, KM_PRESS, KM_ALT | KM_CTRL, 0); RNA_boolean_set(kmi->ptr, "extend", FALSE); - kmi = WM_keymap_add_item(keymap, "MESH_OT_edgering_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_ALT|KM_CTRL, 0); + kmi = WM_keymap_add_item(keymap, "MESH_OT_edgering_select", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_ALT | KM_CTRL, 0); RNA_boolean_set(kmi->ptr, "extend", TRUE); WM_keymap_add_item(keymap, "MESH_OT_select_shortest_path", SELECTMOUSE, KM_PRESS, KM_CTRL, 0); @@ -277,7 +277,7 @@ void ED_keymap_mesh(wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "MESH_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0); WM_keymap_add_item(keymap, "MESH_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0); - WM_keymap_add_item(keymap, "MESH_OT_select_non_manifold", MKEY, KM_PRESS, (KM_CTRL|KM_SHIFT|KM_ALT), 0); + WM_keymap_add_item(keymap, "MESH_OT_select_non_manifold", MKEY, KM_PRESS, (KM_CTRL | KM_SHIFT | KM_ALT), 0); WM_keymap_add_item(keymap, "MESH_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0); kmi = WM_keymap_add_item(keymap, "MESH_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0); @@ -285,7 +285,7 @@ void ED_keymap_mesh(wmKeyConfig *keyconf) kmi = WM_keymap_add_item(keymap, "MESH_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0); RNA_boolean_set(kmi->ptr, "deselect", TRUE); - WM_keymap_add_item(keymap, "MESH_OT_faces_select_linked_flat", FKEY, KM_PRESS, (KM_CTRL|KM_SHIFT|KM_ALT), 0); + WM_keymap_add_item(keymap, "MESH_OT_faces_select_linked_flat", FKEY, KM_PRESS, (KM_CTRL | KM_SHIFT | KM_ALT), 0); WM_keymap_add_item(keymap, "MESH_OT_select_similar", GKEY, KM_PRESS, KM_SHIFT, 0); @@ -302,7 +302,7 @@ void ED_keymap_mesh(wmKeyConfig *keyconf) /* tools */ kmi = WM_keymap_add_item(keymap, "MESH_OT_normals_make_consistent", NKEY, KM_PRESS, KM_CTRL, 0); RNA_boolean_set(kmi->ptr, "inside", FALSE); - kmi = WM_keymap_add_item(keymap, "MESH_OT_normals_make_consistent", NKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0); + kmi = WM_keymap_add_item(keymap, "MESH_OT_normals_make_consistent", NKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0); RNA_boolean_set(kmi->ptr, "inside", TRUE); WM_keymap_add_item(keymap, "VIEW3D_OT_edit_mesh_extrude_move_normal", EKEY, KM_PRESS, 0, 0); /* python operator */ @@ -313,7 +313,7 @@ void ED_keymap_mesh(wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "MESH_OT_spin", RKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "MESH_OT_fill", FKEY, KM_PRESS, KM_ALT, 0); - WM_keymap_add_item(keymap, "MESH_OT_beautify_fill", FKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0); + WM_keymap_add_item(keymap, "MESH_OT_beautify_fill", FKEY, KM_PRESS, KM_SHIFT | KM_ALT, 0); WM_keymap_add_item(keymap, "MESH_OT_quads_convert_to_tris", TKEY, KM_PRESS, KM_CTRL, 0); kmi = WM_keymap_add_item(keymap, "MESH_OT_quads_convert_to_tris", TKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0); @@ -321,7 +321,7 @@ void ED_keymap_mesh(wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "MESH_OT_tris_convert_to_quads", JKEY, KM_PRESS, KM_ALT, 0); - WM_keymap_add_item(keymap, "MESH_OT_rip_move",VKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "MESH_OT_rip_move", VKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "MESH_OT_merge", MKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "TRANSFORM_OT_shrink_fatten", SKEY, KM_PRESS, KM_ALT, 0); @@ -340,11 +340,9 @@ void ED_keymap_mesh(wmKeyConfig *keyconf) /* use KM_CLICK because same key is used for tweaks */ kmi = WM_keymap_add_item(keymap, "MESH_OT_dupli_extrude_cursor", ACTIONMOUSE, KM_CLICK, KM_CTRL, 0); RNA_boolean_set(kmi->ptr, "rotate_source", TRUE); - kmi = WM_keymap_add_item(keymap, "MESH_OT_dupli_extrude_cursor", ACTIONMOUSE, KM_CLICK, KM_SHIFT|KM_CTRL, 0); + kmi = WM_keymap_add_item(keymap, "MESH_OT_dupli_extrude_cursor", ACTIONMOUSE, KM_CLICK, KM_SHIFT | KM_CTRL, 0); RNA_boolean_set(kmi->ptr, "rotate_source", FALSE); - WM_keymap_add_menu(keymap, "VIEW3D_MT_edit_mesh_dissolve", DKEY, KM_PRESS, 0, 0); - WM_keymap_add_menu(keymap, "VIEW3D_MT_edit_mesh_delete", XKEY, KM_PRESS, 0, 0); WM_keymap_add_menu(keymap, "VIEW3D_MT_edit_mesh_delete", DELKEY, KM_PRESS, 0, 0); @@ -363,8 +361,8 @@ void ED_keymap_mesh(wmKeyConfig *keyconf) WM_keymap_add_menu(keymap, "VIEW3D_MT_vertex_group", GKEY, KM_PRESS, KM_CTRL, 0); /* useful stuff from object-mode */ - for (i=0; i<=5; i++) { - kmi = WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", ZEROKEY+i, KM_PRESS, KM_CTRL, 0); + for (i = 0; i <= 5; i++) { + kmi = WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", ZEROKEY + i, KM_PRESS, KM_CTRL, 0); RNA_int_set(kmi->ptr, "level", i); } diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 7d0172b3c15..37922b6e693 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -91,21 +91,21 @@ int join_mesh_exec(bContext *C, wmOperator *op) { - Main *bmain= CTX_data_main(C); - Scene *scene= CTX_data_scene(C); - Object *ob= CTX_data_active_object(C); + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + Object *ob = CTX_data_active_object(C); Material **matar, *ma; Mesh *me; MVert *mvert, *mv; MEdge *medge = NULL; MPoly *mpoly = NULL; MLoop *mloop = NULL; - Key *key, *nkey=NULL; + Key *key, *nkey = NULL; KeyBlock *kb, *okb, *kbn; float imat[4][4], cmat[4][4], *fp1, *fp2, curpos; - int a, b, totcol, totmat=0, totedge=0, totvert=0, ok=0; - int totloop=0, totpoly=0, vertofs, *matmap=NULL; - int i, j, index, haskey=0, edgeofs, loopofs, polyofs; + int a, b, totcol, totmat = 0, totedge = 0, totvert = 0, ok = 0; + int totloop = 0, totpoly = 0, vertofs, *matmap = NULL; + int i, j, index, haskey = 0, edgeofs, loopofs, polyofs; bDeformGroup *dg, *odg; MDeformVert *dvert; CustomData vdata, edata, fdata, ldata, pdata; @@ -116,24 +116,24 @@ int join_mesh_exec(bContext *C, wmOperator *op) } /* ob is the object we are adding geometry to */ - if (!ob || ob->type!=OB_MESH) { + if (!ob || ob->type != OB_MESH) { BKE_report(op->reports, RPT_WARNING, "Active object is not a mesh"); return OPERATOR_CANCELLED; } /* count & check */ - CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { - if (base->object->type==OB_MESH) { - me= base->object->data; - - totvert+= me->totvert; - totedge+= me->totedge; - totloop+= me->totloop; - totpoly+= me->totpoly; - totmat+= base->object->totcol; + CTX_DATA_BEGIN(C, Base *, base, selected_editable_bases) { + if (base->object->type == OB_MESH) { + me = base->object->data; + + totvert += me->totvert; + totedge += me->totedge; + totloop += me->totloop; + totpoly += me->totpoly; + totmat += base->object->totcol; if (base->object == ob) - ok= 1; + ok = 1; /* check for shapekeys */ if (me->key) @@ -143,16 +143,16 @@ int join_mesh_exec(bContext *C, wmOperator *op) CTX_DATA_END; /* that way the active object is always selected */ - if (ok==0) { + if (ok == 0) { BKE_report(op->reports, RPT_WARNING, "Active object is not a selected mesh"); return OPERATOR_CANCELLED; } /* only join meshes if there are verts to join, there aren't too many, and we only had one mesh selected */ - me= (Mesh *)ob->data; - key= me->key; + me = (Mesh *)ob->data; + key = me->key; - if (totvert==0 || totvert==me->totvert) { + if (totvert == 0 || totvert == me->totvert) { BKE_report(op->reports, RPT_WARNING, "No mesh data to join"); return OPERATOR_CANCELLED; } @@ -163,48 +163,49 @@ int join_mesh_exec(bContext *C, wmOperator *op) } /* new material indices and material array */ - matar= MEM_callocN(sizeof(void*)*totmat, "join_mesh matar"); - if (totmat) matmap= MEM_callocN(sizeof(int)*totmat, "join_mesh matmap"); - totcol= ob->totcol; + matar = MEM_callocN(sizeof(void *) * totmat, "join_mesh matar"); + if (totmat) matmap = MEM_callocN(sizeof(int) * totmat, "join_mesh matmap"); + totcol = ob->totcol; /* obact materials in new main array, is nicer start! */ - for (a=0; a<ob->totcol; a++) { - matar[a]= give_current_material(ob, a+1); + for (a = 0; a < ob->totcol; a++) { + matar[a] = give_current_material(ob, a + 1); id_us_plus((ID *)matar[a]); /* increase id->us : will be lowered later */ } /* - if destination mesh had shapekeys, move them somewhere safe, and set up placeholders - * with arrays that are large enough to hold shapekey data for all meshes + * with arrays that are large enough to hold shapekey data for all meshes * - if destination mesh didn't have shapekeys, but we encountered some in the meshes we're * joining, set up a new keyblock and assign to the mesh */ if (key) { /* make a duplicate copy that will only be used here... (must remember to free it!) */ - nkey= copy_key(key); + nkey = copy_key(key); /* for all keys in old block, clear data-arrays */ - for (kb= key->block.first; kb; kb= kb->next) { + for (kb = key->block.first; kb; kb = kb->next) { if (kb->data) MEM_freeN(kb->data); - kb->data= MEM_callocN(sizeof(float)*3*totvert, "join_shapekey"); - kb->totelem= totvert; - kb->weights= NULL; + kb->data = MEM_callocN(sizeof(float) * 3 * totvert, "join_shapekey"); + kb->totelem = totvert; + kb->weights = NULL; } } else if (haskey) { /* add a new key-block and add to the mesh */ - key= me->key= add_key((ID *)me); + key = me->key = add_key((ID *)me); key->type = KEY_RELATIVE; } /* first pass over objects - copying materials and vertexgroups across */ - CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { + CTX_DATA_BEGIN(C, Base *, base, selected_editable_bases) + { /* only act if a mesh, and not the one we're joining to */ - if ((ob!=base->object) && (base->object->type==OB_MESH)) { - me= base->object->data; + if ((ob != base->object) && (base->object->type == OB_MESH)) { + me = base->object->data; /* Join this object's vertex groups to the base one's */ - for (dg=base->object->defbase.first; dg; dg=dg->next) { + for (dg = base->object->defbase.first; dg; dg = dg->next) { /* See if this group exists in the object (if it doesn't, add it to the end) */ if (!defgroup_find_name(ob, dg->name)) { odg = MEM_callocN(sizeof(bDeformGroup), "join deformGroup"); @@ -212,21 +213,21 @@ int join_mesh_exec(bContext *C, wmOperator *op) BLI_addtail(&ob->defbase, odg); } } - if (ob->defbase.first && ob->actdef==0) - ob->actdef=1; + if (ob->defbase.first && ob->actdef == 0) + ob->actdef = 1; if (me->totvert) { /* Add this object's materials to the base one's if they don't exist already (but only if limits not exceeded yet) */ if (totcol < MAXMAT) { - for (a=1; a<=base->object->totcol; a++) { - ma= give_current_material(base->object, a); + for (a = 1; a <= base->object->totcol; a++) { + ma = give_current_material(base->object, a); - for (b=0; b<totcol; b++) { + for (b = 0; b < totcol; b++) { if (ma == matar[b]) break; } - if (b==totcol) { - matar[b]= ma; + if (b == totcol) { + matar[b] = ma; if (ma) { id_us_plus(&ma->id); } @@ -239,29 +240,29 @@ int join_mesh_exec(bContext *C, wmOperator *op) /* if this mesh has shapekeys, check if destination mesh already has matching entries too */ if (me->key && key) { - for (kb= me->key->block.first; kb; kb= kb->next) { + for (kb = me->key->block.first; kb; kb = kb->next) { /* if key doesn't exist in destination mesh, add it */ if (key_get_named_keyblock(key, kb->name) == NULL) { /* copy this existing one over to the new shapekey block */ - kbn= MEM_dupallocN(kb); - kbn->prev= kbn->next= NULL; + kbn = MEM_dupallocN(kb); + kbn->prev = kbn->next = NULL; /* adjust adrcode and other settings to fit (allocate a new data-array) */ - kbn->data= MEM_callocN(sizeof(float)*3*totvert, "joined_shapekey"); - kbn->totelem= totvert; - kbn->weights= NULL; + kbn->data = MEM_callocN(sizeof(float) * 3 * totvert, "joined_shapekey"); + kbn->totelem = totvert; + kbn->weights = NULL; - okb= key->block.last; - curpos= (okb) ? okb->pos : -0.1f; + okb = key->block.last; + curpos = (okb) ? okb->pos : -0.1f; if (key->type == KEY_RELATIVE) - kbn->pos= curpos + 0.1f; + kbn->pos = curpos + 0.1f; else - kbn->pos= curpos; + kbn->pos = curpos; BLI_addtail(&key->block, kbn); - kbn->adrcode= key->totkey; + kbn->adrcode = key->totkey; key->totkey++; - if (key->totkey==1) key->refkey= kbn; + if (key->totkey == 1) key->refkey = kbn; // XXX 2.5 Animato #if 0 @@ -286,23 +287,24 @@ int join_mesh_exec(bContext *C, wmOperator *op) memset(&ldata, 0, sizeof(ldata)); memset(&pdata, 0, sizeof(pdata)); - mvert= CustomData_add_layer(&vdata, CD_MVERT, CD_CALLOC, NULL, totvert); - medge= CustomData_add_layer(&edata, CD_MEDGE, CD_CALLOC, NULL, totedge); - mloop= CustomData_add_layer(&ldata, CD_MLOOP, CD_CALLOC, NULL, totloop); - mpoly= CustomData_add_layer(&pdata, CD_MPOLY, CD_CALLOC, NULL, totpoly); - - vertofs= 0; - edgeofs= 0; - loopofs= 0; - polyofs= 0; + mvert = CustomData_add_layer(&vdata, CD_MVERT, CD_CALLOC, NULL, totvert); + medge = CustomData_add_layer(&edata, CD_MEDGE, CD_CALLOC, NULL, totedge); + mloop = CustomData_add_layer(&ldata, CD_MLOOP, CD_CALLOC, NULL, totloop); + mpoly = CustomData_add_layer(&pdata, CD_MPOLY, CD_CALLOC, NULL, totpoly); + + vertofs = 0; + edgeofs = 0; + loopofs = 0; + polyofs = 0; /* inverse transform for all selected meshes in this object */ invert_m4_m4(imat, ob->obmat); - CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { + CTX_DATA_BEGIN(C, Base *, base, selected_editable_bases) + { /* only join if this is a mesh */ - if (base->object->type==OB_MESH) { - me= base->object->data; + if (base->object->type == OB_MESH) { + me = base->object->data; if (me->totvert) { /* standard data */ @@ -310,17 +312,17 @@ int join_mesh_exec(bContext *C, wmOperator *op) CustomData_copy_data(&me->vdata, &vdata, 0, vertofs, me->totvert); /* vertex groups */ - dvert= CustomData_get(&vdata, vertofs, CD_MDEFORMVERT); + dvert = CustomData_get(&vdata, vertofs, CD_MDEFORMVERT); /* NB: vertex groups here are new version */ if (dvert) { - for (i=0; i<me->totvert; i++) { - for (j=0; j<dvert[i].totweight; j++) { + for (i = 0; i < me->totvert; i++) { + for (j = 0; j < dvert[i].totweight; j++) { /* Find the old vertex group */ odg = BLI_findlink(&base->object->defbase, dvert[i].dw[j].def_nr); if (odg) { /* Search for a match in the new object, and set new index */ - for (dg=ob->defbase.first, index=0; dg; dg=dg->next, index++) { + for (dg = ob->defbase.first, index = 0; dg; dg = dg->next, index++) { if (!strcmp(dg->name, odg->name)) { dvert[i].dw[j].def_nr = index; break; @@ -337,7 +339,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) mult_m4_m4m4(cmat, imat, base->object->obmat); /* transform vertex coordinates into new space */ - for (a=0, mv=mvert; a < me->totvert; a++, mv++) { + for (a = 0, mv = mvert; a < me->totvert; a++, mv++) { mul_m4_v3(cmat, mv->co); } @@ -347,24 +349,24 @@ int join_mesh_exec(bContext *C, wmOperator *op) */ if (key) { /* if this mesh has any shapekeys, check first, otherwise just copy coordinates */ - for (kb= key->block.first; kb; kb= kb->next) { + for (kb = key->block.first; kb; kb = kb->next) { /* get pointer to where to write data for this mesh in shapekey's data array */ - fp1= ((float *)kb->data) + (vertofs*3); + fp1 = ((float *)kb->data) + (vertofs * 3); /* check if this mesh has such a shapekey */ - okb= key_get_named_keyblock(me->key, kb->name); + okb = key_get_named_keyblock(me->key, kb->name); if (okb) { /* copy this mesh's shapekey to the destination shapekey (need to transform first) */ - fp2= ((float *)(okb->data)); - for (a=0; a < me->totvert; a++, fp1+=3, fp2+=3) { + fp2 = ((float *)(okb->data)); + for (a = 0; a < me->totvert; a++, fp1 += 3, fp2 += 3) { copy_v3_v3(fp1, fp2); mul_m4_v3(cmat, fp1); } } else { /* copy this mesh's vertex coordinates to the destination shapekey */ - mv= mvert; - for (a=0; a < me->totvert; a++, fp1+=3, mv++) { + mv = mvert; + for (a = 0; a < me->totvert; a++, fp1 += 3, mv++) { copy_v3_v3(fp1, mv->co); } } @@ -377,23 +379,23 @@ int join_mesh_exec(bContext *C, wmOperator *op) * - otherwise, copy across plain coordinates (no need to transform coordinates) */ if (key) { - for (kb= key->block.first; kb; kb= kb->next) { + for (kb = key->block.first; kb; kb = kb->next) { /* get pointer to where to write data for this mesh in shapekey's data array */ - fp1= ((float *)kb->data) + (vertofs*3); + fp1 = ((float *)kb->data) + (vertofs * 3); /* check if this was one of the original shapekeys */ - okb= key_get_named_keyblock(nkey, kb->name); + okb = key_get_named_keyblock(nkey, kb->name); if (okb) { /* copy this mesh's shapekey to the destination shapekey */ - fp2= ((float *)(okb->data)); - for (a=0; a < me->totvert; a++, fp1+=3, fp2+=3) { + fp2 = ((float *)(okb->data)); + for (a = 0; a < me->totvert; a++, fp1 += 3, fp2 += 3) { copy_v3_v3(fp1, fp2); } } else { /* copy base-coordinates to the destination shapekey */ - mv= mvert; - for (a=0; a < me->totvert; a++, fp1+=3, mv++) { + mv = mvert; + for (a = 0; a < me->totvert; a++, fp1 += 3, mv++) { copy_v3_v3(fp1, mv->co); } } @@ -402,27 +404,27 @@ int join_mesh_exec(bContext *C, wmOperator *op) } /* advance mvert pointer to end of base mesh's data */ - mvert+= me->totvert; + mvert += me->totvert; } if (me->totedge) { CustomData_merge(&me->edata, &edata, CD_MASK_MESH, CD_DEFAULT, totedge); CustomData_copy_data(&me->edata, &edata, 0, edgeofs, me->totedge); - for (a=0; a<me->totedge; a++, medge++) { - medge->v1+= vertofs; - medge->v2+= vertofs; + for (a = 0; a < me->totedge; a++, medge++) { + medge->v1 += vertofs; + medge->v2 += vertofs; } } if (me->totloop) { - if (base->object!=ob) + if (base->object != ob) multiresModifier_prepare_join(scene, base->object, ob); CustomData_merge(&me->ldata, &ldata, CD_MASK_MESH, CD_DEFAULT, totloop); CustomData_copy_data(&me->ldata, &ldata, 0, loopofs, me->totloop); - for (a=0; a<me->totloop; a++, mloop++) { + for (a = 0; a < me->totloop; a++, mloop++) { mloop->v += vertofs; mloop->e += edgeofs; } @@ -430,12 +432,12 @@ int join_mesh_exec(bContext *C, wmOperator *op) if (me->totpoly) { /* make mapping for materials */ - for (a=1; a<=base->object->totcol; a++) { - ma= give_current_material(base->object, a); + for (a = 1; a <= base->object->totcol; a++) { + ma = give_current_material(base->object, a); - for (b=0; b<totcol; b++) { + for (b = 0; b < totcol; b++) { if (ma == matar[b]) { - matmap[a-1]= b; + matmap[a - 1] = b; break; } } @@ -444,9 +446,9 @@ int join_mesh_exec(bContext *C, wmOperator *op) CustomData_merge(&me->pdata, &pdata, CD_MASK_MESH, CD_DEFAULT, totpoly); CustomData_copy_data(&me->pdata, &pdata, 0, polyofs, me->totpoly); - for (a=0; a<me->totpoly; a++, mpoly++) { + for (a = 0; a < me->totpoly; a++, mpoly++) { mpoly->loopstart += loopofs; - mpoly->mat_nr= matmap ? matmap[(int)mpoly->mat_nr] : 0; + mpoly->mat_nr = matmap ? matmap[(int)mpoly->mat_nr] : 0; } polyofs += me->totpoly; @@ -467,49 +469,49 @@ int join_mesh_exec(bContext *C, wmOperator *op) CTX_DATA_END; /* return to mesh we're merging to */ - me= ob->data; + me = ob->data; CustomData_free(&me->vdata, me->totvert); CustomData_free(&me->edata, me->totedge); CustomData_free(&me->ldata, me->totloop); CustomData_free(&me->pdata, me->totpoly); - me->totvert= totvert; - me->totedge= totedge; - me->totloop= totloop; - me->totpoly= totpoly; - - me->vdata= vdata; - me->edata= edata; - me->ldata= ldata; - me->pdata= pdata; + me->totvert = totvert; + me->totedge = totedge; + me->totloop = totloop; + me->totpoly = totpoly; + + me->vdata = vdata; + me->edata = edata; + me->ldata = ldata; + me->pdata = pdata; mesh_update_customdata_pointers(me, TRUE); /* BMESH_TODO, check if this arg can be failse, non urgent - campbell */ /* old material array */ - for (a=1; a<=ob->totcol; a++) { - ma= ob->mat[a-1]; + for (a = 1; a <= ob->totcol; a++) { + ma = ob->mat[a - 1]; if (ma) ma->id.us--; } - for (a=1; a<=me->totcol; a++) { - ma= me->mat[a-1]; + for (a = 1; a <= me->totcol; a++) { + ma = me->mat[a - 1]; if (ma) ma->id.us--; } if (ob->mat) MEM_freeN(ob->mat); if (ob->matbits) MEM_freeN(ob->matbits); if (me->mat) MEM_freeN(me->mat); - ob->mat= me->mat= NULL; - ob->matbits= NULL; + ob->mat = me->mat = NULL; + ob->matbits = NULL; if (totcol) { - me->mat= matar; - ob->mat= MEM_callocN(sizeof(void *)*totcol, "join obmatar"); - ob->matbits= MEM_callocN(sizeof(char)*totcol, "join obmatbits"); + me->mat = matar; + ob->mat = MEM_callocN(sizeof(void *) * totcol, "join obmatar"); + ob->matbits = MEM_callocN(sizeof(char) * totcol, "join obmatbits"); } else MEM_freeN(matar); - ob->totcol= me->totcol= totcol; + ob->totcol = me->totcol = totcol; if (matmap) MEM_freeN(matmap); @@ -533,21 +535,21 @@ int join_mesh_exec(bContext *C, wmOperator *op) MEM_freeN(nkey); } - DAG_scene_sort(bmain, scene); // removed objects, need to rebuild dag before editmode call + DAG_scene_sort(bmain, scene); // removed objects, need to rebuild dag before editmode call #if 0 ED_object_enter_editmode(C, EM_WAITCURSOR); - ED_object_exit_editmode(C, EM_FREEDATA|EM_WAITCURSOR|EM_DO_UNDO); + ED_object_exit_editmode(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO); #else /* toggle editmode using lower level functions so this can be called from python */ - EDBM_MakeEditBMesh(scene->toolsettings, scene, ob); - EDBM_LoadEditBMesh(scene, ob); - EDBM_FreeEditBMesh(me->edit_btmesh); + EDBM_mesh_make(scene->toolsettings, scene, ob); + EDBM_mesh_load(ob); + EDBM_mesh_free(me->edit_btmesh); MEM_freeN(me->edit_btmesh); - me->edit_btmesh= NULL; - DAG_id_tag_update(&ob->id, OB_RECALC_OB|OB_RECALC_DATA); + me->edit_btmesh = NULL; + DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA); #endif - WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene); + WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); return OPERATOR_FINISHED; } @@ -559,25 +561,25 @@ int join_mesh_exec(bContext *C, wmOperator *op) int join_mesh_shapes_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); - Object *ob= CTX_data_active_object(C); - Mesh *me= (Mesh *)ob->data; - Mesh *selme=NULL; - DerivedMesh *dm=NULL; - Key *key=me->key; + Scene *scene = CTX_data_scene(C); + Object *ob = CTX_data_active_object(C); + Mesh *me = (Mesh *)ob->data; + Mesh *selme = NULL; + DerivedMesh *dm = NULL; + Key *key = me->key; KeyBlock *kb; - int ok=0, nonequal_verts=0; + int ok = 0, nonequal_verts = 0; - CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { + CTX_DATA_BEGIN(C, Base *, base, selected_editable_bases) { if (base->object == ob) continue; - if (base->object->type==OB_MESH) { + if (base->object->type == OB_MESH) { selme = (Mesh *)base->object->data; - if (selme->totvert==me->totvert) + if (selme->totvert == me->totvert) ok++; else - nonequal_verts=1; + nonequal_verts = 1; } } CTX_DATA_END; @@ -591,27 +593,28 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) } if (key == NULL) { - key= me->key= add_key((ID *)me); - key->type= KEY_RELATIVE; + key = me->key = add_key((ID *)me); + key->type = KEY_RELATIVE; /* first key added, so it was the basis. initialize it with the existing mesh */ - kb= add_keyblock(key, NULL); + kb = add_keyblock(key, NULL); mesh_to_key(me, kb); } /* now ready to add new keys from selected meshes */ - CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { + CTX_DATA_BEGIN(C, Base *, base, selected_editable_bases) + { if (base->object == ob) continue; - if (base->object->type==OB_MESH) { + if (base->object->type == OB_MESH) { selme = (Mesh *)base->object->data; - if (selme->totvert==me->totvert) { + if (selme->totvert == me->totvert) { dm = mesh_get_derived_deform(scene, base->object, CD_MASK_BAREMESH); if (!dm) continue; - kb= add_keyblock(key, base->object->id.name+2); + kb = add_keyblock(key, base->object->id.name + 2); DM_to_meshkey(dm, me, kb); @@ -621,7 +624,7 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) } CTX_DATA_END; - WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene); + WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); return OPERATOR_FINISHED; } @@ -630,9 +633,9 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) /* important note; this is unfinished, needs better API for editmode, and custom threshold */ -#define MOC_RES 8 -#define MOC_NODE_RES 8 -#define MOC_THRESH 0.00002f +#define MOC_RES 8 +#define MOC_NODE_RES 8 +#define MOC_THRESH 0.00002f typedef struct MocNode { struct MocNode *next; @@ -643,30 +646,30 @@ static int mesh_octree_get_base_offs(float *co, float *offs, float *div) { int vx, vy, vz; - vx= floor( (co[0]-offs[0])/div[0] ); - vy= floor( (co[1]-offs[1])/div[1] ); - vz= floor( (co[2]-offs[2])/div[2] ); - - CLAMP(vx, 0, MOC_RES-1); - CLAMP(vy, 0, MOC_RES-1); - CLAMP(vz, 0, MOC_RES-1); + vx = floor( (co[0] - offs[0]) / div[0]); + vy = floor( (co[1] - offs[1]) / div[1]); + vz = floor( (co[2] - offs[2]) / div[2]); - return (vx*MOC_RES*MOC_RES) + vy*MOC_RES + vz; + CLAMP(vx, 0, MOC_RES - 1); + CLAMP(vy, 0, MOC_RES - 1); + CLAMP(vz, 0, MOC_RES - 1); + + return (vx * MOC_RES * MOC_RES) + vy * MOC_RES + vz; } static void mesh_octree_add_node(MocNode **bt, intptr_t index) { - if (*bt==NULL) { - *bt= MEM_callocN(sizeof(MocNode), "MocNode"); - (*bt)->index[0]= index; + if (*bt == NULL) { + *bt = MEM_callocN(sizeof(MocNode), "MocNode"); + (*bt)->index[0] = index; } else { int a; - for (a=0; a<MOC_NODE_RES; a++) { - if ((*bt)->index[a]==index) + for (a = 0; a < MOC_NODE_RES; a++) { + if ((*bt)->index[a] == index) return; - else if ((*bt)->index[a]==0) { - (*bt)->index[a]= index; + else if ((*bt)->index[a] == 0) { + (*bt)->index[a] = index; return; } } @@ -676,7 +679,7 @@ static void mesh_octree_add_node(MocNode **bt, intptr_t index) static void mesh_octree_free_node(MocNode **bt) { - if ( (*bt)->next ) { + if ( (*bt)->next) { mesh_octree_free_node(&(*bt)->next); } MEM_freeN(*bt); @@ -684,52 +687,52 @@ static void mesh_octree_free_node(MocNode **bt) /* temporal define, just to make nicer code below */ -#define MOC_INDEX(vx, vy, vz) (((vx)*MOC_RES*MOC_RES) + (vy)*MOC_RES + (vz)) +#define MOC_INDEX(vx, vy, vz) (((vx) * MOC_RES * MOC_RES) + (vy) * MOC_RES + (vz)) static void mesh_octree_add_nodes(MocNode **basetable, float *co, float *offs, float *div, intptr_t index) { float fx, fy, fz; int vx, vy, vz; - if ( !finite(co[0]) || - !finite(co[1]) || - !finite(co[2])) + if (!finite(co[0]) || + !finite(co[1]) || + !finite(co[2])) { return; } - fx= (co[0]-offs[0])/div[0]; - fy= (co[1]-offs[1])/div[1]; - fz= (co[2]-offs[2])/div[2]; - CLAMP(fx, 0.0f, MOC_RES-MOC_THRESH); - CLAMP(fy, 0.0f, MOC_RES-MOC_THRESH); - CLAMP(fz, 0.0f, MOC_RES-MOC_THRESH); - - vx= (int)floorf(fx); - vy= (int)floorf(fy); - vz= (int)floorf(fz); + fx = (co[0] - offs[0]) / div[0]; + fy = (co[1] - offs[1]) / div[1]; + fz = (co[2] - offs[2]) / div[2]; + CLAMP(fx, 0.0f, MOC_RES - MOC_THRESH); + CLAMP(fy, 0.0f, MOC_RES - MOC_THRESH); + CLAMP(fz, 0.0f, MOC_RES - MOC_THRESH); + + vx = (int)floorf(fx); + vy = (int)floorf(fy); + vz = (int)floorf(fz); mesh_octree_add_node(basetable + MOC_INDEX(vx, vy, vz), index); if (vx > 0) - if (fx-((float)vx)-MOC_THRESH < 0.0f) + if (fx - ((float)vx) - MOC_THRESH < 0.0f) mesh_octree_add_node(basetable + MOC_INDEX(vx - 1, vy, vz), index); if (vx < MOC_RES - 2) - if (fx-((float)vx)+MOC_THRESH > 1.0f) + if (fx - ((float)vx) + MOC_THRESH > 1.0f) mesh_octree_add_node(basetable + MOC_INDEX(vx + 1, vy, vz), index); if (vy > 0) - if (fy-((float)vy)-MOC_THRESH < 0.0f) + if (fy - ((float)vy) - MOC_THRESH < 0.0f) mesh_octree_add_node(basetable + MOC_INDEX(vx, vy - 1, vz), index); if (vy < MOC_RES - 2) - if (fy-((float)vy)+MOC_THRESH > 1.0f) + if (fy - ((float)vy) + MOC_THRESH > 1.0f) mesh_octree_add_node(basetable + MOC_INDEX(vx, vy + 1, vz), index); if (vz > 0) - if (fz-((float)vz)-MOC_THRESH < 0.0f) + if (fz - ((float)vz) - MOC_THRESH < 0.0f) mesh_octree_add_node(basetable + MOC_INDEX(vx, vy, vz - 1), index); - if (vz <MOC_RES - 2) - if (fz-((float)vz)+MOC_THRESH > 1.0f) + if (vz < MOC_RES - 2) + if (fz - ((float)vz) + MOC_THRESH > 1.0f) mesh_octree_add_node(basetable + MOC_INDEX(vx, vy, vz + 1), index); } @@ -739,19 +742,19 @@ static intptr_t mesh_octree_find_index(MocNode **bt, MVert *mvert, float *co) float *vec; int a; - if (*bt==NULL) + if (*bt == NULL) return -1; - for (a=0; a<MOC_NODE_RES; a++) { + for (a = 0; a < MOC_NODE_RES; a++) { if ((*bt)->index[a]) { /* does mesh verts and editmode, code looks potential dangerous, octree should really be filled OK! */ if (mvert) { - vec= (mvert+(*bt)->index[a]-1)->co; + vec = (mvert + (*bt)->index[a] - 1)->co; if (compare_v3v3(vec, co, MOC_THRESH)) - return (*bt)->index[a]-1; + return (*bt)->index[a] - 1; } else { - BMVert *eve= (BMVert *)((*bt)->index[a]); + BMVert *eve = (BMVert *)((*bt)->index[a]); if (compare_v3v3(eve->co, co, MOC_THRESH)) return (*bt)->index[a]; } @@ -775,13 +778,13 @@ intptr_t mesh_octree_table(Object *ob, BMEditMesh *em, float *co, char mode) { MocNode **bt; - if (mode=='u') { /* use table */ - if (MeshOctree.table==NULL) + if (mode == 'u') { /* use table */ + if (MeshOctree.table == NULL) mesh_octree_table(ob, em, NULL, 's'); if (MeshOctree.table) { - Mesh *me= ob->data; - bt= MeshOctree.table + mesh_octree_get_base_offs(co, MeshOctree.offs, MeshOctree.div); + Mesh *me = ob->data; + bt = MeshOctree.table + mesh_octree_get_base_offs(co, MeshOctree.offs, MeshOctree.div); if (em) return mesh_octree_find_index(bt, NULL, co); else @@ -789,19 +792,20 @@ intptr_t mesh_octree_table(Object *ob, BMEditMesh *em, float *co, char mode) } return -1; } - else if (mode=='s') { /* start table */ - Mesh *me= ob->data; + else if (mode == 's') { /* start table */ + Mesh *me = ob->data; float min[3], max[3]; /* we compute own bounding box and don't reuse ob->bb because * we are using the undeformed coordinates*/ INIT_MINMAX(min, max); - if (em && me->edit_btmesh==em) { + if (em && me->edit_btmesh == em) { BMIter iter; BMVert *eve; - BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { + BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) + { DO_MINMAX(eve->co, min, max); } } @@ -809,36 +813,37 @@ intptr_t mesh_octree_table(Object *ob, BMEditMesh *em, float *co, char mode) MVert *mvert; int a; - for (a=0, mvert= me->mvert; a<me->totvert; a++, mvert++) + for (a = 0, mvert = me->mvert; a < me->totvert; a++, mvert++) DO_MINMAX(mvert->co, min, max); } /* for quick unit coordinate calculus */ copy_v3_v3(MeshOctree.offs, min); - MeshOctree.offs[0]-= MOC_THRESH; /* we offset it 1 threshold unit extra */ - MeshOctree.offs[1]-= MOC_THRESH; - MeshOctree.offs[2]-= MOC_THRESH; + MeshOctree.offs[0] -= MOC_THRESH; /* we offset it 1 threshold unit extra */ + MeshOctree.offs[1] -= MOC_THRESH; + MeshOctree.offs[2] -= MOC_THRESH; sub_v3_v3v3(MeshOctree.div, max, min); - MeshOctree.div[0]+= 2*MOC_THRESH; /* and divide with 2 threshold unit more extra (try 8x8 unit grid on paint) */ - MeshOctree.div[1]+= 2*MOC_THRESH; - MeshOctree.div[2]+= 2*MOC_THRESH; - - mul_v3_fl(MeshOctree.div, 1.0f/MOC_RES); - if (MeshOctree.div[0]==0.0f) MeshOctree.div[0]= 1.0f; - if (MeshOctree.div[1]==0.0f) MeshOctree.div[1]= 1.0f; - if (MeshOctree.div[2]==0.0f) MeshOctree.div[2]= 1.0f; + MeshOctree.div[0] += 2 * MOC_THRESH; /* and divide with 2 threshold unit more extra (try 8x8 unit grid on paint) */ + MeshOctree.div[1] += 2 * MOC_THRESH; + MeshOctree.div[2] += 2 * MOC_THRESH; + + mul_v3_fl(MeshOctree.div, 1.0f / MOC_RES); + if (MeshOctree.div[0] == 0.0f) MeshOctree.div[0] = 1.0f; + if (MeshOctree.div[1] == 0.0f) MeshOctree.div[1] = 1.0f; + if (MeshOctree.div[2] == 0.0f) MeshOctree.div[2] = 1.0f; if (MeshOctree.table) /* happens when entering this call without ending it */ mesh_octree_table(ob, em, co, 'e'); - MeshOctree.table= MEM_callocN(MOC_RES*MOC_RES*MOC_RES*sizeof(void *), "sym table"); + MeshOctree.table = MEM_callocN(MOC_RES * MOC_RES * MOC_RES * sizeof(void *), "sym table"); - if (em && me->edit_btmesh==em) { + if (em && me->edit_btmesh == em) { BMVert *eve; BMIter iter; - BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { + BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) + { mesh_octree_add_nodes(MeshOctree.table, eve->co, MeshOctree.offs, MeshOctree.div, (intptr_t)(eve)); } } @@ -846,40 +851,40 @@ intptr_t mesh_octree_table(Object *ob, BMEditMesh *em, float *co, char mode) MVert *mvert; int a; - for (a=0, mvert= me->mvert; a<me->totvert; a++, mvert++) - mesh_octree_add_nodes(MeshOctree.table, mvert->co, MeshOctree.offs, MeshOctree.div, a+1); + for (a = 0, mvert = me->mvert; a < me->totvert; a++, mvert++) + mesh_octree_add_nodes(MeshOctree.table, mvert->co, MeshOctree.offs, MeshOctree.div, a + 1); } } - else if (mode=='e') { /* end table */ + else if (mode == 'e') { /* end table */ if (MeshOctree.table) { int a; - for (a=0, bt=MeshOctree.table; a<MOC_RES*MOC_RES*MOC_RES; a++, bt++) { + for (a = 0, bt = MeshOctree.table; a < MOC_RES * MOC_RES * MOC_RES; a++, bt++) { if (*bt) mesh_octree_free_node(bt); } MEM_freeN(MeshOctree.table); - MeshOctree.table= NULL; + MeshOctree.table = NULL; } } return 0; } -MirrTopoStore_t mesh_topo_store= {NULL, -1. -1, -1}; +MirrTopoStore_t mesh_topo_store = {NULL, -1. - 1, -1}; /* mode is 's' start, or 'e' end, or 'u' use */ /* if end, ob can be NULL */ /* note, is supposed return -1 on error, which callers are currently checking for, but is not used so far */ int mesh_mirrtopo_table(Object *ob, char mode) { - if (mode=='u') { /* use table */ + if (mode == 'u') { /* use table */ if (ED_mesh_mirrtopo_recalc_check(ob->data, ob->mode, &mesh_topo_store)) { mesh_mirrtopo_table(ob, 's'); } } - else if (mode=='s') { /* start table */ + else if (mode == 's') { /* start table */ ED_mesh_mirrtopo_init(ob->data, ob->mode, &mesh_topo_store, FALSE); } - else if (mode=='e') { /* end table */ + else if (mode == 'e') { /* end table */ ED_mesh_mirrtopo_free(&mesh_topo_store); } return 0; @@ -887,21 +892,21 @@ int mesh_mirrtopo_table(Object *ob, char mode) static int mesh_get_x_mirror_vert_spacial(Object *ob, int index) { - Mesh *me= ob->data; + Mesh *me = ob->data; MVert *mvert; float vec[3]; - mvert= me->mvert+index; - vec[0]= -mvert->co[0]; - vec[1]= mvert->co[1]; - vec[2]= mvert->co[2]; + mvert = me->mvert + index; + vec[0] = -mvert->co[0]; + vec[1] = mvert->co[1]; + vec[2] = mvert->co[2]; return mesh_octree_table(ob, NULL, vec, 'u'); } static int mesh_get_x_mirror_vert_topo(Object *ob, int index) { - if (mesh_mirrtopo_table(ob, 'u')==-1) + if (mesh_mirrtopo_table(ob, 'u') == -1) return -1; return mesh_topo_store.index_lookup[index]; @@ -925,16 +930,16 @@ static BMVert *editbmesh_get_x_mirror_vert_spacial(Object *ob, BMEditMesh *em, f /* ignore nan verts */ if (!finite(co[0]) || - !finite(co[1]) || - !finite(co[2]) - ) + !finite(co[1]) || + !finite(co[2]) + ) return NULL; - vec[0]= -co[0]; - vec[1]= co[1]; - vec[2]= co[2]; + vec[0] = -co[0]; + vec[1] = co[1]; + vec[2] = co[2]; - poinval= mesh_octree_table(ob, em, vec, 'u'); + poinval = mesh_octree_table(ob, em, vec, 'u'); if (poinval != -1) return (BMVert *)(poinval); return NULL; @@ -943,7 +948,7 @@ static BMVert *editbmesh_get_x_mirror_vert_spacial(Object *ob, BMEditMesh *em, f static BMVert *editbmesh_get_x_mirror_vert_topo(Object *ob, struct BMEditMesh *em, BMVert *eve, int index) { intptr_t poinval; - if (mesh_mirrtopo_table(ob, 'u')==-1) + if (mesh_mirrtopo_table(ob, 'u') == -1) return NULL; if (index == -1) { @@ -951,7 +956,8 @@ static BMVert *editbmesh_get_x_mirror_vert_topo(Object *ob, struct BMEditMesh *e BMVert *v; index = 0; - BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { + BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) + { if (v == eve) break; index++; @@ -962,7 +968,7 @@ static BMVert *editbmesh_get_x_mirror_vert_topo(Object *ob, struct BMEditMesh *e } } - poinval= mesh_topo_store.index_lookup[index]; + poinval = mesh_topo_store.index_lookup[index]; if (poinval != -1) return (BMVert *)(poinval); @@ -989,22 +995,22 @@ static float *editmesh_get_mirror_uv(BMEditMesh *em, int axis, float *uv, float /* ignore nan verts */ if (isnan(uv[0]) || !finite(uv[0]) || - isnan(uv[1]) || !finite(uv[1]) - ) + isnan(uv[1]) || !finite(uv[1]) + ) return NULL; if (axis) { - vec[0]= uv[0]; - vec[1]= -((uv[1])-mirrCent[1]) + mirrCent[1]; + vec[0] = uv[0]; + vec[1] = -((uv[1]) - mirrCent[1]) + mirrCent[1]; cent_vec[0] = face_cent[0]; - cent_vec[1]= -((face_cent[1])-mirrCent[1]) + mirrCent[1]; + cent_vec[1] = -((face_cent[1]) - mirrCent[1]) + mirrCent[1]; } else { - vec[0]= -((uv[0])-mirrCent[0]) + mirrCent[0]; - vec[1]= uv[1]; + vec[0] = -((uv[0]) - mirrCent[0]) + mirrCent[0]; + vec[1] = uv[1]; - cent_vec[0]= -((face_cent[0])-mirrCent[0]) + mirrCent[0]; + cent_vec[0] = -((face_cent[0]) - mirrCent[0]) + mirrCent[0]; cent_vec[1] = face_cent[1]; } @@ -1013,23 +1019,25 @@ static float *editmesh_get_mirror_uv(BMEditMesh *em, int axis, float *uv, float BMIter iter; BMFace *efa; - BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { + BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) + { poly_uv_center(em, efa, cent); if ( (fabs(cent[0] - cent_vec[0]) < 0.001) && (fabs(cent[1] - cent_vec[1]) < 0.001) ) { BMIter liter; BMLoop *l; - BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { + BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) + { MLoopUV *luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); if ( (fabs(luv->uv[0] - vec[0]) < 0.001) && (fabs(luv->uv[1] - vec[1]) < 0.001) ) { return luv->uv; + } } } } } - } return NULL; } @@ -1038,39 +1046,39 @@ static float *editmesh_get_mirror_uv(BMEditMesh *em, int axis, float *uv, float static unsigned int mirror_facehash(const void *ptr) { - const MFace *mf= ptr; + const MFace *mf = ptr; int v0, v1; if (mf->v4) { - v0= MIN4(mf->v1, mf->v2, mf->v3, mf->v4); - v1= MAX4(mf->v1, mf->v2, mf->v3, mf->v4); + v0 = MIN4(mf->v1, mf->v2, mf->v3, mf->v4); + v1 = MAX4(mf->v1, mf->v2, mf->v3, mf->v4); } else { - v0= MIN3(mf->v1, mf->v2, mf->v3); - v1= MAX3(mf->v1, mf->v2, mf->v3); + v0 = MIN3(mf->v1, mf->v2, mf->v3); + v1 = MAX3(mf->v1, mf->v2, mf->v3); } - return ((v0*39)^(v1*31)); + return ((v0 * 39) ^ (v1 * 31)); } static int mirror_facerotation(MFace *a, MFace *b) { if (b->v4) { - if (a->v1==b->v1 && a->v2==b->v2 && a->v3==b->v3 && a->v4==b->v4) + if (a->v1 == b->v1 && a->v2 == b->v2 && a->v3 == b->v3 && a->v4 == b->v4) return 0; - else if (a->v4==b->v1 && a->v1==b->v2 && a->v2==b->v3 && a->v3==b->v4) + else if (a->v4 == b->v1 && a->v1 == b->v2 && a->v2 == b->v3 && a->v3 == b->v4) return 1; - else if (a->v3==b->v1 && a->v4==b->v2 && a->v1==b->v3 && a->v2==b->v4) + else if (a->v3 == b->v1 && a->v4 == b->v2 && a->v1 == b->v3 && a->v2 == b->v4) return 2; - else if (a->v2==b->v1 && a->v3==b->v2 && a->v4==b->v3 && a->v1==b->v4) + else if (a->v2 == b->v1 && a->v3 == b->v2 && a->v4 == b->v3 && a->v1 == b->v4) return 3; } else { - if (a->v1==b->v1 && a->v2==b->v2 && a->v3==b->v3) + if (a->v1 == b->v1 && a->v2 == b->v2 && a->v3 == b->v3) return 0; - else if (a->v3==b->v1 && a->v1==b->v2 && a->v2==b->v3) + else if (a->v3 == b->v1 && a->v1 == b->v2 && a->v2 == b->v3) return 1; - else if (a->v2==b->v1 && a->v3==b->v2 && a->v1==b->v3) + else if (a->v2 == b->v1 && a->v3 == b->v2 && a->v1 == b->v3) return 2; } @@ -1079,52 +1087,52 @@ static int mirror_facerotation(MFace *a, MFace *b) static int mirror_facecmp(const void *a, const void *b) { - return (mirror_facerotation((MFace*)a, (MFace*)b) == -1); + return (mirror_facerotation((MFace *)a, (MFace *)b) == -1); } /* BMESH_TODO, convert to MPoly (functions above also) */ int *mesh_get_x_mirror_faces(Object *ob, BMEditMesh *em) { - Mesh *me= ob->data; - MVert *mv, *mvert= me->mvert; - MFace mirrormf, *mf, *hashmf, *mface= me->mface; + Mesh *me = ob->data; + MVert *mv, *mvert = me->mvert; + MFace mirrormf, *mf, *hashmf, *mface = me->mface; GHash *fhash; int *mirrorverts, *mirrorfaces; int a; - mirrorverts= MEM_callocN(sizeof(int)*me->totvert, "MirrorVerts"); - mirrorfaces= MEM_callocN(sizeof(int)*2*me->totface, "MirrorFaces"); + mirrorverts = MEM_callocN(sizeof(int) * me->totvert, "MirrorVerts"); + mirrorfaces = MEM_callocN(sizeof(int) * 2 * me->totface, "MirrorFaces"); mesh_octree_table(ob, em, NULL, 's'); - for (a=0, mv=mvert; a<me->totvert; a++, mv++) - mirrorverts[a]= mesh_get_x_mirror_vert(ob, a); + for (a = 0, mv = mvert; a < me->totvert; a++, mv++) + mirrorverts[a] = mesh_get_x_mirror_vert(ob, a); mesh_octree_table(ob, em, NULL, 'e'); - fhash= BLI_ghash_new(mirror_facehash, mirror_facecmp, "mirror_facehash gh"); - for (a=0, mf=mface; a<me->totface; a++, mf++) + fhash = BLI_ghash_new(mirror_facehash, mirror_facecmp, "mirror_facehash gh"); + for (a = 0, mf = mface; a < me->totface; a++, mf++) BLI_ghash_insert(fhash, mf, mf); - for (a=0, mf=mface; a<me->totface; a++, mf++) { - mirrormf.v1= mirrorverts[mf->v3]; - mirrormf.v2= mirrorverts[mf->v2]; - mirrormf.v3= mirrorverts[mf->v1]; - mirrormf.v4= (mf->v4)? mirrorverts[mf->v4]: 0; + for (a = 0, mf = mface; a < me->totface; a++, mf++) { + mirrormf.v1 = mirrorverts[mf->v3]; + mirrormf.v2 = mirrorverts[mf->v2]; + mirrormf.v3 = mirrorverts[mf->v1]; + mirrormf.v4 = (mf->v4) ? mirrorverts[mf->v4] : 0; /* make sure v4 is not 0 if a quad */ - if (mf->v4 && mirrormf.v4==0) { + if (mf->v4 && mirrormf.v4 == 0) { SWAP(unsigned int, mirrormf.v1, mirrormf.v3); SWAP(unsigned int, mirrormf.v2, mirrormf.v4); } - hashmf= BLI_ghash_lookup(fhash, &mirrormf); + hashmf = BLI_ghash_lookup(fhash, &mirrormf); if (hashmf) { - mirrorfaces[a*2]= hashmf - mface; - mirrorfaces[a*2+1]= mirror_facerotation(&mirrormf, hashmf); + mirrorfaces[a * 2] = hashmf - mface; + mirrorfaces[a * 2 + 1] = mirror_facerotation(&mirrormf, hashmf); } else - mirrorfaces[a*2]= -1; + mirrorfaces[a * 2] = -1; } BLI_ghash_free(fhash, NULL, NULL); |