Blender V4.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
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 uiItemR(layout, ptr, "spline_type", UI_ITEM_NONE, "", ICON_NONE);
32}
33
34static void node_init(bNodeTree * /*tree*/, bNode *node)
35{
36 NodeGeometryCurveSplineType *data = MEM_cnew<NodeGeometryCurveSplineType>(__func__);
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, GEO_NODE_CURVE_SPLINE_TYPE, "Set Spline Type", NODE_CLASS_GEOMETRY);
96 ntype.declare = node_declare;
98 ntype.initfunc = node_init;
100 "NodeGeometryCurveSplineType",
104
106
107 node_rna(ntype.rna_ext.srna);
108}
110
111} // namespace blender::nodes::node_geo_curve_spline_type_cc
Low-level operations for curves.
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1799
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
CurveType
@ CURVE_TYPE_POLY
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
#define UI_ITEM_NONE
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
bool is_single_type(CurveType type) const
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void curves_copy_parameters(const Curves &src, Curves &dst)
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
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, int type, const char *name, short nclass)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:46
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:58
const EnumPropertyItem rna_enum_curves_type_items[]
Definition rna_curves.cc:22
CurvesGeometry geometry
StructRNA * srna
Definition RNA_types.hh:780
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:218
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126