forked from blender/blender
Export other channels and parameters from texture nodes #16
@ -9,6 +9,8 @@
|
||||
|
||||
namespace blender::nodes::materialx {
|
||||
|
||||
static const std::string TEXCOORD_NODE_NAME = "node_texcoord";
|
||||
|
||||
NodeParser::NodeParser(MaterialX::GraphElement *graph,
|
||||
const Depsgraph *depsgraph,
|
||||
const Material *material,
|
||||
@ -81,6 +83,17 @@ NodeItem NodeParser::empty() const
|
||||
return NodeItem(graph_);
|
||||
}
|
||||
|
||||
NodeItem NodeParser::texcoord_node()
|
||||
{
|
||||
NodeItem res = empty();
|
||||
res.node = graph_->getNode(TEXCOORD_NODE_NAME);
|
||||
if (!res.node) {
|
||||
res = create_node("texcoord", "vector2");
|
||||
res.node->setName(TEXCOORD_NODE_NAME);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
NodeItem NodeParser::get_input_default(const bNodeSocket &socket, NodeItem::Type to_type)
|
||||
{
|
||||
NodeItem res = empty();
|
||||
|
@ -42,6 +42,7 @@ class NodeParser {
|
||||
NodeItem get_input_value(int index, NodeItem::Type to_type);
|
||||
NodeItem empty() const;
|
||||
template<class T> NodeItem value(const T &data) const;
|
||||
NodeItem texcoord_node();
|
||||
|
||||
private:
|
||||
NodeItem get_input_default(const bNodeSocket &socket, NodeItem::Type to_type);
|
||||
|
@ -14,7 +14,7 @@ NodeItem TexCheckerNodeParser::compute()
|
||||
NodeItem scale = get_input_value("Scale", NodeItem::Type::Float);
|
||||
|
||||
if (!vector) {
|
||||
vector = create_node("texcoord", "vector2");
|
||||
vector = texcoord_node();
|
||||
}
|
||||
vector = (vector * scale) % value(2.0f);
|
||||
NodeItem mix = (vector.extract(0).floor() + vector.extract(1).floor())
|
||||
|
@ -4,7 +4,9 @@
|
||||
|
||||
#include "node_parser.h"
|
||||
|
||||
#ifdef WITH_HYDRA
|
||||
#include "hydra/image.h"
|
||||
#endif
|
||||
|
||||
#include "DEG_depsgraph_query.h"
|
||||
|
||||
@ -17,14 +19,15 @@ NodeItem TexEnvironmentNodeParser::compute()
|
||||
Scene *scene = DEG_get_input_scene(depsgraph_);
|
||||
Main *bmain = DEG_get_bmain(depsgraph_);
|
||||
std::string image_path;
|
||||
|
||||
#ifdef WITH_HYDRA
|
||||
/* 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");
|
||||
NodeItem res = create_node("image", "color3");
|
||||
NodeItem texcoord = texcoord_node();
|
||||
NodeItem res = create_node("image", "color4");
|
||||
res.set_input("file", image_path, "filename");
|
||||
res.set_input("texcoord", texcoord);
|
||||
return res;
|
||||
|
@ -4,7 +4,9 @@
|
||||
|
||||
#include "node_parser.h"
|
||||
|
||||
#ifdef WITH_HYDRA
|
||||
# include "hydra/image.h"
|
||||
#endif
|
||||
|
||||
#include "DEG_depsgraph_query.h"
|
||||
|
||||
@ -17,14 +19,15 @@ NodeItem TexImageNodeParser::compute()
|
||||
Scene *scene = DEG_get_input_scene(depsgraph_);
|
||||
Main *bmain = DEG_get_bmain(depsgraph_);
|
||||
std::string image_path;
|
||||
|
||||
#ifdef WITH_HYDRA
|
||||
/* 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");
|
||||
NodeItem res = create_node("image", "color3");
|
||||
NodeItem texcoord = texcoord_node();
|
||||
NodeItem res = create_node("image", "color4");
|
||||
res.set_input("file", image_path, "filename");
|
||||
res.set_input("texcoord", texcoord);
|
||||
return res;
|
||||
|
Loading…
Reference in New Issue
Block a user