diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-07-03 13:53:06 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-07-03 13:53:06 +0400 |
commit | 6d9de6a72b74191986ae77ff39079d1e9e68f58b (patch) | |
tree | fef3c81044e9dc10d85be2213932470b52d11fe3 | |
parent | 905cb1639ad8f82502ecf9f1701963972f96080e (diff) |
fix [#35975] "Select Linked" = "Select All" in Weight Paint mode?
looks like this was broken since bmesh merge.
-rw-r--r-- | source/blender/blenkernel/BKE_mesh.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 14 | ||||
-rw-r--r-- | source/blender/editors/include/ED_mesh.h | 2 | ||||
-rw-r--r-- | source/blender/editors/mesh/editface.c | 94 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_ops.c | 5 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_utils.c | 7 |
6 files changed, 58 insertions, 65 deletions
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index de1f3deaf81..11c9c00613f 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -366,6 +366,7 @@ void BKE_mesh_loops_to_mface_corners(struct CustomData *fdata, struct CustomData const int numTex, const int numCol, const int hasPCol, const int hasOrigSpace); void BKE_mesh_poly_edgehash_insert(struct EdgeHash *ehash, const struct MPoly *mp, const struct MLoop *mloop); +void BKE_mesh_poly_edgebitmap_insert(unsigned int *edge_bitmap, const struct MPoly *mp, const struct MLoop *mloop); void BKE_mesh_do_versions_cd_flag_init(struct Mesh *mesh); diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 4ec86cbac7b..b40c3475df5 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -48,6 +48,7 @@ #include "BLI_blenlib.h" #include "BLI_math.h" #include "BLI_edgehash.h" +#include "BLI_bitmap.h" #include "BLI_scanfill.h" #include "BLI_array.h" @@ -3802,6 +3803,19 @@ void BKE_mesh_poly_edgehash_insert(EdgeHash *ehash, const MPoly *mp, const MLoop } } +void BKE_mesh_poly_edgebitmap_insert(unsigned int *edge_bitmap, const MPoly *mp, const MLoop *mloop) +{ + const MLoop *ml; + int i = mp->totloop; + + ml = mloop; + + while (i-- != 0) { + BLI_BITMAP_SET(edge_bitmap, ml->e); + ml++; + } +} + void BKE_mesh_do_versions_cd_flag_init(Mesh *mesh) { if (UNLIKELY(mesh->cd_flag)) { diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index f318e17ba32..807d94b56b0 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -204,7 +204,7 @@ void paintface_flush_flags(struct Object *ob); bool paintface_mouse_select(struct bContext *C, struct Object *ob, const int mval[2], bool extend, bool deselect, bool toggle); int do_paintface_box_select(struct ViewContext *vc, struct rcti *rect, bool select, bool extend); void paintface_deselect_all_visible(struct Object *ob, int action, bool flush_flags); -void paintface_select_linked(struct bContext *C, struct Object *ob, const int mval[2], int mode); +void paintface_select_linked(struct bContext *C, struct Object *ob, const int mval[2], const bool select); bool paintface_minmax(struct Object *ob, float r_min[3], float r_max[3]); void paintface_hide(struct Object *ob, const bool unselected); diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c index 5dd09962d1d..b2c7846ab6c 100644 --- a/source/blender/editors/mesh/editface.c +++ b/source/blender/editors/mesh/editface.c @@ -30,6 +30,7 @@ #include "BLI_blenlib.h" #include "BLI_math.h" #include "BLI_edgehash.h" +#include "BLI_bitmap.h" #include "BLF_translation.h" @@ -44,6 +45,7 @@ #include "BKE_mesh.h" #include "BKE_context.h" #include "BKE_editmesh.h" +#include "BKE_utildefines.h" #include "BIF_gl.h" @@ -182,29 +184,22 @@ void paintface_reveal(Object *ob) /* Set tface seams based on edge data, uses hash table to find seam edges. */ -static void select_linked_tfaces_with_seams(int mode, Mesh *me, unsigned int index) +static void select_linked_tfaces_with_seams(Mesh *me, const unsigned int index, const bool select) { - EdgeHash *ehash, *seamhash; MPoly *mp; MLoop *ml; - MEdge *med; - char *linkflag; - int a, b, mark = 0; + int a, b; bool do_it = true; + bool mark = false; - ehash = BLI_edgehash_new(); - seamhash = BLI_edgehash_new(); - linkflag = MEM_callocN(sizeof(char) * me->totpoly, "linkflaguv"); - - 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); + BLI_bitmap edge_tag = BLI_BITMAP_NEW(me->totedge, __func__); + BLI_bitmap poly_tag = BLI_BITMAP_NEW(me->totpoly, __func__); - if (mode == 0 || mode == 1) { + if (index != (unsigned int)-1) { /* only put face under cursor in array */ - mp = ((MPoly *)me->mpoly) + index; - BKE_mesh_poly_edgehash_insert(ehash, mp, me->mloop + mp->loopstart); - linkflag[index] = 1; + mp = &me->mpoly[index]; + BKE_mesh_poly_edgebitmap_insert(edge_tag, mp, me->mloop + mp->loopstart); + BLI_BITMAP_SET(poly_tag, index); } else { /* fill array by selection */ @@ -214,8 +209,8 @@ static void select_linked_tfaces_with_seams(int mode, Mesh *me, unsigned int ind /* pass */ } else if (mp->flag & ME_FACE_SEL) { - BKE_mesh_poly_edgehash_insert(ehash, mp, me->mloop + mp->loopstart); - linkflag[a] = 1; + BKE_mesh_poly_edgebitmap_insert(edge_tag, mp, me->mloop + mp->loopstart); + BLI_BITMAP_SET(poly_tag, a); } } } @@ -229,75 +224,54 @@ static void select_linked_tfaces_with_seams(int mode, Mesh *me, unsigned int ind if (mp->flag & ME_HIDE) continue; - if (!linkflag[a]) { - MLoop *mnextl; - mark = 0; + if (!BLI_BITMAP_GET(poly_tag, a)) { + mark = false; ml = me->mloop + mp->loopstart; for (b = 0; b < mp->totloop; b++, ml++) { - mnextl = b < mp->totloop - 1 ? ml - 1 : me->mloop + mp->loopstart; - if (!BLI_edgehash_haskey(seamhash, ml->v, mnextl->v)) - if (!BLI_edgehash_haskey(ehash, ml->v, mnextl->v)) - mark = 1; + if ((me->medge[ml->e].flag & ME_SEAM) == 0) { + if (BLI_BITMAP_GET(edge_tag, ml->e)) { + mark = true; + break; + } + } } if (mark) { - linkflag[a] = 1; - BKE_mesh_poly_edgehash_insert(ehash, mp, me->mloop + mp->loopstart); + BLI_BITMAP_SET(poly_tag, a); + BKE_mesh_poly_edgebitmap_insert(edge_tag, mp, me->mloop + mp->loopstart); do_it = true; } } } - } - BLI_edgehash_free(ehash, NULL); - BLI_edgehash_free(seamhash, NULL); - - if (mode == 0 || mode == 2) { - for (a = 0, mp = me->mpoly; a < me->totpoly; a++, mp++) - if (linkflag[a]) - mp->flag |= ME_FACE_SEL; - else - mp->flag &= ~ME_FACE_SEL; - } - else if (mode == 1) { - for (a = 0, mp = me->mpoly; a < me->totpoly; a++, mp++) - if (linkflag[a] && (mp->flag & ME_FACE_SEL)) - break; + MEM_freeN(edge_tag); - if (a < me->totpoly) { - for (a = 0, mp = me->mpoly; a < me->totpoly; a++, mp++) - if (linkflag[a]) - mp->flag &= ~ME_FACE_SEL; - } - else { - for (a = 0, mp = me->mpoly; a < me->totpoly; a++, mp++) - if (linkflag[a]) - mp->flag |= ME_FACE_SEL; + for (a = 0, mp = me->mpoly; a < me->totpoly; a++, mp++) { + if (BLI_BITMAP_GET(poly_tag, a)) { + BKE_BIT_TEST_SET(mp->flag, select, ME_FACE_SEL); } } - MEM_freeN(linkflag); + MEM_freeN(poly_tag); } -void paintface_select_linked(bContext *UNUSED(C), Object *ob, const int UNUSED(mval[2]), int mode) +void paintface_select_linked(bContext *C, Object *ob, const int mval[2], const bool select) { Mesh *me; - unsigned int index = 0; + unsigned int index = (unsigned int)-1; me = BKE_mesh_from_object(ob); if (me == NULL || me->totpoly == 0) return; - if (mode == 0 || mode == 1) { - /* XXX - Causes glitches, not sure why */ -#if 0 - if (!ED_mesh_pick_face(C, me, mval, &index, ED_MESH_PICK_DEFAULT_FACE_SIZE)) + if (mval) { + if (!ED_mesh_pick_face(C, ob, mval, &index, ED_MESH_PICK_DEFAULT_FACE_SIZE)) { return; -#endif + } } - select_linked_tfaces_with_seams(mode, me, index); + select_linked_tfaces_with_seams(me, index, select); paintface_flush_flags(ob); } diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 2c7824d4a0d..6de6734f975 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -1295,7 +1295,10 @@ void ED_keymap_paint(wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "PAINT_OT_face_select_reveal", HKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked", LKEY, KM_PRESS, KM_CTRL, 0); - WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked_pick", LKEY, KM_PRESS, 0, 0); + kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked_pick", LKEY, KM_PRESS, 0, 0); + RNA_boolean_set(kmi->ptr, "deselect", false); + kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0); + RNA_boolean_set(kmi->ptr, "deselect", true); keymap = WM_keymap_find(keyconf, "UV Sculpt", 0, 0); keymap->poll = uv_sculpt_poll; diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 4670a8294f6..8db9215a376 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -431,8 +431,9 @@ void PAINT_OT_face_select_linked(wmOperatorType *ot) static int paint_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - int mode = RNA_boolean_get(op->ptr, "extend") ? 1 : 0; - paintface_select_linked(C, CTX_data_active_object(C), event->mval, mode); + const bool select = !RNA_boolean_get(op->ptr, "deselect"); + view3d_operator_needs_opengl(C); + paintface_select_linked(C, CTX_data_active_object(C), event->mval, select); ED_region_tag_redraw(CTX_wm_region(C)); return OPERATOR_FINISHED; } @@ -448,7 +449,7 @@ void PAINT_OT_face_select_linked_pick(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the existing selection"); + RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Deselect rather than select items"); } |