diff options
author | Jacques Lucke <jacques@blender.org> | 2021-02-15 14:06:21 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-02-15 14:06:40 +0300 |
commit | d6b2c184816419385b591dfba4d1303cb445d91e (patch) | |
tree | 62e56b73139eaa31638a2647f43cfbedcc38dc67 /source/blender/makesrna/intern | |
parent | c233f081d6eca7334405d104a7c85b04790c886b (diff) |
Attributes: return refined Attribute from attributes.new method
Previously `mesh.attributes.new(...)` would return a generic attribute that
one could not do much with. Now it returns refined attributes like `FloatAttribute`.
Diffstat (limited to 'source/blender/makesrna/intern')
-rw-r--r-- | source/blender/makesrna/intern/rna_attribute.c | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/source/blender/makesrna/intern/rna_attribute.c b/source/blender/makesrna/intern/rna_attribute.c index 21b26b51e0a..28c65992236 100644 --- a/source/blender/makesrna/intern/rna_attribute.c +++ b/source/blender/makesrna/intern/rna_attribute.c @@ -79,6 +79,34 @@ static char *rna_Attribute_path(PointerRNA *ptr) return BLI_sprintfN("attributes['%s']", layer->name); } +static StructRNA *srna_by_custom_data_layer_type(const CustomDataType type) +{ + switch (type) { + case CD_PROP_FLOAT: + return &RNA_FloatAttribute; + case CD_PROP_INT32: + return &RNA_IntAttribute; + case CD_PROP_FLOAT3: + return &RNA_FloatVectorAttribute; + case CD_PROP_COLOR: + return &RNA_FloatColorAttribute; + case CD_MLOOPCOL: + return &RNA_ByteColorAttribute; + case CD_PROP_STRING: + return &RNA_StringAttribute; + case CD_PROP_BOOL: + return &RNA_BoolAttribute; + default: + return NULL; + } +} + +static StructRNA *rna_Attribute_refine(PointerRNA *ptr) +{ + CustomDataLayer *layer = ptr->data; + return srna_by_custom_data_layer_type(layer->type); +} + static void rna_Attribute_name_set(PointerRNA *ptr, const char *value) { BKE_id_attribute_rename(ptr->owner_id, ptr->data, value, NULL); @@ -280,35 +308,11 @@ void rna_AttributeGroup_iterator_next(CollectionPropertyIterator *iter) PointerRNA rna_AttributeGroup_iterator_get(CollectionPropertyIterator *iter) { /* refine to the proper type */ - StructRNA *type; CustomDataLayer *layer = rna_iterator_array_get(iter); - - switch (layer->type) { - case CD_PROP_FLOAT: - type = &RNA_FloatAttribute; - break; - case CD_PROP_INT32: - type = &RNA_IntAttribute; - break; - case CD_PROP_FLOAT3: - type = &RNA_FloatVectorAttribute; - break; - case CD_PROP_COLOR: - type = &RNA_FloatColorAttribute; - break; - case CD_MLOOPCOL: - type = &RNA_ByteColorAttribute; - break; - case CD_PROP_STRING: - type = &RNA_StringAttribute; - break; - case CD_PROP_BOOL: - type = &RNA_BoolAttribute; - break; - default: - return PointerRNA_NULL; + 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); } @@ -598,6 +602,7 @@ static void rna_def_attribute(BlenderRNA *brna) RNA_def_struct_sdna(srna, "CustomDataLayer"); RNA_def_struct_ui_text(srna, "Attribute", "Geometry attribute"); RNA_def_struct_path_func(srna, "rna_Attribute_path"); + RNA_def_struct_refine_func(srna, "rna_Attribute_refine"); prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Attribute_name_set"); |