title: How to raycast onto a pointcloud in ThreeJs R71
body: <p>I am working in autodesk forge which includes Threejs r71 and I want to use a raycaster to detect clicks on different elements within a pointcloud. </p>
  
  <p>Sample code for how to do this with ThreeJs r71 be appreciated.</p>
  
  <p>Right now, I register an extension with the forge api and run the code below within it. It creates creates a pointcloud and positions the points at predetermined locations (saved within the cameraInfo array). </p>
  
  <pre><code>let geometry = new THREE.Geometry();
  this.cameraInfo.forEach( function(e) {
          geometry.vertices.push(e.position);
      }
  )
  const material = new THREE.PointCloudMaterial( { size: 150, color: 0Xff0000, sizeAttenuation: true } );
  this.points = new THREE.PointCloud( geometry, material );
  this.scene.add(this.points);
  
  /* Set up event listeners */
  document.addEventListener('mousemove', event =&gt; {
      // console.log('mouse move!');
      let mouse = {
          x: ( event.clientX / window.innerWidth ) * 2 - 1,
          y: - ( event.clientY / window.innerHeight ) * 2 + 1
      };
  
      let raycaster = new THREE.Raycaster();
  
      raycaster.params.PointCloud.threshold = 15;
      let vector = new THREE.Vector3(mouse.x, mouse.y, 0.5).unproject(this.camera);
      raycaster.ray.set(this.camera.position, vector.sub(this.camera.position).normalize());
      this.scene.updateMatrixWorld();
      let intersects = raycaster.intersectObject(this.points);
  
  
      if (intersects.length &gt; 0) {
          const hitIndex = intersects[0].index;
          const hitPoint = this.points.geometry.vertices[ hitIndex ];
          console.log(hitIndex);
          console.log(hitPoint);
      }
  
  }, false);
  </code></pre>
  
  <p>The output seems to be illogical. At certain camera positions, it will constantly tell me that it is intersecting an item in the pointcloud (regardless of where the mouse is). And at certain camera positions, it won't detect an intersection at all. </p>
  
  <p>TLDR: it doesn't actually detect an intersection b/w my pointcloud and the mouse.</p>