Blender V5.3
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#include "DNA_space_types.h"
12
13#include "BLI_listbase.hh"
14
15#include "BKE_compositor.hh"
16#include "BKE_context.hh"
17#include "BKE_global.hh"
18#include "BKE_image.hh"
19#include "BKE_main.hh"
20#include "BKE_node.hh"
21#include "BKE_node_runtime.hh"
23#include "BKE_tracking.hh"
24
25#include "UI_resources.hh"
26
27#include "SEQ_modifier.hh"
28#include "SEQ_select.hh"
29#include "SEQ_sequencer.hh"
30
31#include "node_common.h"
32
33#include "RNA_prototypes.hh"
34
35#include "NOD_composite.hh"
37
38namespace blender {
39
41 bke::bNodeTreeType * /*treetype*/,
42 bNodeTree **r_ntree,
43 ID **r_id,
44 ID **r_from)
45{
46 const SpaceNode *snode = CTX_wm_space_node(C);
48 *r_ntree = nullptr;
49 Scene *sequencer_scene = CTX_data_sequencer_scene(C);
50 if (!sequencer_scene) {
51 return;
52 }
53 Strip *strip = seq::select_active_get(sequencer_scene);
54 if (!strip) {
55 return;
56 }
57
58 bNodeTree *node_group = nullptr;
59 if (strip->type == STRIP_TYPE_COMPOSITOR && strip->effectdata) {
60 CompositorEffectVars *comp_data = static_cast<CompositorEffectVars *>(strip->effectdata);
61 node_group = comp_data->node_group;
62 }
63 else {
65 if (smd && smd->type == eSeqModifierType_Compositor) {
67 reinterpret_cast<SequencerCompositorModifierData *>(smd);
68 node_group = scmd->node_group;
69 }
70 }
71
72 if (node_group) {
73 *r_from = nullptr;
74 *r_id = &sequencer_scene->id;
75 *r_ntree = node_group;
76 }
77 return;
78 }
79
80 Scene *scene = CTX_data_scene(C);
82 if (!effect || !effect->node_group || ID_MISSING(effect->node_group)) {
83 return;
84 }
85
86 *r_from = &scene->id;
87 *r_id = &scene->id;
88 *r_ntree = effect->node_group;
89}
90
91static void foreach_nodeclass(void *calldata, bke::bNodeClassCallback func)
92{
93 func(calldata, NODE_CLASS_INPUT, N_("Input"));
94 func(calldata, NODE_CLASS_OUTPUT, N_("Output"));
95 func(calldata, NODE_CLASS_OP_COLOR, N_("Color"));
96 func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector"));
97 func(calldata, NODE_CLASS_OP_FILTER, N_("Filter"));
98 func(calldata, NODE_CLASS_CONVERTER, N_("Converter"));
99 func(calldata, NODE_CLASS_MATTE, N_("Matte"));
100 func(calldata, NODE_CLASS_DISTORT, N_("Distort"));
101 func(calldata, NODE_CLASS_GROUP, N_("Group"));
102 func(calldata, NODE_CLASS_INTERFACE, N_("Interface"));
103 func(calldata, NODE_CLASS_LAYOUT, N_("Layout"));
104}
105
106static void update(bNodeTree *ntree)
107{
109
111}
112
114 bke::bNodeSocketType *socket_type)
115{
116 return bke::node_is_static_socket_type(*socket_type) && ELEM(socket_type->type,
118 SOCK_INT,
122 SOCK_RGBA,
124 SOCK_MENU,
128 SOCK_FONT,
130}
131
137{
138 /* Basic math types can be implicitly converted to each other. */
139 if (ELEM(from_type,
143 SOCK_RGBA,
145 SOCK_INT) &&
147 {
148 return true;
149 }
150
151 if (ELEM(from_type, SOCK_FLOAT, SOCK_VECTOR) && to_type == SOCK_ROTATION) {
152 return true;
153 }
154
155 if (from_type == SOCK_MATRIX && to_type == SOCK_ROTATION) {
156 return true;
157 }
158 if (from_type == SOCK_ROTATION && to_type == SOCK_MATRIX) {
159 return true;
160 }
161
162 if (from_type == SOCK_ROTATION && to_type == SOCK_VECTOR) {
163 return true;
164 }
165
166 return from_type == to_type;
167}
168
170
172{
173 bke::bNodeTreeType *tt = ntreeType_Composite = MEM_new<bke::bNodeTreeType>(__func__);
174
175 tt->type = NTREE_COMPOSIT;
176 tt->idname = "CompositorNodeTree"_ustr;
177 tt->group_idname = "CompositorNodeGroup"_ustr;
178 tt->ui_name = N_("Compositor");
179 tt->ui_icon = ICON_NODE_COMPOSITING;
180 tt->ui_description = N_("Create effects and post-process renders, images, and the 3D Viewport");
181 tt->asset_catalog_path_prefix = "Compositing";
182
184 tt->update = update;
188
189 tt->rna_ext.srna = RNA_CompositorNodeTree;
190
192}
193
194/* *********************************************** */
195
197{
198 /* XXX Think using G_MAIN here is valid, since you want to update current file's scene nodes,
199 * not the ones in temp main generated for rendering?
200 * This is still rather weak though,
201 * ideally render struct would store its own main AND original G_MAIN. */
202
203 for (Scene *sce_iter = G_MAIN->scenes.first(); sce_iter;
204 sce_iter = static_cast<Scene *>(sce_iter->id.next))
205 {
206 for (const SceneCompositorEffect &effect : sce_iter->compositor_effects) {
207 if (effect.node_group && !ID_MISSING(effect.node_group)) {
208 for (bNode *node : effect.node_group->all_nodes()) {
209 if (node->id == (ID *)scene) {
211 }
212 }
213 }
214 }
215 }
217}
218
219} // namespace blender
#define G_MAIN
#define NODE_CLASS_OUTPUT
Definition BKE_node.hh:479
#define NODE_CLASS_INTERFACE
Definition BKE_node.hh:490
#define NODE_CLASS_MATTE
Definition BKE_node.hh:485
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:486
#define NODE_CLASS_OP_VECTOR
Definition BKE_node.hh:481
#define NODE_CLASS_LAYOUT
Definition BKE_node.hh:494
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:480
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define NODE_CLASS_OP_FILTER
Definition BKE_node.hh:482
#define NODE_CLASS_GROUP
Definition BKE_node.hh:483
#define ID_MISSING(_id)
Definition DNA_ID.h:695
#define C
Definition RandGen.cpp:29
#define ELEM(...)
uint to_type(bool)
SceneCompositorEffect * get_active_effect(const Scene &scene)
void node_tree_set_output(bNodeTree &ntree)
Definition node.cc:5238
void node_tree_type_add(bNodeTreeType &nt)
Definition node.cc:2844
void(*)(void *calldata, int nclass, StringRefNull name) bNodeClassCallback
Definition BKE_node.hh:523
bool node_is_static_socket_type(const bNodeSocketType &stype)
Definition node.cc:3483
Strip * select_active_get(const Scene *scene)
StripModifierData * modifier_get_active(const Strip *strip)
BMesh Iterators.
void BKE_ntree_update(Main &bmain, std::optional< Span< bNodeTree * > > modified_trees=std::nullopt, const NodeTreeUpdateExtraParams &params={})
Scene * CTX_data_sequencer_scene(const bContext *C)
static bool composite_node_tree_socket_type_valid(bke::bNodeTreeType *, bke::bNodeSocketType *socket_type)
static bool composite_validate_link(eNodeSocketDatatype from_type, eNodeSocketDatatype to_type)
bke::bNodeTreeType * ntreeType_Composite
static void composite_get_from_context(const bContext *C, bke::bNodeTreeType *, bNodeTree **r_ntree, ID **r_id, ID **r_from)
@ SNODE_COMPOSITOR_SEQUENCER
SpaceNode * CTX_wm_space_node(const bContext *C)
static void update(bNodeTree *ntree)
void BKE_ntree_update_tag_node_property(bNodeTree *ntree, bNode *node)
void ntree_update_reroute_nodes(bNodeTree *ntree)
void ntreeCompositTagRender(Scene *scene)
void register_node_tree_type_cmp()
Scene * CTX_data_scene(const bContext *C)
@ eSeqModifierType_Compositor
static void foreach_nodeclass(void *calldata, bke::bNodeClassCallback func)
Defines a socket type.
Definition BKE_node.hh:163
eNodeSocketDatatype type
Definition BKE_node.hh:198
bool(*) valid_socket_type(bNodeTreeType *ntreetype, bNodeSocketType *socket_type)
Definition BKE_node.hh:569
void(*) get_from_context(const bContext *C, bNodeTreeType *ntreetype, bNodeTree **r_ntree, ID **r_id, ID **r_from)
Definition BKE_node.hh:554
void(*) update(bNodeTree *ntree)
Definition BKE_node.hh:564
void(*) foreach_nodeclass(void *calldata, bNodeClassCallback func)
Definition BKE_node.hh:550
std::optional< std::string > asset_catalog_path_prefix
Definition BKE_node.hh:546
bool(*) validate_link(eNodeSocketDatatype from, eNodeSocketDatatype to)
Definition BKE_node.hh:566
#define N_(msgid)