local function S(S,w,J)local Z=w:Inverse()for S,w in next,S:GetDescendants()do w.CFrame=J*(Z*w.CFrame)end end local function w(S,w,J,Z)local u=Instance.new("\077\111\100\101\108")local a=(TAU*J)/S-GAP local l=(TAU*w)/S-GAP local x=a/J local K=l/w local v=x-K local H={}local O={}local r=math.ceil(a/Z)for S=0,r,1 do H[S+1]=(CENTER*CFrame.fromEulerAnglesXYZ(0,0,(S/r)*x))*Vector3.new(J,0,0)O[S+1]=(CENTER*CFrame.fromEulerAnglesXYZ(0,0,v/2+(S/r)*K))*Vector3.new(w,0,0)end for S=1,r,1 do local w=H[S]local J=O[S]local Z=H[S+1]local a=O[S+1]Triangle(u,w,J,Z)Triangle(u,J,Z,a)end return u end local function J(J,Z,u)u=u or 0 local a=(1-Z)*EXTERIOR_RADIUS-1 local l=a-2 local x=w(J,(1-Z)*EXTERIOR_RADIUS,EXTERIOR_RADIUS,PART_PER_UNIT)local K=w(J,l,a,PART_PER_UNIT/2)local v=Instance.new("\070\114\097\109\101")local H=Instance.new("\070\114\097\109\101")local O=Instance.new("\070\114\097\109\101")H.BackgroundTransparency=1 O.BackgroundTransparency=1 H.Size=UDim2.new(1,0,1,0)O.Size=UDim2.new(1,0,1,0)H.Name="\082\097\100\105\097\108"O.Name="\065\116\116\097\099\104"H.Parent=v O.Parent=v local r=Z*EXTERIOR_RADIUS local g=EXTERIOR_RADIUS-r local f=1-Z/2 local Y=(TAU*EXTERIOR_RADIUS)/J local y=Y/EXTERIOR_RADIUS local n=(TAU*g)/J-GAP local Q=n/g local e=Vector2.new(math.cos(Q),math.sin(Q))*g-Vector2.new(g,0)local A=math.min(e.Magnitude/(EXTERIOR_RADIUS*2),.18)for w=0,J-1,1 do local Z=VPF:Clone()local a=CAMERA:Clone()Z.CurrentCamera=a Z.Name=w+1 local l=(w/J)*TAU+u local K=x:Clone()S(K,CENTER,CENTER*CFrame.fromEulerAnglesXYZ(0,0,l+EX_OFFSET))K.Parent=Z local v=((l-EX_OFFSET)+y/2)+G_OFFSET local r=(-math.cos(v)/2)*f local g=(math.sin(v)/2)*f local Y=Instance.new("\070\114\097\109\101")Y.Name=w+1 Y.BackgroundTransparency=1 Y.BackgroundColor3=Color3.new()Y.BorderSizePixel=0 Y.AnchorPoint=Vector2.new(.5,.5)Y.Position=UDim2.new(.5+r,0,.5+g,0)Y.Size=UDim2.new(A,0,A,0)Y.Parent=O a.Parent=Z Z.Parent=H end x:Destroy()local U=VPF:Clone()local j=CAMERA:Clone()U.CurrentCamera=j U.Name="\082\097\100\105\097\108\068\105\097\108"local L=GAP/(2*a)local G=-TAU/4+L S(K,CENTER,CENTER*CFrame.fromEulerAnglesXYZ(0,0,u+G))K.Parent=U U.Parent=v v.BackgroundTransparency=1 v.SizeConstraint=Enum.SizeConstraint.RelativeYY v.Size=UDim2.new(1,0,1,0)return v end
--

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
