forked from blender/blender
Implement export of Math node. Continue other arithmetic support for NodeItem #6
@ -8,6 +8,8 @@ namespace blender::nodes::materialx {
|
|||||||
|
|
||||||
NodeItem MathNodeParser::compute()
|
NodeItem MathNodeParser::compute()
|
||||||
{
|
{
|
||||||
|
/* TODO: finish some math operations */
|
||||||
|
|
||||||
auto op = node->custom1;
|
auto op = node->custom1;
|
||||||
printf("%d\n", int(op));
|
printf("%d\n", int(op));
|
||||||
|
|
||||||
@ -76,6 +78,9 @@ NodeItem MathNodeParser::compute()
|
|||||||
case NODE_MATH_TANH:
|
case NODE_MATH_TANH:
|
||||||
res = x.tanh();
|
res = x.tanh();
|
||||||
break;
|
break;
|
||||||
|
case NODE_MATH_TRUNC:
|
||||||
|
res = x.sign() * x.abs().floor();
|
||||||
|
break;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
/* 2-operand operations */
|
/* 2-operand operations */
|
||||||
@ -117,17 +122,14 @@ NodeItem MathNodeParser::compute()
|
|||||||
case NODE_MATH_ARCTAN2:
|
case NODE_MATH_ARCTAN2:
|
||||||
res = x.atan2(y);
|
res = x.atan2(y);
|
||||||
break;
|
break;
|
||||||
case NODE_MATH_TRUNC:
|
|
||||||
//res = x.atan2(y);
|
|
||||||
break;
|
|
||||||
case NODE_MATH_SNAP:
|
case NODE_MATH_SNAP:
|
||||||
//res = x.atan2(y);
|
// res = ;
|
||||||
break;
|
break;
|
||||||
case NODE_MATH_PINGPONG:
|
case NODE_MATH_PINGPONG:
|
||||||
//res = x.atan2(y);
|
// res = ;
|
||||||
break;
|
break;
|
||||||
case NODE_MATH_FLOORED_MODULO:
|
case NODE_MATH_FLOORED_MODULO:
|
||||||
//res = x.atan2(y);
|
// res = ;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
@ -135,27 +137,26 @@ NodeItem MathNodeParser::compute()
|
|||||||
NodeItem z = get_input_value(2);
|
NodeItem z = get_input_value(2);
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case NODE_MATH_WRAP:
|
case NODE_MATH_WRAP:
|
||||||
//res = x * y + z;
|
// res = ;
|
||||||
break;
|
break;
|
||||||
case NODE_MATH_COMPARE:
|
case NODE_MATH_COMPARE:
|
||||||
//res = x * y + z;
|
res = z.if_else("<", (x - y).abs(), value(1.0f), value(0.0f));
|
||||||
break;
|
break;
|
||||||
case NODE_MATH_MULTIPLY_ADD:
|
case NODE_MATH_MULTIPLY_ADD:
|
||||||
res = x * y + z;
|
res = x * y + z;
|
||||||
break;
|
break;
|
||||||
case NODE_MATH_SMOOTH_MIN:
|
case NODE_MATH_SMOOTH_MIN:
|
||||||
//res = x * y + z;
|
// res = ;
|
||||||
break;
|
break;
|
||||||
case NODE_MATH_SMOOTH_MAX:
|
case NODE_MATH_SMOOTH_MAX:
|
||||||
//res = x * y + z;
|
// res = ;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* TODO: log unsupported operation*/
|
BLI_assert_unreachable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +75,11 @@ NodeItem NodeItem::operator-(const NodeItem &other) const
|
|||||||
return arithmetic(other, "subtract", [](float a, float b) { return a - b; });
|
return arithmetic(other, "subtract", [](float a, float b) { return a - b; });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NodeItem NodeItem::operator-() const
|
||||||
|
{
|
||||||
|
return val(0.0f) - *this;
|
||||||
|
}
|
||||||
|
|
||||||
NodeItem NodeItem::operator*(const NodeItem &other) const
|
NodeItem NodeItem::operator*(const NodeItem &other) const
|
||||||
{
|
{
|
||||||
return arithmetic(other, "multiply", [](float a, float b) { return a * b; });
|
return arithmetic(other, "multiply", [](float a, float b) { return a * b; });
|
||||||
@ -177,6 +182,17 @@ NodeItem NodeItem::if_else(const std::string &condition,
|
|||||||
const NodeItem &if_val,
|
const NodeItem &if_val,
|
||||||
const NodeItem &else_val) const
|
const NodeItem &else_val) const
|
||||||
{
|
{
|
||||||
|
/* TODO: if_else() doesn't work correctly. Here is description
|
||||||
|
* Node: <ifgreater>
|
||||||
|
* Output the value of in1 if value1>value2, or the value of in2 if value1<=value2.
|
||||||
|
<nodedef name="ND_ifgreater_color3" node="ifgreater" nodegroup="conditional">
|
||||||
|
<input name="value1" type="float" value="1.0" />
|
||||||
|
<input name="value2" type="float" value="0.0" />
|
||||||
|
<input name="in1" type="color3" value="0.0, 0.0, 0.0" />
|
||||||
|
<input name="in2" type="color3" value="0.0, 0.0, 0.0" />
|
||||||
|
<output name="out" type="color3" defaultinput="in1" />
|
||||||
|
</nodedef>
|
||||||
|
*/
|
||||||
if (condition == "<") {
|
if (condition == "<") {
|
||||||
return other.if_else(">", *this, else_val, if_val);
|
return other.if_else(">", *this, else_val, if_val);
|
||||||
}
|
}
|
||||||
@ -264,12 +280,12 @@ NodeItem NodeItem::atan2(const NodeItem &other) const
|
|||||||
|
|
||||||
NodeItem NodeItem::sinh() const
|
NodeItem NodeItem::sinh() const
|
||||||
{
|
{
|
||||||
return exp() - (val(0.0f) - *this).exp()) / val(2.0f);
|
return (exp() - (-*this).exp()) / val(2.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeItem NodeItem::cosh() const
|
NodeItem NodeItem::cosh() const
|
||||||
{
|
{
|
||||||
return exp() - (val(0.0f) - *this).exp()) / val(2.0f);
|
return (exp() - (-*this).exp()) / val(2.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeItem NodeItem::tanh() const
|
NodeItem NodeItem::tanh() const
|
||||||
|
@ -32,6 +32,7 @@ class NodeItem {
|
|||||||
operator bool() const;
|
operator bool() const;
|
||||||
NodeItem operator+(const NodeItem &other) const;
|
NodeItem operator+(const NodeItem &other) const;
|
||||||
NodeItem operator-(const NodeItem &other) const;
|
NodeItem operator-(const NodeItem &other) const;
|
||||||
|
NodeItem operator-() const;
|
||||||
NodeItem operator*(const NodeItem &other) const;
|
NodeItem operator*(const NodeItem &other) const;
|
||||||
NodeItem operator/(const NodeItem &other) const;
|
NodeItem operator/(const NodeItem &other) const;
|
||||||
NodeItem operator%(const NodeItem &other) const;
|
NodeItem operator%(const NodeItem &other) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user