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