forked from blender/blender
MaterialX: Implement export of Input nodes #20
@ -376,8 +376,6 @@ NodeItem NodeItem::convert(Type to_type) const
|
||||
switch (to_type) {
|
||||
case Type::Vector4:
|
||||
return convert(Type::Vector3).convert(Type::Vector4);
|
||||
case Type::Vector3:
|
||||
return convert(Type::Vector3);
|
||||
case Type::Color3:
|
||||
return convert(Type::Vector3).convert(Type::Color3);
|
||||
case Type::Color4:
|
||||
@ -390,20 +388,12 @@ NodeItem NodeItem::convert(Type to_type) const
|
||||
switch (to_type) {
|
||||
case 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:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Type::Vector4:
|
||||
switch (to_type) {
|
||||
case Type::Vector3:
|
||||
return convert(Type::Vector3);
|
||||
case Type::Vector2:
|
||||
return convert(Type::Vector3).convert(Type::Vector2);
|
||||
case Type::Color3:
|
||||
@ -418,8 +408,6 @@ NodeItem NodeItem::convert(Type to_type) const
|
||||
return convert(Type::Vector3).convert(Type::Vector2);
|
||||
case Type::Vector4:
|
||||
return convert(Type::Vector3).convert(Type::Vector4);
|
||||
case Type::Vector3:
|
||||
return convert(Type::Vector3);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
@ -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);
|
||||
}
|
||||
|
||||
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
|
||||
@ -116,19 +116,18 @@ NodeItem NodeParser::empty() const
|
||||
return NodeItem(graph_);
|
||||
}
|
||||
|
||||
NodeItem NodeParser::texcoord_node(NodeItem::Type data_type)
|
||||
NodeItem NodeParser::texcoord_node()
|
||||
{
|
||||
NodeItem res = empty();
|
||||
std::string name = TEXCOORD_NODE_NAME + "_" + NodeItem::type(data_type);
|
||||
res.node = graph_->getNode(name);
|
||||
res.node = graph_->getNode(TEXCOORD_NODE_NAME);
|
||||
if (!res.node) {
|
||||
res = create_node("texcoord", data_type);
|
||||
res.node->setName(name);
|
||||
res = create_node("texcoord", NodeItem::Type::Vector2);
|
||||
res.node->setName(TEXCOORD_NODE_NAME);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
NodeItem NodeParser::get_default(const bNodeSocket &socket, NodeItem::Type to_type)
|
||||
NodeItem NodeParser::get_default(const bNodeSocket &socket)
|
||||
{
|
||||
NodeItem res = empty();
|
||||
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);
|
||||
}
|
||||
}
|
||||
return res.convert(to_type);
|
||||
return res;
|
||||
}
|
||||
|
||||
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);
|
||||
if (!res) {
|
||||
res = get_default(socket, to_type);
|
||||
res = get_default(socket).convert(to_type);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -42,18 +42,18 @@ class NodeParser {
|
||||
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(int index, NodeItem::Type to_type);
|
||||
NodeItem get_output_default(const std::string &name, NodeItem::Type to_type);
|
||||
NodeItem get_output_default(int index, NodeItem::Type to_type);
|
||||
NodeItem get_output_default(const std::string &name);
|
||||
NodeItem get_output_default(int index);
|
||||
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_value(const std::string &name, NodeItem::Type to_type);
|
||||
NodeItem get_input_value(int index, NodeItem::Type to_type);
|
||||
NodeItem empty() const;
|
||||
template<class T> NodeItem val(const T &data) const;
|
||||
NodeItem texcoord_node(NodeItem::Type data_type = NodeItem::Type::Vector2);
|
||||
NodeItem texcoord_node();
|
||||
|
||||
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_value(const bNodeSocket &socket, NodeItem::Type to_type);
|
||||
};
|
||||
|
@ -65,7 +65,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
* res.set_input("coneangle", val(90.0f));
|
||||
* res.set_input("maxdistance", maxdistance);
|
||||
*/
|
||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
Review
```
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
|
||||
NODE_SHADER_MATERIALX_END
|
||||
|
@ -83,7 +83,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
/* TODO: some outputs expected be implemented within the next iteration (see nodedef
|
||||
* <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
|
||||
NODE_SHADER_MATERIALX_END
|
||||
|
@ -30,7 +30,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
#ifdef WITH_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
|
||||
NODE_SHADER_MATERIALX_END
|
||||
|
@ -78,7 +78,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
res.set_input("space", val(std::string("world")));
|
||||
}
|
||||
else {
|
||||
res = get_output_default(name, NodeItem::Type::Any);
|
||||
res = get_output_default(name);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
#ifdef WITH_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
|
||||
NODE_SHADER_MATERIALX_END
|
||||
|
@ -51,7 +51,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
* res.set_input("seed", val(0));
|
||||
*}*/
|
||||
else {
|
||||
res = get_output_default(name, NodeItem::Type::Any);
|
||||
res = get_output_default(name);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
#ifdef WITH_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
|
||||
NODE_SHADER_MATERIALX_END
|
||||
|
@ -26,7 +26,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
#ifdef WITH_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
|
||||
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
|
||||
{
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
|
@ -90,7 +90,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
#ifdef WITH_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
|
||||
NODE_SHADER_MATERIALX_END
|
||||
|
@ -79,7 +79,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
std::string name = socket_out_->name;
|
||||
|
||||
if (ELEM(name, "Generated", "UV")) {
|
||||
res = texcoord_node(NodeItem::Type::Vector3);
|
||||
res = texcoord_node();
|
||||
}
|
||||
else if (name == "Normal") {
|
||||
res = create_node("normal", NodeItem::Type::Vector3);
|
||||
@ -90,7 +90,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
res.set_input("space", val(std::string("world")));
|
||||
}
|
||||
else {
|
||||
res = get_output_default(name, NodeItem::Type::Any);
|
||||
res = get_output_default(name);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -73,7 +73,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
/* NODE: "From Instances" not implemented
|
||||
* UV selection not implemented
|
||||
*/
|
||||
return texcoord_node(NodeItem::Type::Vector3);
|
||||
return texcoord_node();
|
||||
}
|
||||
#endif
|
||||
NODE_SHADER_MATERIALX_END
|
||||
|
@ -42,7 +42,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
#ifdef WITH_MATERIALX
|
||||
{
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
|
@ -72,7 +72,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
{
|
||||
/* TODO: some output expected be implemented within the next iteration (see nodedef
|
||||
* <geomcolor>)*/
|
||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
start from empty() start from empty()
|
||||
return get_output_default(socket_out_->name, NodeItem::Type::Any);
|
||||
return get_output_default(socket_out_->name);
|
||||
}
|
||||
#endif
|
||||
NODE_SHADER_MATERIALX_END
|
||||
|
@ -44,7 +44,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
#ifdef WITH_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
|
||||
NODE_SHADER_MATERIALX_END
|
||||
|
Loading…
Reference in New Issue
Block a user