Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ANG = {}
- local MATH = require(script.Parent.Mathlib)
- function buildPoint(x,y,z, parent)
- local point = Instance.new("Part")
- point.Anchored = true
- point.Size = Vector3.new(1,1,1)
- point.CFrame = CFrame.new(x,y,z)
- point.Parent = parent
- point.CanCollide = false
- return point
- end
- function setDay(obj, delta)
- game:GetService("Debris"):AddItem(obj, delta)
- end
- function connectPoints(p1, p2, parent)
- local beam = Instance.new("Part")
- beam.BrickColor = BrickColor.Black()
- beam.FormFactor = "Custom"
- beam.Material = "Plastic"
- beam.Transparency = 0.25
- beam.Anchored = true
- beam.Locked = true
- beam.CanCollide = false
- local distance = (p1 - p2).magnitude
- beam.Size = Vector3.new(0.3, 0.3, distance)
- beam.CFrame = CFrame.new(p1, p2) * CFrame.new(0, 0, -distance / 2)
- beam.Parent = parent
- return beam
- end
- function ANG:generate()
- local debugContent = Instance.new("Model")
- local map = {}
- local render = ANG.settings.debugging.doLiveRendering
- local PR = ANG.settings.debugging.doCreatePR
- local MO = ANG.settings.debugging.doCreateMO
- local yoffset = ANG.settings.debugging.yOffset
- local scaling = ANG.settings.debugging.scaling
- local smoothening = ANG.settings.voxelSmoothening
- local layers = ANG.settings.perlin.layers
- local frequency = ANG.settings.perlin.frequency
- local octaves = ANG.settings.perlin.octaves
- local redist = ANG.settings.perlin.redistrobution
- local size = ANG.settings.mapsize
- local seed = ANG.settings.seed
- if (render) then
- debugContent.Parent = workspace
- end
- -- Build each layer
- for layer=1, layers, 1 do
- map[layer]={}
- for x=1, size, 1 do
- map[layer][x] = {}
- for y=1, size, 1 do
- local height = math.noise( x*frequency[layer], y*frequency[layer], seed*frequency[layer]) * octaves[layer]
- map[layer][x][y] = height
- end
- end
- end
- -- Create the map
- local finalMap = {}
- for x=1, size, 1 do
- finalMap[x] = {}
- for y=1, size, 1 do
- local height = 0
- for layer=1, layers, 1 do
- height = height + map[layer][x][y]
- end
- -- local alt = height^redist
- -- local alt = height
- -- local alt = MATH.DPow(height, redist)
- local alt = height * redist
- -- create the mesh ( if rendering is enabled )
- if (render) then
- if (PR) then
- buildPoint(x*scaling, alt+yoffset, y*scaling, debugContent)
- end
- if (MO) then
- local tp = Vector3.new( x*scaling, alt+yoffset, y*scaling )
- if (x>1) then
- connectPoints(
- tp,
- Vector3.new((x-1)*scaling, finalMap[x-1][y]+yoffset, y*scaling),
- debugContent
- )
- end
- if (y>1) then
- connectPoints(
- tp,
- Vector3.new(x*scaling, finalMap[x][y-1]+yoffset, (y-1)*scaling),
- debugContent
- )
- end
- end
- end
- finalMap[x][y] = alt
- end
- wait()
- end
- local result = {}
- result.map = finalMap
- result.meta = {
- info={genversion="1.0.0 beta-x"},
- size=size,
- }
- result.scope = debugContent
- return result
- end
- local ANGCreator = {}
- function ANGCreator.new(settings)
- local r = setmetatable(ANG, {})
- r.settings = settings
- return r
- end
- return ANGCreator
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement