Blender  V2.93
node_add.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2005 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "MEM_guardedalloc.h"
25 
26 #include "DNA_collection_types.h"
27 #include "DNA_node_types.h"
28 #include "DNA_texture_types.h"
29 
30 #include "BLI_listbase.h"
31 #include "BLI_math.h"
32 
33 #include "BLT_translation.h"
34 
35 #include "BKE_context.h"
36 #include "BKE_image.h"
37 #include "BKE_lib_id.h"
38 #include "BKE_main.h"
39 #include "BKE_node.h"
40 #include "BKE_report.h"
41 #include "BKE_scene.h"
42 #include "BKE_texture.h"
43 
44 #include "DEG_depsgraph_build.h"
45 
46 #include "ED_node.h" /* own include */
47 #include "ED_render.h"
48 #include "ED_screen.h"
49 
50 #include "RNA_access.h"
51 #include "RNA_define.h"
52 #include "RNA_enum_types.h"
53 
54 #include "WM_api.h"
55 #include "WM_types.h"
56 
57 #include "UI_view2d.h"
58 
59 #include "node_intern.h" /* own include */
60 
61 /* -------------------------------------------------------------------- */
70 bNode *node_add_node(const bContext *C, const char *idname, int type, float locx, float locy)
71 {
72  SpaceNode *snode = CTX_wm_space_node(C);
73  Main *bmain = CTX_data_main(C);
74  bNode *node = NULL;
75 
76  node_deselect_all(snode);
77 
78  if (idname) {
79  node = nodeAddNode(C, snode->edittree, idname);
80  }
81  else {
82  node = nodeAddStaticNode(C, snode->edittree, type);
83  }
84  BLI_assert(node && node->typeinfo);
85 
86  /* Position mouse in node header. */
87  node->locx = locx - NODE_DY * 1.5f / UI_DPI_FAC;
88  node->locy = locy + NODE_DY * 0.5f / UI_DPI_FAC;
89 
90  nodeSetSelected(node, true);
91 
92  ntreeUpdateTree(bmain, snode->edittree);
93  ED_node_set_active(bmain, snode->edittree, node, NULL);
94 
95  snode_update(snode, node);
96 
97  if (snode->nodetree->type == NTREE_TEXTURE) {
99  }
100 
101  return node;
102 }
103 
106 /* -------------------------------------------------------------------- */
111  float mcoords[][2],
112  int tot,
113  float result[2])
114 {
115  float coord_array[NODE_LINK_RESOL + 1][2];
116 
117  if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) {
118  for (int i = 0; i < tot - 1; i++) {
119  for (int b = 0; b < NODE_LINK_RESOL; b++) {
121  mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1], result) > 0) {
122  return true;
123  }
124  }
125  }
126  }
127  return false;
128 }
129 
130 typedef struct bNodeSocketLink {
132 
133  struct bNodeSocket *sock;
134  struct bNodeLink *link;
135  float point[2];
137 
139  bNodeSocket *sock,
140  bNodeLink *link,
141  const float point[2])
142 {
143  bNodeSocketLink *socklink, *prev;
144 
145  socklink = MEM_callocN(sizeof(bNodeSocketLink), "socket link");
146  socklink->sock = sock;
147  socklink->link = link;
148  copy_v2_v2(socklink->point, point);
149 
150  for (prev = lb->last; prev; prev = prev->prev) {
151  if (prev->sock == sock) {
152  break;
153  }
154  }
155  BLI_insertlinkafter(lb, prev, socklink);
156  return socklink;
157 }
158 
160  bNodeSocketLink *socklink,
161  int in_out)
162 {
163  SpaceNode *snode = CTX_wm_space_node(C);
164  bNodeTree *ntree = snode->edittree;
165  bNode *reroute_node = NULL;
166  bNodeSocket *cursock = socklink->sock;
167  float insert_point[2];
168  int num_links;
169 
170  zero_v2(insert_point);
171  num_links = 0;
172 
173  while (socklink && socklink->sock == cursock) {
174  if (!(socklink->link->flag & NODE_LINK_TEST)) {
175  socklink->link->flag |= NODE_LINK_TEST;
176 
177  /* create the reroute node for this cursock */
178  if (!reroute_node) {
179  reroute_node = nodeAddStaticNode(C, ntree, NODE_REROUTE);
180 
181  /* add a single link to/from the reroute node to replace multiple links */
182  if (in_out == SOCK_OUT) {
184  socklink->link->fromnode,
185  socklink->link->fromsock,
186  reroute_node,
187  reroute_node->inputs.first);
188  }
189  else {
191  reroute_node,
192  reroute_node->outputs.first,
193  socklink->link->tonode,
194  socklink->link->tosock);
195  }
196  }
197 
198  /* insert the reroute node into the link */
199  if (in_out == SOCK_OUT) {
200  socklink->link->fromnode = reroute_node;
201  socklink->link->fromsock = reroute_node->outputs.first;
202  }
203  else {
204  socklink->link->tonode = reroute_node;
205  socklink->link->tosock = reroute_node->inputs.first;
206  }
207 
208  add_v2_v2(insert_point, socklink->point);
209  num_links++;
210  }
211  socklink = socklink->next;
212  }
213 
214  if (num_links > 0) {
215  /* average cut point from shared links */
216  mul_v2_fl(insert_point, 1.0f / num_links);
217 
218  reroute_node->locx = insert_point[0] / UI_DPI_FAC;
219  reroute_node->locy = insert_point[1] / UI_DPI_FAC;
220  }
221 
222  return socklink;
223 }
224 
226 {
227  SpaceNode *snode = CTX_wm_space_node(C);
228  ARegion *region = CTX_wm_region(C);
229  bNodeTree *ntree = snode->edittree;
230  float mcoords[256][2];
231  int i = 0;
232 
233  /* Get the cut path */
234  RNA_BEGIN (op->ptr, itemptr, "path") {
235  float loc[2];
236 
237  RNA_float_get_array(&itemptr, "loc", loc);
239  &region->v2d, (short)loc[0], (short)loc[1], &mcoords[i][0], &mcoords[i][1]);
240  i++;
241  if (i >= 256) {
242  break;
243  }
244  }
245  RNA_END;
246 
247  if (i > 1) {
248  ListBase output_links, input_links;
249  bNodeLink *link;
250  bNodeSocketLink *socklink;
251  float insert_point[2];
252 
253  /* always first */
255 
256  node_deselect_all(snode);
257 
258  /* Find cut links and sort them by sockets */
259  BLI_listbase_clear(&output_links);
260  BLI_listbase_clear(&input_links);
261 
262  for (link = ntree->links.first; link; link = link->next) {
263  if (nodeLinkIsHidden(link)) {
264  continue;
265  }
266  if (add_reroute_intersect_check(link, mcoords, i, insert_point)) {
267  add_reroute_insert_socket_link(&output_links, link->fromsock, link, insert_point);
268  add_reroute_insert_socket_link(&input_links, link->tosock, link, insert_point);
269 
270  /* Clear flag */
271  link->flag &= ~NODE_LINK_TEST;
272  }
273  }
274 
275  /* Create reroute nodes for intersected links.
276  * Only one reroute if links share the same input/output socket.
277  */
278  socklink = output_links.first;
279  while (socklink) {
280  socklink = add_reroute_do_socket_section(C, socklink, SOCK_OUT);
281  }
282  socklink = input_links.first;
283  while (socklink) {
284  socklink = add_reroute_do_socket_section(C, socklink, SOCK_IN);
285  }
286 
287  BLI_freelistN(&output_links);
288  BLI_freelistN(&input_links);
289 
290  /* always last */
292  snode_notify(C, snode);
293  snode_dag_update(C, snode);
294 
295  return OPERATOR_FINISHED;
296  }
297 
299 }
300 
302 {
303  ot->name = "Add Reroute";
304  ot->idname = "NODE_OT_add_reroute";
305  ot->description = "Add a reroute node";
306 
311 
313 
314  /* flags */
316 
317  /* properties */
318  PropertyRNA *prop;
319  prop = RNA_def_collection_runtime(ot->srna, "path", &RNA_OperatorMousePath, "Path", "");
321  /* internal */
322  RNA_def_int(ot->srna, "cursor", WM_CURSOR_CROSS, 0, INT_MAX, "Cursor", "", 0, INT_MAX);
323 }
324 
327 /* -------------------------------------------------------------------- */
332  wmOperator *op,
333  bNodeTree *ntree)
334 {
335  char name[MAX_ID_NAME - 2];
336  RNA_string_get(op->ptr, "name", name);
337 
338  bNodeTree *node_group = (bNodeTree *)BKE_libblock_find_name(bmain, ID_NT, name);
339  if (!node_group) {
340  return NULL;
341  }
342 
343  const char *disabled_hint = NULL;
344  if ((node_group->type != ntree->type) || !nodeGroupPoll(ntree, node_group, &disabled_hint)) {
345  if (disabled_hint) {
346  BKE_reportf(op->reports,
347  RPT_ERROR,
348  "Can not add node group '%s' to '%s':\n %s",
349  node_group->id.name + 2,
350  ntree->id.name + 2,
351  disabled_hint);
352  }
353  else {
354  BKE_reportf(op->reports,
355  RPT_ERROR,
356  "Can not add node group '%s' to '%s'",
357  node_group->id.name + 2,
358  ntree->id.name + 2);
359  }
360 
361  return NULL;
362  }
363 
364  return node_group;
365 }
366 
368 {
369  Main *bmain = CTX_data_main(C);
370  SpaceNode *snode = CTX_wm_space_node(C);
371  bNodeTree *ntree = snode->edittree;
372  bNodeTree *node_group;
373 
374  if (!(node_group = node_add_group_get_and_poll_group_node_tree(bmain, op, ntree))) {
375  return OPERATOR_CANCELLED;
376  }
377 
379 
380  bNode *group_node = node_add_node(C,
382  (node_group->type == NTREE_CUSTOM) ? NODE_CUSTOM_GROUP :
383  NODE_GROUP,
384  snode->runtime->cursor[0],
385  snode->runtime->cursor[1]);
386  if (!group_node) {
387  BKE_report(op->reports, RPT_WARNING, "Could not add node group");
388  return OPERATOR_CANCELLED;
389  }
390 
391  group_node->id = &node_group->id;
392  id_us_plus(group_node->id);
393 
394  nodeSetActive(ntree, group_node);
395  ntreeUpdateTree(bmain, node_group);
396  ntreeUpdateTree(bmain, ntree);
397 
398  snode_notify(C, snode);
399  snode_dag_update(C, snode);
400 
401  return OPERATOR_FINISHED;
402 }
403 
404 static int node_add_group_invoke(bContext *C, wmOperator *op, const wmEvent *event)
405 {
406  ARegion *region = CTX_wm_region(C);
407  SpaceNode *snode = CTX_wm_space_node(C);
408 
409  /* Convert mouse coordinates to v2d space. */
410  UI_view2d_region_to_view(&region->v2d,
411  event->mval[0],
412  event->mval[1],
413  &snode->runtime->cursor[0],
414  &snode->runtime->cursor[1]);
415 
416  snode->runtime->cursor[0] /= UI_DPI_FAC;
417  snode->runtime->cursor[1] /= UI_DPI_FAC;
418 
419  return node_add_group_exec(C, op);
420 }
421 
423 {
424  /* identifiers */
425  ot->name = "Add Node Group";
426  ot->description = "Add an existing node group to the current node editor";
427  ot->idname = "NODE_OT_add_group";
428 
429  /* callbacks */
433 
434  /* flags */
436 
437  RNA_def_string(ot->srna, "name", "Mask", MAX_ID_NAME - 2, "Name", "Data-block name to assign");
438 }
439 
442 /* -------------------------------------------------------------------- */
447 {
448  char name[MAX_ID_NAME - 2];
449  RNA_string_get(op->ptr, "name", name);
450 
451  Object *object = (Object *)BKE_libblock_find_name(bmain, ID_OB, name);
452  if (!object) {
453  return NULL;
454  }
455 
456  return object;
457 }
458 
460 {
461  Main *bmain = CTX_data_main(C);
462  SpaceNode *snode = CTX_wm_space_node(C);
463  bNodeTree *ntree = snode->edittree;
464  Object *object;
465 
466  if (!(object = node_add_object_get_and_poll_object_node_tree(bmain, op))) {
467  return OPERATOR_CANCELLED;
468  }
469 
471 
472  bNode *object_node = node_add_node(
473  C, NULL, GEO_NODE_OBJECT_INFO, snode->runtime->cursor[0], snode->runtime->cursor[1]);
474  if (!object_node) {
475  BKE_report(op->reports, RPT_WARNING, "Could not add node object");
476  return OPERATOR_CANCELLED;
477  }
478 
479  bNodeSocket *sock = nodeFindSocket(object_node, SOCK_IN, "Object");
480  if (!sock) {
481  BKE_report(op->reports, RPT_WARNING, "Could not find node object socket");
482  return OPERATOR_CANCELLED;
483  }
484 
485  bNodeSocketValueObject *socket_data = sock->default_value;
486  socket_data->value = object;
487  id_us_plus(&object->id);
488 
489  nodeSetActive(ntree, object_node);
490  ntreeUpdateTree(bmain, ntree);
491 
492  snode_notify(C, snode);
493  snode_dag_update(C, snode);
494 
495  ED_node_tag_update_nodetree(bmain, ntree, object_node);
497 
498  return OPERATOR_FINISHED;
499 }
500 
501 static int node_add_object_invoke(bContext *C, wmOperator *op, const wmEvent *event)
502 {
503  ARegion *region = CTX_wm_region(C);
504  SpaceNode *snode = CTX_wm_space_node(C);
505 
506  /* Convert mouse coordinates to v2d space. */
507  UI_view2d_region_to_view(&region->v2d,
508  event->mval[0],
509  event->mval[1],
510  &snode->runtime->cursor[0],
511  &snode->runtime->cursor[1]);
512 
513  snode->runtime->cursor[0] /= UI_DPI_FAC;
514  snode->runtime->cursor[1] /= UI_DPI_FAC;
515 
516  return node_add_object_exec(C, op);
517 }
518 
520 {
521  const SpaceNode *snode = CTX_wm_space_node(C);
524 }
525 
527 {
528  /* identifiers */
529  ot->name = "Add Node Object";
530  ot->description = "Add an object info node to the current node editor";
531  ot->idname = "NODE_OT_add_object";
532 
533  /* callbacks */
537 
538  /* flags */
540 
541  RNA_def_string(ot->srna, "name", "Object", MAX_ID_NAME - 2, "Name", "Data-block name to assign");
542 }
543 
546 /* -------------------------------------------------------------------- */
551 {
552  char name[MAX_ID_NAME - 2];
553  RNA_string_get(op->ptr, "name", name);
554 
555  Tex *texture = (Tex *)BKE_libblock_find_name(bmain, ID_TE, name);
556  if (!texture) {
557  return NULL;
558  }
559 
560  return texture;
561 }
562 
564 {
565  Main *bmain = CTX_data_main(C);
566  SpaceNode *snode = CTX_wm_space_node(C);
567  bNodeTree *ntree = snode->edittree;
568  Tex *texture;
569 
571  return OPERATOR_CANCELLED;
572  }
573 
575 
576  bNode *texture_node = node_add_node(C,
577  NULL,
579  snode->runtime->cursor[0],
580  snode->runtime->cursor[1]);
581  if (!texture_node) {
582  BKE_report(op->reports, RPT_WARNING, "Could not add texture node");
583  return OPERATOR_CANCELLED;
584  }
585 
586  texture_node->id = &texture->id;
587  id_us_plus(&texture->id);
588 
589  nodeSetActive(ntree, texture_node);
590  ntreeUpdateTree(bmain, ntree);
591 
592  snode_notify(C, snode);
593  snode_dag_update(C, snode);
594 
595  ED_node_tag_update_nodetree(bmain, ntree, texture_node);
596 
597  return OPERATOR_FINISHED;
598 }
599 
600 static int node_add_texture_invoke(bContext *C, wmOperator *op, const wmEvent *event)
601 {
602  ARegion *region = CTX_wm_region(C);
603  SpaceNode *snode = CTX_wm_space_node(C);
604 
605  /* Convert mouse coordinates to v2d space. */
606  UI_view2d_region_to_view(&region->v2d,
607  event->mval[0],
608  event->mval[1],
609  &snode->runtime->cursor[0],
610  &snode->runtime->cursor[1]);
611 
612  snode->runtime->cursor[0] /= UI_DPI_FAC;
613  snode->runtime->cursor[1] /= UI_DPI_FAC;
614 
615  return node_add_texture_exec(C, op);
616 }
617 
619 {
620  const SpaceNode *snode = CTX_wm_space_node(C);
623 }
624 
626 {
627  /* identifiers */
628  ot->name = "Add Node Texture";
629  ot->description = "Add a texture to the current node editor";
630  ot->idname = "NODE_OT_add_texture";
631 
632  /* callbacks */
636 
637  /* flags */
639 
641  ot->srna, "name", "Texture", MAX_ID_NAME - 2, "Name", "Data-block name to assign");
642 }
643 
646 /* -------------------------------------------------------------------- */
651  wmOperator *op)
652 {
653  char name[MAX_ID_NAME - 2];
654  RNA_string_get(op->ptr, "name", name);
655 
656  Collection *collection = (Collection *)BKE_libblock_find_name(bmain, ID_GR, name);
657  if (!collection) {
658  return NULL;
659  }
660 
661  return collection;
662 }
663 
665 {
666  Main *bmain = CTX_data_main(C);
667  SpaceNode *snode = CTX_wm_space_node(C);
668  bNodeTree *ntree = snode->edittree;
669  Collection *collection;
670 
671  if (!(collection = node_add_collection_get_and_poll_collection_node_tree(bmain, op))) {
672  return OPERATOR_CANCELLED;
673  }
674 
676 
677  bNode *collection_node = node_add_node(
678  C, NULL, GEO_NODE_COLLECTION_INFO, snode->runtime->cursor[0], snode->runtime->cursor[1]);
679  if (!collection_node) {
680  BKE_report(op->reports, RPT_WARNING, "Could not add node collection");
681  return OPERATOR_CANCELLED;
682  }
683 
684  bNodeSocket *sock = nodeFindSocket(collection_node, SOCK_IN, "Collection");
685  if (!sock) {
686  BKE_report(op->reports, RPT_WARNING, "Could not find node collection socket");
687  return OPERATOR_CANCELLED;
688  }
689 
690  bNodeSocketValueCollection *socket_data = sock->default_value;
691  socket_data->value = collection;
692  id_us_plus(&collection->id);
693 
694  nodeSetActive(ntree, collection_node);
695  ntreeUpdateTree(bmain, ntree);
696 
697  snode_notify(C, snode);
698  snode_dag_update(C, snode);
699 
700  ED_node_tag_update_nodetree(bmain, ntree, collection_node);
701 
702  return OPERATOR_FINISHED;
703 }
704 
705 static int node_add_collection_invoke(bContext *C, wmOperator *op, const wmEvent *event)
706 {
707  ARegion *region = CTX_wm_region(C);
708  SpaceNode *snode = CTX_wm_space_node(C);
709 
710  /* Convert mouse coordinates to v2d space. */
711  UI_view2d_region_to_view(&region->v2d,
712  event->mval[0],
713  event->mval[1],
714  &snode->runtime->cursor[0],
715  &snode->runtime->cursor[1]);
716 
717  snode->runtime->cursor[0] /= UI_DPI_FAC;
718  snode->runtime->cursor[1] /= UI_DPI_FAC;
719 
720  return node_add_collection_exec(C, op);
721 }
722 
724 {
725  const SpaceNode *snode = CTX_wm_space_node(C);
728 }
729 
731 {
732  /* identifiers */
733  ot->name = "Add Node Collection";
734  ot->description = "Add an collection info node to the current node editor";
735  ot->idname = "NODE_OT_add_collection";
736 
737  /* callbacks */
741 
742  /* flags */
744 
746  ot->srna, "name", "Collection", MAX_ID_NAME - 2, "Name", "Data-block name to assign");
747 }
748 
751 /* -------------------------------------------------------------------- */
756 {
757  const SpaceNode *snode = CTX_wm_space_node(C);
758  return ED_operator_node_editable(C) &&
760 }
761 
763 {
764  Main *bmain = CTX_data_main(C);
765  SpaceNode *snode = CTX_wm_space_node(C);
766  bNode *node;
767  Image *ima;
768  int type = 0;
769 
770  ima = (Image *)WM_operator_drop_load_path(C, op, ID_IM);
771  if (!ima) {
772  return OPERATOR_CANCELLED;
773  }
774 
775  switch (snode->nodetree->type) {
776  case NTREE_SHADER:
778  break;
779  case NTREE_TEXTURE:
781  break;
782  case NTREE_COMPOSIT:
784  break;
785  default:
786  return OPERATOR_CANCELLED;
787  }
788 
790 
791  node = node_add_node(C, NULL, type, snode->runtime->cursor[0], snode->runtime->cursor[1]);
792 
793  if (!node) {
794  BKE_report(op->reports, RPT_WARNING, "Could not add an image node");
795  return OPERATOR_CANCELLED;
796  }
797 
798  node->id = (ID *)ima;
799 
800  /* When adding new image file via drag-drop we need to load imbuf in order
801  * to get proper image source.
802  */
803  if (RNA_struct_property_is_set(op->ptr, "filepath")) {
806  }
807 
808  snode_notify(C, snode);
809  snode_dag_update(C, snode);
810 
811  return OPERATOR_FINISHED;
812 }
813 
814 static int node_add_file_invoke(bContext *C, wmOperator *op, const wmEvent *event)
815 {
816  ARegion *region = CTX_wm_region(C);
817  SpaceNode *snode = CTX_wm_space_node(C);
818 
819  /* convert mouse coordinates to v2d space */
820  UI_view2d_region_to_view(&region->v2d,
821  event->mval[0],
822  event->mval[1],
823  &snode->runtime->cursor[0],
824  &snode->runtime->cursor[1]);
825 
826  snode->runtime->cursor[0] /= UI_DPI_FAC;
827  snode->runtime->cursor[1] /= UI_DPI_FAC;
828 
829  if (RNA_struct_property_is_set(op->ptr, "filepath") ||
830  RNA_struct_property_is_set(op->ptr, "name")) {
831  return node_add_file_exec(C, op);
832  }
833  return WM_operator_filesel(C, op, event);
834 }
835 
837 {
838  /* identifiers */
839  ot->name = "Add File Node";
840  ot->description = "Add a file node to the current node editor";
841  ot->idname = "NODE_OT_add_file";
842 
843  /* callbacks */
847 
848  /* flags */
850 
853  FILE_SPECIAL,
858  RNA_def_string(ot->srna, "name", "Image", MAX_ID_NAME - 2, "Name", "Data-block name to assign");
859 }
860 
863 /* -------------------------------------------------------------------- */
868 {
869  SpaceNode *snode = CTX_wm_space_node(C);
870 
872 }
873 
875 {
876  Main *bmain = CTX_data_main(C);
877  SpaceNode *snode = CTX_wm_space_node(C);
878  bNode *node;
879  ID *mask = NULL;
880 
881  /* check input variables */
882  char name[MAX_ID_NAME - 2];
883  RNA_string_get(op->ptr, "name", name);
884  mask = BKE_libblock_find_name(bmain, ID_MSK, name);
885  if (!mask) {
886  BKE_reportf(op->reports, RPT_ERROR, "Mask '%s' not found", name);
887  return OPERATOR_CANCELLED;
888  }
889 
891 
893  C, NULL, CMP_NODE_MASK, snode->runtime->cursor[0], snode->runtime->cursor[1]);
894 
895  if (!node) {
896  BKE_report(op->reports, RPT_WARNING, "Could not add a mask node");
897  return OPERATOR_CANCELLED;
898  }
899 
900  node->id = mask;
901  id_us_plus(mask);
902 
903  snode_notify(C, snode);
904  snode_dag_update(C, snode);
905 
906  return OPERATOR_FINISHED;
907 }
908 
910 {
911  /* identifiers */
912  ot->name = "Add Mask Node";
913  ot->description = "Add a mask node to the current node editor";
914  ot->idname = "NODE_OT_add_mask";
915 
916  /* callbacks */
919 
920  /* flags */
922 
923  RNA_def_string(ot->srna, "name", "Mask", MAX_ID_NAME - 2, "Name", "Data-block name to assign");
924 }
925 
928 /* -------------------------------------------------------------------- */
933 {
934  SpaceNode *snode = CTX_wm_space_node(C);
935  Main *bmain = CTX_data_main(C);
936  bNodeTree *ntree;
937  PointerRNA ptr, idptr;
938  PropertyRNA *prop;
939  const char *idname;
940  char treename_buf[MAX_ID_NAME - 2];
941  const char *treename;
942 
943  if (RNA_struct_property_is_set(op->ptr, "type")) {
944  prop = RNA_struct_find_property(op->ptr, "type");
945  RNA_property_enum_identifier(C, op->ptr, prop, RNA_property_enum_get(op->ptr, prop), &idname);
946  }
947  else if (snode) {
948  idname = snode->tree_idname;
949  }
950  else {
951  return OPERATOR_CANCELLED;
952  }
953 
954  if (RNA_struct_property_is_set(op->ptr, "name")) {
955  RNA_string_get(op->ptr, "name", treename_buf);
956  treename = treename_buf;
957  }
958  else {
959  treename = DATA_("NodeTree");
960  }
961 
962  if (!ntreeTypeFind(idname)) {
963  BKE_reportf(op->reports, RPT_ERROR, "Node tree type %s undefined", idname);
964  return OPERATOR_CANCELLED;
965  }
966 
967  ntree = ntreeAddTree(bmain, treename, idname);
968 
969  /* hook into UI */
971 
972  if (prop) {
973  /* RNA_property_pointer_set increases the user count,
974  * fixed here as the editor is the initial user.
975  */
976  id_us_min(&ntree->id);
977 
978  RNA_id_pointer_create(&ntree->id, &idptr);
979  RNA_property_pointer_set(&ptr, prop, idptr, NULL);
980  RNA_property_update(C, &ptr, prop);
981  }
982  else if (snode) {
983  snode->nodetree = ntree;
984 
986  }
987 
988  return OPERATOR_FINISHED;
989 }
990 
993  PropertyRNA *UNUSED(prop),
994  bool *r_free)
995 {
996  return rna_node_tree_type_itemf(NULL, NULL, r_free);
997 }
998 
1000 {
1001  PropertyRNA *prop;
1002 
1003  /* identifiers */
1004  ot->name = "New Node Tree";
1005  ot->idname = "NODE_OT_new_node_tree";
1006  ot->description = "Create a new node tree";
1007 
1008  /* api callbacks */
1010 
1011  /* flags */
1013 
1014  prop = RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, 0, "Tree Type", "");
1016  RNA_def_string(ot->srna, "name", "NodeTree", MAX_ID_NAME - 2, "Name", "");
1017 }
1018 
struct SpaceNode * CTX_wm_space_node(const bContext *C)
Definition: context.c:854
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:689
struct ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:725
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
#define IMA_SIGNAL_RELOAD
Definition: BKE_image.h:162
void BKE_image_signal(struct Main *bmain, struct Image *ima, struct ImageUser *iuser, int signal)
Definition: image.c:3499
void id_us_min(struct ID *id)
Definition: lib_id.c:297
void id_us_plus(struct ID *id)
Definition: lib_id.c:288
struct ID * BKE_libblock_find_name(struct Main *bmain, const short type, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: lib_id.c:1333
#define NODE_REROUTE
Definition: BKE_node.h:873
bool nodeLinkIsHidden(const struct bNodeLink *link)
bool nodeGroupPoll(struct bNodeTree *nodetree, struct bNodeTree *grouptree, const char **r_disabled_hint)
Definition: node_common.c:96
#define NODE_CUSTOM_GROUP
Definition: BKE_node.h:876
struct bNodeTreeType * ntreeTypeFind(const char *idname)
Definition: node.cc:1207
void ntreeUpdateTree(struct Main *main, struct bNodeTree *ntree)
Definition: node.cc:4262
void ntreeTexCheckCyclics(struct bNodeTree *ntree)
#define TEX_NODE_IMAGE
Definition: BKE_node.h:1333
struct bNodeLink * nodeAddLink(struct bNodeTree *ntree, struct bNode *fromnode, struct bNodeSocket *fromsock, struct bNode *tonode, struct bNodeSocket *tosock)
Definition: node.cc:2189
struct bNodeSocket * nodeFindSocket(const struct bNode *node, eNodeSocketInOut in_out, const char *identifier)
struct bNode * nodeAddNode(const struct bContext *C, struct bNodeTree *ntree, const char *idname)
Definition: node.cc:1991
void nodeSetSelected(struct bNode *node, bool select)
Definition: node.cc:3664
struct bNodeTree * ntreeAddTree(struct Main *bmain, const char *name, const char *idname)
Definition: node.cc:2529
struct bNode * nodeAddStaticNode(const struct bContext *C, struct bNodeTree *ntree, int type)
Definition: node.cc:2004
void nodeSetActive(struct bNodeTree *ntree, struct bNode *node)
Definition: node.cc:3694
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
#define BLI_assert(a)
Definition: BLI_assert.h:58
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
Definition: BLI_listbase.h:128
void BLI_insertlinkafter(struct ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition: listbase.c:352
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:547
int isect_seg_seg_v2_point(const float v0[2], const float v1[2], const float v2[2], const float v3[2], float vi[2])
Definition: math_geom.c:1353
MINLINE void mul_v2_fl(float r[2], float f)
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void add_v2_v2(float r[2], const float a[2])
MINLINE void zero_v2(float r[2])
#define UNUSED(x)
#define ELEM(...)
#define DATA_(msgid)
void DEG_relations_tag_update(struct Main *bmain)
#define MAX_ID_NAME
Definition: DNA_ID.h:269
@ ID_TE
Definition: DNA_ID_enums.h:64
@ ID_IM
Definition: DNA_ID_enums.h:65
@ ID_NT
Definition: DNA_ID_enums.h:80
@ ID_MSK
Definition: DNA_ID_enums.h:86
@ ID_GR
Definition: DNA_ID_enums.h:77
@ ID_OB
Definition: DNA_ID_enums.h:59
Object groups, one object can be in many groups at once.
#define NTREE_TEXTURE
#define NTREE_GEOMETRY
#define NTREE_CUSTOM
#define NTREE_COMPOSIT
#define NODE_LINK_TEST
@ SOCK_OUT
@ SOCK_IN
#define NTREE_SHADER
@ FILE_SORT_DEFAULT
@ FILE_SPECIAL
@ FILE_TYPE_MOVIE
@ FILE_TYPE_FOLDER
@ FILE_TYPE_IMAGE
@ FILE_OPENFILE
@ FILE_DEFAULTDISPLAY
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_PASS_THROUGH
void ED_node_tree_update(const struct bContext *C)
void ED_node_tag_update_nodetree(struct Main *bmain, struct bNodeTree *ntree, struct bNode *node)
Definition: node_draw.cc:164
void ED_node_set_active(struct Main *bmain, struct bNodeTree *ntree, struct bNode *node, bool *r_active_texture_changed)
Definition: node_edit.c:665
void ED_preview_kill_jobs(struct wmWindowManager *wm, struct Main *bmain)
bool ED_operator_node_editable(struct bContext *C)
Definition: screen_ops.c:303
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Separate TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC Boolean Random Edge Subdivision Point Object Attribute Attribute Attribute Color Attribute Attribute Vector Point GEO_NODE_ATTRIBUTE_SAMPLE_TEXTURE
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Separate TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC Boolean Random Edge Subdivision Point Object Attribute Attribute Attribute Color Attribute Attribute Vector Point Attribute Sample GEO_NODE_COLLECTION_INFO
NODE_GROUP
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View CMP_NODE_MASK
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Separate TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC Boolean Random Edge Subdivision Point GEO_NODE_OBJECT_INFO
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume SH_NODE_TEX_IMAGE
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set CMP_NODE_IMAGE
#define RNA_BEGIN(sptr, itemptr, propname)
Definition: RNA_access.h:1248
#define RNA_END
Definition: RNA_access.h:1255
StructRNA RNA_OperatorMousePath
const EnumPropertyItem * rna_node_tree_type_itemf(void *data, bool(*poll)(void *data, struct bNodeTreeType *), bool *r_free)
@ PROP_SKIP_SAVE
Definition: RNA_types.h:204
@ PROP_HIDDEN
Definition: RNA_types.h:202
#define C
Definition: RandGen.cpp:39
bool UI_but_active_drop_name(struct bContext *C)
void UI_context_active_but_prop_get_templateID(struct bContext *C, struct PointerRNA *r_ptr, struct PropertyRNA **r_prop)
#define UI_DPI_FAC
Definition: UI_interface.h:309
void UI_view2d_region_to_view(const struct View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
#define WM_FILESEL_RELPATH
Definition: WM_api.h:533
#define WM_FILESEL_FILEPATH
Definition: WM_api.h:537
@ OPTYPE_INTERNAL
Definition: WM_types.h:175
@ OPTYPE_UNDO
Definition: WM_types.h:155
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define NA_EDITED
Definition: WM_types.h:462
#define NC_IMAGE
Definition: WM_types.h:285
OperationNode * node
bool node_link_bezier_points(const View2D *v2d, const SpaceNode *snode, const bNodeLink *link, float coord_array[][2], const int resol)
Definition: drawnode.c:3746
bNodeTree * ntree
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
static bool node_add_object_poll(bContext *C)
Definition: node_add.c:519
static int node_add_object_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: node_add.c:501
static bool node_add_texture_poll(bContext *C)
Definition: node_add.c:618
void NODE_OT_add_file(wmOperatorType *ot)
Definition: node_add.c:836
void NODE_OT_add_collection(wmOperatorType *ot)
Definition: node_add.c:730
static const EnumPropertyItem * new_node_tree_type_itemf(bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
Definition: node_add.c:991
static int node_add_mask_exec(bContext *C, wmOperator *op)
Definition: node_add.c:874
static Object * node_add_object_get_and_poll_object_node_tree(Main *bmain, wmOperator *op)
Definition: node_add.c:446
void NODE_OT_add_group(wmOperatorType *ot)
Definition: node_add.c:422
static int node_add_texture_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: node_add.c:600
static bNodeTree * node_add_group_get_and_poll_group_node_tree(Main *bmain, wmOperator *op, bNodeTree *ntree)
Definition: node_add.c:331
void NODE_OT_add_reroute(wmOperatorType *ot)
Definition: node_add.c:301
static bool node_add_mask_poll(bContext *C)
Definition: node_add.c:867
static int node_add_group_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: node_add.c:404
static int node_add_object_exec(bContext *C, wmOperator *op)
Definition: node_add.c:459
void NODE_OT_add_texture(wmOperatorType *ot)
Definition: node_add.c:625
static int node_add_collection_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: node_add.c:705
static bNodeSocketLink * add_reroute_insert_socket_link(ListBase *lb, bNodeSocket *sock, bNodeLink *link, const float point[2])
Definition: node_add.c:138
static int add_reroute_exec(bContext *C, wmOperator *op)
Definition: node_add.c:225
static int node_add_file_exec(bContext *C, wmOperator *op)
Definition: node_add.c:762
static bool node_add_collection_poll(bContext *C)
Definition: node_add.c:723
static int node_add_texture_exec(bContext *C, wmOperator *op)
Definition: node_add.c:563
static Collection * node_add_collection_get_and_poll_collection_node_tree(Main *bmain, wmOperator *op)
Definition: node_add.c:650
void NODE_OT_add_mask(wmOperatorType *ot)
Definition: node_add.c:909
static int node_add_collection_exec(bContext *C, wmOperator *op)
Definition: node_add.c:664
void NODE_OT_add_object(wmOperatorType *ot)
Definition: node_add.c:526
static bNodeSocketLink * add_reroute_do_socket_section(bContext *C, bNodeSocketLink *socklink, int in_out)
Definition: node_add.c:159
static int node_add_file_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: node_add.c:814
bNode * node_add_node(const bContext *C, const char *idname, int type, float locx, float locy)
Definition: node_add.c:70
struct bNodeSocketLink bNodeSocketLink
static Tex * node_add_texture_get_and_poll_texture_node_tree(Main *bmain, wmOperator *op)
Definition: node_add.c:550
static bool add_reroute_intersect_check(bNodeLink *link, float mcoords[][2], int tot, float result[2])
Definition: node_add.c:110
void NODE_OT_new_node_tree(wmOperatorType *ot)
Definition: node_add.c:999
static bool node_add_file_poll(bContext *C)
Definition: node_add.c:755
static int node_add_group_exec(bContext *C, wmOperator *op)
Definition: node_add.c:367
static int new_node_tree_exec(bContext *C, wmOperator *op)
Definition: node_add.c:932
void snode_update(SpaceNode *snode, bNode *node)
Definition: node_edit.c:643
void snode_dag_update(bContext *C, SpaceNode *snode)
Definition: node_edit.c:393
void snode_notify(bContext *C, SpaceNode *snode)
Definition: node_edit.c:411
const char * node_group_idname(bContext *C)
Definition: node_group.c:110
#define NODE_LINK_RESOL
Definition: node_intern.h:335
void node_deselect_all(struct SpaceNode *snode)
Definition: node_select.c:204
#define NODE_DY
Definition: node_intern.h:327
void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
Definition: rna_access.c:122
void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value, ReportList *reports)
Definition: rna_access.c:3673
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:866
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
Definition: rna_access.c:6378
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2317
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
Definition: rna_access.c:6514
bool RNA_property_enum_identifier(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier)
Definition: rna_access.c:1925
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3543
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:6685
PropertyRNA * RNA_def_collection_runtime(StructOrFunctionRNA *cont_, const char *identifier, StructRNA *type, const char *ui_name, const char *ui_description)
Definition: rna_define.c:4210
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3675
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3585
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
Definition: rna_define.c:3819
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3771
const EnumPropertyItem DummyRNA_NULL_items[]
Definition: rna_rna.c:40
Definition: DNA_ID.h:273
char name[66]
Definition: DNA_ID.h:283
void * last
Definition: DNA_listBase.h:47
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
char tree_idname[64]
SpaceNode_Runtime * runtime
struct bNodeTree * edittree
struct bNodeTree * nodetree
struct Collection * value
struct Object * value
void * default_value
ListBase links
float locy
ListBase inputs
struct ID * id
float locx
ListBase outputs
int mval[2]
Definition: WM_types.h:583
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:752
const char * name
Definition: WM_types.h:721
int(* modal)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:768
const char * idname
Definition: WM_types.h:723
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:776
void(* cancel)(struct bContext *, struct wmOperator *)
Definition: WM_types.h:760
struct StructRNA * srna
Definition: WM_types.h:802
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
struct ReportList * reports
struct PointerRNA * ptr
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
@ WM_CURSOR_CROSS
Definition: wm_cursors.h:42
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3157
wmOperatorType * ot
Definition: wm_files.c:3156
int WM_gesture_lines_modal(bContext *C, wmOperator *op, const wmEvent *event)
void WM_gesture_lines_cancel(bContext *C, wmOperator *op)
int WM_gesture_lines_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void WM_operator_properties_filesel(wmOperatorType *ot, int filter, short type, short action, short flag, short display, short sort)
int WM_operator_filesel(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
ID * WM_operator_drop_load_path(struct bContext *C, wmOperator *op, const short idcode)