diff options
author | Hans Goudey <h.goudey@me.com> | 2022-08-14 04:50:06 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-08-14 04:50:06 +0300 |
commit | 6d041a7d510b43a128b3be393a69c2b45ae4885c (patch) | |
tree | 5bcf7e158da5c2d912e0a0e62909664752cdaa3a /source/blender/bmesh/intern | |
parent | 0018db40a6923d78d879e0ac2f1793c13e9b5737 (diff) | |
parent | b5e92c3dfe70f94556719594c6c1b457cda59768 (diff) |
Merge branch 'master' into refactor-mesh-bevel-weight-generic
Diffstat (limited to 'source/blender/bmesh/intern')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_construct.c | 36 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh.cc | 145 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh.h | 2 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh_convert.cc | 139 |
4 files changed, 230 insertions, 92 deletions
diff --git a/source/blender/bmesh/intern/bmesh_construct.c b/source/blender/bmesh/intern/bmesh_construct.c index a7637d2712c..0ee5545527b 100644 --- a/source/blender/bmesh/intern/bmesh_construct.c +++ b/source/blender/bmesh/intern/bmesh_construct.c @@ -512,16 +512,24 @@ void BM_mesh_copy_init_customdata_from_mesh_array(BMesh *bm_dst, for (int i = 0; i < me_src_array_len; i++) { const Mesh *me_src = me_src_array[i]; if (i == 0) { - CustomData_copy(&me_src->vdata, &bm_dst->vdata, CD_MASK_BMESH.vmask, CD_CALLOC, 0); - CustomData_copy(&me_src->edata, &bm_dst->edata, CD_MASK_BMESH.emask, CD_CALLOC, 0); - CustomData_copy(&me_src->ldata, &bm_dst->ldata, CD_MASK_BMESH.lmask, CD_CALLOC, 0); - CustomData_copy(&me_src->pdata, &bm_dst->pdata, CD_MASK_BMESH.pmask, CD_CALLOC, 0); + CustomData_copy_mesh_to_bmesh( + &me_src->vdata, &bm_dst->vdata, CD_MASK_BMESH.vmask, CD_CALLOC, 0); + CustomData_copy_mesh_to_bmesh( + &me_src->edata, &bm_dst->edata, CD_MASK_BMESH.emask, CD_CALLOC, 0); + CustomData_copy_mesh_to_bmesh( + &me_src->ldata, &bm_dst->ldata, CD_MASK_BMESH.lmask, CD_CALLOC, 0); + CustomData_copy_mesh_to_bmesh( + &me_src->pdata, &bm_dst->pdata, CD_MASK_BMESH.pmask, CD_CALLOC, 0); } else { - CustomData_merge(&me_src->vdata, &bm_dst->vdata, CD_MASK_BMESH.vmask, CD_CALLOC, 0); - CustomData_merge(&me_src->edata, &bm_dst->edata, CD_MASK_BMESH.emask, CD_CALLOC, 0); - CustomData_merge(&me_src->ldata, &bm_dst->ldata, CD_MASK_BMESH.lmask, CD_CALLOC, 0); - CustomData_merge(&me_src->pdata, &bm_dst->pdata, CD_MASK_BMESH.pmask, CD_CALLOC, 0); + CustomData_merge_mesh_to_bmesh( + &me_src->vdata, &bm_dst->vdata, CD_MASK_BMESH.vmask, CD_CALLOC, 0); + CustomData_merge_mesh_to_bmesh( + &me_src->edata, &bm_dst->edata, CD_MASK_BMESH.emask, CD_CALLOC, 0); + CustomData_merge_mesh_to_bmesh( + &me_src->ldata, &bm_dst->ldata, CD_MASK_BMESH.lmask, CD_CALLOC, 0); + CustomData_merge_mesh_to_bmesh( + &me_src->pdata, &bm_dst->pdata, CD_MASK_BMESH.pmask, CD_CALLOC, 0); } cd_flag |= me_src->cd_flag; @@ -714,26 +722,25 @@ BMesh *BM_mesh_copy(BMesh *bm_old) char BM_vert_flag_from_mflag(const char mflag) { - return (((mflag & SELECT) ? BM_ELEM_SELECT : 0) | ((mflag & ME_HIDE) ? BM_ELEM_HIDDEN : 0)); + return ((mflag & SELECT) ? BM_ELEM_SELECT : 0); } char BM_edge_flag_from_mflag(const short mflag) { return (((mflag & SELECT) ? BM_ELEM_SELECT : 0) | ((mflag & ME_SEAM) ? BM_ELEM_SEAM : 0) | ((mflag & ME_EDGEDRAW) ? BM_ELEM_DRAW : 0) | - ((mflag & ME_SHARP) == 0 ? BM_ELEM_SMOOTH : 0) | /* invert */ - ((mflag & ME_HIDE) ? BM_ELEM_HIDDEN : 0)); + ((mflag & ME_SHARP) == 0 ? BM_ELEM_SMOOTH : 0)); } char BM_face_flag_from_mflag(const char mflag) { return (((mflag & ME_FACE_SEL) ? BM_ELEM_SELECT : 0) | - ((mflag & ME_SMOOTH) ? BM_ELEM_SMOOTH : 0) | ((mflag & ME_HIDE) ? BM_ELEM_HIDDEN : 0)); + ((mflag & ME_SMOOTH) ? BM_ELEM_SMOOTH : 0)); } char BM_vert_flag_to_mflag(BMVert *v) { const char hflag = v->head.hflag; - return (((hflag & BM_ELEM_SELECT) ? SELECT : 0) | ((hflag & BM_ELEM_HIDDEN) ? ME_HIDE : 0)); + return (((hflag & BM_ELEM_SELECT) ? SELECT : 0)); } short BM_edge_flag_to_mflag(BMEdge *e) @@ -743,7 +750,6 @@ short BM_edge_flag_to_mflag(BMEdge *e) return (((hflag & BM_ELEM_SELECT) ? SELECT : 0) | ((hflag & BM_ELEM_SEAM) ? ME_SEAM : 0) | ((hflag & BM_ELEM_DRAW) ? ME_EDGEDRAW : 0) | ((hflag & BM_ELEM_SMOOTH) == 0 ? ME_SHARP : 0) | - ((hflag & BM_ELEM_HIDDEN) ? ME_HIDE : 0) | (BM_edge_is_wire(e) ? ME_LOOSEEDGE : 0) | /* not typical */ ME_EDGERENDER); } @@ -752,5 +758,5 @@ char BM_face_flag_to_mflag(BMFace *f) const char hflag = f->head.hflag; return (((hflag & BM_ELEM_SELECT) ? ME_FACE_SEL : 0) | - ((hflag & BM_ELEM_SMOOTH) ? ME_SMOOTH : 0) | ((hflag & BM_ELEM_HIDDEN) ? ME_HIDE : 0)); + ((hflag & BM_ELEM_SMOOTH) ? ME_SMOOTH : 0)); } diff --git a/source/blender/bmesh/intern/bmesh_mesh.cc b/source/blender/bmesh/intern/bmesh_mesh.cc index c16d874e3ec..4f42ce4a470 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.cc +++ 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 = (BMFlagLayer *)BLI_mempool_calloc(toolflagpool); + v_olfag->oflags = static_cast<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 = (BMFlagLayer *)BLI_mempool_calloc(toolflagpool); + e_olfag->oflags = static_cast<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 = (BMFlagLayer *)BLI_mempool_calloc(toolflagpool); + f_olfag->oflags = static_cast<BMFlagLayer *>(BLI_mempool_calloc(toolflagpool)); } bm->totflags = 1; @@ -125,7 +125,7 @@ void BM_mesh_elem_toolflags_clear(BMesh *bm) BMesh *BM_mesh_create(const BMAllocTemplate *allocsize, const struct BMeshCreateParams *params) { /* allocate the structure */ - BMesh *bm = (BMesh *)MEM_callocN(sizeof(BMesh), __func__); + BMesh *bm = static_cast<BMesh *>(MEM_callocN(sizeof(BMesh), __func__)); /* allocate the memory pools for the mesh elements */ bm_mempool_init(bm, allocsize, params->use_toolflags); @@ -262,7 +262,7 @@ 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((BPy_BMGeneric *)bm->py_handle); + bpy_bm_generic_invalidate(static_cast<BPy_BMGeneric *>(bm->py_handle)); bm->py_handle = nullptr; } @@ -581,7 +581,8 @@ void BM_mesh_elem_table_ensure(BMesh *bm, const char htype) if (bm->vtable) { MEM_freeN(bm->vtable); } - bm->vtable = (BMVert **)MEM_mallocN(sizeof(void **) * bm->totvert, "bm->vtable"); + bm->vtable = static_cast<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); @@ -594,7 +595,8 @@ void BM_mesh_elem_table_ensure(BMesh *bm, const char htype) if (bm->etable) { MEM_freeN(bm->etable); } - bm->etable = (BMEdge **)MEM_mallocN(sizeof(void **) * bm->totedge, "bm->etable"); + bm->etable = static_cast<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); @@ -607,7 +609,8 @@ void BM_mesh_elem_table_ensure(BMesh *bm, const char htype) if (bm->ftable) { MEM_freeN(bm->ftable); } - bm->ftable = (BMFace **)MEM_mallocN(sizeof(void **) * bm->totface, "bm->ftable"); + bm->ftable = static_cast<BMFace **>( + MEM_mallocN(sizeof(void **) * bm->totface, "bm->ftable")); bm->ftable_tot = bm->totface; } BM_iter_as_array(bm, BM_FACES_OF_MESH, nullptr, (void **)bm->ftable, bm->totface); @@ -647,17 +650,17 @@ void BM_mesh_elem_table_free(BMesh *bm, const char htype) BMVert *BM_vert_at_index_find(BMesh *bm, const int index) { - return (BMVert *)BLI_mempool_findelem(bm->vpool, index); + return static_cast<BMVert *>(BLI_mempool_findelem(bm->vpool, index)); } BMEdge *BM_edge_at_index_find(BMesh *bm, const int index) { - return (BMEdge *)BLI_mempool_findelem(bm->epool, index); + return static_cast<BMEdge *>(BLI_mempool_findelem(bm->epool, index)); } BMFace *BM_face_at_index_find(BMesh *bm, const int index) { - return (BMFace *)BLI_mempool_findelem(bm->fpool, index); + return static_cast<BMFace *>(BLI_mempool_findelem(bm->fpool, index)); } BMLoop *BM_loop_at_index_find(BMesh *bm, const int index) @@ -754,16 +757,17 @@ 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 = (BMVert *)MEM_mallocN(sizeof(BMVert) * totvert, "BM_mesh_remap verts copy"); + verts_copy = static_cast<BMVert *>( + MEM_mallocN(sizeof(BMVert) * totvert, "BM_mesh_remap verts copy")); void **pyptrs = (cd_vert_pyptr != -1) ? - (void **)MEM_mallocN(sizeof(void *) * totvert, __func__) : + static_cast<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 = (void **)BM_ELEM_CD_GET_VOID_P(((BMElem *)ve), cd_vert_pyptr); + void **pyptr = static_cast<void **>(BM_ELEM_CD_GET_VOID_P(((BMElem *)ve), cd_vert_pyptr)); pyptrs[i] = *pyptr; } } @@ -781,7 +785,8 @@ 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 = (void **)BM_ELEM_CD_GET_VOID_P(((BMElem *)new_vep), cd_vert_pyptr); + void **pyptr = static_cast<void **>( + BM_ELEM_CD_GET_VOID_P(((BMElem *)new_vep), cd_vert_pyptr)); *pyptr = pyptrs[*new_idx]; } } @@ -808,15 +813,16 @@ 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 = (BMEdge *)MEM_mallocN(sizeof(BMEdge) * totedge, "BM_mesh_remap edges copy"); + edges_copy = static_cast<BMEdge *>( + MEM_mallocN(sizeof(BMEdge) * totedge, "BM_mesh_remap edges copy")); void **pyptrs = (cd_edge_pyptr != -1) ? - (void **)MEM_mallocN(sizeof(void *) * totedge, __func__) : + static_cast<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 = (void **)BM_ELEM_CD_GET_VOID_P(((BMElem *)ed), cd_edge_pyptr); + void **pyptr = static_cast<void **>(BM_ELEM_CD_GET_VOID_P(((BMElem *)ed), cd_edge_pyptr)); pyptrs[i] = *pyptr; } } @@ -834,7 +840,8 @@ 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 = (void **)BM_ELEM_CD_GET_VOID_P(((BMElem *)new_edp), cd_edge_pyptr); + void **pyptr = static_cast<void **>( + BM_ELEM_CD_GET_VOID_P(((BMElem *)new_edp), cd_edge_pyptr)); *pyptr = pyptrs[*new_idx]; } } @@ -861,15 +868,16 @@ 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 = (BMFace *)MEM_mallocN(sizeof(BMFace) * totface, "BM_mesh_remap faces copy"); + faces_copy = static_cast<BMFace *>( + MEM_mallocN(sizeof(BMFace) * totface, "BM_mesh_remap faces copy")); void **pyptrs = (cd_poly_pyptr != -1) ? - (void **)MEM_mallocN(sizeof(void *) * totface, __func__) : + static_cast<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 = (void **)BM_ELEM_CD_GET_VOID_P(((BMElem *)fa), cd_poly_pyptr); + void **pyptr = static_cast<void **>(BM_ELEM_CD_GET_VOID_P(((BMElem *)fa), cd_poly_pyptr)); pyptrs[i] = *pyptr; } } @@ -883,7 +891,8 @@ 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 = (void **)BM_ELEM_CD_GET_VOID_P(((BMElem *)new_fap), cd_poly_pyptr); + void **pyptr = static_cast<void **>( + BM_ELEM_CD_GET_VOID_P(((BMElem *)new_fap), cd_poly_pyptr)); *pyptr = pyptrs[*new_idx]; } } @@ -903,7 +912,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 = (BMEdge *)BLI_ghash_lookup(eptr_map, ve->e); + ve->e = static_cast<BMEdge *>(BLI_ghash_lookup(eptr_map, ve->e)); BLI_assert(ve->e); } } @@ -919,8 +928,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 = (BMVert *)BLI_ghash_lookup(vptr_map, ed->v1); - ed->v2 = (BMVert *)BLI_ghash_lookup(vptr_map, ed->v2); + ed->v1 = static_cast<BMVert *>(BLI_ghash_lookup(vptr_map, ed->v1)); + ed->v2 = static_cast<BMVert *>(BLI_ghash_lookup(vptr_map, ed->v2)); BLI_assert(ed->v1); BLI_assert(ed->v2); } @@ -939,10 +948,14 @@ 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 = (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); + ed->v1_disk_link.prev = static_cast<BMEdge *>( + BLI_ghash_lookup(eptr_map, ed->v1_disk_link.prev)); + ed->v1_disk_link.next = static_cast<BMEdge *>( + BLI_ghash_lookup(eptr_map, ed->v1_disk_link.next)); + ed->v2_disk_link.prev = static_cast<BMEdge *>( + BLI_ghash_lookup(eptr_map, ed->v2_disk_link.prev)); + ed->v2_disk_link.next = static_cast<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); @@ -956,17 +969,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 = (BMVert *)BLI_ghash_lookup(vptr_map, lo->v); + lo->v = static_cast<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 = (BMEdge *)BLI_ghash_lookup(eptr_map, lo->e); + lo->e = static_cast<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 = (BMFace *)BLI_ghash_lookup(fptr_map, lo->f); + lo->f = static_cast<BMFace *>(BLI_ghash_lookup(fptr_map, lo->f)); BLI_assert(lo->f); } } @@ -975,23 +988,23 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const /* Selection history */ { BMEditSelection *ese; - for (ese = (BMEditSelection *)bm->selected.first; ese; ese = ese->next) { + for (ese = static_cast<BMEditSelection *>(bm->selected.first); ese; ese = ese->next) { switch (ese->htype) { case BM_VERT: if (vptr_map) { - ese->ele = (BMElem *)BLI_ghash_lookup(vptr_map, ese->ele); + ese->ele = static_cast<BMElem *>(BLI_ghash_lookup(vptr_map, ese->ele)); BLI_assert(ese->ele); } break; case BM_EDGE: if (eptr_map) { - ese->ele = (BMElem *)BLI_ghash_lookup(eptr_map, ese->ele); + ese->ele = static_cast<BMElem *>(BLI_ghash_lookup(eptr_map, ese->ele)); BLI_assert(ese->ele); } break; case BM_FACE: if (fptr_map) { - ese->ele = (BMElem *)BLI_ghash_lookup(fptr_map, ese->ele); + ese->ele = static_cast<BMElem *>(BLI_ghash_lookup(fptr_map, ese->ele)); BLI_assert(ese->ele); } break; @@ -1001,7 +1014,7 @@ 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 = (BMFace *)BLI_ghash_lookup(fptr_map, bm->act_face); + bm->act_face = static_cast<BMFace *>(BLI_ghash_lookup(fptr_map, bm->act_face)); BLI_assert(bm->act_face); } } @@ -1027,18 +1040,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) ? - (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; + BMVert **vtable_dst = (remap & BM_VERT) ? static_cast<BMVert **>(MEM_mallocN( + sizeof(BMVert *) * bm->totvert, __func__)) : + nullptr; + BMEdge **etable_dst = (remap & BM_EDGE) ? static_cast<BMEdge **>(MEM_mallocN( + sizeof(BMEdge *) * bm->totedge, __func__)) : + nullptr; + BMLoop **ltable_dst = (remap & BM_LOOP) ? static_cast<BMLoop **>(MEM_mallocN( + sizeof(BMLoop *) * bm->totloop, __func__)) : + nullptr; + BMFace **ftable_dst = (remap & BM_FACE) ? static_cast<BMFace **>(MEM_mallocN( + sizeof(BMFace *) * bm->totface, __func__)) : + nullptr; const bool use_toolflags = params->use_toolflags; @@ -1047,12 +1060,13 @@ 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 = (BMVert *)BLI_mempool_alloc(vpool_dst); + BMVert *v_dst = static_cast<BMVert *>(BLI_mempool_alloc(vpool_dst)); memcpy(v_dst, v_src, sizeof(BMVert)); if (use_toolflags) { - ((BMVert_OFlag *)v_dst)->oflags = bm->vtoolflagpool ? (BMFlagLayer *)BLI_mempool_calloc( - bm->vtoolflagpool) : - nullptr; + ((BMVert_OFlag *)v_dst)->oflags = bm->vtoolflagpool ? + static_cast<BMFlagLayer *>( + BLI_mempool_calloc(bm->vtoolflagpool)) : + nullptr; } vtable_dst[index] = v_dst; @@ -1065,12 +1079,13 @@ 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 = (BMEdge *)BLI_mempool_alloc(epool_dst); + BMEdge *e_dst = static_cast<BMEdge *>(BLI_mempool_alloc(epool_dst)); memcpy(e_dst, e_src, sizeof(BMEdge)); if (use_toolflags) { - ((BMEdge_OFlag *)e_dst)->oflags = bm->etoolflagpool ? (BMFlagLayer *)BLI_mempool_calloc( - bm->etoolflagpool) : - nullptr; + ((BMEdge_OFlag *)e_dst)->oflags = bm->etoolflagpool ? + static_cast<BMFlagLayer *>( + BLI_mempool_calloc(bm->etoolflagpool)) : + nullptr; } etable_dst[index] = e_dst; @@ -1085,12 +1100,13 @@ 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 = (BMFace *)BLI_mempool_alloc(fpool_dst); + BMFace *f_dst = static_cast<BMFace *>(BLI_mempool_alloc(fpool_dst)); memcpy(f_dst, f_src, sizeof(BMFace)); if (use_toolflags) { - ((BMFace_OFlag *)f_dst)->oflags = bm->ftoolflagpool ? (BMFlagLayer *)BLI_mempool_calloc( - bm->ftoolflagpool) : - nullptr; + ((BMFace_OFlag *)f_dst)->oflags = bm->ftoolflagpool ? + static_cast<BMFlagLayer *>( + BLI_mempool_calloc(bm->ftoolflagpool)) : + nullptr; } ftable_dst[index] = f_dst; @@ -1102,7 +1118,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 = (BMLoop *)BLI_mempool_alloc(lpool_dst); + BMLoop *l_dst = static_cast<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 */ @@ -1319,7 +1335,8 @@ 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] = (float(*)[3])MEM_mallocN(bm->totvert * sizeof(*vert_coords), __func__); + float(*vert_coords)[3] = static_cast<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.h b/source/blender/bmesh/intern/bmesh_mesh.h index a5994b52bc2..d766a26cf6e 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.h +++ b/source/blender/bmesh/intern/bmesh_mesh.h @@ -17,7 +17,7 @@ void BM_mesh_elem_toolflags_ensure(BMesh *bm); void BM_mesh_elem_toolflags_clear(BMesh *bm); struct BMeshCreateParams { - bool use_toolflags : true; + bool use_toolflags : 1; }; /** diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.cc b/source/blender/bmesh/intern/bmesh_mesh_convert.cc index 739e474c59a..eadf87d7ebd 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc +++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc @@ -83,7 +83,10 @@ #include "BLI_listbase.h" #include "BLI_math_vector.h" #include "BLI_span.hh" +#include "BLI_string_ref.hh" +#include "BLI_task.hh" +#include "BKE_attribute.hh" #include "BKE_customdata.h" #include "BKE_mesh.h" #include "BKE_mesh_runtime.h" @@ -103,7 +106,9 @@ static CLG_LogRef LOG = {"bmesh.mesh.convert"}; using blender::Array; using blender::IndexRange; +using blender::MutableSpan; using blender::Span; +using blender::StringRef; void BM_mesh_cd_flag_ensure(BMesh *bm, Mesh *mesh, const char cd_flag) { @@ -184,10 +189,10 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar if (!me || !me->totvert) { if (me && is_new) { /* No verts? still copy custom-data layout. */ - CustomData_copy(&me->vdata, &bm->vdata, mask.vmask, CD_DEFAULT, 0); - CustomData_copy(&me->edata, &bm->edata, mask.emask, CD_DEFAULT, 0); - CustomData_copy(&me->ldata, &bm->ldata, mask.lmask, CD_DEFAULT, 0); - CustomData_copy(&me->pdata, &bm->pdata, mask.pmask, CD_DEFAULT, 0); + CustomData_copy_mesh_to_bmesh(&me->vdata, &bm->vdata, mask.vmask, CD_DEFAULT, 0); + CustomData_copy_mesh_to_bmesh(&me->edata, &bm->edata, mask.emask, CD_DEFAULT, 0); + CustomData_copy_mesh_to_bmesh(&me->ldata, &bm->ldata, mask.lmask, CD_DEFAULT, 0); + CustomData_copy_mesh_to_bmesh(&me->pdata, &bm->pdata, mask.pmask, CD_DEFAULT, 0); CustomData_bmesh_init_pool(&bm->vdata, me->totvert, BM_VERT); CustomData_bmesh_init_pool(&bm->edata, me->totedge, BM_EDGE); @@ -203,10 +208,10 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar } if (is_new) { - CustomData_copy(&me->vdata, &bm->vdata, mask.vmask, CD_CALLOC, 0); - CustomData_copy(&me->edata, &bm->edata, mask.emask, CD_CALLOC, 0); - CustomData_copy(&me->ldata, &bm->ldata, mask.lmask, CD_CALLOC, 0); - CustomData_copy(&me->pdata, &bm->pdata, mask.pmask, CD_CALLOC, 0); + CustomData_copy_mesh_to_bmesh(&me->vdata, &bm->vdata, mask.vmask, CD_CALLOC, 0); + CustomData_copy_mesh_to_bmesh(&me->edata, &bm->edata, mask.emask, CD_CALLOC, 0); + CustomData_copy_mesh_to_bmesh(&me->ldata, &bm->ldata, mask.lmask, CD_CALLOC, 0); + CustomData_copy_mesh_to_bmesh(&me->pdata, &bm->pdata, mask.pmask, CD_CALLOC, 0); } else { CustomData_bmesh_merge(&me->vdata, &bm->vdata, mask.vmask, CD_CALLOC, bm, BM_VERT); @@ -318,6 +323,13 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar CustomData_get_offset(&bm->vdata, CD_SHAPE_KEYINDEX) : -1; + const bool *hide_vert = (const bool *)CustomData_get_layer_named( + &me->vdata, CD_PROP_BOOL, ".hide_vert"); + const bool *hide_edge = (const bool *)CustomData_get_layer_named( + &me->edata, CD_PROP_BOOL, ".hide_edge"); + const bool *hide_poly = (const bool *)CustomData_get_layer_named( + &me->pdata, CD_PROP_BOOL, ".hide_poly"); + Span<MVert> mvert{me->mvert, me->totvert}; Array<BMVert *> vtable(me->totvert); for (const int i : mvert.index_range()) { @@ -327,6 +339,9 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar /* Transfer flag. */ v->head.hflag = BM_vert_flag_from_mflag(mvert[i].flag & ~SELECT); + if (hide_vert && hide_vert[i]) { + BM_elem_flag_enable(v, BM_ELEM_HIDDEN); + } /* This is necessary for selection counts to work properly. */ if (mvert[i].flag & SELECT) { @@ -366,6 +381,9 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar /* Transfer flags. */ e->head.hflag = BM_edge_flag_from_mflag(medge[i].flag & ~SELECT); + if (hide_edge && hide_edge[i]) { + BM_elem_flag_enable(e, BM_ELEM_HIDDEN); + } /* This is necessary for selection counts to work properly. */ if (medge[i].flag & SELECT) { @@ -416,6 +434,9 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar /* Transfer flag. */ f->head.hflag = BM_face_flag_from_mflag(mpoly[i].flag & ~ME_FACE_SEL); + if (hide_poly && hide_poly[i]) { + BM_elem_flag_enable(f, BM_ELEM_HIDDEN); + } /* This is necessary for selection counts to work properly. */ if (mpoly[i].flag & ME_FACE_SEL) { @@ -861,6 +882,63 @@ BLI_INLINE void bmesh_quick_edgedraw_flag(MEdge *med, BMEdge *e) } } +template<typename GetFn> +static void write_elem_flag_to_attribute(blender::bke::MutableAttributeAccessor &attributes, + const StringRef attribute_name, + const eAttrDomain domain, + const bool do_write, + const GetFn &get_fn) +{ + using namespace blender; + if (do_write) { + bke::SpanAttributeWriter<bool> attribute = attributes.lookup_or_add_for_write_only_span<bool>( + attribute_name, domain); + threading::parallel_for(attribute.span.index_range(), 4096, [&](IndexRange range) { + for (const int i : range) { + attribute.span[i] = get_fn(i); + } + }); + attribute.finish(); + } + else { + /* To avoid overhead, remove the hide attribute if possible. */ + attributes.remove(attribute_name); + } +} + +static void convert_bmesh_hide_flags_to_mesh_attributes(BMesh &bm, + const bool need_hide_vert, + const bool need_hide_edge, + const bool need_hide_poly, + Mesh &mesh) +{ + using namespace blender; + /* The "hide" attributes are stored as flags on #BMesh. */ + BLI_assert(CustomData_get_layer_named(&bm.vdata, CD_PROP_BOOL, ".hide_vert") == nullptr); + BLI_assert(CustomData_get_layer_named(&bm.edata, CD_PROP_BOOL, ".hide_edge") == nullptr); + BLI_assert(CustomData_get_layer_named(&bm.pdata, CD_PROP_BOOL, ".hide_poly") == nullptr); + + if (!(need_hide_vert || need_hide_edge || need_hide_poly)) { + return; + } + + bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh); + BM_mesh_elem_table_ensure(&bm, BM_VERT | BM_EDGE | BM_FACE); + + write_elem_flag_to_attribute( + attributes, ".hide_vert", ATTR_DOMAIN_POINT, need_hide_vert, [&](const int i) { + return BM_elem_flag_test(BM_vert_at_index(&bm, i), BM_ELEM_HIDDEN); + }); + write_elem_flag_to_attribute( + attributes, ".hide_edge", ATTR_DOMAIN_EDGE, need_hide_edge, [&](const int i) { + return BM_elem_flag_test(BM_edge_at_index(&bm, i), BM_ELEM_HIDDEN); + }); + write_elem_flag_to_attribute( + attributes, ".hide_poly", ATTR_DOMAIN_FACE, need_hide_poly, [&](const int i) { + return BM_elem_flag_test(BM_face_at_index(&bm, i), BM_ELEM_HIDDEN); + }); +} + void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMeshParams *params) { MEdge *med; @@ -895,10 +973,10 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh { CustomData_MeshMasks mask = CD_MASK_MESH; CustomData_MeshMasks_update(&mask, ¶ms->cd_mask_extra); - CustomData_copy(&bm->vdata, &me->vdata, mask.vmask, CD_CALLOC, me->totvert); - CustomData_copy(&bm->edata, &me->edata, mask.emask, CD_CALLOC, me->totedge); - CustomData_copy(&bm->ldata, &me->ldata, mask.lmask, CD_CALLOC, me->totloop); - CustomData_copy(&bm->pdata, &me->pdata, mask.pmask, CD_CALLOC, me->totpoly); + CustomData_copy_mesh_to_bmesh(&bm->vdata, &me->vdata, mask.vmask, CD_CALLOC, me->totvert); + CustomData_copy_mesh_to_bmesh(&bm->edata, &me->edata, mask.emask, CD_CALLOC, me->totedge); + CustomData_copy_mesh_to_bmesh(&bm->ldata, &me->ldata, mask.lmask, CD_CALLOC, me->totloop); + CustomData_copy_mesh_to_bmesh(&bm->pdata, &me->pdata, mask.pmask, CD_CALLOC, me->totpoly); } MVert *mvert = bm->totvert ? (MVert *)MEM_callocN(sizeof(MVert) * bm->totvert, "bm_to_me.vert") : @@ -915,6 +993,10 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh CustomData_add_layer(&me->ldata, CD_MLOOP, CD_ASSIGN, mloop, me->totloop); CustomData_add_layer(&me->pdata, CD_MPOLY, CD_ASSIGN, mpoly, me->totpoly); + bool need_hide_vert = false; + bool need_hide_edge = false; + bool need_hide_poly = false; + /* Clear normals on the mesh completely, since the original vertex and polygon count might be * different than the BMesh's. */ BKE_mesh_clear_derived_normals(me); @@ -929,6 +1011,9 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh copy_v3_v3(mvert->co, v->co); mvert->flag = BM_vert_flag_to_mflag(v); + if (BM_elem_flag_test(v, BM_ELEM_HIDDEN)) { + need_hide_vert = true; + } BM_elem_index_set(v, i); /* set_inline */ @@ -949,6 +1034,9 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh med->v2 = BM_elem_index_get(e->v2); med->flag = BM_edge_flag_to_mflag(e); + if (BM_elem_flag_test(e, BM_ELEM_HIDDEN)) { + need_hide_edge = true; + } BM_elem_index_set(e, i); /* set_inline */ @@ -975,6 +1063,9 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh mpoly->totloop = f->len; mpoly->mat_nr = f->mat_nr; mpoly->flag = BM_face_flag_to_mflag(f); + if (BM_elem_flag_test(f, BM_ELEM_HIDDEN)) { + need_hide_poly = true; + } l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { @@ -1067,6 +1158,9 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh } } + convert_bmesh_hide_flags_to_mesh_attributes( + *bm, need_hide_vert, need_hide_edge, need_hide_poly, *me); + BKE_mesh_update_customdata_pointers(me, false); { @@ -1158,6 +1252,10 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks * const int cd_edge_crease_offset = CustomData_get_offset(&bm->edata, CD_CREASE); + bool need_hide_vert = false; + bool need_hide_edge = false; + bool need_hide_poly = false; + /* Clear normals on the mesh completely, since the original vertex and polygon count might be * different than the BMesh's. */ BKE_mesh_clear_derived_normals(me); @@ -1172,6 +1270,13 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks * BM_elem_index_set(eve, i); /* set_inline */ mv->flag = BM_vert_flag_to_mflag(eve); + if (BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) { + need_hide_vert = true; + } + + if (cd_vert_bweight_offset != -1) { + mv->bweight = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eve, cd_vert_bweight_offset); + } CustomData_from_bmesh_block(&bm->vdata, &me->vdata, eve->head.data, i); } @@ -1186,6 +1291,9 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks * med->v2 = BM_elem_index_get(eed->v2); med->flag = BM_edge_flag_to_mflag(eed); + if (BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) { + need_hide_edge = true; + } /* Handle this differently to editmode switching, * only enable draw for single user edges rather than calculating angle. */ @@ -1213,6 +1321,10 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks * mp->totloop = efa->len; mp->flag = BM_face_flag_to_mflag(efa); + if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) { + need_hide_poly = true; + } + mp->loopstart = j; mp->mat_nr = efa->mat_nr; @@ -1232,5 +1344,8 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks * } bm->elem_index_dirty &= ~(BM_FACE | BM_LOOP); + convert_bmesh_hide_flags_to_mesh_attributes( + *bm, need_hide_vert, need_hide_edge, need_hide_poly, *me); + me->cd_flag = BM_mesh_cd_flag_from_bmesh(bm); } |