VoxelTerrain

Inherits: VoxelNode

Voxel volume using constant level of detail.

Properties:

Type Name Default
AABB bounds AABB( -5.36871e+08, -5.36871e+08, -5.36871e+08, 1.07374e+09, 1.07374e+09, 1.07374e+09 )
int collision_layer 1
int collision_mask 1
bool generate_collisions true
int max_view_distance 128
int mesh_block_size 16
bool run_stream_in_editor true

Methods:

Return Signature
Vector3 data_block_to_voxel ( Vector3 block_pos ) const
Material get_material ( int id ) const
Dictionary get_statistics ( ) const
VoxelTool get_voxel_tool ( )
void save_block ( Vector3 position )
void save_modified_blocks ( )
void set_material ( int id, Material material )
Vector3 voxel_to_data_block ( Vector3 voxel_pos ) const

Signals:

Emitted when a new block is loaded from stream.

Note: it might be not visible yet.

  • block_unloaded( Vector3 position )

Emitted when a block unloaded due to being outside view distance.

Property Descriptions

  • AABB bounds = AABB( -5.36871e+08, -5.36871e+08, -5.36871e+08, 1.07374e+09, 1.07374e+09, 1.07374e+09 )

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.

  • int collision_layer = 1

  • int collision_mask = 1

  • bool generate_collisions = true

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.

  • int max_view_distance = 128

Sets the maximum distance this terrain can support. If a VoxelViewer requests more, it will be clamped.

Note: there is an internal limit of 512 for constant LOD terrains, because going further can affect performance and memory very badly at the moment.

  • int mesh_block_size = 16

  • bool run_stream_in_editor = true

Makes the terrain appear in the editor.

Important: this option will turn off automatically if you setup a script world generator. Modifying scripts while they are in use by threads causes undefined behaviors. You can still turn on this option if you need a preview, but it is strongly advised to turn it back off and wait until all generation has finished before you edit the script again.

Method Descriptions

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
}

Creates an instance of VoxelTool bound to this node, to access voxels and edition methods.

You can keep it in a member variable to avoid creating one again, as long as the node still exists.

Forces a specific block to be saved.

Note 1: all modified blocks are automatically saved before the terrain is destroyed.

Note 2: this will only have an effect if the stream setup on this terrain supports saving.

Note 3: saving is asynchronous and won't block the game. the save may complete only a short time after you call this method.

  • void save_modified_blocks( )

Forces all modified blocks to be saved.

Note 1: all modified blocks are automatically saved before the terrain is destroyed.

Note 2: this will only have an effect if the stream setup on this terrain supports saving.

Note 3: saving is asynchronous and won't block the game. the save may complete only a short time after you call this method.

Generated on May 31, 2021