Blender  V3.3
NOD_socket_declarations.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
6 
7 #include "RNA_types.h"
8 
9 #include "BLI_color.hh"
10 #include "BLI_math_vec_types.hh"
11 
12 namespace blender::nodes::decl {
13 
14 class FloatBuilder;
15 
16 class Float : public SocketDeclaration {
17  private:
18  float default_value_ = 0.0f;
19  float soft_min_value_ = -FLT_MAX;
20  float soft_max_value_ = FLT_MAX;
21  PropertySubType subtype_ = PROP_NONE;
22 
23  friend FloatBuilder;
24 
25  public:
27 
28  bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
29  bool matches(const bNodeSocket &socket) const override;
30  bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
31  bool can_connect(const bNodeSocket &socket) const override;
32 };
33 
34 class FloatBuilder : public SocketDeclarationBuilder<Float> {
35  public:
36  FloatBuilder &min(float value);
37  FloatBuilder &max(float value);
38  FloatBuilder &default_value(float value);
40 };
41 
42 class IntBuilder;
43 
44 class Int : public SocketDeclaration {
45  private:
46  int default_value_ = 0;
47  int soft_min_value_ = INT32_MIN;
48  int soft_max_value_ = INT32_MAX;
49  PropertySubType subtype_ = PROP_NONE;
50 
51  friend IntBuilder;
52 
53  public:
55 
56  bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
57  bool matches(const bNodeSocket &socket) const override;
58  bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
59  bool can_connect(const bNodeSocket &socket) const override;
60 };
61 
62 class IntBuilder : public SocketDeclarationBuilder<Int> {
63  public:
64  IntBuilder &min(int value);
65  IntBuilder &max(int value);
66  IntBuilder &default_value(int value);
68 };
69 
70 class VectorBuilder;
71 
72 class Vector : public SocketDeclaration {
73  private:
74  float3 default_value_ = {0, 0, 0};
75  float soft_min_value_ = -FLT_MAX;
76  float soft_max_value_ = FLT_MAX;
77  PropertySubType subtype_ = PROP_NONE;
78 
79  friend VectorBuilder;
80 
81  public:
83 
84  bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
85  bool matches(const bNodeSocket &socket) const override;
86  bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
87  bool can_connect(const bNodeSocket &socket) const override;
88 };
89 
90 class VectorBuilder : public SocketDeclarationBuilder<Vector> {
91  public:
92  VectorBuilder &default_value(const float3 value);
94  VectorBuilder &min(float min);
95  VectorBuilder &max(float max);
97 };
98 
99 class BoolBuilder;
100 
101 class Bool : public SocketDeclaration {
102  private:
103  bool default_value_ = false;
104  friend BoolBuilder;
105 
106  public:
108 
109  bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
110  bool matches(const bNodeSocket &socket) const override;
111  bool can_connect(const bNodeSocket &socket) const override;
112 };
113 
114 class BoolBuilder : public SocketDeclarationBuilder<Bool> {
115  public:
116  BoolBuilder &default_value(bool value);
117 };
118 
119 class ColorBuilder;
120 
121 class Color : public SocketDeclaration {
122  private:
123  ColorGeometry4f default_value_;
124 
125  friend ColorBuilder;
126 
127  public:
129 
130  bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
131  bool matches(const bNodeSocket &socket) const override;
132  bool can_connect(const bNodeSocket &socket) const override;
133 };
134 
135 class ColorBuilder : public SocketDeclarationBuilder<Color> {
136  public:
138 };
139 
140 class StringBuilder;
141 
142 class String : public SocketDeclaration {
143  private:
144  std::string default_value_;
145 
146  friend StringBuilder;
147 
148  public:
150 
151  bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
152  bool matches(const bNodeSocket &socket) const override;
153  bool can_connect(const bNodeSocket &socket) const override;
154 };
155 
156 class StringBuilder : public SocketDeclarationBuilder<String> {
157  public:
158  StringBuilder &default_value(const std::string value);
159 };
160 
162  private:
163  const char *idname_;
164 
165  public:
166  IDSocketDeclaration(const char *idname);
167 
168  bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
169  bool matches(const bNodeSocket &socket) const override;
170  bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
171  bool can_connect(const bNodeSocket &socket) const override;
172 };
173 
174 class Object : public IDSocketDeclaration {
175  public:
177 
178  Object();
179 };
180 
182  public:
184 
185  Material();
186 };
187 
189  public:
191 
192  Collection();
193 };
194 
195 class Texture : public IDSocketDeclaration {
196  public:
198 
199  Texture();
200 };
201 
202 class Image : public IDSocketDeclaration {
203  public:
205 
206  Image();
207 };
208 
209 class ShaderBuilder;
210 
211 class Shader : public SocketDeclaration {
212  private:
213  friend ShaderBuilder;
214 
215  public:
217 
218  bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
219  bool matches(const bNodeSocket &socket) const override;
220  bool can_connect(const bNodeSocket &socket) const override;
221 };
222 
223 class ShaderBuilder : public SocketDeclarationBuilder<Shader> {
224 };
225 
226 /* -------------------------------------------------------------------- */
230 inline FloatBuilder &FloatBuilder::min(const float value)
231 {
232  decl_->soft_min_value_ = value;
233  return *this;
234 }
235 
236 inline FloatBuilder &FloatBuilder::max(const float value)
237 {
238  decl_->soft_max_value_ = value;
239  return *this;
240 }
241 
242 inline FloatBuilder &FloatBuilder::default_value(const float value)
243 {
244  decl_->default_value_ = value;
245  return *this;
246 }
247 
249 {
250  decl_->subtype_ = subtype;
251  return *this;
252 }
253 
256 /* -------------------------------------------------------------------- */
260 inline IntBuilder &IntBuilder::min(const int value)
261 {
262  decl_->soft_min_value_ = value;
263  return *this;
264 }
265 
266 inline IntBuilder &IntBuilder::max(const int value)
267 {
268  decl_->soft_max_value_ = value;
269  return *this;
270 }
271 
272 inline IntBuilder &IntBuilder::default_value(const int value)
273 {
274  decl_->default_value_ = value;
275  return *this;
276 }
277 
279 {
280  decl_->subtype_ = subtype;
281  return *this;
282 }
283 
286 /* -------------------------------------------------------------------- */
291 {
292  decl_->default_value_ = value;
293  return *this;
294 }
295 
297 {
298  decl_->subtype_ = subtype;
299  return *this;
300 }
301 
303 {
304  decl_->soft_min_value_ = min;
305  return *this;
306 }
307 
309 {
310  decl_->soft_max_value_ = max;
311  return *this;
312 }
313 
315 {
316  decl_->compact_ = true;
317  return *this;
318 }
319 
322 /* -------------------------------------------------------------------- */
326 inline BoolBuilder &BoolBuilder::default_value(const bool value)
327 {
328  decl_->default_value_ = value;
329  return *this;
330 }
331 
334 /* -------------------------------------------------------------------- */
339 {
340  decl_->default_value_ = value;
341  return *this;
342 }
343 
346 /* -------------------------------------------------------------------- */
350 inline StringBuilder &StringBuilder::default_value(std::string value)
351 {
352  decl_->default_value_ = std::move(value);
353  return *this;
354 }
355 
358 /* -------------------------------------------------------------------- */
362 inline IDSocketDeclaration::IDSocketDeclaration(const char *idname) : idname_(idname)
363 {
364 }
365 
366 inline Object::Object() : IDSocketDeclaration("NodeSocketObject")
367 {
368 }
369 
370 inline Material::Material() : IDSocketDeclaration("NodeSocketMaterial")
371 {
372 }
373 
374 inline Collection::Collection() : IDSocketDeclaration("NodeSocketCollection")
375 {
376 }
377 
378 inline Texture::Texture() : IDSocketDeclaration("NodeSocketTexture")
379 {
380 }
381 
382 inline Image::Image() : IDSocketDeclaration("NodeSocketImage")
383 {
384 }
385 
388 } // namespace blender::nodes::decl
PropertySubType
Definition: RNA_types.h:125
@ PROP_NONE
Definition: RNA_types.h:126
bNodeSocket & build(bNodeTree &ntree, bNode &node) const override
bool matches(const bNodeSocket &socket) const override
bool can_connect(const bNodeSocket &socket) const override
ColorBuilder & default_value(const ColorGeometry4f value)
bool can_connect(const bNodeSocket &socket) const override
bNodeSocket & build(bNodeTree &ntree, bNode &node) const override
bool matches(const bNodeSocket &socket) const override
FloatBuilder & subtype(PropertySubType subtype)
FloatBuilder & default_value(float value)
bool can_connect(const bNodeSocket &socket) const override
bNodeSocket & build(bNodeTree &ntree, bNode &node) const override
bNodeSocket & update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override
bool matches(const bNodeSocket &socket) const override
bool can_connect(const bNodeSocket &socket) const override
bNodeSocket & build(bNodeTree &ntree, bNode &node) const override
bNodeSocket & update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override
bool matches(const bNodeSocket &socket) const override
IntBuilder & subtype(PropertySubType subtype)
bool can_connect(const bNodeSocket &socket) const override
bNodeSocket & build(bNodeTree &ntree, bNode &node) const override
bool matches(const bNodeSocket &socket) const override
bNodeSocket & update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override
bool can_connect(const bNodeSocket &socket) const override
bNodeSocket & build(bNodeTree &ntree, bNode &node) const override
bool matches(const bNodeSocket &socket) const override
StringBuilder & default_value(const std::string value)
bool can_connect(const bNodeSocket &socket) const override
bool matches(const bNodeSocket &socket) const override
bNodeSocket & build(bNodeTree &ntree, bNode &node) const override
VectorBuilder & subtype(PropertySubType subtype)
VectorBuilder & default_value(const float3 value)
bool can_connect(const bNodeSocket &socket) const override
bool matches(const bNodeSocket &socket) const override
bNodeSocket & build(bNodeTree &ntree, bNode &node) const override
bNodeSocket & update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override
OperationNode * node
bNodeTree * ntree
#define min(a, b)
Definition: sort.c:35
#define INT32_MAX
Definition: stdint.h:137
#define INT32_MIN
Definition: stdint.h:136
float max