Blender V5.3
node_geo_curve_primitive_line.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 auto enable_direction = [](bNode &node) {
22 };
23
24 b.add_input<decl::Vector>("Start"_ustr)
26 .description("Position of the first control point");
27 auto &end = b.add_input<decl::Vector>("End"_ustr)
28 .default_value({0.0f, 0.0f, 1.0f})
29 .subtype(PROP_TRANSLATION)
30 .description("Position of the second control point")
31 .make_available([](bNode &node) {
33 });
34 auto &direction =
35 b.add_input<decl::Vector>("Direction"_ustr)
36 .default_value({0.0f, 0.0f, 1.0f})
37 .description("Direction the line is going in. The length of this vector does not matter")
38 .make_available(enable_direction);
39 auto &length = b.add_input<decl::Float>("Length"_ustr)
40 .default_value(1.0f)
41 .subtype(PROP_DISTANCE)
42 .description("Distance between the two points")
43 .make_available(enable_direction);
44 b.add_output<decl::Geometry>("Curve"_ustr);
45
46 const bNode *node = b.node_or_null();
47 if (node != nullptr) {
48 const NodeGeometryCurvePrimitiveLine &storage = node_storage(*node);
50 storage.mode);
51
52 end.available(mode == GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_POINTS);
53 direction.available(mode == GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_DIRECTION);
55 }
56}
57
58static void node_layout(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
59{
60 layout.prop(ptr, "mode", ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
61}
62
63static void node_init(bNodeTree * /*tree*/, bNode *node)
64{
65 NodeGeometryCurvePrimitiveLine *data = MEM_new<NodeGeometryCurvePrimitiveLine>(__func__);
66
68 node->storage = data;
69}
70
71static Curves *create_point_line_curve(const float3 start, const float3 end)
72{
74 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
75
76 curves.positions_for_write().first() = start;
77 curves.positions_for_write().last() = end;
78
79 return curves_id;
80}
81
83 const float3 direction,
84 const float length)
85{
87 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
88
89 curves.positions_for_write().first() = start;
90 curves.positions_for_write().last() = math::normalize(direction) * length + start;
91
92 return curves_id;
93}
94
96{
97 const NodeGeometryCurvePrimitiveLine &storage = node_storage(params.node());
99
100 Curves *curves = nullptr;
102 curves = create_point_line_curve(params.extract_input<float3>("Start"_ustr),
103 params.extract_input<float3>("End"_ustr));
104 }
107 params.extract_input<float3>("Direction"_ustr),
108 params.extract_input<float>("Length"_ustr));
109 }
110
111 params.set_output("Curve"_ustr, GeometrySet::from_curves(curves));
112}
113
114static void node_rna(StructRNA *srna)
115{
116 static const EnumPropertyItem mode_items[] = {
118 "POINTS",
119 ICON_NONE,
120 "Points",
121 "Define the start and end points of the line"},
123 "DIRECTION",
124 ICON_NONE,
125 "Direction",
126 "Define a line with a start point, direction and length"},
127 {0, nullptr, 0, nullptr, nullptr},
128 };
129
131 "mode",
132 "Mode",
133 "Method used to determine radius and placement",
134 mode_items,
137}
138
139static void node_register()
140{
141 static bke::bNodeType ntype;
142 geo_node_type_base(&ntype, "GeometryNodeCurvePrimitiveLine"_ustr, GEO_NODE_CURVE_PRIMITIVE_LINE);
143 ntype.ui_name = "Curve Line";
144 ntype.ui_description = "Generate a poly spline line with two points";
145 ntype.enum_name_legacy = "CURVE_PRIMITIVE_LINE";
147 ntype.initfunc = node_init;
149 "NodeGeometryCurvePrimitiveLine",
152 ntype.declare = node_declare;
156
157 node_rna(ntype.rna_ext.srna);
158}
160
161} // namespace blender::nodes::node_geo_curve_primitive_line_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_LINE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
#define storage(slot, qualifiers)
float length(VecOp< float, D >) RET
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
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
static Curves * create_direction_line_curve(const float3 start, const float3 direction, const float length)
static Curves * create_point_line_curve(const float3 start, const float3 end)
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)
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
GeometryNodeCurvePrimitiveLineMode
@ GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_DIRECTION
@ GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_POINTS
VecBase< float, 3 > float3
@ PROP_TRANSLATION
Definition RNA_types.hh:318
@ PROP_DISTANCE
Definition RNA_types.hh:313
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
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)