forked from blender/blender
Export to MatX various Texture nodes #5
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
|
||||
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));
|
||||
|
@ -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>()));
|
||||
}
|
||||
NodeItem lacunarity = get_input_value("Lacunarity");
|
||||
|
||||
NodeItem texcoord = create_node("position", "vector3");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user