forked from blender/blender
MaterialX: Implement export of Input nodes #20
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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
|
|||||||
};
|
};
|
||||||
|
@ -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
Bogdan Nagirniak
commented
```
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
|
||||||
|
@ -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
Bogdan Nagirniak
commented
Start with 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
Bogdan Nagirniak
commented
`else if`
|
|||||||
|
@ -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
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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
Bogdan Nagirniak
commented
use use `std::string name = socket_out_->name` and `ELEM(name, ....)`
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
NODE_SHADER_MATERIALX_END
|
NODE_SHADER_MATERIALX_END
|
||||||
|
@ -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
Bogdan Nagirniak
commented
I think I think `return get_output_default` can be used here
|
|||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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;
|
||||||
|
@ -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
|
||||||
|
@ -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
Bogdan Nagirniak
commented
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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user
use one function here instead of 3
get_default(const bNodeSocket &socket, NodeItem::Type to_type)