Blender V5.3
node_geo_set_curve_radius.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
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>("Curve"_ustr)
20 .description("Curves to set the radius on");
21 b.add_output<decl::Geometry>("Curve"_ustr).propagate_all_geometry().align_with_previous();
22 b.add_input<decl::Bool>("Selection"_ustr)
23 .default_value(true)
24 .hide_value()
25 .evaluated_geometry_field();
26 b.add_input<decl::Float>("Radius"_ustr)
27 .min(0.0f)
28 .default_value(0.005f)
29 .subtype(PROP_DISTANCE)
30 .evaluated_geometry_field();
31}
32
34 const fn::FieldContext &field_context,
35 const Field<bool> &selection,
36 const Field<float> &radius)
37{
38 bke::try_capture_field_on_geometry(curves.attributes_for_write(),
39 field_context,
40 "radius",
42 selection,
43 radius);
44}
45
47{
48 GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve"_ustr);
49 const Field<bool> selection = params.extract_input<Field<bool>>("Selection"_ustr);
50 const Field<float> radius = params.extract_input<Field<float>>("Radius"_ustr);
51
52 geometry::foreach_real_geometry(geometry_set, [&](GeometrySet &geometry_set) {
53 if (Curves *curves_id = geometry_set.get_curves_for_write()) {
54 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
55 const bke::CurvesFieldContext field_context(*curves_id, AttrDomain::Point);
56 set_radius(curves, field_context, selection, radius);
57 }
59 using namespace blender::bke::greasepencil;
60 for (const int layer_index : grease_pencil->layers().index_range()) {
61 Drawing *drawing = grease_pencil->get_eval_drawing(grease_pencil->layer(layer_index));
62 if (drawing == nullptr) {
63 continue;
64 }
66 drawing->strokes_for_write(),
68 selection,
69 radius);
70 }
71 }
72 });
73
74 params.set_output("Curve"_ustr, std::move(geometry_set));
75}
76
77static void node_register()
78{
79 static bke::bNodeType ntype;
80
81 geo_node_type_base(&ntype, "GeometryNodeSetCurveRadius"_ustr, GEO_NODE_SET_CURVE_RADIUS);
82 ntype.ui_name = "Set Curve Radius";
83 ntype.ui_description = "Set the radius of the curve at each control point";
84 ntype.enum_name_legacy = "SET_CURVE_RADIUS";
87 ntype.declare = node_declare;
89}
91
92} // namespace blender::nodes::node_geo_set_curve_radius_cc
Low-level operations for curves.
Low-level operations for grease pencil.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define GEO_NODE_SET_CURVE_RADIUS
#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_field_on_geometry(MutableAttributeAccessor attributes, const fn::FieldContext &field_context, const StringRef name, AttrDomain domain, const fn::Field< bool > &selection, const fn::GField &field)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void foreach_real_geometry(bke::GeometrySet &geometry, FunctionRef< void(bke::GeometrySet &geometry_set)> fn)
static void node_declare(NodeDeclarationBuilder &b)
static void set_radius(bke::CurvesGeometry &curves, const fn::FieldContext &field_context, const Field< bool > &selection, const Field< float > &radius)
static void node_geo_exec(GeoNodeExecParams params)
@ PROP_DISTANCE
Definition RNA_types.hh:313
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
#define min(a, b)
Definition sort.cc:38
GreasePencil * get_grease_pencil_for_write()
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
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393