-- This will create an inverted sphere, meant for a skydome or similar
function Script:CreateSphere(latitudeBands, longitudeBands, radius)
local model = Model:Create()
local surface = model:AddSurface()
for latNumber=0,latitudeBands,1
do
local theta = latNumber * math.pi / latitudeBands
local sinTheta = math.sin(theta)
local cosTheta = math.cos(theta)
for longNumber = 0,longitudeBands,1
do
local phi = longNumber * 2 * math.pi / longitudeBands;
local sinPhi = math.sin(phi);
local cosPhi = math.cos(phi);
local x = cosPhi * sinTheta;
local y = cosTheta;
local z = sinPhi * sinTheta;
local u = 1 - (longNumber / longitudeBands);
local v = 1 - (latNumber / latitudeBands);
surface:AddVertex(radius * x, radius * y, radius * z, x, y, z, u, v)
end
end
for latNumber = 0,latitudeBands-1,1
do
for longNumber = 0,longitudeBands-1,1
do
local first = (latNumber * (longitudeBands + 1)) + longNumber;
local second = first + longitudeBands + 1;
surface:AddTriangle(second,second + 1,first + 1)
surface:AddTriangle(first + 1,first,second)
end
end
model:UpdateAABB(Entity.LocalAABB)
model:UpdateAABB(Entity.GlobalAABB)
return model
end