Im trying to create a rubiks cube and im having kinda stupid problem.
Basically i only want to color the showing faces of the “big cube” but all i am getting so far is all the 27 “mini cubes” colored in ALL the faces and thats kinda f*ing my head.
Here’s the code im using to color the mini cubes:
for (var i = 0; i < this.geometry.faces.length; i += 2){
var color = colors[indiceCor++] //color of each face
this.geometry.faces[i].color.set(color); //triangle 1
this.geometry.faces[i+1].color.set(color);//triangle 2
}
// cubes material
this.material = new THREE.MeshBasicMaterial({
vertexColors: true
});
//creating all the cubes
for (let x = -1; x < 2; x++) {
for (let y = -1; y < 2; y++) {
for (let z = -1; z < 2; z++) {
if ((x === 0) && (y === 0) && (z === 0)) {
continue;
}
let cube =new THREE.Mesh(this.geometry,this.material);
cube.position.x = x;
cube.position.y = y;
cube.position.z = z;
this.scene.add(cube)
this.cubes.push(cube);
}
}
}