[Bf-blender-cvs] [5b4732f81ca] master: Cleanup: Use new enum for CurveEval handle types
Hans Goudey
noreply at git.blender.org
Tue Feb 22 23:38:12 CET 2022
Commit: 5b4732f81ca8a159e937336fba7c8eb3220216de
Author: Hans Goudey
Date: Tue Feb 22 17:37:58 2022 -0500
Branches: master
https://developer.blender.org/rB5b4732f81ca8a159e937336fba7c8eb3220216de
Cleanup: Use new enum for CurveEval handle types
This will make the transition to the new curves data structure
a bit simple, since the handle types can be copied directly between
the two. The change to CurveEval is simple because it is runtime-only.
===================================================================
M source/blender/blenkernel/BKE_spline.hh
M source/blender/blenkernel/intern/curve_eval.cc
M source/blender/blenkernel/intern/spline_bezier.cc
M source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_select_by_handle_type.cc
M source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_set_handles.cc
M source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_spline_type.cc
M source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_subdivide.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_primitive_bezier_segment.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_set_handles.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_subdivide.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc
M source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_spline.hh b/source/blender/blenkernel/BKE_spline.hh
index 846dcd3ca8e..646af6f8f98 100644
--- a/source/blender/blenkernel/BKE_spline.hh
+++ b/source/blender/blenkernel/BKE_spline.hh
@@ -10,6 +10,8 @@
#include "FN_generic_virtual_array.hh"
+#include "DNA_curves_types.h"
+
#include "BLI_float4x4.hh"
#include "BLI_math_vec_types.hh"
#include "BLI_vector.hh"
@@ -252,26 +254,13 @@ class Spline {
* factors and indices in a list of floats, which is then used to interpolate any other data.
*/
class BezierSpline final : public Spline {
- public:
- enum class HandleType {
- /** The handle can be moved anywhere, and doesn't influence the point's other handle. */
- Free,
- /** The location is automatically calculated to be smooth. */
- Auto,
- /** The location is calculated to point to the next/previous control point. */
- Vector,
- /** The location is constrained to point in the opposite direction as the other handle. */
- Align,
- };
-
- private:
blender::Vector<blender::float3> positions_;
blender::Vector<float> radii_;
blender::Vector<float> tilts_;
int resolution_;
- blender::Vector<HandleType> handle_types_left_;
- blender::Vector<HandleType> handle_types_right_;
+ blender::Vector<int8_t> handle_types_left_;
+ blender::Vector<int8_t> handle_types_right_;
/* These are mutable to allow lazy recalculation of #Auto and #Vector handle positions. */
mutable blender::Vector<blender::float3> handle_positions_left_;
@@ -323,8 +312,8 @@ class BezierSpline final : public Spline {
blender::Span<float> radii() const final;
blender::MutableSpan<float> tilts() final;
blender::Span<float> tilts() const final;
- blender::Span<HandleType> handle_types_left() const;
- blender::MutableSpan<HandleType> handle_types_left();
+ blender::Span<int8_t> handle_types_left() const;
+ blender::MutableSpan<int8_t> handle_types_left();
blender::Span<blender::float3> handle_positions_left() const;
/**
* Get writable access to the handle position.
@@ -333,8 +322,8 @@ class BezierSpline final : public Spline {
* uninitialized memory while auto-generating handles.
*/
blender::MutableSpan<blender::float3> handle_positions_left(bool write_only = false);
- blender::Span<HandleType> handle_types_right() const;
- blender::MutableSpan<HandleType> handle_types_right();
+ blender::Span<int8_t> handle_types_right() const;
+ blender::MutableSpan<int8_t> handle_types_right();
blender::Span<blender::float3> handle_positions_right() const;
/**
* Get writable access to the handle position.
diff --git a/source/blender/blenkernel/intern/curve_eval.cc b/source/blender/blenkernel/intern/curve_eval.cc
index 7fb833e67f8..49010caef24 100644
--- a/source/blender/blenkernel/intern/curve_eval.cc
+++ b/source/blender/blenkernel/intern/curve_eval.cc
@@ -160,24 +160,24 @@ void CurveEval::mark_cache_invalid()
}
}
-static BezierSpline::HandleType handle_type_from_dna_bezt(const eBezTriple_Handle dna_handle_type)
+static HandleType handle_type_from_dna_bezt(const eBezTriple_Handle dna_handle_type)
{
switch (dna_handle_type) {
case HD_FREE:
- return BezierSpline::HandleType::Free;
+ return BEZIER_HANDLE_FREE;
case HD_AUTO:
- return BezierSpline::HandleType::Auto;
+ return BEZIER_HANDLE_AUTO;
case HD_VECT:
- return BezierSpline::HandleType::Vector;
+ return BEZIER_HANDLE_VECTOR;
case HD_ALIGN:
- return BezierSpline::HandleType::Align;
+ return BEZIER_HANDLE_ALIGN;
case HD_AUTO_ANIM:
- return BezierSpline::HandleType::Auto;
+ return BEZIER_HANDLE_AUTO;
case HD_ALIGN_DOUBLESIDE:
- return BezierSpline::HandleType::Align;
+ return BEZIER_HANDLE_ALIGN;
}
BLI_assert_unreachable();
- return BezierSpline::HandleType::Auto;
+ return BEZIER_HANDLE_AUTO;
}
static Spline::NormalCalculationMode normal_mode_from_dna_curve(const int twist_mode)
@@ -220,8 +220,8 @@ static SplinePtr spline_from_dna_bezier(const Nurb &nurb)
MutableSpan<float3> positions = spline->positions();
MutableSpan<float3> handle_positions_left = spline->handle_positions_left(true);
MutableSpan<float3> handle_positions_right = spline->handle_positions_right(true);
- MutableSpan<BezierSpline::HandleType> handle_types_left = spline->handle_types_left();
- MutableSpan<BezierSpline::HandleType> handle_types_right = spline->handle_types_right();
+ MutableSpan<int8_t> handle_types_left = spline->handle_types_left();
+ MutableSpan<int8_t> handle_types_right = spline->handle_types_right();
MutableSpan<float> radii = spline->radii();
MutableSpan<float> tilts = spline->tilts();
diff --git a/source/blender/blenkernel/intern/spline_bezier.cc b/source/blender/blenkernel/intern/spline_bezier.cc
index 57f1d73d55e..3c2ac1dae9c 100644
--- a/source/blender/blenkernel/intern/spline_bezier.cc
+++ b/source/blender/blenkernel/intern/spline_bezier.cc
@@ -93,11 +93,11 @@ Span<float> BezierSpline::tilts() const
{
return tilts_;
}
-Span<BezierSpline::HandleType> BezierSpline::handle_types_left() const
+Span<int8_t> BezierSpline::handle_types_left() const
{
return handle_types_left_;
}
-MutableSpan<BezierSpline::HandleType> BezierSpline::handle_types_left()
+MutableSpan<int8_t> BezierSpline::handle_types_left()
{
return handle_types_left_;
}
@@ -114,11 +114,11 @@ MutableSpan<float3> BezierSpline::handle_positions_left(const bool write_only)
return handle_positions_left_;
}
-Span<BezierSpline::HandleType> BezierSpline::handle_types_right() const
+Span<int8_t> BezierSpline::handle_types_right() const
{
return handle_types_right_;
}
-MutableSpan<BezierSpline::HandleType> BezierSpline::handle_types_right()
+MutableSpan<int8_t> BezierSpline::handle_types_right()
{
return handle_types_right_;
}
@@ -187,7 +187,7 @@ void BezierSpline::ensure_auto_handles() const
for (const int i : IndexRange(this->size())) {
using namespace blender;
- if (ELEM(HandleType::Auto, handle_types_left_[i], handle_types_right_[i])) {
+ if (ELEM(BEZIER_HANDLE_AUTO, handle_types_left_[i], handle_types_right_[i])) {
const float3 prev_diff = positions_[i] - previous_position(positions_, is_cyclic_, i);
const float3 next_diff = next_position(positions_, is_cyclic_, i) - positions_[i];
float prev_len = math::length(prev_diff);
@@ -203,23 +203,23 @@ void BezierSpline::ensure_auto_handles() const
/* This magic number is unfortunate, but comes from elsewhere in Blender. */
const float len = math::length(dir) * 2.5614f;
if (len != 0.0f) {
- if (handle_types_left_[i] == HandleType::Auto) {
+ if (handle_types_left_[i] == BEZIER_HANDLE_AUTO) {
const float prev_len_clamped = std::min(prev_len, next_len * 5.0f);
handle_positions_left_[i] = positions_[i] + dir * -(prev_len_clamped / len);
}
- if (handle_types_right_[i] == HandleType::Auto) {
+ if (handle_types_right_[i] == BEZIER_HANDLE_AUTO) {
const float next_len_clamped = std::min(next_len, prev_len * 5.0f);
handle_positions_right_[i] = positions_[i] + dir * (next_len_clamped / len);
}
}
}
- if (handle_types_left_[i] == HandleType::Vector) {
+ if (handle_types_left_[i] == BEZIER_HANDLE_VECTOR) {
const float3 prev = previous_position(positions_, is_cyclic_, i);
handle_positions_left_[i] = math::interpolate(positions_[i], prev, 1.0f / 3.0f);
}
- if (handle_types_right_[i] == HandleType::Vector) {
+ if (handle_types_right_[i] == BEZIER_HANDLE_VECTOR) {
const float3 next = next_position(positions_, is_cyclic_, i);
handle_positions_right_[i] = math::interpolate(positions_[i], next, 1.0f / 3.0f);
}
@@ -257,8 +257,8 @@ void BezierSpline::transform(const blender::float4x4 &matrix)
}
static void set_handle_position(const float3 &position,
- const BezierSpline::HandleType type,
- const BezierSpline::HandleType type_other,
+ const HandleType type,
+ const HandleType type_other,
const float3 &new_value,
float3 &handle,
float3 &handle_other)
@@ -266,12 +266,12 @@ static void set_handle_position(const float3 &position,
using namespace blender::math;
/* Don't bother when the handle positions are calculated automatically anyway. */
- if (ELEM(type, BezierSpline::HandleType::Auto, BezierSpline::HandleType::Vector)) {
+ if (ELEM(type, BEZIER_HANDLE_AUTO, BEZIER_HANDLE_VECTOR)) {
return;
}
handle = new_value;
- if (type_other == BezierSpline::HandleType::Align) {
+ if (type_other == BEZIER_HANDLE_ALIGN) {
/* Keep track of the old length of the opposite handle. */
const float length = distance(handle_other, position);
/* Set the other handle to directly opposite from the current handle. */
@@ -283,8 +283,8 @@ static void set_handle_position(const float3 &position,
void BezierSpline::set_handle_position_right(const int index, const blender::float3 &value)
{
set_handle_position(positions_[index],
- handle_types_right_[index],
- handle_types_left_[index],
+ static_cast<HandleType>(handle_types_right_[index]),
+ static_cast<HandleType>(handle_types_left_[index]),
value,
handle_positions_right_[index],
handle_positions_left_[index]);
@@ -293,8 +293,8 @@ void BezierSpline::set_handle_position_right(const int index, const blender::flo
void BezierSpline::set_handle_position_left(const int index, const blender::float3 &value)
{
set_handle_position(positions_[index],
- handle_types_left_[index],
- handle_types_right_[index],
+ static_cast<HandleType>(handle_types_right_[index]),
+ static_cast<HandleType>(handle_types_left_[index]),
value,
h
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list