Support group nodes #22

Merged
Bogdan Nagirniak merged 18 commits from BogdanNagirniak/blender:matx-group-nodes into matx-export-material 2023-09-18 12:49:19 +02:00
4 changed files with 32 additions and 19 deletions
Showing only changes of commit 9530f24d3d - Show all commits

View File

@ -18,7 +18,7 @@ NodeItem GroupNodeParser::compute()
return res;
}
std::string name = MaterialX::createValidName(node_->name); /* or ngroup->name */
std::string name = MaterialX::createValidName(ngroup->idname);
MaterialX::NodeGraphPtr group_graph = graph_->getChildOfType<MaterialX::NodeGraph>(name);
if (!group_graph) {
group_graph = graph_->addChild<MaterialX::NodeGraph>(name);
@ -28,33 +28,33 @@ NodeItem GroupNodeParser::compute()
GroupOutputNodeParser(
group_graph.get(), depsgraph_, material_, node_out, socket_out_, NodeItem::Type::Any)
.compute_full();
/* We have to be in NodeParser's graph_, therefore copying output */
res.output = out.output;
return res;
}
NodeItem GroupOutputNodeParser::compute()
{
NodeItem value = get_input_link(socket_out_->index(), to_type_);
NodeItem value = get_input_value(socket_out_->index(), to_type_);
NodeItem res = create_output();
res.set_output(value);
return res;
}
std::string GroupOutputNodeParser::name_out() const
{
std::string name = "output";
if (node_->input_sockets().size() > 1) {
name += std::to_string(socket_out_->index() + 1);
}
return name;
}
NodeItem GroupInputNodeParser::compute()
{
auto in = graph_->addInput();
return empty();
}
NodeItem GroupInputNodeParser::compute_full()
{
CLOG_INFO(LOG_MATERIALX_SHADER,
1,
"%s [%d] => %s",
node_->name,
node_->typeinfo->type,
NodeItem::type(to_type_).c_str());
return compute();
}
} // namespace blender::nodes::materialx

View File

@ -18,13 +18,15 @@ class GroupOutputNodeParser : public NodeParser {
public:
using NodeParser::NodeParser;
NodeItem compute() override;
protected:
std::string name_out() const override;
};
class GroupInputNodeParser : public NodeParser {
public:
using NodeParser::NodeParser;
NodeItem compute() override;
NodeItem compute_full() override;
};
} // namespace blender::nodes::materialx

View File

@ -34,10 +34,14 @@ NodeItem NodeParser::compute_full()
NodeItem res = empty();
/* Checking if node was already computed */
res.node = graph_->getNode(node_name());
res.node = graph_->getNode(name_out());
if (res.node) {
return res;
}
res.output = graph_->getOutput(name_out());
if (res.output) {
return res;
}
CLOG_INFO(LOG_MATERIALX_SHADER,
1,
@ -48,7 +52,10 @@ NodeItem NodeParser::compute_full()
res = compute();
if (res.node) {
res.node->setName(node_name());
res.node->setName(name_out());
}
else if (res.output) {
res.output->setName(name_out());
}
if (NodeItem::is_arithmetic(to_type_)) {
res = res.convert(to_type_);
@ -56,7 +63,7 @@ NodeItem NodeParser::compute_full()
return res;
}
std::string NodeParser::node_name() const
std::string NodeParser::name_out() const
{
std::string name = node_->name;
if (node_->output_sockets().size() > 1) {
@ -174,6 +181,10 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket, NodeItem::Type to
return GroupNodeParser(graph_, depsgraph_, material_, from_node, link->fromsock, to_type)
.compute_full();
}
if (from_node->is_group_input()) {
return GroupInputNodeParser(graph_, depsgraph_, material_, from_node, link->fromsock, to_type)
.compute_full();
}
if (!from_node->typeinfo->materialx_fn) {
CLOG_WARN(LOG_MATERIALX_SHADER,

View File

@ -38,7 +38,7 @@ class NodeParser {
virtual NodeItem compute_full();
protected:
std::string node_name() const;
virtual std::string name_out() const;
NodeItem create_node(const std::string &category, NodeItem::Type type);
NodeItem create_output();
NodeItem get_input_default(const std::string &name, NodeItem::Type to_type);