diff options
author | Johnny Matthews <guitargeek> | 2021-09-15 21:57:01 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-09-15 21:57:01 +0300 |
commit | 231948f33f8f3e79f7ae38ab9b3db3e597f13b4a (patch) | |
tree | b0f47890380d5a48d10f697e33cbb5465aeb2be9 /source/blender/nodes/geometry/nodes/node_geo_curve_reverse.cc | |
parent | a866a32ff257fd9ff4d543adbddad283a189bbc6 (diff) |
Splines: Add a method for reversing a Spline
This moved the spline reversing logic out of the Curve Reverse geometry
node and into the spline class. This allows a spline to reverse itself
with a call to `my_spline.reverse()`
The base class will reverse position, radii & tilt, while specialized
versions are created for Bezier and Nurbs splines to reverse the
additional data that these classes encapsulate.
Differential Revision: https://developer.blender.org/D12501
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_curve_reverse.cc')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_curve_reverse.cc | 42 |
1 files changed, 2 insertions, 40 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_reverse.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_reverse.cc index 70bb9bd28f4..32bcbe2c608 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_reverse.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_reverse.cc @@ -49,47 +49,9 @@ static void geo_node_curve_reverse_exec(GeoNodeExecParams params) threading::parallel_for(splines.index_range(), 128, [&](IndexRange range) { for (const int i : range) { - if (!selection[i]) { - continue; + if (selection[i]) { + splines[i]->reverse(); } - - splines[i]->positions().reverse(); - splines[i]->radii().reverse(); - splines[i]->tilts().reverse(); - - splines[i]->attributes.foreach_attribute( - [&](const AttributeIDRef &attribute_id, const AttributeMetaData &meta_data) { - std::optional<blender::fn::GMutableSpan> output_attribute = - splines[i]->attributes.get_for_write(attribute_id); - if (!output_attribute) { - BLI_assert_unreachable(); - return false; - } - attribute_math::convert_to_static_type(meta_data.data_type, [&](auto dummy) { - using T = decltype(dummy); - output_attribute->typed<T>().reverse(); - }); - return true; - }, - ATTR_DOMAIN_POINT); - - /* Deal with extra info on derived types. */ - if (BezierSpline *spline = dynamic_cast<BezierSpline *>(splines[i].get())) { - spline->handle_types_left().reverse(); - spline->handle_types_right().reverse(); - - spline->handle_positions_left().reverse(); - spline->handle_positions_right().reverse(); - for (int i : spline->handle_positions_left().index_range()) { - std::swap(spline->handle_positions_left()[i], spline->handle_positions_right()[i]); - } - } - else if (NURBSpline *spline = dynamic_cast<NURBSpline *>(splines[i].get())) { - spline->weights().reverse(); - } - /* Nothing to do for poly splines. */ - - splines[i]->mark_cache_invalid(); } }); |