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
This commit is contained in:
Hans Goudey 2022-03-18 10:30:27 -05:00
parent fe9e7036b0
commit 5d7f4f2cab
Notes: blender-bot 2023-02-14 10:11:49 +01:00
Referenced by issue #95443, Refactor curve nodes to use new data structure
2 changed files with 31 additions and 11 deletions

View File

@ -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();

View File

@ -13,7 +13,6 @@
#include "BKE_curves.hh"
#include "BKE_mesh.h"
#include "BKE_pointcloud.h"
#include "BKE_spline.hh"
#include "BKE_volume.h"
#include "DEG_depsgraph_query.h"
@ -127,9 +126,7 @@ static void translate_geometry_set(GeometrySet &geometry,
const Depsgraph &depsgraph)
{
if (Curves *curves = geometry.get_curves_for_write()) {
std::unique_ptr<CurveEval> curve = curves_to_curve_eval(*curves);
curve->translate(translation);
geometry.replace_curves(curve_eval_to_curves(*curve));
bke::CurvesGeometry::wrap(curves->geometry).translate(translation);
}
if (Mesh *mesh = geometry.get_mesh_for_write()) {
translate_mesh(*mesh, translation);
@ -150,9 +147,7 @@ void transform_geometry_set(GeometrySet &geometry,
const Depsgraph &depsgraph)
{
if (Curves *curves = geometry.get_curves_for_write()) {
std::unique_ptr<CurveEval> curve = curves_to_curve_eval(*curves);
curve->transform(transform);
geometry.replace_curves(curve_eval_to_curves(*curve));
bke::CurvesGeometry::wrap(curves->geometry).transform(transform);
}
if (Mesh *mesh = geometry.get_mesh_for_write()) {
transform_mesh(*mesh, transform);