From 8cf5eaa2baa70515f4731cc9ac5ac6c5e5cf3c44 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 1 Jun 2017 16:42:14 +1000 Subject: Add Face-Map to select similar Handy for setting up face-maps, also allows selecting all faces with no assigned map. --- source/blender/bmesh/intern/bmesh_operators.h | 1 + source/blender/bmesh/operators/bmo_similar.c | 47 ++++++++++++++++++++------- 2 files changed, 37 insertions(+), 11 deletions(-) (limited to 'source/blender/bmesh') diff --git a/source/blender/bmesh/intern/bmesh_operators.h b/source/blender/bmesh/intern/bmesh_operators.h index 31c696da0d4..80b57eb3565 100644 --- a/source/blender/bmesh/intern/bmesh_operators.h +++ b/source/blender/bmesh/intern/bmesh_operators.h @@ -83,6 +83,7 @@ enum { SIMFACE_NORMAL, SIMFACE_COPLANAR, SIMFACE_SMOOTH, + SIMFACE_FACEMAP, #ifdef WITH_FREESTYLE SIMFACE_FREESTYLE #endif diff --git a/source/blender/bmesh/operators/bmo_similar.c b/source/blender/bmesh/operators/bmo_similar.c index 0e49c957213..0cd17258834 100644 --- a/source/blender/bmesh/operators/bmo_similar.c +++ b/source/blender/bmesh/operators/bmo_similar.c @@ -106,11 +106,28 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op) const float thresh = BMO_slot_float_get(op->slots_in, "thresh"); const float thresh_radians = thresh * (float)M_PI; const int compare = BMO_slot_int_get(op->slots_in, "compare"); + /* for comparison types that use custom-data */ + int cd_offset = -1; /* initial_elem - other_elem */ float delta_fl; int delta_i; + if (type == SIMFACE_FACEMAP) { + cd_offset = CustomData_get_offset(&bm->pdata, CD_FACEMAP); + if (cd_offset == -1) { + return; + } + } +#ifdef WITH_FREESTYLE + else if (type == SIMFACE_FREESTYLE) { + cd_offset = CustomData_get_offset(&bm->pdata, CD_FREESTYLE_FACE); + if (cd_offset == -1) { + return; + } + } +#endif + num_total = BM_mesh_elem_count(bm, BM_FACE); /* @@ -182,7 +199,6 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op) cont = false; } break; - case SIMFACE_NORMAL: angle = angle_normalized_v3v3(fs->no, fm->no); /* if the angle between the normals -> 0 */ if (angle <= thresh_radians) { @@ -239,20 +255,29 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op) cont = false; } break; + case SIMFACE_FACEMAP: + { + BLI_assert(cd_offset != -1); + const int *fmap1 = BM_ELEM_CD_GET_VOID_P(fs, cd_offset); + const int *fmap2 = BM_ELEM_CD_GET_VOID_P(fm, cd_offset); + if (*fmap1 == *fmap2) { + BMO_face_flag_enable(bm, fm, FACE_MARK); + cont = false; + } + break; + } #ifdef WITH_FREESTYLE case SIMFACE_FREESTYLE: - if (CustomData_has_layer(&bm->pdata, CD_FREESTYLE_FACE)) { - FreestyleEdge *ffa1, *ffa2; - - ffa1 = CustomData_bmesh_get(&bm->pdata, fs->head.data, CD_FREESTYLE_FACE); - ffa2 = CustomData_bmesh_get(&bm->pdata, fm->head.data, CD_FREESTYLE_FACE); - - if (ffa1 && ffa2 && (ffa1->flag & FREESTYLE_FACE_MARK) == (ffa2->flag & FREESTYLE_FACE_MARK)) { - BMO_face_flag_enable(bm, fm, FACE_MARK); - cont = false; - } + { + BLI_assert(cd_offset != -1); + const FreestyleEdge *ffa1 = BM_ELEM_CD_GET_VOID_P(fs, cd_offset); + const FreestyleEdge *ffa2 = BM_ELEM_CD_GET_VOID_P(fm, cd_offset); + if ((ffa1->flag & FREESTYLE_FACE_MARK) == (ffa2->flag & FREESTYLE_FACE_MARK)) { + BMO_face_flag_enable(bm, fm, FACE_MARK); + cont = false; } break; + } #endif default: BLI_assert(0); -- cgit v1.2.3