diff options
author | Hans Goudey <h.goudey@me.com> | 2022-07-20 02:16:12 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-07-20 02:16:12 +0300 |
commit | 40ffb94ab47c29cf989d561922e1970e89a836ca (patch) | |
tree | d390755eb84eccf48b81922b8212379a2ac59754 | |
parent | 410a6efb747f188da30c75074d6bf318b862d5d5 (diff) |
Cleanup: Use generic utility for copying compressed attribute
In the future, `materialize_compressed_to_uninitialized_threaded`
could be moved somewhere else and reused.
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc | 19 | ||||
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_points_to_vertices.cc | 15 |
2 files changed, 4 insertions, 30 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc b/source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc index b3f04186c63..f14329c96da 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc @@ -22,16 +22,6 @@ static void node_declare(NodeDeclarationBuilder &b) b.add_output<decl::Geometry>(N_("Points")); } -template<typename T> -static void copy_attribute_to_points(const VArray<T> &src, - const IndexMask mask, - MutableSpan<T> dst) -{ - for (const int i : mask.index_range()) { - dst[i] = src[mask[i]]; - } -} - static void convert_instances_to_points(GeometrySet &geometry_set, Field<float3> position_field, Field<float> radius_field, @@ -65,8 +55,8 @@ static void convert_instances_to_points(GeometrySet &geometry_set, bke::SpanAttributeWriter<float> point_radii = point_attributes.lookup_or_add_for_write_only_span<float>("radius", ATTR_DOMAIN_POINT); - copy_attribute_to_points(positions, selection, point_positions.span); - copy_attribute_to_points(radii, selection, point_radii.span); + positions.materialize_compressed_to_uninitialized(selection, point_positions.span); + radii.materialize_compressed_to_uninitialized(selection, point_radii.span); point_positions.finish(); point_radii.finish(); @@ -90,10 +80,7 @@ static void convert_instances_to_points(GeometrySet &geometry_set, attribute_id, ATTR_DOMAIN_POINT, attribute_kind.data_type); BLI_assert(dst); - attribute_math::convert_to_static_type(attribute_kind.data_type, [&](auto dummy) { - using T = decltype(dummy); - copy_attribute_to_points(src.typed<T>(), selection, dst.span.typed<T>()); - }); + src.materialize_compressed_to_uninitialized(selection, dst.span.data()); dst.finish(); } } diff --git a/source/blender/nodes/geometry/nodes/node_geo_points_to_vertices.cc b/source/blender/nodes/geometry/nodes/node_geo_points_to_vertices.cc index 9cc64d4bc44..74fff8efeee 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_points_to_vertices.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_points_to_vertices.cc @@ -18,14 +18,6 @@ static void node_declare(NodeDeclarationBuilder &b) b.add_output<decl::Geometry>(N_("Mesh")); } -template<typename T> -static void copy_attribute_to_vertices(const Span<T> src, const IndexMask mask, MutableSpan<T> dst) -{ - for (const int i : mask.index_range()) { - dst[i] = src[mask[i]]; - } -} - /* One improvement would be to move the attribute arrays directly to the mesh when possible. */ static void geometry_set_points_to_vertices(GeometrySet &geometry_set, Field<bool> &selection_field) @@ -66,12 +58,7 @@ static void geometry_set_points_to_vertices(GeometrySet &geometry_set, mesh_component.attributes_for_write()->lookup_or_add_for_write_only_span( attribute_id, ATTR_DOMAIN_POINT, data_type); if (dst && src) { - attribute_math::convert_to_static_type(data_type, [&](auto dummy) { - using T = decltype(dummy); - VArray<T> src_typed = src.typed<T>(); - VArraySpan<T> src_typed_span{src_typed}; - copy_attribute_to_vertices(src_typed_span, selection, dst.span.typed<T>()); - }); + src.materialize_compressed_to_uninitialized(selection, dst.span.data()); dst.finish(); } } |