Blender V5.0
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", "Geometry")
19 .supported_type({GeometryComponent::Type::Curve, GeometryComponent::Type::GreasePencil})
20 .description("Curves to change the cyclic state of");
21 b.add_output<decl::Geometry>("Curve", "Geometry").propagate_all().align_with_previous();
22 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
23 b.add_input<decl::Bool>("Cyclic").field_on_all();
24}
25
27 const fn::FieldContext &field_context,
28 const Field<bool> &selection,
29 const Field<bool> &cyclic)
30{
32 field_context,
33 "cyclic",
35 selection,
36 cyclic);
37}
38
39static void set_grease_pencil_cyclic(GreasePencil &grease_pencil,
40 const Field<bool> &selection,
41 const Field<bool> &cyclic)
42{
43 using namespace blender::bke::greasepencil;
44 for (const int layer_index : grease_pencil.layers().index_range()) {
45 Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
46 if (drawing == nullptr) {
47 continue;
48 }
50 drawing->strokes_for_write(),
51 bke::GreasePencilLayerFieldContext(grease_pencil, AttrDomain::Curve, layer_index),
52 selection,
53 cyclic);
54 }
55}
56
58{
59 GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
60 const Field<bool> selection = params.extract_input<Field<bool>>("Selection");
61 const Field<bool> cyclic = params.extract_input<Field<bool>>("Cyclic");
62
63 geometry::foreach_real_geometry(geometry_set, [&](GeometrySet &geometry_set) {
64 if (Curves *curves_id = geometry_set.get_curves_for_write()) {
65 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
66 const bke::CurvesFieldContext field_context{*curves_id, AttrDomain::Curve};
67 set_curve_cyclic(curves, field_context, selection, cyclic);
68 }
69 if (GreasePencil *grease_pencil = geometry_set.get_grease_pencil_for_write()) {
70 set_grease_pencil_cyclic(*grease_pencil, selection, cyclic);
71 }
72 });
73
74 params.set_output("Geometry", std::move(geometry_set));
75}
76
77static void node_register()
78{
79 static blender::bke::bNodeType ntype;
80
81 geo_node_type_base(&ntype, "GeometryNodeSetSplineCyclic", GEO_NODE_SET_SPLINE_CYCLIC);
82 ntype.ui_name = "Set Spline Cyclic";
83 ntype.ui_description =
84 "Control whether each spline loops back on itself by changing the \"cyclic\" attribute";
85 ntype.enum_name_legacy = "SET_SPLINE_CYCLIC";
88 ntype.declare = node_declare;
90}
92
93} // 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:461
#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:2416
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)
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(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
GreasePencil * get_grease_pencil_for_write()
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362