Octarr

2021
C#

Octarr is an endless 3D array system based on an octree. While working on a Godot project, I needed a way to easily store voxels in an otherwise polygonal world. This seemed like an interesting solution and an opportunity to understand how octrees work.

Soon enough I had a working iteration and could place voxel blocks in the world. The green lines show used octree nodes. Unlike multidimensional or jagged arrays, Octarr is memory friendly. You can write a data block at the 2^64 coordinate and not run out of memory. That was the main obstacle which I managed to overcome using this system.

// Create an octarr
public Octarr<Data> octarr = new Octarr<Data>();

// Write
octarr[10, -20, 30] = new Data();

// Read
Data data = octarr[10, -20, 30];

// Delete
octarr[10, -20, 30] = null;

Octarr carries a user specified data type, and C# array indexers are utilized for data manipulation. Octarr's size is completely dynamic, so there's no need to initialize array size before writing data.

To find a block placed at a 2^64 coordinate it takes roughly 64 octree node lookups (logarithmic complexity). A block placed that far begins to cause floating point precision errors in the debug rendering.

Feel free to check out the project's repository on GitHub!

Back to projects