I've been working on a personal project using Three JS as my main 3D object renderer. I'm trying to randomly generate spheres at various x, y, and z coordinates within a specified range. I was able to achieve this, but now I want each of these objects to have a random rotation speed along the x, y, and z axes ranging from -0.005 to 0.005. I'm unsure how to approach this and would greatly appreciate any help. Here is my code for random generation and animating 3D objects:
function randomStar(){
const geometry = new THREE.SphereGeometry(0.25, 24, 24);
const starMaterial = new THREE.MeshBasicMaterial({color: 0xffffff, wireframe: false});
const star = new THREE.Mesh(geometry, starMaterial);
const [x,y,z] = Array(3).fill().map(() => THREE.MathUtils.randFloatSpread(150));
star.position.set(x,y,z);
star.rotation.x += 0.01;
star.rotation.y += 0.01;
scene.add(star);
}
Array(350).fill().forEach(randomStar);
function animate() {
requestAnimationFrame( animate );
torus.rotation.y += 0.005;
torus.rotation.x += 0.005
torusOne.rotation.x += 0.002
torusOne.rotation.y += 0.005;
torusTwo.rotation.y+= 0.005;
torusTwo.rotation.x += 0.002
globe.rotation.y += 0.001
renderer.render(scene, camera);
}
animate();