forked from blender/blender
Implement export of Shader BSDF nodes #13
@ -101,6 +101,7 @@ NodeItem NodeItem::operator+(const NodeItem &other) const
|
||||
{
|
||||
Type type = this->type();
|
||||
if (ELEM(type, Type::BSDF, Type::EDF)) {
|
||||
/* Special case: add BSDF/EDF shaders */
|
||||
NodeItem res = empty();
|
||||
if (other.type() == type) {
|
||||
res.node = graph_->addNode("add", MaterialX::EMPTY_STRING, this->type(type));
|
||||
@ -130,8 +131,10 @@ NodeItem NodeItem::operator*(const NodeItem &other) const
|
||||
{
|
||||
Type type = this->type();
|
||||
if (ELEM(type, Type::BSDF, Type::EDF)) {
|
||||
/* Special case: multiple BSDF/EDF shader by Float or Color3 */
|
||||
NodeItem res = empty();
|
||||
if (ELEM(other.type(), Type::Float, Type::Color3)) {
|
||||
Type other_type = other.type();
|
||||
if (ELEM(other_type, Type::Float, Type::Color3)) {
|
||||
res.node = graph_->addNode("multiply", MaterialX::EMPTY_STRING, this->type(type));
|
||||
res.set_input("in1", *this);
|
||||
res.set_input("in2", other);
|
||||
@ -178,7 +181,7 @@ bool NodeItem::operator==(const NodeItem &other) const
|
||||
|
||||
NodeItem item1 = *this;
|
||||
NodeItem item2 = other;
|
||||
Type to_type = adjust_types(item1, item2);
|
||||
Type to_type = cast_types(item1, item2);
|
||||
if (to_type == Type::Empty) {
|
||||
return false;
|
||||
}
|
||||
@ -560,7 +563,7 @@ NodeItem NodeItem::if_else(CompareOp op,
|
||||
|
||||
auto item1 = if_val;
|
||||
auto item2 = else_val;
|
||||
Type to_type = adjust_types(item1, item2);
|
||||
Type to_type = cast_types(item1, item2);
|
||||
if (to_type == Type::Empty) {
|
||||
return res;
|
||||
}
|
||||
@ -671,7 +674,7 @@ bool NodeItem::is_arithmetic(Type type)
|
||||
return type >= Type::Float && type <= Type::Color4;
|
||||
}
|
||||
|
||||
NodeItem::Type NodeItem::adjust_types(NodeItem &item1, NodeItem &item2)
|
||||
NodeItem::Type NodeItem::cast_types(NodeItem &item1, NodeItem &item2)
|
||||
{
|
||||
Type t1 = item1.type();
|
||||
Type t2 = item2.type();
|
||||
@ -761,7 +764,7 @@ NodeItem NodeItem::arithmetic(const NodeItem &other,
|
||||
NodeItem res = empty();
|
||||
NodeItem item1 = *this;
|
||||
NodeItem item2 = other;
|
||||
Type to_type = adjust_types(item1, item2);
|
||||
Type to_type = cast_types(item1, item2);
|
||||
if (to_type == Type::Empty) {
|
||||
return res;
|
||||
}
|
||||
|
@ -11,22 +11,24 @@ namespace blender::nodes::materialx {
|
||||
class NodeItem {
|
||||
public:
|
||||
enum class Type {
|
||||
Empty = 0,
|
||||
Any,
|
||||
Any = 0,
|
||||
Empty,
|
||||
|
||||
/* Value types */
|
||||
String,
|
||||
Filename,
|
||||
Integer,
|
||||
/* Block of arithmetic types. Ordered by type cast */
|
||||
Float,
|
||||
Vector2,
|
||||
Vector3,
|
||||
Vector4,
|
||||
Color3,
|
||||
Vector4,
|
||||
Color4,
|
||||
/* End of arithmetic types */
|
||||
|
||||
/* Shader types
|
||||
* Note: There are only supported types */
|
||||
* NOTE: There are only supported types */
|
||||
BSDF,
|
||||
EDF,
|
||||
SurfaceShader,
|
||||
@ -106,7 +108,7 @@ class NodeItem {
|
||||
|
||||
private:
|
||||
static bool is_arithmetic(Type type);
|
||||
static Type adjust_types(NodeItem &item1, NodeItem &item2);
|
||||
static Type cast_types(NodeItem &item1, NodeItem &item2);
|
||||
|
||||
bool is_arithmetic() const;
|
||||
NodeItem arithmetic(const std::string &category, std::function<float(float)> func) const;
|
||||
|
Loading…
Reference in New Issue
Block a user