Advertisement
eea

3dnoise

eea
Dec 10th, 2021 (edited)
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.91 KB | None | 0 0
  1. local Remote = Instance.new("RemoteEvent", owner.Character)
  2. Remote.Name = "G"
  3. local db
  4.  
  5. local o = game.Players.LocalPlayer
  6. local c = workspace.CurrentCamera
  7. local sg = Instance.new("ScreenGui", owner.PlayerGui)
  8. sg.Name = "PN"
  9. local re = owner.Character:WaitForChild("G")
  10. local b = Instance.new("TextButton", sg)
  11.  
  12. b.Size = UDim2.fromScale(.2 / c.ViewportSize.X, .1 / c.ViewportSize.Y)
  13. b.Position = UDim2.fromOffset(1000 / c.ViewportSize.X, 600 /c.ViewportSize.Y)
  14. b.Text = "Generate"
  15. local r = Instance.new("UICorner")
  16. r.Parent = b
  17.  
  18. NLS([[
  19. owner.PlayerGui.PN.TextButton.MouseButton1Click:Connect(function()
  20.    
  21.     owner.Character.G:FireServer()
  22.    
  23. end)
  24. ]], owner.Character)
  25.  
  26. local Blocks = {}
  27. local Tween = game:GetService("TweenService")
  28. local Settings = {}
  29.  
  30. Settings.XIter = 20
  31. Settings.YIter = 20
  32. Settings.ZIter = 20
  33.  
  34. Settings.XOffset = 0
  35. Settings.YOffset = 1
  36. Settings.ZOffset = 0
  37.  
  38. Settings.Fill = 0
  39. Settings.Detail = 7.4
  40.  
  41. Settings.Union = true
  42.  
  43. Settings.TerrainProperties = {}
  44.  
  45. Settings.TerrainProperties.Terrain = false
  46. Settings.TerrainProperties.Material = Enum.Material.Grass
  47.  
  48. Settings.BlockProperties = {}
  49.  
  50. Settings.BlockProperties.Size = Vector3.new(4,4,4)
  51. Settings.BlockProperties.Material = "SmoothPlastic"
  52. Settings.BlockProperties.Anchored = true
  53. Settings.BlockProperties.Transparency = 0
  54.  
  55. local uh = Instance.new("Part",folder)
  56. uh.Name = "uh"
  57. uh.Position = Vector3.new(0,20,0)
  58. uh.Size = Vector3.new(1,1,1)
  59. uh.Transparency = 1
  60. uh.Anchored = true
  61.  
  62. local i = TweenInfo.new(
  63.  
  64.    .8,
  65.    Enum.EasingStyle.Bounce,
  66.    Enum.EasingDirection.Out,
  67.    0,
  68.    false,
  69.    .1
  70.  
  71. )
  72.  
  73. local Functions = {}
  74.  
  75. function Functions:ThreeDimensionalNoise(x, y, z, folder, seed)
  76.    local noise = math.noise((x + seed) / Settings.Detail, (y + seed) / Settings.Detail, (z + seed) / Settings.Detail) + Settings.Fill
  77.  
  78.    local cnoise = math.clamp(noise, -0.5, 0.5)
  79.    if cnoise >= 0 then
  80.       local b = Instance.new("SpawnLocation", folder)
  81.       b.Enabled = false
  82.       b.Size = Settings.BlockProperties.Size
  83.       b.Anchored = Settings.BlockProperties.Anchored
  84.       b.Position = owner.Character.HumanoidRootPart.Position + Vector3.new(0,5,0) + Vector3.new(0,(Settings.BlockProperties.Size.Y/2),0)
  85.       b.Color = Color3.new(cnoise + 0.5, cnoise + 0.5, cnoise + 0.5)
  86.       b.Material = Settings.BlockProperties.Material
  87.       b.CanCollide = false
  88.       b.Locked = true
  89.  
  90.       local t = Tween:Create(b, i, {Position = (Vector3.new(x,y,z) * Settings.BlockProperties.Size) + Vector3.new(Settings.XOffset, Settings.YOffset, Settings.ZOffset)})
  91.  
  92.       t:Play()
  93.       table.insert(Blocks, b)  
  94.       t.Completed:Connect(function()
  95.          b.CanCollide = true
  96.          if Settings.TerrainProperties.Terrain then
  97.             workspace.Terrain:FillBlock(b.CFrame, b.Size, Settings.TerrainProperties.Material)
  98.             b:Destroy()
  99.          end
  100.       end)  
  101.    end
  102. end
  103.  
  104. function Functions:MakeFolder(parent)
  105.    return Instance.new("Folder", parent)
  106. end
  107.  
  108. function Functions:GetSeed()
  109.    return math.random(1,10000000)
  110. end
  111.  
  112. Remote.OnServerEvent:Connect(function()
  113.    if not workspace:FindFirstChild("PN") and not db then
  114.       db = true
  115.       local s = Functions:GetSeed()
  116.       local folder = Functions:MakeFolder(workspace)
  117.       folder.Name = "PN"
  118.       for xc = 1,Settings.XIter,1 do
  119.          for yc = 1,Settings.YIter,1 do
  120.             for zc = 1,Settings.YIter,1 do
  121.                local s, e = pcall(function()
  122.                   Functions:ThreeDimensionalNoise(xc, yc, zc, folder, s)
  123.                end)
  124.  
  125.                if e then
  126.                   wait(2.5)
  127.                   Functions:ThreeDimensionalNoise(xc, yc, zc, folder, s)
  128.                end
  129.             end
  130.             wait()
  131.          end
  132.          wait()
  133.       end
  134.       if Settings.Union then
  135.          local u = uh:UnionAsync(Blocks)
  136.          u.Anchored = true
  137.          u.Name = "Noise"
  138.          u.Parent = folder
  139.          u.Transparency = 0
  140.       end
  141.       wait(.5)
  142.       db = false
  143.    elseif workspace:FindFirstChild("PN") and not db then
  144.       db = true
  145.       local s = Functions:GetSeed()
  146.       workspace:FindFirstChild("PN"):Destroy()
  147.       local folder = Functions:MakeFolder(workspace)
  148.       folder.Name = "PN"
  149.       for xc = 1,Settings.XIter,1 do
  150.          for yc = 1,Settings.YIter,1 do
  151.             for zc = 1,Settings.YIter,1 do
  152.                local s, e = pcall(function()
  153.                   Functions:ThreeDimensionalNoise(xc, yc, zc, folder, s)
  154.                end)
  155.  
  156.                if e then
  157.                   wait(2.5)
  158.                   Functions:ThreeDimensionalNoise(xc, yc, zc, folder, s)
  159.                end
  160.             end
  161.             wait()
  162.          end
  163.          wait()
  164.       end
  165.       if Settings.Union then
  166.          local u = uh:UnionAsync(Blocks)
  167.          u.Anchored = true
  168.          u.Name = "Noise"
  169.          u.Parent = folder
  170.          u.Transparency = 0
  171.       end
  172.       wait(.5)
  173.       db = false
  174.    end
  175. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement