matx-code-improvements #8

Merged
Bogdan Nagirniak merged 6 commits from BogdanNagirniak/blender:matx-code-improvements into matx-export-material 2023-09-04 10:10:09 +02:00
4 changed files with 12 additions and 17 deletions
Showing only changes of commit 979fb90575 - Show all commits

View File

@ -18,6 +18,13 @@ NodeParser::NodeParser(MaterialX::GraphElement *graph,
{
}
std::string NodeParser::node_name(const bNode *node, const bNodeSocket *socket_out)
{
return MaterialX::createValidName(node->output_sockets().size() <= 1 ?
std::string(node->name) :
std::string(node->name) + "_" + socket_out->name);
}
NodeItem NodeParser::create_node(const std::string &mx_category, const std::string &mx_type)
{
NodeItem res = empty();
@ -60,13 +67,6 @@ NodeItem NodeParser::empty() const
return NodeItem(graph_);
}
std::string NodeParser::node_name(const bNode *node, const bNodeSocket *socket_out)
{
return MaterialX::createValidName(node->output_sockets().size() == 1 ?
std::string(node->name) :
std::string(node->name) + "_" + socket_out->name);
}
NodeItem NodeParser::get_input_default(const bNodeSocket &socket)
{
NodeItem res = empty();

View File

@ -30,6 +30,7 @@ class NodeParser {
virtual NodeItem compute() = 0;
protected:
static std::string node_name(const bNode *node, const bNodeSocket *socket_out);
NodeItem create_node(const std::string &mx_category, const std::string &mx_type);
NodeItem get_input_default(const std::string &name);
NodeItem get_input_default(int index);
@ -41,7 +42,6 @@ class NodeParser {
template<class T> NodeItem value(const T &data) const;
private:
static std::string node_name(const bNode *node, const bNodeSocket *socket_out);
NodeItem get_input_default(const bNodeSocket &socket);
NodeItem get_input_link(const bNodeSocket &socket);
NodeItem get_input_value(const bNodeSocket &socket);

View File

@ -29,7 +29,7 @@ NodeItem OutputMaterialNodeParser::compute(const std::string &socket_name)
surface.set_input("base_color", value(MaterialX::Color3(1.0f, 0.0f, 1.0f)));
}
NodeItem res = create_node("surfacematerial", "material");
res.set_name("Material");
res.node->setName(node_name(node_, nullptr));
res.set_input("surfaceshader", surface);
return res;
}
@ -49,7 +49,7 @@ NodeItem OutputMaterialNodeParser::compute_default()
}
NodeItem res = create_node("surfacematerial", "material");
res.set_name("Material");
res.node->setName("Material_Default");
res.set_input("surfaceshader", surface);
return res;
}

View File

@ -16,16 +16,11 @@ NodeItem TexCheckerNodeParser::compute()
float v = scale.value->asA<float>();
scale = value(MaterialX::Vector2(v, v));
}
/* Modifier to follow Cycles result */
scale = scale * value(4.0f);
NodeItem texcoord = create_node("texcoord", "vector2");
NodeItem place2d = create_node("place2d", "vector2");
place2d.set_input("texcoord", texcoord * scale);
/* TODO: fix offset:
* place2d.set_input("offset", offset); */
NodeItem separate = create_node("separate2", "multioutput");
separate.set_input("in", place2d);
separate.add_output("outx", "float");
@ -43,8 +38,8 @@ NodeItem TexCheckerNodeParser::compute()
(modulo_x.floor() + modulo_y.floor()).if_else("==", value(1.0f), value(0.0f), value(1.0f));
NodeItem res = create_node("mix", "color3");
res.set_input("fg", color1.to_color3());
res.set_input("bg", color2.to_color3());
res.set_input("bg", color1.to_color3());
res.set_input("fg", color2.to_color3());
res.set_input("mix", ifequal);
return res;
}