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
4 changed files with 25 additions and 24 deletions
Showing only changes of commit 537fe23b81 - Show all commits

View File

@ -15,12 +15,8 @@ NodeItem BSDFPrincipledNodeParser::compute()
NodeItem base_color = get_input_value("Base Color"); NodeItem base_color = get_input_value("Base Color");
NodeItem subsurface = get_input_value("Subsurface"); NodeItem subsurface = get_input_value("Subsurface");
NodeItem subsurface_radius = empty(); NodeItem subsurface_radius = get_input_value("Subsurface Radius");
NodeItem subsurface_color = empty(); NodeItem subsurface_color = get_input_value("Subsurface Color");
if (subsurface != zero) {
subsurface_radius = get_input_value("Subsurface Radius");
subsurface_color = get_input_value("Subsurface Color");
}
NodeItem metallic = get_input_value("Metallic"); NodeItem metallic = get_input_value("Metallic");
NodeItem specular = get_input_value("Specular"); NodeItem specular = get_input_value("Specular");
@ -102,13 +98,11 @@ NodeItem BSDFPrincipledNodeParser::compute()
res.set_input("transmission_extra_roughness", transmission_roughness); res.set_input("transmission_extra_roughness", transmission_roughness);
} }
if (subsurface != zero) { res.set_input("subsurface", subsurface);
res.set_input("subsurface", subsurface); res.set_input("subsurface_color", subsurface_color);
res.set_input("subsurface_color", subsurface_color); res.set_input("subsurface_radius", subsurface_radius);
res.set_input("subsurface_radius", subsurface_radius); if (anisotropic) {
if (anisotropic) { res.set_input("subsurface_anisotropy", anisotropic);
res.set_input("subsurface_anisotropy", anisotropic);
}
} }
if (sheen != zero) { if (sheen != zero) {
@ -131,7 +125,7 @@ NodeItem BSDFPrincipledNodeParser::compute()
if (emission != zero) { if (emission != zero) {
res.set_input("emission", emission_strength); res.set_input("emission", emission_strength);
res.set_input("emission_color", emission); res.set_input("emission_color", emission.to_color3());
} }
return res; return res;

View File

@ -14,6 +14,12 @@ NodeItem::NodeItem(MaterialX::GraphElement *graph) : graph_(graph) {}
NodeItem::Type NodeItem::type(const std::string &mx_type) NodeItem::Type NodeItem::type(const std::string &mx_type)
{ {
if (mx_type == "string") {
return Type::String;
}
if (mx_type == "integer") {
return Type::Integer;
}
if (mx_type == "float") { if (mx_type == "float") {
return Type::Float; return Type::Float;
} }
@ -38,6 +44,10 @@ NodeItem::Type NodeItem::type(const std::string &mx_type)
std::string NodeItem::type(Type mx_type) std::string NodeItem::type(Type mx_type)
{ {
switch (mx_type) { switch (mx_type) {
case Type::String:
return "string";
case Type::Integer:
return "integer";
case Type::Float: case Type::Float:
return "float"; return "float";
case Type::Vector2: case Type::Vector2:

View File

@ -10,7 +10,7 @@ namespace blender::nodes::materialx {
class NodeItem { class NodeItem {
public: public:
enum class Type { Empty = 0, Other, Float, Vector2, Vector3, Vector4, Color3, Color4 }; enum class Type { Empty = 0, Other, String, Integer, Float, Vector2, Vector3, Vector4, Color3, Color4 };
public: public:
BogdanNagirniak marked this conversation as resolved Outdated

Add comment what is Other

Add comment what is `Other`
MaterialX::ValuePtr value; MaterialX::ValuePtr value;

View File

@ -8,21 +8,18 @@ namespace blender::nodes::materialx {
NodeItem TexCheckerNodeParser::compute() NodeItem TexCheckerNodeParser::compute()
{ {
NodeItem scale = get_input_value("Scale"); NodeItem vector = get_input_link("Vector");
NodeItem color1 = get_input_value("Color1"); NodeItem color1 = get_input_value("Color1");
NodeItem color2 = get_input_value("Color2"); NodeItem color2 = get_input_value("Color2");
NodeItem scale = get_input_value("Scale");
if (scale.value && scale.type() == NodeItem::Type::Float) { if (!vector) {
float v = scale.value->asA<float>(); vector = create_node("texcoord", "vector2");
scale = value(MaterialX::Vector2(v, v));
} }
vector = vector * scale;
NodeItem texcoord = create_node("texcoord", "vector2");
NodeItem place2d = create_node("place2d", "vector2");
place2d.set_input("texcoord", texcoord * scale);
NodeItem separate = create_node("separate2", "multioutput"); NodeItem separate = create_node("separate2", "multioutput");
separate.set_input("in", place2d); separate.set_input("in", vector);
separate.add_output("outx", "float"); separate.add_output("outx", "float");
separate.add_output("outy", "float"); separate.add_output("outy", "float");