Parsing Improvements #14

Merged
Bogdan Nagirniak merged 5 commits from matx-parsing-improvements into matx-export-material 2023-09-07 15:10:17 +02:00
2 changed files with 12 additions and 11 deletions
Showing only changes of commit 0f0786aea7 - Show all commits

View File

@ -104,7 +104,7 @@ NodeItem NodeItem::operator+(const NodeItem &other) const
/* Special case: add BSDF/EDF shaders */
NodeItem res = empty();
if (other.type() == type) {
res.node = graph_->addNode("add", MaterialX::EMPTY_STRING, this->type(type));
res = create_node("add", type);
res.set_input("in1", *this);
res.set_input("in2", other);
}
@ -135,7 +135,7 @@ NodeItem NodeItem::operator*(const NodeItem &other) const
NodeItem res = empty();
Type other_type = other.type();
if (ELEM(other_type, Type::Float, Type::Color3)) {
res.node = graph_->addNode("multiply", MaterialX::EMPTY_STRING, this->type(type));
res = create_node("multiply", type);
res.set_input("in1", *this);
res.set_input("in2", other);
}
@ -349,7 +349,7 @@ NodeItem NodeItem::exp() const
NodeItem NodeItem::extract(const int index) const
{
NodeItem res = empty();
res.node = graph_->addNode("extract", MaterialX::EMPTY_STRING, "float");
res = create_node("extract", Type::Float);
res.set_input("in", *this);
res.set_input("index", val(index));
return res;
@ -533,7 +533,7 @@ NodeItem NodeItem::convert(Type to_type) const
}
}
else {
res.node = graph_->addNode("convert", MaterialX::EMPTY_STRING, type(to_type));
res = create_node("convert", to_type);
res.set_input("in", *this);
}
return res;
@ -590,7 +590,7 @@ NodeItem NodeItem::if_else(CompareOp op,
res = func(value->asA<float>(), other.value->asA<float>()) ? item1 : item2;
}
else {
res.node = graph_->addNode(category, MaterialX::EMPTY_STRING, type(to_type));
res = create_node(category, to_type);
res.set_input("value1", *this);
res.set_input("value2", other);
res.set_input("in1", item1);
@ -616,12 +616,13 @@ NodeItem::Type NodeItem::type() const
return Type::Empty;
}
NodeItem NodeItem::create_node(const std::string &category, NodeItem::Type type)
NodeItem NodeItem::create_node(const std::string &category, NodeItem::Type type) const
{
std::string type_str = this->type(type);
CLOG_INFO(LOG_MATERIALX_SHADER, 2, "<%s type=%s>", category.c_str(), type_str.c_str());
node = graph_->addNode(category, MaterialX::EMPTY_STRING, type_str);
return *this;
NodeItem res = empty();
res.node = graph_->addNode(category, MaterialX::EMPTY_STRING, type_str);
return res;
}
void NodeItem::set_input(const std::string &in_name, const NodeItem &item)
@ -763,7 +764,7 @@ NodeItem NodeItem::arithmetic(const std::string &category, std::function<float(f
else {
/* TODO: Some of math functions (sin, cos, ...) doesn't work with Color types,
* we have to convert to Vector */
res.node = graph_->addNode(category, MaterialX::EMPTY_STRING, this->type(type));
res = create_node(category, type);
res.set_input("in", *this);
}
return res;
@ -829,7 +830,7 @@ NodeItem NodeItem::arithmetic(const NodeItem &other,
}
}
else {
res.node = graph_->addNode(category, MaterialX::EMPTY_STRING, type(to_type));
res = create_node(category, to_type);
res.set_input("in1", item1);
res.set_input("in2", item2);
}

View File

@ -97,7 +97,7 @@ class NodeItem {
NodeItem empty() const;
template<class T> NodeItem val(const T &data) const;
Type type() const;
NodeItem create_node(const std::string &category, NodeItem::Type type);
NodeItem create_node(const std::string &category, NodeItem::Type type) const;
/* Functions to set input and output */
template<class T> void set_input(const std::string &in_name, const T &value, Type in_type);