local function P(P)local T={}for N=1,#P,1 do T[N]=CORNERS[P[N]]end return T end local function T(P)local T={}local N=PI2/P for p=1,P,1 do local b=CFrame.fromAxisAngle(RIGHT,p*N)*UP T[p]=RIGHT+b T[P+p]=LEFT+b end return T end local function N(P)local T={Vector3.new(-1,PHI,0);Vector3.new(1,PHI,0);Vector3.new(-1,-PHI,0);Vector3.new(1,-PHI,0),Vector3.new(0,-1,PHI);Vector3.new(0,1,PHI),Vector3.new(0,-1,-PHI),Vector3.new(0,1,-PHI),Vector3.new(PHI,0,-1);Vector3.new(PHI,0,1);Vector3.new(-PHI,0,-1);Vector3.new(-PHI,0,1)}local N={1,12;6,1;6;2;1,2,8;1;8;11;1,11;12;2;6;10;6;12,5;12,11;3,11;8;7;8,2;9;4;10,5,4;5;3;4;3,7,4,7,9,4,9,10;5,10;6;3,5;12,7;3,11;9,7;8;10;9,2}local p={}local function b(P,N)local b=P<N and P..("\044"..N)or N..("\044"..P)if not p[b]then T[#T+1]=(T[P]+T[N])/2 p[b]=#T end return p[b]end for P=1,P,1 do for P=#N,1,-3 do local T,p,Q=N[P-2],N[P-1],N[P]local d=b(T,p)local k=b(p,Q)local e=b(Q,T)N[#N+1]=T N[#N+1]=d N[#N+1]=e N[#N+1]=p N[#N+1]=k N[#N+1]=d N[#N+1]=Q N[#N+1]=e N[#N+1]=k N[#N+1]=d N[#N+1]=k N[#N+1]=e table.remove(N,P)table.remove(N,P-1)table.remove(N,P-2)end end for P=1,#T,1 do T[P]=T[P].Unit end return T end
-- VERTICE FUNCTIONS

local function fromIndexArray(array)
	local output = {}
	for i = 1, #array do
		output[i] = CORNERS[array[i]]
	end
	return output
end

local function cylinder(n)
	local output = {}
	local arc = PI2 / n
	for i = 1, n do
		local vi = CFrame.fromAxisAngle(RIGHT, i * arc) * UP
		output[i] = RIGHT + vi
		output[n + i] = LEFT + vi
	end
	return output
end

local function icoSphere(n)
	local verts = {
		Vector3.new(-1, PHI, 0),
		Vector3.new(1, PHI, 0),
		Vector3.new(-1, -PHI, 0),
		Vector3.new(1, -PHI, 0),

		Vector3.new(0, -1, PHI),
		Vector3.new(0, 1, PHI),
		Vector3.new(0, -1, -PHI),
		Vector3.new(0, 1, -PHI),

		Vector3.new(PHI, 0, -1),
		Vector3.new(PHI, 0, 1),
		Vector3.new(-PHI, 0, -1),
		Vector3.new(-PHI, 0, 1),
	}

	local indices = {
		1,
		12,
		6,
		1,
		6,
		2,
		1,
		2,
		8,
		1,
		8,
		11,
		1,
		11,
		12,

		2,
		6,
		10,
		6,
		12,
		5,
		12,
		11,
		3,
		11,
		8,
		7,
		8,
		2,
		9,

		4,
		10,
		5,
		4,
		5,
		3,
		4,
		3,
		7,
		4,
		7,
		9,
		4,
		9,
		10,

		5,
		10,
		6,
		3,
		5,
		12,
		7,
		3,
		11,
		9,
		7,
		8,
		10,
		9,
		2,
	}

	local splits = {}

	local function split(i, j)
		local key = i < j and (i .. "," .. j) or (j .. "," .. i)

		if not splits[key] then
			verts[#verts + 1] = (verts[i] + verts[j]) / 2
			splits[key] = #verts
		end

		return splits[key]
	end

	for _ = 1, n do
		for i = #indices, 1, -3 do
			local v1, v2, v3 = indices[i - 2], indices[i - 1], indices[i]
			local a = split(v1, v2)
			local b = split(v2, v3)
			local c = split(v3, v1)

			indices[#indices + 1] = v1
			indices[#indices + 1] = a
			indices[#indices + 1] = c

			indices[#indices + 1] = v2
			indices[#indices + 1] = b
			indices[#indices + 1] = a

			indices[#indices + 1] = v3
			indices[#indices + 1] = c
			indices[#indices + 1] = b

			indices[#indices + 1] = a
			indices[#indices + 1] = b
			indices[#indices + 1] = c

			table.remove(indices, i)
			table.remove(indices, i - 1)
			table.remove(indices, i - 2)
		end
	end

	-- normalize
	for i = 1, #verts do
		verts[i] = verts[i].Unit
	end

	return verts
end
