Building a mesh from "voxels"

I’m playing around with a voxel-based world, but instead of simply rendering a huge amount of boxes i want to build a new mesh from a group/chunk of voxels/boxes.
I’m having some problems with that though as i can’t seem to get the vertexes right.

The code is Scala, not Java (sorry) and i’ve tried to clean out as much unnecessary parts as possible.

// visibleFaces = current voxels visible sides (if any)
// x,y,z = current voxels coordinates
// Voxel.size = the size of a single voxel/cube (currently 0.75u)
// addVertexes & addIndexes adds points and indexes to lists thats later used for setBuffer in a Mesh
visibleFaces.foreach(face => {
vertexMesh.addVertexes(Face.buildNormalFaceVertextes(face).map(point => point.add(x, y, z).mult(Voxel.size)) : _)
vertexMesh.addIndexes(Array(0,1,2, 2,3,0).map(index => index + vertexMesh.vertices.length) : _


def buildNormalFaceVertextes(faceDirection: Vector3f): Array[Vector3f] = {
(faceDirection match {
case Top => Array(0,1,0, 0,1,1, 1,1,1, 1,1,0)
case Bottom => Array(0,0,0, 0,0,1, 1,0,1, 1,0,0)
case Right => Array(1,0,1, 1,0,0, 1,1,0, 1,1,1)
case Left => Array(0,0,1, 0,0,0, 0,1,0, 0,1,1)
case Front => Array(0,1,1, 0,0,1, 1,0,1, 1,1,1)
case Back => Array(0,1,0, 0,0,0, 1,0,0, 1,1,0)
}).sliding(3).map(coords => new Vector3f(coords(0), coords(1), coords(2))).toArray


// In a class that extends Mesh:
def buildMesh() {
setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices : _))
setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(textureCoords : _
setBuffer(Type.Index, 3, BufferUtils.createIntBuffer(indexes : _*))

For those of you not familiar with Scala, : _* “flattens” an array/list into a list of parameters for a method.

This is the result:

Some of the triangles are correct, but many are not there at all or in the wrong place.

Do you have the order of the tirangles false? Its defined if clockwise or counterclockwise is front, (and in both directx and opengl its different XD)

I’m not 100% sure I’m following the logic but if you do the indexes the way you are (after you’ve added the vertexes) then won’t they always be one face off?

That doesn’t really explain the error you are seeing, I guess. So far I can’t even figure out why you only see one triangle of the quad. I can tell you that some of your ordering is backwards. For example, Front will be properly counter clockwise but Back is backwards.