Blender V4.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
9#include "UI_interface.hh"
10#include "UI_resources.hh"
11
12#include "node_geometry_util.hh"
13
15
17
19{
20 auto enable_direction = [](bNode &node) {
21 node_storage(node).mode = GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_DIRECTION;
22 };
23
24 b.add_input<decl::Vector>("Start")
25 .subtype(PROP_TRANSLATION)
26 .description("Position of the first control point");
27 auto &end = b.add_input<decl::Vector>("End")
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) {
32 node_storage(node).mode = GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_POINTS;
33 });
34 auto &direction =
35 b.add_input<decl::Vector>("Direction")
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")
40 .default_value(1.0f)
42 .description("Distance between the two points")
43 .make_available(enable_direction);
44 b.add_output<decl::Geometry>("Curve");
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);
54 length.available(mode == GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_DIRECTION);
55 }
56}
57
58static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
59{
60 uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
61}
62
63static void node_init(bNodeTree * /*tree*/, bNode *node)
64{
65 NodeGeometryCurvePrimitiveLine *data = MEM_cnew<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"),
103 params.extract_input<float3>("End"));
104 }
106 curves = create_direction_line_curve(params.extract_input<float3>("Start"),
107 params.extract_input<float3>("Direction"),
108 params.extract_input<float>("Length"));
109 }
110
111 params.set_output("Curve", 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 blender::bke::bNodeType ntype;
142 geo_node_type_base(&ntype, GEO_NODE_CURVE_PRIMITIVE_LINE, "Curve Line", NODE_CLASS_GEOMETRY);
143 ntype.initfunc = node_init;
145 "NodeGeometryCurvePrimitiveLine",
148 ntype.declare = node_declare;
152
153 node_rna(ntype.rna_ext.srna);
154}
156
157} // namespace blender::nodes::node_geo_curve_primitive_line_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_POLY
GeometryNodeCurvePrimitiveLineMode
@ GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_POINTS
@ GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_DIRECTION
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
@ PROP_DISTANCE
Definition RNA_types.hh:159
@ PROP_TRANSLATION
Definition RNA_types.hh:164
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_EXPAND
void make_available(bNode &node) const
local_group_size(16, 16) .push_constant(Type b
OperationNode * node
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)
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(uiLayout *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)
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