How to highlight 3d object on mouse hover

You can store the clicked model in a global variable outside the onClick function, to change it back if you have not clicked the model.

var object // Global variable

onClick() {

    ....

    if (intersects.length > 0) {

        object = intersects[0].object;

        object.material.color.set( Math.random() * 0xffffff );
    }
    else { // stored object -> change back to #FFFFFF
        object.material.color.set( 0xffffff );
    }
}
1 Like