BMesh: Minor improvement to face-join

Pass in loops instead of edge & faces.
Nearly all callers have the loop-pairs to pass in.
This commit is contained in:
2016-11-12 10:06:53 +11:00
parent dad0c31ceb
commit 7fd2efa507
7 changed files with 31 additions and 44 deletions

View File

@@ -104,7 +104,6 @@ bool BM_vert_dissolve(BMesh *bm, BMVert *v)
*/
bool BM_disk_dissolve(BMesh *bm, BMVert *v)
{
BMFace *f, *f2;
BMEdge *e, *keepedge = NULL, *baseedge = NULL;
int len = 0;
@@ -141,7 +140,7 @@ bool BM_disk_dissolve(BMesh *bm, BMVert *v)
return false;
}
#else
if (UNLIKELY(!BM_faces_join_pair(bm, e->l->f, e->l->radial_next->f, e, true))) {
if (UNLIKELY(!BM_faces_join_pair(bm, e->l, e->l->radial_next, true))) {
return false;
}
else if (UNLIKELY(!BM_vert_collapse_faces(bm, v->e, v, 1.0, true, false, true))) {
@@ -159,11 +158,10 @@ bool BM_disk_dissolve(BMesh *bm, BMVert *v)
}
/* handle two-valence */
f = e->l->f;
f2 = e->l->radial_next->f;
if (f != f2 && !BM_faces_join_pair(bm, f, f2, e, true)) {
return false;
if (e->l != e->l->radial_next) {
if (!BM_faces_join_pair(bm, e->l, e->l->radial_next, true)) {
return false;
}
}
return true;
@@ -176,9 +174,9 @@ bool BM_disk_dissolve(BMesh *bm, BMVert *v)
done = true;
e = v->e;
do {
f = NULL;
BMFace *f = NULL;
if (BM_edge_is_manifold(e) && (e != baseedge) && (e != keepedge)) {
f = BM_faces_join_pair(bm, e->l->f, e->l->radial_next->f, e, true);
f = BM_faces_join_pair(bm, e->l, e->l->radial_next, true);
/* return if couldn't join faces in manifold
* conditions */
/* !disabled for testing why bad things happen */
@@ -204,12 +202,9 @@ bool BM_disk_dissolve(BMesh *bm, BMVert *v)
if (e->l) {
/* get remaining two faces */
f = e->l->f;
f2 = e->l->radial_next->f;
if (f != f2) {
if (e->l != e->l->radial_next) {
/* join two remaining faces */
if (!BM_faces_join_pair(bm, f, f2, e, true)) {
if (!BM_faces_join_pair(bm, e->l, e->l->radial_next, true)) {
return false;
}
}
@@ -234,20 +229,16 @@ bool BM_disk_dissolve(BMesh *bm, BMVert *v)
*
* \return pointer to the combined face
*/
BMFace *BM_faces_join_pair(BMesh *bm, BMFace *f_a, BMFace *f_b, BMEdge *e, const bool do_del)
BMFace *BM_faces_join_pair(BMesh *bm, BMLoop *l_a, BMLoop *l_b, const bool do_del)
{
BMFace *faces[2] = {f_a, f_b};
BMLoop *l_a = BM_face_edge_share_loop(f_a, e);
BMLoop *l_b = BM_face_edge_share_loop(f_b, e);
BLI_assert(l_a && l_b);
BLI_assert((l_a != l_b) && (l_a->e == l_b->e));
if (l_a->v == l_b->v) {
const int cd_loop_mdisp_offset = CustomData_get_offset(&bm->ldata, CD_MDISPS);
bmesh_loop_reverse(bm, f_b, cd_loop_mdisp_offset, true);
bmesh_loop_reverse(bm, l_b->f, cd_loop_mdisp_offset, true);
}
BMFace *faces[2] = {l_a->f, l_b->f};
return BM_faces_join(bm, faces, 2, do_del);
}
@@ -1040,7 +1031,7 @@ BMEdge *BM_edge_rotate(BMesh *bm, BMEdge *e, const bool ccw, const short check_f
f_hflag_prev_2 = l2->f->head.hflag;
/* don't delete the edge, manually remove the edge after so we can copy its attributes */
f = BM_faces_join_pair(bm, l1->f, l2->f, e, true);
f = BM_faces_join_pair(bm, BM_face_edge_share_loop(l1->f, e), BM_face_edge_share_loop(l2->f, e), true);
if (f == NULL) {
return NULL;

View File

@@ -31,7 +31,7 @@ bool BM_vert_dissolve(BMesh *bm, BMVert *v);
bool BM_disk_dissolve(BMesh *bm, BMVert *v);
BMFace *BM_faces_join_pair(BMesh *bm, BMFace *f1, BMFace *f2, BMEdge *e, const bool do_del);
BMFace *BM_faces_join_pair(BMesh *bm, BMLoop *l_a, BMLoop *l_b, const bool do_del);
/** see: bmesh_polygon_edgenet.h for #BM_face_split_edgenet */

View File

@@ -926,7 +926,8 @@ bool BM_vert_is_manifold(const BMVert *v)
/* count edges while looking for non-manifold edges */
e_first = e_iter = v->e;
l_first = e_iter->l ? e_iter->l : NULL;
/* may be null */
l_first = e_iter->l;
do {
/* loose edge or edge shared by more than two faces,
* edges with 1 face user are OK, otherwise we could

View File

@@ -322,12 +322,12 @@ void bmo_dissolve_edges_exec(BMesh *bm, BMOperator *op)
}
BMO_ITER (e, &eiter, op->slots_in, "edges", BM_EDGE) {
BMFace *fa, *fb;
if (BM_edge_face_pair(e, &fa, &fb)) {
BMLoop *l_a, *l_b;
if (BM_edge_loop_pair(e, &l_a, &l_b)) {
BMFace *f_new;
/* join faces */
f_new = BM_faces_join_pair(bm, fa, fb, e, false);
f_new = BM_faces_join_pair(bm, l_a, l_b, false);
if (f_new) {
/* maintain active face */
@@ -437,12 +437,12 @@ void bmo_dissolve_verts_exec(BMesh *bm, BMOperator *op)
if (!BMO_vert_flag_test(bm, v, VERT_MARK_PAIR)) {
BM_ITER_ELEM (e, &itersub, v, BM_EDGES_OF_VERT) {
BMFace *fa, *fb;
if (BM_edge_face_pair(e, &fa, &fb)) {
BMLoop *l_a, *l_b;
if (BM_edge_loop_pair(e, &l_a, &l_b)) {
BMFace *f_new;
/* join faces */
f_new = BM_faces_join_pair(bm, fa, fb, e, false);
f_new = BM_faces_join_pair(bm, l_a, l_b, false);
/* maintain active face */
if (act_face && bm->act_face == NULL) {

View File

@@ -361,16 +361,16 @@ void bmo_join_triangles_exec(BMesh *bm, BMOperator *op)
qsort(jedges, totedge, sizeof(*jedges), BLI_sortutil_cmp_float);
for (i = 0; i < totedge; i++) {
BMFace *f_a, *f_b;
BMLoop *l_a, *l_b;
e = jedges[i].data;
f_a = e->l->f;
f_b = e->l->radial_next->f;
l_a = e->l;
l_b = e->l->radial_next;
/* check if another edge already claimed this face */
if ((f_a->len == 3) && (f_b->len == 3)) {
if ((l_a->f->len == 3) && (l_b->f->len == 3)) {
BMFace *f_new;
f_new = BM_faces_join_pair(bm, f_a, f_b, e, true);
f_new = BM_faces_join_pair(bm, l_a, l_b, true);
if (f_new) {
BMO_face_flag_enable(bm, f_new, FACE_OUT);
}

View File

@@ -253,10 +253,7 @@ void bmo_triangle_fill_exec(BMesh *bm, BMOperator *op)
if (BMO_edge_flag_test(bm, e, ELE_NEW)) {
/* in rare cases the edges face will have already been removed from the edge */
if (LIKELY(e->l)) {
BMFace *f_new = BM_faces_join_pair(
bm, e->l->f,
e->l->radial_next->f, e,
false); /* join faces */
BMFace *f_new = BM_faces_join_pair(bm, e->l, e->l->radial_next, false);
if (f_new) {
BMO_face_flag_enable(bm, f_new, ELE_NEW);
BM_edge_kill(bm, e);

View File

@@ -322,9 +322,7 @@ void BM_mesh_decimate_dissolve_ex(
i = BM_elem_index_get(e);
if (BM_edge_is_manifold(e)) {
f_new = BM_faces_join_pair(bm, e->l->f,
e->l->radial_next->f, e,
false); /* join faces */
f_new = BM_faces_join_pair(bm, e->l, e->l->radial_next, false);
if (f_new) {
BMLoop *l_first, *l_iter;