You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
1.1 KiB
JavaScript
28 lines
1.1 KiB
JavaScript
/* Copyright (C) 2024 Sebastián Santisi <ssantisi@fi.uba.ar>, CSC-CONICET */
|
|
import * as THREE from 'three';
|
|
|
|
function checkBoard(width, height) {
|
|
var geometry = new THREE.PlaneGeometry(width, height, width, height);
|
|
geometry = geometry.toNonIndexed();
|
|
const colors = new three.BufferAttribute(new Float32Array(geometry.attributes.position.array.length), 3);
|
|
for(var i = 0; i < colors.count; i++) {
|
|
var col = Math.trunc(i / 6) % width;
|
|
var row = Math.trunc(i / 6 / width);
|
|
if((col + row % 2) % 2)
|
|
colors.setXYZ(i, 0x44 / 0xff, 0xaa / 0xff, 0);
|
|
else
|
|
colors.setXYZ(i, 0x55 / 0xff, 0xd4 / 0xff, 0);
|
|
}
|
|
geometry.setAttribute('color', colors);
|
|
const material = new THREE.MeshStandardMaterial({vertexColors: THREE.VertexColors});
|
|
//const material = new THREE.MeshPhongMaterial({vertexColors: THREE.VertexColors, specular: 0x999999, shiness: 30});
|
|
var mesh = new THREE.Mesh(geometry, material);
|
|
mesh.receiveShadow = true;
|
|
|
|
mesh.position.x = width / 2;
|
|
mesh.position.y = height / 2;
|
|
return mesh;
|
|
}
|
|
|
|
export { checkBoard };
|