Blender V4.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
11
13{
14 b.add_input<decl::Geometry>("Geometry")
16 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
17 b.add_input<decl::Bool>("Cyclic").field_on_all();
18 b.add_output<decl::Geometry>("Geometry").propagate_all();
19}
20
22 const fn::FieldContext &field_context,
23 const Field<bool> &selection,
24 const Field<bool> &cyclic)
25{
26 bke::try_capture_field_on_geometry(curves.attributes_for_write(),
27 field_context,
28 "cyclic",
30 selection,
31 cyclic);
32}
33
34static void set_grease_pencil_cyclic(GreasePencil &grease_pencil,
35 const Field<bool> &selection,
36 const Field<bool> &cyclic)
37{
38 using namespace blender::bke::greasepencil;
39 for (const int layer_index : grease_pencil.layers().index_range()) {
40 Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
41 if (drawing == nullptr) {
42 continue;
43 }
45 drawing->strokes_for_write(),
46 bke::GreasePencilLayerFieldContext(grease_pencil, AttrDomain::Curve, layer_index),
47 selection,
48 cyclic);
49 }
50}
51
53{
54 GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
55 const Field<bool> selection = params.extract_input<Field<bool>>("Selection");
56 const Field<bool> cyclic = params.extract_input<Field<bool>>("Cyclic");
57
58 geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
59 if (Curves *curves_id = geometry_set.get_curves_for_write()) {
60 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
61 const bke::CurvesFieldContext field_context{*curves_id, AttrDomain::Curve};
62 set_curve_cyclic(curves, field_context, selection, cyclic);
63 }
64 if (GreasePencil *grease_pencil = geometry_set.get_grease_pencil_for_write()) {
65 set_grease_pencil_cyclic(*grease_pencil, selection, cyclic);
66 }
67 });
68
69 params.set_output("Geometry", std::move(geometry_set));
70}
71
72static void node_register()
73{
74 static blender::bke::bNodeType ntype;
75
76 geo_node_type_base(&ntype, GEO_NODE_SET_SPLINE_CYCLIC, "Set Spline Cyclic", NODE_CLASS_GEOMETRY);
78 ntype.declare = node_declare;
80}
82
83} // 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:418
#define NOD_REGISTER_NODE(REGISTER_FUNC)
bke::CurvesGeometry & strokes_for_write()
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
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 node_register_type(bNodeType *ntype)
Definition node.cc:1708
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, int type, const char *name, short nclass)
void modify_geometry_sets(ForeachSubGeometryCallback callback)
GreasePencil * get_grease_pencil_for_write()
Defines a node type.
Definition BKE_node.hh:218
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
NodeDeclareFunction declare
Definition BKE_node.hh:347