Blender V5.0
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")
19 .supported_type(GeometryComponent::Type::GreasePencil)
20 .align_with_previous()
21 .description("Grease Pencil to set the softness of");
22 b.add_output<decl::Geometry>("Grease Pencil").propagate_all().align_with_previous();
23 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
24 b.add_input<decl::Float>("Softness").default_value(0.0f).min(0.0f).max(1.0f).field_on_all();
25}
26
28{
29 GeometrySet geometry_set = params.extract_input<GeometrySet>("Grease Pencil");
30 const Field<bool> selection = params.extract_input<Field<bool>>("Selection");
31 const Field<float> softness = params.extract_input<Field<float>>("Softness");
32
34 if (GreasePencil *grease_pencil = geometry.get_grease_pencil_for_write()) {
35 using namespace bke::greasepencil;
36 for (const int layer_index : grease_pencil->layers().index_range()) {
37 Drawing *drawing = grease_pencil->get_eval_drawing(grease_pencil->layer(layer_index));
38 if (drawing == nullptr) {
39 continue;
40 }
41 bke::CurvesGeometry &curves = drawing->strokes_for_write();
42
43 const bke::GreasePencilLayerFieldContext layer_field_context(
44 *grease_pencil, AttrDomain::Curve, layer_index);
45
47 layer_field_context,
48 {"softness"},
49 AttrDomain::Curve,
50 selection,
51 {softness});
52 }
53 }
54 });
55
56 params.set_output("Grease Pencil", std::move(geometry_set));
57}
58
59static void node_register()
60{
61 static blender::bke::bNodeType ntype;
62
63 geo_node_type_base(&ntype, "GeometryNodeSetGreasePencilSoftness");
64 ntype.ui_name = "Set Grease Pencil Softness";
65 ntype.ui_description = "Set softness attribute on Grease Pencil geometry";
68 ntype.declare = node_declare;
71}
73
74} // 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:461
constexpr int NODE_DEFAULT_MAX_WIDTH
Definition BKE_node.hh:1250
#define NOD_REGISTER_NODE(REGISTER_FUNC)
MutableAttributeAccessor attributes_for_write()
bke::CurvesGeometry & strokes_for_write()
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_type_size(bNodeType &ntype, int width, int minwidth, int maxwidth)
Definition node.cc:5384
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
bool try_capture_fields_on_geometry(MutableAttributeAccessor attributes, const fn::FieldContext &field_context, Span< StringRef > attribute_ids, AttrDomain domain, const fn::Field< bool > &selection, Span< fn::GField > fields)
void foreach_real_geometry(bke::GeometrySet &geometry, FunctionRef< void(bke::GeometrySet &geometry_set)> fn)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
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
NodeDeclareFunction declare
Definition BKE_node.hh:362