I am currently working on a Three.js project for a webpage 3D example where I want to create a checkerboard. The issue I am facing is that my code assigns three colors, but I only need two colors (black and white). How can I adjust the mathematical calculations to generate the correct checkerboard pattern?
// Creating geometry for the checkerboard
var cbgeometry = new THREE.PlaneGeometry( 500, 500, 8, 8 );
// Defining materials for the board
var cbmaterials = [];
cbmaterials.push( new THREE.MeshBasicMaterial( { color: 0xffffff, side: THREE.DoubleSide }) );
cbmaterials.push( new THREE.MeshBasicMaterial( { color: 0x000000, side: THREE.DoubleSide }) );
cbmaterials.push( new THREE.MeshBasicMaterial( { color: 0x0000ff, side: THREE.DoubleSide }) );
// Assigning material based on the color index
var l = cbgeometry.faces.length / 2;
for( var i = 0; i < l; i ++ ) {
var j = 2 * i;
cbgeometry.faces[ j ].materialIndex = i % 3;
cbgeometry.faces[ j + 1 ].materialIndex = i % 3;
}
// Creating the mesh with the defined materials
var cb = new THREE.Mesh( cbgeometry, new THREE.MeshFaceMaterial( cbmaterials ) );
scene.add( cb );