Class ElasticSceneGenerator
This class produces a realized scene from a Graph.ElasticSceneDefinitionNode for the current Player location (specified via GenerationOrigin). In addition to running any spawners in the defined scene definition, this entails generation of a Terrain if a height map has been specified.
During movement of the player, the generator takes care that the generated terrain and any spawned objects get refreshed. For the terrain, this means re-creating the current terrain area when the player moves past a threshold. For spawned objects, this means updating their spawners, so they may discard instances that have gone out of range and instantiate new spawn candidates that have come in range.
The TerrainGenerator maintains all the basic information about the terrain like the different resolutions of the heightmap, the alphamaps, the base map and the spawn areas. Also the general extents of the resulting terrain are defined here.
Implements
Namespace: Holoride.ElasticSDK
Assembly: Holoride.ElasticSDK.Runtime.dll
Syntax
[AddComponentMenu("holoride/Elastic Scene Generator")]
[HelpURL("http://localhost:8080/api/Holoride.ElasticSDK.ElasticSceneGenerator.html")]
public class ElasticSceneGenerator : MonoBehaviour, IPipelineContainer
Fields
AutoGenerate
States if the terrain start generating automatically.
Declaration
[Tooltip("States if the terrain start generating automatically.")]
public bool AutoGenerate
Field Value
Type | Description |
---|---|
bool |
AutoUpdate
States if the terrain should update/refresh automatically.
Declaration
[Tooltip("States if the terrain should update/refresh automatically.")]
public bool AutoUpdate
Field Value
Type | Description |
---|---|
bool |
BasemapDistance
The distance the terrain rendering falls back to a pre-lightened basemap.
Declaration
[Tooltip("The distance the terrain rendering falls back to a pre-lightened basemap.")]
[Range(1, 20000)]
public float BasemapDistance
Field Value
Type | Description |
---|---|
float |
BaseMapResolution
The resolution of the basemap as defined by the Unity's Terrain class.
Declaration
[Tooltip("The resolution of the basemap as defined by the Unity's Terrain class.")]
[Range(64, 2048)]
public int BaseMapResolution
Field Value
Type | Description |
---|---|
int |
BlendMargin
The blend margin between overlapping terrains.
Declaration
[Tooltip("The blend margin between overlapping terrains.")]
[Range(0, 1)]
public float BlendMargin
Field Value
Type | Description |
---|---|
float |
BoundsDistanceThreshold
Offset from the InnerBounds of the latest finished generation context, in meters. When this threshold is reached, the OnEnterGenerationOverdue event is invoked.
Declaration
[Tooltip("Offset from GenerationContext.InnerBounds of the latest finished generation context, in meters. When this threshold is reached, the OnGenerationOverdue event is invoked.")]
public float BoundsDistanceThreshold
Field Value
Type | Description |
---|---|
float |
CurrentTerrain
The current Terrain object.
Declaration
[HideInInspector]
public Terrain CurrentTerrain
Field Value
Type | Description |
---|---|
Terrain |
DisabledCollisionGOLayer
A layer that's excluded from terrain collision which is particularly important for collision solving.
Declaration
[Tooltip("A layer that's excluded from terrain collision which is particularly important for collision solving.")]
public int DisabledCollisionGOLayer
Field Value
Type | Description |
---|---|
int |
DrawInstanced
States whether to enable instanced drawing of the terrain.
Declaration
[Tooltip("States whether to enable instanced drawing of the terrain.")]
public bool DrawInstanced
Field Value
Type | Description |
---|---|
bool |
Extents
The edge length of the square terrain.
Declaration
[Tooltip("The edge length of the square terrain.")]
public float Extents
Field Value
Type | Description |
---|---|
float |
GenerationOrigin
The transform position where the terrain is generated.
Declaration
[Tooltip("The transform position where the terrain is generated.")]
public Transform GenerationOrigin
Field Value
Type | Description |
---|---|
Transform |
GridDivisions
The divisions of a terrain to trigger updates.
Declaration
public int GridDivisions
Field Value
Type | Description |
---|---|
int |
HeightmapPixelError
The PixelError property as defined by Unity's Terrain class that controls the trade-off between rendering performance and popup artifacts.
Declaration
[Tooltip("The PixelError property as defined by Unity's Terrain class that controls the trade-off between rendering performance and popup artifacts.")]
[Range(1, 200)]
public float HeightmapPixelError
Field Value
Type | Description |
---|---|
float |
HeightOffset
The height offset between the pivot altitude and the terrain zero value. Changing this value lowers or raises the entire terrain.
Declaration
[Tooltip("The height offset between the pivot altitude and the terrain zero value. Changing this value lowers or raises the entire terrain.")]
public float HeightOffset
Field Value
Type | Description |
---|---|
float |
HeightUploadChunkCount
The number of frames the upload process of the heightmap to the VRAM is distributed into. A trade-off between performance and the time-span it takes.
Declaration
[Tooltip("The number of frames the upload process of the heightmap into VRAM is distributed into. A trade-off between performance and the time-span it takes.")]
[Range(1, 256)]
public int HeightUploadChunkCount
Field Value
Type | Description |
---|---|
int |
MapResolution
The resolution of the heightmap of the Terrain and the maps of the graph. This value has a large influence on the terrain rendering performance, the memory consumption and the time it takes to generate the terrain.
Declaration
[Tooltip("The resolution of the heightmap of the Terrain and the maps of the graph. This value has a large influence on the terrain rendering performance, the memory consumption and the time it takes to generate the terrain.")]
[Range(64, 2048)]
[FormerlySerializedAs("TerrainResolution")]
public int MapResolution
Field Value
Type | Description |
---|---|
int |
MaxHeight
The maximum height above/below sea level.
Declaration
[Tooltip("The maximum height above/below sea level.")]
public float MaxHeight
Field Value
Type | Description |
---|---|
float |
MinHeight
The minimum height above/below sea level.
Declaration
[Tooltip("The minimum height above/below sea level.")]
public float MinHeight
Field Value
Type | Description |
---|---|
float |
OnEnterGenerationOverdue
The event which is invoked when the GenerationOrigin, i.e. the Player, got too close to the latest finished generation context's InnerBounds, based on the given BoundsDistanceThreshold.
Declaration
public UnityEvent OnEnterGenerationOverdue
Field Value
Type | Description |
---|---|
UnityEvent |
OnGenerationFinished
The event which is called when the initial generation process is finished.
Declaration
public UnityEvent<GenerationContext> OnGenerationFinished
Field Value
Type | Description |
---|---|
UnityEvent<GenerationContext> |
Remarks
Propagates the latest finished GenerationContext.
OnGenerationStarted
The event which is called when the initial generation process has started.
Declaration
public UnityEvent OnGenerationStarted
Field Value
Type | Description |
---|---|
UnityEvent |
OnLeaveGenerationOverdue
The event which is invoked when the current generation left the overdue state.
Declaration
public UnityEvent OnLeaveGenerationOverdue
Field Value
Type | Description |
---|---|
UnityEvent |
OnUpdateFinished
The event which is called every time a generation process has finished.
Declaration
public UnityEvent<GenerationContext> OnUpdateFinished
Field Value
Type | Description |
---|---|
UnityEvent<GenerationContext> |
Remarks
Propagates the latest finished GenerationContext.
OnUpdateStarted
The event which is called every time a generation process has started.
Declaration
public UnityEvent OnUpdateStarted
Field Value
Type | Description |
---|---|
UnityEvent |
Parent
The parent of the terrain and all spawned objects.
Declaration
[Tooltip("The parent of the terrain and all spawned objects.")]
public GameObject Parent
Field Value
Type | Description |
---|---|
GameObject |
QuarterSizedTerrainObject
States whether to quarter the size of the generated terrain. This reduces the popup effects caused by incoming data.
Declaration
[Tooltip("States whether to quarter the size of the generated terrain. This reduces the popup effects caused by incoming data.")]
public bool QuarterSizedTerrainObject
Field Value
Type | Description |
---|---|
bool |
SceneDefinition
The terrain compositing node that was added to an elastic graph.
Declaration
[FormerlySerializedAs("TerrainCompositing")]
[Tooltip("The terrain compositing node that was added to an elastic graph.")]
public ElasticSceneDefinitionNode SceneDefinition
Field Value
Type | Description |
---|---|
ElasticSceneDefinitionNode |
TerrainGenerationState
Contains the current terrain related state of the generation process and will be updated over time.
Declaration
public TerrainGenerationState TerrainGenerationState
Field Value
Type | Description |
---|---|
TerrainGenerationState |
TerrainGOLayer
The GameObject layer of the generated terrain.
Declaration
[Tooltip("The GameObject layer of the generated terrain.")]
public int TerrainGOLayer
Field Value
Type | Description |
---|---|
int |
TerrainMaterial
The material used for terrain rendering.
Declaration
[Tooltip("The material used for terrain rendering.")]
public Material TerrainMaterial
Field Value
Type | Description |
---|---|
Material |
TextureWeightmapUploadChunkCount
The number of frames the upload process of the texture weightmap to the VRAM is distributed into. A trade-off between performance and the time-span it takes.
Declaration
[Tooltip("The number of frames the upload process of the texture weightmap into VRAM is distributed into. A trade-off between performance and the time-span it takes.")]
[Range(1, 256)]
public int TextureWeightmapUploadChunkCount
Field Value
Type | Description |
---|---|
int |
Properties
FrameBudget
Gets or sets the frame budget when processing a pipeline. If zero, it will proceed with the least possible impact on every frame.
Declaration
public TimeSpan FrameBudget { get; set; }
Property Value
Type | Description |
---|---|
TimeSpan |
GeneratedNodeWorkers
Gets a mapping between the current graph nodes and their generated workers.
Declaration
public Dictionary<IPipelineNode, IPipelineWorker> GeneratedNodeWorkers { get; }
Property Value
Type | Description |
---|---|
Dictionary<IPipelineNode, IPipelineWorker> |
IsGenerationStateOverdue
Gets a value indicating whether the current generation is overdue.
Declaration
public bool IsGenerationStateOverdue { get; }
Property Value
Type | Description |
---|---|
bool |
IsGeneratorRunning
Gets a value indicating whether the generation process is running.
Declaration
public bool IsGeneratorRunning { get; }
Property Value
Type | Description |
---|---|
bool |
Pipeline
Gets the pipeline that is generated from the node graph when starting the generation process.
Declaration
public Pipeline Pipeline { get; }
Property Value
Type | Description |
---|---|
Pipeline |
ShiftManager
Declaration
public WorldShiftManager ShiftManager { get; set; }
Property Value
Type | Description |
---|---|
WorldShiftManager |
TerrainExtents
Gets the terrain extents while taking the half resolution option into account.
Declaration
public float TerrainExtents { get; }
Property Value
Type | Description |
---|---|
float |
TerrainResolution
Gets the terrain resolution while taking the half resolution option into account.
Declaration
public int TerrainResolution { get; }
Property Value
Type | Description |
---|---|
int |
Methods
OnValidate()
Implements the OnValidate method of the MonoBehaviour life-cycle.
Declaration
public void OnValidate()
StartGenerator()
Generates the Terrain and starts the spawning process.
Declaration
public void StartGenerator()
StopGenerator()
Destroys the terrain.
Declaration
public void StopGenerator()
TryGetGlobalOutput<T>(int, GlobalPosition, CancellationToken)
Returns the data of the connected OutputNode at a specific position..
Declaration
public UniTask<(bool Success, T Result)> TryGetGlobalOutput<T>(int portIndex, GlobalPosition position, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
int | portIndex | Index starting at 0 of the OutputNodes. |
GlobalPosition | position | Samples the OutputNode at a certain position. |
CancellationToken | cancellationToken | Token to cancel the async UniTask operation. |
Returns
Type | Description |
---|---|
Cysharp.Threading.Tasks.UniTask<T><(bool Success, T Result)> | The value returned from the mapper by passing the input node. |
Type Parameters
Name | Description |
---|---|
T | Used to select which IWorkerMapper will be used. |
TryGetGlobalOutput<T>(int, CancellationToken)
Returns the data of the connected OutputNode.
Declaration
public UniTask<(bool Success, T Result)> TryGetGlobalOutput<T>(int portIndex, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
int | portIndex | Index starting at 0 of the OutputNodes. |
CancellationToken | cancellationToken | Token to cancel the async UniTask operation. |
Returns
Type | Description |
---|---|
Cysharp.Threading.Tasks.UniTask<T><(bool Success, T Result)> | The value returned from the mapper by passing the input node. |
Type Parameters
Name | Description |
---|---|
T | Used to select which IWorkerMapper will be used. |
TryGetGlobalOutput<T>(string, GlobalPosition, CancellationToken)
Returns the data of the connected OutputNode at a specific position.
Declaration
public UniTask<(bool Success, T Result)> TryGetGlobalOutput<T>(string portName, GlobalPosition position, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | portName | Name of the port as displayed in the node graph. |
GlobalPosition | position | Samples the OutputNode at a certain position. |
CancellationToken | cancellationToken | Token to cancel the async UniTask operation. |
Returns
Type | Description |
---|---|
Cysharp.Threading.Tasks.UniTask<T><(bool Success, T Result)> | The value returned from the mapper by passing the input node. |
Type Parameters
Name | Description |
---|---|
T | Used to select which Mapper (either INodeMapper or IWorkerMapper) will be used. |
TryGetGlobalOutput<T>(string, CancellationToken)
Returns the data of the connected OutputNode.
Declaration
public UniTask<(bool Success, T Result)> TryGetGlobalOutput<T>(string portName, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | portName | Name of the port as displayed in the node graph. |
CancellationToken | cancellationToken | Token to cancel the async UniTask operation. |
Returns
Type | Description |
---|---|
Cysharp.Threading.Tasks.UniTask<T><(bool Success, T Result)> | The value returned from the mapper by passing the input node. |
Type Parameters
Name | Description |
---|---|
T | Used to select which Mapper (either INodeMapper or IWorkerMapper) will be used. |