[Bf-blender-cvs] [a1cc0d3af3e] temp-sculpt-colors: temp-sculpt-colors: fix buf in next_color_attr
Joseph Eagar
noreply at git.blender.org
Wed Nov 17 13:19:04 CET 2021
Commit: a1cc0d3af3e87961fb633dc654dabfc8a8516694
Author: Joseph Eagar
Date: Wed Nov 17 04:18:49 2021 -0800
Branches: temp-sculpt-colors
https://developer.blender.org/rBa1cc0d3af3e87961fb633dc654dabfc8a8516694
temp-sculpt-colors: fix buf in next_color_attr
===================================================================
M source/blender/editors/geometry/geometry_attributes.c
===================================================================
diff --git a/source/blender/editors/geometry/geometry_attributes.c b/source/blender/editors/geometry/geometry_attributes.c
index e72737bd73c..b991855b6da 100644
--- a/source/blender/editors/geometry/geometry_attributes.c
+++ b/source/blender/editors/geometry/geometry_attributes.c
@@ -30,6 +30,8 @@
#include "DEG_depsgraph.h"
+#include "DNA_mesh_types.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -89,7 +91,7 @@ static int geometry_attribute_add_exec(bContext *C, wmOperator *op)
CustomDataType type = (CustomDataType)RNA_enum_get(op->ptr, "data_type");
AttributeDomain domain = (AttributeDomain)RNA_enum_get(op->ptr, "domain");
CustomDataLayer *layer = BKE_id_attribute_new(
- id, name, type, domain, CD_MASK_PROP_ALL, op->reports);
+ id, name, type, CD_MASK_PROP_ALL, domain, op->reports);
if (layer == NULL) {
return OPERATOR_CANCELLED;
@@ -103,6 +105,38 @@ static int geometry_attribute_add_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
+static void next_color_attr(struct ID *id, CustomDataLayer *layer, bool is_render)
+{
+ AttributeRef *ref = is_render ? BKE_id_attributes_render_color_ref_p(id) :
+ BKE_id_attributes_active_color_ref_p(id);
+
+ if (!ref || layer != (is_render ? BKE_id_attributes_render_color_get(id) :
+ BKE_id_attributes_active_color_get(id))) {
+ return;
+ }
+
+ AttributeDomainMask domain_mask = ATTR_DOMAIN_MASK_POINT | ATTR_DOMAIN_MASK_CORNER;
+ CustomDataMask type_mask = CD_MASK_PROP_COLOR | CD_MASK_MLOOPCOL;
+
+ int length = BKE_id_attributes_length(id, domain_mask, type_mask);
+ int idx = BKE_id_attribute_index_from_ref(id, ref, domain_mask, type_mask);
+
+ if (idx == length - 1) {
+ idx = MAX2(idx - 1, 0);
+ }
+ else {
+ idx++;
+ }
+
+ BKE_id_attribute_ref_from_index(id, idx, domain_mask, type_mask, ref);
+}
+
+static void next_color_attrs(struct ID *id, CustomDataLayer *layer)
+{
+ next_color_attr(id, layer, false); /* active */
+ next_color_attr(id, layer, true); /* render */
+}
+
void GEOMETRY_OT_attribute_add(wmOperatorType *ot)
{
/* identifiers */
@@ -152,6 +186,8 @@ static int geometry_attribute_remove_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
+ next_color_attrs(id, layer);
+
if (!BKE_id_attribute_remove(id, layer, op->reports)) {
return OPERATOR_CANCELLED;
}
@@ -263,15 +299,12 @@ static int geometry_color_attribute_remove_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
+ next_color_attrs(id, layer);
+
if (!BKE_id_attribute_remove(id, layer, op->reports)) {
return OPERATOR_CANCELLED;
}
- int *active_index = BKE_id_attributes_active_index_p(id);
- if (*active_index > 0) {
- *active_index -= 1;
- }
-
DEG_id_tag_update(id, ID_RECALC_GEOMETRY);
WM_main_add_notifier(NC_GEOM | ND_DATA, id);
More information about the Bf-blender-cvs
mailing list