Blender V4.5
node_geo_set_spline_cyclic.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"
7
9
11
13{
14 b.use_custom_socket_order();
15 b.allow_any_socket_order();
16 b.add_input<decl::Geometry>("Geometry")
17 .supported_type({GeometryComponent::Type::Curve, GeometryComponent::Type::GreasePencil});
18 b.add_output<decl::Geometry>("Geometry").propagate_all().align_with_previous();
19 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
20 b.add_input<decl::Bool>("Cyclic").field_on_all();
21}
22
24 const fn::FieldContext &field_context,
25 const Field<bool> &selection,
26 const Field<bool> &cyclic)
27{
29 field_context,
30 "cyclic",
32 selection,
33 cyclic);
34}
35
36static void set_grease_pencil_cyclic(GreasePencil &grease_pencil,
37 const Field<bool> &selection,
38 const Field<bool> &cyclic)
39{
40 using namespace blender::bke::greasepencil;
41 for (const int layer_index : grease_pencil.layers().index_range()) {
42 Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
43 if (drawing == nullptr) {
44 continue;
45 }
47 drawing->strokes_for_write(),
48 bke::GreasePencilLayerFieldContext(grease_pencil, AttrDomain::Curve, layer_index),
49 selection,
50 cyclic);
51 }
52}
53
55{
56 GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
57 const Field<bool> selection = params.extract_input<Field<bool>>("Selection");
58 const Field<bool> cyclic = params.extract_input<Field<bool>>("Cyclic");
59
60 geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
61 if (Curves *curves_id = geometry_set.get_curves_for_write()) {
62 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
63 const bke::CurvesFieldContext field_context{*curves_id, AttrDomain::Curve};
64 set_curve_cyclic(curves, field_context, selection, cyclic);
65 }
66 if (GreasePencil *grease_pencil = geometry_set.get_grease_pencil_for_write()) {
67 set_grease_pencil_cyclic(*grease_pencil, selection, cyclic);
68 }
69 });
70
71 params.set_output("Geometry", std::move(geometry_set));
72}
73
74static void node_register()
75{
76 static blender::bke::bNodeType ntype;
77
78 geo_node_type_base(&ntype, "GeometryNodeSetSplineCyclic", GEO_NODE_SET_SPLINE_CYCLIC);
79 ntype.ui_name = "Set Spline Cyclic";
80 ntype.ui_description =
81 "Control whether each spline loops back on itself by changing the \"cyclic\" attribute";
82 ntype.enum_name_legacy = "SET_SPLINE_CYCLIC";
85 ntype.declare = node_declare;
87}
89
90} // namespace blender::nodes::node_geo_set_spline_cyclic_cc
Low-level operations for curves.
Low-level operations for grease pencil.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:447
#define GEO_NODE_SET_SPLINE_CYCLIC
#define NOD_REGISTER_NODE(REGISTER_FUNC)
MutableAttributeAccessor attributes_for_write()
bke::CurvesGeometry & strokes_for_write()
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
bool try_capture_field_on_geometry(MutableAttributeAccessor attributes, const fn::FieldContext &field_context, const StringRef attribute_id, AttrDomain domain, const fn::Field< bool > &selection, const fn::GField &field)
static void set_curve_cyclic(bke::CurvesGeometry &curves, const fn::FieldContext &field_context, const Field< bool > &selection, const Field< bool > &cyclic)
static void node_declare(NodeDeclarationBuilder &b)
static void set_grease_pencil_cyclic(GreasePencil &grease_pencil, const Field< bool > &selection, const Field< bool > &cyclic)
static void node_geo_exec(GeoNodeExecParams params)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void modify_geometry_sets(ForeachSubGeometryCallback callback)
GreasePencil * get_grease_pencil_for_write()
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:347
const char * enum_name_legacy
Definition BKE_node.hh:235
NodeDeclareFunction declare
Definition BKE_node.hh:355