Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-01-18 13:44:08 +0300
committerCampbell Barton <campbell@blender.org>2022-01-19 06:30:10 +0300
commit71879d665d69bd1e96dab0dc089785a43d1d42fd (patch)
treed136a9ea5154d00744a36e5163073c711c7958c8 /source/blender/bmesh/intern/bmesh_construct.c
parentee6507f2b1d776099e199a31a3af0f09d2fbba74 (diff)
BMesh: improve handling of custom-data flag (Mesh.cd_flag)
Code that handled merging & initializing custom-data from other meshes sometimes missed checks for this flag, causing bevel weights to lost when the mesh was converted to a BMesh. The following changes are a more general fix for T94197. - Add BM_mesh_copy_init_customdata_from_mesh_array which initializes custom-data from multiple meshes at once. As well as initializing custom-data layers from Mesh.cd_flag. This isn't essential for boolean, however it avoids the overhead of resizing custom-data layers. - Loading mesh data into a BMesh now respects Mesh.cd_flag instead of only checking if the BMesh custom-data-layer exists. Without this, the order of meshes passed to BM_mesh_bm_from_me could give different (incorrect) results. - Copying mesh data now copies `cd_flag` too. This is a precaution as in my tests evaluating modifiers these values always matched. Nevertheless it's correct to copy this value as custom-data it's self is being copied.
Diffstat (limited to 'source/blender/bmesh/intern/bmesh_construct.c')
-rw-r--r--source/blender/bmesh/intern/bmesh_construct.c42
1 files changed, 35 insertions, 7 deletions
diff --git a/source/blender/bmesh/intern/bmesh_construct.c b/source/blender/bmesh/intern/bmesh_construct.c
index 5a9d1ba7bc4..a127089ad2c 100644
--- a/source/blender/bmesh/intern/bmesh_construct.c
+++ b/source/blender/bmesh/intern/bmesh_construct.c
@@ -510,23 +510,51 @@ static BMFace *bm_mesh_copy_new_face(
return f_new;
}
-void BM_mesh_copy_init_customdata_from_mesh(BMesh *bm_dst,
- const Mesh *me_src,
- const BMAllocTemplate *allocsize)
+void BM_mesh_copy_init_customdata_from_mesh_array(BMesh *bm_dst,
+ const Mesh *me_src_array[],
+ const int me_src_array_len,
+ const BMAllocTemplate *allocsize)
+
{
if (allocsize == NULL) {
allocsize = &bm_mesh_allocsize_default;
}
- 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);
+ 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(&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);
+ }
+ 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);
+ }
+
+ 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,
+ const Mesh *me_src,
+ const BMAllocTemplate *allocsize)
+{
+ BM_mesh_copy_init_customdata_from_mesh_array(bm_dst, &me_src, 1, allocsize);
}
void BM_mesh_copy_init_customdata(BMesh *bm_dst, BMesh *bm_src, const BMAllocTemplate *allocsize)