
distributing an unknown amount of points on a spherical shape
as far as I know, no 3D engine can handle the triangulated sphere or geosphere that one can findin 3DSmax
it basically looks like this (sorry for the crappy picture):

it’s made of triangles and as you may have noticed, triangles are good.
as opposed to the whatever sphere (again sorry for the crappy picture):

in the current engines (I think that) you have to do something like a whatever sphere (giving a height segments number and a whatever ‘slice’ number )
It happened quite often at work that I’ve been asked to ditribute a given number of objects on a sphere. When I had to do so, I usually performed a good ol’hack like counting the vertices of a sphere, then creating some temporary triangles every N face, reorient them to finally collect their centers to pin an object there…
tiring.
so I was extremely glad yesterday morning when I found this : nodename (check out Alan’s work, it’s really worth it).
especially as I’ve been asked to do exactly this (distribute a given number of points on a sphere) no later than yesterday noon.
whatever.
I told them: “ok, I found this article this morning but the guy ( Alan ) doesn’t release the actionscript code so I’ll have to port it from C++. give me the afternoon and I’ll let you know what happened”.
edit: I had a chance to check Alan’s code (all you’ve got to do is ask for it ^^) and it’s really worth being seen for it’s more than a straight port. He really “worked it around”.
ok, now check it out:
the distribution algorithm
Technically it’s a kind of spring mass system that works in 3D pushing and pulling vertices in all directions based on their energy. check out nodename’s post for more info.
I changed the algorithm a bit so that you can input a random set of points that will be nicely sorted and returned. there are 2 params vertices, the unsorted array, nstep which is the maximum amount of recursions. in the demo, I’m using 10 recursions which is a good ratio performances/quality.
Of course the higher the recursion amount, the nicest the result (the more violent for the processor though). and also, the algorithm normalizes the position of each vertex so after the distribution, I perform a rescale on every vertex. As they all have the same raidus, it’s not that painful.
and here’s the zip of that unbelieivable demo
The zip file includes my wonderful 3D particles engine (/*cough*/) absolutely uncommented and messy as hell yet it gives an idea of an implementation ( check the addVertice method in Scene3D). of course you can put the Distibution algorithm inside the render loop which gives a ‘shlobolob’ effect when adding a particle but tends to come absolutely unstable for an unknown reason.
Hope you’ll like it, cheers
makc3d
on Nov 28th, 2008
@ 1:06 am:
You are a bit misinformed, away and sandy do have (somewhat cheated out) geospheres, and I think also alternativa3d. Also, there is much older geosphere for away that, however, does not support UVs.
P.s.: what’s with white-on-white text? It’s not funny to ctrl+a to read it :(
makc3d
on Nov 28th, 2008
@ 1:08 am:
Oh yeah, I forgot, folks at panosalado project made one for papervision, too.
nicoptere
on Nov 28th, 2008
@ 12:22 pm:
hi,
shame on me.
both AWAY3D and SANDY DO HAVE a geosphere.
it is specified in the SANDY’s class description that:
what I used it for for was rather basic actually, we did a viral game where people had to find gates on the net and each gate had to be added to a sphere. we needed a “light weight” solution (which could be embedded in banners for example) so that’s what I was so glad to find Alan’s post and to manage to port that class from C. looking back it is pretty dirty especially when compared to Alan’s version.
Paulo Araujo
on Apr 14th, 2009
@ 2:14 pm:
Wow… vry good!
Thanks man!
and Congrats!
P.J. Onori
on Apr 25th, 2009
@ 8:34 pm:
Hi there. I just wanted to mention that I’ve used a portion of your code in a library I’m in the process of writing. I’d love to not only get your feedback on the project, but to also get your blessing in the use of the code. I couldn’t find an email address to hit you up at, so I’m dropping you a comment here. Thanks!
Motosauro » Blog Archive » Motosauro - Appunti di sviluppo e varie
on May 14th, 2009
@ 4:23 pm:
[...] A questo indirizzo ce n’è un esempio e un altro qui [...]
Come & play with my hairy balls … | iq¹²
on Jul 10th, 2009
@ 1:58 pm:
[...] hair roots are placed with the sphere distribution script of Nicolas Barradeau, so thank you [...]
Spherical distribution | signalsondisplay
on Jan 12th, 2010
@ 11:45 pm:
[...] articles and came across this. I know it’s been done before, countless time, by this dude for example. So I tried out this implementation using DirectX9, and it was slow as fuck. So [...]
Michael Gaio
on Mar 28th, 2010
@ 8:55 am:
Thanks! Been looking for this for a while (like years)!