[Bf-blender-cvs] [be1a41878c0] geometry-nodes-curve-support: Geometry Nodes Curves: Implement copying a curve

Hans Goudey noreply at git.blender.org
Thu Apr 15 17:31:39 CEST 2021


Commit: be1a41878c088e103a0adbbaf8a0234993f6fce3
Author: Hans Goudey
Date:   Thu Apr 15 10:31:27 2021 -0500
Branches: geometry-nodes-curve-support
https://developer.blender.org/rBbe1a41878c088e103a0adbbaf8a0234993f6fce3

Geometry Nodes Curves: Implement copying a curve

This makes the spreadsheet pinning work as well.

===================================================================

M	source/blender/blenkernel/BKE_derived_curve.hh
M	source/blender/blenkernel/intern/derived_curve.cc
M	source/blender/blenkernel/intern/geometry_component_curve.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_derived_curve.hh b/source/blender/blenkernel/BKE_derived_curve.hh
index 3ca28487609..eabbc11b5ca 100644
--- a/source/blender/blenkernel/BKE_derived_curve.hh
+++ b/source/blender/blenkernel/BKE_derived_curve.hh
@@ -75,6 +75,8 @@ struct BezierPoint {
  */
 class Spline {
  public:
+  using SplinePtr = std::unique_ptr<Spline>;
+
   enum Type {
     Bezier,
     NURBS,
@@ -110,6 +112,30 @@ class Spline {
 
  public:
   virtual ~Spline() = default;
+  Spline() = default;
+  Spline(Spline &other)
+      : type(other.type), is_cyclic(other.is_cyclic), normal_mode(other.normal_mode)
+  {
+    if (!other.base_cache_dirty_) {
+      evaluated_positions_cache_ = other.evaluated_positions_cache_;
+      evaluated_mapping_cache_ = other.evaluated_mapping_cache_;
+      base_cache_dirty_ = false;
+    }
+    if (!other.tangent_cache_dirty_) {
+      evaluated_tangents_cache_ = other.evaluated_tangents_cache_;
+      tangent_cache_dirty_ = false;
+    }
+    if (!other.normal_cache_dirty_) {
+      evaluated_normals_cache_ = other.evaluated_normals_cache_;
+      normal_cache_dirty_ = false;
+    }
+    if (!other.length_cache_dirty_) {
+      evaluated_lengths_cache_ = other.evaluated_lengths_cache_;
+      length_cache_dirty_ = false;
+    }
+  }
+
+  virtual SplinePtr copy() const = 0;
 
   virtual int size() const = 0;
   virtual int resolution() const = 0;
@@ -147,6 +173,15 @@ class BezierSpline : public Spline {
   int resolution_u;
 
  public:
+  virtual SplinePtr copy() const final;
+  BezierSpline() = default;
+  BezierSpline(const BezierSpline &other)
+      : Spline((Spline &)other),
+        control_points(other.control_points),
+        resolution_u(other.resolution_u)
+  {
+  }
+
   int size() const final;
   int resolution() const final;
   void set_resolution(const int value) final;
@@ -176,11 +211,20 @@ class NURBSPline : public Spline {
   blender::Vector<NURBSPoint> control_points;
 
  private:
-  int32_t flag; /* Cyclic, smooth. */
   int resolution_u;
   uint8_t order;
 
  public:
+  SplinePtr copy() const final;
+  NURBSPline() = default;
+  NURBSPline(const NURBSPline &other)
+      : Spline((Spline &)other),
+        control_points(other.control_points),
+        resolution_u(other.resolution_u),
+        order(other.order)
+  {
+  }
+
   int size() const final;
   int resolution() const final;
   void set_resolution(const int value) final;
@@ -194,11 +238,14 @@ class NURBSPline : public Spline {
 };
 
 /* Proposed name to be different from DNA type. */
-struct DCurve {
+class DCurve {
+ public:
   blender::Vector<SplinePtr> splines;
 
   // bool is_2d;
 
+  DCurve *copy();
+
   // DCurve *copy();
 };
 
diff --git a/source/blender/blenkernel/intern/derived_curve.cc b/source/blender/blenkernel/intern/derived_curve.cc
index c63f6d2ddf8..e45ea3e014a 100644
--- a/source/blender/blenkernel/intern/derived_curve.cc
+++ b/source/blender/blenkernel/intern/derived_curve.cc
@@ -33,6 +33,17 @@ using blender::Span;
 /** \name General Curve Functions
  * \{ */
 
+DCurve *DCurve::copy()
+{
+  DCurve *new_curve = new DCurve();
+
+  for (SplinePtr &spline : this->splines) {
+    new_curve->splines.append(spline->copy());
+  }
+
+  return new_curve;
+}
+
 static BezierPoint::HandleType handle_type_from_dna_bezt(const eBezTriple_Handle dna_handle_type)
 {
   switch (dna_handle_type) {
@@ -491,6 +502,17 @@ void Spline::trim_lengths(const float start_length, const float end_length)
 /** \name Bezier Spline
  * \{ */
 
+SplinePtr BezierSpline::copy() const
+{
+  SplinePtr new_spline = std::make_unique<BezierSpline>(*this);
+
+  return new_spline;
+}
+
+// BezierSpline(const BezierSpline &other)
+// {
+// }
+
 int BezierSpline::size() const
 {
   return this->control_points.size();
@@ -719,6 +741,13 @@ float BezierSpline::control_point_radius(const int index) const
 /** \name NURBS Spline
  * \{ */
 
+SplinePtr NURBSPline::copy() const
+{
+  SplinePtr new_spline = std::make_unique<NURBSPline>(*this);
+
+  return new_spline;
+}
+
 int NURBSPline::size() const
 {
   return this->control_points.size();
diff --git a/source/blender/blenkernel/intern/geometry_component_curve.cc b/source/blender/blenkernel/intern/geometry_component_curve.cc
index 9a3ec4fca9e..0a0cae65169 100644
--- a/source/blender/blenkernel/intern/geometry_component_curve.cc
+++ b/source/blender/blenkernel/intern/geometry_component_curve.cc
@@ -41,7 +41,7 @@ GeometryComponent *CurveComponent::copy() const
 {
   CurveComponent *new_component = new CurveComponent();
   if (curve_ != nullptr) {
-    // new_component->curve_ = BKE_curve_copy_for_eval(curve_, false);
+    new_component->curve_ = curve_->copy();
     new_component->ownership_ = GeometryOwnershipType::Owned;
   }
   return new_component;
@@ -89,7 +89,7 @@ DCurve *CurveComponent::get_for_write()
 {
   BLI_assert(this->is_mutable());
   if (ownership_ == GeometryOwnershipType::ReadOnly) {
-    // curve_ = BKE_curve_copy_for_eval(curve_, false);
+    curve_ = curve_->copy();
     ownership_ = GeometryOwnershipType::Owned;
   }
   return curve_;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc
index a2f53001886..bb5e35137aa 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc
@@ -290,6 +290,7 @@ static void geo_node_curve_to_mesh_exec(GeoNodeExecParams params)
 
   if (!curve_set.has_curve()) {
     params.set_output("Mesh", GeometrySet());
+    return;
   }
 
   const DCurve *profile_curve = profile_set.get_curve_for_read();



More information about the Bf-blender-cvs mailing list