From 99bf6a12b67a17360191a8afeb4992729a8b6d88 Mon Sep 17 00:00:00 2001 From: Iliya Katueshenock Date: Fri, 29 Sep 2023 13:07:41 +0300 Subject: [PATCH 1/4] init --- source/blender/blenkernel/BKE_geometry_fields.hh | 3 +++ .../blender/blenkernel/intern/geometry_fields.cc | 16 ++++++++++++++++ .../geometry/nodes/node_geo_attribute_capture.cc | 15 ++++++++++----- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/source/blender/blenkernel/BKE_geometry_fields.hh b/source/blender/blenkernel/BKE_geometry_fields.hh index ddc4f2563fe..71bb14c65c6 100644 --- a/source/blender/blenkernel/BKE_geometry_fields.hh +++ b/source/blender/blenkernel/BKE_geometry_fields.hh @@ -345,6 +345,9 @@ bool try_capture_field_on_geometry(GeometryComponent &component, const fn::Field &selection, const fn::GField &field); +void clean_unused_attributes_on_geometry(const AnonymousAttributePropagationInfo &propagation_info, + GeometryComponent &component); + /** * Try to find the geometry domain that the field should be evaluated on. If it is not obvious * which domain is correct, none is returned. diff --git a/source/blender/blenkernel/intern/geometry_fields.cc b/source/blender/blenkernel/intern/geometry_fields.cc index 31645c0f33b..f30efb6679a 100644 --- a/source/blender/blenkernel/intern/geometry_fields.cc +++ b/source/blender/blenkernel/intern/geometry_fields.cc @@ -571,6 +571,22 @@ bool try_capture_field_on_geometry(GeometryComponent &component, return try_capture_field_on_geometry(component, attribute_id, domain, selection, field); } +void clean_unused_attributes_on_geometry(const AnonymousAttributePropagationInfo &propagation_info, + GeometryComponent &component) +{ + MutableAttributeAccessor attributes = *component.attributes_for_write(); + const Set all_ids = attributes.all_ids(); + for (const AttributeIDRef &id : all_ids) { + if (!id.is_anonymous()) { + continue; + } + if (propagation_info.propagate(id.anonymous_id())) { + continue; + } + attributes.remove(id); + } +} + std::optional try_detect_field_domain(const GeometryComponent &component, const fn::GField &field) { diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc index a940f801a92..60842aa8ff6 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc @@ -191,12 +191,18 @@ static void node_geo_exec(GeoNodeExecParams params) break; } + const auto capture_on = [&](GeometryComponent &component) { + /* Changing of the anonymous attributes may require removing attributes that are no longer + * needed. */ + bke::clean_unused_attributes_on_geometry(params.get_output_propagation_info("Geometry"), + component); + bke::try_capture_field_on_geometry(component, *attribute_id, domain, field); + }; + /* Run on the instances component separately to only affect the top level of instances. */ if (domain == ATTR_DOMAIN_INSTANCE) { if (geometry_set.has_instances()) { - GeometryComponent &component = geometry_set.get_component_for_write( - GeometryComponent::Type::Instance); - bke::try_capture_field_on_geometry(component, *attribute_id, domain, field); + capture_on(geometry_set.get_component_for_write(GeometryComponent::Type::Instance)); } } else { @@ -207,8 +213,7 @@ static void node_geo_exec(GeoNodeExecParams params) geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { for (const GeometryComponent::Type type : types) { if (geometry_set.has(type)) { - GeometryComponent &component = geometry_set.get_component_for_write(type); - bke::try_capture_field_on_geometry(component, *attribute_id, domain, field); + capture_on(geometry_set.get_component_for_write(type)); } } }); -- 2.30.2 From 6c399ea5df13df40e62c9294b5d3b8933b25bfd5 Mon Sep 17 00:00:00 2001 From: Iliya Katueshenock Date: Fri, 29 Sep 2023 13:58:16 +0300 Subject: [PATCH 2/4] progress --- .../blender/blenkernel/BKE_geometry_fields.hh | 3 --- .../blenkernel/intern/geometry_fields.cc | 16 ----------- .../nodes/node_geo_attribute_capture.cc | 27 ++++++++++++++++--- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/source/blender/blenkernel/BKE_geometry_fields.hh b/source/blender/blenkernel/BKE_geometry_fields.hh index 71bb14c65c6..ddc4f2563fe 100644 --- a/source/blender/blenkernel/BKE_geometry_fields.hh +++ b/source/blender/blenkernel/BKE_geometry_fields.hh @@ -345,9 +345,6 @@ bool try_capture_field_on_geometry(GeometryComponent &component, const fn::Field &selection, const fn::GField &field); -void clean_unused_attributes_on_geometry(const AnonymousAttributePropagationInfo &propagation_info, - GeometryComponent &component); - /** * Try to find the geometry domain that the field should be evaluated on. If it is not obvious * which domain is correct, none is returned. diff --git a/source/blender/blenkernel/intern/geometry_fields.cc b/source/blender/blenkernel/intern/geometry_fields.cc index f30efb6679a..31645c0f33b 100644 --- a/source/blender/blenkernel/intern/geometry_fields.cc +++ b/source/blender/blenkernel/intern/geometry_fields.cc @@ -571,22 +571,6 @@ bool try_capture_field_on_geometry(GeometryComponent &component, return try_capture_field_on_geometry(component, attribute_id, domain, selection, field); } -void clean_unused_attributes_on_geometry(const AnonymousAttributePropagationInfo &propagation_info, - GeometryComponent &component) -{ - MutableAttributeAccessor attributes = *component.attributes_for_write(); - const Set all_ids = attributes.all_ids(); - for (const AttributeIDRef &id : all_ids) { - if (!id.is_anonymous()) { - continue; - } - if (propagation_info.propagate(id.anonymous_id())) { - continue; - } - attributes.remove(id); - } -} - std::optional try_detect_field_domain(const GeometryComponent &component, const fn::GField &field) { diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc index 60842aa8ff6..b16c2d55821 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc @@ -118,6 +118,27 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) } } +static void clean_unused_attributes(const AnonymousAttributePropagationInfo &propagation_info, + const Set skip, + GeometryComponent &component) +{ + std::optional attributes = component.attributes_for_write(); + const Set all_ids = attributes.has_value() ? attributes->all_ids() : + Set(); + for (const AttributeIDRef &id : all_ids) { + if (!id.is_anonymous()) { + continue; + } + if (skip.contains(id)) { + continue; + } + if (propagation_info.propagate(id.anonymous_id())) { + continue; + } + attributes->remove(id); + } +} + static StringRefNull identifier_suffix(eCustomDataType data_type) { switch (data_type) { @@ -192,11 +213,11 @@ static void node_geo_exec(GeoNodeExecParams params) } const auto capture_on = [&](GeometryComponent &component) { + bke::try_capture_field_on_geometry(component, *attribute_id, domain, field); /* Changing of the anonymous attributes may require removing attributes that are no longer * needed. */ - bke::clean_unused_attributes_on_geometry(params.get_output_propagation_info("Geometry"), - component); - bke::try_capture_field_on_geometry(component, *attribute_id, domain, field); + clean_unused_attributes( + params.get_output_propagation_info("Geometry"), {*attribute_id}, component); }; /* Run on the instances component separately to only affect the top level of instances. */ -- 2.30.2 From 40b5e683a67dede72a0a7178ab82feb0a46ec004 Mon Sep 17 00:00:00 2001 From: Iliya Katueshenock Date: Fri, 29 Sep 2023 14:24:03 +0300 Subject: [PATCH 3/4] fix attr names after restruct --- .../nodes/node_geo_attribute_capture.cc | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc index b16c2d55821..53b9098c808 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc @@ -123,19 +123,27 @@ static void clean_unused_attributes(const AnonymousAttributePropagationInfo &pro GeometryComponent &component) { std::optional attributes = component.attributes_for_write(); - const Set all_ids = attributes.has_value() ? attributes->all_ids() : - Set(); - for (const AttributeIDRef &id : all_ids) { + if (!attributes.has_value()) { + return; + } + + Vector unused_ids; + attributes->for_all([&](const AttributeIDRef &id, const AttributeMetaData /*meta_data*/) { if (!id.is_anonymous()) { - continue; + return true; } if (skip.contains(id)) { - continue; + return true; } if (propagation_info.propagate(id.anonymous_id())) { - continue; + return true; } - attributes->remove(id); + unused_ids.append(id.name()); + return true; + }); + + for (const std::string &unused_id : unused_ids) { + attributes->remove(unused_id); } } -- 2.30.2 From b95a7f68f41aae319ff54aacf630f521202b84de Mon Sep 17 00:00:00 2001 From: Iliya Katueshenock Date: Fri, 29 Sep 2023 16:51:16 +0300 Subject: [PATCH 4/4] ref arg --- .../blender/nodes/geometry/nodes/node_geo_attribute_capture.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc index 53b9098c808..d206e1a3155 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc @@ -119,7 +119,7 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) } static void clean_unused_attributes(const AnonymousAttributePropagationInfo &propagation_info, - const Set skip, + const Set &skip, GeometryComponent &component) { std::optional attributes = component.attributes_for_write(); -- 2.30.2