diff options
author | Charlie Jolly <charlie> | 2021-04-30 16:11:45 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-04-30 16:11:45 +0300 |
commit | 95d2d0d35a6644c57fef4665a14d17a482dc3e07 (patch) | |
tree | cea5a2ae7a67aa85a0745f0f11dbd2aa4179fd67 /source/blender/nodes | |
parent | 6cf28e98fbbd7e92ea4d2bc28009b3d108ddb1a1 (diff) |
Geometry Nodes: Add an "Auto" option for Attribute Convert data type
Currently there is an "Auto" option for the domain, this commit adds a
similar option for "Auto" data type, that uses the data type from the
target attribute or the source attribute (in that order).
Ref T87347
Differential Revision: https://developer.blender.org/D10932
Diffstat (limited to 'source/blender/nodes')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_attribute_convert.cc | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_convert.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_convert.cc index 60bb27191b4..28fd06a8cc1 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_convert.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_convert.cc @@ -35,8 +35,10 @@ static void geo_node_attribute_convert_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "domain", 0, "", ICON_NONE); - uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE); + uiLayoutSetPropSep(layout, true); + uiLayoutSetPropDecorate(layout, false); + uiItemR(layout, ptr, "domain", 0, nullptr, ICON_NONE); + uiItemR(layout, ptr, "data_type", 0, IFACE_("Type"), ICON_NONE); } static void geo_node_attribute_convert_init(bNodeTree *UNUSED(tree), bNode *node) @@ -44,26 +46,27 @@ static void geo_node_attribute_convert_init(bNodeTree *UNUSED(tree), bNode *node NodeAttributeConvert *data = (NodeAttributeConvert *)MEM_callocN(sizeof(NodeAttributeConvert), __func__); - data->data_type = CD_PROP_FLOAT; + data->data_type = CD_AUTO_FROM_NAME; data->domain = ATTR_DOMAIN_AUTO; node->storage = data; } namespace blender::nodes { -static AttributeDomain get_result_domain(const GeometryComponent &component, - StringRef source_name, - StringRef result_name) +static AttributeMetaData get_result_domain_and_type(const GeometryComponent &component, + const StringRef source_name, + const StringRef result_name) { std::optional<AttributeMetaData> result_info = component.attribute_get_meta_data(result_name); if (result_info) { - return result_info->domain; + return *result_info; } std::optional<AttributeMetaData> source_info = component.attribute_get_meta_data(source_name); if (source_info) { - return source_info->domain; + return *source_info; } - return ATTR_DOMAIN_POINT; + /* The node won't do anything in this case, but we still have to return a value. */ + return AttributeMetaData{ATTR_DOMAIN_POINT, CD_PROP_BOOL}; } static bool conversion_can_be_skipped(const GeometryComponent &component, @@ -92,13 +95,14 @@ static void attribute_convert_calc(GeometryComponent &component, const GeoNodeExecParams ¶ms, const StringRef source_name, const StringRef result_name, - const CustomDataType result_type, + const CustomDataType data_type, const AttributeDomain domain) { - const AttributeDomain result_domain = (domain == ATTR_DOMAIN_AUTO) ? - get_result_domain( - component, source_name, result_name) : - domain; + const AttributeMetaData auto_info = get_result_domain_and_type( + component, source_name, result_name); + const AttributeDomain result_domain = (domain == ATTR_DOMAIN_AUTO) ? auto_info.domain : domain; + const CustomDataType result_type = (data_type == CD_AUTO_FROM_NAME) ? auto_info.data_type : + data_type; if (conversion_can_be_skipped(component, source_name, result_name, result_domain, result_type)) { return; |