[Bf-blender-cvs] [21adf2ec89a] master: Cleanup: Split UV sample geometry node into two functions

Hans Goudey noreply at git.blender.org
Fri Nov 18 20:43:21 CET 2022


Commit: 21adf2ec89aebf3f73a19331508a40de57c3cfc8
Author: Hans Goudey
Date:   Fri Nov 18 13:38:34 2022 -0600
Branches: master
https://developer.blender.org/rB21adf2ec89aebf3f73a19331508a40de57c3cfc8

Cleanup: Split UV sample geometry node into two functions

This separates the UV reverse sampling and the barycentric mixing of
the mesh attribute into separate multi-functions. This separates
concerns and allows for future de-duplication of the UV sampling
function if that is implemented as an optimization pass. That would
be helpful since it's the much more expensive operation.

This was simplified by returning the triangle index in the reverse
UV sampler rather than a pointer to the triangle, which required
passing a span of triangles separately in a few places.

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

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_slide.cc
M	source/blender/geometry/GEO_add_curves_on_mesh.hh
M	source/blender/geometry/GEO_reverse_uv_sampler.hh
M	source/blender/geometry/intern/add_curves_on_mesh.cc
M	source/blender/geometry/intern/reverse_uv_sampler.cc
M	source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc
M	source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc

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

diff --git a/source/blender/editors/curves/intern/curves_ops.cc b/source/blender/editors/curves/intern/curves_ops.cc
index 1d2b1264477..5673c6876ed 100644
--- a/source/blender/editors/curves/intern/curves_ops.cc
+++ b/source/blender/editors/curves/intern/curves_ops.cc
@@ -635,7 +635,7 @@ static void snap_curves_to_surface_exec_object(Object &curves_ob,
             continue;
           }
 
-          const MLoopTri &looptri = *lookup_result.looptri;
+          const MLoopTri &looptri = surface_looptris[lookup_result.looptri_index];
           const float3 &bary_coords = lookup_result.bary_weights;
 
           const float3 &p0_su = verts[loops[looptri.tri[0]].v].co;
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc
index 0d2c2d3f0c9..fa9cf3d3a04 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc
@@ -228,6 +228,7 @@ struct AddOperationExecutor {
     add_inputs.fallback_curve_length = brush_settings_->curve_length;
     add_inputs.fallback_point_count = std::max(2, brush_settings_->points_per_curve);
     add_inputs.transforms = &transforms_;
+    add_inputs.surface_looptris = surface_looptris_orig;
     add_inputs.reverse_uv_sampler = &reverse_uv_sampler;
     add_inputs.surface = &surface_orig;
     add_inputs.corner_normals_su = corner_normals_su;
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_density.cc b/source/blender/editors/sculpt_paint/curves_sculpt_density.cc
index 78e2d55e6b9..78eea553737 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_density.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_density.cc
@@ -280,6 +280,7 @@ struct DensityAddOperationExecutor {
     add_inputs.transforms = &transforms_;
     add_inputs.surface = surface_orig_;
     add_inputs.corner_normals_su = corner_normals_su;
+    add_inputs.surface_looptris = surface_looptris_orig;
     add_inputs.reverse_uv_sampler = &reverse_uv_sampler;
     add_inputs.old_roots_kdtree = self_->original_curve_roots_kdtree_;
 
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc b/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
index ae89bc1c58b..89110f72e4b 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
@@ -292,8 +292,9 @@ struct SlideOperationExecutor {
       /* Compute the normal at the initial surface position. */
       const float3 normal_cu = math::normalize(
           transforms_.surface_to_curves_normal *
-          geometry::compute_surface_point_normal(
-              *result.looptri, result.bary_weights, corner_normals_orig_su_));
+          geometry::compute_surface_point_normal(surface_looptris_orig_[result.looptri_index],
+                                                 result.bary_weights,
+                                                 corner_normals_orig_su_));
 
       r_curves_to_slide.append({curve_i, radius_falloff, normal_cu});
     }
@@ -389,7 +390,7 @@ struct SlideOperationExecutor {
           found_invalid_uv_mapping_.store(true);
           continue;
         }
-        const MLoopTri &looptri_orig = *result.looptri;
+        const MLoopTri &looptri_orig = surface_looptris_orig_[result.looptri_index];
         const float3 &bary_weights_orig = result.bary_weights;
 
         /* Gather old and new surface normal. */
@@ -397,7 +398,7 @@ struct SlideOperationExecutor {
         const float3 new_normal_cu = math::normalize(
             transforms_.surface_to_curves_normal *
             geometry::compute_surface_point_normal(
-                *result.looptri, result.bary_weights, corner_normals_orig_su_));
+                looptri_orig, result.bary_weights, corner_normals_orig_su_));
 
         /* Gather old and new surface position. */
         const float3 old_first_pos_orig_cu = self_->initial_positions_cu_[first_point_i];
diff --git a/source/blender/geometry/GEO_add_curves_on_mesh.hh b/source/blender/geometry/GEO_add_curves_on_mesh.hh
index 2d2ba89a18f..d0f72deeb46 100644
--- a/source/blender/geometry/GEO_add_curves_on_mesh.hh
+++ b/source/blender/geometry/GEO_add_curves_on_mesh.hh
@@ -30,6 +30,7 @@ struct AddCurvesOnMeshInputs {
 
   /** Information about the surface that the new curves are attached to. */
   const Mesh *surface = nullptr;
+  Span<MLoopTri> surface_looptris;
   const ReverseUVSampler *reverse_uv_sampler = nullptr;
   Span<float3> corner_normals_su;
 
diff --git a/source/blender/geometry/GEO_reverse_uv_sampler.hh b/source/blender/geometry/GEO_reverse_uv_sampler.hh
index ee91e0b0731..62c6382c9d8 100644
--- a/source/blender/geometry/GEO_reverse_uv_sampler.hh
+++ b/source/blender/geometry/GEO_reverse_uv_sampler.hh
@@ -35,7 +35,7 @@ class ReverseUVSampler {
 
   struct Result {
     ResultType type = ResultType::None;
-    const MLoopTri *looptri = nullptr;
+    int looptri_index = -1;
     float3 bary_weights;
   };
 
diff --git a/source/blender/geometry/intern/add_curves_on_mesh.cc b/source/blender/geometry/intern/add_curves_on_mesh.cc
index a03c9b994a9..1cc13a40fc4 100644
--- a/source/blender/geometry/intern/add_curves_on_mesh.cc
+++ b/source/blender/geometry/intern/add_curves_on_mesh.cc
@@ -140,6 +140,7 @@ static void interpolate_position_with_interpolation(CurvesGeometry &curves,
                                                     const Span<float> new_lengths_cu,
                                                     const Span<float3> new_normals_su,
                                                     const bke::CurvesSurfaceTransforms &transforms,
+                                                    const Span<MLoopTri> looptris,
                                                     const ReverseUVSampler &reverse_uv_sampler,
                                                     const Span<float3> corner_normals_su)
 {
@@ -178,7 +179,7 @@ static void interpolate_position_with_interpolation(CurvesGeometry &curves,
         }
 
         const float3 neighbor_normal_su = compute_surface_point_normal(
-            *result.looptri, result.bary_weights, corner_normals_su);
+            looptris[result.looptri_index], result.bary_weights, corner_normals_su);
         const float3 neighbor_normal_cu = math::normalize(transforms.surface_to_curves_normal *
                                                           neighbor_normal_su);
 
@@ -254,7 +255,7 @@ AddCurvesOnMeshOutputs add_curves_on_mesh(CurvesGeometry &curves,
       outputs.uv_error = true;
       continue;
     }
-    const MLoopTri &looptri = *result.looptri;
+    const MLoopTri &looptri = inputs.surface_looptris[result.looptri_index];
     bary_coords.append(result.bary_weights);
     looptris.append(&looptri);
     const float3 root_position_su = attribute_math::mix3<float3>(
@@ -358,6 +359,7 @@ AddCurvesOnMeshOutputs add_curves_on_mesh(CurvesGeometry &curves,
                                             new_lengths_cu,
                                             new_normals_su,
                                             *inputs.transforms,
+                                            inputs.surface_looptris,
                                             *inputs.reverse_uv_sampler,
                                             inputs.corner_normals_su);
   }
diff --git a/source/blender/geometry/intern/reverse_uv_sampler.cc b/source/blender/geometry/intern/reverse_uv_sampler.cc
index f66e4a3ac2e..d69935a8fe3 100644
--- a/source/blender/geometry/intern/reverse_uv_sampler.cc
+++ b/source/blender/geometry/intern/reverse_uv_sampler.cc
@@ -48,7 +48,7 @@ ReverseUVSampler::Result ReverseUVSampler::sample(const float2 &query_uv) const
 
   float best_dist = FLT_MAX;
   float3 best_bary_weights;
-  const MLoopTri *best_looptri;
+  int best_looptri;
 
   /* The distance to an edge that is allowed to be inside or outside the triangle. Without this,
    * the lookup can fail for floating point accuracy reasons when the uv is almost exact on an
@@ -84,7 +84,7 @@ ReverseUVSampler::Result ReverseUVSampler::sample(const float2 &query_uv) const
     if (dist < best_dist) {
       best_dist = dist;
       best_bary_weights = bary_weights;
-      best_looptri = &looptri;
+      best_looptri = looptri_index;
     }
   }
 
diff --git a/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc
index dabd2a1a9f2..d926e7e4e30 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc
@@ -68,9 +68,11 @@ static void deform_curves(const CurvesGeometry &curves,
 
   const Span<MVert> surface_verts_old = surface_mesh_old.verts();
   const Span<MLoop> surface_loops_old = surface_mesh_old.loops();
+  const Span<MLoopTri> surface_looptris_old = surface_mesh_old.looptris();
 
   const Span<MVert> surface_verts_new = surface_mesh_new.verts();
   const Span<MLoop> surface_loops_new = surface_mesh_new.loops();
+  const Span<MLoopTri> surface_looptris_new = surface_mesh_new.looptris();
 
   threading::parallel_for(curves.curves_range(), 256, [&](const IndexRange range) {
     for (const int curve_i : range) {
@@ -85,8 +87,8 @@ static void deform_curves(const CurvesGeometry &curves,
         continue;
       }
 
-      const MLoopTri &looptri_old = *surface_sample_old.looptri;
-      const MLoopTri &looptri_new = *surface_sample_new.looptri;
+      const MLoopTri &looptri_old = surface_looptris_old[surface_sample_old.looptri_index];
+      const MLoopTri &looptri_new = surface_looptris_new[surface_sample_new.looptri_index];
       const float3 &bary_weights_old = surface_sample_old.bary_weights;
       const float3 &bary_weights_new = surface_sample_new.bary_weights;
 
diff --git a/source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc
index 0a6dd569395..0e6e68036d9 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc
@@ -105,9 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list