Blender V5.0
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")
19 .supported_type({GeometryComponent::Type::Curve, GeometryComponent::Type::GreasePencil})
20 .description("Curves to set tilt on");
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 b.add_input<decl::Float>("Tilt").subtype(PROP_ANGLE).field_on_all();
24}
25
27 const fn::FieldContext &field_context,
28 const Field<bool> &selection,
29 const Field<float> &tilt)
30{
32 field_context,
33 "tilt",
35 selection,
36 tilt);
37}
38
39static void set_grease_pencil_tilt(GreasePencil &grease_pencil,
40 const Field<bool> &selection,
41 const Field<float> &tilt)
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::Point, layer_index),
52 selection,
53 tilt);
54 }
55}
56
58{
59 GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
60 const Field<bool> selection = params.extract_input<Field<bool>>("Selection");
61 const Field<float> tilt = params.extract_input<Field<float>>("Tilt");
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::Point);
67 set_curve_tilt(curves, field_context, selection, tilt);
68 }
69 if (GreasePencil *grease_pencil = geometry_set.get_grease_pencil_for_write()) {
70 set_grease_pencil_tilt(*grease_pencil, selection, tilt);
71 }
72 });
73
74 params.set_output("Curve", std::move(geometry_set));
75}
76
77static void node_register()
78{
79 static blender::bke::bNodeType ntype;
80
81 geo_node_type_base(&ntype, "GeometryNodeSetCurveTilt", GEO_NODE_SET_CURVE_TILT);
82 ntype.ui_name = "Set Curve Tilt";
83 ntype.ui_description = "Set the tilt angle at each curve control point";
84 ntype.enum_name_legacy = "SET_CURVE_TILT";
87 ntype.declare = node_declare;
89}
91
92} // 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:461
#define GEO_NODE_SET_CURVE_TILT
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_ANGLE
Definition RNA_types.hh:252
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_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(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