Blender V5.0
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").field_source();
19}
20
21static void node_layout(uiLayout *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
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();
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 {
87 }
88
90 const AttrDomain domain,
91 const IndexMask &mask) const final
92 {
93 if (domain != AttrDomain::Point) {
94 return {};
95 }
96 Array<bool> selection(mask.min_array_size());
97 select_by_handle_type(curves, type_, mode_, selection);
98 return VArray<bool>::from_container(std::move(selection));
99 }
100
102 {
103 return get_default_hash(int(mode_), int(type_));
104 }
105
106 bool is_equal_to(const fn::FieldNode &other) const final
107 {
108 if (const HandleTypeFieldInput *other_handle_selection =
109 dynamic_cast<const HandleTypeFieldInput *>(&other))
110 {
111 return mode_ == other_handle_selection->mode_ && type_ == other_handle_selection->type_;
112 }
113 return false;
114 }
115
116 std::optional<AttrDomain> preferred_domain(const bke::CurvesGeometry & /*curves*/) const final
117 {
118 return AttrDomain::Point;
119 }
120};
121
123{
124 const NodeGeometryCurveSelectHandles &storage = node_storage(params.node());
125 const HandleType handle_type = handle_type_from_input_type(
128
129 Field<bool> selection_field{std::make_shared<HandleTypeFieldInput>(handle_type, mode)};
130 params.set_output("Selection", std::move(selection_field));
131}
132
133static void node_register()
134{
135 static blender::bke::bNodeType ntype;
136
138 &ntype, "GeometryNodeCurveHandleTypeSelection", GEO_NODE_CURVE_HANDLE_TYPE_SELECTION);
139 ntype.ui_name = "Handle Type Selection";
140 ntype.ui_description = "Provide a selection based on the handle types of Bézier control points";
141 ntype.enum_name_legacy = "CURVE_HANDLE_TYPE_SELECTION";
142 ntype.nclass = NODE_CLASS_INPUT;
143 ntype.declare = node_declare;
145 ntype.initfunc = node_init;
147 "NodeGeometryCurveSelectHandles",
151
153}
155
156} // namespace blender::nodes::node_geo_curve_handle_type_selection_cc
Low-level operations for curves.
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1240
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define GEO_NODE_CURVE_HANDLE_TYPE_SELECTION
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
#define final(a, b, c)
Definition BLI_hash.h:19
HandleType
@ BEZIER_HANDLE_FREE
@ BEZIER_HANDLE_ALIGN
@ BEZIER_HANDLE_VECTOR
@ BEZIER_HANDLE_AUTO
GeometryNodeCurveHandleMode
@ GEO_NODE_CURVE_HANDLE_RIGHT
@ GEO_NODE_CURVE_HANDLE_LEFT
GeometryNodeCurveHandleType
@ GEO_NODE_CURVE_HANDLE_ALIGN
@ GEO_NODE_CURVE_HANDLE_AUTO
@ GEO_NODE_CURVE_HANDLE_FREE
@ GEO_NODE_CURVE_HANDLE_VECTOR
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ UI_ITEM_R_EXPAND
#define UI_ITEM_NONE
BMesh const char void * data
unsigned long long int uint64_t
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
Definition BLI_span.hh:573
constexpr void fill(const T &value) const
Definition BLI_span.hh:517
static VArray from_container(ContainerT container)
VArray< int8_t > handle_types_left() const
OffsetIndices< int > points_by_curve() const
VArray< int8_t > handle_types_right() const
IndexRange curves_range() const
VArray< int8_t > curve_types() const
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
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
static int left
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
static HandleType handle_type_from_input_type(const GeometryNodeCurveHandleType type)
static void node_layout(uiLayout *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)
uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:233
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
void * storage
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