[Bf-blender-cvs] [17243337d73] master: Cleanup: Remove unecessary helper function

Hans Goudey noreply at git.blender.org
Sat Jul 31 20:26:07 CEST 2021


Commit: 17243337d7317045a46c521cfc74c3739a5404d6
Author: Hans Goudey
Date:   Sat Jul 31 14:26:01 2021 -0400
Branches: master
https://developer.blender.org/rB17243337d7317045a46c521cfc74c3739a5404d6

Cleanup: Remove unecessary helper function

Retrieving a mesh's looptris now take's a const mesh after
rB5f8969bb4b4, which removes the need for this function.
Since it's only two lines, avoiding the use of a separate function
in this case is simpler.

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

M	source/blender/blenkernel/BKE_mesh_sample.hh
M	source/blender/blenkernel/intern/mesh_sample.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_transfer.cc
M	source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc

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

diff --git a/source/blender/blenkernel/BKE_mesh_sample.hh b/source/blender/blenkernel/BKE_mesh_sample.hh
index dc747ba5b42..2fbf7372a09 100644
--- a/source/blender/blenkernel/BKE_mesh_sample.hh
+++ b/source/blender/blenkernel/BKE_mesh_sample.hh
@@ -40,8 +40,6 @@ using fn::GMutableSpan;
 using fn::GSpan;
 using fn::GVArray;
 
-Span<MLoopTri> get_mesh_looptris(const Mesh &mesh);
-
 void sample_point_attribute(const Mesh &mesh,
                             Span<int> looptri_indices,
                             Span<float3> bary_coords,
diff --git a/source/blender/blenkernel/intern/mesh_sample.cc b/source/blender/blenkernel/intern/mesh_sample.cc
index bd46407d060..5388f6e530e 100644
--- a/source/blender/blenkernel/intern/mesh_sample.cc
+++ b/source/blender/blenkernel/intern/mesh_sample.cc
@@ -24,14 +24,6 @@
 
 namespace blender::bke::mesh_surface_sample {
 
-Span<MLoopTri> get_mesh_looptris(const Mesh &mesh)
-{
-  /* 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));
-  const int looptris_len = BKE_mesh_runtime_looptri_len(&mesh);
-  return {looptris, looptris_len};
-}
-
 template<typename T>
 BLI_NOINLINE static void sample_point_attribute(const Mesh &mesh,
                                                 const Span<int> looptri_indices,
@@ -39,7 +31,8 @@ BLI_NOINLINE static void sample_point_attribute(const Mesh &mesh,
                                                 const VArray<T> &data_in,
                                                 const MutableSpan<T> data_out)
 {
-  const Span<MLoopTri> looptris = get_mesh_looptris(mesh);
+  const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
+                                BKE_mesh_runtime_looptri_len(&mesh)};
 
   for (const int i : bary_coords.index_range()) {
     const int looptri_index = looptri_indices[i];
@@ -85,7 +78,8 @@ BLI_NOINLINE static void sample_corner_attribute(const Mesh &mesh,
                                                  const VArray<T> &data_in,
                                                  const MutableSpan<T> data_out)
 {
-  Span<MLoopTri> looptris = get_mesh_looptris(mesh);
+  const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
+                                BKE_mesh_runtime_looptri_len(&mesh)};
 
   for (const int i : bary_coords.index_range()) {
     const int looptri_index = looptri_indices[i];
@@ -130,7 +124,8 @@ void sample_face_attribute(const Mesh &mesh,
                            const VArray<T> &data_in,
                            const MutableSpan<T> data_out)
 {
-  Span<MLoopTri> looptris = get_mesh_looptris(mesh);
+  const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
+                                BKE_mesh_runtime_looptri_len(&mesh)};
 
   for (const int i : data_out.index_range()) {
     const int looptri_index = looptri_indices[i];
@@ -172,7 +167,8 @@ Span<float3> MeshAttributeInterpolator::ensure_barycentric_coords()
   }
   bary_coords_.reinitialize(positions_.size());
 
-  Span<MLoopTri> looptris = get_mesh_looptris(*mesh_);
+  const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(mesh_),
+                                BKE_mesh_runtime_looptri_len(mesh_)};
 
   for (const int i : bary_coords_.index_range()) {
     const int looptri_index = looptri_indices_[i];
@@ -199,7 +195,8 @@ Span<float3> MeshAttributeInterpolator::ensure_nearest_weights()
   }
   nearest_weights_.reinitialize(positions_.size());
 
-  Span<MLoopTri> looptris = get_mesh_looptris(*mesh_);
+  const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(mesh_),
+                                BKE_mesh_runtime_looptri_len(mesh_)};
 
   for (const int i : nearest_weights_.index_range()) {
     const int looptri_index = looptri_indices_[i];
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_transfer.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_transfer.cc
index 6a23443d3ab..ab2136f4e8d 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_transfer.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_transfer.cc
@@ -204,7 +204,8 @@ static void get_closest_mesh_polygons(const Mesh &mesh,
   Array<int> looptri_indices(positions.size());
   get_closest_mesh_looptris(mesh, positions, looptri_indices, r_distances_sq, r_positions);
 
-  Span<MLoopTri> looptris = bke::mesh_surface_sample::get_mesh_looptris(mesh);
+  const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
+                                BKE_mesh_runtime_looptri_len(&mesh)};
   for (const int i : positions.index_range()) {
     const MLoopTri &looptri = looptris[looptri_indices[i]];
     r_poly_indices[i] = looptri.poly;
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 d456c72744f..99930b5ae46 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
@@ -81,13 +81,6 @@ static float3 normal_to_euler_rotation(const float3 normal)
   return rotation;
 }
 
-static Span<MLoopTri> get_mesh_looptris(const Mesh &mesh)
-{
-  const MLoopTri *looptris = BKE_mesh_runtime_looptri_ensure(&mesh);
-  const int looptris_len = BKE_mesh_runtime_looptri_len(&mesh);
-  return {looptris, looptris_len};
-}
-
 static void sample_mesh_surface(const Mesh &mesh,
                                 const float4x4 &transform,
                                 const float base_density,
@@ -97,7 +90,8 @@ static void sample_mesh_surface(const Mesh &mesh,
                                 Vector<float3> &r_bary_coords,
                                 Vector<int> &r_looptri_indices)
 {
-  Span<MLoopTri> looptris = get_mesh_looptris(mesh);
+  const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
+                                BKE_mesh_runtime_looptri_len(&mesh)};
 
   for (const int looptri_index : looptris.index_range()) {
     const MLoopTri &looptri = looptris[looptri_index];
@@ -208,7 +202,8 @@ BLI_NOINLINE static void update_elimination_mask_based_on_density_factors(
     Span<int> looptri_indices,
     MutableSpan<bool> elimination_mask)
 {
-  Span<MLoopTri> looptris = get_mesh_looptris(mesh);
+  const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
+                                BKE_mesh_runtime_looptri_len(&mesh)};
   for (const int i : bary_coords.index_range()) {
     if (elimination_mask[i]) {
       continue;
@@ -365,7 +360,8 @@ BLI_NOINLINE static void compute_special_attributes(Span<GeometryInstanceGroup>
     const GeometrySet &set = set_group.geometry_set;
     const MeshComponent &component = *set.get_component_for_read<MeshComponent>();
     const Mesh &mesh = *component.get_for_read();
-    Span<MLoopTri> looptris = get_mesh_looptris(mesh);
+    const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
+                                  BKE_mesh_runtime_looptri_len(&mesh)};
 
     for (const float4x4 &transform : set_group.transforms) {
       const int offset = instance_start_offsets[i_instance];



More information about the Bf-blender-cvs mailing list