Skip to content

Instantly share code, notes, and snippets.

@robinNavas
Forked from akella/mouse.js
Created February 27, 2021 08:49
Show Gist options
  • Select an option

  • Save robinNavas/2e3e0d575bd55eadfdfc609845b93b56 to your computer and use it in GitHub Desktop.

Select an option

Save robinNavas/2e3e0d575bd55eadfdfc609845b93b56 to your computer and use it in GitHub Desktop.
function onDocumentMouseDown( event ) {
event.preventDefault();
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
// find intersections
raycaster.setFromCamera( mouse, camera );
var intersects = raycaster.intersectObjects( scene.children );
var vector = new THREE.Vector3().copy( intersects[ 0 ].point );
intersects[ 0 ].object.worldToLocal( vector );
mat.uniforms.mouse.value.x = vector.x;
mat.uniforms.mouse.value.y = vector.y;
}
document.addEventListener( 'mousemove', onDocumentMouseDown, false );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment