写在前面
之前用processing写过类似的弹性球。具体写法不难,主要是在IDE熟悉的基础上理解球坐标的原理。只需要两层for循环的嵌套即可完成主体部分。
for嵌套
for(var fi=0;fi<=Math.PI;fi+=Math.PI/10){
var count=10-3*Math.abs(Math.PI/2-fi);
for(var theta=0;theta<=Math.PI*2;theta+=Math.PI/count){
var cubeGeo=new THREE.CubeGeometry(0.4,0.4,0.4);
var cubeMaterial=new THREE.MeshLambertMaterial({color:Math.random()*0xffffff});
var cube=new THREE.Mesh(cubeGeo,cubeMaterial);
cube.position.set(5*Math.sin(fi)*Math.sin(theta),5*Math.sin(fi)*Math.cos(theta),5*Math.cos(fi));
scene.add(cube);
}