

= 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


image::http///destroflyer.mania-community.de/other/imagehost/cubes/heightmap_australia.jpg[heightmap_australia.jpg,with="",height="",align="right"]

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:


[source,java]

----
//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:


image:http///destroflyer.mania-community.de/other/imagehost/cubes/test_australia.png[test_australia.png,with="800",height=""]



== 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
