local function a(a)local T={}for X=1,#a,1 do T[X]=CORNERS[a[X]]end return T end local function T(a)local T={}local X=PI2/a for F=1,a,1 do local J=CFrame.fromAxisAngle(RIGHT,F*X)*UP T[F]=RIGHT+J T[a+F]=LEFT+J end return T end local function X(a)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 X={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 F={}local function J(a,X)local J=a<X and a..("\044"..X)or X..("\044"..a)if not F[J]then T[#T+1]=(T[a]+T[X])/2 F[J]=#T end return F[J]end for a=1,a,1 do for a=#X,1,-3 do local T,F,r=X[a-2],X[a-1],X[a]local N=J(T,F)local g=J(F,r)local s=J(r,T)X[#X+1]=T X[#X+1]=N X[#X+1]=s X[#X+1]=F X[#X+1]=g X[#X+1]=N X[#X+1]=r X[#X+1]=s X[#X+1]=g X[#X+1]=N X[#X+1]=g X[#X+1]=s table.remove(X,a)table.remove(X,a-1)table.remove(X,a-2)end end for a=1,#T,1 do T[a]=T[a].Unit end return T end


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
