Space filling curves for 'concentric' flood filling?

Started by
1 comment, last by Anfaenger 7 years, 10 months ago

I'm writing a chunk-based voxel engine and I need to gradually load and grow the area around the player.

My chunks are organized in a 3D 'matrix' ('rolling' array with toroidal ('modulo') addressing) representing the visible (rectangular) region of chunks.

The 'matrix' is stored as a 1D array of chunks, each chunk contains its status, the mesh pointer, etc.

I decided to use a simple flood-fill algorithm for determining which chunks to load first after an empty world is created.

But a (non-recursive) flood-fill relies on a queue (for storing the next chunks to process) and performs 8 steps in each direction (with ugly checks, and most of them fail).

Is there a neat space-filling curve for linearizing the 3D 'matrix' which allows to visit chunks in a closest-to-far manner, starting from any given player position inside the cube? The curve should be reasonably simple and quick, and (of course) not 'intersect' already visited elements. Is there anything more efficient (or elegant) than hardcoded 'spiral curve'?

The advantage of using a space-filling curve is that instead of storing an array of chunks to be processed you could store a single value (e.g. the position of the last processed chunk encoded in an int).

(and I have trouble figuring out on paper how to code even the simplest 3D 'cubic spiral' curve.)

Advertisement

You might want to look into n-ary Gray codes https://en.wikipedia.org/wiki/Gray_code#Special_types_of_Gray_codes

They define a hamiltonian path, which is what you are looking for

(3 bit binary gray code is a hamiltonian path of a cube, but if you want to fill further, you need 3 digits with higher values)

If I understood correctly, Gray codes allow to visit vertices of the cube once,

but I need to walk over the whole surface of the cube.

I'm looking for a (bijective) mapping from integer points on the cube surface to single integers and vice versa (not necessarily a space-filling curve).

btw, it seems in 3D there are no space-filling spiral curves:

https://www.reddit.com/r/math/comments/1vfxk3/is_there_a_3_dimensional_space_filling_spiral/

This topic is closed to new replies.

Advertisement