Having issues with Terrain:CopyRegion() and Terrain:PasteRegion()

Hi,

I’m sure that I must be doing something wrong but I can’t figure this out - when I copy a region and then paste it again, its

  1. Copied the incorrect region
  2. Pasted it in the wrong location? (Not sure if this is because of 1. or not)

Video of the problem:

My Code:

local post0, post1 = game.Workspace.post0, game.Workspace.post1

local point0 = post0.Position + Vector3.new(0, post0.Size.Y/2, 0)
local point1 = post1.Position - Vector3.new(0, post1.Size.Y/2, 0)

local minX = math.min(point0.X, point1.X)
local maxX = math.max(point0.X, point1.X)
local minY = math.min(point0.Y, point1.Y)
local maxY = math.max(point0.Y, point1.Y)
local minZ = math.min(point0.Z, point1.Z)
local maxZ = math.max(point0.Z, point1.Z)



local corner = Instance.new("Part")
	corner.Anchored = true
	corner.Size = Vector3.new(1.2, 1.2, 1.2)
	corner.Position = Vector3.new(minX, minY, minZ)
	corner.Color = Color3.fromRGB(0,255,0)
local corner2 = corner:Clone()
	corner2.Position = Vector3.new(maxX, maxY, maxZ)
	
corner.Parent = game.Workspace 
corner2.Parent = game.Workspace



local region = Region3int16.new(Vector3int16.new(minX, minY, minZ), Vector3int16.new(maxX, maxY, maxZ))
print("Point0", point0)
print("Point1", point1)
print("Region", region)



local terrain = game.Workspace.Terrain:CopyRegion(region)
wait(10)
game.Workspace.Terrain:Clear()
wait(3)
game.Workspace.Terrain:PasteRegion(terrain, Vector3int16.new(minX, minY, minZ), true)

The 2 green blocks visualise the corners of the Region3int16, and the lower one is where it is pasted.

4 Likes

Ok, just found something interesting…

If you divide all the proportions by 4, it seems to work pretty much as intended.

Region3’s when created can be aligned to the terrain voxel grid by using the function Region3:ExpandToGrid(4) (only accepts 4 at this time, is a variable incase ROBLOX decide to add capability for different voxel values).
However this cannot be done with a Region3int16 (must use this one when dealing with terrain) - think this may be a bug?

Updated Video

Updated Code

local post0, post1 = game.Workspace.post0, game.Workspace.post1

local point0 = post0.Position + Vector3.new(0, post0.Size.Y/2, 0)
local point1 = post1.Position - Vector3.new(0, post1.Size.Y/2, 0)

local r = 4
local minX = math.min(point0.X, point1.X)
local maxX = math.max(point0.X, point1.X)
local minY = math.min(point0.Y, point1.Y)
local maxY = math.max(point0.Y, point1.Y)
local minZ = math.min(point0.Z, point1.Z)
local maxZ = math.max(point0.Z, point1.Z)



local corner = Instance.new("Part")
	corner.Anchored = true
	corner.Size = Vector3.new(1.2, 1.2, 1.2)
	corner.Position = Vector3.new(minX, minY, minZ)
	corner.Color = Color3.fromRGB(0,255,0)
local corner2 = corner:Clone()
	corner2.Position = Vector3.new(maxX, maxY, maxZ)
	
corner.Parent = game.Workspace 
corner2.Parent = game.Workspace



local region = Region3int16.new(Vector3int16.new(minX/r, minY/r, minZ/r), Vector3int16.new(maxX/r, maxY/r, maxZ/r))
print("Point0", point0)
print("Point1", point1)
print("Region", region)



local terrain = game.Workspace.Terrain:CopyRegion(region)
wait(10)
game.Workspace.Terrain:Clear()
wait(3)
game.Workspace.Terrain:PasteRegion(terrain, Vector3int16.new(minX/r, minY/r, minZ/r), true)
7 Likes