diff options
Diffstat (limited to 'source/blender/bmesh/tools')
-rw-r--r-- | source/blender/bmesh/tools/bmesh_beautify.c | 16 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_beautify.h | 14 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_bevel.c | 15 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_bisect_plane.c | 2 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_path.c | 6 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_path.h | 9 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_region_match.c | 8 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_triangulate.c | 70 |
8 files changed, 96 insertions, 44 deletions
diff --git a/source/blender/bmesh/tools/bmesh_beautify.c b/source/blender/bmesh/tools/bmesh_beautify.c index 6639e767e77..1c6dc6f5c0e 100644 --- a/source/blender/bmesh/tools/bmesh_beautify.c +++ b/source/blender/bmesh/tools/bmesh_beautify.c @@ -125,9 +125,6 @@ static void erot_state_alternate(const BMEdge *e, EdRotState *e_state) /* -------------------------------------------------------------------- */ /* Calculate the improvement of rotating the edge */ -/** - * \return a negative value means the edge can be rotated. - */ static float bm_edge_calc_rotate_beauty__area( const float v1[3], const float v2[3], const float v3[3], const float v4[3]) { @@ -272,6 +269,12 @@ static float bm_edge_calc_rotate_beauty__angle( return FLT_MAX; } +/** + * Assuming we have 2 triangles sharing an edge (2 - 4), + * check if the edge running from (1 - 3) gives better results. + * + * \return (negative number means the edge can be rotated, lager == better). + */ float BM_verts_calc_rotate_beauty( const BMVert *v1, const BMVert *v2, const BMVert *v3, const BMVert *v4, const short flag, const short method) @@ -400,9 +403,10 @@ static void bm_edge_update_beauty_cost(BMEdge *e, Heap *eheap, HeapNode **eheap_ /** * \note This function sets the edge indices to invalid values. */ -void BM_mesh_beautify_fill(BMesh *bm, BMEdge **edge_array, const int edge_array_len, - const short flag, const short method, - const short oflag_edge, const short oflag_face) +void BM_mesh_beautify_fill( + BMesh *bm, BMEdge **edge_array, const int edge_array_len, + const short flag, const short method, + const short oflag_edge, const short oflag_face) { Heap *eheap; /* edge heap */ HeapNode **eheap_table; /* edge index aligned table pointing to the eheap */ diff --git a/source/blender/bmesh/tools/bmesh_beautify.h b/source/blender/bmesh/tools/bmesh_beautify.h index 7cc17008b50..0d6aa23b81d 100644 --- a/source/blender/bmesh/tools/bmesh_beautify.h +++ b/source/blender/bmesh/tools/bmesh_beautify.h @@ -31,12 +31,14 @@ enum { VERT_RESTRICT_TAG = (1 << 0), }; -void BM_mesh_beautify_fill(BMesh *bm, BMEdge **edge_array, const int edge_array_len, - const short flag, const short method, - const short oflag_edge, const short oflag_face); +void BM_mesh_beautify_fill( + BMesh *bm, BMEdge **edge_array, const int edge_array_len, + const short flag, const short method, + const short oflag_edge, const short oflag_face); -float BM_verts_calc_rotate_beauty(const BMVert *v1, const BMVert *v2, - const BMVert *v3, const BMVert *v4, - const short flag, const short method); +float BM_verts_calc_rotate_beauty( + const BMVert *v1, const BMVert *v2, + const BMVert *v3, const BMVert *v4, + const short flag, const short method); #endif /* __BMESH_BEAUTIFY_H__ */ diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c index 4a9fb677257..c3d1ca86fbf 100644 --- a/source/blender/bmesh/tools/bmesh_bevel.c +++ b/source/blender/bmesh/tools/bmesh_bevel.c @@ -787,7 +787,7 @@ static void offset_on_edge_between(BevelParams *bp, EdgeHalf *e1, EdgeHalf *e2, * be on emid if that does a better job of keeping offsets at the user spec. * Viewed from the vertex normal side, the CCW order of the edges is e1, emid, e2. * The offset lines may not meet exactly: the lines may be angled so that they can't meet. - * In that case, pick the the offset_on_edge_between. */ + * In that case, pick the offset_on_edge_between. */ static void offset_in_two_planes(BevelParams *bp, EdgeHalf *e1, EdgeHalf *e2, EdgeHalf *emid, BMVert *v, float meetco[3]) { @@ -1387,7 +1387,7 @@ static void set_bound_vert_seams(BevVert *bv) } /* Make a circular list of BoundVerts for bv, each of which has the coordinates - * of a vertex on the the boundary of the beveled vertex bv->v. + * of a vertex on the boundary of the beveled vertex bv->v. * This may adjust some EdgeHalf widths, and there might have to be * a subsequent pass to make the widths as consistent as possible. * The first time through, construct will be true and we are making the BoundVerts @@ -2229,7 +2229,6 @@ static VMesh *make_cube_corner_adj_vmesh(BevelParams *bp) BoundVert *bndv; int i, j, k, ns2; float co[3], coc[3]; - float w; if (r == PRO_SQUARE_R) return make_cube_corner_straight(mem_arena, nseg); @@ -2262,10 +2261,8 @@ static VMesh *make_cube_corner_adj_vmesh(BevelParams *bp) bndv = bndv->next; } /* center vertex */ - w = (float)(1.0 / M_SQRT3); - co[0] = w; - co[1] = w; - co[2] = w; + copy_v3_fl(co, M_SQRT1_3); + if (nseg > 2) { if (r > 1.5f) mul_v3_fl(co, 1.4f); @@ -2935,6 +2932,10 @@ static BevVert *bevel_vert_construct(BMesh *bm, BevelParams *bp, BMVert *v) } bv->offset *= weight; } + else if (bp->use_weights) { + weight = BM_elem_float_data_get(&bm->vdata, v, CD_BWEIGHT); + bv->offset *= weight; + } } BLI_ghash_insert(bp->vert_hash, v, bv); diff --git a/source/blender/bmesh/tools/bmesh_bisect_plane.c b/source/blender/bmesh/tools/bmesh_bisect_plane.c index 463304f27f7..e6e33c905da 100644 --- a/source/blender/bmesh/tools/bmesh_bisect_plane.c +++ b/source/blender/bmesh/tools/bmesh_bisect_plane.c @@ -112,7 +112,7 @@ static int bm_vert_sortval_cb(const void *v_a_v, const void *v_b_v) static void bm_face_bisect_verts(BMesh *bm, BMFace *f, const float plane[4], const short oflag_center) { - /* unlikely more then 2 verts are needed */ + /* unlikely more than 2 verts are needed */ const unsigned int f_len_orig = (unsigned int)f->len; BMVert **vert_split_arr = BLI_array_alloca(vert_split_arr, f_len_orig); STACK_DECLARE(vert_split_arr); diff --git a/source/blender/bmesh/tools/bmesh_path.c b/source/blender/bmesh/tools/bmesh_path.c index 060d0dd969b..8ae3507a738 100644 --- a/source/blender/bmesh/tools/bmesh_path.c +++ b/source/blender/bmesh/tools/bmesh_path.c @@ -95,7 +95,7 @@ static void verttag_add_adjacent(Heap *heap, BMVert *v_a, BMVert **verts_prev, f LinkNode *BM_mesh_calc_path_vert( BMesh *bm, BMVert *v_src, BMVert *v_dst, const bool use_length, - void *user_data, bool (*test_fn)(BMVert *, void *user_data)) + bool (*test_fn)(BMVert *, void *user_data), void *user_data) { LinkNode *path = NULL; /* BM_ELEM_TAG flag is used to store visited edges */ @@ -221,7 +221,7 @@ static void edgetag_add_adjacent(Heap *heap, BMEdge *e1, BMEdge **edges_prev, fl LinkNode *BM_mesh_calc_path_edge( BMesh *bm, BMEdge *e_src, BMEdge *e_dst, const bool use_length, - void *user_data, bool (*filter_fn)(BMEdge *, void *user_data)) + bool (*filter_fn)(BMEdge *, void *user_data), void *user_data) { LinkNode *path = NULL; /* BM_ELEM_TAG flag is used to store visited edges */ @@ -347,7 +347,7 @@ static void facetag_add_adjacent(Heap *heap, BMFace *f_a, BMFace **faces_prev, f LinkNode *BM_mesh_calc_path_face( BMesh *bm, BMFace *f_src, BMFace *f_dst, const bool use_length, - void *user_data, bool (*test_fn)(BMFace *, void *user_data)) + bool (*test_fn)(BMFace *, void *user_data), void *user_data) { LinkNode *path = NULL; /* BM_ELEM_TAG flag is used to store visited edges */ diff --git a/source/blender/bmesh/tools/bmesh_path.h b/source/blender/bmesh/tools/bmesh_path.h index a13290b875e..c39e08e83ef 100644 --- a/source/blender/bmesh/tools/bmesh_path.h +++ b/source/blender/bmesh/tools/bmesh_path.h @@ -29,14 +29,17 @@ struct LinkNode *BM_mesh_calc_path_vert( BMesh *bm, BMVert *v_src, BMVert *v_dst, const bool use_length, - void *user_data, bool (*filter_fn)(BMVert *, void *)); + bool (*filter_fn)(BMVert *, void *), void *user_data) +ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2, 3, 5); struct LinkNode *BM_mesh_calc_path_edge( BMesh *bm, BMEdge *e_src, BMEdge *e_dst, const bool use_length, - void *user_data, bool (*filter_fn)(BMEdge *, void *)); + bool (*filter_fn)(BMEdge *, void *), void *user_data) +ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2, 3, 5); struct LinkNode *BM_mesh_calc_path_face( BMesh *bm, BMFace *f_src, BMFace *f_dst, const bool use_length, - void *user_data, bool (*test_fn)(BMFace *, void *)); + bool (*test_fn)(BMFace *, void *), void *user_data) +ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2, 3, 5); #endif /* __BMESH_PATH_H__ */ diff --git a/source/blender/bmesh/tools/bmesh_region_match.c b/source/blender/bmesh/tools/bmesh_region_match.c index 050d5ae4808..bb7000e5534 100644 --- a/source/blender/bmesh/tools/bmesh_region_match.c +++ b/source/blender/bmesh/tools/bmesh_region_match.c @@ -656,7 +656,7 @@ static bool bm_uuidwalk_facestep_begin( bool ok = false; BLI_assert(BLI_ghash_size(uuidwalk->cache.faces_from_uuid) == 0); - BLI_assert(BLI_countlist(&fstep->items) == 0); + BLI_assert(BLI_listbase_is_empty(&fstep->items)); f_link_prev_p = &fstep->faces; for (f_link = fstep->faces; f_link; f_link = f_link_next) { @@ -695,7 +695,7 @@ static bool bm_uuidwalk_facestep_begin( BLI_ghash_clear(uuidwalk->cache.faces_from_uuid, NULL, NULL); - BLI_sortlist(&fstep->items, facestep_sort); + BLI_listbase_sort(&fstep->items, facestep_sort); return ok; } @@ -781,7 +781,7 @@ static BMFace **bm_mesh_region_match_pair( UUIDFaceStep *fstep_src = w_src->faces_step.first; UUIDFaceStep *fstep_dst = w_dst->faces_step.first; - BLI_assert(BLI_countlist(&w_src->faces_step) == BLI_countlist(&w_dst->faces_step)); + BLI_assert(BLI_listbase_count(&w_src->faces_step) == BLI_listbase_count(&w_dst->faces_step)); while (fstep_src) { @@ -874,7 +874,7 @@ static BMFace **bm_mesh_region_match_pair( const unsigned int faces_result_len = (unsigned int)BLI_ghash_size(w_dst->faces_uuid); unsigned int i; - faces_result = MEM_mallocN(sizeof(faces_result) * (faces_result_len + 1), __func__); + faces_result = MEM_mallocN(sizeof(*faces_result) * (faces_result_len + 1), __func__); GHASH_ITER_INDEX (gh_iter, w_dst->faces_uuid, i) { BMFace *f = BLI_ghashIterator_getKey(&gh_iter); faces_result[i] = f; diff --git a/source/blender/bmesh/tools/bmesh_triangulate.c b/source/blender/bmesh/tools/bmesh_triangulate.c index 446c03a543f..b76054f270f 100644 --- a/source/blender/bmesh/tools/bmesh_triangulate.c +++ b/source/blender/bmesh/tools/bmesh_triangulate.c @@ -27,13 +27,20 @@ * */ +#include "DNA_modifier_types.h" /* for MOD_TRIANGULATE_NGON_BEAUTY only */ + #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" #include "BLI_alloca.h" #include "BLI_memarena.h" #include "BLI_listbase.h" -#include "BLI_scanfill.h" +#include "BLI_heap.h" +#include "BLI_edgehash.h" + +/* only for defines */ +#include "BLI_polyfill2d.h" +#include "BLI_polyfill2d_beautify.h" #include "bmesh.h" @@ -42,16 +49,25 @@ /** * a version of #BM_face_triangulate that maps to #BMOpSlot */ -static void bm_face_triangulate_mapping(BMesh *bm, BMFace *face, MemArena *sf_arena, - const int quad_method, const int ngon_method, - const bool use_tag, - BMOperator *op, BMOpSlot *slot_facemap_out) +static void bm_face_triangulate_mapping( + BMesh *bm, BMFace *face, + const int quad_method, const int ngon_method, + const bool use_tag, + BMOperator *op, BMOpSlot *slot_facemap_out, + + MemArena *pf_arena, + /* use for MOD_TRIANGULATE_NGON_BEAUTY only! */ + struct Heap *pf_heap, struct EdgeHash *pf_ehash) { int faces_array_tot = face->len - 3; BMFace **faces_array = BLI_array_alloca(faces_array, faces_array_tot); BLI_assert(face->len > 3); - BM_face_triangulate(bm, face, faces_array, &faces_array_tot, sf_arena, quad_method, ngon_method, use_tag); + BM_face_triangulate( + bm, face, faces_array, &faces_array_tot, + quad_method, ngon_method, use_tag, + pf_arena, + pf_heap, pf_ehash); if (faces_array_tot) { int i; @@ -63,22 +79,39 @@ static void bm_face_triangulate_mapping(BMesh *bm, BMFace *face, MemArena *sf_ar } -void BM_mesh_triangulate(BMesh *bm, const int quad_method, const int ngon_method, const bool tag_only, - BMOperator *op, BMOpSlot *slot_facemap_out) +void BM_mesh_triangulate( + BMesh *bm, const int quad_method, const int ngon_method, const bool tag_only, + BMOperator *op, BMOpSlot *slot_facemap_out) { BMIter iter; BMFace *face; - MemArena *sf_arena; + MemArena *pf_arena; + Heap *pf_heap; + EdgeHash *pf_ehash; - sf_arena = BLI_memarena_new(BLI_SCANFILL_ARENA_SIZE, __func__); + pf_arena = BLI_memarena_new(BLI_POLYFILL_ARENA_SIZE, __func__); + + if (ngon_method == MOD_TRIANGULATE_NGON_BEAUTY) { + pf_heap = BLI_heap_new_ex(BLI_POLYFILL_ALLOC_NGON_RESERVE); + pf_ehash = BLI_edgehash_new_ex(__func__, BLI_POLYFILL_ALLOC_NGON_RESERVE); + } + else { + pf_heap = NULL; + pf_ehash = NULL; + } if (slot_facemap_out) { /* same as below but call: bm_face_triangulate_mapping() */ BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) { if (face->len > 3) { if (tag_only == false || BM_elem_flag_test(face, BM_ELEM_TAG)) { - bm_face_triangulate_mapping(bm, face, sf_arena, quad_method, ngon_method, tag_only, - op, slot_facemap_out); + bm_face_triangulate_mapping( + bm, face, quad_method, + ngon_method, tag_only, + op, slot_facemap_out, + + pf_arena, + pf_heap, pf_ehash); } } } @@ -87,11 +120,20 @@ void BM_mesh_triangulate(BMesh *bm, const int quad_method, const int ngon_method BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) { if (face->len > 3) { if (tag_only == false || BM_elem_flag_test(face, BM_ELEM_TAG)) { - BM_face_triangulate(bm, face, NULL, NULL, sf_arena, quad_method, ngon_method, tag_only); + BM_face_triangulate( + bm, face, NULL, NULL, + quad_method, ngon_method, tag_only, + pf_arena, + pf_heap, pf_ehash); } } } } - BLI_memarena_free(sf_arena); + BLI_memarena_free(pf_arena); + + if (ngon_method == MOD_TRIANGULATE_NGON_BEAUTY) { + BLI_heap_free(pf_heap, NULL); + BLI_edgehash_free(pf_ehash, NULL); + } } |