Blender V5.3
node_geo_curve_spline_type.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"
6
7#include "NOD_rna_define.hh"
8
10#include "UI_resources.hh"
11
13#include "GEO_set_curve_type.hh"
14
15#include "RNA_enum_types.hh"
16
17#include "node_geometry_util.hh"
18
20
22
24{
25 b.use_custom_socket_order();
26 b.allow_any_socket_order();
27 b.add_default_layout();
28 b.add_input<decl::Geometry>("Curve"_ustr)
29 .supported_type(GeometryComponent::Type::Curve)
30 .description("Curves to change the type of");
31 b.add_output<decl::Geometry>("Curve"_ustr).propagate_all_geometry().align_with_previous();
32 b.add_input<decl::Bool>("Selection"_ustr)
33 .default_value(true)
34 .hide_value()
35 .evaluated_geometry_field();
36}
37
38static void node_layout(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
39{
40 layout.prop(ptr, "spline_type", UI_ITEM_NONE, "", ICON_NONE);
41}
42
43static void node_init(bNodeTree * /*tree*/, bNode *node)
44{
45 NodeGeometryCurveSplineType *data = MEM_new<NodeGeometryCurveSplineType>(__func__);
46
47 data->spline_type = CURVE_TYPE_POLY;
48 node->storage = data;
49}
50
52{
53 const NodeGeometryCurveSplineType &storage = node_storage(params.node());
54 const CurveType dst_type = CurveType(storage.spline_type);
55
56 GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve"_ustr);
57 Field<bool> selection_field = params.extract_input<Field<bool>>("Selection"_ustr);
58
59 geometry::foreach_real_geometry(geometry_set, [&](GeometrySet &geometry_set) {
60 if (!geometry_set.has_curves()) {
61 return;
62 }
63 const Curves &src_curves_id = *geometry_set.get_curves();
64 const bke::CurvesGeometry &src_curves = src_curves_id.geometry.wrap();
65 if (src_curves.is_single_type(dst_type)) {
66 return;
67 }
68
69 const bke::CurvesFieldContext field_context{src_curves_id, AttrDomain::Curve};
70 fn::FieldEvaluator evaluator{field_context, src_curves.curves_num()};
71 evaluator.set_selection(selection_field);
72 evaluator.evaluate();
73 const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
74 if (selection.is_empty()) {
75 return;
76 }
77
79 src_curves, selection, dst_type, params.get_attribute_filter("Curve"_ustr));
80 Curves *dst_curves_id = bke::curves_new_nomain(std::move(dst_curves));
81 bke::curves_copy_parameters(src_curves_id, *dst_curves_id);
82 geometry_set.replace_curves(dst_curves_id);
83 });
84
85 params.set_output("Curve"_ustr, std::move(geometry_set));
86}
87
88static void node_rna(StructRNA *srna)
89{
91 "spline_type",
92 "Type",
93 "The curve type to change the selected curves to",
95 NOD_storage_enum_accessors(spline_type),
97 nullptr,
98 true);
99}
100
101static void node_register()
102{
103 static bke::bNodeType ntype;
104 geo_node_type_base(&ntype, "GeometryNodeCurveSplineType"_ustr, GEO_NODE_CURVE_SPLINE_TYPE);
105 ntype.ui_name = "Set Spline Type";
106 ntype.ui_description = "Change the type of curves";
107 ntype.enum_name_legacy = "CURVE_SPLINE_TYPE";
109 ntype.declare = node_declare;
111 ntype.initfunc = node_init;
113 "NodeGeometryCurveSplineType",
117
119
120 node_rna(ntype.rna_ext.srna);
121}
123
124} // namespace blender::nodes::node_geo_curve_spline_type_cc
Low-level operations for curves.
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1353
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define GEO_NODE_CURVE_SPLINE_TYPE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
#define UI_ITEM_NONE
bool is_single_type(CurveType type) const
void set_selection(Field< bool > selection)
IndexMask get_evaluated_selection_as_mask() const
NodeAttributeFilter get_attribute_filter(const UString output_identifier) const
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
#define storage(slot, qualifiers)
void curves_copy_parameters(const Curves &src, Curves &dst)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
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:6166
Curves * curves_new_nomain(int points_num, int curves_num)
void foreach_real_geometry(bke::GeometrySet &geometry, FunctionRef< void(bke::GeometrySet &geometry_set)> fn)
bke::CurvesGeometry convert_curves(const bke::CurvesGeometry &src_curves, const IndexMask &selection, CurveType dst_type, const bke::AttributeFilter &attribute_filter, const ConvertCurvesOptions &options={})
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
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)
const EnumPropertyItem rna_enum_curves_type_items[]
Definition rna_curves.cc:26
BMesh const char void * data
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
const Curves * get_curves() const
void replace_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Defines a node type.
Definition BKE_node.hh:265
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)