Blender V4.5
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
9#include "UI_interface.hh"
10#include "UI_resources.hh"
11
12#include "GEO_set_curve_type.hh"
13
14#include "RNA_enum_types.hh"
15
16#include "node_geometry_util.hh"
17
19
21
23{
24 b.add_input<decl::Geometry>("Curve").supported_type(GeometryComponent::Type::Curve);
25 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
26 b.add_output<decl::Geometry>("Curve").propagate_all();
27}
28
29static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
30{
31 layout->prop(ptr, "spline_type", UI_ITEM_NONE, "", ICON_NONE);
32}
33
34static void node_init(bNodeTree * /*tree*/, bNode *node)
35{
37
38 data->spline_type = CURVE_TYPE_POLY;
39 node->storage = data;
40}
41
43{
44 const NodeGeometryCurveSplineType &storage = node_storage(params.node());
45 const CurveType dst_type = CurveType(storage.spline_type);
46
47 GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
48 Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
49
50 geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
51 if (!geometry_set.has_curves()) {
52 return;
53 }
54 const Curves &src_curves_id = *geometry_set.get_curves();
55 const bke::CurvesGeometry &src_curves = src_curves_id.geometry.wrap();
56 if (src_curves.is_single_type(dst_type)) {
57 return;
58 }
59
60 const bke::CurvesFieldContext field_context{src_curves_id, AttrDomain::Curve};
61 fn::FieldEvaluator evaluator{field_context, src_curves.curves_num()};
62 evaluator.set_selection(selection_field);
63 evaluator.evaluate();
64 const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
65 if (selection.is_empty()) {
66 return;
67 }
68
70 src_curves, selection, dst_type, params.get_attribute_filter("Curve"));
71 Curves *dst_curves_id = bke::curves_new_nomain(std::move(dst_curves));
72 bke::curves_copy_parameters(src_curves_id, *dst_curves_id);
73 geometry_set.replace_curves(dst_curves_id);
74 });
75
76 params.set_output("Curve", std::move(geometry_set));
77}
78
79static void node_rna(StructRNA *srna)
80{
82 "spline_type",
83 "Type",
84 "The curve type to change the selected curves to",
86 NOD_storage_enum_accessors(spline_type),
88 nullptr,
89 true);
90}
91
92static void node_register()
93{
94 static blender::bke::bNodeType ntype;
95 geo_node_type_base(&ntype, "GeometryNodeCurveSplineType", GEO_NODE_CURVE_SPLINE_TYPE);
96 ntype.ui_name = "Set Spline Type";
97 ntype.ui_description = "Change the type of curves";
98 ntype.enum_name_legacy = "CURVE_SPLINE_TYPE";
100 ntype.declare = node_declare;
102 ntype.initfunc = node_init;
104 "NodeGeometryCurveSplineType",
108
110
111 node_rna(ntype.rna_ext.srna);
112}
114
115} // namespace blender::nodes::node_geo_curve_spline_type_cc
Low-level operations for curves.
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1215
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:447
#define GEO_NODE_CURVE_SPLINE_TYPE
CurveType
@ CURVE_TYPE_POLY
#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: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 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:22
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)
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)
PointerRNA * ptr
Definition wm_files.cc:4226