My current project involves creating a random star chart within three.js that transforms into a planet (sphere) when zoomed out.
The issue I am facing is that the code I am using randomly generates stars, but when I zoom out, it appears as a cube instead of a sphere.
for (var i = 0;i<2000;i++){
var mesh = new THREE.Mesh( geometry, material);
mesh.position.x = ( Math.random() - 0.5) * 4000 * Math.random();
mesh.position.y = ( Math.random() - 0.5) * 4000* Math.random() ;
mesh.position.z = ( Math.random() - 0.5) * 4000* Math.random() ;
mesh.rotation.x = Math.random();
mesh.rotation.y = Math.random();
mesh.rotation.z = Math.random();
scene.add(mesh);
objects.push(mesh);
}
In this for loop, the spawning of stars occurs, and lines 3-6 are crucial in determining how the stars are positioned. However, my attempts to create a sphere by multiplying the positioning with Math.random have only resulted in a less defined cube instead.