Commit: a0c45a2d5416f780451a23830087a6e712d26ef1
Author: Hans Goudey
Date:   Mon Jun 28 14:28:52 2021 -0500
Branches: master
https://developer.blender.org/rBa0c45a2d5416f780451a23830087a6e712d26ef1

Cleanup: Add function to create a CurveEval from a nurbs list

Sometimes the current spline list isn't part of the original curve, like
when using the deformed control points, etc. This will be helpful in
the curve modifier stack.

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

M       source/blender/blenkernel/BKE_spline.hh
M       source/blender/blenkernel/intern/curve_eval.cc
M       source/blender/blenkernel/intern/geometry_set_instances.cc
M       source/blender/blenlib/BLI_vector.hh

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

diff --git a/source/blender/blenkernel/BKE_spline.hh 
b/source/blender/blenkernel/BKE_spline.hh
index 0de9270bde1..1aac2e311e3 100644
--- a/source/blender/blenkernel/BKE_spline.hh
+++ b/source/blender/blenkernel/BKE_spline.hh
@@ -32,6 +32,7 @@
 #include "BKE_attribute_math.hh"
 
 struct Curve;
+struct ListBase;
 
 class Spline;
 using SplinePtr = std::unique_ptr<Spline>;
@@ -546,4 +547,6 @@ struct CurveEval {
   void assert_valid_point_attributes() const;
 };
 
-std::unique_ptr<CurveEval> curve_eval_from_dna_curve(const Curve &curve);
+std::unique_ptr<CurveEval> curve_eval_from_dna_curve(const Curve &curve,
+                                                     const ListBase 
&nurbs_list);
+std::unique_ptr<CurveEval> curve_eval_from_dna_curve(const Curve &dna_curve);
diff --git a/source/blender/blenkernel/intern/curve_eval.cc 
b/source/blender/blenkernel/intern/curve_eval.cc
index 0a6e4458a35..72ee2587c8a 100644
--- a/source/blender/blenkernel/intern/curve_eval.cc
+++ b/source/blender/blenkernel/intern/curve_eval.cc
@@ -257,9 +257,10 @@ static SplinePtr spline_from_dna_poly(const Nurb &nurb)
   return spline;
 }
 
-std::unique_ptr<CurveEval> curve_eval_from_dna_curve(const Curve &dna_curve)
+std::unique_ptr<CurveEval> curve_eval_from_dna_curve(const Curve &dna_curve,
+                                                     const ListBase 
&nurbs_list)
 {
-  Vector<const Nurb *> nurbs(*BKE_curve_nurbs_get(&const_cast<Curve 
&>(dna_curve)));
+  Vector<const Nurb *> nurbs(nurbs_list);
 
   std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>();
   curve->resize(nurbs.size());
@@ -295,6 +296,11 @@ std::unique_ptr<CurveEval> curve_eval_from_dna_curve(const 
Curve &dna_curve)
   return curve;
 }
 
+std::unique_ptr<CurveEval> curve_eval_from_dna_curve(const Curve &dna_curve)
+{
+  return curve_eval_from_dna_curve(dna_curve, 
*BKE_curve_nurbs_get_for_read(&dna_curve));
+}
+
 /**
  * Check the invariants that curve control point attributes should always 
uphold, necessary
  * because attributes are stored on splines rather than in a flat array on the 
curve:
diff --git a/source/blender/blenkernel/intern/geometry_set_instances.cc 
b/source/blender/blenkernel/intern/geometry_set_instances.cc
index 3c50b966f04..01b51d552a9 100644
--- a/source/blender/blenkernel/intern/geometry_set_instances.cc
+++ b/source/blender/blenkernel/intern/geometry_set_instances.cc
@@ -56,7 +56,7 @@ static void add_curve_data_as_geometry_component(const Object 
&object, GeometryS
 {
   BLI_assert(object.type == OB_CURVE);
   if (object.data != nullptr) {
-    std::unique_ptr<CurveEval> curve = curve_eval_from_dna_curve(*(Curve 
*)object.data);
+    std::unique_ptr<CurveEval> curve = curve_eval_from_dna_curve(*(const Curve 
*)object.data);
     CurveComponent &curve_component = 
geometry_set.get_component_for_write<CurveComponent>();
     curve_component.replace(curve.release(), GeometryOwnershipType::Owned);
   }
diff --git a/source/blender/blenlib/BLI_vector.hh 
b/source/blender/blenlib/BLI_vector.hh
index 5b88ad6fa7d..da02c4f4ae1 100644
--- a/source/blender/blenlib/BLI_vector.hh
+++ b/source/blender/blenlib/BLI_vector.hh
@@ -213,7 +213,8 @@ class Vector {
    * Example Usage:
    *  Vector<ModifierData *> modifiers(ob->modifiers);
    */
-  Vector(ListBase &values, Allocator allocator = {}) : 
Vector(NoExceptConstructor(), allocator)
+  Vector(const ListBase &values, Allocator allocator = {})
+      : Vector(NoExceptConstructor(), allocator)
   {
     LISTBASE_FOREACH (T, value, &values) {
       this->append(value);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to