Blender V4.3
node_geo_curve_primitive_quadrilateral.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#include "NOD_rna_define.hh"
7
8#include "UI_interface.hh"
9#include "UI_resources.hh"
10
12
13#include "node_geometry_util.hh"
14
16
18
20{
21 auto &width = b.add_input<decl::Float>("Width")
22 .default_value(2.0f)
23 .min(0.0f)
25 .description("The X axis size of the shape");
26 auto &height = b.add_input<decl::Float>("Height")
27 .default_value(2.0f)
28 .min(0.0f)
30 .description("The Y axis size of the shape")
31 .available(false);
32 auto &bottom = b.add_input<decl::Float>("Bottom Width")
33 .default_value(4.0f)
34 .min(0.0f)
36 .description("The X axis size of the shape")
37 .available(false);
38 auto &top = b.add_input<decl::Float>("Top Width")
39 .default_value(2.0f)
40 .min(0.0f)
42 .description("The X axis size of the shape")
43 .available(false);
44 auto &offset =
45 b.add_input<decl::Float>("Offset")
46 .default_value(1.0f)
48 .description(
49 "For Parallelogram, the relative X difference between the top and bottom edges. For "
50 "Trapezoid, the amount to move the top edge in the positive X axis")
51 .available(false);
52 auto &bottom_height = b.add_input<decl::Float>("Bottom Height")
53 .default_value(3.0f)
54 .min(0.0f)
56 .description("The distance between the bottom point and the X axis")
57 .available(false);
58 auto &top_height = b.add_input<decl::Float>("Top Height")
59 .default_value(1.0f)
61 .description("The distance between the top point and the X axis")
62 .available(false);
63 auto &p1 = b.add_input<decl::Vector>("Point 1")
64 .default_value({-1.0f, -1.0f, 0.0f})
65 .subtype(PROP_TRANSLATION)
66 .description("The exact location of the point to use")
67 .available(false);
68 auto &p2 = b.add_input<decl::Vector>("Point 2")
69 .default_value({1.0f, -1.0f, 0.0f})
70 .subtype(PROP_TRANSLATION)
71 .description("The exact location of the point to use")
72 .available(false);
73 auto &p3 = b.add_input<decl::Vector>("Point 3")
74 .default_value({1.0f, 1.0f, 0.0f})
75 .subtype(PROP_TRANSLATION)
76 .description("The exact location of the point to use")
77 .available(false);
78 auto &p4 = b.add_input<decl::Vector>("Point 4")
79 .default_value({-1.0f, 1.0f, 0.0f})
80 .subtype(PROP_TRANSLATION)
81 .description("The exact location of the point to use")
82 .available(false);
83 b.add_output<decl::Geometry>("Curve");
84
85 const bNode *node = b.node_or_null();
86 if (node != nullptr) {
87 const NodeGeometryCurvePrimitiveQuad &storage = node_storage(*node);
90 width.available(true);
91 height.available(true);
92 break;
94 width.available(true);
95 height.available(true);
96 offset.available(true);
97 break;
99 bottom.available(true);
100 top.available(true);
101 offset.available(true);
102 height.available(true);
103 break;
105 width.available(true);
106 bottom_height.available(true);
107 top_height.available(true);
108 break;
110 p1.available(true);
111 p2.available(true);
112 p3.available(true);
113 p4.available(true);
114 break;
115 }
116 }
117}
118
119static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
120{
121 uiItemR(layout, ptr, "mode", UI_ITEM_NONE, "", ICON_NONE);
122}
123
124static void node_init(bNodeTree * /*tree*/, bNode *node)
125{
126 NodeGeometryCurvePrimitiveQuad *data = MEM_cnew<NodeGeometryCurvePrimitiveQuad>(__func__);
128 node->storage = data;
129}
130
132 public:
133 std::string socket_name;
136 {
137 bNode &node = params.add_node("GeometryNodeCurvePrimitiveQuadrilateral");
138 node_storage(node).mode = quad_mode;
139 params.update_and_connect_available_socket(node, socket_name);
140 }
141};
142
144{
145 const NodeDeclaration &declaration = *params.node_type().static_declaration;
146 if (params.in_out() == SOCK_OUT) {
148 }
149 else if (params.node_tree().typeinfo->validate_link(
150 eNodeSocketDatatype(params.other_socket().type), SOCK_FLOAT))
151 {
152 params.add_item(IFACE_("Width"),
154 params.add_item(IFACE_("Height"),
156 params.add_item(IFACE_("Bottom Width"),
158 params.add_item(IFACE_("Top Width"),
160 params.add_item(IFACE_("Offset"),
162 params.add_item(IFACE_("Point 1"),
164 }
165}
166
168 const float height,
169 const float width)
170{
171 positions[0] = float3(width / 2.0f, height / 2.0f, 0.0f);
172 positions[1] = float3(-width / 2.0f, height / 2.0f, 0.0f);
173 positions[2] = float3(-width / 2.0f, -height / 2.0f, 0.0f);
174 positions[3] = float3(width / 2.0f, -height / 2.0f, 0.0f);
175}
176
178 const float3 &p1,
179 const float3 &p2,
180 const float3 &p3,
181 const float3 &p4)
182{
183 positions[0] = p1;
184 positions[1] = p2;
185 positions[2] = p3;
186 positions[3] = p4;
187}
188
190 const float height,
191 const float width,
192 const float offset)
193{
194 positions[0] = float3(width / 2.0f + offset / 2.0f, height / 2.0f, 0.0f);
195 positions[1] = float3(-width / 2.0f + offset / 2.0f, height / 2.0f, 0.0f);
196 positions[2] = float3(-width / 2.0f - offset / 2.0f, -height / 2.0f, 0.0f);
197 positions[3] = float3(width / 2.0f - offset / 2.0f, -height / 2.0f, 0.0f);
198}
200 const float bottom,
201 const float top,
202 const float offset,
203 const float height)
204{
205 positions[0] = float3(top / 2.0f + offset, height / 2.0f, 0.0f);
206 positions[1] = float3(-top / 2.0f + offset, height / 2.0f, 0.0f);
207 positions[2] = float3(-bottom / 2.0f, -height / 2.0f, 0.0f);
208 positions[3] = float3(bottom / 2.0f, -height / 2.0f, 0.0f);
209}
210
212 const float width,
213 const float bottom_height,
214 const float top_height)
215{
216 positions[0] = float3(0, -bottom_height, 0);
217 positions[1] = float3(width / 2, 0, 0);
218 positions[2] = float3(0, top_height, 0);
219 positions[3] = float3(-width / 2.0f, 0, 0);
220}
221
223{
224 const NodeGeometryCurvePrimitiveQuad &storage = node_storage(params.node());
226
228 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
229 curves.cyclic_for_write().first() = true;
230
231 MutableSpan<float3> positions = curves.positions_for_write();
232
233 switch (mode) {
235 create_rectangle_curve(positions,
236 std::max(params.extract_input<float>("Height"), 0.0f),
237 std::max(params.extract_input<float>("Width"), 0.0f));
238 break;
239
242 std::max(params.extract_input<float>("Height"), 0.0f),
243 std::max(params.extract_input<float>("Width"), 0.0f),
244 params.extract_input<float>("Offset"));
245 break;
247 create_trapezoid_curve(positions,
248 std::max(params.extract_input<float>("Bottom Width"), 0.0f),
249 std::max(params.extract_input<float>("Top Width"), 0.0f),
250 params.extract_input<float>("Offset"),
251 std::max(params.extract_input<float>("Height"), 0.0f));
252 break;
254 create_kite_curve(positions,
255 std::max(params.extract_input<float>("Width"), 0.0f),
256 std::max(params.extract_input<float>("Bottom Height"), 0.0f),
257 params.extract_input<float>("Top Height"));
258 break;
260 create_points_curve(positions,
261 params.extract_input<float3>("Point 1"),
262 params.extract_input<float3>("Point 2"),
263 params.extract_input<float3>("Point 3"),
264 params.extract_input<float3>("Point 4"));
265 break;
266 default:
267 params.set_default_remaining_outputs();
268 return;
269 }
270
271 params.set_output("Curve", GeometrySet::from_curves(curves_id));
272}
273
274static void node_rna(StructRNA *srna)
275{
276 static EnumPropertyItem mode_items[] = {
278 "RECTANGLE",
279 0,
280 "Rectangle",
281 "Create a rectangle"},
283 "PARALLELOGRAM",
284 0,
285 "Parallelogram",
286 "Create a parallelogram"},
288 "TRAPEZOID",
289 0,
290 "Trapezoid",
291 "Create a trapezoid"},
292 {GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_KITE, "KITE", 0, "Kite", "Create a Kite / Dart"},
294 "POINTS",
295 0,
296 "Points",
297 "Create a quadrilateral from four points"},
298 {0, nullptr, 0, nullptr, nullptr},
299 };
300
302 "mode",
303 "Mode",
304 "",
305 mode_items,
308}
309
310static void node_register()
311{
312 static blender::bke::bNodeType ntype;
314 &ntype, GEO_NODE_CURVE_PRIMITIVE_QUADRILATERAL, "Quadrilateral", NODE_CLASS_GEOMETRY);
315 ntype.declare = node_declare;
318 ntype.initfunc = node_init;
320 "NodeGeometryCurvePrimitiveQuad",
325
326 node_rna(ntype.rna_ext.srna);
327}
329
330} // namespace blender::nodes::node_geo_curve_primitive_quadrilateral_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
#define IFACE_(msgid)
@ CURVE_TYPE_POLY
@ SOCK_OUT
eNodeSocketDatatype
@ SOCK_FLOAT
GeometryNodeCurvePrimitiveQuadMode
@ GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_KITE
@ GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_TRAPEZOID
@ GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_POINTS
@ GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_RECTANGLE
@ GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_PARALLELOGRAM
#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
#define UI_ITEM_NONE
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
Vector< SocketDeclaration * > outputs
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 void create_kite_curve(MutableSpan< float3 > positions, const float width, const float bottom_height, const float top_height)
static void create_rectangle_curve(MutableSpan< float3 > positions, const float height, const float width)
static void create_parallelogram_curve(MutableSpan< float3 > positions, const float height, const float width, const float offset)
static void create_points_curve(MutableSpan< float3 > positions, const float3 &p1, const float3 &p2, const float3 &p3, const float3 &p4)
static void create_trapezoid_curve(MutableSpan< float3 > positions, const float bottom, const float top, const float offset, const float height)
void search_link_ops_for_declarations(GatherLinkSearchOpParams &params, Span< SocketDeclaration * > declarations)
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, 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
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:363
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126