The First Cube

by Taylor Hadden | 17:40

So I figure I have to start documenting this process eventually. For the past several months, I’ve been working in my (small amount of) free time on a set of first person movement model, but I’m going to talk about that at a later time. The thing that I’m going to talk about today is a cube.

CubeNice and boring, no? Well like I said, I have to start this process sometime, and at its most basic is a good place to begin. This cube is actually generated dynamically at runtime. The layout of the cube is determined by a voxel octree, which is a type of data structure that dynamically subdivides only as is necessary. That means that for this entire 32x32x32 cube (a total of 32,768 blocks!), only one piece of voxel information is needed.

This means that large geological features, such as massive mountain ranges, can seriously save on the number of individual blocks actually stored and held in memory. Of course, with highly detailed terrain where no two adjacent blocks are the same (still unlikely), you’re going to be storing unique data for each block. The actual performance implications of that will be a battle for another day, however.

Cube-Wireframe

The wireframe of the cube

This octree data structure is then fed into a piece of code that translates the voxel information into a mesh. At that point, Unity takes over and does the grunt work of actually displaying the cube. The mesh generator in these images is configured to use half-meter cubes (it only builds the external faces), but it can be setup to use any cube size to represent the data.

At the moment, I am just generating very simple two-triangle planes for the sides of the cubes, but I plan on introducing more complexity when appropriate for the surface type. For example, a dirt wall isn’t going to be perfectly smooth, and using a rougher piece of geometry for that dirt wall in addition to its texture will greatly add to its sense of physicality.

Cube-Detail

A look at some very basic detail.

For the moment though, I can generate cubes. It’s not much, but it’s a stepping stone. Next time, I’m going to talk more about the usefulness of octree data when it comes to generating collision volumes.