Implement type conversion for NodeItem #10

Closed
Bogdan Nagirniak wants to merge 9 commits from BogdanNagirniak/blender:matx-nodeitem-type into matx-export-material

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
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());
}
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,
String,
Integer,
Float,
Vector2,
Vector3,
Vector4,
Color3,
Color4
};
enum class IfType { Less = 0, LessEq, Eq, GreaterEq, Greater, NotEq };
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);