[Bf-blender-cvs] [f0cd1fed189] blender-v3.3-release: Fix T102537: Curve subdivide mishandles single point curves

Hans Goudey noreply at git.blender.org
Mon Nov 28 14:55:11 CET 2022


Commit: f0cd1fed189b5747268bfce8daad13093dbcabb1
Author: Hans Goudey
Date:   Tue Nov 15 18:52:02 2022 -0600
Branches: blender-v3.3-release
https://developer.blender.org/rBf0cd1fed189b5747268bfce8daad13093dbcabb1

Fix T102537: Curve subdivide mishandles single point curves

Also, single point cyclic Catmull Rom curves aren't evaluated properly.
Cyclic is meant to make no difference in that case. Now they correctly
evaluate to a single point.

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

M	source/blender/blenkernel/intern/curve_catmull_rom.cc
M	source/blender/geometry/intern/subdivide_curves.cc

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

diff --git a/source/blender/blenkernel/intern/curve_catmull_rom.cc b/source/blender/blenkernel/intern/curve_catmull_rom.cc
index 952d59edcf9..f26ae1f723f 100644
--- a/source/blender/blenkernel/intern/curve_catmull_rom.cc
+++ b/source/blender/blenkernel/intern/curve_catmull_rom.cc
@@ -12,8 +12,12 @@ namespace blender::bke::curves::catmull_rom {
 int calculate_evaluated_num(const int points_num, const bool cyclic, const int resolution)
 {
   const int eval_num = resolution * segments_num(points_num, cyclic);
+  if (cyclic) {
+    /* Make sure there is a single evaluated point for the single-point curve case. */
+    return std::max(eval_num, 1);
+  }
   /* If the curve isn't cyclic, one last point is added to the final point. */
-  return cyclic ? eval_num : eval_num + 1;
+  return eval_num + 1;
 }
 
 /* Adapted from Cycles #catmull_rom_basis_eval function. */
diff --git a/source/blender/geometry/intern/subdivide_curves.cc b/source/blender/geometry/intern/subdivide_curves.cc
index 8057f029e73..f2c54d4fa59 100644
--- a/source/blender/geometry/intern/subdivide_curves.cc
+++ b/source/blender/geometry/intern/subdivide_curves.cc
@@ -37,16 +37,21 @@ static void calculate_result_offsets(const bke::CurvesGeometry &src_curves,
       const IndexRange src_segments = curve_dst_offsets(src_points, curve_i);
 
       MutableSpan<int> point_offsets = dst_point_offsets.slice(src_segments);
-
       MutableSpan<int> point_counts = point_offsets.drop_back(1);
-      cuts.materialize_compressed(src_points, point_counts);
-      for (int &count : point_counts) {
-        /* Make sure the number of cuts is greater than zero and add one for the existing point. */
-        count = std::max(count, 0) + 1;
+
+      if (src_points.size() == 1) {
+        point_counts.first() = 1;
       }
-      if (!cyclic[curve_i]) {
-        /* The last point only has a segment to be subdivided if the curve isn't cyclic. */
-        point_counts.last() = 1;
+      else {
+        cuts.materialize_compressed(src_points, point_counts);
+        for (int &count : point_counts) {
+          /* Make sure there at least one cut, and add one for the existing point. */
+          count = std::max(count, 0) + 1;
+        }
+        if (!cyclic[curve_i]) {
+          /* The last point only has a segment to be subdivided if the curve isn't cyclic. */
+          point_counts.last() = 1;
+        }
       }
 
       bke::curves::accumulate_counts_to_offsets(point_offsets);



More information about the Bf-blender-cvs mailing list