Implement export of Math node. Continue other arithmetic support for NodeItem #6

Merged
Bogdan Nagirniak merged 9 commits from BogdanNagirniak/blender:matx-arithmetic into matx-export-material 2023-08-31 12:35:55 +02:00
2 changed files with 38 additions and 27 deletions
Showing only changes of commit 612b6a370e - Show all commits

View File

@ -101,7 +101,10 @@ bool NodeItem::operator==(const NodeItem &other) const
if (node && node == other.node) { if (node && node == other.node) {
return true; return true;
} }
/* TODO: implement */ if (value && other.value) {
NodeItem cmp = if_else("==", other, val(1.0f), val(0.0f));
return cmp.value->asA<float>() == 1.0f;
}
return false; return false;
} }
@ -164,36 +167,44 @@ NodeItem NodeItem::dot(const NodeItem &other) const
return d; return d;
} }
NodeItem NodeItem::if_else(char condition, NodeItem NodeItem::if_else(const std::string &condition,
const NodeItem &other, const NodeItem &other,
const NodeItem &if_val, const NodeItem &if_val,
const NodeItem &else_val) const const NodeItem &else_val) const
{ {
//def if_else(self, cond: str, other, if_value, else_value): if (condition == "<") {
// if cond == '>': return other.if_else(">", *this, else_val, if_val);
// res = self._arithmetic_helper(other, 'ifgreater', lambda a, b: float(a > b)) }
// elif cond == '>=': if (condition == "<=") {
// res = self._arithmetic_helper(other, 'ifgreatereq', lambda a, b: float(a >= b)) return other.if_else(">=", *this, else_val, if_val);
// elif cond == '==': }
// res = self._arithmetic_helper(other, 'ifequal', lambda a, b: float(a == b)) if (condition == "!=") {
// elif cond == '<': return if_else("==", other, else_val, if_val);
// return self.node_item(other).if_else('>', self, else_value, if_value) }
// elif cond == '<=':
// return self.node_item(other).if_else('>=', self, else_value, if_value)
// elif cond == '!=':
// return self.if_else('==', other, else_value, if_value)
// else:
// raise ValueError("Incorrect condition:", cond)
// if isinstance(res.data, float): NodeItem res = empty();
// return if_value if res.data == 1.0 else else_value if (condition == ">") {
// elif isinstance(res.data, tuple): res = arithmetic(other, "ifgreater", [](float a, float b) { return float(a > b); });
// return if_value if res.data[0] == 1.0 else else_value }
// else: else if (condition == ">=") {
// res.set_input('value1', if_value) res = arithmetic(other, "ifgreatereq", [](float a, float b) { return float(a >= b); });
// res.set_input('value2', else_value) }
// return res else if (condition == "==") {
return empty(); res = arithmetic(other, "ifequal", [](float a, float b) { return float(a == b); });
}
else {
BLI_assert_unreachable();
}
if (res.value) {
/* Getting sum of elements via dot product with 1.0f and comparing to 0.0f */
res = res.dot(val(1.0f)).value->asA<float>() == 0.0f ? else_val : if_val;
}
else if (res.node) {
res.set_input("value1", if_val);
res.set_input("value2", else_val);
}
return res;
} }
NodeItem NodeItem::blend(const NodeItem &a, const NodeItem &b) const NodeItem NodeItem::blend(const NodeItem &a, const NodeItem &b) const

View File

@ -44,7 +44,7 @@ class NodeItem {
NodeItem min(const NodeItem &other) const; NodeItem min(const NodeItem &other) const;
NodeItem max(const NodeItem &other) const; NodeItem max(const NodeItem &other) const;
NodeItem dot(const NodeItem &other) const; NodeItem dot(const NodeItem &other) const;
NodeItem if_else(char condition, NodeItem if_else(const std::string &condition,
const NodeItem &other, const NodeItem &other,
const NodeItem &if_val, const NodeItem &if_val,
const NodeItem &else_val) const; const NodeItem &else_val) const;