Game Development Reference
In-Depth Information
3. Add indices to the sides of the mesh that are exposed and check the neighbors to
see which ones these are. Then, add six indices (for two triangles) for each mesh
to a list using
GEOMETRY_INDICES_DATA
, as follows:
List<Integer> indices = new ArrayList<Integer>();
for(intdir = 0; dir < 6; dir++){
if(!cube.hasNeighbor(dir)){
for(int j = 0; j < 6; j++){
indices.add(GEOMETRY_INDICES_DATA[dir * 6 + j]);
}
}
}
4. To add these to the mesh, first convert them into an array. Then, set the array as
the index buffer, as follows:
m.setBuffer(VertexBuffer.Type.Index, 1,
BufferUtils.createIntBuffer(indexArray));
5. For texture coords and vertex normals, simply use the data we have already set up
as follows:
m.setBuffer(VertexBuffer.Type.TexCoord, 2,
BufferUtils.createFloatBuffer(GEOMETRY_TEXTURE_DATA));
m.setBuffer(VertexBuffer.Type.Normal, 3,
GEOMETRY_NORMALS_DATA);
6. Now, return the mesh to the calling method.
7. Add one more method called
generateBlock
to the
CubeUtil
class and cre-
ate a 3D array of
CubeCell
and return it. The principle for it is the same as the
heightmap we created in the
Using noise to generate a terrain
recipe, except here
we use three dimensions instead of two. The following code with generate a
CubeCell
class in a 3D pattern:
CubeCell[][][] terrainBlock = new
CubeCell[size][size][size];
for(int y = 0; y < size; y++){
for(int z = 0; z < size; z++){
for(int x = 0; x < size; x++){
double value = fractalSum.value(x, y, z);