Blender V5.0
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")
19 .supported_type({GeometryComponent::Type::Curve, GeometryComponent::Type::GreasePencil})
20 .description("Curves to set the radius on");
21 b.add_output<decl::Geometry>("Curve").propagate_all().align_with_previous();
22 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
23 b.add_input<decl::Float>("Radius")
24 .min(0.0f)
25 .default_value(0.005f)
26 .subtype(PROP_DISTANCE)
27 .field_on_all();
28}
29
30static void set_radius(bke::CurvesGeometry &curves,
31 const fn::FieldContext &field_context,
32 const Field<bool> &selection,
33 const Field<float> &radius)
34{
36 field_context,
37 "radius",
39 selection,
40 radius);
41}
42
44{
45 GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
46 const Field<bool> selection = params.extract_input<Field<bool>>("Selection");
47 const Field<float> radius = params.extract_input<Field<float>>("Radius");
48
49 geometry::foreach_real_geometry(geometry_set, [&](GeometrySet &geometry_set) {
50 if (Curves *curves_id = geometry_set.get_curves_for_write()) {
51 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
52 const bke::CurvesFieldContext field_context(*curves_id, AttrDomain::Point);
53 set_radius(curves, field_context, selection, radius);
54 }
55 if (GreasePencil *grease_pencil = geometry_set.get_grease_pencil_for_write()) {
56 using namespace blender::bke::greasepencil;
57 for (const int layer_index : grease_pencil->layers().index_range()) {
58 Drawing *drawing = grease_pencil->get_eval_drawing(grease_pencil->layer(layer_index));
59 if (drawing == nullptr) {
60 continue;
61 }
63 drawing->strokes_for_write(),
64 bke::GreasePencilLayerFieldContext(*grease_pencil, AttrDomain::Point, layer_index),
65 selection,
66 radius);
67 }
68 }
69 });
70
71 params.set_output("Curve", std::move(geometry_set));
72}
73
74static void node_register()
75{
76 static blender::bke::bNodeType ntype;
77
78 geo_node_type_base(&ntype, "GeometryNodeSetCurveRadius", GEO_NODE_SET_CURVE_RADIUS);
79 ntype.ui_name = "Set Curve Radius";
80 ntype.ui_description = "Set the radius of the curve at each control point";
81 ntype.enum_name_legacy = "SET_CURVE_RADIUS";
84 ntype.declare = node_declare;
86}
88
89} // 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:461
#define GEO_NODE_SET_CURVE_RADIUS
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_DISTANCE
Definition RNA_types.hh:256
MutableAttributeAccessor attributes_for_write()
bke::CurvesGeometry & strokes_for_write()
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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 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)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
#define min(a, b)
Definition sort.cc:36
GreasePencil * get_grease_pencil_for_write()
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
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362