Blender  V3.3
node_geo_curve_set_handle_type.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <atomic>
4 
5 #include "BKE_curves.hh"
6 
7 #include "UI_interface.h"
8 #include "UI_resources.h"
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, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
26  uiItemR(layout, ptr, "handle_type", 0, "", ICON_NONE);
27 }
28 
30 {
31  NodeGeometryCurveSetHandles *data = MEM_cnew<NodeGeometryCurveSetHandles>(__func__);
32 
33  data->handle_type = GEO_NODE_CURVE_HANDLE_AUTO;
35  node->storage = data;
36 }
37 
39 {
40  switch (type) {
42  return BEZIER_HANDLE_AUTO;
44  return BEZIER_HANDLE_ALIGN;
46  return BEZIER_HANDLE_FREE;
48  return BEZIER_HANDLE_VECTOR;
49  }
51  return BEZIER_HANDLE_AUTO;
52 }
53 
55  const GeometryNodeCurveHandleMode mode,
56  const HandleType new_handle_type,
57  const Field<bool> &selection_field)
58 {
59  Curves &curves_id = *component.get_for_write();
61 
63  fn::FieldEvaluator evaluator{field_context, curves.points_num()};
64  evaluator.set_selection(selection_field);
65  evaluator.evaluate();
66  const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
67 
68  if (mode & GEO_NODE_CURVE_HANDLE_LEFT) {
69  curves.handle_types_left_for_write().fill_indices(selection, new_handle_type);
70  }
71  if (mode & GEO_NODE_CURVE_HANDLE_RIGHT) {
72  curves.handle_types_right_for_write().fill_indices(selection, new_handle_type);
73  }
74 
75  /* Eagerly calculate automatically derived handle positions if necessary. */
77  curves.calculate_bezier_auto_handles();
78  }
79 }
80 
82 {
83  const NodeGeometryCurveSetHandles &storage = node_storage(params.node());
86 
87  GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
88  Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
89 
90  const HandleType new_handle_type = handle_type_from_input_type(type);
91 
92  std::atomic<bool> has_curves = false;
93  std::atomic<bool> has_bezier = false;
94 
95  geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
96  if (!geometry_set.has_curves()) {
97  return;
98  }
99  has_curves = true;
101  const AttributeAccessor attributes = *component.attributes();
102  if (!attributes.contains("handle_type_left") || !attributes.contains("handle_type_right")) {
103  return;
104  }
105  has_bezier = true;
106 
108  mode,
109  new_handle_type,
110  selection_field);
111  });
112 
113  if (has_curves && !has_bezier) {
114  params.error_message_add(NodeWarningType::Info, TIP_("Input curves do not have Bezier type"));
115  }
116 
117  params.set_output("Curve", std::move(geometry_set));
118 }
119 } // namespace blender::nodes::node_geo_curve_set_handle_type_cc
120 
122 {
124 
125  static bNodeType ntype;
127  &ntype, GEO_NODE_CURVE_SET_HANDLE_TYPE, "Set Handle Type", NODE_CLASS_GEOMETRY);
131  node_type_storage(&ntype,
132  "NodeGeometryCurveSetHandles",
136 
137  nodeRegisterType(&ntype);
138 }
@ 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 NODE_CLASS_GEOMETRY
Definition: BKE_node.h:359
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 GEO_NODE_CURVE_SET_HANDLE_TYPE
Definition: BKE_node.h:1442
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
#define UNUSED(x)
#define ELEM(...)
#define TIP_(msgid)
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:108
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
in reality light always falls off quadratically Particle Info
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)
static CurvesGeometry & wrap(::CurvesGeometry &dna_struct)
Definition: BKE_curves.hh:138
OperationNode * node
void * tree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static void set_type_in_component(CurveComponent &component, const GeometryNodeCurveHandleMode mode, const HandleType new_handle_type, const Field< bool > &selection_field)
static HandleType handle_type_from_input_type(GeometryNodeCurveHandleType type)
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_set_handle_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
GeometryComponent & get_component_for_write(GeometryComponentType component_type)
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