Blender V5.0
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")
29 .supported_type(GeometryComponent::Type::Curve)
30 .description("Curves to change the type of");
31 b.add_output<decl::Geometry>("Curve").propagate_all().align_with_previous();
32 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
33}
34
35static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
36{
37 layout->prop(ptr, "spline_type", UI_ITEM_NONE, "", ICON_NONE);
38}
39
40static void node_init(bNodeTree * /*tree*/, bNode *node)
41{
43
44 data->spline_type = CURVE_TYPE_POLY;
45 node->storage = data;
46}
47
49{
50 const NodeGeometryCurveSplineType &storage = node_storage(params.node());
51 const CurveType dst_type = CurveType(storage.spline_type);
52
53 GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
54 Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
55
56 geometry::foreach_real_geometry(geometry_set, [&](GeometrySet &geometry_set) {
57 if (!geometry_set.has_curves()) {
58 return;
59 }
60 const Curves &src_curves_id = *geometry_set.get_curves();
61 const bke::CurvesGeometry &src_curves = src_curves_id.geometry.wrap();
62 if (src_curves.is_single_type(dst_type)) {
63 return;
64 }
65
66 const bke::CurvesFieldContext field_context{src_curves_id, AttrDomain::Curve};
67 fn::FieldEvaluator evaluator{field_context, src_curves.curves_num()};
68 evaluator.set_selection(selection_field);
69 evaluator.evaluate();
70 const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
71 if (selection.is_empty()) {
72 return;
73 }
74
76 src_curves, selection, dst_type, params.get_attribute_filter("Curve"));
77 Curves *dst_curves_id = bke::curves_new_nomain(std::move(dst_curves));
78 bke::curves_copy_parameters(src_curves_id, *dst_curves_id);
79 geometry_set.replace_curves(dst_curves_id);
80 });
81
82 params.set_output("Curve", std::move(geometry_set));
83}
84
85static void node_rna(StructRNA *srna)
86{
88 "spline_type",
89 "Type",
90 "The curve type to change the selected curves to",
92 NOD_storage_enum_accessors(spline_type),
94 nullptr,
95 true);
96}
97
98static void node_register()
99{
100 static blender::bke::bNodeType ntype;
101 geo_node_type_base(&ntype, "GeometryNodeCurveSplineType", GEO_NODE_CURVE_SPLINE_TYPE);
102 ntype.ui_name = "Set Spline Type";
103 ntype.ui_description = "Change the type of curves";
104 ntype.enum_name_legacy = "CURVE_SPLINE_TYPE";
106 ntype.declare = node_declare;
108 ntype.initfunc = node_init;
110 "NodeGeometryCurveSplineType",
114
116
117 node_rna(ntype.rna_ext.srna);
118}
120
121} // namespace blender::nodes::node_geo_curve_spline_type_cc
Low-level operations for curves.
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1240
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#define GEO_NODE_CURVE_SPLINE_TYPE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
#define UI_ITEM_NONE
BMesh const char void * data
bool is_single_type(CurveType type) const
void set_selection(Field< bool > selection)
Definition FN_field.hh:383
IndexMask get_evaluated_selection_as_mask() const
Definition field.cc:817
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:2416
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:5414
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(uiLayout *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)
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
const EnumPropertyItem rna_enum_curves_type_items[]
Definition rna_curves.cc:24
CurvesGeometry geometry
StructRNA * srna
void * storage
const Curves * get_curves() const
void replace_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeDeclareFunction declare
Definition BKE_node.hh:362
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)
PointerRNA * ptr
Definition wm_files.cc:4238