Latest updates# Description of the problem that is addressed in the patch.
Starting changes to accept equation as an inputThe Attribute Math node currently allows the user to use mathematical functions with 1, 2 or 3 variables, and combine multiple such functions together using multiple instances of the same node.
However, a mathematical operation with multiple operators and functions - like `(x * sin(x)^2 - b)*c` - requires at least 4 nodes to implement, and is hard to grok in a node tree with multiple such operations.
Fix# Description of the proposed some compilolution, and a motivation errorsas to why this is the best solution.
In progress codeThe proposed solution adds an Attribute Math Expression node, that accepts arbitrary mathematical expressions using one or more of the functions already available with the Attribute Math node. Additionally a "negate" operation has been added to support the unary minus operation.
Build error after using evaluate() method.# List of alternative solutions, Unresolve externaland a motivation as to why these are undesirable.
Created header file so other code can execute expressions,Parsing mathematical expressions isn't new, and there are multiple implementations of this available. Examples are libmatheval, other similar math calculators, expression parsers using antlr, etc. However, including these with blender would increase the dependencies on other libraries (antlr, yacc/lex, etc) increasing the build time and footprint of Blender which is long enough as it stands.
I have implemented a simple version of the shunting yard algorithm with some modifications to support function calls and multi-parameter functions.
The expression parser has been abstracted externally, and is intended to evolve to a shell using multiple possible parsing strategies, like vector math for example.
The new node offloads the user entered expression to this parser, and evaluates it for each index of the span result. but build is still failingAny errors (exceptions) reported by the parser are relayed to the user using node errors.
The parser itself offloads the execution of individual operands and functions to NOD_math_functions.hh similar to how the Attribute Math node does it.
Seems to be working!A similar approach can be used to create a generic Math Expression (the not-Attribute kind) node that can be used in multiple node editors like Geometry and Shader.
Removed dummy implementationIf support for new functions is added to blender, it is a matter of creating some additional configurations to leverage them in this editor.
Fixed compil# Limitation error in static typess of the proposed solution.
Attempt to fix missing node in blender and change references to equation to expressionI have currently not implement unit tests, as I haven't figure GTest out yet.
Fixed rna_nodetree.c but python still can't find GeometryNodeAttributeExpression# Mock-up of the proposed user interface and a description of how users are going to interact with the new feature.
Fixed python error for creating the new node.
Changed node name to 'Attribute Math Expression' in UI.
Moved expression parser to external file in nodes intern/ folder.
Removed redundant headers.
Create only one instance of the parser for every time the calculation needs to happen.
Added some error handling.
Added support for constants. Improved error handling. Fixed bug in parsing operations after between two closing brackets. Removed dump methods.
Added support for multi-parameter functions.
Removed commented code, readying for arc patch.
Fixed unused variable compilation warning for 'success'.A mockup is provided at:
https://blender.community/c/rightclickselect/Nshbbc/