I am creating a 3D level editor which should be used to generate the very basic layout (level geometry) and a few basic game-logic entities of maps used in my game. So far, I decided to use voxels (i have a fbx untextured model file and do NOT draw this myself via vertices etc. as I already found tutorials on that which are not suitable for me) as the way to create the level geometry and most of this works fine. The next step would be to implement code that allows me to texturize these cubes by specifically applying textures to faces.

Using something like the following Draw method I can apply a Texture2D to the whole voxel (so I am not able to chose the face to which I want to apply the texture) and this works fine for now (though I have sometime issues orienting it, which should not be part of this question)

public void Draw() {
    foreach(ModelMesh mesh in this.Model.Meshes) {
        foreach(ModelMeshPart part in mesh.MeshParts) {
            BasicEffect effect = (BasicEffect)part.Effect;

            effect.World = this.World;
            effect.View = Engine.View;
            effect.Projection = Engine.Projection;

            if(this.Texture != null) {
                // UNLIT textures
                effect.Texture = this.Texture;
                effect.TextureEnabled = true;
            } else
                // LIT placeholder voxel

I will have about 10 textures which I want to be able to apply programmatically on each face of the voxels - which approach would you suggest me to achieve the desired result?

  • \$\begingroup\$ What if you had a mesh part for each face? Then you could texture each part on its own. \$\endgroup\$
    – Thraka
    Commented Aug 2, 2012 at 17:28
  • \$\begingroup\$ @Thraka: Neither have I enough experience in modelling nor did I create the model myself. Therefore I do not understand what you suggest. \$\endgroup\$ Commented Aug 2, 2012 at 21:33
  • 1
    \$\begingroup\$ This seems to be an incredibly ineffective way of drawing multiple single voxels and might not work at all that way. How many voxels do you expect to draw and can you alter the mesh or create a new one? Are the individual mesh parts the faces of the voxels? \$\endgroup\$
    – Darcara
    Commented Aug 2, 2012 at 22:39
  • \$\begingroup\$ @Darcara: Thinking about the efficiency I have approximated an upper bound of 750 entities (unmerged voxels + custom entities) for a level - after some optimization it would be easy to merge voxels to bigger blocks (and therefore decreasing the number of entities) but at the beginning I have to have the option to build the world with voxels and individually choose the material (texture) on their visible faces during the creation. Concerning the structure of the model... I have no idea as I have used one box I found in a sample project - shame on me :( \$\endgroup\$ Commented Aug 2, 2012 at 23:19
  • \$\begingroup\$ Do you have access to the UV's? Unless I'm misunderstanding this a texture-map and modified UV's will do this for you. \$\endgroup\$ Commented Aug 3, 2012 at 6:00

1 Answer 1


For a small amount of voxels you could try cube maps with one texture per voxel. This is however quite wasteful and wasteful, and will not scale. Alternatively, if each face has its own texture coordinates you can create a texture atlas and modify the texture coordinates of each mesh.

The next best thing would be to create a mesh where each ModelMeshPart is one face of your cube. Then you can set the texture for each face individually. This will however still not scale very well, but should fast enough for 750 cubes.

  • \$\begingroup\$ As far as I know and understand cube maps, they are used for reflections and therefore I do not see how they could be used to do what I want. Nevertheless your second approach seems quite convincing to me - one could maybe combine this with face culling. I will have a look into Blender and consider this a good solution, but I want to see what other people suggest me as alternatives. \$\endgroup\$ Commented Aug 3, 2012 at 9:11
  • 1
    \$\begingroup\$ I meant cube maps like the sky box here, but mapping it to the outside of the box. It's just a way of mapping a texture to the 8 vertices of the cube such that each vertex needs only one set of texture coordinates, but it still seems seamless. \$\endgroup\$
    – Darcara
    Commented Aug 3, 2012 at 10:55
  • \$\begingroup\$ +1 for Half Life reference! - Now I understand, I could create unwrapped textures for all possible combinations of materials precreated (which would be overkill so maybe I could create this texture during runtime) and then applying it to the voxels. Do you have any references to look up on this procedure? \$\endgroup\$ Commented Aug 3, 2012 at 11:17
  • 1
    \$\begingroup\$ You have to generate at runtime, unless all combinations are known beforehand, because with only 10 textures there are 10^6 possible combinations. Creating a cube map is relatively easy. Look at the numbered view here, you'll see that each square corresponds to one face. Create a big enough RenderTarget2D (it's Texture2D) and draw your stock textures into the right places using SpriteBatch. Now the render target is the texture that contains your cube map. \$\endgroup\$
    – Darcara
    Commented Aug 3, 2012 at 11:35
  • \$\begingroup\$ I was able to draw the RenderTarget2D and assign it to the cube but it does not wrap automatically! What is the general approach to wrap this cube map around the cube? \$\endgroup\$ Commented Aug 3, 2012 at 14:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .