Ivan Bacher
Ivan Bacher

Reputation: 6154

Map objects to outside of sphere

say i have an array of x sphere meshes that i want to add to a scene in a manner that all objects combined look like a large sphere. how would i go about doing this?

i can map them in a circle but the 3D part is somewhat harder.

this is the code im using to draw them in a circle manner:

var theta = 0;
var rad = 5 * objectsToAddToScene.length;

for (var i = 0; i < objectsToAddToScene.length; i++) {

  var obj = objectsToAddToScene[i];

  theta = ((Math.PI * 2) / objectsToAddToScene.length) * i;

  obj.position.x = Math.sin(theta) * rad;
  obj.position.y = -Math.cos(theta) * rad;

  Three.addObjToScene(obj);
 }; 

kind of the same as this example http://threejs.org/examples/webgl_interactive_cubes_gpu.html but with a sphere, and just placing the objects on the outer border

Upvotes: 0

Views: 86

Answers (1)

WestLangley
WestLangley

Reputation: 104783

One way is to let three.js do it for you.

var geometry = new THREE.SphereGeometry( radius, n, n/2 );
geometry.mergeVertices();

and then use geometry.vertices for your positions.

Alternatively, your could use IcosahedronGeometry( radius, n );

three.js r.65

Upvotes: 2

Related Questions