Unigine.TileSet Class
This class is used to manage a regular tileset of the ObjectTerrainGlobal. The tileset can have an arbitrary number of tiles. Each tile is represented by the following elements:
- Data - an image with tile data.
- Mask - a single-channel image describing data weights.
In case if a tile has no mask, all weights are considered equal to 1.
Tileset Class
Members
int getImageType()
Returns a numerical code of the image type used in the tileset.Return value
Image type identifier. See the FORMAT_* variables.int setTileData(ivec2 tile_coord, Image data)
Sets the data for the specified tile by copying from the source image.Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
- Image data - Source image containing a new tile data to be set.
Return value
1 if the data of the tile was successfully set; otherwise, 0.int getTileData(ivec2 tile_coord, Image data, int force = 1)
Copies the data of the specified tile to the given image instance.Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
- Image data - Image to which the tile data is to be copied.
- int force - Force flag.
- If 1 is specified, the data will be copied immediately.
- If 0 is specified, data copy operation will be queued to a separate thread.
It is recommended to set this flag to 0 when possible to avoid spikes.
Return value
1 if the tile data was successfully copied to the image; otherwise, 0.int getTileDataState(ivec2 tile_coord)
Returns the state of the data for the tile with specified coordinates.Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
Return value
Tile data state. One of the TILE_STATE_* values.int getTileResolution()
Returns the tile resolution of the tileset.Return value
Tile resolution, in pixels.Tiles are square and have the same number of pixels in both dimensions.
ivec2 getTileCoord(dvec2 flat_position)
Returns the coordinates of the tile containing the given point on the terrain.Arguments
- dvec2 flat_position - Coordinates of the point on the terrain (X, Y).
Return value
Tile coordinates in the tileset (X, Y).int reloadTileData(ivec2 tile_coord)
Reloads the data for the tile with specified coordinates from the tileset file .Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
Return value
1 if the tile data was successfully loaded from the tileset file; otherwise, 0.dvec2 getTilePixelFlatPosition(ivec2 tile_coord, vec2 pixel_coord, int use_half_pixel_offset = 0)
Returns the coordinates of the point on the terrain (X, Y) corresponding to the specified pixel of the given tile.Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
- vec2 pixel_coord - Pixel coordinates on the tile (X, Y).
- int use_half_pixel_offset - 1 to use half-pixel offset; 0 to use zero-offset.
Return value
Coordinates of the point on the terrain (X, Y).int isTileMaskLoaded(ivec2 tile_coord)
Returns a value indicating if a mask is loaded for the tile with the specified coordinates.Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
Return value
1 if a mask is loaded for the tile; otherwise, 0.vec2 getTilePixelCoord(dvec2 flat_position, int use_half_pixel_offset = 0)
Returns the local tile coordinates of the pixel corresponding to the specified point on the terrain. To determine the tile that contains this pixel use the getTileCoord() method.Arguments
- dvec2 flat_position - Coordinates of the point on the terrain (X, Y).
- int use_half_pixel_offset - 1 to use half-pixel offset; 0 to use zero-offset.
Return value
Local tile coordinates of the pixel (X, Y).int saveTile(ivec2 tile_coord, int force = 0)
Saves changes of the specified tile to the tileset file.Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
- int force - Force flag.
- If 1 is specified, the changes will be saved immediately.
- If 0 is specified, the saving operation will be queued to a separate thread.
It is recommended to set this flag to 0 when possible to avoid spikes.
Return value
1 if changes of the specified tile were successfully saved to the tileset file; otherwise, 0.int saveAll(int force = 1)
Saves changes of all tiles to the tileset file.Arguments
- int force - Force flag.
- If 1 is specified, the changes will be saved immediately.
- If 0 is specified, the saving operation will be queued to a separate thread.
It is recommended to set this flag to 0 when possible to avoid spikes.
Return value
1 if all changes were successfully saved to the tileset file; otherwise, 0.float getLifeTime(ivec2 tile_coord)
Returns the current lifetime of the tile. This parameter determines how long the specified tile will be kept in the RAM without being accessed.Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
Return value
Tile lifetime, in seconds.int getDataFormat()
Returns a value indicating current image format for the tile data.Return value
Tile data image format. One of the Image.FORMAT_* values.int getMaskFormat()
Returns a value indicating current image format for the tile mask.Return value
Tile mask image format. One of the Image.FORMAT_* values.string getPath()
Returns the path to the tileset file.Return value
Path to the tileset file.int getTileMask(ivec2 tile_coord, Image mask, int force = 1)
Copies the mask of the specified tile to the given image instance.Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
- Image mask - Image to which the tile mask is to be copied.
- int force - Force flag.
- If 1 is specified, the mask will be copied immediately.
- If 0 is specified, mask copy operation will be queued to a separate thread.
It is recommended to set this flag to 0 when possible to avoid spikes.
Return value
1 if the tile mask was successfully copied to the image; otherwise, 0.int removeTileMask(ivec2 tile_coord)
Removes the mask of the tile with specified coordinates from the tileset.This method does not remove the mask from the tileset file.
Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
Return value
1 if the mask of the tile was successfully removed from the tileset; otherwise, 0.int setTileMask(ivec2 tile_coord, Image mask)
Sets the mask for the specified tile by copying it from the source image.Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
- Image mask - Source image containing a new tile mask to be set.
Return value
1 if the mask of the tile was successfully set; otherwise, 0.int reloadTileMask(ivec2 tile_coord)
Reloads the mask for the tile with specified coordinates from the tileset file .Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
Return value
1 if the tile mask was successfully loaded from the tileset file; otherwise, 0.float getTileDensity()
Returns the tile density (number of pixels per unit) of the tileset.Return value
Tile density, in pixels per unit.int hasTileFileMask(ivec2 tile_coord)
Returns a value indicating if the tile with specified coordinates has a mask in the tileset file.Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
Return value
1 if the specified tile has a mask in the tileset file; otherwise, 0.int hasTileMask(ivec2 tile_coord)
Returns a value indicating if the tile with specified coordinates has a mask in the tileset.Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
Return value
1 if the specified tile has a mask in the tileset; otherwise, 0.int isTileDataLoaded(ivec2 tile_coord)
Returns a value indicating if data is loaded for the tile with the specified coordinates.Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
Return value
1 if data is loaded for the tile; otherwise, 0.int getTileMaskState(ivec2 tile_coord)
Returns the state of the mask for the tile with specified coordinates.Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
Return value
Tile mask state. One of the TILE_STATE_* values.float getTileSize()
Returns actual tile size in the tileset.Return value
Tile size, in units.int hasTile(ivec2 tile_coord)
Returns a value indicating if there is a tile with specified coordinates in the tileset.Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
Return value
1 if there is a tile with specified coordinates in the tileset; otherwise, 0.int hasTileFile(ivec2 tile_coord)
Returns a value indicating if there is a tile with specified coordinates in the tileset file.Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
Return value
1 if there is a tile with specified coordinates in the tileset file; otherwise, 0.int removeTile(ivec2 tile_coord)
Removes the tile with specified coordinates from the tileset.This method does not remove the tile from the tileset file.
Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
Return value
1 if the tile was successfully removed from the tileset; otherwise, 0.int setLifeTime(ivec2 tile_coord, float seconds)
Sets the lifetime for the specified tile This parameter determines how long the specified tile will be kept in the RAM without being accessed.Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
- float seconds - Tile lifetime, in seconds.
Return value
1 if the lifetime for the specified tile was successfully set; otherwise, 0.dvec2 getTileFlatPosition(ivec2 tile_coord)
Returns the coordinates of the point on the terrain (X, Y) corresponding to the top-left corner of the specified tile.Arguments
- ivec2 tile_coord - Tile coordinates in the tileset (X, Y).
Return value
Coordinates of the point on the terrain (X, Y).float fetchData(Vec2 position, out vec4 result, int layer, bool force)
Fetches the data for the specified point on the terrain and puts it to the output vector.Arguments
- Vec2 position - Coordinates of the point on the terrain (X, Y).
- out vec4 result - Output vector to store the data retrieved for the specified point.
- int layer - Layer number.
- bool force - Force flag.
- If 1 is specified, the data will be fetched immediately.
- If 0 is specified, the operation will be queued to a separate thread.
It is recommended to set this flag to 0 when possible to avoid spikes.
Return value
1.0f if the data was fetched successfully; otherwise, 0.0f.int TILE_STATE_NONE
Description
The tile in the tileset does not differ from the tile in the tileset file (standard tile state).int TILE_STATE_MODIFIED
Description
The tile in the tileset is modified.int TILE_STATE_REMOVED
Description
The tile in the tileset is removed.Last update: 2018-08-10
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)