forked from blender/blender
Export to MatX various Texture nodes #5
@ -68,7 +68,7 @@ NodeItem BSDFPrincipledNodeParser::compute()
|
|||||||
NodeItem tangent = get_input_link("Tangent");
|
NodeItem tangent = get_input_link("Tangent");
|
||||||
|
|
||||||
/* Creating standard_surface */
|
/* Creating standard_surface */
|
||||||
NodeItem res = create_node("standard_surface", "surfaceshader");
|
NodeItem res = create_node("standard_surface", "surfaceshader", false);
|
||||||
res.set_input("base", 1.0, "float");
|
res.set_input("base", 1.0, "float");
|
||||||
res.set_input("base_color", base_color.to_color3());
|
res.set_input("base_color", base_color.to_color3());
|
||||||
res.set_input("diffuse_roughness", roughness);
|
res.set_input("diffuse_roughness", roughness);
|
||||||
|
@ -550,7 +550,9 @@ MaterialX::ValuePtr NodeItem::float_to_type(float v, std::string mx_type)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NodeItem::adjust_types(MaterialX::ValuePtr &val1, MaterialX::ValuePtr &val2, std::string &mx_type)
|
bool NodeItem::adjust_types(MaterialX::ValuePtr &val1,
|
||||||
|
MaterialX::ValuePtr &val2,
|
||||||
|
std::string &mx_type)
|
||||||
{
|
{
|
||||||
std::string t1 = val1->getTypeString();
|
std::string t1 = val1->getTypeString();
|
||||||
std::string t2 = val2->getTypeString();
|
std::string t2 = val2->getTypeString();
|
||||||
|
@ -79,7 +79,9 @@ class NodeItem {
|
|||||||
std::function<float(float, float)> func) const;
|
std::function<float(float, float)> func) const;
|
||||||
static MaterialX::ValuePtr float_to_type(float v, std::string mx_type);
|
static MaterialX::ValuePtr float_to_type(float v, std::string mx_type);
|
||||||
/* Functions for adjusting values to make equal types */
|
/* Functions for adjusting values to make equal types */
|
||||||
static bool adjust_types(MaterialX::ValuePtr &val1, MaterialX::ValuePtr &val2, std::string &mx_type);
|
static bool adjust_types(MaterialX::ValuePtr &val1,
|
||||||
|
MaterialX::ValuePtr &val2,
|
||||||
|
std::string &mx_type);
|
||||||
static bool adjust_types(NodeItem &val1, NodeItem &val2, std::string &mx_type);
|
static bool adjust_types(NodeItem &val1, NodeItem &val2, std::string &mx_type);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,11 +18,11 @@ NodeParser::NodeParser(MaterialX::GraphElement *graph,
|
|||||||
|
|
||||||
NodeItem NodeParser::create_node(const std::string &mx_category,
|
NodeItem NodeParser::create_node(const std::string &mx_category,
|
||||||
const std::string &mx_type,
|
const std::string &mx_type,
|
||||||
bool accessory)
|
bool noname)
|
||||||
{
|
{
|
||||||
NodeItem res = empty();
|
NodeItem res = empty();
|
||||||
res.node = graph->addNode(mx_category,
|
res.node = graph->addNode(mx_category,
|
||||||
accessory ? MaterialX::EMPTY_STRING :
|
noname ? MaterialX::EMPTY_STRING :
|
||||||
MaterialX::createValidName(node->name),
|
MaterialX::createValidName(node->name),
|
||||||
mx_type);
|
mx_type);
|
||||||
return res;
|
return res;
|
||||||
|
@ -31,7 +31,7 @@ class NodeParser {
|
|||||||
protected:
|
protected:
|
||||||
NodeItem create_node(const std::string &mx_category,
|
NodeItem create_node(const std::string &mx_category,
|
||||||
const std::string &mx_type,
|
const std::string &mx_type,
|
||||||
bool accessory = false);
|
bool noname = true);
|
||||||
NodeItem get_input_default(const std::string &name);
|
NodeItem get_input_default(const std::string &name);
|
||||||
NodeItem get_input_default(int index);
|
NodeItem get_input_default(int index);
|
||||||
NodeItem get_input_link(const std::string &name);
|
NodeItem get_input_link(const std::string &name);
|
||||||
@ -65,6 +65,7 @@ template<class T> NodeItem NodeParser::value(const T &data) const
|
|||||||
public: \
|
public: \
|
||||||
using NodeParser::NodeParser; \
|
using NodeParser::NodeParser; \
|
||||||
NodeItem compute() override; \
|
NodeItem compute() override; \
|
||||||
|
\
|
||||||
protected: \
|
protected: \
|
||||||
NodeItem get_input_default(const bNodeSocket &socket) override; \
|
NodeItem get_input_default(const bNodeSocket &socket) override; \
|
||||||
};
|
};
|
||||||
|
@ -11,7 +11,7 @@ NodeItem OutputMaterialNodeParser::compute()
|
|||||||
NodeItem node = empty();
|
NodeItem node = empty();
|
||||||
NodeItem surface = get_input_link("Surface");
|
NodeItem surface = get_input_link("Surface");
|
||||||
if (surface) {
|
if (surface) {
|
||||||
node = create_node("surfacematerial", "material");
|
node = create_node("surfacematerial", "material", false);
|
||||||
node.set_input("surfaceshader", surface);
|
node.set_input("surfaceshader", surface);
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
|
@ -28,32 +28,32 @@ NodeItem TexCheckerNodeParser::compute()
|
|||||||
NodeItem color1 = get_input_value("Color1");
|
NodeItem color1 = get_input_value("Color1");
|
||||||
NodeItem color2 = get_input_value("Color2");
|
NodeItem color2 = get_input_value("Color2");
|
||||||
|
|
||||||
NodeItem texcoord = create_node("texcoord", "vector2", true);
|
NodeItem texcoord = create_node("texcoord", "vector2");
|
||||||
NodeItem frequency = create_node("constant", "vector2", true);
|
NodeItem frequency = create_node("constant", "vector2");
|
||||||
|
|
||||||
/* Modifier to follow Cycles result. */
|
/* Modifier to follow Cycles result. */
|
||||||
NodeItem scale_fitter(graph);
|
NodeItem scale_fitter(graph);
|
||||||
scale_fitter.value = MaterialX::Value::createValue<float>(4.0f);
|
scale_fitter.value = MaterialX::Value::createValue<float>(4.0f);
|
||||||
frequency.set_input("value", scale * scale_fitter);
|
frequency.set_input("value", scale * scale_fitter);
|
||||||
|
|
||||||
NodeItem offset = create_node("constant", "vector2", true);
|
NodeItem offset = create_node("constant", "vector2");
|
||||||
offset.set_input("value", empty().val(MaterialX::Vector2({0.0f, 0.0f})));
|
offset.set_input("value", empty().val(MaterialX::Vector2({0.0f, 0.0f})));
|
||||||
|
|
||||||
NodeItem place2d = create_node("place2d", "vector2", true);
|
NodeItem place2d = create_node("place2d", "vector2");
|
||||||
place2d.set_input("texcoord", texcoord * frequency);
|
place2d.set_input("texcoord", texcoord * frequency);
|
||||||
place2d.set_input("offset", offset);
|
place2d.set_input("offset", offset);
|
||||||
|
|
||||||
NodeItem separate = create_node("separate2", "multioutput", true);
|
NodeItem separate = create_node("separate2", "multioutput");
|
||||||
separate.set_input("in", place2d);
|
separate.set_input("in", place2d);
|
||||||
separate.node->addOutput("outx", "float");
|
separate.node->addOutput("outx", "float");
|
||||||
separate.node->addOutput("outy", "float");
|
separate.node->addOutput("outy", "float");
|
||||||
|
|
||||||
NodeItem modulo_x = create_node("modulo", "float", true);
|
NodeItem modulo_x = create_node("modulo", "float");
|
||||||
modulo_x.set_input("in1", separate);
|
modulo_x.set_input("in1", separate);
|
||||||
modulo_x.set_input("in2", empty().val(2.0f));
|
modulo_x.set_input("in2", empty().val(2.0f));
|
||||||
modulo_x.node->setConnectedOutput("in1", separate.node->getOutput("outx"));
|
modulo_x.node->setConnectedOutput("in1", separate.node->getOutput("outx"));
|
||||||
|
|
||||||
NodeItem modulo_y = create_node("modulo", "float", true);
|
NodeItem modulo_y = create_node("modulo", "float");
|
||||||
modulo_y.set_input("in1", separate);
|
modulo_y.set_input("in1", separate);
|
||||||
modulo_y.set_input("in2", empty().val(2.0f));
|
modulo_y.set_input("in2", empty().val(2.0f));
|
||||||
modulo_y.node->setConnectedOutput("in1", separate.node->getOutput("outy"));
|
modulo_y.node->setConnectedOutput("in1", separate.node->getOutput("outy"));
|
||||||
@ -61,7 +61,7 @@ NodeItem TexCheckerNodeParser::compute()
|
|||||||
NodeItem ifequal = (modulo_x.floor() + modulo_y.floor())
|
NodeItem ifequal = (modulo_x.floor() + modulo_y.floor())
|
||||||
.if_else("==", empty().val(1.0f), empty().val(0.0f), empty().val(1.0f));
|
.if_else("==", empty().val(1.0f), empty().val(0.0f), empty().val(1.0f));
|
||||||
|
|
||||||
NodeItem res = create_node("mix", "color3", true);
|
NodeItem res = create_node("mix", "color3", false);
|
||||||
res.set_input("fg", color1.to_color3());
|
res.set_input("fg", color1.to_color3());
|
||||||
res.set_input("bg", color2.to_color3());
|
res.set_input("bg", color2.to_color3());
|
||||||
res.set_input("mix", ifequal);
|
res.set_input("mix", ifequal);
|
||||||
|
@ -23,8 +23,8 @@ NodeItem TexEnvironmentNodeParser::compute()
|
|||||||
image_path = io::hydra::cache_or_get_image_file(bmain, scene, image, &tex->iuser);
|
image_path = io::hydra::cache_or_get_image_file(bmain, scene, image, &tex->iuser);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NodeItem texcoord = create_node("texcoord", "vector2", true);
|
NodeItem texcoord = create_node("texcoord", "vector2");
|
||||||
NodeItem res = create_node("image", "color3");
|
NodeItem res = create_node("image", "color3", false);
|
||||||
res.set_input("file", image_path, "filename");
|
res.set_input("file", image_path, "filename");
|
||||||
res.set_input("texcoord", texcoord);
|
res.set_input("texcoord", texcoord);
|
||||||
return res;
|
return res;
|
||||||
|
@ -23,8 +23,8 @@ NodeItem TexImageNodeParser::compute()
|
|||||||
image_path = io::hydra::cache_or_get_image_file(bmain, scene, image, &tex->iuser);
|
image_path = io::hydra::cache_or_get_image_file(bmain, scene, image, &tex->iuser);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NodeItem texcoord = create_node("texcoord", "vector2", true);
|
NodeItem texcoord = create_node("texcoord", "vector2");
|
||||||
NodeItem res = create_node("image", "color3");
|
NodeItem res = create_node("image", "color3", false);
|
||||||
res.set_input("file", image_path, "filename");
|
res.set_input("file", image_path, "filename");
|
||||||
res.set_input("texcoord", texcoord);
|
res.set_input("texcoord", texcoord);
|
||||||
return res;
|
return res;
|
||||||
|
@ -28,9 +28,9 @@ NodeItem TexNoiseNodeParser::compute()
|
|||||||
NodeItem detail = get_input_value("Detail");
|
NodeItem detail = get_input_value("Detail");
|
||||||
NodeItem lacunarity = get_input_value("Lacunarity");
|
NodeItem lacunarity = get_input_value("Lacunarity");
|
||||||
|
|
||||||
NodeItem texcoord = create_node("position", "vector3", true);
|
NodeItem texcoord = create_node("position", "vector3");
|
||||||
|
|
||||||
NodeItem res = create_node("fractal3d", "color3", true);
|
NodeItem res = create_node("fractal3d", "color3", false);
|
||||||
res.set_input("position", texcoord * scale);
|
res.set_input("position", texcoord * scale);
|
||||||
res.set_input("octaves", detail);
|
res.set_input("octaves", detail);
|
||||||
res.set_input("lacunarity", lacunarity);
|
res.set_input("lacunarity", lacunarity);
|
||||||
|
Loading…
Reference in New Issue
Block a user