Skip to main content

VoxelEdit

Client Server

Deprecated

The voxel edit functions in this class are old and may not correctly work. Instead use Vox.

Server Only

Currently voxel edits can only be done on the server side.

Use this class to create voxel edits.

Use this class by first creating a VoxelEdit object, then setting the properties such as shape and color and finally calling one of the edit methods:

  • Paint()
  • Add()
  • Remove()
  • Copy()
  • Kernel()
A function to make a voxel capsule from position 1 to position 2
function self:makeLine(p1, p2)
--first create a VoxelEdit object
local ve = VoxelEdit()

--modify some properties
local thickness = 0.2
ve.shape = Capsule(p1, p2, thickness)
ve.color = Vec3(1, 0, 1)

--call the edit method
ve:Add()
end

Every scene has only one static voxel data and can have multiple dynamic voxel data. The static voxel data is used for the world and can not be moved. However both can be edited. To choose whether to edit the static or dynamic voxel data, use the filter property.

Creating dynamic voxel data attached to an object
--create an object with voxel data and renderer
local ob = Scene:CreateObject("Voxel Sphere")
local vd = ob:AddComponent("VoxelData")
local vr = ob:AddComponent("VoxelRenderer")
local vres = VoxelDataResource() --new empty voxel data
vd.data = vres
ob.transform.pos = Vec3(0, 30, 0)

--voxel edit
local ve = VoxelEdit()

--target the object and ignore static voxels
ve.filter.useStatic = false
ve.filter.forceList = { ob }

--add sphere
ve.color = Vec3(0,0.5,1)
ve.shape = Sphere(ob.transform.pos, 1)
ve:Add()

Use the copy operation to copy voxels from one object to others or the static voxel data.

Copy from voxel object to static voxel data
--select some object with voxel data here
local copyFrom = Scene:GetObjectByName("Voxel Sphere")

local ve = VoxelEdit()

--make a box fitting the target to copy from
local b = Box()
local center, size = copyFrom:GetComponentByType("VoxelRenderer"):GetBounds()
b.pos = center
b.size = size
ve.shape = b
ve.filter.useNotStatic = false

--select what data to copy and its pasted transformation
ve.copyResource = copyFrom:GetComponentByType("VoxelData").data
ve.copyDestinationPos = copyFrom.transform.pos
ve.copyDestinationRot = copyFrom.transform.rot
ve.copyDestinationScale = copyFrom.transform.scale
ve:Copy()

See a different example here

Constructors

VoxelEdit VoxelEdit()

VoxelEdit VoxelEdit(Shape shape)

VoxelEdit VoxelEdit(Shape shape, Vec3 position)

Methods

nil Flush()

Flush() adds a special operation in the queue, which waits for all running ops to finish. If we had flush after each op, it would eliminate all multithreaded processing.

nil Paint()

Change the color of voxels

nil Add()

Add voxels

nil Remove()

Remove voxels

nil Copy()

Copy voxels somewhere

nil Kernel()

Smoothing/Inflate/Deflate

Image CaptureImage(Mat4 textureUvTmWorld, number relBorderSize)

Image GetImageResource(string name)

nil FreeTmpLayers(integer clientId)

It projects cone on voxel geometry and everything inside will be copies to tmp all raycasts will collide with this tmp layer instead until FreeTmpLayers

nil FillTmpLayers(integer clientId)

It projects cone on voxel geometry and everything inside will be copies to tmp all raycasts will collide with this tmp layer instead until FreeTmpLayers parameters specify "cone" - two positions and end radius

string[] GetMaterialNames()

table GetMaterial(string materialName)

nil SetMaterial(string materialName, table matData)

nil SetStaticSceneMaterial(string materialName, number roughness, number metallicity)

nil SetVoxelDataResourceMaterial(VoxelDataResource vdr, string materialName)

nil ReplaceVoxelDataResourceMaterial(VoxelDataResource vdr, string destMaterialName, string srcMaterialName, boolean clearSourceMat)

nil BackupSurfaceAttributes()

Properties

boolean blendEnable

BlendMode blendMode

Various blend modes which you may know from Photoshop. See a list of explanations here.

number blendOpacity

number blendRadiusRatio

Vec3 color

Filter filter

Shape shape

if shape is nil the operation will match all targets

boolean clampToMinVoxelSize

if ClampToMinVoxelSize is true (it's default), it sets size of shape to at least size of voxel size of target. This can interfere with your box size if it's too small.

Transform copySourceTr

Transform copyDestinationTr

Vec3 copyDestinationPos

Quat copyDestinationRot

number copyDestinationScale

Vec3 copySourcePos

Quat copySourceRot

number copySourceScale

VoxelDataResource copyResource

number roughness

boolean roughnessEnable

number metallicity

boolean metallicityEnable

RemoveType removeType

number removeHardness

boolean useMaterialColor

string material

table removeList

table carveList

table removeCountList

boolean removeStats

boolean usesPbr

CopyOperation copyOperation

InsertOperation insertOperation

integer kernelType

0 = Smooth 7x5x7 1 = Smooth 3x3x3 2 = Smooth 5x5x5 3 = Inflate 4 = Deflate 5 = Normals smooth 6 = Normals sharp

Image imageColor

Image imageNormal

Mat4 imageUVTm

boolean imageUVClamp

boolean imageNormalBlendEnable

number imageNormalBlendPower

fun(progress:number) OnProgress

callback function. progress from 0-1. May not be called every frame. Is called after script updates

fun(info:RemoveCountInfo) OnFinished

callback function. onFinished is called after onProgress if it was last part

fun() OnError

callback function