forked from blender/blender
Export to MatX various Texture nodes #5
@ -28,7 +28,10 @@ void NodeItem::set_input(const std::string &name, const NodeItem &item)
|
||||
void NodeItem::set_input(const std::string &name, const MaterialX::ValuePtr value)
|
||||
{
|
||||
std::string mx_type = value->getTypeString();
|
||||
if (value->isA<float>()) {
|
||||
if (value->isA<int>()) {
|
||||
set_input(name, value->asA<int>(), mx_type);
|
||||
}
|
||||
else if (value->isA<float>()) {
|
||||
set_input(name, value->asA<float>(), mx_type);
|
||||
}
|
||||
else if (value->isA<MaterialX::Vector2>()) {
|
||||
@ -350,6 +353,12 @@ NodeItem NodeParser::get_input_default(const std::string &name)
|
||||
NodeItem res = empty_value();
|
||||
|
||||
const bNodeSocket &socket = node->input_by_identifier(name);
|
||||
/* Explicit check for Detail socket of Noise Texture node since MaterialX expects integer for octaves. */
|
||||
if (node->typeinfo->type == SH_NODE_TEX_NOISE && STREQ(socket.name, "Detail")) {
|
||||
int v = socket.default_value_typed<bNodeSocketValueFloat>()->value;
|
||||
res.value = MaterialX::Value::createValue<int>(v);
|
||||
return res;
|
||||
}
|
||||
switch (socket.type) {
|
||||
case SOCK_FLOAT: {
|
||||
float v = socket.default_value_typed<bNodeSocketValueFloat>()->value;
|
||||
@ -413,6 +422,9 @@ NodeItem NodeParser::get_input_link(const std::string &name)
|
||||
case SH_NODE_TEX_ENVIRONMENT:
|
||||
parser = std::make_unique<TexEnvironmentNodeParser>(graph, depsgraph, material, in_node);
|
||||
break;
|
||||
case SH_NODE_TEX_NOISE:
|
||||
parser = std::make_unique<TexNoiseNodeParser>(graph, depsgraph, material, in_node);
|
||||
break;
|
||||
default:
|
||||
// TODO: warning log
|
||||
return res;
|
||||
|
@ -109,5 +109,6 @@ DECLARE_PARSER(MixRGBNodeParser)
|
||||
DECLARE_PARSER(OutputMaterialNodeParser)
|
||||
DECLARE_PARSER(TexImageNodeParser)
|
||||
DECLARE_PARSER(TexEnvironmentNodeParser)
|
||||
DECLARE_PARSER(TexNoiseNodeParser)
|
||||
|
||||
} // namespace blender::nodes::materialx
|
||||
|
33
source/blender/nodes/shader/materialx/nodes/tex_noise.cc
Normal file
33
source/blender/nodes/shader/materialx/nodes/tex_noise.cc
Normal file
@ -0,0 +1,33 @@
|
||||
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "node_parser.h"
|
||||
|
||||
#include "hydra/image.h"
|
||||
|
||||
#include "DEG_depsgraph_query.h"
|
||||
|
||||
namespace blender::nodes::materialx {
|
||||
|
||||
NodeItem TexNoiseNodeParser::compute()
|
||||
{
|
||||
Image *image = (Image *)node->id;
|
||||
NodeTexNoise *tex = static_cast<NodeTexNoise *>(node->storage);
|
||||
Scene *scene = DEG_get_input_scene(depsgraph);
|
||||
Main *bmain = DEG_get_bmain(depsgraph);
|
||||
|
||||
NodeItem texcoord = create_node("position", "vector3", true);
|
||||
NodeItem scale = get_input_value("Scale");
|
||||
NodeItem position = texcoord * scale;
|
||||
NodeItem detail = get_input_value("Detail");
|
||||
NodeItem lacunarity = get_input_value("Lacunarity");
|
||||
|
||||
NodeItem res = create_node("fractal3d", "color3", true);
|
||||
res.set_input("position", position);
|
||||
res.set_input("octaves", detail);
|
||||
res.set_input("lacunarity", lacunarity);
|
||||
return res;
|
||||
}
|
||||
|
||||
} // namespace blender::nodes::materialx
|
Loading…
Reference in New Issue
Block a user