Blender  V3.3
node_geo_curve_spline_type.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "BKE_curves.hh"
4 
5 #include "UI_interface.h"
6 #include "UI_resources.h"
7 
8 #include "GEO_set_curve_type.hh"
9 
10 #include "node_geometry_util.hh"
11 
13 
15 
17 {
18  b.add_input<decl::Geometry>(N_("Curve")).supported_type(GEO_COMPONENT_TYPE_CURVE);
19  b.add_input<decl::Bool>(N_("Selection")).default_value(true).hide_value().supports_field();
20  b.add_output<decl::Geometry>(N_("Curve"));
21 }
22 
23 static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
24 {
25  uiItemR(layout, ptr, "spline_type", 0, "", ICON_NONE);
26 }
27 
29 {
30  NodeGeometryCurveSplineType *data = MEM_cnew<NodeGeometryCurveSplineType>(__func__);
31 
32  data->spline_type = CURVE_TYPE_POLY;
33  node->storage = data;
34 }
35 
37 {
38  const NodeGeometryCurveSplineType &storage = node_storage(params.node());
39  const CurveType dst_type = CurveType(storage.spline_type);
40 
41  GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
42  Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
43 
44  geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
45  if (!geometry_set.has_curves()) {
46  return;
47  }
48  const CurveComponent &src_component = *geometry_set.get_component_for_read<CurveComponent>();
49  const Curves &src_curves_id = *src_component.get_for_read();
50  const bke::CurvesGeometry &src_curves = bke::CurvesGeometry::wrap(src_curves_id.geometry);
51  if (src_curves.is_single_type(dst_type)) {
52  return;
53  }
54 
55  GeometryComponentFieldContext field_context{src_component, ATTR_DOMAIN_CURVE};
56  fn::FieldEvaluator evaluator{field_context, src_curves.curves_num()};
57  evaluator.set_selection(selection_field);
58  evaluator.evaluate();
59  const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
60  if (selection.is_empty()) {
61  return;
62  }
63 
65  selection, dst_type, [&]() -> bke::CurvesGeometry & {
67  })) {
68  return;
69  }
70 
71  bke::CurvesGeometry dst_curves = geometry::convert_curves(src_curves, selection, dst_type);
72 
73  Curves *dst_curves_id = bke::curves_new_nomain(std::move(dst_curves));
74  bke::curves_copy_parameters(src_curves_id, *dst_curves_id);
75  geometry_set.replace_curves(dst_curves_id);
76  });
77 
78  params.set_output("Curve", std::move(geometry_set));
79 }
80 
81 } // namespace blender::nodes::node_geo_curve_spline_type_cc
82 
84 {
86 
87  static bNodeType ntype;
92  node_type_storage(&ntype,
93  "NodeGeometryCurveSplineType",
97 
98  nodeRegisterType(&ntype);
99 }
@ ATTR_DOMAIN_CURVE
Definition: BKE_attribute.h:31
Low-level operations for curves.
@ GEO_COMPONENT_TYPE_CURVE
#define NODE_STORAGE_FUNCS(StorageT)
Definition: BKE_node.h:1563
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
#define NODE_CLASS_GEOMETRY
Definition: BKE_node.h:359
#define GEO_NODE_CURVE_SPLINE_TYPE
Definition: BKE_node.h:1441
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
Definition: node.cc:4426
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define UNUSED(x)
CurveType
@ CURVE_TYPE_POLY
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
const Curves * get_for_read() const
bool is_empty() const
static CurvesGeometry & wrap(::CurvesGeometry &dna_struct)
Definition: BKE_curves.hh:138
bool is_single_type(CurveType type) const
Definition: BKE_curves.hh:800
OperationNode * node
void * tree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void curves_copy_parameters(const Curves &src, Curves &dst)
Definition: curves.cc:391
Curves * curves_new_nomain(int points_num, int curves_num)
Definition: curves.cc:367
bke::CurvesGeometry convert_curves(const bke::CurvesGeometry &src_curves, IndexMask selection, CurveType dst_type)
bool try_curves_conversion_in_place(IndexMask selection, CurveType dst_type, FunctionRef< bke::CurvesGeometry &()> get_writable_curves_fn)
static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static void node_init(const struct bContext *C, bNodeTree *ntree, bNode *node)
Definition: node.cc:1082
void register_node_type_geo_curve_spline_type()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:55
void node_free_standard_storage(bNode *node)
Definition: node_util.c:43
CurvesGeometry geometry
Curves * get_curves_for_write()
void replace_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const GeometryComponent * get_component_for_read(GeometryComponentType component_type) const
void modify_geometry_sets(ForeachSubGeometryCallback callback)
bool has_curves() const
Defines a node type.
Definition: BKE_node.h:226
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:316
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:244
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480