[Bf-blender-cvs] [0e9567c63c4] attribute-accessor: cleanup

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


Commit: 0e9567c63c45fb1546fa44c89ebcf61f84cd7d6d
Author: Jacques Lucke
Date:   Tue Nov 17 13:51:33 2020 +0100
Branches: attribute-accessor
https://developer.blender.org/rB0e9567c63c45fb1546fa44c89ebcf61f84cd7d6d

cleanup

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

M	source/blender/blenkernel/BKE_attribute_accessor.hh
M	source/blender/nodes/NOD_geometry_exec.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 4a43e12044a..05d3afecb23 100644
--- a/source/blender/blenkernel/BKE_attribute_accessor.hh
+++ b/source/blender/blenkernel/BKE_attribute_accessor.hh
@@ -62,20 +62,33 @@ class ReadAttribute {
     this->get_internal(index, r_value);
   }
 
-  template<typename T> T get(const int64_t index) const
+ protected:
+  /* r_value is expected to be uninitialized. */
+  virtual void get_internal(const int64_t index, void *r_value) const = 0;
+};
+
+template<typename T> class TypedReadAttributeRef {
+ private:
+  const ReadAttribute &attribute_;
+
+ public:
+  TypedReadAttributeRef(const ReadAttribute &attribute) : attribute_(attribute)
   {
-    BLI_assert(index < size_);
+    BLI_assert(attribute.cpp_type().is<T>());
+  }
+
+  T operator[](const int64_t index) const
+  {
+    BLI_assert(index < attribute_.size());
     T value;
     value.~T();
-    this->get_internal(index, &value);
+    attribute_.get(index, &value);
     return value;
   }
-
- protected:
-  /* r_value is expected to be uninitialized. */
-  virtual void get_internal(const int64_t index, void *r_value) const = 0;
 };
 
+using FloatReadAttribute = TypedReadAttributeRef<float>;
+
 using ReadAttributePtr = std::unique_ptr<ReadAttribute>;
 
 ReadAttributePtr mesh_attribute_get_for_read(const MeshComponent &mesh_component,
diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh
index fd85836df6d..ad90df01175 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -26,6 +26,7 @@
 
 namespace blender::nodes {
 
+using bke::FloatReadAttribute;
 using bke::PersistentDataHandleMap;
 using bke::PersistentObjectHandle;
 using bke::ReadAttribute;
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 09772341f35..60100a3bf40 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
@@ -47,7 +47,7 @@ namespace blender::nodes {
 
 static Vector<float3> scatter_points_from_mesh(const Mesh *mesh,
                                                const float density,
-                                               const ReadAttribute &density_factors)
+                                               const FloatReadAttribute &density_factors)
 {
   /* This only updates a cache and can be considered to be logically const. */
   const MLoopTri *looptris = BKE_mesh_runtime_looptri_ensure(const_cast<Mesh *>(mesh));
@@ -63,9 +63,9 @@ static Vector<float3> scatter_points_from_mesh(const Mesh *mesh,
     const float3 v0_pos = mesh->mvert[v0_index].co;
     const float3 v1_pos = mesh->mvert[v1_index].co;
     const float3 v2_pos = mesh->mvert[v2_index].co;
-    const float v0_density_factor = density_factors.get<float>(v0_index);
-    const float v1_density_factor = density_factors.get<float>(v1_index);
-    const float v2_density_factor = density_factors.get<float>(v2_index);
+    const float v0_density_factor = density_factors[v0_index];
+    const float v1_density_factor = density_factors[v1_index];
+    const float v2_density_factor = density_factors[v2_index];
     const float looptri_density_factor = (v0_density_factor + v1_density_factor +
                                           v2_density_factor) /
                                          3.0f;



More information about the Bf-blender-cvs mailing list