Implement type conversion for NodeItem #9

Merged
Bogdan Nagirniak merged 12 commits from BogdanNagirniak/blender:matx-nodeitem-type into matx-export-material 2023-09-05 12:03:24 +02:00
3 changed files with 30 additions and 29 deletions
Showing only changes of commit 4bd93247d8 - Show all commits

View File

@ -12,38 +12,38 @@ namespace blender::nodes::materialx {
NodeItem::NodeItem(MaterialX::GraphElement *graph) : graph_(graph) {} NodeItem::NodeItem(MaterialX::GraphElement *graph) : graph_(graph) {}
NodeItem::Type NodeItem::type(const std::string &mx_type) NodeItem::Type NodeItem::type(const std::string &type_str)
{ {
if (mx_type == "string") { if (type_str == "string") {
return Type::String; return Type::String;
} }
if (mx_type == "integer") { if (type_str == "integer") {
return Type::Integer; return Type::Integer;
} }
if (mx_type == "float") { if (type_str == "float") {
return Type::Float; return Type::Float;
} }
if (mx_type == "vector2") { if (type_str == "vector2") {
return Type::Vector2; return Type::Vector2;
} }
if (mx_type == "vector3") { if (type_str == "vector3") {
return Type::Vector3; return Type::Vector3;
} }
if (mx_type == "vector4") { if (type_str == "vector4") {
return Type::Vector4; return Type::Vector4;
} }
if (mx_type == "color3") { if (type_str == "color3") {
return Type::Color3; return Type::Color3;
} }
if (mx_type == "color4") { if (type_str == "color4") {
return Type::Color4; return Type::Color4;
} }
return Type::Other; return Type::Other;
} }
std::string NodeItem::type(Type mx_type) std::string NodeItem::type(Type tp)
{ {
switch (mx_type) { switch (tp) {
case Type::String: case Type::String:
return "string"; return "string";
case Type::Integer: case Type::Integer:
@ -61,8 +61,9 @@ std::string NodeItem::type(Type mx_type)
case Type::Color4: case Type::Color4:
return "color4"; return "color4";
default: default:
return ""; break;
} }
return "";
} }
NodeItem NodeItem::empty() const NodeItem NodeItem::empty() const
@ -119,15 +120,15 @@ void NodeItem::set_input(const std::string &name,
void NodeItem::set_input(const std::string &name, void NodeItem::set_input(const std::string &name,
const NodeItem &item, const NodeItem &item,
Type to_type, Type in_type,
const std::string &output_name) const std::string &output_name)
{ {
set_input(name, item.convert(to_type), output_name); set_input(name, item.convert(in_type), output_name);
} }
void NodeItem::add_output(const std::string &name, const std::string &mx_type) void NodeItem::add_output(const std::string &name, Type out_type)
{ {
node->addOutput(name, mx_type); node->addOutput(name, type(out_type));
} }
NodeItem::operator bool() const NodeItem::operator bool() const

View File

@ -24,22 +24,22 @@ class NodeItem {
NodeItem(MaterialX::GraphElement *graph); NodeItem(MaterialX::GraphElement *graph);
~NodeItem() = default; ~NodeItem() = default;
static Type type(const std::string &mx_type); static Type type(const std::string &type_str);
static std::string type(Type mx_type); static std::string type(Type tp);
NodeItem empty() const; NodeItem empty() const;
template<class T> NodeItem val(const T &data) const; template<class T> NodeItem val(const T &data) const;
template<class T> template<class T>
void set_input(const std::string &name, const T &value, const std::string &mx_type); void set_input(const std::string &in_name, const T &value, const std::string &in_type);
void set_input(const std::string &name, void set_input(const std::string &in_name,
const NodeItem &item, const NodeItem &item,
const std::string &output_name = ""); const std::string &out_name = "");
void set_input(const std::string &name, void set_input(const std::string &in_name,
BogdanNagirniak marked this conversation as resolved
Review

Suggest add #pragma region for such places

Suggest add `#pragma region` for such places
Review

It is not commonly used in Blender code

It is not commonly used in Blender code
const NodeItem &item, const NodeItem &item,
Type to_type, Type in_type,
const std::string &output_name = ""); const std::string &out_name = "");
void add_output(const std::string &name, const std::string &mx_type); void add_output(const std::string &in_name, Type out_type);
operator bool() const; operator bool() const;
NodeItem operator+(const NodeItem &other) const; NodeItem operator+(const NodeItem &other) const;
@ -106,9 +106,9 @@ template<class T> NodeItem NodeItem::val(const T &data) const
} }
template<class T> template<class T>
void NodeItem::set_input(const std::string &name, const T &value, const std::string &mx_type) void NodeItem::set_input(const std::string &in_name, const T &value, const std::string &in_type)
{ {
node->setInputValue(name, value, mx_type); node->setInputValue(in_name, value, in_type);
} }
} // namespace blender::nodes::materialx } // namespace blender::nodes::materialx

View File

@ -20,8 +20,8 @@ NodeItem TexCheckerNodeParser::compute()
NodeItem separate = create_node("separate2", "multioutput"); NodeItem separate = create_node("separate2", "multioutput");
separate.set_input("in", vector); separate.set_input("in", vector);
separate.add_output("outx", "float"); separate.add_output("outx", NodeItem::Type::Float);
separate.add_output("outy", "float"); separate.add_output("outy", NodeItem::Type::Float);
NodeItem modulo_x = create_node("modulo", "float"); NodeItem modulo_x = create_node("modulo", "float");
modulo_x.set_input("in1", separate, "outx"); modulo_x.set_input("in1", separate, "outx");