I am currently working on a function to randomly change the color of 10 objects called material
. However, I am struggling with how to integrate this function into either an array or vectors. I attempted to use arrays like meshArrayX
in the color(selector)
function, but encountered issues where the object positions were undefined and no objects were colored at all.
var mesh, scene,
MeshBasicMaterial = new THREE.MeshBasicMaterial({
color: 0x000000,
opacity: 0.3,
transparent: true
});
var BoxGeometry = new THREE.BoxGeometry(16, 16, 16);
function random(){
var random = [0, 16, 32];
var randomValue = random[Math.floor(random.length * Math.random())];
console.log(randomValue);
}
function color(selector){
for(var v=0; v<10; v++){
selector.position.x = random();
selector.position.y = random();
selector.position.z = random();
selector.material.color.setHex( 0x0000ff);
}
}
var meshArrayX = [];
for (var x=0; x<3; x++) {
var meshArrayY = [meshArrayX.push(mesh = new THREE.Mesh(BoxGeometry, MeshBasicMaterial))];
for(var y=0; y<3; y++){
var meshArrayZ = [meshArrayY.push(mesh = new THREE.Mesh(BoxGeometry, MeshBasicMaterial))];
for(var z=0; z<3; z++){
meshArrayZ.push(mesh = new THREE.Mesh(BoxGeometry, MeshBasicMaterial));
mesh.position.x = 16*x;
mesh.position.y = 16*y;
mesh.position.z = 16*z;
scene.add(mesh);
console.log(meshArrayX.length, meshArrayY.length-1, meshArrayZ.length-1, mesh.position);
}
}
}
color(mesh);