Blender V5.3
node_geo_set_grease_pencil_softness.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 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>("Grease Pencil"_ustr)
20 .align_with_previous()
21 .description("Grease Pencil to set the softness of");
22 b.add_output<decl::Geometry>("Grease Pencil"_ustr)
23 .propagate_all_geometry()
24 .align_with_previous();
25 b.add_input<decl::Bool>("Selection"_ustr)
26 .default_value(true)
27 .hide_value()
28 .evaluated_geometry_field();
29 b.add_input<decl::Float>("Softness"_ustr)
30 .default_value(0.0f)
31 .min(0.0f)
32 .max(1.0f)
33 .evaluated_geometry_field();
34}
35
37{
38 GeometrySet geometry_set = params.extract_input<GeometrySet>("Grease Pencil"_ustr);
39 const Field<bool> selection = params.extract_input<Field<bool>>("Selection"_ustr);
40 const Field<float> softness = params.extract_input<Field<float>>("Softness"_ustr);
41
43 if (GreasePencil *grease_pencil = geometry.get_grease_pencil_for_write()) {
44 using namespace bke::greasepencil;
45 for (const int layer_index : grease_pencil->layers().index_range()) {
46 Drawing *drawing = grease_pencil->get_eval_drawing(grease_pencil->layer(layer_index));
47 if (drawing == nullptr) {
48 continue;
49 }
51
52 const bke::GreasePencilLayerFieldContext layer_field_context(
53 *grease_pencil, AttrDomain::Curve, layer_index);
54
55 bke::try_capture_fields_on_geometry(curves.attributes_for_write(),
56 layer_field_context,
57 {"softness"},
58 AttrDomain::Curve,
59 selection,
60 {softness});
61 }
62 }
63 });
64
65 params.set_output("Grease Pencil"_ustr, std::move(geometry_set));
66}
67
68static void node_register()
69{
70 static bke::bNodeType ntype;
71
72 geo_node_type_base(&ntype, "GeometryNodeSetGreasePencilSoftness"_ustr);
73 ntype.ui_name = "Set Grease Pencil Softness";
74 ntype.ui_description = "Set softness attribute on Grease Pencil geometry";
77 ntype.declare = node_declare;
80}
82
83} // namespace blender::nodes::node_geo_set_grease_pencil_softness_cc
Low-level operations for curves.
Low-level operations for grease pencil.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#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_fields_on_geometry(MutableAttributeAccessor attributes, const fn::FieldContext &field_context, Span< StringRef > names, AttrDomain domain, const fn::Field< bool > &selection, Span< fn::GField > fields)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void foreach_real_geometry(bke::GeometrySet &geometry, FunctionRef< void(bke::GeometrySet &geometry_set)> fn)
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
static constexpr int _180
Definition BKE_node.hh:247
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
NodeDeclareFunction declare
Definition BKE_node.hh:393