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.

Are there any elegant soloution to generate a simple-six sided cube, where each cube is made out of more than one face? The method I have used ended up a horrible and complicated mess of logic that is imopssible to follow and most likely to maintain. The algorithm should not generate reduntant vertices, and should output the indice list for the mesh as well.

The reason I need this is that the cubes vertices will be deformed depending on various factors, meaning that a simple six-faced cube will nto do.

share|improve this question
    
What you mean by multifaced? Every cube has at least 6 faces. –  Miro Aug 17 '12 at 23:17
    
I suppose the term you're looking for is tesselation. –  Jari Komppa Sep 17 '12 at 10:35
add comment

1 Answer

The way I'd approach this is to first write an algorithm that generates the mesh for just one side of the cube - that is, just a square, subdivided into as many polygons as you want. This should be easy to get right since it's just a grid.

Run this six times to generate the six sides of the cube, then concatenate all the meshes together and weld the shared verts at the edges and corners. The welding can be accomplished by explicitly keeping track of the edges and corners of each square during the initial generation and concatenation phases and hard-coding the logic for which ones should be welded together, or it can be done by a generic algorithm that detects pairs of vertices within a certain distance of each other and welds them. (For the latter you'd probably want to build an octree or something to accelerate queries for nearby vertices, else the whole thing will be O(n^2), not good if you subdivide finely and have a lot of vertices.)

share|improve this answer
add 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.