Blender V4.5
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 1,
92 "%s [%d] => %s",
93 node_->name,
94 node_->typeinfo->type_legacy,
95 NodeItem::type(to_type_).c_str());
96
97#ifdef USE_MATERIALX_NODEGRAPH
98 /* Checking if output was already computed */
99 NodeItem res = graph_.get_output(out_name(socket_out_));
100 if (res.output) {
101 return res;
102 }
103
104 res = compute();
105 return res;
106#else
107 return compute();
108#endif
109}
110
111std::string GroupOutputNodeParser::out_name(const bNodeSocket *out_socket)
112{
113 return MaterialX::createValidName(std::string("out_") + out_socket->name);
114}
115
117{
118#ifdef USE_MATERIALX_NODEGRAPH
119 NodeItem value = group_parser_->get_input_link(socket_out_->index(), to_type_);
120 if (!value) {
121 return empty();
122 }
123
124 if (value.value) {
125 value = group_parser_->create_node("constant", value.type(), {{"value", value}});
126 }
127 return create_input(in_name(), value);
128#else
129 if (use_group_default_) {
130 return group_parser_->get_input_value(socket_out_->index(), to_type_);
131 }
132 return group_parser_->get_input_link(socket_out_->index(), to_type_);
133#endif
134}
135
137{
139 1,
140 "%s [%d] => %s",
141 node_->name,
142 node_->typeinfo->type_legacy,
143 NodeItem::type(to_type_).c_str());
144
145#ifdef USE_MATERIALX_NODEGRAPH
146 /* Checking if input was already computed */
147 NodeItem res = graph_.get_input(in_name());
148 if (res.input) {
149 return res;
150 }
151
152 res = compute();
153 return res;
154#else
155 return compute();
156#endif
157}
158
159std::string GroupInputNodeParser::in_name() const
160{
161 return MaterialX::createValidName(std::string("in_") + socket_out_->name);
162}
163
164} // namespace blender::nodes::materialx
#define CLOG_INFO(clg_ref, level,...)
Definition CLG_log.h:179
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 eGPUType type)
struct CLG_LogRef * LOG_MATERIALX_SHADER
static blender::bke::bNodeSocketTemplate outputs[]
char name[66]
Definition DNA_ID.h:415
i
Definition text_draw.cc:230