Blender  V3.3
node_geo_curve_primitive_quadratic_bezier.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "BKE_curves.hh"
4 #include "node_geometry_util.hh"
5 
7 
9 {
10  b.add_input<decl::Int>(N_("Resolution"))
11  .default_value(16)
12  .min(3)
13  .max(256)
14  .subtype(PROP_UNSIGNED)
15  .description(N_("The number of edges on the curve"));
16  b.add_input<decl::Vector>(N_("Start"))
17  .default_value({-1.0f, 0.0f, 0.0f})
18  .subtype(PROP_TRANSLATION)
19  .description(N_("Position of the first control point"));
20  b.add_input<decl::Vector>(N_("Middle"))
21  .default_value({0.0f, 2.0f, 0.0f})
22  .subtype(PROP_TRANSLATION)
23  .description(N_("Position of the middle control point"));
24  b.add_input<decl::Vector>(N_("End"))
25  .default_value({1.0f, 0.0f, 0.0f})
26  .subtype(PROP_TRANSLATION)
27  .description(N_("Position of the last control point"));
28  b.add_output<decl::Geometry>(N_("Curve"));
29 }
30 
32  const float3 p2,
33  const float3 p3,
34  const int resolution)
35 {
36  Curves *curves_id = bke::curves_new_nomain_single(resolution + 1, CURVE_TYPE_POLY);
38 
39  MutableSpan<float3> positions = curves.positions_for_write();
40 
41  const float step = 1.0f / resolution;
42  for (const int i : IndexRange(resolution + 1)) {
43  const float factor = step * i;
44  const float3 q1 = math::interpolate(p1, p2, factor);
45  const float3 q2 = math::interpolate(p2, p3, factor);
46  positions[i] = math::interpolate(q1, q2, factor);
47  }
48 
49  return curves_id;
50 }
51 
53 {
55  params.extract_input<float3>("Start"),
56  params.extract_input<float3>("Middle"),
57  params.extract_input<float3>("End"),
58  std::max(params.extract_input<int>("Resolution"), 3));
59  params.set_output("Curve", GeometrySet::create_with_curves(curves));
60 }
61 
62 } // namespace blender::nodes::node_geo_curve_primitive_quadratic_bezier_cc
63 
65 {
67 
68  static bNodeType ntype;
73  nodeRegisterType(&ntype);
74 }
Low-level operations for curves.
#define NODE_CLASS_GEOMETRY
Definition: BKE_node.h:359
#define GEO_NODE_CURVE_PRIMITIVE_QUADRATIC_BEZIER
Definition: BKE_node.h:1410
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
@ CURVE_TYPE_POLY
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to curves
@ PROP_TRANSLATION
Definition: RNA_types.h:154
@ PROP_UNSIGNED
Definition: RNA_types.h:142
static CurvesGeometry & wrap(::CurvesGeometry &dna_struct)
Definition: BKE_curves.hh:138
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
Curves * curves_new_nomain_single(int points_num, CurveType type)
Definition: curves.cc:375
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)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_geo_curve_primitive_quadratic_bezier()
MutableSpan< float3 > positions
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
CurvesGeometry geometry
static GeometrySet create_with_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Defines a node type.
Definition: BKE_node.h:226
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:316
NodeDeclareFunction declare
Definition: BKE_node.h:324
float max
#define N_(msgid)