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:
authorJoseph Eagar <joeedh@gmail.com>2022-04-05 21:42:55 +0300
committerJoseph Eagar <joeedh@gmail.com>2022-04-05 21:42:55 +0300
commiteae36be372a6b16ee3e76eff0485a47da4f3c230 (patch)
treed1ca2dc30951e31f1b91eed6a4edfdfb0824bf1f /source/blender/makesrna/intern/rna_attribute.c
parenta3e122b9aec59fc303c2375a78183cfb8642c14f (diff)
Refactor: Unify vertex and sculpt colors into new
color attribute system. This commit removes sculpt colors from experimental status and unifies it with vertex colors. It introduces the concept of "color attributes", which are any attributes that represents colors. Color attributes can be represented with byte or floating-point numbers and can be stored in either vertices or face corners. Color attributes share a common namespace (so you can no longer have a floating-point sculpt color attribute and a byte vertex color attribute with the same name). Note: this commit does not include vertex paint mode, which is a separate patch, see: https://developer.blender.org/D14179 Differential Revision: https://developer.blender.org/D12587 Ref D12587
Diffstat (limited to 'source/blender/makesrna/intern/rna_attribute.c')
-rw-r--r--source/blender/makesrna/intern/rna_attribute.c179
1 files changed, 176 insertions, 3 deletions
diff --git a/source/blender/makesrna/intern/rna_attribute.c b/source/blender/makesrna/intern/rna_attribute.c
index f86383a6328..01266a26104 100644
--- a/source/blender/makesrna/intern/rna_attribute.c
+++ b/source/blender/makesrna/intern/rna_attribute.c
@@ -339,6 +339,12 @@ static int rna_Attributes_layer_skip(CollectionPropertyIterator *UNUSED(iter), v
return !(CD_TYPE_AS_MASK(layer->type) & CD_MASK_PROP_ALL);
}
+static int rna_Attributes_noncolor_layer_skip(CollectionPropertyIterator *UNUSED(iter), void *data)
+{
+ CustomDataLayer *layer = (CustomDataLayer *)data;
+ return !(CD_TYPE_AS_MASK(layer->type) & CD_MASK_COLOR_ALL) || (layer->flag & CD_FLAG_TEMPORARY);
+}
+
/* Attributes are spread over multiple domains in separate CustomData, we use repeated
* array iterators to loop over all. */
static void rna_AttributeGroup_next_domain(ID *id,
@@ -377,7 +383,34 @@ void rna_AttributeGroup_iterator_next(CollectionPropertyIterator *iter)
PointerRNA rna_AttributeGroup_iterator_get(CollectionPropertyIterator *iter)
{
- /* refine to the proper type */
+ /* Refine to the proper type. */
+ CustomDataLayer *layer = rna_iterator_array_get(iter);
+ StructRNA *type = srna_by_custom_data_layer_type(layer->type);
+ if (type == NULL) {
+ return PointerRNA_NULL;
+ }
+ return rna_pointer_inherit_refine(&iter->parent, type, layer);
+}
+
+void rna_AttributeGroup_color_iterator_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+ memset(&iter->internal.array, 0, sizeof(iter->internal.array));
+ rna_AttributeGroup_next_domain(ptr->owner_id, iter, rna_Attributes_noncolor_layer_skip);
+}
+
+void rna_AttributeGroup_color_iterator_next(CollectionPropertyIterator *iter)
+{
+ rna_iterator_array_next(iter);
+
+ if (!iter->valid) {
+ ID *id = iter->parent.owner_id;
+ rna_AttributeGroup_next_domain(id, iter, rna_Attributes_noncolor_layer_skip);
+ }
+}
+
+PointerRNA rna_AttributeGroup_color_iterator_get(CollectionPropertyIterator *iter)
+{
+ /* Refine to the proper type. */
CustomDataLayer *layer = rna_iterator_array_get(iter);
StructRNA *type = srna_by_custom_data_layer_type(layer->type);
if (type == NULL) {
@@ -386,9 +419,16 @@ PointerRNA rna_AttributeGroup_iterator_get(CollectionPropertyIterator *iter)
return rna_pointer_inherit_refine(&iter->parent, type, layer);
}
+int rna_AttributeGroup_color_length(PointerRNA *ptr)
+{
+ return BKE_id_attributes_length(ptr->owner_id,
+ ATTR_DOMAIN_MASK_POINT | ATTR_DOMAIN_MASK_CORNER,
+ CD_MASK_PROP_COLOR | CD_MASK_MLOOPCOL);
+}
+
int rna_AttributeGroup_length(PointerRNA *ptr)
{
- return BKE_id_attributes_length(ptr->owner_id, CD_MASK_PROP_ALL);
+ return BKE_id_attributes_length(ptr->owner_id, ATTR_DOMAIN_MASK_ALL, CD_MASK_PROP_ALL);
}
static int rna_AttributeGroup_active_index_get(PointerRNA *ptr)
@@ -424,7 +464,7 @@ static void rna_AttributeGroup_active_index_range(
PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax)
{
*min = 0;
- *max = BKE_id_attributes_length(ptr->owner_id, CD_MASK_PROP_ALL);
+ *max = BKE_id_attributes_length(ptr->owner_id, ATTR_DOMAIN_MASK_ALL, CD_MASK_PROP_ALL);
*softmin = *min;
*softmax = *max;
@@ -435,6 +475,98 @@ static void rna_AttributeGroup_update_active(Main *bmain, Scene *scene, PointerR
rna_Attribute_update_data(bmain, scene, ptr);
}
+static PointerRNA rna_AttributeGroup_active_color_get(PointerRNA *ptr)
+{
+ ID *id = ptr->owner_id;
+ CustomDataLayer *layer = BKE_id_attributes_active_color_get(id);
+
+ PointerRNA attribute_ptr;
+ RNA_pointer_create(id, &RNA_Attribute, layer, &attribute_ptr);
+ return attribute_ptr;
+}
+
+static void rna_AttributeGroup_active_color_set(PointerRNA *ptr,
+ PointerRNA attribute_ptr,
+ ReportList *UNUSED(reports))
+{
+ ID *id = ptr->owner_id;
+ CustomDataLayer *layer = attribute_ptr.data;
+
+ BKE_id_attributes_active_color_set(id, layer);
+}
+
+static int rna_AttributeGroup_active_color_index_get(PointerRNA *ptr)
+{
+ CustomDataLayer *layer = BKE_id_attributes_active_color_get(ptr->owner_id);
+
+ return BKE_id_attribute_to_index(
+ ptr->owner_id, layer, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL);
+}
+
+static void rna_AttributeGroup_active_color_index_set(PointerRNA *ptr, int value)
+{
+ CustomDataLayer *layer = BKE_id_attribute_from_index(
+ ptr->owner_id, value, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL);
+
+ if (!layer) {
+ fprintf(stderr, "%s: error setting active color index to %d\n", __func__, value);
+ return;
+ }
+
+ BKE_id_attributes_active_color_set(ptr->owner_id, layer);
+}
+
+static void rna_AttributeGroup_active_color_index_range(
+ PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax)
+{
+ *min = 0;
+ *max = BKE_id_attributes_length(ptr->owner_id, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL);
+
+ *softmin = *min;
+ *softmax = *max;
+}
+
+static void rna_AttributeGroup_update_active_color(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+ ID *id = ptr->owner_id;
+
+ /* Cheating way for importers to avoid slow updates. */
+ if (id->us > 0) {
+ DEG_id_tag_update(id, 0);
+ WM_main_add_notifier(NC_GEOM | ND_DATA, id);
+ }
+}
+
+static int rna_AttributeGroup_render_color_index_get(PointerRNA *ptr)
+{
+ CustomDataLayer *layer = BKE_id_attributes_render_color_get(ptr->owner_id);
+
+ return BKE_id_attribute_to_index(
+ ptr->owner_id, layer, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL);
+}
+
+static void rna_AttributeGroup_render_color_index_set(PointerRNA *ptr, int value)
+{
+ CustomDataLayer *layer = BKE_id_attribute_from_index(
+ ptr->owner_id, value, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL);
+
+ if (!layer) {
+ fprintf(stderr, "%s: error setting render color index to %d\n", __func__, value);
+ return;
+ }
+
+ BKE_id_attributes_render_color_set(ptr->owner_id, layer);
+}
+
+static void rna_AttributeGroup_render_color_index_range(
+ PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax)
+{
+ *min = 0;
+ *max = BKE_id_attributes_length(ptr->owner_id, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL);
+
+ *softmin = *min;
+ *softmax = *max;
+}
#else
static void rna_def_attribute_float(BlenderRNA *brna)
@@ -826,6 +958,33 @@ static void rna_def_attribute_group(BlenderRNA *brna)
"rna_AttributeGroup_active_index_set",
"rna_AttributeGroup_active_index_range");
RNA_def_property_update(prop, 0, "rna_AttributeGroup_update_active");
+
+ prop = RNA_def_property(srna, "active_color", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "Attribute");
+ RNA_def_property_pointer_funcs(prop,
+ "rna_AttributeGroup_active_color_get",
+ "rna_AttributeGroup_active_color_set",
+ NULL,
+ NULL);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
+ RNA_def_property_ui_text(prop, "Active Color", "Active color attribute");
+ RNA_def_property_update(prop, 0, "rna_AttributeGroup_update_active_color");
+
+ prop = RNA_def_property(srna, "active_color_index", PROP_INT, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ RNA_def_property_int_funcs(prop,
+ "rna_AttributeGroup_active_color_index_get",
+ "rna_AttributeGroup_active_color_index_set",
+ "rna_AttributeGroup_active_color_index_range");
+ RNA_def_property_update(prop, 0, "rna_AttributeGroup_update_active_color");
+
+ prop = RNA_def_property(srna, "render_color_index", PROP_INT, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ RNA_def_property_int_funcs(prop,
+ "rna_AttributeGroup_render_color_index_get",
+ "rna_AttributeGroup_render_color_index_set",
+ "rna_AttributeGroup_render_color_index_range");
+ RNA_def_property_update(prop, 0, "rna_AttributeGroup_update_active_color");
}
void rna_def_attributes_common(StructRNA *srna)
@@ -846,6 +1005,20 @@ void rna_def_attributes_common(StructRNA *srna)
RNA_def_property_struct_type(prop, "Attribute");
RNA_def_property_ui_text(prop, "Attributes", "Geometry attributes");
RNA_def_property_srna(prop, "AttributeGroup");
+
+ prop = RNA_def_property(srna, "color_attributes", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_funcs(prop,
+ "rna_AttributeGroup_color_iterator_begin",
+ "rna_AttributeGroup_color_iterator_next",
+ "rna_iterator_array_end",
+ "rna_AttributeGroup_color_iterator_get",
+ "rna_AttributeGroup_color_length",
+ NULL,
+ NULL,
+ NULL);
+ RNA_def_property_struct_type(prop, "Attribute");
+ RNA_def_property_ui_text(prop, "Color Attributes", "Geometry color attributes");
+ RNA_def_property_srna(prop, "AttributeGroup");
}
void RNA_def_attribute(BlenderRNA *brna)