I have compiled a WebGL script that displays multiple grids using jsonloader and three.js, and now I want to add MouseOver and onClick events. The first one is just a change in the color of the grid when the mouse hangs over it:
function render() {
requestAnimationFrame(render);
mesh.rotation.z += 0.090;
raycaster.setFromCamera(mouse, camera);
var intersects = raycaster.intersectObjects(scene.children);
for (var i = 0; i < intersects.length; i++) {
intersects[i].object.material.color.set(0xff0000);
}
renderer.render(scene, camera);
}
The rendering function above allows me to change the color of any mesh to red, hanging over it. I tried several if / else options to try, and this effect only works when the mouse is over the grid, but I can’t get it to work - it just stays red. Can anyone suggest how I can change my script?
Thank.
source
share