[Bf-blender-cvs] [0d203862ca0] geometry-nodes-curve-support: Geometry Nodes Curves: Add initial support for poly splines

Hans Goudey noreply at git.blender.org
Thu Apr 15 19:13:26 CEST 2021


Commit: 0d203862ca0e743048e5646d6d0a4e6a7f2a1f00
Author: Hans Goudey
Date:   Thu Apr 15 12:13:20 2021 -0500
Branches: geometry-nodes-curve-support
https://developer.blender.org/rB0d203862ca0e743048e5646d6d0a4e6a7f2a1f00

Geometry Nodes Curves: Add initial support for poly splines

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

M	source/blender/blenkernel/BKE_derived_curve.hh
M	source/blender/blenkernel/intern/derived_curve.cc

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

diff --git a/source/blender/blenkernel/BKE_derived_curve.hh b/source/blender/blenkernel/BKE_derived_curve.hh
index eabbc11b5ca..37d874e0ac8 100644
--- a/source/blender/blenkernel/BKE_derived_curve.hh
+++ b/source/blender/blenkernel/BKE_derived_curve.hh
@@ -237,6 +237,39 @@ class NURBSPline : public Spline {
   float control_point_radius(const int index) const final;
 };
 
+struct PolyPoint {
+  blender::float3 position;
+  float radius;
+
+  /* User defined tilt in radians, added on top of the auto-calculated tilt. */
+  float tilt;
+};
+
+class PolySpline : public Spline {
+ public:
+  blender::Vector<PolyPoint> control_points;
+
+ private:
+ public:
+  SplinePtr copy() const final;
+  PolySpline() = default;
+  PolySpline(const PolySpline &other)
+      : Spline((Spline &)other), control_points(other.control_points)
+  {
+  }
+
+  int size() const final;
+  int resolution() const final;
+  void set_resolution(const int value) final;
+  int evaluated_points_size() const final;
+
+ protected:
+  void correct_end_tangents() const final;
+  void ensure_base_cache() const final;
+
+  float control_point_radius(const int index) const final;
+};
+
 /* Proposed name to be different from DNA type. */
 class DCurve {
  public:
diff --git a/source/blender/blenkernel/intern/derived_curve.cc b/source/blender/blenkernel/intern/derived_curve.cc
index e45ea3e014a..6e123cc0839 100644
--- a/source/blender/blenkernel/intern/derived_curve.cc
+++ b/source/blender/blenkernel/intern/derived_curve.cc
@@ -113,6 +113,19 @@ DCurve *dcurve_from_dna_curve(const Curve &dna_curve)
         break;
       }
       case CU_POLY: {
+        std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>();
+        spline->type = Spline::Type::Poly;
+        spline->is_cyclic = nurb->flagu & CU_NURB_CYCLIC;
+
+        for (const BPoint &bp : Span(nurb->bp, nurb->pntsu)) {
+          PolyPoint point;
+          point.position = bp.vec;
+          point.radius = bp.radius;
+          point.tilt = bp.tilt;
+          spline->control_points.append(std::move(point));
+        }
+
+        curve->splines.append(std::move(spline));
         break;
       }
       default: {
@@ -788,4 +801,68 @@ float NURBSPline::control_point_radius(const int index) const
 /** \name Poly Spline
  * \{ */
 
+SplinePtr PolySpline::copy() const
+{
+  SplinePtr new_spline = std::make_unique<PolySpline>(*this);
+
+  return new_spline;
+}
+
+int PolySpline::size() const
+{
+  return this->control_points.size();
+}
+
+int PolySpline::resolution() const
+{
+  return 1;
+}
+
+void PolySpline::set_resolution(const int UNUSED(value))
+{
+  /* Poly curve has no resolution, there is just one evaluated point per control point. */
+}
+
+int PolySpline::evaluated_points_size() const
+{
+  return this->control_points.size();
+}
+
+void PolySpline::correct_end_tangents() const
+{
+}
+
+void PolySpline::ensure_base_cache() const
+{
+
+  if (!this->base_cache_dirty_) {
+    return;
+  }
+
+  std::lock_guard lock{this->base_cache_mutex_};
+  if (!this->base_cache_dirty_) {
+    return;
+  }
+
+  const int total = this->evaluated_points_size();
+  this->evaluated_positions_cache_.resize(total);
+  this->evaluated_mapping_cache_.resize(total);
+
+  MutableSpan<float3> positions = this->evaluated_positions_cache_.as_mutable_span();
+  MutableSpan<PointMapping> mappings = this->evaluated_mapping_cache_.as_mutable_span();
+
+  for (const int i : positions.index_range()) {
+    positions[i] = this->control_points[i].position;
+    mappings[i].control_point_index = i;
+    mappings[i].factor = 0.0f;
+  }
+
+  this->base_cache_dirty_ = false;
+}
+
+float PolySpline::control_point_radius(const int index) const
+{
+  return this->control_points[index].radius;
+}
+
 /** \} */



More information about the Bf-blender-cvs mailing list