Work with arrays

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

Array ports

When a port's type is an array, its shape is wider where it touches the node, resembling a top hat on its side.

Array port

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.

Fan-in, collapsed

Fan-in, expanded

To create fan-in ports in your own graphs and compounds, see Create fan-in ports for arrays

Nodes for working with 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.

Auto-looping

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:

When auto-looping occurs, it is indicated by a special icon on the affected ports:

Auto-loop