Several graph node types evaluate mathematical expressions at runtime. These are the Function nodes documented in the node reference, including FunctionScalarToScalar, FunctionVectorToScalar, FunctionVectorToVector, and FunctionVectorToColor. Expressions are stored as string properties on the node (for example, the StringGraphNodeProperty named function).
Nodes with a vector input that has no incoming connection receive the evaluation point implicitly. That is how cell-shape functions such as a gyroid receive x, y, and z without an explicit wire in the graph.
The API provides several nodes that allow the user to specify functions to be evaluated on the node inputs. These functions are specified as a string property belonging to the node. There is a specific syntax that must be followed when writing these functions, and the supported operations are detailed below:
Scalar - 'x' - scalar input
Vector - 'x', 'y', and 'z' are the inputs that match the input vector format.
Color – No function node has a color input.
Scalar output property name: 'function'.
Vector output property names: 'x', 'y', and 'z'.
Color output property names: 'r', 'g', 'b', and 'a'.
Addition '+'
Usage: 'a + b'
Subtraction '-'
Usage: 'a - b'
Multiplication '*'
Usage: 'a * b'
Division '/'
Usage: 'a / b'
Exponentiation '^'
Usage: 'a^b'
Modulo 'mod'
Usage: 'mod(a, b)'
Maximum 'max'
Usage: 'max(a, b)' or 'max(a, b, c)'
Note: Maximum can have a variable number of inputs
Minimum 'min'
Usage: 'min(a, b)' or 'min(a, b, c)'
Note: Minimum can have a variable number of inputs
Power 'pow'
Usage: 'pow(a, b)'
Note: a raised to the power of b
Norm 'norm'
Usage: 'norm(a, b)'
Norm Squared 'norm2'
Usage: 'norm2(a, b)'
Clamp 'clamp'
Usage: 'clamp(value, minimum, maximum)'
Returns: max(minimum, min(value, maximum))
Select 'select'
Usage: 'select(value1, value2, outVal1, outVal2)'
Arguments:
value1: First value to compare
value2: Second value to compare
outVal1: First output value
outVal2: second output value
Returns: if a < b ? c else d
Floor 'floor'
Usage: 'floor(a)'
Ceil 'ceil'
Usage: 'ceil(a)'
Round 'round'
Usage: 'round(a)'
Sine 'sin'
Usage: 'sin(a)'
Cosine 'cos'
Usage: 'cos(a)'
Tangent 'tan'
Usage: 'tan(a)'
ArcSine 'asin'
Usage: 'asin(a)'
Arccosine 'acos'
Usage: 'acos(a)'
Arctangent 'atan'
Usage: 'atan(a)'
Absolute Value 'abs'
Usage: 'abs(a)'
Logarithm 'log'
Usage: 'log(a)'
Exponential 'exp'
Usage: 'exp(a)'
Square Root 'sqrt'
Usage: 'sqrt(a)'
Arctangent2 'atan2'
Usage: 'atan2(a, b)'
Pi - 'pi'
Pi multiplied by 2 - 'pi2'
Euler's Number - 'e'
The following gyroid cell-shape expression is taken from the Volumetric Custom Feature Sample:
cellGraph = volumetricModel.getGraph(adsk.volume.GraphTypes.CellGraphType)
gyroidNode = cellGraph.nodes.add("gyroid", "FunctionVectorToScalar")
gyroidNode.properties.itemByName("function").value = (
"(sin(x*pi2)*cos(y*pi2)+sin(y*pi2)*cos(z*pi2)+sin(z*pi2)*cos(x*pi2))*0.333333333+0.5"
)