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
3 changed files with 47 additions and 1 deletions
Showing only changes of commit 5baa0be770 - Show all commits

View File

@ -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) {
DagerD marked this conversation as resolved Outdated

Override get_input_default in SH_NODE_TEX_NOISE and move this code there.

Override `get_input_default` in SH_NODE_TEX_NOISE and move this code there.
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;

View File

@ -109,5 +109,6 @@ DECLARE_PARSER(MixRGBNodeParser)
DECLARE_PARSER(OutputMaterialNodeParser)
DECLARE_PARSER(TexImageNodeParser)
DECLARE_PARSER(TexEnvironmentNodeParser)
DECLARE_PARSER(TexNoiseNodeParser)
} // namespace blender::nodes::materialx

View 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);
DagerD marked this conversation as resolved Outdated

Use following order:

  1. get_input_...()
  2. operations: math, new nodes
  3. creating result node.
  NodeItem detail = get_input_value("Detail");
  NodeItem lacunarity = get_input_value("Lacunarity");
  NodeItem scale = get_input_value("Scale");

  NodeItem texcoord = create_node("position", "vector3", true);
  NodeItem position = texcoord * scale;
Use following order: 1. get_input_...() 2. operations: math, new nodes 3. creating result node. ``` NodeItem detail = get_input_value("Detail"); NodeItem lacunarity = get_input_value("Lacunarity"); NodeItem scale = get_input_value("Scale"); NodeItem texcoord = create_node("position", "vector3", true); NodeItem position = texcoord * scale; ```
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