Blender V5.3
node_geo_set_curve_tilt.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)
20 .description("Curves to set tilt on");
21 b.add_output<decl::Geometry>("Curve"_ustr).propagate_all_geometry().align_with_previous();
22 b.add_input<decl::Bool>("Selection"_ustr)
23 .default_value(true)
24 .hide_value()
25 .evaluated_geometry_field();
26 b.add_input<decl::Float>("Tilt"_ustr).subtype(PROP_ANGLE).evaluated_geometry_field();
27}
28
30 const fn::FieldContext &field_context,
31 const Field<bool> &selection,
32 const Field<float> &tilt)
33{
34 bke::try_capture_field_on_geometry(curves.attributes_for_write(),
35 field_context,
36 "tilt",
38 selection,
39 tilt);
40}
41
43 const Field<bool> &selection,
44 const Field<float> &tilt)
45{
46 using namespace blender::bke::greasepencil;
47 for (const int layer_index : grease_pencil.layers().index_range()) {
48 Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
49 if (drawing == nullptr) {
50 continue;
51 }
53 drawing->strokes_for_write(),
55 selection,
56 tilt);
57 }
58}
59
61{
62 GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve"_ustr);
63 const Field<bool> selection = params.extract_input<Field<bool>>("Selection"_ustr);
64 const Field<float> tilt = params.extract_input<Field<float>>("Tilt"_ustr);
65
66 geometry::foreach_real_geometry(geometry_set, [&](GeometrySet &geometry_set) {
67 if (Curves *curves_id = geometry_set.get_curves_for_write()) {
68 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
69 const bke::CurvesFieldContext field_context(*curves_id, AttrDomain::Point);
70 set_curve_tilt(curves, field_context, selection, tilt);
71 }
73 set_grease_pencil_tilt(*grease_pencil, selection, tilt);
74 }
75 });
76
77 params.set_output("Curve"_ustr, std::move(geometry_set));
78}
79
80static void node_register()
81{
82 static bke::bNodeType ntype;
83
84 geo_node_type_base(&ntype, "GeometryNodeSetCurveTilt"_ustr, GEO_NODE_SET_CURVE_TILT);
85 ntype.ui_name = "Set Curve Tilt";
86 ntype.ui_description = "Set the tilt angle at each curve control point";
87 ntype.enum_name_legacy = "SET_CURVE_TILT";
90 ntype.declare = node_declare;
92}
94
95} // namespace blender::nodes::node_geo_set_curve_tilt_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_CURVE_TILT
#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_tilt(bke::CurvesGeometry &curves, const fn::FieldContext &field_context, const Field< bool > &selection, const Field< float > &tilt)
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
static void set_grease_pencil_tilt(GreasePencil &grease_pencil, const Field< bool > &selection, const Field< float > &tilt)
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