[Bf-blender-cvs] [dccdc6213ec] master: Curves: Expose function to calculate vector handles

Hans Goudey noreply at git.blender.org
Mon Jul 4 18:52:19 CEST 2022


Commit: dccdc6213ec6ff3c3ff681090f56648ec4023034
Author: Hans Goudey
Date:   Mon Jul 4 11:50:33 2022 -0500
Branches: master
https://developer.blender.org/rBdccdc6213ec6ff3c3ff681090f56648ec4023034

Curves: Expose function to calculate vector handles

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

M	source/blender/blenkernel/BKE_curves.hh
M	source/blender/blenkernel/intern/curve_bezier.cc

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

diff --git a/source/blender/blenkernel/BKE_curves.hh b/source/blender/blenkernel/BKE_curves.hh
index b1f096b1c39..cc0c607f9bb 100644
--- a/source/blender/blenkernel/BKE_curves.hh
+++ b/source/blender/blenkernel/BKE_curves.hh
@@ -515,6 +515,14 @@ void calculate_evaluated_offsets(Span<int8_t> handle_types_left,
                                  int resolution,
                                  MutableSpan<int> evaluated_offsets);
 
+/**
+ * Calculate the automatically defined positions for a vector handle (#BEZIER_HANDLE_VECTOR). While
+ * this can be calculated automatically with #calculate_auto_handles, when more context is
+ * available, it can be preferable for performance reasons to calculate it for a single segment
+ * when necessary.
+ */
+float3 calculate_vector_handle(const float3 &point, const float3 &next_point);
+
 /**
  * Recalculate all auto (#BEZIER_HANDLE_AUTO) and vector (#BEZIER_HANDLE_VECTOR) handles with
  * positions automatically derived from the neighboring control points, and update aligned
@@ -819,6 +827,11 @@ inline bool point_is_sharp(const Span<int8_t> handle_types_left,
          ELEM(handle_types_right[index], BEZIER_HANDLE_VECTOR, BEZIER_HANDLE_FREE);
 }
 
+inline float3 calculate_vector_handle(const float3 &point, const float3 &next_point)
+{
+  return math::interpolate(point, next_point, 1.0f / 3.0f);
+}
+
 /** \} */
 
 }  // namespace curves::bezier
diff --git a/source/blender/blenkernel/intern/curve_bezier.cc b/source/blender/blenkernel/intern/curve_bezier.cc
index 5ba17f1761b..1d6ee4938b5 100644
--- a/source/blender/blenkernel/intern/curve_bezier.cc
+++ b/source/blender/blenkernel/intern/curve_bezier.cc
@@ -106,11 +106,11 @@ static void calculate_point_handles(const HandleType type_left,
   }
 
   if (type_left == BEZIER_HANDLE_VECTOR) {
-    left = math::interpolate(position, prev_position, 1.0f / 3.0f);
+    left = calculate_vector_handle(position, prev_position);
   }
 
   if (type_right == BEZIER_HANDLE_VECTOR) {
-    right = math::interpolate(position, next_position, 1.0f / 3.0f);
+    right = calculate_vector_handle(position, next_position);
   }
 
   /* When one of the handles is "aligned" handle, it must be aligned with the other, i.e. point in



More information about the Bf-blender-cvs mailing list