Hi, I’m currently working on a game where terrain maps are created from seeds. A big problem right now is that it takes forever to generate terrains larger than 1000x1000 with WriteVoxel. In fact, attempting to WriteVoxel() a 1000x1000 map will throw you an error, so I had program a chunk system, where 100x100 pieces are loaded one after the other.
The terrain will clear for a few seconds, and then load in just a few seconds again. I’m talking like 5 seconds, compared to 85 with WriteVoxels.
My question is how can better use PasteRegion to my advantage? I generate the map with a height map (with math.noise) and WriteVoxel(). Is it possible to save terrainRegion from above in a DataStore for example? Or somehow create a TerrainRegion from a height map? As I said, I’m comparing 5 seconds to 85 right now…
Here’s some code I was playing around with that should help you:
local terrain = game.Workspace.Terrain
local resolution = 4 -- I think this is redundant, trying to set a resolution other than 4 throws an error
local region = Region3.new(Vector3.new(-150, -150, -150), Vector3.new(150,150,150))
local region2 = Region3.new(Vector3.new(-150, 150, 350), Vector3.new(150,450,650))
region = region:ExpandToGrid(resolution)
region2 = region2:ExpandToGrid(resolution)
local terrainVoxels, terrainVoxelOccupancy = terrain:ReadVoxels(region, resolution)
--terrain:Clear()
terrain:WriteVoxels(region2, resolution, terrainVoxels, terrainVoxelOccupancy)
I’m talking about CopyRegion and PasteRegion. My script uses WriteVoxels and it takes forever to load compared to when I try PasteRegion in the command bar. I want to be able to store a TerrainRegion though, or somehow turn a terrain material and occupancy array into a TerrainRegion
Are you sure it’s the actual write voxel function causing the lag and not the algorithm creating the heightmap? I’m able to create a map approximately 1k studs x 1k studs x 256 studs in under a second.