2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Blender Foundation (2008), Nathan Letwory, Robin Allen, Bob Holcomb
20 * ***** END GPL LICENSE BLOCK *****
23 /** \file blender/makesrna/intern/rna_nodetree.c
31 #include "BLI_listbase.h"
33 #include "BLI_string.h"
34 #include "BLI_utildefines.h"
36 #include "BLF_translation.h"
38 #include "DNA_material_types.h"
39 #include "DNA_mesh_types.h"
40 #include "DNA_node_types.h"
41 #include "DNA_object_types.h"
42 #include "DNA_scene_types.h"
43 #include "DNA_text_types.h"
44 #include "DNA_texture_types.h"
46 #include "BKE_animsys.h"
49 #include "BKE_image.h"
50 #include "BKE_texture.h"
51 #include "BKE_idprop.h"
53 #include "RNA_access.h"
54 #include "RNA_define.h"
55 #include "RNA_enum_types.h"
57 #include "rna_internal.h"
58 #include "rna_internal_types.h"
60 #include "IMB_imbuf.h"
61 #include "IMB_imbuf_types.h"
65 #include "MEM_guardedalloc.h"
67 EnumPropertyItem node_socket_in_out_items[] = {
68 { SOCK_IN, "IN", 0, "Input", "" },
69 { SOCK_OUT, "OUT", 0, "Output", "" },
70 { 0, NULL, 0, NULL, NULL }
74 static EnumPropertyItem node_socket_type_items[] = {
75 {SOCK_CUSTOM, "CUSTOM", 0, "Custom", ""},
76 {SOCK_FLOAT, "VALUE", 0, "Value", ""},
77 {SOCK_INT, "INT", 0, "Int", ""},
78 {SOCK_BOOLEAN, "BOOLEAN", 0, "Boolean", ""},
79 {SOCK_VECTOR, "VECTOR", 0, "Vector", ""},
80 {SOCK_STRING, "STRING", 0, "String", ""},
81 {SOCK_RGBA, "RGBA", 0, "RGBA", ""},
82 {SOCK_SHADER, "SHADER", 0, "Shader", ""},
83 {0, NULL, 0, NULL, NULL}
86 static EnumPropertyItem node_quality_items[] = {
87 {NTREE_QUALITY_HIGH, "HIGH", 0, "High", "High quality"},
88 {NTREE_QUALITY_MEDIUM, "MEDIUM", 0, "Medium", "Medium quality"},
89 {NTREE_QUALITY_LOW, "LOW", 0, "Low", "Low quality"},
90 {0, NULL, 0, NULL, NULL}
93 static EnumPropertyItem node_chunksize_items[] = {
94 {NTREE_CHUNCKSIZE_32, "32", 0, "32x32", "Chunksize of 32x32"},
95 {NTREE_CHUNCKSIZE_64, "64", 0, "64x64", "Chunksize of 64x64"},
96 {NTREE_CHUNCKSIZE_128, "128", 0, "128x128", "Chunksize of 128x128"},
97 {NTREE_CHUNCKSIZE_256, "256", 0, "256x256", "Chunksize of 256x256"},
98 {NTREE_CHUNCKSIZE_512, "512", 0, "512x512", "Chunksize of 512x512"},
99 {NTREE_CHUNCKSIZE_1024, "1024", 0, "1024x1024", "Chunksize of 1024x1024"},
100 {0, NULL, 0, NULL, NULL}
104 #define DEF_ICON_BLANK_SKIP
105 #define DEF_ICON(name) {ICON_##name, (#name), 0, (#name), ""},
106 #define DEF_VICO(name)
107 EnumPropertyItem node_icon_items[] = {
108 #include "UI_icons.h"
109 {0, NULL, 0, NULL, NULL}};
110 #undef DEF_ICON_BLANK_SKIP
114 EnumPropertyItem node_math_items[] = {
115 { 0, "ADD", 0, "Add", ""},
116 { 1, "SUBTRACT", 0, "Subtract", ""},
117 { 2, "MULTIPLY", 0, "Multiply", ""},
118 { 3, "DIVIDE", 0, "Divide", ""},
119 { 4, "SINE", 0, "Sine", ""},
120 { 5, "COSINE", 0, "Cosine", ""},
121 { 6, "TANGENT", 0, "Tangent", ""},
122 { 7, "ARCSINE", 0, "Arcsine", ""},
123 { 8, "ARCCOSINE", 0, "Arccosine", ""},
124 { 9, "ARCTANGENT", 0, "Arctangent", ""},
125 {10, "POWER", 0, "Power", ""},
126 {11, "LOGARITHM", 0, "Logarithm", ""},
127 {12, "MINIMUM", 0, "Minimum", ""},
128 {13, "MAXIMUM", 0, "Maximum", ""},
129 {14, "ROUND", 0, "Round", ""},
130 {15, "LESS_THAN", 0, "Less Than", ""},
131 {16, "GREATER_THAN", 0, "Greater Than", ""},
132 {17, "MODULO", 0, "Modulo", ""},
133 {0, NULL, 0, NULL, NULL}
136 EnumPropertyItem node_vec_math_items[] = {
137 {0, "ADD", 0, "Add", ""},
138 {1, "SUBTRACT", 0, "Subtract", ""},
139 {2, "AVERAGE", 0, "Average", ""},
140 {3, "DOT_PRODUCT", 0, "Dot Product", ""},
141 {4, "CROSS_PRODUCT", 0, "Cross Product", ""},
142 {5, "NORMALIZE", 0, "Normalize", ""},
143 {0, NULL, 0, NULL, NULL}
146 EnumPropertyItem node_filter_items[] = {
147 {0, "SOFTEN", 0, "Soften", ""},
148 {1, "SHARPEN", 0, "Sharpen", ""},
149 {2, "LAPLACE", 0, "Laplace", ""},
150 {3, "SOBEL", 0, "Sobel", ""},
151 {4, "PREWITT", 0, "Prewitt", ""},
152 {5, "KIRSCH", 0, "Kirsch", ""},
153 {6, "SHADOW", 0, "Shadow", ""},
154 {0, NULL, 0, NULL, NULL}
158 static EnumPropertyItem node_sampler_type_items[] = {
159 {0, "NEAREST", 0, "Nearest", ""},
160 {1, "BILINEAR", 0, "Bilinear", ""},
161 {2, "BICUBIC", 0, "Bicubic", ""},
162 {0, NULL, 0, NULL, NULL}
168 #include "BLI_linklist.h"
169 #include "BLI_string.h"
171 #include "BKE_context.h"
172 #include "BKE_idprop.h"
173 #include "BKE_library.h"
175 #include "BKE_global.h"
178 #include "ED_render.h"
180 #include "NOD_common.h"
181 #include "NOD_socket.h"
183 #include "RE_engine.h"
184 #include "RE_pipeline.h"
186 #include "DNA_scene_types.h"
190 int rna_node_tree_type_to_enum(bNodeTreeType *typeinfo)
192 int i = 0, result = -1;
193 NODE_TREE_TYPES_BEGIN (nt)
195 if (nt == typeinfo) {
205 int rna_node_tree_idname_to_enum(const char *idname)
207 int i = 0, result = -1;
208 NODE_TREE_TYPES_BEGIN (nt)
210 if (STREQ(nt->idname, idname)) {
220 bNodeTreeType *rna_node_tree_type_from_enum(int value)
223 bNodeTreeType *result = NULL;
224 NODE_TREE_TYPES_BEGIN (nt)
236 EnumPropertyItem *rna_node_tree_type_itemf(void *data, int (*poll)(void *data, bNodeTreeType *), bool *r_free)
238 EnumPropertyItem tmp = {0, "", 0, "", ""};
239 EnumPropertyItem *item = NULL;
240 int totitem = 0, i = 0;
242 NODE_TREE_TYPES_BEGIN (nt)
244 if (poll && !poll(data, nt)) {
250 tmp.identifier = nt->idname;
251 tmp.icon = nt->ui_icon;
252 tmp.name = nt->ui_name;
253 tmp.description = nt->ui_description;
255 RNA_enum_item_add(&item, &totitem, &tmp);
261 RNA_enum_item_end(&item, &totitem);
267 int rna_node_type_to_enum(bNodeType *typeinfo)
269 int i = 0, result = -1;
270 NODE_TYPES_BEGIN(ntype)
271 if (ntype == typeinfo) {
280 int rna_node_idname_to_enum(const char *idname)
282 int i = 0, result = -1;
283 NODE_TYPES_BEGIN(ntype)
284 if (STREQ(ntype->idname, idname)) {
293 bNodeType *rna_node_type_from_enum(int value)
296 bNodeType *result = NULL;
297 NODE_TYPES_BEGIN(ntype)
307 EnumPropertyItem *rna_node_type_itemf(void *data, int (*poll)(void *data, bNodeType *), bool *r_free)
309 EnumPropertyItem *item = NULL;
310 EnumPropertyItem tmp = {0, "", 0, "", ""};
311 int totitem = 0, i = 0;
313 NODE_TYPES_BEGIN(ntype)
314 if (poll && !poll(data, ntype)) {
320 tmp.identifier = ntype->idname;
321 tmp.icon = ntype->ui_icon;
322 tmp.name = ntype->ui_name;
323 tmp.description = ntype->ui_description;
325 RNA_enum_item_add(&item, &totitem, &tmp);
329 RNA_enum_item_end(&item, &totitem);
335 int rna_node_socket_type_to_enum(bNodeSocketType *typeinfo)
337 int i = 0, result = -1;
338 NODE_SOCKET_TYPES_BEGIN(stype)
339 if (stype == typeinfo) {
344 NODE_SOCKET_TYPES_END
348 int rna_node_socket_idname_to_enum(const char *idname)
350 int i = 0, result = -1;
351 NODE_SOCKET_TYPES_BEGIN(stype)
352 if (STREQ(stype->idname, idname)) {
357 NODE_SOCKET_TYPES_END
361 bNodeSocketType *rna_node_socket_type_from_enum(int value)
364 bNodeSocketType *result = NULL;
365 NODE_SOCKET_TYPES_BEGIN(stype)
371 NODE_SOCKET_TYPES_END
375 EnumPropertyItem *rna_node_socket_type_itemf(void *data, int (*poll)(void *data, bNodeSocketType *), bool *r_free)
377 EnumPropertyItem *item = NULL;
378 EnumPropertyItem tmp = {0, "", 0, "", ""};
379 int totitem = 0, i = 0;
382 NODE_SOCKET_TYPES_BEGIN(stype)
383 if (poll && !poll(data, stype)) {
388 srna = stype->ext_socket.srna;
390 tmp.identifier = stype->idname;
391 tmp.icon = RNA_struct_ui_icon(srna);
392 tmp.name = RNA_struct_ui_name(srna);
393 tmp.description = RNA_struct_ui_description(srna);
395 RNA_enum_item_add(&item, &totitem, &tmp);
398 NODE_SOCKET_TYPES_END
399 RNA_enum_item_end(&item, &totitem);
405 static EnumPropertyItem *rna_node_static_type_itemf(bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free)
407 EnumPropertyItem *item = NULL;
408 EnumPropertyItem tmp;
411 /* hack, don't want to add include path to RNA just for this, since in the future RNA types
412 * for nodes should be defined locally at runtime anyway ...
415 tmp.value = NODE_CUSTOM;
416 tmp.identifier = "CUSTOM";
418 tmp.description = "Custom Node";
419 tmp.icon = ICON_NONE;
420 RNA_enum_item_add(&item, &totitem, &tmp);
422 tmp.value = NODE_UNDEFINED;
423 tmp.identifier = "UNDEFINED";
424 tmp.name = "UNDEFINED";
425 tmp.description = "";
426 tmp.icon = ICON_NONE;
427 RNA_enum_item_add(&item, &totitem, &tmp);
429 #define DefNode(Category, ID, DefFunc, EnumName, StructName, UIName, UIDesc) \
430 if (STREQ(#Category, "Node")) { \
432 tmp.identifier = EnumName; \
434 tmp.description = UIDesc; \
435 tmp.icon = ICON_NONE; \
436 RNA_enum_item_add(&item, &totitem, &tmp); \
438 #include "../../nodes/NOD_static_types.h"
441 if (RNA_struct_is_a(ptr->type, &RNA_ShaderNode)) {
442 #define DefNode(Category, ID, DefFunc, EnumName, StructName, UIName, UIDesc) \
443 if (STREQ(#Category, "ShaderNode")) { \
445 tmp.identifier = EnumName; \
447 tmp.description = UIDesc; \
448 tmp.icon = ICON_NONE; \
449 RNA_enum_item_add(&item, &totitem, &tmp); \
451 #include "../../nodes/NOD_static_types.h"
455 if (RNA_struct_is_a(ptr->type, &RNA_CompositorNode)) {
456 #define DefNode(Category, ID, DefFunc, EnumName, StructName, UIName, UIDesc) \
457 if (STREQ(#Category, "CompositorNode")) { \
459 tmp.identifier = EnumName; \
461 tmp.description = UIDesc; \
462 tmp.icon = ICON_NONE; \
463 RNA_enum_item_add(&item, &totitem, &tmp); \
465 #include "../../nodes/NOD_static_types.h"
469 if (RNA_struct_is_a(ptr->type, &RNA_TextureNode)) {
470 #define DefNode(Category, ID, DefFunc, EnumName, StructName, UIName, UIDesc) \
471 if (STREQ(#Category, "TextureNode")) { \
473 tmp.identifier = EnumName; \
475 tmp.description = UIDesc; \
476 tmp.icon = ICON_NONE; \
477 RNA_enum_item_add(&item, &totitem, &tmp); \
479 #include "../../nodes/NOD_static_types.h"
483 RNA_enum_item_end(&item, &totitem);
489 /* ******** Node Tree ******** */
491 static StructRNA *rna_NodeTree_refine(struct PointerRNA *ptr)
493 bNodeTree *ntree = (bNodeTree *)ptr->data;
495 if (ntree->typeinfo->ext.srna)
496 return ntree->typeinfo->ext.srna;
498 return &RNA_NodeTree;
501 static int rna_NodeTree_poll(const bContext *C, bNodeTreeType *ntreetype)
503 extern FunctionRNA rna_NodeTree_poll_func;
511 RNA_pointer_create(NULL, ntreetype->ext.srna, NULL, &ptr); /* dummy */
512 func = &rna_NodeTree_poll_func; /* RNA_struct_find_function(&ptr, "poll"); */
514 RNA_parameter_list_create(&list, &ptr, func);
515 RNA_parameter_set_lookup(&list, "context", &C);
516 ntreetype->ext.call((bContext *)C, &ptr, func, &list);
518 RNA_parameter_get_lookup(&list, "visible", &ret);
519 visible = *(int *)ret;
521 RNA_parameter_list_free(&list);
526 static void rna_NodeTree_update_reg(bNodeTree *ntree)
528 extern FunctionRNA rna_NodeTree_update_func;
534 RNA_id_pointer_create(&ntree->id, &ptr);
535 func = &rna_NodeTree_update_func; /* RNA_struct_find_function(&ptr, "update"); */
537 RNA_parameter_list_create(&list, &ptr, func);
538 ntree->typeinfo->ext.call(NULL, &ptr, func, &list);
540 RNA_parameter_list_free(&list);
543 static void rna_NodeTree_get_from_context(const bContext *C, bNodeTreeType *ntreetype,
544 bNodeTree **r_ntree, ID **r_id, ID **r_from)
546 extern FunctionRNA rna_NodeTree_get_from_context_func;
551 void *ret1, *ret2, *ret3;
553 RNA_pointer_create(NULL, ntreetype->ext.srna, NULL, &ptr); /* dummy */
554 func = &rna_NodeTree_get_from_context_func; /* RNA_struct_find_function(&ptr, "get_from_context"); */
556 RNA_parameter_list_create(&list, &ptr, func);
557 RNA_parameter_set_lookup(&list, "context", &C);
558 ntreetype->ext.call((bContext *)C, &ptr, func, &list);
560 RNA_parameter_get_lookup(&list, "result_1", &ret1);
561 RNA_parameter_get_lookup(&list, "result_2", &ret2);
562 RNA_parameter_get_lookup(&list, "result_3", &ret3);
563 *r_ntree = *(bNodeTree **)ret1;
564 *r_id = *(ID **)ret2;
565 *r_from = *(ID **)ret3;
567 RNA_parameter_list_free(&list);
570 static void rna_NodeTree_unregister(Main *UNUSED(bmain), StructRNA *type)
572 bNodeTreeType *nt = RNA_struct_blender_type_get(type);
577 RNA_struct_free_extension(type, &nt->ext);
579 ntreeTypeFreeLink(nt);
581 RNA_struct_free(&BLENDER_RNA, type);
583 /* update while blender is running */
584 WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
587 static StructRNA *rna_NodeTree_register(
588 Main *bmain, ReportList *reports, void *data, const char *identifier,
589 StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
591 bNodeTreeType *nt, dummynt;
592 bNodeTree dummyntree;
594 int have_function[3];
596 /* setup dummy tree & tree type to store static properties in */
597 memset(&dummynt, 0, sizeof(bNodeTreeType));
598 memset(&dummyntree, 0, sizeof(bNodeTree));
599 dummyntree.typeinfo = &dummynt;
600 RNA_pointer_create(NULL, &RNA_NodeTree, &dummyntree, &dummyptr);
602 /* validate the python class */
603 if (validate(&dummyptr, data, have_function) != 0)
606 if (strlen(identifier) >= sizeof(dummynt.idname)) {
607 BKE_reportf(reports, RPT_ERROR, "Registering node tree class: '%s' is too long, maximum length is %d",
608 identifier, (int)sizeof(dummynt.idname));
612 /* check if we have registered this tree type before, and remove it */
613 nt = ntreeTypeFind(dummynt.idname);
615 rna_NodeTree_unregister(bmain, nt->ext.srna);
617 /* create a new node tree type */
618 nt = MEM_callocN(sizeof(bNodeTreeType), "node tree type");
619 memcpy(nt, &dummynt, sizeof(dummynt));
621 nt->type = NTREE_CUSTOM;
623 nt->ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, nt->idname, &RNA_NodeTree);
627 RNA_struct_blender_type_set(nt->ext.srna, nt);
629 RNA_def_struct_ui_text(nt->ext.srna, nt->ui_name, nt->ui_description);
630 RNA_def_struct_ui_icon(nt->ext.srna, nt->ui_icon);
632 nt->poll = (have_function[0]) ? rna_NodeTree_poll : NULL;
633 nt->update = (have_function[1]) ? rna_NodeTree_update_reg : NULL;
634 nt->get_from_context = (have_function[2]) ? rna_NodeTree_get_from_context : NULL;
638 /* update while blender is running */
639 WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
644 static bool rna_NodeTree_check(bNodeTree *ntree, ReportList *reports)
646 if (!ntreeIsRegistered(ntree)) {
648 BKE_reportf(reports, RPT_ERROR, "Node tree '%s' has undefined type %s", ntree->id.name + 2, ntree->idname);
656 static void rna_NodeTree_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
658 bNodeTree *ntree = (bNodeTree *)ptr->id.data;
660 /* when using border, make it so no old data from outside of
661 * border is hanging around
662 * ideally shouldn't be in RNA callback, but how to teach
663 * compo to only clear frame when border usage is actually
666 if (ntree->flag & NTREE_VIEWER_BORDER) {
667 Image *ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
669 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
673 memset(ibuf->rect, 0, 4 * ibuf->x * ibuf->y);
675 if (ibuf->rect_float)
676 memset(ibuf->rect_float, 0, 4 * ibuf->x * ibuf->y * sizeof(float));
678 ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
681 BKE_image_release_ibuf(ima, ibuf, lock);
684 WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
685 WM_main_add_notifier(NC_SCENE | ND_NODES, &ntree->id);
687 ED_node_tag_update_nodetree(bmain, ntree);
690 static bNode *rna_NodeTree_node_new(bNodeTree *ntree, bContext *C, ReportList *reports, const char *type)
695 if (!rna_NodeTree_check(ntree, reports))
698 ntype = nodeTypeFind(type);
700 BKE_reportf(reports, RPT_ERROR, "Node type %s undefined", type);
704 if (ntype->poll && !ntype->poll(ntype, ntree)) {
705 BKE_reportf(reports, RPT_ERROR, "Cannot add node of type %s to node tree '%s'", type, ntree->id.name + 2);
709 node = nodeAddNode(C, ntree, type);
710 BLI_assert(node && node->typeinfo);
712 if (ntree->type == NTREE_TEXTURE) {
713 ntreeTexCheckCyclics(ntree);
716 ntreeUpdateTree(CTX_data_main(C), ntree);
717 nodeUpdate(ntree, node);
718 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
723 static void rna_NodeTree_node_remove(bNodeTree *ntree, ReportList *reports, PointerRNA *node_ptr)
725 bNode *node = node_ptr->data;
727 if (!rna_NodeTree_check(ntree, reports))
730 if (BLI_findindex(&ntree->nodes, node) == -1) {
731 BKE_reportf(reports, RPT_ERROR, "Unable to locate node '%s' in node tree", node->name);
736 nodeFreeNode(ntree, node);
737 RNA_POINTER_INVALIDATE(node_ptr);
739 ntreeUpdateTree(G.main, ntree); /* update group node socket links */
740 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
743 static void rna_NodeTree_node_clear(bNodeTree *ntree, ReportList *reports)
745 bNode *node = ntree->nodes.first;
747 if (!rna_NodeTree_check(ntree, reports))
751 bNode *next_node = node->next;
756 nodeFreeNode(ntree, node);
761 ntreeUpdateTree(G.main, ntree);
763 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
766 static PointerRNA rna_NodeTree_active_node_get(PointerRNA *ptr)
768 bNodeTree *ntree = (bNodeTree *)ptr->data;
769 bNode *node = nodeGetActive(ntree);
770 return rna_pointer_inherit_refine(ptr, &RNA_Node, node);
773 static void rna_NodeTree_active_node_set(PointerRNA *ptr, const PointerRNA value)
775 bNodeTree *ntree = (bNodeTree *)ptr->data;
776 bNode *node = (bNode *)value.data;
778 if (node && BLI_findindex(&ntree->nodes, node) != -1)
779 nodeSetActive(ntree, node);
781 nodeClearActive(ntree);
784 static bNodeLink *rna_NodeTree_link_new(bNodeTree *ntree, ReportList *reports,
785 bNodeSocket *fromsock, bNodeSocket *tosock,
789 bNode *fromnode = NULL, *tonode = NULL;
791 if (!rna_NodeTree_check(ntree, reports))
794 nodeFindNode(ntree, fromsock, &fromnode, NULL);
795 nodeFindNode(ntree, tosock, &tonode, NULL);
796 /* check validity of the sockets:
797 * if sockets from different trees are passed in this will fail!
799 if (!fromnode || !tonode)
802 if (&fromsock->in_out == &tosock->in_out) {
803 BKE_report(reports, RPT_ERROR, "Same input/output direction of sockets");
808 /* remove other socket links if limit is exceeded */
809 if (nodeCountSocketLinks(ntree, fromsock) + 1 > fromsock->limit)
810 nodeRemSocketLinks(ntree, fromsock);
811 if (nodeCountSocketLinks(ntree, tosock) + 1 > tosock->limit)
812 nodeRemSocketLinks(ntree, tosock);
815 ret = nodeAddLink(ntree, fromnode, fromsock, tonode, tosock);
819 nodeUpdate(ntree, tonode);
821 ntreeUpdateTree(G.main, ntree);
823 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
828 static void rna_NodeTree_link_remove(bNodeTree *ntree, ReportList *reports, PointerRNA *link_ptr)
830 bNodeLink *link = link_ptr->data;
832 if (!rna_NodeTree_check(ntree, reports))
835 if (BLI_findindex(&ntree->links, link) == -1) {
836 BKE_report(reports, RPT_ERROR, "Unable to locate link in node tree");
840 nodeRemLink(ntree, link);
841 RNA_POINTER_INVALIDATE(link_ptr);
843 ntreeUpdateTree(G.main, ntree);
844 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
847 static void rna_NodeTree_link_clear(bNodeTree *ntree, ReportList *reports)
849 bNodeLink *link = ntree->links.first;
851 if (!rna_NodeTree_check(ntree, reports))
855 bNodeLink *next_link = link->next;
857 nodeRemLink(ntree, link);
861 ntreeUpdateTree(G.main, ntree);
863 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
866 static int rna_NodeTree_active_input_get(PointerRNA *ptr)
868 bNodeTree *ntree = (bNodeTree *)ptr->data;
872 for (gsock = ntree->inputs.first, index = 0; gsock; gsock = gsock->next, ++index)
873 if (gsock->flag & SELECT)
878 static void rna_NodeTree_active_input_set(PointerRNA *ptr, int value)
880 bNodeTree *ntree = (bNodeTree *)ptr->data;
884 for (gsock = ntree->inputs.first, index = 0; gsock; gsock = gsock->next, ++index) {
886 gsock->flag |= SELECT;
888 gsock->flag &= ~SELECT;
890 for (gsock = ntree->outputs.first; gsock; gsock = gsock->next) {
891 gsock->flag &= ~SELECT;
895 static int rna_NodeTree_active_output_get(PointerRNA *ptr)
897 bNodeTree *ntree = (bNodeTree *)ptr->data;
901 for (gsock = ntree->outputs.first, index = 0; gsock; gsock = gsock->next, ++index)
902 if (gsock->flag & SELECT)
907 static void rna_NodeTree_active_output_set(PointerRNA *ptr, int value)
909 bNodeTree *ntree = (bNodeTree *)ptr->data;
913 for (gsock = ntree->inputs.first; gsock; gsock = gsock->next) {
914 gsock->flag &= ~SELECT;
916 for (gsock = ntree->outputs.first, index = 0; gsock; gsock = gsock->next, ++index) {
918 gsock->flag |= SELECT;
920 gsock->flag &= ~SELECT;
924 static bNodeSocket *rna_NodeTree_inputs_new(bNodeTree *ntree, ReportList *reports, const char *type, const char *name)
928 if (!rna_NodeTree_check(ntree, reports))
931 sock = ntreeAddSocketInterface(ntree, SOCK_IN, type, name);
933 ntreeUpdateTree(G.main, ntree);
934 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
939 static bNodeSocket *rna_NodeTree_outputs_new(bNodeTree *ntree, ReportList *reports, const char *type, const char *name)
943 if (!rna_NodeTree_check(ntree, reports))
946 sock = ntreeAddSocketInterface(ntree, SOCK_OUT, type, name);
948 ntreeUpdateTree(G.main, ntree);
949 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
954 static void rna_NodeTree_socket_remove(bNodeTree *ntree, ReportList *reports, bNodeSocket *sock)
956 if (!rna_NodeTree_check(ntree, reports))
959 if (BLI_findindex(&ntree->inputs, sock) == -1 && BLI_findindex(&ntree->outputs, sock) == -1) {
960 BKE_reportf(reports, RPT_ERROR, "Unable to locate socket '%s' in node", sock->identifier);
963 ntreeRemoveSocketInterface(ntree, sock);
965 ntreeUpdateTree(G.main, ntree);
966 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
970 static void rna_NodeTree_inputs_clear(bNodeTree *ntree, ReportList *reports)
972 bNodeSocket *sock, *nextsock;
974 if (!rna_NodeTree_check(ntree, reports))
977 for (sock = ntree->inputs.first; sock; sock = nextsock) {
978 nextsock = sock->next;
979 ntreeRemoveSocketInterface(ntree, sock);
982 ntreeUpdateTree(G.main, ntree);
983 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
986 static void rna_NodeTree_outputs_clear(bNodeTree *ntree, ReportList *reports)
988 bNodeSocket *sock, *nextsock;
990 if (!rna_NodeTree_check(ntree, reports))
993 for (sock = ntree->outputs.first; sock; sock = nextsock) {
994 nextsock = sock->next;
995 ntreeRemoveSocketInterface(ntree, sock);
998 ntreeUpdateTree(G.main, ntree);
999 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
1002 static void rna_NodeTree_inputs_move(bNodeTree *ntree, int from_index, int to_index)
1006 if (from_index == to_index)
1008 if (from_index < 0 || to_index < 0)
1011 sock = BLI_findlink(&ntree->inputs, from_index);
1012 if (to_index < from_index) {
1013 bNodeSocket *nextsock = BLI_findlink(&ntree->inputs, to_index);
1015 BLI_remlink(&ntree->inputs, sock);
1016 BLI_insertlinkbefore(&ntree->inputs, nextsock, sock);
1020 bNodeSocket *prevsock = BLI_findlink(&ntree->inputs, to_index);
1022 BLI_remlink(&ntree->inputs, sock);
1023 BLI_insertlinkafter(&ntree->inputs, prevsock, sock);
1027 ntree->update |= NTREE_UPDATE_GROUP_IN;
1029 ntreeUpdateTree(G.main, ntree);
1030 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
1033 static void rna_NodeTree_outputs_move(bNodeTree *ntree, int from_index, int to_index)
1037 if (from_index == to_index)
1039 if (from_index < 0 || to_index < 0)
1042 sock = BLI_findlink(&ntree->outputs, from_index);
1043 if (to_index < from_index) {
1044 bNodeSocket *nextsock = BLI_findlink(&ntree->outputs, to_index);
1046 BLI_remlink(&ntree->outputs, sock);
1047 BLI_insertlinkbefore(&ntree->outputs, nextsock, sock);
1051 bNodeSocket *prevsock = BLI_findlink(&ntree->outputs, to_index);
1053 BLI_remlink(&ntree->outputs, sock);
1054 BLI_insertlinkafter(&ntree->outputs, prevsock, sock);
1058 ntree->update |= NTREE_UPDATE_GROUP_OUT;
1060 ntreeUpdateTree(G.main, ntree);
1061 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
1064 static void rna_NodeTree_interface_update(bNodeTree *ntree, bContext *C)
1066 ntree->update |= NTREE_UPDATE_GROUP;
1067 ntreeUpdateTree(G.main, ntree);
1069 ED_node_tag_update_nodetree(CTX_data_main(C), ntree);
1073 /* ******** NodeLink ******** */
1075 static int rna_NodeLink_is_hidden_get(PointerRNA *ptr)
1077 bNodeLink *link = ptr->data;
1078 return nodeLinkIsHidden(link);
1082 /* ******** Node ******** */
1084 static StructRNA *rna_Node_refine(struct PointerRNA *ptr)
1086 bNode *node = (bNode *)ptr->data;
1088 if (node->typeinfo->ext.srna)
1089 return node->typeinfo->ext.srna;
1094 static char *rna_Node_path(PointerRNA *ptr)
1096 bNode *node = (bNode *)ptr->data;
1097 char name_esc[sizeof(node->name) * 2];
1099 BLI_strescape(name_esc, node->name, sizeof(name_esc));
1100 return BLI_sprintfN("nodes[\"%s\"]", name_esc);
1103 char *rna_Node_ImageUser_path(PointerRNA *ptr)
1105 bNodeTree *ntree = (bNodeTree *)ptr->id.data;
1107 char name_esc[sizeof(node->name) * 2];
1109 for (node = ntree->nodes.first; node; node = node->next) {
1110 if (node->type == SH_NODE_TEX_ENVIRONMENT) {
1111 NodeTexEnvironment *data = node->storage;
1112 if (&data->iuser != ptr->data)
1115 else if (node->type == SH_NODE_TEX_IMAGE) {
1116 NodeTexImage *data = node->storage;
1117 if (&data->iuser != ptr->data)
1123 BLI_strescape(name_esc, node->name, sizeof(name_esc));
1124 return BLI_sprintfN("nodes[\"%s\"].image_user", name_esc);
1130 static int rna_Node_poll(bNodeType *ntype, bNodeTree *ntree)
1132 extern FunctionRNA rna_Node_poll_func;
1140 RNA_pointer_create(NULL, ntype->ext.srna, NULL, &ptr); /* dummy */
1141 func = &rna_Node_poll_func; /* RNA_struct_find_function(&ptr, "poll"); */
1143 RNA_parameter_list_create(&list, &ptr, func);
1144 RNA_parameter_set_lookup(&list, "node_tree", &ntree);
1145 ntype->ext.call(NULL, &ptr, func, &list);
1147 RNA_parameter_get_lookup(&list, "visible", &ret);
1148 visible = *(int *)ret;
1150 RNA_parameter_list_free(&list);
1155 static int rna_Node_poll_instance(bNode *node, bNodeTree *ntree)
1157 extern FunctionRNA rna_Node_poll_instance_func;
1165 RNA_pointer_create(NULL, node->typeinfo->ext.srna, node, &ptr); /* dummy */
1166 func = &rna_Node_poll_instance_func; /* RNA_struct_find_function(&ptr, "poll_instance"); */
1168 RNA_parameter_list_create(&list, &ptr, func);
1169 RNA_parameter_set_lookup(&list, "node_tree", &ntree);
1170 node->typeinfo->ext.call(NULL, &ptr, func, &list);
1172 RNA_parameter_get_lookup(&list, "visible", &ret);
1173 visible = *(int *)ret;
1175 RNA_parameter_list_free(&list);
1180 static int rna_Node_poll_instance_default(bNode *node, bNodeTree *ntree)
1182 /* use the basic poll function */
1183 return rna_Node_poll(node->typeinfo, ntree);
1186 static void rna_Node_update_reg(bNodeTree *ntree, bNode *node)
1188 extern FunctionRNA rna_Node_update_func;
1194 RNA_pointer_create((ID *)ntree, node->typeinfo->ext.srna, node, &ptr);
1195 func = &rna_Node_update_func; /* RNA_struct_find_function(&ptr, "update"); */
1197 RNA_parameter_list_create(&list, &ptr, func);
1198 node->typeinfo->ext.call(NULL, &ptr, func, &list);
1200 RNA_parameter_list_free(&list);
1203 static void rna_Node_init(const bContext *C, PointerRNA *ptr)
1205 extern FunctionRNA rna_Node_init_func;
1207 bNode *node = (bNode *)ptr->data;
1211 func = &rna_Node_init_func; /* RNA_struct_find_function(&ptr, "init"); */
1213 RNA_parameter_list_create(&list, ptr, func);
1214 node->typeinfo->ext.call((bContext *)C, ptr, func, &list);
1216 RNA_parameter_list_free(&list);
1219 static void rna_Node_copy(PointerRNA *ptr, struct bNode *copynode)
1221 extern FunctionRNA rna_Node_copy_func;
1223 bNode *node = (bNode *)ptr->data;
1227 func = &rna_Node_copy_func; /* RNA_struct_find_function(&ptr, "copy"); */
1229 RNA_parameter_list_create(&list, ptr, func);
1230 RNA_parameter_set_lookup(&list, "node", ©node);
1231 node->typeinfo->ext.call(NULL, ptr, func, &list);
1233 RNA_parameter_list_free(&list);
1236 static void rna_Node_free(PointerRNA *ptr)
1238 extern FunctionRNA rna_Node_free_func;
1240 bNode *node = (bNode *)ptr->data;
1244 func = &rna_Node_free_func; /* RNA_struct_find_function(&ptr, "free"); */
1246 RNA_parameter_list_create(&list, ptr, func);
1247 node->typeinfo->ext.call(NULL, ptr, func, &list);
1249 RNA_parameter_list_free(&list);
1252 static void rna_Node_draw_buttons(struct uiLayout *layout, bContext *C, PointerRNA *ptr)
1254 extern FunctionRNA rna_Node_draw_buttons_func;
1256 bNode *node = (bNode *)ptr->data;
1260 func = &rna_Node_draw_buttons_func; /* RNA_struct_find_function(&ptr, "draw_buttons"); */
1262 RNA_parameter_list_create(&list, ptr, func);
1263 RNA_parameter_set_lookup(&list, "context", &C);
1264 RNA_parameter_set_lookup(&list, "layout", &layout);
1265 node->typeinfo->ext.call(C, ptr, func, &list);
1267 RNA_parameter_list_free(&list);
1270 static void rna_Node_draw_buttons_ext(struct uiLayout *layout, bContext *C, PointerRNA *ptr)
1272 extern FunctionRNA rna_Node_draw_buttons_ext_func;
1274 bNode *node = (bNode *)ptr->data;
1278 func = &rna_Node_draw_buttons_ext_func; /* RNA_struct_find_function(&ptr, "draw_buttons_ext"); */
1280 RNA_parameter_list_create(&list, ptr, func);
1281 RNA_parameter_set_lookup(&list, "context", &C);
1282 RNA_parameter_set_lookup(&list, "layout", &layout);
1283 node->typeinfo->ext.call(C, ptr, func, &list);
1285 RNA_parameter_list_free(&list);
1288 static void rna_Node_draw_label(bNodeTree *ntree, bNode *node, char *label, int maxlen)
1290 extern FunctionRNA rna_Node_draw_label_func;
1298 func = &rna_Node_draw_label_func; /* RNA_struct_find_function(&ptr, "draw_label"); */
1300 RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr);
1301 RNA_parameter_list_create(&list, &ptr, func);
1302 node->typeinfo->ext.call(NULL, &ptr, func, &list);
1304 RNA_parameter_get_lookup(&list, "label", &ret);
1305 rlabel = *(char **)ret;
1306 BLI_strncpy(label, rlabel != NULL ? rlabel : "", maxlen);
1308 RNA_parameter_list_free(&list);
1311 static int rna_Node_is_registered_node_type(StructRNA *type)
1313 return (RNA_struct_blender_type_get(type) != NULL);
1316 static void rna_Node_is_registered_node_type_runtime(bContext *UNUSED(C), ReportList *UNUSED(reports), PointerRNA *ptr, ParameterList *parms)
1318 int result = (RNA_struct_blender_type_get(ptr->type) != NULL);
1319 RNA_parameter_set_lookup(parms, "result", &result);
1322 static void rna_Node_unregister(Main *UNUSED(bmain), StructRNA *type)
1324 bNodeType *nt = RNA_struct_blender_type_get(type);
1329 RNA_struct_free_extension(type, &nt->ext);
1331 /* this also frees the allocated nt pointer, no MEM_free call needed! */
1332 nodeUnregisterType(nt);
1334 RNA_struct_free(&BLENDER_RNA, type);
1336 /* update while blender is running */
1337 WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
1340 /* Generic internal registration function.
1341 * Can be used to implement callbacks for registerable RNA node subtypes.
1343 static bNodeType *rna_Node_register_base(Main *bmain, ReportList *reports, StructRNA *basetype,
1344 void *data, const char *identifier,
1345 StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
1347 bNodeType *nt, dummynt;
1349 PointerRNA dummyptr;
1352 int have_function[9];
1354 /* setup dummy node & node type to store static properties in */
1355 memset(&dummynt, 0, sizeof(bNodeType));
1356 /* this does some additional initialization of default values */
1357 node_type_base_custom(&dummynt, identifier, "", 0, 0);
1359 memset(&dummynode, 0, sizeof(bNode));
1360 dummynode.typeinfo = &dummynt;
1361 RNA_pointer_create(NULL, basetype, &dummynode, &dummyptr);
1363 /* validate the python class */
1364 if (validate(&dummyptr, data, have_function) != 0)
1367 if (strlen(identifier) >= sizeof(dummynt.idname)) {
1368 BKE_reportf(reports, RPT_ERROR, "Registering node class: '%s' is too long, maximum length is %d",
1369 identifier, (int)sizeof(dummynt.idname));
1373 /* check if we have registered this node type before, and remove it */
1374 nt = nodeTypeFind(dummynt.idname);
1376 rna_Node_unregister(bmain, nt->ext.srna);
1378 /* create a new node type */
1379 nt = MEM_callocN(sizeof(bNodeType), "node type");
1380 memcpy(nt, &dummynt, sizeof(dummynt));
1381 /* make sure the node type struct is freed on unregister */
1384 nt->ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, nt->idname, basetype);
1385 nt->ext.data = data;
1386 nt->ext.call = call;
1387 nt->ext.free = free;
1388 RNA_struct_blender_type_set(nt->ext.srna, nt);
1390 RNA_def_struct_ui_text(nt->ext.srna, nt->ui_name, nt->ui_description);
1391 RNA_def_struct_ui_icon(nt->ext.srna, nt->ui_icon);
1393 func = RNA_def_function_runtime(nt->ext.srna, "is_registered_node_type", rna_Node_is_registered_node_type_runtime);
1394 RNA_def_function_ui_description(func, "True if a registered node type");
1395 RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_SELF_TYPE);
1396 parm = RNA_def_boolean(func, "result", false, "Result", "");
1397 RNA_def_function_return(func, parm);
1399 /* XXX bad level call! needed to initialize the basic draw functions ... */
1400 ED_init_custom_node_type(nt);
1402 nt->poll = (have_function[0]) ? rna_Node_poll : NULL;
1403 nt->poll_instance = (have_function[1]) ? rna_Node_poll_instance : rna_Node_poll_instance_default;
1404 nt->updatefunc = (have_function[2]) ? rna_Node_update_reg : NULL;
1405 nt->initfunc_api = (have_function[3]) ? rna_Node_init : NULL;
1406 nt->copyfunc_api = (have_function[4]) ? rna_Node_copy : NULL;
1407 nt->freefunc_api = (have_function[5]) ? rna_Node_free : NULL;
1408 nt->draw_buttons = (have_function[6]) ? rna_Node_draw_buttons : NULL;
1409 nt->draw_buttons_ex = (have_function[7]) ? rna_Node_draw_buttons_ext : NULL;
1410 nt->labelfunc = (have_function[8]) ? rna_Node_draw_label : NULL;
1412 /* sanitize size values in case not all have been registered */
1413 if (nt->maxwidth < nt->minwidth)
1414 nt->maxwidth = nt->minwidth;
1415 if (nt->maxheight < nt->minheight)
1416 nt->maxheight = nt->minheight;
1417 CLAMP(nt->width, nt->minwidth, nt->maxwidth);
1418 CLAMP(nt->height, nt->minheight, nt->maxheight);
1423 static StructRNA *rna_Node_register(
1424 Main *bmain, ReportList *reports,
1425 void *data, const char *identifier,
1426 StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
1428 bNodeType *nt = rna_Node_register_base(bmain, reports, &RNA_Node, data, identifier, validate, call, free);
1432 nodeRegisterType(nt);
1434 /* update while blender is running */
1435 WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
1437 return nt->ext.srna;
1440 static StructRNA *rna_ShaderNode_register(
1441 Main *bmain, ReportList *reports,
1442 void *data, const char *identifier,
1443 StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
1445 bNodeType *nt = rna_Node_register_base(bmain, reports, &RNA_ShaderNode, data, identifier, validate, call, free);
1449 nodeRegisterType(nt);
1451 /* update while blender is running */
1452 WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
1454 return nt->ext.srna;
1457 static StructRNA *rna_CompositorNode_register(
1458 Main *bmain, ReportList *reports,
1459 void *data, const char *identifier,
1460 StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
1462 bNodeType *nt = rna_Node_register_base(bmain, reports, &RNA_CompositorNode, data, identifier, validate, call, free);
1466 nodeRegisterType(nt);
1468 /* update while blender is running */
1469 WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
1471 return nt->ext.srna;
1474 static StructRNA *rna_TextureNode_register(
1475 Main *bmain, ReportList *reports,
1476 void *data, const char *identifier,
1477 StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
1479 bNodeType *nt = rna_Node_register_base(bmain, reports, &RNA_TextureNode, data, identifier, validate, call, free);
1483 nodeRegisterType(nt);
1485 /* update while blender is running */
1486 WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
1488 return nt->ext.srna;
1491 static IDProperty *rna_Node_idprops(PointerRNA *ptr, bool create)
1493 bNode *node = ptr->data;
1495 if (create && !node->prop) {
1496 IDPropertyTemplate val = {0};
1497 node->prop = IDP_New(IDP_GROUP, &val, "RNA_Node ID properties");
1503 static void rna_Node_parent_set(PointerRNA *ptr, PointerRNA value)
1505 bNode *node = ptr->data;
1506 bNode *parent = value.data;
1509 /* XXX only Frame node allowed for now,
1510 * in the future should have a poll function or so to test possible attachment.
1512 if (parent->type != NODE_FRAME)
1515 /* make sure parent is not attached to the node */
1516 if (nodeAttachNodeCheck(parent, node))
1520 nodeDetachNode(node);
1522 nodeAttachNode(node, parent);
1526 static int rna_Node_parent_poll(PointerRNA *ptr, PointerRNA value)
1528 bNode *node = ptr->data;
1529 bNode *parent = value.data;
1531 /* XXX only Frame node allowed for now,
1532 * in the future should have a poll function or so to test possible attachment.
1534 if (parent->type != NODE_FRAME)
1537 /* make sure parent is not attached to the node */
1538 if (nodeAttachNodeCheck(parent, node))
1544 static void rna_Node_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
1546 bNodeTree *ntree = (bNodeTree *)ptr->id.data;
1547 ED_node_tag_update_nodetree(bmain, ntree);
1550 static void rna_Node_socket_value_update(ID *id, bNode *UNUSED(node), bContext *C)
1552 ED_node_tag_update_nodetree(CTX_data_main(C), (bNodeTree *)id);
1555 static void rna_Node_select_set(PointerRNA *ptr, int value)
1557 bNode *node = (bNode *)ptr->data;
1558 nodeSetSelected(node, value);
1561 static void rna_Node_name_set(PointerRNA *ptr, const char *value)
1563 bNodeTree *ntree = (bNodeTree *)ptr->id.data;
1564 bNode *node = (bNode *)ptr->data;
1565 char oldname[sizeof(node->name)];
1567 /* make a copy of the old name first */
1568 BLI_strncpy(oldname, node->name, sizeof(node->name));
1570 BLI_strncpy_utf8(node->name, value, sizeof(node->name));
1572 nodeUniqueName(ntree, node);
1574 /* fix all the animation data which may link to this */
1575 BKE_all_animdata_fix_paths_rename(NULL, "nodes", oldname, node->name);
1578 static bNodeSocket *rna_Node_inputs_new(ID *id, bNode *node, ReportList *reports, const char *type, const char *name, const char *identifier)
1580 bNodeTree *ntree = (bNodeTree *)id;
1583 sock = nodeAddSocket(ntree, node, SOCK_IN, type, identifier, name);
1586 BKE_report(reports, RPT_ERROR, "Unable to create socket");
1589 ntreeUpdateTree(G.main, ntree);
1590 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
1596 static bNodeSocket *rna_Node_outputs_new(ID *id, bNode *node, ReportList *reports, const char *type, const char *name, const char *identifier)
1598 bNodeTree *ntree = (bNodeTree *)id;
1601 sock = nodeAddSocket(ntree, node, SOCK_OUT, type, identifier, name);
1604 BKE_reportf(reports, RPT_ERROR, "Unable to create socket");
1607 ntreeUpdateTree(G.main, ntree);
1608 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
1614 static void rna_Node_socket_remove(ID *id, bNode *node, ReportList *reports, bNodeSocket *sock)
1616 bNodeTree *ntree = (bNodeTree *)id;
1618 if (BLI_findindex(&node->inputs, sock) == -1 && BLI_findindex(&node->outputs, sock) == -1) {
1619 BKE_reportf(reports, RPT_ERROR, "Unable to locate socket '%s' in node", sock->identifier);
1622 nodeRemoveSocket(ntree, node, sock);
1624 ntreeUpdateTree(G.main, ntree);
1625 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
1629 static void rna_Node_inputs_clear(ID *id, bNode *node)
1631 bNodeTree *ntree = (bNodeTree *)id;
1632 bNodeSocket *sock, *nextsock;
1634 for (sock = node->inputs.first; sock; sock = nextsock) {
1635 nextsock = sock->next;
1636 nodeRemoveSocket(ntree, node, sock);
1639 ntreeUpdateTree(G.main, ntree);
1640 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
1643 static void rna_Node_outputs_clear(ID *id, bNode *node)
1645 bNodeTree *ntree = (bNodeTree *)id;
1646 bNodeSocket *sock, *nextsock;
1648 for (sock = node->outputs.first; sock; sock = nextsock) {
1649 nextsock = sock->next;
1650 nodeRemoveSocket(ntree, node, sock);
1653 ntreeUpdateTree(G.main, ntree);
1654 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
1657 static void rna_Node_inputs_move(ID *id, bNode *node, int from_index, int to_index)
1659 bNodeTree *ntree = (bNodeTree *)id;
1662 if (from_index == to_index)
1664 if (from_index < 0 || to_index < 0)
1667 sock = BLI_findlink(&node->inputs, from_index);
1668 if (to_index < from_index) {
1669 bNodeSocket *nextsock = BLI_findlink(&node->inputs, to_index);
1671 BLI_remlink(&node->inputs, sock);
1672 BLI_insertlinkbefore(&node->inputs, nextsock, sock);
1676 bNodeSocket *prevsock = BLI_findlink(&node->inputs, to_index);
1678 BLI_remlink(&node->inputs, sock);
1679 BLI_insertlinkafter(&node->inputs, prevsock, sock);
1683 ntreeUpdateTree(G.main, ntree);
1684 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
1687 static void rna_Node_outputs_move(ID *id, bNode *node, int from_index, int to_index)
1689 bNodeTree *ntree = (bNodeTree *)id;
1692 if (from_index == to_index)
1694 if (from_index < 0 || to_index < 0)
1697 sock = BLI_findlink(&node->outputs, from_index);
1698 if (to_index < from_index) {
1699 bNodeSocket *nextsock = BLI_findlink(&node->outputs, to_index);
1701 BLI_remlink(&node->outputs, sock);
1702 BLI_insertlinkbefore(&node->outputs, nextsock, sock);
1706 bNodeSocket *prevsock = BLI_findlink(&node->outputs, to_index);
1708 BLI_remlink(&node->outputs, sock);
1709 BLI_insertlinkafter(&node->outputs, prevsock, sock);
1713 ntreeUpdateTree(G.main, ntree);
1714 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
1717 static void rna_Node_width_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
1719 bNode *node = ptr->data;
1720 *min = *softmin = node->typeinfo->minwidth;
1721 *max = *softmax = node->typeinfo->maxwidth;
1724 static void rna_Node_height_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
1726 bNode *node = ptr->data;
1727 *min = *softmin = node->typeinfo->minheight;
1728 *max = *softmax = node->typeinfo->maxheight;
1731 static void rna_Node_dimensions_get(PointerRNA *ptr, float *value)
1733 bNode *node = ptr->data;
1734 value[0] = node->totr.xmax - node->totr.xmin;
1735 value[1] = node->totr.ymax - node->totr.ymin;
1739 /* ******** Node Socket ******** */
1741 static void rna_NodeSocket_draw(bContext *C, struct uiLayout *layout, PointerRNA *ptr, PointerRNA *node_ptr, const char *text)
1743 extern FunctionRNA rna_NodeSocket_draw_func;
1745 bNodeSocket *sock = (bNodeSocket *)ptr->data;
1749 func = &rna_NodeSocket_draw_func; /* RNA_struct_find_function(&ptr, "draw"); */
1751 RNA_parameter_list_create(&list, ptr, func);
1752 RNA_parameter_set_lookup(&list, "context", &C);
1753 RNA_parameter_set_lookup(&list, "layout", &layout);
1754 RNA_parameter_set_lookup(&list, "node", node_ptr);
1755 RNA_parameter_set_lookup(&list, "text", &text);
1756 sock->typeinfo->ext_socket.call(C, ptr, func, &list);
1758 RNA_parameter_list_free(&list);
1761 static void rna_NodeSocket_draw_color(bContext *C, PointerRNA *ptr, PointerRNA *node_ptr, float *r_color)
1763 extern FunctionRNA rna_NodeSocket_draw_color_func;
1765 bNodeSocket *sock = (bNodeSocket *)ptr->data;
1770 func = &rna_NodeSocket_draw_color_func; /* RNA_struct_find_function(&ptr, "draw_color"); */
1772 RNA_parameter_list_create(&list, ptr, func);
1773 RNA_parameter_set_lookup(&list, "context", &C);
1774 RNA_parameter_set_lookup(&list, "node", node_ptr);
1775 sock->typeinfo->ext_socket.call(C, ptr, func, &list);
1777 RNA_parameter_get_lookup(&list, "color", &ret);
1778 copy_v4_v4(r_color, (float *)ret);
1780 RNA_parameter_list_free(&list);
1783 static void rna_NodeSocket_unregister(Main *UNUSED(bmain), StructRNA *type)
1785 bNodeSocketType *st = RNA_struct_blender_type_get(type);
1789 RNA_struct_free_extension(type, &st->ext_socket);
1791 nodeUnregisterSocketType(st);
1793 RNA_struct_free(&BLENDER_RNA, type);
1795 /* update while blender is running */
1796 WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
1799 static StructRNA *rna_NodeSocket_register(
1800 Main *UNUSED(bmain), ReportList *reports, void *data, const char *identifier,
1801 StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
1803 bNodeSocketType *st, dummyst;
1804 bNodeSocket dummysock;
1805 PointerRNA dummyptr;
1806 int have_function[2];
1808 /* setup dummy socket & socket type to store static properties in */
1809 memset(&dummyst, 0, sizeof(bNodeSocketType));
1811 memset(&dummysock, 0, sizeof(bNodeSocket));
1812 dummysock.typeinfo = &dummyst;
1813 RNA_pointer_create(NULL, &RNA_NodeSocket, &dummysock, &dummyptr);
1815 /* validate the python class */
1816 if (validate(&dummyptr, data, have_function) != 0)
1819 if (strlen(identifier) >= sizeof(dummyst.idname)) {
1820 BKE_reportf(reports, RPT_ERROR, "Registering node socket class: '%s' is too long, maximum length is %d",
1821 identifier, (int)sizeof(dummyst.idname));
1825 /* check if we have registered this socket type before */
1826 st = nodeSocketTypeFind(dummyst.idname);
1828 /* create a new node socket type */
1829 st = MEM_callocN(sizeof(bNodeSocketType), "node socket type");
1830 memcpy(st, &dummyst, sizeof(dummyst));
1832 nodeRegisterSocketType(st);
1835 /* if RNA type is already registered, unregister first */
1836 if (st->ext_socket.srna) {
1837 StructRNA *srna = st->ext_socket.srna;
1838 RNA_struct_free_extension(srna, &st->ext_socket);
1839 RNA_struct_free(&BLENDER_RNA, srna);
1841 st->ext_socket.srna = RNA_def_struct_ptr(&BLENDER_RNA, st->idname, &RNA_NodeSocket);
1842 st->ext_socket.data = data;
1843 st->ext_socket.call = call;
1844 st->ext_socket.free = free;
1845 RNA_struct_blender_type_set(st->ext_socket.srna, st);
1847 /* XXX bad level call! needed to initialize the basic draw functions ... */
1848 ED_init_custom_node_socket_type(st);
1850 st->draw = (have_function[0]) ? rna_NodeSocket_draw : NULL;
1851 st->draw_color = (have_function[1]) ? rna_NodeSocket_draw_color : NULL;
1853 /* update while blender is running */
1854 WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
1856 return st->ext_socket.srna;
1859 static StructRNA *rna_NodeSocket_refine(PointerRNA *ptr)
1861 bNodeSocket *sock = (bNodeSocket *)ptr->data;
1863 if (sock->typeinfo->ext_socket.srna)
1864 return sock->typeinfo->ext_socket.srna;
1866 return &RNA_NodeSocket;
1869 static char *rna_NodeSocket_path(PointerRNA *ptr)
1871 bNodeTree *ntree = (bNodeTree *)ptr->id.data;
1872 bNodeSocket *sock = (bNodeSocket *)ptr->data;
1875 char name_esc[sizeof(node->name) * 2];
1877 if (!nodeFindNode(ntree, sock, &node, &socketindex))
1880 BLI_strescape(name_esc, node->name, sizeof(name_esc));
1882 if (sock->in_out == SOCK_IN) {
1883 return BLI_sprintfN("nodes[\"%s\"].inputs[%d]", name_esc, socketindex);
1886 return BLI_sprintfN("nodes[\"%s\"].outputs[%d]", name_esc, socketindex);
1890 static IDProperty *rna_NodeSocket_idprops(PointerRNA *ptr, bool create)
1892 bNodeSocket *sock = ptr->data;
1894 if (create && !sock->prop) {
1895 IDPropertyTemplate val = {0};
1896 sock->prop = IDP_New(IDP_GROUP, &val, "RNA_NodeSocket ID properties");
1902 static PointerRNA rna_NodeSocket_node_get(PointerRNA *ptr)
1904 bNodeTree *ntree = (bNodeTree *)ptr->id.data;
1905 bNodeSocket *sock = (bNodeSocket *)ptr->data;
1909 nodeFindNode(ntree, sock, &node, NULL);
1911 RNA_pointer_create((ID *)ntree, &RNA_Node, node, &r_ptr);
1915 static void rna_NodeSocket_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
1917 bNodeTree *ntree = (bNodeTree *)ptr->id.data;
1918 ED_node_tag_update_nodetree(bmain, ntree);
1921 static int rna_NodeSocket_is_output_get(PointerRNA *ptr)
1923 bNodeSocket *sock = ptr->data;
1924 return sock->in_out == SOCK_OUT;
1927 static void rna_NodeSocket_link_limit_set(PointerRNA *ptr, int value)
1929 bNodeSocket *sock = ptr->data;
1930 sock->limit = (value == 0 ? 0xFFF : value);
1933 static void rna_NodeSocket_hide_set(PointerRNA *ptr, int value)
1935 bNodeSocket *sock = (bNodeSocket *)ptr->data;
1937 /* don't hide linked sockets */
1938 if (sock->flag & SOCK_IN_USE)
1942 sock->flag |= SOCK_HIDDEN;
1944 sock->flag &= ~SOCK_HIDDEN;
1948 static void rna_NodeSocketInterface_draw(bContext *C, struct uiLayout *layout, PointerRNA *ptr)
1950 extern FunctionRNA rna_NodeSocketInterface_draw_func;
1952 bNodeSocket *stemp = (bNodeSocket *)ptr->data;
1956 if (!stemp->typeinfo)
1959 func = &rna_NodeSocketInterface_draw_func; /* RNA_struct_find_function(&ptr, "draw"); */
1961 RNA_parameter_list_create(&list, ptr, func);
1962 RNA_parameter_set_lookup(&list, "context", &C);
1963 RNA_parameter_set_lookup(&list, "layout", &layout);
1964 stemp->typeinfo->ext_interface.call(C, ptr, func, &list);
1966 RNA_parameter_list_free(&list);
1969 static void rna_NodeSocketInterface_draw_color(bContext *C, PointerRNA *ptr, float *r_color)
1971 extern FunctionRNA rna_NodeSocketInterface_draw_color_func;
1973 bNodeSocket *sock = (bNodeSocket *)ptr->data;
1978 if (!sock->typeinfo)
1981 func = &rna_NodeSocketInterface_draw_color_func; /* RNA_struct_find_function(&ptr, "draw_color"); */
1983 RNA_parameter_list_create(&list, ptr, func);
1984 RNA_parameter_set_lookup(&list, "context", &C);
1985 sock->typeinfo->ext_interface.call(C, ptr, func, &list);
1987 RNA_parameter_get_lookup(&list, "color", &ret);
1988 copy_v4_v4(r_color, (float *)ret);
1990 RNA_parameter_list_free(&list);
1993 static void rna_NodeSocketInterface_register_properties(bNodeTree *ntree, bNodeSocket *stemp, StructRNA *data_srna)
1995 extern FunctionRNA rna_NodeSocketInterface_register_properties_func;
2001 if (!stemp->typeinfo)
2004 RNA_pointer_create((ID *)ntree, &RNA_NodeSocketInterface, stemp, &ptr);
2005 func = &rna_NodeSocketInterface_register_properties_func; /* RNA_struct_find_function(&ptr, "register_properties"); */
2007 RNA_parameter_list_create(&list, &ptr, func);
2008 RNA_parameter_set_lookup(&list, "data_rna_type", &data_srna);
2009 stemp->typeinfo->ext_interface.call(NULL, &ptr, func, &list);
2011 RNA_parameter_list_free(&list);
2014 static void rna_NodeSocketInterface_init_socket(bNodeTree *ntree, bNodeSocket *stemp, bNode *node, bNodeSocket *sock, const char *data_path)
2016 extern FunctionRNA rna_NodeSocketInterface_init_socket_func;
2018 PointerRNA ptr, node_ptr, sock_ptr;
2022 if (!stemp->typeinfo)
2025 RNA_pointer_create((ID *)ntree, &RNA_NodeSocketInterface, stemp, &ptr);
2026 RNA_pointer_create((ID *)ntree, &RNA_Node, node, &node_ptr);
2027 RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &sock_ptr);
2028 func = &rna_NodeSocketInterface_init_socket_func; /* RNA_struct_find_function(&ptr, "init_socket"); */
2030 RNA_parameter_list_create(&list, &ptr, func);
2031 RNA_parameter_set_lookup(&list, "node", &node_ptr);
2032 RNA_parameter_set_lookup(&list, "socket", &sock_ptr);
2033 RNA_parameter_set_lookup(&list, "data_path", &data_path);
2034 stemp->typeinfo->ext_interface.call(NULL, &ptr, func, &list);
2036 RNA_parameter_list_free(&list);
2039 static void rna_NodeSocketInterface_from_socket(bNodeTree *ntree, bNodeSocket *stemp, bNode *node, bNodeSocket *sock)
2041 extern FunctionRNA rna_NodeSocketInterface_from_socket_func;
2043 PointerRNA ptr, node_ptr, sock_ptr;
2047 if (!stemp->typeinfo)
2050 RNA_pointer_create((ID *)ntree, &RNA_NodeSocketInterface, stemp, &ptr);
2051 RNA_pointer_create((ID *)ntree, &RNA_Node, node, &node_ptr);
2052 RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &sock_ptr);
2053 func = &rna_NodeSocketInterface_from_socket_func; /* RNA_struct_find_function(&ptr, "from_socket"); */
2055 RNA_parameter_list_create(&list, &ptr, func);
2056 RNA_parameter_set_lookup(&list, "node", &node_ptr);
2057 RNA_parameter_set_lookup(&list, "socket", &sock_ptr);
2058 stemp->typeinfo->ext_interface.call(NULL, &ptr, func, &list);
2060 RNA_parameter_list_free(&list);
2063 static void rna_NodeSocketInterface_unregister(Main *UNUSED(bmain), StructRNA *type)
2065 bNodeSocketType *st = RNA_struct_blender_type_get(type);
2069 RNA_struct_free_extension(type, &st->ext_interface);
2071 RNA_struct_free(&BLENDER_RNA, type);
2073 /* update while blender is running */
2074 WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
2077 static StructRNA *rna_NodeSocketInterface_register(
2078 Main *UNUSED(bmain), ReportList *UNUSED(reports), void *data, const char *identifier,
2079 StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
2081 bNodeSocketType *st, dummyst;
2082 bNodeSocket dummysock;
2083 PointerRNA dummyptr;
2084 int have_function[5];
2086 /* setup dummy socket & socket type to store static properties in */
2087 memset(&dummyst, 0, sizeof(bNodeSocketType));
2089 memset(&dummysock, 0, sizeof(bNodeSocket));
2090 dummysock.typeinfo = &dummyst;
2091 RNA_pointer_create(NULL, &RNA_NodeSocketInterface, &dummysock, &dummyptr);
2093 /* validate the python class */
2094 if (validate(&dummyptr, data, have_function) != 0)
2097 /* check if we have registered this socket type before */
2098 st = nodeSocketTypeFind(dummyst.idname);
2100 /* basic socket type registered by a socket class before. */
2103 /* create a new node socket type */
2104 st = MEM_callocN(sizeof(bNodeSocketType), "node socket type");
2105 memcpy(st, &dummyst, sizeof(dummyst));
2107 nodeRegisterSocketType(st);
2110 /* if RNA type is already registered, unregister first */
2111 if (st->ext_interface.srna) {
2112 StructRNA *srna = st->ext_interface.srna;
2113 RNA_struct_free_extension(srna, &st->ext_interface);
2114 RNA_struct_free(&BLENDER_RNA, srna);
2116 st->ext_interface.srna = RNA_def_struct_ptr(&BLENDER_RNA, identifier, &RNA_NodeSocketInterface);
2117 st->ext_interface.data = data;
2118 st->ext_interface.call = call;
2119 st->ext_interface.free = free;
2120 RNA_struct_blender_type_set(st->ext_interface.srna, st);
2122 st->interface_draw = (have_function[0]) ? rna_NodeSocketInterface_draw : NULL;
2123 st->interface_draw_color = (have_function[1]) ? rna_NodeSocketInterface_draw_color : NULL;
2124 st->interface_register_properties = (have_function[2]) ? rna_NodeSocketInterface_register_properties : NULL;
2125 st->interface_init_socket = (have_function[3]) ? rna_NodeSocketInterface_init_socket : NULL;
2126 st->interface_from_socket = (have_function[4]) ? rna_NodeSocketInterface_from_socket : NULL;
2128 /* update while blender is running */
2129 WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
2131 return st->ext_interface.srna;
2134 static StructRNA *rna_NodeSocketInterface_refine(PointerRNA *ptr)
2136 bNodeSocket *sock = (bNodeSocket *)ptr->data;
2138 if (sock->typeinfo && sock->typeinfo->ext_interface.srna)
2139 return sock->typeinfo->ext_interface.srna;
2141 return &RNA_NodeSocketInterface;
2144 static char *rna_NodeSocketInterface_path(PointerRNA *ptr)
2146 bNodeTree *ntree = (bNodeTree *)ptr->id.data;
2147 bNodeSocket *sock = (bNodeSocket *)ptr->data;
2150 socketindex = BLI_findindex(&ntree->inputs, sock);
2151 if (socketindex != -1)
2152 return BLI_sprintfN("inputs[%d]", socketindex);
2154 socketindex = BLI_findindex(&ntree->outputs, sock);
2155 if (socketindex != -1)
2156 return BLI_sprintfN("outputs[%d]", socketindex);
2161 static IDProperty *rna_NodeSocketInterface_idprops(PointerRNA *ptr, bool create)
2163 bNodeSocket *sock = ptr->data;
2165 if (create && !sock->prop) {
2166 IDPropertyTemplate val = {0};
2167 sock->prop = IDP_New(IDP_GROUP, &val, "RNA_NodeSocketInterface ID properties");
2173 static void rna_NodeSocketInterface_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
2175 bNodeTree *ntree = ptr->id.data;
2176 bNodeSocket *stemp = ptr->data;
2178 if (!stemp->typeinfo)
2181 ntree->update |= NTREE_UPDATE_GROUP;
2182 ntreeUpdateTree(G.main, ntree);
2184 ED_node_tag_update_nodetree(bmain, ntree);
2188 /* ******** Standard Node Socket Base Types ******** */
2190 static void rna_NodeSocketStandard_draw(ID *id, bNodeSocket *sock, struct bContext *C, struct uiLayout *layout, PointerRNA *nodeptr,
2194 RNA_pointer_create(id, &RNA_NodeSocket, sock, &ptr);
2195 sock->typeinfo->draw(C, layout, &ptr, nodeptr, text);
2198 static void rna_NodeSocketStandard_draw_color(ID *id, bNodeSocket *sock, struct bContext *C, PointerRNA *nodeptr, float *r_color)
2201 RNA_pointer_create(id, &RNA_NodeSocket, sock, &ptr);
2202 sock->typeinfo->draw_color(C, &ptr, nodeptr, r_color);
2205 static void rna_NodeSocketInterfaceStandard_draw(ID *id, bNodeSocket *sock, struct bContext *C, struct uiLayout *layout)
2208 RNA_pointer_create(id, &RNA_NodeSocket, sock, &ptr);
2209 sock->typeinfo->interface_draw(C, layout, &ptr);
2212 static void rna_NodeSocketInterfaceStandard_draw_color(ID *id, bNodeSocket *sock, struct bContext *C, float *r_color)
2215 RNA_pointer_create(id, &RNA_NodeSocket, sock, &ptr);
2216 sock->typeinfo->interface_draw_color(C, &ptr, r_color);
2219 static void rna_NodeSocketStandard_float_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
2221 bNodeSocket *sock = ptr->data;
2222 bNodeSocketValueFloat *dval = sock->default_value;
2223 int subtype = sock->typeinfo->subtype;
2225 *min = (subtype == PROP_UNSIGNED ? 0.0f : -FLT_MAX);
2227 *softmin = dval->min;
2228 *softmax = dval->max;
2231 static void rna_NodeSocketStandard_int_range(PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax)
2233 bNodeSocket *sock = ptr->data;
2234 bNodeSocketValueInt *dval = sock->default_value;
2235 int subtype = sock->typeinfo->subtype;
2237 *min = (subtype == PROP_UNSIGNED ? 0 : INT_MIN);
2239 *softmin = dval->min;
2240 *softmax = dval->max;
2243 static void rna_NodeSocketStandard_vector_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
2245 bNodeSocket *sock = ptr->data;
2246 bNodeSocketValueVector *dval = sock->default_value;
2250 *softmin = dval->min;
2251 *softmax = dval->max;
2254 /* using a context update function here, to avoid searching the node if possible */
2255 static void rna_NodeSocketStandard_value_update(struct bContext *C, PointerRNA *ptr)
2259 /* default update */
2260 rna_NodeSocket_update(CTX_data_main(C), CTX_data_scene(C), ptr);
2262 /* try to use node from context, faster */
2263 node = CTX_data_pointer_get(C, "node").data;
2265 bNodeTree *ntree = ptr->id.data;
2266 bNodeSocket *sock = ptr->data;
2268 /* fall back to searching node in the tree */
2269 nodeFindNode(ntree, sock, &node, NULL);
2273 nodeSynchronizeID(node, true);
2277 /* ******** Node Types ******** */
2279 static void rna_NodeInternalSocketTemplate_name_get(PointerRNA *ptr, char *value)
2281 bNodeSocketTemplate *stemp = ptr->data;
2282 strcpy(value, stemp->name);
2285 static int rna_NodeInternalSocketTemplate_name_length(PointerRNA *ptr)
2287 bNodeSocketTemplate *stemp = ptr->data;
2288 return strlen(stemp->name);
2291 static void rna_NodeInternalSocketTemplate_identifier_get(PointerRNA *ptr, char *value)
2293 bNodeSocketTemplate *stemp = ptr->data;
2294 strcpy(value, stemp->identifier);
2297 static int rna_NodeInternalSocketTemplate_identifier_length(PointerRNA *ptr)
2299 bNodeSocketTemplate *stemp = ptr->data;
2300 return strlen(stemp->identifier);
2303 static int rna_NodeInternalSocketTemplate_type_get(PointerRNA *ptr)
2305 bNodeSocketTemplate *stemp = ptr->data;
2309 static PointerRNA rna_NodeInternal_input_template(StructRNA *srna, int index)
2311 bNodeType *ntype = RNA_struct_blender_type_get(srna);
2312 if (ntype && ntype->inputs) {
2313 bNodeSocketTemplate *stemp = ntype->inputs;
2315 while (i < index && stemp->type >= 0) {
2319 if (i == index && stemp->type >= 0) {
2321 RNA_pointer_create(NULL, &RNA_NodeInternalSocketTemplate, stemp, &ptr);
2325 return PointerRNA_NULL;
2328 static PointerRNA rna_NodeInternal_output_template(StructRNA *srna, int index)
2330 bNodeType *ntype = RNA_struct_blender_type_get(srna);
2331 if (ntype && ntype->outputs) {
2332 bNodeSocketTemplate *stemp = ntype->outputs;
2334 while (i < index && stemp->type >= 0) {
2338 if (i == index && stemp->type >= 0) {
2340 RNA_pointer_create(NULL, &RNA_NodeInternalSocketTemplate, stemp, &ptr);
2344 return PointerRNA_NULL;
2347 static int rna_NodeInternal_poll(StructRNA *srna, bNodeTree *ntree)
2349 bNodeType *ntype = RNA_struct_blender_type_get(srna);
2350 return ntype && (!ntype->poll || ntype->poll(ntype, ntree));
2353 static int rna_NodeInternal_poll_instance(bNode *node, bNodeTree *ntree)
2355 bNodeType *ntype = node->typeinfo;
2356 if (ntype->poll_instance) {
2357 return ntype->poll_instance(node, ntree);
2360 /* fall back to basic poll function */
2361 return !ntype->poll || ntype->poll(ntype, ntree);
2365 static void rna_NodeInternal_update(ID *id, bNode *node)
2367 bNodeTree *ntree = (bNodeTree *)id;
2368 if (node->typeinfo->updatefunc)
2369 node->typeinfo->updatefunc(ntree, node);
2372 static void rna_NodeInternal_draw_buttons(ID *id, bNode *node, struct bContext *C, struct uiLayout *layout)
2374 if (node->typeinfo->draw_buttons) {
2376 RNA_pointer_create(id, &RNA_Node, node, &ptr);
2377 node->typeinfo->draw_buttons(layout, C, &ptr);
2381 static void rna_NodeInternal_draw_buttons_ext(ID *id, bNode *node, struct bContext *C, struct uiLayout *layout)
2383 if (node->typeinfo->draw_buttons_ex) {
2385 RNA_pointer_create(id, &RNA_Node, node, &ptr);
2386 node->typeinfo->draw_buttons_ex(layout, C, &ptr);
2388 else if (node->typeinfo->draw_buttons) {
2390 RNA_pointer_create(id, &RNA_Node, node, &ptr);
2391 node->typeinfo->draw_buttons(layout, C, &ptr);
2395 static StructRNA *rna_NodeCustomGroup_register(
2396 Main *bmain, ReportList *reports,
2397 void *data, const char *identifier,
2398 StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
2400 bNodeType *nt = rna_Node_register_base(bmain, reports, &RNA_NodeCustomGroup, data, identifier, validate, call, free);
2404 /* this updates the group node instance from the tree's interface */
2405 nt->verifyfunc = node_group_verify;
2407 nodeRegisterType(nt);
2409 /* update while blender is running */
2410 WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
2412 return nt->ext.srna;
2415 static void rna_CompositorNode_tag_need_exec(bNode *node)
2417 node->need_exec = true;
2420 static void rna_Node_tex_image_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
2422 bNodeTree *ntree = (bNodeTree *)ptr->id.data;
2424 ED_node_tag_update_nodetree(bmain, ntree);
2425 WM_main_add_notifier(NC_IMAGE, NULL);
2428 static void rna_Node_material_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
2430 bNodeTree *ntree = (bNodeTree *)ptr->id.data;
2431 bNode *node = (bNode *)ptr->data;
2434 nodeSetActive(ntree, node);
2436 ED_node_tag_update_nodetree(bmain, ntree);
2439 static void rna_NodeGroup_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
2441 bNodeTree *ntree = (bNodeTree *)ptr->id.data;
2442 bNode *node = (bNode *)ptr->data;
2445 ntreeUpdateTree(bmain, (bNodeTree *)node->id);
2447 ED_node_tag_update_nodetree(bmain, ntree);
2450 static void rna_NodeGroup_node_tree_set(PointerRNA *ptr, const PointerRNA value)
2452 bNodeTree *ntree = ptr->id.data;
2453 bNode *node = ptr->data;
2454 bNodeTree *ngroup = value.data;
2456 if (nodeGroupPoll(ntree, ngroup)) {
2458 id_us_min(node->id);
2460 id_us_plus(&ngroup->id);
2462 node->id = &ngroup->id;
2466 static int rna_NodeGroup_node_tree_poll(PointerRNA *ptr, const PointerRNA value)
2468 bNodeTree *ntree = ptr->id.data;
2469 bNodeTree *ngroup = value.data;
2471 /* only allow node trees of the same type as the group node's tree */
2472 if (ngroup->type != ntree->type)
2475 return nodeGroupPoll(ntree, ngroup);
2479 static StructRNA *rna_NodeGroup_interface_typef(PointerRNA *ptr)
2481 bNode *node = ptr->data;
2482 bNodeTree *ngroup = (bNodeTree *)node->id;
2485 StructRNA *srna = ntreeInterfaceTypeGet(ngroup, true);
2489 return &RNA_PropertyGroup;
2492 static StructRNA *rna_NodeGroupInputOutput_interface_typef(PointerRNA *ptr)
2494 bNodeTree *ntree = ptr->id.data;
2497 StructRNA *srna = ntreeInterfaceTypeGet(ntree, true);
2501 return &RNA_PropertyGroup;
2504 static void rna_distance_matte_t1_set(PointerRNA *ptr, float value)
2506 bNode *node = (bNode *)ptr->data;
2507 NodeChroma *chroma = node->storage;
2512 static void rna_distance_matte_t2_set(PointerRNA *ptr, float value)
2514 bNode *node = (bNode *)ptr->data;
2515 NodeChroma *chroma = node->storage;
2520 static void rna_difference_matte_t1_set(PointerRNA *ptr, float value)
2522 bNode *node = (bNode *)ptr->data;
2523 NodeChroma *chroma = node->storage;
2528 static void rna_difference_matte_t2_set(PointerRNA *ptr, float value)
2530 bNode *node = (bNode *)ptr->data;
2531 NodeChroma *chroma = node->storage;
2536 /* Button Set Funcs for Matte Nodes */
2537 static void rna_Matte_t1_set(PointerRNA *ptr, float value)
2539 bNode *node = (bNode *)ptr->data;
2540 NodeChroma *chroma = node->storage;
2544 if (value < chroma->t2)
2548 static void rna_Matte_t2_set(PointerRNA *ptr, float value)
2550 bNode *node = (bNode *)ptr->data;
2551 NodeChroma *chroma = node->storage;
2553 if (value > chroma->t1)
2559 static void rna_Node_scene_set(PointerRNA *ptr, PointerRNA value)
2561 bNode *node = (bNode *)ptr->data;
2564 id_us_min(node->id);
2568 node->id = value.data;
2570 id_us_plus(node->id);
2573 static void rna_Node_image_layer_update(Main *bmain, Scene *scene, PointerRNA *ptr)
2575 bNode *node = (bNode *)ptr->data;
2576 Image *ima = (Image *)node->id;
2577 ImageUser *iuser = node->storage;
2579 BKE_image_multilayer_index(ima->rr, iuser);
2580 BKE_image_signal(ima, iuser, IMA_SIGNAL_SRC_CHANGE);
2582 rna_Node_update(bmain, scene, ptr);
2585 static EnumPropertyItem *renderresult_layers_add_enum(RenderLayer *rl)
2587 EnumPropertyItem *item = NULL;
2588 EnumPropertyItem tmp = {0, "", 0, "", ""};
2589 int i = 0, totitem = 0;
2592 tmp.identifier = rl->name;
2593 /* little trick: using space char instead empty string makes the item selectable in the dropdown */
2594 if (rl->name[0] == '\0')
2597 tmp.name = rl->name;
2599 RNA_enum_item_add(&item, &totitem, &tmp);
2603 RNA_enum_item_end(&item, &totitem);
2608 static EnumPropertyItem *rna_Node_image_layer_itemf(bContext *UNUSED(C), PointerRNA *ptr,
2609 PropertyRNA *UNUSED(prop), bool *r_free)
2611 bNode *node = (bNode *)ptr->data;
2612 Image *ima = (Image *)node->id;
2613 EnumPropertyItem *item = NULL;
2616 if (ima && ima->rr) {
2617 rl = ima->rr->layers.first;
2618 item = renderresult_layers_add_enum(rl);
2622 RNA_enum_item_end(&item, &totitem);
2630 static EnumPropertyItem *rna_Node_scene_layer_itemf(bContext *UNUSED(C), PointerRNA *ptr,
2631 PropertyRNA *UNUSED(prop), bool *r_free)
2633 bNode *node = (bNode *)ptr->data;
2634 Scene *sce = (Scene *)node->id;
2635 EnumPropertyItem *item = NULL;
2639 rl = sce->r.layers.first;
2640 item = renderresult_layers_add_enum(rl);
2644 RNA_enum_item_end(&item, &totitem);
2652 static EnumPropertyItem *rna_Node_channel_itemf(bContext *UNUSED(C), PointerRNA *ptr,
2653 PropertyRNA *UNUSED(prop), bool *r_free)
2655 bNode *node = (bNode *)ptr->data;
2656 EnumPropertyItem *item = NULL;
2657 EnumPropertyItem tmp = {0, "", 0, "", ""};
2660 switch (node->custom1) {
2661 case CMP_NODE_CHANNEL_MATTE_CS_RGB:
2662 tmp.identifier = "R"; tmp.name = "R"; tmp.value = 1;
2663 RNA_enum_item_add(&item, &totitem, &tmp);
2664 tmp.identifier = "G"; tmp.name = "G"; tmp.value = 2;
2665 RNA_enum_item_add(&item, &totitem, &tmp);
2666 tmp.identifier = "B"; tmp.name = "B"; tmp.value = 3;
2667 RNA_enum_item_add(&item, &totitem, &tmp);
2669 case CMP_NODE_CHANNEL_MATTE_CS_HSV:
2670 tmp.identifier = "H"; tmp.name = "H"; tmp.value = 1;
2671 RNA_enum_item_add(&item, &totitem, &tmp);
2672 tmp.identifier = "S"; tmp.name = "S"; tmp.value = 2;
2673 RNA_enum_item_add(&item, &totitem, &tmp);
2674 tmp.identifier = "V"; tmp.name = "V"; tmp.value = 3;
2675 RNA_enum_item_add(&item, &totitem, &tmp);
2677 case CMP_NODE_CHANNEL_MATTE_CS_YUV:
2678 tmp.identifier = "Y"; tmp.name = "Y"; tmp.value = 1;
2679 RNA_enum_item_add(&item, &totitem, &tmp);
2680 tmp.identifier = "G"; tmp.name = "U"; tmp.value = 2;
2681 RNA_enum_item_add(&item, &totitem, &tmp);
2682 tmp.identifier = "V"; tmp.name = "V"; tmp.value = 3;
2683 RNA_enum_item_add(&item, &totitem, &tmp);
2685 case CMP_NODE_CHANNEL_MATTE_CS_YCC:
2686 tmp.identifier = "Y"; tmp.name = "Y"; tmp.value = 1;
2687 RNA_enum_item_add(&item, &totitem, &tmp);
2688 tmp.identifier = "CB"; tmp.name = "Cr"; tmp.value = 2;
2689 RNA_enum_item_add(&item, &totitem, &tmp);
2690 tmp.identifier = "CR"; tmp.name = "Cb"; tmp.value = 3;
2691 RNA_enum_item_add(&item, &totitem, &tmp);
2697 RNA_enum_item_end(&item, &totitem);
2703 static void rna_Image_Node_update_id(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
2705 bNodeTree *ntree = (bNodeTree *)ptr->id.data;
2706 bNode *node = (bNode *)ptr->data;
2708 node->update |= NODE_UPDATE_ID;
2709 nodeUpdate(ntree, node); /* to update image node sockets */
2712 static void rna_Mapping_Node_update(Main *bmain, Scene *scene, PointerRNA *ptr)
2714 bNode *node = ptr->data;
2715 init_tex_mapping(node->storage);
2716 rna_Node_update(bmain, scene, ptr);
2719 static void rna_NodeOutputFile_slots_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
2721 bNode *node = ptr->data;
2722 rna_iterator_listbase_begin(iter, &node->inputs, NULL);
2725 static PointerRNA rna_NodeOutputFile_slot_file_get(CollectionPropertyIterator *iter)
2728 bNodeSocket *sock = rna_iterator_listbase_get(iter);
2729 RNA_pointer_create(iter->parent.id.data, &RNA_NodeOutputFileSlotFile, sock->storage, &ptr);
2733 static void rna_NodeColorBalance_update_lgg(Main *bmain, Scene *scene, PointerRNA *ptr)
2735 ntreeCompositColorBalanceSyncFromLGG(ptr->id.data, ptr->data);
2736 rna_Node_update(bmain, scene, ptr);
2739 static void rna_NodeColorBalance_update_cdl(Main *bmain, Scene *scene, PointerRNA *ptr)
2741 ntreeCompositColorBalanceSyncFromCDL(ptr->id.data, ptr->data);
2742 rna_Node_update(bmain, scene, ptr);
2745 /* ******** Node Socket Types ******** */
2747 static PointerRNA rna_NodeOutputFile_slot_layer_get(CollectionPropertyIterator *iter)
2750 bNodeSocket *sock = rna_iterator_listbase_get(iter);
2751 RNA_pointer_create(iter->parent.id.data, &RNA_NodeOutputFileSlotLayer, sock->storage, &ptr);
2755 static int rna_NodeOutputFileSocket_find_node(bNodeTree *ntree, NodeImageMultiFileSocket *data, bNode **nodep, bNodeSocket **sockp)
2760 for (node = ntree->nodes.first; node; node = node->next) {
2761 for (sock = node->inputs.first; sock; sock = sock->next) {
2762 NodeImageMultiFileSocket *sockdata = sock->storage;
2763 if (sockdata == data) {
2776 static void rna_NodeOutputFileSlotFile_path_set(PointerRNA *ptr, const char *value)
2778 bNodeTree *ntree = ptr->id.data;
2779 NodeImageMultiFileSocket *sockdata = ptr->data;
2783 if (rna_NodeOutputFileSocket_find_node(ntree, sockdata, &node, &sock)) {
2784 ntreeCompositOutputFileSetPath(node, sock, value);
2788 static void rna_NodeOutputFileSlotLayer_name_set(PointerRNA *ptr, const char *value)
2790 bNodeTree *ntree = ptr->id.data;
2791 NodeImageMultiFileSocket *sockdata = ptr->data;
2795 if (rna_NodeOutputFileSocket_find_node(ntree, sockdata, &node, &sock)) {
2796 ntreeCompositOutputFileSetLayer(node, sock, value);
2800 static bNodeSocket *rna_NodeOutputFile_slots_new(ID *id, bNode *node, bContext *C, ReportList *UNUSED(reports), const char *name)
2802 bNodeTree *ntree = (bNodeTree *)id;
2803 Scene *scene = CTX_data_scene(C);
2804 ImageFormatData *im_format = NULL;
2807 im_format = &scene->r.im_format;
2809 sock = ntreeCompositOutputFileAddSocket(ntree, node, name, im_format);
2811 ntreeUpdateTree(CTX_data_main(C), ntree);
2812 WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
2817 static void rna_ShaderNodeScript_mode_set(PointerRNA *ptr, int value)
2819 bNode *node = (bNode *)ptr->data;
2820 NodeShaderScript *nss = node->storage;
2822 if (nss->mode != value) {
2824 nss->filepath[0] = '\0';
2825 nss->flag &= ~NODE_SCRIPT_AUTO_UPDATE;
2827 /* replace text datablock by filepath */
2829 Text *text = (Text *)node->id;
2831 if (value == NODE_SCRIPT_EXTERNAL && text->name) {
2832 BLI_strncpy(nss->filepath, text->name, sizeof(nss->filepath));
2833 BLI_path_rel(nss->filepath, G.main->name);
2836 id_us_min(node->id);
2840 /* remove any bytecode */
2841 if (nss->bytecode) {
2842 MEM_freeN(nss->bytecode);
2843 nss->bytecode = NULL;
2846 nss->bytecode_hash[0] = '\0';
2850 static void rna_ShaderNodeScript_bytecode_get(PointerRNA *ptr, char *value)
2852 bNode *node = (bNode *)ptr->data;
2853 NodeShaderScript *nss = node->storage;
2855 strcpy(value, (nss->bytecode) ? nss->bytecode : "");
2858 static int rna_ShaderNodeScript_bytecode_length(PointerRNA *ptr)
2860 bNode *node = (bNode *)ptr->data;
2861 NodeShaderScript *nss = node->storage;
2863 return (nss->bytecode) ? strlen(nss->bytecode) : 0;
2866 static void rna_ShaderNodeScript_bytecode_set(PointerRNA *ptr, const char *value)
2868 bNode *node = (bNode *)ptr->data;
2869 NodeShaderScript *nss = node->storage;
2872 MEM_freeN(nss->bytecode);
2874 if (value && value[0])
2875 nss->bytecode = BLI_strdup(value);
2877 nss->bytecode = NULL;
2880 static void rna_ShaderNodeScript_update(Main *bmain, Scene *scene, PointerRNA *ptr)
2882 bNodeTree *ntree = (bNodeTree *)ptr->id.data;
2883 bNode *node = (bNode *)ptr->data;
2884 RenderEngineType *engine_type = RE_engines_find(scene->r.engine);
2886 if (engine_type && engine_type->update_script_node) {
2887 /* auto update node */
2888 RenderEngine *engine = RE_engine_create(engine_type);
2889 engine_type->update_script_node(engine, ntree, node);
2890 RE_engine_free(engine);
2893 ED_node_tag_update_nodetree(bmain, ntree);
2896 static void rna_ShaderNodeSubsurface_update(Main *bmain, Scene *scene, PointerRNA *ptr)
2898 bNodeTree *ntree = (bNodeTree *)ptr->id.data;
2899 bNode *node = (bNode *)ptr->data;
2901 nodeUpdate(ntree, node);
2902 rna_Node_update(bmain, scene, ptr);
2905 static void rna_CompositorNodeScale_update(Main *bmain, Scene *scene, PointerRNA *ptr)
2907 bNodeTree *ntree = (bNodeTree *)ptr->id.data;
2908 bNode *node = (bNode *)ptr->data;
2910 nodeUpdate(ntree, node);
2911 rna_Node_update(bmain, scene, ptr);
2916 static EnumPropertyItem prop_image_layer_items[] = {
2917 { 0, "PLACEHOLDER", 0, "Placeholder", ""},
2918 {0, NULL, 0, NULL, NULL}
2921 static EnumPropertyItem prop_scene_layer_items[] = {
2922 { 0, "PLACEHOLDER", 0, "Placeholder", ""},
2923 {0, NULL, 0, NULL, NULL}
2926 static EnumPropertyItem prop_tri_channel_items[] = {
2927 { 1, "R", 0, "R", ""},
2928 { 2, "G", 0, "G", ""},
2929 { 3, "B", 0, "B", ""},
2930 {0, NULL, 0, NULL, NULL}
2933 static EnumPropertyItem node_flip_items[] = {
2934 {0, "X", 0, "Flip X", ""},
2935 {1, "Y", 0, "Flip Y", ""},
2936 {2, "XY", 0, "Flip X & Y", ""},
2937 {0, NULL, 0, NULL, NULL}
2940 static EnumPropertyItem node_ycc_items[] = {
2941 { 0, "ITUBT601", 0, "ITU 601", ""},
2942 { 1, "ITUBT709", 0, "ITU 709", ""},
2943 { 2, "JFIF", 0, "Jpeg", ""},
2944 {0, NULL, 0, NULL, NULL}
2947 static EnumPropertyItem node_glossy_items[] = {
2948 {SHD_GLOSSY_SHARP, "SHARP", 0, "Sharp", ""},
2949 {SHD_GLOSSY_BECKMANN, "BECKMANN", 0, "Beckmann", ""},
2950 {SHD_GLOSSY_GGX, "GGX", 0, "GGX", ""},
2951 {0, NULL, 0, NULL, NULL}
2954 static EnumPropertyItem node_toon_items[] = {
2955 {SHD_TOON_DIFFUSE, "DIFFUSE", 0, "Diffuse", ""},
2956 {SHD_TOON_GLOSSY, "GLOSSY", 0, "Glossy", ""},
2957 {0, NULL, 0, NULL, NULL}
2960 static EnumPropertyItem node_hair_items[] = {
2961 {SHD_HAIR_REFLECTION, "Reflection", 0, "Reflection", ""},
2962 {SHD_HAIR_TRANSMISSION, "Transmission", 0, "Transmission", ""},
2963 {0, NULL, 0, NULL, NULL}
2966 static EnumPropertyItem node_script_mode_items[] = {
2967 {NODE_SCRIPT_INTERNAL, "INTERNAL", 0, "Internal", "Use internal text datablock"},
2968 {NODE_SCRIPT_EXTERNAL, "EXTERNAL", 0, "External", "Use external .osl or .oso file"},
2969 {0, NULL, 0, NULL, NULL}
2972 /* -- Common nodes ---------------------------------------------------------- */
2974 static void def_group_input(StructRNA *srna)
2978 prop = RNA_def_property(srna, "interface", PROP_POINTER, PROP_NONE);
2979 RNA_def_property_pointer_funcs(prop, NULL, NULL, "rna_NodeGroupInputOutput_interface_typef", NULL);
2980 RNA_def_property_struct_type(prop, "PropertyGroup");
2981 RNA_def_property_flag(prop, PROP_IDPROPERTY);
2982 RNA_def_property_ui_text(prop, "Interface", "Interface socket data");
2985 static void def_group_output(StructRNA *srna)
2989 prop = RNA_def_property(srna, "interface", PROP_POINTER, PROP_NONE);
2990 RNA_def_property_pointer_funcs(prop, NULL, NULL, "rna_NodeGroupInputOutput_interface_typef", NULL);
2991 RNA_def_property_struct_type(prop, "PropertyGroup");
2992 RNA_def_property_flag(prop, PROP_IDPROPERTY);
2993 RNA_def_property_ui_text(prop, "Interface", "Interface socket data");
2995 prop = RNA_def_property(srna, "is_active_output", PROP_BOOLEAN, PROP_NONE);
2996 RNA_def_property_boolean_sdna(prop, NULL, "flag", NODE_DO_OUTPUT);
2997 RNA_def_property_ui_text(prop, "Active Output", "True if this node is used as the active group output");
2998 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3001 static void def_group(StructRNA *srna)
3005 prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
3006 RNA_def_property_pointer_sdna(prop, NULL, "id");
3007 RNA_def_property_struct_type(prop, "NodeTree");
3008 RNA_def_property_pointer_funcs(prop, NULL, "rna_NodeGroup_node_tree_set", NULL, "rna_NodeGroup_node_tree_poll");
3009 RNA_def_property_flag(prop, PROP_EDITABLE);
3010 RNA_def_property_ui_text(prop, "Node Tree", "");
3011 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeGroup_update");
3013 prop = RNA_def_property(srna, "interface", PROP_POINTER, PROP_NONE);
3014 RNA_def_property_pointer_funcs(prop, NULL, NULL, "rna_NodeGroup_interface_typef", NULL);
3015 RNA_def_property_struct_type(prop, "PropertyGroup");
3016 RNA_def_property_flag(prop, PROP_IDPROPERTY);
3017 RNA_def_property_ui_text(prop, "Interface", "Interface socket data");
3020 static void def_custom_group(BlenderRNA *brna)
3024 srna = RNA_def_struct(brna, "NodeCustomGroup", "Node");
3025 RNA_def_struct_ui_text(srna, "Custom Group", "Base node type for custom registered node group types");
3026 RNA_def_struct_sdna(srna, "bNode");
3028 RNA_def_struct_register_funcs(srna, "rna_NodeCustomGroup_register", "rna_Node_unregister", NULL);
3033 static void def_frame(StructRNA *srna)
3037 RNA_def_struct_sdna_from(srna, "NodeFrame", "storage");
3039 prop = RNA_def_property(srna, "shrink", PROP_BOOLEAN, PROP_NONE);
3040 RNA_def_property_boolean_sdna(prop, NULL, "flag", NODE_FRAME_SHRINK);
3041 RNA_def_property_ui_text(prop, "Shrink", "Shrink the frame to minimal bounding box");
3042 RNA_def_property_update(prop, NC_NODE | ND_DISPLAY, NULL);
3044 prop = RNA_def_property(srna, "label_size", PROP_INT, PROP_NONE);
3045 RNA_def_property_int_sdna(prop, NULL, "label_size");
3046 RNA_def_property_range(prop, 8, 64);
3047 RNA_def_property_ui_text(prop, "Label Font Size", "Font size to use for displaying the label");
3048 RNA_def_property_update(prop, NC_NODE | ND_DISPLAY, NULL);
3051 static void def_math(StructRNA *srna)
3055 prop = RNA_def_property(srna, "operation", PROP_ENUM, PROP_NONE);
3056 RNA_def_property_enum_sdna(prop, NULL, "custom1");
3057 RNA_def_property_enum_items(prop, node_math_items);
3058 RNA_def_property_ui_text(prop, "Operation", "");
3059 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3061 prop = RNA_def_property(srna, "use_clamp", PROP_BOOLEAN, PROP_NONE);
3062 RNA_def_property_boolean_sdna(prop, NULL, "custom2", 1);
3063 RNA_def_property_ui_text(prop, "Clamp", "Clamp result of the node to 0..1 range");
3064 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3067 static void def_vector_math(StructRNA *srna)
3071 prop = RNA_def_property(srna, "operation", PROP_ENUM, PROP_NONE);
3072 RNA_def_property_enum_sdna(prop, NULL, "custom1");
3073 RNA_def_property_enum_items(prop, node_vec_math_items);
3074 RNA_def_property_ui_text(prop, "Operation", "");
3075 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3078 static void def_rgb_curve(StructRNA *srna)
3082 prop = RNA_def_property(srna, "mapping", PROP_POINTER, PROP_NONE);
3083 RNA_def_property_pointer_sdna(prop, NULL, "storage");
3084 RNA_def_property_struct_type(prop, "CurveMapping");
3085 RNA_def_property_ui_text(prop, "Mapping", "");
3086 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3089 static void def_vector_curve(StructRNA *srna)
3093 prop = RNA_def_property(srna, "mapping", PROP_POINTER, PROP_NONE);
3094 RNA_def_property_pointer_sdna(prop, NULL, "storage");
3095 RNA_def_property_struct_type(prop, "CurveMapping");
3096 RNA_def_property_ui_text(prop, "Mapping", "");
3097 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3100 static void def_time(StructRNA *srna)
3104 prop = RNA_def_property(srna, "curve", PROP_POINTER, PROP_NONE);
3105 RNA_def_property_pointer_sdna(prop, NULL, "storage");
3106 RNA_def_property_struct_type(prop, "CurveMapping");
3107 RNA_def_property_ui_text(prop, "Curve", "");
3108 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3110 prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_NONE);
3111 RNA_def_property_int_sdna(prop, NULL, "custom1");
3112 RNA_def_property_ui_text(prop, "Start Frame", "");
3113 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3115 prop = RNA_def_property(srna, "frame_end", PROP_INT, PROP_NONE);
3116 RNA_def_property_int_sdna(prop, NULL, "custom2");
3117 RNA_def_property_ui_text(prop, "End Frame", "");
3118 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3121 static void def_colorramp(StructRNA *srna)
3125 prop = RNA_def_property(srna, "color_ramp", PROP_POINTER, PROP_NONE);
3126 RNA_def_property_pointer_sdna(prop, NULL, "storage");
3127 RNA_def_property_struct_type(prop, "ColorRamp");
3128 RNA_def_property_ui_text(prop, "Color Ramp", "");
3129 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3132 static void def_mix_rgb(StructRNA *srna)
3136 prop = RNA_def_property(srna, "blend_type", PROP_ENUM, PROP_NONE);
3137 RNA_def_property_enum_sdna(prop, NULL, "custom1");
3138 RNA_def_property_enum_items(prop, ramp_blend_items);
3139 RNA_def_property_ui_text(prop, "Blend Type", "");
3140 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3142 prop = RNA_def_property(srna, "use_alpha", PROP_BOOLEAN, PROP_NONE);
3143 RNA_def_property_boolean_sdna(prop, NULL, "custom2", 1);
3144 RNA_def_property_ui_text(prop, "Alpha", "Include alpha of second input in this operation");
3145 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3147 prop = RNA_def_property(srna, "use_clamp", PROP_BOOLEAN, PROP_NONE);
3148 RNA_def_property_boolean_sdna(prop, NULL, "custom2", 2);
3149 RNA_def_property_ui_text(prop, "Clamp", "Clamp result of the node to 0..1 range");
3150 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3153 static void def_texture(StructRNA *srna)
3157 prop = RNA_def_property(srna, "texture", PROP_POINTER, PROP_NONE);
3158 RNA_def_property_pointer_sdna(prop, NULL, "id");
3159 RNA_def_property_struct_type(prop, "Texture");
3160 RNA_def_property_flag(prop, PROP_EDITABLE);
3161 RNA_def_property_ui_text(prop, "Texture", "");
3162 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3164 prop = RNA_def_property(srna, "node_output", PROP_INT, PROP_NONE);
3165 RNA_def_property_int_sdna(prop, NULL, "custom1");
3166 RNA_def_property_ui_text(prop, "Node Output", "For node-based textures, which output node to use");
3167 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3171 /* -- Shader Nodes ---------------------------------------------------------- */
3173 static void def_sh_output(StructRNA *srna)
3177 prop = RNA_def_property(srna, "is_active_output", PROP_BOOLEAN, PROP_NONE);
3178 RNA_def_property_boolean_sdna(prop, NULL, "flag", NODE_DO_OUTPUT);
3179 RNA_def_property_ui_text(prop, "Active Output", "True if this node is used as the active output");
3180 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3183 static void def_sh_material(StructRNA *srna)
3187 prop = RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
3188 RNA_def_property_pointer_sdna(prop, NULL, "id");
3189 RNA_def_property_struct_type(prop, "Material");
3190 RNA_def_property_flag(prop, PROP_EDITABLE);
3191 RNA_def_property_ui_text(prop, "Material", "");
3192 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_material_update");
3194 prop = RNA_def_property(srna, "use_diffuse", PROP_BOOLEAN, PROP_NONE);
3195 RNA_def_property_boolean_sdna(prop, NULL, "custom1", SH_NODE_MAT_DIFF);
3196 RNA_def_property_ui_text(prop, "Diffuse", "Material Node outputs Diffuse");
3197 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3199 prop = RNA_def_property(srna, "use_specular", PROP_BOOLEAN, PROP_NONE);
3200 RNA_def_property_boolean_sdna(prop, NULL, "custom1", SH_NODE_MAT_SPEC);
3201 RNA_def_property_ui_text(prop, "Specular", "Material Node outputs Specular");
3202 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3204 prop = RNA_def_property(srna, "invert_normal", PROP_BOOLEAN, PROP_NONE);
3205 RNA_def_property_boolean_sdna(prop, NULL, "custom1", SH_NODE_MAT_NEG);
3206 RNA_def_property_ui_text(prop, "Invert Normal", "Material Node uses inverted normal");
3207 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3210 static void def_sh_mapping(StructRNA *srna)
3212 static EnumPropertyItem prop_vect_type_items[] = {
3213 {TEXMAP_TYPE_TEXTURE, "TEXTURE", 0, "Texture", "Transform a texture by inverse mapping the texture coordinate"},
3214 {TEXMAP_TYPE_POINT, "POINT", 0, "Point", "Transform a point"},
3215 {TEXMAP_TYPE_VECTOR, "VECTOR", 0, "Vector", "Transform a direction vector"},
3216 {TEXMAP_TYPE_NORMAL, "NORMAL", 0, "Normal", "Transform a normal vector with unit length"},
3217 {0, NULL, 0, NULL, NULL}
3222 RNA_def_struct_sdna_from(srna, "TexMapping", "storage");
3224 prop = RNA_def_property(srna, "vector_type", PROP_ENUM, PROP_NONE);
3225 RNA_def_property_enum_sdna(prop, NULL, "type");
3226 RNA_def_property_enum_items(prop, prop_vect_type_items);
3227 RNA_def_property_ui_text(prop, "Type", "Type of vector that the mapping transforms");
3228 RNA_def_property_update(prop, 0, "rna_Mapping_Node_update");
3230 prop = RNA_def_property(srna, "translation", PROP_FLOAT, PROP_TRANSLATION);
3231 RNA_def_property_float_sdna(prop, NULL, "loc");
3232 RNA_def_property_ui_text(prop, "Location", "");
3233 RNA_def_property_update(prop, 0, "rna_Mapping_Node_update");
3235 /* Not PROP_XYZ, this is now in radians, no more degrees */
3236 prop = RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_EULER);
3237 RNA_def_property_float_sdna(prop, NULL, "rot");
3238 RNA_def_property_ui_text(prop, "Rotation", "");
3239 RNA_def_property_update(prop, 0, "rna_Mapping_Node_update");
3241 prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_XYZ);
3242 RNA_def_property_float_sdna(prop, NULL, "size");
3243 RNA_def_property_flag(prop, PROP_PROPORTIONAL);
3244 RNA_def_property_ui_text(prop, "Scale", "");
3245 RNA_def_property_update(prop, 0, "rna_Mapping_Node_update");
3247 prop = RNA_def_property(srna, "min", PROP_FLOAT, PROP_XYZ);
3248 RNA_def_property_float_sdna(prop, NULL, "min");
3249 RNA_def_property_ui_text(prop, "Minimum", "Minimum value for clipping");
3250 RNA_def_property_update(prop, 0, "rna_Mapping_Node_update");
3252 prop = RNA_def_property(srna, "max", PROP_FLOAT, PROP_XYZ);
3253 RNA_def_property_float_sdna(prop, NULL, "max");
3254 RNA_def_property_ui_text(prop, "Maximum", "Maximum value for clipping");
3255 RNA_def_property_update(prop, 0, "rna_Mapping_Node_update");
3257 prop = RNA_def_property(srna, "use_min", PROP_BOOLEAN, PROP_NONE);
3258 RNA_def_property_boolean_sdna(prop, NULL, "flag", TEXMAP_CLIP_MIN);
3259 RNA_def_property_ui_text(prop, "Has Minimum", "Whether to use minimum clipping value");
3260 RNA_def_property_update(prop, 0, "rna_Mapping_Node_update");
3262 prop = RNA_def_property(srna, "use_max", PROP_BOOLEAN, PROP_NONE);
3263 RNA_def_property_boolean_sdna(prop, NULL, "flag", TEXMAP_CLIP_MAX);
3264 RNA_def_property_ui_text(prop, "Has Maximum", "Whether to use maximum clipping value");
3265 RNA_def_property_update(prop, 0, "rna_Mapping_Node_update");
3268 static void def_sh_geometry(StructRNA *srna)
3272 RNA_def_struct_sdna_from(srna, "NodeGeometry", "storage");
3274 prop = RNA_def_property(srna, "uv_layer", PROP_STRING, PROP_NONE);
3275 RNA_def_property_string_sdna(prop, NULL, "uvname");
3276 RNA_def_property_ui_text(prop, "UV Map", "");
3277 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3279 prop = RNA_def_property(srna, "color_layer", PROP_STRING, PROP_NONE);
3280 RNA_def_property_string_sdna(prop, NULL, "colname");
3281 RNA_def_property_ui_text(prop, "Vertex Color Layer", "");
3282 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3285 static void def_sh_lamp(StructRNA *srna)
3289 prop = RNA_def_property(srna, "lamp_object", PROP_POINTER, PROP_NONE);
3290 RNA_def_property_pointer_sdna(prop, NULL, "id");
3291 RNA_def_property_struct_type(prop, "Object");
3292 RNA_def_property_flag(prop, PROP_EDITABLE);
3293 RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_Lamp_object_poll");
3294 RNA_def_property_ui_text(prop, "Lamp Object", "");
3295 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3298 static void def_sh_attribute(StructRNA *srna)
3302 RNA_def_struct_sdna_from(srna, "NodeShaderAttribute", "storage");
3304 prop = RNA_def_property(srna, "attribute_name", PROP_STRING, PROP_NONE);
3305 RNA_def_property_string_sdna(prop, NULL, "name");
3306 RNA_def_property_ui_text(prop, "Attribute Name", "");
3307 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3310 static void def_sh_tex(StructRNA *srna)
3314 prop = RNA_def_property(srna, "texture_mapping", PROP_POINTER, PROP_NONE);
3315 RNA_def_property_pointer_sdna(prop, NULL, "base.tex_mapping");
3316 RNA_def_property_flag(prop, PROP_NEVER_NULL);
3317 RNA_def_property_ui_text(prop, "Texture Mapping", "Texture coordinate mapping settings");
3319 prop = RNA_def_property(srna, "color_mapping", PROP_POINTER, PROP_NONE);
3320 RNA_def_property_pointer_sdna(prop, NULL, "base.color_mapping");
3321 RNA_def_property_flag(prop, PROP_NEVER_NULL);
3322 RNA_def_property_ui_text(prop, "Color Mapping", "Color mapping settings");
3325 static void def_sh_tex_sky(StructRNA *srna)
3327 static EnumPropertyItem prop_sky_type[] = {
3328 {SHD_SKY_OLD, "PREETHAM", 0, "Preetham", ""},
3329 {SHD_SKY_NEW, "HOSEK_WILKIE", 0, "Hosek / Wilkie", ""},
3330 {0, NULL, 0, NULL, NULL}
3332 static float default_dir[3] = {0.0f, 0.0f, 1.0f};
3336 RNA_def_struct_sdna_from(srna, "NodeTexSky", "storage");
3339 prop = RNA_def_property(srna, "sky_type", PROP_ENUM, PROP_NONE);
3340 RNA_def_property_enum_sdna(prop, NULL, "sky_model");
3341 RNA_def_property_enum_items(prop, prop_sky_type);
3342 RNA_def_property_ui_text(prop, "Sky Type", "");
3343 RNA_def_property_update(prop, 0, "rna_Node_update");
3345 prop = RNA_def_property(srna, "sun_direction", PROP_FLOAT, PROP_DIRECTION);
3346 RNA_def_property_ui_text(prop, "Sun Direction", "Direction from where the sun is shining");
3347 RNA_def_property_array(prop, 3);
3348 RNA_def_property_float_array_default(prop, default_dir);
3349 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3351 prop = RNA_def_property(srna, "turbidity", PROP_FLOAT, PROP_NONE);
3352 RNA_def_property_range(prop, 1.0f, 10.0f);
3353 RNA_def_property_ui_range(prop, 1.0f, 10.0f, 10, 3);
3354 RNA_def_property_ui_text(prop, "Turbidity", "Atmospheric turbidity");
3355 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3357 prop = RNA_def_property(srna, "ground_albedo", PROP_FLOAT, PROP_FACTOR);
3358 RNA_def_property_range(prop, 0.0f, 1.0f);
3359 RNA_def_property_ui_text(prop, "Ground Albedo", "Ground color that is subtly reflected in the sky");
3360 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
3363 static void def_sh_tex_environment(StructRNA *srna)
3365 static const EnumPropertyItem prop_color_space_items[] = {
3366 {SHD_COLORSPACE_COLOR, "COLOR", 0, "Color",
3367 "Image contains color data, and will be converted to linear color for rendering"},
3368 {SHD_COLORSPACE_NONE, "NONE", 0, "Non-Color Data",
3369 "Image contains non-color data, for example a displacement or normal map, "
3370 "and will not be converted"},
3371 {0, NULL, 0, NULL, NULL}
3374 static const EnumPropertyItem prop_projection_items[] = {
3375 {SHD_PROJ_EQUIRECTANGULAR, "EQUIRECTANGULAR", 0, "Equirectangular",
3376 "Equirectangular or latitude-longitude projection"},
3377 {SHD_PROJ_MIRROR_BALL, "MIRROR_BALL", 0, "Mirror Ball",
3378 "Projection from an orthographic photo of a mirror ball"},
3379 {0, NULL, 0, NULL, NULL}
3384 prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE);
3385 RNA_def_property_pointer_sdna(prop, NULL, "id");
3386 RNA_def_property_struct_type(prop, "Image");
3387 RNA_def_property_flag(prop, PROP_EDITABLE);
3388 RNA_def_property_ui_text(prop, "Image", "");
3389 RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_tex_image_update");
3391 RNA_def_struct_sdna_from(srna, "NodeTexEnvironment", "storage");
3394 prop = RNA_def_property(srna, "color_space", PROP_ENUM, PROP_NONE);
3395 RNA_def_property_enum_items(prop, prop_color_space_items);
3396 RNA_def_property_ui_text(prop, "Color Space", "Image file color space");
3397 RNA_def_property_update(prop, 0, "rna_Node_update");
3399 prop = RNA_def_property(srna, "projection", PROP_ENUM, PROP_NONE);
3400 RNA_def_property_enum_items(prop, prop_projection_items);
3401 RNA_def_property_ui_text(prop, "Projection", "Projection of the input image");
3402 RNA_def_property_update(prop, 0, "rna_Node_update");
3404 prop = RNA_def_property(srna, "image_user", PROP_POINTER, PROP_NONE);
3405 RNA_def_property_flag(prop, PROP_NEVER_NULL);
3406 RNA_def_property_pointer_sdna(prop, NULL, "iuser");
3407 RNA_def_property_ui_text(prop, "Image User",
3408 "Parameters defining which layer, pass and frame of the image is displayed");
3409 RNA_def_property_update(prop, 0, "rna_Node_update");
3412 static void def_sh_tex_image(StructRNA *srna)
3414 static const EnumPropertyItem prop_color_space_items[] = {
3415 {SHD_COLORSPACE_COLOR, "COLOR", 0, "Color",
3416 "Image contains color data, and will be converted to linear color for rendering"},
3417 {SHD_COLORSPACE_NONE, "NONE", 0, "Non-Color Data",
3418 "Image contains non-color data, for example a displacement or normal map, "
3419 "and will not be converted"},
3420 {0, NULL, 0, NULL, NULL}