Blender V5.0
group_nodes.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "group_nodes.h"
6#include "node_parser.h"
7
8#include "BKE_node_runtime.hh"
9
10#ifdef USE_MATERIALX_NODEGRAPH
11# include "BLI_vector.hh"
12#endif
13
15
17 const bNode *node,
18 const bNodeSocket *socket_out,
20 GroupNodeParser *group_parser,
21 bool use_group_default)
22 : NodeParser(graph, node, socket_out, to_type, group_parser),
23 use_group_default_(use_group_default)
25}
26
28{
29 const bNodeTree *ngroup = reinterpret_cast<const bNodeTree *>(node_->id);
30 ngroup->ensure_topology_cache();
31 const bNode *node_out = ngroup->group_output_node();
32 if (!node_out) {
33 return empty();
34 }
35
36 NodeGraph group_graph(graph_, ngroup->id.name + 2);
37
39 group_graph, node_out, socket_out_, to_type_, this, use_group_default_)
40 .compute_full();
41
42#ifdef USE_MATERIALX_NODEGRAPH
43 /* We have to be in NodeParser's graph_, therefore copying output */
44 NodeItem res = empty();
45 res.output = out.output;
46 return res;
47#else
48 return out;
49#endif
50}
51
53{
54 NodeItem res = compute();
56 res = res.convert(to_type_);
57 }
58 return res;
59}
60
62{
63#ifdef USE_MATERIALX_NODEGRAPH
64 Vector<NodeItem> values;
65 for (const auto *socket_in : node_->input_sockets()) {
68 if (value.value) {
69 value = create_node("constant", value.type(), {{"value", value}});
70 }
71 values.append(value);
72 }
74 for (int i = 0; i < values.size(); ++i) {
75 if (values[i]) {
76 outputs.append(create_output(out_name(node_->input_sockets()[i]), values[i]));
77 }
78 }
79 return outputs[socket_out_->index()];
80#else
81 if (use_group_default_) {
82 return get_input_value(socket_out_->index(), to_type_);
83 }
84 return get_input_link(socket_out_->index(), to_type_);
85#endif
86}
87
89{
91 "%s [%d] => %s",
92 node_->name,
93 node_->typeinfo->type_legacy,
94 NodeItem::type(to_type_).c_str());
95
96#ifdef USE_MATERIALX_NODEGRAPH
97 /* Checking if output was already computed */
98 NodeItem res = graph_.get_output(out_name(socket_out_));
99 if (res.output) {
100 return res;
101 }
102
103 res = compute();
104 return res;
105#else
106 return compute();
107#endif
108}
109
110std::string GroupOutputNodeParser::out_name(const bNodeSocket *out_socket)
111{
112 return MaterialX::createValidName(std::string("out_") + out_socket->identifier);
113}
114
116{
117#ifdef USE_MATERIALX_NODEGRAPH
118 NodeItem value = group_parser_->get_input_link(socket_out_->index(), to_type_);
119 if (!value) {
120 return empty();
121 }
122
123 if (value.value) {
124 value = group_parser_->create_node("constant", value.type(), {{"value", value}});
125 }
126 return create_input(in_name(), value);
127#else
128 if (use_group_default_) {
129 return group_parser_->get_input_value(socket_out_->index(), to_type_);
130 }
131 return group_parser_->get_input_link(socket_out_->index(), to_type_);
132#endif
133}
134
136{
138 "%s [%d] => %s",
139 node_->name,
140 node_->typeinfo->type_legacy,
141 NodeItem::type(to_type_).c_str());
142
143#ifdef USE_MATERIALX_NODEGRAPH
144 /* Checking if input was already computed */
145 NodeItem res = graph_.get_input(in_name());
146 if (res.input) {
147 return res;
148 }
149
150 res = compute();
151 return res;
152#else
153 return compute();
154#endif
155}
156
157std::string GroupInputNodeParser::in_name() const
158{
159 return MaterialX::createValidName(std::string("in_") + socket_out_->identifier);
160}
161
162} // namespace blender::nodes::materialx
#define CLOG_DEBUG(clg_ref,...)
Definition CLG_log.h:191
#define CLOG_INFO(clg_ref,...)
Definition CLG_log.h:190
void append(const T &value)
GroupNodeParser(NodeGraph &graph, const bNode *node, const bNodeSocket *socket_out, NodeItem::Type to_type, GroupNodeParser *group_parser, bool use_group_default)
MaterialX::OutputPtr output
Definition node_item.h:56
static bool is_arithmetic(Type type)
Definition node_item.cc:116
NodeItem convert(Type to_type) const
Definition node_item.cc:517
static Type type(const std::string &type_str)
Definition node_item.cc:16
NodeItem get_input_value(const std::string &name, NodeItem::Type to_type)
NodeParser(NodeGraph &graph, const bNode *node, const bNodeSocket *socket_out, NodeItem::Type to_type, GroupNodeParser *group_parser)
NodeItem create_node(const std::string &category, NodeItem::Type type)
#define out
static Type to_type(const GPUType type)
struct CLG_LogRef * LOG_IO_MATERIALX
static blender::bke::bNodeSocketTemplate outputs[]
char name[258]
Definition DNA_ID.h:432
char identifier[64]
i
Definition text_draw.cc:230