Export to MatX various Texture nodes #5

Merged
Bogdan Nagirniak merged 17 commits from matx-add-tex-nodes into matx-export-material 2023-08-31 19:49:26 +02:00
5 changed files with 58 additions and 1 deletions
Showing only changes of commit ac2707ef40 - Show all commits

View File

@ -152,12 +152,14 @@ if(WITH_MATERIALX)
materialx/nodes/node_parser.cc materialx/nodes/node_parser.cc
materialx/nodes/output_material.cc materialx/nodes/output_material.cc
materialx/nodes/tex_image.cc materialx/nodes/tex_image.cc
materialx/nodes/tex_environment.cc
materialx/material.h materialx/material.h
materialx/nodes/bsdf_principled.h materialx/nodes/bsdf_principled.h
materialx/nodes/node_parser.h materialx/nodes/node_parser.h
materialx/nodes/output_material.h materialx/nodes/output_material.h
materialx/nodes/tex_image.h materialx/nodes/tex_image.h
materialx/nodes/tex_environment.h
) )
endif() endif()

View File

@ -6,6 +6,7 @@
#include "bsdf_principled.h" #include "bsdf_principled.h"
#include "tex_image.h" #include "tex_image.h"
#include "tex_environment.h"
#include <BKE_node_runtime.hh> #include <BKE_node_runtime.hh>
@ -154,6 +155,9 @@ NodeItem NodeParser::get_input_link(const std::string &name)
case SH_NODE_TEX_IMAGE: case SH_NODE_TEX_IMAGE:
parser = std::make_unique<TexImageNodeParser>(graph, depsgraph, material, in_node); parser = std::make_unique<TexImageNodeParser>(graph, depsgraph, material, in_node);
break; break;
case SH_NODE_TEX_ENVIRONMENT:
parser = std::make_unique<TexEnvironmentNodeParser>(graph, depsgraph, material, in_node);
break;
default: default:
// TODO: warning log // TODO: warning log
return res; return res;

View File

@ -0,0 +1,34 @@
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "tex_environment.h"
#include "node_parser.h"
#include "hydra/image.h"
#include "DEG_depsgraph_query.h"
namespace blender::nodes::materialx {
NodeItem TexEnvironmentNodeParser::compute()
{
Image *image = (Image *)node->id;
NodeTexEnvironment *tex = static_cast<NodeTexEnvironment *>(node->storage);
Scene *scene = DEG_get_input_scene(depsgraph);
Main *bmain = DEG_get_bmain(depsgraph);
std::string image_path;
/* TODO: What if Blender built without Hydra? Also io::hydra::cache_or_get_image_file contains
* pretty general code, so could be moved from bf_usd project. */
#ifdef WITH_HYDRA
image_path = io::hydra::cache_or_get_image_file(bmain, scene, image, &tex->iuser);
#endif
NodeItem texcoord = create_node("texcoord", "vector2", true);
NodeItem res = create_node("image", "color3");
res.set_input("file", image_path, "filename");
res.set_input("texcoord", texcoord);
return res;
}
} // namespace blender::nodes::materialx

View File

@ -0,0 +1,17 @@
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "node_parser.h"
namespace blender::nodes::materialx {
class TexEnvironmentNodeParser : public NodeParser {
public:
using NodeParser::NodeParser;
NodeItem compute() override;
};
} // namespace blender::nodes::materialx

View File

@ -18,7 +18,7 @@ NodeItem TexImageNodeParser::compute()
Scene *scene = DEG_get_input_scene(depsgraph); Scene *scene = DEG_get_input_scene(depsgraph);
Main *bmain = DEG_get_bmain(depsgraph); Main *bmain = DEG_get_bmain(depsgraph);
std::string image_path; std::string image_path;
/* TODO: What if Blender built without Hydra? Also io::hydra::cache_or_get_image_file contain /* TODO: What if Blender built without Hydra? Also io::hydra::cache_or_get_image_file contains
* pretty general code, so could be moved from bf_usd project. */ * pretty general code, so could be moved from bf_usd project. */
#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);