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 25 additions and 18 deletions
Showing only changes of commit 49b542724e - Show all commits

View File

@ -617,53 +617,59 @@ NodeItem::Type NodeItem::type() const
return Type::Empty; return Type::Empty;
} }
void NodeItem::set_input(const std::string &name, void NodeItem::set_input(const std::string &in_name, const NodeItem &item)
const NodeItem &item,
const std::string &output_name)
{ {
if (item.value) { if (item.value) {
Type item_type = item.type(); Type item_type = item.type();
std::string mx_type = type(item_type); std::string mx_type = type(item_type);
switch (item_type) { switch (item_type) {
case Type::String: case Type::String:
set_input(name, item.value->asA<std::string>(), mx_type); set_input(in_name, item.value->asA<std::string>(), mx_type);
break; break;
case Type::Integer: case Type::Integer:
set_input(name, item.value->asA<int>(), mx_type); set_input(in_name, item.value->asA<int>(), mx_type);
break; break;
case Type::Float: case Type::Float:
set_input(name, item.value->asA<float>(), mx_type); set_input(in_name, item.value->asA<float>(), mx_type);
break; break;
case Type::Vector2: case Type::Vector2:
set_input(name, item.value->asA<MaterialX::Vector2>(), mx_type); set_input(in_name, item.value->asA<MaterialX::Vector2>(), mx_type);
break; break;
case Type::Vector3: case Type::Vector3:
set_input(name, item.value->asA<MaterialX::Vector3>(), mx_type); set_input(in_name, item.value->asA<MaterialX::Vector3>(), mx_type);
break; break;
case Type::Vector4: case Type::Vector4:
set_input(name, item.value->asA<MaterialX::Vector4>(), mx_type); set_input(in_name, item.value->asA<MaterialX::Vector4>(), mx_type);
break; break;
case Type::Color3: case Type::Color3:
set_input(name, item.value->asA<MaterialX::Color3>(), mx_type); set_input(in_name, item.value->asA<MaterialX::Color3>(), mx_type);
break; break;
case Type::Color4: case Type::Color4:
set_input(name, item.value->asA<MaterialX::Color4>(), mx_type); set_input(in_name, item.value->asA<MaterialX::Color4>(), mx_type);
break; break;
default: default:
BLI_assert_unreachable(); BLI_assert_unreachable();
} }
} }
else if (item.node) { else if (item.node) {
node->setConnectedNode(name, item.node); node->setConnectedNode(in_name, item.node);
if (output_name != "") {
node->setConnectedOutput(name, item.node->getOutput(output_name));
}
} }
else { else {
CLOG_WARN(LOG_MATERIALX_SHADER, "Empty item to input: %s", name.c_str()); CLOG_WARN(LOG_MATERIALX_SHADER, "Empty item to input: %s", in_name.c_str());
} }
} }
void NodeItem::set_input_output(const std::string &in_name,
const NodeItem &item,
const std::string &out_name)
{
if (!item.node) {
BLI_assert_unreachable();
}
node->setConnectedNode(in_name, item.node);
node->setConnectedOutput(in_name, item.node->getOutput(out_name));
}
void NodeItem::add_output(const std::string &name, Type out_type) void NodeItem::add_output(const std::string &name, Type out_type)
{ {
node->addOutput(name, type(out_type)); node->addOutput(name, type(out_type));

View File

@ -101,9 +101,10 @@ class NodeItem {
/* Functions to set input and output */ /* Functions to set input and output */
template<class T> template<class T>
void set_input(const std::string &in_name, const T &value, const std::string &in_type); void set_input(const std::string &in_name, const T &value, const std::string &in_type);
void set_input(const std::string &in_name, void set_input(const std::string &in_name, const NodeItem &item);
void set_input_output(const std::string &in_name,
const NodeItem &item, const NodeItem &item,
const std::string &out_name = ""); const std::string &out_name);
void add_output(const std::string &in_name, Type out_type); void add_output(const std::string &in_name, Type out_type);
private: private: