Blender V4.5
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
11
13{
14 b.use_custom_socket_order();
15 b.allow_any_socket_order();
16 b.add_input<decl::Geometry>("Curve").supported_type(
17 {GeometryComponent::Type::Curve, GeometryComponent::Type::GreasePencil});
18 b.add_output<decl::Geometry>("Curve").propagate_all().align_with_previous();
19 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
20 b.add_input<decl::Float>("Tilt").subtype(PROP_ANGLE).field_on_all();
21}
22
24 const fn::FieldContext &field_context,
25 const Field<bool> &selection,
26 const Field<float> &tilt)
27{
29 field_context,
30 "tilt",
32 selection,
33 tilt);
34}
35
36static void set_grease_pencil_tilt(GreasePencil &grease_pencil,
37 const Field<bool> &selection,
38 const Field<float> &tilt)
39{
40 using namespace blender::bke::greasepencil;
41 for (const int layer_index : grease_pencil.layers().index_range()) {
42 Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
43 if (drawing == nullptr) {
44 continue;
45 }
47 drawing->strokes_for_write(),
48 bke::GreasePencilLayerFieldContext(grease_pencil, AttrDomain::Point, layer_index),
49 selection,
50 tilt);
51 }
52}
53
55{
56 GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
57 const Field<bool> selection = params.extract_input<Field<bool>>("Selection");
58 const Field<float> tilt = params.extract_input<Field<float>>("Tilt");
59
60 geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
61 if (Curves *curves_id = geometry_set.get_curves_for_write()) {
62 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
63 const bke::CurvesFieldContext field_context(*curves_id, AttrDomain::Point);
64 set_curve_tilt(curves, field_context, selection, tilt);
65 }
66 if (GreasePencil *grease_pencil = geometry_set.get_grease_pencil_for_write()) {
67 set_grease_pencil_tilt(*grease_pencil, selection, tilt);
68 }
69 });
70
71 params.set_output("Curve", std::move(geometry_set));
72}
73
74static void node_register()
75{
76 static blender::bke::bNodeType ntype;
77
78 geo_node_type_base(&ntype, "GeometryNodeSetCurveTilt", GEO_NODE_SET_CURVE_TILT);
79 ntype.ui_name = "Set Curve Tilt";
80 ntype.ui_description = "Set the tilt angle at each curve control point";
81 ntype.enum_name_legacy = "SET_CURVE_TILT";
84 ntype.declare = node_declare;
86}
88
89} // 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:447
#define GEO_NODE_SET_CURVE_TILT
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_ANGLE
Definition RNA_types.hh:240
MutableAttributeAccessor attributes_for_write()
bke::CurvesGeometry & strokes_for_write()
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
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)
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)
void modify_geometry_sets(ForeachSubGeometryCallback callback)
GreasePencil * get_grease_pencil_for_write()
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:347
const char * enum_name_legacy
Definition BKE_node.hh:235
NodeDeclareFunction declare
Definition BKE_node.hh:355