diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h index ad5b2cce36d..de4d2d7896a 100644 --- a/source/blender/blenkernel/BKE_attribute.h +++ b/source/blender/blenkernel/BKE_attribute.h @@ -111,6 +111,7 @@ struct CustomDataLayer *BKE_attribute_search_for_write(AttributeOwner &owner, blender::bke::AttrDomain BKE_attribute_domain(const AttributeOwner &owner, const struct CustomDataLayer *layer); +int BKE_attribute_domain_size(const AttributeOwner &owner, int domain); int BKE_attribute_data_length(AttributeOwner &owner, struct CustomDataLayer *layer); bool BKE_attribute_required(const AttributeOwner &owner, const char *name); bool BKE_attribute_rename(AttributeOwner &owner, diff --git a/source/blender/blenkernel/intern/attribute.cc b/source/blender/blenkernel/intern/attribute.cc index 4e18bed0c06..7d01b189a01 100644 --- a/source/blender/blenkernel/intern/attribute.cc +++ b/source/blender/blenkernel/intern/attribute.cc @@ -727,6 +727,12 @@ AttrDomain BKE_attribute_domain(const AttributeOwner &owner, const CustomDataLay return AttrDomain(AttrDomain::Point); } +int BKE_attribute_domain_size(const AttributeOwner &owner, const int domain) +{ + const std::array info = get_domains(owner); + return info[domain].length; +} + int BKE_attribute_data_length(AttributeOwner &owner, CustomDataLayer *layer) { /* When in mesh editmode, attributes point to bmesh customdata layers, the attribute data is diff --git a/source/blender/makesrna/intern/rna_attribute.cc b/source/blender/makesrna/intern/rna_attribute.cc index a26a8b192ce..c7c8e206d87 100644 --- a/source/blender/makesrna/intern/rna_attribute.cc +++ b/source/blender/makesrna/intern/rna_attribute.cc @@ -695,6 +695,12 @@ static void rna_AttributeGroup_update_active_color(Main * /*bmain*/, } } +static int rna_AttributeGroupID_domain_size(ID *id, const int domain) +{ + AttributeOwner owner = AttributeOwner::from_id(id); + return BKE_attribute_domain_size(owner, domain); +} + static PointerRNA rna_AttributeGroupMesh_active_color_get(PointerRNA *ptr) { AttributeOwner owner = AttributeOwner::from_id(ptr->owner_id); @@ -938,6 +944,13 @@ static void rna_AttributeGroupGreasePencilDrawing_active_index_range( *softmax = *max; } +static int rna_AttributeGroupGreasePencilDrawing_domain_size(GreasePencilDrawing *drawing, + const int domain) +{ + AttributeOwner owner = AttributeOwner(AttributeOwnerType::GreasePencilDrawing, drawing); + return BKE_attribute_domain_size(owner, domain); +} + #else static void rna_def_attribute_float(BlenderRNA *brna) @@ -1498,6 +1511,19 @@ static void rna_def_attribute_group_id_common(StructRNA *srna) "rna_AttributeGroupID_active_index_set", "rna_AttributeGroupID_active_index_range"); RNA_def_property_update(prop, 0, "rna_AttributeGroup_update_active"); + + /* Domain Size */ + func = RNA_def_function(srna, "domain_size", "rna_AttributeGroupID_domain_size"); + RNA_def_function_ui_description(func, "Get the size of a given domain"); + parm = RNA_def_enum(func, + "domain", + rna_enum_attribute_domain_items, + int(AttrDomain::Point), + "Domain", + "Type of element that attribute is stored on"); + RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED); + parm = RNA_def_int(func, "size", 0, 0, INT_MAX, "Size", "Size of the domain", 0, INT_MAX); + RNA_def_function_return(func, parm); } static void rna_def_attribute_group_mesh(BlenderRNA *brna) @@ -1660,6 +1686,20 @@ static void rna_def_attribute_group_grease_pencil_drawing(BlenderRNA *brna) "rna_AttributeGroupGreasePencilDrawing_active_index_set", "rna_AttributeGroupGreasePencilDrawing_active_index_range"); RNA_def_property_update(prop, 0, "rna_AttributeGroup_update_active"); + + /* Domain Size */ + func = RNA_def_function( + srna, "domain_size", "rna_AttributeGroupGreasePencilDrawing_domain_size"); + RNA_def_function_ui_description(func, "Get the size of a given domain"); + parm = RNA_def_enum(func, + "domain", + rna_enum_attribute_domain_items, + int(AttrDomain::Point), + "Domain", + "Type of element that attribute is stored on"); + RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED); + parm = RNA_def_int(func, "size", 0, 0, INT_MAX, "Size", "Size of the domain", 0, INT_MAX); + RNA_def_function_return(func, parm); } void rna_def_attributes_common(StructRNA *srna, const AttributeOwnerType type)