Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-03-01 20:06:11 +0300
committerHans Goudey <h.goudey@me.com>2022-03-01 20:06:29 +0300
commit444d57d440459304a248ba75e1936b69be4d09dd (patch)
treea46df9fb2ac5e4a428f98202c50181f3958716cc
parent89bf5d8ba98f4236f97777d14d3a6029f0471e42 (diff)
Geometry Nodes: Port most curve primitives to new data-block
Create `Curves` directly, instead of using the conversion from `CurveEval`. This means that the `tilt` and `radius` attributes don't need to be allocated. The old behavior is kept by using the right defaults in the conversion to `CurveEval` later on. The Bezier segment primitive isn't ported yet, because functions to provide easy access to built-in attributes used for Bezier curves haven't been added yet. Differential Revision: https://developer.blender.org/D14212
-rw-r--r--source/blender/blenkernel/BKE_curves.hh5
-rw-r--r--source/blender/blenkernel/intern/curves.cc9
-rw-r--r--source/blender/editors/include/ED_curves.h2
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc126
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc59
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc63
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc27
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc18
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc44
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc37
10 files changed, 172 insertions, 218 deletions
diff --git a/source/blender/blenkernel/BKE_curves.hh b/source/blender/blenkernel/BKE_curves.hh
index 6fa7de49eb0..f3d9090d16b 100644
--- a/source/blender/blenkernel/BKE_curves.hh
+++ b/source/blender/blenkernel/BKE_curves.hh
@@ -158,4 +158,9 @@ class CurvesGeometry : public ::CurvesGeometry {
Curves *curves_new_nomain(int point_size, int curves_size);
+/**
+ * Create a new curves data-block containing a single curve with the given length and type.
+ */
+Curves *curves_new_nomain_single(int point_size, CurveType type);
+
} // namespace blender::bke
diff --git a/source/blender/blenkernel/intern/curves.cc b/source/blender/blenkernel/intern/curves.cc
index c7aaf4718fe..838f7f28e93 100644
--- a/source/blender/blenkernel/intern/curves.cc
+++ b/source/blender/blenkernel/intern/curves.cc
@@ -374,4 +374,13 @@ Curves *curves_new_nomain(const int point_size, const int curves_size)
return curves;
}
+Curves *curves_new_nomain_single(const int point_size, const CurveType type)
+{
+ Curves *curves = curves_new_nomain(point_size, 1);
+ CurvesGeometry &geometry = CurvesGeometry::wrap(curves->geometry);
+ geometry.offsets().last() = point_size;
+ geometry.curve_types().first() = type;
+ return curves;
+}
+
} // namespace blender::bke
diff --git a/source/blender/editors/include/ED_curves.h b/source/blender/editors/include/ED_curves.h
index 706563061d4..9233b65b2ce 100644
--- a/source/blender/editors/include/ED_curves.h
+++ b/source/blender/editors/include/ED_curves.h
@@ -25,4 +25,4 @@ namespace blender::ed::curves {
bke::CurvesGeometry primitive_random_sphere(int curves_size, int points_per_curve);
}
-#endif \ No newline at end of file
+#endif
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc
index 339e65321b1..6c7d7ed375b 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc
@@ -1,11 +1,15 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
-#include "BKE_spline.hh"
+#include <numeric>
+
#include "BLI_math_base_safe.h"
+
+#include "BKE_curves.hh"
+
#include "UI_interface.h"
#include "UI_resources.h"
+
#include "node_geometry_util.hh"
-#include <numeric>
namespace blender::nodes::node_geo_curve_primitive_arc_cc {
@@ -139,32 +143,24 @@ static bool colinear_f3_f3_f3(const float3 p1, const float3 p2, const float3 p3)
return (ELEM(a, b, b * -1.0f));
}
-static std::unique_ptr<CurveEval> create_arc_curve_from_points(const int resolution,
- const float3 a,
- const float3 b,
- const float3 c,
- float angle_offset,
- const bool connect_center,
- const bool invert_arc,
- float3 &r_center,
- float3 &r_normal,
- float &r_radius)
+static Curves *create_arc_curve_from_points(const int resolution,
+ const float3 a,
+ const float3 b,
+ const float3 c,
+ float angle_offset,
+ const bool connect_center,
+ const bool invert_arc,
+ float3 &r_center,
+ float3 &r_normal,
+ float &r_radius)
{
- std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>();
- std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>();
-
- if (connect_center) {
- spline->resize(resolution + 1);
- }
- else {
- spline->resize(resolution);
- }
+ const int size = connect_center ? resolution + 1 : resolution;
+ Curves *curves_id = bke::curves_new_nomain_single(size, CURVE_TYPE_POLY);
+ bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry);
const int stepcount = resolution - 1;
const int centerpoint = resolution;
- MutableSpan<float3> positions = spline->positions();
- spline->radii().fill(1.0f);
- spline->tilts().fill(0.0f);
+ MutableSpan<float3> positions = curves.positions();
const bool is_colinear = colinear_f3_f3_f3(a, b, c);
@@ -254,7 +250,7 @@ static std::unique_ptr<CurveEval> create_arc_curve_from_points(const int resolut
}
if (connect_center) {
- spline->set_cyclic(true);
+ curves.cyclic().first() = true;
positions[centerpoint] = center;
}
@@ -263,36 +259,26 @@ static std::unique_ptr<CurveEval> create_arc_curve_from_points(const int resolut
normal = -normal;
}
- curve->add_spline(std::move(spline));
- curve->attributes.reallocate(curve->splines().size());
r_center = center;
r_radius = radius;
r_normal = normal;
- return curve;
+ return curves_id;
}
-static std::unique_ptr<CurveEval> create_arc_curve_from_radius(const int resolution,
- const float radius,
- const float start_angle,
- const float sweep_angle,
- const bool connect_center,
- const bool invert_arc)
+static Curves *create_arc_curve_from_radius(const int resolution,
+ const float radius,
+ const float start_angle,
+ const float sweep_angle,
+ const bool connect_center,
+ const bool invert_arc)
{
- std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>();
- std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>();
-
- if (connect_center) {
- spline->resize(resolution + 1);
- }
- else {
- spline->resize(resolution);
- }
+ const int size = connect_center ? resolution + 1 : resolution;
+ Curves *curves_id = bke::curves_new_nomain_single(size, CURVE_TYPE_POLY);
+ bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry);
const int stepcount = resolution - 1;
const int centerpoint = resolution;
- MutableSpan<float3> positions = spline->positions();
- spline->radii().fill(1.0f);
- spline->tilts().fill(0.0f);
+ MutableSpan<float3> positions = curves.positions();
const float sweep = (invert_arc) ? -(2.0f * M_PI - sweep_angle) : sweep_angle;
@@ -305,13 +291,11 @@ static std::unique_ptr<CurveEval> create_arc_curve_from_radius(const int resolut
}
if (connect_center) {
- spline->set_cyclic(true);
+ curves.cyclic().first() = true;
positions[centerpoint] = float3(0.0f, 0.0f, 0.0f);
}
- curve->add_spline(std::move(spline));
- curve->attributes.reallocate(curve->splines().size());
- return curve;
+ return curves_id;
}
static void node_geo_exec(GeoNodeExecParams params)
@@ -322,35 +306,35 @@ static void node_geo_exec(GeoNodeExecParams params)
switch (mode) {
case GEO_NODE_CURVE_PRIMITIVE_ARC_TYPE_POINTS: {
- std::unique_ptr<CurveEval> curve;
float3 r_center, r_normal;
float r_radius;
- curve = create_arc_curve_from_points(std::max(params.extract_input<int>("Resolution"), 2),
- params.extract_input<float3>("Start"),
- params.extract_input<float3>("Middle"),
- params.extract_input<float3>("End"),
- params.extract_input<float>("Offset Angle"),
- params.extract_input<bool>("Connect Center"),
- params.extract_input<bool>("Invert Arc"),
- r_center,
- r_normal,
- r_radius);
- params.set_output("Curve", GeometrySet::create_with_curves(curve_eval_to_curves(*curve)));
+ Curves *curves = create_arc_curve_from_points(
+ std::max(params.extract_input<int>("Resolution"), 2),
+ params.extract_input<float3>("Start"),
+ params.extract_input<float3>("Middle"),
+ params.extract_input<float3>("End"),
+ params.extract_input<float>("Offset Angle"),
+ params.extract_input<bool>("Connect Center"),
+ params.extract_input<bool>("Invert Arc"),
+ r_center,
+ r_normal,
+ r_radius);
+ params.set_output("Curve", GeometrySet::create_with_curves(curves));
params.set_output("Center", r_center);
params.set_output("Normal", r_normal);
params.set_output("Radius", r_radius);
break;
}
case GEO_NODE_CURVE_PRIMITIVE_ARC_TYPE_RADIUS: {
- std::unique_ptr<CurveEval> curve;
- curve = create_arc_curve_from_radius(std::max(params.extract_input<int>("Resolution"), 2),
- params.extract_input<float>("Radius"),
- params.extract_input<float>("Start Angle"),
- params.extract_input<float>("Sweep Angle"),
- params.extract_input<bool>("Connect Center"),
- params.extract_input<bool>("Invert Arc"));
-
- params.set_output("Curve", GeometrySet::create_with_curves(curve_eval_to_curves(*curve)));
+ Curves *curves = create_arc_curve_from_radius(
+ std::max(params.extract_input<int>("Resolution"), 2),
+ params.extract_input<float>("Radius"),
+ params.extract_input<float>("Start Angle"),
+ params.extract_input<float>("Sweep Angle"),
+ params.extract_input<bool>("Connect Center"),
+ params.extract_input<bool>("Invert Arc"));
+
+ params.set_output("Curve", GeometrySet::create_with_curves(curves));
break;
}
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc
index 54d7c488fb7..874e29dda86 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
-#include "BKE_spline.hh"
+#include "BKE_curves.hh"
#include "UI_interface.h"
#include "UI_resources.h"
@@ -92,7 +92,7 @@ static bool colinear_f3_f3_f3(const float3 p1, const float3 p2, const float3 p3)
return (ELEM(a, b, b * -1.0f));
}
-static std::unique_ptr<CurveEval> create_point_circle_curve(
+static Curves *create_point_circle_curve(
const float3 p1, const float3 p2, const float3 p3, const int resolution, float3 &r_center)
{
if (colinear_f3_f3_f3(p1, p2, p3)) {
@@ -100,11 +100,11 @@ static std::unique_ptr<CurveEval> create_point_circle_curve(
return nullptr;
}
- std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>();
- std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>();
+ Curves *curves_id = bke::curves_new_nomain_single(resolution, CURVE_TYPE_POLY);
+ bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry);
+ curves.cyclic().first() = true;
- spline->resize(resolution);
- MutableSpan<float3> positions = spline->positions();
+ MutableSpan<float3> positions = curves.positions();
float3 center;
/* Midpoints of `P1->P2` and `P2->P3`. */
@@ -147,24 +147,17 @@ static std::unique_ptr<CurveEval> create_point_circle_curve(
positions[i] = center + r * sin(theta) * v1 + r * cos(theta) * v4;
}
- spline->radii().fill(1.0f);
- spline->tilts().fill(0.0f);
- spline->set_cyclic(true);
- curve->add_spline(std::move(spline));
- curve->attributes.reallocate(curve->splines().size());
-
r_center = center;
- return curve;
+ return curves_id;
}
-static std::unique_ptr<CurveEval> create_radius_circle_curve(const int resolution,
- const float radius)
+static Curves *create_radius_circle_curve(const int resolution, const float radius)
{
- std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>();
- std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>();
+ Curves *curves_id = bke::curves_new_nomain_single(resolution, CURVE_TYPE_POLY);
+ bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry);
+ curves.cyclic().first() = true;
- spline->resize(resolution);
- MutableSpan<float3> positions = spline->positions();
+ MutableSpan<float3> positions = curves.positions();
const float theta_step = (2.0f * M_PI) / float(resolution);
for (int i : IndexRange(resolution)) {
@@ -173,12 +166,8 @@ static std::unique_ptr<CurveEval> create_radius_circle_curve(const int resolutio
const float y = radius * sin(theta);
positions[i] = float3(x, y, 0.0f);
}
- spline->radii().fill(1.0f);
- spline->tilts().fill(0.0f);
- spline->set_cyclic(true);
- curve->add_spline(std::move(spline));
- curve->attributes.reallocate(curve->splines().size());
- return curve;
+
+ return curves_id;
}
static void node_geo_exec(GeoNodeExecParams params)
@@ -187,23 +176,23 @@ static void node_geo_exec(GeoNodeExecParams params)
const GeometryNodeCurvePrimitiveCircleMode mode = (GeometryNodeCurvePrimitiveCircleMode)
storage.mode;
- std::unique_ptr<CurveEval> curve;
+ Curves *curves;
if (mode == GEO_NODE_CURVE_PRIMITIVE_CIRCLE_TYPE_POINTS) {
float3 center_point;
- curve = create_point_circle_curve(params.extract_input<float3>("Point 1"),
- params.extract_input<float3>("Point 2"),
- params.extract_input<float3>("Point 3"),
- std::max(params.extract_input<int>("Resolution"), 3),
- center_point);
+ curves = create_point_circle_curve(params.extract_input<float3>("Point 1"),
+ params.extract_input<float3>("Point 2"),
+ params.extract_input<float3>("Point 3"),
+ std::max(params.extract_input<int>("Resolution"), 3),
+ center_point);
params.set_output("Center", center_point);
}
else if (mode == GEO_NODE_CURVE_PRIMITIVE_CIRCLE_TYPE_RADIUS) {
- curve = create_radius_circle_curve(std::max(params.extract_input<int>("Resolution"), 3),
- params.extract_input<float>("Radius"));
+ curves = create_radius_circle_curve(std::max(params.extract_input<int>("Resolution"), 3),
+ params.extract_input<float>("Radius"));
}
- if (curve) {
- params.set_output("Curve", GeometrySet::create_with_curves(curve_eval_to_curves(*curve)));
+ if (curves) {
+ params.set_output("Curve", GeometrySet::create_with_curves(curves));
}
else {
params.set_default_remaining_outputs();
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc
index ece7e44cc35..2e2f4254752 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
-#include "BKE_spline.hh"
+#include "BKE_curves.hh"
#include "UI_interface.h"
#include "UI_resources.h"
@@ -60,39 +60,28 @@ static void node_update(bNodeTree *ntree, bNode *node)
ntree, length_socket, mode == GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_DIRECTION);
}
-static std::unique_ptr<CurveEval> create_point_line_curve(const float3 start, const float3 end)
+static Curves *create_point_line_curve(const float3 start, const float3 end)
{
- std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>();
- std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>();
-
- spline->resize(2);
- MutableSpan<float3> positions = spline->positions();
- positions[0] = start;
- positions[1] = end;
- spline->radii().fill(1.0f);
- spline->tilts().fill(0.0f);
- curve->add_spline(std::move(spline));
- curve->attributes.reallocate(curve->splines().size());
- return curve;
+ Curves *curves_id = bke::curves_new_nomain_single(2, CURVE_TYPE_POLY);
+ bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry);
+
+ curves.positions().first() = start;
+ curves.positions().last() = end;
+
+ return curves_id;
}
-static std::unique_ptr<CurveEval> create_direction_line_curve(const float3 start,
- const float3 direction,
- const float length)
+static Curves *create_direction_line_curve(const float3 start,
+ const float3 direction,
+ const float length)
{
- std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>();
- std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>();
-
- spline->resize(2);
- MutableSpan<float3> positions = spline->positions();
- positions[0] = start;
- positions[1] = math::normalize(direction) * length + start;
-
- spline->radii().fill(1.0f);
- spline->tilts().fill(0.0f);
- curve->add_spline(std::move(spline));
- curve->attributes.reallocate(curve->splines().size());
- return curve;
+ Curves *curves_id = bke::curves_new_nomain_single(2, CURVE_TYPE_POLY);
+ bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry);
+
+ curves.positions().first() = start;
+ curves.positions().last() = math::normalize(direction) * length + start;
+
+ return curves_id;
}
static void node_geo_exec(GeoNodeExecParams params)
@@ -100,18 +89,18 @@ static void node_geo_exec(GeoNodeExecParams params)
const NodeGeometryCurvePrimitiveLine &storage = node_storage(params.node());
const GeometryNodeCurvePrimitiveLineMode mode = (GeometryNodeCurvePrimitiveLineMode)storage.mode;
- std::unique_ptr<CurveEval> curve;
+ Curves *curves = nullptr;
if (mode == GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_POINTS) {
- curve = create_point_line_curve(params.extract_input<float3>("Start"),
- params.extract_input<float3>("End"));
+ curves = create_point_line_curve(params.extract_input<float3>("Start"),
+ params.extract_input<float3>("End"));
}
else if (mode == GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_DIRECTION) {
- curve = create_direction_line_curve(params.extract_input<float3>("Start"),
- params.extract_input<float3>("Direction"),
- params.extract_input<float>("Length"));
+ curves = create_direction_line_curve(params.extract_input<float3>("Start"),
+ params.extract_input<float3>("Direction"),
+ params.extract_input<float>("Length"));
}
- params.set_output("Curve", GeometrySet::create_with_curves(curve_eval_to_curves(*curve)));
+ params.set_output("Curve", GeometrySet::create_with_curves(curves));
}
} // namespace blender::nodes::node_geo_curve_primitive_line_cc
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc
index c6c33cffa54..37810ccaff5 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
-#include "BKE_spline.hh"
+#include "BKE_curves.hh"
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_curve_primitive_quadratic_bezier_cc {
@@ -28,18 +28,15 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Curve"));
}
-static std::unique_ptr<CurveEval> create_quadratic_bezier_curve(const float3 p1,
- const float3 p2,
- const float3 p3,
- const int resolution)
+static Curves *create_quadratic_bezier_curve(const float3 p1,
+ const float3 p2,
+ const float3 p3,
+ const int resolution)
{
- std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>();
- std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>();
+ Curves *curves_id = bke::curves_new_nomain_single(resolution + 1, CURVE_TYPE_POLY);
+ bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry);
- spline->resize(resolution + 1);
- MutableSpan<float3> positions = spline->positions();
- spline->radii().fill(1.0f);
- spline->tilts().fill(0.0f);
+ MutableSpan<float3> positions = curves.positions();
const float step = 1.0f / resolution;
for (const int i : IndexRange(resolution + 1)) {
@@ -49,19 +46,17 @@ static std::unique_ptr<CurveEval> create_quadratic_bezier_curve(const float3 p1,
positions[i] = math::interpolate(q1, q2, factor);
}
- curve->add_spline(std::move(spline));
- curve->attributes.reallocate(curve->splines().size());
- return curve;
+ return curves_id;
}
static void node_geo_exec(GeoNodeExecParams params)
{
- std::unique_ptr<CurveEval> curve = create_quadratic_bezier_curve(
+ Curves *curves = create_quadratic_bezier_curve(
params.extract_input<float3>("Start"),
params.extract_input<float3>("Middle"),
params.extract_input<float3>("End"),
std::max(params.extract_input<int>("Resolution"), 3));
- params.set_output("Curve", GeometrySet::create_with_curves(curve_eval_to_curves(*curve)));
+ params.set_output("Curve", GeometrySet::create_with_curves(curves));
}
} // namespace blender::nodes::node_geo_curve_primitive_quadratic_bezier_cc
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc
index cc2b9e4bc4e..ad3123a6a4a 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
-#include "BKE_spline.hh"
+#include "BKE_curves.hh"
#include "UI_interface.h"
#include "UI_resources.h"
@@ -216,13 +216,11 @@ static void node_geo_exec(GeoNodeExecParams params)
const NodeGeometryCurvePrimitiveQuad &storage = node_storage(params.node());
const GeometryNodeCurvePrimitiveQuadMode mode = (GeometryNodeCurvePrimitiveQuadMode)storage.mode;
- std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>();
- std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>();
- spline->resize(4);
- spline->radii().fill(1.0f);
- spline->tilts().fill(0.0f);
- spline->set_cyclic(true);
- MutableSpan<float3> positions = spline->positions();
+ Curves *curves_id = bke::curves_new_nomain_single(4, CURVE_TYPE_POLY);
+ bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry);
+ curves.cyclic().first() = true;
+
+ MutableSpan<float3> positions = curves.positions();
switch (mode) {
case GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_RECTANGLE:
@@ -262,9 +260,7 @@ static void node_geo_exec(GeoNodeExecParams params)
return;
}
- curve->add_spline(std::move(spline));
- curve->attributes.reallocate(curve->splines().size());
- params.set_output("Curve", GeometrySet::create_with_curves(curve_eval_to_curves(*curve)));
+ params.set_output("Curve", GeometrySet::create_with_curves(curves_id));
}
} // namespace blender::nodes::node_geo_curve_primitive_quadrilateral_cc
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc
index d4f7c4ed5f1..22619577d04 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
-#include "BKE_spline.hh"
+#include "BKE_curves.hh"
#include "node_geometry_util.hh"
@@ -35,26 +35,23 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Curve"));
}
-static std::unique_ptr<CurveEval> create_spiral_curve(const float rotations,
- const int resolution,
- const float start_radius,
- const float end_radius,
- const float height,
- const bool direction)
+static Curves *create_spiral_curve(const float rotations,
+ const int resolution,
+ const float start_radius,
+ const float end_radius,
+ const float height,
+ const bool direction)
{
- std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>();
- std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>();
-
const int totalpoints = std::max(int(resolution * rotations), 1);
const float delta_radius = (end_radius - start_radius) / (float)totalpoints;
const float delta_height = height / (float)totalpoints;
const float delta_theta = (M_PI * 2 * rotations) / (float)totalpoints *
(direction ? 1.0f : -1.0f);
- spline->resize(totalpoints + 1);
- MutableSpan<float3> positions = spline->positions();
- spline->radii().fill(1.0f);
- spline->tilts().fill(0.0f);
+ Curves *curves_id = bke::curves_new_nomain_single(totalpoints + 1, CURVE_TYPE_POLY);
+ bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry);
+
+ MutableSpan<float3> positions = curves.positions();
for (const int i : IndexRange(totalpoints + 1)) {
const float theta = i * delta_theta;
@@ -66,9 +63,7 @@ static std::unique_ptr<CurveEval> create_spiral_curve(const float rotations,
positions[i] = {x, y, z};
}
- curve->add_spline(std::move(spline));
- curve->attributes.reallocate(curve->splines().size());
- return curve;
+ return curves_id;
}
static void node_geo_exec(GeoNodeExecParams params)
@@ -79,14 +74,13 @@ static void node_geo_exec(GeoNodeExecParams params)
return;
}
- std::unique_ptr<CurveEval> curve = create_spiral_curve(
- rotations,
- std::max(params.extract_input<int>("Resolution"), 1),
- params.extract_input<float>("Start Radius"),
- params.extract_input<float>("End Radius"),
- params.extract_input<float>("Height"),
- params.extract_input<bool>("Reverse"));
- params.set_output("Curve", GeometrySet::create_with_curves(curve_eval_to_curves(*curve)));
+ Curves *curves = create_spiral_curve(rotations,
+ std::max(params.extract_input<int>("Resolution"), 1),
+ params.extract_input<float>("Start Radius"),
+ params.extract_input<float>("End Radius"),
+ params.extract_input<float>("Height"),
+ params.extract_input<bool>("Reverse"));
+ params.set_output("Curve", GeometrySet::create_with_curves(curves));
}
} // namespace blender::nodes::node_geo_curve_primitive_spiral_cc
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc
index 5b6852abfc2..e7e899881cf 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
-#include "BKE_spline.hh"
+#include "BKE_curves.hh"
#include "node_geometry_util.hh"
@@ -33,19 +33,16 @@ static void node_declare(NodeDeclarationBuilder &b)
.description(N_("An attribute field with a selection of the outer points"));
}
-static std::unique_ptr<CurveEval> create_star_curve(const float inner_radius,
- const float outer_radius,
- const float twist,
- const int points)
+static Curves *create_star_curve(const float inner_radius,
+ const float outer_radius,
+ const float twist,
+ const int points)
{
- std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>();
- std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>();
- spline->set_cyclic(true);
+ Curves *curves_id = bke::curves_new_nomain_single(points * 2, CURVE_TYPE_POLY);
+ bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry);
+ curves.cyclic().first() = true;
- spline->resize(points * 2);
- MutableSpan<float3> positions = spline->positions();
- spline->radii().fill(1.0f);
- spline->tilts().fill(0.0f);
+ MutableSpan<float3> positions = curves.positions();
const float theta_step = (2.0f * M_PI) / float(points);
for (const int i : IndexRange(points)) {
@@ -58,10 +55,7 @@ static std::unique_ptr<CurveEval> create_star_curve(const float inner_radius,
positions[i * 2 + 1] = {inner_x, inner_y, 0.0f};
}
- curve->add_spline(std::move(spline));
- curve->attributes.reallocate(curve->splines().size());
-
- return curve;
+ return curves_id;
}
static void create_selection_output(CurveComponent &component,
@@ -78,12 +72,11 @@ static void create_selection_output(CurveComponent &component,
static void node_geo_exec(GeoNodeExecParams params)
{
- std::unique_ptr<CurveEval> curve = create_star_curve(
- std::max(params.extract_input<float>("Inner Radius"), 0.0f),
- std::max(params.extract_input<float>("Outer Radius"), 0.0f),
- params.extract_input<float>("Twist"),
- std::max(params.extract_input<int>("Points"), 3));
- GeometrySet output = GeometrySet::create_with_curves(curve_eval_to_curves(*curve));
+ Curves *curves = create_star_curve(std::max(params.extract_input<float>("Inner Radius"), 0.0f),
+ std::max(params.extract_input<float>("Outer Radius"), 0.0f),
+ params.extract_input<float>("Twist"),
+ std::max(params.extract_input<int>("Points"), 3));
+ GeometrySet output = GeometrySet::create_with_curves(curves);
if (params.output_is_required("Outer Points")) {
StrongAnonymousAttributeID attribute_output("Outer Points");