Blender V5.3
node_geo_curve_primitive_bezier_segment.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"
6
7#include "NOD_rna_define.hh"
8
10#include "UI_resources.hh"
11
12#include "node_geometry_util.hh"
13
15
17
19{
20 b.add_input<decl::Int>("Resolution"_ustr)
21 .default_value(16)
22 .min(1)
23 .max(256)
24 .subtype(PROP_UNSIGNED)
25 .description("The number of evaluated points on the curve");
26 b.add_input<decl::Vector>("Start"_ustr)
27 .default_value({-1.0f, 0.0f, 0.0f})
28 .subtype(PROP_TRANSLATION)
29 .description("Position of the start control point of the curve");
30 b.add_input<decl::Vector>("Start Handle"_ustr)
31 .default_value({-0.5f, 0.5f, 0.0f})
32 .subtype(PROP_TRANSLATION)
33 .description(
34 "Position of the start handle used to define the shape of the curve. In Offset mode, "
35 "relative to Start point");
36 b.add_input<decl::Vector>("End Handle"_ustr)
38 .description(
39 "Position of the end handle used to define the shape of the curve. In Offset mode, "
40 "relative to End point");
41 b.add_input<decl::Vector>("End"_ustr)
42 .default_value({1.0f, 0.0f, 0.0f})
43 .subtype(PROP_TRANSLATION)
44 .description("Position of the end control point of the curve");
45 b.add_output<decl::Geometry>("Curve"_ustr);
46}
47
48static void node_layout(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
49{
50 layout.prop(ptr, "mode", ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
51}
52
53static void node_init(bNodeTree * /*tree*/, bNode *node)
54{
55 NodeGeometryCurvePrimitiveBezierSegment *data = MEM_new<NodeGeometryCurvePrimitiveBezierSegment>(
56 __func__);
57
59 node->storage = data;
60}
61
63 const float3 start_handle_right,
64 const float3 end,
65 const float3 end_handle_left,
66 const int resolution,
68{
70 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
71 curves.resolution_for_write().fill(resolution);
72
73 MutableSpan<float3> positions = curves.positions_for_write();
74 curves.handle_types_left_for_write().fill(BEZIER_HANDLE_ALIGN);
75 curves.handle_types_right_for_write().fill(BEZIER_HANDLE_ALIGN);
76
77 positions.first() = start;
78 positions.last() = end;
79
80 MutableSpan<float3> handles_right = curves.handle_positions_right_for_write();
81 MutableSpan<float3> handles_left = curves.handle_positions_left_for_write();
82
84 handles_left.first() = 2.0f * start - start_handle_right;
85 handles_right.first() = start_handle_right;
86
87 handles_left.last() = end_handle_left;
88 handles_right.last() = 2.0f * end - end_handle_left;
89 }
90 else {
91 handles_left.first() = start - start_handle_right;
92 handles_right.first() = start + start_handle_right;
93
94 handles_left.last() = end + end_handle_left;
95 handles_right.last() = end - end_handle_left;
96 }
97
98 return curves_id;
99}
100
102{
103 const NodeGeometryCurvePrimitiveBezierSegment &storage = node_storage(params.node());
106
108 params.extract_input<float3>("Start"_ustr),
109 params.extract_input<float3>("Start Handle"_ustr),
110 params.extract_input<float3>("End"_ustr),
111 params.extract_input<float3>("End Handle"_ustr),
112 std::max(params.extract_input<int>("Resolution"_ustr), 1),
113 mode);
114 params.set_output("Curve"_ustr, GeometrySet::from_curves(curves));
115}
116
117static void node_rna(StructRNA *srna)
118{
119 static const EnumPropertyItem mode_items[] = {
120
122 "POSITION",
123 ICON_NONE,
124 "Position",
125 "The start and end handles are fixed positions"},
127 "OFFSET",
128 ICON_NONE,
129 "Offset",
130 "The start and end handles are offsets from the spline's control points"},
131 {0, nullptr, 0, nullptr, nullptr},
132 };
133
135 "mode",
136 "Mode",
137 "Method used to determine control handles",
138 mode_items,
141}
142
143static void node_register()
144{
145 static bke::bNodeType ntype;
146 geo_node_type_base(&ntype,
147 "GeometryNodeCurvePrimitiveBezierSegment"_ustr,
149 ntype.ui_name = "Bézier Segment";
150 ntype.ui_description = "Generate a 2D Bézier spline from the given control points and handles";
151 ntype.enum_name_legacy = "CURVE_PRIMITIVE_BEZIER_SEGMENT";
153 ntype.initfunc = node_init;
155 "NodeGeometryCurvePrimitiveBezierSegment",
158 ntype.declare = node_declare;
162
163 node_rna(ntype.rna_ext.srna);
164}
166
167} // namespace blender::nodes::node_geo_curve_primitive_bezier_segment_cc
Low-level operations for curves.
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1353
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
btScalar max
constexpr T & first() const
Definition BLI_span.hh:685
constexpr T & last(const int64_t n=0) const
Definition BLI_span.hh:695
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
#define storage(slot, qualifiers)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
Curves * curves_new_nomain_single(int points_num, CurveType type)
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:6166
static Curves * create_bezier_segment_curve(const float3 start, const float3 start_handle_right, const float3 end, const float3 end_handle_left, const int resolution, const GeometryNodeCurvePrimitiveBezierSegmentMode mode)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
GeometryNodeCurvePrimitiveBezierSegmentMode
@ GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT_OFFSET
@ GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT_POSITION
BMesh const char void * data
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
VecBase< float, 3 > float3
@ PROP_TRANSLATION
Definition RNA_types.hh:318
@ PROP_UNSIGNED
Definition RNA_types.hh:306
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
#define min(a, b)
Definition sort.cc:38
Defines a node type.
Definition BKE_node.hh:265
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
static GeometrySet from_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)