Blender  V3.3
node_geo_curve_handle_type_selection.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 "node_geometry_util.hh"
9 
11 
13 
15 {
16  b.add_output<decl::Bool>(N_("Selection")).field_source();
17 }
18 
19 static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
20 {
21  uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
22  uiItemR(layout, ptr, "handle_type", 0, "", ICON_NONE);
23 }
24 
26 {
27  NodeGeometryCurveSelectHandles *data = MEM_cnew<NodeGeometryCurveSelectHandles>(__func__);
28 
29  data->handle_type = GEO_NODE_CURVE_HANDLE_AUTO;
31  node->storage = data;
32 }
33 
35 {
36  switch (type) {
38  return BEZIER_HANDLE_AUTO;
40  return BEZIER_HANDLE_ALIGN;
42  return BEZIER_HANDLE_FREE;
44  return BEZIER_HANDLE_VECTOR;
45  }
47  return BEZIER_HANDLE_AUTO;
48 }
49 
51  const HandleType type,
52  const GeometryNodeCurveHandleMode mode,
53  const MutableSpan<bool> r_selection)
54 {
55  VArray<int8_t> curve_types = curves.curve_types();
56  VArray<int8_t> left = curves.handle_types_left();
57  VArray<int8_t> right = curves.handle_types_right();
58 
59  for (const int i_curve : curves.curves_range()) {
60  const IndexRange points = curves.points_for_curve(i_curve);
61  if (curve_types[i_curve] != CURVE_TYPE_BEZIER) {
62  r_selection.slice(points).fill(false);
63  }
64  else {
65  for (const int i_point : points) {
66  r_selection[i_point] = (mode & GEO_NODE_CURVE_HANDLE_LEFT && left[i_point] == type) ||
67  (mode & GEO_NODE_CURVE_HANDLE_RIGHT && right[i_point] == type);
68  }
69  }
70  }
71 }
72 
74  HandleType type_;
76 
77  public:
79  : GeometryFieldInput(CPPType::get<bool>(), "Handle Type Selection node"),
80  type_(type),
81  mode_(mode)
82  {
84  }
85 
87  const eAttrDomain domain,
88  IndexMask mask) const final
89  {
90  if (component.type() != GEO_COMPONENT_TYPE_CURVE || domain != ATTR_DOMAIN_POINT) {
91  return {};
92  }
93 
94  const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
95  const Curves *curves_id = curve_component.get_for_read();
96  if (curves_id == nullptr) {
97  return {};
98  }
99 
100  Array<bool> selection(mask.min_array_size());
101  select_by_handle_type(bke::CurvesGeometry::wrap(curves_id->geometry), type_, mode_, selection);
102  return VArray<bool>::ForContainer(std::move(selection));
103  }
104 
105  uint64_t hash() const override
106  {
107  return get_default_hash_2((int)mode_, (int)type_);
108  }
109 
110  bool is_equal_to(const fn::FieldNode &other) const override
111  {
112  if (const HandleTypeFieldInput *other_handle_selection =
113  dynamic_cast<const HandleTypeFieldInput *>(&other)) {
114  return mode_ == other_handle_selection->mode_ && type_ == other_handle_selection->type_;
115  }
116  return false;
117  }
118 };
119 
121 {
122  const NodeGeometryCurveSelectHandles &storage = node_storage(params.node());
123  const HandleType handle_type = handle_type_from_input_type(
126 
127  Field<bool> selection_field{std::make_shared<HandleTypeFieldInput>(handle_type, mode)};
128  params.set_output("Selection", std::move(selection_field));
129 }
130 
131 } // namespace blender::nodes::node_geo_curve_handle_type_selection_cc
132 
134 {
136 
137  static bNodeType ntype;
138 
140  &ntype, GEO_NODE_CURVE_HANDLE_TYPE_SELECTION, "Handle Type Selection", NODE_CLASS_INPUT);
144  node_type_storage(&ntype,
145  "NodeGeometryCurveSelectHandles",
149 
150  nodeRegisterType(&ntype);
151 }
eAttrDomain
Definition: BKE_attribute.h:25
@ ATTR_DOMAIN_POINT
Definition: BKE_attribute.h:27
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 GEO_NODE_CURVE_HANDLE_TYPE_SELECTION
Definition: BKE_node.h:1444
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
#define NODE_CLASS_INPUT
Definition: BKE_node.h:345
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
#define final(a, b, c)
Definition: BLI_hash.h:21
#define UNUSED(x)
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:108
@ 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
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble right
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to curves
@ UI_ITEM_R_EXPAND
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
const Curves * get_for_read() const
constexpr void fill(const T &value)
Definition: BLI_span.hh:527
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
Definition: BLI_span.hh:581
static VArray ForContainer(ContainerT container)
static CurvesGeometry & wrap(::CurvesGeometry &dna_struct)
Definition: BKE_curves.hh:138
GVArray get_varray_for_context(const GeometryComponent &component, const eAttrDomain domain, IndexMask mask) const final
OperationNode * node
void * tree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
static int left
static HandleType handle_type_from_input_type(const GeometryNodeCurveHandleType type)
static void select_by_handle_type(const bke::CurvesGeometry &curves, const HandleType type, const GeometryNodeCurveHandleMode mode, const MutableSpan< bool > r_selection)
static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
uint64_t get_default_hash_2(const T1 &v1, const T2 &v2)
Definition: BLI_hash.hh:223
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_handle_type_selection()
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
unsigned __int64 uint64_t
Definition: stdint.h:90
CurvesGeometry geometry
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