How To

Storing an Octree

3

McPepic 2023-03-31 20:36

So while I was messing with my 3D Ray marching program, I thought it would be cool to try and implement a voxel-based engine. After a lot of thought and research, I decided on having an octree-based system where I split the world up into "layers".

The first layer could be 64x64x64 voxels. All I'd have to keep track of for this area is whether or not there are any blocks. If not, I'd have a ray that I could move along to the edge of the area, knowing that there's nothing for the ray to hit in the current chunk.

If there was at least one block in the chunk, though, then I'd go one layer deeper where each chunk in the new layer has half the dimensions of the previous layer (ie 64x64x64 => 32x32x32)

I was just wondering what the most efficient/fastest way to store this would be. Also, if you have any more considerations, that would be helpful.


Timo 2023-04-01 08:17

NX‘s Basic is definitely not made for this stuff.
I have to check the max dimensions allowed…


Timo 2023-04-01 08:21 (Edited)

4 dimensions.
Anyway, there is a bigger issue:
DIM A(63,63,63)
This array is already too big and throws an error :(
You could do workarounds by using more arrays, but then your code will get messy.


McPepic 2023-04-01 14:48

@Timo
Yeah, I realize that might be too big. I was mostly using it for an example. 16x16x16 would work much better, as it only takes 4 thousand elements out of the maximum 32 thousand for arrays. I was thinking before about storing data in strings, but that causes more problems. It’s better to get it working on a small scale anyways.


SP4CEBAR 2023-04-05 14:28

you could almost store 64^3 bits: you need $8000 bytes, which can almost be done


Log in to reply.