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
18 changed files with 33 additions and 46 deletions
Showing only changes of commit 1b6b13df4c - Show all commits

View File

@ -376,8 +376,6 @@ NodeItem NodeItem::convert(Type to_type) const
switch (to_type) { switch (to_type) {
case Type::Vector4: case Type::Vector4:
return convert(Type::Vector3).convert(Type::Vector4); return convert(Type::Vector3).convert(Type::Vector4);
case Type::Vector3:
return convert(Type::Vector3);
case Type::Color3: case Type::Color3:
return convert(Type::Vector3).convert(Type::Color3); return convert(Type::Vector3).convert(Type::Color3);
case Type::Color4: case Type::Color4:
@ -390,20 +388,12 @@ NodeItem NodeItem::convert(Type to_type) const
switch (to_type) { switch (to_type) {
case Type::Color4: case Type::Color4:
return convert(Type::Color3).convert(Type::Color4); return convert(Type::Color3).convert(Type::Color4);
case Type::Color3:
return convert(Type::Color3);
case Type::Vector4:
return convert(Type::Vector4);
case Type::Vector2:
return convert(Type::Vector2);
default: default:
break; break;
} }
break; break;
case Type::Vector4: case Type::Vector4:
switch (to_type) { switch (to_type) {
case Type::Vector3:
return convert(Type::Vector3);
case Type::Vector2: case Type::Vector2:
return convert(Type::Vector3).convert(Type::Vector2); return convert(Type::Vector3).convert(Type::Vector2);
case Type::Color3: case Type::Color3:
@ -418,8 +408,6 @@ NodeItem NodeItem::convert(Type to_type) const
return convert(Type::Vector3).convert(Type::Vector2); return convert(Type::Vector3).convert(Type::Vector2);
case Type::Vector4: case Type::Vector4:
return convert(Type::Vector3).convert(Type::Vector4); return convert(Type::Vector3).convert(Type::Vector4);
case Type::Vector3:
return convert(Type::Vector3);
default: default:
break; break;
} }

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), to_type); return get_default(node_->input_by_identifier(name)).convert(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), to_type); return get_default(node_->input_socket(index)).convert(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::Type to_type) NodeItem NodeParser::get_output_default(const std::string &name)
{ {
return get_default(node_->output_by_identifier(name), to_type); return get_default(node_->output_by_identifier(name));
} }
NodeItem NodeParser::get_output_default(int index, NodeItem::Type to_type) NodeItem NodeParser::get_output_default(int index)
{ {
return get_default(node_->output_socket(index), to_type); return get_default(node_->output_socket(index));
} }
NodeItem NodeParser::empty() const NodeItem NodeParser::empty() const
@ -116,19 +116,18 @@ NodeItem NodeParser::empty() const
return NodeItem(graph_); return NodeItem(graph_);
} }
NodeItem NodeParser::texcoord_node(NodeItem::Type data_type) NodeItem NodeParser::texcoord_node()
{ {
NodeItem res = empty(); NodeItem res = empty();
std::string name = TEXCOORD_NODE_NAME + "_" + NodeItem::type(data_type); res.node = graph_->getNode(TEXCOORD_NODE_NAME);
res.node = graph_->getNode(name);
if (!res.node) { if (!res.node) {
res = create_node("texcoord", data_type); res = create_node("texcoord", NodeItem::Type::Vector2);
res.node->setName(name); res.node->setName(TEXCOORD_NODE_NAME);
} }
return res; return res;
} }
NodeItem NodeParser::get_default(const bNodeSocket &socket, NodeItem::Type to_type) NodeItem NodeParser::get_default(const bNodeSocket &socket)
{ {
NodeItem res = empty(); NodeItem res = empty();
switch (socket.type) { switch (socket.type) {
@ -153,7 +152,7 @@ NodeItem NodeParser::get_default(const bNodeSocket &socket, NodeItem::Type to_ty
CLOG_WARN(LOG_MATERIALX_SHADER, "Unsupported socket type: %d", socket.type); CLOG_WARN(LOG_MATERIALX_SHADER, "Unsupported socket type: %d", socket.type);
} }
} }
return res.convert(to_type); return res;
} }
NodeItem NodeParser::get_input_link(const bNodeSocket &socket, NodeItem::Type to_type) NodeItem NodeParser::get_input_link(const bNodeSocket &socket, NodeItem::Type to_type)
@ -191,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, to_type); res = get_default(socket).convert(to_type);
} }
return res; return res;
} }

View File

@ -42,18 +42,18 @@ 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::Type to_type); NodeItem get_output_default(const std::string &name);
NodeItem get_output_default(int index, NodeItem::Type to_type); NodeItem get_output_default(int index);
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);
NodeItem get_input_value(int index, NodeItem::Type to_type); NodeItem get_input_value(int index, NodeItem::Type to_type);
NodeItem empty() const; NodeItem empty() const;
template<class T> NodeItem val(const T &data) const; template<class T> NodeItem val(const T &data) const;
NodeItem texcoord_node(NodeItem::Type data_type = NodeItem::Type::Vector2); NodeItem texcoord_node();
private: private:
NodeItem get_default(const bNodeSocket &socket, NodeItem::Type to_type); NodeItem get_default(const bNodeSocket &socket);
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);
}; };

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, NodeItem::Type::Any); return get_output_default(socket_out_->name);
} }
#endif #endif
NODE_SHADER_MATERIALX_END NODE_SHADER_MATERIALX_END

View File

@ -83,7 +83,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

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, NodeItem::Type::Any); return get_output_default(socket_out_->name);
} }
#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, NodeItem::Type::Any); res = get_output_default(name);
} }
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, NodeItem::Type::Any); return get_output_default(socket_out_->name);
} }
#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, NodeItem::Type::Any); res = get_output_default(name);
} }
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, NodeItem::Type::Any); return get_output_default(socket_out_->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, 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
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", NodeItem::Type::Color4)); res.set_input("value", get_output_default("Color"));
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, NodeItem::Type::Vector3);; return get_output_default(socket_out_->name);
} }
#endif #endif
NODE_SHADER_MATERIALX_END NODE_SHADER_MATERIALX_END

View File

@ -79,7 +79,7 @@ NODE_SHADER_MATERIALX_BEGIN
std::string name = socket_out_->name; std::string name = socket_out_->name;
if (ELEM(name, "Generated", "UV")) { if (ELEM(name, "Generated", "UV")) {
res = texcoord_node(NodeItem::Type::Vector3); res = texcoord_node();
} }
else if (name == "Normal") { else if (name == "Normal") {
res = create_node("normal", NodeItem::Type::Vector3); res = create_node("normal", NodeItem::Type::Vector3);
@ -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, NodeItem::Type::Any); res = get_output_default(name);
} }
return res; return res;

View File

@ -73,7 +73,7 @@ NODE_SHADER_MATERIALX_BEGIN
/* NODE: "From Instances" not implemented /* NODE: "From Instances" not implemented
* UV selection not implemented * UV selection not implemented
*/ */
return texcoord_node(NodeItem::Type::Vector3); return texcoord_node();
} }
#endif #endif
NODE_SHADER_MATERIALX_END NODE_SHADER_MATERIALX_END

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", NodeItem::Type::Float)); res.set_input("value", get_output_default("Value"));
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, NodeItem::Type::Any); return get_output_default(socket_out_->name);
} }
#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, NodeItem::Type::Float); return get_output_default(socket_out_->name);
} }
#endif #endif
NODE_SHADER_MATERIALX_END NODE_SHADER_MATERIALX_END