Implement type conversion for NodeItem #9

Merged
Bogdan Nagirniak merged 12 commits from BogdanNagirniak/blender:matx-nodeitem-type into matx-export-material 2023-09-05 12:03:24 +02:00
6 changed files with 28 additions and 13 deletions
Showing only changes of commit 826df5ce92 - Show all commits

View File

@ -2,8 +2,8 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "node_parser.h"
#include "../material.h"
#include "node_parser.h"
namespace blender::nodes::materialx {

View File

@ -187,7 +187,6 @@ bool NodeItem::operator==(const NodeItem &other) const
return false;
}
NodeItem item1 = *this;
NodeItem item2 = other;
Type tp = adjust_types(item1, item2);
@ -526,8 +525,8 @@ NodeItem NodeItem::convert(Type to_type) const
res.value = MaterialX::Value::createValue<MaterialX::Vector2>({v[0], v[1]});
break;
case Type::Vector4:
res.value =
MaterialX::Value::createValue<MaterialX::Vector4>({v[0], v[1], v[2], 0.0f});
res.value = MaterialX::Value::createValue<MaterialX::Vector4>(
{v[0], v[1], v[2], 0.0f});
break;
case Type::Color3:
res.value = MaterialX::Value::createValue<MaterialX::Color3>({v[0], v[1], v[2]});
@ -569,7 +568,8 @@ NodeItem NodeItem::convert(Type to_type) const
auto v = value->asA<MaterialX::Color4>();
switch (to_type) {
case Type::Vector4:
res.value = MaterialX::Value::createValue<MaterialX::Vector4>({v[0], v[1], v[2], v[3]});
res.value = MaterialX::Value::createValue<MaterialX::Vector4>(
{v[0], v[1], v[2], v[3]});
break;
case Type::Color3:
res.value = MaterialX::Value::createValue<MaterialX::Color3>({v[0], v[1], v[2]});
@ -611,8 +611,7 @@ bool NodeItem::is_arithmetic() const
return is_arithmetic(type());
}
BogdanNagirniak marked this conversation as resolved Outdated

Type::Float -> Type::Integer

Type::Float -> Type::Integer

Integer isn't used in arithmetic operations

Integer isn't used in arithmetic operations
NodeItem NodeItem::arithmetic(const std::string &category,
std::function<float(float)> func) const
NodeItem NodeItem::arithmetic(const std::string &category, std::function<float(float)> func) const
{
NodeItem res = empty();
Type t = type();

View File

@ -10,7 +10,18 @@ namespace blender::nodes::materialx {
class NodeItem {
public:
enum class Type { Empty = 0, Other, String, Integer, Float, Vector2, Vector3, Vector4, Color3, Color4 };
enum class Type {
Empty = 0,
Other,
BogdanNagirniak marked this conversation as resolved Outdated

Add comment what is Other

Add comment what is `Other`
String,
Integer,
Float,
Vector2,
Vector3,
Vector4,
Color3,
Color4
};
enum class IfType { Less = 0, LessEq, Eq, GreaterEq, Greater, NotEq };
BogdanNagirniak marked this conversation as resolved Outdated

IfType -> ComparisonType

IfType -> ComparisonType
public:

View File

@ -14,7 +14,11 @@ NodeParser::NodeParser(MaterialX::GraphElement *graph,
const Material *material,
const bNode *node,
const bNodeSocket *socket_out)
: graph_(graph), depsgraph_(depsgraph), material_(material), node_(node), socket_out_(socket_out)
: graph_(graph),
depsgraph_(depsgraph),
material_(material),
node_(node),
socket_out_(socket_out)
{
}

View File

@ -37,7 +37,8 @@ NodeItem OutputMaterialNodeParser::compute(const std::string &socket_name)
NodeItem OutputMaterialNodeParser::compute_default()
{
NodeItem surface = create_node("standard_surface", "surfaceshader");
surface.set_input("base_color", value(MaterialX::Color3(material_->r, material_->g, material_->b)));
surface.set_input("base_color",
value(MaterialX::Color3(material_->r, material_->g, material_->b)));
surface.set_input("diffuse_roughness", value(material_->roughness));
if (material_->metallic > 0.0f) {
surface.set_input("metalness", value(material_->metallic));

View File

@ -31,8 +31,8 @@ NodeItem TexCheckerNodeParser::compute()
modulo_y.set_input("in1", separate, "outy");
modulo_y.set_input("in2", value(2.0f));
NodeItem ifequal =
(modulo_x.floor() + modulo_y.floor()).if_else(NodeItem::IfType::Eq, value(1.0f), value(0.0f), value(1.0f));
NodeItem ifequal = (modulo_x.floor() + modulo_y.floor())
.if_else(NodeItem::IfType::Eq, value(1.0f), value(0.0f), value(1.0f));
NodeItem res = create_node("mix", "color3");
res.set_input("bg", color1, NodeItem::Type::Color3);