Improving Icosphere Generation

October 25, 2018

Following my first post on generating an Icosphere, I thought about how to proceed for a cube sphere and decided to just follow exactly the same steps. As for the icosphere, I started with a cube and subdivided it. It was pretty straightforward and easier than I thought. Gere is the result.

Cubesphere first try

As you can see something the vertex aren’t very well aligned. And the issue gets clearer at higher subdivisions.

Cubesphere anomaly

The UV mapping from the icosphere still works. So at higher subdivision and without the wire-frame it would be hard to see, but it does annoy me a lot now that I know there is an issue. After some re-reading of the code I finally understood. What is happening is that every time I create a new point, I directly push it to it’s spherified position. Then, when subdividing again, the triangles’ side aren’t equal and it makes this warping effect.

This means it’s probably an issue with the icosphere as well. As the whole point of making an icosphere was to optimize the density of vertex on the mesh, it’s another reason to solve it!

Icosphere anomaly

To solve this, what I would actually need to do is very simply to do the full subdivision before normalizing the base primitive. And voilà! Way easier than I thought.

Corrected icosphere Corrected cubesphere

It’s much better and everything is well aligned. Though the cube has the triangle at the center of each face far larger than the ones near the side of the face. I remember I read about this effect on Catlike Coding’s blog and here as well. The trick is to manually remap the vertices to better fit a sphere. After integrating the equation to my scripts, I am pretty happy, but it’s still not as good as the default unity sphere. I wonder if manually placed the vertices or if they have a better algorithm to remap the vertices. I couldn’t find more info on this so I’ll keep the current result, but let me know if you do!

Cubesphere comparison, left: Unity, right: my scrtip Cubesphere comparison, left: Unity, right: my scrtip

Now that the work was done for the cube and icosahedron, it was a breeze to add all the base platonic solids. I also took the opportunity to generalize things a bit and made everything cleaner. Some of the platonic subdivision do not give very satisfying results. And when you have the cubesphere and icosphere, there are not so many reasons to use anything else.

All the different spheres

While refactoring I also improved the editor script and added a limit so that you don’t kill your computer by subdividing too much. (I did)

Finally, I always like the non smoothed icosphere look. This requires that each triangle-face has unique vertices so that the normal of each vertex is equal to the normal of the center of the triangle. I added a boolean and an extra loop to do this after the generation was done. It’s not the most efficient way I am sure, but it was the easiest to do in the current implementation.

Non smoothed icosphere

The final thing I would like to do (in a future post) is to integrate a quad tree and subdivide the sphere in terms of distance to the camera and slope of the terrain. This way, it might be possible to have a working full-scale planet, which is a bit my end-goal with these scripts.