Convert terrain voxel data into a string for easy copy + paste

I was working on a module so I could use terrain in my games maps (they change every round). I decided that the best way to do this was with Terrain:ReadVoxels() and Terrain:WriteVoxels().

However, Terrain:WriteVoxels() requires you to pass terrain voxel data (materials and occupancies) as parameters, which in large chunks of terrain can be a long and boring task of copying + pasting values into a huge table. I decided to make a module that will convert this data into a string value, so it could be easily cut and paste into a module.


How to use:

The module: VoxelData Converter - Roblox

This module is simple to use, but before you use it you should be familar with how Terrain:ReadVoxels() works. Read the documentation here.

Once you have your material and occupancies variables, you can use my module to convert this data into a string.

Pesudo code:

local region = [region here]
local materials, occupancies = workspace.Terrain:ReadVoxels(region, 4)
print(module.convert(--[[ materials or occupancies variable here.]]--))

Why print? Your ouput has no string limit, attempting to set a TextLabel’s text or a script’s source to the value will result in an error. I recommend clearing your output before printing, then after you have run the code you can use CTRL + A to select all of the outputs content.

Once you have copied the output, I recommend pasting the code into Notepad or another text editor to remove any unwanted text such as:

image

Once you have the raw code, I would set up a module per array as they can get extremely large and Roblox’s IDE can get extremely laggy.

Now you can simply use Terrain:WriteVoxels() to paste your terrain! (example from my own map loader module)

Terrain:WriteVoxels(voxelData.region, 4, voxelData.materials, voxelData.occupancies)

If you have any questions, I will try my best to answer them in the replies.

14 Likes

I can see this being useful. Thanks

Question, how do i retrieve the data i got into a real terrain?