Heightmaps

Most of you will know the term “heightmap - Those are images (normally gray-scaled), which describe a terrain. Each pixel is a point on the surface: The brighter the pixel, the higher the terrain at this location. Easy, huh?

“Cubes offers a way to load those heightmaps to generate your blockworld - You specify the image, the frameworks loads it and adds blocks that look like it.

Loading heightmaps

heightmap_australia.jpg

When specifying the heightmap, you can tell the framework where to set the blocks and how to scale them - As an example, let’s rebuild australia in our blockworld:

//Create the block terrain (7x1x7 chunks)
BlockTerrainControl blockTerrain = new BlockTerrainControl(new Vector3Int(7, 1, 7));

//Specify location, heightmap filepath, maximum height and the block class
//(See the heightmap at the right)
blockTerrain.setBlocksFromHeightmap(new Vector3Int(0, 1, 0), "Textures/cubes/heightmap_australia.jpg", 10, CubesTestAssets.BLOCK_GRASS);

//Add the block terrain to a node
Node terrainNode = new Node();
terrainNode.addControl(blockTerrain);
rootNode.attachChild(terrainNode);

After running this code (and adding nice water and shadow effects :P), you should see this:

test_australia.png

Important notes

  • The size of your heightmap defines how large (X, Z) the terrain will be (1px = 1 block)

  • The heighest block will be at a height of (StartY + MaximumHeight)

  • Black pixels (R|G|B = 0|0|0) means that no block will be set

Further improvements

  • You will be able to scale the loaded blocks by the X and Z axis, too

  • It will be possible to specify a loader, that selects a “suitable block type dependant on the location