Blender V4.5
node_geo_curve_fillet.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 "NOD_rna_define.hh"
6
8
10
11#include "UI_interface.hh"
12#include "UI_resources.hh"
13
14#include "GEO_fillet_curves.hh"
15
16#include "node_geometry_util.hh"
17
19
21
23{
24 b.use_custom_socket_order();
25 b.allow_any_socket_order();
26 b.add_default_layout();
27 b.add_input<decl::Geometry>("Curve").supported_type(
28 {GeometryComponent::Type::Curve, GeometryComponent::Type::GreasePencil});
29 b.add_output<decl::Geometry>("Curve").propagate_all().align_with_previous();
30 auto &count_input = b.add_input<decl::Int>("Count")
32 .min(1)
33 .max(1000)
34 .field_on_all()
35 .make_available([](bNode &node) {
36 node_storage(node).mode = GEO_NODE_CURVE_FILLET_POLY;
37 });
38 b.add_input<decl::Float>("Radius")
39 .min(0.0f)
40 .max(FLT_MAX)
42 .default_value(0.25f)
43 .field_on_all();
44 b.add_input<decl::Bool>("Limit Radius")
45 .description("Limit the maximum value of the radius in order to avoid overlapping fillets");
46
47 const bNode *node = b.node_or_null();
48 if (node != nullptr) {
49 const NodeGeometryCurveFillet &storage = node_storage(*node);
50 count_input.available(GeometryNodeCurveFilletMode(storage.mode) == GEO_NODE_CURVE_FILLET_POLY);
51 }
52}
53
54static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
55{
56 layout->prop(ptr, "mode", UI_ITEM_R_EXPAND, std::nullopt, ICON_NONE);
57}
58
59static void node_init(bNodeTree * /*tree*/, bNode *node)
60{
63 node->storage = data;
64}
65
68 const fn::FieldContext &field_context,
69 const std::optional<Field<int>> &count_field,
70 const Field<float> &radius_field,
71 const bool limit_radius,
72 const AttributeFilter &attribute_filter)
73{
74 fn::FieldEvaluator evaluator{field_context, src_curves.points_num()};
75 evaluator.add(radius_field);
76
77 switch (mode) {
79 evaluator.evaluate();
80 return geometry::fillet_curves_bezier(src_curves,
81 src_curves.curves_range(),
82 evaluator.get_evaluated<float>(0),
83 limit_radius,
84 attribute_filter);
85 }
87 evaluator.add(*count_field);
88 evaluator.evaluate();
89 return geometry::fillet_curves_poly(src_curves,
90 src_curves.curves_range(),
91 evaluator.get_evaluated<float>(0),
92 evaluator.get_evaluated<int>(1),
93 limit_radius,
94 attribute_filter);
95 }
96 }
97 return bke::CurvesGeometry();
98}
99
100static void fillet_grease_pencil(GreasePencil &grease_pencil,
102 const std::optional<Field<int>> &count_field,
103 const Field<float> &radius_field,
104 const bool limit_radius,
105 const AttributeFilter &attribute_filter)
106{
107 using namespace blender::bke::greasepencil;
108 for (const int layer_index : grease_pencil.layers().index_range()) {
109 Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
110 if (drawing == nullptr) {
111 continue;
112 }
113 const bke::CurvesGeometry &src_curves = drawing->strokes();
114 if (src_curves.is_empty()) {
115 continue;
116 }
117 const bke::GreasePencilLayerFieldContext field_context(
118 grease_pencil, AttrDomain::Curve, layer_index);
119 bke::CurvesGeometry dst_curves = fillet_curve(src_curves,
120 mode,
121 field_context,
122 count_field,
123 radius_field,
124 limit_radius,
125 attribute_filter);
126 drawing->strokes_for_write() = std::move(dst_curves);
127 drawing->tag_topology_changed();
128 }
129}
130
132{
133 GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
134
135 const NodeGeometryCurveFillet &storage = node_storage(params.node());
137
138 Field<float> radius_field = params.extract_input<Field<float>>("Radius");
139 const bool limit_radius = params.extract_input<bool>("Limit Radius");
140
141 std::optional<Field<int>> count_field;
142 if (mode == GEO_NODE_CURVE_FILLET_POLY) {
143 count_field.emplace(params.extract_input<Field<int>>("Count"));
144 }
145
146 const NodeAttributeFilter &attribute_filter = params.get_attribute_filter("Curve");
147
148 geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
149 if (geometry_set.has_curves()) {
150 const Curves &curves_id = *geometry_set.get_curves();
151 const bke::CurvesGeometry &src_curves = curves_id.geometry.wrap();
152 const bke::CurvesFieldContext field_context{curves_id, AttrDomain::Point};
153 bke::CurvesGeometry dst_curves = fillet_curve(src_curves,
154 mode,
155 field_context,
156 count_field,
157 radius_field,
158 limit_radius,
159 attribute_filter);
160 Curves *dst_curves_id = bke::curves_new_nomain(std::move(dst_curves));
161 bke::curves_copy_parameters(curves_id, *dst_curves_id);
162 geometry_set.replace_curves(dst_curves_id);
163 }
164 if (geometry_set.has_grease_pencil()) {
165 GreasePencil &grease_pencil = *geometry_set.get_grease_pencil_for_write();
167 grease_pencil, mode, count_field, radius_field, limit_radius, attribute_filter);
168 }
169 });
170
171 params.set_output("Curve", std::move(geometry_set));
172}
173
174static void node_rna(StructRNA *srna)
175{
176 static EnumPropertyItem mode_items[] = {
178 "BEZIER",
179 0,
180 "Bézier",
181 "Align Bézier handles to create circular arcs at each control point"},
183 "POLY",
184 0,
185 "Poly",
186 "Add control points along a circular arc (handle type is vector if Bézier Spline)"},
187 {0, nullptr, 0, nullptr, nullptr},
188 };
189
191 "mode",
192 "Mode",
193 "How to choose number of vertices on fillet",
194 mode_items,
197}
198
199static void node_register()
200{
201 static blender::bke::bNodeType ntype;
202
203 geo_node_type_base(&ntype, "GeometryNodeFilletCurve", GEO_NODE_FILLET_CURVE);
204 ntype.ui_name = "Fillet Curve";
205 ntype.ui_description = "Round corners by generating circular arcs on each control point";
206 ntype.enum_name_legacy = "FILLET_CURVE";
210 ntype, "NodeGeometryCurveFillet", node_free_standard_storage, node_copy_standard_storage);
211 ntype.declare = node_declare;
212 ntype.initfunc = node_init;
215
216 node_rna(ntype.rna_ext.srna);
217}
219
220} // namespace blender::nodes::node_geo_curve_fillet_cc
Low-level operations for grease pencil.
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1215
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:447
#define GEO_NODE_FILLET_CURVE
GeometryNodeCurveFilletMode
@ GEO_NODE_CURVE_FILLET_BEZIER
@ GEO_NODE_CURVE_FILLET_POLY
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
@ PROP_DISTANCE
Definition RNA_types.hh:244
@ UI_ITEM_R_EXPAND
BMesh const char void * data
IndexRange curves_range() const
bke::CurvesGeometry & strokes_for_write()
const bke::CurvesGeometry & strokes() const
int add(GField field, GVArray *varray_ptr)
Definition field.cc:751
const GVArray & get_evaluated(const int field_index) const
Definition FN_field.hh:448
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void curves_copy_parameters(const Curves &src, Curves &dst)
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:5603
Curves * curves_new_nomain(int points_num, int curves_num)
bke::CurvesGeometry fillet_curves_bezier(const bke::CurvesGeometry &src_curves, const IndexMask &curve_selection, const VArray< float > &radius, bool limit_radius, const bke::AttributeFilter &attribute_filter)
bke::CurvesGeometry fillet_curves_poly(const bke::CurvesGeometry &src_curves, const IndexMask &curve_selection, const VArray< float > &radius, const VArray< int > &counts, bool limit_radius, const bke::AttributeFilter &attribute_filter)
static void node_init(bNodeTree *, bNode *node)
static bke::CurvesGeometry fillet_curve(const bke::CurvesGeometry &src_curves, const GeometryNodeCurveFilletMode mode, const fn::FieldContext &field_context, const std::optional< Field< int > > &count_field, const Field< float > &radius_field, const bool limit_radius, const AttributeFilter &attribute_filter)
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void fillet_grease_pencil(GreasePencil &grease_pencil, const GeometryNodeCurveFilletMode mode, const std::optional< Field< int > > &count_field, const Field< float > &radius_field, const bool limit_radius, const AttributeFilter &attribute_filter)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:42
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:54
#define min(a, b)
Definition sort.cc:36
#define FLT_MAX
Definition stdcycles.h:14
CurvesGeometry geometry
StructRNA * srna
Definition RNA_types.hh:909
void * storage
const Curves * get_curves() const
void replace_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
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
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:277
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:347
const char * enum_name_legacy
Definition BKE_node.hh:235
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:355
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
max
Definition text_draw.cc:251
PointerRNA * ptr
Definition wm_files.cc:4226