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-07-24 03:59:59 +0300
committerHans Goudey <h.goudey@me.com>2022-07-24 03:59:59 +0300
commitc94c0d988a5640ab7c6fb815462792dcf8dd863b (patch)
tree4e8d03520ec1f9a7ef4ae0236a6d93ea13fae114 /source/blender/blenkernel/intern/attribute.cc
parent0c3851d31fa89642797f00da179ca91702c28697 (diff)
Fix: Removing attributes from UI invalidates caches
Use the new attribute API to implement the attribute remove function used by RNA, except for BMesh attributes. Currently, removing curve attributes from the panel in the property editor does not mark the relevant caches dirty (for example, the cache of curve type counts), because that behavior is implemented with the new attribute API. Also, eventually we want to merge the two APIs, and removing an attribute is the first function that can be partially implemented with the new API. Differential Revision: https://developer.blender.org/D15495
Diffstat (limited to 'source/blender/blenkernel/intern/attribute.cc')
-rw-r--r--source/blender/blenkernel/intern/attribute.cc43
1 files changed, 36 insertions, 7 deletions
diff --git a/source/blender/blenkernel/intern/attribute.cc b/source/blender/blenkernel/intern/attribute.cc
index 030e4941874..b277fc39caf 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -8,6 +8,7 @@
*/
#include <cstring>
+#include <optional>
#include "MEM_guardedalloc.h"
@@ -24,7 +25,7 @@
#include "BKE_attribute.h"
#include "BKE_attribute.hh"
-#include "BKE_curves.h"
+#include "BKE_curves.hh"
#include "BKE_customdata.h"
#include "BKE_editmesh.h"
#include "BKE_pointcloud.h"
@@ -89,6 +90,36 @@ static void get_domains(const ID *id, DomainInfo info[ATTR_DOMAIN_NUM])
}
}
+namespace blender::bke {
+
+static std::optional<blender::bke::MutableAttributeAccessor> get_attribute_accessor_for_write(
+ ID &id)
+{
+ switch (GS(id.name)) {
+ case ID_ME: {
+ Mesh &mesh = reinterpret_cast<Mesh &>(id);
+ /* The attribute API isn't implemented for BMesh, so edit mode meshes are not supported. */
+ BLI_assert(mesh.edit_mesh == nullptr);
+ return mesh_attributes_for_write(mesh);
+ }
+ case ID_PT: {
+ PointCloud &pointcloud = reinterpret_cast<PointCloud &>(id);
+ return pointcloud_attributes_for_write(pointcloud);
+ }
+ case ID_CV: {
+ Curves &curves_id = reinterpret_cast<Curves &>(id);
+ CurvesGeometry &curves = CurvesGeometry::wrap(curves_id.geometry);
+ return curves.attributes_for_write();
+ }
+ default: {
+ BLI_assert_unreachable();
+ return {};
+ }
+ }
+}
+
+} // namespace blender::bke
+
bool BKE_id_attributes_supported(const ID *id)
{
DomainInfo info[ATTR_DOMAIN_NUM];
@@ -242,6 +273,7 @@ CustomDataLayer *BKE_id_attribute_duplicate(ID *id, const char *name, ReportList
bool BKE_id_attribute_remove(ID *id, const char *name, ReportList *reports)
{
+ using namespace blender::bke;
if (BKE_id_attribute_required(id, name)) {
BKE_report(reports, RPT_ERROR, "Attribute is required and can't be removed");
return false;
@@ -266,12 +298,9 @@ bool BKE_id_attribute_remove(ID *id, const char *name, ReportList *reports)
ATTR_FALLTHROUGH;
}
default:
- for (const int domain : IndexRange(ATTR_DOMAIN_NUM)) {
- if (CustomData *data = info[domain].customdata) {
- if (CustomData_free_layer_named(data, name, info[domain].length)) {
- return true;
- }
- }
+ if (std::optional<MutableAttributeAccessor> attributes = get_attribute_accessor_for_write(
+ *id)) {
+ return attributes->remove(name);
}
return false;
}