Blender V5.3
node_tree_interface.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 <queue>
10
11#include "BKE_context.hh"
12#include "BKE_idprop.hh"
13#include "BKE_lib_id.hh"
14#include "BKE_lib_query.hh"
15#include "BKE_node.hh"
16#include "BKE_node_enum.hh"
17#include "BKE_node_runtime.hh"
21
22#include "BLI_math_vector_c.hh"
23#include "BLI_stack.hh"
24#include "BLI_string.hh"
25
26#include "BLO_read_write.hh"
27
29#include "DNA_mask_types.h"
30#include "DNA_material_types.h"
32#include "DNA_node_types.h"
33#include "DNA_sound_types.h"
34#include "DNA_text_types.h"
35#include "DNA_vfont_types.h"
36
38#include "NOD_socket.hh"
40
41#include "RNA_access.hh"
42#include "RNA_path.hh"
43#include "RNA_prototypes.hh"
44
45namespace blender {
46
47namespace bke::node_interface {
48
49namespace socket_types {
50
51/* Check valid socket type for node tree interfaces. */
52static bool is_supported_socket_type(const StringRef socket_type)
53{
54 const bke::bNodeSocketType *typeinfo = bke::node_socket_type_find(socket_type);
55 if (typeinfo == nullptr) {
56 return false;
57 }
58 /* Accept all dynamic socket types. */
59 if (!node_is_static_socket_type(*typeinfo)) {
60 return true;
61 }
62 /* Static socket types must have a valid base type.
63 * Built-in sockets can have multiple registered RNA types for the base type, e.g.
64 * `NodeSocketFloatUnsigned`, `NodeSocketFloatFactor`. */
66 return true;
67 }
68 return false;
69}
70
71/* -------------------------------------------------------------------- */
74
75static void *make_socket_data(const StringRef socket_type)
76{
77 const bNodeSocketType *stype = node_socket_type_find(socket_type);
78 if (!stype) {
79 return nullptr;
80 }
81 return socket_value_new(stype->type, stype->subtype);
82}
83
85
86/* -------------------------------------------------------------------- */
89
90static void socket_data_free(bNodeTreeInterfaceSocket &socket, const bool do_id_user)
91{
92 if (socket.socket_data == nullptr) {
93 return;
94 }
95 if (const bNodeSocketType *stype = socket.socket_typeinfo()) {
96 socket_value_free(stype->type, socket.socket_data, do_id_user);
97 }
98 socket.socket_data = nullptr;
99}
100
102
103/* -------------------------------------------------------------------- */
106
108 const bNodeTreeInterfaceSocket &src,
109 int flag)
110{
111 const bool do_id_user = (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0;
112 if (const bNodeSocketType *stype = src.socket_typeinfo()) {
113 dst.socket_data = socket_value_copy(stype->type, src.socket_data, do_id_user);
114 }
115}
116
117/* Copy socket data from a raw pointer, e.g. from a #bNodeSocket. */
119 const void *src_socket_data,
120 int flag)
121{
122 if (dst.socket_data != nullptr) {
123 socket_data_free(dst, true);
124 }
125
126 const bool do_id_user = (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0;
127 if (const bNodeSocketType *stype = dst.socket_typeinfo()) {
128 dst.socket_data = socket_value_copy(stype->type, src_socket_data, do_id_user);
129 }
130}
131
133
134/* -------------------------------------------------------------------- */
137
138/* NOTE: no default implementation, every used type must write at least the base struct. */
139
141{
142 writer->write_struct(&data);
143}
145{
146 writer->write_struct(&data);
147}
149{
150 writer->write_struct(&data);
151}
153{
154 writer->write_struct(&data);
155}
157{
158 writer->write_struct(&data);
159}
161{
162 writer->write_struct(&data);
163}
165{
166 writer->write_struct(&data);
167}
169{
170 writer->write_struct(&data);
171}
173{
174 writer->write_struct(&data);
175}
181{
182 writer->write_struct(&data);
183}
185{
186 writer->write_struct(&data);
187}
189{
190 writer->write_struct(&data);
191}
193{
194 writer->write_struct(&data);
195}
197{
198 writer->write_struct(&data);
199}
201{
202 writer->write_struct(&data);
203}
205{
206 writer->write_struct(&data);
207}
209{
210 writer->write_struct(&data);
211}
216
218{
219 socket_data_to_static_type(socket.socket_type, [&]<typename SocketDataType>() {
220 socket_data_write_impl(writer, get_socket_data_as<SocketDataType>(socket));
221 });
222}
223
225
226/* -------------------------------------------------------------------- */
229
230template<typename T> void socket_data_read_data_impl(BlendDataReader *reader, T **data)
231{
232 BLO_read_struct(reader, T, data);
233}
235{
237 /* Clear runtime data. */
238 (*data)->enum_items = nullptr;
239 (*data)->runtime_flag = 0;
240}
241
243{
244 static const Map<StringRef, StringRef> map = {
245 {"NodeSocketFloat", "NodeSocketFloatPixel"},
246 {"NodeSocketVector", "NodeSocketVectorPixel"},
247 {"NodeSocketVector2D", "NodeSocketVectorPixel2D"},
248 {"NodeSocketVector4D", "NodeSocketVectorPixel4D"},
249 {"NodeSocketInt", "NodeSocketIntPixel"},
250 {"NodeSocketIntVector2D", "NodeSocketIntVectorPixel2D"},
251 {"NodeSocketIntVector3D", "NodeSocketIntVectorPixel3D"}};
252 return map;
253}
254
256{
257 bool data_read = false;
258 socket_data_to_static_type(socket.socket_type, [&]<typename SocketDataType>() {
259 socket_data_read_data_impl(reader, reinterpret_cast<SocketDataType **>(&socket.socket_data));
260
261 /* Pixel subtype was set to None to ensure forward compatibility.
262 * So the pixel subtype is restored here. */
263 if (socket.is_pixel_socket_forward_compat) {
264 const Map<StringRef, StringRef> &subtype_none_to_pixel_map = subtype_none_to_pixel();
265 const StringRef *pixel_type = subtype_none_to_pixel_map.lookup_ptr(socket.socket_type);
266 if (pixel_type != nullptr) {
267 MEM_SAFE_DELETE(socket.socket_type);
268 socket.socket_type = BLI_strdupn(pixel_type->data(), pixel_type->size());
269 SocketDataType *socket_data = reinterpret_cast<SocketDataType *>(socket.socket_data);
270 if constexpr (requires { socket_data->subtype; }) {
271 if (socket_data) {
272 socket_data->subtype = PROP_PIXEL;
273 }
274 }
275 }
276 }
277
278 data_read = true;
279 });
280 if (!data_read && socket.socket_data) {
281 /* Not sure how this can happen exactly, but it did happen in #127855. */
282 socket.socket_data = nullptr;
283 }
284}
285
287
288/* -------------------------------------------------------------------- */
291
292template<typename T> StringRefNull socket_type_from_data_impl(const T & /*data*/);
369
371{
372 StringRefNull socket_type;
373 socket_data_to_static_type(socket.socket_type, [&]<typename SocketDataType>() {
374 socket_type = socket_type_from_data_impl(get_socket_data_as<SocketDataType>(socket));
375 });
376 return socket_type;
377}
378
380
381/* -------------------------------------------------------------------- */
384
385template<typename T>
387{
388}
397template<>
402template<>
407template<>
432
434{
435 socket_data_to_static_type(socket.socket_type, [&]<typename SocketDataType>() {
436 socket_data_foreach_id_impl(data, get_socket_data_as<SocketDataType>(socket));
437 });
438}
439
441
442} // namespace socket_types
443
444namespace item_types {
445
447
448static void item_copy(bNodeTreeInterfaceItem &dst,
449 const bNodeTreeInterfaceItem &src,
450 int flag,
451 UidGeneratorFn generate_uid);
452
460 const int flag,
461 UidGeneratorFn generate_uid)
462{
463 panel.items_num = items_src.size();
465
466 /* Copy buffers. */
467 for (const int i : items_src.index_range()) {
468 const bNodeTreeInterfaceItem *item_src = items_src[i];
469 panel.items_array[i] = MEM_dupalloc(item_src);
470 item_types::item_copy(*panel.items_array[i], *item_src, flag, generate_uid);
471 }
472}
473
480 const bNodeTreeInterfaceItem &src,
481 const int flag,
482 UidGeneratorFn generate_uid)
483{
484 switch (dst.item_type) {
486 bNodeTreeInterfaceSocket &dst_socket = reinterpret_cast<bNodeTreeInterfaceSocket &>(dst);
487 const bNodeTreeInterfaceSocket &src_socket =
488 reinterpret_cast<const bNodeTreeInterfaceSocket &>(src);
489 BLI_assert(src_socket.socket_type != nullptr);
490
491 dst_socket.name_ = BLI_strdup_null(src_socket.name_);
492 dst_socket.description_ = BLI_strdup_null(src_socket.description_);
493 dst_socket.socket_type = BLI_strdup(src_socket.socket_type);
495 dst_socket.identifier = generate_uid ? BLI_sprintfN("Socket_%d", generate_uid()) :
496 BLI_strdup(src_socket.identifier);
497 if (src_socket.properties) {
498 dst_socket.properties = IDP_CopyProperty_ex(src_socket.properties, flag);
499 }
500 if (src_socket.socket_data != nullptr) {
501 socket_types::socket_data_copy(dst_socket, src_socket, flag);
502 }
503 break;
504 }
506 bNodeTreeInterfacePanel &dst_panel = reinterpret_cast<bNodeTreeInterfacePanel &>(dst);
507 const bNodeTreeInterfacePanel &src_panel = reinterpret_cast<const bNodeTreeInterfacePanel &>(
508 src);
509
510 dst_panel.name_ = BLI_strdup_null(src_panel.name_);
511 dst_panel.description_ = BLI_strdup_null(src_panel.description_);
512 dst_panel.identifier = generate_uid ? generate_uid() : src_panel.identifier;
513
514 panel_init(dst_panel, src_panel.items(), flag, generate_uid);
515 break;
516 }
517 }
518}
519
520static void item_free(bNodeTreeInterfaceItem &item, const bool do_id_user)
521{
522 switch (item.item_type) {
524 bNodeTreeInterfaceSocket &socket = reinterpret_cast<bNodeTreeInterfaceSocket &>(item);
525
526 if (socket.socket_data != nullptr) {
527 socket_types::socket_data_free(socket, do_id_user);
528 }
529
530 MEM_SAFE_DELETE(socket.name_);
531 MEM_SAFE_DELETE(socket.description_);
532 MEM_SAFE_DELETE(socket.socket_type);
533 MEM_SAFE_DELETE(socket.default_attribute_name);
534 MEM_SAFE_DELETE(socket.identifier);
535 if (socket.properties) {
536 IDP_FreeProperty_ex(socket.properties, do_id_user);
537 }
538 break;
539 }
541 bNodeTreeInterfacePanel &panel = reinterpret_cast<bNodeTreeInterfacePanel &>(item);
542
543 panel.clear(do_id_user);
544 MEM_SAFE_DELETE(panel.name_);
545 MEM_SAFE_DELETE(panel.description_);
546 break;
547 }
548 }
549
550 MEM_delete(&item);
551}
552
554
556{
557 switch (item.item_type) {
559 bNodeTreeInterfaceSocket &socket = reinterpret_cast<bNodeTreeInterfaceSocket &>(item);
560 writer->write_string(socket.name_);
561 writer->write_string(socket.identifier);
562 writer->write_string(socket.description_);
563 writer->write_string(socket.socket_type);
564 writer->write_string(socket.default_attribute_name);
565 if (socket.properties) {
566 IDP_BlendWrite(writer, socket.properties);
567 }
568
569 socket_types::socket_data_write(writer, socket);
570 break;
571 }
573 bNodeTreeInterfacePanel &panel = reinterpret_cast<bNodeTreeInterfacePanel &>(item);
574 writer->write_string(panel.name_);
575 writer->write_string(panel.description_);
576 writer->write_pointer_array(panel.items_num, panel.items_array);
577 for (bNodeTreeInterfaceItem *child_item : panel.items()) {
578 item_write_struct(writer, *child_item);
579 }
580 break;
581 }
582 }
583}
584
586{
587 static const Map<StringRef, StringRef> map = {
588 {"NodeSocketFloatPixel", "NodeSocketFloat"},
589 {"NodeSocketVectorPixel", "NodeSocketVector"},
590 {"NodeSocketVectorPixel2D", "NodeSocketVector2D"},
591 {"NodeSocketVectorPixel4D", "NodeSocketVector4D"},
592 {"NodeSocketIntPixel", "NodeSocketInt"},
593 {"NodeSocketIntVectorPixel2D", "NodeSocketIntVector2D"},
594 {"NodeSocketIntVectorPixel3D", "NodeSocketIntVector3D"}};
595 return map;
596}
597
599{
600 socket_types::socket_data_to_static_type(socket.socket_type, [&]<typename SocketDataType>() {
601 SocketDataType *socket_data = reinterpret_cast<SocketDataType *>(socket.socket_data);
602 if constexpr (requires { socket_data->subtype; }) {
603 if (socket_data) {
604 socket_data->subtype = subtype;
605 }
606 }
607 });
608}
609
611{
612 /* The Pixel subtype is written as None subtype to ensure forward compatibility. */
614 const Map<StringRef, StringRef> &subtype_pixel_to_none_map = subtype_pixel_to_none();
615 const StringRef new_type = subtype_pixel_to_none_map.lookup(socket.socket_type);
616 /* Sockets with and without Pixel subtype share the same socket storage, so socket_type can
617 * be assigned safely. */
618 char *original_type = BLI_strdup(socket.socket_type);
619 BLI_assert(new_type.size() <= StringRef(original_type).size());
620 new_type.copy_unsafe(socket.socket_type);
622
623 socket.is_pixel_socket_forward_compat = true;
624
626 item_write_data(writer, item);
627
628 /* Restore type and subtype. */
629 StringRef(original_type).copy_unsafe(socket.socket_type);
631 socket.is_pixel_socket_forward_compat = false;
632 MEM_SAFE_DELETE(original_type);
633}
634
636{
637 switch (item.item_type) {
639 /* Forward compatible writing of older single value only flag. To be removed in 5.0. */
644
645 /* Todo(#140111): Forward compatible writing of Pixel subtype. To be removed in 6.0. */
646 if (!writer->is_undo() && subtype_pixel_to_none().contains(socket.socket_type)) {
647 pixel_subtype_forward_compat(writer, item);
648 }
649 else {
651 item_write_data(writer, item);
652 }
653
654 break;
655 }
658 item_write_data(writer, item);
659 break;
660 }
661 }
662}
663
664static size_t item_struct_size(const bNodeTreeInterfaceItem &item)
665{
666 switch (item.item_type) {
668 return sizeof(bNodeTreeInterfaceSocket);
670 return sizeof(bNodeTreeInterfacePanel);
671 }
672 return sizeof(bNodeTreeInterfaceItem);
673}
674
676{
677 switch (item.item_type) {
679 bNodeTreeInterfaceSocket &socket = reinterpret_cast<bNodeTreeInterfaceSocket &>(item);
680 BLO_read_string(reader, &socket.name_);
681 BLO_read_string(reader, &socket.description_);
682 BLO_read_string(reader, &socket.socket_type);
684 BLO_read_string(reader, &socket.identifier);
685 BLO_read_struct(reader, IDProperty, &socket.properties);
686 IDP_BlendDataRead(reader, &socket.properties);
687
688 /* Improve forward compatibility for unknown default input types. */
689 const bNodeSocketType *stype = socket.socket_typeinfo();
691 *stype, NodeDefaultInputType(socket.default_input)))
692 {
694 }
695
697 break;
698 }
700 bNodeTreeInterfacePanel &panel = reinterpret_cast<bNodeTreeInterfacePanel &>(item);
701 BLO_read_string(reader, &panel.name_);
702 BLO_read_string(reader, &panel.description_);
704
705 /* Read the direct-data for each interface item if possible. The pointer becomes null if the
706 * struct type is not known, or the data is too small for its type. */
707 for (const int i : IndexRange(panel.items_num)) {
709 reader, &panel.items_array[i], item_struct_size);
710 }
711 /* Forward compatibility: Discard unknown tree interface item types that may be introduced in
712 * the future. Their pointer is set to null above. */
713 panel.items_num = std::remove_if(
714 panel.items_array,
715 panel.items_array + panel.items_num,
716 [&](const bNodeTreeInterfaceItem *item) { return item == nullptr; }) -
717 panel.items_array;
718 /* Now read the actual data if the known interface items. */
719 for (const int i : IndexRange(panel.items_num)) {
720 item_read_data(reader, *panel.items_array[i]);
721 }
722 break;
723 }
724 }
725}
726
728{
729 switch (item.item_type) {
731 bNodeTreeInterfaceSocket &socket = reinterpret_cast<bNodeTreeInterfaceSocket &>(item);
732
735 BKE_lib_query_idpropertiesForeachIDLink_callback(prop, data);
736 }));
737
739 break;
740 }
742 bNodeTreeInterfacePanel &panel = reinterpret_cast<bNodeTreeInterfacePanel &>(item);
743 for (bNodeTreeInterfaceItem *item : panel.items()) {
744 item_foreach_id(data, *item);
745 }
746 break;
747 }
748 }
749}
750
751/* Move all child items to the new parent. */
753{
754 switch (item.item_type) {
756 return {};
757 }
759 bNodeTreeInterfacePanel &panel = reinterpret_cast<bNodeTreeInterfacePanel &>(item);
760 return panel.items();
761 }
762 }
763 return {};
764}
765
766} // namespace item_types
767
768} // namespace bke::node_interface
769
770using namespace blender::bke::node_interface;
771
772StringRefNull bNodeTreeInterfaceSocket::name() const
773{
774 return this->name_ ? this->name_ : "";
775}
776
777StringRefNull bNodeTreeInterfaceSocket::description() const
778{
779 return this->description_ ? this->description_ : "";
780}
781
782bke::bNodeSocketType *bNodeTreeInterfaceSocket::socket_typeinfo() const
783{
785 if (!value) {
787 }
788 return value;
789}
790
791ColorGeometry4f bNodeTreeInterfaceSocket::socket_color() const
792{
793 bke::bNodeSocketType *typeinfo = this->socket_typeinfo();
794 if (typeinfo && typeinfo->draw_color_simple) {
795 float color[4];
796 typeinfo->draw_color_simple(typeinfo, color);
797 return ColorGeometry4f(color);
798 }
799 return ColorGeometry4f(1.0f, 0.0f, 1.0f, 1.0f);
800}
801
802bool bNodeTreeInterfaceSocket::set_socket_type(const StringRef new_socket_type)
803{
804 if (!socket_types::is_supported_socket_type(new_socket_type)) {
805 return false;
806 }
807
808 if (this->socket_data != nullptr) {
810 }
811 MEM_SAFE_DELETE(this->socket_type);
812
813 this->socket_type = BLI_strdupn(new_socket_type.data(), new_socket_type.size());
814 this->socket_data = socket_types::make_socket_data(new_socket_type);
815
816 bke::bNodeSocketType *stype = this->socket_typeinfo();
818 NodeDefaultInputType(this->default_input)))
819 {
820 this->default_input = NODE_DEFAULT_INPUT_VALUE;
821 }
822
823 /* Reset unsupported structure_type to auto. */
824 const bool supports_fields = nodes::socket_type_supports_fields(stype->type);
825 const bool supports_grids = nodes::socket_type_supports_grids(stype->type);
826 const bool supports_dynamic = supports_fields || supports_grids;
827 const bool supports_lists = true;
828 switch (this->structure_type) {
831 break;
833 if (!supports_fields) {
834 this->structure_type = NodeSocketInterfaceStructureType::Auto;
835 }
836 break;
838 if (!supports_grids) {
839 this->structure_type = NodeSocketInterfaceStructureType::Auto;
840 }
841 break;
843 if (!supports_dynamic) {
844 this->structure_type = NodeSocketInterfaceStructureType::Auto;
845 }
846 break;
848 if (!supports_lists) {
849 this->structure_type = NodeSocketInterfaceStructureType::Auto;
850 }
851 break;
852 }
853
854 return true;
855}
856
857[[maybe_unused]] static bool is_same_socket_base_type(const StringRef socket_type_a,
858 const StringRef socket_type_b)
859{
860 const bke::bNodeSocketType *typeinfo_a = bke::node_socket_type_find(socket_type_a);
861 const bke::bNodeSocketType *typeinfo_b = bke::node_socket_type_find(socket_type_b);
862 if (typeinfo_a == nullptr || typeinfo_b == nullptr) {
863 return false;
864 }
865 /* Dynamic socket types are fine/ignored here. */
866 if (!bke::node_is_static_socket_type(*typeinfo_a) &&
868 {
869 return true;
870 }
871 return typeinfo_a->type == typeinfo_b->type;
872}
873
874void bNodeTreeInterfaceSocket::update_socket_type()
875{
876 const StringRefNull new_socket_type = socket_types::socket_type_from_data(*this);
877 BLI_assert_msg(is_same_socket_base_type(this->socket_type, new_socket_type),
878 "Cannot change socket base type without replacing socket data");
879
880 if (new_socket_type != this->socket_type) {
881 MEM_SAFE_DELETE(this->socket_type);
882 this->socket_type = BLI_strdup(new_socket_type.c_str());
883
884 bke::bNodeSocketType *stype = this->socket_typeinfo();
886 NodeDefaultInputType(this->default_input)))
887 {
888 this->default_input = NODE_DEFAULT_INPUT_VALUE;
889 }
890 }
891}
892
893void bNodeTreeInterfaceSocket::init_from_socket_instance(const bNodeSocket *socket)
894{
896
897 if (this->socket_data != nullptr) {
899 }
900 MEM_SAFE_DELETE(this->socket_type);
901 if (socket->flag & SOCK_HIDE_VALUE) {
903 }
904
905 this->socket_type = BLI_strdup(socket->idname);
906 this->socket_data = socket_types::make_socket_data(socket->idname);
908}
909
910StringRefNull bNodeTreeInterfacePanel::name() const
911{
912 return this->name_ ? this->name_ : "";
913}
914
915StringRefNull bNodeTreeInterfacePanel::description() const
916{
917 return this->description_ ? this->description_ : "";
918}
919
920IndexRange bNodeTreeInterfacePanel::items_range() const
921{
922 return IndexRange(items_num);
923}
924
925Span<const bNodeTreeInterfaceItem *> bNodeTreeInterfacePanel::items() const
926{
927 return Span(items_array, items_num);
928}
929
930MutableSpan<bNodeTreeInterfaceItem *> bNodeTreeInterfacePanel::items()
931{
932 return MutableSpan(items_array, items_num);
933}
934
935bool bNodeTreeInterfacePanel::contains(const bNodeTreeInterfaceItem &item) const
936{
937 return items().contains(&item);
938}
939
940bool bNodeTreeInterfacePanel::contains_recursive(const bNodeTreeInterfaceItem &item) const
941{
942 bool is_child = false;
943 /* Have to capture item address here instead of just a reference,
944 * otherwise pointer comparison will not work. */
945 this->foreach_item(
946 [&](const bNodeTreeInterfaceItem &titem) {
947 if (&titem == &item) {
948 is_child = true;
949 return false;
950 }
951 return true;
952 },
953 true);
954 return is_child;
955}
956
957int bNodeTreeInterfacePanel::item_position(const bNodeTreeInterfaceItem &item) const
958{
959 return items().first_index_try(&item);
960}
961
962int bNodeTreeInterfacePanel::item_index(const bNodeTreeInterfaceItem &item) const
963{
964 int index = 0;
965 bool found = false;
966 /* Have to capture item address here instead of just a reference,
967 * otherwise pointer comparison will not work. */
968 this->foreach_item([&](const bNodeTreeInterfaceItem &titem) {
969 if (&titem == &item) {
970 found = true;
971 return false;
972 }
973 ++index;
974 return true;
975 });
976 return found ? index : -1;
977}
978
979const bNodeTreeInterfaceItem *bNodeTreeInterfacePanel::item_at_index(int index) const
980{
981 int i = 0;
982 const bNodeTreeInterfaceItem *result = nullptr;
983 this->foreach_item([&](const bNodeTreeInterfaceItem &item) {
984 if (i == index) {
985 result = &item;
986 return false;
987 }
988 ++i;
989 return true;
990 });
991 return result;
992}
993
994bNodeTreeInterfacePanel *bNodeTreeInterfacePanel::find_parent_recursive(
995 const bNodeTreeInterfaceItem &item)
996{
997 std::queue<bNodeTreeInterfacePanel *> queue;
998
999 if (this->contains(item)) {
1000 return this;
1001 }
1002 queue.push(this);
1003
1004 while (!queue.empty()) {
1005 bNodeTreeInterfacePanel *parent = queue.front();
1006 queue.pop();
1007
1008 for (bNodeTreeInterfaceItem *titem : parent->items()) {
1010 continue;
1011 }
1012
1014 if (tpanel->contains(item)) {
1015 return tpanel;
1016 }
1017 queue.push(tpanel);
1018 }
1019 }
1020
1021 return nullptr;
1022}
1023
1024int bNodeTreeInterfacePanel::find_valid_insert_position_for_item(
1025 const bNodeTreeInterfaceItem &item, const int initial_pos) const
1026{
1027 const bool sockets_above_panels = !(this->flag &
1029 const Span<const bNodeTreeInterfaceItem *> items = this->items();
1030
1031 /* True if item a should be above item b. */
1032 auto must_be_before = [sockets_above_panels](const bNodeTreeInterfaceItem &a,
1033 const bNodeTreeInterfaceItem &b) -> bool {
1034 /* Keep sockets above panels. */
1035 if (sockets_above_panels) {
1038 {
1039 return true;
1040 }
1041 }
1042 /* Keep outputs above inputs. */
1045 {
1046 const auto &sa = reinterpret_cast<const bNodeTreeInterfaceSocket &>(a);
1047 const auto &sb = reinterpret_cast<const bNodeTreeInterfaceSocket &>(b);
1048 const bool is_output_a = sa.flag & NODE_INTERFACE_SOCKET_OUTPUT;
1049 const bool is_output_b = sb.flag & NODE_INTERFACE_SOCKET_OUTPUT;
1050 if ((sa.flag & NODE_INTERFACE_SOCKET_PANEL_TOGGLE) ||
1052 {
1053 /* Panel toggle inputs are allowed to be above outputs. */
1054 return false;
1055 }
1056 if (is_output_a && !is_output_b) {
1057 return true;
1058 }
1059 }
1060 return false;
1061 };
1062
1063 int min_pos = 0;
1064 for (const int i : items.index_range()) {
1065 if (must_be_before(*items[i], item)) {
1066 min_pos = i + 1;
1067 }
1068 }
1069 int max_pos = items.size();
1070 for (const int i : items.index_range()) {
1071 if (must_be_before(item, *items[i])) {
1072 max_pos = i;
1073 break;
1074 }
1075 }
1076 BLI_assert(min_pos <= max_pos);
1077 return std::clamp(initial_pos, min_pos, max_pos);
1078}
1079
1080void bNodeTreeInterfacePanel::add_item(bNodeTreeInterfaceItem &item)
1081{
1082 /* Same as inserting at the end. */
1083 insert_item(item, this->items_num);
1084}
1085
1086void bNodeTreeInterfacePanel::insert_item(bNodeTreeInterfaceItem &item, int position)
1087{
1088 /* Apply any constraints on the item positions. */
1089 position = find_valid_insert_position_for_item(item, position);
1090 position = std::min(std::max(position, 0), items_num);
1091
1092 MutableSpan<bNodeTreeInterfaceItem *> old_items = this->items();
1093 items_num++;
1094 items_array = MEM_new_array_zeroed<bNodeTreeInterfaceItem *>(items_num, __func__);
1095 this->items().take_front(position).copy_from(old_items.take_front(position));
1096 this->items().drop_front(position + 1).copy_from(old_items.drop_front(position));
1097 this->items()[position] = &item;
1098
1099 if (old_items.data()) {
1100 MEM_delete(old_items.data());
1101 }
1102}
1103
1104bool bNodeTreeInterfacePanel::remove_item(bNodeTreeInterfaceItem &item, const bool free)
1105{
1106 const int position = this->item_position(item);
1107 if (!this->items().index_range().contains(position)) {
1108 return false;
1109 }
1110
1111 MutableSpan<bNodeTreeInterfaceItem *> old_items = this->items();
1112 items_num--;
1113 items_array = MEM_new_array_zeroed<bNodeTreeInterfaceItem *>(items_num, __func__);
1114 this->items().take_front(position).copy_from(old_items.take_front(position));
1115 this->items().drop_front(position).copy_from(old_items.drop_front(position + 1));
1116
1117 /* Guaranteed not empty, contains at least the removed item */
1118 MEM_delete(old_items.data());
1119
1120 if (free) {
1121 item_types::item_free(item, true);
1122 }
1123
1124 return true;
1125}
1126
1127void bNodeTreeInterfacePanel::clear(bool do_id_user)
1128{
1129 for (bNodeTreeInterfaceItem *item : this->items()) {
1130 item_types::item_free(*item, do_id_user);
1131 }
1132 MEM_SAFE_DELETE(items_array);
1133 items_array = nullptr;
1134 items_num = 0;
1135}
1136
1137bool bNodeTreeInterfacePanel::move_item(bNodeTreeInterfaceItem &item, int new_position)
1138{
1139 const int old_position = this->item_position(item);
1140 if (!this->items().index_range().contains(old_position)) {
1141 return false;
1142 }
1143
1144 new_position = find_valid_insert_position_for_item(item, new_position);
1145 new_position = std::min(std::max(new_position, 0), items_num);
1146 if (old_position == new_position) {
1147 /* Nothing changes. */
1148 return true;
1149 }
1150
1151 if (old_position < new_position) {
1152 /* Actual target position and all existing items shifted by 1. */
1153 const Span<bNodeTreeInterfaceItem *> moved_items = this->items().slice(
1154 old_position + 1, new_position - old_position - 1);
1155 bNodeTreeInterfaceItem *tmp = this->items()[old_position];
1156 std::copy(
1157 moved_items.begin(), moved_items.end(), this->items().drop_front(old_position).data());
1158 this->items()[new_position - 1] = tmp;
1159 }
1160 else /* old_position > new_position */ {
1161 const Span<bNodeTreeInterfaceItem *> moved_items = this->items().slice(
1162 new_position, old_position - new_position);
1163 bNodeTreeInterfaceItem *tmp = this->items()[old_position];
1164 std::copy_backward(
1165 moved_items.begin(), moved_items.end(), this->items().drop_front(old_position + 1).data());
1166 this->items()[new_position] = tmp;
1167 }
1168
1169 return true;
1170}
1171
1172void bNodeTreeInterfacePanel::foreach_item(FunctionRef<bool(bNodeTreeInterfaceItem &item)> fn,
1173 bool include_self)
1174{
1175 using ItemSpan = Span<bNodeTreeInterfaceItem *>;
1176 Stack<ItemSpan> stack;
1177
1178 if (include_self && fn(this->item) == false) {
1179 return;
1180 }
1181 stack.push(this->items());
1182
1183 while (!stack.is_empty()) {
1184 const ItemSpan current_items = stack.pop();
1185
1186 for (const int index : current_items.index_range()) {
1187 bNodeTreeInterfaceItem *item = current_items[index];
1188 if (fn(*item) == false) {
1189 return;
1190 }
1191
1193 bNodeTreeInterfacePanel *panel = reinterpret_cast<bNodeTreeInterfacePanel *>(item);
1194 /* Reinsert remaining items. */
1195 if (index < current_items.size() - 1) {
1196 const ItemSpan remaining_items = current_items.drop_front(index + 1);
1197 stack.push(remaining_items);
1198 }
1199 /* Handle child items first before continuing with current span. */
1200 stack.push(panel->items());
1201 break;
1202 }
1203 }
1204 }
1205}
1206
1207void bNodeTreeInterfacePanel::foreach_item(
1208 FunctionRef<bool(const bNodeTreeInterfaceItem &item)> fn, bool include_self) const
1209{
1210 using ItemSpan = Span<const bNodeTreeInterfaceItem *>;
1211 Stack<ItemSpan> stack;
1212
1213 if (include_self && fn(this->item) == false) {
1214 return;
1215 }
1216 stack.push(this->items());
1217
1218 while (!stack.is_empty()) {
1219 const ItemSpan current_items = stack.pop();
1220
1221 for (const int index : current_items.index_range()) {
1222 const bNodeTreeInterfaceItem *item = current_items[index];
1223 if (fn(*item) == false) {
1224 return;
1225 }
1226
1228 const bNodeTreeInterfacePanel *panel = reinterpret_cast<const bNodeTreeInterfacePanel *>(
1229 item);
1230 /* Reinsert remaining items. */
1231 if (index < current_items.size() - 1) {
1232 const ItemSpan remaining_items = current_items.drop_front(index + 1);
1233 stack.push(remaining_items);
1234 }
1235 /* Handle child items first before continuing with current span. */
1236 stack.push(panel->items());
1237 break;
1238 }
1239 }
1240 }
1241}
1242
1243const bNodeTreeInterfaceSocket *bNodeTreeInterfacePanel::header_toggle_socket() const
1244{
1245 if (this->items().is_empty()) {
1246 return nullptr;
1247 }
1248 const bNodeTreeInterfaceItem *first_item = this->items().first();
1249 if (first_item->item_type != NodeTreeInterfaceItemType::Socket) {
1250 return nullptr;
1251 }
1252 const auto &socket = *reinterpret_cast<const bNodeTreeInterfaceSocket *>(first_item);
1253 if (!(socket.flag & NODE_INTERFACE_SOCKET_INPUT) ||
1255 {
1256 return nullptr;
1257 }
1258 const bke::bNodeSocketType *typeinfo = socket.socket_typeinfo();
1259 if (!typeinfo || typeinfo->type != SOCK_BOOLEAN) {
1260 return nullptr;
1261 }
1262 return &socket;
1263}
1264bNodeTreeInterfaceSocket *bNodeTreeInterfacePanel::header_toggle_socket()
1265{
1266 return const_cast<bNodeTreeInterfaceSocket *>(
1267 const_cast<const bNodeTreeInterfacePanel *>(this)->header_toggle_socket());
1268}
1269
1270namespace bke::node_interface {
1271
1273 const StringRef name,
1274 const StringRef description,
1275 const StringRef socket_type,
1276 const NodeTreeInterfaceSocketFlag flag)
1277{
1278 BLI_assert(!socket_type.is_empty());
1279 if (!socket_types::is_supported_socket_type(socket_type)) {
1280 return nullptr;
1281 }
1282
1283 bNodeTreeInterfaceSocket *new_socket = MEM_new<bNodeTreeInterfaceSocket>(__func__);
1284 BLI_assert(new_socket);
1285
1286 /* Init common socket properties. */
1287 new_socket->identifier = BLI_sprintfN("Socket_%d", uid);
1289 new_socket->name_ = BLI_strdupn(name.data(), name.size());
1290 new_socket->description_ = description.is_empty() ?
1291 nullptr :
1292 BLI_strdupn(description.data(), description.size());
1293 new_socket->socket_type = BLI_strdupn(socket_type.data(), socket_type.size());
1294 new_socket->flag = flag;
1295
1296 new_socket->socket_data = socket_types::make_socket_data(socket_type);
1297
1298 return new_socket;
1299}
1300
1302 bNodeTree &ntree,
1303 const bNode &from_node,
1304 const bNodeSocket &from_sock,
1305 const std::optional<StringRef> name,
1306 const std::optional<eNodeSocketInOut> in_out)
1307{
1308 ntree.ensure_topology_cache();
1309
1310 BLI_assert(from_sock.typeinfo);
1311 const StringRef socket_type = from_sock.typeinfo->idname.ref();
1312 const bool is_input = in_out ? bool(*in_out & SOCK_IN) : from_sock.is_input();
1313
1314 bNodeTreeInterfaceSocket *iosock = nullptr;
1315
1316 /* Try to find an existing node group interface item for the template socket and copy it.
1317 * Note: This does not work if the template socket has a different input/output type than the
1318 * generated socket. */
1319 if (from_node.is_group() && from_sock.is_input() == is_input) {
1320 if (const bNodeTree *group = reinterpret_cast<const bNodeTree *>(from_node.id)) {
1321 /* Copy interface socket directly from source group to avoid loosing data. */
1322 group->ensure_interface_cache();
1323 const bNodeTreeInterfaceSocket &src_io_socket =
1324 from_sock.is_input() ? *group->interface_inputs()[from_sock.index()] :
1325 *group->interface_outputs()[from_sock.index()];
1326 iosock = reinterpret_cast<bNodeTreeInterfaceSocket *>(
1327 ntree.tree_interface.add_item_copy(src_io_socket.item, nullptr));
1328 }
1329 }
1330
1331 if (!iosock) {
1335
1337 StringRef description = from_sock.description;
1338 if (decl) {
1339 if (!decl->description.empty()) {
1340 description = decl->description;
1341 }
1343 if (from_sock.type == SOCK_MENU) {
1344 if (const auto *menu_decl = dynamic_cast<const nodes::decl::Menu *>(decl)) {
1345 SET_FLAG_FROM_TEST(flag, menu_decl->is_expanded, NODE_INTERFACE_SOCKET_MENU_EXPANDED);
1346 }
1347 }
1348 }
1349
1350 const StringRef io_name = name ? *name : node_socket_label(from_sock);
1351 iosock = ntree.tree_interface.add_socket(io_name, description, socket_type, flag, nullptr);
1352
1353 if (iosock) {
1354 if (decl) {
1355 iosock->default_input = decl->default_input_type;
1356 }
1357 }
1358 }
1359 if (iosock == nullptr) {
1360 return nullptr;
1361 }
1362 const bke::bNodeSocketType *typeinfo = iosock->socket_typeinfo();
1363 if (typeinfo->interface_from_socket) {
1364 typeinfo->interface_from_socket(&ntree.id, iosock, &from_node, &from_sock);
1365 }
1366 return iosock;
1367}
1368
1369static std::string get_node_property_path(const bNodeTree &tree,
1370 const bNode &node,
1371 const StringRefNull prop)
1372{
1374 &const_cast<bNodeTree &>(tree).id, RNA_Node, &const_cast<bNode &>(node));
1375 return *RNA_path_from_ID_to_property(&node_ptr,
1376 RNA_struct_find_property(&node_ptr, prop.c_str()));
1377}
1378
1379static std::string get_socket_property_path(const bNodeTree &tree,
1380 const bNodeSocket &socket,
1381 const StringRefNull prop)
1382{
1384 &const_cast<bNodeTree &>(tree).id, RNA_NodeSocket, &const_cast<bNodeSocket &>(socket));
1385 return *RNA_path_from_ID_to_property(&socket_ptr,
1386 RNA_struct_find_property(&socket_ptr, prop.c_str()));
1387}
1388
1390 const bNodeTree &src_tree,
1391 const bNodeSocket &src_socket,
1392 bContext &C,
1393 bNodeTree &dst_tree,
1394 Vector<AnimationBasePathChange> &anim_basepaths)
1395{
1396 const void *value = src_socket.default_value;
1397 const std::string src_property_path = value ? get_socket_property_path(
1398 src_tree, src_socket, "default_value") :
1399 "";
1400
1401 switch (socket_type) {
1402 case SOCK_CUSTOM:
1403 case SOCK_SHADER:
1404 case SOCK_GEOMETRY:
1405 case SOCK_TEXTURE:
1406 case SOCK_MATRIX:
1407 case SOCK_BUNDLE:
1408 case SOCK_CLOSURE:
1409 case SOCK_SCENE:
1410 case SOCK_TEXT_ID:
1411 case SOCK_MASK:
1412 case SOCK_SOUND:
1413 return nullptr;
1414
1415 case SOCK_FLOAT: {
1416 bNode *node = bke::node_add_node(&C, dst_tree, "ShaderNodeValue"_ustr);
1417 bNodeSocket *socket = node->outputs.first();
1418 socket_value_copy_content(SOCK_FLOAT, socket->default_value, value, true);
1419 anim_basepaths.append(
1420 {src_property_path, get_socket_property_path(dst_tree, *socket, "default_value")});
1421 return node;
1422 }
1423 case SOCK_VECTOR: {
1424 bNode *node = bke::node_add_node(&C, dst_tree, "FunctionNodeInputVector"_ustr);
1425 auto &node_storage = *static_cast<NodeInputVector *>(node->storage);
1426 const auto &socket_value = *static_cast<const bNodeSocketValueVector *>(value);
1427 node_storage.dimensions = socket_value.dimensions;
1428 copy_v4_v4(node_storage.vector, socket_value.value);
1429 anim_basepaths.append(
1430 {src_property_path, get_node_property_path(dst_tree, *node, "vector")});
1431 return node;
1432 }
1433 case SOCK_INT_VECTOR: {
1434 bNode *node = bke::node_add_node(&C, dst_tree, "FunctionNodeInputIntVector"_ustr);
1435 auto &node_storage = *static_cast<NodeInputIntVector *>(node->storage);
1436 const auto &socket_value = *static_cast<const bNodeSocketValueIntVector *>(value);
1437 node_storage.dimensions = socket_value.dimensions;
1438 copy_v3_v3_int(node_storage.vector, socket_value.value);
1439 anim_basepaths.append(
1440 {src_property_path, get_node_property_path(dst_tree, *node, "vector")});
1441 return node;
1442 }
1443 case SOCK_RGBA: {
1444 switch (dst_tree.type) {
1445 case NTREE_COMPOSIT: {
1446 bNode *node = bke::node_add_node(&C, dst_tree, "CompositorNodeRGB"_ustr);
1447 bNodeSocket *socket = node->outputs.first();
1448 *socket->default_value_typed<bNodeSocketValueFloat>() =
1449 *static_cast<const bNodeSocketValueFloat *>(value);
1450 anim_basepaths.append(
1451 {src_property_path, get_socket_property_path(dst_tree, *socket, "default_value")});
1452 return node;
1453 }
1454 case NTREE_SHADER: {
1455 bNode *node = bke::node_add_node(&C, dst_tree, "ShaderNodeRGB"_ustr);
1456 bNodeSocket *socket = node->outputs.first();
1457 *socket->default_value_typed<bNodeSocketValueFloat>() =
1458 *static_cast<const bNodeSocketValueFloat *>(value);
1459 anim_basepaths.append(
1460 {src_property_path, get_socket_property_path(dst_tree, *socket, "default_value")});
1461 return node;
1462 }
1463 case NTREE_GEOMETRY: {
1464 bNode *node = bke::node_add_node(&C, dst_tree, "FunctionNodeInputColor"_ustr);
1465 auto &node_storage = *static_cast<NodeInputColor *>(node->storage);
1466 copy_v4_v4(node_storage.color, static_cast<const bNodeSocketValueRGBA *>(value)->value);
1467 anim_basepaths.append(
1468 {src_property_path, get_node_property_path(dst_tree, *node, "value")});
1469 return node;
1470 }
1471 case NTREE_TEXTURE:
1472 case NTREE_UNDEFINED:
1473 case NTREE_CUSTOM:
1474 break;
1475 }
1476 return nullptr;
1477 }
1478 case SOCK_BOOLEAN: {
1479 bNode *node = bke::node_add_node(&C, dst_tree, "FunctionNodeInputBool"_ustr);
1480 auto &node_storage = *static_cast<NodeInputBool *>(node->storage);
1481 node_storage.boolean = static_cast<const bNodeSocketValueBoolean *>(value)->value;
1482 anim_basepaths.append(
1483 {src_property_path, get_node_property_path(dst_tree, *node, "boolean")});
1484 return node;
1485 }
1486 case SOCK_INT: {
1487 bNode *node = bke::node_add_node(&C, dst_tree, "FunctionNodeInputInt"_ustr);
1488 auto &node_storage = *static_cast<NodeInputInt *>(node->storage);
1489 node_storage.integer = static_cast<const bNodeSocketValueInt *>(value)->value;
1490 anim_basepaths.append(
1491 {src_property_path, get_node_property_path(dst_tree, *node, "integer")});
1492 return node;
1493 }
1494 case SOCK_STRING: {
1495 bNode *node = bke::node_add_node(&C, dst_tree, "FunctionNodeInputString"_ustr);
1496 auto &node_storage = *static_cast<NodeInputString *>(node->storage);
1497 node_storage.string = BLI_strdup(static_cast<const bNodeSocketValueString *>(value)->value);
1498 anim_basepaths.append(
1499 {src_property_path, get_node_property_path(dst_tree, *node, "string")});
1500 return node;
1501 }
1502 case SOCK_OBJECT: {
1503 bNode *node = bke::node_add_node(&C, dst_tree, "GeometryNodeInputObject"_ustr);
1504 Object *ptr = static_cast<const bNodeSocketValueObject *>(value)->value;
1505 node->id = ptr ? &ptr->id : nullptr;
1506 id_us_plus(node->id);
1507 anim_basepaths.append(
1508 {src_property_path, get_node_property_path(dst_tree, *node, "object")});
1509 return node;
1510 }
1511 case SOCK_IMAGE: {
1512 bNode *node = bke::node_add_node(&C, dst_tree, "GeometryNodeInputImage"_ustr);
1513 Image *ptr = static_cast<const bNodeSocketValueImage *>(value)->value;
1514 node->id = ptr ? &ptr->id : nullptr;
1515 id_us_plus(node->id);
1516 anim_basepaths.append({src_property_path, get_node_property_path(dst_tree, *node, "image")});
1517 return node;
1518 }
1519 case SOCK_COLLECTION: {
1520 bNode *node = bke::node_add_node(&C, dst_tree, "GeometryNodeInputCollection"_ustr);
1521 Collection *ptr = static_cast<const bNodeSocketValueCollection *>(value)->value;
1522 node->id = ptr ? &ptr->id : nullptr;
1523 id_us_plus(node->id);
1524 anim_basepaths.append(
1525 {src_property_path, get_node_property_path(dst_tree, *node, "collection")});
1526 return node;
1527 }
1528 case SOCK_MATERIAL: {
1529 bNode *node = bke::node_add_node(&C, dst_tree, "GeometryNodeInputMaterial"_ustr);
1530 Material *ptr = static_cast<const bNodeSocketValueMaterial *>(value)->value;
1531 node->id = ptr ? &ptr->id : nullptr;
1532 id_us_plus(node->id);
1533 anim_basepaths.append(
1534 {src_property_path, get_node_property_path(dst_tree, *node, "material")});
1535 return node;
1536 }
1537 case SOCK_ROTATION: {
1538 bNode *node = bke::node_add_node(&C, dst_tree, "FunctionNodeInputRotation"_ustr);
1539 auto &node_storage = *static_cast<NodeInputRotation *>(node->storage);
1540 copy_v3_v3(node_storage.rotation_euler,
1541 static_cast<const bNodeSocketValueRotation *>(value)->value_euler);
1542 anim_basepaths.append(
1543 {src_property_path, get_node_property_path(dst_tree, *node, "rotation_euler")});
1544 return node;
1545 }
1546 case SOCK_MENU: {
1547 bNode *node = bke::node_add_node(&C, dst_tree, "FunctionNodeInputMenu"_ustr);
1548 auto &node_storage = *static_cast<NodeInputMenu *>(node->storage);
1549 const auto &socket_value = *static_cast<const bNodeSocketValueMenu *>(value);
1550 node_storage.value = socket_value.value;
1551 anim_basepaths.append({src_property_path, get_node_property_path(dst_tree, *node, "value")});
1552 return node;
1553 }
1554 case SOCK_FONT: {
1555 bNode *node = bke::node_add_node(&C, dst_tree, "GeometryNodeInputFont"_ustr);
1556 VFont *ptr = static_cast<const bNodeSocketValueFont *>(value)->value;
1557 node->id = ptr ? &ptr->id : nullptr;
1558 id_us_plus(node->id);
1559 anim_basepaths.append({src_property_path, get_node_property_path(dst_tree, *node, "font")});
1560 return node;
1561 }
1562 }
1564 return nullptr;
1565}
1566
1568{
1569 if (tree.type == NTREE_COMPOSIT) {
1570 bNode *node = bke::node_add_node(&C, tree, "CompositorNodeSceneTime"_ustr);
1571 bke::node_find_socket(*node, SOCK_OUT, "Seconds"_ustr)->flag |= SOCK_HIDDEN;
1572 return node;
1573 }
1574 if (tree.type == NTREE_GEOMETRY) {
1575 bNode *node = bke::node_add_node(&C, tree, "GeometryNodeInputSceneTime"_ustr);
1576 bke::node_find_socket(*node, SOCK_OUT, "Seconds"_ustr)->flag |= SOCK_HIDDEN;
1577 return node;
1578 }
1579 return nullptr;
1580}
1581
1583 const NodeDefaultInputType default_input,
1584 bContext &C,
1585 bNodeTree &tree)
1586{
1587 switch (socket_type) {
1588 case SOCK_CUSTOM:
1589 case SOCK_RGBA:
1590 case SOCK_INT_VECTOR:
1591 case SOCK_BOOLEAN:
1592 case SOCK_STRING:
1593 case SOCK_SHADER:
1594 case SOCK_GEOMETRY:
1595 case SOCK_TEXTURE:
1596 case SOCK_IMAGE:
1597 case SOCK_COLLECTION:
1598 case SOCK_MATERIAL:
1599 case SOCK_BUNDLE:
1600 case SOCK_CLOSURE:
1601 case SOCK_SCENE:
1602 case SOCK_TEXT_ID:
1603 case SOCK_MASK:
1604 case SOCK_SOUND:
1605 case SOCK_ROTATION:
1606 case SOCK_MENU:
1607 case SOCK_FONT:
1608 return nullptr;
1609
1610 case SOCK_OBJECT: {
1611 if (default_input == NODE_DEFAULT_INPUT_SELF_OBJECT) {
1612 return bke::node_add_node(&C, tree, "GeometryNodeSelfObject"_ustr);
1613 }
1614 return nullptr;
1615 }
1616 case SOCK_FLOAT: {
1617 if (default_input == NODE_DEFAULT_INPUT_SCENE_FRAME) {
1619 }
1620 return nullptr;
1621 }
1622 case SOCK_VECTOR:
1623 if (default_input == NODE_DEFAULT_INPUT_NORMAL_FIELD) {
1624 bNode *node = bke::node_add_node(&C, tree, "GeometryNodeInputNormal"_ustr);
1625 bke::node_find_socket(*node, SOCK_OUT, "True Normal"_ustr)->flag |= SOCK_HIDDEN;
1626 return node;
1627 }
1628 if (default_input == NODE_DEFAULT_INPUT_POSITION_FIELD) {
1629 return bke::node_add_node(&C, tree, "GeometryNodeInputPosition"_ustr);
1630 }
1631 if (default_input == NODE_DEFAULT_INPUT_HANDLE_LEFT_FIELD) {
1632 bNode *node = bke::node_add_node(&C, tree, "GeometryNodeInputCurveHandlePositions"_ustr);
1633 bke::node_find_socket(*node, SOCK_IN, "Relative"_ustr)->flag |= SOCK_HIDDEN;
1634 bke::node_find_socket(*node, SOCK_OUT, "Right"_ustr)->flag |= SOCK_HIDDEN;
1635 return node;
1636 }
1637 if (default_input == NODE_DEFAULT_INPUT_HANDLE_RIGHT_FIELD) {
1638 bNode *node = bke::node_add_node(&C, tree, "GeometryNodeInputCurveHandlePositions"_ustr);
1639 bke::node_find_socket(*node, SOCK_IN, "Relative"_ustr)->flag |= SOCK_HIDDEN;
1640 bke::node_find_socket(*node, SOCK_OUT, "Left"_ustr)->flag |= SOCK_HIDDEN;
1641 return node;
1642 }
1643 return nullptr;
1644
1645 case SOCK_INT:
1646 if (default_input == NODE_DEFAULT_INPUT_INDEX_FIELD) {
1647 return bke::node_add_node(&C, tree, "GeometryNodeInputIndex"_ustr);
1648 }
1649 if (default_input == NODE_DEFAULT_INPUT_ID_INDEX_FIELD) {
1650 return bke::node_add_node(&C, tree, "GeometryNodeInputID"_ustr);
1651 }
1652 if (default_input == NODE_DEFAULT_INPUT_SCENE_FRAME) {
1654 }
1655 return nullptr;
1656
1657 case SOCK_MATRIX:
1658 if (default_input == NODE_DEFAULT_INPUT_INSTANCE_TRANSFORM_FIELD) {
1659 return bke::node_add_node(&C, tree, "GeometryNodeInstanceTransform"_ustr);
1660 }
1661 return nullptr;
1662 }
1664 return nullptr;
1665}
1666
1667static std::string socket_basepath(const bNodeTree &tree, const bNodeSocket &socket)
1668{
1670 &const_cast<bNodeTree &>(tree).id, RNA_NodeSocket, &const_cast<bNodeSocket &>(socket));
1671 return *RNA_path_from_ID_to_struct(&ptr);
1672}
1673
1675 const bNodeTree &src_tree,
1676 const bNodeSocket *src_socket,
1677 bContext &C,
1678 bNodeTree &dst_tree,
1679 Vector<AnimationBasePathChange> &anim_basepaths)
1680{
1681 const bNodeSocketType *socket_typeinfo = bke::node_socket_type_find_static(socket_type);
1682 if (!socket_typeinfo) {
1683 return nullptr;
1684 }
1685
1686 const std::string socket_idname = socket_typeinfo->idname.string();
1687 const void *src_value = src_socket ? src_socket->default_value : nullptr;
1688
1689 bNode *proxy_node = bke::node_add_node(&C, dst_tree, "NodeImplicitConversion"_ustr);
1690 auto &data = *static_cast<NodeImplicitConversion *>(proxy_node->storage);
1691 STRNCPY(data.type_idname, socket_idname.c_str());
1692 BKE_ntree_update_tag_node_property(&dst_tree, proxy_node);
1694
1695 bNodeSocket *socket = proxy_node->inputs.first();
1696 bke::socket_value_copy_content(socket->type, socket->default_value, src_value, true);
1697
1698 proxy_node->flag |= NODE_COLLAPSED;
1699
1700 if (src_socket) {
1701 bNodeSocket &proxy_socket = *proxy_node->inputs.first();
1702 anim_basepaths.append(
1703 {socket_basepath(src_tree, *src_socket), socket_basepath(dst_tree, proxy_socket)});
1704 }
1705
1706 return proxy_node;
1707}
1708
1710 const StringRef name,
1711 const StringRef description,
1712 const NodeTreeInterfacePanelFlag flag)
1713{
1714 BLI_assert(!name.is_empty());
1715
1716 bNodeTreeInterfacePanel *new_panel = MEM_new<bNodeTreeInterfacePanel>(__func__);
1718 new_panel->name_ = BLI_strdupn(name.data(), name.size());
1719 new_panel->description_ = description.is_empty() ?
1720 nullptr :
1721 BLI_strdupn(description.data(), description.size());
1722 new_panel->identifier = uid;
1723 new_panel->flag = flag;
1724 return new_panel;
1725}
1726
1728{
1729 if (item_reference == nullptr) {
1730 return;
1731 }
1732
1733 MEM_delete(item_reference->items);
1734 MEM_delete(item_reference);
1735}
1736
1737} // namespace bke::node_interface
1738
1739void bNodeTreeInterface::init_data()
1740{
1741 this->runtime = MEM_new<bke::bNodeTreeInterfaceRuntime>(__func__);
1742 this->tag_missing_runtime_data();
1743}
1744
1745void bNodeTreeInterface::copy_data(const bNodeTreeInterface &src, int flag)
1746{
1747 item_types::panel_init(this->root_panel, src.root_panel.items(), flag, nullptr);
1748 this->active_index = src.active_index;
1749
1750 this->runtime = MEM_new<bke::bNodeTreeInterfaceRuntime>(__func__);
1751 this->tag_missing_runtime_data();
1752}
1753
1754void bNodeTreeInterface::free_data()
1755{
1756 MEM_delete(this->runtime);
1757
1758 /* Called when freeing the main database, don't do user refcount here. */
1759 this->root_panel.clear(false);
1760}
1761
1762void bNodeTreeInterface::write(BlendWriter *writer)
1763{
1764 /* Don't write the root panel struct itself, it's nested in the interface struct. */
1765 item_types::item_write_data(writer, this->root_panel.item);
1766}
1767
1768void bNodeTreeInterface::read_data(BlendDataReader *reader)
1769{
1770 /* Root item must be a panel, not checked elsewhere because it is embedded. */
1771 if (this->root_panel.item.item_type != NodeTreeInterfaceItemType::Panel) {
1772 BLO_read_data_invalidate(reader, "Corrupt .blend file, invalid node tree interface.");
1773 this->root_panel = bNodeTreeInterfacePanel();
1774 }
1775 item_types::item_read_data(reader, this->root_panel.item);
1776
1777 this->runtime = MEM_new<bke::bNodeTreeInterfaceRuntime>(__func__);
1778 this->tag_missing_runtime_data();
1779}
1780
1781bNodeTreeInterfaceItem *bNodeTreeInterface::active_item()
1782{
1783 bNodeTreeInterfaceItem *active = nullptr;
1784 int count = this->active_index;
1785 this->foreach_item([&](bNodeTreeInterfaceItem &item) {
1786 if (count == 0) {
1787 active = &item;
1788 return false;
1789 }
1790 --count;
1791 return true;
1792 });
1793 return active;
1794}
1795
1796const bNodeTreeInterfaceItem *bNodeTreeInterface::active_item() const
1797{
1798 const bNodeTreeInterfaceItem *active = nullptr;
1799 int count = this->active_index;
1800 this->foreach_item([&](const bNodeTreeInterfaceItem &item) {
1801 if (count == 0) {
1802 active = &item;
1803 return false;
1804 }
1805 --count;
1806 return true;
1807 });
1808 return active;
1809}
1810
1811void bNodeTreeInterfaceItem::set_selected(const bool select)
1812{
1813 switch (this->item_type) {
1818 break;
1819 }
1821 bNodeTreeInterfaceSocket *socket =
1824 break;
1825 }
1826 }
1827}
1828
1829void bNodeTreeInterface::active_item_set(bNodeTreeInterfaceItem *item,
1830 const bool deselect_original)
1831{
1832 if (deselect_original) {
1833 if (bNodeTreeInterfaceItem *original_active = this->active_item()) {
1834 original_active->set_selected(false);
1835 }
1836 }
1837 this->active_index = 0;
1838 int count = 0;
1839 this->foreach_item([&](bNodeTreeInterfaceItem &titem) {
1840 if (&titem == item) {
1841 this->active_index = count;
1842 item->set_selected(true);
1843 return false;
1844 }
1845 ++count;
1846 return true;
1847 });
1848}
1849
1850bNodeTreeInterfaceSocket *bNodeTreeInterface::add_socket(const StringRef name,
1851 const StringRef description,
1852 const StringRef socket_type,
1853 const NodeTreeInterfaceSocketFlag flag,
1855{
1856 /* Check that each interface socket is either an input or an output. Technically, it can be
1857 * both at the same time, but we don't want that for the time being. */
1860 if (parent == nullptr) {
1861 parent = &root_panel;
1862 }
1863 BLI_assert(this->find_item(parent->item));
1864
1866 this->next_uid++, name, description, socket_type, flag);
1867 if (new_socket) {
1868 parent->add_item(new_socket->item);
1869 }
1870
1871 this->tag_items_changed();
1872 return new_socket;
1873}
1874
1875bNodeTreeInterfaceSocket *bNodeTreeInterface::insert_socket(const StringRef name,
1876 const StringRef description,
1877 const StringRef socket_type,
1878 const NodeTreeInterfaceSocketFlag flag,
1880 const int position)
1881{
1882 if (parent == nullptr) {
1883 parent = &root_panel;
1884 }
1885 BLI_assert(this->find_item(parent->item));
1886
1888 this->next_uid++, name, description, socket_type, flag);
1889 if (new_socket) {
1890 parent->insert_item(new_socket->item, position);
1891 }
1892
1893 this->tag_items_changed();
1894 return new_socket;
1895}
1896
1897bNodeTreeInterfacePanel *bNodeTreeInterface::add_panel(const StringRef name,
1898 const StringRef description,
1899 const NodeTreeInterfacePanelFlag flag,
1901{
1902 if (parent == nullptr) {
1903 parent = &root_panel;
1904 }
1905 BLI_assert(this->find_item(parent->item));
1906
1907 bNodeTreeInterfacePanel *new_panel = make_panel(this->next_uid++, name, description, flag);
1908 if (new_panel) {
1909 parent->add_item(new_panel->item);
1910 }
1911
1912 this->tag_items_changed();
1913 return new_panel;
1914}
1915
1916bNodeTreeInterfacePanel *bNodeTreeInterface::insert_panel(const StringRef name,
1917 const StringRef description,
1918 const NodeTreeInterfacePanelFlag flag,
1920 const int position)
1921{
1922 if (parent == nullptr) {
1923 parent = &root_panel;
1924 }
1925 BLI_assert(this->find_item(parent->item));
1926
1927 bNodeTreeInterfacePanel *new_panel = make_panel(this->next_uid++, name, description, flag);
1928 if (new_panel) {
1929 parent->insert_item(new_panel->item, position);
1930 }
1931
1932 this->tag_items_changed();
1933 return new_panel;
1934}
1935
1936bNodeTreeInterfaceItem *bNodeTreeInterface::add_item_copy(const bNodeTreeInterfaceItem &item,
1938{
1939 BLI_assert(&item != &this->root_panel.item);
1940 if (parent == nullptr) {
1941 parent = &root_panel;
1942 }
1943 BLI_assert(this->find_item(parent->item));
1944
1945 bNodeTreeInterfaceItem *citem = MEM_dupalloc(&item);
1946 item_types::item_copy(*citem, item, 0, [&]() { return this->next_uid++; });
1947 parent->add_item(*citem);
1948
1949 this->tag_items_changed();
1950 return citem;
1951}
1952
1953bNodeTreeInterfaceItem *bNodeTreeInterface::insert_item_copy(const bNodeTreeInterfaceItem &item,
1955 int position)
1956{
1957 BLI_assert(&item != &this->root_panel.item);
1958 if (parent == nullptr) {
1959 parent = &root_panel;
1960 }
1961 BLI_assert(this->find_item(parent->item));
1962
1963 bNodeTreeInterfaceItem *citem = MEM_dupalloc(&item);
1964 item_types::item_copy(*citem, item, 0, [&]() { return this->next_uid++; });
1965 parent->insert_item(*citem, position);
1966
1967 this->tag_items_changed();
1968 return citem;
1969}
1970
1971bool bNodeTreeInterface::remove_item(bNodeTreeInterfaceItem &item, bool move_content_to_parent)
1972{
1973 BLI_assert(&item != &this->root_panel.item);
1974 bNodeTreeInterfacePanel *parent = this->find_item_parent(item, true);
1975 if (parent == nullptr) {
1976 return false;
1977 }
1978 if (move_content_to_parent) {
1979 int position = parent->item_position(item);
1980 /* Cache children to avoid invalidating the iterator. */
1982 for (bNodeTreeInterfaceItem *child : children) {
1983 this->move_item_to_parent(*child, parent, position++);
1984 }
1985 }
1986 if (parent->remove_item(item, true)) {
1987 this->tag_items_changed();
1988 return true;
1989 }
1990
1991 return false;
1992}
1993
1994void bNodeTreeInterface::clear_items()
1995{
1996 root_panel.clear(true);
1997 this->tag_items_changed();
1998}
1999
2000bool bNodeTreeInterface::move_item(bNodeTreeInterfaceItem &item, const int new_position)
2001{
2002 BLI_assert(&item != &this->root_panel.item);
2003 bNodeTreeInterfacePanel *parent = this->find_item_parent(item, true);
2004 if (parent == nullptr) {
2005 return false;
2006 }
2007
2008 if (parent->move_item(item, new_position)) {
2009 this->tag_items_changed();
2010 return true;
2011 }
2012 return false;
2013}
2014
2015bool bNodeTreeInterface::move_item_to_parent(bNodeTreeInterfaceItem &item,
2016 bNodeTreeInterfacePanel *new_parent,
2017 int new_position)
2018{
2019 BLI_assert(&item != &this->root_panel.item);
2020 if (new_parent == nullptr) {
2021 new_parent = &this->root_panel;
2022 }
2023
2025 bNodeTreeInterfacePanel &src_item = reinterpret_cast<bNodeTreeInterfacePanel &>(item);
2026 if (src_item.contains_recursive(new_parent->item)) {
2027 return false;
2028 }
2029 }
2030
2031 bNodeTreeInterfacePanel *parent = this->find_item_parent(item, true);
2032 if (parent == nullptr) {
2033 return false;
2034 }
2035
2036 if (parent == new_parent) {
2037 if (parent->move_item(item, new_position)) {
2038 this->tag_items_changed();
2039 return true;
2040 }
2041 }
2042 else {
2043 /* NOTE: only remove and reinsert when parents different, otherwise removing the item can
2044 * change the desired target position! */
2045 if (parent->remove_item(item, false)) {
2046 new_parent->insert_item(item, new_position);
2047 this->tag_items_changed();
2048 return true;
2049 }
2050 }
2051 return false;
2052}
2053
2054void bNodeTreeInterface::foreach_id(LibraryForeachIDData *cb)
2055{
2056 item_types::item_foreach_id(cb, root_panel.item);
2057}
2058
2059bool bNodeTreeInterface::items_cache_is_available() const
2060{
2061 return !this->runtime->items_cache_mutex_.is_dirty();
2062}
2063
2064void bNodeTreeInterface::ensure_items_cache() const
2065{
2066 bke::bNodeTreeInterfaceRuntime &runtime = *this->runtime;
2067
2068 runtime.items_cache_mutex_.ensure([&]() {
2069 /* Rebuild draw-order list of interface items for linear access. */
2070 runtime.items_.clear();
2071 runtime.inputs_.clear();
2072 runtime.outputs_.clear();
2073
2074 /* Items in the cache are mutable pointers, but node tree update considers ID data to be
2075 * immutable when caching. DNA ListBaseT pointers can be mutable even if their container is
2076 * const, but the items returned by #foreach_item inherit qualifiers from the container. */
2077 bNodeTreeInterface &mutable_self = const_cast<bNodeTreeInterface &>(*this);
2078
2079 mutable_self.foreach_item([&](bNodeTreeInterfaceItem &item) {
2080 runtime.items_.add_new(&item);
2082 if (socket->flag & NODE_INTERFACE_SOCKET_INPUT) {
2083 runtime.inputs_.add_new(socket);
2084 }
2085 if (socket->flag & NODE_INTERFACE_SOCKET_OUTPUT) {
2086 runtime.outputs_.add_new(socket);
2087 }
2088 }
2089 return true;
2090 });
2091 });
2092}
2093
2094int bNodeTreeInterface::input_index_by_identifier(const StringRef identifier) const
2095{
2096 BLI_assert(this->items_cache_is_available());
2097 return this->runtime->inputs_.index_of_try_as(identifier);
2098}
2099
2100int bNodeTreeInterface::output_index_by_identifier(const StringRef identifier) const
2101{
2102 BLI_assert(this->items_cache_is_available());
2103 return this->runtime->outputs_.index_of_try_as(identifier);
2104}
2105
2106void bNodeTreeInterface::tag_interface_changed()
2107{
2108 this->runtime->interface_changed_.store(true);
2109}
2110
2111bool bNodeTreeInterface::requires_dependent_tree_updates() const
2112{
2113 return this->runtime->interface_changed_.load(std::memory_order_relaxed);
2114}
2115
2116void bNodeTreeInterface::tag_items_changed()
2117{
2118 this->tag_interface_changed();
2119 this->runtime->items_cache_mutex_.tag_dirty();
2120}
2121
2122void bNodeTreeInterface::tag_items_changed_generic()
2123{
2124 /* Perform a full update since we don't know what changed exactly. */
2125 this->tag_items_changed();
2126}
2127
2128void bNodeTreeInterface::tag_item_property_changed()
2129{
2130 this->tag_interface_changed();
2131}
2132
2133void bNodeTreeInterface::tag_missing_runtime_data()
2134{
2135 this->tag_items_changed();
2136}
2137
2138void bNodeTreeInterface::reset_interface_changed()
2139{
2140 this->runtime->interface_changed_.store(false);
2141}
2142
2143} // namespace blender
#define IDP_BlendDataRead(reader, prop)
#define BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(data_, func_call_)
#define BKE_LIB_FOREACHID_PROCESS_IDSUPER(data_, id_super_, cb_flag_)
#define BLO_read_struct(reader, struct_name, ptr_p)
Object groups, one object can be in many groups at once.
#define C
Definition RandGen.cpp:29
#define BLI_assert_unreachable()
#define SET_FLAG_FROM_TEST(value, test, flag)
#define BLI_assert(a)
#define BLI_assert_msg(a, msg)
constexpr Span drop_front(int64_t n) const
Definition BLI_span.hh:175
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:141
constexpr Span()=default
constexpr const T & first() const
Definition BLI_span.hh:319
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr const T * end() const
Definition BLI_span.hh:228
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr const T * begin() const
Definition BLI_span.hh:224
constexpr Span take_front(int64_t n) const
Definition BLI_span.hh:197
void ensure(const FunctionRef< void()> compute_cache)
constexpr IndexRange()=default
const Value & lookup(const Key &key) const
Definition BLI_map.hh:545
constexpr T * data() const
Definition BLI_span.hh:545
constexpr MutableSpan drop_front(const int64_t n) const
Definition BLI_span.hh:613
constexpr MutableSpan take_front(const int64_t n) const
Definition BLI_span.hh:635
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
bool is_empty() const
Definition BLI_stack.hh:310
void push(const T &value)
Definition BLI_stack.hh:215
constexpr const char * c_str() const
constexpr StringRef()
const std::string & string() const
StringRefNull ref() const
void append(const T &value)
const nodes::SocketDeclaration * declaration
constexpr bool is_empty() const
constexpr int64_t size() const
void copy_unsafe(char *dst) const
constexpr const char * data() const
#define position
#define index(i)
#define select(A, B, C)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str)
Definition mallocn.cc:119
#define T
bool contains(const VArray< bool > &varray, const IndexMask &indices_to_check, bool value)
void item_write_struct(BlendWriter *writer, bNodeTreeInterfaceItem &item)
static void item_copy(bNodeTreeInterfaceItem &dst, const bNodeTreeInterfaceItem &src, int flag, UidGeneratorFn generate_uid)
static void pixel_subtype_forward_compat(BlendWriter *writer, bNodeTreeInterfaceItem &item)
static void socket_set_subtype(bNodeTreeInterfaceSocket &socket, const PropertySubType subtype)
static const Map< StringRef, StringRef > & subtype_pixel_to_none()
static size_t item_struct_size(const bNodeTreeInterfaceItem &item)
static void item_free(bNodeTreeInterfaceItem &item, const bool do_id_user)
static void item_write_data(BlendWriter *writer, bNodeTreeInterfaceItem &item)
static Span< bNodeTreeInterfaceItem * > item_children(bNodeTreeInterfaceItem &item)
static void item_read_data(BlendDataReader *reader, bNodeTreeInterfaceItem &item)
static void item_foreach_id(LibraryForeachIDData *data, bNodeTreeInterfaceItem &item)
static void panel_init(bNodeTreeInterfacePanel &panel, const Span< const bNodeTreeInterfaceItem * > items_src, const int flag, UidGeneratorFn generate_uid)
static StringRefNull socket_type_from_data(const bNodeTreeInterfaceSocket &socket)
StringRefNull socket_type_from_data_impl(const T &)
static void socket_data_read_data(BlendDataReader *reader, bNodeTreeInterfaceSocket &socket)
void socket_data_foreach_id_impl(LibraryForeachIDData *, T &)
static void * make_socket_data(const StringRef socket_type)
static void socket_data_free(bNodeTreeInterfaceSocket &socket, const bool do_id_user)
static void socket_data_write(BlendWriter *writer, bNodeTreeInterfaceSocket &socket)
static void socket_data_foreach_id(LibraryForeachIDData *data, bNodeTreeInterfaceSocket &socket)
bool socket_data_to_static_type(const StringRef socket_type, const Fn &fn)
static void socket_data_copy(bNodeTreeInterfaceSocket &dst, const bNodeTreeInterfaceSocket &src, int flag)
static const Map< StringRef, StringRef > & subtype_none_to_pixel()
static void socket_data_copy_ptr(bNodeTreeInterfaceSocket &dst, const void *src_socket_data, int flag)
static bool is_supported_socket_type(const StringRef socket_type)
void socket_data_write_impl(BlendWriter *writer, bNodeSocketValueFloat &data)
void socket_data_read_data_impl(BlendDataReader *reader, T **data)
T & get_item_as(bNodeTreeInterfaceItem &item)
static bNodeTreeInterfaceSocket * make_socket(const int uid, const StringRef name, const StringRef description, const StringRef socket_type, const NodeTreeInterfaceSocketFlag flag)
void item_reference_free(bNodeTreeInterfaceItemReference *item_reference)
static bNode * create_proxy_implicit_scene_frame_node(bContext &C, bNodeTree &tree)
static std::string get_socket_property_path(const bNodeTree &tree, const bNodeSocket &socket, const StringRefNull prop)
static bNodeTreeInterfacePanel * make_panel(const int uid, const StringRef name, const StringRef description, const NodeTreeInterfacePanelFlag flag)
bNode * create_proxy_implicit_input_node(eNodeSocketDatatype socket_type, NodeDefaultInputType default_input, bContext &C, bNodeTree &tree)
static std::string socket_basepath(const bNodeTree &tree, const bNodeSocket &socket)
bNodeTreeInterfaceSocket * add_interface_socket_from_node(bNodeTree &ntree, const bNode &from_node, const bNodeSocket &from_sock, std::optional< StringRef > name=std::nullopt, std::optional< eNodeSocketInOut > in_out=std::nullopt)
static std::string get_node_property_path(const bNodeTree &tree, const bNode &node, const StringRefNull prop)
bNode * create_proxy_converter_node(eNodeSocketDatatype socket_type, const bNodeTree &src_tree, const bNodeSocket *src_socket, bContext &C, bNodeTree &dst_tree, Vector< AnimationBasePathChange > &anim_basepaths)
bNode * create_proxy_const_input_node(eNodeSocketDatatype socket_type, const bNodeTree &src_tree, const bNodeSocket &src_socket, bContext &C, bNodeTree &dst_tree, Vector< AnimationBasePathChange > &anim_basepaths)
void free(Subdiv *subdiv)
Definition subdiv.cc:192
void * socket_value_copy(eNodeSocketDatatype type, const void *src, bool do_id_user)
Definition node.cc:3285
bNodeSocketType NodeSocketTypeUndefined
Definition node.cc:135
void * socket_value_new(eNodeSocketDatatype type, int subtype=0)
Definition node.cc:3274
bNode * node_add_node(const bContext *C, bNodeTree &ntree, UString idname, std::optional< int > unique_identifier=std::nullopt)
Definition node.cc:4260
void socket_value_free(eNodeSocketDatatype type, void *data, bool do_id_user)
Definition node.cc:3347
bNodeSocketType * node_socket_type_find(StringRef idname)
Definition node.cc:2966
bNodeSocketType * node_socket_type_find_static(int type, int subtype=0)
Definition node.cc:2975
void socket_value_copy_content(eNodeSocketDatatype type, void *dst, const void *src, bool do_id_user)
Definition node.cc:3312
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, UString identifier)
Definition node.cc:3036
std::optional< StringRefNull > node_static_socket_type(int type, int subtype, std::optional< int > dimensions=std::nullopt)
Definition node.cc:3492
StringRefNull node_socket_label(const bNodeSocket &sock)
Definition node.cc:5758
bool node_is_static_socket_type(const bNodeSocketType &stype)
Definition node.cc:3483
bool socket_type_supports_default_input_type(const bke::bNodeSocketType &socket_type, const NodeDefaultInputType input_type)
bool socket_type_supports_fields(const eNodeSocketDatatype socket_type)
bool socket_type_supports_grids(const eNodeSocketDatatype socket_type)
BMesh Iterators.
void BLO_read_struct_with_type_size(BlendDataReader *reader, T **ptr_p, FunctionRef< size_t(const T &data)> type_size_fn)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void IDP_FreeProperty_ex(IDProperty *prop, bool do_id_user)
Definition idprop.cc:1398
char * STRNCPY(char(&dst)[N], const char *src)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void BLO_read_pointer_array_and_validate_size(BlendDataReader *reader, T **ptr_p, SizeT *array_size)
void id_us_plus(ID *id)
Definition lib_id.cc:433
std::optional< std::string > RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
Definition rna_path.cc:1237
MINLINE void copy_v3_v3_int(int r[3], const int a[3])
void IDP_BlendWrite(BlendWriter *writer, const IDProperty *prop)
Definition idprop.cc:1696
void IDP_foreach_property(IDProperty *id_property_root, int type_filter, FunctionRef< void(IDProperty *id_property)> callback)
std::optional< std::string > RNA_path_from_ID_to_struct(const PointerRNA *ptr)
Definition rna_path.cc:1078
char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLO_read_data_invalidate(BlendDataReader *reader, const char *message)
Definition readfile.cc:6839
@ LIB_ID_CREATE_NO_USER_REFCOUNT
BMesh const char void * data
void BKE_ntree_update_after_single_tree_change(Main &bmain, bNodeTree &modified_tree, const NodeTreeUpdateExtraParams &params={})
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
static bool is_same_socket_base_type(const StringRef socket_type_a, const StringRef socket_type_b)
void BKE_ntree_update_tag_node_property(bNodeTree *ntree, bNode *node)
Main * CTX_data_main(const bContext *C)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
MINLINE void copy_v4_v4(float r[4], const float a[4])
IDProperty * IDP_CopyProperty_ex(const IDProperty *prop, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:968
@ IDP_TYPE_FILTER_ID
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
Definition readfile.cc:6653
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void write_pointer_array(int64_t num, const void *data)
void write_string(const char *data)
void write_struct_cast(const void *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
bool is_undo() const
bke::bNodeSocketType * typeinfo
eNodeSocketDatatype type
bke::bNodeSocketRuntime * runtime
NodeSocketInterfaceStructureType structure_type
bNodeTreeInterface tree_interface
eNodeTree_Type type
ListBaseT< bNodeSocket > inputs
Defines a socket type.
Definition BKE_node.hh:163
eNodeSocketDatatype type
Definition BKE_node.hh:198
void(*) draw_color_simple(const bNodeSocketType *socket_type, float *r_color)
Definition BKE_node.hh:177
void(*) interface_from_socket(ID *id, bNodeTreeInterfaceSocket *interface_socket, const bNode *node, const bNodeSocket *socket)
Definition BKE_node.hh:188