VoxelTerrain
Voxel volume using constant level of detail.
Voxel volume using constant level of detail.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
VoxelTerrainConstructor
public VoxelTerrain();Properties17
AreaEditNotificationEnabledProperty
public bool AreaEditNotificationEnabled { get; set; }AutomaticLoadingEnabledProperty
public bool AutomaticLoadingEnabled { get; set; }If turned off, the terrain will no longer automatically load blocks around viewers locally. This may be used in multiplayer scenarios, when the terrain is client-side, because blocks will be sent by the server instead.
BlockEnterNotificationEnabledProperty
public bool BlockEnterNotificationEnabled { get; set; }BoundsProperty
public Aabb Bounds { get; set; }Defines the bounds within which the terrain is allowed to have voxels. If an infinite world generator is used, blocks will only generate within this region. Everything outside will be left empty.
If any dimension of the new bounds is larger than 512 and VoxelTerrain.MaxViewDistance is larger than 512, then VoxelTerrain.MaxViewDistance will be clamped to 512. This measure is to avoid crashing due to a potential huge amount of chunks that would load.
CollisionLayerProperty
public int CollisionLayer { get; set; }CollisionMarginProperty
public float CollisionMargin { get; set; }CollisionMaskProperty
public int CollisionMask { get; set; }DebugDrawEnabledProperty
public bool DebugDrawEnabled { get; set; }DebugDrawShadowOccludersProperty
public bool DebugDrawShadowOccluders { get; set; }DebugDrawVisualAndCollisionBlocksProperty
public bool DebugDrawVisualAndCollisionBlocks { get; set; }DebugDrawVolumeBoundsProperty
public bool DebugDrawVolumeBounds { get; set; }DebugDrawVoxelMetadataProperty
public bool DebugDrawVoxelMetadata { get; set; }GenerateCollisionsProperty
public bool GenerateCollisions { get; set; }Enables the generation of collision shapes using the classic physics engine. Use this feature if you need realistic or non-trivial collisions or physics.
Note 1: you also need VoxelViewer to request collisions, otherwise they won't generate.
Note 2: If you need simple Minecraft/AABB physics, you can use VoxelBoxMover which may perform better in blocky worlds.
MaterialOverrideProperty
public Material MaterialOverride { get; set; }MaxViewDistanceProperty
public int MaxViewDistance { get; set; }Sets the maximum distance this terrain can support. If a VoxelViewer requests more, it will be clamped.
MeshBlockSizeProperty
public uint MeshBlockSize { get; set; }Sets how many voxels across meshes of the terrain span.
Voxel chunks are stored in cubic chunks of 16x16x16 voxels, and by default meshes of the terrain match that size. But you can set this to 32 so meshes will span 2x2x2 voxel chunks. This is a performance tradeoff. Higher mesh size may speed up rendering, at the cost of slower mesh updates.
Values other than 16 and 32 are not supported.
Note: this setting also affects VoxelInstancer chunks.
UseGpuGenerationProperty
public bool UseGpuGeneration { get; set; }Enables GPU block generation, which can speed it up. This is only valid for generators that support it. Vulkan is required.
Methods42
DataBlockToVoxelVector3I
public Vector3I DataBlockToVoxel(Vector3I blockPos);Converts data block coordinates into voxel coordinates. Voxel coordinates of a block correspond to its lowest corner.
| Name | Type | Default |
|---|---|---|
blockPos | Vector3I | — |
Vector3IDebugGetDrawFlagbool
public bool DebugGetDrawFlag(VoxelTerrain.DebugDrawFlag flagIndex);| Name | Type | Default |
|---|---|---|
flagIndex | VoxelTerrain.DebugDrawFlag | — |
boolDebugGetDrawShadowOccludersbool
public bool DebugGetDrawShadowOccluders();boolDebugIsDrawEnabledbool
public bool DebugIsDrawEnabled();boolDebugSetDrawEnabledvoid
public void DebugSetDrawEnabled(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
DebugSetDrawFlagvoid
public void DebugSetDrawFlag(VoxelTerrain.DebugDrawFlag flagIndex, bool enabled);| Name | Type | Default |
|---|---|---|
flagIndex | VoxelTerrain.DebugDrawFlag | — |
enabled | bool | — |
DebugSetDrawShadowOccludersvoid
public void DebugSetDrawShadowOccluders(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
GetBoundsAabb
public Aabb GetBounds();AabbGetCollisionLayerint
public int GetCollisionLayer();intGetCollisionMarginfloat
public float GetCollisionMargin();floatGetCollisionMaskint
public int GetCollisionMask();intGetDataBlockSizeuint
public uint GetDataBlockSize();uintGetGenerateCollisionsbool
public bool GetGenerateCollisions();boolGetGeneratorUseGpubool
public bool GetGeneratorUseGpu();boolGetMaterialOverrideMaterial
public Material GetMaterialOverride();MaterialGetMaxViewDistanceint
public int GetMaxViewDistance();intGetMeshBlockSizeuint
public uint GetMeshBlockSize();uintGetStatisticsReckfell.Collections.Dictionary
public Reckfell.Collections.Dictionary GetStatistics();Gets debug information about how much time is spent processing the terrain. The returned dictionary has the following structure:
{
"time_detect_required_blocks": int,
"time_request_blocks_to_load": int,
"time_process_load_responses": int,
"time_request_blocks_to_update": int,
"time_process_update_responses": int,
"remaining_main_thread_blocks": int,
"dropped_block_loads": int,
"dropped_block_meshs": int,
"updated_blocks": int
}Reckfell.Collections.DictionaryGetViewerNetworkPeerIdsInAreaint[]
public int[] GetViewerNetworkPeerIdsInArea(Vector3I areaOrigin, Vector3I areaSize);| Name | Type | Default |
|---|---|---|
areaOrigin | Vector3I | — |
areaSize | Vector3I | — |
int[]HasDataBlockbool
public bool HasDataBlock(Vector3I blockPosition);| Name | Type | Default |
|---|---|---|
blockPosition | Vector3I | — |
boolIsAreaEditNotificationEnabledbool
public bool IsAreaEditNotificationEnabled();boolIsAreaMeshedbool
public bool IsAreaMeshed(Aabb areaInVoxels);Returns true if the area has been processed by meshing. It does not mean the area actually contains a mesh. Returns false if the area has not been processed by meshing (therefore it is unknown whethere there should be a mesh here or not). When streaming terrain, this can be used to determine if an area has fully "loaded", in case the game relies meshes or mesh colliders.
| Name | Type | Default |
|---|---|---|
areaInVoxels | Aabb | — |
boolIsAutomaticLoadingEnabledbool
public bool IsAutomaticLoadingEnabled();boolIsBlockEnterNotificationEnabledbool
public bool IsBlockEnterNotificationEnabled();boolSaveBlockvoid
public void SaveBlock(Vector3I position);Forces a specific block to be saved. Note 1: this will only have an effect if the stream setup on this terrain supports saving. Note 2: saving is asynchronous and won't block the game. the save may complete only a short time after you call this method.
| Name | Type | Default |
|---|---|---|
position | Vector3I | — |
SaveModifiedBlocksVoxelSaveCompletionTracker
public VoxelSaveCompletionTracker SaveModifiedBlocks();Forces all modified blocks to be saved. Note 1: this will only have an effect if the stream setup on this terrain supports saving. Note 2: saving is asynchronous and won't block the game. the save may complete only a short time after you call this method. Use the returned tracker object to know when saving has completed. However, saves occurring after calling this method won't be tracked by this object. Note that blocks getting unloaded as the viewer moves around can also trigger saving tasks, independently from this function.
VoxelSaveCompletionTrackerSetAreaEditNotificationEnabledvoid
public void SetAreaEditNotificationEnabled(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetAutomaticLoadingEnabledvoid
public void SetAutomaticLoadingEnabled(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetBlockEnterNotificationEnabledvoid
public void SetBlockEnterNotificationEnabled(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetBoundsvoid
public void SetBounds(Aabb bounds);| Name | Type | Default |
|---|---|---|
bounds | Aabb | — |
SetCollisionLayervoid
public void SetCollisionLayer(int layer);| Name | Type | Default |
|---|---|---|
layer | int | — |
SetCollisionMarginvoid
public void SetCollisionMargin(float margin);| Name | Type | Default |
|---|---|---|
margin | float | — |
SetCollisionMaskvoid
public void SetCollisionMask(int mask);| Name | Type | Default |
|---|---|---|
mask | int | — |
SetGenerateCollisionsvoid
public void SetGenerateCollisions(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetGeneratorUseGpuvoid
public void SetGeneratorUseGpu(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetMaterialOverridevoid
public void SetMaterialOverride(Material material);| Name | Type | Default |
|---|---|---|
material | Material | — |
SetMaxViewDistancevoid
public void SetMaxViewDistance(int distanceInVoxels);| Name | Type | Default |
|---|---|---|
distanceInVoxels | int | — |
SetMeshBlockSizevoid
public void SetMeshBlockSize(uint size);| Name | Type | Default |
|---|---|---|
size | uint | — |
TrySetBlockDatabool
public bool TrySetBlockData(Vector3I position, VoxelBuffer voxels);| Name | Type | Default |
|---|---|---|
position | Vector3I | — |
voxels | VoxelBuffer | — |
boolVoxelToDataBlockVector3I
public Vector3I VoxelToDataBlock(Vector3 voxelPos);| Name | Type | Default |
|---|---|---|
voxelPos | Vector3 | — |
Vector3I_OnAreaEditedvoid
public virtual void _OnAreaEdited(Vector3I areaOrigin, Vector3I areaSize);| Name | Type | Default |
|---|---|---|
areaOrigin | Vector3I | — |
areaSize | Vector3I | — |
_OnDataBlockEnteredvoid
public virtual void _OnDataBlockEntered(VoxelDataBlockEnterInfo info);| Name | Type | Default |
|---|---|---|
info | VoxelDataBlockEnterInfo | — |
Signals and events4
BlockLoadedEvent
public event VoxelTerrain.BlockLoadedEventHandler BlockLoaded;Emitted when a new data block is loaded from stream. This can happen before the mesh or collider becomes available.
| Name | Type | Default |
|---|---|---|
position | Vector3I | — |
BlockUnloadedEvent
public event VoxelTerrain.BlockUnloadedEventHandler BlockUnloaded;Emitted when a data block is unloaded due to being outside view distance.
| Name | Type | Default |
|---|---|---|
position | Vector3I | — |
MeshBlockEnteredEvent
public event VoxelTerrain.MeshBlockEnteredEventHandler MeshBlockEntered;Emitted when a mesh block receives its first update since it was added in the range of viewers. This is regardless of the mesh being empty or not. It tracks changes of the same state obtained with VoxelTerrain.IsAreaMeshed.
| Name | Type | Default |
|---|---|---|
position | Vector3I | — |
MeshBlockExitedEvent
public event VoxelTerrain.MeshBlockExitedEventHandler MeshBlockExited;Emitted when a mesh block gets unloaded. It is the counterpart of VoxelTerrain.MeshBlockEntered.
| Name | Type | Default |
|---|---|---|
position | Vector3I | — |