matx-code-improvements #8

Merged
Bogdan Nagirniak merged 6 commits from BogdanNagirniak/blender:matx-code-improvements into matx-export-material 2023-09-04 10:10:09 +02:00
4 changed files with 15 additions and 10 deletions
Showing only changes of commit d3d9a29b60 - Show all commits

View File

@ -79,11 +79,6 @@ void NodeItem::add_output(const std::string &name, const std::string &mx_type)
node->addOutput(name, mx_type); node->addOutput(name, mx_type);
} }
void NodeItem::set_name(const std::string &name)
{
node->setName(MaterialX::createValidName(name));
}
NodeItem::operator bool() const NodeItem::operator bool() const
{ {
return value || node; return value || node;

View File

@ -33,7 +33,6 @@ class NodeItem {
const MaterialX::NodePtr node, const MaterialX::NodePtr node,
const std::string &output_name = ""); const std::string &output_name = "");
void add_output(const std::string &name, const std::string &mx_type); void add_output(const std::string &name, const std::string &mx_type);
void set_name(const std::string &name);
operator bool() const; operator bool() const;
NodeItem operator+(const NodeItem &other) const; NodeItem operator+(const NodeItem &other) const;

View File

@ -60,6 +60,13 @@ NodeItem NodeParser::empty() const
return NodeItem(graph_); return NodeItem(graph_);
} }
std::string NodeParser::node_name(const bNode *node, const bNodeSocket *socket_out)
{
return MaterialX::createValidName(node->output_sockets().size() == 1 ?
std::string(node->name) :
std::string(node->name) + "_" + socket_out->name);
}
NodeItem NodeParser::get_input_default(const bNodeSocket &socket) NodeItem NodeParser::get_input_default(const bNodeSocket &socket)
{ {
NodeItem res = empty(); NodeItem res = empty();
@ -105,6 +112,12 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket)
from_node = link->fromnode; from_node = link->fromnode;
} }
/* Checking if node was already computed */
res.node = graph_->getNode(node_name(from_node, link->fromsock));
if (res.node) {
return res;
}
/* Computing from_node with required NodeParser object */ /* Computing from_node with required NodeParser object */
#define CASE_NODE_TYPE(type, T) \ #define CASE_NODE_TYPE(type, T) \
case type: \ case type: \
@ -126,7 +139,6 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket)
"Unsupported node: %s [%d]", "Unsupported node: %s [%d]",
from_node->name, from_node->name,
from_node->typeinfo->type); from_node->typeinfo->type);
return res;
} }
return res; return res;
@ -146,9 +158,7 @@ NodeItem NodeParser::compute_full()
CLOG_INFO(LOG_MATERIALX_SHADER, 1, "%s [%d]", node_->name, node_->typeinfo->type); CLOG_INFO(LOG_MATERIALX_SHADER, 1, "%s [%d]", node_->name, node_->typeinfo->type);
NodeItem res = compute(); NodeItem res = compute();
if (res.node) { if (res.node) {
res.set_name(node_->output_sockets().size() == 1 ? res.node->setName(node_name(node_, socket_out_));
std::string(node_->name) :
std::string(node_->name) + "_" + socket_out_->name);
} }
return res; return res;
} }

View File

@ -41,6 +41,7 @@ class NodeParser {
template<class T> NodeItem value(const T &data) const; template<class T> NodeItem value(const T &data) const;
private: private:
static std::string node_name(const bNode *node, const bNodeSocket *socket_out);
NodeItem get_input_default(const bNodeSocket &socket); NodeItem get_input_default(const bNodeSocket &socket);
NodeItem get_input_link(const bNodeSocket &socket); NodeItem get_input_link(const bNodeSocket &socket);
NodeItem get_input_value(const bNodeSocket &socket); NodeItem get_input_value(const bNodeSocket &socket);