From f46b2d0d13e74827e5c2c8953229914b6b25fe92 Mon Sep 17 00:00:00 2001 From: David-Haver Date: Fri, 5 Apr 2024 22:24:46 +0300 Subject: [PATCH 01/10] Fix: wrong index --- source/blender/geometry/intern/realize_instances.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/geometry/intern/realize_instances.cc b/source/blender/geometry/intern/realize_instances.cc index 27a735a5516..3358ec31bbd 100644 --- a/source/blender/geometry/intern/realize_instances.cc +++ b/source/blender/geometry/intern/realize_instances.cc @@ -585,7 +585,7 @@ static void gather_realize_tasks_for_instances(GatherTasksInfo &gather_info, const int i = indices[mask_index]; /* If at top level, retrieve depth from gather_info, else continue with target_depth. */ - const int depth_target = current_depth == 0 ? gather_info.depths[mask_index] : target_depth; + const int depth_target = current_depth == 0 ? gather_info.depths[i] : target_depth; const int handle = handles[i]; const float4x4 &transform = transforms[i]; const InstanceReference &reference = references[handle]; -- 2.30.2 From 7f9df6a168f9eefa75fd169e05679e78e06e433a Mon Sep 17 00:00:00 2001 From: David-Haver Date: Tue, 16 Apr 2024 18:35:02 +0300 Subject: [PATCH 02/10] fixing miss caculated transforms --- source/blender/geometry/intern/realize_instances.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/geometry/intern/realize_instances.cc b/source/blender/geometry/intern/realize_instances.cc index 3358ec31bbd..2755f58fcf2 100644 --- a/source/blender/geometry/intern/realize_instances.cc +++ b/source/blender/geometry/intern/realize_instances.cc @@ -1000,8 +1000,8 @@ static void execute_instances_tasks( array_utils::gather(handle_map.as_span(), src_handles, all_handles.slice(dst_range)); array_utils::copy(src_instances.transforms(), all_transforms.slice(dst_range)); - for (blender::float4x4 &transfrom : all_transforms.slice(dst_range)) { - transfrom *= src_base_transform; + for (blender::float4x4 &transform : all_transforms.slice(dst_range)) { + transform = src_base_transform * transform; } } -- 2.30.2 From 67cae5c97117585b9dce0a221f2363c00a06d4b3 Mon Sep 17 00:00:00 2001 From: David-Haver Date: Tue, 16 Apr 2024 18:45:56 +0300 Subject: [PATCH 03/10] Reverting styling changes to simplfy the PR. will be done in a seperate PR. --- .../blender/geometry/GEO_join_geometries.hh | 6 ++--- .../geometry/intern/join_geometries.cc | 25 +++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/source/blender/geometry/GEO_join_geometries.hh b/source/blender/geometry/GEO_join_geometries.hh index 0bdb179c5db..569ac84d96a 100644 --- a/source/blender/geometry/GEO_join_geometries.hh +++ b/source/blender/geometry/GEO_join_geometries.hh @@ -12,7 +12,7 @@ namespace blender::geometry { bke::GeometrySet join_geometries(Span geometries, const bke::AnonymousAttributePropagationInfo &propagation_info); -void join_attributes(Span src_components, - Span ignored_attributes, - bke::GeometryComponent &r_result); +void join_attributes(const Span src_components, + GeometryComponent &r_result, + const Span ignored_attributes = {}) } // namespace blender::geometry diff --git a/source/blender/geometry/intern/join_geometries.cc b/source/blender/geometry/intern/join_geometries.cc index 1b1ac578dc8..c6318302229 100644 --- a/source/blender/geometry/intern/join_geometries.cc +++ b/source/blender/geometry/intern/join_geometries.cc @@ -74,8 +74,8 @@ static void fill_new_attribute(const Span src_compone } void join_attributes(const Span src_components, - const Span ignored_attributes, - GeometryComponent &r_result) + GeometryComponent &result, + const Span ignored_attributes = {}) { const Map info = get_final_attribute_info(src_components, ignored_attributes); @@ -85,7 +85,7 @@ void join_attributes(const Span src_components, const AttributeMetaData &meta_data = item.value; bke::GSpanAttributeWriter write_attribute = - r_result.attributes_for_write()->lookup_or_add_for_write_only_span( + result.attributes_for_write()->lookup_or_add_for_write_only_span( attribute_id, meta_data.domain, meta_data.data_type); if (!write_attribute) { continue; @@ -97,7 +97,7 @@ void join_attributes(const Span src_components, } static void join_instances(const Span src_components, - GeometrySet &r_result) + GeometrySet &result) { Array offsets_data(src_components.size() + 1); for (const int i : src_components.index_range()) { @@ -127,9 +127,9 @@ static void join_instances(const Span src_components, array_utils::gather(handle_map.as_span(), src_handles, all_handles.slice(dst_range)); } - r_result.replace_instances(dst_instances.release()); - auto &dst_component = r_result.get_component_for_write(); - join_attributes(src_components, {".reference_index"}, dst_component); + result.replace_instances(dst_instances.release()); + auto &dst_component = result.get_component_for_write(); + join_attributes(src_components, dst_component, {".reference_index"}); } static void join_volumes(const Span /*src_components*/, @@ -142,7 +142,7 @@ static void join_volumes(const Span /*src_components* static void join_component_type(const bke::GeometryComponent::Type component_type, const Span src_geometry_sets, const bke::AnonymousAttributePropagationInfo &propagation_info, - GeometrySet &r_result) + GeometrySet &result) { Vector components; for (const GeometrySet &geometry_set : src_geometry_sets) { @@ -156,16 +156,16 @@ static void join_component_type(const bke::GeometryComponent::Type component_typ return; } if (components.size() == 1) { - r_result.add(*components.first()); + result.add(*components.first()); return; } switch (component_type) { case bke::GeometryComponent::Type::Instance: - join_instances(components, r_result); + join_instances(components, result); return; case bke::GeometryComponent::Type::Volume: - join_volumes(components, r_result); + join_volumes(components, result); return; default: break; @@ -185,10 +185,9 @@ static void join_component_type(const bke::GeometryComponent::Type component_typ options.keep_original_ids = true; options.realize_instance_attributes = false; options.propagation_info = propagation_info; - GeometrySet joined_components = realize_instances( GeometrySet::from_instances(instances.release()), options); - r_result.add(joined_components.get_component_for_write(component_type)); + result.add(joined_components.get_component_for_write(component_type)); } GeometrySet join_geometries(const Span geometries, -- 2.30.2 From 0e4f509040bc02881d85b217fa4a480857e93d4e Mon Sep 17 00:00:00 2001 From: David-Haver Date: Tue, 16 Apr 2024 19:37:48 +0300 Subject: [PATCH 04/10] Forgot to make format --- source/blender/geometry/GEO_join_geometries.hh | 6 +++--- source/blender/geometry/intern/join_geometries.cc | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/blender/geometry/GEO_join_geometries.hh b/source/blender/geometry/GEO_join_geometries.hh index 569ac84d96a..23e4e1038c0 100644 --- a/source/blender/geometry/GEO_join_geometries.hh +++ b/source/blender/geometry/GEO_join_geometries.hh @@ -12,7 +12,7 @@ namespace blender::geometry { bke::GeometrySet join_geometries(Span geometries, const bke::AnonymousAttributePropagationInfo &propagation_info); -void join_attributes(const Span src_components, - GeometryComponent &r_result, - const Span ignored_attributes = {}) +void join_attributes(const Span src_components, + bke::GeometryComponent &r_result, + const Span ignored_attributes = {}) } // namespace blender::geometry diff --git a/source/blender/geometry/intern/join_geometries.cc b/source/blender/geometry/intern/join_geometries.cc index c6318302229..befb2d43494 100644 --- a/source/blender/geometry/intern/join_geometries.cc +++ b/source/blender/geometry/intern/join_geometries.cc @@ -74,8 +74,8 @@ static void fill_new_attribute(const Span src_compone } void join_attributes(const Span src_components, - GeometryComponent &result, - const Span ignored_attributes = {}) + GeometryComponent &result, + const Span ignored_attributes = {}) { const Map info = get_final_attribute_info(src_components, ignored_attributes); -- 2.30.2 From 45b9d27a2362f1b96e4a9b8324464334e7d07f1a Mon Sep 17 00:00:00 2001 From: David-Haver Date: Tue, 16 Apr 2024 19:40:29 +0300 Subject: [PATCH 05/10] Changed geometry_set_from_reference to don't use an out param --- .../geometry/intern/realize_instances.cc | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/source/blender/geometry/intern/realize_instances.cc b/source/blender/geometry/intern/realize_instances.cc index 2755f58fcf2..813d3205e34 100644 --- a/source/blender/geometry/intern/realize_instances.cc +++ b/source/blender/geometry/intern/realize_instances.cc @@ -168,7 +168,7 @@ struct RealizeCurveTask { CurvesElementStartIndices start_indices; const RealizeCurveInfo *curve_info; - /* Transformation applied to the position of control points and handles. */ + /** Transformation applied to the position of control points and handles. */ float4x4 transform; AttributeFallbacksArray attribute_fallbacks; /** Only used when the output contains an output attribute. */ @@ -220,7 +220,7 @@ struct AllCurvesInfo { }; struct AllInstancesInfo { - /** store an array of void pointer to attributes for each component. */ + /** Stores an array of void pointer to attributes for each component. */ Vector attribute_fallback; /** Instance components to merge for output geometry. */ Vector instances_components_to_merge; @@ -500,36 +500,35 @@ static Vector> prepare_attribute_fallbacks( return attributes_to_override; } -static bke::GeometrySet &geometry_set_from_reference(const InstanceReference &reference, - bke::GeometrySet &r_geometry_set) +static bke::GeometrySet geometry_set_from_reference(const InstanceReference &reference) { switch (reference.type()) { case InstanceReference::Type::Object: { const Object &object = reference.object(); - r_geometry_set = bke::object_get_evaluated_geometry_set(object); + const bke::GeometrySet geometry_set = bke::object_get_evaluated_geometry_set(object); + return geometry_set; break; } case InstanceReference::Type::Collection: { Collection *collection_ptr = &reference.collection(); std::unique_ptr instances = std::make_unique(); realize_collections(collection_ptr, instances.get()); - r_geometry_set.replace_instances(instances.release()); + bke::GeometrySet geometry_set; + geometry_set.replace_instances(instances.release()); + return geometry_set; break; } case InstanceReference::Type::GeometrySet: { - r_geometry_set = reference.geometry_set(); + const bke::GeometrySet geometry_set = reference.geometry_set(); + return geometry_set; break; } case InstanceReference::Type::None: { - r_geometry_set = bke::GeometrySet(); // Return an empty GeometrySet for None type - break; - } - default: { - r_geometry_set = bke::GeometrySet(); + return {}; // Return an empty GeometrySet for None type break; } } - return r_geometry_set; + return {}; } /** @@ -543,8 +542,7 @@ static void foreach_geometry_in_reference( FunctionRef fn) { - bke::GeometrySet geometry_set; - geometry_set_from_reference(reference, geometry_set); + bke::GeometrySet geometry_set = geometry_set_from_reference(reference); fn(geometry_set, base_transform, id); } @@ -778,9 +776,8 @@ static bool attribute_foreach(const bke::GeometrySet &geometry_set, for (const int index : indices.index_range()) { const int i = indices[index]; const int depth_target_tmp = (0 == current_depth) ? instance_depth[i] : depth_target; - bke::GeometrySet instance_geometry_set; - geometry_set_from_reference(instances.references()[instances.reference_handles()[i]], - instance_geometry_set); + bke::GeometrySet instance_geometry_set = geometry_set_from_reference( + instances.references()[instances.reference_handles()[i]]); /*Process child instances with a recursive call.*/ if (current_depth != depth_target_tmp) { child_has_component = child_has_component | attribute_foreach(instance_geometry_set, @@ -1014,7 +1011,7 @@ static void execute_instances_tasks( } join_attributes( - for_join_attributes, {"position", ".reference_index", "instance_transform"}, dst_component); + for_join_attributes, dst_component, {"position", ".reference_index", "instance_transform"}); } /** \} */ -- 2.30.2 From b0a0b346bcf687979697ac8199e1c6a43b5f67e2 Mon Sep 17 00:00:00 2001 From: David-Haver Date: Wed, 17 Apr 2024 01:14:56 +0300 Subject: [PATCH 06/10] Fixed spaces in comments --- source/blender/geometry/intern/realize_instances.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/blender/geometry/intern/realize_instances.cc b/source/blender/geometry/intern/realize_instances.cc index 813d3205e34..2de35bc0c9a 100644 --- a/source/blender/geometry/intern/realize_instances.cc +++ b/source/blender/geometry/intern/realize_instances.cc @@ -763,7 +763,7 @@ static bool attribute_foreach(const bke::GeometrySet &geometry_set, const bke::GeometrySet::AttributeForeachCallback callback) { - /*Initialize flag to track if child instances have the specified components.*/ + /* Initialize flag to track if child instances have the specified components.*/ bool child_has_component = true; if (geometry_set.has_instances()) { @@ -778,7 +778,7 @@ static bool attribute_foreach(const bke::GeometrySet &geometry_set, const int depth_target_tmp = (0 == current_depth) ? instance_depth[i] : depth_target; bke::GeometrySet instance_geometry_set = geometry_set_from_reference( instances.references()[instances.reference_handles()[i]]); - /*Process child instances with a recursive call.*/ + /* Process child instances with a recursive call.*/ if (current_depth != depth_target_tmp) { child_has_component = child_has_component | attribute_foreach(instance_geometry_set, component_types, @@ -791,17 +791,17 @@ static bool attribute_foreach(const bke::GeometrySet &geometry_set, } } - /*Flag to track if any relevant attributes were found.*/ + /* Flag to track if any relevant attributes were found.*/ bool is_relevant = false; for (const bke::GeometryComponent::Type component_type : component_types) { if (geometry_set.has(component_type)) { - /*Check if the current instance components is the main one*/ + /* Check if the current instance components is the main one*/ const bool is_special_instance = (bke::GeometryComponent::Type::Instance == component_type) && (component_types.size() > 1); if (!is_special_instance || child_has_component) { - /*Process attributes for the current component.*/ + /* Process attributes for the current component.*/ const bke::GeometryComponent &component = *geometry_set.get_component(component_type); const std::optional attributes = component.attributes(); if (attributes.has_value()) { -- 2.30.2 From 78c758b4e692e1b2e658a535765e46b3fe6bfd61 Mon Sep 17 00:00:00 2001 From: David-Haver Date: Wed, 17 Apr 2024 01:24:53 +0300 Subject: [PATCH 07/10] Fixed static placment in a function decleration --- source/blender/geometry/intern/realize_instances.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/geometry/intern/realize_instances.cc b/source/blender/geometry/intern/realize_instances.cc index 2de35bc0c9a..e137ccc7491 100644 --- a/source/blender/geometry/intern/realize_instances.cc +++ b/source/blender/geometry/intern/realize_instances.cc @@ -825,7 +825,7 @@ static bool attribute_foreach(const bke::GeometrySet &geometry_set, * Specialized for Specialized attribute_foreach to get: * current_depth, depth_target, instance_depth and selection. */ -void static gather_attributes_for_propagation( +static void gather_attributes_for_propagation( bke::GeometrySet re_geometry_set, const Span component_types, const bke::GeometryComponent::Type dst_component_type, -- 2.30.2 From 8afa69f54bc08acaa722251638b38e9dfb07bb1e Mon Sep 17 00:00:00 2001 From: David-Haver Date: Wed, 17 Apr 2024 13:46:14 +0300 Subject: [PATCH 08/10] Fixes to compiler error --- source/blender/geometry/GEO_join_geometries.hh | 2 +- source/blender/geometry/intern/join_geometries.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/geometry/GEO_join_geometries.hh b/source/blender/geometry/GEO_join_geometries.hh index 23e4e1038c0..5465b67ceea 100644 --- a/source/blender/geometry/GEO_join_geometries.hh +++ b/source/blender/geometry/GEO_join_geometries.hh @@ -14,5 +14,5 @@ bke::GeometrySet join_geometries(Span geometries, void join_attributes(const Span src_components, bke::GeometryComponent &r_result, - const Span ignored_attributes = {}) + const Span ignored_attributes = {}); } // namespace blender::geometry diff --git a/source/blender/geometry/intern/join_geometries.cc b/source/blender/geometry/intern/join_geometries.cc index befb2d43494..b6686eff115 100644 --- a/source/blender/geometry/intern/join_geometries.cc +++ b/source/blender/geometry/intern/join_geometries.cc @@ -75,7 +75,7 @@ static void fill_new_attribute(const Span src_compone void join_attributes(const Span src_components, GeometryComponent &result, - const Span ignored_attributes = {}) + const Span ignored_attributes) { const Map info = get_final_attribute_info(src_components, ignored_attributes); -- 2.30.2 From 317e703221969e7c15afafa4e33e51f4f3f34c1d Mon Sep 17 00:00:00 2001 From: David-Haver Date: Thu, 18 Apr 2024 19:31:38 +0300 Subject: [PATCH 09/10] Change to the realize all field tool tip --- .../nodes/geometry/nodes/node_geo_realize_instances.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/blender/nodes/geometry/nodes/node_geo_realize_instances.cc b/source/blender/nodes/geometry/nodes/node_geo_realize_instances.cc index 3f9f64e6a47..5b85b0e5529 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_realize_instances.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_realize_instances.cc @@ -23,7 +23,9 @@ static void node_declare(NodeDeclarationBuilder &b) b.add_input("Realize All") .default_value(true) .field_on_all() - .description("Determine wether to realize nested instances completly"); + .description( + "Realize all levels of nested instances for a top-level instances. Overrides the value " + "of the Depth input"); b.add_input("Depth").default_value(0).min(0).field_on_all().description( "Number of levels of nested instances to realize for each top-level instance"); b.add_output("Geometry").propagate_all(); -- 2.30.2 From 702784e07cfac77299242daa0653d44146beaf2e Mon Sep 17 00:00:00 2001 From: David-Haver Date: Thu, 18 Apr 2024 19:47:54 +0300 Subject: [PATCH 10/10] Better explaning a part of execute_instances_tasks --- source/blender/geometry/intern/realize_instances.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/blender/geometry/intern/realize_instances.cc b/source/blender/geometry/intern/realize_instances.cc index e137ccc7491..2dfaab30a2e 100644 --- a/source/blender/geometry/intern/realize_instances.cc +++ b/source/blender/geometry/intern/realize_instances.cc @@ -942,13 +942,14 @@ static void execute_instances_tasks( std::unique_ptr dst_instances = std::make_unique(); dst_instances->resize(offsets.total_size()); - /* Prepare generic output attributes. */ + /* Makes sure generic output attributes exists. */ for (const int attribute_index : all_instances_attributes.index_range()) { bke::AttrDomain domain = bke::AttrDomain::Instance; bke::AttributeIDRef id = all_instances_attributes.ids[attribute_index]; eCustomDataType type = all_instances_attributes.kinds[attribute_index].data_type; - blender::bke::MutableAttributeAccessor attr = dst_instances->attributes_for_write(); - attr.lookup_or_add_for_write_only_span(id, domain, type).finish(); + dst_instances->attributes_for_write() + .lookup_or_add_for_write_only_span(id, domain, type) + .finish(); } MutableSpan all_transforms = dst_instances->transforms_for_write(); -- 2.30.2