Class VisualChunkMeshLayer
Base class for HexSurface layer that contains visuals (mesh for each chunk).
Inheritance
Inherited Members
Namespace: Fwt.HexTerrains.ChunkMehes.Data
Assembly: fwt.hexterrains.dll
Syntax
public class VisualChunkMeshLayer : ChunkMeshLayer, IDisposable, ISerializableTerrainLayer
Fields
BiomeUvConfigs
Represents the collection of biome UV configuration data used for chunk mesh generation if mesh is generated with IsUseBiomeAtlas
Declaration
public NativeList<ChunkMeshBiomeUVConfig> BiomeUvConfigs
Field Value
| Type | Description |
|---|---|
| NativeList<ChunkMeshBiomeUVConfig> |
ChunkMeshSources
Data layer that stores mesh sources for the hex terrain chunks. Mesh sources are filled in respected Jobs and then used to generate/fill meshes for the chunks.
Declaration
public ChunkMeshSourcesDataLayer ChunkMeshSources
Field Value
| Type | Description |
|---|---|
| ChunkMeshSourcesDataLayer |
ChunkMeshes
Data layer that stores meshes for the hex terrain chunks.
Declaration
public ChunkMeshesDataLayer ChunkMeshes
Field Value
| Type | Description |
|---|---|
| ChunkMeshesDataLayer |
DefaultRenderConfig
Fallback render config for the hex terrain chunks. When getting a render config for view mode, if the config is not found, this one will be used instead.
Declaration
public HexSurfaceRenderConfigAsset DefaultRenderConfig
Field Value
| Type | Description |
|---|---|
| HexSurfaceRenderConfigAsset |
MeshDatas
DataLayer with a MeshData per chunk
Declaration
public ChunkValueDataLayer<Mesh.MeshDataArray> MeshDatas
Field Value
| Type | Description |
|---|---|
| ChunkValueDataLayer<Mesh.MeshDataArray> |
OffsetTransform
Surface is rendered with this offset from the terrain's origin
Declaration
public Matrix4x4 OffsetTransform
Field Value
| Type | Description |
|---|---|
| Matrix4x4 |
RenderConfigs
List of render configs for the hex terrain chunks. Config index = view mode. So if you have 3 view modes, you will have 3 configs in this list. When the view mode == 0, the first config will be used, when view mode == 1, the second config will be used, etc.
Declaration
public List<HexSurfaceRenderConfigAsset> RenderConfigs
Field Value
| Type | Description |
|---|---|
| List<HexSurfaceRenderConfigAsset> |
RenderSettings
Render settings for the hex terrain chunks.
Declaration
public ChunkMeshRenderSettings RenderSettings
Field Value
| Type | Description |
|---|---|
| ChunkMeshRenderSettings |
Properties
IsGenerateMeshesWithMeshData
Declaration
public virtual bool IsGenerateMeshesWithMeshData { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
IsVisible
If true, the surface is visible and should be rendered. There for the meshes will be calculated and created and rendered.
Declaration
public virtual bool IsVisible { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
CalcDirtyMeshSources(JobHandle)
Calculates dirty mesh sources based on the dirty cell metrics and transparency maps. Marks chunks as dirty in the ChunkMeshSources layer if their underlying cell metrics or transparency have changed. Marks the ChunkMeshSources layer as dirty if any updates are made.
Declaration
public virtual JobHandle CalcDirtyMeshSources(JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| JobHandle | dependency | JobHandle that will be used as dependency to scheduled jobs |
Returns
| Type | Description |
|---|---|
| JobHandle | combined JobHandle of all scheduled jobs or input dependency if no jobs were scheduled |
CalcMeshSources(ChunksGridLayer, bool, JobHandle)
Schedules mesh generation jobs for visible and dirty chunks in the specified grid layer, returning a handle to the combined job dependencies.
Declaration
public virtual JobHandle CalcMeshSources(ChunksGridLayer chunksGridLayer, bool isCalcAllMeshes, JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| ChunksGridLayer | chunksGridLayer | The grid layer containing the chunks for which mesh sources are to be calculated. Cannot be null and must have valid visible chunks and chunk metrics. |
| bool | isCalcAllMeshes | A value indicating whether to recalculate mesh sources for all visible chunks (true), or only for those marked as dirty (false). |
| JobHandle | dependency | A job handle representing the dependencies that must be completed before mesh generation begins. |
Returns
| Type | Description |
|---|---|
| JobHandle | A Unity.Jobs.JobHandle that represents the combined dependencies of the scheduled mesh generation jobs.
If no jobs are scheduled, returns the input |
Remarks
Mesh generation is only scheduled for chunks that are both visible and dirty, unless
isCalcAllMeshes is true. If required data or layers are not available,
or if there are no chunks to process, the method returns the input dependency without scheduling any
jobs.
Cleanup()
Resets all dirty flags from data layers. Called at the beginning of the frame. Does not clear dirty flags for layers that have to keep their dirty flags between frames, such as ChunkMeshSources
Declaration
public override void Cleanup()
Overrides
CleanupAsync(JobHandle)
Asyncrhonously resets all dirty flags from data layers. Called at the beginning of the frame. Does not clear dirty flags for layers that have to keep their dirty flags between frames, such as ChunkMeshSources
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
CompleteFillingMeshes(bool)
Declaration
protected virtual void CompleteFillingMeshes(bool createAllMeshes)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | createAllMeshes |
CreateChunkMeshes(bool)
Declaration
public virtual void CreateChunkMeshes(bool createAllMeshes = false)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | createAllMeshes |
CreateChunkMeshesOld(bool)
Creates or updates the mesh instances for all or modified chunks based on the current mesh source data.
Declaration
public virtual void CreateChunkMeshesOld(bool createAllMeshes = false)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | createAllMeshes | If set to true, recreates meshes for all chunks regardless of whether they have changed; otherwise, only updates meshes for chunks marked as dirty. |
Remarks
This method processes the mesh source data and generates corresponding mesh objects
for each chunk. It is typically called after chunk data has been generated or modified. If no changes are
detected and createAllMeshes is false, the method performs no
action.
CreateChunkMeshes_Classic(bool)
Creates or updates the mesh instances for all or modified chunks based on the current mesh source data.
Declaration
public virtual void CreateChunkMeshes_Classic(bool createAllMeshes = false)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | createAllMeshes | If set to true, recreates meshes for all chunks regardless of whether they have changed; otherwise, only updates meshes for chunks marked as dirty. |
Remarks
This method processes the mesh source data and generates corresponding mesh objects
for each chunk. It is typically called after chunk data has been generated or modified. If no changes are
detected and createAllMeshes is false, the method performs no
action.
CreateChunkMeshes_MeshData(bool)
Creates or updates the mesh instances for all or modified chunks based on the current mesh source data.
Declaration
public virtual void CreateChunkMeshes_MeshData(bool createAllMeshes = false)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | createAllMeshes | If set to true, recreates meshes for all chunks regardless of whether they have changed; otherwise, only updates meshes for chunks marked as dirty. |
Remarks
This method processes the mesh source data and generates corresponding mesh objects
for each chunk. It is typically called after chunk data has been generated or modified. If no changes are
detected and createAllMeshes is false, the method performs no
action.
Dispose()
Disposes all allocated native memory.
Declaration
public override void Dispose()
Overrides
ExportMeshes(List<Mesh>)
Fills the list of meshes with the meshes from this layer ChunkMeshes. If provided list is null, a new list will be created.
Declaration
public virtual List<Mesh> ExportMeshes(List<Mesh> meshList = null)
Parameters
| Type | Name | Description |
|---|---|---|
| List<Mesh> | meshList | List of meshes to be filled |
Returns
| Type | Description |
|---|---|
| List<Mesh> |
ExportMeshesToAssets(ChunksGridLayer, string, string)
Exports all generated meshes from the specified chunks grid layer to individual mesh asset files in the given directory.
Declaration
public virtual bool ExportMeshesToAssets(ChunksGridLayer chunksGridLayer, string directoryPath, string meshAssetNameMask = "{0}_Chunk_{1}_{2}")
Parameters
| Type | Name | Description |
|---|---|---|
| ChunksGridLayer | chunksGridLayer | The chunks grid layer containing the meshes to export. Must not be null. |
| string | directoryPath | The file system path to the directory where mesh asset files will be saved. If the directory does not exist, it will be created. |
| string | meshAssetNameMask | An optional format string used to generate mesh asset file names. The format should include placeholders for the layer name, chunk index, and chunk coordinates. Defaults to "{0}Chunk{1}_{2}". |
Returns
| Type | Description |
|---|---|
| bool | true if the meshes were successfully exported to asset files; otherwise, false. |
Remarks
This method is intended for use in the Unity Editor and has no effect at runtime. Meshes are exported as individual asset files using the specified naming convention. If a mesh is null, it is skipped and a warning is logged.
FillBiomeUVConfigs(IEnumerable<ChunkMeshBiomeUVConfig>)
Fills the BiomeUvConfigs list with the provided biome UV configurations.
Declaration
public virtual void FillBiomeUVConfigs(IEnumerable<ChunkMeshBiomeUVConfig> biomeUVConfigs)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<ChunkMeshBiomeUVConfig> | biomeUVConfigs |
GenerateAllMeshes(ChunksGridLayer)
Generates and updates all chunk meshes for the specified grid layer, ensuring that all chunks are visible and up to date.
Declaration
public virtual void GenerateAllMeshes(ChunksGridLayer chunksGridLayer)
Parameters
| Type | Name | Description |
|---|---|---|
| ChunksGridLayer | chunksGridLayer | The grid layer containing the chunks for which meshes will be generated and updated. Cannot be null. |
Remarks
This method marks all chunk mesh sources and meshes as dirty, sets all chunks in the specified grid layer as visible, and then recalculates and creates meshes for all visible chunks. If any required data or the grid layer is null, the method returns without performing any operations.
GetChunkMesh(int)
Returns a mesh for the Chunk with given index
Declaration
public virtual Mesh GetChunkMesh(int chunkIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | chunkIndex |
Returns
| Type | Description |
|---|---|
| Mesh |
GetLayerVisibility()
Gets a value indicating whether the layer is currently visible.
Declaration
public virtual bool GetLayerVisibility()
Returns
| Type | Description |
|---|---|
| bool | true if the layer is visible; otherwise, false. |
GetRenderConfigAsset(int)
Returns a render config asset for provided view mode RenderConfigs If nothing is found, returns a DefaultRenderConfig DefaultRenderConfig
Declaration
public virtual HexSurfaceRenderConfigAsset GetRenderConfigAsset(int viewMode)
Parameters
| Type | Name | Description |
|---|---|---|
| int | viewMode | view mode to get a render config for |
Returns
| Type | Description |
|---|---|
| HexSurfaceRenderConfigAsset | render config asset |
HasIncorrectValues(Bounds)
Determines whether the specified bounds contain any invalid or incorrect values in their center or extents components.
Declaration
protected virtual bool HasIncorrectValues(Bounds bounds)
Parameters
| Type | Name | Description |
|---|---|---|
| Bounds | bounds | The bounds to check for incorrect values. |
Returns
| Type | Description |
|---|---|
| bool | true if any component of the center or extents of the bounds contains an incorrect value; otherwise, false. |
Init(HexTerrainSettings)
Initializes the data layers and resources required for the hex terrain system using the specified settings.
Declaration
public override void Init(HexTerrainSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| HexTerrainSettings | settings | The settings to use for initializing the hex terrain, including chunk count and configuration options. Cannot be null. |
Overrides
Init<TInitArgs>(HexTerrainSettings, TInitArgs)
Initializes the mesh layer with the specified terrain settings and mesh layer configuration.
Declaration
public override void Init<TInitArgs>(HexTerrainSettings settings, TInitArgs initArgs)
Parameters
| Type | Name | Description |
|---|---|---|
| HexTerrainSettings | settings | The terrain settings to use for initialization. Provides configuration values such as grid size, elevation, and other terrain-related parameters. |
| TInitArgs | initArgs |
Type Parameters
| Name | Description |
|---|---|
| TInitArgs |
Overrides
Remarks
If args is a IVisualChunkMeshLayerConfig, this
method copies its render settings, visibility, render configurations, and biome UV configurations to the
mesh layer. Existing render configurations are cleared and replaced. The method also ensures that biome UV
configuration storage is properly initialized and holds the new values from the provided args.
IsIncorrectValue(float)
Determines whether the specified floating-point value is not a valid finite number.
Declaration
protected virtual bool IsIncorrectValue(float y)
Parameters
| Type | Name | Description |
|---|---|---|
| float | y | The floating-point value to evaluate. |
Returns
| Type | Description |
|---|---|
| bool | true if the value is NaN, negative infinity, or positive infinity; otherwise, false. |
Render(ChunksGridLayer, HexTerrainViewMode, LocalToWorld, Camera)
Renders visible chunks from the provided chunks grid layer using the specified view mode and terrain transform.
Declaration
public virtual void Render(ChunksGridLayer chunksGridLayer, HexTerrainViewMode viewMode, LocalToWorld terrainTransform, Camera camera)
Parameters
| Type | Name | Description |
|---|---|---|
| ChunksGridLayer | chunksGridLayer | ChunksGridLayer of the terrain |
| HexTerrainViewMode | viewMode | view mode in which to render the terrain (which render config to use is dependent on this value) |
| LocalToWorld | terrainTransform | transform of the terrain entity |
| Camera | camera | camera to render the chunk meshes for |
RenderOld(ChunksGridLayer, HexTerrainViewMode, LocalToWorld, Camera)
Renders visible chunks from the provided chunks grid layer using the specified view mode and terrain transform.
Declaration
public virtual void RenderOld(ChunksGridLayer chunksGridLayer, HexTerrainViewMode viewMode, LocalToWorld terrainTransform, Camera camera)
Parameters
| Type | Name | Description |
|---|---|---|
| ChunksGridLayer | chunksGridLayer | ChunksGridLayer of the terrain |
| HexTerrainViewMode | viewMode | view mode in which to render the terrain (which render config to use is dependent on this value) |
| LocalToWorld | terrainTransform | transform of the terrain entity |
| Camera | camera | camera to render the chunk meshes for |
ScheduleGenerateMeshJob(ChunkMetricsDataLayer, ChunkMeshSourcesDataLayer, CellMetricsDataLayer, int, JobHandle)
Schedules a job to generate a mesh for the chunk with a given index. If you want to introduce your own mesh generator, override this method and schedule your own job.
Declaration
public virtual JobHandle ScheduleGenerateMeshJob(ChunkMetricsDataLayer chunkMetrics, ChunkMeshSourcesDataLayer chunkMeshSources, CellMetricsDataLayer cellMetrics, int chunkIndex, JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| ChunkMetricsDataLayer | chunkMetrics | Metrix of all terrain chunks |
| ChunkMeshSourcesDataLayer | chunkMeshSources | MeshSources to save generated mesh data into |
| CellMetricsDataLayer | cellMetrics | Metrics of all cells |
| int | chunkIndex | Index of chunk to schedule a mesh generation for |
| JobHandle | dependency | JobHandle to use as parameter when scheduling job |
Returns
| Type | Description |
|---|---|
| JobHandle |
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.
SetChunkMesh(int, Mesh)
Sets a mesh for the chunk with a given index
Declaration
public virtual bool SetChunkMesh(int chunkIndex, Mesh mesh)
Parameters
| Type | Name | Description |
|---|---|---|
| int | chunkIndex | |
| Mesh | mesh |
Returns
| Type | Description |
|---|---|
| bool |
SetLayerVisibility(bool)
Sets the visibility state of the layer.
Declaration
public virtual void SetLayerVisibility(bool isVisible)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isVisible | A value indicating whether the layer should be visible. Set to true to make the layer visible; otherwise, false. |
ToggleLayerVisibility()
Toggles the visibility state of the layer.
Declaration
public virtual void ToggleLayerVisibility()
Remarks
Calling this method switches the layer between visible and hidden states. The current
visibility is determined by the value of the IsVisible property.