shadmar Posted July 18, 2014 Share Posted July 18, 2014 -- 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 2 Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.