Threejs - Raycast Point Inside Shape

by black strings

HTML

<script src="https://rawgit.com/mrdoob/three.js/dev/build/three.js"></script>
<script src="https://rawgit.com/mrdoob/three.js/dev/examples/js/controls/OrbitControls.js"></script>

JavaScript

var scene, renderer, camera, controls;

init();
animate();

function init()
{	
    renderer = new THREE.WebGLRenderer( {antialias:true} );
	var width = window.innerWidth;
	var height = window.innerHeight;

    renderer.setSize (width, height);
    
	document.body.appendChild (renderer.domElement);

	scene = new THREE.Scene();

	camera = new THREE.PerspectiveCamera (60, width/height, 0.01, 10000);
	camera.position.y = 16;
	camera.position.z = 40;
	camera.lookAt (new THREE.Vector3(0,0,0));
    
  scene.add( camera );

  controls = new THREE.OrbitControls(camera, renderer.domElement);
    
	var gridXZ = new THREE.GridHelper(100, 10, 
  	new THREE.Color(0xffffff), 
  	new THREE.Color(0xffffff)
  );
  
	scene.add(gridXZ);  
  
  var customPlane = createTestPlane();
  var testPoint = new THREE.Vector3(60, 65, 0);

  createRayCastFromCamera(testPoint);
   
}

function createRayCastFromCamera(testPoint){
		
    // get the direction towards the point
    var rayDirection = new THREE.Vector3();
    rayDirection.subVectors(testPoint, camera.getWorldPosition());
    rayDirection.normalize();
   
   // create ray cast
   raycaster = new THREE.Raycaster();
   //cast a ray in the direction towards the point
   raycaster.set( camera.getWorldPosition(), rayDirection);
   
   // only used for when doing mouse clicking from camera
   //raycaster.setFromCamera({x:15, y:15}, camera);
   //camera.getWorldDirection()
   
   console.log(raycaster.intersectObjects(scene.children, true));
   
   // line visual helper to simulate the ray from camera to test point
    var lineGeo = new THREE.Geometry();
    lineGeo.vertices.push(camera.getWorldPosition().clone(), testPoint.clone());
    var line = new THREE.Line(lineGeo, new THREE.LineBasicMaterial());
    scene.add(line);
    
   /*
    raycaster.ray.direction.copy( direction ).applyEuler(rotation);
    raycaster.ray.origin.copy( camera.position );
    */
}

function createTestPlane(){
	var points = [
  	new THREE.Vector2(0,0),
    new...