[Bf-blender-cvs] [b7878a4d457] master: Cleanup: Move bmesh_mesh_convert.c to C++
Hans Goudey
noreply at git.blender.org
Sat Jan 22 06:53:29 CET 2022
Commit: b7878a4d457a59d4a42f8ac0f428ea336562d75a
Author: Hans Goudey
Date: Fri Jan 21 23:53:15 2022 -0600
Branches: master
https://developer.blender.org/rBb7878a4d457a59d4a42f8ac0f428ea336562d75a
Cleanup: Move bmesh_mesh_convert.c to C++
Useful for a simpler bug fix, code clarity,
and easier possible optimizations in the future.
===================================================================
M source/blender/bmesh/CMakeLists.txt
R086 source/blender/bmesh/intern/bmesh_mesh_convert.c source/blender/bmesh/intern/bmesh_mesh_convert.cc
===================================================================
diff --git a/source/blender/bmesh/CMakeLists.txt b/source/blender/bmesh/CMakeLists.txt
index f57d4da4d26..e2ed005cf9e 100644
--- a/source/blender/bmesh/CMakeLists.txt
+++ b/source/blender/bmesh/CMakeLists.txt
@@ -98,7 +98,7 @@ set(SRC
intern/bmesh_marking.h
intern/bmesh_mesh.c
intern/bmesh_mesh.h
- intern/bmesh_mesh_convert.c
+ intern/bmesh_mesh_convert.cc
intern/bmesh_mesh_convert.h
intern/bmesh_mesh_debug.c
intern/bmesh_mesh_debug.h
diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.c b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
similarity index 86%
rename from source/blender/bmesh/intern/bmesh_mesh_convert.c
rename to source/blender/bmesh/intern/bmesh_mesh_convert.cc
index a7dd5be5cbd..b404c412160 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_convert.c
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
@@ -107,9 +107,9 @@ void BM_mesh_cd_flag_ensure(BMesh *bm, Mesh *mesh, const char cd_flag)
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 != NULL);
- BLI_assert(bm->edata.totlayer == 0 || bm->edata.pool != NULL);
- BLI_assert(bm->pdata.totlayer == 0 || bm->pdata.pool != NULL);
+ 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)) {
@@ -178,8 +178,8 @@ char BM_mesh_cd_flag_from_bmesh(BMesh *bm)
static BMFace *bm_face_create_from_mpoly(
MPoly *mp, MLoop *ml, BMesh *bm, BMVert **vtable, BMEdge **etable)
{
- BMVert **verts = BLI_array_alloca(verts, mp->totloop);
- BMEdge **edges = BLI_array_alloca(edges, mp->totloop);
+ BMVert **verts = (BMVert **)BLI_array_alloca(verts, mp->totloop);
+ BMEdge **edges = (BMEdge **)BLI_array_alloca(edges, mp->totloop);
int j;
for (j = 0; j < mp->totloop; j++, ml++) {
@@ -187,7 +187,7 @@ static BMFace *bm_face_create_from_mpoly(
edges[j] = etable[ml->e];
}
- return BM_face_create(bm, verts, edges, mp->totloop, NULL, BM_CREATE_SKIP_CD);
+ return BM_face_create(bm, verts, edges, mp->totloop, nullptr, BM_CREATE_SKIP_CD);
}
void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshParams *params)
@@ -198,11 +198,11 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar
MEdge *medge;
MLoop *mloop;
MPoly *mp;
- KeyBlock *actkey, *block;
- BMVert *v, **vtable = NULL;
- BMEdge *e, **etable = NULL;
- BMFace *f, **ftable = NULL;
- float(*keyco)[3] = NULL;
+ KeyBlock *actkey;
+ BMVert *v, **vtable = nullptr;
+ BMEdge *e, **etable = nullptr;
+ BMFace *f, **ftable = nullptr;
+ float(*keyco)[3] = nullptr;
int totloops, i;
CustomData_MeshMasks mask = CD_MASK_BMESH;
CustomData_MeshMasks_update(&mask, ¶ms->cd_mask_extra);
@@ -225,7 +225,7 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar
/* Only copy normals to the new BMesh if they are not already dirty. This avoids unnecessary
* work, but also accessing normals on an incomplete mesh, for example when restoring undo steps
* in edit mode. */
- const float(*vert_normals)[3] = NULL;
+ const float(*vert_normals)[3] = nullptr;
if (!BKE_mesh_vertex_normals_are_dirty(me)) {
vert_normals = BKE_mesh_vertex_normals_ensure(me);
}
@@ -246,7 +246,7 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar
/* -------------------------------------------------------------------- */
/* Shape Key */
int tot_shape_keys = 0;
- if (me->key != NULL && DEG_is_original_id(&me->id)) {
+ if (me->key != nullptr && DEG_is_original_id(&me->id)) {
/* Evaluated meshes can be topologically inconsistent with their shape keys.
* Shape keys are also already integrated into the state of the evaluated
* mesh, so considering them here would kind of apply them twice. */
@@ -273,20 +273,20 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar
if (is_new == false) {
tot_shape_keys = min_ii(tot_shape_keys, CustomData_number_of_layers(&bm->vdata, CD_SHAPEKEY));
}
- const float(**shape_key_table)[3] = tot_shape_keys ?
- BLI_array_alloca(shape_key_table, tot_shape_keys) :
- NULL;
+ const float(**shape_key_table)[3] = tot_shape_keys ? (const float(**)[3])BLI_array_alloca(
+ shape_key_table, tot_shape_keys) :
+ nullptr;
if ((params->active_shapekey != 0) && tot_shape_keys > 0) {
- actkey = BLI_findlink(&me->key->block, params->active_shapekey - 1);
+ actkey = static_cast<KeyBlock *>(BLI_findlink(&me->key->block, params->active_shapekey - 1));
}
else {
- actkey = NULL;
+ actkey = nullptr;
}
if (is_new) {
if (tot_shape_keys || params->add_key_index) {
- CustomData_add_layer(&bm->vdata, CD_SHAPE_KEYINDEX, CD_ASSIGN, NULL, 0);
+ CustomData_add_layer(&bm->vdata, CD_SHAPE_KEYINDEX, CD_ASSIGN, nullptr, 0);
}
}
@@ -301,26 +301,28 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar
__func__);
me->key->uidgen = 1;
- for (block = me->key->block.first; block; block = block->next) {
+ LISTBASE_FOREACH (KeyBlock *, block, &me->key->block) {
block->uid = me->key->uidgen++;
}
}
}
if (actkey && actkey->totelem == me->totvert) {
- keyco = params->use_shapekey ? actkey->data : NULL;
+ keyco = params->use_shapekey ? static_cast<float(*)[3]>(actkey->data) : nullptr;
if (is_new) {
bm->shapenr = params->active_shapekey;
}
}
- for (i = 0, block = me->key->block.first; i < tot_shape_keys; block = block->next, i++) {
+ KeyBlock *block;
+ for (i = 0, block = static_cast<KeyBlock *>(me->key->block.first); i < tot_shape_keys;
+ block = block->next, i++) {
if (is_new) {
- CustomData_add_layer_named(&bm->vdata, CD_SHAPEKEY, CD_ASSIGN, NULL, 0, block->name);
+ CustomData_add_layer_named(&bm->vdata, CD_SHAPEKEY, CD_ASSIGN, nullptr, 0, block->name);
int j = CustomData_get_layer_index_n(&bm->vdata, CD_SHAPEKEY, i);
bm->vdata.layers[j].uid = block->uid;
}
- shape_key_table[i] = (const float(*)[3])block->data;
+ shape_key_table[i] = static_cast<const float(*)[3]>(block->data);
}
}
@@ -349,10 +351,10 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar
CustomData_get_offset(&bm->vdata, CD_SHAPE_KEYINDEX) :
-1;
- vtable = MEM_mallocN(sizeof(BMVert **) * me->totvert, __func__);
+ vtable = static_cast<BMVert **>(MEM_mallocN(sizeof(BMVert **) * me->totvert, __func__));
for (i = 0, mvert = me->mvert; i < me->totvert; i++, mvert++) {
- v = vtable[i] = BM_vert_create(bm, keyco ? keyco[i] : mvert->co, NULL, BM_CREATE_SKIP_CD);
+ v = vtable[i] = BM_vert_create(bm, keyco ? keyco[i] : mvert->co, nullptr, BM_CREATE_SKIP_CD);
BM_elem_index_set(v, i); /* set_ok */
/* Transfer flag. */
@@ -381,7 +383,7 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar
/* Set shape-key data. */
if (tot_shape_keys) {
- float(*co_dst)[3] = BM_ELEM_CD_GET_VOID_P(v, cd_shape_key_offset);
+ float(*co_dst)[3] = (float(*)[3])BM_ELEM_CD_GET_VOID_P(v, cd_shape_key_offset);
for (int j = 0; j < tot_shape_keys; j++, co_dst++) {
copy_v3_v3(*co_dst, shape_key_table[j][i]);
}
@@ -391,12 +393,12 @@ 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. */
}
- etable = MEM_mallocN(sizeof(BMEdge **) * me->totedge, __func__);
+ etable = static_cast<BMEdge **>(MEM_mallocN(sizeof(BMEdge **) * me->totedge, __func__));
medge = me->medge;
for (i = 0; i < me->totedge; i++, medge++) {
e = etable[i] = BM_edge_create(
- bm, vtable[medge->v1], vtable[medge->v2], NULL, BM_CREATE_SKIP_CD);
+ bm, vtable[medge->v1], vtable[medge->v2], nullptr, BM_CREATE_SKIP_CD);
BM_elem_index_set(e, i); /* set_ok */
/* Transfer flags. */
@@ -423,7 +425,7 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar
/* Only needed for selection. */
if (me->mselect && me->totselect != 0) {
- ftable = MEM_mallocN(sizeof(BMFace **) * me->totpoly, __func__);
+ ftable = static_cast<BMFace **>(MEM_mallocN(sizeof(BMFace **) * me->totpoly, __func__));
}
mloop = me->mloop;
@@ -433,11 +435,11 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar
BMLoop *l_first;
f = bm_face_create_from_mpoly(mp, mloop + mp->loopstart, bm, vtable, etable);
- if (ftable != NULL) {
+ if (ftable != nullptr) {
ftable[i] = f;
}
- if (UNLIKELY(f == NULL)) {
+ if (UNLIKELY(f == nullptr)) {
printf(
"%s: Warning! Bad face in mesh"
" \"%s\" at index %d!, skipping\n",
@@ -508,9 +510,9 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar
continue;
}
- if (*ele_p != NULL) {
+ if (*ele_p != nullptr) {
BM_select_history_store_notest(bm, *ele_p);
- *ele_p = NULL;
+ *ele_p = nullptr;
}
}
}
@@ -531,7 +533,7 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar
static BMVert **bm_to_mesh_vertex_map(BMesh *bm, int ototvert)
{
const int cd_shape_keyindex_offset = CustomData_get_offset(&bm->vdata, CD_SHAPE_KEYINDEX);
- BMVert **vertMap = NULL;
+ BMVert **vertMap = nullptr;
BMVert *eve;
int i = 0;
BMIter iter;
@@ -539,7 +541,7 @@ static BMVert **bm_to_mesh_vertex_map(BMesh *bm, int ototvert
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list