MaterialX: Implement export of Input nodes #20

Merged
Bogdan Nagirniak merged 26 commits from Vasyl-Pidhirskyi/blender:BLEN-530 into matx-export-material 2023-09-15 19:55:37 +02:00
16 changed files with 26 additions and 27 deletions
Showing only changes of commit 34ad30637a - Show all commits

View File

@ -73,12 +73,12 @@ NodeItem NodeParser::create_node(const std::string &category, NodeItem::Type typ
NodeItem NodeParser::get_input_default(const std::string &name, NodeItem::Type to_type) NodeItem NodeParser::get_input_default(const std::string &name, NodeItem::Type to_type)
{ {
return get_default(node_->input_by_identifier(name)).convert(to_type); return get_default(node_->input_by_identifier(name), to_type);
} }
NodeItem NodeParser::get_input_default(int index, NodeItem::Type to_type) NodeItem NodeParser::get_input_default(int index, NodeItem::Type to_type)
{ {
return get_default(node_->input_socket(index)).convert(to_type); return get_default(node_->input_socket(index), to_type);
} }
NodeItem NodeParser::get_input_link(const std::string &name, NodeItem::Type to_type) NodeItem NodeParser::get_input_link(const std::string &name, NodeItem::Type to_type)
@ -101,14 +101,14 @@ NodeItem NodeParser::get_input_value(int index, NodeItem::Type to_type)
return get_input_value(node_->input_socket(index), to_type); return get_input_value(node_->input_socket(index), to_type);
} }
NodeItem NodeParser::get_output_default(const std::string &name) NodeItem NodeParser::get_output_default(const std::string &name, NodeItem::Type to_type)
{ {
return get_default(node_->output_by_identifier(name)); return get_default(node_->output_by_identifier(name), to_type);
} }
NodeItem NodeParser::get_output_default(int index) NodeItem NodeParser::get_output_default(int index, NodeItem::Type to_type)
{ {
return get_default(node_->output_socket(index)); return get_default(node_->output_socket(index), to_type);
} }
NodeItem NodeParser::empty() const NodeItem NodeParser::empty() const
@ -127,7 +127,7 @@ NodeItem NodeParser::texcoord_node()
return res; return res;
} }
NodeItem NodeParser::get_default(const bNodeSocket &socket) NodeItem NodeParser::get_default(const bNodeSocket &socket, NodeItem::Type to_type)
{ {
NodeItem res = empty(); NodeItem res = empty();
switch (socket.type) { switch (socket.type) {
@ -152,7 +152,7 @@ NodeItem NodeParser::get_default(const bNodeSocket &socket)
CLOG_WARN(LOG_MATERIALX_SHADER, "Unsupported socket type: %d", socket.type); CLOG_WARN(LOG_MATERIALX_SHADER, "Unsupported socket type: %d", socket.type);
} }
} }
return res; 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)
@ -190,7 +190,7 @@ NodeItem NodeParser::get_input_value(const bNodeSocket &socket, NodeItem::Type t
{ {
NodeItem res = get_input_link(socket, to_type); NodeItem res = get_input_link(socket, to_type);
if (!res) { if (!res) {
res = get_default(socket).convert(to_type); res = get_default(socket, to_type);
} }
return res; return res;
} }

View File

@ -42,8 +42,8 @@ class NodeParser {
NodeItem create_node(const std::string &category, NodeItem::Type type); NodeItem create_node(const std::string &category, NodeItem::Type type);
NodeItem get_input_default(const std::string &name, NodeItem::Type to_type); NodeItem get_input_default(const std::string &name, NodeItem::Type to_type);
NodeItem get_input_default(int index, NodeItem::Type to_type); NodeItem get_input_default(int index, NodeItem::Type to_type);
NodeItem get_output_default(const std::string &name); NodeItem get_output_default(const std::string &name, NodeItem::Type to_type);
NodeItem get_output_default(int index); NodeItem get_output_default(int index, NodeItem::Type to_type);
NodeItem get_input_link(const std::string &name, NodeItem::Type to_type); NodeItem get_input_link(const std::string &name, NodeItem::Type to_type);
NodeItem get_input_link(int index, NodeItem::Type to_type); NodeItem get_input_link(int index, NodeItem::Type to_type);
NodeItem get_input_value(const std::string &name, NodeItem::Type to_type); NodeItem get_input_value(const std::string &name, NodeItem::Type to_type);
@ -53,7 +53,7 @@ class NodeParser {
NodeItem texcoord_node(); NodeItem texcoord_node();
private: private:
NodeItem get_default(const bNodeSocket &socket); 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);
NodeItem get_input_value(const bNodeSocket &socket, NodeItem::Type to_type); NodeItem get_input_value(const bNodeSocket &socket, NodeItem::Type to_type);
BogdanNagirniak marked this conversation as resolved Outdated

use one function here instead of 3 get_default(const bNodeSocket &socket, NodeItem::Type to_type)

use one function here instead of 3 `get_default(const bNodeSocket &socket, NodeItem::Type to_type)`
}; };

View File

@ -65,7 +65,7 @@ NODE_SHADER_MATERIALX_BEGIN
* res.set_input("coneangle", val(90.0f)); * res.set_input("coneangle", val(90.0f));
* res.set_input("maxdistance", maxdistance); * res.set_input("maxdistance", maxdistance);
*/ */
BogdanNagirniak marked this conversation as resolved
Review
NodeItem color = get_input_value("Color", NodeItem::Type::Color4);
NodeItem res = color;
``` NodeItem color = get_input_value("Color", NodeItem::Type::Color4); NodeItem res = color; ```
return get_output_default(socket_out_->name); return get_output_default(socket_out_->name, NodeItem::Type::Any);
} }
#endif #endif
NODE_SHADER_MATERIALX_END NODE_SHADER_MATERIALX_END

View File

@ -82,8 +82,7 @@ NODE_SHADER_MATERIALX_BEGIN
{ {
/* TODO: some outputs expected be implemented within the next iteration (see nodedef /* TODO: some outputs expected be implemented within the next iteration (see nodedef
* <geompropvalue>) */ * <geompropvalue>) */
BogdanNagirniak marked this conversation as resolved
Review

Start with NodeItem res = empty(); add check if (STREQ(socket_out_->name, "Color"))

Start with `NodeItem res = empty();` add check `if (STREQ(socket_out_->name, "Color"))`
return get_output_default(socket_out_->name, NodeItem::Type::Any);
return get_output_default(socket_out_->name);
} }
#endif #endif
NODE_SHADER_MATERIALX_END NODE_SHADER_MATERIALX_END
BogdanNagirniak marked this conversation as resolved Outdated

else if

`else if`

View File

@ -30,7 +30,7 @@ NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX #ifdef WITH_MATERIALX
{ {
/* NOTE: This node doesn't have an implementation in MaterialX.*/ /* NOTE: This node doesn't have an implementation in MaterialX.*/
return get_output_default(socket_out_->name); return get_output_default(socket_out_->name, NodeItem::Type::Any);
} }
#endif #endif
NODE_SHADER_MATERIALX_END NODE_SHADER_MATERIALX_END

View File

@ -78,7 +78,7 @@ NODE_SHADER_MATERIALX_BEGIN
res.set_input("space", val(std::string("world"))); res.set_input("space", val(std::string("world")));
} }
else { else {
res = get_output_default(name); res = get_output_default(name, NodeItem::Type::Any);
} }
return res; return res;
} }

View File

@ -33,7 +33,7 @@ NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX #ifdef WITH_MATERIALX
{ {
/* NOTE: This node doesn't have an implementation in MaterialX.*/ /* NOTE: This node doesn't have an implementation in MaterialX.*/
return get_output_default(socket_out_->name); return get_output_default(socket_out_->name, NodeItem::Type::Any);
} }
#endif #endif
NODE_SHADER_MATERIALX_END NODE_SHADER_MATERIALX_END

View File

@ -51,7 +51,7 @@ NODE_SHADER_MATERIALX_BEGIN
* res.set_input("seed", val(0)); * res.set_input("seed", val(0));
*}*/ *}*/
else { else {
res = get_output_default(name); res = get_output_default(name, NodeItem::Type::Any);
} }
return res; return res;
} }

View File

@ -38,7 +38,7 @@ NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX #ifdef WITH_MATERIALX
{ {
/* NOTE: This node doesn't have an implementation in MaterialX.*/ /* NOTE: This node doesn't have an implementation in MaterialX.*/
return get_output_default(socket_out_->name); return get_output_default(socket_out_->name, NodeItem::Type::Any);
BogdanNagirniak marked this conversation as resolved Outdated

use std::string name = socket_out_->name and ELEM(name, ....)

use `std::string name = socket_out_->name` and `ELEM(name, ....)`
} }
#endif #endif
NODE_SHADER_MATERIALX_END NODE_SHADER_MATERIALX_END

View File

@ -26,7 +26,7 @@ NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX #ifdef WITH_MATERIALX
{ {
/* NOTE: This node doesn't have an implementation in MaterialX.*/ /* NOTE: This node doesn't have an implementation in MaterialX.*/
return get_output_default(socket_out_->name); return get_output_default(socket_out_->name, NodeItem::Type::Any);
} }
#endif #endif
NODE_SHADER_MATERIALX_END NODE_SHADER_MATERIALX_END
BogdanNagirniak marked this conversation as resolved
Review

I think return get_output_default can be used here

I think `return get_output_default` can be used here

View File

@ -30,7 +30,7 @@ NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX #ifdef WITH_MATERIALX
{ {
NodeItem res = create_node("constant", NodeItem::Type::Color4); NodeItem res = create_node("constant", NodeItem::Type::Color4);
res.set_input("value", get_output_default("Color")); res.set_input("value", get_output_default("Color", NodeItem::Type::Color4));
return res; return res;
} }
#endif #endif

View File

@ -90,7 +90,7 @@ NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX #ifdef WITH_MATERIALX
{ {
/* TODO: This node doesn't have an implementation in MaterialX.*/ /* TODO: This node doesn't have an implementation in MaterialX.*/
return get_output_default(socket_out_->name); return get_output_default(socket_out_->name, NodeItem::Type::Vector3);
} }
#endif #endif
NODE_SHADER_MATERIALX_END NODE_SHADER_MATERIALX_END

View File

@ -90,7 +90,7 @@ NODE_SHADER_MATERIALX_BEGIN
res.set_input("space", val(std::string("world"))); res.set_input("space", val(std::string("world")));
} }
else { else {
res = get_output_default(name); res = get_output_default(name, NodeItem::Type::Any);
} }
return res; return res;

View File

@ -42,7 +42,7 @@ NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX #ifdef WITH_MATERIALX
{ {
NodeItem res = create_node("constant", NodeItem::Type::Float); NodeItem res = create_node("constant", NodeItem::Type::Float);
res.set_input("value", get_output_default("Value")); res.set_input("value", get_output_default("Value", NodeItem::Type::Float));
return res; return res;
} }
#endif #endif

View File

@ -72,7 +72,7 @@ NODE_SHADER_MATERIALX_BEGIN
{ {
/* TODO: some output expected be implemented within the next iteration (see nodedef /* TODO: some output expected be implemented within the next iteration (see nodedef
* <geomcolor>)*/ * <geomcolor>)*/
BogdanNagirniak marked this conversation as resolved
Review

start from empty()

start from empty()
return get_output_default(socket_out_->name); return get_output_default(socket_out_->name, NodeItem::Type::Any);
} }
#endif #endif
NODE_SHADER_MATERIALX_END NODE_SHADER_MATERIALX_END

View File

@ -44,7 +44,7 @@ NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX #ifdef WITH_MATERIALX
{ {
/* NOTE: This node doesn't have an implementation in MaterialX.*/ /* NOTE: This node doesn't have an implementation in MaterialX.*/
return get_output_default(socket_out_->name); return get_output_default(socket_out_->name, NodeItem::Type::Float);
} }
#endif #endif
NODE_SHADER_MATERIALX_END NODE_SHADER_MATERIALX_END