Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/swift502/octarr

Dynamic array-like octree written in C#.
https://github.com/swift502/octarr

array csharp dynamic octree

Last synced: 7 days ago
JSON representation

Dynamic array-like octree written in C#.

Awesome Lists containing this project

README

        





Example of using Octarr to store voxels and visualizing octree nodes using the DrawTree debug function

# Octarr

Stands for octree based 3D array.

Octarr is a dynamic cubic octree capable of storing class data, accessed via indexers. Written in C#, based on the C++ [Cubic-octree](https://github.com/markusgod/cubic-octree).

Basically a generic endless 3D array, which can be accessed like regular arrays and grows and shrinks depending on how much space needs to be allocated. Location index can be positive or negative in any direction. Octarr is centered around the zero coordinate (0, 0, 0), and grows and shrinks _from_ and _to_ this zero coordinate.

Unlike multidimensional or jagged arrays, octarr is memory friendly. You can write a data block at the `[2^64, 2^64, 2^64]` position and not run out of memory. It will then take roughly 64 octree node lookups (logarithmic complexity) to find that data, or anything near it. Octarr is internally using the [BigInteger](https://docs.microsoft.com/dotnet/api/system.numerics.biginteger) data type to allow for unconstrained data location.

```cs
// Usage
public Octarr octarr = new Octarr(); // Create an octarr
octarr[10, -20, 30] = new Data(); // Write
Data data = octarr[10, -20, 30]; // Read assigned, returns your object
data = octarr[1, 2, 3]; // Read unassigned, returns null

// Debug
int nodeCount = octarr.GetNodeCount(); // Count all octree nodes
octarr.DrawTree((float x, float y, float z, float halfSize) =>
{
DrawBox(x, y, z, halfSize); // Draw the octree using your own box drawing function
});
```

## Limitations

Data is currently required to be classes. If you want to store structs (int, string, etc.) it'll require some simple modifications and a definition of a default data value other than null.