[Bf-blender-cvs] [a6f2da1caf2] geometry-nodes-curve-support: Geometry nodes curves: Transform curve from object info node
Hans Goudey
noreply at git.blender.org
Thu Apr 15 20:52:24 CEST 2021
Commit: a6f2da1caf2ac7d7ac0b2c08415cffa0958a432e
Author: Hans Goudey
Date: Thu Apr 15 13:52:18 2021 -0500
Branches: geometry-nodes-curve-support
https://developer.blender.org/rBa6f2da1caf2ac7d7ac0b2c08415cffa0958a432e
Geometry nodes curves: Transform curve from object info node
===================================================================
M source/blender/blenkernel/BKE_derived_curve.hh
M source/blender/blenkernel/intern/derived_curve.cc
M source/blender/nodes/geometry/nodes/node_geo_object_info.cc
M source/blender/nodes/geometry/nodes/node_geo_transform.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_derived_curve.hh b/source/blender/blenkernel/BKE_derived_curve.hh
index 37d874e0ac8..3cb1f42e6f6 100644
--- a/source/blender/blenkernel/BKE_derived_curve.hh
+++ b/source/blender/blenkernel/BKE_derived_curve.hh
@@ -23,6 +23,7 @@
#include <mutex>
#include "BLI_float3.hh"
+#include "BLI_float4x4.hh"
#include "BLI_vector.hh"
#include "BKE_curve.h"
@@ -280,6 +281,9 @@ class DCurve {
DCurve *copy();
// DCurve *copy();
+
+ void translate(const blender::float3 translation);
+ void transform(const blender::float4x4 &transform);
};
DCurve *dcurve_from_dna_curve(const Curve &curve);
\ No newline at end of file
diff --git a/source/blender/blenkernel/intern/derived_curve.cc b/source/blender/blenkernel/intern/derived_curve.cc
index 6e123cc0839..eb2e185e724 100644
--- a/source/blender/blenkernel/intern/derived_curve.cc
+++ b/source/blender/blenkernel/intern/derived_curve.cc
@@ -25,6 +25,7 @@
using blender::Array;
using blender::float3;
+using blender::float4x4;
using blender::IndexRange;
using blender::MutableSpan;
using blender::Span;
@@ -44,6 +45,44 @@ DCurve *DCurve::copy()
return new_curve;
}
+void DCurve::translate(const float3 translation)
+{
+ for (SplinePtr &spline : this->splines) {
+ if (BezierSpline *bezier_spline = dynamic_cast<BezierSpline *>(spline.get())) {
+ for (BezierPoint &point : bezier_spline->control_points) {
+ point.handle_position_a += translation;
+ point.position += translation;
+ point.handle_position_b += translation;
+ }
+ }
+ else if (PolySpline *poly_spline = dynamic_cast<PolySpline *>(spline.get())) {
+ for (PolyPoint &point : poly_spline->control_points) {
+ point.position += translation;
+ }
+ }
+ spline->mark_cache_invalid();
+ }
+}
+
+void DCurve::transform(const float4x4 &matrix)
+{
+ for (SplinePtr &spline : this->splines) {
+ if (BezierSpline *bezier_spline = dynamic_cast<BezierSpline *>(spline.get())) {
+ for (BezierPoint &point : bezier_spline->control_points) {
+ point.handle_position_a = matrix * point.handle_position_a;
+ point.position = matrix * point.position;
+ point.handle_position_b = matrix * point.handle_position_b;
+ }
+ }
+ else if (PolySpline *poly_spline = dynamic_cast<PolySpline *>(spline.get())) {
+ for (PolyPoint &point : poly_spline->control_points) {
+ point.position = matrix * point.position;
+ }
+ }
+ spline->mark_cache_invalid();
+ }
+}
+
static BezierPoint::HandleType handle_type_from_dna_bezt(const eBezTriple_Handle dna_handle_type)
{
switch (dna_handle_type) {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_object_info.cc b/source/blender/nodes/geometry/nodes/node_geo_object_info.cc
index a48b3744a9c..9764940115e 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_object_info.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_object_info.cc
@@ -64,23 +64,27 @@ static void geo_node_object_info_exec(GeoNodeExecParams params)
const Object *self_object = params.self_object();
if (object != nullptr) {
- if (object->type == OB_CURVE) {
- geometry_set = GeometrySet::create_with_curve(dcurve_from_dna_curve(*(Curve *)object->data));
+ float transform[4][4];
+ mul_m4_m4m4(transform, self_object->imat, object->obmat);
+
+ float quaternion[4];
+ if (transform_space_relative) {
+ mat4_decompose(location, quaternion, scale, transform);
}
else {
- float transform[4][4];
- mul_m4_m4m4(transform, self_object->imat, object->obmat);
+ mat4_decompose(location, quaternion, scale, object->obmat);
+ }
+ quat_to_eul(rotation, quaternion);
- float quaternion[4];
- if (transform_space_relative) {
- mat4_decompose(location, quaternion, scale, transform);
+ if (object != self_object) {
+ if (object->type == OB_CURVE) {
+ DCurve *curve = dcurve_from_dna_curve(*(Curve *)object->data);
+ if (transform_space_relative) {
+ curve->transform(float4x4(transform));
+ }
+ geometry_set = GeometrySet::create_with_curve(curve);
}
else {
- mat4_decompose(location, quaternion, scale, object->obmat);
- }
- quat_to_eul(rotation, quaternion);
-
- if (object != self_object) {
InstancesComponent &instances = geometry_set.get_component_for_write<InstancesComponent>();
if (transform_space_relative) {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_transform.cc b/source/blender/nodes/geometry/nodes/node_geo_transform.cc
index be92804e313..9fc8e6daccc 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_transform.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_transform.cc
@@ -160,31 +160,11 @@ static void transform_curve(DCurve &curve,
{
if (use_translate(rotation, scale)) {
- for (SplinePtr &spline : curve.splines) {
- if (spline->type == Spline::Type::Bezier) {
- BezierSpline &bezier_spline = static_cast<BezierSpline &>(*spline);
- for (BezierPoint &point : bezier_spline.control_points) {
- point.handle_position_a += translation;
- point.position += translation;
- point.handle_position_b += translation;
- }
- }
- spline->mark_cache_invalid();
- }
+ curve.translate(translation);
}
else {
const float4x4 matrix = float4x4::from_loc_eul_scale(translation, rotation, scale);
- for (SplinePtr &spline : curve.splines) {
- if (spline->type == Spline::Type::Bezier) {
- BezierSpline &bezier_spline = static_cast<BezierSpline &>(*spline);
- for (BezierPoint &point : bezier_spline.control_points) {
- point.handle_position_a = matrix * point.handle_position_a;
- point.position = matrix * point.position;
- point.handle_position_b = matrix * point.handle_position_b;
- }
- }
- spline->mark_cache_invalid();
- }
+ curve.transform(matrix);
}
}
More information about the Bf-blender-cvs
mailing list