Icosphere Shape

I wrote some code to create an icosphere. It’s an interesting shape that has both benefits and drawbacks. Anyway - feel free to use it as you wish.

The image above shows the first six levels of recursion.

Useage:

Mesh icosphere = new Icosphere(int recursions, float size);

https://gist.github.com/jayfella/3b57cf705991e5fc1a6c023ade3fec34

15 Likes

no normals?

  • could the position buffer be used, or are those no longer normalized after mult(size)?

So if you used the Vertex buffer for each point in the icosphere the point itself is the correct vertex for a normal.

One way (if you wanted to alter this code to add it) is to simply take the point, and normalize it a la

Vector3f myNormal = vertices.get(x).normalize();

Add that into your normal array maintaining the same position as you got it from and that should do it.
https://jmonkeyengine.github.io/wiki/jme3/advanced/custom_meshes.html#setting-the-mesh-buffer

But if you’re just doing a critique of this posted library… Then yes. I agree. The normals should’ve been added as well. :stuck_out_tongue:

I kinda gave up with it when I posted it here. Mapping an icosphere is an art. Some people have come up with decent results, but unless you specifically want one, it’s far easier using a sphere.

I thought they were talking about face normal vectors, not uv coordinates.

yeah sorry i meant that was the point at which i stopped working on it.

not gonna pretend i knew the maths off the top of my head but here is the equation. i’ll update the gist when i get on my pc.

I don’t think you’d need any fancy math in this case since it’s basically a sphere. Adding up the three vertex vectors and normalizing the result should give the triangle center normal no?

The perils of not being educated in the field you love… big gaps in the horizon of things you should really know at this point :stuck_out_tongue: my strong point is not maths, though i try to eradicate that with reading as time goes by. i have a soft spot for it these days.

Thank you for posting this algorithm.
An icosphere might make a nice replacement for com.jme3.scene.debug.WireSphere
I’ll probably add it to one of my libraries at some point.

For any sphere, if the mesh is radius 1 then the vertex positions are also the vertex normals.

…it’s only if you want a flat sided sphere that you need to average anything. But then you would also need to unshare the vertexes (I assume they are shared in this mesh).

2 Likes

I’ve started using this in my game so I’ve updated the code.

  • use word “radius” as opposed to “size” for clarity.
  • Added license (the same as JME3).
  • Normals are now generated.

Please see first post for the link.

What does your texture look like using Longitude/Latitude mapping? Is there any stretching/warping around the axis poles?
I used hardcoded uv coords on the principle icosahedron mesh to match a “Fisher/Snyder’s equal-area polyhedral projection” texture template, but i have a lot of unused space as i made to fit into a texture with 2:1 resolution ratio (512x256) which extends slightly past the edge of the uv map to avoid stretching the unwrapped triangles.
it is fairly easy to accommodate new vertices from subdivision as it is basically the 2d variant of the method for getting the midpoint for each edge of the principle triangle during subdivision.

That’s the problem with this shape, there is no way to project a texture economically on to it. I use it as a glowing orb to represent a spirit, so just use vertex colours instead.

It irks me that I didn’t put any reference links in the code to what I read on getting this working. But as far as I recall, you get two choices, economical texture use with warped poles or wasted texture space with 1:1 mapping.