diff options
author | Hans Goudey <h.goudey@me.com> | 2022-07-31 03:45:07 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-07-31 03:45:07 +0300 |
commit | 8ebcb9885adcbed59efb7c546c8b4879238f35fe (patch) | |
tree | 95239279fa05275cae70658fcea225cdf2b2f8c0 /source/blender/bmesh | |
parent | 0fea90d1f50c567c2ba49c7e5b084310bfdb88b7 (diff) | |
parent | 3c5620aabd33c39caa48192e978d0bf237b5b59b (diff) |
Merge branch 'master' into refactor-mesh-bevel-weight-generic
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r-- | source/blender/bmesh/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh.cc (renamed from source/blender/bmesh/intern/bmesh_mesh.c) | 200 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh_tessellate.c | 2 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_connect_pair.c | 24 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_primitive.c | 32 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_path_uv.c | 203 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_path_uv.h | 8 |
7 files changed, 332 insertions, 139 deletions
diff --git a/source/blender/bmesh/CMakeLists.txt b/source/blender/bmesh/CMakeLists.txt index 31492cd5c13..0d1eeab8eec 100644 --- a/source/blender/bmesh/CMakeLists.txt +++ b/source/blender/bmesh/CMakeLists.txt @@ -80,7 +80,7 @@ set(SRC intern/bmesh_log.h intern/bmesh_marking.c intern/bmesh_marking.h - intern/bmesh_mesh.c + intern/bmesh_mesh.cc intern/bmesh_mesh.h intern/bmesh_mesh_convert.cc intern/bmesh_mesh_convert.h diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.cc index 7dba854b9ef..c16d874e3ec 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.cc @@ -88,19 +88,19 @@ void BM_mesh_elem_toolflags_ensure(BMesh *bm) BMVert_OFlag *v_olfag; BLI_mempool *toolflagpool = bm->vtoolflagpool; BM_ITER_MESH (v_olfag, &iter, bm, BM_VERTS_OF_MESH) { - v_olfag->oflags = BLI_mempool_calloc(toolflagpool); + v_olfag->oflags = (BMFlagLayer *)BLI_mempool_calloc(toolflagpool); } BMEdge_OFlag *e_olfag; toolflagpool = bm->etoolflagpool; BM_ITER_MESH (e_olfag, &iter, bm, BM_EDGES_OF_MESH) { - e_olfag->oflags = BLI_mempool_calloc(toolflagpool); + e_olfag->oflags = (BMFlagLayer *)BLI_mempool_calloc(toolflagpool); } BMFace_OFlag *f_olfag; toolflagpool = bm->ftoolflagpool; BM_ITER_MESH (f_olfag, &iter, bm, BM_FACES_OF_MESH) { - f_olfag->oflags = BLI_mempool_calloc(toolflagpool); + f_olfag->oflags = (BMFlagLayer *)BLI_mempool_calloc(toolflagpool); } bm->totflags = 1; @@ -110,22 +110,22 @@ void BM_mesh_elem_toolflags_clear(BMesh *bm) { if (bm->vtoolflagpool) { BLI_mempool_destroy(bm->vtoolflagpool); - bm->vtoolflagpool = NULL; + bm->vtoolflagpool = nullptr; } if (bm->etoolflagpool) { BLI_mempool_destroy(bm->etoolflagpool); - bm->etoolflagpool = NULL; + bm->etoolflagpool = nullptr; } if (bm->ftoolflagpool) { BLI_mempool_destroy(bm->ftoolflagpool); - bm->ftoolflagpool = NULL; + bm->ftoolflagpool = nullptr; } } BMesh *BM_mesh_create(const BMAllocTemplate *allocsize, const struct BMeshCreateParams *params) { /* allocate the structure */ - BMesh *bm = MEM_callocN(sizeof(BMesh), __func__); + BMesh *bm = (BMesh *)MEM_callocN(sizeof(BMesh), __func__); /* allocate the memory pools for the mesh elements */ bm_mempool_init(bm, allocsize, params->use_toolflags); @@ -262,8 +262,8 @@ void BM_mesh_free(BMesh *bm) if (bm->py_handle) { /* keep this out of 'BM_mesh_data_free' because we want python * to be able to clear the mesh and maintain access. */ - bpy_bm_generic_invalidate(bm->py_handle); - bm->py_handle = NULL; + bpy_bm_generic_invalidate((BPy_BMGeneric *)bm->py_handle); + bm->py_handle = nullptr; } MEM_freeN(bm); @@ -336,7 +336,7 @@ void BM_mesh_elem_index_ensure_ex(BMesh *bm, const char htype, int elem_offset[4 BM_ELEM_INDEX_VALIDATE(bm, "Should Never Fail!", __func__); #endif - if (elem_offset == NULL) { + if (elem_offset == nullptr) { /* Simple case. */ const char htype_needed = bm->elem_index_dirty & htype; if (htype_needed == 0) { @@ -445,7 +445,7 @@ finally: void BM_mesh_elem_index_ensure(BMesh *bm, const char htype) { - BM_mesh_elem_index_ensure_ex(bm, htype, NULL); + BM_mesh_elem_index_ensure_ex(bm, htype, nullptr); } void BM_mesh_elem_index_validate( @@ -459,7 +459,7 @@ void BM_mesh_elem_index_validate( BMIter iter; BMElem *ele; int i; - bool is_any_error = 0; + bool is_any_error = false; for (i = 0; i < 3; i++) { const bool is_dirty = (flag_types[i] & bm->elem_index_dirty) != 0; @@ -581,9 +581,10 @@ void BM_mesh_elem_table_ensure(BMesh *bm, const char htype) if (bm->vtable) { MEM_freeN(bm->vtable); } - bm->vtable = MEM_mallocN(sizeof(void **) * bm->totvert, "bm->vtable"); + bm->vtable = (BMVert **)MEM_mallocN(sizeof(void **) * bm->totvert, "bm->vtable"); bm->vtable_tot = bm->totvert; } + BM_iter_as_array(bm, BM_VERTS_OF_MESH, nullptr, (void **)bm->vtable, bm->totvert); } if (htype_needed & BM_EDGE) { if (bm->etable && bm->totedge <= bm->etable_tot && bm->totedge * 2 >= bm->etable_tot) { @@ -593,9 +594,10 @@ void BM_mesh_elem_table_ensure(BMesh *bm, const char htype) if (bm->etable) { MEM_freeN(bm->etable); } - bm->etable = MEM_mallocN(sizeof(void **) * bm->totedge, "bm->etable"); + bm->etable = (BMEdge **)MEM_mallocN(sizeof(void **) * bm->totedge, "bm->etable"); bm->etable_tot = bm->totedge; } + BM_iter_as_array(bm, BM_EDGES_OF_MESH, nullptr, (void **)bm->etable, bm->totedge); } if (htype_needed & BM_FACE) { if (bm->ftable && bm->totface <= bm->ftable_tot && bm->totface * 2 >= bm->ftable_tot) { @@ -605,21 +607,10 @@ void BM_mesh_elem_table_ensure(BMesh *bm, const char htype) if (bm->ftable) { MEM_freeN(bm->ftable); } - bm->ftable = MEM_mallocN(sizeof(void **) * bm->totface, "bm->ftable"); + bm->ftable = (BMFace **)MEM_mallocN(sizeof(void **) * bm->totface, "bm->ftable"); bm->ftable_tot = bm->totface; } - } - - if (htype_needed & BM_VERT) { - BM_iter_as_array(bm, BM_VERTS_OF_MESH, NULL, (void **)bm->vtable, bm->totvert); - } - - if (htype_needed & BM_EDGE) { - BM_iter_as_array(bm, BM_EDGES_OF_MESH, NULL, (void **)bm->etable, bm->totedge); - } - - if (htype_needed & BM_FACE) { - BM_iter_as_array(bm, BM_FACES_OF_MESH, NULL, (void **)bm->ftable, bm->totface); + BM_iter_as_array(bm, BM_FACES_OF_MESH, nullptr, (void **)bm->ftable, bm->totface); } finally: @@ -656,17 +647,17 @@ void BM_mesh_elem_table_free(BMesh *bm, const char htype) BMVert *BM_vert_at_index_find(BMesh *bm, const int index) { - return BLI_mempool_findelem(bm->vpool, index); + return (BMVert *)BLI_mempool_findelem(bm->vpool, index); } BMEdge *BM_edge_at_index_find(BMesh *bm, const int index) { - return BLI_mempool_findelem(bm->epool, index); + return (BMEdge *)BLI_mempool_findelem(bm->epool, index); } BMFace *BM_face_at_index_find(BMesh *bm, const int index) { - return BLI_mempool_findelem(bm->fpool, index); + return (BMFace *)BLI_mempool_findelem(bm->fpool, index); } BMLoop *BM_loop_at_index_find(BMesh *bm, const int index) @@ -687,13 +678,13 @@ BMLoop *BM_loop_at_index_find(BMesh *bm, const int index) } i -= f->len; } - return NULL; + return nullptr; } BMVert *BM_vert_at_index_find_or_table(BMesh *bm, const int index) { if ((bm->elem_table_dirty & BM_VERT) == 0) { - return (index < bm->totvert) ? bm->vtable[index] : NULL; + return (index < bm->totvert) ? bm->vtable[index] : nullptr; } return BM_vert_at_index_find(bm, index); } @@ -701,7 +692,7 @@ BMVert *BM_vert_at_index_find_or_table(BMesh *bm, const int index) BMEdge *BM_edge_at_index_find_or_table(BMesh *bm, const int index) { if ((bm->elem_table_dirty & BM_EDGE) == 0) { - return (index < bm->totedge) ? bm->etable[index] : NULL; + return (index < bm->totedge) ? bm->etable[index] : nullptr; } return BM_edge_at_index_find(bm, index); } @@ -709,7 +700,7 @@ BMEdge *BM_edge_at_index_find_or_table(BMesh *bm, const int index) BMFace *BM_face_at_index_find_or_table(BMesh *bm, const int index) { if ((bm->elem_table_dirty & BM_FACE) == 0) { - return (index < bm->totface) ? bm->ftable[index] : NULL; + return (index < bm->totface) ? bm->ftable[index] : nullptr; } return BM_face_at_index_find(bm, index); } @@ -735,7 +726,7 @@ int BM_mesh_elem_count(BMesh *bm, const char htype) void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const uint *face_idx) { /* Mapping old to new pointers. */ - GHash *vptr_map = NULL, *eptr_map = NULL, *fptr_map = NULL; + GHash *vptr_map = nullptr, *eptr_map = nullptr, *fptr_map = nullptr; BMIter iter, iterl; BMVert *ve; BMEdge *ed; @@ -763,14 +754,16 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const /* Make a copy of all vertices. */ verts_pool = bm->vtable; - verts_copy = MEM_mallocN(sizeof(BMVert) * totvert, "BM_mesh_remap verts copy"); - void **pyptrs = (cd_vert_pyptr != -1) ? MEM_mallocN(sizeof(void *) * totvert, __func__) : NULL; + verts_copy = (BMVert *)MEM_mallocN(sizeof(BMVert) * totvert, "BM_mesh_remap verts copy"); + void **pyptrs = (cd_vert_pyptr != -1) ? + (void **)MEM_mallocN(sizeof(void *) * totvert, __func__) : + nullptr; for (i = totvert, ve = verts_copy + totvert - 1, vep = verts_pool + totvert - 1; i--; ve--, vep--) { *ve = **vep; // printf("*vep: %p, verts_pool[%d]: %p\n", *vep, i, verts_pool[i]); if (cd_vert_pyptr != -1) { - void **pyptr = BM_ELEM_CD_GET_VOID_P(((BMElem *)ve), cd_vert_pyptr); + void **pyptr = (void **)BM_ELEM_CD_GET_VOID_P(((BMElem *)ve), cd_vert_pyptr); pyptrs[i] = *pyptr; } } @@ -788,7 +781,7 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const #endif BLI_ghash_insert(vptr_map, *vep, new_vep); if (cd_vert_pyptr != -1) { - void **pyptr = BM_ELEM_CD_GET_VOID_P(((BMElem *)new_vep), cd_vert_pyptr); + void **pyptr = (void **)BM_ELEM_CD_GET_VOID_P(((BMElem *)new_vep), cd_vert_pyptr); *pyptr = pyptrs[*new_idx]; } } @@ -815,13 +808,15 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const /* Make a copy of all vertices. */ edges_pool = bm->etable; - edges_copy = MEM_mallocN(sizeof(BMEdge) * totedge, "BM_mesh_remap edges copy"); - void **pyptrs = (cd_edge_pyptr != -1) ? MEM_mallocN(sizeof(void *) * totedge, __func__) : NULL; + edges_copy = (BMEdge *)MEM_mallocN(sizeof(BMEdge) * totedge, "BM_mesh_remap edges copy"); + void **pyptrs = (cd_edge_pyptr != -1) ? + (void **)MEM_mallocN(sizeof(void *) * totedge, __func__) : + nullptr; for (i = totedge, ed = edges_copy + totedge - 1, edp = edges_pool + totedge - 1; i--; ed--, edp--) { *ed = **edp; if (cd_edge_pyptr != -1) { - void **pyptr = BM_ELEM_CD_GET_VOID_P(((BMElem *)ed), cd_edge_pyptr); + void **pyptr = (void **)BM_ELEM_CD_GET_VOID_P(((BMElem *)ed), cd_edge_pyptr); pyptrs[i] = *pyptr; } } @@ -839,7 +834,7 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const "mapping edge from %d to %d (%p/%p to %p)\n", i, *new_idx, *edp, edges_pool[i], new_edp); #endif if (cd_edge_pyptr != -1) { - void **pyptr = BM_ELEM_CD_GET_VOID_P(((BMElem *)new_edp), cd_edge_pyptr); + void **pyptr = (void **)BM_ELEM_CD_GET_VOID_P(((BMElem *)new_edp), cd_edge_pyptr); *pyptr = pyptrs[*new_idx]; } } @@ -866,13 +861,15 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const /* Make a copy of all vertices. */ faces_pool = bm->ftable; - faces_copy = MEM_mallocN(sizeof(BMFace) * totface, "BM_mesh_remap faces copy"); - void **pyptrs = (cd_poly_pyptr != -1) ? MEM_mallocN(sizeof(void *) * totface, __func__) : NULL; + faces_copy = (BMFace *)MEM_mallocN(sizeof(BMFace) * totface, "BM_mesh_remap faces copy"); + void **pyptrs = (cd_poly_pyptr != -1) ? + (void **)MEM_mallocN(sizeof(void *) * totface, __func__) : + nullptr; for (i = totface, fa = faces_copy + totface - 1, fap = faces_pool + totface - 1; i--; fa--, fap--) { *fa = **fap; if (cd_poly_pyptr != -1) { - void **pyptr = BM_ELEM_CD_GET_VOID_P(((BMElem *)fa), cd_poly_pyptr); + void **pyptr = (void **)BM_ELEM_CD_GET_VOID_P(((BMElem *)fa), cd_poly_pyptr); pyptrs[i] = *pyptr; } } @@ -886,7 +883,7 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const *new_fap = *fa; BLI_ghash_insert(fptr_map, *fap, new_fap); if (cd_poly_pyptr != -1) { - void **pyptr = BM_ELEM_CD_GET_VOID_P(((BMElem *)new_fap), cd_poly_pyptr); + void **pyptr = (void **)BM_ELEM_CD_GET_VOID_P(((BMElem *)new_fap), cd_poly_pyptr); *pyptr = pyptrs[*new_idx]; } } @@ -906,7 +903,7 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const BM_ITER_MESH (ve, &iter, bm, BM_VERTS_OF_MESH) { // printf("Vert e: %p -> %p\n", ve->e, BLI_ghash_lookup(eptr_map, ve->e)); if (ve->e) { - ve->e = BLI_ghash_lookup(eptr_map, ve->e); + ve->e = (BMEdge *)BLI_ghash_lookup(eptr_map, ve->e); BLI_assert(ve->e); } } @@ -922,8 +919,8 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const printf("Edge v1: %p -> %p\n", ed->v1, BLI_ghash_lookup(vptr_map, ed->v1)); printf("Edge v2: %p -> %p\n", ed->v2, BLI_ghash_lookup(vptr_map, ed->v2)); #endif - ed->v1 = BLI_ghash_lookup(vptr_map, ed->v1); - ed->v2 = BLI_ghash_lookup(vptr_map, ed->v2); + ed->v1 = (BMVert *)BLI_ghash_lookup(vptr_map, ed->v1); + ed->v2 = (BMVert *)BLI_ghash_lookup(vptr_map, ed->v2); BLI_assert(ed->v1); BLI_assert(ed->v2); } @@ -942,10 +939,10 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const ed->v2_disk_link.next, BLI_ghash_lookup(eptr_map, ed->v2_disk_link.next)); #endif - ed->v1_disk_link.prev = BLI_ghash_lookup(eptr_map, ed->v1_disk_link.prev); - ed->v1_disk_link.next = BLI_ghash_lookup(eptr_map, ed->v1_disk_link.next); - ed->v2_disk_link.prev = BLI_ghash_lookup(eptr_map, ed->v2_disk_link.prev); - ed->v2_disk_link.next = BLI_ghash_lookup(eptr_map, ed->v2_disk_link.next); + ed->v1_disk_link.prev = (BMEdge *)BLI_ghash_lookup(eptr_map, ed->v1_disk_link.prev); + ed->v1_disk_link.next = (BMEdge *)BLI_ghash_lookup(eptr_map, ed->v1_disk_link.next); + ed->v2_disk_link.prev = (BMEdge *)BLI_ghash_lookup(eptr_map, ed->v2_disk_link.prev); + ed->v2_disk_link.next = (BMEdge *)BLI_ghash_lookup(eptr_map, ed->v2_disk_link.next); BLI_assert(ed->v1_disk_link.prev); BLI_assert(ed->v1_disk_link.next); BLI_assert(ed->v2_disk_link.prev); @@ -959,17 +956,17 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const BM_ITER_ELEM (lo, &iterl, fa, BM_LOOPS_OF_FACE) { if (vptr_map) { // printf("Loop v: %p -> %p\n", lo->v, BLI_ghash_lookup(vptr_map, lo->v)); - lo->v = BLI_ghash_lookup(vptr_map, lo->v); + lo->v = (BMVert *)BLI_ghash_lookup(vptr_map, lo->v); BLI_assert(lo->v); } if (eptr_map) { // printf("Loop e: %p -> %p\n", lo->e, BLI_ghash_lookup(eptr_map, lo->e)); - lo->e = BLI_ghash_lookup(eptr_map, lo->e); + lo->e = (BMEdge *)BLI_ghash_lookup(eptr_map, lo->e); BLI_assert(lo->e); } if (fptr_map) { // printf("Loop f: %p -> %p\n", lo->f, BLI_ghash_lookup(fptr_map, lo->f)); - lo->f = BLI_ghash_lookup(fptr_map, lo->f); + lo->f = (BMFace *)BLI_ghash_lookup(fptr_map, lo->f); BLI_assert(lo->f); } } @@ -978,23 +975,23 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const /* Selection history */ { BMEditSelection *ese; - for (ese = bm->selected.first; ese; ese = ese->next) { + for (ese = (BMEditSelection *)bm->selected.first; ese; ese = ese->next) { switch (ese->htype) { case BM_VERT: if (vptr_map) { - ese->ele = BLI_ghash_lookup(vptr_map, ese->ele); + ese->ele = (BMElem *)BLI_ghash_lookup(vptr_map, ese->ele); BLI_assert(ese->ele); } break; case BM_EDGE: if (eptr_map) { - ese->ele = BLI_ghash_lookup(eptr_map, ese->ele); + ese->ele = (BMElem *)BLI_ghash_lookup(eptr_map, ese->ele); BLI_assert(ese->ele); } break; case BM_FACE: if (fptr_map) { - ese->ele = BLI_ghash_lookup(fptr_map, ese->ele); + ese->ele = (BMElem *)BLI_ghash_lookup(fptr_map, ese->ele); BLI_assert(ese->ele); } break; @@ -1004,19 +1001,19 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const if (fptr_map) { if (bm->act_face) { - bm->act_face = BLI_ghash_lookup(fptr_map, bm->act_face); + bm->act_face = (BMFace *)BLI_ghash_lookup(fptr_map, bm->act_face); BLI_assert(bm->act_face); } } if (vptr_map) { - BLI_ghash_free(vptr_map, NULL, NULL); + BLI_ghash_free(vptr_map, nullptr, nullptr); } if (eptr_map) { - BLI_ghash_free(eptr_map, NULL, NULL); + BLI_ghash_free(eptr_map, nullptr, nullptr); } if (fptr_map) { - BLI_ghash_free(fptr_map, NULL, NULL); + BLI_ghash_free(fptr_map, nullptr, nullptr); } } @@ -1030,14 +1027,18 @@ void BM_mesh_rebuild(BMesh *bm, const char remap = (vpool_dst ? BM_VERT : 0) | (epool_dst ? BM_EDGE : 0) | (lpool_dst ? BM_LOOP : 0) | (fpool_dst ? BM_FACE : 0); - BMVert **vtable_dst = (remap & BM_VERT) ? MEM_mallocN(bm->totvert * sizeof(BMVert *), __func__) : - NULL; - BMEdge **etable_dst = (remap & BM_EDGE) ? MEM_mallocN(bm->totedge * sizeof(BMEdge *), __func__) : - NULL; - BMLoop **ltable_dst = (remap & BM_LOOP) ? MEM_mallocN(bm->totloop * sizeof(BMLoop *), __func__) : - NULL; - BMFace **ftable_dst = (remap & BM_FACE) ? MEM_mallocN(bm->totface * sizeof(BMFace *), __func__) : - NULL; + BMVert **vtable_dst = (remap & BM_VERT) ? + (BMVert **)MEM_mallocN(bm->totvert * sizeof(BMVert *), __func__) : + nullptr; + BMEdge **etable_dst = (remap & BM_EDGE) ? + (BMEdge **)MEM_mallocN(bm->totedge * sizeof(BMEdge *), __func__) : + nullptr; + BMLoop **ltable_dst = (remap & BM_LOOP) ? + (BMLoop **)MEM_mallocN(bm->totloop * sizeof(BMLoop *), __func__) : + nullptr; + BMFace **ftable_dst = (remap & BM_FACE) ? + (BMFace **)MEM_mallocN(bm->totface * sizeof(BMFace *), __func__) : + nullptr; const bool use_toolflags = params->use_toolflags; @@ -1046,12 +1047,12 @@ void BM_mesh_rebuild(BMesh *bm, int index; BMVert *v_src; BM_ITER_MESH_INDEX (v_src, &iter, bm, BM_VERTS_OF_MESH, index) { - BMVert *v_dst = BLI_mempool_alloc(vpool_dst); + BMVert *v_dst = (BMVert *)BLI_mempool_alloc(vpool_dst); memcpy(v_dst, v_src, sizeof(BMVert)); if (use_toolflags) { - ((BMVert_OFlag *)v_dst)->oflags = bm->vtoolflagpool ? - BLI_mempool_calloc(bm->vtoolflagpool) : - NULL; + ((BMVert_OFlag *)v_dst)->oflags = bm->vtoolflagpool ? (BMFlagLayer *)BLI_mempool_calloc( + bm->vtoolflagpool) : + nullptr; } vtable_dst[index] = v_dst; @@ -1064,12 +1065,12 @@ void BM_mesh_rebuild(BMesh *bm, int index; BMEdge *e_src; BM_ITER_MESH_INDEX (e_src, &iter, bm, BM_EDGES_OF_MESH, index) { - BMEdge *e_dst = BLI_mempool_alloc(epool_dst); + BMEdge *e_dst = (BMEdge *)BLI_mempool_alloc(epool_dst); memcpy(e_dst, e_src, sizeof(BMEdge)); if (use_toolflags) { - ((BMEdge_OFlag *)e_dst)->oflags = bm->etoolflagpool ? - BLI_mempool_calloc(bm->etoolflagpool) : - NULL; + ((BMEdge_OFlag *)e_dst)->oflags = bm->etoolflagpool ? (BMFlagLayer *)BLI_mempool_calloc( + bm->etoolflagpool) : + nullptr; } etable_dst[index] = e_dst; @@ -1084,12 +1085,12 @@ void BM_mesh_rebuild(BMesh *bm, BM_ITER_MESH_INDEX (f_src, &iter, bm, BM_FACES_OF_MESH, index) { if (remap & BM_FACE) { - BMFace *f_dst = BLI_mempool_alloc(fpool_dst); + BMFace *f_dst = (BMFace *)BLI_mempool_alloc(fpool_dst); memcpy(f_dst, f_src, sizeof(BMFace)); if (use_toolflags) { - ((BMFace_OFlag *)f_dst)->oflags = bm->ftoolflagpool ? - BLI_mempool_calloc(bm->ftoolflagpool) : - NULL; + ((BMFace_OFlag *)f_dst)->oflags = bm->ftoolflagpool ? (BMFlagLayer *)BLI_mempool_calloc( + bm->ftoolflagpool) : + nullptr; } ftable_dst[index] = f_dst; @@ -1101,7 +1102,7 @@ void BM_mesh_rebuild(BMesh *bm, BMLoop *l_iter_src, *l_first_src; l_iter_src = l_first_src = BM_FACE_FIRST_LOOP((BMFace *)f_src); do { - BMLoop *l_dst = BLI_mempool_alloc(lpool_dst); + BMLoop *l_dst = (BMLoop *)BLI_mempool_alloc(lpool_dst); memcpy(l_dst, l_iter_src, sizeof(BMLoop)); ltable_dst[index_loop] = l_dst; BM_elem_index_set(l_iter_src, index_loop++); /* set_ok */ @@ -1279,30 +1280,25 @@ void BM_mesh_toolflags_set(BMesh *bm, bool use_toolflags) const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_BM(bm); - BLI_mempool *vpool_dst = NULL; - BLI_mempool *epool_dst = NULL; - BLI_mempool *fpool_dst = NULL; + BLI_mempool *vpool_dst = nullptr; + BLI_mempool *epool_dst = nullptr; + BLI_mempool *fpool_dst = nullptr; - bm_mempool_init_ex(&allocsize, use_toolflags, &vpool_dst, &epool_dst, NULL, &fpool_dst); + bm_mempool_init_ex(&allocsize, use_toolflags, &vpool_dst, &epool_dst, nullptr, &fpool_dst); if (use_toolflags == false) { BLI_mempool_destroy(bm->vtoolflagpool); BLI_mempool_destroy(bm->etoolflagpool); BLI_mempool_destroy(bm->ftoolflagpool); - bm->vtoolflagpool = NULL; - bm->etoolflagpool = NULL; - bm->ftoolflagpool = NULL; + bm->vtoolflagpool = nullptr; + bm->etoolflagpool = nullptr; + bm->ftoolflagpool = nullptr; } + struct BMeshCreateParams params = {}; + params.use_toolflags = use_toolflags; - BM_mesh_rebuild(bm, - &((struct BMeshCreateParams){ - .use_toolflags = use_toolflags, - }), - vpool_dst, - epool_dst, - NULL, - fpool_dst); + BM_mesh_rebuild(bm, ¶ms, vpool_dst, epool_dst, nullptr, fpool_dst); bm->use_toolflags = use_toolflags; } @@ -1323,7 +1319,7 @@ void BM_mesh_vert_coords_get(BMesh *bm, float (*vert_coords)[3]) float (*BM_mesh_vert_coords_alloc(BMesh *bm, int *r_vert_len))[3] { - float(*vert_coords)[3] = MEM_mallocN(bm->totvert * sizeof(*vert_coords), __func__); + float(*vert_coords)[3] = (float(*)[3])MEM_mallocN(bm->totvert * sizeof(*vert_coords), __func__); BM_mesh_vert_coords_get(bm, vert_coords); *r_vert_len = bm->totvert; return vert_coords; diff --git a/source/blender/bmesh/intern/bmesh_mesh_tessellate.c b/source/blender/bmesh/intern/bmesh_mesh_tessellate.c index 8d401ae1e5c..69510263ec9 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_tessellate.c +++ b/source/blender/bmesh/intern/bmesh_mesh_tessellate.c @@ -6,7 +6,7 @@ * This file contains code for polygon tessellation * (creating triangles from polygons). * - * \see mesh_tessellate.c for the #Mesh equivalent of this file. + * \see mesh_tessellate.cc for the #Mesh equivalent of this file. */ #include "DNA_meshdata_types.h" diff --git a/source/blender/bmesh/operators/bmo_connect_pair.c b/source/blender/bmesh/operators/bmo_connect_pair.c index e91dab3dd6f..26f1a9e626e 100644 --- a/source/blender/bmesh/operators/bmo_connect_pair.c +++ b/source/blender/bmesh/operators/bmo_connect_pair.c @@ -83,7 +83,7 @@ typedef struct PathContext { /* only to access BMO flags */ BMesh *bm_bmoflag; - BMVert *v_a, *v_b; + BMVert *v_pair[2]; BLI_mempool *link_pool; } PathContext; @@ -593,17 +593,17 @@ void bmo_connect_vert_pair_exec(BMesh *bm, BMOperator *op) } pc.bm_bmoflag = bm; - pc.v_a = ((BMVert **)op_verts_slot->data.p)[0]; - pc.v_b = ((BMVert **)op_verts_slot->data.p)[1]; + pc.v_pair[0] = ((BMVert **)op_verts_slot->data.p)[0]; + pc.v_pair[1] = ((BMVert **)op_verts_slot->data.p)[1]; /* fail! */ - if (!(pc.v_a && pc.v_b)) { + if (!(pc.v_pair[0] && pc.v_pair[1])) { return; } #ifdef DEBUG_PRINT - printf("%s: v_a: %d\n", __func__, BM_elem_index_get(pc.v_a)); - printf("%s: v_b: %d\n", __func__, BM_elem_index_get(pc.v_b)); + printf("%s: v_pair[0]: %d\n", __func__, BM_elem_index_get(pc.v_pair[0])); + printf("%s: v_pair[1]: %d\n", __func__, BM_elem_index_get(pc.v_pair[1])); #endif /* tag so we won't touch ever (typically hidden faces) */ @@ -618,15 +618,15 @@ void bmo_connect_vert_pair_exec(BMesh *bm, BMOperator *op) /* calculate matrix */ { - bm_vert_pair_to_matrix(&pc.v_a, pc.matrix); - pc.axis_sep = dot_m3_v3_row_x(pc.matrix, pc.v_a->co); + bm_vert_pair_to_matrix(pc.v_pair, pc.matrix); + pc.axis_sep = dot_m3_v3_row_x(pc.matrix, pc.v_pair[0]->co); } /* add first vertex */ { PathLinkState *state; state = MEM_callocN(sizeof(*state), __func__); - state_link_add(&pc, state, (BMElem *)pc.v_a, NULL); + state_link_add(&pc, state, (BMElem *)pc.v_pair[0], NULL); BLI_heapsimple_insert(pc.states, state->dist, state); } @@ -642,7 +642,7 @@ void bmo_connect_vert_pair_exec(BMesh *bm, BMOperator *op) /* either we insert this into 'pc.states' or its freed */ bool continue_search; - if (state->link_last->ele == (BMElem *)pc.v_b) { + if (state->link_last->ele == (BMElem *)pc.v_pair[1]) { /* pass, wait until all are found */ #ifdef DEBUG_PRINT printf("%s: state %p loop found %.4f\n", __func__, state, state->dist); @@ -698,8 +698,8 @@ void bmo_connect_vert_pair_exec(BMesh *bm, BMOperator *op) } while ((link = link->next)); } - BMO_vert_flag_enable(bm, pc.v_a, VERT_OUT); - BMO_vert_flag_enable(bm, pc.v_b, VERT_OUT); + BMO_vert_flag_enable(bm, pc.v_pair[0], VERT_OUT); + BMO_vert_flag_enable(bm, pc.v_pair[1], VERT_OUT); BLI_mempool_destroy(pc.link_pool); diff --git a/source/blender/bmesh/operators/bmo_primitive.c b/source/blender/bmesh/operators/bmo_primitive.c index 432c7590f3c..c60ffbedb94 100644 --- a/source/blender/bmesh/operators/bmo_primitive.c +++ b/source/blender/bmesh/operators/bmo_primitive.c @@ -855,12 +855,12 @@ void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op) /* one segment first */ for (a = 0; a <= tot; a++) { /* Going in this direction, then edge extruding, makes normals face outward */ - /* Calculate with doubles for higher precision, see: T87779. */ - const float phi = M_PI * ((double)a / (double)tot); + float sin_phi, cos_phi; + sin_cos_from_fraction(a, 2 * tot, &sin_phi, &cos_phi); - vec[0] = 0.0; - vec[1] = rad * sinf(phi); - vec[2] = rad * cosf(phi); + vec[0] = 0.0f; + vec[1] = rad * sin_phi; + vec[2] = rad * cos_phi; eve = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); BMO_vert_flag_enable(bm, eve, VERT_MARK); @@ -1262,11 +1262,9 @@ void bmo_create_circle_exec(BMesh *bm, BMOperator *op) for (a = 0; a < segs; a++) { /* Going this way ends up with normal(s) upward */ - - /* Calculate with doubles for higher precision, see: T87779. */ - const float phi = (2.0 * M_PI) * ((double)a / (double)segs); - vec[0] = -radius * sinf(phi); - vec[1] = radius * cosf(phi); + sin_cos_from_fraction(a, segs, &vec[0], &vec[1]); + vec[0] *= -radius; + vec[1] *= radius; vec[2] = 0.0f; mul_m4_v3(mat, vec); v1 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); @@ -1393,16 +1391,18 @@ void bmo_create_cone_exec(BMesh *bm, BMOperator *op) BMFace **side_faces = MEM_mallocN(sizeof(*side_faces) * side_faces_len, __func__); for (int i = 0; i < segs; i++) { - /* Calculate with doubles for higher precision, see: T87779. */ - const float phi = (2.0 * M_PI) * ((double)i / (double)segs); - vec[0] = rad1 * sinf(phi); - vec[1] = rad1 * cosf(phi); + /* Calculate with higher precision, see: T87779. */ + float sin_phi, cos_phi; + sin_cos_from_fraction(i, segs, &sin_phi, &cos_phi); + + vec[0] = rad1 * sin_phi; + vec[1] = rad1 * cos_phi; vec[2] = -depth_half; mul_m4_v3(mat, vec); v1 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); - vec[0] = rad2 * sinf(phi); - vec[1] = rad2 * cosf(phi); + vec[0] = rad2 * sin_phi; + vec[1] = rad2 * cos_phi; vec[2] = depth_half; mul_m4_v3(mat, vec); v2 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); diff --git a/source/blender/bmesh/tools/bmesh_path_uv.c b/source/blender/bmesh/tools/bmesh_path_uv.c index 76697f51ac7..3d736cdc3b8 100644 --- a/source/blender/bmesh/tools/bmesh_path_uv.c +++ b/source/blender/bmesh/tools/bmesh_path_uv.c @@ -47,9 +47,7 @@ static float step_cost_3_v2_ex( return cost * (1.0f + 0.5f * (2.0f - sqrtf(fabsf(dot_v2v2(d1, d2))))); } -static float UNUSED_FUNCTION(step_cost_3_v2)(const float v1[2], - const float v2[2], - const float v3[2]) +static float step_cost_3_v2(const float v1[2], const float v2[2], const float v3[2]) { return step_cost_3_v2_ex(v1, v2, v3, false, false); } @@ -60,7 +58,7 @@ static float UNUSED_FUNCTION(step_cost_3_v2)(const float v1[2], /** \name BM_mesh_calc_path_uv_vert * \{ */ -static void looptag_add_adjacent_uv(HeapSimple *heap, +static void verttag_add_adjacent_uv(HeapSimple *heap, BMLoop *l_a, BMLoop **loops_prev, float *cost, @@ -162,7 +160,7 @@ struct LinkNode *BM_mesh_calc_path_uv_vert(BMesh *bm, if (!BM_elem_flag_test(l, BM_ELEM_TAG)) { /* Adjacent loops are tagged while stepping to avoid 2x loops. */ BM_elem_flag_enable(l, BM_ELEM_TAG); - looptag_add_adjacent_uv(heap, l, loops_prev, cost, params); + verttag_add_adjacent_uv(heap, l, loops_prev, cost, params); } } @@ -185,8 +183,199 @@ struct LinkNode *BM_mesh_calc_path_uv_vert(BMesh *bm, /** \name BM_mesh_calc_path_uv_edge * \{ */ -/* TODO(@sidd017): Setting this as todo, since we now support proper UV edge selection (D12028). - * Till then, continue using vertex path to fake shortest path calculation for edges. */ +static float edgetag_cut_cost_vert_uv( + BMLoop *l_e_a, BMLoop *l_e_b, BMLoop *l_v, const float aspect_y, const int cd_loop_uv_offset) +{ + BMLoop *l_v1 = (l_v->v == l_e_a->v) ? l_e_a->next : l_e_a; + BMLoop *l_v2 = (l_v->v == l_e_b->v) ? l_e_b->next : l_e_b; + + MLoopUV *luv_v1 = BM_ELEM_CD_GET_VOID_P(l_v1, cd_loop_uv_offset); + MLoopUV *luv_v2 = BM_ELEM_CD_GET_VOID_P(l_v2, cd_loop_uv_offset); + MLoopUV *luv_v = BM_ELEM_CD_GET_VOID_P(l_v, cd_loop_uv_offset); + + float uv_v1[2] = {luv_v1->uv[0], luv_v1->uv[1] / aspect_y}; + float uv_v2[2] = {luv_v2->uv[0], luv_v2->uv[1] / aspect_y}; + float uv_v[2] = {luv_v->uv[0], luv_v->uv[1] / aspect_y}; + + return step_cost_3_v2(uv_v1, uv_v, uv_v2); +} + +static float edgetag_cut_cost_face_uv( + BMLoop *l_e_a, BMLoop *l_e_b, BMFace *f, const float aspect_v2[2], const int cd_loop_uv_offset) +{ + float l_e_a_cent[2], l_e_b_cent[2], f_cent[2]; + MLoopUV *luv_e_a = BM_ELEM_CD_GET_VOID_P(l_e_a, cd_loop_uv_offset); + MLoopUV *luv_e_b = BM_ELEM_CD_GET_VOID_P(l_e_b, cd_loop_uv_offset); + + mid_v2_v2v2(l_e_a_cent, luv_e_a->uv, luv_e_a->uv); + mid_v2_v2v2(l_e_b_cent, luv_e_b->uv, luv_e_b->uv); + + mul_v2_v2(l_e_a_cent, aspect_v2); + mul_v2_v2(l_e_b_cent, aspect_v2); + + BM_face_uv_calc_center_median_weighted(f, aspect_v2, cd_loop_uv_offset, f_cent); + + return step_cost_3_v2(l_e_a_cent, l_e_b_cent, f_cent); +} + +static void edgetag_add_adjacent_uv(HeapSimple *heap, + BMLoop *l_a, + BMLoop **loops_prev, + float *cost, + const struct BMCalcPathUVParams *params) +{ + BLI_assert(params->aspect_y != 0.0f); + const uint cd_loop_uv_offset = params->cd_loop_uv_offset; + BMLoop *l_a_verts[2] = {l_a, l_a->next}; + const int l_a_index = BM_elem_index_get(l_a); + + if (params->use_step_face == false) { + for (int i = 0; i < ARRAY_SIZE(l_a_verts); i++) { + + /* Skip current UV vert if it is part of the previous UV edge in the path. */ + if (loops_prev[l_a_index]) { + BMLoop *l_prev = loops_prev[l_a_index]; + if (l_a_verts[i]->v != l_prev->v) { + l_prev = (l_a_verts[i]->v == l_prev->next->v) ? l_prev->next : NULL; + } + if (l_prev && BM_loop_uv_share_vert_check(l_a_verts[i], l_prev, cd_loop_uv_offset)) { + continue; + } + } + + BMEdge *e_b; + BMIter eiter; + BM_ITER_ELEM (e_b, &eiter, l_a_verts[i]->v, BM_EDGES_OF_VERT) { + BMLoop *l_first, *l_b; + l_first = l_b = e_b->l; + do { + if (!BM_elem_flag_test(l_b, BM_ELEM_TAG)) { + BMLoop *l_b_vert = (l_a_verts[i]->v == l_b->v) ? l_b : l_b->next; + if (BM_loop_uv_share_vert_check(l_a_verts[i], l_b_vert, cd_loop_uv_offset)) { + /* We know 'l_b' is not visited, check it out! */ + const int l_b_index = BM_elem_index_get(l_b); + const float cost_cut = params->use_topology_distance ? + 1.0f : + edgetag_cut_cost_vert_uv(l_a, + l_b, + l_a_verts[i], + params->aspect_y, + cd_loop_uv_offset); + const float cost_new = cost[l_a_index] + cost_cut; + + if (cost[l_b_index] > cost_new) { + cost[l_b_index] = cost_new; + loops_prev[l_b_index] = l_a; + BLI_heapsimple_insert(heap, cost_new, l_b); + } + } + } + } while ((l_b = l_b->radial_next) != l_first); + } + } + } + else { + const float aspect_v2[2] = {1.0f, 1.0f / params->aspect_y}; + BMLoop *l_first, *l_iter; + l_iter = l_first = l_a; + do { + /* Ensures connected UVs and that they lie on the same island. */ + if (!BM_loop_uv_share_edge_check(l_a, l_iter, cd_loop_uv_offset)) { + continue; + } + + BMLoop *l_cycle_iter, *l_cycle_end; + l_cycle_iter = l_iter->next; + l_cycle_end = l_iter; + do { + BMLoop *l_b = l_cycle_iter; + if (!BM_elem_flag_test(l_b, BM_ELEM_TAG)) { + /* We know 'l_b' is not visited, check it out! */ + const int l_b_index = BM_elem_index_get(l_b); + const float cost_cut = params->use_topology_distance ? + 1.0f : + edgetag_cut_cost_face_uv(l_a, + l_b, + l_iter->f, + aspect_v2, + params->cd_loop_uv_offset); + const float cost_new = cost[l_a_index] + cost_cut; + + if (cost[l_b_index] > cost_new) { + cost[l_b_index] = cost_new; + loops_prev[l_b_index] = l_a; + BLI_heapsimple_insert(heap, cost_new, l_b); + } + } + } while ((l_cycle_iter = l_cycle_iter->next) != l_cycle_end); + } while ((l_iter = l_iter->radial_next) != l_first); + } +} + +struct LinkNode *BM_mesh_calc_path_uv_edge(BMesh *bm, + BMLoop *l_src, + BMLoop *l_dst, + const struct BMCalcPathUVParams *params, + bool (*filter_fn)(BMLoop *, void *), + void *user_data) +{ + LinkNode *path = NULL; + + BMFace *f; + BMIter iter; + HeapSimple *heap; + float *cost; + BMLoop **loops_prev; + int i = 0, totloop; + + BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { + BMLoop *l_first = BM_FACE_FIRST_LOOP(f); + BMLoop *l_iter = l_first; + do { + BM_elem_flag_set(l_iter, BM_ELEM_TAG, !filter_fn(l_iter, user_data)); + BM_elem_index_set(l_iter, i); + i += 1; + } while ((l_iter = l_iter->next) != l_first); + } + bm->elem_index_dirty &= ~BM_LOOP; + + totloop = bm->totloop; + loops_prev = MEM_callocN(sizeof(*loops_prev) * totloop, __func__); + cost = MEM_mallocN(sizeof(*cost) * totloop, __func__); + + copy_vn_fl(cost, totloop, COST_INIT_MAX); + + /* Regular dijkstra shortest path, but over UV loops/edges instead of vertices. */ + heap = BLI_heapsimple_new(); + BLI_heapsimple_insert(heap, 0.0f, l_src); + cost[BM_elem_index_get(l_src)] = 0.0f; + + BMLoop *l = NULL; + while (!BLI_heapsimple_is_empty(heap)) { + l = BLI_heapsimple_pop_min(heap); + + if ((l->e == l_dst->e) && (BM_loop_uv_share_edge_check(l, l_dst, params->cd_loop_uv_offset))) { + break; + } + + if (!BM_elem_flag_test(l, BM_ELEM_TAG)) { + BM_elem_flag_enable(l, BM_ELEM_TAG); + edgetag_add_adjacent_uv(heap, l, loops_prev, cost, params); + } + } + + if ((l->e == l_dst->e) && (BM_loop_uv_share_edge_check(l, l_dst, params->cd_loop_uv_offset))) { + do { + BLI_linklist_prepend(&path, l); + } while ((l = loops_prev[BM_elem_index_get(l)])); + } + + MEM_freeN(loops_prev); + MEM_freeN(cost); + BLI_heapsimple_free(heap, NULL); + + return path; +} /** \} */ diff --git a/source/blender/bmesh/tools/bmesh_path_uv.h b/source/blender/bmesh/tools/bmesh_path_uv.h index af7341e2219..d7b5faa70e5 100644 --- a/source/blender/bmesh/tools/bmesh_path_uv.h +++ b/source/blender/bmesh/tools/bmesh_path_uv.h @@ -21,6 +21,14 @@ struct LinkNode *BM_mesh_calc_path_uv_vert(BMesh *bm, void *user_data) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2, 3, 5); +struct LinkNode *BM_mesh_calc_path_uv_edge(BMesh *bm, + BMLoop *l_src, + BMLoop *l_dst, + const struct BMCalcPathUVParams *params, + bool (*filter_fn)(BMLoop *, void *), + void *user_data) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(1, 2, 3, 5); + struct LinkNode *BM_mesh_calc_path_uv_face(BMesh *bm, BMFace *f_src, BMFace *f_dst, |