diff options
author | Michael Kowalski <makowalski@nvidia.com> | 2022-09-23 23:56:14 +0300 |
---|---|---|
committer | Michael Kowalski <makowalski@nvidia.com> | 2022-09-23 23:56:14 +0300 |
commit | b2ad97ba97f3e55d1dd463e29ca0b2ec6fe761e1 (patch) | |
tree | f94394835c6b731e4e379f4ef48fb78b4af4b9ca /source/blender/bmesh | |
parent | b31807c75f0c18c43ac6979e6da57dc9d420167a (diff) | |
parent | 7e980f2b8cb96aa6d04dc72899d08473367eeeb9 (diff) |
Merge branch 'master' into tmp-usd-alab-v2-T100452tmp-usd-alab-v2-T100452
Diffstat (limited to 'source/blender/bmesh')
29 files changed, 342 insertions, 400 deletions
diff --git a/source/blender/bmesh/CMakeLists.txt b/source/blender/bmesh/CMakeLists.txt index 0d1eeab8eec..0efa5f73ae4 100644 --- a/source/blender/bmesh/CMakeLists.txt +++ b/source/blender/bmesh/CMakeLists.txt @@ -111,7 +111,7 @@ set(SRC intern/bmesh_query.c intern/bmesh_query.h intern/bmesh_query_inline.h - intern/bmesh_query_uv.c + intern/bmesh_query_uv.cc intern/bmesh_query_uv.h intern/bmesh_structure.c intern/bmesh_structure.h diff --git a/source/blender/bmesh/bmesh.h b/source/blender/bmesh/bmesh.h index 2833105e5a4..3956db0288a 100644 --- a/source/blender/bmesh/bmesh.h +++ b/source/blender/bmesh/bmesh.h @@ -148,7 +148,7 @@ * * These conventions should be used throughout the bmesh module. * - * - `bmesh_kernel_*()` - Low level API, for primitive functions that others are built ontop of. + * - `bmesh_kernel_*()` - Low level API, for primitive functions that others are built on top of. * - `bmesh_***()` - Low level API function. * - `bm_***()` - 'static' functions, not a part of the API at all, * but use prefix since they operate on BMesh data. diff --git a/source/blender/bmesh/intern/bmesh_construct.c b/source/blender/bmesh/intern/bmesh_construct.c index 0ee5545527b..3ee9fa7aee4 100644 --- a/source/blender/bmesh/intern/bmesh_construct.c +++ b/source/blender/bmesh/intern/bmesh_construct.c @@ -21,8 +21,6 @@ #include "bmesh.h" #include "intern/bmesh_private.h" -#define SELECT 1 - bool BM_verts_from_edges(BMVert **vert_arr, BMEdge **edge_arr, const int len) { int i, i_prev = len - 1; @@ -507,42 +505,34 @@ void BM_mesh_copy_init_customdata_from_mesh_array(BMesh *bm_dst, allocsize = &bm_mesh_allocsize_default; } - char cd_flag = 0; - for (int i = 0; i < me_src_array_len; i++) { const Mesh *me_src = me_src_array[i]; if (i == 0) { CustomData_copy_mesh_to_bmesh( - &me_src->vdata, &bm_dst->vdata, CD_MASK_BMESH.vmask, CD_CALLOC, 0); + &me_src->vdata, &bm_dst->vdata, CD_MASK_BMESH.vmask, CD_SET_DEFAULT, 0); CustomData_copy_mesh_to_bmesh( - &me_src->edata, &bm_dst->edata, CD_MASK_BMESH.emask, CD_CALLOC, 0); + &me_src->edata, &bm_dst->edata, CD_MASK_BMESH.emask, CD_SET_DEFAULT, 0); CustomData_copy_mesh_to_bmesh( - &me_src->ldata, &bm_dst->ldata, CD_MASK_BMESH.lmask, CD_CALLOC, 0); + &me_src->ldata, &bm_dst->ldata, CD_MASK_BMESH.lmask, CD_SET_DEFAULT, 0); CustomData_copy_mesh_to_bmesh( - &me_src->pdata, &bm_dst->pdata, CD_MASK_BMESH.pmask, CD_CALLOC, 0); + &me_src->pdata, &bm_dst->pdata, CD_MASK_BMESH.pmask, CD_SET_DEFAULT, 0); } else { CustomData_merge_mesh_to_bmesh( - &me_src->vdata, &bm_dst->vdata, CD_MASK_BMESH.vmask, CD_CALLOC, 0); + &me_src->vdata, &bm_dst->vdata, CD_MASK_BMESH.vmask, CD_SET_DEFAULT, 0); CustomData_merge_mesh_to_bmesh( - &me_src->edata, &bm_dst->edata, CD_MASK_BMESH.emask, CD_CALLOC, 0); + &me_src->edata, &bm_dst->edata, CD_MASK_BMESH.emask, CD_SET_DEFAULT, 0); CustomData_merge_mesh_to_bmesh( - &me_src->ldata, &bm_dst->ldata, CD_MASK_BMESH.lmask, CD_CALLOC, 0); + &me_src->ldata, &bm_dst->ldata, CD_MASK_BMESH.lmask, CD_SET_DEFAULT, 0); CustomData_merge_mesh_to_bmesh( - &me_src->pdata, &bm_dst->pdata, CD_MASK_BMESH.pmask, CD_CALLOC, 0); + &me_src->pdata, &bm_dst->pdata, CD_MASK_BMESH.pmask, CD_SET_DEFAULT, 0); } - - cd_flag |= me_src->cd_flag; } - cd_flag |= BM_mesh_cd_flag_from_bmesh(bm_dst); - CustomData_bmesh_init_pool(&bm_dst->vdata, allocsize->totvert, BM_VERT); CustomData_bmesh_init_pool(&bm_dst->edata, allocsize->totedge, BM_EDGE); CustomData_bmesh_init_pool(&bm_dst->ldata, allocsize->totloop, BM_LOOP); CustomData_bmesh_init_pool(&bm_dst->pdata, allocsize->totface, BM_FACE); - - BM_mesh_cd_flag_apply(bm_dst, cd_flag); } void BM_mesh_copy_init_customdata_from_mesh(BMesh *bm_dst, @@ -558,10 +548,10 @@ void BM_mesh_copy_init_customdata(BMesh *bm_dst, BMesh *bm_src, const BMAllocTem allocsize = &bm_mesh_allocsize_default; } - CustomData_copy(&bm_src->vdata, &bm_dst->vdata, CD_MASK_BMESH.vmask, CD_CALLOC, 0); - CustomData_copy(&bm_src->edata, &bm_dst->edata, CD_MASK_BMESH.emask, CD_CALLOC, 0); - CustomData_copy(&bm_src->ldata, &bm_dst->ldata, CD_MASK_BMESH.lmask, CD_CALLOC, 0); - CustomData_copy(&bm_src->pdata, &bm_dst->pdata, CD_MASK_BMESH.pmask, CD_CALLOC, 0); + CustomData_copy(&bm_src->vdata, &bm_dst->vdata, CD_MASK_BMESH.vmask, CD_SET_DEFAULT, 0); + CustomData_copy(&bm_src->edata, &bm_dst->edata, CD_MASK_BMESH.emask, CD_SET_DEFAULT, 0); + CustomData_copy(&bm_src->ldata, &bm_dst->ldata, CD_MASK_BMESH.lmask, CD_SET_DEFAULT, 0); + CustomData_copy(&bm_src->pdata, &bm_dst->pdata, CD_MASK_BMESH.pmask, CD_SET_DEFAULT, 0); CustomData_bmesh_init_pool(&bm_dst->vdata, allocsize->totvert, BM_VERT); CustomData_bmesh_init_pool(&bm_dst->edata, allocsize->totedge, BM_EDGE); @@ -596,7 +586,7 @@ void BM_mesh_copy_init_customdata_all_layers(BMesh *bm_dst, for (int l = 0; l < src->totlayer; l++) { CustomData_add_layer_named( - dst, src->layers[l].type, CD_CALLOC, NULL, 0, src->layers[l].name); + dst, src->layers[l].type, CD_SET_DEFAULT, NULL, 0, src->layers[l].name); } CustomData_bmesh_init_pool(dst, size, htypes[i]); } @@ -720,35 +710,21 @@ BMesh *BM_mesh_copy(BMesh *bm_old) return bm_new; } -char BM_vert_flag_from_mflag(const char mflag) -{ - 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) | + return (((mflag & ME_SEAM) ? BM_ELEM_SEAM : 0) | ((mflag & ME_EDGEDRAW) ? BM_ELEM_DRAW : 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)); -} - -char BM_vert_flag_to_mflag(BMVert *v) -{ - const char hflag = v->head.hflag; - - return (((hflag & BM_ELEM_SELECT) ? SELECT : 0)); + return ((mflag & ME_SMOOTH) ? BM_ELEM_SMOOTH : 0); } short BM_edge_flag_to_mflag(BMEdge *e) { const char hflag = e->head.hflag; - return (((hflag & BM_ELEM_SELECT) ? SELECT : 0) | ((hflag & BM_ELEM_SEAM) ? ME_SEAM : 0) | - ((hflag & BM_ELEM_DRAW) ? ME_EDGEDRAW : 0) | + return (((hflag & BM_ELEM_SEAM) ? ME_SEAM : 0) | ((hflag & BM_ELEM_DRAW) ? ME_EDGEDRAW : 0) | ((hflag & BM_ELEM_SMOOTH) == 0 ? ME_SHARP : 0) | (BM_edge_is_wire(e) ? ME_LOOSEEDGE : 0) | /* not typical */ ME_EDGERENDER); @@ -757,6 +733,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)); + return ((hflag & BM_ELEM_SMOOTH) ? ME_SMOOTH : 0); } diff --git a/source/blender/bmesh/intern/bmesh_construct.h b/source/blender/bmesh/intern/bmesh_construct.h index 1851cf58d4e..225e15c90e9 100644 --- a/source/blender/bmesh/intern/bmesh_construct.h +++ b/source/blender/bmesh/intern/bmesh_construct.h @@ -169,8 +169,5 @@ BMesh *BM_mesh_copy(BMesh *bm_old); char BM_face_flag_from_mflag(char mflag); char BM_edge_flag_from_mflag(short mflag); /* ME -> BM */ -char BM_vert_flag_from_mflag(char mflag); char BM_face_flag_to_mflag(BMFace *f); short BM_edge_flag_to_mflag(BMEdge *e); -/* BM -> ME */ -char BM_vert_flag_to_mflag(BMVert *v); diff --git a/source/blender/bmesh/intern/bmesh_core.c b/source/blender/bmesh/intern/bmesh_core.c index 4d84d558cd7..5fbbd087d7e 100644 --- a/source/blender/bmesh/intern/bmesh_core.c +++ b/source/blender/bmesh/intern/bmesh_core.c @@ -95,7 +95,7 @@ BMVert *BM_vert_create(BMesh *bm, /* handles 'v->no' too */ BM_elem_attrs_copy(bm, bm, v_example, v); - /* exception: don't copy the original shapekey index */ + /* Exception: don't copy the original shape-key index. */ keyi = CustomData_bmesh_get(&bm->vdata, v->head.data, CD_SHAPE_KEYINDEX); if (keyi) { *keyi = ORIGINDEX_NONE; diff --git a/source/blender/bmesh/intern/bmesh_delete.c b/source/blender/bmesh/intern/bmesh_delete.c index e2436e53099..8ec7dc410d0 100644 --- a/source/blender/bmesh/intern/bmesh_delete.c +++ b/source/blender/bmesh/intern/bmesh_delete.c @@ -86,7 +86,6 @@ void BMO_mesh_delete_oflag_tagged(BMesh *bm, const short oflag, const char htype void BMO_mesh_delete_oflag_context(BMesh *bm, const short oflag, const int type) { BMEdge *e; - BMFace *f; BMIter eiter; BMIter fiter; @@ -128,6 +127,7 @@ void BMO_mesh_delete_oflag_context(BMesh *bm, const short oflag, const int type) case DEL_FACES: case DEL_FACES_KEEP_BOUNDARY: { /* go through and mark all edges and all verts of all faces for delete */ + BMFace *f; BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { if (BMO_face_flag_test(bm, f, oflag)) { BMLoop *l_first = BM_FACE_FIRST_LOOP(f); @@ -257,8 +257,6 @@ void BM_mesh_delete_hflag_tagged(BMesh *bm, const char hflag, const char htype) void BM_mesh_delete_hflag_context(BMesh *bm, const char hflag, const int type) { - BMEdge *e; - BMFace *f; BMIter eiter; BMIter fiter; @@ -271,6 +269,7 @@ void BM_mesh_delete_hflag_context(BMesh *bm, const char hflag, const int type) } case DEL_EDGES: { /* flush down to vert */ + BMEdge *e; BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) { if (BM_elem_flag_test(e, hflag)) { BM_elem_flag_enable(e->v1, hflag); @@ -299,6 +298,8 @@ void BM_mesh_delete_hflag_context(BMesh *bm, const char hflag, const int type) } case DEL_FACES: { /* go through and mark all edges and all verts of all faces for delete */ + BMFace *f; + BMEdge *e; BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { if (BM_elem_flag_test(f, hflag)) { BMLoop *l_first = BM_FACE_FIRST_LOOP(f); diff --git a/source/blender/bmesh/intern/bmesh_interp.c b/source/blender/bmesh/intern/bmesh_interp.c index 0c3db31dd1f..b7028dee5e1 100644 --- a/source/blender/bmesh/intern/bmesh_interp.c +++ b/source/blender/bmesh/intern/bmesh_interp.c @@ -846,7 +846,7 @@ void BM_data_layer_add(BMesh *bm, CustomData *data, int type) /* the pool is now owned by olddata and must not be shared */ data->pool = NULL; - CustomData_add_layer(data, type, CD_DEFAULT, NULL, 0); + CustomData_add_layer(data, type, CD_SET_DEFAULT, NULL, 0); update_data_blocks(bm, &olddata, data); if (olddata.layers) { @@ -864,7 +864,7 @@ void BM_data_layer_add_named(BMesh *bm, CustomData *data, int type, const char * /* the pool is now owned by olddata and must not be shared */ data->pool = NULL; - CustomData_add_layer_named(data, type, CD_DEFAULT, NULL, 0, name); + CustomData_add_layer_named(data, type, CD_SET_DEFAULT, NULL, 0, name); update_data_blocks(bm, &olddata, data); if (olddata.layers) { diff --git a/source/blender/bmesh/intern/bmesh_log.c b/source/blender/bmesh/intern/bmesh_log.c index 64e6c63e9f0..04ad80214c2 100644 --- a/source/blender/bmesh/intern/bmesh_log.c +++ b/source/blender/bmesh/intern/bmesh_log.c @@ -288,7 +288,8 @@ static void bm_log_verts_restore(BMesh *bm, BMLog *log, GHash *verts) static void bm_log_faces_restore(BMesh *bm, BMLog *log, GHash *faces) { GHashIterator gh_iter; - const int cd_face_sets = CustomData_get_offset(&bm->pdata, CD_SCULPT_FACE_SETS); + const int cd_face_sets = CustomData_get_offset_named( + &bm->pdata, CD_PROP_INT32, ".sculpt_face_set"); GHASH_ITER (gh_iter, faces) { void *key = BLI_ghashIterator_getKey(&gh_iter); diff --git a/source/blender/bmesh/intern/bmesh_log.h b/source/blender/bmesh/intern/bmesh_log.h index 5daa5dd9a68..75ff54c7d46 100644 --- a/source/blender/bmesh/intern/bmesh_log.h +++ b/source/blender/bmesh/intern/bmesh_log.h @@ -22,7 +22,7 @@ BMLog *BM_log_create(BMesh *bm); /** * Allocate and initialize a new #BMLog using existing #BMLogEntries * - * The 'entry' should be the last entry in the BMLog. Its prev pointer + * The 'entry' should be the last entry in the #BMLog. Its `prev` pointer * will be followed back to find the first entry. * * The unused IDs field of the log will be initialized by taking all diff --git a/source/blender/bmesh/intern/bmesh_marking.c b/source/blender/bmesh/intern/bmesh_marking.c index f348cd58085..a1c2815ab2f 100644 --- a/source/blender/bmesh/intern/bmesh_marking.c +++ b/source/blender/bmesh/intern/bmesh_marking.c @@ -1020,7 +1020,7 @@ static BMEditSelection *bm_select_history_create(BMHeader *ele) return ese; } -/* --- macro wrapped funcs --- */ +/* --- Macro wrapped functions. --- */ bool _bm_select_history_check(BMesh *bm, const BMHeader *ele) { @@ -1075,7 +1075,7 @@ void _bm_select_history_store_after(BMesh *bm, BMEditSelection *ese_ref, BMHeade BM_select_history_store_after_notest(bm, ese_ref, (BMElem *)ele); } } -/* --- end macro wrapped funcs --- */ +/* --- End macro wrapped functions --- */ void BM_select_history_clear(BMesh *bm) { diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.cc b/source/blender/bmesh/intern/bmesh_mesh_convert.cc index b9c004b5392..a97c7d1ea20 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc +++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc @@ -110,85 +110,6 @@ using blender::MutableSpan; using blender::Span; using blender::StringRef; -void BM_mesh_cd_flag_ensure(BMesh *bm, Mesh *mesh, const char cd_flag) -{ - const char cd_flag_all = BM_mesh_cd_flag_from_bmesh(bm) | cd_flag; - BM_mesh_cd_flag_apply(bm, cd_flag_all); - if (mesh) { - mesh->cd_flag = cd_flag_all; - } -} - -void BM_mesh_cd_flag_apply(BMesh *bm, const char cd_flag) -{ - /* CustomData_bmesh_init_pool() must run first */ - BLI_assert(bm->vdata.totlayer == 0 || bm->vdata.pool != nullptr); - BLI_assert(bm->edata.totlayer == 0 || bm->edata.pool != nullptr); - BLI_assert(bm->pdata.totlayer == 0 || bm->pdata.pool != nullptr); - - if (cd_flag & ME_CDFLAG_VERT_BWEIGHT) { - if (!CustomData_has_layer(&bm->vdata, CD_BWEIGHT)) { - BM_data_layer_add(bm, &bm->vdata, CD_BWEIGHT); - } - } - else { - if (CustomData_has_layer(&bm->vdata, CD_BWEIGHT)) { - BM_data_layer_free(bm, &bm->vdata, CD_BWEIGHT); - } - } - - if (cd_flag & ME_CDFLAG_VERT_CREASE) { - if (!CustomData_has_layer(&bm->vdata, CD_CREASE)) { - BM_data_layer_add(bm, &bm->vdata, CD_CREASE); - } - } - else { - if (CustomData_has_layer(&bm->vdata, CD_CREASE)) { - BM_data_layer_free(bm, &bm->vdata, CD_CREASE); - } - } - - if (cd_flag & ME_CDFLAG_EDGE_BWEIGHT) { - if (!CustomData_has_layer(&bm->edata, CD_BWEIGHT)) { - BM_data_layer_add(bm, &bm->edata, CD_BWEIGHT); - } - } - else { - if (CustomData_has_layer(&bm->edata, CD_BWEIGHT)) { - BM_data_layer_free(bm, &bm->edata, CD_BWEIGHT); - } - } - - if (cd_flag & ME_CDFLAG_EDGE_CREASE) { - if (!CustomData_has_layer(&bm->edata, CD_CREASE)) { - BM_data_layer_add(bm, &bm->edata, CD_CREASE); - } - } - else { - if (CustomData_has_layer(&bm->edata, CD_CREASE)) { - BM_data_layer_free(bm, &bm->edata, CD_CREASE); - } - } -} - -char BM_mesh_cd_flag_from_bmesh(BMesh *bm) -{ - char cd_flag = 0; - if (CustomData_has_layer(&bm->vdata, CD_BWEIGHT)) { - cd_flag |= ME_CDFLAG_VERT_BWEIGHT; - } - if (CustomData_has_layer(&bm->vdata, CD_CREASE)) { - cd_flag |= ME_CDFLAG_VERT_CREASE; - } - if (CustomData_has_layer(&bm->edata, CD_BWEIGHT)) { - cd_flag |= ME_CDFLAG_EDGE_BWEIGHT; - } - if (CustomData_has_layer(&bm->edata, CD_CREASE)) { - cd_flag |= ME_CDFLAG_EDGE_CREASE; - } - return cd_flag; -} - /* Static function for alloc (duplicate in modifiers_bmesh.c) */ static BMFace *bm_face_create_from_mpoly(BMesh &bm, Span<MLoop> loops, @@ -217,10 +138,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_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_copy_mesh_to_bmesh(&me->vdata, &bm->vdata, mask.vmask, CD_CONSTRUCT, 0); + CustomData_copy_mesh_to_bmesh(&me->edata, &bm->edata, mask.emask, CD_CONSTRUCT, 0); + CustomData_copy_mesh_to_bmesh(&me->ldata, &bm->ldata, mask.lmask, CD_CONSTRUCT, 0); + CustomData_copy_mesh_to_bmesh(&me->pdata, &bm->pdata, mask.pmask, CD_CONSTRUCT, 0); CustomData_bmesh_init_pool(&bm->vdata, me->totvert, BM_VERT); CustomData_bmesh_init_pool(&bm->edata, me->totedge, BM_EDGE); @@ -236,16 +157,16 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar } if (is_new) { - 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); + CustomData_copy_mesh_to_bmesh(&me->vdata, &bm->vdata, mask.vmask, CD_SET_DEFAULT, 0); + CustomData_copy_mesh_to_bmesh(&me->edata, &bm->edata, mask.emask, CD_SET_DEFAULT, 0); + CustomData_copy_mesh_to_bmesh(&me->ldata, &bm->ldata, mask.lmask, CD_SET_DEFAULT, 0); + CustomData_copy_mesh_to_bmesh(&me->pdata, &bm->pdata, mask.pmask, CD_SET_DEFAULT, 0); } else { - CustomData_bmesh_merge(&me->vdata, &bm->vdata, mask.vmask, CD_CALLOC, bm, BM_VERT); - CustomData_bmesh_merge(&me->edata, &bm->edata, mask.emask, CD_CALLOC, bm, BM_EDGE); - CustomData_bmesh_merge(&me->ldata, &bm->ldata, mask.lmask, CD_CALLOC, bm, BM_LOOP); - CustomData_bmesh_merge(&me->pdata, &bm->pdata, mask.pmask, CD_CALLOC, bm, BM_FACE); + CustomData_bmesh_merge(&me->vdata, &bm->vdata, mask.vmask, CD_SET_DEFAULT, bm, BM_VERT); + CustomData_bmesh_merge(&me->edata, &bm->edata, mask.emask, CD_SET_DEFAULT, bm, BM_EDGE); + CustomData_bmesh_merge(&me->ldata, &bm->ldata, mask.lmask, CD_SET_DEFAULT, bm, BM_LOOP); + CustomData_bmesh_merge(&me->pdata, &bm->pdata, mask.pmask, CD_SET_DEFAULT, bm, BM_FACE); } /* -------------------------------------------------------------------- */ @@ -338,47 +259,41 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar CustomData_bmesh_init_pool(&bm->ldata, me->totloop, BM_LOOP); CustomData_bmesh_init_pool(&bm->pdata, me->totpoly, BM_FACE); } - BM_mesh_cd_flag_apply(bm, me->cd_flag | (is_new ? 0 : BM_mesh_cd_flag_from_bmesh(bm))); /* Only copy these values over if the source mesh is flagged to be using them. * Even if `bm` has these layers, they may have been added from another mesh, when `!is_new`. */ - const int cd_vert_bweight_offset = (me->cd_flag & ME_CDFLAG_VERT_BWEIGHT) ? - CustomData_get_offset(&bm->vdata, CD_BWEIGHT) : - -1; - const int cd_edge_bweight_offset = (me->cd_flag & ME_CDFLAG_EDGE_BWEIGHT) ? - CustomData_get_offset(&bm->edata, CD_BWEIGHT) : - -1; - const int cd_edge_crease_offset = (me->cd_flag & ME_CDFLAG_EDGE_CREASE) ? - CustomData_get_offset(&bm->edata, CD_CREASE) : - -1; const int cd_shape_key_offset = tot_shape_keys ? CustomData_get_offset(&bm->vdata, CD_SHAPEKEY) : -1; const int cd_shape_keyindex_offset = is_new && (tot_shape_keys || params->add_key_index) ? CustomData_get_offset(&bm->vdata, CD_SHAPE_KEYINDEX) : -1; + const bool *select_vert = (const bool *)CustomData_get_layer_named( + &me->vdata, CD_PROP_BOOL, ".select_vert"); + const bool *select_edge = (const bool *)CustomData_get_layer_named( + &me->edata, CD_PROP_BOOL, ".select_edge"); + const bool *select_poly = (const bool *)CustomData_get_layer_named( + &me->pdata, CD_PROP_BOOL, ".select_poly"); 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"); + const int *material_indices = (const int *)CustomData_get_layer_named( + &me->pdata, CD_PROP_INT32, "material_index"); - Span<MVert> mvert{me->mvert, me->totvert}; + Span<MVert> mvert = me->verts(); Array<BMVert *> vtable(me->totvert); for (const int i : mvert.index_range()) { BMVert *v = vtable[i] = BM_vert_create( bm, keyco ? keyco[i] : mvert[i].co, nullptr, BM_CREATE_SKIP_CD); BM_elem_index_set(v, i); /* set_ok */ - /* 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) { + if (select_vert && select_vert[i]) { BM_vert_select_set(bm, v, true); } @@ -389,10 +304,6 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar /* Copy Custom Data */ CustomData_to_bmesh_block(&me->vdata, &bm->vdata, i, &v->head.data, true); - if (cd_vert_bweight_offset != -1) { - BM_ELEM_CD_SET_FLOAT(v, cd_vert_bweight_offset, (float)mvert[i].bweight / 255.0f); - } - /* Set shape key original index. */ if (cd_shape_keyindex_offset != -1) { BM_ELEM_CD_SET_INT(v, cd_shape_keyindex_offset, i); @@ -410,7 +321,7 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar bm->elem_index_dirty &= ~BM_VERT; /* Added in order, clear dirty flag. */ } - Span<MEdge> medge{me->medge, me->totedge}; + const Span<MEdge> medge = me->edges(); Array<BMEdge *> etable(me->totedge); for (const int i : medge.index_range()) { BMEdge *e = etable[i] = BM_edge_create( @@ -418,32 +329,23 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar BM_elem_index_set(e, i); /* set_ok */ /* Transfer flags. */ - e->head.hflag = BM_edge_flag_from_mflag(medge[i].flag & ~SELECT); + e->head.hflag = BM_edge_flag_from_mflag(medge[i].flag); 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) { + if (select_edge && select_edge[i]) { BM_edge_select_set(bm, e, true); } /* Copy Custom Data */ CustomData_to_bmesh_block(&me->edata, &bm->edata, i, &e->head.data, true); - - if (cd_edge_bweight_offset != -1) { - BM_ELEM_CD_SET_FLOAT(e, cd_edge_bweight_offset, (float)medge[i].bweight / 255.0f); - } - if (cd_edge_crease_offset != -1) { - BM_ELEM_CD_SET_FLOAT(e, cd_edge_crease_offset, (float)medge[i].crease / 255.0f); - } } if (is_new) { bm->elem_index_dirty &= ~BM_EDGE; /* Added in order, clear dirty flag. */ } - Span<MPoly> mpoly{me->mpoly, me->totpoly}; - Span<MLoop> mloop{me->mloop, me->totloop}; + const Span<MPoly> mpoly = me->polys(); + const Span<MLoop> mloop = me->loops(); /* Only needed for selection. */ @@ -474,17 +376,15 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar BM_elem_index_set(f, bm->totface - 1); /* set_ok */ /* Transfer flag. */ - f->head.hflag = BM_face_flag_from_mflag(mpoly[i].flag & ~ME_FACE_SEL); + f->head.hflag = BM_face_flag_from_mflag(mpoly[i].flag); 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) { + if (select_poly && select_poly[i]) { BM_face_select_set(bm, f, true); } - f->mat_nr = mpoly[i].mat_nr; + f->mat_nr = material_indices == nullptr ? 0 : material_indices[i]; if (i == me->act_face) { bm->act_face = f; } @@ -703,7 +603,7 @@ static int bm_to_mesh_shape_layer_index_from_kb(BMesh *bm, KeyBlock *currkey) */ static void bm_to_mesh_shape(BMesh *bm, Key *key, - MVert *mvert, + MutableSpan<MVert> mvert, const bool active_shapekey_to_mvert) { KeyBlock *actkey = static_cast<KeyBlock *>(BLI_findlink(&key->block, bm->shapenr - 1)); @@ -923,28 +823,35 @@ 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) +template<typename T, typename GetFn> +static void write_fn_to_attribute(blender::bke::MutableAttributeAccessor attributes, + const StringRef attribute_name, + const eAttrDomain domain, + 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); - } + bke::SpanAttributeWriter<T> attribute = attributes.lookup_or_add_for_write_only_span<T>( + 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(); +} + +static void assert_bmesh_has_no_mesh_only_attributes(const BMesh &bm) +{ + (void)bm; /* Unused in the release builds. */ + + /* 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); + /* The "selection" attributes are stored as flags on #BMesh. */ + BLI_assert(CustomData_get_layer_named(&bm.vdata, CD_PROP_BOOL, ".select_vert") == nullptr); + BLI_assert(CustomData_get_layer_named(&bm.edata, CD_PROP_BOOL, ".select_edge") == nullptr); + BLI_assert(CustomData_get_layer_named(&bm.pdata, CD_PROP_BOOL, ".select_poly") == nullptr); } static void convert_bmesh_hide_flags_to_mesh_attributes(BMesh &bm, @@ -955,43 +862,71 @@ static void convert_bmesh_hide_flags_to_mesh_attributes(BMesh &bm, { 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); + assert_bmesh_has_no_mesh_only_attributes(bm); if (!(need_hide_vert || need_hide_edge || need_hide_poly)) { return; } - bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh); + bke::MutableAttributeAccessor attributes = mesh.attributes_for_write(); 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); - }); + if (need_hide_vert) { + write_fn_to_attribute<bool>(attributes, ".hide_vert", ATTR_DOMAIN_POINT, [&](const int i) { + return BM_elem_flag_test(BM_vert_at_index(&bm, i), BM_ELEM_HIDDEN); + }); + } + if (need_hide_edge) { + write_fn_to_attribute<bool>(attributes, ".hide_edge", ATTR_DOMAIN_EDGE, [&](const int i) { + return BM_elem_flag_test(BM_edge_at_index(&bm, i), BM_ELEM_HIDDEN); + }); + } + if (need_hide_poly) { + write_fn_to_attribute<bool>(attributes, ".hide_poly", ATTR_DOMAIN_FACE, [&](const int i) { + return BM_elem_flag_test(BM_face_at_index(&bm, i), BM_ELEM_HIDDEN); + }); + } +} + +static void convert_bmesh_selection_flags_to_mesh_attributes(BMesh &bm, + const bool need_select_vert, + const bool need_select_edge, + const bool need_select_poly, + Mesh &mesh) +{ + using namespace blender; + if (!(need_select_vert || need_select_edge || need_select_poly)) { + return; + } + + bke::MutableAttributeAccessor attributes = mesh.attributes_for_write(); + BM_mesh_elem_table_ensure(&bm, BM_VERT | BM_EDGE | BM_FACE); + + if (need_select_vert) { + write_fn_to_attribute<bool>(attributes, ".select_vert", ATTR_DOMAIN_POINT, [&](const int i) { + return BM_elem_flag_test(BM_vert_at_index(&bm, i), BM_ELEM_SELECT); + }); + } + if (need_select_edge) { + write_fn_to_attribute<bool>(attributes, ".select_edge", ATTR_DOMAIN_EDGE, [&](const int i) { + return BM_elem_flag_test(BM_edge_at_index(&bm, i), BM_ELEM_SELECT); + }); + } + if (need_select_poly) { + write_fn_to_attribute<bool>(attributes, ".select_poly", ATTR_DOMAIN_FACE, [&](const int i) { + return BM_elem_flag_test(BM_face_at_index(&bm, i), BM_ELEM_SELECT); + }); + } } void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMeshParams *params) { - MEdge *med; BMVert *v, *eve; BMEdge *e; BMFace *f; BMIter iter; int i, j; - const int cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT); - const int cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT); - const int cd_edge_crease_offset = CustomData_get_offset(&bm->edata, CD_CREASE); const int cd_shape_keyindex_offset = CustomData_get_offset(&bm->vdata, CD_SHAPE_KEYINDEX); const int ototvert = me->totvert; @@ -1016,91 +951,76 @@ 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_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); + CustomData_copy_mesh_to_bmesh(&bm->vdata, &me->vdata, mask.vmask, CD_SET_DEFAULT, me->totvert); + CustomData_copy_mesh_to_bmesh(&bm->edata, &me->edata, mask.emask, CD_SET_DEFAULT, me->totedge); + CustomData_copy_mesh_to_bmesh(&bm->ldata, &me->ldata, mask.lmask, CD_SET_DEFAULT, me->totloop); + CustomData_copy_mesh_to_bmesh(&bm->pdata, &me->pdata, mask.pmask, CD_SET_DEFAULT, me->totpoly); } - MVert *mvert = bm->totvert ? (MVert *)MEM_callocN(sizeof(MVert) * bm->totvert, "bm_to_me.vert") : - nullptr; - MEdge *medge = bm->totedge ? (MEdge *)MEM_callocN(sizeof(MEdge) * bm->totedge, "bm_to_me.edge") : - nullptr; - MLoop *mloop = bm->totloop ? (MLoop *)MEM_callocN(sizeof(MLoop) * bm->totloop, "bm_to_me.loop") : - nullptr; - MPoly *mpoly = bm->totface ? (MPoly *)MEM_callocN(sizeof(MPoly) * bm->totface, "bm_to_me.poly") : - nullptr; - - CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, mvert, me->totvert); - CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, medge, me->totedge); - CustomData_add_layer(&me->ldata, CD_MLOOP, CD_ASSIGN, mloop, me->totloop); - CustomData_add_layer(&me->pdata, CD_MPOLY, CD_ASSIGN, mpoly, me->totpoly); - + CustomData_add_layer(&me->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, me->totvert); + CustomData_add_layer(&me->edata, CD_MEDGE, CD_SET_DEFAULT, nullptr, me->totedge); + CustomData_add_layer(&me->ldata, CD_MLOOP, CD_SET_DEFAULT, nullptr, me->totloop); + CustomData_add_layer(&me->pdata, CD_MPOLY, CD_SET_DEFAULT, nullptr, me->totpoly); + MutableSpan<MVert> mvert = me->verts_for_write(); + MutableSpan<MEdge> medge = me->edges_for_write(); + MutableSpan<MPoly> mpoly = me->polys_for_write(); + MutableSpan<MLoop> mloop = me->loops_for_write(); + + bool need_select_vert = false; + bool need_select_edge = false; + bool need_select_poly = false; bool need_hide_vert = false; bool need_hide_edge = false; bool need_hide_poly = false; + bool need_material_index = 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); - me->cd_flag = BM_mesh_cd_flag_from_bmesh(bm); - - /* This is called again, 'dotess' arg is used there. */ - BKE_mesh_update_customdata_pointers(me, false); - i = 0; BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { - copy_v3_v3(mvert->co, v->co); + copy_v3_v3(mvert[i].co, v->co); - mvert->flag = BM_vert_flag_to_mflag(v); if (BM_elem_flag_test(v, BM_ELEM_HIDDEN)) { need_hide_vert = true; } + if (BM_elem_flag_test(v, BM_ELEM_SELECT)) { + need_select_vert = true; + } BM_elem_index_set(v, i); /* set_inline */ /* Copy over custom-data. */ CustomData_from_bmesh_block(&bm->vdata, &me->vdata, v->head.data, i); - if (cd_vert_bweight_offset != -1) { - mvert->bweight = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(v, cd_vert_bweight_offset); - } - i++; - mvert++; BM_CHECK_ELEMENT(v); } bm->elem_index_dirty &= ~BM_VERT; - med = medge; i = 0; BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { - med->v1 = BM_elem_index_get(e->v1); - med->v2 = BM_elem_index_get(e->v2); + medge[i].v1 = BM_elem_index_get(e->v1); + medge[i].v2 = BM_elem_index_get(e->v2); - med->flag = BM_edge_flag_to_mflag(e); + medge[i].flag = BM_edge_flag_to_mflag(e); if (BM_elem_flag_test(e, BM_ELEM_HIDDEN)) { need_hide_edge = true; } + if (BM_elem_flag_test(e, BM_ELEM_SELECT)) { + need_select_edge = true; + } BM_elem_index_set(e, i); /* set_inline */ /* Copy over custom-data. */ CustomData_from_bmesh_block(&bm->edata, &me->edata, e->head.data, i); - bmesh_quick_edgedraw_flag(med, e); - - if (cd_edge_crease_offset != -1) { - med->crease = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(e, cd_edge_crease_offset); - } - if (cd_edge_bweight_offset != -1) { - med->bweight = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(e, cd_edge_bweight_offset); - } + bmesh_quick_edgedraw_flag(&medge[i], e); i++; - med++; BM_CHECK_ELEMENT(e); } bm->elem_index_dirty &= ~BM_EDGE; @@ -1109,24 +1029,28 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh j = 0; BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { BMLoop *l_iter, *l_first; - mpoly->loopstart = j; - mpoly->totloop = f->len; - mpoly->mat_nr = f->mat_nr; - mpoly->flag = BM_face_flag_to_mflag(f); + mpoly[i].loopstart = j; + mpoly[i].totloop = f->len; + if (f->mat_nr != 0) { + need_material_index = true; + } + mpoly[i].flag = BM_face_flag_to_mflag(f); if (BM_elem_flag_test(f, BM_ELEM_HIDDEN)) { need_hide_poly = true; } + if (BM_elem_flag_test(f, BM_ELEM_SELECT)) { + need_select_poly = true; + } l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { - mloop->e = BM_elem_index_get(l_iter->e); - mloop->v = BM_elem_index_get(l_iter->v); + mloop[j].e = BM_elem_index_get(l_iter->e); + mloop[j].v = BM_elem_index_get(l_iter->v); /* Copy over custom-data. */ CustomData_from_bmesh_block(&bm->ldata, &me->ldata, l_iter->head.data, j); j++; - mloop++; BM_CHECK_ELEMENT(l_iter); BM_CHECK_ELEMENT(l_iter->e); BM_CHECK_ELEMENT(l_iter->v); @@ -1140,10 +1064,17 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh CustomData_from_bmesh_block(&bm->pdata, &me->pdata, f->head.data, i); i++; - mpoly++; BM_CHECK_ELEMENT(f); } + if (need_material_index) { + BM_mesh_elem_table_ensure(bm, BM_FACE); + write_fn_to_attribute<int>( + me->attributes_for_write(), "material_index", ATTR_DOMAIN_FACE, [&](const int i) { + return static_cast<int>(BM_face_at_index(bm, i)->mat_nr); + }); + } + /* Patch hook indices and vertex parents. */ if (params->calc_object_remap && (ototvert > 0)) { BLI_assert(bmain != nullptr); @@ -1210,8 +1141,8 @@ 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); + convert_bmesh_selection_flags_to_mesh_attributes( + *bm, need_select_vert, need_select_edge, need_select_poly, *me); { me->totselect = BLI_listbase_count(&(bm->selected)); @@ -1238,7 +1169,7 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh } if (me->key) { - bm_to_mesh_shape(bm, me->key, me->mvert, params->active_shapekey_to_mvert); + bm_to_mesh_shape(bm, me->key, mvert, params->active_shapekey_to_mvert); } /* Run this even when shape keys aren't used since it may be used for hooks or vertex parents. */ @@ -1259,8 +1190,12 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh BKE_mesh_runtime_clear_geometry(me); } +/* NOTE: The function is called from multiple threads with the same input BMesh and different + * mesh objects. */ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *cd_mask_extra) { + using namespace blender; + /* Must be an empty mesh. */ BLI_assert(me->totvert == 0); BLI_assert(cd_mask_extra == nullptr || (cd_mask_extra->vmask & CD_MASK_SHAPEKEY) == 0); @@ -1271,10 +1206,10 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks * me->totloop = bm->totloop; me->totpoly = bm->totface; - CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, nullptr, bm->totvert); - CustomData_add_layer(&me->edata, CD_MEDGE, CD_CALLOC, nullptr, bm->totedge); - CustomData_add_layer(&me->ldata, CD_MLOOP, CD_CALLOC, nullptr, bm->totloop); - CustomData_add_layer(&me->pdata, CD_MPOLY, CD_CALLOC, nullptr, bm->totface); + CustomData_add_layer(&me->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, bm->totvert); + CustomData_add_layer(&me->edata, CD_MEDGE, CD_SET_DEFAULT, nullptr, bm->totedge); + CustomData_add_layer(&me->ldata, CD_MLOOP, CD_SET_DEFAULT, nullptr, bm->totloop); + CustomData_add_layer(&me->pdata, CD_MPOLY, CD_SET_DEFAULT, nullptr, bm->totface); /* Don't process shape-keys, we only feed them through the modifier stack as needed, * e.g. for applying modifiers or the like. */ @@ -1283,37 +1218,32 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks * CustomData_MeshMasks_update(&mask, cd_mask_extra); } mask.vmask &= ~CD_MASK_SHAPEKEY; - CustomData_merge(&bm->vdata, &me->vdata, mask.vmask, CD_CALLOC, me->totvert); - CustomData_merge(&bm->edata, &me->edata, mask.emask, CD_CALLOC, me->totedge); - CustomData_merge(&bm->ldata, &me->ldata, mask.lmask, CD_CALLOC, me->totloop); - CustomData_merge(&bm->pdata, &me->pdata, mask.pmask, CD_CALLOC, me->totpoly); - - BKE_mesh_update_customdata_pointers(me, false); + CustomData_merge(&bm->vdata, &me->vdata, mask.vmask, CD_SET_DEFAULT, me->totvert); + CustomData_merge(&bm->edata, &me->edata, mask.emask, CD_SET_DEFAULT, me->totedge); + CustomData_merge(&bm->ldata, &me->ldata, mask.lmask, CD_SET_DEFAULT, me->totloop); + CustomData_merge(&bm->pdata, &me->pdata, mask.pmask, CD_SET_DEFAULT, me->totpoly); BMIter iter; BMVert *eve; BMEdge *eed; BMFace *efa; - MVert *mvert = me->mvert; - MEdge *medge = me->medge; - MLoop *mloop = me->mloop; - MPoly *mpoly = me->mpoly; + MutableSpan<MVert> mvert = me->verts_for_write(); + MutableSpan<MEdge> medge = me->edges_for_write(); + MutableSpan<MPoly> mpoly = me->polys_for_write(); + MutableSpan<MLoop> loops = me->loops_for_write(); + MLoop *mloop = loops.data(); unsigned int i, j; - const int cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT); - const int cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT); - 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); me->runtime.deformed_only = true; + bke::MutableAttributeAccessor mesh_attributes = me->attributes_for_write(); + + bke::SpanAttributeWriter<bool> hide_vert_attribute; + bke::SpanAttributeWriter<bool> select_vert_attribute; BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) { MVert *mv = &mvert[i]; @@ -1321,23 +1251,27 @@ 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); + if (!hide_vert_attribute) { + hide_vert_attribute = mesh_attributes.lookup_or_add_for_write_span<bool>( + ".hide_vert", ATTR_DOMAIN_POINT); + } + hide_vert_attribute.span[i] = true; } - - if (cd_vert_bweight_offset != -1) { - mv->bweight = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eve, cd_vert_bweight_offset); + if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { + if (!select_vert_attribute) { + select_vert_attribute = mesh_attributes.lookup_or_add_for_write_span<bool>( + ".select_vert", ATTR_DOMAIN_POINT); + } + select_vert_attribute.span[i] = true; } CustomData_from_bmesh_block(&bm->vdata, &me->vdata, eve->head.data, i); } bm->elem_index_dirty &= ~BM_VERT; + bke::SpanAttributeWriter<bool> hide_edge_attribute; + bke::SpanAttributeWriter<bool> select_edge_attribute; BM_ITER_MESH_INDEX (eed, &iter, bm, BM_EDGES_OF_MESH, i) { MEdge *med = &medge[i]; @@ -1348,7 +1282,18 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks * med->flag = BM_edge_flag_to_mflag(eed); if (BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) { - need_hide_edge = true; + if (!hide_edge_attribute) { + hide_edge_attribute = mesh_attributes.lookup_or_add_for_write_span<bool>(".hide_edge", + ATTR_DOMAIN_EDGE); + } + hide_edge_attribute.span[i] = true; + } + if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { + if (!select_edge_attribute) { + select_edge_attribute = mesh_attributes.lookup_or_add_for_write_span<bool>( + ".select_edge", ATTR_DOMAIN_EDGE); + } + select_edge_attribute.span[i] = true; } /* Handle this differently to editmode switching, @@ -1359,18 +1304,14 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks * } } - if (cd_edge_crease_offset != -1) { - med->crease = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eed, cd_edge_crease_offset); - } - if (cd_edge_bweight_offset != -1) { - med->bweight = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eed, cd_edge_bweight_offset); - } - CustomData_from_bmesh_block(&bm->edata, &me->edata, eed->head.data, i); } bm->elem_index_dirty &= ~BM_EDGE; j = 0; + bke::SpanAttributeWriter<int> material_index_attribute; + bke::SpanAttributeWriter<bool> hide_poly_attribute; + bke::SpanAttributeWriter<bool> select_poly_attribute; BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, i) { BMLoop *l_iter; BMLoop *l_first; @@ -1381,11 +1322,28 @@ 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; + if (!hide_poly_attribute) { + hide_poly_attribute = mesh_attributes.lookup_or_add_for_write_span<bool>(".hide_poly", + ATTR_DOMAIN_FACE); + } + hide_poly_attribute.span[i] = true; + } + if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) { + if (!select_poly_attribute) { + select_poly_attribute = mesh_attributes.lookup_or_add_for_write_span<bool>( + ".select_poly", ATTR_DOMAIN_FACE); + } + select_poly_attribute.span[i] = true; } mp->loopstart = j; - mp->mat_nr = efa->mat_nr; + if (efa->mat_nr != 0) { + if (!material_index_attribute) { + material_index_attribute = mesh_attributes.lookup_or_add_for_write_span<int>( + "material_index", ATTR_DOMAIN_FACE); + } + material_index_attribute.span[i] = efa->mat_nr; + } l_iter = l_first = BM_FACE_FIRST_LOOP(efa); do { @@ -1403,8 +1361,13 @@ 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); + assert_bmesh_has_no_mesh_only_attributes(*bm); - me->cd_flag = BM_mesh_cd_flag_from_bmesh(bm); + material_index_attribute.finish(); + hide_vert_attribute.finish(); + hide_edge_attribute.finish(); + hide_poly_attribute.finish(); + select_vert_attribute.finish(); + select_edge_attribute.finish(); + select_poly_attribute.finish(); } diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.h b/source/blender/bmesh/intern/bmesh_mesh_convert.h index e2871dc04d3..3f8e9e3dfef 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_convert.h +++ b/source/blender/bmesh/intern/bmesh_mesh_convert.h @@ -13,10 +13,6 @@ struct CustomData_MeshMasks; struct Main; struct Mesh; -void BM_mesh_cd_flag_ensure(BMesh *bm, struct Mesh *mesh, char cd_flag); -void BM_mesh_cd_flag_apply(BMesh *bm, char cd_flag); -char BM_mesh_cd_flag_from_bmesh(BMesh *bm); - struct BMeshFromMeshParams { bool calc_face_normal; bool calc_vert_normal; @@ -61,8 +57,8 @@ struct BMeshToMeshParams { bool active_shapekey_to_mvert; struct CustomData_MeshMasks cd_mask_extra; }; + /** - * * \param bmain: May be NULL in case \a calc_object_remap parameter option is not set. */ void BM_mesh_bm_to_me(struct Main *bmain, diff --git a/source/blender/bmesh/intern/bmesh_query.h b/source/blender/bmesh/intern/bmesh_query.h index 85eadd3076a..9d690395d72 100644 --- a/source/blender/bmesh/intern/bmesh_query.h +++ b/source/blender/bmesh/intern/bmesh_query.h @@ -138,7 +138,6 @@ BMLoop *BM_face_other_vert_loop(BMFace *f, BMVert *v_prev, BMVert *v) ATTR_WARN_ * +----------+ <-- This loop defines the face and vertex.. * l * </pre> - * */ BMLoop *BM_loop_other_vert_loop_by_edge(BMLoop *l, BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); diff --git a/source/blender/bmesh/intern/bmesh_query_uv.c b/source/blender/bmesh/intern/bmesh_query_uv.cc index 1225543cd06..5a725407c6b 100644 --- a/source/blender/bmesh/intern/bmesh_query_uv.c +++ b/source/blender/bmesh/intern/bmesh_query_uv.cc @@ -6,9 +6,10 @@ #include "MEM_guardedalloc.h" -#include "BLI_alloca.h" +#include "BLI_array.hh" #include "BLI_linklist.h" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_utildefines_stack.h" #include "BKE_customdata.h" @@ -80,7 +81,7 @@ void BM_face_uv_calc_center_median(const BMFace *f, const int cd_loop_uv_offset, zero_v2(r_cent); l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { - const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset); + const MLoopUV *luv = (const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset); add_v2_v2(r_cent, luv->uv); } while ((l_iter = l_iter->next) != l_first); @@ -89,16 +90,16 @@ void BM_face_uv_calc_center_median(const BMFace *f, const int cd_loop_uv_offset, float BM_face_uv_calc_cross(const BMFace *f, const int cd_loop_uv_offset) { - float(*uvs)[2] = BLI_array_alloca(uvs, f->len); + blender::Array<blender::float2, BM_DEFAULT_NGON_STACK_SIZE> uvs(f->len); const BMLoop *l_iter; const BMLoop *l_first; int i = 0; l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { - const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset); - copy_v2_v2(uvs[i++], luv->uv); + const MLoopUV *luv = (const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset); + uvs[i++] = luv->uv; } while ((l_iter = l_iter->next) != l_first); - return cross_poly_v2(uvs, f->len); + return cross_poly_v2(reinterpret_cast<const float(*)[2]>(uvs.data()), f->len); } void BM_face_uv_minmax(const BMFace *f, float min[2], float max[2], const int cd_loop_uv_offset) @@ -107,7 +108,7 @@ void BM_face_uv_minmax(const BMFace *f, float min[2], float max[2], const int cd const BMLoop *l_first; l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { - const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset); + const MLoopUV *luv = (const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset); minmax_v2v2_v2(min, max, luv->uv); } while ((l_iter = l_iter->next) != l_first); } @@ -118,7 +119,7 @@ void BM_face_uv_transform(BMFace *f, const float matrix[2][2], const int cd_loop BMLoop *l_first; l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { - MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset); + MLoopUV *luv = (MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset); mul_m2_v2(matrix, luv->uv); } while ((l_iter = l_iter->next) != l_first); } @@ -126,12 +127,12 @@ void BM_face_uv_transform(BMFace *f, const float matrix[2][2], const int cd_loop bool BM_loop_uv_share_edge_check(BMLoop *l_a, BMLoop *l_b, const int cd_loop_uv_offset) { BLI_assert(l_a->e == l_b->e); - MLoopUV *luv_a_curr = BM_ELEM_CD_GET_VOID_P(l_a, cd_loop_uv_offset); - MLoopUV *luv_a_next = BM_ELEM_CD_GET_VOID_P(l_a->next, cd_loop_uv_offset); - MLoopUV *luv_b_curr = BM_ELEM_CD_GET_VOID_P(l_b, cd_loop_uv_offset); - MLoopUV *luv_b_next = BM_ELEM_CD_GET_VOID_P(l_b->next, cd_loop_uv_offset); + MLoopUV *luv_a_curr = (MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_a, cd_loop_uv_offset); + MLoopUV *luv_a_next = (MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_a->next, cd_loop_uv_offset); + MLoopUV *luv_b_curr = (MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_b, cd_loop_uv_offset); + MLoopUV *luv_b_next = (MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_b->next, cd_loop_uv_offset); if (l_a->v != l_b->v) { - SWAP(MLoopUV *, luv_b_curr, luv_b_next); + std::swap(luv_b_curr, luv_b_next); } return (equals_v2v2(luv_a_curr->uv, luv_b_curr->uv) && equals_v2v2(luv_a_next->uv, luv_b_next->uv)); @@ -140,8 +141,8 @@ bool BM_loop_uv_share_edge_check(BMLoop *l_a, BMLoop *l_b, const int cd_loop_uv_ bool BM_loop_uv_share_vert_check(BMLoop *l_a, BMLoop *l_b, const int cd_loop_uv_offset) { BLI_assert(l_a->v == l_b->v); - const MLoopUV *luv_a = BM_ELEM_CD_GET_VOID_P(l_a, cd_loop_uv_offset); - const MLoopUV *luv_b = BM_ELEM_CD_GET_VOID_P(l_b, cd_loop_uv_offset); + const MLoopUV *luv_a = (const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_a, cd_loop_uv_offset); + const MLoopUV *luv_b = (const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_b, cd_loop_uv_offset); if (!equals_v2v2(luv_a->uv, luv_b->uv)) { return false; } @@ -160,8 +161,10 @@ bool BM_edge_uv_share_vert_check(BMEdge *e, BMLoop *l_a, BMLoop *l_b, const int const BMLoop *l_other_b = BM_loop_other_vert_loop_by_edge(l_b, e); { - const MLoopUV *luv_other_a = BM_ELEM_CD_GET_VOID_P(l_other_a, cd_loop_uv_offset); - const MLoopUV *luv_other_b = BM_ELEM_CD_GET_VOID_P(l_other_b, cd_loop_uv_offset); + const MLoopUV *luv_other_a = (const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_other_a, + cd_loop_uv_offset); + const MLoopUV *luv_other_b = (const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_other_b, + cd_loop_uv_offset); if (!equals_v2v2(luv_other_a->uv, luv_other_b->uv)) { return false; } @@ -172,7 +175,7 @@ bool BM_edge_uv_share_vert_check(BMEdge *e, BMLoop *l_a, BMLoop *l_b, const int bool BM_face_uv_point_inside_test(const BMFace *f, const float co[2], const int cd_loop_uv_offset) { - float(*projverts)[2] = BLI_array_alloca(projverts, f->len); + blender::Array<blender::float2, BM_DEFAULT_NGON_STACK_SIZE> projverts(f->len); BMLoop *l_iter; int i; @@ -180,8 +183,9 @@ bool BM_face_uv_point_inside_test(const BMFace *f, const float co[2], const int BLI_assert(BM_face_is_normal_valid(f)); for (i = 0, l_iter = BM_FACE_FIRST_LOOP(f); i < f->len; i++, l_iter = l_iter->next) { - copy_v2_v2(projverts[i], BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset)); + projverts[i] = ((const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset))->uv; } - return isect_point_poly_v2(co, projverts, f->len, false); + return isect_point_poly_v2( + co, reinterpret_cast<const float(*)[2]>(projverts.data()), f->len, false); } diff --git a/source/blender/bmesh/intern/bmesh_structure.c b/source/blender/bmesh/intern/bmesh_structure.c index 6baaeb43f1a..7d340f02f2e 100644 --- a/source/blender/bmesh/intern/bmesh_structure.c +++ b/source/blender/bmesh/intern/bmesh_structure.c @@ -182,9 +182,8 @@ void bmesh_disk_edge_remove(BMEdge *e, BMVert *v) BMEdge *bmesh_disk_edge_exists(const BMVert *v1, const BMVert *v2) { - BMEdge *e_iter, *e_first; - if (v1->e) { + BMEdge *e_iter, *e_first; e_first = e_iter = v1->e; do { diff --git a/source/blender/bmesh/operators/bmo_connect.c b/source/blender/bmesh/operators/bmo_connect.c index 42de425103e..59a12db9241 100644 --- a/source/blender/bmesh/operators/bmo_connect.c +++ b/source/blender/bmesh/operators/bmo_connect.c @@ -18,7 +18,7 @@ #define VERT_INPUT 1 #define EDGE_OUT 1 -/* Edge spans 2 VERT_INPUT's, its a nop, +/* Edge spans 2 VERT_INPUT's, its a NOP, * but include in "edges.out" */ #define EDGE_OUT_ADJ 2 diff --git a/source/blender/bmesh/operators/bmo_connect_nonplanar.c b/source/blender/bmesh/operators/bmo_connect_nonplanar.c index ac88ffb9065..8112844fc8a 100644 --- a/source/blender/bmesh/operators/bmo_connect_nonplanar.c +++ b/source/blender/bmesh/operators/bmo_connect_nonplanar.c @@ -24,7 +24,7 @@ static float bm_face_subset_calc_planar(BMLoop *l_first, BMLoop *l_last, const float no[3]) { float axis_mat[3][3]; - float z_prev, z_curr; + float z_prev; float delta_z = 0.0f; /* Newell's Method */ @@ -35,7 +35,7 @@ static float bm_face_subset_calc_planar(BMLoop *l_first, BMLoop *l_last, const f z_prev = dot_m3_v3_row_z(axis_mat, l_last->v->co); do { - z_curr = dot_m3_v3_row_z(axis_mat, l_iter->v->co); + const float z_curr = dot_m3_v3_row_z(axis_mat, l_iter->v->co); delta_z += fabsf(z_curr - z_prev); z_prev = z_curr; } while ((l_iter = l_iter->next) != l_term); diff --git a/source/blender/bmesh/operators/bmo_create.c b/source/blender/bmesh/operators/bmo_create.c index a809fe6ee3d..9dba48a8961 100644 --- a/source/blender/bmesh/operators/bmo_create.c +++ b/source/blender/bmesh/operators/bmo_create.c @@ -77,7 +77,6 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) * | . * | . * +........+ <-- starts out free standing. - * */ /* Here we check for consistency and create 2 edges */ diff --git a/source/blender/bmesh/operators/bmo_join_triangles.c b/source/blender/bmesh/operators/bmo_join_triangles.c index 1339efb3057..ab74aa2e1bb 100644 --- a/source/blender/bmesh/operators/bmo_join_triangles.c +++ b/source/blender/bmesh/operators/bmo_join_triangles.c @@ -22,7 +22,9 @@ #include "intern/bmesh_operators_private.h" /* own include */ -/* assumes edges are validated before reaching this poin */ +/** + * \note Assumes edges are validated before reaching this point. + */ static float quad_calc_error(const float v1[3], const float v2[3], const float v3[3], diff --git a/source/blender/bmesh/operators/bmo_poke.c b/source/blender/bmesh/operators/bmo_poke.c index 7ff3b9b072c..6622dbf7575 100644 --- a/source/blender/bmesh/operators/bmo_poke.c +++ b/source/blender/bmesh/operators/bmo_poke.c @@ -52,8 +52,7 @@ void bmo_poke_exec(BMesh *bm, BMOperator *op) } BMO_ITER (f, &oiter, op->slots_in, "faces", BM_FACE) { - BMFace *f_new; - float f_center[3], f_center_mean[3]; + float f_center[3]; BMVert *v_center = NULL; BMLoop *l_iter, *l_first; /* only interpolate the central loop from the face once, @@ -69,15 +68,6 @@ void bmo_poke_exec(BMesh *bm, BMOperator *op) v_center = BM_vert_create(bm, f_center, NULL, BM_CREATE_NOP); BMO_vert_flag_enable(bm, v_center, ELE_NEW); - if (cd_loop_mdisp_offset != -1) { - if (center_mode == BMOP_POKE_MEDIAN) { - copy_v3_v3(f_center_mean, f_center); - } - else { - BM_face_calc_center_median(f, f_center_mean); - } - } - /* handled by BM_loop_interp_from_face */ // BM_vert_interp_from_face(bm, v_center, f); @@ -92,8 +82,7 @@ void bmo_poke_exec(BMesh *bm, BMOperator *op) l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { BMLoop *l_new; - - f_new = BM_face_create_quad_tri( + BMFace *f_new = BM_face_create_quad_tri( bm, l_iter->v, l_iter->next->v, v_center, NULL, f, BM_CREATE_NOP); l_new = BM_FACE_FIRST_LOOP(f_new); diff --git a/source/blender/bmesh/operators/bmo_removedoubles.c b/source/blender/bmesh/operators/bmo_removedoubles.c index e3275555b86..99ca49f3d4f 100644 --- a/source/blender/bmesh/operators/bmo_removedoubles.c +++ b/source/blender/bmesh/operators/bmo_removedoubles.c @@ -657,10 +657,10 @@ static void bmesh_find_doubles_common(BMesh *bm, for (int i = 0; i < verts_len; i++) { BMVert *v_check = verts[i]; if (duplicates[i] == -1) { - /* nop (others can use as target) */ + /* NOP (others can use as target). */ } else if (duplicates[i] == i) { - /* keep (others can use as target) */ + /* Keep (others can use as target). */ } else { BMVert *v_other = verts[duplicates[i]]; diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c index d6c64809e13..6b2df40549d 100644 --- a/source/blender/bmesh/operators/bmo_subdivide.c +++ b/source/blender/bmesh/operators/bmo_subdivide.c @@ -86,7 +86,7 @@ typedef struct SubDPattern { * split the edge only? */ -/* flags for all elements share a common bitfield space */ +/** Flags for all elements share a common bit-field space. */ #define SUBD_SPLIT 1 #define EDGE_PERCENT 2 @@ -966,7 +966,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) patterns[5] = NULL; } - /* add a temporary shapekey layer to store displacements on current geometry */ + /* Add a temporary shape-key layer to store displacements on current geometry. */ BM_data_layer_add(bm, &bm->vdata, CD_SHAPEKEY); bmo_subd_init_shape_info(bm, ¶ms); diff --git a/source/blender/bmesh/operators/bmo_subdivide_edgering.c b/source/blender/bmesh/operators/bmo_subdivide_edgering.c index 3d2f5947539..6f41da7bb43 100644 --- a/source/blender/bmesh/operators/bmo_subdivide_edgering.c +++ b/source/blender/bmesh/operators/bmo_subdivide_edgering.c @@ -42,7 +42,8 @@ #define FACE_IN_STACK (1 << 2) /* -------------------------------------------------------------------- */ -/* Specialized Utility Funcs */ +/** \name Specialized Utility Functions + * \{ */ #ifndef NDEBUG static uint bm_verts_tag_count(BMesh *bm) @@ -183,9 +184,13 @@ finally: return has_overlap; } +/** \} */ + /* -------------------------------------------------------------------- */ -/* Edge Loop Pairs */ -/* key (ordered loop pointers) */ +/** \name Edge Loop Pairs + * + * key (ordered loop pointers). + * \{ */ static GSet *bm_edgering_pair_calc(BMesh *bm, ListBase *eloops_rim) { /** @@ -258,8 +263,11 @@ static GSet *bm_edgering_pair_calc(BMesh *bm, ListBase *eloops_rim) return eloop_pair_gs; } +/** \} */ + /* -------------------------------------------------------------------- */ -/* Subdivide an edge 'n' times and return an open edgeloop */ +/** \name Subdivide an edge 'n' times and return an open edgeloop + * \{ */ static void bm_edge_subdiv_as_loop( BMesh *bm, ListBase *eloops, BMEdge *e, BMVert *v_a, const int cuts) @@ -290,8 +298,11 @@ static void bm_edge_subdiv_as_loop( BLI_addtail(eloops, eloop); } +/** \} */ + /* -------------------------------------------------------------------- */ -/* LoopPair Cache (struct and util funcs) */ +/** \name Loop Pair Cache (struct and utilities functions) + * \{ */ /** * Use for finding spline handle direction from surrounding faces. @@ -510,8 +521,11 @@ static void bm_edgering_pair_store_free(LoopPairStore *lpair, const int interp_m MEM_freeN(lpair); } +/** \} */ + /* -------------------------------------------------------------------- */ -/* Interpolation Function */ +/** \name Interpolation Function + * \{ */ static void bm_edgering_pair_interpolate(BMesh *bm, LoopPairStore *lpair, @@ -1216,3 +1230,5 @@ cleanup: BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "faces.out", BM_FACE, FACE_OUT); } } + +/** \} */ diff --git a/source/blender/bmesh/operators/bmo_utils.c b/source/blender/bmesh/operators/bmo_utils.c index 309ef2cf21e..d88f3112a71 100644 --- a/source/blender/bmesh/operators/bmo_utils.c +++ b/source/blender/bmesh/operators/bmo_utils.c @@ -470,7 +470,7 @@ void bmo_rotate_uvs_exec(BMesh *bm, BMOperator *op) BMLoop *lf; /* current face loops */ MLoopUV *f_luv; /* first face loop uv */ float p_uv[2]; /* previous uvs */ - float t_uv[2]; /* tmp uvs */ + float t_uv[2]; /* temp uvs */ int n = 0; BM_ITER_ELEM (lf, &l_iter, fs, BM_LOOPS_OF_FACE) { @@ -603,7 +603,7 @@ void bmo_rotate_colors_exec(BMesh *bm, BMOperator *op) const size_t size = cd_loop_color_type == CD_PROP_COLOR ? sizeof(MPropCol) : sizeof(MLoopCol); void *p_col; /* previous color */ - void *t_col = alloca(size); /* tmp color */ + void *t_col = alloca(size); /* Temp color. */ BMO_ITER (fs, &fs_iter, op->slots_in, "faces", BM_FACE) { if (use_ccw == false) { /* same loops direction */ diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c index aa2c93f7c5a..b08051341be 100644 --- a/source/blender/bmesh/tools/bmesh_bevel.c +++ b/source/blender/bmesh/tools/bmesh_bevel.c @@ -4799,7 +4799,7 @@ static float projected_boundary_area(BevVert *bv, BMFace *f) find_face_internal_boundverts(bv, f, unsnapped); do { float *co = v->nv.v->co; - if (v == unsnapped[0] || v == unsnapped[1] || v == unsnapped[2]) { + if (ELEM(v, unsnapped[0], unsnapped[1], unsnapped[2])) { mul_v2_m3v3(proj_co[i], axis_mat, co); } else { @@ -4922,7 +4922,7 @@ static void build_center_ngon(BevelParams *bp, BMesh *bm, BevVert *bv, int mat_n BLI_array_append(vv, mesh_vert(vm, i, ns2, ns2)->v); if (frep) { BLI_array_append(vf, frep); - if (v == frep_unsnapped[0] || v == frep_unsnapped[1] || v == frep_unsnapped[2]) { + if (ELEM(v, frep_unsnapped[0], frep_unsnapped[1], frep_unsnapped[2])) { BLI_array_append(ve, NULL); } else { @@ -5299,7 +5299,7 @@ static void snap_edges_for_vmesh_vert(int i, int previ = (i + n_bndv - 1) % n_bndv; /* Make jj and kk be the j and k indices for this corner. */ int jj = corner < 2 ? j : j + 1; - int kk = (corner == 0 || corner == 3) ? k : k + 1; + int kk = ELEM(corner, 0, 3) ? k : k + 1; if (jj < ns2 && kk < ns2) { ; /* No snap. */ } @@ -5765,7 +5765,7 @@ static BMFace *bevel_build_poly(BevelParams *bp, BMesh *bm, BevVert *bv) BLI_array_append(bmverts, bndv->nv.v); if (repface) { BLI_array_append(bmfaces, repface); - if (bndv == unsnapped[0] || bndv == unsnapped[1] || bndv == unsnapped[2]) { + if (ELEM(bndv, unsnapped[0], unsnapped[1], unsnapped[2])) { BLI_array_append(bmedges, NULL); } else { @@ -7083,7 +7083,7 @@ static void bevel_build_edge_polygons(BMesh *bm, BevelParams *bp, BMEdge *bme) } } - /* Fix UVs along end edge joints. A nop unless other side built already. */ + /* Fix UVs along end edge joints. A NOP unless other side built already. */ /* TODO: If some seam, may want to do selective merge. */ if (!bv1->any_seam && bv1->vmesh->mesh_kind == M_NONE) { bev_merge_end_uvs(bm, bv1, e1); diff --git a/source/blender/bmesh/tools/bmesh_path_region_uv.c b/source/blender/bmesh/tools/bmesh_path_region_uv.c index 5c70f7fa5ec..56090ed9916 100644 --- a/source/blender/bmesh/tools/bmesh_path_region_uv.c +++ b/source/blender/bmesh/tools/bmesh_path_region_uv.c @@ -109,9 +109,10 @@ static bool bm_loop_region_test_chain(BMLoop *l, int *const depths[2], const int static LinkNode *mesh_calc_path_region_elem(BMesh *bm, BMElem *ele_src, BMElem *ele_dst, - const uint cd_loop_uv_offset, + const int cd_loop_uv_offset, const char path_htype) { + BLI_assert(cd_loop_uv_offset >= 0); int ele_loops_len[2]; BMLoop **ele_loops[2]; @@ -397,7 +398,7 @@ static LinkNode *mesh_calc_path_region_elem(BMesh *bm, LinkNode *BM_mesh_calc_path_uv_region_vert(BMesh *bm, BMElem *ele_src, BMElem *ele_dst, - const uint cd_loop_uv_offset, + const int cd_loop_uv_offset, bool (*filter_fn)(BMLoop *, void *user_data), void *user_data) { @@ -426,7 +427,7 @@ LinkNode *BM_mesh_calc_path_uv_region_vert(BMesh *bm, LinkNode *BM_mesh_calc_path_uv_region_edge(BMesh *bm, BMElem *ele_src, BMElem *ele_dst, - const uint cd_loop_uv_offset, + const int cd_loop_uv_offset, bool (*filter_fn)(BMLoop *, void *user_data), void *user_data) { @@ -455,7 +456,7 @@ LinkNode *BM_mesh_calc_path_uv_region_edge(BMesh *bm, LinkNode *BM_mesh_calc_path_uv_region_face(BMesh *bm, BMElem *ele_src, BMElem *ele_dst, - const uint cd_loop_uv_offset, + const int cd_loop_uv_offset, bool (*filter_fn)(BMFace *, void *user_data), void *user_data) { diff --git a/source/blender/bmesh/tools/bmesh_path_region_uv.h b/source/blender/bmesh/tools/bmesh_path_region_uv.h index fa1b2bfcf9b..f399395e051 100644 --- a/source/blender/bmesh/tools/bmesh_path_region_uv.h +++ b/source/blender/bmesh/tools/bmesh_path_region_uv.h @@ -9,7 +9,7 @@ struct LinkNode *BM_mesh_calc_path_uv_region_vert(BMesh *bm, BMElem *ele_src, BMElem *ele_dst, - uint cd_loop_uv_offset, + int cd_loop_uv_offset, bool (*filter_fn)(BMLoop *, void *user_data), void *user_data) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2, 3); @@ -17,7 +17,7 @@ struct LinkNode *BM_mesh_calc_path_uv_region_vert(BMesh *bm, struct LinkNode *BM_mesh_calc_path_uv_region_edge(BMesh *bm, BMElem *ele_src, BMElem *ele_dst, - uint cd_loop_uv_offset, + int cd_loop_uv_offset, bool (*filter_fn)(BMLoop *, void *user_data), void *user_data) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2, 3); @@ -25,7 +25,7 @@ struct LinkNode *BM_mesh_calc_path_uv_region_edge(BMesh *bm, struct LinkNode *BM_mesh_calc_path_uv_region_face(BMesh *bm, BMElem *ele_src, BMElem *ele_dst, - uint cd_loop_uv_offset, + int cd_loop_uv_offset, bool (*filter_fn)(BMFace *, void *user_data), void *user_data) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2, 3); diff --git a/source/blender/bmesh/tools/bmesh_path_uv.c b/source/blender/bmesh/tools/bmesh_path_uv.c index 3d736cdc3b8..6531677fce6 100644 --- a/source/blender/bmesh/tools/bmesh_path_uv.c +++ b/source/blender/bmesh/tools/bmesh_path_uv.c @@ -65,7 +65,7 @@ static void verttag_add_adjacent_uv(HeapSimple *heap, const struct BMCalcPathUVParams *params) { BLI_assert(params->aspect_y != 0.0f); - const uint cd_loop_uv_offset = params->cd_loop_uv_offset; + const int cd_loop_uv_offset = params->cd_loop_uv_offset; const int l_a_index = BM_elem_index_get(l_a); const MLoopUV *luv_a = BM_ELEM_CD_GET_VOID_P(l_a, cd_loop_uv_offset); const float uv_a[2] = {luv_a->uv[0], luv_a->uv[1] / params->aspect_y}; @@ -225,7 +225,7 @@ static void edgetag_add_adjacent_uv(HeapSimple *heap, const struct BMCalcPathUVParams *params) { BLI_assert(params->aspect_y != 0.0f); - const uint cd_loop_uv_offset = params->cd_loop_uv_offset; + const int 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); @@ -462,7 +462,7 @@ static void facetag_add_adjacent_uv(HeapSimple *heap, const float aspect_v2[2], const struct BMCalcPathUVParams *params) { - const uint cd_loop_uv_offset = params->cd_loop_uv_offset; + const int cd_loop_uv_offset = params->cd_loop_uv_offset; const int f_a_index = BM_elem_index_get(f_a); /* Loop over faces of face, but do so by first looping over loops. */ diff --git a/source/blender/bmesh/tools/bmesh_path_uv.h b/source/blender/bmesh/tools/bmesh_path_uv.h index d7b5faa70e5..ebfedba70bb 100644 --- a/source/blender/bmesh/tools/bmesh_path_uv.h +++ b/source/blender/bmesh/tools/bmesh_path_uv.h @@ -9,7 +9,7 @@ struct BMCalcPathUVParams { uint use_topology_distance : 1; uint use_step_face : 1; - uint cd_loop_uv_offset; + int cd_loop_uv_offset; float aspect_y; }; |