reckfellENGINE

VoxelTool

Helper class to easily access and modify voxels

On this page
class VoxelToolReckfellSharpInherits RefCounted

Helper class to easily access and modify voxels

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, because it has multiple derived implementations. By default, if an operation overlaps a non-editable area (if not loaded yet for example), the operation will be cancelled. This behavior may vary in derived classes.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Properties9

ChannelProperty
# Channel
C#
public VoxelBuffer.ChannelId Channel { get; set; }

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.

EraserValueProperty
# EraserValue
C#
public ulong EraserValue { get; set; }

Sets which value will be used to erase voxels when editing the VoxelBuffer.ChannelId.ChannelType channel in VoxelTool.ModeEnum.Remove mode. Only relevant for blocky voxels.

ModeProperty
# Mode
C#
public VoxelTool.ModeEnum Mode { get; set; }

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

SdfScaleProperty
# SdfScale
C#
public float SdfScale { get; set; }

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 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.

SdfStrengthProperty
# SdfStrength
C#
public float SdfStrength { get; set; }

When editing VoxelBuffer.ChannelId.ChannelSdf of smooth Terrains in VoxelTool.ModeEnum.Add or VoxelTool.ModeEnum.Remove, determines the interpolation phase between current values and values set by the tool. Can be interpreted as the amount of "matter" added or subtracted.

TextureFalloffProperty
# TextureFalloff
C#
public float TextureFalloff { get; set; }

Range VoxelTool.ModeEnum.TexturePaint. Lower values produce sharper transitions. Can be compared to brush softness in an image editing program. This is only relevant with smooth voxels and texturing modes that support long gradients.

TextureIndexProperty
# TextureIndex
C#
public int TextureIndex { get; set; }

Index of the texture used in smooth voxel texture painting mode. The choice of this index depends on the way you setup rendering of textured voxel meshes (for example, layer index in a texture array).

TextureOpacityProperty
# TextureOpacity
C#
public float TextureOpacity { get; set; }

Range VoxelTool.TextureIndex when tool is set to VoxelTool.ModeEnum.TexturePaint. Can be compared to brush opacity in an image editing program.

ValueProperty
# Value
C#
public ulong Value { get; set; }

Sets which voxel value will be used. This is not relevant when editing VoxelBuffer.ChannelId.ChannelSdf.

Methods47

ColorToU16int
# ColorToU16
C#
public static int ColorToU16(Color color);

Encodes normalized 4-float color into 16-bit integer data. It is used with the COLOR channel, in cases where the channel represents direct colors (without using a palette).

Parameters
NameTypeDefault
colorColor—
Returns int
ColorToU16Weightsint
# ColorToU16Weights
C#
public static int ColorToU16Weights(Color _UnnamedArg0);

Encodes normalized 4-float color into 16-bit integer data, for use with the WEIGHTS channel.

Parameters
NameTypeDefault
_UnnamedArg0Color—
Returns int
ColorToU32uint
# ColorToU32
C#
public static uint ColorToU32(Color color);

Encodes normalized 4-float color into 32-bit integer data, for use with the COLOR channel.

Parameters
NameTypeDefault
colorColor—
Returns uint
Copyvoid
# Copy
C#
public void Copy(Vector3I srcPos, VoxelBuffer dstBuffer, int channelsMask = 255, bool withMetadata = true);

Copies voxels in a box and stores them in the passed buffer. The source format will overwrite the destination. src_pos is the lowest corner of the box, and its size is determined by the size of dst_buffer. channels_mask is a bitmask where each bit tells which channels will be copied. Example: 1 << VoxelBuffer.CHANNEL_SDF to get only SDF data. Use VoxelBuffer.ChannelMask.AllChannelsMask if you want them all.

Parameters
NameTypeDefault
srcPosVector3I—
dstBufferVoxelBuffer—
channelsMaskint255
withMetadatabooltrue
DoBoxvoid
# DoBox
C#
public void DoBox(Vector3I begin, Vector3I end);

Operate on a rectangular cuboid section of the terrain. With blocky voxels, begin and end are inclusive. With smooth voxels, end is exclusive. You may choose which operation to do before calling this function, by setting VoxelTool.Mode. With blocky voxels, you may also set VoxelTool.Value to choose which voxel ID to use.

Parameters
NameTypeDefault
beginVector3I—
endVector3I—
DoMeshvoid
# DoMesh
C#
public void DoMesh(VoxelMeshSdf meshSdf, Transform3D transform, float isolevel = 0f);

Applies the given mesh shape to the terrain. The model must be baked into a signed distance field with VoxelMeshSdf. transform may be used to position, rotate and scale the model. Non-uniform scale might introduce artifacts. isolevel is a distance that inflates or contracts the model if increased or decreased respectively. Quality depends on resolution of the model's SDF, and performance will be lower than primitive shapes such as VoxelTool.DoSphere.

Parameters
NameTypeDefault
meshSdfVoxelMeshSdf—
transformTransform3D—
isolevelfloat0f
DoPath2 overloads
# DoPath · 1/2
C#
public void DoPath(Vector3[] points, float[] radii);

Traces a "tube" defined by a list of points, each having a corresponding radius to control the width of the tube at each point. The begin and end of the path is rounded. This is equivalent to placing/carving multiple connected capsules with varying top/bottom radius. The path is not using bezier or splines, each point is connected linearly to the next. If you need more smoothness, you may add points to areas that need them. The more points, the slower it is.

Parameters
NameTypeDefault
pointsVector3[]—
radiifloat[]—
# DoPath · 2/2
C#
public void DoPath(ReadOnlySpan<Vector3> points, ReadOnlySpan<float> radii);

Traces a "tube" defined by a list of points, each having a corresponding radius to control the width of the tube at each point. The begin and end of the path is rounded. This is equivalent to placing/carving multiple connected capsules with varying top/bottom radius. The path is not using bezier or splines, each point is connected linearly to the next. If you need more smoothness, you may add points to areas that need them. The more points, the slower it is.

Parameters
NameTypeDefault
pointsReadOnlySpan<Vector3>—
radiiReadOnlySpan<float>—
DoPointvoid
# DoPoint
C#
public void DoPoint(Vector3I pos);

Operates on a single voxel. You may choose which operation to do before calling this function, by setting VoxelTool.Mode. With blocky voxels, you may also set VoxelTool.Value to choose which voxel ID to use. This function is not well adapted to smooth voxels, and can introduce blockyness.

Parameters
NameTypeDefault
posVector3I—
DoSpherevoid
# DoSphere
C#
public void DoSphere(Vector3 center, float radius);

Operate on voxels within a sphere. You may choose which operation to do before calling this function, by setting VoxelTool.Mode. With blocky voxels, you may also set VoxelTool.Value to choose which voxel ID to use.

Parameters
NameTypeDefault
centerVector3—
radiusfloat—
GetChannelVoxelBuffer.ChannelId
# GetChannel
C#
public VoxelBuffer.ChannelId GetChannel();
Returns VoxelBuffer.ChannelId
GetEraserValueulong
# GetEraserValue
C#
public ulong GetEraserValue();
Returns ulong
GetModeVoxelTool.ModeEnum
# GetMode
C#
public VoxelTool.ModeEnum GetMode();
Returns VoxelTool.ModeEnum
GetSdfScalefloat
# GetSdfScale
C#
public float GetSdfScale();
Returns float
GetSdfStrengthfloat
# GetSdfStrength
C#
public float GetSdfStrength();
Returns float
GetTextureFallofffloat
# GetTextureFalloff
C#
public float GetTextureFalloff();
Returns float
GetTextureIndexint
# GetTextureIndex
C#
public int GetTextureIndex();
Returns int
GetTextureOpacityfloat
# GetTextureOpacity
C#
public float GetTextureOpacity();
Returns float
GetValueulong
# GetValue
C#
public ulong GetValue();
Returns ulong
GetVoxelulong
# GetVoxel
C#
public ulong GetVoxel(Vector3I pos);

Gets data from voxel at pos coordinates. The returned value will be an unsigned integer. The meaning of the value depends on VoxelTool.Channel the tool is set to. When using VoxelBuffer.ChannelId.ChannelSdf for smooth voxels, the returned value will be an encoded value, so you may use VoxelTool.GetVoxelF to get a float value instead.

Parameters
NameTypeDefault
posVector3I—
Returns ulong
GetVoxelFfloat
# GetVoxelF
C#
public float GetVoxelF(Vector3I pos);

Gets data from voxel at pos coordinates, interpreting it as a floating-point SDF value. This is recommended to query the VoxelBuffer.ChannelId.ChannelSdf channel for smooth voxels.

Parameters
NameTypeDefault
posVector3I—
Returns float
GetVoxelMetadataVariant
# GetVoxelMetadata
C#
public Variant GetVoxelMetadata(Vector3I pos);

Gets arbitrary data attached to a specific voxel.

Parameters
NameTypeDefault
posVector3I—
Returns Variant
GrowSpherevoid
# GrowSphere
C#
public void GrowSphere(Vector3 sphereCenter, float sphereRadius, float strength);

Adds/removes (depending on VoxelTool.Mode) a value to/from all voxels within a sphere. Added/removed value will be equal to strength at the center of the sphere, and decreases linearly to zero at the surface of the sphere. Voxels outside the sphere will not be affected. sphere_center is position in the terrain that will be smoothed out. sphere_radius radius of a sphere from the center where voxel values will be affected. Should be greater than zero. strength value that controls maximal value that will be added/removed to/from voxels. Suggested range is [0, 10]. Note 1: This is currently implemented only for terrain that uses SDF data (smooth voxels). Note 2: This is meant to be analogous to Surface tool from Unreal Engine Voxel Plugin. Note 3: This method assumes terrain SDF is coherent. If it isn't, you may notice differences in speeds at which terrain erodes or grows. For example, some generators fallback to a constant SDF when far away from the surface in order to speed up calculations (see VoxelGeneratorGraph.SdfClipThreshold). Note 4: If you want to use this method to dig terrain "smoothly" by calling it every frame, an alternative is to use VoxelTool.DoSphere but instead of the center being on the surface, move it back by about 0.95% of the radius so only a small fraction of the sphere will penetrate, digging a hole progressively.

Parameters
NameTypeDefault
sphereCenterVector3—
sphereRadiusfloat—
strengthfloat—
IsAreaEditablebool
# IsAreaEditable
C#
public bool IsAreaEditable(Aabb box);

Returns true if the specified voxel area can be edited. This can also be interpreted as the area being "loaded". Note: when using LOD, only the nearest LOD (0) is editable. Other factors can influence whether an area is editable or not, such as streaming mode or terrain bounds.

Parameters
NameTypeDefault
boxAabb—
Returns bool
NormalizeColorColor
# NormalizeColor
C#
public static Color NormalizeColor(Color _UnnamedArg0);

A helper method to set the sum of channels of the Color to 1.

Parameters
NameTypeDefault
_UnnamedArg0Color—
Returns Color
Pastevoid
# Paste
C#
public void Paste(Vector3I dstPos, VoxelBuffer srcBuffer, int channelsMask = 255);

Paste voxels in a box from the given buffer at a specific location. dst_pos is the lowest corner of the box, and its size is determined by the size of src_buffer. channels_mask is a bitmask where each bit tells which channels will be modified. Example: 1 << VoxelBuffer.CHANNEL_SDF only write SDF data. Use VoxelBuffer.ChannelMask.AllChannelsMask if you want them all.

Parameters
NameTypeDefault
dstPosVector3I—
srcBufferVoxelBuffer—
channelsMaskint255
PasteMaskedvoid
# PasteMasked
C#
public void PasteMasked(Vector3I dstPos, VoxelBuffer srcBuffer, int channelsMask, int maskChannel, long maskValue);

Paste voxels in a box from the given buffer at a specific location. Voxels having a specific value in a mask channel will not be pasted. dst_pos is the lowest corner of the box, and its size is determined by the size of src_buffer. channels_mask is a bitmask where each bit tells which channels will be modified. Example: 1 << VoxelBuffer.CHANNEL_SDF only write SDF data. Use VoxelBuffer.ChannelMask.AllChannelsMask if you want them all. src_mask_channel channel from the source buffer that will be used to lookup mask values. src_mask_value if voxels of the source buffer have this value in the channel specified for masking, then they won't be pasted.

Parameters
NameTypeDefault
dstPosVector3I—
srcBufferVoxelBuffer—
channelsMaskint—
maskChannelint—
maskValuelong—
PasteMaskedWritableList2 overloads
# PasteMaskedWritableList · 1/2
C#
public void PasteMaskedWritableList(Vector3I position, VoxelBuffer voxels, byte channelsMask, byte srcMaskChannel, ulong srcMaskValue, byte dstMaskChannel, int[] dstWritableList);

Paste voxels in a box from the given buffer at a specific location. Voxels having a specific value in a mask channel of the source buffer will not be pasted, and existing voxels at the destination will only be modified if they have specific values. dst_pos is the lowest corner of the box, and its size is determined by the size of src_buffer. channels_mask is a bitmask where each bit tells which channels will be modified. Example: 1 << VoxelBuffer.CHANNEL_SDF only write SDF data. Use VoxelBuffer.ChannelMask.AllChannelsMask if you want them all. src_mask_channel channel from the source buffer that will be used to lookup mask values. src_mask_value if voxels of the source buffer have this value in the channel specified for masking, then they won't be pasted. dst_mask_channel channel from the destination that will be used to select writable voxels. dst_writable_list List of values the destination voxels must have in order to be written to. Values in that list must be between 0 and 65535. A very large amount of values can also affect performance.

Parameters
NameTypeDefault
positionVector3I—
voxelsVoxelBuffer—
channelsMaskbyte—
srcMaskChannelbyte—
srcMaskValueulong—
dstMaskChannelbyte—
dstWritableListint[]—
# PasteMaskedWritableList · 2/2
C#
public void PasteMaskedWritableList(Vector3I position, VoxelBuffer voxels, byte channelsMask, byte srcMaskChannel, ulong srcMaskValue, byte dstMaskChannel, ReadOnlySpan<int> dstWritableList);

Paste voxels in a box from the given buffer at a specific location. Voxels having a specific value in a mask channel of the source buffer will not be pasted, and existing voxels at the destination will only be modified if they have specific values. dst_pos is the lowest corner of the box, and its size is determined by the size of src_buffer. channels_mask is a bitmask where each bit tells which channels will be modified. Example: 1 << VoxelBuffer.CHANNEL_SDF only write SDF data. Use VoxelBuffer.ChannelMask.AllChannelsMask if you want them all. src_mask_channel channel from the source buffer that will be used to lookup mask values. src_mask_value if voxels of the source buffer have this value in the channel specified for masking, then they won't be pasted. dst_mask_channel channel from the destination that will be used to select writable voxels. dst_writable_list List of values the destination voxels must have in order to be written to. Values in that list must be between 0 and 65535. A very large amount of values can also affect performance.

Parameters
NameTypeDefault
positionVector3I—
voxelsVoxelBuffer—
channelsMaskbyte—
srcMaskChannelbyte—
srcMaskValueulong—
dstMaskChannelbyte—
dstWritableListReadOnlySpan<int>—
RaycastVoxelRaycastResult
# Raycast
C#
public VoxelRaycastResult Raycast(Vector3 origin, Vector3 direction, float maxDistance = 10f, uint collisionMask = 4294967295);

Runs a voxel-based raycast to find the first hit from an origin and a direction. Coordinates are in world space. Returns a result object if a voxel got hit, otherwise returns null. This is useful when colliders cannot be relied upon. It might also be faster (at least at short range), and is more precise to find which voxel is hit. It internally uses the DDA algorithm. collision_mask is currently only used with blocky voxels. It is combined with VoxelBlockyModel.CollisionMask to decide which voxel types the ray can collide with.

Parameters
NameTypeDefault
originVector3—
directionVector3—
maxDistancefloat10f
collisionMaskuint4294967295
Returns VoxelRaycastResult
SetChannelvoid
# SetChannel
C#
public void SetChannel(VoxelBuffer.ChannelId v);
Parameters
NameTypeDefault
vVoxelBuffer.ChannelId—
SetEraserValuevoid
# SetEraserValue
C#
public void SetEraserValue(ulong v);
Parameters
NameTypeDefault
vulong—
SetModevoid
# SetMode
C#
public void SetMode(VoxelTool.ModeEnum m);
Parameters
NameTypeDefault
mVoxelTool.ModeEnum—
SetRaycastNormalEnabledvoid
# SetRaycastNormalEnabled
C#
public void SetRaycastNormalEnabled(bool enabled);

Sets whether VoxelTool.Raycast will compute hit normals. This is true by default.

Parameters
NameTypeDefault
enabledbool—
SetSdfScalevoid
# SetSdfScale
C#
public void SetSdfScale(float scale);
Parameters
NameTypeDefault
scalefloat—
SetSdfStrengthvoid
# SetSdfStrength
C#
public void SetSdfStrength(float strength);
Parameters
NameTypeDefault
strengthfloat—
SetTextureFalloffvoid
# SetTextureFalloff
C#
public void SetTextureFalloff(float falloff);
Parameters
NameTypeDefault
fallofffloat—
SetTextureIndexvoid
# SetTextureIndex
C#
public void SetTextureIndex(int index);
Parameters
NameTypeDefault
indexint—
SetTextureOpacityvoid
# SetTextureOpacity
C#
public void SetTextureOpacity(float opacity);
Parameters
NameTypeDefault
opacityfloat—
SetValuevoid
# SetValue
C#
public void SetValue(ulong v);
Parameters
NameTypeDefault
vulong—
SetVoxelvoid
# SetVoxel
C#
public void SetVoxel(Vector3I pos, ulong v);

Sets the raw integer value of a specific voxel on the current channel.

Parameters
NameTypeDefault
posVector3I—
vulong—
SetVoxelFvoid
# SetVoxelF
C#
public void SetVoxelF(Vector3I pos, float v);

Sets the signed distance field (SDF) value a specific voxel. This should preferably be used on the SDF channel.

Parameters
NameTypeDefault
posVector3I—
vfloat—
SetVoxelMetadatavoid
# SetVoxelMetadata
C#
public void SetVoxelMetadata(Vector3I pos, Variant meta);

Attaches arbitrary data on a specific voxel. Old data is replaced. Passing null will erase metadata. If the underlying voxels can be saved, this metadata will also be saved, so make sure the data supports serialization (i.e you can't put nodes or arbitrary objects in it).

Parameters
NameTypeDefault
posVector3I—
metaVariant—
SmoothSpherevoid
# SmoothSphere
C#
public void SmoothSphere(Vector3 sphereCenter, float sphereRadius, int blurRadius);

Smoothens out terrain by performing box blur in a spherical area. Strength will be maximal at the center of the sphere, and decreases linearly to zero at the surface of the sphere. Voxels outside the sphere will not be affected. sphere_center is position in the terrain that will be smoothed out. sphere_radius radius of a sphere from the center where voxel values will be affected. Should be greater than zero. blur_radius half the box blur length that will be sampled to calculate average voxel values. Higher values results in more aggressive smoothing. Should be at least 1. Note 1: This is currently implemented only for terrain that uses SDF data (smooth voxels). Note 2: Beware of using high sphere_radius and high blur_radius as the performance can drop quickly if this is called 60 times a second.

Parameters
NameTypeDefault
sphereCenterVector3—
sphereRadiusfloat—
blurRadiusint—
U16IndicesToVec4IVector4I
# U16IndicesToVec4I
C#
public static Vector4I U16IndicesToVec4I(int _UnnamedArg0);

Decodes raw voxel integer data from the INDICES channel into a 4-integer vector.

Parameters
NameTypeDefault
_UnnamedArg0int—
Returns Vector4I
U16WeightsToColorColor
# U16WeightsToColor
C#
public static Color U16WeightsToColor(int _UnnamedArg0);

Decodes raw voxel integer data from the WEIGHTS channel into a normalized 4-float color.

Parameters
NameTypeDefault
_UnnamedArg0int—
Returns Color
Vec4IToU16Indicesint
# Vec4IToU16Indices
C#
public static int Vec4IToU16Indices(Vector4I _UnnamedArg0);

Encodes a 4-integer vector into 16-bit integer voxel data, for use in the INDICES channel.

Parameters
NameTypeDefault
_UnnamedArg0Vector4I—
Returns int

VoxelTool.ModeEnum

ValueDescription
Add = 0

When editing VoxelBuffer.ChannelId.ChannelSdf, will add matter. Useful for building.

Remove = 1

When editing VoxelBuffer.ChannelId.ChannelSdf, will subtract matter. Useful for digging.

Set = 2

Replace voxel values without any blending. Useful for blocky voxels.

TexturePaint = 3

When editing VoxelBuffer.ChannelId.ChannelSdf in smooth Terrain, enables texture painting. The value of VoxelTool.TextureIndex will be added to texture indices of the affected voxels. The texture's weight will be blended based on the values of VoxelTool.TextureFalloff and VoxelTool.TextureOpacity. Results will differ depending on which texturing mode is used by the mesher.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.