Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "Model")
- local p1 = Instance.new("WedgePart")
- p1.Anchored, p1.Locked = true, true
- p1.TopSurface, p1.BottomSurface, p1.BackSurface = "Smooth", "Smooth", "SmoothNoOutlines"
- local p2 = Instance.new("WedgePart")
- p2.Anchored, p2.Locked = true, true
- p2.TopSurface, p2.BottomSurface, p2.BackSurface = "Smooth", "Smooth", "SmoothNoOutlines"
- p1.Size, p2.Size = s1, s2
- p1.CFrame, p2.CFrame = c1, c2
- p1.Parent, p2.Parent = triangle, triangle
- triangle.Parent = workspace
- end
- local function Polygonise(grid, isolevel)
- local cubeindex = 0
- for i = 0, 7 do
- if grid.val[i] < isolevel then
- cubeindex = cubeindex + 2^i
- end
- end
- if edgeTable[cubeindex] == 0 then return end
- local vertlist = {}
- 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}
- for i = 0, 11 do
- local n = edgeTable[cubeindex]
- local b = 2^i
- if ((n - n%b)/b)%2 == 1 then
- local a, b = groups[i*2+1], groups[i*2+2]
- local p1, p2 = grid.p[a], grid.p[b]
- local valp1, valp2 = grid.val[a], grid.val[b]
- vertlist[i] = p1 + (p2 - p1) * ((isolevel - valp1) / (valp2 - valp1))
- end
- end
- for i = 1, 16, 3 do
- local tri = triTable[cubeindex]
- if tri[i] == -1 then break end
- Draw(vertlist[tri[i]], vertlist[tri[i+1]], vertlist[tri[i+2]])
- end
- end
- local cells = {}
- for x = 1, sizex do
- cells[x] = {}
- for y = 1, sizey do
- cells[x][y] = {}
- for z = 1, sizez do
- cells[x][y][z] = {p = Vector3.new(x, y, z), val = math.noise(x/precision, y/precision, z/precision)+1}
- end
- end
- end
- local Stepped = game:GetService("RunService").Stepped
- local clock = tick()
- for x = 1, sizex-1 do
- for y = 1, sizey-1 do
- for z = 1, sizez-1 do
- if tick() - clock > .1 then
- Stepped:Wait()
- clock = tick()
- end
- local grid = {p = {}, val = {}}
- local list = {cells[x][y][z], cells[x+1][y][z], cells[x+1][y][z+1], cells[x][y][z+1],
- cells[x][y+1][z], cells[x+1][y+1][z], cells[x+1][y+1][z+1], cells[x][y+1][z+1]}
- for i = 1, 8 do
- grid.p[i-1] = list[i].p
- grid.val[i-1] = list[i].val
- end
- Polygonise(grid, 1)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement