Blender V5.0
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")
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")
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")
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")
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")
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");
46}
47
48static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
49{
50 layout->prop(ptr, "mode", UI_ITEM_R_EXPAND, std::nullopt, ICON_NONE);
51}
52
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();
76
77 positions.first() = start;
78 positions.last() = end;
79
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"),
109 params.extract_input<float3>("Start Handle"),
110 params.extract_input<float3>("End"),
111 params.extract_input<float3>("End Handle"),
112 std::max(params.extract_input<int>("Resolution"), 1),
113 mode);
114 params.set_output("Curve", 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 blender::bke::bNodeType ntype;
147 &ntype, "GeometryNodeCurvePrimitiveBezierSegment", GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT);
148 ntype.ui_name = "Bézier Segment";
149 ntype.ui_description = "Generate a 2D Bézier spline from the given control points and handles";
150 ntype.enum_name_legacy = "CURVE_PRIMITIVE_BEZIER_SEGMENT";
152 ntype.initfunc = node_init;
154 "NodeGeometryCurvePrimitiveBezierSegment",
157 ntype.declare = node_declare;
161
162 node_rna(ntype.rna_ext.srna);
163}
165
166} // namespace blender::nodes::node_geo_curve_primitive_bezier_segment_cc
Low-level operations for curves.
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1240
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#define GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT
@ BEZIER_HANDLE_ALIGN
GeometryNodeCurvePrimitiveBezierSegmentMode
@ GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT_POSITION
@ GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT_OFFSET
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
@ PROP_TRANSLATION
Definition RNA_types.hh:261
@ PROP_UNSIGNED
Definition RNA_types.hh:249
@ UI_ITEM_R_EXPAND
BMesh const char void * data
constexpr void fill(const T &value) const
Definition BLI_span.hh:517
constexpr T & first() const
Definition BLI_span.hh:679
constexpr T & last(const int64_t n=0) const
Definition BLI_span.hh:689
MutableSpan< float3 > positions_for_write()
MutableSpan< int8_t > handle_types_right_for_write()
MutableSpan< int > resolution_for_write()
MutableSpan< float3 > handle_positions_left_for_write()
MutableSpan< float3 > handle_positions_right_for_write()
MutableSpan< int8_t > handle_types_left_for_write()
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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:5414
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
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)
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)
VecBase< float, 3 > float3
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:42
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:54
#define min(a, b)
Definition sort.cc:36
CurvesGeometry geometry
StructRNA * srna
void * storage
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeDeclareFunction declare
Definition BKE_node.hh:362
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< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
max
Definition text_draw.cc:251
PointerRNA * ptr
Definition wm_files.cc:4238