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(Shape, Vec3)​

VoxelEdit(Shape)​

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, number)​

Image GetImageResource(string)​

nil FreeTmpLayers(integer)​

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, Vec3, table, number, integer)​

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

table GetMaterialNames()​

table GetMaterial(string)​

nil SetMaterial(string, table)​

nil SetStaticSceneMaterial(string, number, number)​

nil SetVoxelDataResourceMaterial(VoxelDataResource, string)​

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​

userdata filter​

userdata 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​

userdata copyResource​

number roughness​

boolean roughnessEnable​

number metallicity​

boolean metallicityEnable​

RemoveType removeType​

number removeHardness​

boolean useMaterialColor​

string material​

table removeList​

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

userdata imageColor​

userdata imageNormal​

Mat4 imageUVTm​

boolean imageUVClamp​

boolean imageNormalBlendEnable​

number imageNormalBlendPower​

userdata onProgress​

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

userdata onFinished​

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

userdata onError​

callback function