Blender V4.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
9#include "UI_interface.hh"
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)
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)
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")
37 .subtype(PROP_TRANSLATION)
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 uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
51}
52
53static void node_init(bNodeTree * /*tree*/, bNode *node)
54{
56 MEM_cnew<NodeGeometryCurvePrimitiveBezierSegment>(__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"),
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, GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT, "Bézier Segment", NODE_CLASS_GEOMETRY);
148 ntype.initfunc = node_init;
150 "NodeGeometryCurvePrimitiveBezierSegment",
153 ntype.declare = node_declare;
157
158 node_rna(ntype.rna_ext.srna);
159}
161
162} // namespace blender::nodes::node_geo_curve_primitive_bezier_segment_cc
Low-level operations for curves.
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1799
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
@ CURVE_TYPE_BEZIER
@ 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:164
@ PROP_UNSIGNED
Definition RNA_types.hh:152
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_EXPAND
constexpr void fill(const T &value) const
Definition BLI_span.hh:518
constexpr T & first() const
Definition BLI_span.hh:680
constexpr T & last(const int64_t n=0) const
Definition BLI_span.hh:690
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
Curves * curves_new_nomain_single(int points_num, CurveType type)
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)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:46
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:58
CurvesGeometry geometry
StructRNA * srna
Definition RNA_types.hh:780
static GeometrySet from_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Defines a node type.
Definition BKE_node.hh:218
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126