Blender V4.3
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, GEO_NODE_CURVE_PRIMITIVE_QUADRATIC_BEZIER, "Quadratic Bézier", NODE_CLASS_GEOMETRY);
69 ntype.declare = node_declare;
72}
74
75} // namespace blender::nodes::node_geo_curve_primitive_quadratic_bezier_cc
Low-level operations for curves.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
@ CURVE_TYPE_POLY
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_TRANSLATION
Definition RNA_types.hh:164
@ PROP_UNSIGNED
Definition RNA_types.hh:152
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
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)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
CurvesGeometry geometry
static GeometrySet from_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Defines a node type.
Definition BKE_node.hh:218
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
NodeDeclareFunction declare
Definition BKE_node.hh:347