diff options
author | Charlie Jolly <charlie> | 2021-03-13 19:49:56 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-03-13 19:49:56 +0300 |
commit | 670453d1ecdbb43a552b2f607cac9d1b84f09d6c (patch) | |
tree | d2d8e8180959124c3dc912c27b91986d135f9f49 /source/blender/makesrna/intern/rna_nodetree.c | |
parent | 8ab6450abbbb8d30db33d006fcbea543beb82e6c (diff) |
Geometry Nodes: Add Attribute Convert node
The Attribute Convert node provides functionality to change attributes
between different domains and data types. Before it was impossible to
write to a UV Map attribute with the attribute math nodes since they
did not output a 2D vector type. This makes it possible to
"convert into" a UV map attribute.
The data type conversion uses the implicit conversions provided by
`\nodes\intern\node_tree_multi_function.cc`.
The `Auto` domain mode chooses the domain based on the following rules:
1. If the result attribute already exists, use that domain.
2. If the result attribute doesn't exist, use the source attribute domain.
3. Otherwise use the default domain (points).
See {T85700}
Differential Revision: https://developer.blender.org/D10624
Diffstat (limited to 'source/blender/makesrna/intern/rna_nodetree.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_nodetree.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index dfb882cde33..aed1b82e940 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -1929,6 +1929,23 @@ static void rna_GeometryNodeAttributeRandomize_data_type_update(Main *bmain, rna_Node_socket_update(bmain, scene, ptr); } +static bool attribute_convert_type_supported(const EnumPropertyItem *item) +{ + return ELEM(item->value, + CD_PROP_FLOAT, + CD_PROP_FLOAT2, + CD_PROP_FLOAT3, + CD_PROP_COLOR, + CD_PROP_BOOL, + CD_PROP_INT32); +} +static const EnumPropertyItem *rna_GeometryNodeAttributeConvert_type_itemf( + bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free) +{ + *r_free = true; + return itemf_function_check(rna_enum_attribute_type_items, attribute_convert_type_supported); +} + static bool attribute_fill_type_supported(const EnumPropertyItem *item) { return ELEM( @@ -8647,6 +8664,35 @@ static void def_geo_attribute_fill(StructRNA *srna) "rna_GeometryNodeAttributeFill_domain_itemf"); } +static void def_geo_attribute_convert(StructRNA *srna) +{ + static const EnumPropertyItem rna_enum_attribute_convert_domain_items[] = { + {ATTR_DOMAIN_AUTO, "AUTO", 0, "Auto", ""}, + {ATTR_DOMAIN_POINT, "POINT", 0, "Point", "Attribute on point"}, + {ATTR_DOMAIN_EDGE, "EDGE", 0, "Edge", "Attribute on mesh edge"}, + {ATTR_DOMAIN_CORNER, "CORNER", 0, "Corner", "Attribute on mesh polygon corner"}, + {ATTR_DOMAIN_POLYGON, "POLYGON", 0, "Polygon", "Attribute on mesh polygons"}, + {0, NULL, 0, NULL, NULL}, + }; + + PropertyRNA *prop; + + RNA_def_struct_sdna_from(srna, "NodeAttributeConvert", "storage"); + + prop = RNA_def_property(srna, "data_type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, rna_enum_attribute_type_items); + RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_GeometryNodeAttributeConvert_type_itemf"); + RNA_def_property_enum_default(prop, CD_PROP_FLOAT); + RNA_def_property_ui_text(prop, "Data Type", "The data type to save the result attribute with"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_GeometryNode_socket_update"); + + prop = RNA_def_property(srna, "domain", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, rna_enum_attribute_convert_domain_items); + RNA_def_property_enum_default(prop, ATTR_DOMAIN_AUTO); + RNA_def_property_ui_text(prop, "Domain", "The geometry domain to save the result attribute in"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); +} + static void def_geo_attribute_math(StructRNA *srna) { PropertyRNA *prop; |