Blender  V3.3
node_geo_curve_primitive_quadrilateral.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "BKE_curves.hh"
4 #include "UI_interface.h"
5 #include "UI_resources.h"
6 
8 
9 #include "node_geometry_util.hh"
10 
12 
14 
16 {
17  b.add_input<decl::Float>(N_("Width"))
18  .default_value(2.0f)
19  .min(0.0f)
20  .subtype(PROP_DISTANCE)
21  .description(N_("The X axis size of the shape"));
22  b.add_input<decl::Float>(N_("Height"))
23  .default_value(2.0f)
24  .min(0.0f)
25  .subtype(PROP_DISTANCE)
26  .description(N_("The Y axis size of the shape"));
27  b.add_input<decl::Float>(N_("Bottom Width"))
28  .default_value(4.0f)
29  .min(0.0f)
30  .subtype(PROP_DISTANCE)
31  .description(N_("The X axis size of the shape"));
32  b.add_input<decl::Float>(N_("Top Width"))
33  .default_value(2.0f)
34  .min(0.0f)
35  .subtype(PROP_DISTANCE)
36  .description(N_("The X axis size of the shape"));
37  b.add_input<decl::Float>(N_("Offset"))
38  .default_value(1.0f)
39  .subtype(PROP_DISTANCE)
40  .description(
41  N_("For Parallelogram, the relative X difference between the top and bottom edges. For "
42  "Trapezoid, the amount to move the top edge in the positive X axis"));
43  b.add_input<decl::Float>(N_("Bottom Height"))
44  .default_value(3.0f)
45  .min(0.0f)
46  .subtype(PROP_DISTANCE)
47  .description(N_("The distance between the bottom point and the X axis"));
48  b.add_input<decl::Float>(N_("Top Height"))
49  .default_value(1.0f)
50  .subtype(PROP_DISTANCE)
51  .description(N_("The distance between the top point and the X axis"));
52  b.add_input<decl::Vector>(N_("Point 1"))
53  .default_value({-1.0f, -1.0f, 0.0f})
54  .subtype(PROP_DISTANCE)
55  .description(N_("The exact location of the point to use"));
56  b.add_input<decl::Vector>(N_("Point 2"))
57  .default_value({1.0f, -1.0f, 0.0f})
58  .subtype(PROP_DISTANCE)
59  .description(N_("The exact location of the point to use"));
60  b.add_input<decl::Vector>(N_("Point 3"))
61  .default_value({1.0f, 1.0f, 0.0f})
62  .subtype(PROP_DISTANCE)
63  .description(N_("The exact location of the point to use"));
64  b.add_input<decl::Vector>(N_("Point 4"))
65  .default_value({-1.0f, 1.0f, 0.0f})
66  .subtype(PROP_DISTANCE)
67  .description(N_("The exact location of the point to use"));
68  b.add_output<decl::Geometry>(N_("Curve"));
69 }
70 
71 static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
72 {
73  uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
74 }
75 
77 {
78  NodeGeometryCurvePrimitiveQuad *data = MEM_cnew<NodeGeometryCurvePrimitiveQuad>(__func__);
80  node->storage = data;
81 }
82 
84 {
85  const NodeGeometryCurvePrimitiveQuad &storage = node_storage(*node);
87  storage.mode);
88 
89  bNodeSocket *width = ((bNodeSocket *)node->inputs.first);
90  bNodeSocket *height = width->next;
91  bNodeSocket *bottom = height->next;
92  bNodeSocket *top = bottom->next;
93  bNodeSocket *offset = top->next;
94  bNodeSocket *bottom_height = offset->next;
95  bNodeSocket *top_height = bottom_height->next;
96  bNodeSocket *p1 = top_height->next;
97  bNodeSocket *p2 = p1->next;
98  bNodeSocket *p3 = p2->next;
99  bNodeSocket *p4 = p3->next;
100 
101  Vector<bNodeSocket *> available_sockets;
102 
104  available_sockets.extend({width, height});
105  }
107  available_sockets.extend({width, height, offset});
108  }
110  available_sockets.extend({bottom, top, offset, height});
111  }
112  else if (mode == GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_KITE) {
113  available_sockets.extend({width, bottom_height, top_height});
114  }
116  available_sockets.extend({p1, p2, p3, p4});
117  }
118 
119  LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
120  nodeSetSocketAvailability(ntree, sock, available_sockets.contains(sock));
121  }
122 }
123 
125  public:
126  std::string socket_name;
129  {
130  bNode &node = params.add_node("GeometryNodeCurvePrimitiveQuadrilateral");
131  node_storage(node).mode = quad_mode;
132  params.update_and_connect_available_socket(node, socket_name);
133  }
134 };
135 
137 {
138  const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
139  if (params.in_out() == SOCK_OUT) {
141  }
142  else if (params.node_tree().typeinfo->validate_link(
143  static_cast<eNodeSocketDatatype>(params.other_socket().type), SOCK_FLOAT)) {
144  params.add_item(IFACE_("Width"),
146  params.add_item(IFACE_("Height"),
148  params.add_item(IFACE_("Bottom Width"),
150  params.add_item(IFACE_("Top Width"),
152  params.add_item(IFACE_("Offset"),
154  params.add_item(IFACE_("Point 1"),
156  }
157 }
158 
160  const float height,
161  const float width)
162 {
163  positions[0] = float3(width / 2.0f, height / 2.0f, 0.0f);
164  positions[1] = float3(-width / 2.0f, height / 2.0f, 0.0f);
165  positions[2] = float3(-width / 2.0f, -height / 2.0f, 0.0f);
166  positions[3] = float3(width / 2.0f, -height / 2.0f, 0.0f);
167 }
168 
170  const float3 &p1,
171  const float3 &p2,
172  const float3 &p3,
173  const float3 &p4)
174 {
175  positions[0] = p1;
176  positions[1] = p2;
177  positions[2] = p3;
178  positions[3] = p4;
179 }
180 
182  const float height,
183  const float width,
184  const float offset)
185 {
186  positions[0] = float3(width / 2.0f + offset / 2.0f, height / 2.0f, 0.0f);
187  positions[1] = float3(-width / 2.0f + offset / 2.0f, height / 2.0f, 0.0f);
188  positions[2] = float3(-width / 2.0f - offset / 2.0f, -height / 2.0f, 0.0f);
189  positions[3] = float3(width / 2.0f - offset / 2.0f, -height / 2.0f, 0.0f);
190 }
192  const float bottom,
193  const float top,
194  const float offset,
195  const float height)
196 {
197  positions[0] = float3(top / 2.0f + offset, height / 2.0f, 0.0f);
198  positions[1] = float3(-top / 2.0f + offset, height / 2.0f, 0.0f);
199  positions[2] = float3(-bottom / 2.0f, -height / 2.0f, 0.0f);
200  positions[3] = float3(bottom / 2.0f, -height / 2.0f, 0.0f);
201 }
202 
204  const float width,
205  const float bottom_height,
206  const float top_height)
207 {
208  positions[0] = float3(0, -bottom_height, 0);
209  positions[1] = float3(width / 2, 0, 0);
210  positions[2] = float3(0, top_height, 0);
211  positions[3] = float3(-width / 2.0f, 0, 0);
212 }
213 
215 {
216  const NodeGeometryCurvePrimitiveQuad &storage = node_storage(params.node());
218 
220  bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry);
221  curves.cyclic_for_write().first() = true;
222 
223  MutableSpan<float3> positions = curves.positions_for_write();
224 
225  switch (mode) {
228  std::max(params.extract_input<float>("Height"), 0.0f),
229  std::max(params.extract_input<float>("Width"), 0.0f));
230  break;
231 
234  std::max(params.extract_input<float>("Height"), 0.0f),
235  std::max(params.extract_input<float>("Width"), 0.0f),
236  params.extract_input<float>("Offset"));
237  break;
240  std::max(params.extract_input<float>("Bottom Width"), 0.0f),
241  std::max(params.extract_input<float>("Top Width"), 0.0f),
242  params.extract_input<float>("Offset"),
243  std::max(params.extract_input<float>("Height"), 0.0f));
244  break;
247  std::max(params.extract_input<float>("Width"), 0.0f),
248  std::max(params.extract_input<float>("Bottom Height"), 0.0f),
249  params.extract_input<float>("Top Height"));
250  break;
253  params.extract_input<float3>("Point 1"),
254  params.extract_input<float3>("Point 2"),
255  params.extract_input<float3>("Point 3"),
256  params.extract_input<float3>("Point 4"));
257  break;
258  default:
259  params.set_default_remaining_outputs();
260  return;
261  }
262 
263  params.set_output("Curve", GeometrySet::create_with_curves(curves_id));
264 }
265 
266 } // namespace blender::nodes::node_geo_curve_primitive_quadrilateral_cc
267 
269 {
271 
272  static bNodeType ntype;
280  node_type_storage(&ntype,
281  "NodeGeometryCurvePrimitiveQuad",
285  nodeRegisterType(&ntype);
286 }
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
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
#define GEO_NODE_CURVE_PRIMITIVE_QUADRILATERAL
Definition: BKE_node.h:1415
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
#define UNUSED(x)
#define IFACE_(msgid)
@ CURVE_TYPE_POLY
@ SOCK_OUT
eNodeSocketDatatype
@ SOCK_FLOAT
GeometryNodeCurvePrimitiveQuadMode
@ GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_KITE
@ GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_TRAPEZOID
@ GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_POINTS
@ GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_RECTANGLE
@ GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_PARALLELOGRAM
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_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 width
_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 GLdouble GLdouble top
_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 GLdouble bottom
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
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
bool contains(const T &value) const
Definition: BLI_vector.hh:837
void extend(Span< T > array)
Definition: BLI_vector.hh:530
static CurvesGeometry & wrap(::CurvesGeometry &dna_struct)
Definition: BKE_curves.hh:138
Span< SocketDeclarationPtr > outputs() const
OperationNode * node
void * tree
bNodeTree * ntree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
Curves * curves_new_nomain_single(int points_num, CurveType type)
Definition: curves.cc:375
static void create_kite_curve(MutableSpan< float3 > positions, const float width, const float bottom_height, const float top_height)
static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void create_rectangle_curve(MutableSpan< float3 > positions, const float height, const float width)
static void create_parallelogram_curve(MutableSpan< float3 > positions, const float height, const float width, const float offset)
static void create_points_curve(MutableSpan< float3 > positions, const float3 &p1, const float3 &p2, const float3 &p3, const float3 &p4)
static void create_trapezoid_curve(MutableSpan< float3 > positions, const float bottom, const float top, const float offset, const float height)
void search_link_ops_for_declarations(GatherLinkSearchOpParams &params, Span< SocketDeclarationPtr > declarations)
vec_base< float, 3 > float3
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_quadrilateral()
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
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
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition: BKE_node.h:335
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