Blender V5.3
node_geo_curve_handle_type_selection.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
8#include "UI_resources.hh"
9
10#include "node_geometry_util.hh"
11
13
15
17{
18 b.add_output<decl::Bool>("Selection"_ustr).structure_type(StructureType::Field);
19}
20
21static void node_layout(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
22{
23 layout.prop(ptr, "mode", ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
24 layout.prop(ptr, "handle_type", UI_ITEM_NONE, "", ICON_NONE);
25}
26
27static void node_init(bNodeTree * /*tree*/, bNode *node)
28{
29 NodeGeometryCurveSelectHandles *data = MEM_new<NodeGeometryCurveSelectHandles>(__func__);
30
31 data->handle_type = GEO_NODE_CURVE_HANDLE_AUTO;
33 node->storage = data;
34}
35
51
53 const HandleType type,
55 const MutableSpan<bool> r_selection)
56{
57 const OffsetIndices points_by_curve = curves.points_by_curve();
58 VArray<int8_t> curve_types = curves.curve_types();
59 VArray<int8_t> left = curves.handle_types_left();
60 VArray<int8_t> right = curves.handle_types_right();
61
62 for (const int i_curve : curves.curves_range()) {
63 const IndexRange points = points_by_curve[i_curve];
64 if (curve_types[i_curve] != CURVE_TYPE_BEZIER) {
65 r_selection.slice(points).fill(false);
66 }
67 else {
68 for (const int i_point : points) {
69 r_selection[i_point] = (mode & GEO_NODE_CURVE_HANDLE_LEFT && left[i_point] == type) ||
70 (mode & GEO_NODE_CURVE_HANDLE_RIGHT && right[i_point] == type);
71 }
72 }
73 }
74}
75
77 HandleType type_;
79
80 public:
82 : bke::CurvesFieldInput(CPPType::get<bool>(), "Handle Type Selection node"),
83 type_(type),
84 mode_(mode)
85 {
86 }
87
89 const AttrDomain domain,
90 const IndexMask &mask) const final
91 {
92 if (domain != AttrDomain::Point) {
93 return {};
94 }
95 Array<bool> selection(mask.min_array_size());
96 select_by_handle_type(curves, type_, mode_, selection);
97 return VArray<bool>::from_container(std::move(selection));
98 }
99
100 void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep & /*deep_hash_cache*/) const override
101 {
102 static constexpr int8_t id = 0;
103 hash.add(&id);
104 hash.add(type_);
105 hash.add(mode_);
106 }
107
108 std::optional<AttrDomain> preferred_domain(const bke::CurvesGeometry & /*curves*/) const final
109 {
110 return AttrDomain::Point;
111 }
112};
113
115{
116 const NodeGeometryCurveSelectHandles &storage = node_storage(params.node());
117 const HandleType handle_type = handle_type_from_input_type(
120
121 Field<bool> selection_field = Field<bool>::from_input<HandleTypeFieldInput>(handle_type, mode);
122 params.set_output("Selection"_ustr, std::move(selection_field));
123}
124
125static void node_register()
126{
127 static bke::bNodeType ntype;
128
130 &ntype, "GeometryNodeCurveHandleTypeSelection"_ustr, GEO_NODE_CURVE_HANDLE_TYPE_SELECTION);
131 ntype.ui_name = "Handle Type Selection";
132 ntype.ui_description = "Provide a selection based on the handle types of Bézier control points";
133 ntype.enum_name_legacy = "CURVE_HANDLE_TYPE_SELECTION";
134 ntype.nclass = NODE_CLASS_INPUT;
135 ntype.declare = node_declare;
137 ntype.initfunc = node_init;
140 "NodeGeometryCurveSelectHandles",
144
146}
148
149} // namespace blender::nodes::node_geo_curve_handle_type_selection_cc
Low-level operations for curves.
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1353
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define GEO_NODE_CURVE_HANDLE_TYPE_SELECTION
#define final(a, b, c)
Definition BLI_hash_c.hh:21
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define UI_ITEM_NONE
#define BLI_assert_unreachable()
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
Definition BLI_span.hh:579
constexpr void fill(const T &value) const
Definition BLI_span.hh:523
static VArray from_container(ContainerT container)
uint64_t hash() const
Definition field.cc:185
static Field from_input(Args &&...args)
void set_output(const UString identifier, T &&value)
std::optional< AttrDomain > preferred_domain(const bke::CurvesGeometry &) const final
GVArray get_varray_for_context(const bke::CurvesGeometry &curves, const AttrDomain domain, const IndexMask &mask) const final
#define storage(slot, qualifiers)
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
static HandleType handle_type_from_input_type(const GeometryNodeCurveHandleType type)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void select_by_handle_type(const bke::CurvesGeometry &curves, const HandleType type, const GeometryNodeCurveHandleMode mode, const MutableSpan< bool > r_selection)
GeometryNodeCurveHandleType
@ GEO_NODE_CURVE_HANDLE_FREE
@ GEO_NODE_CURVE_HANDLE_AUTO
@ GEO_NODE_CURVE_HANDLE_VECTOR
@ GEO_NODE_CURVE_HANDLE_ALIGN
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)
signed char int8_t
Definition BKE_text.h:76
GeometryNodeCurveHandleMode
@ GEO_NODE_CURVE_HANDLE_LEFT
@ GEO_NODE_CURVE_HANDLE_RIGHT
static constexpr int _160
Definition BKE_node.hh:246
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)