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
4 changed files with 37 additions and 29 deletions
Showing only changes of commit 700ed91013 - Show all commits

View File

@ -16,13 +16,15 @@ NodeItem NodeItem::empty() const
return NodeItem(graph_);
}
void NodeItem::set_input(const std::string &name, const NodeItem &item)
void NodeItem::set_input(const std::string &name,
const NodeItem &item,
const std::string &output_name)
{
if (item.value) {
set_input(name, item.value);
}
else if (item.node) {
set_input(name, item.node);
set_input(name, item.node, output_name);
}
}
@ -58,9 +60,19 @@ void NodeItem::set_input(const std::string &name, const MaterialX::ValuePtr valu
}
}
void NodeItem::set_input(const std::string &name, const MaterialX::NodePtr node)
void NodeItem::set_input(const std::string &name,
const MaterialX::NodePtr node,
const std::string &output_name)
{
this->node->setConnectedNode(name, node);
if (output_name != "") {
this->node->setConnectedOutput("in1", node->getOutput(output_name));
}
}
void NodeItem::add_output(const std::string &name, const std::string &mx_type)
{
node->addOutput(name, mx_type);
}
NodeItem::operator bool() const

View File

@ -25,9 +25,14 @@ class NodeItem {
template<class T>
void set_input(const std::string &name, const T &value, const std::string &mx_type);
void set_input(const std::string &name, const NodeItem &item);
void set_input(const std::string &name,
const NodeItem &item,
const std::string &output_name = "");
void set_input(const std::string &name, const MaterialX::ValuePtr value);
void set_input(const std::string &name, const MaterialX::NodePtr node);
void set_input(const std::string &name,
const MaterialX::NodePtr node,
const std::string &output_name = "");
void add_output(const std::string &name, const std::string &mx_type);
operator bool() const;
NodeItem operator+(const NodeItem &other) const;

View File

@ -4,48 +4,40 @@
#include "node_parser.h"
#include "hydra/image.h"
namespace blender::nodes::materialx {
NodeItem TexCheckerNodeParser::compute()
{
NodeItem scale = get_input_value("Scale");
NodeItem color1 = get_input_value("Color1");
NodeItem color2 = get_input_value("Color2");
DagerD marked this conversation as resolved Outdated

change create_node() signature accessory->noname = true

change create_node() signature accessory->noname = true
if (scale.value && scale.type() == "float") {
float v = scale.value->asA<float>();
scale = value(MaterialX::Vector2(v, v));
}
NodeItem color1 = get_input_value("Color1");
NodeItem color2 = get_input_value("Color2");
/* Modifier to follow Cycles result */
scale = scale * value(4.0f);
NodeItem texcoord = create_node("texcoord", "vector2");
NodeItem frequency = create_node("constant", "vector2");
/* Modifier to follow Cycles result. */
scale = scale * value(4.0f);
frequency.set_input("value", scale);
//NodeItem offset = create_node("constant", "vector2");
//offset.set_input("value", value(MaterialX::Vector2(0.0f, 0.0f)));
NodeItem place2d = create_node("place2d", "vector2");
place2d.set_input("texcoord", texcoord * frequency);
//place2d.set_input("offset", offset);
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.node->addOutput("outx", "float");
separate.node->addOutput("outy", "float");
separate.add_output("outx", "float");
separate.add_output("outy", "float");
NodeItem modulo_x = create_node("modulo", "float");
modulo_x.set_input("in1", separate);
modulo_x.set_input("in1", separate, "outx");
modulo_x.set_input("in2", value(2.0f));
modulo_x.node->setConnectedOutput("in1", separate.node->getOutput("outx"));
NodeItem modulo_y = create_node("modulo", "float");
modulo_y.set_input("in1", separate);
modulo_y.set_input("in1", separate, "outy");
modulo_y.set_input("in2", value(2.0f));
modulo_y.node->setConnectedOutput("in1", separate.node->getOutput("outy"));
NodeItem ifequal =
(modulo_x.floor() + modulo_y.floor()).if_else("==", value(1.0f), value(0.0f), value(1.0f));

View File

@ -4,18 +4,17 @@
#include "node_parser.h"
#include "hydra/image.h"
namespace blender::nodes::materialx {
NodeItem TexNoiseNodeParser::compute()
{
NodeItem scale = get_input_value("Scale");
NodeItem detail = get_input_value("Detail");
NodeItem lacunarity = get_input_value("Lacunarity");
if (detail.value && detail.type() == "float") {
detail = value(int(detail.value->asA<float>()));
}
DagerD marked this conversation as resolved Outdated

Use following order:

  1. get_input_...()
  2. operations: math, new nodes
  3. creating result node.
  NodeItem detail = get_input_value("Detail");
  NodeItem lacunarity = get_input_value("Lacunarity");
  NodeItem scale = get_input_value("Scale");

  NodeItem texcoord = create_node("position", "vector3", true);
  NodeItem position = texcoord * scale;
Use following order: 1. get_input_...() 2. operations: math, new nodes 3. creating result node. ``` NodeItem detail = get_input_value("Detail"); NodeItem lacunarity = get_input_value("Lacunarity"); NodeItem scale = get_input_value("Scale"); NodeItem texcoord = create_node("position", "vector3", true); NodeItem position = texcoord * scale; ```
NodeItem lacunarity = get_input_value("Lacunarity");
NodeItem texcoord = create_node("position", "vector3");