[Bf-blender-cvs] [5d7f4f2cab2] master: Curves: Port transform node to new data-block
Hans Goudey
noreply at git.blender.org
Fri Mar 18 16:30:36 CET 2022
Commit: 5d7f4f2cab20a936df4bcdb60e9a6943d41566d3
Author: Hans Goudey
Date: Fri Mar 18 10:30:27 2022 -0500
Branches: master
https://developer.blender.org/rB5d7f4f2cab20a936df4bcdb60e9a6943d41566d3
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
===================================================================
M source/blender/blenkernel/intern/curves_geometry.cc
M source/blender/nodes/geometry/nodes/node_geo_transform.cc
===================================================================
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();
diff --git a/source/blender/nodes/geometry/nodes/node_geo_transform.cc b/source/blender/nodes/geometry/nodes/node_geo_transform.cc
index 9159ac081e0..a04544e2814 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_transform.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_transform.cc
@@ -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);
More information about the Bf-blender-cvs
mailing list