Blender  V3.3
node_geo_curve_primitive_line.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  auto enable_direction = [](bNode &node) {
18  };
19 
20  b.add_input<decl::Vector>(N_("Start"))
21  .subtype(PROP_TRANSLATION)
22  .description(N_("Position of the first control point"));
23  b.add_input<decl::Vector>(N_("End"))
24  .default_value({0.0f, 0.0f, 1.0f})
25  .subtype(PROP_TRANSLATION)
26  .description(N_("Position of the second control point"))
27  .make_available([](bNode &node) {
29  });
30  b.add_input<decl::Vector>(N_("Direction"))
31  .default_value({0.0f, 0.0f, 1.0f})
32  .description(N_("Direction the line is going in. The length of this vector does not matter"))
33  .make_available(enable_direction);
34  b.add_input<decl::Float>(N_("Length"))
35  .default_value(1.0f)
36  .subtype(PROP_DISTANCE)
37  .description(N_("Distance between the two points"))
38  .make_available(enable_direction);
39  b.add_output<decl::Geometry>(N_("Curve"));
40 }
41 
42 static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
43 {
44  uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
45 }
46 
48 {
49  NodeGeometryCurvePrimitiveLine *data = MEM_cnew<NodeGeometryCurvePrimitiveLine>(__func__);
50 
52  node->storage = data;
53 }
54 
56 {
57  const NodeGeometryCurvePrimitiveLine &storage = node_storage(*node);
59 
60  bNodeSocket *p2_socket = ((bNodeSocket *)node->inputs.first)->next;
61  bNodeSocket *direction_socket = p2_socket->next;
62  bNodeSocket *length_socket = direction_socket->next;
63 
66  ntree, direction_socket, mode == GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_DIRECTION);
68  ntree, length_socket, mode == GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_DIRECTION);
69 }
70 
71 static Curves *create_point_line_curve(const float3 start, const float3 end)
72 {
75 
76  curves.positions_for_write().first() = start;
77  curves.positions_for_write().last() = end;
78 
79  return curves_id;
80 }
81 
83  const float3 direction,
84  const float length)
85 {
88 
89  curves.positions_for_write().first() = start;
90  curves.positions_for_write().last() = math::normalize(direction) * length + start;
91 
92  return curves_id;
93 }
94 
96 {
97  const NodeGeometryCurvePrimitiveLine &storage = node_storage(params.node());
99 
100  Curves *curves = nullptr;
102  curves = create_point_line_curve(params.extract_input<float3>("Start"),
103  params.extract_input<float3>("End"));
104  }
106  curves = create_direction_line_curve(params.extract_input<float3>("Start"),
107  params.extract_input<float3>("Direction"),
108  params.extract_input<float>("Length"));
109  }
110 
111  params.set_output("Curve", GeometrySet::create_with_curves(curves));
112 }
113 
114 } // namespace blender::nodes::node_geo_curve_primitive_line_cc
115 
117 {
119 
120  static bNodeType ntype;
124  node_type_storage(&ntype,
125  "NodeGeometryCurvePrimitiveLine",
131  nodeRegisterType(&ntype);
132 }
Low-level operations for curves.
void node_type_update(struct bNodeType *ntype, void(*updatefunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4443
#define NODE_STORAGE_FUNCS(StorageT)
Definition: BKE_node.h:1563
#define GEO_NODE_CURVE_PRIMITIVE_LINE
Definition: BKE_node.h:1414
void nodeSetSocketAvailability(struct bNodeTree *ntree, struct bNodeSocket *sock, bool is_available)
Definition: node.cc:3664
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
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define UNUSED(x)
@ CURVE_TYPE_POLY
GeometryNodeCurvePrimitiveLineMode
@ GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_POINTS
@ GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_DIRECTION
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_DISTANCE
Definition: RNA_types.h:149
@ PROP_TRANSLATION
Definition: RNA_types.h:154
@ 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
bNodeTree * ntree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static ulong * next
Curves * curves_new_nomain_single(int points_num, CurveType type)
Definition: curves.cc:375
T length(const vec_base< T, Size > &a)
vec_base< T, Size > normalize(const vec_base< T, Size > &v)
static Curves * create_point_line_curve(const float3 start, const float3 end)
static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static Curves * create_direction_line_curve(const float3 start, const float3 direction, const float length)
static void node_update(bNodeTree *ntree, bNode *node)
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_line()
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)
struct bNodeSocket * next
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