Blender V4.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
7#include "UI_interface.hh"
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 uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
24 uiItemR(layout, ptr, "handle_type", UI_ITEM_NONE, "", ICON_NONE);
25}
26
27static void node_init(bNodeTree * /*tree*/, bNode *node)
28{
29 NodeGeometryCurveSelectHandles *data = MEM_cnew<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 {
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>::ForContainer(std::move(selection));
99 }
100
101 uint64_t hash() const final
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, GEO_NODE_CURVE_HANDLE_TYPE_SELECTION, "Handle Type Selection", NODE_CLASS_INPUT);
139 ntype.declare = node_declare;
141 ntype.initfunc = node_init;
143 "NodeGeometryCurveSelectHandles",
147
149}
151
152} // namespace blender::nodes::node_geo_curve_handle_type_selection_cc
Low-level operations for curves.
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1799
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
@ CURVE_TYPE_BEZIER
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)
#define UI_ITEM_NONE
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_EXPAND
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
Definition BLI_span.hh:574
constexpr void fill(const T &value) const
Definition BLI_span.hh:518
static VArray ForContainer(ContainerT container)
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
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
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
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)
Definition BLI_hash.hh:219
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
GPU_SHADER_INTERFACE_INFO(overlay_edit_curve_handle_iface, "vert").flat(Type pos vertex_in(1, Type::UINT, "data") .vertex_out(overlay_edit_curve_handle_iface) .geometry_layout(PrimitiveIn Frequency::GEOMETRY storage_buf(1, Qualifier::READ, "uint", "data[]", Frequency::GEOMETRY) .push_constant(Type Frequency::GEOMETRY selection[]
unsigned __int64 uint64_t
Definition stdint.h:90
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