[Bf-blender-cvs] [f3ef0763b41] master: Cleanup: Use new curves type enum for CurveEval
Hans Goudey
noreply at git.blender.org
Wed Feb 23 03:52:55 CET 2022
Commit: f3ef0763b41155e6234343de900b207bb5b2e20d
Author: Hans Goudey
Date: Tue Feb 22 21:52:48 2022 -0500
Branches: master
https://developer.blender.org/rBf3ef0763b41155e6234343de900b207bb5b2e20d
Cleanup: Use new curves type enum for CurveEval
Though this is less aesthetically pleasing, it makes the transition to the
new curves type (T95941) a bit simpler, and it has to be done anyway.
===================================================================
M source/blender/blenkernel/BKE_spline.hh
M source/blender/blenkernel/intern/curve_eval.cc
M source/blender/blenkernel/intern/curve_to_mesh_convert.cc
M source/blender/blenkernel/intern/geometry_component_curve.cc
A source/blender/blenkernel/intern/geometry_component_curves.cc
M source/blender/blenkernel/intern/spline_base.cc
M source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_select_by_handle_type.cc
M source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_set_handles.cc
M source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_spline_type.cc
M source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_subdivide.cc
M source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_delete_geometry.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_set_handles.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_subdivide.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc
M source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
M source/blender/nodes/geometry/nodes/node_geo_input_tangent.cc
M source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc
M source/blender/nodes/geometry/nodes/node_geo_set_spline_resolution.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_spline.hh b/source/blender/blenkernel/BKE_spline.hh
index 646af6f8f98..439f20ee471 100644
--- a/source/blender/blenkernel/BKE_spline.hh
+++ b/source/blender/blenkernel/BKE_spline.hh
@@ -51,12 +51,6 @@ using SplinePtr = std::unique_ptr<Spline>;
*/
class Spline {
public:
- enum class Type {
- Bezier,
- NURBS,
- Poly,
- };
-
enum NormalCalculationMode {
ZUp,
Minimum,
@@ -67,7 +61,7 @@ class Spline {
blender::bke::CustomDataAttributes attributes;
protected:
- Type type_;
+ CurveType type_;
bool is_cyclic_ = false;
/** Direction of the spline at each evaluated point. */
@@ -87,7 +81,7 @@ class Spline {
public:
virtual ~Spline() = default;
- Spline(const Type type) : type_(type)
+ Spline(const CurveType type) : type_(type)
{
}
Spline(Spline &other) : attributes(other.attributes), type_(other.type_)
@@ -109,7 +103,7 @@ class Spline {
SplinePtr copy_without_attributes() const;
static void copy_base_settings(const Spline &src, Spline &dst);
- Spline::Type type() const;
+ CurveType type() const;
/** Return the number of control points. */
virtual int size() const = 0;
@@ -285,7 +279,7 @@ class BezierSpline final : public Spline {
mutable bool mapping_cache_dirty_ = true;
public:
- BezierSpline() : Spline(Type::Bezier)
+ BezierSpline() : Spline(CURVE_TYPE_BEZIER)
{
}
BezierSpline(const BezierSpline &other)
@@ -508,7 +502,7 @@ class NURBSpline final : public Spline {
mutable bool position_cache_dirty_ = true;
public:
- NURBSpline() : Spline(Type::NURBS)
+ NURBSpline() : Spline(CURVE_TYPE_NURBS)
{
}
NURBSpline(const NURBSpline &other)
@@ -575,7 +569,7 @@ class PolySpline final : public Spline {
blender::Vector<float> tilts_;
public:
- PolySpline() : Spline(Type::Poly)
+ PolySpline() : Spline(CURVE_TYPE_POLY)
{
}
PolySpline(const PolySpline &other)
@@ -647,7 +641,7 @@ struct CurveEval {
* \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 has_spline_with_type(const Spline::Type type) const;
+ bool has_spline_with_type(const CurveType type) const;
void resize(int size);
/**
diff --git a/source/blender/blenkernel/intern/curve_eval.cc b/source/blender/blenkernel/intern/curve_eval.cc
index 49010caef24..8529e7ad194 100644
--- a/source/blender/blenkernel/intern/curve_eval.cc
+++ b/source/blender/blenkernel/intern/curve_eval.cc
@@ -36,7 +36,7 @@ blender::MutableSpan<SplinePtr> CurveEval::splines()
return splines_;
}
-bool CurveEval::has_spline_with_type(const Spline::Type type) const
+bool CurveEval::has_spline_with_type(const CurveType type) const
{
for (const SplinePtr &spline : this->splines()) {
if (spline->type() == type) {
diff --git a/source/blender/blenkernel/intern/curve_to_mesh_convert.cc b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc
index e62733e36ef..5d80ef47908 100644
--- a/source/blender/blenkernel/intern/curve_to_mesh_convert.cc
+++ b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc
@@ -226,7 +226,7 @@ static void spline_extrude_to_mesh_data(const ResultInfo &info,
}
/* Mark edge loops from sharp vector control points sharp. */
- if (profile.type() == Spline::Type::Bezier) {
+ if (profile.type() == CURVE_TYPE_BEZIER) {
const BezierSpline &bezier_spline = static_cast<const BezierSpline &>(profile);
Span<int> control_point_offsets = bezier_spline.control_point_offsets();
for (const int i : IndexRange(bezier_spline.size())) {
diff --git a/source/blender/blenkernel/intern/geometry_component_curve.cc b/source/blender/blenkernel/intern/geometry_component_curve.cc
index fff77dbd367..2004f1c0609 100644
--- a/source/blender/blenkernel/intern/geometry_component_curve.cc
+++ b/source/blender/blenkernel/intern/geometry_component_curve.cc
@@ -420,15 +420,18 @@ static Array<float3> curve_normal_point_domain(const CurveEval &curve)
const Spline &spline = *splines[i];
MutableSpan spline_normals{normals.as_mutable_span().slice(offsets[i], spline.size())};
switch (splines[i]->type()) {
- case Spline::Type::Bezier:
+ case CURVE_TYPE_BEZIER:
calculate_bezier_normals(static_cast<const BezierSpline &>(spline), spline_normals);
break;
- case Spline::Type::Poly:
+ case CURVE_TYPE_POLY:
calculate_poly_normals(static_cast<const PolySpline &>(spline), spline_normals);
break;
- case Spline::Type::NURBS:
+ case CURVE_TYPE_NURBS:
calculate_nurbs_normals(static_cast<const NURBSpline &>(spline), spline_normals);
break;
+ case CURVE_TYPE_CATMULL_ROM:
+ BLI_assert_unreachable();
+ break;
}
}
});
@@ -447,7 +450,7 @@ VArray<float3> curve_normals_varray(const CurveComponent &component, const Attri
/* Use a reference to evaluated normals if possible to avoid an allocation and a copy.
* This is only possible when there is only one poly spline. */
- if (splines.size() == 1 && splines.first()->type() == Spline::Type::Poly) {
+ if (splines.size() == 1 && splines.first()->type() == CURVE_TYPE_POLY) {
const PolySpline &spline = static_cast<PolySpline &>(*splines.first());
return VArray<float3>::ForSpan(spline.evaluated_normals());
}
@@ -955,7 +958,7 @@ class VArrayImpl_For_BezierHandles final : public VMutableArrayImpl<float3> {
{
const PointIndices indices = lookup_point_indices(offsets_, index);
const Spline &spline = *splines_[indices.spline_index];
- if (spline.type() == Spline::Type::Bezier) {
+ if (spline.type() == CURVE_TYPE_BEZIER) {
const BezierSpline &bezier_spline = static_cast<const BezierSpline &>(spline);
return is_right_ ? bezier_spline.handle_positions_right()[indices.point_index] :
bezier_spline.handle_positions_left()[indices.point_index];
@@ -967,7 +970,7 @@ class VArrayImpl_For_BezierHandles final : public VMutableArrayImpl<float3> {
{
const PointIndices indices = lookup_point_indices(offsets_, index);
Spline &spline = *splines_[indices.spline_index];
- if (spline.type() == Spline::Type::Bezier) {
+ if (spline.type() == CURVE_TYPE_BEZIER) {
BezierSpline &bezier_spline = static_cast<BezierSpline &>(spline);
if (is_right_) {
bezier_spline.set_handle_position_right(indices.point_index, value);
@@ -983,7 +986,7 @@ class VArrayImpl_For_BezierHandles final : public VMutableArrayImpl<float3> {
{
for (const int spline_index : splines_.index_range()) {
Spline &spline = *splines_[spline_index];
- if (spline.type() == Spline::Type::Bezier) {
+ if (spline.type() == CURVE_TYPE_BEZIER) {
const int offset = offsets_[spline_index];
BezierSpline &bezier_spline = static_cast<BezierSpline &>(spline);
@@ -1024,7 +1027,7 @@ class VArrayImpl_For_BezierHandles final : public VMutableArrayImpl<float3> {
{
Array<Span<float3>> spans(splines.size());
for (const int i : spans.index_range()) {
- if (splines[i]->type() == Spline::Type::Bezier) {
+ if (splines[i]->type() == CURVE_TYPE_BEZIER) {
BezierSpline &bezier_spline = static_cast<BezierSpline &>(*splines[i]);
spans[i] = is_right ? bezier_spline.handle_positions_right() :
bezier_spline.handle_positions_left();
@@ -1214,7 +1217,7 @@ class PositionAttributeProvider final : public BuiltinPointAttributeProvider<flo
/* 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_spline_with_type(Spline::Type::Bezier)) {
+ if (!curve->has_spline_with_type(CURVE_TYPE_BEZIER)) {
return BuiltinPointAttributeProvider<float3>::try_get_for_write(component);
}
@@ -1255,7 +1258,7 @@ class BezierHandleAttributeProvider : public BuiltinAttributeProvider {
return {};
}
- if (!curve->has_spline_with_type(Spline::Type::Bezier)) {
+ if (!curve->has_spline_with_type(CURVE_TYPE_BEZIER)) {
return {};
}
@@ -1273,7 +1276,7 @@ class BezierHandleAttributeProvider : public BuiltinAttributeProvider {
return {};
}
- if (!curve->has_spline_with_type(Spline::Type::Bezier)) {
+ if (!curve->has_spline_with_type(CURVE_TYPE_BEZIER)) {
return {};
}
@@ -1304,7 +1307,7 @@ class BezierHandleAttributeProvider : public BuiltinAttributeProvider {
return false;
}
- return curve->has_spline_with_type(Spline::Type::Bezier) &&
+ return curve->has_spline_with_type(CURVE_TYPE_BEZIER) &&
component.attribute_domain_size(ATTR_DOMAIN_POINT) != 0;
}
};
diff --git a/source/blender/blenkernel/intern/geometry_component_curves.cc b/source/blender/blenkernel/intern/geometry_component_curves.cc
new file mode 100644
index 00000000000..07b71ab5ae7
--- /dev/null
+++ b/source/blender/blenkernel/intern/geometry_component_curves.cc
@@ -0,0 +1,517 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BLI_task.hh"
+
+#include "DNA_ID_enums.h"
+#include "DNA_curve_types.h"
+
+#include "BKE_attribute_access.hh"
+#include "BKE_attribute_math.hh"
+#include "BKE_curve.h"
+#include "BKE_curves.hh"
+#include "BKE_geometry_set.hh"
+#include "BKE_lib_id.h"
+#include "BKE_spline.hh"
+
+#include "attribute_access_intern.hh"
+
+using blender::fn::GVArray;
+
+/* -------------------------------------------------------------------- */
+/** \name Geometry Component Implementation
+ * \{ */
+
+CurveComponent::CurveComponent() : GeometryComponent(GEO_COMPONENT_TYPE_CURVE)
+{
+}
+
+CurveComponent::~CurveComponent()
+{
+ this->clear();
+}
+
+GeometryComponent *CurveComponent::copy() const
+{
+ CurveComponent *new_component = new CurveComponent();
+ if (curves_ != nullptr) {
+ new_component->curves_ = BKE_curves_copy_for_eval(curves_, false);
+ new_component->ownership_ = GeometryOwnershipType::Owned;
+ }
+ return new_component;
+}
+
+void CurveComponent::clear()
+{
+ BLI_assert(this->is_mut
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list