An array is an indexed list of values. For example, the data
of the point_position
property of a mesh is an array of float3
values, indexed by the vertex number.
You can get or set an individual value in an array by specifying its index. Arrays in Bifrost use zero-based indexing. This means that in an array of size 5, the index of the first value is 0, not 1, and the index of the last value is 4.
Although negative numbers do not represent valid array indices, the index type is a signed integer (long
).
When a port's type is an array, its shape is wider where it touches the node, resembling a top hat on its side.
Some array ports allow fan-in connections. This means that you can connect multiple connections of either single elements or arrays. All the connected inputs are automatically concatenated into a single input array, similar to using a build_array
node.
To create fan-in ports in your own graphs and compounds, see Create fan-in ports for arrays
There are many nodes for working with arrays in the Core::Array
namespace. In addition, the for-each
and iterate
compounds can be used to loop through the values of an array.
Much of the time, you do not need to loop through an array to process its values. This is because most nodes will automatically loop on the elements of an array when needed.
For example:
add
node, you get a single value as an output. No auto-looping is needed in this case.add
node, the single value is automatically added to every value in the array. The output is another array containing the sums.add
node, the corresponding values of the arrays are added together and the output is also an array. If the arrays have different sizes, the output array is truncated to the size of the smaller input.When auto-looping occurs, it is indicated by a special icon on the affected ports: