forked from blender/blender
Implement type conversion for NodeItem #9
@ -2,8 +2,8 @@
|
|||||||
*
|
*
|
||||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||||
|
|
||||||
#include "node_parser.h"
|
|
||||||
#include "../material.h"
|
#include "../material.h"
|
||||||
|
#include "node_parser.h"
|
||||||
|
|
||||||
namespace blender::nodes::materialx {
|
namespace blender::nodes::materialx {
|
||||||
|
|
||||||
|
@ -187,7 +187,6 @@ bool NodeItem::operator==(const NodeItem &other) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NodeItem item1 = *this;
|
NodeItem item1 = *this;
|
||||||
NodeItem item2 = other;
|
NodeItem item2 = other;
|
||||||
Type tp = adjust_types(item1, item2);
|
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]});
|
res.value = MaterialX::Value::createValue<MaterialX::Vector2>({v[0], v[1]});
|
||||||
break;
|
break;
|
||||||
case Type::Vector4:
|
case Type::Vector4:
|
||||||
res.value =
|
res.value = MaterialX::Value::createValue<MaterialX::Vector4>(
|
||||||
MaterialX::Value::createValue<MaterialX::Vector4>({v[0], v[1], v[2], 0.0f});
|
{v[0], v[1], v[2], 0.0f});
|
||||||
break;
|
break;
|
||||||
case Type::Color3:
|
case Type::Color3:
|
||||||
res.value = MaterialX::Value::createValue<MaterialX::Color3>({v[0], v[1], v[2]});
|
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>();
|
auto v = value->asA<MaterialX::Color4>();
|
||||||
switch (to_type) {
|
switch (to_type) {
|
||||||
case Type::Vector4:
|
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;
|
break;
|
||||||
case Type::Color3:
|
case Type::Color3:
|
||||||
res.value = MaterialX::Value::createValue<MaterialX::Color3>({v[0], v[1], v[2]});
|
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());
|
return is_arithmetic(type());
|
||||||
}
|
}
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
|
|||||||
|
|
||||||
NodeItem NodeItem::arithmetic(const std::string &category,
|
NodeItem NodeItem::arithmetic(const std::string &category, std::function<float(float)> func) const
|
||||||
std::function<float(float)> func) const
|
|
||||||
{
|
{
|
||||||
NodeItem res = empty();
|
NodeItem res = empty();
|
||||||
Type t = type();
|
Type t = type();
|
||||||
|
@ -10,7 +10,18 @@ namespace blender::nodes::materialx {
|
|||||||
|
|
||||||
class NodeItem {
|
class NodeItem {
|
||||||
public:
|
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
Georgiy Markelov
commented
Add comment what is Add comment what is `Other`
|
|||||||
|
String,
|
||||||
|
Integer,
|
||||||
|
Float,
|
||||||
|
Vector2,
|
||||||
|
Vector3,
|
||||||
|
Vector4,
|
||||||
|
Color3,
|
||||||
|
Color4
|
||||||
|
};
|
||||||
enum class IfType { Less = 0, LessEq, Eq, GreaterEq, Greater, NotEq };
|
enum class IfType { Less = 0, LessEq, Eq, GreaterEq, Greater, NotEq };
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
Georgiy Markelov
commented
IfType -> ComparisonType IfType -> ComparisonType
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -14,7 +14,11 @@ NodeParser::NodeParser(MaterialX::GraphElement *graph,
|
|||||||
const Material *material,
|
const Material *material,
|
||||||
const bNode *node,
|
const bNode *node,
|
||||||
const bNodeSocket *socket_out)
|
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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +122,7 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket)
|
|||||||
/* Checking if node was already computed */
|
/* Checking if node was already computed */
|
||||||
res.node = graph_->getNode(node_name(from_node, link->fromsock));
|
res.node = graph_->getNode(node_name(from_node, link->fromsock));
|
||||||
if (res.node) {
|
if (res.node) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Computing from_node with required NodeParser object */
|
/* Computing from_node with required NodeParser object */
|
||||||
|
@ -37,7 +37,8 @@ NodeItem OutputMaterialNodeParser::compute(const std::string &socket_name)
|
|||||||
NodeItem OutputMaterialNodeParser::compute_default()
|
NodeItem OutputMaterialNodeParser::compute_default()
|
||||||
{
|
{
|
||||||
NodeItem surface = create_node("standard_surface", "surfaceshader");
|
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));
|
surface.set_input("diffuse_roughness", value(material_->roughness));
|
||||||
if (material_->metallic > 0.0f) {
|
if (material_->metallic > 0.0f) {
|
||||||
surface.set_input("metalness", value(material_->metallic));
|
surface.set_input("metalness", value(material_->metallic));
|
||||||
|
@ -31,8 +31,8 @@ NodeItem TexCheckerNodeParser::compute()
|
|||||||
modulo_y.set_input("in1", separate, "outy");
|
modulo_y.set_input("in1", separate, "outy");
|
||||||
modulo_y.set_input("in2", value(2.0f));
|
modulo_y.set_input("in2", value(2.0f));
|
||||||
|
|
||||||
NodeItem ifequal =
|
NodeItem ifequal = (modulo_x.floor() + modulo_y.floor())
|
||||||
(modulo_x.floor() + modulo_y.floor()).if_else(NodeItem::IfType::Eq, value(1.0f), value(0.0f), value(1.0f));
|
.if_else(NodeItem::IfType::Eq, value(1.0f), value(0.0f), value(1.0f));
|
||||||
|
|
||||||
NodeItem res = create_node("mix", "color3");
|
NodeItem res = create_node("mix", "color3");
|
||||||
res.set_input("bg", color1, NodeItem::Type::Color3);
|
res.set_input("bg", color1, NodeItem::Type::Color3);
|
||||||
|
Loading…
Reference in New Issue
Block a user
Type::Float -> Type::Integer
Integer isn't used in arithmetic operations