Triangles for sphere
I have been trying to make a sphere through code for a couple of hours now, I have got the vertices part working but I am stuck on getting the triangles to work. When I try to run my test example I get some hollow bowl looking thing, I have checked that there isn't anything wrong with the vertices with Gizmos, here is the code I tried using:
private void CreateTriangles()
{
int len = vertices.Length;
//Top Cap
int i = 0;
for (int lon = 0; lon < Width; lon++)
{
triangles[i++] = lon + 2;
triangles[i++] = lon + 1;
triangles[i++] = 0;
}
//Middle
for (int lat = 0; lat < Width - 1; lat++)
{
for (int lon = 0; lon < Width; lon++)
{
int current = lon + lat * (Width + 1) + 1;
int next = current + Width + 1;
triangles[i++] = current;
triangles[i++] = current + 1;
triangles[i++] = next + 1;
triangles[i++] = current;
triangles[i++] = next + 1;
triangles[i++] = next;
}
}
//Bottom Cap
for (int lon = 0; lon < Width; lon++)
{
triangles[i++] = len - 1;
triangles[i++] = len - (lon + 2) - 1;
triangles[i++] = len - (lon + 1) - 1;
}
}
If you need more code to understand the problem just ask. Result:
Hi @$$anonymous$$akakWasTaken
You could download this package, it has an example in it to create sphere from code:
I have now fixed it on the outside, but my code generates a web of passing edges on the inside of my sphere: Pastebin
Your answer
Follow this Question
Related Questions
Triangles become black when flipping triangles 0 Answers
Seamless Terrain on Quad Sphere 0 Answers
Generating Mesh using Points 1 Answer
Procedural generated meshes to be used w/o procedure 1 Answer
How can I make my L-system trees 3d. 0 Answers