Blender V4.5
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 "UI_interface.hh"
15
16#include "COM_node_operation.hh"
17
19
20/* **************** SWITCH VIEW ******************** */
21
23
25{
26 b.add_output<decl::Color>(N_("Image"));
27
28 const bNode *node = b.node_or_null();
29 if (node == nullptr) {
30 return;
31 }
32
33 Scene *scene = reinterpret_cast<Scene *>(node->id);
34
35 if (scene != nullptr) {
36 /* add the new views */
37 LISTBASE_FOREACH (SceneRenderView *, srv, &scene->r.views) {
38 if (srv->viewflag & SCE_VIEW_DISABLE) {
39 continue;
40 }
41 b.add_input<decl::Color>(N_(srv->name)).default_value({0.0f, 0.0f, 0.0f, 1.0f});
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:353
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:439
#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:2748
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:404
struct RenderData r
struct ID * id
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:336
const char * enum_name_legacy
Definition BKE_node.hh:235
NodeDeclareFunction declare
Definition BKE_node.hh:355
void(* initfunc_api)(const bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
#define N_(msgid)
PointerRNA * ptr
Definition wm_files.cc:4226