[Bf-blender-cvs] [c25df02ac30] master: Cleanup: simplify accessing mesh looptris

Jacques Lucke noreply at git.blender.org
Sat Sep 24 11:41:19 CEST 2022


Commit: c25df02ac3036449081701349d36d2f16b2c92f2
Author: Jacques Lucke
Date:   Sat Sep 24 11:41:08 2022 +0200
Branches: master
https://developer.blender.org/rBc25df02ac3036449081701349d36d2f16b2c92f2

Cleanup: simplify accessing mesh looptris

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

M	source/blender/blenkernel/intern/mesh_remesh_voxel.cc
M	source/blender/blenkernel/intern/mesh_runtime.cc
M	source/blender/blenkernel/intern/mesh_sample.cc
M	source/blender/editors/curves/intern/curves_ops.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_add.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_density.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_puff.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
M	source/blender/geometry/intern/mesh_to_volume.cc
M	source/blender/makesdna/DNA_mesh_types.h
M	source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc
M	source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc
M	source/blender/nodes/geometry/nodes/node_geo_sample_nearest.cc

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

diff --git a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
index 12f42dbc4ec..3c492e2e167 100644
--- a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
+++ b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
@@ -194,8 +194,7 @@ static openvdb::FloatGrid::Ptr remesh_voxel_level_set_create(const Mesh *mesh,
 {
   const Span<MVert> verts = mesh->verts();
   const Span<MLoop> loops = mesh->loops();
-  Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(mesh),
-                          BKE_mesh_runtime_looptri_len(mesh)};
+  const Span<MLoopTri> looptris = mesh->looptris();
 
   std::vector<openvdb::Vec3s> points(mesh->totvert);
   std::vector<openvdb::Vec3I> triangles(looptris.size());
diff --git a/source/blender/blenkernel/intern/mesh_runtime.cc b/source/blender/blenkernel/intern/mesh_runtime.cc
index 782657428f5..062d6cdb952 100644
--- a/source/blender/blenkernel/intern/mesh_runtime.cc
+++ b/source/blender/blenkernel/intern/mesh_runtime.cc
@@ -112,6 +112,13 @@ void BKE_mesh_runtime_clear_cache(Mesh *mesh)
   BKE_mesh_clear_derived_normals(mesh);
 }
 
+blender::Span<MLoopTri> Mesh::looptris() const
+{
+  const MLoopTri *looptris = BKE_mesh_runtime_looptri_ensure(this);
+  const int num_looptris = BKE_mesh_runtime_looptri_len(this);
+  return {looptris, num_looptris};
+}
+
 /**
  * Ensure the array is large enough
  *
diff --git a/source/blender/blenkernel/intern/mesh_sample.cc b/source/blender/blenkernel/intern/mesh_sample.cc
index 1ddac19304d..ed7ae8113a7 100644
--- a/source/blender/blenkernel/intern/mesh_sample.cc
+++ b/source/blender/blenkernel/intern/mesh_sample.cc
@@ -22,8 +22,7 @@ BLI_NOINLINE static void sample_point_attribute(const Mesh &mesh,
                                                 const MutableSpan<T> dst)
 {
   const Span<MLoop> loops = mesh.loops();
-  const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
-                                BKE_mesh_runtime_looptri_len(&mesh)};
+  const Span<MLoopTri> looptris = mesh.looptris();
 
   for (const int i : mask) {
     const int looptri_index = looptri_indices[i];
@@ -69,8 +68,7 @@ BLI_NOINLINE static void sample_corner_attribute(const Mesh &mesh,
                                                  const IndexMask mask,
                                                  const MutableSpan<T> dst)
 {
-  const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
-                                BKE_mesh_runtime_looptri_len(&mesh)};
+  const Span<MLoopTri> looptris = mesh.looptris();
 
   for (const int i : mask) {
     const int looptri_index = looptri_indices[i];
@@ -115,8 +113,7 @@ void sample_face_attribute(const Mesh &mesh,
                            const IndexMask mask,
                            const MutableSpan<T> dst)
 {
-  const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
-                                BKE_mesh_runtime_looptri_len(&mesh)};
+  const Span<MLoopTri> looptris = mesh.looptris();
 
   for (const int i : mask) {
     const int looptri_index = looptri_indices[i];
@@ -161,8 +158,7 @@ Span<float3> MeshAttributeInterpolator::ensure_barycentric_coords()
 
   const Span<MVert> verts = mesh_->verts();
   const Span<MLoop> loops = mesh_->loops();
-  const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(mesh_),
-                                BKE_mesh_runtime_looptri_len(mesh_)};
+  const Span<MLoopTri> looptris = mesh_->looptris();
 
   for (const int i : mask_) {
     const int looptri_index = looptri_indices_[i];
@@ -191,8 +187,7 @@ Span<float3> MeshAttributeInterpolator::ensure_nearest_weights()
 
   const Span<MVert> verts = mesh_->verts();
   const Span<MLoop> loops = mesh_->loops();
-  const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(mesh_),
-                                BKE_mesh_runtime_looptri_len(mesh_)};
+  const Span<MLoopTri> looptris = mesh_->looptris();
 
   for (const int i : mask_) {
     const int looptri_index = looptri_indices_[i];
@@ -265,8 +260,7 @@ int sample_surface_points_spherical(RandomNumberGenerator &rng,
 {
   const Span<MVert> verts = mesh.verts();
   const Span<MLoop> loops = mesh.loops();
-  const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
-                                BKE_mesh_runtime_looptri_len(&mesh)};
+  const Span<MLoopTri> looptris = mesh.looptris();
 
   const float sample_radius_sq = pow2f(sample_radius);
   const float sample_plane_area = M_PI * sample_radius_sq;
@@ -363,8 +357,7 @@ int sample_surface_points_projected(
 {
   const Span<MVert> verts = mesh.verts();
   const Span<MLoop> loops = mesh.loops();
-  const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
-                                BKE_mesh_runtime_looptri_len(&mesh)};
+  const Span<MLoopTri> looptris = mesh.looptris();
 
   int point_count = 0;
   for ([[maybe_unused]] const int _ : IndexRange(tries_num)) {
diff --git a/source/blender/editors/curves/intern/curves_ops.cc b/source/blender/editors/curves/intern/curves_ops.cc
index 54d91ccfc90..f52e11276e9 100644
--- a/source/blender/editors/curves/intern/curves_ops.cc
+++ b/source/blender/editors/curves/intern/curves_ops.cc
@@ -232,8 +232,7 @@ static void try_convert_single_object(Object &curves_ob,
   BLI_SCOPED_DEFER([&]() { free_bvhtree_from_mesh(&surface_bvh); });
 
   const Span<float3> positions_cu = curves.positions();
-  const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&surface_me),
-                                BKE_mesh_runtime_looptri_len(&surface_me)};
+  const Span<MLoopTri> looptris = surface_me.looptris();
 
   if (looptris.is_empty()) {
     *r_could_not_convert_some_curves = true;
@@ -545,8 +544,7 @@ static void snap_curves_to_surface_exec_object(Object &curves_ob,
   const Mesh &surface_mesh = *static_cast<const Mesh *>(surface_ob.data);
   const Span<MVert> verts = surface_mesh.verts();
   const Span<MLoop> loops = surface_mesh.loops();
-  const Span<MLoopTri> surface_looptris = {BKE_mesh_runtime_looptri_ensure(&surface_mesh),
-                                           BKE_mesh_runtime_looptri_len(&surface_mesh)};
+  const Span<MLoopTri> surface_looptris = surface_mesh.looptris();
   VArraySpan<float2> surface_uv_map;
   if (curves_id.surface_uv_map != nullptr) {
     const bke::AttributeAccessor surface_attributes = surface_mesh.attributes();
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc
index b5d739ae08e..00130e6d19e 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc
@@ -144,8 +144,7 @@ struct AddOperationExecutor {
     }
     surface_verts_eval_ = surface_eval_->verts();
     surface_loops_eval_ = surface_eval_->loops();
-    surface_looptris_eval_ = {BKE_mesh_runtime_looptri_ensure(surface_eval_),
-                              BKE_mesh_runtime_looptri_len(surface_eval_)};
+    surface_looptris_eval_ = surface_eval_->looptris();
     BKE_bvhtree_from_mesh_get(&surface_bvh_eval_, surface_eval_, BVHTREE_FROM_LOOPTRI, 2);
     BLI_SCOPED_DEFER([&]() { free_bvhtree_from_mesh(&surface_bvh_eval_); });
 
@@ -206,8 +205,7 @@ struct AddOperationExecutor {
       return;
     }
 
-    const Span<MLoopTri> surface_looptris_orig = {BKE_mesh_runtime_looptri_ensure(&surface_orig),
-                                                  BKE_mesh_runtime_looptri_len(&surface_orig)};
+    const Span<MLoopTri> surface_looptris_orig = surface_orig.looptris();
 
     /* Find normals. */
     if (!CustomData_has_layer(&surface_orig.ldata, CD_NORMAL)) {
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_density.cc b/source/blender/editors/sculpt_paint/curves_sculpt_density.cc
index a37eb4bb560..1e598e6bc5b 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_density.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_density.cc
@@ -132,8 +132,7 @@ struct DensityAddOperationExecutor {
 
     BKE_bvhtree_from_mesh_get(&surface_bvh_eval_, surface_eval_, BVHTREE_FROM_LOOPTRI, 2);
     BLI_SCOPED_DEFER([&]() { free_bvhtree_from_mesh(&surface_bvh_eval_); });
-    surface_looptris_eval_ = {BKE_mesh_runtime_looptri_ensure(surface_eval_),
-                              BKE_mesh_runtime_looptri_len(surface_eval_)};
+    surface_looptris_eval_ = surface_eval_->looptris();
     /* Find UV map. */
     VArraySpan<float2> surface_uv_map;
     if (curves_id_orig_->surface_uv_map != nullptr) {
@@ -265,8 +264,7 @@ struct DensityAddOperationExecutor {
         reinterpret_cast<const float3 *>(CustomData_get_layer(&surface_orig_->ldata, CD_NORMAL)),
         surface_orig_->totloop};
 
-    const Span<MLoopTri> surface_looptris_orig = {BKE_mesh_runtime_looptri_ensure(surface_orig_),
-                                                  BKE_mesh_runtime_looptri_len(surface_orig_)};
+    const Span<MLoopTri> surface_looptris_orig = surface_orig_->looptris();
     const geometry::ReverseUVSampler reverse_uv_sampler{surface_uv_map, surface_looptris_orig};
 
     geometry::AddCurvesOnMeshInputs add_inputs;
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc b/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc
index ec69aae372c..b4e949106e7 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc
@@ -121,8 +121,7 @@ struct PuffOperationExecutor {
 
     surface_verts_ = surface_->verts();
     surface_loops_ = surface_->loops();
-    surface_looptris_ = {BKE_mesh_runtime_looptri_ensure(surface_),
-                         BKE_mesh_runtime_looptri_len(surface_)};
+    surface_looptris_ = surface_->looptris();
     BKE_bvhtree_from_mesh_get(&surface_bvh_, surface_, BVHTREE_FROM_LOOPTRI, 2);
     BLI_SCOPED_DEFER([&]() { free_bvhtree_from_mesh(&surface_bvh_); });
 
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc b/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
index 1108f5c72a9..c607f8f3b69 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list