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