forked from blender/blender
Support group nodes #22
@ -45,6 +45,17 @@ NodeItem GroupNodeParser::compute()
|
||||
return res;
|
||||
}
|
||||
|
||||
NodeItem GroupNodeParser::compute_full()
|
||||
{
|
||||
CLOG_INFO(LOG_MATERIALX_SHADER,
|
||||
1,
|
||||
"%s [%d] => %s",
|
||||
node_->name,
|
||||
node_->typeinfo->type,
|
||||
NodeItem::type(to_type_).c_str());
|
||||
return compute();
|
||||
}
|
||||
|
||||
NodeItem GroupOutputNodeParser::compute()
|
||||
{
|
||||
#ifdef USE_MATERIALX_NODEGRAPH
|
||||
@ -98,7 +109,11 @@ NodeItem GroupOutputNodeParser::compute_full()
|
||||
NodeItem GroupInputNodeParser::compute()
|
||||
{
|
||||
#ifdef USE_MATERIALX_NODEGRAPH
|
||||
NodeItem value = group_parser_->get_input_value(socket_out_->index(), to_type_);
|
||||
NodeItem value = group_parser_->get_input_link(socket_out_->index(), to_type_);
|
||||
if (!value) {
|
||||
return empty();
|
||||
}
|
||||
|
||||
if (value.value) {
|
||||
NodeItem constant = create_node("constant", value.type());
|
||||
constant.set_input("value", value);
|
||||
@ -106,7 +121,7 @@ NodeItem GroupInputNodeParser::compute()
|
||||
}
|
||||
return create_input("input" + std::to_string(socket_out_->index() + 1), value);
|
||||
#else
|
||||
return group_parser_->get_input_value(socket_out_->index(), to_type_);
|
||||
return group_parser_->get_input_link(socket_out_->index(), to_type_);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
/* TODO: pxr::UsdMtlxRead() doesn't perform nodegraphs.
|
||||
* Uncomment USE_MATERIALX_NODEGRAPH after fixing it. */
|
||||
/* #define USE_MATERIALX_NODEGRAPH */
|
||||
#define USE_MATERIALX_NODEGRAPH
|
||||
|
||||
namespace blender::nodes::materialx {
|
||||
|
||||
@ -21,6 +21,7 @@ class GroupNodeParser : public NodeParser {
|
||||
public:
|
||||
using NodeParser::NodeParser;
|
||||
NodeItem compute() override;
|
||||
NodeItem compute_full() override;
|
||||
};
|
||||
|
||||
class GroupOutputNodeParser : public NodeParser {
|
||||
|
@ -105,7 +105,7 @@ bool NodeItem::is_arithmetic(Type type)
|
||||
|
||||
NodeItem::operator bool() const
|
||||
{
|
||||
return value || node || output;
|
||||
return value || node || input || output;
|
||||
}
|
||||
|
||||
NodeItem NodeItem::operator+(const NodeItem &other) const
|
||||
@ -808,10 +808,16 @@ NodeItem NodeItem::arithmetic(const std::string &category, std::function<float(f
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* TODO: Some of math functions (sin, cos, ...) doesn't work with Color types,
|
||||
* we have to convert to Vector */
|
||||
NodeItem v = *this;
|
||||
if (ELEM(type, Type::Color3, Type::Color4) &&
|
||||
ELEM(category, "sin", "cos", "tan", "asin", "acos", "atan2", "sqrt", "ln", "exp"))
|
||||
{
|
||||
/* Such fucntions doesn't have implementation in MaterialX, converting to Vector types */
|
||||
type = type == Type::Color3 ? Type::Vector3 : Type::Vector4;
|
||||
v = v.convert(type);
|
||||
}
|
||||
res = create_node(category, type);
|
||||
res.set_input("in", *this);
|
||||
res.set_input("in", v);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user