Blender V5.3
node_socket_declarations.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "NOD_bundle_type.hh"
13
14#include "BKE_lib_id.hh"
15#include "BKE_node_runtime.hh"
16
17#include "BLI_math_vector_c.hh"
18#include "BLI_string.hh"
19#include "BLI_string_utf8.hh"
20
22
30{
31 if (output.structure_type == StructureType::Field) {
32 if (!ELEM(input.structure_type, StructureType::Field, StructureType::Dynamic)) {
33 return false;
34 }
35 }
36 return true;
37}
38
39static bool sockets_can_connect(const SocketDeclaration &socket_decl,
40 const bNodeSocket &other_socket)
41{
42 /* Input sockets cannot connect to input sockets, outputs cannot connect to outputs. */
43 if (socket_decl.in_out == other_socket.in_out) {
44 return false;
45 }
46
47 if (other_socket.runtime->declaration) {
48 if (socket_decl.in_out == SOCK_IN) {
49 if (!field_types_are_compatible(socket_decl, *other_socket.runtime->declaration)) {
50 return false;
51 }
52 }
53 else {
54 if (!field_types_are_compatible(*other_socket.runtime->declaration, socket_decl)) {
55 return false;
56 }
57 }
58 }
59
60 return true;
61}
62
63static bool basic_types_can_connect(const SocketDeclaration & /*socket_decl*/,
64 const bNodeSocket &other_socket)
65{
66 return ELEM(other_socket.type,
73}
74
75static void modify_subtype_except_for_storage(bNodeSocket &socket, int new_subtype)
76{
77 const StringRefNull idname = *bke::node_static_socket_type(socket.type, new_subtype);
78 STRNCPY_UTF8(socket.idname, idname.c_str());
80 socket.typeinfo = socktype;
81}
82
83static void modify_subtype_except_for_storage(bNodeSocket &socket, int subtype, int dimensions)
84{
85 const StringRefNull idname = *bke::node_static_socket_type(socket.type, subtype, dimensions);
86 STRNCPY_UTF8(socket.idname, idname.c_str());
88 socket.typeinfo = socktype;
89}
90
91/* -------------------------------------------------------------------- */
94
96{
98 node,
99 this->in_out,
101 this->subtype,
102 this->identifier.ref(),
103 this->name.ref());
104 this->set_common_flags(socket);
105 bNodeSocketValueFloat &value = *static_cast<bNodeSocketValueFloat *>(socket.default_value);
106 value.min = this->soft_min_value;
107 value.max = this->soft_max_value;
108 value.value = this->default_value;
109 return socket;
110}
111
112bool Float::matches(const bNodeSocket &socket) const
113{
114 if (!this->matches_common_data(socket)) {
115 return false;
116 }
117 if (socket.type != SOCK_FLOAT) {
118 return false;
119 }
120 if (socket.typeinfo->subtype != this->subtype) {
121 return false;
122 }
123 bNodeSocketValueFloat &value = *static_cast<bNodeSocketValueFloat *>(socket.default_value);
124 if (value.min != this->soft_min_value) {
125 return false;
126 }
127 if (value.max != this->soft_max_value) {
128 return false;
129 }
130 return true;
131}
132
133bool Float::can_connect(const bNodeSocket &socket) const
134{
135 if (!sockets_can_connect(*this, socket)) {
136 return false;
137 }
138 if (this->in_out == SOCK_OUT && socket.type == SOCK_ROTATION) {
139 return true;
140 }
141 return basic_types_can_connect(*this, socket);
142}
143
145{
146 if (socket.type != SOCK_FLOAT) {
147 BLI_assert(socket.in_out == this->in_out);
148 return this->build(ntree, node);
149 }
150 if (socket.typeinfo->subtype != this->subtype) {
152 }
153 this->set_common_flags(socket);
154 bNodeSocketValueFloat &value = *static_cast<bNodeSocketValueFloat *>(socket.default_value);
155 value.min = this->soft_min_value;
156 value.max = this->soft_max_value;
157 value.subtype = this->subtype;
158 return socket;
159}
160
162{
163 if (const Float *other = dynamic_cast<const Float *>(&other_decl)) {
164 this->decl_->default_value = other->default_value;
165 this->decl_->soft_min_value = other->soft_min_value;
166 this->decl_->soft_max_value = other->soft_max_value;
167 this->decl_->subtype = other->subtype;
168 }
169 return *this;
170}
171
173
174/* -------------------------------------------------------------------- */
177
179{
181 node,
182 this->in_out,
183 SOCK_INT,
184 this->subtype,
185 this->identifier.ref(),
186 this->name.ref());
187 this->set_common_flags(socket);
188 bNodeSocketValueInt &value = *static_cast<bNodeSocketValueInt *>(socket.default_value);
189 value.min = this->soft_min_value;
190 value.max = this->soft_max_value;
191 value.value = this->default_value;
192 return socket;
193}
194
195bool Int::matches(const bNodeSocket &socket) const
196{
197 if (!this->matches_common_data(socket)) {
198 return false;
199 }
200 if (socket.type != SOCK_INT) {
201 return false;
202 }
203 if (socket.typeinfo->subtype != this->subtype) {
204 return false;
205 }
206 bNodeSocketValueInt &value = *static_cast<bNodeSocketValueInt *>(socket.default_value);
207 if (value.min != this->soft_min_value) {
208 return false;
209 }
210 if (value.max != this->soft_max_value) {
211 return false;
212 }
213 return true;
214}
215
216bool Int::can_connect(const bNodeSocket &socket) const
217{
218 if (!sockets_can_connect(*this, socket)) {
219 return false;
220 }
221 return basic_types_can_connect(*this, socket);
222}
223
225{
226 if (socket.type != SOCK_INT) {
227 BLI_assert(socket.in_out == this->in_out);
228 return this->build(ntree, node);
229 }
230 if (socket.typeinfo->subtype != this->subtype) {
232 }
233 this->set_common_flags(socket);
234 bNodeSocketValueInt &value = *static_cast<bNodeSocketValueInt *>(socket.default_value);
235 value.min = this->soft_min_value;
236 value.max = this->soft_max_value;
237 value.subtype = this->subtype;
238 return socket;
239}
240
242{
243 if (const Int *other = dynamic_cast<const Int *>(&other_decl)) {
244 this->decl_->default_value = other->default_value;
245 this->decl_->soft_min_value = other->soft_min_value;
246 this->decl_->soft_max_value = other->soft_max_value;
247 this->decl_->subtype = other->subtype;
248 }
249 return *this;
250}
251
253
254/* -------------------------------------------------------------------- */
257
259{
261 SOCK_VECTOR, this->subtype, this->dimensions);
263 ntree, node, this->in_out, idname, this->identifier.ref(), this->name.ref());
264 this->set_common_flags(socket);
265 bNodeSocketValueVector &value = *static_cast<bNodeSocketValueVector *>(socket.default_value);
266 std::copy_n(&this->default_value[0], this->dimensions, value.value);
267 value.dimensions = this->dimensions;
268 value.min = this->soft_min_value;
269 value.max = this->soft_max_value;
270 return socket;
271}
272
273bool Vector::matches(const bNodeSocket &socket) const
274{
275 if (!this->matches_common_data(socket)) {
276 return false;
277 }
278 if (socket.type != SOCK_VECTOR) {
279 return false;
280 }
281 if (socket.typeinfo->subtype != this->subtype) {
282 return false;
283 }
284 const bNodeSocketValueVector &value = *static_cast<const bNodeSocketValueVector *>(
285 socket.default_value);
286 if (value.dimensions != this->dimensions) {
287 return false;
288 }
289 if (value.min != this->soft_min_value) {
290 return false;
291 }
292 if (value.max != this->soft_max_value) {
293 return false;
294 }
295 return true;
296}
297
298bool Vector::can_connect(const bNodeSocket &socket) const
299{
300 if (!sockets_can_connect(*this, socket)) {
301 return false;
302 }
303 if (socket.type == SOCK_ROTATION) {
304 return true;
305 }
306 return basic_types_can_connect(*this, socket);
307}
308
310{
311 if (socket.type != SOCK_VECTOR) {
312 BLI_assert(socket.in_out == this->in_out);
313 return this->build(ntree, node);
314 }
315 if (socket.typeinfo->subtype != this->subtype) {
317 }
318 this->set_common_flags(socket);
319 bNodeSocketValueVector &value = *static_cast<bNodeSocketValueVector *>(socket.default_value);
320 if (value.dimensions != this->dimensions) {
322 }
323 value.subtype = this->subtype;
324 value.dimensions = this->dimensions;
325 value.min = this->soft_min_value;
326 value.max = this->soft_max_value;
327 return socket;
328}
329
331{
332 if (const Vector *other = dynamic_cast<const Vector *>(&other_decl)) {
333 this->decl_->default_value = other->default_value;
334 this->decl_->soft_min_value = other->soft_min_value;
335 this->decl_->soft_max_value = other->soft_max_value;
336 this->decl_->dimensions = other->dimensions;
337 this->decl_->subtype = other->subtype;
338 }
339 return *this;
340}
341
343
344/* -------------------------------------------------------------------- */
347
349{
351 SOCK_INT_VECTOR, this->subtype, this->dimensions);
353 ntree, node, this->in_out, idname, this->identifier.ref(), this->name.ref());
354 this->set_common_flags(socket);
356 socket.default_value);
357 std::copy_n(&this->default_value[0], this->dimensions, value.value);
358 value.dimensions = this->dimensions;
359 value.min = this->soft_min_value;
360 value.max = this->soft_max_value;
361 return socket;
362}
363
364bool IntVector::matches(const bNodeSocket &socket) const
365{
366 if (!this->matches_common_data(socket)) {
367 return false;
368 }
369 if (socket.type != SOCK_INT_VECTOR) {
370 return false;
371 }
372 if (socket.typeinfo->subtype != this->subtype) {
373 return false;
374 }
375 const bNodeSocketValueIntVector &value = *static_cast<const bNodeSocketValueIntVector *>(
376 socket.default_value);
377 if (value.dimensions != this->dimensions) {
378 return false;
379 }
380 if (value.min != this->soft_min_value) {
381 return false;
382 }
383 if (value.max != this->soft_max_value) {
384 return false;
385 }
386 return true;
387}
388
389bool IntVector::can_connect(const bNodeSocket &socket) const
390{
391 if (!sockets_can_connect(*this, socket)) {
392 return false;
393 }
394 return basic_types_can_connect(*this, socket);
395}
396
398{
399 if (socket.type != SOCK_INT_VECTOR) {
400 BLI_assert(socket.in_out == this->in_out);
401 return this->build(ntree, node);
402 }
403 if (socket.typeinfo->subtype != this->subtype) {
405 }
406 this->set_common_flags(socket);
408 socket.default_value);
409 if (value.dimensions != this->dimensions) {
411 }
412 value.subtype = this->subtype;
413 value.dimensions = this->dimensions;
414 value.min = this->soft_min_value;
415 value.max = this->soft_max_value;
416 return socket;
417}
418
420
421/* -------------------------------------------------------------------- */
424
426{
428 node,
429 this->in_out,
431 PROP_NONE,
432 this->identifier.ref(),
433 this->name.ref());
434 this->set_common_flags(socket);
435 bNodeSocketValueBoolean &value = *static_cast<bNodeSocketValueBoolean *>(socket.default_value);
436 value.value = this->default_value;
437 return socket;
438}
439
440bool Bool::matches(const bNodeSocket &socket) const
441{
442 if (!this->matches_common_data(socket)) {
443 return false;
444 }
445 if (socket.type != SOCK_BOOLEAN) {
446 return false;
447 }
448 return true;
449}
450
451bool Bool::can_connect(const bNodeSocket &socket) const
452{
453 if (!sockets_can_connect(*this, socket)) {
454 return false;
455 }
456 return basic_types_can_connect(*this, socket);
457}
458
460{
461 if (socket.type != SOCK_BOOLEAN) {
462 BLI_assert(socket.in_out == this->in_out);
463 return this->build(ntree, node);
464 }
465 this->set_common_flags(socket);
466 return socket;
467}
468
470{
471 if (const Bool *other = dynamic_cast<const Bool *>(&other_decl)) {
472 this->decl_->default_value = other->default_value;
473 }
474 return *this;
475}
476
478
479/* -------------------------------------------------------------------- */
482
484{
486 ntree, node, this->in_out, SOCK_RGBA, PROP_NONE, this->identifier.ref(), this->name.ref());
487 this->set_common_flags(socket);
488 bNodeSocketValueRGBA &value = *static_cast<bNodeSocketValueRGBA *>(socket.default_value);
489 copy_v4_v4(value.value, this->default_value);
490 return socket;
491}
492
493bool Color::matches(const bNodeSocket &socket) const
494{
495 if (!this->matches_common_data(socket)) {
496 return false;
497 }
498 if (socket.type != SOCK_RGBA) {
499 return false;
500 }
501 return true;
502}
503
504bool Color::can_connect(const bNodeSocket &socket) const
505{
506 if (!sockets_can_connect(*this, socket)) {
507 return false;
508 }
509 return basic_types_can_connect(*this, socket);
510}
511
513{
514 if (socket.type != SOCK_RGBA) {
515 BLI_assert(socket.in_out == this->in_out);
516 return this->build(ntree, node);
517 }
518 this->set_common_flags(socket);
519 return socket;
520}
521
523{
524 if (const Color *other = dynamic_cast<const Color *>(&other_decl)) {
525 this->decl_->default_value = other->default_value;
526 }
527 return *this;
528}
529
531/* -------------------------------------------------------------------- */
534
536{
538 node,
539 this->in_out,
541 PROP_NONE,
542 this->identifier.ref(),
543 this->name.ref());
544 this->set_common_flags(socket);
545 bNodeSocketValueRotation &value = *static_cast<bNodeSocketValueRotation *>(socket.default_value);
547 return socket;
548}
549
550bool Rotation::matches(const bNodeSocket &socket) const
551{
552 if (!this->matches_common_data(socket)) {
553 return false;
554 }
555 if (socket.type != SOCK_ROTATION) {
556 return false;
557 }
558 return true;
559}
560
561bool Rotation::can_connect(const bNodeSocket &socket) const
562{
563 if (!sockets_can_connect(*this, socket)) {
564 return false;
565 }
566 if (this->in_out == SOCK_IN) {
568 }
570}
571
573{
574 if (socket.type != SOCK_ROTATION) {
575 BLI_assert(socket.in_out == this->in_out);
576 return this->build(ntree, node);
577 }
578 this->set_common_flags(socket);
579 return socket;
580}
581
583{
584 if (const Rotation *other = dynamic_cast<const Rotation *>(&other_decl)) {
585 this->decl_->default_value = other->default_value;
586 }
587 return *this;
588}
589
591
592/* -------------------------------------------------------------------- */
595
597{
599 ntree, node, this->in_out, SOCK_MATRIX, PROP_NONE, this->identifier.ref(), this->name.ref());
600 this->set_common_flags(socket);
601 return socket;
602}
603
604bool Matrix::matches(const bNodeSocket &socket) const
605{
606 if (!this->matches_common_data(socket)) {
607 return false;
608 }
609 if (socket.type != SOCK_MATRIX) {
610 return false;
611 }
612 return true;
613}
614
615bool Matrix::can_connect(const bNodeSocket &socket) const
616{
617 if (!sockets_can_connect(*this, socket)) {
618 return false;
619 }
620 if (this->in_out == SOCK_IN) {
622 }
623 return ELEM(socket.type, SOCK_MATRIX, SOCK_VECTOR, SOCK_MATRIX);
624}
625
627{
628 if (socket.type != SOCK_MATRIX) {
629 BLI_assert(socket.in_out == this->in_out);
630 return this->build(ntree, node);
631 }
632 this->set_common_flags(socket);
633 return socket;
634}
635
637
638/* -------------------------------------------------------------------- */
641
643{
645 node,
646 this->in_out,
648 this->subtype,
649 this->identifier.ref(),
650 this->name.ref());
651 STRNCPY((static_cast<bNodeSocketValueString *>(socket.default_value))->value,
652 this->default_value.c_str());
653 this->set_common_flags(socket);
654 return socket;
655}
656
657bool String::matches(const bNodeSocket &socket) const
658{
659 if (!this->matches_common_data(socket)) {
660 return false;
661 }
662 if (socket.type != SOCK_STRING) {
663 return false;
664 }
665 if (socket.typeinfo->subtype != this->subtype) {
666 return false;
667 }
668 return true;
669}
670
671bool String::can_connect(const bNodeSocket &socket) const
672{
673 return sockets_can_connect(*this, socket) && socket.type == SOCK_STRING;
674}
675
677{
678 if (socket.type != SOCK_STRING) {
679 BLI_assert(socket.in_out == this->in_out);
680 return this->build(ntree, node);
681 }
682 if (socket.typeinfo->subtype != this->subtype) {
684 }
685 this->set_common_flags(socket);
686 bNodeSocketValueString &value = *static_cast<bNodeSocketValueString *>(socket.default_value);
687 value.subtype = this->subtype;
688 return socket;
689}
690
692{
693 BLI_assert(decl_->subtype == PROP_FILEPATH);
694 decl_->path_filter = std::move(filter);
695 return *this;
696}
697
699{
700 if (const String *other = dynamic_cast<const String *>(&other_decl)) {
701 this->decl_->default_value = other->default_value;
702 this->decl_->subtype = other->subtype;
703 this->decl_->path_filter = other->path_filter;
704 }
705 return *this;
706}
707
709
710/* -------------------------------------------------------------------- */
713
715{
717 ntree, node, this->in_out, SOCK_MENU, PROP_NONE, this->identifier.ref(), this->name.ref());
718
719 (static_cast<bNodeSocketValueMenu *>(socket.default_value))->value = this->default_value.value;
720 this->set_common_flags(socket);
721 return socket;
722}
723
724bool Menu::matches(const bNodeSocket &socket) const
725{
726 if (!this->matches_common_data(socket)) {
727 return false;
728 }
729 if (socket.type != SOCK_MENU) {
730 return false;
731 }
732 return true;
733}
734
735bool Menu::can_connect(const bNodeSocket &socket) const
736{
737 return sockets_can_connect(*this, socket) && socket.type == SOCK_MENU;
738}
739
741{
742 if (socket.type != SOCK_MENU) {
743 BLI_assert(socket.in_out == this->in_out);
744 return this->build(ntree, node);
745 }
746 this->set_common_flags(socket);
747 return socket;
748}
749
751 const StaticItemFilterFn filter_fn)
752{
753 /* Using a global map ensures that the same runtime data is used for the same static items.
754 * This is necessary because otherwise each node would have a different (incompatible) menu
755 * definition. */
756 static Mutex mutex;
759 items_by_enum_ptr;
760
761 std::lock_guard lock{mutex};
762 decl_->items = items_by_enum_ptr.lookup_or_add_cb({items, filter_fn}, [&]() {
764 for (const EnumPropertyItem *item = items; item->identifier; item++) {
765 if (filter_fn && !filter_fn(*item)) {
766 continue;
767 }
768 bke::RuntimeNodeEnumItem runtime_item;
769 runtime_item.name = item->name;
770 runtime_item.description = item->description;
771 runtime_item.identifier = item->value;
772 runtime_item.icon = item->icon;
773 runtime_items->items.append(std::move(runtime_item));
774 }
776 });
777 return *this;
778}
779
781
782/* -------------------------------------------------------------------- */
785
787{
789 ntree, node, this->in_out, SOCK_BUNDLE, PROP_NONE, this->identifier.ref(), this->name.ref());
790 this->set_common_flags(socket);
791 return socket;
792}
793
794bool Bundle::matches(const bNodeSocket &socket) const
795{
796 if (!this->matches_common_data(socket)) {
797 return false;
798 }
799 if (socket.type != SOCK_BUNDLE) {
800 return false;
801 }
802 return true;
803}
804
805bool Bundle::can_connect(const bNodeSocket &socket) const
806{
807 if (!sockets_can_connect(*this, socket)) {
808 return false;
809 }
810 return ELEM(socket.type, SOCK_BUNDLE);
811}
812
814{
815 if (socket.type != SOCK_BUNDLE) {
816 BLI_assert(socket.in_out == this->in_out);
817 return this->build(ntree, node);
818 }
819 this->set_common_flags(socket);
820 return socket;
821}
822
824{
825 decl_->bundle_type = std::move(bundle_type);
826 return *this;
827}
828
830{
831 BLI_assert(this->is_output());
832 decl_->pass_through_input_index = std::move(index);
833 return *this;
834}
835
837
838/* -------------------------------------------------------------------- */
841
842Closure::Closure() = default;
843
844Closure::~Closure() = default;
845
847{
849 node,
850 this->in_out,
852 PROP_NONE,
853 this->identifier.ref(),
854 this->name.ref());
855 this->set_common_flags(socket);
856 return socket;
857}
858
859bool Closure::matches(const bNodeSocket &socket) const
860{
861 if (!this->matches_common_data(socket)) {
862 return false;
863 }
864 if (socket.type != SOCK_CLOSURE) {
865 return false;
866 }
867 return true;
868}
869
870bool Closure::can_connect(const bNodeSocket &socket) const
871{
872 if (!sockets_can_connect(*this, socket)) {
873 return false;
874 }
875 return ELEM(socket.type, SOCK_CLOSURE);
876}
877
879{
880 if (socket.type != SOCK_CLOSURE) {
881 BLI_assert(socket.in_out == this->in_out);
882 return this->build(ntree, node);
883 }
884 this->set_common_flags(socket);
885 return socket;
886}
887
889 std::function<ClosureSignature(const bNode &)> create_signature)
890{
891 if (create_signature) {
892 decl_->create_signature = std::make_unique<std::function<ClosureSignature(const bNode &)>>(
893 std::move(create_signature));
894 }
895 else {
896 decl_->create_signature.reset();
897 }
898}
899
901
902/* -------------------------------------------------------------------- */
905
907{
909 ntree, node, this->in_out, this->idname, this->identifier.ref(), this->name.ref());
910 if (this->default_value_fn) {
911 ID *id = this->default_value_fn(node);
912 /* Assumes that all ID sockets like #bNodeSocketValueObject and #bNodeSocketValueImage have the
913 * ID pointer at the start of the struct. */
914 *static_cast<ID **>(socket.default_value) = id;
915 id_us_plus(id);
916 }
917 this->set_common_flags(socket);
918 return socket;
919}
920
922{
923 if (!this->matches_common_data(socket)) {
924 return false;
925 }
926 if (!STREQ(socket.idname, this->idname)) {
927 return false;
928 }
929 return true;
930}
931
933{
934 return sockets_can_connect(*this, socket) && STREQ(socket.idname, this->idname);
935}
936
938 bNode &node,
939 bNodeSocket &socket) const
940{
941 if (StringRef(socket.idname) != this->idname) {
942 BLI_assert(socket.in_out == this->in_out);
943 return this->build(ntree, node);
944 }
945 this->set_common_flags(socket);
946 return socket;
947}
948
950
951/* -------------------------------------------------------------------- */
954
956{
958 ntree, node, this->in_out, "NodeSocketGeometry", this->identifier.ref(), this->name.ref());
959 this->set_common_flags(socket);
960 return socket;
961}
962
963bool Geometry::matches(const bNodeSocket &socket) const
964{
965 if (!this->matches_common_data(socket)) {
966 return false;
967 }
968 if (socket.type != SOCK_GEOMETRY) {
969 return false;
970 }
971 return true;
972}
973
974bool Geometry::can_connect(const bNodeSocket &socket) const
975{
976 return sockets_can_connect(*this, socket) && socket.type == SOCK_GEOMETRY;
977}
978
980{
981 return supported_types_;
982}
983
985{
986 return only_realized_data_;
987}
988
990{
991 return only_instances_;
992}
993
999
1002{
1003 decl_->supported_types_ = supported_types;
1004 return *this;
1005}
1006
1008{
1009 decl_->only_realized_data_ = value;
1010 return *this;
1011}
1012
1014{
1015 decl_->only_instances_ = value;
1016 return *this;
1017}
1018
1020
1021/* -------------------------------------------------------------------- */
1024
1026{
1028 ntree, node, this->in_out, "NodeSocketShader", this->identifier.ref(), this->name.ref());
1029 this->set_common_flags(socket);
1030 return socket;
1031}
1032
1033bool Shader::matches(const bNodeSocket &socket) const
1034{
1035 if (!this->matches_common_data(socket)) {
1036 return false;
1037 }
1038 if (socket.type != SOCK_SHADER) {
1039 return false;
1040 }
1041 return true;
1042}
1043
1044bool Shader::can_connect(const bNodeSocket &socket) const
1045{
1046 if (!sockets_can_connect(*this, socket)) {
1047 return false;
1048 }
1049 /* Basic types can convert to shaders, but not the other way around. */
1050 if (this->in_out == SOCK_IN) {
1051 return ELEM(
1053 }
1054 return socket.type == SOCK_SHADER;
1055}
1056
1058
1059/* -------------------------------------------------------------------- */
1062
1064{
1066 ntree, node, this->in_out, "NodeSocketVirtual", this->identifier.ref(), this->name.ref());
1067 return socket;
1068}
1069
1070bool Extend::matches(const bNodeSocket &socket) const
1071{
1072 if (socket.identifier != this->identifier) {
1073 return false;
1074 }
1075 return true;
1076}
1077
1078bool Extend::can_connect(const bNodeSocket & /*socket*/) const
1079{
1080 return false;
1081}
1082
1084 bNode & /*node*/,
1085 bNodeSocket &socket) const
1086{
1087 return socket;
1088}
1089
1091
1092/* -------------------------------------------------------------------- */
1095
1097{
1099 ntree, node, this->in_out, idname_, this->identifier.ref(), this->name.ref());
1100 if (this->init_socket_fn) {
1101 this->init_socket_fn(node, socket, "interface");
1102 }
1103 return socket;
1104}
1105
1106bool Custom::matches(const bNodeSocket &socket) const
1107{
1108 if (!this->matches_common_data(socket)) {
1109 return false;
1110 }
1111 if (socket.type != SOCK_CUSTOM) {
1112 return false;
1113 }
1114 if (socket.typeinfo->idname != idname_) {
1115 return false;
1116 }
1117 return true;
1118}
1119
1120bool Custom::can_connect(const bNodeSocket &socket) const
1121{
1122 return sockets_can_connect(*this, socket) && STREQ(socket.idname, idname_);
1123}
1124
1126{
1127 if (socket.typeinfo->idname != idname_) {
1128 return this->build(ntree, node);
1129 }
1130 this->set_common_flags(socket);
1131 return socket;
1132}
1133
1135
1136} // namespace blender::nodes::decl
#define STRNCPY_UTF8(dst, src)
volatile int lock
#define ELEM(...)
#define STREQ(a, b)
#define output
Value & lookup_or_add_cb(const Key &key, const CreateValueF &create_value)
Definition BLI_map.hh:620
constexpr const char * c_str() const
constexpr StringRef()
StringRefNull ref() const
const nodes::SocketDeclaration * declaration
bool matches_common_data(const bNodeSocket &socket) const
void set_common_flags(bNodeSocket &socket) const
BoolBuilder & try_copy_ui_data(const SocketDeclaration &other_decl) 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
BundleBuilder & pass_through_input_index(std::optional< int > index)
BundleBuilder & bundle_type(BundleType bundle_type)
bNodeSocket & build(bNodeTree &ntree, bNode &node) const override
bool can_connect(const bNodeSocket &socket) const override
bool matches(const bNodeSocket &socket) const override
bNodeSocket & update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override
void create_signature(std::function< ClosureSignature(const bNode &)> create_signature)
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
ColorBuilder & try_copy_ui_data(const SocketDeclaration &other_decl) 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
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
std::function< void(bNode &node, bNodeSocket &socket, const char *data_path)> init_socket_fn
bool can_connect(const bNodeSocket &socket) const override
bool can_connect(const bNodeSocket &socket) const override
bool matches(const bNodeSocket &socket) const override
bNodeSocket & update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override
bNodeSocket & build(bNodeTree &ntree, bNode &node) const override
FloatBuilder & try_copy_ui_data(const SocketDeclaration &other_decl) 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
GeometryBuilder & only_realized_data(bool value=true)
GeometryBuilder & only_instances(bool value=true)
GeometryBuilder & supported_type(bke::GeometryComponent::Type supported_type)
bNodeSocket & build(bNodeTree &ntree, bNode &node) const override
bool can_connect(const bNodeSocket &socket) const override
Span< bke::GeometryComponent::Type > supported_types() const
bool matches(const bNodeSocket &socket) const override
std::function< ID *(const bNode &node)> default_value_fn
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 & try_copy_ui_data(const SocketDeclaration &other_decl) override
bool matches(const bNodeSocket &socket) const override
bool can_connect(const bNodeSocket &socket) const override
bNodeSocket & update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override
bNodeSocket & build(bNodeTree &ntree, bNode &node) 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
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
bNodeSocket & update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override
bool matches(const bNodeSocket &socket) const override
bool(*)(const EnumPropertyItem &item) StaticItemFilterFn
MenuBuilder & static_items(const EnumPropertyItem *items, const StaticItemFilterFn filter_fn=nullptr)
bool matches(const bNodeSocket &socket) const override
bNodeSocket & build(bNodeTree &ntree, bNode &node) const override
bool can_connect(const bNodeSocket &socket) const override
bNodeSocket & update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override
RotationBuilder & try_copy_ui_data(const SocketDeclaration &other_decl) override
bNodeSocket & build(bNodeTree &ntree, bNode &node) const override
bool matches(const bNodeSocket &socket) const override
bool can_connect(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 & try_copy_ui_data(const SocketDeclaration &other_decl) override
StringBuilder & path_filter(std::optional< std::string > filter)
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
VectorBuilder & try_copy_ui_data(const SocketDeclaration &other_decl) override
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
bNodeSocket * node_add_socket(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out, StringRefNull idname, StringRefNull identifier, StringRefNull name)
Definition node.cc:3461
bNodeSocketType * node_socket_type_find(StringRef idname)
Definition node.cc:2966
bNodeSocket * node_add_static_socket(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out, int type, int subtype, StringRefNull identifier, StringRefNull name)
Definition node.cc:3980
std::optional< StringRefNull > node_static_socket_type(int type, int subtype, std::optional< int > dimensions=std::nullopt)
Definition node.cc:3492
static bool basic_types_can_connect(const SocketDeclaration &, const bNodeSocket &other_socket)
static void modify_subtype_except_for_storage(bNodeSocket &socket, int new_subtype)
static bool field_types_are_compatible(const SocketDeclaration &input, const SocketDeclaration &output)
static bool sockets_can_connect(const SocketDeclaration &socket_decl, const bNodeSocket &other_socket)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
char * STRNCPY(char(&dst)[N], const char *src)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void id_us_plus(ID *id)
Definition lib_id.cc:433
std::mutex Mutex
Definition BLI_mutex.hh:51
MINLINE void copy_v4_v4(float r[4], const float a[4])
VecBase< float, 3 > float3
@ PROP_FILEPATH
Definition RNA_types.hh:284
bke::bNodeSocketType * typeinfo
eNodeSocketDatatype type
bke::bNodeSocketRuntime * runtime
eNodeSocketInOut in_out
Vector< RuntimeNodeEnumItem > items
Defines a socket type.
Definition BKE_node.hh:163