forked from blender/blender
Support group nodes #22
@ -18,7 +18,7 @@ NodeItem GroupNodeParser::compute()
|
|||||||
return res;
|
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);
|
MaterialX::NodeGraphPtr group_graph = graph_->getChildOfType<MaterialX::NodeGraph>(name);
|
||||||
if (!group_graph) {
|
if (!group_graph) {
|
||||||
group_graph = graph_->addChild<MaterialX::NodeGraph>(name);
|
group_graph = graph_->addChild<MaterialX::NodeGraph>(name);
|
||||||
@ -28,33 +28,33 @@ NodeItem GroupNodeParser::compute()
|
|||||||
GroupOutputNodeParser(
|
GroupOutputNodeParser(
|
||||||
group_graph.get(), depsgraph_, material_, node_out, socket_out_, NodeItem::Type::Any)
|
group_graph.get(), depsgraph_, material_, node_out, socket_out_, NodeItem::Type::Any)
|
||||||
.compute_full();
|
.compute_full();
|
||||||
|
|
||||||
|
/* We have to be in NodeParser's graph_, therefore copying output */
|
||||||
res.output = out.output;
|
res.output = out.output;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeItem GroupOutputNodeParser::compute()
|
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();
|
NodeItem res = create_output();
|
||||||
res.set_output(value);
|
res.set_output(value);
|
||||||
return res;
|
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()
|
NodeItem GroupInputNodeParser::compute()
|
||||||
{
|
{
|
||||||
|
auto in = graph_->addInput();
|
||||||
return empty();
|
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
|
} // namespace blender::nodes::materialx
|
||||||
|
@ -18,13 +18,15 @@ class GroupOutputNodeParser : public NodeParser {
|
|||||||
public:
|
public:
|
||||||
using NodeParser::NodeParser;
|
using NodeParser::NodeParser;
|
||||||
NodeItem compute() override;
|
NodeItem compute() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string name_out() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GroupInputNodeParser : public NodeParser {
|
class GroupInputNodeParser : public NodeParser {
|
||||||
public:
|
public:
|
||||||
using NodeParser::NodeParser;
|
using NodeParser::NodeParser;
|
||||||
NodeItem compute() override;
|
NodeItem compute() override;
|
||||||
NodeItem compute_full() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::nodes::materialx
|
} // namespace blender::nodes::materialx
|
||||||
|
@ -34,10 +34,14 @@ NodeItem NodeParser::compute_full()
|
|||||||
NodeItem res = empty();
|
NodeItem res = empty();
|
||||||
|
|
||||||
/* Checking if node was already computed */
|
/* Checking if node was already computed */
|
||||||
res.node = graph_->getNode(node_name());
|
res.node = graph_->getNode(name_out());
|
||||||
if (res.node) {
|
if (res.node) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
res.output = graph_->getOutput(name_out());
|
||||||
|
if (res.output) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
CLOG_INFO(LOG_MATERIALX_SHADER,
|
CLOG_INFO(LOG_MATERIALX_SHADER,
|
||||||
1,
|
1,
|
||||||
@ -48,7 +52,10 @@ NodeItem NodeParser::compute_full()
|
|||||||
|
|
||||||
res = compute();
|
res = compute();
|
||||||
if (res.node) {
|
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_)) {
|
if (NodeItem::is_arithmetic(to_type_)) {
|
||||||
res = res.convert(to_type_);
|
res = res.convert(to_type_);
|
||||||
@ -56,7 +63,7 @@ NodeItem NodeParser::compute_full()
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string NodeParser::node_name() const
|
std::string NodeParser::name_out() const
|
||||||
{
|
{
|
||||||
std::string name = node_->name;
|
std::string name = node_->name;
|
||||||
if (node_->output_sockets().size() > 1) {
|
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)
|
return GroupNodeParser(graph_, depsgraph_, material_, from_node, link->fromsock, to_type)
|
||||||
.compute_full();
|
.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) {
|
if (!from_node->typeinfo->materialx_fn) {
|
||||||
CLOG_WARN(LOG_MATERIALX_SHADER,
|
CLOG_WARN(LOG_MATERIALX_SHADER,
|
||||||
|
@ -38,7 +38,7 @@ class NodeParser {
|
|||||||
virtual NodeItem compute_full();
|
virtual NodeItem compute_full();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string node_name() const;
|
virtual std::string name_out() const;
|
||||||
NodeItem create_node(const std::string &category, NodeItem::Type type);
|
NodeItem create_node(const std::string &category, NodeItem::Type type);
|
||||||
NodeItem create_output();
|
NodeItem create_output();
|
||||||
NodeItem get_input_default(const std::string &name, NodeItem::Type to_type);
|
NodeItem get_input_default(const std::string &name, NodeItem::Type to_type);
|
||||||
|
Loading…
Reference in New Issue
Block a user