diff options
author | Hans Goudey <h.goudey@me.com> | 2022-03-18 18:30:27 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-03-18 18:30:27 +0300 |
commit | 5d7f4f2cab20a936df4bcdb60e9a6943d41566d3 (patch) | |
tree | 39ccb73e9bcebc62a64e2182d9eb8ccb9f606ecd /source/blender/blenkernel/intern/curves_geometry.cc | |
parent | fe9e7036b00716d8ac986db5b9f832ec80d0a62b (diff) |
Curves: Port transform node to new data-block
Make the new curves' translate and transform functions also affect
the handle position attributes.
Differential Revision: https://developer.blender.org/D14372
Diffstat (limited to 'source/blender/blenkernel/intern/curves_geometry.cc')
-rw-r--r-- | source/blender/blenkernel/intern/curves_geometry.cc | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc index 20d6c4e2f09..1fcdcd2f4e9 100644 --- a/source/blender/blenkernel/intern/curves_geometry.cc +++ b/source/blender/blenkernel/intern/curves_geometry.cc @@ -5,6 +5,7 @@ */ #include <mutex> +#include <utility> #include "MEM_guardedalloc.h" @@ -656,9 +657,8 @@ void CurvesGeometry::tag_normals_changed() this->runtime->normal_cache_dirty = true; } -void CurvesGeometry::translate(const float3 &translation) +static void translate_positions(MutableSpan<float3> positions, const float3 &translation) { - MutableSpan<float3> positions = this->positions(); threading::parallel_for(positions.index_range(), 2048, [&](const IndexRange range) { for (float3 &position : positions.slice(range)) { position += translation; @@ -666,9 +666,8 @@ void CurvesGeometry::translate(const float3 &translation) }); } -void CurvesGeometry::transform(const float4x4 &matrix) +static void transform_positions(MutableSpan<float3> positions, const float4x4 &matrix) { - MutableSpan<float3> positions = this->positions(); threading::parallel_for(positions.index_range(), 1024, [&](const IndexRange range) { for (float3 &position : positions.slice(range)) { position = matrix * position; @@ -676,6 +675,32 @@ void CurvesGeometry::transform(const float4x4 &matrix) }); } +void CurvesGeometry::translate(const float3 &translation) +{ + /* Use `as_const` because the non-const functions can add the handle attributes. */ + translate_positions(this->positions(), translation); + if (!std::as_const(*this).handle_positions_left().is_empty()) { + translate_positions(this->handle_positions_left(), translation); + } + if (!std::as_const(*this).handle_positions_right().is_empty()) { + translate_positions(this->handle_positions_right(), translation); + } + this->tag_positions_changed(); +} + +void CurvesGeometry::transform(const float4x4 &matrix) +{ + /* Use `as_const` because the non-const functions can add the handle attributes. */ + transform_positions(this->positions(), matrix); + if (!std::as_const(*this).handle_positions_left().is_empty()) { + transform_positions(this->handle_positions_left(), matrix); + } + if (!std::as_const(*this).handle_positions_right().is_empty()) { + transform_positions(this->handle_positions_right(), matrix); + } + this->tag_positions_changed(); +} + static std::optional<bounds::MinMaxResult<float3>> curves_bounds(const CurvesGeometry &curves) { Span<float3> positions = curves.positions(); |