Blender V5.3
node_composite_switch_view.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
5#include "BLI_listbase.hh"
6
7#include "DNA_node_types.h"
8
9#include "BKE_context.hh"
10#include "BKE_lib_id.hh"
11#include "BKE_node.hh"
12#include "BKE_node_runtime.hh"
13
14#include "COM_node_operation.hh"
15
17
19
21{
22 b.add_output<decl::Color>("Image"_ustr).structure_type(StructureType::Dynamic);
23
24 const bNode *node = b.node_or_null();
25 if (node == nullptr) {
26 return;
27 }
28
29 Scene *scene = reinterpret_cast<Scene *>(node->id);
30
31 if (scene != nullptr) {
32 /* add the new views */
33 for (SceneRenderView &srv : scene->r.views) {
34 if (srv.viewflag & SCE_VIEW_DISABLE) {
35 continue;
36 }
37 b.add_input<decl::Color>(UString(srv.name))
38 .default_value({0.0f, 0.0f, 0.0f, 1.0f})
39 .structure_type(StructureType::Dynamic);
40 }
41 }
42}
43
44static void node_init_api(const bContext *C, PointerRNA *node_ptr)
45{
46 Scene *scene = CTX_data_scene(C);
47 bNode *node = node_ptr->data_as<bNode>();
48 node->id = id_cast<ID *>(scene);
49 id_us_plus(node->id);
50}
51
52using namespace blender::compositor;
53
55 public:
57
58 void execute() override
59 {
60 Result &result = get_result("Image");
61
62 /* A context that is not multi view, pass the first input through as a fallback. */
63 if (this->context().get_view_name().is_empty()) {
64 const Result &input = this->get_input(this->node().input_socket(0).identifier);
65 result.share_data(input);
66 return;
67 }
68
69 const Result &input = this->get_input(this->context().get_view_name());
70 result.share_data(input);
71 }
72};
73
75{
76 return new SwitchViewOperation(context, node);
77}
78
79static void node_register()
80{
81 static bke::bNodeType ntype;
82
83 cmp_node_type_base(&ntype, "CompositorNodeSwitchView"_ustr, CMP_NODE_SWITCH_VIEW);
84 ntype.ui_name = "Switch View";
85 ntype.ui_description = "Combine the views (left and right) into a single stereo 3D output";
86 ntype.enum_name_legacy = "VIEWSWITCH";
88 ntype.declare = node_declare;
91
93}
95
96} // namespace blender::nodes::node_composite_switch_view_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define CMP_NODE_SWITCH_VIEW
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define C
Definition RandGen.cpp:29
UString()=default
NodeOperation(Context &context, const bNode &node)
Result & get_result(StringRef identifier)
Definition operation.cc:40
Context & context() const
Definition operation.cc:57
Result & get_input(StringRef identifier) const
Definition operation.cc:35
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static void node_init_api(const bContext *C, PointerRNA *node_ptr)
static void node_declare(NodeDeclarationBuilder &b)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
void id_us_plus(ID *id)
Definition lib_id.cc:433
Scene * CTX_data_scene(const bContext *C)
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
T * data_as() const
Definition RNA_types.hh:139
ListBaseT< SceneRenderView > views
struct RenderData r
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
void(*) initfunc_api(const bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:333
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:379
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393