Blender V5.3
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
10#include "node_geometry_util.hh"
11
13
15{
16 b.use_custom_socket_order();
17 b.allow_any_socket_order();
18 b.add_input<decl::Geometry>("Curve"_ustr, "Geometry"_ustr)
20 .description("Curves to change the cyclic state of");
21 b.add_output<decl::Geometry>("Curve"_ustr, "Geometry"_ustr)
22 .propagate_all_geometry()
23 .align_with_previous();
24 b.add_input<decl::Bool>("Selection"_ustr)
25 .default_value(true)
26 .hide_value()
27 .evaluated_geometry_field();
28 b.add_input<decl::Bool>("Cyclic"_ustr).evaluated_geometry_field();
29}
30
32 const fn::FieldContext &field_context,
33 const Field<bool> &selection,
34 const Field<bool> &cyclic)
35{
36 bke::try_capture_field_on_geometry(curves.attributes_for_write(),
37 field_context,
38 "cyclic",
40 selection,
41 cyclic);
42}
43
45 const Field<bool> &selection,
46 const Field<bool> &cyclic)
47{
48 using namespace blender::bke::greasepencil;
49 for (const int layer_index : grease_pencil.layers().index_range()) {
50 Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
51 if (drawing == nullptr) {
52 continue;
53 }
55 drawing->strokes_for_write(),
57 selection,
58 cyclic);
59 }
60}
61
63{
64 GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"_ustr);
65 const Field<bool> selection = params.extract_input<Field<bool>>("Selection"_ustr);
66 const Field<bool> cyclic = params.extract_input<Field<bool>>("Cyclic"_ustr);
67
68 geometry::foreach_real_geometry(geometry_set, [&](GeometrySet &geometry_set) {
69 if (Curves *curves_id = geometry_set.get_curves_for_write()) {
70 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
71 const bke::CurvesFieldContext field_context{*curves_id, AttrDomain::Curve};
72 set_curve_cyclic(curves, field_context, selection, cyclic);
73 }
75 set_grease_pencil_cyclic(*grease_pencil, selection, cyclic);
76 }
77 });
78
79 params.set_output("Geometry"_ustr, std::move(geometry_set));
80}
81
82static void node_register()
83{
84 static bke::bNodeType ntype;
85
86 geo_node_type_base(&ntype, "GeometryNodeSetSplineCyclic"_ustr, GEO_NODE_SET_SPLINE_CYCLIC);
87 ntype.ui_name = "Set Spline Cyclic";
88 ntype.ui_description =
89 "Control whether each spline loops back on itself by changing the \"cyclic\" attribute";
90 ntype.enum_name_legacy = "SET_SPLINE_CYCLIC";
93 ntype.declare = node_declare;
95}
97
98} // 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:492
#define GEO_NODE_SET_SPLINE_CYCLIC
#define NOD_REGISTER_NODE(REGISTER_FUNC)
bke::CurvesGeometry & strokes_for_write()
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
bool try_capture_field_on_geometry(MutableAttributeAccessor attributes, const fn::FieldContext &field_context, const StringRef name, AttrDomain domain, const fn::Field< bool > &selection, const fn::GField &field)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void foreach_real_geometry(bke::GeometrySet &geometry, FunctionRef< void(bke::GeometrySet &geometry_set)> fn)
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(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
GreasePencil * get_grease_pencil_for_write()
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393