Blender V4.5
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
11
13{
14 b.use_custom_socket_order();
15 b.allow_any_socket_order();
16 b.add_input<decl::Geometry>("Curve").supported_type(
17 {GeometryComponent::Type::Curve, GeometryComponent::Type::GreasePencil});
18 b.add_output<decl::Geometry>("Curve").propagate_all().align_with_previous();
19 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
20 b.add_input<decl::Float>("Radius")
21 .min(0.0f)
22 .default_value(0.005f)
23 .subtype(PROP_DISTANCE)
24 .field_on_all();
25}
26
27static void set_radius(bke::CurvesGeometry &curves,
28 const fn::FieldContext &field_context,
29 const Field<bool> &selection,
30 const Field<float> &radius)
31{
33 field_context,
34 "radius",
36 selection,
37 radius);
38}
39
41{
42 GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
43 const Field<bool> selection = params.extract_input<Field<bool>>("Selection");
44 const Field<float> radius = params.extract_input<Field<float>>("Radius");
45
46 geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
47 if (Curves *curves_id = geometry_set.get_curves_for_write()) {
48 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
49 const bke::CurvesFieldContext field_context(*curves_id, AttrDomain::Point);
50 set_radius(curves, field_context, selection, radius);
51 }
52 if (GreasePencil *grease_pencil = geometry_set.get_grease_pencil_for_write()) {
53 using namespace blender::bke::greasepencil;
54 for (const int layer_index : grease_pencil->layers().index_range()) {
55 Drawing *drawing = grease_pencil->get_eval_drawing(grease_pencil->layer(layer_index));
56 if (drawing == nullptr) {
57 continue;
58 }
60 drawing->strokes_for_write(),
61 bke::GreasePencilLayerFieldContext(*grease_pencil, AttrDomain::Point, layer_index),
62 selection,
63 radius);
64 }
65 }
66 });
67
68 params.set_output("Curve", std::move(geometry_set));
69}
70
71static void node_register()
72{
73 static blender::bke::bNodeType ntype;
74
75 geo_node_type_base(&ntype, "GeometryNodeSetCurveRadius", GEO_NODE_SET_CURVE_RADIUS);
76 ntype.ui_name = "Set Curve Radius";
77 ntype.ui_description = "Set the radius of the curve at each control point";
78 ntype.enum_name_legacy = "SET_CURVE_RADIUS";
81 ntype.declare = node_declare;
83}
85
86} // 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:447
#define GEO_NODE_SET_CURVE_RADIUS
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_DISTANCE
Definition RNA_types.hh:244
MutableAttributeAccessor attributes_for_write()
bke::CurvesGeometry & strokes_for_write()
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
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)
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
void modify_geometry_sets(ForeachSubGeometryCallback callback)
GreasePencil * get_grease_pencil_for_write()
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
const char * enum_name_legacy
Definition BKE_node.hh:235
NodeDeclareFunction declare
Definition BKE_node.hh:355