Volumetric Function Expression Syntax

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.

Function Syntax

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:

Example

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"
)

Related topics