[Bf-blender-cvs] [d7552814130] attribute-accessor: simplify typed access

Jacques Lucke noreply at git.blender.org
Tue Nov 17 13:55:52 CET 2020


Commit: d7552814130bc41ac137dc56bcda1f70ceb6a0b0
Author: Jacques Lucke
Date:   Tue Nov 17 13:55:23 2020 +0100
Branches: attribute-accessor
https://developer.blender.org/rBd7552814130bc41ac137dc56bcda1f70ceb6a0b0

simplify typed access

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

M	source/blender/blenkernel/BKE_attribute_accessor.hh
M	source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc

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

diff --git a/source/blender/blenkernel/BKE_attribute_accessor.hh b/source/blender/blenkernel/BKE_attribute_accessor.hh
index 05d3afecb23..94e3c692b0b 100644
--- a/source/blender/blenkernel/BKE_attribute_accessor.hh
+++ b/source/blender/blenkernel/BKE_attribute_accessor.hh
@@ -67,29 +67,30 @@ class ReadAttribute {
   virtual void get_internal(const int64_t index, void *r_value) const = 0;
 };
 
-template<typename T> class TypedReadAttributeRef {
+using ReadAttributePtr = std::unique_ptr<ReadAttribute>;
+
+template<typename T> class TypedReadAttribute {
  private:
-  const ReadAttribute &attribute_;
+  ReadAttributePtr attribute_;
 
  public:
-  TypedReadAttributeRef(const ReadAttribute &attribute) : attribute_(attribute)
+  TypedReadAttribute(ReadAttributePtr attribute) : attribute_(std::move(attribute))
   {
-    BLI_assert(attribute.cpp_type().is<T>());
+    BLI_assert(attribute_);
+    BLI_assert(attribute_->cpp_type().is<T>());
   }
 
   T operator[](const int64_t index) const
   {
-    BLI_assert(index < attribute_.size());
+    BLI_assert(index < attribute_->size());
     T value;
     value.~T();
-    attribute_.get(index, &value);
+    attribute_->get(index, &value);
     return value;
   }
 };
 
-using FloatReadAttribute = TypedReadAttributeRef<float>;
-
-using ReadAttributePtr = std::unique_ptr<ReadAttribute>;
+using FloatReadAttribute = TypedReadAttribute<float>;
 
 ReadAttributePtr mesh_attribute_get_for_read(const MeshComponent &mesh_component,
                                              const StringRef attribute_name);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
index 60100a3bf40..94dcf735957 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
@@ -113,13 +113,13 @@ static void geo_point_distribute_exec(GeoNodeExecParams params)
   const Mesh *mesh_in = mesh_component.get_for_read();
 
   const float default_factor = 1.0f;
-  ReadAttributePtr density_factors = bke::mesh_attribute_get_for_read(mesh_component,
-                                                                      density_attribute,
-                                                                      ATTR_DOMAIN_VERTEX,
-                                                                      CPPType::get<float>(),
-                                                                      &default_factor);
+  FloatReadAttribute density_factors = bke::mesh_attribute_get_for_read(mesh_component,
+                                                                        density_attribute,
+                                                                        ATTR_DOMAIN_VERTEX,
+                                                                        CPPType::get<float>(),
+                                                                        &default_factor);
 
-  Vector<float3> points = scatter_points_from_mesh(mesh_in, density, *density_factors);
+  Vector<float3> points = scatter_points_from_mesh(mesh_in, density, density_factors);
 
   PointCloud *pointcloud = BKE_pointcloud_new_nomain(points.size());
   memcpy(pointcloud->co, points.data(), sizeof(float3) * points.size());



More information about the Bf-blender-cvs mailing list