Hey. So instead of working on my games or tutorials, I messed around in the game engine, heh. This time, the subject that I was interested in was voxels. I tried to use them before, with pretty poor results, as I couldn't get a large number of voxels to render in the BGE. Well, I then had an idea, which I tried to implement into the BGE, with pretty good results.
Unfortunately, the BGE can't do this, merging meshes together. Neither can it add or delete
faces from meshes. However, you can manipulate the faces that are there.
So, what I did was create many, many cubes in a single object (they
don't have to be cubes; they can just be detached faces). Then, I wrote a
function that I call Flatten, which takes other objects' meshes and
applies their vertex values to the source mesh (the cube-packed 'fodder'
object that you see below).
So the idea is that the game first places a lot of objects (cube
placeholders, really), and they are all set to be invisible. Then, the
game adds the faces for the cubes, which are all in one object to draw
in a single batch. Finally, the Flatten function moves each of those vertices
(and UV and normal values) to align to each vertex in each invisible
cube placeholder, ending up with the result you see above. The remaining
faces are pushed down 100000 BU (or whatever number) so that they're outside the camera's
view frustum (and so, the camera won't draw those faces).
There's one major upside to this method - it runs very quickly. Unfortunately, there are also two downsides to this method.
1. All faces have to have the same material and texture. Since the faces
aren't individual objects, you can't replace their mesh, and changing
materials for faces isn't supported by the BGE (as of yet). Fortunately,
the script copies UV values, so different blocks would indeed appear
different, as long as they were all on a single texture image.
2. It requires that you have enough faces available in a 'fodder' object to
supplement each 'chunk' of land. The larger the chunk, the more faces
each 'fodder' object must have to cover it. This makes the game start up
slowly if your chunk data's large (not even add the mesh slowly, just
starting up and loading the polygons into memory is kinda slow).
Fortunately, you only have to have one chunk data, as you can use LibNew
to make a new mesh from the first one. Currently, it's pretty usable.
This has a lot of implications for both Minecraft-like block based
games, as well as games with a large amount of place-able and
So... Anybody want to try an open-source Minecraft from this?
You can download the demo for yourself here. It's made for Blender 2.6. By the way, if you do use the scripts or assets, you may not distribute them outside of personal projects without prior consent from me, the author.