forked from blender/blender
MaterialX: add support for nodes #11
@ -148,18 +148,19 @@ if(WITH_MATERIALX)
|
||||
list(APPEND SRC
|
||||
materialx/material.cc
|
||||
materialx/nodes/bsdf_principled.cc
|
||||
materialx/nodes/invert.cc
|
||||
materialx/nodes/hueSatVal.cc
|
||||
DagerD marked this conversation as resolved
Outdated
|
||||
materialx/nodes/invert.cc
|
||||
materialx/nodes/math.cc
|
||||
materialx/nodes/mix_rgb.cc
|
||||
materialx/nodes/node_item.cc
|
||||
materialx/nodes/node_parser.cc
|
||||
materialx/nodes/normal_map.cc
|
||||
materialx/nodes/output_material.cc
|
||||
materialx/nodes/tex_image.cc
|
||||
materialx/nodes/tex_environment.cc
|
||||
materialx/nodes/tex_noise.cc
|
||||
materialx/nodes/sepcomb_xyz.cc
|
||||
materialx/nodes/tex_checker.cc
|
||||
materialx/nodes/tex_environment.cc
|
||||
materialx/nodes/tex_image.cc
|
||||
materialx/nodes/tex_noise.cc
|
||||
materialx/nodes/vector_math.cc
|
||||
|
||||
materialx/material.h
|
||||
|
@ -374,6 +374,75 @@ NodeItem NodeItem::exp() const
|
||||
return arithmetic("exp", [](float a) { return std::expf(a); });
|
||||
}
|
||||
|
||||
NodeItem NodeItem::separate(int index) const
|
||||
{
|
||||
NodeItem res = empty();
|
||||
std::string mx_type = type();
|
||||
if (value) {
|
||||
float v;
|
||||
if (mx_type == "float") {
|
||||
v = value->asA<float>();
|
||||
}
|
||||
else if (mx_type == "color3") {
|
||||
v = value->asA<MaterialX::Color3>()[index];
|
||||
}
|
||||
else if (mx_type == "color4") {
|
||||
v = value->asA<MaterialX::Color4>()[index];
|
||||
}
|
||||
else if (mx_type == "vector2") {
|
||||
v = value->asA<MaterialX::Vector2>()[index];
|
||||
}
|
||||
else if (mx_type == "vector3") {
|
||||
v = value->asA<MaterialX::Vector3>()[index];
|
||||
}
|
||||
else if (mx_type == "vector4") {
|
||||
v = value->asA<MaterialX::Vector4>()[index];
|
||||
}
|
||||
else {
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
res = val(v);
|
||||
}
|
||||
else {
|
||||
std::string node_name;
|
||||
if (mx_type == "float") {
|
||||
res = *this;
|
||||
}
|
||||
else if (mx_type == "vector2") {
|
||||
node_name = "separate2";
|
||||
}
|
||||
else if (mx_type == "vector3" || mx_type == "color3") {
|
||||
node_name = "separate3";
|
||||
}
|
||||
else if (mx_type == "vector4" || mx_type == "color4") {
|
||||
node_name = "separate4";
|
||||
}
|
||||
else {
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
res.node = graph_->addNode(node_name, MaterialX::EMPTY_STRING, "multioutput");
|
||||
bool is_color = STRPREFIX(mx_type.c_str(), "color");
|
||||
switch (index) {
|
||||
case 0:
|
||||
res.add_output(is_color ? "outr" : "outx", "float");
|
||||
break;
|
||||
case 1:
|
||||
res.add_output(is_color ? "outg" : "outy", "float");
|
||||
break;
|
||||
case 2:
|
||||
res.add_output(is_color ? "outb" : "outz", "float");
|
||||
break;
|
||||
case 3:
|
||||
res.add_output(is_color ? "outa" : "outw", "float");
|
||||
break;
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
res.set_input("in", *this);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
NodeItem NodeItem::to_color3() const
|
||||
{
|
||||
std::string mx_type = type();
|
||||
|
@ -72,6 +72,7 @@ class NodeItem {
|
||||
NodeItem sqrt() const;
|
||||
NodeItem sign() const;
|
||||
NodeItem exp() const;
|
||||
NodeItem separate(int index) const;
|
||||
|
||||
NodeItem to_color3() const;
|
||||
NodeItem to_vector3() const;
|
||||
|
@ -131,6 +131,7 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket)
|
||||
CASE_NODE_TYPE(SH_NODE_MATH, MathNodeParser)
|
||||
CASE_NODE_TYPE(SH_NODE_MIX_RGB_LEGACY, MixRGBNodeParser)
|
||||
CASE_NODE_TYPE(SH_NODE_NORMAL_MAP, NormalMapNodeParser)
|
||||
CASE_NODE_TYPE(SH_NODE_SEPXYZ, SeparateXYZNodeParser)
|
||||
CASE_NODE_TYPE(SH_NODE_TEX_CHECKER, TexCheckerNodeParser)
|
||||
CASE_NODE_TYPE(SH_NODE_TEX_ENVIRONMENT, TexEnvironmentNodeParser)
|
||||
CASE_NODE_TYPE(SH_NODE_TEX_IMAGE, TexImageNodeParser)
|
||||
|
@ -67,6 +67,7 @@ DECLARE_PARSER(InvertNodeParser)
|
||||
DECLARE_PARSER(MathNodeParser)
|
||||
DECLARE_PARSER(MixRGBNodeParser)
|
||||
DECLARE_PARSER(NormalMapNodeParser)
|
||||
DECLARE_PARSER(SeparateXYZNodeParser)
|
||||
DECLARE_PARSER(TexCheckerNodeParser)
|
||||
DECLARE_PARSER(TexEnvironmentNodeParser)
|
||||
DECLARE_PARSER(TexImageNodeParser)
|
||||
|
Loading…
Reference in New Issue
Block a user
hue_sat_val.cc