Blender V5.0
node_composite_switchview.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_listbase.h"
10
11#include "BKE_context.hh"
12#include "BKE_lib_id.hh"
13
14#include "COM_node_operation.hh"
15
17
18/* **************** SWITCH VIEW ******************** */
19
21
23{
24 b.add_output<decl::Color>(N_("Image")).structure_type(StructureType::Dynamic);
25
26 const bNode *node = b.node_or_null();
27 if (node == nullptr) {
28 return;
29 }
30
31 Scene *scene = reinterpret_cast<Scene *>(node->id);
32
33 if (scene != nullptr) {
34 /* add the new views */
35 LISTBASE_FOREACH (SceneRenderView *, srv, &scene->r.views) {
36 if (srv->viewflag & SCE_VIEW_DISABLE) {
37 continue;
38 }
39 b.add_input<decl::Color>(N_(srv->name))
40 .default_value({0.0f, 0.0f, 0.0f, 1.0f})
41 .structure_type(StructureType::Dynamic);
42 }
43 }
44}
45
47{
48 Scene *scene = CTX_data_scene(C);
49 bNode *node = (bNode *)ptr->data;
50
51 /* store scene for dynamic declaration */
52 node->id = (ID *)scene;
53 id_us_plus(node->id);
54}
55
56using namespace blender::compositor;
57
59 public:
61
62 void execute() override
63 {
64 Result &result = get_result("Image");
65
66 /* A context that is not multi view, pass the first input through as a fallback. */
67 if (context().get_view_name().is_empty()) {
68 const Result &input = get_input(node().input(0)->identifier);
69 result.share_data(input);
70 return;
71 }
72
73 const Result &input = get_input(context().get_view_name());
74 result.share_data(input);
75 }
76};
77
79{
80 return new SwitchViewOperation(context, node);
81}
82
83} // namespace blender::nodes::node_composite_switchview_cc
84
86{
88
89 static blender::bke::bNodeType ntype;
90
91 cmp_node_type_base(&ntype, "CompositorNodeSwitchView", CMP_NODE_SWITCH_VIEW);
92 ntype.ui_name = "Switch View";
93 ntype.ui_description = "Combine the views (left and right) into a single stereo 3D output";
94 ntype.enum_name_legacy = "VIEWSWITCH";
96 ntype.declare = file_ns::node_declare;
97 ntype.initfunc_api = file_ns::init_switch_view;
98 ntype.get_compositor_operation = file_ns::get_compositor_operation;
99
101}
Scene * CTX_data_scene(const bContext *C)
void id_us_plus(ID *id)
Definition lib_id.cc:358
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:453
#define CMP_NODE_SWITCH_VIEW
#define LISTBASE_FOREACH(type, var, list)
@ SCE_VIEW_DISABLE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define C
Definition RandGen.cpp:29
NodeOperation(Context &context, DNode node)
Result & get_result(StringRef identifier)
Definition operation.cc:39
Result & get_input(StringRef identifier) const
Definition operation.cc:138
#define input
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
static NodeOperation * get_compositor_operation(Context &context, DNode node)
static void node_declare(NodeDeclarationBuilder &b)
static void init_switch_view(const bContext *C, PointerRNA *ptr)
static void register_node_type_cmp_switch_view()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Definition DNA_ID.h:414
struct RenderData r
struct ID * id
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:348
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362
void(* initfunc_api)(const bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:302
#define N_(msgid)
PointerRNA * ptr
Definition wm_files.cc:4238