old_contents: /**
    @author David Piegza
  
    Implements a selection for objects in a scene.
    
    It invokes a callback function when the mouse enters and when it leaves the object.
    Based on a Three.js selection example.
    
    Parameters:
      domElement: HTMLDomElement
      selected: callback function, passes the current selected object (on mouseover)
      clicked: callback function, passes the current clicked object
   */
  
  THREE.ObjectSelection = function(parameters) {
    var parameters = parameters || {};
  
    this.domElement = parameters.domElement || document;
    this.projector = new THREE.Projector;
    this.INTERSECTED;
    
    var _this = this;
    
    var callbackSelected = parameters.selected;
    var callbackClicked = parameters.clicked;
    var mouse = { x: 0, y: 0 };
  
    this.domElement.addEventListener( 'mousemove', onDocumentMouseMove, false );
    function onDocumentMouseMove( event ) {
      mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
      mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
    }
  
    this.domElement.addEventListener( 'click', onDocumentMouseClick, false );
    function onDocumentMouseClick( event ) {
      if(_this.INTERSECTED) {
        if(typeof callbackClicked === 'function') {
          callbackClicked(_this.INTERSECTED);
        }
      }
    }
  
    this.render = function(scene, camera) {
      // find intersections
      camera.update();
  
      var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
      this.projector.unprojectVector( vector, camera );
  
      var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );
  
      var intersects = ray.intersectScene( scene );
      if( intersects.length > 0 ) {
        if ( this.INTERSECTED != intersects[ 0 ].object ) {
          if ( this.INTERSECTED ) {
            this.INTERSECTED.materials[ 0 ].color.setHex( this.INTERSECTED.currentHex );
          }
  
          this.INTERSECTED = intersects[ 0 ].object;
          this.INTERSECTED.currentHex = this.INTERSECTED.materials[ 0 ].color.getHex();
          this.INTERSECTED.materials[ 0 ].color.setHex( 0xff0000 );
          if(typeof callbackSelected === 'function') {
            callbackSelected(this.INTERSECTED);
          }
        }
      } else {
        if ( this.INTERSECTED ) {
          this.INTERSECTED.materials[ 0 ].color.setHex( this.INTERSECTED.currentHex );
        }
        this.INTERSECTED = null;
        if(typeof callbackSelected === 'function') {
          callbackSelected(this.INTERSECTED);
        }
      }
    }  
  }
  
  
  
  
  
  
  
new_contents: /**
    @author David Piegza
  
    Implements a selection for objects in a scene.
  
    It invokes a callback function when the mouse enters and when it leaves the object.
    Based on a Three.js selection example.
  
    Parameters:
      domElement: HTMLDomElement
      selected: callback function, passes the current selected object (on mouseover)
      clicked: callback function, passes the current clicked object
   */
  
  THREE.ObjectSelection = function(parameters) {
    var parameters = parameters || {};
  
    this.domElement = parameters.domElement || document;
    this.projector = new THREE.Projector();
    this.INTERSECTED;
  
    var _this = this;
  
    var callbackSelected = parameters.selected;
    var callbackClicked = parameters.clicked;
    var mouse = { x: 0, y: 0 };
  
    this.domElement.addEventListener( 'mousemove', onDocumentMouseMove, false );
    function onDocumentMouseMove( event ) {
      mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
      mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
    }
  
    this.domElement.addEventListener( 'click', onDocumentMouseClick, false );
    function onDocumentMouseClick( event ) {
      if(_this.INTERSECTED) {
        if(typeof callbackClicked === 'function') {
          callbackClicked(_this.INTERSECTED);
        }
      }
    }
  
    this.render = function(scene, camera) {
      var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
      this.projector.unprojectVector( vector, camera );
  
      var raycaster = new THREE.Raycaster(camera.position, vector.sub(camera.position).normalize());
  
      var intersects = raycaster.intersectObject(scene, true);
  
      if( intersects.length > 0 ) {
        if ( this.INTERSECTED != intersects[ 0 ].object ) {
          if ( this.INTERSECTED ) {
            this.INTERSECTED.material.color.setHex( this.INTERSECTED.currentHex );
          }
  
          this.INTERSECTED = intersects[ 0 ].object;
          this.INTERSECTED.currentHex = this.INTERSECTED.material.color.getHex();
          this.INTERSECTED.material.color.setHex( 0xff0000 );
          if(typeof callbackSelected === 'function') {
            callbackSelected(this.INTERSECTED);
          }
        }
      } else {
        if ( this.INTERSECTED ) {
          this.INTERSECTED.material.color.setHex( this.INTERSECTED.currentHex );
        }
        this.INTERSECTED = null;
        if(typeof callbackSelected === 'function') {
          callbackSelected(this.INTERSECTED);
        }
      }
    }
  }
  
subject: Update three.js calls in ObjectSelection