Blender V4.5
node_composite_tree.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2007 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DNA_node_types.h"
10#include "DNA_scene_types.h"
11
12#include "BLI_listbase.h"
13
14#include "BKE_context.hh"
15#include "BKE_global.hh"
16#include "BKE_image.hh"
17#include "BKE_main.hh"
18#include "BKE_node.hh"
19#include "BKE_node_runtime.hh"
21#include "BKE_tracking.h"
22
23#include "UI_resources.hh"
24
25#include "node_common.h"
26
27#include "RNA_prototypes.hh"
28
29#include "NOD_composite.hh"
31
33 blender::bke::bNodeTreeType * /*treetype*/,
34 bNodeTree **r_ntree,
35 ID **r_id,
36 ID **r_from)
37{
38 Scene *scene = CTX_data_scene(C);
39
40 *r_from = nullptr;
41 *r_id = &scene->id;
42 *r_ntree = scene->nodetree;
43}
44
45static void foreach_nodeclass(void *calldata, blender::bke::bNodeClassCallback func)
46{
47 func(calldata, NODE_CLASS_INPUT, N_("Input"));
48 func(calldata, NODE_CLASS_OUTPUT, N_("Output"));
49 func(calldata, NODE_CLASS_OP_COLOR, N_("Color"));
50 func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector"));
51 func(calldata, NODE_CLASS_OP_FILTER, N_("Filter"));
52 func(calldata, NODE_CLASS_CONVERTER, N_("Converter"));
53 func(calldata, NODE_CLASS_MATTE, N_("Matte"));
54 func(calldata, NODE_CLASS_DISTORT, N_("Distort"));
55 func(calldata, NODE_CLASS_GROUP, N_("Group"));
56 func(calldata, NODE_CLASS_INTERFACE, N_("Interface"));
57 func(calldata, NODE_CLASS_LAYOUT, N_("Layout"));
58}
59
60/* local tree then owns all compbufs */
61static void localize(bNodeTree *localtree, bNodeTree *ntree)
62{
63
64 bNode *node = (bNode *)ntree->nodes.first;
65 bNode *local_node = (bNode *)localtree->nodes.first;
66 while (node != nullptr) {
67
68 /* Ensure new user input gets handled ok. */
69 node->runtime->need_exec = 0;
70 local_node->runtime->original = node;
71
72 /* move over the compbufs */
73 /* right after #blender::bke::node_tree_copy_tree() `oldsock` pointers are valid */
74
75 if (node->type_legacy == CMP_NODE_VIEWER) {
76 if (node->id) {
77 if (node->flag & NODE_DO_OUTPUT) {
78 local_node->id = (ID *)node->id;
79 }
80 else {
81 local_node->id = nullptr;
82 }
83 }
84 }
85
86 node = node->next;
87 local_node = local_node->next;
88 }
89}
90
91static void local_merge(Main *bmain, bNodeTree *localtree, bNodeTree *ntree)
92{
93 /* move over the compbufs and previews */
94 blender::bke::node_preview_merge_tree(ntree, localtree, true);
95
96 LISTBASE_FOREACH (bNode *, lnode, &localtree->nodes) {
97 if (bNode *orig_node = blender::bke::node_find_node_by_name(*ntree, lnode->name)) {
98 if (lnode->type_legacy == CMP_NODE_VIEWER) {
99 if (lnode->id && (lnode->flag & NODE_DO_OUTPUT)) {
100 /* image_merge does sanity check for pointers */
101 BKE_image_merge(bmain, (Image *)orig_node->id, (Image *)lnode->id);
102 }
103 }
104 else if (lnode->type_legacy == CMP_NODE_MOVIEDISTORTION) {
105 /* special case for distortion node: distortion context is allocating in exec function
106 * and to achieve much better performance on further calls this context should be
107 * copied back to original node */
108 if (lnode->storage) {
109 if (orig_node->storage) {
110 BKE_tracking_distortion_free((MovieDistortion *)orig_node->storage);
111 }
112
113 orig_node->storage = BKE_tracking_distortion_copy((MovieDistortion *)lnode->storage);
114 }
115 }
116 }
117 }
118}
119
120static void update(bNodeTree *ntree)
121{
123
125}
126
127static void composite_node_add_init(bNodeTree * /*bnodetree*/, bNode *bnode)
128{
129 /* Composite node will only show previews for input classes
130 * by default, other will be hidden
131 * but can be made visible with the show_preview option */
132 if (bnode->typeinfo->nclass != NODE_CLASS_INPUT) {
133 bnode->flag &= ~NODE_PREVIEW;
134 }
135}
136
143
145{
146 /* All supported types can be implicitly converted to other types. */
147 return true;
148}
149
151
153{
154 blender::bke::bNodeTreeType *tt = ntreeType_Composite = MEM_new<blender::bke::bNodeTreeType>(
155 __func__);
156
157 tt->type = NTREE_COMPOSIT;
158 tt->idname = "CompositorNodeTree";
159 tt->group_idname = "CompositorNodeGroup";
160 tt->ui_name = N_("Compositor");
161 tt->ui_icon = ICON_NODE_COMPOSITING;
162 tt->ui_description = N_("Compositing nodes");
163
165 tt->localize = localize;
167 tt->update = update;
172
173 tt->rna_ext.srna = &RNA_CompositorNodeTree;
174
176}
177
178/* *********************************************** */
179
181{
182 if (ntree == nullptr) {
183 return;
184 }
185
186 for (bNode *node : ntree->all_nodes()) {
187 if (node->type_legacy == CMP_NODE_R_LAYERS) {
188 node_cmp_rlayers_outputs(ntree, node);
189 }
190 else if (node->type_legacy == CMP_NODE_CRYPTOMATTE &&
191 node->custom1 == CMP_NODE_CRYPTOMATTE_SOURCE_RENDER)
192 {
193 node->typeinfo->updatefunc(ntree, node);
194 }
195 }
196}
197
199{
200 /* XXX Think using G_MAIN here is valid, since you want to update current file's scene nodes,
201 * not the ones in temp main generated for rendering?
202 * This is still rather weak though,
203 * ideally render struct would store its own main AND original G_MAIN. */
204
205 for (Scene *sce_iter = (Scene *)G_MAIN->scenes.first; sce_iter;
206 sce_iter = (Scene *)sce_iter->id.next)
207 {
208 if (sce_iter->nodetree) {
209 for (bNode *node : sce_iter->nodetree->all_nodes()) {
210 if (node->id == (ID *)scene || node->type_legacy == CMP_NODE_COMPOSITE) {
211 BKE_ntree_update_tag_node_property(sce_iter->nodetree, node);
212 }
213 else if (node->type_legacy == CMP_NODE_TEXTURE) /* uses scene size_x/size_y */ {
214 BKE_ntree_update_tag_node_property(sce_iter->nodetree, node);
215 }
216 }
217 }
218 }
220}
221
223{
224 /* XXX: after render animation system gets a refresh, this call allows composite to end clean. */
225
226 if (ntree == nullptr) {
227 return;
228 }
229
230 for (bNode *node : ntree->all_nodes()) {
231 node->runtime->need_exec = 0;
232 if (node->is_group()) {
234 }
235 }
236}
237
239{
240 node->runtime->need_exec = true;
241}
Scene * CTX_data_scene(const bContext *C)
#define G_MAIN
void BKE_image_merge(Main *bmain, Image *dest, Image *source)
#define NODE_CLASS_OUTPUT
Definition BKE_node.hh:434
#define NODE_CLASS_INTERFACE
Definition BKE_node.hh:445
#define NODE_CLASS_MATTE
Definition BKE_node.hh:440
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:439
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:441
#define NODE_CLASS_OP_VECTOR
Definition BKE_node.hh:436
#define NODE_CLASS_LAYOUT
Definition BKE_node.hh:449
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:435
#define NODE_CLASS_INPUT
Definition BKE_node.hh:433
#define NODE_CLASS_OP_FILTER
Definition BKE_node.hh:437
#define NODE_CLASS_GROUP
Definition BKE_node.hh:438
#define CMP_NODE_COMPOSITE
#define CMP_NODE_VIEWER
#define CMP_NODE_CRYPTOMATTE
#define CMP_NODE_MOVIEDISTORTION
#define CMP_NODE_TEXTURE
#define CMP_NODE_R_LAYERS
void BKE_ntree_update(Main &bmain, std::optional< blender::Span< bNodeTree * > > modified_trees=std::nullopt, const NodeTreeUpdateExtraParams &params={})
void BKE_ntree_update_tag_node_property(bNodeTree *ntree, bNode *node)
struct MovieDistortion * BKE_tracking_distortion_copy(struct MovieDistortion *distortion)
Definition tracking.cc:2306
void BKE_tracking_distortion_free(struct MovieDistortion *distortion)
Definition tracking.cc:2407
#define LISTBASE_FOREACH(type, var, list)
#define ELEM(...)
@ CMP_NODE_CRYPTOMATTE_SOURCE_RENDER
@ NTREE_COMPOSIT
@ NODE_DO_OUTPUT
@ NODE_PREVIEW
eNodeSocketDatatype
@ SOCK_INT
@ SOCK_VECTOR
@ SOCK_BOOLEAN
@ SOCK_FLOAT
@ SOCK_RGBA
#define C
Definition RandGen.cpp:29
bNode * node_find_node_by_name(bNodeTree &ntree, StringRefNull name)
Definition node.cc:3607
void node_tree_set_output(bNodeTree &ntree)
Definition node.cc:4742
void node_tree_type_add(bNodeTreeType &nt)
Definition node.cc:2672
void(*)(void *calldata, int nclass, StringRefNull name) bNodeClassCallback
Definition BKE_node.hh:478
void node_preview_merge_tree(bNodeTree *to_ntree, bNodeTree *from_ntree, bool remove_old)
Definition node.cc:4517
bool node_is_static_socket_type(const bNodeSocketType &stype)
Definition node.cc:3158
void ntree_update_reroute_nodes(bNodeTree *ntree)
void node_cmp_rlayers_outputs(bNodeTree *ntree, bNode *node)
static void composite_node_add_init(bNodeTree *, bNode *bnode)
void ntreeCompositTagRender(Scene *scene)
static void local_merge(Main *bmain, bNodeTree *localtree, bNodeTree *ntree)
static void localize(bNodeTree *localtree, bNodeTree *ntree)
void ntreeCompositTagNeedExec(bNode *node)
static void update(bNodeTree *ntree)
void ntreeCompositUpdateRLayers(bNodeTree *ntree)
void ntreeCompositClearTags(bNodeTree *ntree)
static bool composite_node_tree_socket_type_valid(blender::bke::bNodeTreeType *, blender::bke::bNodeSocketType *socket_type)
static void composite_get_from_context(const bContext *C, blender::bke::bNodeTreeType *, bNodeTree **r_ntree, ID **r_id, ID **r_from)
blender::bke::bNodeTreeType * ntreeType_Composite
static bool composite_validate_link(eNodeSocketDatatype, eNodeSocketDatatype)
void register_node_tree_type_cmp()
static void foreach_nodeclass(void *calldata, blender::bke::bNodeClassCallback func)
StructRNA * srna
Definition RNA_types.hh:909
Definition DNA_ID.h:404
void * first
struct bNodeTree * nodetree
ListBase nodes
bNodeTypeHandle * typeinfo
struct ID * id
int16_t type_legacy
struct bNode * next
bNodeRuntimeHandle * runtime
Defines a socket type.
Definition BKE_node.hh:152
eNodeSocketDatatype type
Definition BKE_node.hh:187
void(* update)(bNodeTree *ntree)
Definition BKE_node.hh:508
void(* foreach_nodeclass)(void *calldata, bNodeClassCallback func)
Definition BKE_node.hh:493
void(* node_add_init)(bNodeTree *ntree, bNode *bnode)
Definition BKE_node.hh:512
void(* get_from_context)(const bContext *C, bNodeTreeType *ntreetype, bNodeTree **r_ntree, ID **r_id, ID **r_from)
Definition BKE_node.hh:497
void(* localize)(bNodeTree *localtree, bNodeTree *ntree)
Definition BKE_node.hh:504
void(* local_merge)(Main *bmain, bNodeTree *localtree, bNodeTree *ntree)
Definition BKE_node.hh:505
bool(* validate_link)(eNodeSocketDatatype from, eNodeSocketDatatype to)
Definition BKE_node.hh:510
bool(* valid_socket_type)(bNodeTreeType *ntreetype, bNodeSocketType *socket_type)
Definition BKE_node.hh:515
#define N_(msgid)