Blender V5.0
node_geo_curve_primitive_quadratic_bezier.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_curves.hh"
7
9
11{
12 b.add_input<decl::Int>("Resolution")
13 .default_value(16)
14 .min(3)
15 .max(256)
17 .description("The number of edges on the curve");
18 b.add_input<decl::Vector>("Start")
19 .default_value({-1.0f, 0.0f, 0.0f})
20 .subtype(PROP_TRANSLATION)
21 .description("Position of the first control point");
22 b.add_input<decl::Vector>("Middle")
23 .default_value({0.0f, 2.0f, 0.0f})
24 .subtype(PROP_TRANSLATION)
25 .description("Position of the middle control point");
26 b.add_input<decl::Vector>("End")
27 .default_value({1.0f, 0.0f, 0.0f})
28 .subtype(PROP_TRANSLATION)
29 .description("Position of the last control point");
30 b.add_output<decl::Geometry>("Curve");
31}
32
34 const float3 p2,
35 const float3 p3,
36 const int resolution)
37{
38 Curves *curves_id = bke::curves_new_nomain_single(resolution + 1, CURVE_TYPE_POLY);
39 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
40
41 MutableSpan<float3> positions = curves.positions_for_write();
42
43 const float step = 1.0f / resolution;
44 for (const int i : IndexRange(resolution + 1)) {
45 const float factor = step * i;
46 const float3 q1 = math::interpolate(p1, p2, factor);
47 const float3 q2 = math::interpolate(p2, p3, factor);
48 positions[i] = math::interpolate(q1, q2, factor);
49 }
50
51 return curves_id;
52}
53
55{
57 params.extract_input<float3>("Start"),
58 params.extract_input<float3>("Middle"),
59 params.extract_input<float3>("End"),
60 std::max(params.extract_input<int>("Resolution"), 3));
61 params.set_output("Curve", GeometrySet::from_curves(curves));
62}
63
64static void node_register()
65{
66 static blender::bke::bNodeType ntype;
68 &ntype, "GeometryNodeCurveQuadraticBezier", GEO_NODE_CURVE_PRIMITIVE_QUADRATIC_BEZIER);
69 ntype.ui_name = "Quadratic Bézier";
70 ntype.ui_description =
71 "Generate a poly spline in a parabola shape with control points positions";
72 ntype.enum_name_legacy = "CURVE_PRIMITIVE_QUADRATIC_BEZIER";
74 ntype.declare = node_declare;
77}
79
80} // namespace blender::nodes::node_geo_curve_primitive_quadratic_bezier_cc
Low-level operations for curves.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#define GEO_NODE_CURVE_PRIMITIVE_QUADRATIC_BEZIER
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_TRANSLATION
Definition RNA_types.hh:261
@ PROP_UNSIGNED
Definition RNA_types.hh:249
MutableSpan< float3 > positions_for_write()
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
Curves * curves_new_nomain_single(int points_num, CurveType type)
T interpolate(const T &a, const T &b, const FactorT &t)
static Curves * create_quadratic_bezier_curve(const float3 p1, const float3 p2, const float3 p3, const int resolution)
VecBase< float, 3 > float3
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
CurvesGeometry geometry
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362
static GeometrySet from_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
i
Definition text_draw.cc:230