# Class: tbterrain

tiletexture-based terrain, uses elevation data and surface layers, which are organized as tiles.
Every tile has 4 layers of surfacetiles. You can use up to 256 surfacetiletypes, each with a unique texture. However on an area of 32x32 tiles no more than eight textures can be used.

## Hierarchy

    o-+ resource
      o-+ tbterrain

## Methods:

### Method overview:

- createatlas
- createblank
- createfinish
- createfromtex
- defaultpath
- forcreate
- getcoords
- getheights
- getrestype
- height
- savecolor
- saveheight
- savesurface
- size
- surfacelayer
- surfacetile
- tilecolor
- tileheight
- tilesurf
- tileupdate

createatlas (tbterrain)
  returns: ([texture])
  each terrain instance should have its own atlas texture. With this function you can generate one. (uses current active resource chunk)
createblank (string name, int width,int height, float heightfactor)
  returns: (tbterrain)
  creates a new tbterrain. Dimensions must be >= 32.
  After setting all used tiletypes and layers run the newfinish function.
createfinish (tbterrain)
  returns: ()
  initializes all needed data for rendering. Set all known tiletypes and layers before
createfromtex (string name, texture heightmap, float heightfactor, [texture colormap])
  returns: (tbterrain)
  creates a new tbterrain using the given elevation and color data. Make sure the textures kept their data, and you can free the data afterwards. If the heightmap has 4 colorvalues it is used as float texture, else the red value is multiplied by heightfactor.
  After setting all used tiletypes and layers run the createfinish function.
defaultpath ([string])
  returns: ([string])
  returns or sets the default resource path. Luxinia will search in those when resources are not found.
forcreate ([int tilesize, int atlascount])
  returns: ([int tilesize, int atlascount])
  default specifications for newly generated terrains. Tilesize is the length of a single tile. Atlascount is the number of surfacetiles that can be active within current visible block.
  All values passed must be even > 1, and atlascount should be power of 2.
getcoords (tbterrain,float x,y,z)
  returns: (int x,y)
  converts world position into terrain coords
getheights (tbterrain)
  returns: (floatarray)
  returns a mounted floatarray, in which you can directly access heights of the terrain grid. There is steps*2+1 floats for each dimension.
getrestype ()
  returns: (int restype)
  returns the resource type as int value, useful for resdata or reschunk functions
height (tbterrain self, float x,y)
  returns: (float height)
  returns interpolated height at x/y
savecolor (tbterrain,string)
  returns: (boolean)
  stores colormap to given file (TGA)
saveheight (tbterrain,string, [boolean precise])
  returns: (boolean)
  stores heightmap to given file (TGA). By default stores only red channel into RGB, if precise is set then RGB as utilized as 24 BIT precision
savesurface (tbterrain,string, int layer)
  returns: (boolean)
  stores surface layer to given file (TGA)
size (tbterrain)
  returns: (int width,height)
  returns width and height of terrain
surfacelayer (tbterrain,int layer, data texture)
  returns: ()
  sets the given layer with the data from the data texture.
surfacetile (tbterrain,int id, string tiletexturename)
  returns: ()
  creates a new surface tile using the given id (1..255) and creates a special texture from the given texturename.
tilecolor (tbterrain,int x,int y,[float r,g,b,a])
  returns: (float r,g,b,a)
  returns or sets tile color
tileheight (tbterrain,int x,int y,[float float])
  returns: ([float])
  returns or sets tile height
tilesurf (tbterrain,int x,int y,int layer,[int id])
  returns: ([int id])
  returns or sets tile surface id
tileupdate (tbterrain,int x,int y,[int region])
  returns: ()
  updates tile, makes changes effective, optionally a whole region

## Inherited Methods:

### From resource

condition, getresname, getresshortname, resuserstring