Sphere generator

This is a pastime project I’ve been working on for a while and I recently got it to a state where I could share the code, because why not? :slight_smile:

It’s a quite simple app that generates a sphere mesh in 3D at runtime, with customizable resolution ie. You can decide how many fragments you want the sphere to be divided into, both horizontally and vertically.

And the sphere can be textured too! Yay :stuck_out_tongue:
You will need some kind of square texture though, but a quick google search will do the job, remember that it has to be square or you will get weird results.

About the texture mapping, it is not optimal, the top and bottom of the square contains artefacts because of the way I decided to map the texture, it can be improved. But at a high resolution you barely notice the artefacts. You are welcome to improve on that.

As a last mention here, as I said that the mesh is not optimized you sha’nt go too high on the resolution as the mesh gets very big and the amount of redundant vertices increase exponentially (vertices get alot more compressed at the top and bottom, making the overall concentration of verts increase at the poles)

Note: no texture or shader included!
Though you only need a real basic texture shader or a color only shader depending on what you want to use.

But enough talking, here’s the code:
http://pastebin.com/7kPkXwSV

Edit: added shader to code, and fixed errors, now it should be fully working!

error: [string "function setup()..."]:27: bad argument #1 to 'shader' (Shader not found)

could you make a shader-included version? That is easy to include then into the project.

@Muffincoder - Jmv38 has some nice sphere code too (without artifacts) and can wrap images like world maps around it, too, if you ask him where it is…

Now I have added shader code to the pastebin code(it is untested so please tell me if it doesnt work)

Also, one texture that looks great on the sphere is this: http://planetpixelemporium.com/earth.html

And choose the earth color texture in the list

@muffincoder there is a problem with shader compilation, but the sphere is ok. Nice work!

@Jmv38 Now it should work fine, as long as you change texture to one you got on your device. Thanks!

@Muffincoder the next step, if you want to share a a 100% working example, is to load the image link inside your program with hhtp.request(). That is not too difficult,

@Muffincoder - I have some code for downloading custom images here

http://coolcodea.wordpress.com/2013/05/23/62-3d-downloading-images-on-demand/

Nice! Here is a variation on how to create the sphere:
http://codea.io/talk/discussion/2424/isosphere/p1

@muffincoder you can find a sphere tuto somewhere here http://jmv38.comze.com/CODEAbis/server.php