VoxelTool

Inherits: Reference

Helper class to easily access and modify voxels

Description:

Abstract interface to access and edit voxels. It allows accessing individual voxels, or doing bulk operations such as carving large chunks or copy/paste boxes.

It's not a class to instantiate alone, you may get it from the voxel objects you want to work with.

Properties:

Type Name Default
int channel 0
int eraser_value 0
int mode 0
float sdf_scale 0.002
float texture_falloff 0.5
int texture_index 0
float texture_opacity 1.0
int value 0

Methods:

Return Signature
void copy ( Vector3 src_pos, Reference dst_buffer, int channels_mask )
void do_box ( Vector3 begin, Vector3 end )
void do_point ( Vector3 pos )
void do_sphere ( Vector3 center, float radius )
int get_voxel ( Vector3 pos )
float get_voxel_f ( Vector3 pos )
Variant get_voxel_metadata ( Vector3 pos )
bool is_area_editable ( AABB box )
void paste ( Vector3 dst_pos, Reference src_buffer, int channels_mask, int src_mask_value )
VoxelRaycastResult raycast ( Vector3 origin, Vector3 direction, float max_distance=10.0, int collision_mask=4294967295 )
void set_voxel ( Vector3 pos, int v )
void set_voxel_f ( Vector3 pos, float v )
void set_voxel_metadata ( Vector3 pos, Variant meta )

Enumerations:

enum Mode:

  • MODE_ADD = 0 --- When editing [enum VoxelBuffer.CHANNEL_SDF], will add matter. Useful for building.
  • MODE_REMOVE = 1 --- When editing [enum VoxelBuffer.CHANNEL_SDF], will subtract matter. Useful for digging.
  • MODE_SET = 2 --- Replace voxel values without any blending. Useful for blocky voxels.
  • MODE_TEXTURE_PAINT = 3

Property Descriptions

  • int channel = 0

Set which channel will be edited. When used on a terrain node, it will default to the first available channel, based on the stream and generator.

  • int eraser_value = 0

Sets which value will be used to erase voxels when editing the enum VoxelBuffer.CHANNEL_TYPE channel in enum MODE_REMOVE mode.

Sets how do_* functions will behave. This may vary depending on the channel.

  • float sdf_scale = 0.002

When working with smooth voxels, applies a scale to the signed distance field. A high scale (1 or higher) will tend to produce blocky results, and a low scale (below 1, but not too close to zero) will tend to be smoother.

This is related to the enum VoxelBuffer.Depth configuration on voxels. For 8-bit and 16-bit, there is a limited range of values the Signed Distance Field can take, and by default it is clamped to -1..1, so the gradient can only range across 2 voxels. But when LOD is used, it is better to stretch that range over a longer distance, and this is achieved by scaling SDF values.

  • float texture_falloff = 0.5

  • int texture_index = 0

  • float texture_opacity = 1.0

  • int value = 0

Sets which voxel value will be used. This is not relevant when editing enum VoxelBuffer.CHANNEL_SDF.

Method Descriptions

Operate on a rectangular cuboid section of the terrain. begin and end are inclusive. Choose operation and which voxel to use by setting value and mode before calling this function.

Generated on May 31, 2021