Class ChunkMeshLayer
Represents a terrain layer for a chunk mesh, providing data structures and operations for managing cell heights, biomes, transparency, and cell metrics within a hex-based terrain system.
Inherited Members
Namespace: Fwt.HexTerrains.ChunkMehes.Data
Assembly: fwt.hexterrains.dll
Syntax
public class ChunkMeshLayer : HexTerrainLayer, IDisposable, ISerializableTerrainLayer
Remarks
The ChunkMeshLayer class manages multiple data layers — including height, biome, transparency, and cell metrics maps — for a chunk of hex terrain. It supports initialization, serialization, deserialization, and job-based processing for efficient updates and rendering. The class also provides mechanisms for handling overlapping layers, enabling advanced visual effects such as transparency based on relative cell heights. Most operations are designed to be used in a job-based, multi-threaded environment and require proper initialization before use. Thread safety and correct job dependency management are the responsibility of the caller.
Fields
ChunkMeshLayerSettings
The ChunkMeshLayer-specific settings
Declaration
public ChunkMeshLayerSettings ChunkMeshLayerSettings
Field Value
| Type | Description |
|---|---|
| ChunkMeshLayerSettings |
TransparencyMap
Transparent flag map per cell. If true, the cell is transparent.
Declaration
public CellValueDataLayer<bool> TransparencyMap
Field Value
| Type | Description |
|---|---|
| CellValueDataLayer<bool> |
Properties
BiomeMap
Map of biomes per cell. Index = cell index, Value = biome index.
Declaration
public virtual ColorMapCellValueDataLayer_Int BiomeMap { get; set; }
Property Value
| Type | Description |
|---|---|
| ColorMapCellValueDataLayer_Int |
CellMetricsMap
Map of cell metrics per cell. Index = cell index, Value = cell metrics.
Declaration
public virtual CellMetricsDataLayer CellMetricsMap { get; set; }
Property Value
| Type | Description |
|---|---|
| CellMetricsDataLayer |
HeightMap
Map of heights per cell. Index = cell index, Value = height value.
Declaration
public virtual ColorMapCellValueDataLayer_Float HeightMap { get; set; }
Property Value
| Type | Description |
|---|---|
| ColorMapCellValueDataLayer_Float |
SyncBiomeMapLayerReference
If set, the biome map of this layer will be synchronized with the specified layer.
Declaration
public HexTerrainLayerReference SyncBiomeMapLayerReference { get; set; }
Property Value
| Type | Description |
|---|---|
| HexTerrainLayerReference |
SyncHeightMapLayerReference
If set, the heightmap of this layer will be synchronized with the specified layer.
Declaration
public HexTerrainLayerReference SyncHeightMapLayerReference { get; set; }
Property Value
| Type | Description |
|---|---|
| HexTerrainLayerReference |
SyncTransparencyMapLayerReference
If set, the transparency map of this layer will be synchronized with the specified layer.
Declaration
public HexTerrainLayerReference SyncTransparencyMapLayerReference { get; set; }
Property Value
| Type | Description |
|---|---|
| HexTerrainLayerReference |
TerrainMetrics
Metrics of the whole terrain
Declaration
public HexTerrainMetrics TerrainMetrics { get; set; }
Property Value
| Type | Description |
|---|---|
| HexTerrainMetrics |
Methods
CalcCellMetrics(JobHandle)
Schedules the calculation of cell metrics based on the current state of the height, biome, and transparency maps, and returns a handle representing the scheduled job and its dependencies.
Declaration
public virtual JobHandle CalcCellMetrics(JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| JobHandle | dependency | A handle representing the job dependencies that must be completed before cell metrics calculation begins. |
Returns
| Type | Description |
|---|---|
| JobHandle | A JobHandle that represents the scheduled cell metrics calculation job and its dependencies. If required data layers are missing or no recalculation is needed, returns the input dependency handle unchanged. |
Remarks
This method checks whether the relevant data layers are present and whether any of them are marked as dirty before scheduling the calculation. If no recalculation is necessary, the method returns immediately. The returned JobHandle should be used to ensure that dependent jobs are scheduled correctly.
CalculateBiomeColorMap(JobHandle)
Calculates a color map based on the biome map, taking into account any overlapping layers if specified in the settings. If an overlapping layer is defined and valid, it will be used to determine which cells should be painted as transparent based on their relative heights. If no overlapping layer is defined or valid, a default color map will be calculated based solely on the biome map and height map. The method ensures that all necessary data layers are present and properly synchronized before scheduling the color map calculation jobs.
Declaration
protected virtual JobHandle CalculateBiomeColorMap(JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| JobHandle | dependency | job handle to use as a dependency for scheduled jobs |
Returns
| Type | Description |
|---|---|
| JobHandle | scheduled jobs dependency |
CalculateColorMap(JobHandle)
Calculates the color map for the chunk mesh layer, taking into account any overlapping layers if specified.
Declaration
public override JobHandle CalculateColorMap(JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| JobHandle | dependency | JobHandle to use as dependency for all scheduled jobs |
Returns
| Type | Description |
|---|---|
| JobHandle | combined JobHandle of all scheduled jobs or input dependency if no jobs were scheduled |
Overrides
CalculateDefaultBiomeColorMap(JobHandle)
Schedules a job to calculate the color map for this chunk mesh layer, taking into account the heightmap for making cells that are below treshold height a transparent cells. Paints cells as transparent if they are lower than the transparent height treshold.
Declaration
public virtual JobHandle CalculateDefaultBiomeColorMap(JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| JobHandle | dependency |
Returns
| Type | Description |
|---|---|
| JobHandle |
CalculateHeightColorMap(JobHandle)
Calculates a color map based on the height map
Declaration
protected virtual JobHandle CalculateHeightColorMap(JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| JobHandle | dependency | job handle to use as a dependency for scheduled jobs |
Returns
| Type | Description |
|---|---|
| JobHandle | scheduled jobs dependency |
CalculateOverlapBiomeColorMap(ChunkMeshLayer, JobHandle)
Schedules a job to calculate the color map for this chunk mesh layer, taking into account an overlapping layer. Paints cells as transparent if they are lower than the overlapping layer's height at the same cell index.
Declaration
public virtual JobHandle CalculateOverlapBiomeColorMap(ChunkMeshLayer overlappingLayer, JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| ChunkMeshLayer | overlappingLayer | ChunkMeshLayer that overlaps with current layer |
| JobHandle | dependency |
Returns
| Type | Description |
|---|---|
| JobHandle |
Cleanup()
Clears dirty flags for all data layers. Must be called at the beginning of the frame.
Declaration
public override void Cleanup()
Overrides
CleanupAsync(JobHandle)
Clears dirty flags for all data layers. Must be called at the beginning of the frame.
Declaration
public override JobHandle CleanupAsync(JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| JobHandle | dependency |
Returns
| Type | Description |
|---|---|
| JobHandle |
Overrides
CompleteAllJobs()
Completes all jobs that affect data layers.
Declaration
public override void CompleteAllJobs()
Overrides
DeserializeLayer(BinaryReader, HexTerrainSettings)
Deserializes the terrain layer data from the specified binary stream using the provided terrain settings.
Declaration
public virtual bool DeserializeLayer(BinaryReader reader, HexTerrainSettings terrainSettings)
Parameters
| Type | Name | Description |
|---|---|---|
| BinaryReader | reader | A BinaryReader positioned at the start of the terrain layer data to deserialize. |
| HexTerrainSettings | terrainSettings | The terrain settings to use when initializing and interpreting the deserialized data. |
Returns
| Type | Description |
|---|---|
| bool | true if the layer was successfully deserialized; otherwise, false. |
Dispose()
Disposes all allocated native memory.
Declaration
public override void Dispose()
Overrides
FillBiomeByHeight(NativeList<int>, NativeList<float>, IList<float>, int)
Fills the biome map by assigning biome indices based on the corresponding cell heights and specified biome level thresholds.
Declaration
public virtual bool FillBiomeByHeight(NativeList<int> biomeMap, NativeList<float> heightMap, IList<float> autoPaintBiomesLevels, int autoPaintBiomesOffset)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeList<int> | biomeMap | A list that will be populated with biome indices for each cell. Must be created and have a length equal to the height map. |
| NativeList<float> | heightMap | A list of height values for each cell. Must be created and have a length equal to the biome map. |
| IList<float> | autoPaintBiomesLevels | A list of height thresholds that define the boundaries between different biomes. Each value represents the minimum height required for a cell to be assigned to the corresponding biome. |
| int | autoPaintBiomesOffset |
Returns
| Type | Description |
|---|---|
| bool | true if the biome map and height map are both created and the operation completes successfully; otherwise, false. |
Remarks
The method assigns a biome index to each cell in the biome map based on its height and the provided biome level thresholds. The length of biomeMap and heightMap must match. The method does not perform validation on the length of autoPaintBiomesLevels.
GetAutoBiomeHeightLevel(float, IList<float>)
Determines the biome level index corresponding to the specified height based on the provided biome level thresholds.
Declaration
public virtual int GetAutoBiomeHeightLevel(float height, IList<float> levelBiomes)
Parameters
| Type | Name | Description |
|---|---|---|
| float | height | The height value to evaluate against the biome level thresholds. |
| IList<float> | levelBiomes | A list of height thresholds that define the boundaries between biome levels. Must not be null or empty. |
Returns
| Type | Description |
|---|---|
| int | The zero-based index of the biome level that contains the specified height. Returns 0 if the list of biome levels is null or empty, or if the height is below all thresholds. |
Remarks
The biome levels are determined by comparing the height to each threshold in descending order. The method returns the index of the first threshold that is less than or equal to the specified height.
Init(HexTerrainSettings)
Initializes the terrain data layers and metrics using the specified settings.
Declaration
public override void Init(HexTerrainSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| HexTerrainSettings | settings | The settings used to configure the terrain, including cell count and other parameters required for initialization. |
Overrides
Remarks
This method prepares all core data layers for use based on the provided settings. It should be called before accessing terrain data to ensure all layers are properly initialized. Calling this method multiple times will reinitialize the data layers with the new settings.
Init<TInitArgs>(HexTerrainSettings, TInitArgs)
Initializes the terrain system using the specified settings and initialization arguments.
Declaration
public override void Init<TInitArgs>(HexTerrainSettings settings, TInitArgs initArgs)
Parameters
| Type | Name | Description |
|---|---|---|
| HexTerrainSettings | settings | The configuration settings to apply when initializing the terrain system. Cannot be null. |
| TInitArgs | initArgs | Additional arguments required for initialization. The expected type and usage depend on the implementation. |
Type Parameters
| Name | Description |
|---|---|
| TInitArgs | The type of the initialization arguments to be used during terrain system setup. |
Overrides
SerializeLayer(BinaryWriter)
Serializes the current layer's data to the specified binary writer.
Declaration
public virtual bool SerializeLayer(BinaryWriter writer)
Parameters
| Type | Name | Description |
|---|---|---|
| BinaryWriter | writer | The binary writer to which the layer data will be serialized. Cannot be null. |
Returns
| Type | Description |
|---|---|
| bool | true if the layer was successfully serialized; otherwise, false. |
SetAllDirty(bool)
Marks all chunks in the associated maps as either dirty or clean.
Declaration
public override void SetAllDirty(bool isDirty)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isDirty | A value indicating whether to mark all chunks as dirty (true) or clean (false). |
Overrides
Remarks
Use this method to force all chunks in the height, biome, transparency, and cell metrics maps to be reprocessed or refreshed as needed.
SyncBiomeMap(JobHandle)
Synchronizes the local biome map with the corresponding biome map from the parent chunk mesh layer, scheduling any necessary jobs to update dirty regions.
Declaration
public virtual JobHandle SyncBiomeMap(JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| JobHandle | dependency | A job handle representing the current dependency chain. The synchronization job will be scheduled to run after this dependency completes. |
Returns
| Type | Description |
|---|---|
| JobHandle | A job handle that represents the scheduled synchronization operation. If no synchronization is required, returns the original dependency handle. |
Remarks
This method only schedules synchronization if either the local or source biome map is marked as dirty. If no biome maps are present or no updates are needed, the method returns the input dependency unchanged. The returned job handle should be used to ensure that any subsequent operations depending on the biome map data are properly synchronized.
SyncData(JobHandle)
Synchronizes the data between different layers before the calculation of the CellMetrics..
Declaration
public virtual JobHandle SyncData(JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| JobHandle | dependency | A handle representing the job dependencies that must be completed before any synchronization begins. |
Returns
| Type | Description |
|---|---|
| JobHandle | A JobHandle that represents the scheduled synchronization calculation job and its dependencies. If required data layers are missing or no recalculation is needed, returns the input dependency handle unchanged. |
SyncHeightMap(JobHandle)
Synchronizes the local height map with the corresponding height map from the parent chunk mesh layer, scheduling any necessary jobs to update dirty regions.
Declaration
public virtual JobHandle SyncHeightMap(JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| JobHandle | dependency | A job handle representing the current dependency chain. The synchronization job will be scheduled to run after this dependency completes. |
Returns
| Type | Description |
|---|---|
| JobHandle | A job handle that represents the scheduled synchronization operation. If no synchronization is required, returns the original dependency handle. |
Remarks
This method only schedules synchronization if either the local or source height map is marked as dirty. If no height maps are present or no updates are needed, the method returns the input dependency unchanged. The returned job handle should be used to ensure that any subsequent operations depending on the height map data are properly synchronized.
SyncTransparencyMap(JobHandle)
Synchronizes the local transparency map with the corresponding transparency map from the parent chunk mesh layer, scheduling any necessary jobs to update dirty regions.
Declaration
public virtual JobHandle SyncTransparencyMap(JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| JobHandle | dependency | A job handle representing the current dependency chain. The synchronization job will be scheduled to run after this dependency completes. |
Returns
| Type | Description |
|---|---|
| JobHandle | A job handle that represents the scheduled synchronization operation. If no synchronization is required, returns the original dependency handle. |
Remarks
This method only schedules synchronization if either the local or source transparency map is marked as dirty. If no transparency maps are present or no updates are needed, the method returns the input dependency unchanged. The returned job handle should be used to ensure that any subsequent operations depending on the transparency map data are properly synchronized.