Hi,
I found a code snippet distributing lines around a sphere. Unlucky me, it is written “so much past” newer versions so → Geometry and line generation is outdated. Can anyone help me to understand and update:
var pointsOnSphere = function (n) {
var upts = new Array();
var inc = Math.PI * (3 - Math.sqrt(5));
var off = 2.0 / n;
var x, y, z;
var r;
var phi;
for (var k = 0; k < n; k++){
y = k * off - 1 + (off /2);
r = Math.sqrt(1 - y * y);
phi = k * inc;
x = Math.cos(phi) * r;
z = Math.sin(phi) * r;
upts.push(new THREE.Vector3(x, y, z));
}
return upts;
}
var lineGeo = new THREE.Geometry();
var radius = 40;
var lngArray = [];
var seedArray = [];
var colorArray = [];
var drawArray = [];
var numOfPoints = 105000;
var points = pointsOnSphere(numOfPoints);
for (var i = 0; i < numOfPoints; i++) {
var num = 5+Math.floor(Math.random()*2);
var base = points[i];
base.multiplyScalar( radius );
var seed = Math.random();
var lat = 90 - (Math.acos(-base.y / radius)) * 180 / Math.PI;
var lon = ((270 + (Math.atan2(-base.x , -base.z)) * 180 / Math.PI) % 360) -180;
for (var j = 0; j < num; j++) {
var vertex = new THREE.Vector3().copy(base);
var lng = radius+(j*3.0);
var color = new THREE.Color(0xffffff);
var black = (j/num)+0.2;
color.setRGB(1.0, 1.0, 0.0);
vertex.setLength( lng );
lineGeo.vertices.push( vertex );
colorArray.push( color );
seedArray.push( seed );
lngArray.push( lng );
if (j == num-1 || j == 0) {
drawArray.push( 0 );
} else {
drawArray.push( 1 );
}
}
}
var vertices = lineGeo.vertices;
var values_color = attributes.customColor.value;
var values_lng = attributes.lng.value;
var values_seed = attributes.seed.value;
var values_draw = attributes.draw.value;
for( var v = 0; v < vertices.length; v++ ) {
values_lng[ v ] = lngArray[v];
values_seed[ v ] = seedArray[v];
values_draw[ v ] = drawArray[v];
values_color[ v ] = colorArray[v];
}
lines = new THREE.Line( lineGeo, shaderMaterial, THREE.LineStrip );
Many many thanks