diff options
author | Joseph Eagar <joeedh@gmail.com> | 2022-03-30 23:00:42 +0300 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2022-03-30 23:00:42 +0300 |
commit | 7a463bc17a231d7d7a95d0596d1452fb03820c23 (patch) | |
tree | 06f92c9b1a06f4b3856e91509880430fa2334d5d /source/blender/makesrna | |
parent | 2e3fdeed94f32e100921e610c7c99e5d1a5bf727 (diff) |
temp-sculpt-colors: patch updates
* Got rid of active_render and temporary attribute
RNA properties
* Active render color attribute is now set via
an internal operator, GEOMETRY_OT_color_attribute_render_set.
There is also a new property in AttributeGroup,
render_color_index that is the index of the active
render color attribute inside the color attribute list.
* Temporary properties are now filtered internally in
RNA.
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/intern/rna_attribute.c | 144 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_internal.h | 10 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_modifier.c | 17 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_scene_api.c | 2 |
5 files changed, 43 insertions, 134 deletions
diff --git a/source/blender/makesrna/intern/rna_attribute.c b/source/blender/makesrna/intern/rna_attribute.c index 88529fd244a..01266a26104 100644 --- a/source/blender/makesrna/intern/rna_attribute.c +++ b/source/blender/makesrna/intern/rna_attribute.c @@ -266,7 +266,7 @@ static void rna_Attribute_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), { ID *id = ptr->owner_id; - /* Cheating way for importers to avoid slow updates. */ + /* 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); @@ -342,7 +342,7 @@ static int rna_Attributes_layer_skip(CollectionPropertyIterator *UNUSED(iter), v 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); + 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 @@ -505,7 +505,6 @@ static int rna_AttributeGroup_active_color_index_get(PointerRNA *ptr) static void rna_AttributeGroup_active_color_index_set(PointerRNA *ptr, int value) { - ID *id = ptr->owner_id; CustomDataLayer *layer = BKE_id_attribute_from_index( ptr->owner_id, value, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL); @@ -527,7 +526,7 @@ static void rna_AttributeGroup_active_color_index_range( *softmax = *max; } -static void rna_AttributeGroup_update_active_color(Main *bmain, Scene *scene, PointerRNA *ptr) +static void rna_AttributeGroup_update_active_color(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { ID *id = ptr->owner_id; @@ -538,118 +537,35 @@ static void rna_AttributeGroup_update_active_color(Main *bmain, Scene *scene, Po } } -static bool rna_Attribute_active_render_get(PointerRNA *ptr) +static int rna_AttributeGroup_render_color_index_get(PointerRNA *ptr) { - ID *id = ptr->owner_id; - CustomDataLayer *layer = ptr->data; - - if (!BKE_id_attributes_supported(id)) { - return false; - } - - if (ELEM(layer->type, CD_PROP_COLOR, CD_MLOOPCOL)) { - return layer == BKE_id_attributes_render_color_get(id); - } - - if (GS(id->name) != ID_ME) { - /* Only meshes for now. */ - return false; - } - - Mesh *me = (Mesh *)id; - AttributeDomain domain = BKE_id_attribute_domain(id, layer); - CustomData *cdata = NULL; - - switch (domain) { - case ATTR_DOMAIN_POINT: - cdata = &me->vdata; - break; - case ATTR_DOMAIN_EDGE: - cdata = &me->edata; - break; - case ATTR_DOMAIN_CORNER: - cdata = &me->ldata; - break; - case ATTR_DOMAIN_FACE: - cdata = &me->pdata; - break; - default: - return false; - } + CustomDataLayer *layer = BKE_id_attributes_render_color_get(ptr->owner_id); - int idx = CustomData_get_layer_index(cdata, layer->type); - - if (idx == -1) { - return false; - } - - CustomDataLayer *base = cdata->layers + idx; - - return layer == base + base->active_rnd; + return BKE_id_attribute_to_index( + ptr->owner_id, layer, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL); } -static void rna_Attribute_active_render_set(PointerRNA *ptr, bool value) +static void rna_AttributeGroup_render_color_index_set(PointerRNA *ptr, int value) { - ID *id = ptr->owner_id; - CustomDataLayer *layer = ptr->data; - - if (!value) { - return; // do nothing; - } - - if (!BKE_id_attributes_supported(id)) { - return; - } - - if (GS(id->name) != ID_ME) { - /* Only meshes for now. */ - return; - } - - if (ELEM(layer->type, CD_PROP_COLOR, CD_MLOOPCOL)) { - BKE_id_attributes_render_color_set(id, layer); + CustomDataLayer *layer = BKE_id_attribute_from_index( + ptr->owner_id, value, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL); - if (id->us > 0) { - DEG_id_tag_update(id, 0); - WM_main_add_notifier(NC_GEOM | ND_DATA, id); - } + if (!layer) { + fprintf(stderr, "%s: error setting render color index to %d\n", __func__, value); return; } - Mesh *me = (Mesh *)id; - AttributeDomain domain = BKE_id_attribute_domain(id, layer); - CustomData *cdata; - - switch (domain) { - case ATTR_DOMAIN_POINT: - cdata = &me->vdata; - break; - case ATTR_DOMAIN_EDGE: - cdata = &me->edata; - break; - case ATTR_DOMAIN_CORNER: - cdata = &me->ldata; - break; - case ATTR_DOMAIN_FACE: - cdata = &me->pdata; - break; - default: - return; - } - - int idx = CustomData_get_layer_index(cdata, layer->type); - - if (idx != -1) { - CustomDataLayer *base = cdata->layers + idx; - int newrender = layer - base; + BKE_id_attributes_render_color_set(ptr->owner_id, layer); +} - CustomData_set_layer_render(cdata, layer->type, newrender); +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); - if (id->us > 0) { - DEG_id_tag_update(id, 0); - WM_main_add_notifier(NC_GEOM | ND_DATA, id); - } - } + *softmin = *min; + *softmax = *max; } #else @@ -968,16 +884,6 @@ static void rna_def_attribute(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Data Type", "Type of data stored in attribute"); RNA_def_property_clear_flag(prop, PROP_EDITABLE); - prop = RNA_def_property(srna, "temporary", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", CD_FLAG_TEMPORARY); - RNA_def_property_ui_text(prop, "Temporary", "Layer is temporary"); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); - - prop = RNA_def_property(srna, "active_render", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_funcs( - prop, "rna_Attribute_active_render_get", "rna_Attribute_active_render_set"); - RNA_def_property_ui_text(prop, "Active Render", "Active for render"); - prop = RNA_def_property(srna, "domain", PROP_ENUM, PROP_NONE); RNA_def_property_enum_items(prop, rna_enum_attribute_domain_items); RNA_def_property_enum_funcs( @@ -1071,6 +977,14 @@ static void rna_def_attribute_group(BlenderRNA *brna) "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) diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index eec1ce60089..7fb84246fc0 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -217,6 +217,11 @@ void rna_AttributeGroup_iterator_next(CollectionPropertyIterator *iter); PointerRNA rna_AttributeGroup_iterator_get(CollectionPropertyIterator *iter); int rna_AttributeGroup_length(PointerRNA *ptr); +void rna_AttributeGroup_color_iterator_begin(CollectionPropertyIterator *iter, PointerRNA *ptr); +void rna_AttributeGroup_color_iterator_next(CollectionPropertyIterator *iter); +PointerRNA rna_AttributeGroup_color_iterator_get(CollectionPropertyIterator *iter); +int rna_AttributeGroup_color_length(PointerRNA *ptr); + void rna_def_animdata_common(struct StructRNA *srna); bool rna_AnimaData_override_apply(struct Main *bmain, @@ -678,8 +683,3 @@ void rna_RenderPass_rect_set(PointerRNA *ptr, const float *values); : -FLT_MAX, double \ : -DBL_MAX) #endif - -void rna_AttributeGroup_color_iterator_begin(CollectionPropertyIterator *iter, PointerRNA *ptr); -void rna_AttributeGroup_color_iterator_next(CollectionPropertyIterator *iter); -PointerRNA rna_AttributeGroup_color_iterator_get(CollectionPropertyIterator *iter); -int rna_AttributeGroup_color_length(PointerRNA *ptr); diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index c0470109b04..fe0d4fed838 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -1365,9 +1365,6 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_src_itemf( Object *ob_src = dtmd->ob_source; if (ob_src) { - Mesh *me_eval; - int num_data, i; - AttributeDomain domain = STREQ(RNA_property_identifier(prop), "layers_vcol_select_vert_src") ? ATTR_DOMAIN_POINT : @@ -1380,6 +1377,8 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_src_itemf( CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH; CustomData *cdata; + Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, &cddata_masks); + if (domain == ATTR_DOMAIN_POINT) { cddata_masks.vmask |= CD_MASK_COLOR_ALL; cdata = &me_eval->vdata; @@ -1392,10 +1391,8 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_src_itemf( CustomDataType types[2] = {CD_PROP_COLOR, CD_MLOOPCOL}; int idx = 0; - for (int i = 0; i < 2; i++) { - me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, &cddata_masks); - num_data = CustomData_number_of_layers(cdata, types[i]); + int num_data = CustomData_number_of_layers(cdata, types[i]); RNA_enum_item_add_separator(&item, &totitem); @@ -1487,18 +1484,16 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_dst_itemf( Object *ob_dst = CTX_data_active_object(C); /* XXX Is this OK? */ if (ob_dst && ob_dst->data) { - Mesh *me_dst; - int num_data, i, idx = 0; - CustomDataType types[2] = {CD_PROP_COLOR, CD_MLOOPCOL}; - me_dst = ob_dst->data; + Mesh *me_dst = ob_dst->data; CustomData *cdata = STREQ(RNA_property_identifier(prop), "layers_vcol_vert_select_dst") ? &me_dst->vdata : &me_dst->ldata; + int idx = 0; for (int i = 0; i < 2; i++) { - num_data = CustomData_number_of_layers(cdata, types[i]); + int num_data = CustomData_number_of_layers(cdata, types[i]); RNA_enum_item_add_separator(&item, &totitem); diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index abaee9ddfc3..b14ae3b20fc 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -448,7 +448,7 @@ const EnumPropertyItem rna_enum_bake_target_items[] = { "VERTEX_COLORS", 0, "Color Attributes", - "Bake to active vertex color layer on meshes"}, + "Bake to active color attribute layer on meshes"}, {0, NULL, 0, NULL, NULL}, }; @@ -3157,7 +3157,7 @@ static void rna_def_tool_settings(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "uvcalc_flag", UVCALC_TRANSFORM_CORRECT); RNA_def_property_ui_text(prop, "Correct Face Attributes", - "Correct data such as UV's and vertex colors when transforming"); + "Correct data such as UV's and color attributes when transforming"); RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); prop = RNA_def_property(srna, "use_transform_correct_keep_connected", PROP_BOOLEAN, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_scene_api.c b/source/blender/makesrna/intern/rna_scene_api.c index 40fec071703..200e1d65caf 100644 --- a/source/blender/makesrna/intern/rna_scene_api.c +++ b/source/blender/makesrna/intern/rna_scene_api.c @@ -357,7 +357,7 @@ void RNA_api_scene(StructRNA *srna) RNA_def_boolean(func, "selected_only", 0, "Selected only", "Export only selected objects"); RNA_def_boolean(func, "uvs", 1, "UVs", "Export UVs"); RNA_def_boolean(func, "normals", 1, "Normals", "Export normals"); - RNA_def_boolean(func, "vcolors", 0, "Color Attributes", "Export vertex colors"); + RNA_def_boolean(func, "vcolors", 0, "Color Attributes", "Export color attributes"); RNA_def_boolean( func, "apply_subdiv", 1, "Subsurfs as meshes", "Export subdivision surfaces as meshes"); RNA_def_boolean(func, "flatten", 0, "Flatten hierarchy", "Flatten hierarchy"); |