I’m using the functions Terrain:ReadVoxels() and Terrain:WriteVoxels(). What I’m trying to do is read one area of terrain, and then copy that over somewhere else. While this does work, it isn’t perfect. You probably can’t tell from the image, but closer up it’s more obvious. I also checked to see if it was just me, by reading both pieces of terrain using the ReadVoxels function, and they were different.
Notes:
- Both regions are the same size
- Both regions are the same orientation
- I’m never changing the “materials” or “occupancies” given by the ReadVoxels function
- The code provided is the only piece of code in the whole game
Code
--// Services
local Terrain = workspace.Terrain
--// Variables
local region1Part = workspace.Region1
local region2Part = workspace.Region2
--// Constants
local RESOLUTION = 4
--// Functions
local function roundVector3(vector, toNearest)
return Vector3.new(
math.round(vector.X / toNearest) * toNearest,
math.round(vector.Y / toNearest) * toNearest,
math.round(vector.Z / toNearest) * toNearest
)
end
local function roundSize(part, toNearest)
part.Size = roundVector3(part.Size, RESOLUTION)
end
--// Main
roundSize(region1Part, RESOLUTION)
roundSize(region2Part, RESOLUTION)
local readPos1 = roundVector3(region1Part.Position - (region1Part.Size/2), RESOLUTION)
local readPos2 = roundVector3(region1Part.Position + (region1Part.Size/2), RESOLUTION)
local readRegion = Region3.new(readPos1, readPos2)
local materials, occupancies = workspace.Terrain:ReadVoxels(readRegion, RESOLUTION)
local writePos1 = roundVector3(region2Part.Position - (region2Part.Size/2), RESOLUTION)
local writePos2 = roundVector3(region2Part.Position + (region2Part.Size/2), RESOLUTION)
local writeRegion = Region3.new(writePos1, writePos2)
workspace.Terrain:WriteVoxels(writeRegion, RESOLUTION, materials, occupancies)
---------
task.wait(2)
local _materials, _occupancies = workspace.Terrain:ReadVoxels(writeRegion, RESOLUTION)
warn(materials == _materials, occupancies == _occupancies) -- prints false false
To be honest I don’t know if this is me or Roblox (because I’m not changing any values) but wanted to be sure before posting something in studio bugs (could also be some kind of limitations, I don’t know)