Currently, I am working on developing a scene with three.js and incorporating 3 spheres into it. My goal is to switch all wireframe materials of the spheres created to non-wireframe ones. I opted not to use scene.traverse() as my scene contains multiple objects and I only wish to modify the spheres. However, with my existing code, I am limited to switching only one sphere. How can I access each individual sphere? Any assistance would be greatly appreciated. Thank you!
var numSpheres = 3;
function createSphere (x, y, z){
sphere = new THREE.Object3D();
material = new THREE.MeshBasicMaterial({ color: 0XFFA500, wireframe: true});
geometry = new THREE.SphereGeometry (2, 8, 8);
mesh = new THREE.Mesh(geometry, material);
sphere.add(mesh);
sphere.position.set(x, y, z);
scene.add(sphere);
}
createSpheres(numSpheres){
for(i = 1; i <= numSpheres; i++){
var randomnumber1 = Math.floor(Math.random() * (29.5 - -29.5 + 1)) + -29.5;
var randomnumber2 = Math.floor(Math.random() * (29.5 - -29.5 + 1)) + -29.5;
createSphere(randomnumber1, 3, randomnumber2);
}
}
function onKeyDown(e){
case 65:
case 97:
sphere.traverse(function (node){
if(node instanceof THREE.mesh) {
node.material.wireframe = !node.material.wireframe;
}
});