Blender V4.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
11
13{
14 b.add_input<decl::Geometry>("Curve").supported_type(
16 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
17 b.add_input<decl::Float>("Tilt").subtype(PROP_ANGLE).field_on_all();
18 b.add_output<decl::Geometry>("Curve").propagate_all();
19}
20
22 const fn::FieldContext &field_context,
23 const Field<bool> &selection,
24 const Field<float> &tilt)
25{
26 bke::try_capture_field_on_geometry(curves.attributes_for_write(),
27 field_context,
28 "tilt",
30 selection,
31 tilt);
32}
33
34static void set_grease_pencil_tilt(GreasePencil &grease_pencil,
35 const Field<bool> &selection,
36 const Field<float> &tilt)
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::Point, layer_index),
47 selection,
48 tilt);
49 }
50}
51
53{
54 GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
55 const Field<bool> selection = params.extract_input<Field<bool>>("Selection");
56 const Field<float> tilt = params.extract_input<Field<float>>("Tilt");
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::Point);
62 set_curve_tilt(curves, field_context, selection, tilt);
63 }
64 if (GreasePencil *grease_pencil = geometry_set.get_grease_pencil_for_write()) {
65 set_grease_pencil_tilt(*grease_pencil, selection, tilt);
66 }
67 });
68
69 params.set_output("Curve", 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_CURVE_TILT, "Set Curve Tilt", NODE_CLASS_GEOMETRY);
78 ntype.declare = node_declare;
80}
82
83} // 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:418
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_ANGLE
Definition RNA_types.hh:155
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_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, 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