Commit: 444d57d440459304a248ba75e1936b69be4d09dd Author: Hans Goudey Date: Tue Mar 1 12:06:11 2022 -0500 Branches: master https://developer.blender.org/rB444d57d440459304a248ba75e1936b69be4d09dd
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 =================================================================== M source/blender/blenkernel/BKE_curves.hh M source/blender/blenkernel/intern/curves.cc M source/blender/editors/include/ED_curves.h M source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc M source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc M source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc M source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc M source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc M source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc M source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc =================================================================== 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( + @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list [email protected] List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
