Export to MatX various Texture nodes #5

Merged
Bogdan Nagirniak merged 17 commits from matx-add-tex-nodes into matx-export-material 2023-08-31 19:49:26 +02:00
3 changed files with 50 additions and 5 deletions
Showing only changes of commit fb203b045e - Show all commits

View File

@ -41,8 +41,9 @@ class NodeParser {
NodeItem empty() const;
template<class T> NodeItem value(const T &data) const;
virtual NodeItem get_input_default(const bNodeSocket &socket);
private:
NodeItem get_input_default(const bNodeSocket &socket);
NodeItem get_input_link(const bNodeSocket &socket);
NodeItem get_input_value(const bNodeSocket &socket);
};
@ -66,7 +67,23 @@ DECLARE_PARSER(MixRGBNodeParser)
DECLARE_PARSER(OutputMaterialNodeParser)
DECLARE_PARSER(TexImageNodeParser)
DECLARE_PARSER(TexEnvironmentNodeParser)
DECLARE_PARSER(TexNoiseNodeParser)
DECLARE_PARSER(TexCheckerNodeParser)
class TexNoiseNodeParser : public NodeParser {
public:
using NodeParser::NodeParser;
NodeItem compute() override;
protected:
NodeItem get_input_default(const bNodeSocket &socket) override;
};
class TexCheckerNodeParser : public NodeParser {
public:
using NodeParser::NodeParser;
NodeItem compute() override;
protected:
NodeItem get_input_default(const bNodeSocket &socket) override;
};
} // namespace blender::nodes::materialx

View File

@ -8,6 +8,20 @@
namespace blender::nodes::materialx {
NodeItem TexCheckerNodeParser::get_input_default(const bNodeSocket &socket)
{
/* Explicit check for Scale socket since MaterialX has scales for X and Y
* axes and Blender only single. */
if (UNLIKELY(STREQ(socket.name, "Scale"))) {
NodeItem res = empty();
float v = socket.default_value_typed<bNodeSocketValueFloat>()->value;
res.value = MaterialX::Value::createValue<MaterialX::Vector2>({v, v});
return res;
}
return NodeParser::get_input_default(socket);
}
NodeItem TexCheckerNodeParser::compute()
{
NodeItem texcoord = create_node("texcoord", "vector2", true);
@ -58,8 +72,8 @@ NodeItem TexCheckerNodeParser::compute()
NodeItem ifequal = create_node("ifequal", "float", true);
ifequal.set_input("value1", add);
ifequal.set_input("value2", MaterialX::Value::createValue<float>(1.0f));
ifequal.set_input("in1", MaterialX::Value::createValue<float>(1.0f));
ifequal.set_input("in2", MaterialX::Value::createValue<float>(0.0f));
ifequal.set_input("in1", MaterialX::Value::createValue<float>(0.0f));
ifequal.set_input("in2", MaterialX::Value::createValue<float>(1.0f));
NodeItem res = create_node("mix", "color3", true);
NodeItem color1 = get_input_value("Color1");

View File

@ -8,6 +8,20 @@
namespace blender::nodes::materialx {
NodeItem TexNoiseNodeParser::get_input_default(const bNodeSocket &socket)
{
/* Explicit check for Detail socket since MaterialX expects integer for
* octaves. */
if (UNLIKELY(STREQ(socket.name, "Detail"))) {
NodeItem res = empty();
int v = socket.default_value_typed<bNodeSocketValueFloat>()->value;
res.value = MaterialX::Value::createValue<int>(v);
return res;
}
return NodeParser::get_input_default(socket);
}
NodeItem TexNoiseNodeParser::compute()
{
NodeItem texcoord = create_node("position", "vector3", true);