forked from blender/blender
Create parsing system that converts supported nodes and ignores unsupported #2
@ -11,26 +11,28 @@
|
|||||||
|
|
||||||
namespace blender::nodes::materialx {
|
namespace blender::nodes::materialx {
|
||||||
|
|
||||||
static void export_nodegraph(MaterialX::DocumentPtr doc, Depsgraph *depsgraph, Material *material)
|
static void export_nodegraph(MaterialX::GraphElement *graph,
|
||||||
|
Depsgraph *depsgraph,
|
||||||
|
Material *material)
|
||||||
{
|
{
|
||||||
material->nodetree->ensure_topology_cache();
|
material->nodetree->ensure_topology_cache();
|
||||||
|
|
||||||
bNode *output_node = ntreeShaderOutputNode(material->nodetree, SHD_OUTPUT_ALL);
|
bNode *output_node = ntreeShaderOutputNode(material->nodetree, SHD_OUTPUT_ALL);
|
||||||
OutputMaterialNodeParser material_node(doc, depsgraph, material, output_node);
|
OutputMaterialNodeParser parser(graph, depsgraph, material, output_node);
|
||||||
material_node.compute();
|
parser.compute();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void create_standard_surface(MaterialX::DocumentPtr doc, Material *material)
|
static void create_standard_surface(MaterialX::GraphElement *graph, Material *material)
|
||||||
{
|
{
|
||||||
MaterialX::NodePtr surfacematerial = doc->addNode(
|
MaterialX::NodePtr standard_surface = graph->addNode(
|
||||||
"surfacematerial", MaterialX::EMPTY_STRING, "material");
|
|
||||||
MaterialX::NodePtr standard_surface = doc->addNode(
|
|
||||||
"standard_surface", MaterialX::EMPTY_STRING, "surfaceshader");
|
"standard_surface", MaterialX::EMPTY_STRING, "surfaceshader");
|
||||||
|
|
||||||
standard_surface->addInput("base", "float")->setValue(1.0);
|
standard_surface->addInput("base", "float")->setValue(1.0);
|
||||||
standard_surface->addInput("base_color", "color3")
|
standard_surface->addInput("base_color", "color3")
|
||||||
->setValue(MaterialX::Color3(material->r, material->g, material->b));
|
->setValue(MaterialX::Color3(material->r, material->g, material->b));
|
||||||
|
|
||||||
|
MaterialX::NodePtr surfacematerial = graph->addNode(
|
||||||
|
"surfacematerial", MaterialX::EMPTY_STRING, "material");
|
||||||
surfacematerial->addInput(standard_surface->getType(), standard_surface->getType())
|
surfacematerial->addInput(standard_surface->getType(), standard_surface->getType())
|
||||||
->setNodeName(standard_surface->getName());
|
->setNodeName(standard_surface->getName());
|
||||||
}
|
}
|
||||||
@ -39,10 +41,10 @@ MaterialX::DocumentPtr export_to_materialx(Depsgraph *depsgraph, Material *mater
|
|||||||
{
|
{
|
||||||
MaterialX::DocumentPtr doc = MaterialX::createDocument();
|
MaterialX::DocumentPtr doc = MaterialX::createDocument();
|
||||||
if (material->use_nodes) {
|
if (material->use_nodes) {
|
||||||
export_nodegraph(doc, depsgraph, material);
|
export_nodegraph(doc.get(), depsgraph, material);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
create_standard_surface(doc, material);
|
create_standard_surface(doc.get(), material);
|
||||||
}
|
}
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,5 @@
|
|||||||
namespace blender::nodes::materialx {
|
namespace blender::nodes::materialx {
|
||||||
|
|
||||||
MaterialX::DocumentPtr export_to_materialx(Depsgraph *depsgraph, Material *material);
|
MaterialX::DocumentPtr export_to_materialx(Depsgraph *depsgraph, Material *material);
|
||||||
static void create_standard_surface(MaterialX::DocumentPtr doc, Material *material);
|
|
||||||
static void export_nodegraph(MaterialX::DocumentPtr doc, Depsgraph *depsgraph, Material *material);
|
|
||||||
|
|
||||||
} // namespace blender::nodes::materialx
|
} // namespace blender::nodes::materialx
|
||||||
|
@ -10,117 +10,246 @@ namespace blender::nodes::materialx {
|
|||||||
|
|
||||||
NodeItem BSDFPrincipledNodeParser::compute()
|
NodeItem BSDFPrincipledNodeParser::compute()
|
||||||
{
|
{
|
||||||
NodeItem node = create_node("standard_surface", "surfaceshader");
|
auto enabled = [](NodeItem &val) -> bool
|
||||||
|
{
|
||||||
|
if (val.node) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!val.value) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (val.value->isA<float>()) {
|
||||||
|
return val.value->asA<float>() != 0.0f;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
MaterialX::Color3 default_white_color = MaterialX::Color3(1.0, 1.0, 1.0);
|
/* Getting required inputs
|
||||||
#pragma region get inputs
|
* Note: if some inputs are not needed they won't be taken */
|
||||||
const bNodeSocket base_color_socket = node->input_by_identifier("Base Color");
|
NodeItem base_color = get_input_value("Base Color");
|
||||||
const char *matx_input = "base_color";
|
|
||||||
if (base_color_socket.link) {
|
NodeItem subsurface = get_input_value("Subsurface");
|
||||||
get_input_link_node(&base_color_socket, matx_node, matx_input);
|
NodeItem subsurface_radius = empty_value();
|
||||||
}
|
NodeItem subsurface_color = empty_value();
|
||||||
else {
|
if (enabled(subsurface)) {
|
||||||
const float *base_color = base_color_socket.default_value_typed<bNodeSocketValueRGBA>()->value;
|
subsurface_radius = get_input_value("Subsurface Radius");
|
||||||
matx_node->addInput("base_color", "color3")
|
subsurface_color = get_input_value("Subsurface Color");
|
||||||
->setValue(MaterialX::Color3(base_color[0], base_color[1], base_color[2]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const float *base_color =
|
NodeItem metallic = get_input_value("Metallic");
|
||||||
node->input_by_identifier("Base Color").default_value_typed<bNodeSocketValueRGBA>()->value;
|
NodeItem specular = get_input_value("Specular");
|
||||||
const float subsurface =
|
// NodeItem specular_tint = get_input_value("Specular Tint");
|
||||||
node->input_by_identifier("Subsurface").default_value_typed<bNodeSocketValueFloat>()->value;
|
NodeItem roughness = get_input_value("Roughness");
|
||||||
|
|
||||||
const float *subsurface_radius = node->input_by_identifier("Subsurface Radius")
|
NodeItem anisotropic = empty_value();
|
||||||
.default_value_typed<bNodeSocketValueVector>()
|
NodeItem anisotropic_rotation = empty_value();
|
||||||
->value;
|
if (enabled(metallic)) {
|
||||||
const float *subsurface_color = node->input_by_identifier("Subsurface Color")
|
/* TODO: use Specular Tint input */
|
||||||
.default_value_typed<bNodeSocketValueRGBA>()
|
anisotropic = get_input_value("Anisotropic");
|
||||||
->value;
|
if (enabled(anisotropic)) {
|
||||||
const float metallic =
|
anisotropic_rotation = get_input_value("Anisotropic Rotation");
|
||||||
node->input_by_identifier("Metallic").default_value_typed<bNodeSocketValueFloat>()->value;
|
// anisotropic_rotation = 0.5 - (anisotropic_rotation % 1.0)
|
||||||
const float specular =
|
}
|
||||||
node->input_by_identifier("Specular").default_value_typed<bNodeSocketValueFloat>()->value;
|
}
|
||||||
const float roughness =
|
|
||||||
node->input_by_identifier("Roughness").default_value_typed<bNodeSocketValueFloat>()->value;
|
|
||||||
const float anisotropic =
|
|
||||||
node->input_by_identifier("Anisotropic").default_value_typed<bNodeSocketValueFloat>()->value;
|
|
||||||
const float anisotropic_rot = node->input_by_identifier("Anisotropic Rotation")
|
|
||||||
.default_value_typed<bNodeSocketValueFloat>()
|
|
||||||
->value;
|
|
||||||
const float sheen =
|
|
||||||
node->input_by_identifier("Sheen").default_value_typed<bNodeSocketValueFloat>()->value;
|
|
||||||
const float clearcoat =
|
|
||||||
node->input_by_identifier("Clearcoat").default_value_typed<bNodeSocketValueFloat>()->value;
|
|
||||||
const float clearcoat_roughness = node->input_by_identifier("Clearcoat Roughness")
|
|
||||||
.default_value_typed<bNodeSocketValueFloat>()
|
|
||||||
->value;
|
|
||||||
const float IOR =
|
|
||||||
node->input_by_identifier("IOR").default_value_typed<bNodeSocketValueFloat>()->value;
|
|
||||||
const float transmission = node->input_by_identifier("Transmission")
|
|
||||||
.default_value_typed<bNodeSocketValueFloat>()
|
|
||||||
->value;
|
|
||||||
const float *emission =
|
|
||||||
node->input_by_identifier("Emission").default_value_typed<bNodeSocketValueRGBA>()->value;
|
|
||||||
const float emission_str = node->input_by_identifier("Emission Strength")
|
|
||||||
.default_value_typed<bNodeSocketValueFloat>()
|
|
||||||
->value;
|
|
||||||
const float *normal =
|
|
||||||
node->input_by_identifier("Normal").default_value_typed<bNodeSocketValueVector>()->value;
|
|
||||||
const float *clearcoat_normal = node->input_by_identifier("Clearcoat Normal")
|
|
||||||
.default_value_typed<bNodeSocketValueVector>()
|
|
||||||
->value;
|
|
||||||
const float *tangent =
|
|
||||||
node->input_by_identifier("Tangent").default_value_typed<bNodeSocketValueVector>()->value;
|
|
||||||
#pragma endregion get inputs
|
|
||||||
|
|
||||||
#pragma region set inputs
|
NodeItem sheen = get_input_value("Sheen");
|
||||||
matx_node->addInput("base", "float")->setValue(1.0);
|
// sheen_tint = empty_value();
|
||||||
matx_node->addInput("diffuse_roughness", "float")->setValue(roughness);
|
// if enabled(sheen):
|
||||||
matx_node->addInput("normal", "vector3")
|
// sheen_tint = get_input_value("Sheen Tint");
|
||||||
->setValue(MaterialX::Vector3(normal[0], normal[1], normal[2]));
|
|
||||||
matx_node->addInput("tangent", "vector3")
|
|
||||||
->setValue(MaterialX::Vector3(tangent[0], tangent[1], tangent[2]));
|
|
||||||
|
|
||||||
matx_node->addInput("metalness", "float")->setValue(metallic);
|
NodeItem clearcoat = get_input_value("Clearcoat");
|
||||||
|
NodeItem clearcoat_roughness = empty_value();
|
||||||
|
if (enabled(clearcoat)) {
|
||||||
|
clearcoat_roughness = get_input_value("Clearcoat Roughness");
|
||||||
|
}
|
||||||
|
|
||||||
matx_node->addInput("specular", "float")->setValue(specular);
|
NodeItem ior = get_input_value("IOR");
|
||||||
matx_node->addInput("specular_color", "color3")->setValue(default_white_color);
|
|
||||||
matx_node->addInput("specular_roughness", "float")->setValue(roughness);
|
|
||||||
matx_node->addInput("specular_IOR", "float")->setValue(IOR);
|
|
||||||
matx_node->addInput("specular_anisotropy", "float")->setValue(anisotropic);
|
|
||||||
matx_node->addInput("specular_rotation", "float")->setValue(anisotropic_rot);
|
|
||||||
|
|
||||||
matx_node->addInput("transmission", "float")->setValue(transmission);
|
NodeItem transmission = get_input_value("Transmission");
|
||||||
matx_node->addInput("transmission_color", "color3")->setValue(default_white_color);
|
NodeItem transmission_roughness = empty_value();
|
||||||
matx_node->addInput("transmission_extra_roughness", "float")->setValue(roughness);
|
if (enabled(transmission)) {
|
||||||
|
transmission_roughness = get_input_value("Transmission Roughness");
|
||||||
|
}
|
||||||
|
|
||||||
matx_node->addInput("subsurface", "float")->setValue(subsurface);
|
NodeItem emission = get_input_value("Emission");
|
||||||
matx_node->addInput("subsurface_color", "color3")
|
NodeItem emission_strength = get_input_value("Emission Strength");
|
||||||
->setValue(MaterialX::Color3(subsurface_color[0], subsurface_color[1], subsurface_color[2]));
|
|
||||||
matx_node->addInput("subsurface_radius", "color3")
|
|
||||||
->setValue(
|
|
||||||
MaterialX::Color3(subsurface_radius[0], subsurface_radius[1], subsurface_radius[2]));
|
|
||||||
matx_node->addInput("subsurface_anisotropy", "float")->setValue(anisotropic);
|
|
||||||
|
|
||||||
matx_node->addInput("sheen", "float")->setValue(sheen);
|
NodeItem alpha = get_input_value("Alpha");
|
||||||
matx_node->addInput("sheen_color", "color3")->setValue(default_white_color);
|
// transparency = 1.0 - alpha
|
||||||
matx_node->addInput("sheen_roughness", "float")->setValue(roughness);
|
|
||||||
|
|
||||||
matx_node->addInput("coat", "float")->setValue(clearcoat);
|
NodeItem normal = get_input_link("Normal");
|
||||||
matx_node->addInput("coat_color", "color3")->setValue(default_white_color);
|
NodeItem clearcoat_normal = get_input_link("Clearcoat Normal");
|
||||||
matx_node->addInput("coat_roughness", "float")->setValue(clearcoat_roughness);
|
NodeItem tangent = get_input_link("Tangent");
|
||||||
matx_node->addInput("coat_IOR", "float")->setValue(IOR);
|
|
||||||
matx_node->addInput("coat_anisotropy", "float")->setValue(anisotropic);
|
|
||||||
matx_node->addInput("coat_rotation", "float")->setValue(anisotropic_rot);
|
|
||||||
matx_node->addInput("coat_normal", "vector3")
|
|
||||||
->setValue(
|
|
||||||
MaterialX::Vector3(clearcoat_normal[0], clearcoat_normal[1], clearcoat_normal[2]));
|
|
||||||
|
|
||||||
matx_node->addInput("emission", "float")->setValue(emission_str);
|
/* Creating standard_surface */
|
||||||
matx_node->addInput("emission_color", "color3")
|
NodeItem res = create_node("standard_surface", "surfaceshader");
|
||||||
->setValue(MaterialX::Color3(emission[0], emission[1], emission[2]));
|
res.set_input("base", 1.0, "float");
|
||||||
#pragma endregion set inputs
|
res.set_input("base_color", base_color);
|
||||||
return matx_node;
|
res.set_input("diffuse_roughness", roughness);
|
||||||
|
res.set_input("normal", normal);
|
||||||
|
res.set_input("tangent", tangent);
|
||||||
|
|
||||||
|
if (enabled(metallic)) {
|
||||||
|
res.set_input("metalness", metallic);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enabled(specular)) {
|
||||||
|
res.set_input("specular", specular);
|
||||||
|
res.set_input("specular_color", base_color);
|
||||||
|
res.set_input("specular_roughness", roughness);
|
||||||
|
res.set_input("specular_IOR", ior);
|
||||||
|
res.set_input("specular_anisotropy", anisotropic);
|
||||||
|
res.set_input("specular_rotation", anisotropic_rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enabled(transmission)) {
|
||||||
|
res.set_input("transmission", transmission);
|
||||||
|
res.set_input("transmission_color", base_color);
|
||||||
|
res.set_input("transmission_extra_roughness", transmission_roughness);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enabled(subsurface)) {
|
||||||
|
res.set_input("subsurface", subsurface);
|
||||||
|
res.set_input("subsurface_color", subsurface_color);
|
||||||
|
res.set_input("subsurface_radius", subsurface_radius);
|
||||||
|
res.set_input("subsurface_anisotropy", anisotropic);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enabled(sheen)) {
|
||||||
|
res.set_input("sheen", sheen);
|
||||||
|
res.set_input("sheen_color", base_color);
|
||||||
|
res.set_input("sheen_roughness", roughness);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enabled(clearcoat)) {
|
||||||
|
res.set_input("coat", clearcoat);
|
||||||
|
res.set_input("coat_color", base_color);
|
||||||
|
res.set_input("coat_roughness", clearcoat_roughness);
|
||||||
|
res.set_input("coat_IOR", ior);
|
||||||
|
res.set_input("coat_anisotropy", anisotropic);
|
||||||
|
res.set_input("coat_rotation", anisotropic_rotation);
|
||||||
|
res.set_input("coat_normal", clearcoat_normal);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enabled(emission)) {
|
||||||
|
res.set_input("emission", emission_strength);
|
||||||
|
res.set_input("emission_color", emission);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// MaterialX::Color3 default_white_color = MaterialX::Color3(1.0, 1.0, 1.0);
|
||||||
|
//#pragma region get inputs
|
||||||
|
// const bNodeSocket base_color_socket = res->input_by_identifier("Base Color");
|
||||||
|
// const char *matx_input = "base_color";
|
||||||
|
// if (base_color_socket.link) {
|
||||||
|
// get_input_link_node(&base_color_socket, matx_node, matx_input);
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// const float *base_color = base_color_socket.default_value_typed<bNodeSocketValueRGBA>()->value;
|
||||||
|
// matx_node->addInput("base_color", "color3")
|
||||||
|
// ->setValue(MaterialX::Color3(base_color[0], base_color[1], base_color[2]));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// const float *base_color =
|
||||||
|
// res->input_by_identifier("Base Color").default_value_typed<bNodeSocketValueRGBA>()->value;
|
||||||
|
// const float subsurface =
|
||||||
|
// res->input_by_identifier("Subsurface").default_value_typed<bNodeSocketValueFloat>()->value;
|
||||||
|
//
|
||||||
|
// const float *subsurface_radius = res->input_by_identifier("Subsurface Radius")
|
||||||
|
// .default_value_typed<bNodeSocketValueVector>()
|
||||||
|
// ->value;
|
||||||
|
// const float *subsurface_color = res->input_by_identifier("Subsurface Color")
|
||||||
|
// .default_value_typed<bNodeSocketValueRGBA>()
|
||||||
|
// ->value;
|
||||||
|
// const float metallic =
|
||||||
|
// res->input_by_identifier("Metallic").default_value_typed<bNodeSocketValueFloat>()->value;
|
||||||
|
// const float specular =
|
||||||
|
// res->input_by_identifier("Specular").default_value_typed<bNodeSocketValueFloat>()->value;
|
||||||
|
// const float roughness =
|
||||||
|
// res->input_by_identifier("Roughness").default_value_typed<bNodeSocketValueFloat>()->value;
|
||||||
|
// const float anisotropic =
|
||||||
|
// res->input_by_identifier("Anisotropic").default_value_typed<bNodeSocketValueFloat>()->value;
|
||||||
|
// const float anisotropic_rot = res->input_by_identifier("Anisotropic Rotation")
|
||||||
|
// .default_value_typed<bNodeSocketValueFloat>()
|
||||||
|
// ->value;
|
||||||
|
// const float sheen =
|
||||||
|
// res->input_by_identifier("Sheen").default_value_typed<bNodeSocketValueFloat>()->value;
|
||||||
|
// const float clearcoat =
|
||||||
|
// res->input_by_identifier("Clearcoat").default_value_typed<bNodeSocketValueFloat>()->value;
|
||||||
|
// const float clearcoat_roughness = res->input_by_identifier("Clearcoat Roughness")
|
||||||
|
// .default_value_typed<bNodeSocketValueFloat>()
|
||||||
|
// ->value;
|
||||||
|
// const float IOR =
|
||||||
|
// res->input_by_identifier("IOR").default_value_typed<bNodeSocketValueFloat>()->value;
|
||||||
|
// const float transmission = res->input_by_identifier("Transmission")
|
||||||
|
// .default_value_typed<bNodeSocketValueFloat>()
|
||||||
|
// ->value;
|
||||||
|
// const float *emission =
|
||||||
|
// res->input_by_identifier("Emission").default_value_typed<bNodeSocketValueRGBA>()->value;
|
||||||
|
// const float emission_str = res->input_by_identifier("Emission Strength")
|
||||||
|
// .default_value_typed<bNodeSocketValueFloat>()
|
||||||
|
// ->value;
|
||||||
|
// const float *normal =
|
||||||
|
// res->input_by_identifier("Normal").default_value_typed<bNodeSocketValueVector>()->value;
|
||||||
|
// const float *clearcoat_normal = res->input_by_identifier("Clearcoat Normal")
|
||||||
|
// .default_value_typed<bNodeSocketValueVector>()
|
||||||
|
// ->value;
|
||||||
|
// const float *tangent =
|
||||||
|
// res->input_by_identifier("Tangent").default_value_typed<bNodeSocketValueVector>()->value;
|
||||||
|
//#pragma endregion get inputs
|
||||||
|
//
|
||||||
|
//#pragma region set inputs
|
||||||
|
// matx_node->addInput("base", "float")->setValue(1.0);
|
||||||
|
// matx_node->addInput("diffuse_roughness", "float")->setValue(roughness);
|
||||||
|
// matx_node->addInput("normal", "vector3")
|
||||||
|
// ->setValue(MaterialX::Vector3(normal[0], normal[1], normal[2]));
|
||||||
|
// matx_node->addInput("tangent", "vector3")
|
||||||
|
// ->setValue(MaterialX::Vector3(tangent[0], tangent[1], tangent[2]));
|
||||||
|
//
|
||||||
|
// matx_node->addInput("metalness", "float")->setValue(metallic);
|
||||||
|
//
|
||||||
|
// matx_node->addInput("specular", "float")->setValue(specular);
|
||||||
|
// matx_node->addInput("specular_color", "color3")->setValue(default_white_color);
|
||||||
|
// matx_node->addInput("specular_roughness", "float")->setValue(roughness);
|
||||||
|
// matx_node->addInput("specular_IOR", "float")->setValue(IOR);
|
||||||
|
// matx_node->addInput("specular_anisotropy", "float")->setValue(anisotropic);
|
||||||
|
// matx_node->addInput("specular_rotation", "float")->setValue(anisotropic_rot);
|
||||||
|
//
|
||||||
|
// matx_node->addInput("transmission", "float")->setValue(transmission);
|
||||||
|
// matx_node->addInput("transmission_color", "color3")->setValue(default_white_color);
|
||||||
|
// matx_node->addInput("transmission_extra_roughness", "float")->setValue(roughness);
|
||||||
|
//
|
||||||
|
// matx_node->addInput("subsurface", "float")->setValue(subsurface);
|
||||||
|
// matx_node->addInput("subsurface_color", "color3")
|
||||||
|
// ->setValue(MaterialX::Color3(subsurface_color[0], subsurface_color[1], subsurface_color[2]));
|
||||||
|
// matx_node->addInput("subsurface_radius", "color3")
|
||||||
|
// ->setValue(
|
||||||
|
// MaterialX::Color3(subsurface_radius[0], subsurface_radius[1], subsurface_radius[2]));
|
||||||
|
// matx_node->addInput("subsurface_anisotropy", "float")->setValue(anisotropic);
|
||||||
|
//
|
||||||
|
// matx_node->addInput("sheen", "float")->setValue(sheen);
|
||||||
|
// matx_node->addInput("sheen_color", "color3")->setValue(default_white_color);
|
||||||
|
// matx_node->addInput("sheen_roughness", "float")->setValue(roughness);
|
||||||
|
//
|
||||||
|
// matx_node->addInput("coat", "float")->setValue(clearcoat);
|
||||||
|
// matx_node->addInput("coat_color", "color3")->setValue(default_white_color);
|
||||||
|
// matx_node->addInput("coat_roughness", "float")->setValue(clearcoat_roughness);
|
||||||
|
// matx_node->addInput("coat_IOR", "float")->setValue(IOR);
|
||||||
|
// matx_node->addInput("coat_anisotropy", "float")->setValue(anisotropic);
|
||||||
|
// matx_node->addInput("coat_rotation", "float")->setValue(anisotropic_rot);
|
||||||
|
// matx_node->addInput("coat_normal", "vector3")
|
||||||
|
// ->setValue(
|
||||||
|
// MaterialX::Vector3(clearcoat_normal[0], clearcoat_normal[1], clearcoat_normal[2]));
|
||||||
|
//
|
||||||
|
// matx_node->addInput("emission", "float")->setValue(emission_str);
|
||||||
|
// matx_node->addInput("emission_color", "color3")
|
||||||
|
// ->setValue(MaterialX::Color3(emission[0], emission[1], emission[2]));
|
||||||
|
//#pragma endregion set inputs
|
||||||
|
// return matx_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::nodes::materialx
|
} // namespace blender::nodes::materialx
|
||||||
|
@ -16,13 +16,13 @@ NodeItem::NodeItem(MaterialX::GraphElement *graph)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeItem::set_input(const std::string &name, const NodeItem &item)
|
void NodeItem::set_input(const std::string &name, const NodeItem &res)
|
||||||
{
|
{
|
||||||
if (item.value) {
|
if (res.value) {
|
||||||
set_input(name, item.value);
|
set_input(name, res.value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
set_input(name, item.node);
|
set_input(name, res.node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,47 +66,51 @@ NodeParser::NodeParser(MaterialX::GraphElement *graph,
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeItem NodeParser::create_node(const std::string &mx_category, const std::string &mx_type)
|
NodeItem NodeParser::create_node(const std::string &mx_category, const std::string &mx_type, bool accessory)
|
||||||
{
|
{
|
||||||
NodeItem item(graph);
|
NodeItem res = empty_value();
|
||||||
item.node = graph->addNode(mx_category, MaterialX::createValidName(node->name), mx_type);
|
res.node = graph->addNode(mx_category,
|
||||||
return item;
|
accessory ? MaterialX::EMPTY_STRING :
|
||||||
|
MaterialX::createValidName(node->name),
|
||||||
|
mx_type);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeItem NodeParser::get_input_default(const std::string &name)
|
NodeItem NodeParser::get_input_default(const std::string &name)
|
||||||
{
|
{
|
||||||
|
NodeItem res = empty_value();
|
||||||
|
|
||||||
const bNodeSocket &socket = node->input_by_identifier(name);
|
const bNodeSocket &socket = node->input_by_identifier(name);
|
||||||
NodeItem item(graph);
|
|
||||||
switch (socket.type) {
|
switch (socket.type) {
|
||||||
case SOCK_FLOAT: {
|
case SOCK_FLOAT: {
|
||||||
float v = socket.default_value_typed<bNodeSocketValueFloat>()->value;
|
float v = socket.default_value_typed<bNodeSocketValueFloat>()->value;
|
||||||
item.value = MaterialX::Value::createValue<float>(v);
|
res.value = MaterialX::Value::createValue<float>(v);
|
||||||
} break;
|
} break;
|
||||||
case SOCK_VECTOR: {
|
case SOCK_VECTOR: {
|
||||||
const float *v = socket.default_value_typed<bNodeSocketValueVector>()->value;
|
const float *v = socket.default_value_typed<bNodeSocketValueVector>()->value;
|
||||||
item.value = MaterialX::Value::createValue<MaterialX::Vector3>(
|
res.value = MaterialX::Value::createValue<MaterialX::Vector3>(
|
||||||
MaterialX::Vector3(v[0], v[1], v[2]));
|
MaterialX::Vector3(v[0], v[1], v[2]));
|
||||||
} break;
|
} break;
|
||||||
case SOCK_RGBA: {
|
case SOCK_RGBA: {
|
||||||
const float *v = socket.default_value_typed<bNodeSocketValueRGBA>()->value;
|
const float *v = socket.default_value_typed<bNodeSocketValueRGBA>()->value;
|
||||||
item.value = MaterialX::Value::createValue<MaterialX::Color4>(
|
res.value = MaterialX::Value::createValue<MaterialX::Color4>(
|
||||||
MaterialX::Color4(v[0], v[1], v[2], v[3]));
|
MaterialX::Color4(v[0], v[1], v[2], v[3]));
|
||||||
} break;
|
} break;
|
||||||
default: {
|
default: {
|
||||||
// TODO log warn
|
// TODO log warn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return item;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NodeItem NodeParser::get_input_link(const std::string &name)
|
NodeItem NodeParser::get_input_link(const std::string &name)
|
||||||
{
|
{
|
||||||
NodeItem item(graph);
|
NodeItem res = empty_value();
|
||||||
|
|
||||||
const bNodeLink *link = node->input_by_identifier(name).link;
|
const bNodeLink *link = node->input_by_identifier(name).link;
|
||||||
if (!link->is_used()) {
|
if (!link->is_used()) {
|
||||||
return item;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bNode *in_node = link->fromnode;
|
const bNode *in_node = link->fromnode;
|
||||||
@ -115,7 +119,7 @@ NodeItem NodeParser::get_input_link(const std::string &name)
|
|||||||
while (in_node->type == NODE_REROUTE) {
|
while (in_node->type == NODE_REROUTE) {
|
||||||
link = in_node->input_socket(0).link;
|
link = in_node->input_socket(0).link;
|
||||||
if (!link->is_used()) {
|
if (!link->is_used()) {
|
||||||
return item;
|
return res;
|
||||||
}
|
}
|
||||||
in_node = link->fromnode;
|
in_node = link->fromnode;
|
||||||
}
|
}
|
||||||
@ -131,20 +135,25 @@ NodeItem NodeParser::get_input_link(const std::string &name)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// TODO: warning log
|
// TODO: warning log
|
||||||
return item;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
item = parser->compute();
|
res = parser->compute();
|
||||||
return item;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeItem NodeParser::get_input_value(const std::string &name)
|
NodeItem NodeParser::get_input_value(const std::string &name)
|
||||||
{
|
{
|
||||||
NodeItem item = get_input_link(name);
|
NodeItem res = get_input_link(name);
|
||||||
if (!item) {
|
if (!res) {
|
||||||
item = get_input_value(name);
|
res = get_input_value(name);
|
||||||
}
|
}
|
||||||
return item;
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeItem NodeParser::empty_value()
|
||||||
|
{
|
||||||
|
return NodeItem(graph);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string NodeParser::get_mx_type(const bNodeSocket *sock)
|
std::string NodeParser::get_mx_type(const bNodeSocket *sock)
|
||||||
|
@ -56,10 +56,13 @@ class NodeParser {
|
|||||||
virtual NodeItem compute() = 0;
|
virtual NodeItem compute() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NodeItem create_node(const std::string &mx_category, const std::string &mx_type);
|
NodeItem create_node(const std::string &mx_category,
|
||||||
|
const std::string &mx_type,
|
||||||
|
bool accessory = false);
|
||||||
NodeItem get_input_default(const std::string &name);
|
NodeItem get_input_default(const std::string &name);
|
||||||
NodeItem get_input_link(const std::string &name);
|
NodeItem get_input_link(const std::string &name);
|
||||||
NodeItem get_input_value(const std::string &name);
|
NodeItem get_input_value(const std::string &name);
|
||||||
|
NodeItem empty_value();
|
||||||
|
|
||||||
std::string get_mx_type(const bNodeSocket *sock);
|
std::string get_mx_type(const bNodeSocket *sock);
|
||||||
};
|
};
|
||||||
|
@ -6,21 +6,15 @@
|
|||||||
|
|
||||||
namespace blender::nodes::materialx {
|
namespace blender::nodes::materialx {
|
||||||
|
|
||||||
OutputMaterialNodeParser::OutputMaterialNodeParser(MaterialX::DocumentPtr doc,
|
NodeItem OutputMaterialNodeParser::compute()
|
||||||
const Depsgraph *depsgraph,
|
|
||||||
const Material *material,
|
|
||||||
const bNode *node)
|
|
||||||
: NodeParser(doc, depsgraph, material, node)
|
|
||||||
{
|
{
|
||||||
matx_node = doc->addNode("surfacematerial", MaterialX::createValidName(node->name), "material");
|
NodeItem node = empty_value();
|
||||||
}
|
NodeItem surface = get_input_link("Surface");
|
||||||
|
if (surface) {
|
||||||
MaterialX::NodePtr OutputMaterialNodeParser::compute()
|
node = create_node("surfacematerial", "material");
|
||||||
{
|
node.set_input("surfaceshader", surface);
|
||||||
const char *matx_socket = "surfaceshader";
|
}
|
||||||
const bNodeSocket sock = node->input_by_identifier("Surface");
|
return node;
|
||||||
get_input_link_node(&sock, matx_node, matx_socket);
|
|
||||||
return matx_node;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::nodes::materialx
|
} // namespace blender::nodes::materialx
|
||||||
|
@ -10,11 +10,8 @@ namespace blender::nodes::materialx {
|
|||||||
|
|
||||||
class OutputMaterialNodeParser : public NodeParser {
|
class OutputMaterialNodeParser : public NodeParser {
|
||||||
public:
|
public:
|
||||||
OutputMaterialNodeParser(MaterialX::DocumentPtr doc,
|
using NodeParser::NodeParser;
|
||||||
const Depsgraph *depsgraph,
|
NodeItem compute() override;
|
||||||
const Material *material,
|
|
||||||
const bNode *node);
|
|
||||||
MaterialX::NodePtr compute() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::nodes::materialx
|
} // namespace blender::nodes::materialx
|
||||||
|
@ -11,18 +11,8 @@
|
|||||||
|
|
||||||
namespace blender::nodes::materialx {
|
namespace blender::nodes::materialx {
|
||||||
|
|
||||||
const MaterialX::Color3 TexImageNodeParser::texture_error_color_{1.0, 0.0, 1.0};
|
|
||||||
|
|
||||||
TexImageNodeParser::TexImageNodeParser(MaterialX::DocumentPtr doc,
|
NodeItem TexImageNodeParser::compute()
|
||||||
const Depsgraph *depsgraph,
|
|
||||||
const Material *material,
|
|
||||||
const bNode *node)
|
|
||||||
: NodeParser(doc, depsgraph, material, node)
|
|
||||||
{
|
|
||||||
matx_node = doc->addNode("image", MaterialX::createValidName(node->name), "color3");
|
|
||||||
}
|
|
||||||
|
|
||||||
MaterialX::NodePtr TexImageNodeParser::compute()
|
|
||||||
{
|
{
|
||||||
Image *image = (Image *)node->id;
|
Image *image = (Image *)node->id;
|
||||||
NodeTexImage *tex = static_cast<NodeTexImage *>(node->storage);
|
NodeTexImage *tex = static_cast<NodeTexImage *>(node->storage);
|
||||||
@ -34,12 +24,12 @@ MaterialX::NodePtr TexImageNodeParser::compute()
|
|||||||
#ifdef WITH_HYDRA
|
#ifdef WITH_HYDRA
|
||||||
image_path = io::hydra::cache_or_get_image_file(bmain, scene, image, &tex->iuser);
|
image_path = io::hydra::cache_or_get_image_file(bmain, scene, image, &tex->iuser);
|
||||||
#endif
|
#endif
|
||||||
MaterialX::NodePtr uv_node = doc->addNode("texcoord", MaterialX::EMPTY_STRING, "vector2");
|
|
||||||
|
|
||||||
matx_node->addInput("file", "filename")->setValue(image_path);
|
NodeItem texcoord = create_node("texcoord", "vector2", true);
|
||||||
matx_node->addInput("texcoord", "vector2")->setNodeName(uv_node->getName());
|
NodeItem res = create_node("image", "color3");
|
||||||
|
res.set_input("file", image_path, "filename");
|
||||||
return matx_node;
|
res.set_input("texcoord", texcoord);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::nodes::materialx
|
} // namespace blender::nodes::materialx
|
||||||
|
@ -9,16 +9,9 @@
|
|||||||
namespace blender::nodes::materialx {
|
namespace blender::nodes::materialx {
|
||||||
|
|
||||||
class TexImageNodeParser : public NodeParser {
|
class TexImageNodeParser : public NodeParser {
|
||||||
protected:
|
|
||||||
/* Following Cycles color for wrong Texture nodes. */
|
|
||||||
static const MaterialX::Color3 texture_error_color_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TexImageNodeParser(MaterialX::DocumentPtr doc,
|
using NodeParser::NodeParser;
|
||||||
const Depsgraph *depsgraph,
|
NodeItem compute() override;
|
||||||
const Material *material,
|
|
||||||
const bNode *node);
|
|
||||||
MaterialX::NodePtr compute() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::nodes::materialx
|
} // namespace blender::nodes::materialx
|
||||||
|
Loading…
Reference in New Issue
Block a user