Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can I un-voxelize voxel terrain?

Asked by 4 years ago

So I made this script that manages to generate some pretty natural terrain in chunks. I want to make it look more natural by making the blocks less "blocky". I know marching cubes might work with that kind of stuff but it limits terrain generation. Is there any other way to "flatten" the terrain?

Script:

chunks = 20
csize = 30
platform = 4
scale = 150
amplitude = 7

seed = math.random(0, 10e5)
print(seed)

fold = Instance.new("Folder")
fold.Name = "PT"
fold.Parent = game.Workspace

part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(platform, 20, platform)
part.Color = Color3.fromRGB(255, 255, 255)
part.Locked = true
part.Parent = game.ServerStorage

w = Instance.new("Part")
w.Anchored = true
w.Size = Vector3.new(platform, 20, platform)
w.Color = Color3.fromRGB(100, 100, 255)
w.Locked = true
w.Transparency = 0.7
w.Parent = game.ServerStorage

function GenChunk(x, z)
    for x = (-csize/2)+x*csize, (csize/2)+x*csize do
        for z = (-csize/2)+z*csize, (csize/2)+z*csize do
            local y1 = math.noise(x/scale/0.5, z/scale/0.5, seed) * amplitude
            local y2 = math.noise(x/scale, z/scale, seed) * amplitude*3
            local y3 = math.noise(x/scale/1.75, z/scale/1.75, seed) * amplitude*4

            local y = (y1 * y2 * y3)/2

            local p = part:Clone()
            p.CFrame = CFrame.new(Vector3.new(platform*x, y, platform*z))

            if y <= -1 then
                p.Color = Color3.fromRGB(200, 200, 50)
            end
            if y > -1 and y <= 0 then
                p.Color = Color3.fromRGB(100, 50, 0)
            end
            if y > 0 and y <= 2 then
                p.Color = Color3.fromRGB(150, 75, 25)
            end
            if y > 2 and y <= 29 then
                p.Color = Color3.fromRGB(50, 150, 50)
            end
            if y > 29 and y <= 51 then
                p.Color = Color3.fromRGB(50, 100, 50)
            end
            if y > 51 and y <= 65 then
                p.Color = Color3.fromRGB(100, 125, 100)
            end
            if y > 65 then
                p.Color = Color3.fromRGB(200, 200, 200)
            end

            p.Parent = fold

            local wa = w:Clone()
            wa.CFrame = CFrame.new(Vector3.new(platform*x, -3, platform*z))
            wa.Parent = game.Workspace.PT
        end
    end
end

for x = -chunks/2, chunks/2 do
    for z = -chunks/2, chunks/2 do
        wait()
        GenChunk(x, z)
    end
end

print("Done!")

function close()
    game.Workspace.PT:Destroy()
end

game:BindToClose(close)

Image of example terrain: Image_1

Answer this question