Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.48 KB | None | 0 0
  1. "Model")
  2.     local p1 = Instance.new("WedgePart")
  3.     p1.Anchored, p1.Locked = true, true
  4.     p1.TopSurface, p1.BottomSurface, p1.BackSurface = "Smooth", "Smooth", "SmoothNoOutlines"
  5.     local p2 = Instance.new("WedgePart")
  6.     p2.Anchored, p2.Locked = true, true
  7.     p2.TopSurface, p2.BottomSurface, p2.BackSurface = "Smooth", "Smooth", "SmoothNoOutlines"
  8.     p1.Size, p2.Size = s1, s2
  9.     p1.CFrame, p2.CFrame = c1, c2
  10.     p1.Parent, p2.Parent = triangle, triangle
  11.     triangle.Parent = workspace
  12. end
  13.  
  14. local function Polygonise(grid, isolevel)
  15.  
  16.     local cubeindex = 0
  17.     for i = 0, 7 do
  18.         if grid.val[i] < isolevel then
  19.             cubeindex = cubeindex + 2^i
  20.         end
  21.     end
  22.  
  23.     if edgeTable[cubeindex] == 0 then return end
  24.    
  25.     local vertlist = {}
  26.     local groups = {0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7}
  27.     for i = 0, 11 do
  28.         local n = edgeTable[cubeindex]
  29.         local b = 2^i
  30.         if ((n - n%b)/b)%2 == 1 then
  31.             local a, b = groups[i*2+1], groups[i*2+2]
  32.             local p1, p2 = grid.p[a], grid.p[b]
  33.             local valp1, valp2 = grid.val[a], grid.val[b]
  34.             vertlist[i] = p1 + (p2 - p1) * ((isolevel - valp1) / (valp2 - valp1))
  35.         end
  36.     end
  37.    
  38.     for i = 1, 16, 3 do
  39.         local tri = triTable[cubeindex]
  40.         if tri[i] == -1 then break end
  41.         Draw(vertlist[tri[i]], vertlist[tri[i+1]], vertlist[tri[i+2]])
  42.     end
  43. end
  44.  
  45. local cells = {}
  46. for x = 1, sizex do
  47.     cells[x] = {}
  48.     for y = 1, sizey do
  49.         cells[x][y] = {}
  50.         for z = 1, sizez do
  51.             cells[x][y][z] = {p = Vector3.new(x, y, z), val = math.noise(x/precision, y/precision, z/precision)+1}
  52.         end
  53.     end
  54. end
  55.  
  56. local Stepped = game:GetService("RunService").Stepped
  57. local clock = tick()
  58. for x = 1, sizex-1 do
  59.     for y = 1, sizey-1 do
  60.         for z = 1, sizez-1 do
  61.             if tick() - clock > .1 then
  62.                 Stepped:Wait()
  63.                 clock = tick()
  64.             end
  65.             local grid = {p = {}, val = {}}
  66.             local list = {cells[x][y][z], cells[x+1][y][z], cells[x+1][y][z+1], cells[x][y][z+1],
  67.                 cells[x][y+1][z], cells[x+1][y+1][z], cells[x+1][y+1][z+1], cells[x][y+1][z+1]}
  68.             for i = 1, 8 do
  69.                 grid.p[i-1] = list[i].p
  70.                 grid.val[i-1] = list[i].val
  71.             end
  72.             Polygonise(grid, 1)
  73.         end
  74.     end
  75. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement