Sphere grid layout?

Hello guys i am trying to create sphere grid do you know some good tutorial on it?
Currently i am using generator i made for circle grid but thats only work in 2d.I want similar thing but for 3d but cant fgure out how to do it.

Circle grid is this.Thanks for any tips you can give me

  float radiusSquared = gridRadius * gridRadius;
                    for (float x = -gridRadius ; x <= gridRadius - 1; ++x)
                    {
                        for (float y = -gridRadius; y <= gridRadius - 1; ++y)
                        {

                            if (new Vector2(x, y).sqrMagnitude <= radiusSquared)
                            {

                                int randomObject = RandomNumber(1, 100);



                                if (randomObject >= 0 && randomObject <= 10)
                                {
                                    saveSoilPosition = new float[4];
                                    saveSoilPosition[0] = x;
                                    saveSoilPosition[1] = y;
                                    saveSoilPosition[2] = 0;
                                    saveSoilPosition[3] = 0;

                                    saveList.Add(new positionOBject { mineralPosition = saveSoilPosition });

                                    soilCountList.Add(1);



                                    soilCountList.Add(1);
                                } //Soil
                                if (randomObject >= 11 && randomObject <= 84)
                                {

                                    saveIronPosition = new float[4];
                                    saveIronPosition[0] = x;
                                    saveIronPosition[1] = y;
                                    saveIronPosition[2] = 0;
                                    saveIronPosition[3] = 1;
                                    saveList.Add(new positionOBject { mineralPosition = saveIronPosition });


                                    ironCountList.Add(1);
                                }//Iron
                                if (randomObject >= 85 && randomObject <= 94)
                                {
                                    saveSilverPosition = new float[4];
                                    saveSilverPosition[0] = x;
                                    saveSilverPosition[1] = y;
                                    saveSilverPosition[2] = 0;
                                    saveSilverPosition[3] = 2;
                                    saveList.Add(new positionOBject { mineralPosition = saveSilverPosition });

                                    silverCountList.Add(1);
                                }//Silver
                                if (randomObject >= 95 && randomObject <= 97)
                                {
                                    saveGoldPosition = new float[4];
                                    saveGoldPosition[0] = x;
                                    saveGoldPosition[1] = y;
                                    saveGoldPosition[2] = 0;
                                    saveGoldPosition[3] = 3;
                                    saveList.Add(new positionOBject { mineralPosition = saveGoldPosition });


                                    goldCountList.Add(1);
                                }//Gold
                                if (randomObject >= 98 && randomObject <= 100)
                                {
                                    saveDiamondsPosition = new float[4];
                                    saveDiamondsPosition[0] = x;
                                    saveDiamondsPosition[1] = y;
                                    saveDiamondsPosition[2] = 0;
                                    saveDiamondsPosition[3] = 4;
                                    saveList.Add(new positionOBject { mineralPosition = saveDiamondsPosition });


                                    diamondCountList.Add(1);
                                }//Diamonds
                                allMaterialsList.Add(1);

                            }

                        }

                    }

Generally it is not possible to map a grid evenly onto a sphere.

This is because the topology of an infinite plane and a bounded sphere are fundamentally incompatible.

If you are okay with the cells getting closer together near the poles, then you can use latitude as your Y offset and longitude as your X offset and regularly emplace objects based on those two pseudo-axes.

This does mean that at the exact pole, all your objects will be on one spot, where Santa Claus lives in the case of the North Pole.

I dont want map grid on sphere mazbe i wrote it wrong i want create “sphere” from cube gameobjects.

Do you mean to emplace them in space as a sphere? You can look at my coordinate generation for vertices here:

This file:

https://github.com/kurtdekker/makegeo/blob/master/makegeo/Assets/makeuvsphere/MakeUVSphere.cs

i and j are used to traverse latitude and longitude.

The position is generated at line 65 based on the usual trig functions.

Thanks i will check that out currently i am trying to create 3 loops XYZ

Mine is for the surface.

If you just want an even grid in 3 space (x, y, z), do this:

  • iterate x, y, z in nested for loops
  • generate each coordinate spaced however you like
  • IF the coordinate is close enough to center to be considered “in your sphere,” then spawn cube, else do not
1 Like

I found solution i just created cubeand all object what was in bigger distance then dedired radius i just didnt spawn

Try this free tool:

1 Like