local A=require(script.Parent:WaitForChild("\067\079\078\083\084\065\078\084\083"))local m=require(script.Parent:WaitForChild("\084\114\105\097\110\103\108\101"))local Y=math.pi/2 local x=A.TAU local a=A.GAP local s=A.PART_PER_UNIT local t=A.CENTER local I=A.EXTERIOR_RADIUS local Q=A.EX_OFFSET local Z=A.G_OFFSET local W=Instance.new("\086\105\101\119\112\111\114\116\070\114\097\109\101")W.Ambient=Color3.new(1,1,1)W.LightColor=Color3.new(1,1,1)W.LightDirection=Vector3.new(0,0,-1)W.BackgroundTransparency=1 W.Size=UDim2.new(1,0,1,0)local D=Instance.new("\067\097\109\101\114\097")D.CameraType=Enum.CameraType.Scriptable D.CFrame=CFrame.new()D.FieldOfView=A.FOV local function o(A,m,Y)local x=m:Inverse()for A,m in next,A:GetDescendants()do m.CFrame=Y*(x*m.CFrame)end end local function P(A,Y,s,I)local Q=Instance.new("\077\111\100\101\108")local Z=(x*s)/A-a local W=(x*Y)/A-a local D=Z/s local o=W/Y local P=D-o local q={}local i={}local c=math.ceil(Z/I)for A=0,c,1 do q[A+1]=(t*CFrame.fromEulerAnglesXYZ(0,0,(A/c)*D))*Vector3.new(s,0,0)i[A+1]=(t*CFrame.fromEulerAnglesXYZ(0,0,P/2+(A/c)*o))*Vector3.new(Y,0,0)end for A=1,c,1 do local Y=q[A]local x=i[A]local a=q[A+1]local s=i[A+1]m(Q,Y,x,a)m(Q,x,a,s)end return Q end local function q(A,m,Y)Y=Y or 0 local q=(1-m)*I-1 local i=q-2 local c=P(A,(1-m)*I,I,s)local j=P(A,i,q,s/2)local r=Instance.new("\070\114\097\109\101")local B=Instance.new("\070\114\097\109\101")local b=Instance.new("\070\114\097\109\101")B.BackgroundTransparency=1 b.BackgroundTransparency=1 B.Size=UDim2.new(1,0,1,0)b.Size=UDim2.new(1,0,1,0)B.Name="\082\097\100\105\097\108"b.Name="\065\116\116\097\099\104"B.Parent=r b.Parent=r local p=m*I local M=I-p local v=1-m/2 local H=(x*I)/A local R=H/I local F=(x*M)/A-a local E=F/M local G=Vector2.new(math.cos(E),math.sin(E))*M-Vector2.new(M,0)local d=math.min(G.Magnitude/(I*2),.18)for m=0,A-1,1 do local a=W:Clone()local s=D:Clone()a.CurrentCamera=s a.Name=m+1 local I=(m/A)*x+Y local P=c:Clone()o(P,t,t*CFrame.fromEulerAnglesXYZ(0,0,I+Q))P.Parent=a local q=((I-Q)+R/2)+Z local i=(-math.cos(q)/2)*v local j=(math.sin(q)/2)*v local r=Instance.new("\070\114\097\109\101")r.Name=m+1 r.BackgroundTransparency=1 r.BackgroundColor3=Color3.new()r.BorderSizePixel=0 r.AnchorPoint=Vector2.new(.5,.5)r.Position=UDim2.new(.5+i,0,.5+j,0)r.Size=UDim2.new(d,0,d,0)r.Parent=b s.Parent=a a.Parent=B end c:Destroy()local g=W:Clone()local K=D:Clone()g.CurrentCamera=K g.Name="\082\097\100\105\097\108\068\105\097\108"local V=a/(2*q)local w=-x/4+V o(j,t,t*CFrame.fromEulerAnglesXYZ(0,0,Y+w))j.Parent=g g.Parent=r r.BackgroundTransparency=1 r.SizeConstraint=Enum.SizeConstraint.RelativeYY r.Size=UDim2.new(1,0,1,0)return r end return q
-- CONSTANTS

local CONSTANTS = require(script.Parent:WaitForChild("CONSTANTS"))
local Triangle = require(script.Parent:WaitForChild("Triangle"))

local PI2 = math.pi/2
local TAU = CONSTANTS.TAU

local GAP = CONSTANTS.GAP
local PART_PER_UNIT = CONSTANTS.PART_PER_UNIT

local CENTER = CONSTANTS.CENTER
local EXTERIOR_RADIUS = CONSTANTS.EXTERIOR_RADIUS
local EX_OFFSET = CONSTANTS.EX_OFFSET
local G_OFFSET = CONSTANTS.G_OFFSET

local VPF = Instance.new("ViewportFrame")
VPF.Ambient = Color3.new(1, 1, 1)
VPF.LightColor = Color3.new(1, 1, 1)
VPF.LightDirection = Vector3.new(0, 0, -1)
VPF.BackgroundTransparency = 1
VPF.Size = UDim2.new(1, 0, 1, 0)

local CAMERA = Instance.new("Camera")
CAMERA.CameraType = Enum.CameraType.Scriptable
CAMERA.CFrame = CFrame.new()
CAMERA.FieldOfView = CONSTANTS.FOV

--

local function pivotAround(model, pivotCF, newCF)
	local invPivotCF = pivotCF:Inverse()
	for _, part in next, model:GetDescendants() do
		part.CFrame = newCF * (invPivotCF * part.CFrame)
	end
end

local function createSection(subN, interior_radius, exterior_radius, ppu)
	local subModel = Instance.new("Model")
	
	local exCircum = (TAU*exterior_radius)/subN - GAP
	local inCircum = (TAU*interior_radius)/subN - GAP

	local exTheta = exCircum / (exterior_radius)
	local inTheta = inCircum / (interior_radius)
	local diffTheta = exTheta - inTheta
	
	local exPoints = {}
	local inPoints = {}
	
	local nParts = math.ceil(exCircum/ppu)
	
	for i = 0, nParts do
		exPoints[i + 1] = CENTER * CFrame.fromEulerAnglesXYZ(0, 0, (i/nParts)*exTheta) * Vector3.new(exterior_radius, 0, 0)
		inPoints[i + 1] = CENTER * CFrame.fromEulerAnglesXYZ(0, 0, diffTheta/2 + (i/nParts)*inTheta) * Vector3.new(interior_radius, 0, 0)
	end
	
	for i = 1, nParts do
		local a = exPoints[i]
		local b = inPoints[i]
		local c = exPoints[i + 1]
		local d = inPoints[i + 1]
		
		Triangle(subModel, a, b, c)
		Triangle(subModel, b, c, d)
	end
	
	return subModel
end

local function createRadial(subN, tPercent, rotation)
	rotation = rotation or 0
	
	local dialEx = (1 - tPercent)*EXTERIOR_RADIUS - 1
	local dialIn = dialEx - 2
	
	local section = createSection(subN, (1 - tPercent)*EXTERIOR_RADIUS, EXTERIOR_RADIUS, PART_PER_UNIT)
	local innerSection = createSection(subN, dialIn, dialEx, PART_PER_UNIT/2)
	
	local frame = Instance.new("Frame")
	local radialFrame = Instance.new("Frame")
	local attachFrame = Instance.new("Frame")
	radialFrame.BackgroundTransparency = 1
	attachFrame.BackgroundTransparency = 1
	radialFrame.Size = UDim2.new(1, 0, 1, 0)
	attachFrame.Size = UDim2.new(1, 0, 1, 0)
	radialFrame.Name = "Radial"
	attachFrame.Name = "Attach"
	radialFrame.Parent = frame
	attachFrame.Parent = frame
	
	local thickness = tPercent * EXTERIOR_RADIUS
	local interior_radius = EXTERIOR_RADIUS - thickness
	local inv_tPercent = 1 - tPercent/2
	
	local exCircum = (TAU*EXTERIOR_RADIUS)/subN
	local exTheta = exCircum / EXTERIOR_RADIUS
	local inCircum = (TAU*interior_radius)/subN - GAP
	local inTheta = inCircum / (interior_radius)
	
	local edge = Vector2.new(math.cos(inTheta), math.sin(inTheta))*interior_radius - Vector2.new(interior_radius, 0)
	local edgeLen = math.min(edge.Magnitude / (EXTERIOR_RADIUS*2), 0.18)
	
	for i = 0, subN - 1 do
		local vpf = VPF:Clone()
		local cam = CAMERA:Clone()
		vpf.CurrentCamera = cam
		vpf.Name = i + 1
		
		local theta = (i/subN)*TAU + rotation
		
		local sub = section:Clone()
		pivotAround(sub, CENTER, CENTER * CFrame.fromEulerAnglesXYZ(0, 0, theta + EX_OFFSET))
		sub.Parent = vpf
		
		local t = theta - EX_OFFSET + exTheta/2 + G_OFFSET
		local c = -math.cos(t)/2 * inv_tPercent
		local s = math.sin(t)/2 * inv_tPercent
		
		local attach = Instance.new("Frame")
		attach.Name = i + 1
		attach.BackgroundTransparency = 1
		attach.BackgroundColor3 = Color3.new()
		attach.BorderSizePixel = 0
		attach.AnchorPoint = Vector2.new(0.5, 0.5)
		attach.Position = UDim2.new(0.5 + c, 0, 0.5 + s, 0)
		attach.Size = UDim2.new(edgeLen, 0, edgeLen, 0)
		attach.Parent = attachFrame
		
		cam.Parent = vpf
		vpf.Parent = radialFrame
	end
	
	section:Destroy()
	
	local vpf = VPF:Clone()
	local cam = CAMERA:Clone()
	vpf.CurrentCamera = cam
	vpf.Name = "RadialDial"
	
	local g = GAP / (2*dialEx)
	local off = -TAU/4 + g
	
	pivotAround(innerSection, CENTER, CENTER * CFrame.fromEulerAnglesXYZ(0, 0, rotation + off))
	innerSection.Parent = vpf
	vpf.Parent = frame
	
	frame.BackgroundTransparency = 1
	frame.SizeConstraint = Enum.SizeConstraint.RelativeYY
	frame.Size = UDim2.new(1, 0, 1, 0)
	return frame
end

--

return createRadial