Blender  V3.3
node_geo_curve_primitive_bezier_segment.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_input<decl::Int>(N_("Resolution"))
17  .default_value(16)
18  .min(1)
19  .max(256)
20  .subtype(PROP_UNSIGNED)
21  .description(N_("The number of evaluated points on the curve"));
22  b.add_input<decl::Vector>(N_("Start"))
23  .default_value({-1.0f, 0.0f, 0.0f})
24  .subtype(PROP_TRANSLATION)
25  .description(N_("Position of the start control point of the curve"));
26  b.add_input<decl::Vector>(N_("Start Handle"))
27  .default_value({-0.5f, 0.5f, 0.0f})
28  .subtype(PROP_TRANSLATION)
29  .description(
30  N_("Position of the start handle used to define the shape of the curve. In Offset mode, "
31  "relative to Start point"));
32  b.add_input<decl::Vector>(N_("End Handle"))
33  .subtype(PROP_TRANSLATION)
34  .description(
35  N_("Position of the end handle used to define the shape of the curve. In Offset mode, "
36  "relative to End point"));
37  b.add_input<decl::Vector>(N_("End"))
38  .default_value({1.0f, 0.0f, 0.0f})
39  .subtype(PROP_TRANSLATION)
40  .description(N_("Position of the end control point of the curve"));
41  b.add_output<decl::Geometry>(N_("Curve"));
42 }
43 
44 static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
45 {
46  uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
47 }
48 
50 {
52  MEM_cnew<NodeGeometryCurvePrimitiveBezierSegment>(__func__);
53 
55  node->storage = data;
56 }
57 
59  const float3 start_handle_right,
60  const float3 end,
61  const float3 end_handle_left,
62  const int resolution,
64 {
67  curves.resolution_for_write().fill(resolution);
68 
69  MutableSpan<float3> positions = curves.positions_for_write();
70  curves.handle_types_left_for_write().fill(BEZIER_HANDLE_ALIGN);
71  curves.handle_types_right_for_write().fill(BEZIER_HANDLE_ALIGN);
72 
73  positions.first() = start;
74  positions.last() = end;
75 
76  MutableSpan<float3> handles_right = curves.handle_positions_right_for_write();
77  MutableSpan<float3> handles_left = curves.handle_positions_left_for_write();
78 
80  handles_left.first() = 2.0f * start - start_handle_right;
81  handles_right.first() = start_handle_right;
82 
83  handles_left.last() = end_handle_left;
84  handles_right.last() = 2.0f * end - end_handle_left;
85  }
86  else {
87  handles_left.first() = start - start_handle_right;
88  handles_right.first() = start + start_handle_right;
89 
90  handles_left.last() = end + end_handle_left;
91  handles_right.last() = end - end_handle_left;
92  }
93 
94  return curves_id;
95 }
96 
98 {
99  const NodeGeometryCurvePrimitiveBezierSegment &storage = node_storage(params.node());
102 
104  params.extract_input<float3>("Start"),
105  params.extract_input<float3>("Start Handle"),
106  params.extract_input<float3>("End"),
107  params.extract_input<float3>("End Handle"),
108  std::max(params.extract_input<int>("Resolution"), 1),
109  mode);
110  params.set_output("Curve", GeometrySet::create_with_curves(curves));
111 }
112 
113 } // namespace blender::nodes::node_geo_curve_primitive_bezier_segment_cc
114 
116 {
118 
119  static bNodeType ntype;
123  node_type_storage(&ntype,
124  "NodeGeometryCurvePrimitiveBezierSegment",
130  nodeRegisterType(&ntype);
131 }
Low-level operations for curves.
#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_PRIMITIVE_BEZIER_SEGMENT
Definition: BKE_node.h:1411
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define UNUSED(x)
@ CURVE_TYPE_BEZIER
@ BEZIER_HANDLE_ALIGN
GeometryNodeCurvePrimitiveBezierSegmentMode
@ GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT_POSITION
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
@ PROP_TRANSLATION
Definition: RNA_types.h:154
@ PROP_UNSIGNED
Definition: RNA_types.h:142
@ UI_ITEM_R_EXPAND
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
constexpr T & last(const int64_t n=0) const
Definition: BLI_span.hh:680
constexpr T & first() const
Definition: BLI_span.hh:670
static CurvesGeometry & wrap(::CurvesGeometry &dna_struct)
Definition: BKE_curves.hh:138
OperationNode * node
void * tree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
Curves * curves_new_nomain_single(int points_num, CurveType type)
Definition: curves.cc:375
static Curves * create_bezier_segment_curve(const float3 start, const float3 start_handle_right, const float3 end, const float3 end_handle_left, const int resolution, const GeometryNodeCurvePrimitiveBezierSegmentMode mode)
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_primitive_bezier_segment()
MutableSpan< float3 > positions
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
static GeometrySet create_with_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
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
float max
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480