Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/curves_geometry.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||
| /** \file | /** \file | ||||
| * \ingroup bke | * \ingroup bke | ||||
| */ | */ | ||||
| #include <mutex> | #include <mutex> | ||||
| #include <utility> | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BLI_bounds.hh" | #include "BLI_bounds.hh" | ||||
| #include "BLI_index_mask_ops.hh" | #include "BLI_index_mask_ops.hh" | ||||
| #include "DNA_curves_types.h" | #include "DNA_curves_types.h" | ||||
| ▲ Show 20 Lines • Show All 635 Lines • ▼ Show 20 Lines | void CurvesGeometry::tag_topology_changed() | ||||
| this->runtime->offsets_cache_dirty = true; | this->runtime->offsets_cache_dirty = true; | ||||
| this->runtime->nurbs_basis_cache_dirty = true; | this->runtime->nurbs_basis_cache_dirty = true; | ||||
| } | } | ||||
| void CurvesGeometry::tag_normals_changed() | void CurvesGeometry::tag_normals_changed() | ||||
| { | { | ||||
| this->runtime->normal_cache_dirty = true; | 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) { | threading::parallel_for(positions.index_range(), 2048, [&](const IndexRange range) { | ||||
| for (float3 &position : positions.slice(range)) { | for (float3 &position : positions.slice(range)) { | ||||
| position += translation; | position += 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) { | threading::parallel_for(positions.index_range(), 1024, [&](const IndexRange range) { | ||||
| for (float3 &position : positions.slice(range)) { | for (float3 &position : positions.slice(range)) { | ||||
| position = matrix * position; | position = matrix * position; | ||||
| } | } | ||||
| }); | }); | ||||
| } | } | ||||
| 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) | static std::optional<bounds::MinMaxResult<float3>> curves_bounds(const CurvesGeometry &curves) | ||||
| { | { | ||||
| Span<float3> positions = curves.positions(); | Span<float3> positions = curves.positions(); | ||||
| if (curves.radius) { | if (curves.radius) { | ||||
| Span<float> radii{curves.radius, curves.points_size()}; | Span<float> radii{curves.radius, curves.points_size()}; | ||||
| return bounds::min_max_with_radii(positions, radii); | return bounds::min_max_with_radii(positions, radii); | ||||
| } | } | ||||
| return bounds::min_max(positions); | return bounds::min_max(positions); | ||||
| ▲ Show 20 Lines • Show All 274 Lines • Show Last 20 Lines | |||||