diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-03-26 13:09:31 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-03-26 13:09:31 +0400 |
commit | 18d2dd7e3ae0338829fd61740151f41c21668474 (patch) | |
tree | 53d755b496944c9017c2cda0ac812e7c545f4024 /source/blender/bmesh | |
parent | fc9e0a37f0087d003808a87c26e46ed573ae39dd (diff) | |
parent | f1ed223e34e61777af46d33e5bfc2fc03223a689 (diff) |
Merging r55547 through r55594 from trunk into soc-2008-mxcurioni
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r-- | source/blender/bmesh/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_opdefines.c | 2 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_private.h | 1 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_queries.c | 2 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_queries.h | 2 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_structure.c | 2 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_structure.h | 2 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_beautify.c | 353 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_dissolve.c | 3 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_hull.c | 3 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_mesh_conv.c | 14 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_primitive.c | 3 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_removedoubles.c | 3 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_smooth_laplacian.c | 7 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_subdivide.c | 3 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_triangulate.c | 80 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_bevel.c | 9 |
17 files changed, 372 insertions, 118 deletions
diff --git a/source/blender/bmesh/CMakeLists.txt b/source/blender/bmesh/CMakeLists.txt index c3ec5dd83b3..c21da46d678 100644 --- a/source/blender/bmesh/CMakeLists.txt +++ b/source/blender/bmesh/CMakeLists.txt @@ -39,6 +39,7 @@ set(INC_SYS ) set(SRC + operators/bmo_beautify.c operators/bmo_bevel.c operators/bmo_connect.c operators/bmo_create.c diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c index 7e3ee9d249e..869c894b66c 100644 --- a/source/blender/bmesh/intern/bmesh_opdefines.c +++ b/source/blender/bmesh/intern/bmesh_opdefines.c @@ -57,7 +57,7 @@ #include "BLI_utildefines.h" #include "bmesh.h" -#include "intern/bmesh_private.h" +#include "intern/bmesh_operators_private.h" /* The formatting of these bmesh operators is parsed by * 'doc/python_api/rst_from_bmesh_opdefines.py' diff --git a/source/blender/bmesh/intern/bmesh_private.h b/source/blender/bmesh/intern/bmesh_private.h index 850e81ba3ac..6fd18c07179 100644 --- a/source/blender/bmesh/intern/bmesh_private.h +++ b/source/blender/bmesh/intern/bmesh_private.h @@ -77,6 +77,5 @@ void poly_rotate_plane(const float normal[3], float (*verts)[3], const int nvert /* include the rest of our private declarations */ #include "bmesh_structure.h" -#include "bmesh_operators_private.h" #endif /* __BMESH_PRIVATE_H__ */ diff --git a/source/blender/bmesh/intern/bmesh_queries.c b/source/blender/bmesh/intern/bmesh_queries.c index 26b0e42a1c1..44392383925 100644 --- a/source/blender/bmesh/intern/bmesh_queries.c +++ b/source/blender/bmesh/intern/bmesh_queries.c @@ -43,7 +43,7 @@ * Returns whether or not a given vertex is * is part of a given edge. */ -bool BM_vert_in_edge(BMEdge *e, BMVert *v) +bool BM_vert_in_edge(const BMEdge *e, const BMVert *v) { return bmesh_vert_in_edge(e, v); } diff --git a/source/blender/bmesh/intern/bmesh_queries.h b/source/blender/bmesh/intern/bmesh_queries.h index f894912aad3..8326709a2eb 100644 --- a/source/blender/bmesh/intern/bmesh_queries.h +++ b/source/blender/bmesh/intern/bmesh_queries.h @@ -34,7 +34,7 @@ bool BM_verts_in_face(BMFace *f, BMVert **varr, int len); bool BM_edge_in_face(BMFace *f, BMEdge *e); bool BM_edge_in_loop(BMEdge *e, BMLoop *l); -bool BM_vert_in_edge(BMEdge *e, BMVert *v); +bool BM_vert_in_edge(const BMEdge *e, const BMVert *v); bool BM_verts_in_edge(BMVert *v1, BMVert *v2, BMEdge *e); float BM_edge_calc_length(BMEdge *e); diff --git a/source/blender/bmesh/intern/bmesh_structure.c b/source/blender/bmesh/intern/bmesh_structure.c index 0398f9c558f..a0907f0db7a 100644 --- a/source/blender/bmesh/intern/bmesh_structure.c +++ b/source/blender/bmesh/intern/bmesh_structure.c @@ -40,7 +40,7 @@ * MISC utility functions. */ -bool bmesh_vert_in_edge(BMEdge *e, BMVert *v) +bool bmesh_vert_in_edge(const BMEdge *e, const BMVert *v) { if (e->v1 == v || e->v2 == v) return true; return false; diff --git a/source/blender/bmesh/intern/bmesh_structure.h b/source/blender/bmesh/intern/bmesh_structure.h index e67f1e4fb49..f10e3a12377 100644 --- a/source/blender/bmesh/intern/bmesh_structure.h +++ b/source/blender/bmesh/intern/bmesh_structure.h @@ -68,7 +68,7 @@ BMLoop *bmesh_radial_faceloop_find_vert(BMFace *f, BMVert *v); bool bmesh_radial_validate(int radlen, BMLoop *l); /* EDGE UTILITIES */ -bool bmesh_vert_in_edge(BMEdge *e, BMVert *v); +bool bmesh_vert_in_edge(const BMEdge *e, const BMVert *v); bool bmesh_verts_in_edge(BMVert *v1, BMVert *v2, BMEdge *e); bool bmesh_edge_swapverts(BMEdge *e, BMVert *orig, BMVert *newv); /* relink edge */ BMVert *bmesh_edge_other_vert_get(BMEdge *e, BMVert *v); diff --git a/source/blender/bmesh/operators/bmo_beautify.c b/source/blender/bmesh/operators/bmo_beautify.c new file mode 100644 index 00000000000..adf8ed4df67 --- /dev/null +++ b/source/blender/bmesh/operators/bmo_beautify.c @@ -0,0 +1,353 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Joseph Eagar. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/bmesh/operators/bmo_beautify.c + * \ingroup bmesh + */ + +#include "BLI_math.h" + +#include "MEM_guardedalloc.h" + +#include "bmesh.h" +#include "intern/bmesh_operators_private.h" + +// #define DEBUG_TIME + +#ifdef DEBUG_TIME +# include "PIL_time.h" +#endif + +/* -------------------------------------------------------------------- */ +/* GHash for edge rotation */ + +typedef struct EdRotState { + int v1, v2; /* edge vert, small -> large */ + int f1, f2; /* face vert, small -> large */ +} EdRotState; + +static unsigned int erot_ghashutil_hash(const void *ptr) +{ + const EdRotState *e_state = (const EdRotState *)ptr; + unsigned int + hash = BLI_ghashutil_inthash(SET_INT_IN_POINTER(e_state->v1)); + hash ^= BLI_ghashutil_inthash(SET_INT_IN_POINTER(e_state->v2)); + hash ^= BLI_ghashutil_inthash(SET_INT_IN_POINTER(e_state->f1)); + hash ^= BLI_ghashutil_inthash(SET_INT_IN_POINTER(e_state->f2)); + return hash; +} +static int erot_ghashutil_cmp(const void *a, const void *b) +{ + const EdRotState *e_state_a = (const EdRotState *)a; + const EdRotState *e_state_b = (const EdRotState *)b; + if (e_state_a->v1 < e_state_b->v1) return -1; + else if (e_state_a->v1 > e_state_b->v1) return 1; + else if (e_state_a->v2 < e_state_b->v2) return -1; + else if (e_state_a->v2 > e_state_b->v2) return 1; + else if (e_state_a->f1 < e_state_b->f1) return -1; + else if (e_state_a->f1 > e_state_b->f1) return 1; + else if (e_state_a->f2 < e_state_b->f2) return -1; + else if (e_state_a->f2 > e_state_b->f2) return 1; + else return 0; +} + +static GHash *erot_ghash_new(void) +{ + return BLI_ghash_new(erot_ghashutil_hash, erot_ghashutil_cmp, __func__); +} + +/* ensure v0 is smaller */ +#define EDGE_ORD(v0, v1) \ + if (v0 > v1) { \ + v0 ^= v1; \ + v1 ^= v0; \ + v0 ^= v1; \ + } (void)0 + +static void erot_state_ex(const BMEdge *e, int v_index[2], int f_index[2]) +{ + BLI_assert(BM_edge_is_manifold((BMEdge *)e)); + BLI_assert(BM_vert_in_edge(e, e->l->prev->v) == false); + BLI_assert(BM_vert_in_edge(e, e->l->radial_next->prev->v) == false); + + /* verts of the edge */ + v_index[0] = BM_elem_index_get(e->v1); + v_index[1] = BM_elem_index_get(e->v2); + EDGE_ORD(v_index[0], v_index[1]); + + /* verts of each of the 2 faces attached to this edge + * (that are not apart of this edge) */ + f_index[0] = BM_elem_index_get(e->l->prev->v); + f_index[1] = BM_elem_index_get(e->l->radial_next->prev->v); + EDGE_ORD(f_index[0], f_index[1]); +} + +static void erot_state_current(const BMEdge *e, EdRotState *e_state) +{ + erot_state_ex(e, &e_state->v1, &e_state->f1); +} + +static void erot_state_alternate(const BMEdge *e, EdRotState *e_state) +{ + erot_state_ex(e, &e_state->f1, &e_state->v1); +} + +/* -------------------------------------------------------------------- */ +/* Util for setting edge tag once rotated */ + +/* we have rotated an edge, tag other egdes and clear this one */ +static void bm_edge_tag_rotated(BMEdge *e) +{ + BMLoop *l; + BLI_assert(e->l->f->len == 3 && + e->l->radial_next->f->len == 3); + + l = e->l; + BM_elem_flag_enable(l->next->e, BM_ELEM_TAG); + BM_elem_flag_enable(l->prev->e, BM_ELEM_TAG); + l = l->radial_next; + BM_elem_flag_enable(l->next->e, BM_ELEM_TAG); + BM_elem_flag_enable(l->prev->e, BM_ELEM_TAG); +} + +/* -------------------------------------------------------------------- */ +/* Beautify Fill */ + +#define ELE_NEW 1 +#define FACE_MARK 2 + +/** + * \note All edges in \a edge_array must be tagged and + * have their index values set according to their position in the array. + */ +static void bm_mesh_beautify_fill(BMesh *bm, BMEdge **edge_array, const int edge_array_len) +{ + GHash **edge_state_arr = MEM_callocN(edge_array_len * sizeof(GHash *), __func__); + BLI_mempool *edge_state_pool = BLI_mempool_create(sizeof(EdRotState), 512, 512, BLI_MEMPOOL_SYSMALLOC); + bool is_breaked; + int i; + +#ifdef DEBUG_TIME + TIMEIT_START(beautify_fill); +#endif + + do { + is_breaked = true; + + for (i = 0; i < edge_array_len; i++) { + BMEdge *e = edge_array[i]; + GHash *e_state_hash; + + float v1_xy[2], v2_xy[2], v3_xy[2], v4_xy[2]; + + BLI_assert(BM_edge_is_manifold(e) == true); + BLI_assert(BMO_elem_flag_test(bm, e->l->f, FACE_MARK) && + BMO_elem_flag_test(bm, e->l->radial_next->f, FACE_MARK)); + + if (!BM_elem_flag_test(e, BM_ELEM_TAG)) { + continue; + } + else { + /* don't check this edge again, unless adjaced edges are rotated */ + BM_elem_flag_disable(e, BM_ELEM_TAG); + } + + /* check we're not moving back into a state we have been in before */ + e_state_hash = edge_state_arr[i]; + if (e_state_hash != NULL) { + EdRotState e_state_alt; + erot_state_alternate(e, &e_state_alt); + if (BLI_ghash_haskey(e_state_hash, (void *)&e_state_alt)) { + // printf(" skipping, we already have this state\n"); + continue; + } + } + + { + const float *v1, *v2, *v3, *v4; + bool is_zero_a, is_zero_b; + float no[3]; + float axis_mat[3][3]; + + v1 = e->l->prev->v->co; /* first face co */ + v2 = e->l->v->co; /* e->v1 or e->v2*/ + v3 = e->l->radial_next->prev->v->co; /* second face co */ + v4 = e->l->next->v->co; /* e->v1 or e->v2*/ + + if (UNLIKELY(v1 == v3)) { + // printf("This should never happen, but does sometimes!\n"); + continue; + } + + // printf("%p %p %p %p - %p %p\n", v1, v2, v3, v4, e->l->f, e->l->radial_next->f); + BLI_assert((ELEM3(v1, v2, v3, v4) == false) && + (ELEM3(v2, v1, v3, v4) == false) && + (ELEM3(v3, v1, v2, v4) == false) && + (ELEM3(v4, v1, v2, v3) == false)); + + is_zero_a = area_tri_v3(v2, v3, v4) <= FLT_EPSILON; + is_zero_b = area_tri_v3(v2, v4, v1) <= FLT_EPSILON; + + if (LIKELY(is_zero_a == false && is_zero_b == false)) { + float no_a[3], no_b[3]; + normal_tri_v3(no_a, v2, v3, v4); /* a */ + normal_tri_v3(no_b, v2, v4, v1); /* b */ + add_v3_v3v3(no, no_a, no_b); + if (UNLIKELY(normalize_v3(no) <= FLT_EPSILON)) { + continue; + } + } + else if (is_zero_a == false) { + normal_tri_v3(no, v2, v3, v4); /* a */ + } + else if (is_zero_b == false) { + normal_tri_v3(no, v2, v4, v1); /* b */ + } + else { + /* both zero area, no useful normal can be calculated */ + continue; + } + + // { float a = angle_normalized_v3v3(no_a, no_b); printf("~ %.7f\n", a); fflush(stdout);} + + axis_dominant_v3_to_m3(axis_mat, no); + mul_v2_m3v3(v1_xy, axis_mat, v1); + mul_v2_m3v3(v2_xy, axis_mat, v2); + mul_v2_m3v3(v3_xy, axis_mat, v3); + mul_v2_m3v3(v4_xy, axis_mat, v4); + } + + // printf("%p %p %p %p - %p %p\n", v1, v2, v3, v4, e->l->f, e->l->radial_next->f); + + if (is_quad_convex_v2(v1_xy, v2_xy, v3_xy, v4_xy)) { + float len1, len2, len3, len4, len5, len6, opp1, opp2, fac1, fac2; + /* testing rule: + * the area divided by the total edge lengths + */ + len1 = len_v2v2(v1_xy, v2_xy); + len2 = len_v2v2(v2_xy, v3_xy); + len3 = len_v2v2(v3_xy, v4_xy); + len4 = len_v2v2(v4_xy, v1_xy); + len5 = len_v2v2(v1_xy, v3_xy); + len6 = len_v2v2(v2_xy, v4_xy); + + opp1 = area_tri_v2(v1_xy, v2_xy, v3_xy); + opp2 = area_tri_v2(v1_xy, v3_xy, v4_xy); + + fac1 = opp1 / (len1 + len2 + len5) + opp2 / (len3 + len4 + len5); + + opp1 = area_tri_v2(v2_xy, v3_xy, v4_xy); + opp2 = area_tri_v2(v2_xy, v4_xy, v1_xy); + + fac2 = opp1 / (len2 + len3 + len6) + opp2 / (len4 + len1 + len6); + + if (fac1 > fac2) { + e = BM_edge_rotate(bm, e, false, BM_EDGEROT_CHECK_EXISTS); + if (LIKELY(e)) { + + /* add the new state into the hash so we don't move into this state again + * note: we could add the previous state too but this isn't essential) + * for avoiding eternal loops */ + EdRotState *e_state = BLI_mempool_alloc(edge_state_pool); + erot_state_current(e, e_state); + if (UNLIKELY(e_state_hash == NULL)) { + edge_state_arr[i] = e_state_hash = erot_ghash_new(); /* store previous state */ + } + BLI_assert(BLI_ghash_haskey(e_state_hash, (void *)e_state) == false); + BLI_ghash_insert(e_state_hash, e_state, NULL); + + + // printf(" %d -> %d, %d\n", i, BM_elem_index_get(e->v1), BM_elem_index_get(e->v2)); + + /* maintain the index array */ + edge_array[i] = e; + BM_elem_index_set(e, i); + + /* tag other edges so we know to check them again */ + bm_edge_tag_rotated(e); + + /* update flags */ + BMO_elem_flag_enable(bm, e, ELE_NEW); + BMO_elem_flag_enable(bm, e->l->f, FACE_MARK | ELE_NEW); + BMO_elem_flag_enable(bm, e->l->radial_next->f, FACE_MARK | ELE_NEW); + is_breaked = false; + } + } + } + } + } while (is_breaked == false); + + for (i = 0; i < edge_array_len; i++) { + if (edge_state_arr[i]) { + BLI_ghash_free(edge_state_arr[i], NULL, NULL); + } + } + + MEM_freeN(edge_state_arr); + BLI_mempool_destroy(edge_state_pool); + +#ifdef DEBUG_TIME + TIMEIT_END(beautify_fill); +#endif +} + + +void bmo_beautify_fill_exec(BMesh *bm, BMOperator *op) +{ + BMOIter siter; + BMFace *f; + BMEdge *e; + + BMEdge **edge_array; + int edge_array_len = 0; + + BMO_ITER (f, &siter, op->slots_in, "faces", BM_FACE) { + if (f->len == 3) { + BMO_elem_flag_enable(bm, f, FACE_MARK); + } + } + + /* will over alloc if some edges can't be rotated */ + edge_array = MEM_mallocN(sizeof(*edge_array) * BMO_slot_buffer_count(op->slots_in, "edges"), __func__); + + BMO_ITER (e, &siter, op->slots_in, "edges", BM_EDGE) { + + /* edge is manifold and can be rotated */ + if (BM_edge_rotate_check(e) && + /* faces are tagged */ + BMO_elem_flag_test(bm, e->l->f, FACE_MARK) && + BMO_elem_flag_test(bm, e->l->radial_next->f, FACE_MARK)) + { + BM_elem_index_set(e, edge_array_len); /* set_dirty */ + BM_elem_flag_enable(e, BM_ELEM_TAG); + edge_array[edge_array_len] = e; + edge_array_len++; + } + } + bm->elem_index_dirty |= BM_EDGE; + + bm_mesh_beautify_fill(bm, edge_array, edge_array_len); + + MEM_freeN(edge_array); + + BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "geom.out", BM_EDGE | BM_FACE, ELE_NEW); +} diff --git a/source/blender/bmesh/operators/bmo_dissolve.c b/source/blender/bmesh/operators/bmo_dissolve.c index a78a8ec5197..4a241ca645f 100644 --- a/source/blender/bmesh/operators/bmo_dissolve.c +++ b/source/blender/bmesh/operators/bmo_dissolve.c @@ -30,9 +30,8 @@ #include "BLI_math.h" #include "bmesh.h" -#include "intern/bmesh_private.h" +#include "intern/bmesh_operators_private.h" -#include "intern/bmesh_operators_private.h" /* own include */ #define FACE_MARK 1 #define FACE_ORIG 2 diff --git a/source/blender/bmesh/operators/bmo_hull.c b/source/blender/bmesh/operators/bmo_hull.c index 7dc2884c5ed..810b608b28e 100644 --- a/source/blender/bmesh/operators/bmo_hull.c +++ b/source/blender/bmesh/operators/bmo_hull.c @@ -28,9 +28,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_utildefines.h" #include "BLI_array.h" -#include "BLI_ghash.h" #include "BLI_listbase.h" #include "BLI_math.h" @@ -38,7 +36,6 @@ /* XXX: using 128 for totelem and pchunk of mempool, no idea what good * values would be though */ -#include "BLI_mempool.h" #include "bmesh.h" diff --git a/source/blender/bmesh/operators/bmo_mesh_conv.c b/source/blender/bmesh/operators/bmo_mesh_conv.c index 0976c4cdfbb..a75d0353079 100644 --- a/source/blender/bmesh/operators/bmo_mesh_conv.c +++ b/source/blender/bmesh/operators/bmo_mesh_conv.c @@ -28,28 +28,16 @@ * into a Bmesh, and back again. */ -#include "MEM_guardedalloc.h" #include "DNA_mesh_types.h" -#include "DNA_meshdata_types.h" #include "DNA_object_types.h" #include "DNA_key_types.h" -#include "DNA_modifier_types.h" #include "BLI_math.h" -#include "BLI_array.h" - -#include "BKE_mesh.h" -#include "BLI_listbase.h" -#include "BKE_global.h" -#include "BKE_key.h" -#include "BKE_main.h" -#include "BKE_customdata.h" #include "bmesh.h" -#include "intern/bmesh_private.h" +#include "intern/bmesh_operators_private.h" -#include "intern/bmesh_operators_private.h" /* own include */ void bmo_mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) { diff --git a/source/blender/bmesh/operators/bmo_primitive.c b/source/blender/bmesh/operators/bmo_primitive.c index 011002718d3..10a48c1b78c 100644 --- a/source/blender/bmesh/operators/bmo_primitive.c +++ b/source/blender/bmesh/operators/bmo_primitive.c @@ -29,9 +29,8 @@ #include "BLI_math.h" #include "bmesh.h" -#include "intern/bmesh_private.h" +#include "intern/bmesh_operators_private.h" -#include "intern/bmesh_operators_private.h" /* own include */ /* ************************ primitives ******************* */ diff --git a/source/blender/bmesh/operators/bmo_removedoubles.c b/source/blender/bmesh/operators/bmo_removedoubles.c index 8b65764fe1c..65b3267914f 100644 --- a/source/blender/bmesh/operators/bmo_removedoubles.c +++ b/source/blender/bmesh/operators/bmo_removedoubles.c @@ -32,9 +32,8 @@ #include "BKE_customdata.h" #include "bmesh.h" -#include "intern/bmesh_private.h" +#include "intern/bmesh_operators_private.h" -#include "intern/bmesh_operators_private.h" /* own include */ static void remdoubles_splitface(BMFace *f, BMesh *bm, BMOperator *op, BMOpSlot *slot_targetmap) { diff --git a/source/blender/bmesh/operators/bmo_smooth_laplacian.c b/source/blender/bmesh/operators/bmo_smooth_laplacian.c index 6b91d5fded9..0c0a2c308ee 100644 --- a/source/blender/bmesh/operators/bmo_smooth_laplacian.c +++ b/source/blender/bmesh/operators/bmo_smooth_laplacian.c @@ -26,16 +26,9 @@ #include "MEM_guardedalloc.h" -#include "DNA_meshdata_types.h" -#include "BLI_array.h" #include "BLI_math.h" -#include "BLI_math_geom.h" -#include "BLI_smallhash.h" -#include "BLI_heap.h" -#include "BKE_customdata.h" -#include "BKE_mesh.h" #include "bmesh.h" diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c index 88e903c1651..9115ee882dd 100644 --- a/source/blender/bmesh/operators/bmo_subdivide.c +++ b/source/blender/bmesh/operators/bmo_subdivide.c @@ -33,12 +33,11 @@ #include "BKE_customdata.h" -#include "DNA_object_types.h" #include "bmesh.h" #include "intern/bmesh_private.h" +#include "intern/bmesh_operators_private.h" -#include "intern/bmesh_operators_private.h" /* own include */ typedef struct SubDParams { int numcuts; diff --git a/source/blender/bmesh/operators/bmo_triangulate.c b/source/blender/bmesh/operators/bmo_triangulate.c index 1f04c7ce845..29c3764045e 100644 --- a/source/blender/bmesh/operators/bmo_triangulate.c +++ b/source/blender/bmesh/operators/bmo_triangulate.c @@ -28,17 +28,14 @@ #include "DNA_listBase.h" #include "BLI_math.h" -#include "BLI_array.h" #include "BLI_smallhash.h" #include "BLI_scanfill.h" #include "bmesh.h" -#include "intern/bmesh_private.h" +#include "intern/bmesh_operators_private.h" -#include "intern/bmesh_operators_private.h" /* own include */ #define ELE_NEW 1 -#define FACE_MARK 2 #define EDGE_MARK 4 void bmo_triangulate_exec(BMesh *bm, BMOperator *op) @@ -55,81 +52,6 @@ void bmo_triangulate_exec(BMesh *bm, BMOperator *op) BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "faces.out", BM_FACE, BM_ELEM_TAG); } -void bmo_beautify_fill_exec(BMesh *bm, BMOperator *op) -{ - BMOIter siter; - BMIter iter; - BMFace *f; - BMEdge *e; - int stop = 0; - - BMO_slot_buffer_flag_enable(bm, op->slots_in, "edges", BM_EDGE, EDGE_MARK); - - BMO_ITER (f, &siter, op->slots_in, "faces", BM_FACE) { - if (f->len == 3) { - BMO_elem_flag_enable(bm, f, FACE_MARK); - } - } - - while (!stop) { - stop = 1; - - BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { - BMVert *v1, *v2, *v3, *v4; - - if (!BM_edge_is_manifold(e) || !BMO_elem_flag_test(bm, e, EDGE_MARK)) { - continue; - } - - if (!BMO_elem_flag_test(bm, e->l->f, FACE_MARK) || - !BMO_elem_flag_test(bm, e->l->radial_next->f, FACE_MARK)) - { - continue; - } - - v1 = e->l->prev->v; - v2 = e->l->v; - v3 = e->l->radial_next->prev->v; - v4 = e->l->next->v; - - if (is_quad_convex_v3(v1->co, v2->co, v3->co, v4->co)) { - float len1, len2, len3, len4, len5, len6, opp1, opp2, fac1, fac2; - /* testing rule: - * the area divided by the total edge lengths - */ - len1 = len_v3v3(v1->co, v2->co); - len2 = len_v3v3(v2->co, v3->co); - len3 = len_v3v3(v3->co, v4->co); - len4 = len_v3v3(v4->co, v1->co); - len5 = len_v3v3(v1->co, v3->co); - len6 = len_v3v3(v2->co, v4->co); - - opp1 = area_tri_v3(v1->co, v2->co, v3->co); - opp2 = area_tri_v3(v1->co, v3->co, v4->co); - - fac1 = opp1 / (len1 + len2 + len5) + opp2 / (len3 + len4 + len5); - - opp1 = area_tri_v3(v2->co, v3->co, v4->co); - opp2 = area_tri_v3(v2->co, v4->co, v1->co); - - fac2 = opp1 / (len2 + len3 + len6) + opp2 / (len4 + len1 + len6); - - if (fac1 > fac2) { - e = BM_edge_rotate(bm, e, false, BM_EDGEROT_CHECK_EXISTS); - if (e) { - BMO_elem_flag_enable(bm, e, ELE_NEW | EDGE_MARK); - - BMO_elem_flag_enable(bm, e->l->f, FACE_MARK | ELE_NEW); - BMO_elem_flag_enable(bm, e->l->radial_next->f, FACE_MARK | ELE_NEW); - stop = 0; - } - } - } - } - } - - BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "geom.out", BM_EDGE | BM_FACE, ELE_NEW); -} void bmo_triangle_fill_exec(BMesh *bm, BMOperator *op) { diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c index f685b741176..525bf3a2da7 100644 --- a/source/blender/bmesh/tools/bmesh_bevel.c +++ b/source/blender/bmesh/tools/bmesh_bevel.c @@ -43,11 +43,12 @@ #include "bmesh.h" #include "./intern/bmesh_private.h" - - #define BEVEL_EPSILON_D 1e-6 #define BEVEL_EPSILON 1e-6f +/* happens far too often, uncomment for development */ +// #define BEVEL_ASSERT_PROJECT + /* for testing */ // #pragma GCC diagnostic error "-Wpadded" @@ -369,7 +370,9 @@ static void offset_meet(EdgeHalf *e1, EdgeHalf *e2, BMVert *v, BMFace *f, /* intersect the lines; by construction they should be on the same plane and not parallel */ if (!isect_line_line_v3(off1a, off1b, off2a, off2b, meetco, isect2)) { +#ifdef BEVEL_ASSERT_PROJECT BLI_assert(!"offset_meet failure"); +#endif copy_v3_v3(meetco, off1a); /* just to do something */ } } @@ -485,7 +488,9 @@ static void project_to_edge(BMEdge *e, const float co_a[3], const float co_b[3], float otherco[3]; if (!isect_line_line_v3(e->v1->co, e->v2->co, co_a, co_b, projco, otherco)) { +#ifdef BEVEL_ASSERT_PROJECT BLI_assert(!"project meet failure"); +#endif copy_v3_v3(projco, e->v1->co); } } |