From ea6276644010cb109326556addab82974ccd3000 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Sat, 23 Sep 2023 00:30:49 +0300 Subject: [PATCH 1/7] Fixes in group nodes --- .../nodes/shader/materialx/group_nodes.cc | 52 +++++++------------ .../nodes/shader/materialx/node_parser.cc | 4 ++ 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/source/blender/nodes/shader/materialx/group_nodes.cc b/source/blender/nodes/shader/materialx/group_nodes.cc index 6b7d67154913..f4450066828a 100644 --- a/source/blender/nodes/shader/materialx/group_nodes.cc +++ b/source/blender/nodes/shader/materialx/group_nodes.cc @@ -3,7 +3,6 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ #include "group_nodes.h" -#include "node_item.h" #include "node_parser.h" #include "BLI_vector.hh" @@ -33,14 +32,8 @@ NodeItem GroupNodeParser::compute() #endif NodeItem out = - GroupOutputNodeParser(graph, - depsgraph_, - material_, - node_out, - socket_out_, - to_type_, - this, - export_image_fn_) + GroupOutputNodeParser( + graph, depsgraph_, material_, node_out, socket_out_, to_type_, this, export_image_fn_) .compute_full(); #ifdef USE_MATERIALX_NODEGRAPH @@ -66,7 +59,8 @@ NodeItem GroupOutputNodeParser::compute() #ifdef USE_MATERIALX_NODEGRAPH Vector values; for (auto socket_in : node_->input_sockets()) { - NodeItem value = get_input_value(socket_in->index(), NodeItem::Type::Any); + NodeItem value = get_input_value( + socket_in->index(), NodeItem::is_arithmetic(to_type_) ? NodeItem::Type::Any : to_type_); if (value.value) { value = create_node("constant", value.type(), {{"value", value}}); } @@ -80,15 +74,19 @@ NodeItem GroupOutputNodeParser::compute() } return outputs[socket_out_->index()]; #else - if (NodeItem::is_arithmetic(to_type_)) { - return get_input_value(socket_out_->index(), to_type_); - } - return get_input_link(socket_out_->index(), to_type_); + return get_input_value(socket_out_->index(), to_type_); #endif } NodeItem GroupOutputNodeParser::compute_full() { + CLOG_INFO(LOG_MATERIALX_SHADER, + 1, + "%s [%d] => %s", + node_->name, + node_->typeinfo->type, + NodeItem::type(to_type_).c_str()); + #ifdef USE_MATERIALX_NODEGRAPH NodeItem res = empty(); @@ -98,13 +96,6 @@ NodeItem GroupOutputNodeParser::compute_full() return res; } - CLOG_INFO(LOG_MATERIALX_SHADER, - 1, - "%s [%d] => %s", - node_->name, - node_->typeinfo->type, - NodeItem::type(to_type_).c_str()); - res = compute(); return res; #else @@ -121,19 +112,23 @@ NodeItem GroupInputNodeParser::compute() } if (value.value) { - value = create_node("constant", value.type(), {{"value", value}}); + value = group_parser_->create_node("constant", value.type(), {{"value", value}}); } return create_input("input" + std::to_string(socket_out_->index() + 1), value); #else - if (NodeItem::is_arithmetic(to_type_)) { - return group_parser_->get_input_value(socket_out_->index(), to_type_); - } return group_parser_->get_input_link(socket_out_->index(), to_type_); #endif } NodeItem GroupInputNodeParser::compute_full() { + CLOG_INFO(LOG_MATERIALX_SHADER, + 1, + "%s [%d] => %s", + node_->name, + node_->typeinfo->type, + NodeItem::type(to_type_).c_str()); + #ifdef USE_MATERIALX_NODEGRAPH NodeItem res = empty(); @@ -143,13 +138,6 @@ NodeItem GroupInputNodeParser::compute_full() return res; } - CLOG_INFO(LOG_MATERIALX_SHADER, - 1, - "%s [%d] => %s", - node_->name, - node_->typeinfo->type, - NodeItem::type(to_type_).c_str()); - res = compute(); return res; #else diff --git a/source/blender/nodes/shader/materialx/node_parser.cc b/source/blender/nodes/shader/materialx/node_parser.cc index 2f14a971ecb6..07c4bbb04dbf 100644 --- a/source/blender/nodes/shader/materialx/node_parser.cc +++ b/source/blender/nodes/shader/materialx/node_parser.cc @@ -167,6 +167,10 @@ NodeItem NodeParser::texcoord_node(NodeItem::Type type) NodeItem NodeParser::get_default(const bNodeSocket &socket, NodeItem::Type to_type) { NodeItem res = empty(); + if (!NodeItem::is_arithmetic(to_type) && to_type != NodeItem::Type::Any) { + return res; + } + switch (socket.type) { case SOCK_CUSTOM: /* Return empty */ -- 2.30.2 From d515e7984ca1ddc937c85d28866758312b4e4b56 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Sat, 23 Sep 2023 00:44:29 +0300 Subject: [PATCH 2/7] Fixing linux build: set math functions names to convenience. --- .../nodes/shader/materialx/node_item.cc | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/source/blender/nodes/shader/materialx/node_item.cc b/source/blender/nodes/shader/materialx/node_item.cc index bcb7bdf52f9d..18d83b27f598 100644 --- a/source/blender/nodes/shader/materialx/node_item.cc +++ b/source/blender/nodes/shader/materialx/node_item.cc @@ -174,12 +174,12 @@ NodeItem NodeItem::operator/(const NodeItem &other) const NodeItem NodeItem::operator%(const NodeItem &other) const { return arithmetic( - other, "modulo", [](float a, float b) { return b == 0.0f ? 0.0f : std::fmodf(a, b); }); + other, "modulo", [](float a, float b) { return b == 0.0f ? 0.0f : std::fmod(a, b); }); } NodeItem NodeItem::operator^(const NodeItem &other) const { - return arithmetic(other, "power", [](float a, float b) { return std::powf(a, b); }); + return arithmetic(other, "power", [](float a, float b) { return std::pow(a, b); }); } NodeItem NodeItem::operator[](int index) const @@ -245,17 +245,17 @@ bool NodeItem::operator!=(const NodeItem &other) const NodeItem NodeItem::abs() const { - return arithmetic("absval", [](float a) { return std::fabsf(a); }); + return arithmetic("absval", [](float a) { return std::abs(a); }); } NodeItem NodeItem::floor() const { - return arithmetic("floor", [](float a) { return std::floorf(a); }); + return arithmetic("floor", [](float a) { return std::floor(a); }); } NodeItem NodeItem::ceil() const { - return arithmetic("ceil", [](float a) { return std::ceilf(a); }); + return arithmetic("ceil", [](float a) { return std::ceil(a); }); } NodeItem NodeItem::length() const @@ -400,38 +400,38 @@ NodeItem NodeItem::rotate(const NodeItem &angle_xyz, bool invert) NodeItem NodeItem::sin() const { - return to_vector().arithmetic("sin", [](float a) { return std::sinf(a); }); + return to_vector().arithmetic("sin", [](float a) { return std::sin(a); }); } NodeItem NodeItem::cos() const { - return to_vector().arithmetic("cos", [](float a) { return std::cosf(a); }); + return to_vector().arithmetic("cos", [](float a) { return std::cos(a); }); } NodeItem NodeItem::tan() const { - return to_vector().arithmetic("tan", [](float a) { return std::tanf(a); }); + return to_vector().arithmetic("tan", [](float a) { return std::tan(a); }); } NodeItem NodeItem::asin() const { - return to_vector().arithmetic("asin", [](float a) { return std::asinf(a); }); + return to_vector().arithmetic("asin", [](float a) { return std::asin(a); }); } NodeItem NodeItem::acos() const { - return to_vector().arithmetic("acos", [](float a) { return std::acosf(a); }); + return to_vector().arithmetic("acos", [](float a) { return std::acos(a); }); } NodeItem NodeItem::atan() const { - return to_vector().arithmetic("atan", [](float a) { return std::atanf(a); }); + return to_vector().arithmetic("atan", [](float a) { return std::atan(a); }); } NodeItem NodeItem::atan2(const NodeItem &other) const { return to_vector().arithmetic( - other, "atan2", [](float a, float b) { return std::atan2f(a, b); }); + other, "atan2", [](float a, float b) { return std::atan2(a, b); }); } NodeItem NodeItem::sinh() const @@ -456,12 +456,12 @@ NodeItem NodeItem::tanh() const NodeItem NodeItem::ln() const { - return to_vector().arithmetic("ln", [](float a) { return std::logf(a); }); + return to_vector().arithmetic("ln", [](float a) { return std::log(a); }); } NodeItem NodeItem::sqrt() const { - return to_vector().arithmetic("sqrt", [](float a) { return std::sqrtf(a); }); + return to_vector().arithmetic("sqrt", [](float a) { return std::sqrt(a); }); } NodeItem NodeItem::sign() const @@ -471,7 +471,7 @@ NodeItem NodeItem::sign() const NodeItem NodeItem::exp() const { - return to_vector().arithmetic("exp", [](float a) { return std::expf(a); }); + return to_vector().arithmetic("exp", [](float a) { return std::exp(a); }); } NodeItem NodeItem::convert(Type to_type) const -- 2.30.2 From 0c0ba7ee3e190e4ad3b8c45e0af0cea1926b3992 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Sat, 23 Sep 2023 00:47:41 +0300 Subject: [PATCH 3/7] make format --- source/blender/nodes/shader/materialx/node_item.cc | 3 +-- source/blender/nodes/shader/materialx/node_parser.h | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/source/blender/nodes/shader/materialx/node_item.cc b/source/blender/nodes/shader/materialx/node_item.cc index 18d83b27f598..d65332fdb02d 100644 --- a/source/blender/nodes/shader/materialx/node_item.cc +++ b/source/blender/nodes/shader/materialx/node_item.cc @@ -430,8 +430,7 @@ NodeItem NodeItem::atan() const NodeItem NodeItem::atan2(const NodeItem &other) const { - return to_vector().arithmetic( - other, "atan2", [](float a, float b) { return std::atan2(a, b); }); + return to_vector().arithmetic(other, "atan2", [](float a, float b) { return std::atan2(a, b); }); } NodeItem NodeItem::sinh() const diff --git a/source/blender/nodes/shader/materialx/node_parser.h b/source/blender/nodes/shader/materialx/node_parser.h index 6a93ad38f0fd..9e81d06b75bb 100644 --- a/source/blender/nodes/shader/materialx/node_parser.h +++ b/source/blender/nodes/shader/materialx/node_parser.h @@ -18,7 +18,7 @@ extern struct CLG_LogRef *LOG_MATERIALX_SHADER; class GroupNodeParser; -using ExportImageFunction = std::function; +using ExportImageFunction = std::function; /** * This is base abstraction class for parsing Blender nodes into MaterialX nodes. @@ -123,8 +123,7 @@ struct NodeParserData { void node_shader_materialx(void *data, struct bNode *node, struct bNodeSocket *out) \ { \ materialx::NodeParserData *d = reinterpret_cast(data); \ - d->result = MaterialXNodeParser( \ - d->graph, \ + d->result = MaterialXNodeParser(d->graph, \ d->depsgraph, \ d->material, \ node, \ -- 2.30.2 From f98d8a582c398b06cca75c8eaed87a3475c968dc Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Sat, 23 Sep 2023 01:13:59 +0300 Subject: [PATCH 4/7] Better naming of inputs and outputs in nodegraph for group node. --- .../nodes/shader/materialx/group_nodes.cc | 20 ++++++++++++++----- .../nodes/shader/materialx/group_nodes.h | 6 ++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/source/blender/nodes/shader/materialx/group_nodes.cc b/source/blender/nodes/shader/materialx/group_nodes.cc index f4450066828a..48b8a43fd024 100644 --- a/source/blender/nodes/shader/materialx/group_nodes.cc +++ b/source/blender/nodes/shader/materialx/group_nodes.cc @@ -69,7 +69,7 @@ NodeItem GroupOutputNodeParser::compute() Vector outputs; for (int i = 0; i < values.size(); ++i) { if (values[i]) { - outputs.append(create_output("output" + std::to_string(i + 1), values[i])); + outputs.append(create_output(out_name(node_->input_sockets()[i]), values[i])); } } return outputs[socket_out_->index()]; @@ -91,7 +91,7 @@ NodeItem GroupOutputNodeParser::compute_full() NodeItem res = empty(); /* Checking if output was already computed */ - res.output = graph_->getOutput("output" + std::to_string(socket_out_->index() + 1)); + res.output = graph_->getOutput(out_name(socket_out_)); if (res.output) { return res; } @@ -103,6 +103,11 @@ NodeItem GroupOutputNodeParser::compute_full() #endif } +std::string GroupOutputNodeParser::out_name(const bNodeSocket *out_socket) +{ + return MaterialX::createValidName(std::string("out_") + out_socket->name); +} + NodeItem GroupInputNodeParser::compute() { #ifdef USE_MATERIALX_NODEGRAPH @@ -114,7 +119,7 @@ NodeItem GroupInputNodeParser::compute() if (value.value) { value = group_parser_->create_node("constant", value.type(), {{"value", value}}); } - return create_input("input" + std::to_string(socket_out_->index() + 1), value); + return create_input(in_name(), value); #else return group_parser_->get_input_link(socket_out_->index(), to_type_); #endif @@ -132,8 +137,8 @@ NodeItem GroupInputNodeParser::compute_full() #ifdef USE_MATERIALX_NODEGRAPH NodeItem res = empty(); - /* Checking if output was already computed */ - res.input = graph_->getInput("input" + std::to_string(socket_out_->index() + 1)); + /* Checking if input was already computed */ + res.input = graph_->getInput(in_name()); if (res.input) { return res; } @@ -145,4 +150,9 @@ NodeItem GroupInputNodeParser::compute_full() #endif } +std::string GroupInputNodeParser::in_name() const +{ + return MaterialX::createValidName(std::string("in_") + socket_out_->name); +} + } // namespace blender::nodes::materialx diff --git a/source/blender/nodes/shader/materialx/group_nodes.h b/source/blender/nodes/shader/materialx/group_nodes.h index a486a4af5fd6..37db0814697c 100644 --- a/source/blender/nodes/shader/materialx/group_nodes.h +++ b/source/blender/nodes/shader/materialx/group_nodes.h @@ -29,6 +29,9 @@ class GroupOutputNodeParser : public NodeParser { using NodeParser::NodeParser; NodeItem compute() override; NodeItem compute_full() override; + + private: + static std::string out_name(const bNodeSocket *out_socket); }; class GroupInputNodeParser : public NodeParser { @@ -36,6 +39,9 @@ class GroupInputNodeParser : public NodeParser { using NodeParser::NodeParser; NodeItem compute() override; NodeItem compute_full() override; + + private: + std::string in_name() const; }; } // namespace blender::nodes::materialx -- 2.30.2 From cd737eb674c56be22dc4b57cbf20e61ef7ee8bff Mon Sep 17 00:00:00 2001 From: Vasyl-Pidhirskyi Date: Sat, 23 Sep 2023 22:53:13 +0300 Subject: [PATCH 5/7] Added argument use_group_default to specify whether GroupInputNodeParser should get link or value. --- .../nodes/shader/materialx/group_nodes.cc | 17 ++++++++++++---- .../nodes/shader/materialx/material.cc | 3 +++ .../nodes/shader/materialx/node_parser.cc | 20 +++++++++++++++---- .../nodes/shader/materialx/node_parser.h | 8 +++++++- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/source/blender/nodes/shader/materialx/group_nodes.cc b/source/blender/nodes/shader/materialx/group_nodes.cc index 48b8a43fd024..513291fff1df 100644 --- a/source/blender/nodes/shader/materialx/group_nodes.cc +++ b/source/blender/nodes/shader/materialx/group_nodes.cc @@ -31,10 +31,16 @@ NodeItem GroupNodeParser::compute() graph = group_graph.get(); #endif - NodeItem out = - GroupOutputNodeParser( - graph, depsgraph_, material_, node_out, socket_out_, to_type_, this, export_image_fn_) - .compute_full(); + NodeItem out = GroupOutputNodeParser(graph, + depsgraph_, + material_, + node_out, + socket_out_, + to_type_, + this, + use_group_default_, + export_image_fn_) + .compute_full(); #ifdef USE_MATERIALX_NODEGRAPH /* We have to be in NodeParser's graph_, therefore copying output */ @@ -121,6 +127,9 @@ NodeItem GroupInputNodeParser::compute() } return create_input(in_name(), value); #else + if (use_group_default_) { + return group_parser_->get_input_value(socket_out_->index(), to_type_); + } return group_parser_->get_input_link(socket_out_->index(), to_type_); #endif } diff --git a/source/blender/nodes/shader/materialx/material.cc b/source/blender/nodes/shader/materialx/material.cc index 755c937ad740..3cc919511ef8 100644 --- a/source/blender/nodes/shader/materialx/material.cc +++ b/source/blender/nodes/shader/materialx/material.cc @@ -71,6 +71,7 @@ MaterialX::DocumentPtr export_to_materialx(Depsgraph *depsgraph, NodeItem::Type::Material, nullptr, NodeItem(doc.get()), + false, export_image_fn}; output_node->typeinfo->materialx_fn(&data, output_node, nullptr); } @@ -82,6 +83,7 @@ MaterialX::DocumentPtr export_to_materialx(Depsgraph *depsgraph, nullptr, NodeItem::Type::Material, nullptr, + false, export_image_fn) .compute_error(); } @@ -94,6 +96,7 @@ MaterialX::DocumentPtr export_to_materialx(Depsgraph *depsgraph, nullptr, NodeItem::Type::Material, nullptr, + false, export_image_fn) .compute(); } diff --git a/source/blender/nodes/shader/materialx/node_parser.cc b/source/blender/nodes/shader/materialx/node_parser.cc index 07c4bbb04dbf..cd3a4f18ff72 100644 --- a/source/blender/nodes/shader/materialx/node_parser.cc +++ b/source/blender/nodes/shader/materialx/node_parser.cc @@ -21,6 +21,7 @@ NodeParser::NodeParser(MaterialX::GraphElement *graph, const bNodeSocket *socket_out, NodeItem::Type to_type, GroupNodeParser *group_parser, + bool use_group_default, ExportImageFunction export_image_fn) : graph_(graph), depsgraph_(depsgraph), @@ -29,6 +30,7 @@ NodeParser::NodeParser(MaterialX::GraphElement *graph, socket_out_(socket_out), to_type_(to_type), group_parser_(group_parser), + use_group_default_(use_group_default), export_image_fn_(export_image_fn) { } @@ -199,7 +201,9 @@ NodeItem NodeParser::get_default(const bNodeSocket &socket, NodeItem::Type to_ty return res.convert(to_type); } -NodeItem NodeParser::get_input_link(const bNodeSocket &socket, NodeItem::Type to_type) +NodeItem NodeParser::get_input_link(const bNodeSocket &socket, + NodeItem::Type to_type, + bool use_group_default) { const bNodeLink *link = socket.link; if (!(link && link->is_used())) { @@ -225,6 +229,7 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket, NodeItem::Type to link->fromsock, to_type, group_parser_, + use_group_default, export_image_fn_) .compute_full(); } @@ -236,6 +241,7 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket, NodeItem::Type to link->fromsock, to_type, group_parser_, + use_group_default, export_image_fn_) .compute_full(); } @@ -248,15 +254,21 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket, NodeItem::Type to return empty(); } - NodeParserData data = { - graph_, depsgraph_, material_, to_type, group_parser_, empty(), export_image_fn_}; + NodeParserData data = {graph_, + depsgraph_, + material_, + to_type, + group_parser_, + empty(), + use_group_default, + export_image_fn_}; from_node->typeinfo->materialx_fn(&data, const_cast(from_node), link->fromsock); return data.result; } NodeItem NodeParser::get_input_value(const bNodeSocket &socket, NodeItem::Type to_type) { - NodeItem res = get_input_link(socket, to_type); + NodeItem res = get_input_link(socket, to_type, true); if (!res) { res = get_default(socket, to_type); } diff --git a/source/blender/nodes/shader/materialx/node_parser.h b/source/blender/nodes/shader/materialx/node_parser.h index 9e81d06b75bb..3b0397ed0a5f 100644 --- a/source/blender/nodes/shader/materialx/node_parser.h +++ b/source/blender/nodes/shader/materialx/node_parser.h @@ -33,6 +33,7 @@ class NodeParser { const bNodeSocket *socket_out_; NodeItem::Type to_type_; GroupNodeParser *group_parser_; + bool use_group_default_; ExportImageFunction export_image_fn_; public: @@ -43,6 +44,7 @@ class NodeParser { const bNodeSocket *socket_out, NodeItem::Type to_type, GroupNodeParser *group_parser, + bool use_group_default, ExportImageFunction export_image_fn); virtual ~NodeParser() = default; @@ -71,7 +73,9 @@ class NodeParser { private: NodeItem get_default(const bNodeSocket &socket, NodeItem::Type to_type); - NodeItem get_input_link(const bNodeSocket &socket, NodeItem::Type to_type); + NodeItem get_input_link(const bNodeSocket &socket, + NodeItem::Type to_type, + bool use_group_default = false); NodeItem get_input_value(const bNodeSocket &socket, NodeItem::Type to_type); }; @@ -103,6 +107,7 @@ struct NodeParserData { NodeItem::Type to_type; GroupNodeParser *group_parser; NodeItem result; + bool use_group_default; ExportImageFunction export_image_fn; }; @@ -130,6 +135,7 @@ struct NodeParserData { out, \ d->to_type, \ d->group_parser, \ + d->use_group_default, \ d->export_image_fn) \ .compute_full(); \ } -- 2.30.2 From d91cc11fbed7e134c6a754093e556a408d0e241b Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Sun, 24 Sep 2023 07:26:17 +0300 Subject: [PATCH 6/7] Simplification --- .../nodes/shader/materialx/group_nodes.cc | 29 ++++++++++++------- .../nodes/shader/materialx/group_nodes.h | 13 ++++++++- .../nodes/shader/materialx/material.cc | 3 -- .../nodes/shader/materialx/node_parser.cc | 13 ++------- .../nodes/shader/materialx/node_parser.h | 4 --- 5 files changed, 33 insertions(+), 29 deletions(-) diff --git a/source/blender/nodes/shader/materialx/group_nodes.cc b/source/blender/nodes/shader/materialx/group_nodes.cc index 513291fff1df..98d8cdffe54f 100644 --- a/source/blender/nodes/shader/materialx/group_nodes.cc +++ b/source/blender/nodes/shader/materialx/group_nodes.cc @@ -31,16 +31,10 @@ NodeItem GroupNodeParser::compute() graph = group_graph.get(); #endif - NodeItem out = GroupOutputNodeParser(graph, - depsgraph_, - material_, - node_out, - socket_out_, - to_type_, - this, - use_group_default_, - export_image_fn_) - .compute_full(); + NodeItem out = + GroupOutputNodeParser( + graph, depsgraph_, material_, node_out, socket_out_, to_type_, this, export_image_fn_) + .compute_full(); #ifdef USE_MATERIALX_NODEGRAPH /* We have to be in NodeParser's graph_, therefore copying output */ @@ -114,6 +108,21 @@ std::string GroupOutputNodeParser::out_name(const bNodeSocket *out_socket) return MaterialX::createValidName(std::string("out_") + out_socket->name); } +GroupInputNodeParser::GroupInputNodeParser(MaterialX::GraphElement *graph, + const Depsgraph *depsgraph, + const Material *material, + const bNode *node, + const bNodeSocket *socket_out, + NodeItem::Type to_type, + GroupNodeParser *group_parser, + bool use_group_default, + ExportImageFunction export_image_fn) + : NodeParser( + graph, depsgraph, material, node, socket_out, to_type, group_parser, export_image_fn), + use_group_default_(use_group_default) +{ +} + NodeItem GroupInputNodeParser::compute() { #ifdef USE_MATERIALX_NODEGRAPH diff --git a/source/blender/nodes/shader/materialx/group_nodes.h b/source/blender/nodes/shader/materialx/group_nodes.h index 37db0814697c..cc31f7e9417c 100644 --- a/source/blender/nodes/shader/materialx/group_nodes.h +++ b/source/blender/nodes/shader/materialx/group_nodes.h @@ -35,8 +35,19 @@ class GroupOutputNodeParser : public NodeParser { }; class GroupInputNodeParser : public NodeParser { + private: + bool use_group_default_; + public: - using NodeParser::NodeParser; + GroupInputNodeParser(MaterialX::GraphElement *graph, + const Depsgraph *depsgraph, + const Material *material, + const bNode *node, + const bNodeSocket *socket_out, + NodeItem::Type to_type, + GroupNodeParser *group_parser, + bool use_group_default, + ExportImageFunction export_image_fn); NodeItem compute() override; NodeItem compute_full() override; diff --git a/source/blender/nodes/shader/materialx/material.cc b/source/blender/nodes/shader/materialx/material.cc index 3cc919511ef8..755c937ad740 100644 --- a/source/blender/nodes/shader/materialx/material.cc +++ b/source/blender/nodes/shader/materialx/material.cc @@ -71,7 +71,6 @@ MaterialX::DocumentPtr export_to_materialx(Depsgraph *depsgraph, NodeItem::Type::Material, nullptr, NodeItem(doc.get()), - false, export_image_fn}; output_node->typeinfo->materialx_fn(&data, output_node, nullptr); } @@ -83,7 +82,6 @@ MaterialX::DocumentPtr export_to_materialx(Depsgraph *depsgraph, nullptr, NodeItem::Type::Material, nullptr, - false, export_image_fn) .compute_error(); } @@ -96,7 +94,6 @@ MaterialX::DocumentPtr export_to_materialx(Depsgraph *depsgraph, nullptr, NodeItem::Type::Material, nullptr, - false, export_image_fn) .compute(); } diff --git a/source/blender/nodes/shader/materialx/node_parser.cc b/source/blender/nodes/shader/materialx/node_parser.cc index cd3a4f18ff72..1aff5e231790 100644 --- a/source/blender/nodes/shader/materialx/node_parser.cc +++ b/source/blender/nodes/shader/materialx/node_parser.cc @@ -21,7 +21,6 @@ NodeParser::NodeParser(MaterialX::GraphElement *graph, const bNodeSocket *socket_out, NodeItem::Type to_type, GroupNodeParser *group_parser, - bool use_group_default, ExportImageFunction export_image_fn) : graph_(graph), depsgraph_(depsgraph), @@ -30,7 +29,6 @@ NodeParser::NodeParser(MaterialX::GraphElement *graph, socket_out_(socket_out), to_type_(to_type), group_parser_(group_parser), - use_group_default_(use_group_default), export_image_fn_(export_image_fn) { } @@ -229,7 +227,6 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket, link->fromsock, to_type, group_parser_, - use_group_default, export_image_fn_) .compute_full(); } @@ -254,14 +251,8 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket, return empty(); } - NodeParserData data = {graph_, - depsgraph_, - material_, - to_type, - group_parser_, - empty(), - use_group_default, - export_image_fn_}; + NodeParserData data = { + graph_, depsgraph_, material_, to_type, group_parser_, empty(), export_image_fn_}; from_node->typeinfo->materialx_fn(&data, const_cast(from_node), link->fromsock); return data.result; } diff --git a/source/blender/nodes/shader/materialx/node_parser.h b/source/blender/nodes/shader/materialx/node_parser.h index 3b0397ed0a5f..23cfc1f058a4 100644 --- a/source/blender/nodes/shader/materialx/node_parser.h +++ b/source/blender/nodes/shader/materialx/node_parser.h @@ -33,7 +33,6 @@ class NodeParser { const bNodeSocket *socket_out_; NodeItem::Type to_type_; GroupNodeParser *group_parser_; - bool use_group_default_; ExportImageFunction export_image_fn_; public: @@ -44,7 +43,6 @@ class NodeParser { const bNodeSocket *socket_out, NodeItem::Type to_type, GroupNodeParser *group_parser, - bool use_group_default, ExportImageFunction export_image_fn); virtual ~NodeParser() = default; @@ -107,7 +105,6 @@ struct NodeParserData { NodeItem::Type to_type; GroupNodeParser *group_parser; NodeItem result; - bool use_group_default; ExportImageFunction export_image_fn; }; @@ -135,7 +132,6 @@ struct NodeParserData { out, \ d->to_type, \ d->group_parser, \ - d->use_group_default, \ d->export_image_fn) \ .compute_full(); \ } -- 2.30.2 From 6c54864245ad5bf4e91c6f2b2fdada06389f8f21 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Sun, 24 Sep 2023 08:00:36 +0300 Subject: [PATCH 7/7] Moved use_group_default to GroupNodeParser. Fixed setting default from GroupOutput node --- .../nodes/shader/materialx/group_nodes.cc | 49 +++++++++++-------- .../nodes/shader/materialx/group_nodes.h | 33 ++++++------- .../nodes/shader/materialx/node_parser.cc | 11 +++-- .../nodes/shader/materialx/node_parser.h | 2 +- 4 files changed, 52 insertions(+), 43 deletions(-) diff --git a/source/blender/nodes/shader/materialx/group_nodes.cc b/source/blender/nodes/shader/materialx/group_nodes.cc index 98d8cdffe54f..dac98d674dab 100644 --- a/source/blender/nodes/shader/materialx/group_nodes.cc +++ b/source/blender/nodes/shader/materialx/group_nodes.cc @@ -9,6 +9,21 @@ namespace blender::nodes::materialx { +GroupNodeParser::GroupNodeParser(MaterialX::GraphElement *graph, + const Depsgraph *depsgraph, + const Material *material, + const bNode *node, + const bNodeSocket *socket_out, + NodeItem::Type to_type, + GroupNodeParser *group_parser, + ExportImageFunction export_image_fn, + bool use_group_default) + : NodeParser( + graph, depsgraph, material, node, socket_out, to_type, group_parser, export_image_fn), + use_group_default_(use_group_default) +{ +} + NodeItem GroupNodeParser::compute() { NodeItem res = empty(); @@ -31,10 +46,16 @@ NodeItem GroupNodeParser::compute() graph = group_graph.get(); #endif - NodeItem out = - GroupOutputNodeParser( - graph, depsgraph_, material_, node_out, socket_out_, to_type_, this, export_image_fn_) - .compute_full(); + NodeItem out = GroupOutputNodeParser(graph, + depsgraph_, + material_, + node_out, + socket_out_, + to_type_, + this, + export_image_fn_, + use_group_default_) + .compute_full(); #ifdef USE_MATERIALX_NODEGRAPH /* We have to be in NodeParser's graph_, therefore copying output */ @@ -74,7 +95,10 @@ NodeItem GroupOutputNodeParser::compute() } return outputs[socket_out_->index()]; #else - return get_input_value(socket_out_->index(), to_type_); + if (use_group_default_) { + return get_input_value(socket_out_->index(), to_type_); + } + return get_input_link(socket_out_->index(), to_type_); #endif } @@ -108,21 +132,6 @@ std::string GroupOutputNodeParser::out_name(const bNodeSocket *out_socket) return MaterialX::createValidName(std::string("out_") + out_socket->name); } -GroupInputNodeParser::GroupInputNodeParser(MaterialX::GraphElement *graph, - const Depsgraph *depsgraph, - const Material *material, - const bNode *node, - const bNodeSocket *socket_out, - NodeItem::Type to_type, - GroupNodeParser *group_parser, - bool use_group_default, - ExportImageFunction export_image_fn) - : NodeParser( - graph, depsgraph, material, node, socket_out, to_type, group_parser, export_image_fn), - use_group_default_(use_group_default) -{ -} - NodeItem GroupInputNodeParser::compute() { #ifdef USE_MATERIALX_NODEGRAPH diff --git a/source/blender/nodes/shader/materialx/group_nodes.h b/source/blender/nodes/shader/materialx/group_nodes.h index cc31f7e9417c..6072f6aa9062 100644 --- a/source/blender/nodes/shader/materialx/group_nodes.h +++ b/source/blender/nodes/shader/materialx/group_nodes.h @@ -15,18 +15,28 @@ namespace blender::nodes::materialx { class GroupInputNodeParser; class GroupNodeParser : public NodeParser { - friend NodeParser; friend GroupInputNodeParser; + protected: + bool use_group_default_; + public: - using NodeParser::NodeParser; + GroupNodeParser(MaterialX::GraphElement *graph, + const Depsgraph *depsgraph, + const Material *material, + const bNode *node, + const bNodeSocket *socket_out, + NodeItem::Type to_type, + GroupNodeParser *group_parser, + ExportImageFunction export_image_fn, + bool use_group_default); NodeItem compute() override; NodeItem compute_full() override; }; -class GroupOutputNodeParser : public NodeParser { +class GroupOutputNodeParser : public GroupNodeParser { public: - using NodeParser::NodeParser; + using GroupNodeParser::GroupNodeParser; NodeItem compute() override; NodeItem compute_full() override; @@ -34,20 +44,9 @@ class GroupOutputNodeParser : public NodeParser { static std::string out_name(const bNodeSocket *out_socket); }; -class GroupInputNodeParser : public NodeParser { - private: - bool use_group_default_; - +class GroupInputNodeParser : public GroupNodeParser { public: - GroupInputNodeParser(MaterialX::GraphElement *graph, - const Depsgraph *depsgraph, - const Material *material, - const bNode *node, - const bNodeSocket *socket_out, - NodeItem::Type to_type, - GroupNodeParser *group_parser, - bool use_group_default, - ExportImageFunction export_image_fn); + using GroupNodeParser::GroupNodeParser; NodeItem compute() override; NodeItem compute_full() override; diff --git a/source/blender/nodes/shader/materialx/node_parser.cc b/source/blender/nodes/shader/materialx/node_parser.cc index 1aff5e231790..beedcab34710 100644 --- a/source/blender/nodes/shader/materialx/node_parser.cc +++ b/source/blender/nodes/shader/materialx/node_parser.cc @@ -115,12 +115,12 @@ NodeItem NodeParser::get_input_default(int index, NodeItem::Type to_type) NodeItem NodeParser::get_input_link(const std::string &name, NodeItem::Type to_type) { - return get_input_link(node_->input_by_identifier(name), to_type); + return get_input_link(node_->input_by_identifier(name), to_type, false); } NodeItem NodeParser::get_input_link(int index, NodeItem::Type to_type) { - return get_input_link(node_->input_socket(index), to_type); + return get_input_link(node_->input_socket(index), to_type, false); } NodeItem NodeParser::get_input_value(const std::string &name, NodeItem::Type to_type) @@ -227,7 +227,8 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket, link->fromsock, to_type, group_parser_, - export_image_fn_) + export_image_fn_, + use_group_default) .compute_full(); } if (from_node->is_group_input()) { @@ -238,8 +239,8 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket, link->fromsock, to_type, group_parser_, - use_group_default, - export_image_fn_) + export_image_fn_, + use_group_default) .compute_full(); } diff --git a/source/blender/nodes/shader/materialx/node_parser.h b/source/blender/nodes/shader/materialx/node_parser.h index 23cfc1f058a4..83a09aa5b767 100644 --- a/source/blender/nodes/shader/materialx/node_parser.h +++ b/source/blender/nodes/shader/materialx/node_parser.h @@ -73,7 +73,7 @@ class NodeParser { NodeItem get_default(const bNodeSocket &socket, NodeItem::Type to_type); NodeItem get_input_link(const bNodeSocket &socket, NodeItem::Type to_type, - bool use_group_default = false); + bool use_group_default); NodeItem get_input_value(const bNodeSocket &socket, NodeItem::Type to_type); }; -- 2.30.2