MaterialX: add support for nodes #11

Merged
Bogdan Nagirniak merged 17 commits from matx-add-other-nodes into matx-export-material 2023-09-06 10:37:26 +02:00
6 changed files with 55 additions and 2 deletions
Showing only changes of commit f319e437ff - Show all commits

View File

@ -156,6 +156,7 @@ if(WITH_MATERIALX)
materialx/nodes/node_parser.cc
materialx/nodes/normal_map.cc
materialx/nodes/output_material.cc
materialx/nodes/sepcomb_color.cc
materialx/nodes/sepcomb_xyz.cc
materialx/nodes/tex_checker.cc
materialx/nodes/tex_environment.cc

View File

@ -374,7 +374,7 @@ NodeItem NodeItem::exp() const
return arithmetic("exp", [](float a) { return std::expf(a); });
}
NodeItem NodeItem::separate(int index) const
NodeItem NodeItem::separate(const int index) const
{
NodeItem res = empty();
std::string mx_type = type();

View File

@ -72,7 +72,8 @@ class NodeItem {
NodeItem sqrt() const;
NodeItem sign() const;
NodeItem exp() const;
NodeItem separate(int index) const;
NodeItem separate(const int index) const;
NodeItem separate_color(const int index) const;
NodeItem to_color3() const;
NodeItem to_vector3() const;

View File

@ -126,12 +126,14 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket)
switch (from_node->typeinfo->type) {
CASE_NODE_TYPE(SH_NODE_BSDF_PRINCIPLED, BSDFPrincipledNodeParser)
CASE_NODE_TYPE(SH_NODE_COMBINE_COLOR, CombineColorNodeParser)
CASE_NODE_TYPE(SH_NODE_COMBXYZ, CombineXYZNodeParser)
CASE_NODE_TYPE(SH_NODE_HUE_SAT, HueSatValNodeParser)
CASE_NODE_TYPE(SH_NODE_INVERT, InvertNodeParser)
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_SEPARATE_COLOR, SeparateColorNodeParser)
CASE_NODE_TYPE(SH_NODE_SEPXYZ, SeparateXYZNodeParser)
CASE_NODE_TYPE(SH_NODE_TEX_CHECKER, TexCheckerNodeParser)
CASE_NODE_TYPE(SH_NODE_TEX_ENVIRONMENT, TexEnvironmentNodeParser)

View File

@ -62,12 +62,14 @@ template<class T> NodeItem NodeParser::value(const T &data) const
};
DECLARE_PARSER(BSDFPrincipledNodeParser)
DECLARE_PARSER(CombineColorNodeParser)
DECLARE_PARSER(CombineXYZNodeParser)
DECLARE_PARSER(HueSatValNodeParser)
DECLARE_PARSER(InvertNodeParser)
DECLARE_PARSER(MathNodeParser)
DECLARE_PARSER(MixRGBNodeParser)
DECLARE_PARSER(NormalMapNodeParser)
DECLARE_PARSER(SeparateColorNodeParser)
DECLARE_PARSER(SeparateXYZNodeParser)
DECLARE_PARSER(TexCheckerNodeParser)
DECLARE_PARSER(TexEnvironmentNodeParser)

View File

@ -0,0 +1,47 @@
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "node_parser.h"
namespace blender::nodes::materialx {
NodeItem SeparateColorNodeParser::compute()
{
int mode = static_cast<NodeCombSepColor *>(node_->storage)->mode;
NodeItem color = get_input_value("Color");
std::string channel_1;
std::string channel_2;
NodeItem convert = empty();
switch (mode) {
case NODE_COMBSEP_COLOR_RGB:
channel_1 = "Red";
channel_2 = "Green";
break;
case NODE_COMBSEP_COLOR_HSV:
case NODE_COMBSEP_COLOR_HSL:
channel_1 = "Hue";
channel_2 = "Saturation";
convert = create_node("rgbtohsv", "color3");
convert.set_input("in", color.to_color3());
break;
default:
BLI_assert_unreachable();
}
int index = STREQ(socket_out_->name, channel_1.c_str()) ? 0 :
STREQ(socket_out_->name, channel_2.c_str()) ? 1 :
2;
NodeItem res = convert ? convert : color;
return res.separate(index);
}
NodeItem CombineColorNodeParser::compute()
{
/* TODO: implement. */
}
} // namespace blender::nodes::materialx