[Bf-blender-cvs] [dba4f303280] temp_bmesh_multires: Sculpt dyntopo: Added (optional) support for unique mesh id tracking in bmesh
Joseph Eagar
noreply at git.blender.org
Sun Jun 27 06:35:00 CEST 2021
Commit: dba4f303280f513bca07f1219ca475f226ace074
Author: Joseph Eagar
Date: Sat Jun 26 18:24:00 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rBdba4f303280f513bca07f1219ca475f226ace074
Sculpt dyntopo: Added (optional) support for unique mesh id tracking in
bmesh
* System is per element type. So you can have unique ids for verts and
faces, but not edges and loops.
* Supports an optional id to element lookup table.
* Uses single id space for all elements
* Added a new CD_FLAG_ELEM_NOCOPY flag to tell
customdata_bmesh_copy_data to ignore that layer.
* IDs are stored as a temporary customdata layer with
CD_FLAG_ELEM_NOCOPY set.
===================================================================
M source/blender/blenkernel/BKE_customdata.h
M source/blender/blenkernel/intern/customdata.c
M source/blender/blenkernel/intern/pbvh_bmesh.c
M source/blender/bmesh/bmesh_class.h
M source/blender/bmesh/intern/bmesh_construct.c
M source/blender/bmesh/intern/bmesh_core.c
M source/blender/bmesh/intern/bmesh_core.h
M source/blender/bmesh/intern/bmesh_interp.c
M source/blender/bmesh/intern/bmesh_log.c
M source/blender/bmesh/intern/bmesh_mesh.c
M source/blender/bmesh/intern/bmesh_mesh.h
M source/blender/bmesh/intern/bmesh_mesh_convert.c
M source/blender/bmesh/intern/bmesh_mesh_convert.h
M source/blender/bmesh/intern/bmesh_mesh_duplicate.c
M source/blender/bmesh/intern/bmesh_structure.h
M source/blender/bmesh/operators/bmo_dupe.c
M source/blender/editors/sculpt_paint/sculpt_dyntopo.c
M source/blender/editors/sculpt_paint/sculpt_undo.c
M source/blender/makesdna/DNA_customdata_types.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index 1958e414bad..b9067ec951e 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -272,11 +272,15 @@ void CustomData_copy_data_named(const struct CustomData *source,
int count);
void CustomData_copy_elements(int type, void *src_data_ofs, void *dst_data_ofs, int count);
+// ignores CD_MESH_ID layer if it exists
void CustomData_bmesh_swap_data(struct CustomData *source,
struct CustomData *dest,
void *src_block,
void **dest_block);
+// simple pointer swap; will unswaps ids if a CD_MESH_ID layer exists
+void CustomData_bmesh_swap_data_simple(CustomData *data, void **block1, void **block2);
+
void CustomData_bmesh_copy_data(const struct CustomData *source,
struct CustomData *dest,
void *src_block,
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index cdf3bf09b64..330ea94f0c0 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1564,6 +1564,30 @@ static void layerDynTopoVert_interp(
mv->origmask = origmask;
}
+static void layerCopy_noop(const void *UNUSED(source), void *UNUSED(dest), int UNUSED(count))
+{
+ // do nothing
+}
+
+static void layerInterp_noop(const void **UNUSED(sources),
+ const float *UNUSED(weights),
+ const float *UNUSED(sub_weights),
+ int UNUSED(count),
+ void *UNUSED(dest))
+{
+ // do nothing
+}
+
+static void layerDefault_mesh_id(void *data, int count)
+{
+ int *val = (int *)data;
+
+ for (int i = 0; i < count; i++) {
+ // val[i] = -1;
+ val[i] = 0;
+ }
+}
+
static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
/* 0: CD_MVERT */
{sizeof(MVert), "MVert", 1, NULL, NULL, NULL, NULL, NULL, NULL},
@@ -1945,13 +1969,24 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
NULL,
NULL,
NULL},
+ /* 51 CD_DYNTOPO_VERT */
{sizeof(MDynTopoVert),
- NULL, // flag singleton layer
+ "MDynTopoVert",
1,
- N_("DynTopoVert"),
+ NULL, // flag singleton layer
layerDynTopoVert_copy,
NULL,
- layerDynTopoVert_interp}};
+ layerDynTopoVert_interp},
+ /*52 CD_MESH_ID */
+ {sizeof(unsigned int),
+ "MIntProperty",
+ 1,
+ NULL, // flag singleton layer
+ layerCopy_propInt,
+ NULL,
+ layerInterp_noop,
+ NULL,
+ layerDefault_mesh_id}};
static const char *LAYERTYPENAMES[CD_NUMTYPES] = {
/* 0-4 */ "CDMVert",
@@ -3829,6 +3864,10 @@ static void CustomData_bmesh_set_default_n(CustomData *data, void **block, int n
int offset = data->layers[n].offset;
const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[n].type);
+ if (data->layers[n].flag & CD_FLAG_ELEM_NOCOPY) {
+ return;
+ }
+
if (typeInfo->set_default) {
typeInfo->set_default(POINTER_OFFSET(*block, offset), 1);
}
@@ -3848,6 +3887,26 @@ void CustomData_bmesh_set_default(CustomData *data, void **block)
}
}
+void CustomData_bmesh_swap_data_simple(CustomData *data, void **block1, void **block2)
+{
+ int cd_id = data->typemap[CD_MESH_ID];
+ cd_id = cd_id >= 0 ? data->layers[cd_id].offset : -1;
+
+ void *tmp = *block1;
+ *block1 = *block2;
+ *block2 = tmp;
+
+ // unswap ids if they exist
+ if (cd_id != -1 && *block1 && *block2) {
+ int *id1 = (int *)(((char *)*block1) + cd_id);
+ int *id2 = (int *)(((char *)*block2) + cd_id);
+
+ tmp = *id1;
+ *id1 = *id2;
+ *id2 = tmp;
+ }
+}
+
void CustomData_bmesh_swap_data(CustomData *source,
CustomData *dest,
void *src_block,
@@ -3875,6 +3934,11 @@ void CustomData_bmesh_swap_data(CustomData *source,
dest_i_start++;
}
+ if (source->layers[src_i].type == CD_MESH_ID) {
+ // do not swap ids
+ continue;
+ }
+
/* if there are no more dest layers, we're done */
if (dest_i_start >= dest->totlayer) {
return;
@@ -3961,6 +4025,10 @@ void CustomData_bmesh_copy_data_exclude_by_type(const CustomData *source,
/* if we found a matching layer, copy the data */
if (STREQ(dest->layers[dest_i].name, source->layers[src_i].name)) {
if (no_mask || ((CD_TYPE_AS_MASK(dest->layers[dest_i].type) & mask_exclude) == 0)) {
+ if (dest->layers[dest_i].flag & CD_FLAG_ELEM_NOCOPY) {
+ break;
+ }
+
const void *src_data = POINTER_OFFSET(src_block, source->layers[src_i].offset);
void *dest_data = POINTER_OFFSET(*dest_block, dest->layers[dest_i].offset);
const LayerTypeInfo *typeInfo = layerType_getInfo(source->layers[src_i].type);
@@ -4251,12 +4319,12 @@ void CustomData_bmesh_interp_n(CustomData *data,
typeInfo->interp(src_blocks_ofs, weights, sub_weights, count, dst_block_ofs);
}
-void CustomData_bmesh_interp(CustomData *data,
- const void **src_blocks,
- const float *weights,
- const float *sub_weights,
- int count,
- void *dst_block)
+ATTR_NO_OPT void CustomData_bmesh_interp(CustomData *data,
+ const void **src_blocks,
+ const float *weights,
+ const float *sub_weights,
+ int count,
+ void *dst_block)
{
if (count <= 0) {
return;
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index a3330a409f9..13333dce8f5 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -668,8 +668,7 @@ static BMVert *pbvh_bmesh_vert_create(PBVH *pbvh,
BLI_assert((pbvh->totnode == 1 || node_index) && node_index <= pbvh->totnode);
/* avoid initializing customdata because its quite involved */
- BMVert *v = BM_vert_create(pbvh->bm, co, NULL, BM_CREATE_SKIP_CD);
- CustomData_bmesh_set_default(&pbvh->bm->vdata, &v->head.data);
+ BMVert *v = BM_vert_create(pbvh->bm, co, NULL, BM_CREATE_NOP);
if (v_example) {
v->head.hflag = v_example->head.hflag;
@@ -3757,7 +3756,7 @@ CLANG_OPT_BUG static bool cleanup_valence_3_4(PBVH *pbvh,
f1->no, f1->l_first->v->co, f1->l_first->next->v->co, f1->l_first->prev->v->co);
}
else {
- //printf("eek1!\n");
+ // printf("eek1!\n");
}
if (val == 4 && vs[0] != vs[2] && vs[2] != vs[3] && vs[0] != vs[3]) {
@@ -3766,7 +3765,8 @@ CLANG_OPT_BUG static bool cleanup_valence_3_4(PBVH *pbvh,
vs[2] = ls[3]->v;
BMFace *f2 = pbvh_bmesh_face_create(pbvh, n, vs, NULL, v->e->l->f, false, false);
- SWAP(void *, f2->l_first->prev->head.data, ls[3]->head.data);
+ CustomData_bmesh_swap_data_simple(
+ &pbvh->bm->pdata, &f2->l_first->prev->head.data, &ls[3]->head.data);
CustomData_bmesh_copy_data(
&pbvh->bm->ldata, &pbvh->bm->ldata, ls[0]->head.data, &f2->l_first->head.data);
@@ -3778,13 +3778,16 @@ CLANG_OPT_BUG static bool cleanup_valence_3_4(PBVH *pbvh,
BM_log_face_added(pbvh->bm_log, f2);
}
else {
- //printf("eek2!\n");
+ // printf("eek2!\n");
}
if (f1) {
- SWAP(void *, f1->l_first->head.data, ls[0]->head.data);
- SWAP(void *, f1->l_first->next->head.data, ls[1]->head.data);
- SWAP(void *, f1->l_first->prev->head.data, ls[2]->head.data);
+ CustomData_bmesh_swap_data_simple(
+ &pbvh->bm->ldata, &f1->l_first->head.data, &ls[0]->head.data);
+ CustomData_bmesh_swap_data_simple(
+ &pbvh->bm->ldata, &f1->l_first->next->head.data, &ls[1]->head.data);
+ CustomData_bmesh_swap_data_simple(
+ &pbvh->bm->ldata, &f1->l_first->prev->head.data, &ls[2]->head.data);
BM_log_face_added(pbvh->bm_log, f1);
}
@@ -5142,7 +5145,7 @@ BMesh *BKE_pbvh_reorder_bmesh(PBVH *pbvh)
for (int i = 0; i < pbvh->totnode; i++) {
for (int j = 0; j < nodedata[i].totvert; j++) {
BMVert *v1 = nodedata[i].verts[j];
- BMVert *v2 = BM_vert_create(bm2, v1->co, NULL, BM_CREATE_SKIP_CD);
+ BMVert *v2 = BM_vert_create(bm2, v1->co, NULL, BM_CREATE_NOP);
BM_elem_attrs_copy_ex(pbvh->bm, bm2, v1, v2, 0, 0L);
v2->head.index = v1->head.index = BLI_array_len(verts);
@@ -5154,7 +5157,7 @@ BMesh *BKE_pbvh_reorder_bmesh(PBVH *pbvh)
for (int j = 0; j < nodedata[i].totedge; j++) {
BMEdge *e1 = nodedata[i].edges[j];
BMEdge *e2 = BM_edge_create(
- bm2, verts[e1->v1->head.index], verts[e1->v2->head.index], NULL, BM_CREATE_SKIP_CD);
+ bm2, verts[e1->v1->head.index], verts[e1->v2->head.index], NULL, BM_CREATE_NOP);
BM_elem_attrs_copy_ex(pbvh->bm, bm2, e1, e2, 0, 0L);
e2->head.index = e1->head.index = BLI_array_len(edges);
@@ -5183,7 +5186,7 @@ BMesh *BKE_pbvh_reorder_bmesh(PBVH *pbvh)
totloop++;
} while (l1 != f1->l_first);
- BMFace *f2 = BM_face_create(bm2, fvs, fes, totloop, NULL, BM_CREATE_SKIP_CD);
+ BMFace *f2 = BM_face_create(bm2, fvs, fes, totloop, NULL, BM_CREATE_NOP);
f1->head.index = f2->head.index = BLI_array_len(faces);
BLI_array_append(faces, f2);
diff --git a/source/blender/bmesh/bmesh_class.h b/source/blender/bmesh/bmesh_class.h
index 727c2dd2ea9..981d9d25696 100644
--- a/source/blender/bmesh/bmesh_class.h
+++ b/source/blender/bmesh/bmesh_class.h
@@ -295,6 +295,8 @@ typedef struct BMFlagLayer {
// #pragma GCC diagnostic ignored "-Wpadded"
+struct RangeTreeUInt;
+
typedef struct BMesh {
int totvert, totedge, totloop, totface;
int totvertsel, totedgesel, totfacesel;
@@ -378,11 +380,26 @@ typedef s
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list