[Bf-blender-cvs] [40ffb94ab47] master: Cleanup: Use generic utility for copying compressed attribute

Hans Goudey noreply at git.blender.org
Wed Jul 20 01:16:27 CEST 2022


Commit: 40ffb94ab47c29cf989d561922e1970e89a836ca
Author: Hans Goudey
Date:   Tue Jul 19 18:16:12 2022 -0500
Branches: master
https://developer.blender.org/rB40ffb94ab47c29cf989d561922e1970e89a836ca

Cleanup: Use generic utility for copying compressed attribute

In the future, `materialize_compressed_to_uninitialized_threaded`
could be moved somewhere else and reused.

===================================================================

M	source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc
M	source/blender/nodes/geometry/nodes/node_geo_points_to_vertices.cc

===================================================================

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();
     }
   }



More information about the Bf-blender-cvs mailing list