forked from blender/blender
Export to MatX various Texture nodes #5
@ -41,9 +41,8 @@ class NodeParser {
|
|||||||
NodeItem empty() const;
|
NodeItem empty() const;
|
||||||
template<class T> NodeItem value(const T &data) const;
|
template<class T> NodeItem value(const T &data) const;
|
||||||
|
|
||||||
virtual NodeItem get_input_default(const bNodeSocket &socket);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
NodeItem get_input_default(const bNodeSocket &socket);
|
||||||
NodeItem get_input_link(const bNodeSocket &socket);
|
NodeItem get_input_link(const bNodeSocket &socket);
|
||||||
NodeItem get_input_value(const bNodeSocket &socket);
|
NodeItem get_input_value(const bNodeSocket &socket);
|
||||||
};
|
};
|
||||||
@ -60,24 +59,14 @@ template<class T> NodeItem NodeParser::value(const T &data) const
|
|||||||
NodeItem compute() override; \
|
NodeItem compute() override; \
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DECLARE_PARSER_OVERRIDE(T) \
|
|
||||||
class T : public NodeParser { \
|
|
||||||
public: \
|
|
||||||
using NodeParser::NodeParser; \
|
|
||||||
NodeItem compute() override; \
|
|
||||||
\
|
|
||||||
protected: \
|
|
||||||
NodeItem get_input_default(const bNodeSocket &socket) override; \
|
|
||||||
};
|
|
||||||
|
|
||||||
DECLARE_PARSER(BSDFPrincipledNodeParser)
|
DECLARE_PARSER(BSDFPrincipledNodeParser)
|
||||||
DECLARE_PARSER(InvertNodeParser)
|
DECLARE_PARSER(InvertNodeParser)
|
||||||
DECLARE_PARSER(MathNodeParser)
|
DECLARE_PARSER(MathNodeParser)
|
||||||
DECLARE_PARSER(MixRGBNodeParser)
|
DECLARE_PARSER(MixRGBNodeParser)
|
||||||
DECLARE_PARSER(OutputMaterialNodeParser)
|
DECLARE_PARSER(OutputMaterialNodeParser)
|
||||||
DECLARE_PARSER(TexImageNodeParser)
|
DECLARE_PARSER(TexCheckerNodeParser)
|
||||||
DECLARE_PARSER(TexEnvironmentNodeParser)
|
DECLARE_PARSER(TexEnvironmentNodeParser)
|
||||||
DECLARE_PARSER_OVERRIDE(TexNoiseNodeParser)
|
DECLARE_PARSER(TexImageNodeParser)
|
||||||
DECLARE_PARSER_OVERRIDE(TexCheckerNodeParser)
|
DECLARE_PARSER(TexNoiseNodeParser)
|
||||||
|
|
||||||
} // namespace blender::nodes::materialx
|
} // namespace blender::nodes::materialx
|
||||||
|
@ -8,23 +8,13 @@
|
|||||||
|
|
||||||
namespace blender::nodes::materialx {
|
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 TexCheckerNodeParser::compute()
|
||||||
{
|
{
|
||||||
NodeItem scale = get_input_value("Scale");
|
NodeItem scale = get_input_value("Scale");
|
||||||
DagerD marked this conversation as resolved
Outdated
|
|||||||
|
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 color1 = get_input_value("Color1");
|
||||||
NodeItem color2 = get_input_value("Color2");
|
NodeItem color2 = get_input_value("Color2");
|
||||||
|
|
||||||
@ -32,16 +22,15 @@ NodeItem TexCheckerNodeParser::compute()
|
|||||||
NodeItem frequency = create_node("constant", "vector2");
|
NodeItem frequency = create_node("constant", "vector2");
|
||||||
|
|
||||||
/* Modifier to follow Cycles result. */
|
/* Modifier to follow Cycles result. */
|
||||||
NodeItem scale_fitter(graph);
|
scale = scale * value(4.0f);
|
||||||
scale_fitter.value = MaterialX::Value::createValue<float>(4.0f);
|
frequency.set_input("value", scale);
|
||||||
frequency.set_input("value", scale * scale_fitter);
|
|
||||||
|
|
||||||
NodeItem offset = create_node("constant", "vector2");
|
//NodeItem offset = create_node("constant", "vector2");
|
||||||
offset.set_input("value", empty().val(MaterialX::Vector2({0.0f, 0.0f})));
|
//offset.set_input("value", value(MaterialX::Vector2(0.0f, 0.0f)));
|
||||||
|
|
||||||
NodeItem place2d = create_node("place2d", "vector2");
|
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");
|
NodeItem separate = create_node("separate2", "multioutput");
|
||||||
separate.set_input("in", place2d);
|
separate.set_input("in", place2d);
|
||||||
@ -50,16 +39,16 @@ NodeItem TexCheckerNodeParser::compute()
|
|||||||
|
|
||||||
NodeItem modulo_x = create_node("modulo", "float");
|
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", value(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");
|
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", value(2.0f));
|
||||||
modulo_y.node->setConnectedOutput("in1", separate.node->getOutput("outy"));
|
modulo_y.node->setConnectedOutput("in1", separate.node->getOutput("outy"));
|
||||||
|
|
||||||
NodeItem ifequal = (modulo_x.floor() + modulo_y.floor())
|
NodeItem ifequal =
|
||||||
.if_else("==", empty().val(1.0f), empty().val(0.0f), empty().val(1.0f));
|
(modulo_x.floor() + modulo_y.floor()).if_else("==", value(1.0f), value(0.0f), value(1.0f));
|
||||||
|
|
||||||
NodeItem res = create_node("mix", "color3", false);
|
NodeItem res = create_node("mix", "color3", false);
|
||||||
res.set_input("fg", color1.to_color3());
|
res.set_input("fg", color1.to_color3());
|
||||||
|
@ -8,24 +8,13 @@
|
|||||||
|
|
||||||
namespace blender::nodes::materialx {
|
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 TexNoiseNodeParser::compute()
|
||||||
{
|
{
|
||||||
NodeItem scale = get_input_value("Scale");
|
NodeItem scale = get_input_value("Scale");
|
||||||
NodeItem detail = get_input_value("Detail");
|
NodeItem detail = get_input_value("Detail");
|
||||||
|
if (detail.value && detail.type() == "float") {
|
||||||
|
detail = value(int(detail.value->asA<float>()));
|
||||||
|
}
|
||||||
DagerD marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
Use following order:
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 lacunarity = get_input_value("Lacunarity");
|
||||||
|
|
||||||
NodeItem texcoord = create_node("position", "vector3");
|
NodeItem texcoord = create_node("position", "vector3");
|
||||||
|
Loading…
Reference in New Issue
Block a user
change create_node() signature accessory->noname = true