Advertisement
coderboy

Untitled

Sep 27th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.29 KB | None | 0 0
  1. local ANG = {}
  2.  
  3.     local MATH = require(script.Parent.Mathlib)
  4.  
  5.     function buildPoint(x,y,z, parent)
  6.         local point = Instance.new("Part")
  7.         point.Anchored = true
  8.         point.Size = Vector3.new(1,1,1)
  9.         point.CFrame = CFrame.new(x,y,z)
  10.         point.Parent = parent
  11.         point.CanCollide = false
  12.         return point
  13.     end
  14.    
  15.     function setDay(obj, delta)
  16.         game:GetService("Debris"):AddItem(obj, delta)
  17.     end
  18.    
  19.     function connectPoints(p1, p2, parent)
  20.         local beam = Instance.new("Part")
  21.         beam.BrickColor = BrickColor.Black()
  22.         beam.FormFactor = "Custom"
  23.         beam.Material = "Plastic"
  24.         beam.Transparency = 0.25
  25.         beam.Anchored = true
  26.         beam.Locked = true
  27.         beam.CanCollide = false
  28.        
  29.         local distance = (p1 - p2).magnitude
  30.         beam.Size = Vector3.new(0.3, 0.3, distance)
  31.         beam.CFrame = CFrame.new(p1, p2) * CFrame.new(0, 0, -distance / 2)
  32.    
  33.         beam.Parent = parent
  34.         return beam
  35.     end
  36.  
  37.     function ANG:generate()
  38.         local debugContent = Instance.new("Model")
  39.         local map = {}
  40.        
  41.         local render = ANG.settings.debugging.doLiveRendering
  42.         local PR = ANG.settings.debugging.doCreatePR
  43.         local MO = ANG.settings.debugging.doCreateMO
  44.         local yoffset = ANG.settings.debugging.yOffset
  45.         local scaling = ANG.settings.debugging.scaling
  46.        
  47.         local smoothening = ANG.settings.voxelSmoothening
  48.         local layers = ANG.settings.perlin.layers
  49.         local frequency = ANG.settings.perlin.frequency
  50.         local octaves = ANG.settings.perlin.octaves
  51.         local redist = ANG.settings.perlin.redistrobution
  52.         local size = ANG.settings.mapsize
  53.         local seed = ANG.settings.seed
  54.        
  55.         if (render) then
  56.             debugContent.Parent = workspace
  57.         end
  58.        
  59.         -- Build each layer
  60.         for layer=1, layers, 1 do
  61.             map[layer]={}
  62.             for x=1, size, 1 do
  63.                 map[layer][x] = {}
  64.                 for y=1, size, 1 do
  65.                     local height = math.noise( x*frequency[layer], y*frequency[layer], seed*frequency[layer]) * octaves[layer]
  66.                     map[layer][x][y] = height
  67.                 end
  68.             end
  69.         end
  70.        
  71.         -- Create the map
  72.         local finalMap = {}
  73.        
  74.         for x=1, size, 1 do
  75.             finalMap[x] = {}
  76.             for y=1, size, 1 do
  77.                 local height = 0
  78.                
  79.                 for layer=1, layers, 1 do
  80.                     height = height + map[layer][x][y]
  81.                 end
  82.                
  83.                 -- local alt = height^redist
  84.                 -- local alt = height
  85.                 -- local alt = MATH.DPow(height, redist)
  86.                
  87.                 local alt = height * redist
  88.                
  89.                 -- create the mesh ( if rendering is enabled )
  90.                 if (render) then
  91.                     if (PR) then
  92.                         buildPoint(x*scaling, alt+yoffset, y*scaling, debugContent)
  93.                     end
  94.                     if (MO) then
  95.                         local tp = Vector3.new( x*scaling, alt+yoffset, y*scaling )
  96.                         if (x>1) then
  97.                             connectPoints(
  98.                                 tp,
  99.                                 Vector3.new((x-1)*scaling, finalMap[x-1][y]+yoffset, y*scaling),
  100.                                 debugContent
  101.                             )
  102.                         end
  103.                         if (y>1) then
  104.                             connectPoints(
  105.                                 tp,
  106.                                 Vector3.new(x*scaling, finalMap[x][y-1]+yoffset, (y-1)*scaling),
  107.                                 debugContent
  108.                             )
  109.                         end
  110.                     end
  111.                 end
  112.                
  113.                 finalMap[x][y] = alt
  114.             end
  115.             wait()
  116.         end
  117.        
  118.         local result = {}
  119.        
  120.         result.map = finalMap
  121.         result.meta = {
  122.             info={genversion="1.0.0 beta-x"},
  123.             size=size,
  124.         }
  125.         result.scope = debugContent
  126.        
  127.         return result
  128.     end
  129.  
  130. local ANGCreator = {}
  131.  
  132.     function ANGCreator.new(settings)
  133.         local r = setmetatable(ANG, {})
  134.         r.settings = settings
  135.         return r
  136.     end
  137.  
  138. return ANGCreator
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement