Blender V5.0
node_geo_curve_reverse.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")
19 .supported_type({GeometryComponent::Type::Curve, GeometryComponent::Type::GreasePencil})
20 .description("Curves to switch the start and end of");
21 b.add_output<decl::Geometry>("Curve").propagate_all().align_with_previous();
22 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
23}
24
26 const fn::FieldContext &field_context,
27 const Field<bool> &selection_field)
28{
29 fn::FieldEvaluator selection_evaluator{field_context, curves.curves_num()};
30 selection_evaluator.add(selection_field);
31 selection_evaluator.evaluate();
32 const IndexMask selection = selection_evaluator.get_evaluated_as_mask(0);
33 if (selection.is_empty()) {
34 return;
35 }
36 curves.reverse_curves(selection);
37}
38
39static void reverse_grease_pencil(GreasePencil &grease_pencil, const Field<bool> &selection_field)
40{
41 using namespace blender::bke::greasepencil;
42 for (const int layer_index : grease_pencil.layers().index_range()) {
43 Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
44 if (drawing == nullptr) {
45 continue;
46 }
48 const bke::GreasePencilLayerFieldContext field_context(
49 grease_pencil, AttrDomain::Curve, layer_index);
50 reverse_curve(curves, field_context, selection_field);
51 drawing->tag_topology_changed();
52 }
53}
54
56{
57 GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
58 Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
59
61
62 geometry::foreach_real_geometry(geometry_set, [&](GeometrySet &geometry_set) {
63 if (Curves *curves_id = geometry_set.get_curves_for_write()) {
64 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
65 const bke::CurvesFieldContext field_context{*curves_id, AttrDomain::Curve};
66 reverse_curve(curves, field_context, selection_field);
67 }
68 if (GreasePencil *grease_pencil = geometry_set.get_grease_pencil_for_write()) {
69 reverse_grease_pencil(*grease_pencil, selection_field);
70 }
71 });
72
73 params.set_output("Curve", std::move(geometry_set));
74}
75
76static void node_register()
77{
78 static blender::bke::bNodeType ntype;
79 geo_node_type_base(&ntype, "GeometryNodeReverseCurve", GEO_NODE_REVERSE_CURVE);
80 ntype.ui_name = "Reverse Curve";
81 ntype.ui_description = "Change the direction of curves by swapping their start and end data";
82 ntype.enum_name_legacy = "REVERSE_CURVE";
84 ntype.declare = node_declare;
87}
89
90} // namespace blender::nodes::node_geo_curve_reverse_cc
Low-level operations for curves.
Low-level operations for grease pencil.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#define GEO_NODE_REVERSE_CURVE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
void reverse_curves(const IndexMask &curves_to_reverse)
bke::CurvesGeometry & strokes_for_write()
int add(GField field, GVArray *varray_ptr)
Definition field.cc:751
IndexMask get_evaluated_as_mask(int field_index)
Definition field.cc:804
static void remember_deformed_positions_if_necessary(GeometrySet &geometry)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void foreach_real_geometry(bke::GeometrySet &geometry, FunctionRef< void(bke::GeometrySet &geometry_set)> fn)
static void node_declare(NodeDeclarationBuilder &b)
static void reverse_grease_pencil(GreasePencil &grease_pencil, const Field< bool > &selection_field)
static void node_geo_exec(GeoNodeExecParams params)
static void reverse_curve(bke::CurvesGeometry &curves, const fn::FieldContext &field_context, const Field< bool > &selection_field)
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