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:
authorHans Goudey <h.goudey@me.com>2022-06-08 11:42:21 +0300
committerHans Goudey <h.goudey@me.com>2022-06-08 11:48:19 +0300
commit6eea5f70e3b79e3c6683b7bc0e3e2998b67955d6 (patch)
tree94cce89b472021d174349477303a3faeab9cb73d /source/blender/bmesh/intern
parent1af652d42eb917e257d0f4f2773258f4f6ad2a45 (diff)
Attributes: Use names instead of layers for some functions
This mirrors the C++ attribute API better, separates the implementation of attributes from CustomData slightly, and makes functions simpler, clearer, and safer. Also fix an issue with removing an attribute caused by 97712b018df71c meant the first attribute with the given type was removed instead of the attribute with the given name.
Diffstat (limited to 'source/blender/bmesh/intern')
-rw-r--r--source/blender/bmesh/intern/bmesh_interp.c21
-rw-r--r--source/blender/bmesh/intern/bmesh_interp.h4
2 files changed, 25 insertions, 0 deletions
diff --git a/source/blender/bmesh/intern/bmesh_interp.c b/source/blender/bmesh/intern/bmesh_interp.c
index 2f5827bdc4c..0c3db31dd1f 100644
--- a/source/blender/bmesh/intern/bmesh_interp.c
+++ b/source/blender/bmesh/intern/bmesh_interp.c
@@ -894,6 +894,27 @@ void BM_data_layer_free(BMesh *bm, CustomData *data, int type)
}
}
+bool BM_data_layer_free_named(BMesh *bm, CustomData *data, const char *name)
+{
+ CustomData olddata = *data;
+ olddata.layers = (olddata.layers) ? MEM_dupallocN(olddata.layers) : NULL;
+
+ /* the pool is now owned by olddata and must not be shared */
+ data->pool = NULL;
+
+ const bool has_layer = CustomData_free_layer_named(data, name, 0);
+
+ if (has_layer) {
+ update_data_blocks(bm, &olddata, data);
+ }
+
+ if (olddata.layers) {
+ MEM_freeN(olddata.layers);
+ }
+
+ return has_layer;
+}
+
void BM_data_layer_free_n(BMesh *bm, CustomData *data, int type, int n)
{
CustomData olddata;
diff --git a/source/blender/bmesh/intern/bmesh_interp.h b/source/blender/bmesh/intern/bmesh_interp.h
index a2f1dfc706d..2cf9dffceec 100644
--- a/source/blender/bmesh/intern/bmesh_interp.h
+++ b/source/blender/bmesh/intern/bmesh_interp.h
@@ -59,6 +59,10 @@ void BM_data_interp_face_vert_edge(
void BM_data_layer_add(BMesh *bm, CustomData *data, int type);
void BM_data_layer_add_named(BMesh *bm, CustomData *data, int type, const char *name);
void BM_data_layer_free(BMesh *bm, CustomData *data, int type);
+/**
+ * Remove a named custom data layer, if it existed. Return true if the layer was removed.
+ */
+bool BM_data_layer_free_named(BMesh *bm, CustomData *data, const char *name);
void BM_data_layer_free_n(BMesh *bm, CustomData *data, int type, int n);
void BM_data_layer_copy(BMesh *bm, CustomData *data, int type, int src_n, int dst_n);