forked from blender/blender
Implement export of Math node. Continue other arithmetic support for NodeItem #6
@ -101,7 +101,10 @@ bool NodeItem::operator==(const NodeItem &other) const
|
||||
if (node && node == other.node) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -164,36 +167,44 @@ NodeItem NodeItem::dot(const NodeItem &other) const
|
||||
return d;
|
||||
}
|
||||
|
||||
NodeItem NodeItem::if_else(char condition,
|
||||
NodeItem NodeItem::if_else(const std::string &condition,
|
||||
const NodeItem &other,
|
||||
const NodeItem &if_val,
|
||||
const NodeItem &else_val) const
|
||||
{
|
||||
//def if_else(self, cond: str, other, if_value, else_value):
|
||||
// if cond == '>':
|
||||
// res = self._arithmetic_helper(other, 'ifgreater', lambda a, b: float(a > b))
|
||||
// elif cond == '>=':
|
||||
// res = self._arithmetic_helper(other, 'ifgreatereq', lambda a, b: float(a >= b))
|
||||
// elif cond == '==':
|
||||
// res = self._arithmetic_helper(other, 'ifequal', lambda a, b: float(a == b))
|
||||
// elif cond == '<':
|
||||
// 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 (condition == "<") {
|
||||
return other.if_else(">", *this, else_val, if_val);
|
||||
}
|
||||
if (condition == "<=") {
|
||||
return other.if_else(">=", *this, else_val, if_val);
|
||||
}
|
||||
if (condition == "!=") {
|
||||
return if_else("==", other, else_val, if_val);
|
||||
}
|
||||
|
||||
// if isinstance(res.data, float):
|
||||
// return if_value if res.data == 1.0 else else_value
|
||||
// elif isinstance(res.data, tuple):
|
||||
// return if_value if res.data[0] == 1.0 else else_value
|
||||
// else:
|
||||
// res.set_input('value1', if_value)
|
||||
// res.set_input('value2', else_value)
|
||||
// return res
|
||||
return empty();
|
||||
NodeItem res = empty();
|
||||
if (condition == ">") {
|
||||
res = arithmetic(other, "ifgreater", [](float a, float b) { return float(a > b); });
|
||||
}
|
||||
else if (condition == ">=") {
|
||||
res = arithmetic(other, "ifgreatereq", [](float a, float b) { return float(a >= b); });
|
||||
}
|
||||
else if (condition == "==") {
|
||||
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
|
||||
|
@ -44,7 +44,7 @@ class NodeItem {
|
||||
NodeItem min(const NodeItem &other) const;
|
||||
NodeItem max(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 &if_val,
|
||||
const NodeItem &else_val) const;
|
||||
|
Loading…
Reference in New Issue
Block a user