Skip to content

Instantly share code, notes, and snippets.

@akella
Created January 7, 2018 08:16
Show Gist options
  • Select an option

  • Save akella/0345b54bc885dbe6d4c0ccca9e14a2c6 to your computer and use it in GitHub Desktop.

Select an option

Save akella/0345b54bc885dbe6d4c0ccca9e14a2c6 to your computer and use it in GitHub Desktop.

Revisions

  1. akella created this gist Jan 7, 2018.
    20 changes: 20 additions & 0 deletions mouse.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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 );