Generate icosphere mesh fast

2020/06/10

If you seach in the Internet for algorithms to generate icosphere meshes, most algorithms out there take an icosahedron and keep tessellating the triangular faces recursivelly (link).

recursive icosphere tesellation

I have made an algorithm that outputs the result, in a couple of flat arrays(vertices and indices), in a single pass, so it’s faster and very cache friendly. It also has the advantage that you can query the exact memory you need to allocate.

https://gist.github.com/tuket/32951040ca0a4b31395175ee3e075d46

// example usage
int numVerts, numInds;
generateIcosphere(numVerts, numInds, nullptr, nullptr, 8);
vec3* verts = new vec3[numVerts];
int* inds = new int[numInds];
generateIcosphere(numVerts, numInds, &verts, &inds, 8);

generate_icosphere.png

>> Home