Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
                effect.EnableDefaultLighting();
        }
        mesh.Draw();
    }
}

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?

share|improve this question
    
What if you had a mesh part for each face? Then you could texture each part on its own. –  Thraka Aug 2 '12 at 17:28
    
@Thraka: Neither have I enough experience in modelling nor did I create the model myself. Therefore I do not understand what you suggest. –  Christian Ivicevic Aug 2 '12 at 21:33
1  
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? –  Darcara Aug 2 '12 at 22:39
    
@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 :( –  Christian Ivicevic Aug 2 '12 at 23:19
    
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. –  salmonmoose Aug 3 '12 at 6:00
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
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. –  Christian Ivicevic Aug 3 '12 at 9:11
1  
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. –  Darcara Aug 3 '12 at 10:55
    
+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? –  Christian Ivicevic Aug 3 '12 at 11:17
1  
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. –  Darcara Aug 3 '12 at 11:35
    
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? –  Christian Ivicevic Aug 3 '12 at 14:28
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.