Implement type conversion for NodeItem #10

Closed
Bogdan Nagirniak wants to merge 9 commits from BogdanNagirniak/blender:matx-nodeitem-type into matx-export-material

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
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 subsurface = get_input_value("Subsurface");
NodeItem subsurface_radius = empty();
NodeItem subsurface_color = empty();
if (subsurface != zero) {
subsurface_radius = get_input_value("Subsurface Radius");
subsurface_color = get_input_value("Subsurface Color");
}
NodeItem subsurface_radius = get_input_value("Subsurface Radius");
NodeItem subsurface_color = get_input_value("Subsurface Color");
NodeItem metallic = get_input_value("Metallic");
NodeItem specular = get_input_value("Specular");
@ -102,13 +98,11 @@ NodeItem BSDFPrincipledNodeParser::compute()
res.set_input("transmission_extra_roughness", transmission_roughness);
}
if (subsurface != zero) {
res.set_input("subsurface", subsurface);
res.set_input("subsurface_color", subsurface_color);
res.set_input("subsurface_radius", subsurface_radius);
if (anisotropic) {
res.set_input("subsurface_anisotropy", anisotropic);
}
res.set_input("subsurface", subsurface);
res.set_input("subsurface_color", subsurface_color);
res.set_input("subsurface_radius", subsurface_radius);
if (anisotropic) {
res.set_input("subsurface_anisotropy", anisotropic);
}
if (sheen != zero) {
@ -131,7 +125,7 @@ NodeItem BSDFPrincipledNodeParser::compute()
if (emission != zero) {
res.set_input("emission", emission_strength);
res.set_input("emission_color", emission);
res.set_input("emission_color", emission.to_color3());
}
return res;

View File

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

View File

@ -10,7 +10,7 @@ namespace blender::nodes::materialx {
class NodeItem {
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:
MaterialX::ValuePtr value;

View File

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