I have been trying to change the colour of the face of the cube, when i hover over of the mouse occurs, on that given face.
I read many different examples but i could not make it. Here is the gist of the code:
var cubeGeometry = new THREE.BoxGeometry(20, 20, 20);
var cubeMaterial = new THREE.MeshBasicMaterial(
{
color: 0xffffff, //white
vertexColors: THREE.FaceColors
});
cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
cube.userData.originalColor = 0xffff00;
function onDocumentMouseMove(event)
{
event.preventDefault();
// update the mouse variable
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
// calculate objects intersecting the picking ray
var intersects = raycaster.intersectObjects( scene.children );
if ( intersects.length > 0 && intersects[ 0 ].object === cube && isClicked === false)
{
var index = Math.floor( intersects[0].faceIndex / 2 );
cubeGeometry.faces[index].color.setHex(0xff000);
}
else if (isClicked === false) //when its not clicked, and there are no intersects, return it to original color
{
cube.material.color.set( cube.userData.originalColor );
}
}
I added that line to my program, but still it doesn’t work.
Your version seems to color one of the two triangles of the face. What about the whole face?