Blender V4.5
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
11
13{
14 b.use_custom_socket_order();
15 b.allow_any_socket_order();
16 b.add_input<decl::Geometry>("Grease Pencil")
17 .supported_type(GeometryComponent::Type::GreasePencil)
18 .align_with_previous();
19 b.add_output<decl::Geometry>("Grease Pencil").propagate_all().align_with_previous();
20 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
21 b.add_input<decl::Float>("Softness").default_value(0.0f).min(0.0f).max(1.0f).field_on_all();
22}
23
25{
26 GeometrySet geometry_set = params.extract_input<GeometrySet>("Grease Pencil");
27 const Field<bool> selection = params.extract_input<Field<bool>>("Selection");
28 const Field<float> softness = params.extract_input<Field<float>>("Softness");
29
30 geometry_set.modify_geometry_sets([&](GeometrySet &geometry) {
31 if (GreasePencil *grease_pencil = geometry.get_grease_pencil_for_write()) {
32 using namespace bke::greasepencil;
33 for (const int layer_index : grease_pencil->layers().index_range()) {
34 Drawing *drawing = grease_pencil->get_eval_drawing(grease_pencil->layer(layer_index));
35 if (drawing == nullptr) {
36 continue;
37 }
38 bke::CurvesGeometry &curves = drawing->strokes_for_write();
39
40 const bke::GreasePencilLayerFieldContext layer_field_context(
41 *grease_pencil, AttrDomain::Curve, layer_index);
42
44 layer_field_context,
45 {"softness"},
46 AttrDomain::Curve,
47 selection,
48 {softness});
49 }
50 }
51 });
52
53 params.set_output("Grease Pencil", std::move(geometry_set));
54}
55
56static void node_register()
57{
58 static blender::bke::bNodeType ntype;
59
60 geo_node_type_base(&ntype, "GeometryNodeSetGreasePencilSoftness");
61 ntype.ui_name = "Set Grease Pencil Softness";
62 ntype.ui_description = "Set softness attribute on Grease Pencil geometry";
65 ntype.declare = node_declare;
68}
70
71} // 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:447
constexpr int NODE_DEFAULT_MAX_WIDTH
Definition BKE_node.hh:1225
#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:5573
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
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 geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void modify_geometry_sets(ForeachSubGeometryCallback callback)
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
NodeDeclareFunction declare
Definition BKE_node.hh:355