local x=require(script.Parent:WaitForChild("\067\079\078\083\084\065\078\084\083"))local C=require(script.Parent:WaitForChild("\084\114\105\097\110\103\108\101"))local I=math.pi/2 local N=x.TAU local X=x.GAP local a=x.PART_PER_UNIT local O=x.CENTER local q=x.EXTERIOR_RADIUS local c=x.EX_OFFSET local i=x.G_OFFSET local T=Instance.new("\086\105\101\119\112\111\114\116\070\114\097\109\101")T.Ambient=Color3.new(1,1,1)T.LightColor=Color3.new(1,1,1)T.LightDirection=Vector3.new(0,0,-1)T.BackgroundTransparency=1 T.Size=UDim2.new(1,0,1,0)local h=Instance.new("\067\097\109\101\114\097")h.CameraType=Enum.CameraType.Scriptable h.CFrame=CFrame.new()h.FieldOfView=x.FOV local function V(x,C,I)local N=C:Inverse()for x,C in next,x:GetDescendants()do C.CFrame=I*(N*C.CFrame)end end local function Z(x,I,a,q)local c=Instance.new("\077\111\100\101\108")local i=(N*a)/x-X local T=(N*I)/x-X local h=i/a local V=T/I local Z=h-V local F={}local y={}local s=math.ceil(i/q)for x=0,s,1 do F[x+1]=(O*CFrame.fromEulerAnglesXYZ(0,0,(x/s)*h))*Vector3.new(a,0,0)y[x+1]=(O*CFrame.fromEulerAnglesXYZ(0,0,Z/2+(x/s)*V))*Vector3.new(I,0,0)end for x=1,s,1 do local I=F[x]local N=y[x]local X=F[x+1]local a=y[x+1]C(c,I,N,X)C(c,N,X,a)end return c end local function F(x,C,I)I=I or 0 local F=(1-C)*q-1 local y=F-2 local s=Z(x,(1-C)*q,q,a)local L=Z(x,y,F,a/2)local U=Instance.new("\070\114\097\109\101")local r=Instance.new("\070\114\097\109\101")local J=Instance.new("\070\114\097\109\101")r.BackgroundTransparency=1 J.BackgroundTransparency=1 r.Size=UDim2.new(1,0,1,0)J.Size=UDim2.new(1,0,1,0)r.Name="\082\097\100\105\097\108"J.Name="\065\116\116\097\099\104"r.Parent=U J.Parent=U local D=C*q local p=q-D local K=1-C/2 local o=(N*q)/x local G=o/q local f=(N*p)/x-X local w=f/p local S=Vector2.new(math.cos(w),math.sin(w))*p-Vector2.new(p,0)local B=math.min(S.Magnitude/(q*2),.18)for C=0,x-1,1 do local X=T:Clone()local a=h:Clone()X.CurrentCamera=a X.Name=C+1 local q=(C/x)*N+I local Z=s:Clone()V(Z,O,O*CFrame.fromEulerAnglesXYZ(0,0,q+c))Z.Parent=X local F=((q-c)+G/2)+i local y=(-math.cos(F)/2)*K local L=(math.sin(F)/2)*K local U=Instance.new("\070\114\097\109\101")U.Name=C+1 U.BackgroundTransparency=1 U.BackgroundColor3=Color3.new()U.BorderSizePixel=0 U.AnchorPoint=Vector2.new(.5,.5)U.Position=UDim2.new(.5+y,0,.5+L,0)U.Size=UDim2.new(B,0,B,0)U.Parent=J a.Parent=X X.Parent=r end s:Destroy()local g=T:Clone()local A=h:Clone()g.CurrentCamera=A g.Name="\082\097\100\105\097\108\068\105\097\108"local M=X/(2*F)local e=-N/4+M V(L,O,O*CFrame.fromEulerAnglesXYZ(0,0,I+e))L.Parent=g g.Parent=U U.BackgroundTransparency=1 U.SizeConstraint=Enum.SizeConstraint.RelativeYY U.Size=UDim2.new(1,0,1,0)return U end return F
-- 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