Hi!
While searching for good ways to implement level editor to my game, I bumped into voxels as a good alternative. As far as I know, they are three-dimensional representations of pixels. They're not necessarily cubic, they can be, but not necessarily. Together they form a game world and it's up to renderer to decide how voxels are rendered. Please correct me if I'm wrong.
Now, based on this, I came to think of one possible voxel-based editor implementation. Here's the class definition (in C++):
class Voxel{
public:
/// Constructors & destructors:
Voxel(void) = default;
Voxel(Voxel const& voxel_) = default;
Voxel(Voxel&& voxel_) = default;
/// Member functions:
inline Material const& material(void) const;
Voxel& material(Material const& material_);
Voxel& material(Material&& material_);
inline bool const& visible(void) const;
Voxel& visible(bool const& visible_);
Voxel& visible(bool&& visible_);
/// Member functions (overloaded operators, assignment):
Voxel& operator=(Voxel const& voxel_) = default;
Voxel& operator=(Voxel&& voxel_) = default;
/// Static member data:
static Voxel const voxel_null; // This is invisible, default materialized block/voxel.
private:
/// Constructors & destructors:
Voxel(bool&& visible_, Material&& material_);
/// Member data:
bool _m_bVisible;
Material _m_oMaterial;
};
Voxels can be quite tiny. In my case, I intend them to be that way (adds a possiblility of having more details in terrain). I might add
solid()-method later on (don't know if it's necessary, though). Note the static member variable voxel_null, which is an empty voxel with no interesting data in it.
I have ChunkVoxel-class, too (also in C++):
class ChunkVoxel{
public:
/// Constructors & destructors:
ChunkVoxel(void) = default;
ChunkVoxel(ChunkVoxel const& chunk_voxel_) = default;
ChunkVoxel(ChunkVoxel&& chunk_voxel_) = default;
/// Member functions:
inline bool const& visible(void) const;
ChunkVoxel& visible(bool const& visible_);
ChunkVoxel& visible(bool&& visible_);
/// Member functions (overloaded operators, assignment):
ChunkVoxel& operator=(ChunkVoxel const& chunk_voxel_) = default;
ChunkVoxel& operator=(ChunkVoxel&& chunk_voxel_) = default;
private:
/// Member data:
bool _m_bVisible;
union{ // This union allows both one-dimensional and three-dimensional access to voxel data.
Voxel _m_oVoxels[16][16][16];
Voxel _m_oVoxelsUnified[4096]; // Amount of elements: 16^3 = 4096.
};
};
All these classes are work in progress, but to me, they look like quite a good-looking basis.
My ultimate challenging is the rendering: how can one render all these nice voxels in chunks (whenever it is required). What about the editor then? I would like to create editor like these:
">
">
These editors look handy and extremely useful, I would like to create editors like these myself! I'm aware of the fact that C4 engine comes with the source code, even in the standard edition, but come on, 750 dollars!? It's great engine alright, awesome to be honest, but price like that is totally out of my reach.
Anyway, few more questions: would it be wise to have an editor, which can export voxel-based geometry into 3D models (like .3ds or .obj or some custom file formats) so that, in game, voxels no longer need to be converted into triangles? Better performance, you know?
So, what do you think of all this?