[Bf-blender-cvs] [f76dfe8fb45] master: Cleanup: Add function to check a curve's spline types
Hans Goudey
noreply at git.blender.org
Thu Jul 22 23:20:42 CEST 2021
Commit: f76dfe8fb45c9c270c295ff76f6fd058e2b64d0d
Author: Hans Goudey
Date: Thu Jul 22 17:20:04 2021 -0400
Branches: master
https://developer.blender.org/rBf76dfe8fb45c9c270c295ff76f6fd058e2b64d0d
Cleanup: Add function to check a curve's spline types
The need for this has come up a few times.
===================================================================
M source/blender/blenkernel/BKE_spline.hh
M source/blender/blenkernel/intern/curve_eval.cc
M source/blender/blenkernel/intern/geometry_component_curve.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_spline.hh b/source/blender/blenkernel/BKE_spline.hh
index 8f21ca01f31..53485ecbd6b 100644
--- a/source/blender/blenkernel/BKE_spline.hh
+++ b/source/blender/blenkernel/BKE_spline.hh
@@ -543,6 +543,7 @@ struct CurveEval {
blender::Span<SplinePtr> splines() const;
blender::MutableSpan<SplinePtr> splines();
+ bool has_spline_with_type(const Spline::Type type) const;
void resize(const int size);
void add_spline(SplinePtr spline);
diff --git a/source/blender/blenkernel/intern/curve_eval.cc b/source/blender/blenkernel/intern/curve_eval.cc
index 8e1577ab072..5c18f6f3807 100644
--- a/source/blender/blenkernel/intern/curve_eval.cc
+++ b/source/blender/blenkernel/intern/curve_eval.cc
@@ -48,6 +48,22 @@ blender::MutableSpan<SplinePtr> CurveEval::splines()
return splines_;
}
+/**
+ * \return True if the curve contains a spline with the given type.
+ *
+ * \note If you are looping over all of the splines in the same scope anyway,
+ * it's better to avoid calling this function, in case there are many splines.
+ */
+bool CurveEval::has_spline_with_type(const Spline::Type type) const
+{
+ for (const SplinePtr &spline : this->splines()) {
+ if (spline->type() == type) {
+ return true;
+ }
+ }
+ return false;
+}
+
void CurveEval::resize(const int size)
{
splines_.resize(size);
diff --git a/source/blender/blenkernel/intern/geometry_component_curve.cc b/source/blender/blenkernel/intern/geometry_component_curve.cc
index b5c49dbb8b2..0b6ba966974 100644
--- a/source/blender/blenkernel/intern/geometry_component_curve.cc
+++ b/source/blender/blenkernel/intern/geometry_component_curve.cc
@@ -854,17 +854,9 @@ class PositionAttributeProvider final : public BuiltinPointAttributeProvider<flo
return {};
}
- bool curve_has_bezier_spline = false;
- for (SplinePtr &spline : curve->splines()) {
- if (spline->type() == Spline::Type::Bezier) {
- curve_has_bezier_spline = true;
- break;
- }
- }
-
/* Use the regular position virtual array when there aren't any Bezier splines
* to avoid the overhead of checking the spline type for every point. */
- if (!curve_has_bezier_spline) {
+ if (!curve->has_spline_with_type(Spline::Type::Bezier)) {
return BuiltinPointAttributeProvider<float3>::try_get_for_write(component);
}
More information about the Bf-blender-cvs
mailing list